akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	int X, Y, Z;
	cin >> X >> Y >> Z;
	swap(X, Y);
	swap(X, Z);
	cout << X << " " << Y << " " << Z << endl;

	return 0;
}


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

namespace ABC098A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b,c,d,e, max;

            var word = Console.ReadLine().Split(' ');
            //整数A,Bの入力
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = a + b;
            d = a - b;
            e = a * b;
            //最大値maxを求める
            if (c>=d&&c>=e)
                max = c;
            
            else if(c <= d && d >= e)
                max = d;
            else
                max = e;

            Console.WriteLine(max);
            Console.ReadKey();
        }
    }
}



Measured memory_bytes: 13140
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(void){
    int i,n=0,tmp = 0;
    char tem;
    char num[1001];
    while(1){
        scanf("%s",&num);
        i = 0;
        tmp = 0;
        if(num[i]=='0') break;
        while(1){
            if(num[i]=='\0')break;
            tem = num[i];
             n = atoi(&tem);
             tmp+=n;
             i++;
        }
        printf("%d\n",tmp);
    }
    return 0;
}

Measured memory_bytes: 548
MAX = 100003
ws = [0 for i in range(MAX)] 
par = [-1 for i in range(MAX*2)]


def weight(x):
    root(x)
    return ws[x]

def root(x):
    if par[x] < 0: return x
    p = root(par[x])
    ws[x] = ws[x] + ws[par[x]]
    par[x] = p
    return par[x]


def unite(y, x, z):
    z = z + weight(x)
    z = z - weight(y)
    x = root(x)
    y = root(y)
    if x == y: return 0
    if par[y] < par[x]:
        tmp = x
        x = y 
        y = tmp 
        z = -z
     
    par[x] = par[x] + par[y]
    par[y] = x
    ws[y] = z
    return 1 

def diff(x,y):
    if root(x) != root(y) :return 0
    ans = ws[x] - ws[y]
    return 1 ,ans


if __name__=='__main__':
   global ans
   N, Q =  (int(x) for x in  input().split())
   for q in range(Q):
        t, *cmd =  (int(x) for x in  input().split())
        if t:
            x, y = cmd
            z = diff(x, y)
            if z==False :print("?")
            else :print(z[1])
        else:
            x, y, z = cmd
            unite(x, y, z)




Measured memory_bytes: 11136
#include <iostream>
#include <string>

int hoge(int i){
  int ret = 0;
  while(i){
    ret+=i%10;
    i/=10;
  }
  return ret;
}

int main(void){
  int alist[37] = {};

  int n, a,b;
  std::cin >> n >> a >> b;

  int total = 0;
  for(int i=1; i<=n; i++){
    if(hoge(i) <= b && hoge(i) >= a){
      total += i;
    }
  }
  std::cout << total << std::endl;
  return 0;
}




Measured memory_bytes: 256
#include <stdio.h>
#include <float.h> 
int main(void){	
  int n[100];	
  int a[1000];	
  int i,j,max[100],min[100],suma[100],sumb[100],ave[100]; 
  for(i = 0;;i++){  
    scanf("%d",&n[i]);
    if(n[i]==0)break;  
    for(j=0 ; j<n[i] ;j++){ 
      scanf("%d",&a[j]);
    } 
    max[i] = a[0];
    min[i] = a[0];
    suma[i] = 0; 
    for(j=0 ; j<n[i] ; j++){
      if(a[j] >= max[i]){
	max[i] = a[j];
      }
      if(a[j] <= min[i]){
	min[i] = a[j];
      }
      suma[i] += a[j];
    }
  } 

  for(j = 0;j < i;j++){
    sumb[j] = suma[j]-max[j]-min[j]; 
    n[j] -= 2;
    ave[j] = sumb[j] / n[j] ;
    printf("%d\n",ave[j]);    
  }
  return 0;
  
}

Measured memory_bytes: 1032
#include<iostream>
using namespace std;
int m[12][12];
char c[12];
int ans;
int d1[4]={1,0,-1,0};
int d2[4]={0,1,0,-1};
bool valid(int y,int x){
	if(0<=y&&y<12){
		if(0<=x&&x<12){
			if(m[y][x]==1)return true;
		}
	}
	return false;
}
void dfs(int y,int x){
	m[y][x]=0;
	for(int i=0;i<4;i++){
		int ny=y+d1[i],nx=x+d2[i];
		if(valid(ny,nx))dfs(ny,nx);
	}
}
int main(){
	while(1){
		ans=0;
		for(int i=0;i<12;i++){
			if(!(cin>>c))return 0;
			for(int j=0;j<12;j++){
				m[i][j]=(int)(c[j]-'0');
			}
		}
		for(int i=0;i<12;i++){
			for(int j=0;j<12;j++){
				if(valid(i,j)){
					dfs(i,j);
					ans++;
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1140
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.TreeMap;
import java.util.Map;
import java.util.Scanner;
import java.util.SortedMap;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author vdewansa
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        EKnapsack2 solver = new EKnapsack2();
        solver.solve(1, in, out);
        out.close();
    }

    static class EKnapsack2 {
        private void update(SortedMap<Long, Long> m, long W, long w, long v) {
            if (w < 0 || w > W) {
                return;
            }
            if (m.containsKey(w)) {
                m.put(w, Math.max(m.get(w), v));
            } else {
                if (m.headMap(w).isEmpty()) {
                    m.put(w, v);
                } else {
                    long lastKey = m.headMap(w).lastKey();
                    if (v > m.get(lastKey)) {
                        m.put(w, v);
                    }
                }
            }
            for (long ow : m.tailMap(w).keySet()) {
                if (m.get(ow) < v) {
                    m.put(ow, v);
                }
            }

        }

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int W = in.nextInt();
            int[] w = new int[N + 1];
            int[] v = new int[N + 1];
            for (int i = 1; i <= N; i++) {
                w[i] = in.nextInt();
                v[i] = in.nextInt();
            }

            SortedMap<Long, Long> bestPrev = new TreeMap<>();
            SortedMap<Long, Long> bestCur = new TreeMap<>();
            update(bestPrev, W, w[1], v[1]);
            for (int i = 2; i <= N; i++) {
                for (Long wPrev : bestPrev.keySet()) {
                    update(bestCur, W, wPrev, bestPrev.get(wPrev));
                    long wCur = wPrev + w[i];
                    update(bestCur, W, wCur, bestPrev.get(wPrev) + v[i]);
                }
                update(bestCur, W, w[i], v[i]);
                bestPrev = bestCur;
                bestCur = new TreeMap<>();
            }
            out.println(bestPrev.get(bestPrev.lastKey()));
        }

    }
}



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

struct P {
	int to, c, d;
};
vector<P>E[30];
double d[30][31][30];

struct st {
	int p, h, pr; double c;
};
bool operator<(st a, st b) {
	return a.c > b.c;
}
int main() {
	int n, m;
	while (scanf("%d%d", &n, &m), n) {
		int s, g; scanf("%d%d", &s, &g); s--; g--;
		rep(i, n)E[i].clear();
		rep(i, m) {
			int x, y, d, c; scanf("%d%d%d%d", &x, &y, &d, &c); x--; y--;
			E[x].push_back({ y,c,d }); E[y].push_back({ x,c,d });
		}
		priority_queue<st>que;
		fill(d[0][0], d[30][0], INF);
		for (P v : E[s]) {
			d[v.to][1][s] = v.d; que.push({ v.to,1,s,d[v.to][1][s] });
		}
		while (!que.empty()) {
			st p = que.top(); que.pop();
			if (d[p.p][p.h][p.pr] != p.c)continue;
			for (P v : E[p.p]) {
				if (v.to == p.pr)continue;
				for (int i = -1; i <= 1; i++) {
					if (p.h + i > 0 && p.h + i <= v.c) {
						if (d[v.to][p.h + i][p.p] > p.c + v.d / double(p.h + i)) {
							d[v.to][p.h + i][p.p] = p.c + v.d / double(p.h + i);
							que.push({ v.to,p.h + i,p.p,d[v.to][p.h + i][p.p] });
						}
					}
				}
			}
		}
		double Min = INF;
		rep(i, n)Min = min(Min, d[g][1][i]);
		if (Min == INF)puts("unreachable");
		else printf("%.7lf\n", Min);
	}
}

Measured memory_bytes: 3752
import math

n = int(input())
a = [list(map(int, input().split())) for _ in range(n-1)]

for i in range(n-1):
    t = 0
    for j in range(i, n-1):
        if a[j][1] >= t:
            t = a[j][1]
        else:
            t = math.ceil(t / a[j][2]) * a[j][2]
        t += a[j][0]
    print(t)
print(0)

Measured memory_bytes: 3188
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n, temp;
    cin >> n;

    vector<int> a(n);

    for (int i = 0; i < n-1; i++)
    {
        cin >> temp;
        a[temp-1]++;
    }

    for (int elem : a) cout << elem << endl;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
 
long long int INF = 3e18;
double Pi = 3.1415926535897932384626;
 
vector<ll> G[550010];
//vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
 
 
ll mod = 1000000007;
/*
2000000011 is prime
2000000033 is prime
*/

ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

/*
ll fact[800005],rfact[800005];

void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=800000; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[800000] = rui(fact[800000],mod - 2);
    for(ll i=800000; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;}
*/
 
ll n,m,num,sum,a,b,c,d,e,g,h,w,i,j,q,r,l;
ll k,ans;
ll x[500005],y[500005],z[500005];

int main(){
    cin >> n;
    p(rui(n,3));
    return 0;
}






Measured memory_bytes: 14592
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <math.h>
#include <tuple>
#include <queue>
#include <set>

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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


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

    int N;
    cin >> N;

    vector<int> p(N);

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

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

    p[N-1] /= 2;

    int ans = 0;

    for(int i = 0; i < N; i++){
        ans += p[i];
    }

    cout << ans << endl;

    return 0;
}


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

int my_gcd(int A, int B) {
	while (A > 0 && B > 0) {
		if (A > B) {
			A = A % B;
		} else {
			B = B % A;
		}
	}
	// A or B =0
	return A + B;
}

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

	int N, K;
	scanf("%d %d", &N, &K);

	int A;
	scanf("%d", &A);

	int a_max = A;
	int a_gcd = A;

	for (int i = 1; i < N; i++) {
		scanf("%d", &A);
		a_gcd = my_gcd(A, a_gcd);
		a_max = max(a_max, A);
	}
	// cout << "a_gcd=" << a_gcd << "\na_max=" << a_max << "\n";
	if (a_max == K || a_max > K && K % a_gcd == 0) {
		cout << "POSSIBLE";
	} else {
		cout << "IMPOSSIBLE";
	}

	return 0;
}

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

using namespace std;

int n, A, B, a, b;

string s;

int main()
{
    cin >> n >> A >> B >> a >> b;
    cin >> s;
    s = " " + s;
    if(A > B)
    {
        swap(A, B);
        swap(a, b);
    }
    if(a < b)
    {
        for(int i = A; i <= a - 1; i++)
            if(s[i] == '#' && s[i + 1] == '#')
            {
                cout << "No\n";
                return 0;
            }
        for(int i = B; i <= b - 1; i++)
            if(s[i] == '#' && s[i + 1] == '#')
            {
                cout << "No\n";
                return 0;
            }
        cout << "Yes\n";
        return 0;
    }
    for(int i = A; i <= a - 1; i++)
        if(s[i] == '#' && s[i + 1] == '#')
        {
            cout << "No\n";
            return 0;
        }
    for(int i = max(B, 2); i <= min(b, n - 1); i++)
        if(s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.')
        {
            cout << "Yes\n";
            return 0;
        }
    cout << "No\n";
    return 0;
}


Measured memory_bytes: 772
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define modulo 1000000007
typedef long long int ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int main(int argc, char const *argv[])
{
	int a,b;
	cin >> a >> b;

	vector<int> v = {a+b, a-b, a*b};
	sort(v.begin(),v.end());

	cout << v[2] << endl;
	return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main(String args[]) {
    int rep = 1;
    if( args.length > 0 ) { rep = Integer.parseInt(args[0]); }
    (new Main()).__solve(rep);
  }

  void __solve(int rep) {

    try (
      Scanner cin = new Scanner(System.in);
    ) {

      for( int i = 0; i < rep; ++i ) {
        __solve(cin);
      }

    }

  }

  void __solve(Scanner cin) {

	  int N = cin.nextInt();
	  int K = cin.nextInt();
	  
	  int array[] = new int[N];
	  for( int i = 0; i < N; ++i ) {
		  array[i] = cin.nextInt() - 1;
	  }
	  
	  UnionFind uf = new UnionFind(N);
	  
	  for( int i = 0; i < K; ++i ) {
		  int L = cin.nextInt() - 1;
		  int R = cin.nextInt() - 1;
		  uf.merge(L, R);
	  }
	  
	  int ret = 0;
	  for( int i = 0; i < N; ++i ) {
		  if( uf.same(array[i], i) ) { ++ret; }
	  }
	  System.out.println(ret);
	  
  }

  class UnionFind {

	  private static final boolean ufDebug = false;
	  private static final int ROOT = -1;

	  private int group[];
	  private int size;
	  private int rest;

	  private int count[];

	  public UnionFind(int N) {
	    size = rest = N;
	    group = new int[size];
	    for(int i=0; i<N; ++i) { group[i] = ROOT; }
	    count = new int[size];
	  }

	  public int size() {
	    return rest;
	  }

	  public int find(int index) {
	    if( index < 0 || index >= size ) { return -1; }
	    int ret = index;
	    while( group[ret] != ROOT ) { ret = group[ret]; }
	    return ret;
	  }

	  public boolean same(int a, int b) {
	    return find(a) == find(b);
	  }

	  public void merge(int a, int b) {
	    int A = find(a);
	    int B = find(b);
	    if( A == B ) { return; }
	    if( count[A] <= count[B] ) { subMerge(A, B); }
	    else { subMerge(B, A); }
	  }

	  // merge A (small) into B (large)
	  private void subMerge(int A, int B) {
	    if( group[A] != ROOT || group[B] != ROOT ) {
	      if( ufDebug ) { throw new RuntimeException("Implementation Error !"); }
	      return;
	    }
	    group[A] = B;
	    count[B] += count[A] + 1;
	    --rest;
	  }

	}

}


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

namespace ConsoleApp1
{
    /// <summary>
    /// ???????????????????§£????????????
    /// </summary>
    static class P0517
    {
        static void Main(string[] args)
        {
            P0517.Solve();
        }


        public static void Solve()
        {
            int[] input;

            input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

            while (input[0] != 0 || input[1] != 0)
            {
                Console.WriteLine(CalcMaxlen(input));
                input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            }

        }

        private static int CalcMaxlen(int [] input)
        {
            const int WHITE = 0;    //????´???????????????°???
            List<int> cardList = new List<int>();   //??????????????????
            bool isPassAble;    //???????????????

            for (int i = 0; i < input[1]; i++)
            {
                int n = int.Parse(Console.ReadLine());
                cardList.Add(n);
            }

            cardList.Sort();    //???????????????
            isPassAble = cardList[0] == WHITE;  //????´????????????????==????????????

            int len = 1, oldlen = 0, maxlen = 0;
            for (int i = isPassAble ? 2 : 1; i < cardList.Count; i++)
            {
                //??£?????????
                if (cardList[i - 1] + 1 == cardList[i])
                {
                    len++;  //?????????1??????
                }
                //??£?????§?????????????´?????????????????????????
                else if (isPassAble)
                {
                    //?????¨??????????????£???????¶???????????????§?????´??°
                    int sum = len + oldlen + 1;
                    maxlen = maxlen < sum ? sum : maxlen;
                    //????????£??????????????¨?????????????????£???????????????????´???§??????????????????
                    oldlen = (cardList[i - 1] + 2 == cardList[i]) ? len : 0;

                    len = 1;
                }
                //??£?????§????????????
                else
                {
                    //?????§????????´??°
                    maxlen = maxlen < len ? len : maxlen;
                    len = 1;
                }
            }

            //??£?????§????????£?????´????????????????????????????????´??°
            if (isPassAble)
            {
                int sum = len + oldlen + 1;
                maxlen = maxlen < sum ? sum : maxlen;
            }
            else
            {
                maxlen = maxlen < len ? len : maxlen;
            }

            return maxlen;
        }
    }
}

Measured memory_bytes: 11212
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
ll n;
ll a,b,c,d;
ll ans=1e18;
map<ll,ll>mp;
int main(){
	ios::sync_with_stdio(false);
	int t;cin >> t;
	while(t--){
		cin >> n >> a >> b >> c >> d;
		ans=1e18;
		mp.clear();
		mp[n]=0;
		//system("pause");
		while(!mp.empty()){
			auto it=mp.end();--it;
			ll x=it->fi,y=it->se;
			//cout << x << ' ' << y << endl;
			mp.erase(it);
			if(y>=1e18) continue;
			ll nx,ny;
			if(x==0 || 1e18/x>=d) ans=min(ans,d*x+y);
			if(x==0) continue;
			if(x==1) continue;
			nx=x/2;ny=d*abs(nx*2-x)+y+a;
			if(mp[nx]==0) mp[nx]=ny;
			else mp[nx]=min(mp[nx],ny);
			if(x!=2){
				nx=x/2+1;ny=d*abs(nx*2-x)+y+a;
				if(mp[nx]==0) mp[nx]=ny;
				else mp[nx]=min(mp[nx],ny);
			}
			nx=x/3;ny=d*abs(nx*3-x)+y+b;
			if(mp[nx]==0) mp[nx]=ny;
			else mp[nx]=min(mp[nx],ny);
			nx=x/3+1;ny=d*abs(nx*3-x)+y+b;
			if(mp[nx]==0) mp[nx]=ny;
			else mp[nx]=min(mp[nx],ny);
			nx=x/5;ny=d*abs(nx*5-x)+y+c;
			if(mp[nx]==0) mp[nx]=ny;
			else mp[nx]=min(mp[nx],ny);
			nx=x/5+1;ny=d*abs(nx*5-x)+y+c;
			if(mp[nx]==0) mp[nx]=ny;
			else mp[nx]=min(mp[nx],ny);
		}
		cout << ans << '\n';
	}
}

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

int main(){
	long long int n,minn=1e18;
	cin>>n;
	for(long long int i=1;i<=sqrt(n);i++)
		if(!(n%i))
			minn=min(minn,i+n/i);
	cout<<minn-2<<'\n';
}

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

bool check_ATCG(string S, int i) {
	if (S.at(i) == 'A' || S.at(i) == 'T' || S.at(i) == 'C' || S.at(i) == 'G') {
		return true;
	} else {
		return false;
	}
}

int main() {
	string S;
	cin >> S;
	int cnt_max = 0;
	for (int i = 0; i < (int)S.size(); i++) {
		int cnt = 0;
		if (!check_ATCG(S, i)) {
			continue;
		}
		for (int j = i; j < (int)S.size(); j++) {
			if (check_ATCG(S, j)) {
				cnt++;
			} else {
				break;
			}
		}
		if (cnt_max < cnt) cnt_max = cnt;
	}

	cout << cnt_max << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;
const int N=2e5+7;
vector<int> adj[N];
ll lazy[N];
ll ans[N];
void dfs(int u,int p){
	ans[u]=lazy[u];
	for(int v:adj[u]) {
		if(v==p) {
			continue;
		}
		lazy[v]+=lazy[u];
		dfs(v,u);
	}
}
int main()
{

	ios_base:: sync_with_stdio(false); cin.tie(0);
	int n; cin>>n;
	int q; cin>>q;
	for(int i=1; i<n; i++) {
		int u,v; cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	for(int i=1; i<=q; i++) {
		int p,x;
		cin>>p>>x;
		lazy[p]+=x;
	}
	dfs(1,0);
	for(int i=1; i<=n; i++) {
		cout<<ans[i]<<" ";
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 25856
#include <iostream>
#include <string>
#include <set>
using namespace std;

int main()
{
    std::set<std::string> a;
    int N;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        string s;
        cin >> s;
        a.insert(std::move(s));
    }

    cout << a.size() << endl;
}

Measured memory_bytes: 19256
import sys

n = int(input())

result = []
k = 26
i = 1

while k < n:
	n -= k
	k *= 26
	i += 1

length = i
n -= 1

result = []

pow26 = 26 ** (length - 1)
for i in range(length):
	letter = n // pow26 
	result.append(chr(ord('a') + letter))
	n = n % pow26
	pow26 //= 26

print("".join(result))

Measured memory_bytes: 8988
#include<stdio.h>
int main(){
  int n,i,j,k,min,mi,a,b,m;
  int d[101][101]={0};
  int c[101][101]={0};
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d",&a,&m);
    while(m--){
      scanf("%d",&b);
      d[a][b]=1;
    }
  }
  for(i=1;i<=n;i++){
    c[mi=i][i]=0;
    int f[101]={0};
    for(j=0;j<n;j++){
      f[mi]=1;
      for(k=1;k<=n;k++){
	if(f[k]||d[mi][k]==0)continue;
	if(c[i][k]==0||c[i][k]>c[i][mi]+1)c[i][k]=c[i][mi]+1;
      }
      min=2100000000;
      for(k=1;k<=n;k++){
	if(f[k]||c[i][k]==0)continue;
	if(min>c[i][k])min=c[i][mi=k];
      }
    }
    //for(j=0;j<n;j++)printf("%d ",c[i][j+1]);printf("\n");
  }
  scanf("%d",&m);
  while(m--){
    scanf("%d %d %d",&a,&b,&k);
    if(c[a][b]<k&&c[a][b])printf("%d\n",c[a][b]+1);
    else                  printf("NA\n");
  }
  return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    int s = 0;
    rep(i,N) {
        cin >> A[i];
        s += A[i];
    }
    int d = s/N;
    int cost1 = 0;
    rep(i,N){
        cost1 += (A[i]-d)*(A[i]-d);
    }
    int cost2 = 0;
    d++;
    rep(i,N){
        cost2 += (A[i]-d)*(A[i]-d);
    }
    cout << min(cost1,cost2) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
    string S, T;
    cin>>S>>T;
    reverse(S.begin(), S.end());
    reverse(T.begin(), T.end());
    bool can = false;
    bool tmpcan;
    if(S.size()>=T.size()){
        for(int i=0;i<=S.size()-T.size();++i){
            if((S[i]==T[0]) || (S[i]=='?')){
                tmpcan = true;
                for(int j=0;j<T.size();++j){
                    if((S[i+j]!=T[j]) && (S[i+j]!='?')) tmpcan = false;
                }
                if(tmpcan == true){
                    can = true;
                    for(int j=0;j<T.size();++j){
                        S[i+j] = T[j];
                    }
                    break;
                }
            }
        }
    }
    if(can){
        for(int i=0;i<S.size();++i){
            if(S[i]=='?') S[i] = 'a';
        }
        reverse(S.begin(), S.end());
    }
    if(can) cout<<S<<endl;
    else cout<<"UNRESTORABLE"<<endl;
}



Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
	"strconv"
)

func main() {
	// Code for B - 754
	var S string
	fmt.Scanf("%s", &S)
	var min int = 1000
	var number int
	for i := 0; i < len(S)-2; i++ {
		number, _ = strconv.Atoi(S[i : i+3])
		if min > int(math.Abs(float64(number-753))) {
			min = int(math.Abs(float64(number - 753)))
		}

	}

	fmt.Println(min)
}


Measured memory_bytes: 1840
/* Akshat Sharma @akshat98 */
#include <iostream>
#include <bits/stdc++.h>
#define IOS  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define mp   make_pair
#define pb   push_back
#define F    first
#define S    second
#define ll   long long
#define MOD  1000000007
#define MAX  1000000001
#define vi   vector<int>
#define vl   vector<ll>
#define vpi  vector<pair<int,int> >
#define vpl  vector<pair<ll,ll> >
#define rep(i,a,b) for(i=a;i<b;i++)
#define reqp(i,a,b) for(i=a;i<=b;i++)
#define ren for(i=0;i<n;i++)
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef pair<int,int>pii;
typedef pair<ll,ll>pll;


int main()
{
	#ifndef ONLINE_JUDGE
	//freopen("input_file.txt", "r", stdin);
	//freopen("output_file.txt", "w", stdout);
	#endif
	int i,j,k,l,n,test_case,m,r,x;
	test_case=1;
	//cin>>test_case;
	while(test_case--){
		cin>>x;
		cout<<fixed<<setprecision(4)<<3.14159*2*x<<"\n";


	}
	
	return 0;
}

Measured memory_bytes: 3780
/// Updated! https://www.youtube.com/watch?v=U07_n9xGIlM
#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define dbug printf("I am here\n");
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int maxn = 2e5+100;

const ll inf = 1e18;

map< pair < int , int > , vector < int > > mp;

int main()
{
    fast;
    int n;
    cin >> n;
    for(int i = 1; i<=n; i++){
        int f , l;
        l = i%10;
        int d = i;
        while(d >= 10) d/=10;
        f = d;
        mp[{f,l}].push_back(i);
    }
    for(auto v : mp)sort(v.second.begin(),v.second.end());

    ll ans = 0;
    for(auto v : mp){
        int f = v.first.second;
        int l = v.first.first;
        ans += (v.second.size()*mp[{f,l}].size());

//        cout << l << " " << f << endl;
//        vector < int > searc = mp[{f,l}];
//        for(auto d : v.second){
//
//            int lo = 0 , hi = mp[{f,l}].size()-1;
//            ll ad = 0;
//            ll sm = n-d;
//            while(lo <= hi){
//                int mid = (lo + hi)/2;
//                if(searc[mid]<=sm){
//                    ad = mid+1;
//                    lo = mid+1;
//                }
//                else hi = mid - 1;
//            }
//            ans += ad;
//        }
//        cout << endl;
    }
    cout << ans << endl;


}
/*



*/



Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279
 
#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define REP1(i, n) for(ll i = 1; i <= n; i++)
#define REPR1(i, n) for(ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for(ll i = m; i <= n; i++)
const ll INF = LLONG_MAX;
const ull MOD = 1000000007;
#define VEC(type,A,N) vector<type> A(N)
#define VECi(type,A,N,i) vector<type> A(N,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N,vector<type>(M))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N,vector<type>(M,i))
#define ALL(v) v.begin(), v.end()
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
ll gcd(ll a, ll b){
   if (a%b==0)return(b);
   else return(gcd(b, a%b));
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(ll N){
    vector<ll> ret;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ret.push_back(i);
            if (i * i != N) ret.push_back(N / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
int main(){
    ll A,B,N;
    cin>>A>>B>>N;
    
    ll t=min(N,B-1);
    cout<<A*t/B-A*(t/B);
    
    //cout<<fixed<<setprecision(32)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3600
import math
n,d = map(int,input().split(" "))
clist = []

for i in range(n):
    xlist = list(map(int,input().split(" ")))
    clist.append(xlist)

def dis(ylist,zlist):
    distance = 0
    for i in range(d):
        distance += (ylist[i] - zlist[i]) ** 2
    sqdis = math.sqrt(distance)
    return(sqdis)

countdis = 0

for i in range(n-1):
    for j in range(i+1,n):
        if dis(clist[i],clist[j]) % 1 == 0:
            countdis += 1

print(countdis)

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int main() {
string S;
cin >> S;
if (S.at(2) == S.at(3) && S.at(4) == S.at(5)) cout << "Yes" << endl;
else cout << "No" << endl;


return 0;
}

Measured memory_bytes: 256
let draw h w =
  let rec draw' h w isSharp =
    match h with
    |0 -> print_string "\n"
    |_ -> let rec draw_dot_s w isSharp=
            match w with
            |0 -> print_string "\n";
            |_ -> if isSharp then print_string "#"
                  else print_string ".";
                  draw_dot_s (w-1) (not isSharp)
          in
          draw_dot_s w isSharp;
          draw' (h-1) w (not isSharp)
  in
  draw' h w true
;;

let rec loop ()=
  Scanf.sscanf (read_line()) "%d %d" (fun h w -> if h = 0 || w = 0 then ()
                                                 else begin
                                                     draw h w;
                                                     loop()
                                                   end
    )
;;

loop ();;


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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
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 { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(){
    int n, k;
    cin >> n >> k;
    mint ans = 0;
    for (int i=k; i<=n+1; ++i) {
        ll a = ll(i) * (i - 1) / 2;
        ll b1 = ll(n) * (n + 1) / 2, b2 = (ll)(n-i) * (n-i+1) / 2;
        ll b = b1 - b2;
        ans += b - a + 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
h = int(input())
w = int(input())
n = int(input())

c = 0
count = 0
while(True):
    c += max(h,w)
    count += 1
    if c>=n:
        break
    if h >= w:
        w -= 1
    else:
        h -= 1
        
print(count)

Measured memory_bytes: 38384
a[100],v,j,n;p(){for(v=0;v<n;printf("%d%s",a[v++],v-n+1?" ":"\n"));}main(i){for(scanf("%d",&n);j<n;scanf("%d",a+j++));for(p();i<n;a[j+1]=v,p())for(j=i-1,v=a[i++];a[j]>v;a[j+1]=a[j--]);exit(0);}

Measured memory_bytes: 600
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int p[1000000];
int cnt[1000000];

int main()
{
  fill(p, p + 1000000, 1);
  p[0] = p[1] = 0;
  for(int i=2;i<1000000;i++)
    for(int j=i*2;j<1000000;j+=i)
      p[j] = 0;

  for(int i=1;i<1000000;i++)
    cnt[i] = cnt[i-1] + p[i];

  int n;
  while(scanf("%d", &n) != -1)
    printf("%d\n", cnt[n]);

  return 0;
}  

Measured memory_bytes: 8836
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int h,w;
vector<pair<long long,int> >a;
main()
{
	cin>>h>>w;
	for(int i=0;i<h;i++)
	{
		long long x;cin>>x;
		a.push_back(make_pair(x,i));
	}
	for(int i=0;i<w;i++)
	{
		long long x;cin>>x;
		a.push_back(make_pair(x,h+i));
	}
	sort(a.begin(),a.end());
	long long ans=0;
	int cnth=h,cntw=w;
	for(int i=0;i<a.size();i++)
	{
		ans+=a[i].first*(a[i].second<h?cntw:cnth);
		(a[i].second<h?cnth:cntw)--;
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 6996
def insertSort(input_list):
    print(' '.join([str(i) for i in input_list]))
    for i in range(1, len(input_list)):
        tmp = input_list[i]
        j = i - 1

        while j >= 0 and input_list[j] > tmp:
            input_list[j + 1] = input_list[j]
            j -= 1
            input_list[j + 1] = tmp

        print(' '.join([str(i) for i in input_list]))


if __name__ == '__main__':
    N = int(input())

    L = input()
    input_list = [int(i) for i in L.split()]
    insertSort(input_list)



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

using namespace std;

int n,m,s1,s2,cnt[30];
char s[120];

int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++){
		scanf("%s",s+1);
		for (int j=1;j<=m;j++)
			cnt[s[j]-'a']++;
	}
	if ((n&1) && (m&1)) s1++;
	if (n&1) s2+=m/2;
	if (m&1) s2+=n/2;
	for (int i=0;i<26;i++)
		if (cnt[i]%4!=0){
			if (cnt[i]%2!=0) s1--;
			else s2--;
		}
	if (s1>=0 && s2>=0) puts("Yes");
	else puts("No");
	
	return 0;
}
			

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use std::collections::VecDeque;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn solve(seq: &Vec<i32>, k: usize, q: usize, min_value: i32, max_value: i32) -> bool {
    let n = seq.len();
    let mut que = VecDeque::<usize>::new();
    let mut use_flags = vec![false; n];
    let mut l = 0;
    let mut cnt = 0;
    let mut small_value = 0;
    let mut large_value = 0;
    let mut ans = 0;
    for i in 0..n {
        cnt += 1;
        if seq[i] < min_value {
            small_value += 1;
        } else if max_value < seq[i] {
            large_value += 1;
        } else {
            que.push_back(i);
        }
        while cnt > k {
            let v = seq[l];
            if v < min_value {
                small_value -= 1;
                cnt -= 1;
            } else if max_value < v {
                large_value -= 1;
                cnt -= 1;
            } else if !use_flags[l] {
                que.pop_front();
                cnt -= 1;
            }
            l += 1;
        }
        if cnt == k && small_value == 0 && large_value != k {
            let index = que.pop_front().unwrap();
            use_flags[index] = true;
            cnt -= 1;
            ans += 1;
            if ans == q {
                return true;
            }
        }
    }
    return false;
}

fn main() {
    let n = read::<usize>();
    let k = read::<usize>();
    let q = read::<usize>();
    let mut seq = vec![0; n];
    for i in 0..n {
        seq[i] = read::<i32>();
    }
    let mut ans = 1e+9 as i32;
    for i in 0..n {
        let min_value = seq[i];
        let mut left = -1;
        let mut right = ans;
        while right - left > 1 {
            let mid = (left + right) / 2;
            if solve(&seq, k, q, min_value, min_value + mid) {
                right = mid;
            } else {
                left = mid;
            }
        }
        ans = right;
    }
    println!("{}", ans);
}


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

int main()
{


   int a;
   cin>>a;
   string s;
   set <string> p;
   for(int i=0;i<a;i++)
   {
       cin>>s;
       p.insert(s);

   }

   cout<<p.size();














}


Measured memory_bytes: 19212
def gcd(x, y):
    return gcd(y, x%y) if y else x

def printV(x, y):
    g = gcd(x, y)
    print(str(x//g) + "/" +  str(y//g))

S = input()
all = ""
sub = ""
p = -1

for i in range(len(S)):
    if S[i] == '.':
        o = i
    elif S[i] == '(':
        p = i
        sub = all
    elif S[i] != ')':
        all += S[i]

d = len(S) - o - 1
l = p - o - 1
if p == -1:
    printV(int(all), 10**d)
else:
    d -= 2 # for ()
    printV(int(all) - int(sub), 10**d - 10**l)



Measured memory_bytes: 5600
// from alphaGem
//cheat?
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
using namespace std;
long long a[444444];
struct p{long long x,c;inline bool operator<(const p b)const{return x<b.x;}};
priority_queue<p>q;
long long op[444444];
int cp;
long long res[444444];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)scanf("%lld",&a[i]);
	long long mi=2333333333333333333ll;
	for(int i=m;i;i--)if(a[i]<mi)mi=op[++cp]=a[i];
	if(n<mi)mi=op[++cp]=n;
	q.push((p){op[1],1});
	for(int i=2;i<=cp;i++)
	{
		long long cnow=0;
		for(;q.top().x>op[i];q.pop())
		{
			cnow+=q.top().x/op[i]*q.top().c;
			q.push((p){q.top().x%op[i],q.top().c});
		}
		q.push((p){op[i],cnow});
	}
	for(;!q.empty();q.pop())res[q.top().x]+=q.top().c;
	for(int i=n;i;i--)res[i-1]+=res[i];
	for(int i=1;i<=n;i++)printf("%lld\n",res[i]);
	return 0;
}

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

int main(){
	int n=0;
	cin >> n;
	string str1,str2;
	cin >> str1 >> str2;
	string::iterator it,it2;

	for(it=str1.begin(),it2=str2.begin();it2!=str2.end();++it,++it2){
			cout << *it << *it2;

	}


}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  cout << max(0,min(d,b) - max(c,a)) << endl;
  return 0;
}


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


void solve(long long N, long long M, long long C, std::vector<long long> B, std::vector<std::vector<long long>> A){
    long long cnt = 0;
    long long ans = 0;
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < M; ++j){
            ans = ans + A.at(i).at(j) * B.at(j);
        }
        ans = ans + C;
        if(ans > 0){
            cnt++;
        }
        ans = 0;
    }
    cout << cnt << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    long long C;
    scanf("%lld",&C);
    std::vector<long long> B(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&B[i]);
    }
    std::vector<std::vector<long long>> A(N, std::vector<long long>(M));
    for(int i = 0 ; i < N ; i++){
        for(int j = 0 ; j < M ; j++){
            scanf("%lld",&A[i][j]);
        }
    }
    solve(N, M, C, std::move(B), std::move(A));
    return 0;
}


Measured memory_bytes: 256
/* "miles to go before I sleep." */


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

typedef long long ll;
#define mod 1000000007
#define pi  3.14159265358979323846
#define pb push_back
#define mk make_pair
#define popcnt(a) _Generic((a), int: __builtin_popcount(a), \  long long: __builtin_popcountll(a))  
#define precise(x) cout<<fixed<<setprecision(10)<<x
#define test cout<<"#";
#define input freopen("input.txt", "r", stdin)
#define output freopen("output.txt", "w", stdout) 

const ll inf = 1e18L + 2;

double dp[3001][3001];

double solve(vector<double> &v, ll n, ll x)
{
    if(x == 0)
        return 1;
    if(n == 0)
        return 0;
    if(dp[n][x] >= -0.9)
        return dp[n][x];
    return dp[n][x] = solve(v, n-1, x-1)*v[n-1] + solve(v, n-1, x)*(1 - v[n-1]);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    vector<double> v(n);
    for(ll x = 0; x < n; x++)
        cin>>v[x];
    memset(dp, -1, sizeof(dp));
    precise(solve(v, n, (n+2)/2));
}

Measured memory_bytes: 74404
fun main(arr:Array<String>) {
    val (m,d) = readLine()!!.split(" ").map { it.toInt() }
    val target = (1..m).map {m-> (22..d).map { listOf(it / 10, it % 10) }.filter { it[0]*it[1] == m && it.all { b->b>=2 } }.count() }
    val ans = target.sum()
    println(ans)
}

Measured memory_bytes: 35892
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
#define N 100005
struct node{
	int p;
	int y;
	int order;
	int index;
	bool operator<(const node& n) const{
		if( p==n.p )
			return y<n.y;
		return p<n.p;
	}
}c[N];
bool cmp(const node& n1,const node& n2){
	return n1.index<n2.index;
}
int main(){
	int n,m,i,j;
	scanf("%d%d",&n,&m);
	for( i=0;i<m;i++ )
	{
		scanf("%d%d",&c[i].p,&c[i].y);
		c[i].index = i+1;
	}	
	sort(c,c+m);
	int tmp=1;
	for( i=0;i<m;i++ )
	{
		if( i!=0 && c[i].p>c[i-1].p )
		{
			tmp = 1;	
		}
		c[i].order=tmp++;
	}
	sort(c,c+m,cmp);
	int f[6],l[6];
	for( i=0;i<m;i++ )
	{
		int fi=c[i].p,la=c[i].order;
		for( j=5;j>=0;j-- )
		{
			f[j]=fi%10;
			fi/=10;
		}
		for( j=5;j>=0;j-- )
		{
			l[j]=la%10;
			la/=10;
		}
		for( j=0;j<6;j++ )
		{
			printf("%d",f[j]);
		}
		for( j=0;j<6;j++ )
		{
			printf("%d",l[j]);
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 3072
h,w=map(int,input().split())
s=[ input() for _ in range(h)]
ans=[ [0]*w for _ in range(h)]
#print(ans)
for i in range(h):
    for j in range(w):
        if s[i][j]=='#':
            ans[i][j]='#'
        else:
            cnt=0
            for ii in [-1,0,1]:
                for jj in [-1,0,1]:
                    def chk(a,b):
                        if a>=0 and a<h and b>=0 and b<w:
                            return True
                        else:
                            return False
                    if chk(i+ii,j+jj):
                        if s[i+ii][j+jj]=='#':
                            cnt+=1
            ans[i][j]=cnt
for i in range(h):
    print(''.join(list(map(str,ans[i]))))



Measured memory_bytes: 3064
from sys import stdin
import sys
 
A, B, N = [int(x) for x in stdin.readline().rstrip().split()]
# N, M = [int(x) for x in stdin.readline().rstrip().split()]
# U = input().split()
ans = int((A*N)/B)-A*int(N/B)
ans2=0
if B-1<N:
	ans = int((A*(B-1))/B)-A*int((B-1)/B)
else:
  	ans2=0
    
 
 
print(ans)

Measured memory_bytes: 61916
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll h, w; cin >> h >> w;
    vector<string> a(h+2);
    a[0] = string(w+2, '#');
    a[h+1] = string(w+2, '#');

    rep(i, h){
        string t; cin >> t;
        a[i+1] = "#" + t + "#";
    }

    for(auto p: a) cout << p << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
input=sys.stdin.readline

mod=10**9+7
n=int(input())
arr=list(map(int,input().split()))
ans=sum(arr)*sum(arr)
for val in arr:
    ans-=(val*val)%mod
print((ans*pow(2,-1,mod))%mod)

Measured memory_bytes: 31392
a=raw_input()
list=a.split()
W=int(list[0])
H=int(list[1])
x=int(list[2])
y=int(list[3])
r=int(list[4])
if r<=x<=W-r and r<=y<=H-r:
	print 'Yes'
else:
	print 'No'

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())
#define all(a) (a).begin(), (a).end()

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

//print
#define pv(val) cerr << #val << '=' << (val) << endl

const int INF = 1e9;

int main(void){

	vector<int> x(5);
	REP(i,5){
		cin >> x[i];
	}

	REP(i,5){
		if(x[i] == 0) cout << i+1 << endl;
	}


	return 0;

}


Measured memory_bytes: 3624