akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;

}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x) 
{
    return (ll)(log(x) / log(base));
}
ll lcm(ll x,ll y)
{
	return (x*y)/__gcd(x,y);
}
ll cc(ll a,ll b,ll c)
{
	return (b/c)-((a-1)/c);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
    while(TESTS--)
    {
    	ll j,l,m,h,w,f,n,k,b,t,i,ans,gap,limit,l1;
    	cin>>n>>k;
    	if(k<=((n-1)*(n-2))/2)
    	{
    		l=(((n-1)*(n-2))/2)-k;
    		ans=n-1+l;
    		cout<<ans<<'\n';
    		j=1;
    		rep(i,0,n-1)
    		cout<<n<<" "<<(j++)<<'\n';
    		gap=1; limit=n-2; j=2; l1=0;
    		while(l)
    		{
    			repi(i,1,n-2)
    			{
    				repi(j,i+1,n-1)
    				{
    					cout<<i<<" "<<j<<'\n';
    					l--;
    					if(l==0)
    					break;
					}
					if(l==0)
					break;
				}
			}
		}
		else
		cout<<-1;
    }
	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int r = sc.nextInt();
		int D = sc.nextInt();
		long x = sc.nextInt();
		for (int i = 0; i < 10; i++) {
			x = r * x - D;
			System.out.println(x);
		}
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 21204
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

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

	int n,m;
	cin>>n>>m;
	vs in(n);
	rep(i,n)cin>>in[i];

	vvi a(n+2,vi(m+2));
	rep(i,n)rep(j,m)if(in[i][j]-'#')a[i+1][j+1]=a[i+1][j]+1;
	vvi b(n+2,vi(m+2));
	rep(i,n)rep(j,m)if(in[i][j]-'#')b[i+1][j+1]=b[i][j+1]+1;
	vvi c(n+2,vi(m+2));
	rep(i,n)rep(j,m)if(in[n-i-1][m-j-1]-'#')c[n-i][m-j]=c[n-i][m-j+1]+1;
	vvi d(n+2,vi(m+2));
	rep(i,n)rep(j,m)if(in[n-i-1][m-j-1]-'#')d[n-i][m-j]=d[n-i+1][m-j]+1;

	int out=0;
	rep(i,n)rep(j,m)cmax(out,a[i+1][j+1]+b[i+1][j+1]+c[i+1][j+1]+d[i+1][j+1]-3);
	cout<<out<<endl;
}


Measured memory_bytes: 130048
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
int main()
{
	int n,k,d,i,j;
	cin>>n>>k;
	int a[n+1]={0};
	while(k--)
	{
		cin>>d;
		for(i=0;i<d;i++)
		{
			cin>>j;
			a[j]++;
		}
	}
	j=0;
	for(i=1;i<=n;i++)
	{
		if(a[i]==0)
		{
			j++;
		}
	}
	cout<<j;
	return 0;
}

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

using namespace std;

typedef long long int ll;

ll dp[3010][3010];

int main()
{
    int n, a[3010];

    cin >> n;

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


    for (int i = n; i >= 1; i--)
    {
        for (int j = i; j <= n; j++)
        {
            dp[i][j] = max(a[i] - dp[i+1][j],
                           a[j] - dp[i][j-1]);
        }
    }

    cout << dp[1][n] << "\n";

    return 0;
}



Measured memory_bytes: 70016
var toInt = x=>parseInt(x,10);
var toIntArr = arr=>arr.map(x=>toInt(x));
var abs = x=>x>0?x:-x;
function min(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]<val)val = rest[i];return val}
function max(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]>val)val = rest[i];return val}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
 
function Main(input){
	var input = input.split('\n');
	var n = toInt(input[0]);

	for(var i = 0; i < 26; i++){
		for(var j = 0; j < 15; j++){
			if(4*i + 7*j === n){
				console.log('Yes');
				return 0;
			}
		}
	}
	console.log('No');

}

Measured memory_bytes: 21064
#include <bits/stdc++.h>
using namespace std;
int n;
const long long D=1e9+7;
long long gcd(long long x,long long y){
    if(y==0)return x;
    return gcd(y,x%y);
}
long long ans=0;
long long P;
long long s[200005];
long long t[200005];
long long check[200005];
char a[200005];
int main(){

    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>n>>P;
    int i;
    cin>>a+1;
    for(i=1 ; i<=n ; i++)a[i]-='0';
    if(P==2){
        for(i=1 ; i<=n ; i++){
            if(a[i]%2==0)ans+=i;
        }
    }
    else if(P==5){
        for(i=1 ; i<=n ; i++)
            if(a[i]==5 || a[i]==0)ans+=i;

    }
    else{
        t[n]=1;
        for(i=n-1; i>=1 ; i--){
            t[i]=t[i+1]*10%P;
        }
        for(i=1 ;i<=n ; i++){
            s[i]=(s[i-1]+t[i]*a[i])%P;
            check[s[i]]++;
        }
        check[0]++;
        for(i=0 ; i<P ; i++)
            ans+=check[i]*(check[i]-1)/2;

    }


    cout<<ans;
    return 0;
}


Measured memory_bytes: 3712
n, x = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
t = 0
for i in range(n):
    if t <= x:
        ans += 1
    else:
        break
    t += l[i]
else:
    if t <= x:
        ans += 1

print(ans)

Measured memory_bytes: 3064
fun main(args: Array<String>) {
    val (A, B) = readInputLine().split(" ").map { it.toInt() }
    val Amin = (A * 100 + 7) / 8
    val Amax = 100 * (A + 1) / 8
    val Bmin = B * 10
    val Bmax = (B + 1) * 10

    if (Amin in Bmin until Bmax) {
        println(Amin)
        return
    }
    if (Bmin in Amin until Amax) {
        println(Bmin)
        return
    }
    println(-1)
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 38004
def divisor(n):
    ass = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            if i**2 == n:
                continue
            ass.append(n//i)
            if i == 1:
                continue
            ass.append(i)
    ass.sort()
    return ass #sortされていない

def check(n,k):
    while n > k:
        if n % k == 0:
            n //= k
        else:
            n -= k

    if n % k == 0:
        return True
    elif n - k == 1:
        return True
    else:
        return False


def main():
    N = int(input())
    if N == 2:
        print(1)
        exit()
    div = divisor(N-1)
    ans = [N] + div
    for i in range(1,int(N**0.5)+1):
        if i in div:
            continue
        tmp = int(N)
        if i == 1:
            continue
        if N % i == 0:
            while tmp % i == 0:
                tmp //= i
            if tmp % i == 1:
                ans.append(i)
        elif N % i == 1:
            ans.append(i)
        else:
            tmp -= i + 1
            if tmp % i == 0:
                ans.append(i)
    print(len(ans))




    


if __name__ == "__main__":
    main()

Measured memory_bytes: 39792
#!venv/bin/python
 
import math
import numpy as np
import random
import copy
import statistics 
import bisect
import heapq
from collections import defaultdict 
import time
import sys
from pprint import pprint
import itertools

N, L = [ int(x) for x in input().split() ]
#B = [ int(x) for x in input().split() ]

min_abs = 1000
eat_d = None
sum = 0
for i in range(N):
    d = L + i
    sum += d
    if min_abs > d:
        min_abs = abs(d)
        eat_d = d
print(sum - eat_d)



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

using namespace std;

using ll = long long;

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

    int w, h, n;
    cin >> w >> h >> n;

    vector<vector<bool>> rect(h, vector<bool>(w, false));
    for (int i = 0; i < n; ++i) {
        int x, y, a;
        cin >> x >> y >> a;
        if (a == 1) {
            for (int i = 0; i < h; ++i)
                for (int j = 0; j < x; ++j)
                    rect[i][j] = true;
        }
        else if (a == 2) {
            for (int i = 0; i < h; ++i)
                for (int j = x; j < w; ++j)
                    rect[i][j] = true;
        }
        else if (a == 3) {
            for (int i = 0; i < y; ++i)
                for (int j = 0; j < w; ++j)
                    rect[i][j] = true;
        }
        else if (a == 4) {
            for (int i = y; i < h; ++i)
                for (int j = 0; j < w; ++j)
                    rect[i][j] = true;
        }
    }

    int area = 0;
    for (int i = 0; i < h; ++i)
        for (int j = 0; j < w; ++j)
            if (rect[i][j]) ++area;

    cout << h * w - area << endl;

    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

c = 0.0001
while True:
    try:
        a = list(map(int,input().split()))
        b1 = a[0]*a[4]-a[3]*a[1]
        b2 = a[2]*a[4]-a[5]*a[1]
        b3 = a[0]*a[5]-a[3]*a[2]
        print("{0:.3f} {1:.3f}" .format(b2/b1 + c, b3/b1 + c))
    except EOFError:
        break


Measured memory_bytes: 5620
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
	public static void main(String[] args) throws Exception {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      String line1 = br.readLine();
      String str[] = line1.split(" ");
      int n = Integer.parseInt(str[0]),x = Integer.parseInt(str[1]);
      
      String line2 = br.readLine();
      String str2[] = line2.split(" ");
      long[] candyList = new long[n];  
      for(int i =0;i<n;i++){
         candyList[i] = Integer.parseInt(str2[i]);     
      }
      long count=0;
      if(candyList[0]>x){
        count = candyList[0]-x;
        candyList[0]=x;
      }
      for(int i=0;i<n-1;i++){
        long candyNum = candyList[i]+candyList[i+1];
        if(candyNum>x){
          count = count + (candyNum-x);
          candyList[i+1]=(candyList[i+1]-(candyNum-x));
        }
      }
       System.out.println(count); 
	}
}

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

char field[1005][1005];

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


int main(){
	int H,W;
	cin >> H >> W;
	
	rep(i,H){
		rep(j,W){
			cin >> field[i][j];
		}
	}
	
	queue<pair<int,int>> que;
	
	int dist[1005][1005];
	
	rep(i,H){
		rep(j,W){
			dist[i][j] = -1;
		}
	}
	//まず黒いマスを全部queにいれる。
	rep(i,H){
		rep(j,W){
			if(field[i][j] == '#'){
				que.push(make_pair(i,j));
				dist[i][j] = 0;
			}
		}
	}
	
	int count = 0;
	
	while(!que.empty()){
		pair<int,int> p = que.front();
		que.pop();
		
		rep(i,4){
			int ny = p.first + dy[i];
			int nx = p.second + dx[i];
			
			//fieldからはみ出たら飛ばす
			if(ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
			//訪問済だったら飛ばす
			if(dist[ny][nx] != -1) continue;
			if(field[ny][nx] == '.'){
				que.push(make_pair(ny,nx));
				dist[ny][nx] = dist[p.first][p.second] + 1;
			}
		}
	}
	
	int ans = dist[0][0];
	
	rep(i,H){
		rep(j,W){
			ans = max(ans, dist[i][j]);
		}
	}
	
	cout << ans << endl;
	
	
	
}



Measured memory_bytes: 13328
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.math.*;

public class Main {
	static BitSet[] b;
	static int n;

	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		int n = Integer.parseInt(br.readLine());
		String[] str = br.readLine().split(" ");
		int[] l = new int [2*n];
		for(int i = 0; i < 2*n; i++){
			l[i] = Integer.parseInt(str[i]);
		}
		Arrays.sort(l);
		int sum = 0;
		for(int i = 0; i < 2*n; i+=2){
			sum += l[i];
		}
		sb.append(sum);
		System.out.println(sb);
	}
}

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

int main() {
    string S;
    bool flag = true;
    cin >> S;
    int n = S.length();
    for (int i = 0; i < n-1; i++) {
        for (int j = i+1; j < n; j++) {
            if (S[i] == S[j]) {
                flag = false;
                break;
            }
        }
    }
    if (flag) cout << "yes" << endl;
    else cout << "no" << endl;
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  int ans;
  if(s == "SUN") ans = 7;
  else if(s == "MON") ans = 6;
  else if(s == "TUE") ans = 5;
  else if(s == "WED") ans = 4;
  else if(s == "THU") ans = 3;
  else if(s == "FRI") ans = 2;
  else ans = 1;
  
  cout << ans << endl;
  
  return 0;
}


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

int main() {
long long int a;
cin>>a;
long long int b=(a*(a+1))/2;
long long int sum=0,k;
for(long long int i=0;i<a;i++){
cin>>k;
sum+=k;
}
cout<<sum-b<<endl;
}



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

int main() {

	ll n, k;
	cin >> n >> k;

	vector<ll> A(n, 0);
	ll sum = 0;

	for (ll i = 0; i < n; i++) {
		cin >> A[i];
		sum = sum + A[i];
	}

	vector<ll> fact;

	for (ll i = 1; i <= sqrt(sum); i++) {
		if (i*i == sum)
			fact.push_back(i);
		else if (sum%i == 0) {
			fact.push_back(i);
			fact.push_back(sum / i);
		}
	}

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

	vector<pair<ll, ll> > diff(n);
	bool flag = 0;
	ll res = 1;
	for (ll i = fact.size() - 1; i >= 0; i--)
	{
		ll f = fact[i];
		for (ll j = 0; j < n; j++) {
			ll a = A[j] % f;
			diff[j] = { a,f - a };
		}
		sort(diff.begin(), diff.end());
		vector<ll> left(n, 0);
		for (ll j = 0; j < n; j++) {
			left[j] = (j - 1 >= 0 ? left[j - 1] : 0) + diff[j].first;
		}
		vector<ll> right(n, 0);
		for (ll j = n - 1; j >= 0; j--) {
			right[j] = (j + 1 < n ? right[j + 1] : 0) + diff[j].second;
		}
		for (ll j = 0; j < n - 1; j++) {
			if (left[j] == right[j + 1]) {
				if (left[j] <= k) {
					res = f;
					flag = 1;

					cout << f << endl;
					return 0;

				}
			}
		}
		if (flag) break;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
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;
using ll = long long;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n+1), b(n);
    rep(i, n+1) cin >> a[i];
    rep(i, n) cin >> b[i];

    ll ans = 0;
    rep(i, n){
        ans += (b[i] <= a[i]) ? b[i] : a[i];
        b[i] -= (b[i] <= a[i]) ? b[i] : a[i];
        if(b[i] <= 0) continue;
        ans += (b[i] <= a[i+1]) ? b[i] : a[i+1];
        a[i+1] -= (b[i] <= a[i+1]) ? b[i] : a[i+1];
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
#import pprint
w,h,n=map(int,input().split())
x=[]
y=[]
a=[]
for i in range(n):
    xi,yi,ai=map(int,input().split())
    x.append(xi)
    y.append(yi)
    a.append(ai)

dot = [[0] * w for i in range(h)]
#pprint.pprint(dot,width=60)

for i in range(n):
    if a[i] == 1:
        for j in range(x[i]):
            for k in range(h):
                dot[k][j]=1
    if a[i] == 2:
        for j in range(x[i],w):
            for k in range(h):
                dot[k][j]=1
    if a[i] == 3:
        for j in range(y[i]):
            for k in range(w):
                dot[j][k]=1
    if a[i] == 4:
        for j in range(y[i],h):
            for k in range(w):
                dot[j][k]=1
    #pprint.pprint(dot,width=60)

print(sum(dot,[]).count(0))


Measured memory_bytes: 3408
import sys
input = sys.stdin.readline
N,Q = map(int,input().split())
AB = [[] for _ in range(N-1)]
for n in range(N-1):
    AB[n] = list(map(int,input().split()))
PX = [[] for _ in range(Q)]
for q in range(Q):
    PX[q] = list(map(int,input().split()))
graph = [[] for _ in range(N+1)]
for ab in AB:
    graph[ab[0]].append(ab[1])
    graph[ab[1]].append(ab[0])
val = [0] * (N+1)
for px in PX:
    val[px[0]] += px[1]
parent = [0] * (N+1)
Q  = [1]
while Q:
    q = Q.pop()
    for c in graph[q]:
        if c == parent[q]:
            continue
        parent[c] = q
        Q.append(c)
        val[c] += val[q]
print(*val[1:])


Measured memory_bytes: 130196
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


int main() {
    ll a,b;
    cin >> a >> b;

    // a or b == 0
    if ( (a * b) == 0 ) {
        cout << "Zero" << endl;
        return 0;
    }

    // contains 0
    if ( (a*b) < 0 ) {
        cout<< "Zero" << endl;
        return 0;
    }

    // all plus
    if ( a > 0) {
        cout << "Positive" << endl;
        return 0;
    }

    ll dist = abs(a-b);
    if (dist %2 == 0) {
        cout << "Negative" << endl;
        return 0;
    }

    cout << "Positive" << endl;


    return 0;
}


Measured memory_bytes: 256
n, a, b = gets.split.map(&:to_i)
xs = gets.split.map(&:to_i)

ans = 0
(0..n-2).each do |i|
  t = (xs[i+1]-xs[i]) * a
  if t < b
    ans += t
  else
    ans += b
  end
end
puts ans

Measured memory_bytes: 8452
import java.io.*;
import java.util.*;
public class Main {
	static char[][] arr;
	static int n,m;
	static int dn,dm,cn,cm;
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int t=1;//sc.nextInt();
		while(t-->0) {
			n=sc.nextInt();m=sc.nextInt();
			cn=sc.nextInt();cm=sc.nextInt();
			dn=sc.nextInt();dm=sc.nextInt();
			dn--;cn--;dm--;cm--;
			arr=new char[n][m];
			for(int i=0;i<n;i++) {
				arr[i]=sc.next().toCharArray();
			}
			LinkedList<Integer> xqu=new LinkedList<>();
			LinkedList<Integer> yqu=new LinkedList<>();
			xqu.add(cn);yqu.add(cm);
			int[][] dist=new int[n][m];
			//System.out.println(dist.length);
			for(int i=0;i<n;i++) {
				Arrays.fill(dist[i], Integer.MAX_VALUE);
			}
			dist[cn][cm]=0;
			while(xqu.size()>0) {
				int x=xqu.pollFirst();
				int y=yqu.pollFirst();
				int[][] dr= {{0,1},{0,-1},{1,0},{-1,0}};
				for(int[] d:dr) {
					int nx=x+d[0];int ny=y+d[1];
					if(!islegal(nx,ny)) continue;
					if(dist[nx][ny]>dist[x][y]) {
						dist[nx][ny]=dist[x][y];
						xqu.addFirst(nx);
						yqu.addFirst(ny);
					}
				}
				for(int i=x-2;i<=x+2;i++) {
					for(int j=y-2;j<=y+2;j++) {
						int nx=i;int ny=j;
						if(!islegal(nx,ny)) continue;
						
						if(dist[nx][ny]>dist[x][y]+1) {
							dist[nx][ny]=dist[x][y]+1;
							xqu.addLast(nx);
							yqu.addLast(ny);
						}
					}
				}
			}
			System.out.println(dist[dn][dm]==Integer.MAX_VALUE? -1:dist[dn][dm]);
		}

	}
	static boolean islegal(int x,int y) {
		if(x<0 || y<0 ||x>=n || y>=m) return false;
		if(arr[x][y]=='#') return false;
		return true;
	}
	static class node{
		int x,y,k;
		node(int x,int y){
			this.x=x;this.y=y;
			this.k=0;
		}
	}

}
/*class Reader{
	BufferedReader reader;
	Reader(){
		reader=new BufferedReader(new InputStreamReader(System.in));
	}
	int nextInt() throws IOException{
		String in=reader.readLine().trim();
		return Integer.parseInt(in);
	}
	long nextLong() throws IOException{
		String in=reader.readLine().trim();
		return Long.parseLong(in);
	}
	String next() throws IOException{
		return reader.readLine().trim();
	}
	String[] stringArray() throws IOException{
		return reader.readLine().trim().split("\\s+");
	}
	int[] intArray() throws IOException{
		String[] inp=this.stringArray();
		int[] arr=new int[inp.length];
		int i=0;
		for(String s:inp) {
			arr[i++]=Integer.parseInt(s);
		}
		return arr;
	}
}*/




Measured memory_bytes: 67272
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    ll a,b,c,d=0;
    cin>>a>>b>>c;

    for(int i=1; i<=MAX; i++)
    {
        d+=a;
        if(d%b==c)
        {
            cout<<"YES"<<endl;
            return 0;
        }
    }

    cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 3584
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; } value
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

bool func(string s) {
  string a = s;
  reverse(a.begin(), a.end());
  return a == s;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  bool flag = true;
  if(!func(s)) flag = false;
  if(!func(s.substr(0, s.size() / 2))) flag = false;
  YesorNo(flag);
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static int list[] = new int[26];
	public static void main(String[] args) {
		int cnt = 0;
		Scanner scan = new Scanner(System.in);
		String W = scan.nextLine();
		try{
			while(scan.hasNext()){
				String T = scan.next();
				if(T.equals("END_OF_TEXT")){
					scan.close();
				}else if(W.equalsIgnoreCase(T)){
					cnt++;
				}
			}
		}catch(IllegalStateException e){
			System.out.println(cnt);
		}
	}
}

Measured memory_bytes: 26216
s = list(input())
al = [0]*(len(s)+1)

for i in range(len(s)):
    if s[i] == '<':
        al[i+1] = max(al[i]+1, al[i+1])

for i in range(len(s)-1, -1, -1):
    if s[i] == '>':
        al[i] = max(al[i+1]+1, al[i])

print(sum(al))

Measured memory_bytes: 32664
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const int INF=1e9;
vector<int> h,cost;

int main(){
    int n;
    cin>>n;
    h=cost=vector<int>(n,INF);
    rep(i,n) cin>>h[i];
    cost[0]=0;
    cost[1]=abs(h[0]-h[1]);
    rep(i,n){
        if(i-1>=0){
            cost[i]=min(abs(h[i]-h[i-1])+cost[i-1],cost[i]);
        }
        if(i-2>=0){
            cost[i]=min(abs(h[i]-h[i-2])+cost[i-2],cost[i]);
        }
    }
    cout<<cost[n-1];
}

Measured memory_bytes: 3920
def test():

	i = list(map(int,input().split()))
	W = i[0]
	H = i[1]
	x = i[2]
	y = i[3]
	r = i[4]

	if x > 0 and y > 0 and (x + r <= W) and (0 <= x + r) and (y + r <= H) and (0 <= y + r):
		print("Yes")
	else:
		print("No")


if __name__ == "__main__":
	test()



Measured memory_bytes: 5600
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
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;}
constexpr int INF = 1e18;

signed main(){
	int N,M;
	cin >> N >> M;
	int flg = 0;
	map<int,int>mp;
	vector<pair<int,int>>ans;
	REP(i,M){
		int l = i,r = N - i - 1 - flg;
		int diff = r - l;
		mp[diff]++;
		if(mp[N - diff] > 0){
			mp[diff]--;
			mp[diff - 1]++;
			flg++;
			ans.emplace_back(l,r - 1);
		}else{
			ans.emplace_back(l,r);
		}
	}
	REP(i,ans.size())out(1+ans[i].first,1+ans[i].second);
}

Measured memory_bytes: 15652
#include <bits/stdc++.h>
#define drep(i,cc,n) for(int i=(cc);i<=(n);++i)
#define rep(i,n) drep(i,0,n-1)
#define drrep(i,cc,n) for(int i=(cc);i>=(n);--i)
#define rrep(i,n) drrep(i,0,n-1)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,v.size())if(i==0)cout << v[i];else cout << " " << v[i]; cout << endl;
#define arrprint(v,n) rep(i,n)if(i==0)cout << v[i];else cout << " " << v[i]; cout << endl;
#define matprint(v,n,m) rep(i,n){rep(j,m){cout << v[i][j] << " ";}cout << endl;}
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
using ll = long long;
using P = pair<int,int>;
template<typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; //小さいものから取り出す

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    SORT(p);
    int ans = 0;
    rep(i,k)ans += p[i];

    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007

using namespace std;

typedef long long ll;


int add(int a, int b)
{
    ll x = a+b;
    if(x >= mod)
        x -= mod;
    if(x < 0)
        x += mod;
    return x;
}
ll mul(ll a, ll b)
{
    return (a*b) % mod;
}

ll pw(ll a, ll b)
{
    ll ans = 1;
    while(b)
    {
        if(b & 1)
            ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k;
    cin >> n >> k;
    int ans = 0;
    for(int i = 1; i <= n; ++i)
    {
        int nr;
        cin >> nr;
        if(nr >= k)
            ++ans;
    }
    cout << ans;
    return 0;
}


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

int main(){
	int A, B;
	cin>>A>>B;
	int koho1;
	if(B>0){
		koho1 = A+B;
	}	else{
		koho1 = A-B;
	}
	if(A*B>koho1){
		koho1 = A*B;
	}	
	cout<<koho1;
	return 0;
}	


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

#define pb push_back
using namespace std;

int n, k, c;

vector<int> calc(string & s) {
    vector<int> ans;
    int n = s.size();
    vector<int> nxt(n+1);

    nxt[n] = n;
    for(int i = n-1; i >= 0; --i) {
        if(s[i] == 'o') nxt[i] = i;
        else nxt[i] = nxt[i+1];
    }

    int cur = 0;
    // vou escolher k bolinhas
    for(int i = 0; i < k; ++i) {
        assert(cur < n);
        cur = nxt[cur];
        ans.pb(cur);
        cur = cur + c + 1;
    }

    return ans;
}

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

    cin >> n >> k >> c >> s;

    vector<int> pos1 = calc(s);
    reverse(s.begin(), s.end());
    vector<int> pos2 = calc(s);


    reverse(s.begin(), s.end());
    vector<int> nxt(n+1);

    nxt[n] = n;
    for(int i = n-1; i >= 0; --i) {
        if(s[i] == 'o') nxt[i] = i;
        else nxt[i] = nxt[i+1];
    }

    for(int i = 0; i < k; ++i) {
        int x = pos1[i];
        //cout << pos2[k - (i+1) - 1] << endl;
        if(i + 1 < k and n - 1 - pos2[k - (i+1) - 1] <= nxt[x+1] + c) {
            cout << x+1 << '\n';
        }
        if(i + 1 == k and nxt[x+1] == n) {
            cout << x+1 << '\n';
        }
    }




}

Measured memory_bytes: 4076
#include <stdio.h>

int main(void){
	int n, a, num[50] = {0};
	long sum = 0;
    static long dp[51][2501];

	scanf("%d%d", &n, &a);
	for(int i=0; i < n; i++) {
		scanf("%d", &num[i]);
	}

	dp[0][0] = 1;
	for(int i=1; i <= n; i++) {
		for(int j=i; j > 0; j--) {
			for(int k=num[i-1]; k <= j*50; k++) {
				dp[j][k] += dp[j-1][k-num[i-1]];
			}
		}
	}

	for(int i=1; i <= n; i++) {
		sum += dp[i][i*a];
	}
	printf("%ld", sum);

	return 0;
}


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

template<typename T, typename U> bool chmin(T &a, const U &b) {
	return (a > b ? a = b, true : false);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
	return (a < b ? a = b, true : false);
}

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;

double d[200010];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int h,a;
	cin>>h>>a;

	if(h%a){
		cout<<(h/a)+1<<endl;
	}else {
		cout<<h/a<<endl;
	}


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 200005
#define endl '\n'

#define v(type) vector<type>
#define p(type1, type2) pair<type1 , type2>
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int dp[MAX];

void solve() {
    int n;
    cin>>n;
    int a[n];
    for (int i = 0; i < n; ++i) {
        cin>>a[i];
    }
    int x1 = 0;
    for(int i = 0 ; i < n ; i++){
        if(i % 2== 0){
            x1 += a[i];
        }else x1 -= a[i];
    }
    x1 /= 2;
    cout<<2 * x1<<" ";
    for(int i = 0 ; i < n -1 ; i++){
        cout<<2 * (a[i] - x1)<<" ";
        x1 = a[i] - x1;
    }

}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

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

if h > w:
    if n % h != 0:
        print((n//h)+1)
    else:
        print(n//h)
else:
    if n % w != 0:
        print((n//w)+1)
    else:
        print(n//w)

Measured memory_bytes: 3060
n = int(input())
lis = [list(map(int, input().split())) for i in range(n)]

ans = 0
for i in range(n):
    for j in range(i+1, n):
        ans += ((lis[i][0] - lis[j][0]) ** 2 + (lis[i][1] - lis[j][1]) ** 2) ** 0.5

ans *= 2/n

print(ans)

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()

const int MAX = 2e5+10;

int N;

vector<string> solve(vector<string> s) {
    sort(ALL(s));
    vector<string> maxs;
    int mx = 0;
    REP (left, N) {
        int right = left;
        while (right < N && s[left] == s[right]) right++;
        if (right - left == mx) maxs.push_back(s[left]);
        else if (right - left > mx) {
            maxs = vector<string>();
            maxs.push_back(s[left]);
            mx = right - left;
        }
        left = right - 1;
    }

    return maxs;
}

int main() {
    cin >> N;
    vector<string> s(N);
    REP (i, N) cin >> s[i];
    FORE (m, solve(s)) {
        cout << m << endl;
    }
}

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

int top,S[1000];

void push(int);
int pop();

int main(){
  int a,b;
  top = 0;
  char s[100];

  while(scanf("%s",s) != EOF){
    if(s[0] == '+'){
      a = pop();
      b = pop();
      push(a+b);
    }
    else if(s[0] == '-'){
      b = pop();
      a = pop();
      push(a-b);
    }
    else if(s[0] == '*'){
      a = pop();
      b = pop();
      push(a*b);
    }
    else{
      push(atoi(s));
    }
  }

  printf("%d\n",pop());

  return 0;
}
void push(int x){
  S[++top] = x;
}

int pop(){
  top--;
  return S[top+1];
}

Measured memory_bytes: 548
N,K=map(int, input().split())
d = []
A = []
for i in range(0,K):
    d.append(int(input()))
    a=list(map(int, input().split()))
    A.extend(a)
cnt = 0
for i in range(1,N+1):
    if i not in A:
        cnt +=1
print(cnt)


Measured memory_bytes: 9236
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
using ll = long long;
int main() {
string s,t;
cin >> s >> t;
if(s.size()>t.size()){
    cout << "GREATER" << endl;
    return 0;
}
else if(s.size()<t.size()){
    cout << "LESS" << endl;
    return 0;
}
if (s < t) cout << "LESS" << endl;
else if(s>t)
    cout << "GREATER" << endl;
else
    cout << "EQUAL" << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.IO.Pipes;
using System.ComponentModel;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();

            int n = S.Length / 2;
            bool flag = false;
            int ans = 0;
            for (int i = 1; i <= n; i++) 
            {
                if (2 * i == S.Length) 
                {
                    break;
                }
                flag = true;
                for (int j = 0; j < i; j++) 
                {
                    if (S[j] != S[j + i]) 
                    {
                        flag = false;
                    }
                }
                if (flag) ans = i*2;
            }
            Console.WriteLine(ans);

        }

    }
}


Measured memory_bytes: 25752
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 1234567
int w,h,n; pii s[SZ];
const int M=524288;
int ls[SZ],rs[SZ],mx[SZ],tg[SZ];
inline void pd(int x)
{
	mx[x]+=tg[x];
	if(x<=M) tg[x+x]+=tg[x],tg[x+x+1]+=tg[x];
	tg[x]=0;
}
inline void upd(int x)
{pd(x+x); pd(x+x+1); mx[x]=max(mx[x+x],mx[x+x+1]);}
void add(int x,int ql,int qr,int v)
{
	if(qr<ls[x]||rs[x]<ql) return; pd(x);
	if(ql<=ls[x]&&rs[x]<=qr) tg[x]+=v;
	else add(x+x,ql,qr,v),add(x+x+1,ql,qr,v),upd(x);
}
int qmax(int x,int ql,int qr)
{
	if(qr<ls[x]||rs[x]<ql) return -1e9; pd(x);
	if(ql<=ls[x]&&rs[x]<=qr) return mx[x];
	return max(qmax(x+x,ql,qr),qmax(x+x+1,ql,qr));
}
bool by_se(pii a,pii b) {return a.se<b.se;}
pii s1[SZ],s2[SZ];
int work()
{
	memset(mx,0,sizeof mx);
	memset(tg,0,sizeof tg);
	sort(s+1,s+1+n,by_se);
	int g=w/2,ans=0,n1=0,n2=0;
	for(int i=1;i<=n;++i)
	{
		ans=max(ans,qmax(1,1,i-1)+s[i].se);
		add(1,i,i,w-s[i].se);
		if(i==1) continue;
		s1[++n1]=pii(0,i-1);
		s2[++n2]=pii(w,i-1);
		if(s[i].fi<=g)
		{
			int cr=i-1;
			while(n1&&s1[n1].fi<s[i].fi)
			{
				add(1,s1[n1].se,cr,s1[n1].fi-s[i].fi);
				cr=s1[n1--].se-1;
			}
			if(cr!=i-1) s1[++n1]=pii(s[i].fi,cr+1);
		}
		else
		{
			int cr=i-1;
			while(n2&&s2[n2].fi>s[i].fi)
			{
				add(1,s2[n2].se,cr,s[i].fi-s2[n2].fi);
				cr=s2[n2--].se-1;
			}
			if(cr!=i-1) s2[++n2]=pii(s[i].fi,cr+1);
		}
	}
	return ans;
}
int main()
{
	for(int i=1;i<=M;++i) ls[i+M]=rs[i+M]=i;
	for(int i=M-1;i>=1;--i) ls[i]=ls[i+i],rs[i]=rs[i+i+1];
	scanf("%d%d%d",&w,&h,&n);
	for(int i=1;i<=n;++i)
		scanf("%d%d",&s[i].fi,&s[i].se);
	s[++n]=pii(0,0); s[++n]=pii(0,h);
	s[++n]=pii(w,0); s[++n]=pii(w,h);
	int ans=work();
	for(int i=1;i<=n;++i)
		swap(s[i].fi,s[i].se);
	swap(w,h);
	printf("%d\n",max(work(),ans)*2);
}


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

// -- 比較用の関数 cmp --
int cmp( const void *p, const void *q ) {
    return *(int*)p - *(int*)q;
}
// ---------------------------------------
 
int main(void){
  int n;
  int x,i;
  int a[100000];
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }

  qsort( a, n, sizeof(int), cmp);
  x=a[n/2]-a[n/2-1];
  printf("%d\n",x);
}


Measured memory_bytes: 892
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

//難しすぎて何が何だかわからない・・・

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	int pn = 1;
	if (ci - cn + 16 > cm) {
		if ((ct = getcha()) == '-') { pn = -1; ct = getcha(); }
		A = ct - '0';
		while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
	else {
		if ((ct = *ci++) == '-') { pn = -1; ct = *ci++; }
		A = ct - '0';
		while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';;
		return pn * A;
	}
}

ll XD[400000], tmp[400000];
void pakuri_sort(int N, ll A[]) {
	const int b = 9;
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

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


	int N = getint();
	int k = 0;
	const ll are = 1ll << 40;
	ll kazu = 0;
	rep(i, N) {
		ll x = getint() + 1000000000, d = getint();
		XD[k++] = kazu + x * 2 + 1;
		kazu += are;
		XD[k++] = kazu + (x + d) * 2;
		kazu += are;
	}

	pakuri_sort(N + N, XD);

	k = 0;
	rep(i, N + N) {
		int j = XD[i] >> 41;
		if (XD[i] & 1) {
			tmp[k++] = j;
		}
		else {
			tmp[N + j] = k;
		}
	}
	XD[0] = (ll(N + 1) << 32) + N + 1;
	const ll ma = (1ll << 32) - 1;
	k = 0;
	for (int i = N - 1; i >= 0; i--) {
		int j = tmp[N + tmp[i]];
		int mae = k;
		while ((XD[k] >> 32) <= j) k--;
		if (mae == k) XD[k + 1] = 0;
		int kari = max(int(XD[++k] & ma), j);
		XD[k] = kari + (ll(i + 1) << 32);
		XD[N + i] = kari;
	}

	const int mod = 998244353;
	rep(i, N + 1) tmp[i] = 0;
	tmp[0] = 1;
	rep(i, N) {
		tmp[i + 1] = (tmp[i + 1] + tmp[i]) % mod;
		tmp[XD[N + i]] = (tmp[XD[N + i]] + tmp[i]) % mod;
	}

	printf("%lld", tmp[N]);

	Would you please return 0;
}

Measured memory_bytes: 6656
#include<bits/stdc++.h>
using namespace std;
const int N=205,M=998244353;
int n,ans,x[N],y[N],fac[N];
int main(){
	scanf("%d",&n);
	fac[0]=1;
	for (int i=1;i<=n;i++)fac[i]=fac[i-1]*2%M;
	for (int i=1;i<=n;i++)scanf("%d%d",&x[i],&y[i]);
	ans=(fac[n]-n-1-n*(n-1)/2+M)%M;
	for (int i=1;i<=n;i++)
		for (int j=i+1;j<=n;j++){
			int num=0;
			for (int k=j+1;k<=n;k++)
				if ((y[j]-y[i])*(x[k]-x[j])==(y[k]-y[j])*(x[j]-x[i]))num++;
			(ans+=M+1-fac[num])%=M;
		}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int counter = 0;
        for(int i = 0;i < 5;i++){
            int x = sc.nextInt();
            counter += 1;
            if(x == 0){
                System.out.println(counter);
            }
        }
    }
}


Measured memory_bytes: 35752
from collections import defaultdict
dic = defaultdict(int)
n = int(input())
lst = [input() for _ in range(n)]
last = lst[0]
dic[last] = 1
flag = True
for i in range(1, n):
  if lst[i][0] != last[-1]:
    flag = False
    break
  dic[lst[i]] += 1
  if dic[lst[i]] > 1:
    flag = False
    break
  last = lst[i]
if flag:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3316
/*For the name of God*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
const ll inf = 1e9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const ll MAX = 1e7 + 20;
#define fast ios_base:: sync_with_stdio( false ); cin.tie(0); cout.tie(0);
#define eb              emplace_back
#define em              emplace
#define pb              push_back
#define Mp              make_pair
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define rep(i,n)        for(int i=0;i<n;i++)
#define rep1(i,n)       for(int i=1;i<=n;i++)
#define rrep(i,a,n)     for(int i=a;i<=n;i++)
#define per(i,n,a)      for(int i=n;i>=a;i--)
#define pf(n)           printf("%lld",n)
#define pfi(n)          printf("%d",n)
#define sp              printf(" ")
#define ln              "\n"

template< class T > T gcd(T a, T b)
{
    return (b != 0 ? gcd<T>(b, a%b) : a);
}
template< class T > T lcm(T a, T b)
{
    return (a / gcd<T>(a, b) * b);
}
const int N = 200200;
pair<int,int>c[1000001];
int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast

    long long now, count = 0, len = 0;
    cin>>now;
    while (now >= 1) {
        count++;
        now /= 2;
    }
    len = (1ll << count) - 1;
    cout << len<<endl;
}


Measured memory_bytes: 256
def gcd(x, y):
    if y == 0:
        return x
    else:
        return (gcd(y, x % y))


ans = 0
k = int(input())

for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            ans += gcd(gcd(a, b), c)
print(ans)


Measured memory_bytes: 76724