akhauriyash/Code-Regression huggingface dataset:
/*--------------------------"SABUJ-JANA"------"JADAVPUR UNIVERSITY"--------*/
/*-------------------------------@greenindia-----------------------------------*/
//
//		  _____       _           _        _
//		 / ____|     | |         (_)      | |
//		| (___   __ _| |__  _   _ _       | | __ _ _ __   __ _
//		 \___ \ / _` | '_ \| | | | |  _   | |/ _` | '_ \ / _` |
//		 ____) | (_| | |_) | |_| | | | |__| | (_| | | | | (_| |
//		|_____/ \__,_|_.__/ \__,_| |  \____/ \__,_|_| |_|\__,_|
//		                        _/ |
//		                       |__/
/*---------------------- Magic. Do not touch.-----------------------------*/
/*------------------------------God is Great/\---------------------------------*/
#include <bits/stdc++.h>
using namespace std;
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
//cout<<fixed<<showpoint<<setprecision(12)<<ans<<endl;
#define int long long int
#define double long double
#define PI acos(-1)

void print1d(const vector<int>& vec) {for (auto val : vec) {cout << val << " ";} cout << endl;}

void print2d(const vector<vector<int>>& vec) {for (auto row : vec) {for (auto val : row) {cout << val << " ";} cout << endl;}}

signed main() {
 
	crap;

	int n, w;
	cin >> n >> w;
	 
	vector<int> wt(n), val(n);

	int total = 0;
	for (int i = 0; i < n; ++i) {
		cin >> wt[i] >> val[i];
		total += val[i];
	}


	int mx = total + 1;
	int dp[n + 1][mx];

	for (int i = 0; i < n + 1; ++i) {
		for (int j = 0; j < mx + 1; ++j) {
			if (i == 0 and j == 0)
				dp[i][j] = 0;
			else if (i == 0)
				dp[i][j] = INT_MAX;
			else if (j == 0)
				dp[i][j] = 0;
			else if (val[i - 1] <= j)
				dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - val[i - 1]] + wt[i - 1]);
			else
				dp[i][j] = dp[i - 1][j];

		}
	}

	int ans = 0;
	 
	for (int j = 0 ; j < mx; j++) {
		if (dp[n][j] <= w)
			ans = j;
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 79232
import java.util.*;

class Main{
    public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		String line1 = sc.nextLine();
		String line2 = sc.nextLine();
        int iline1 = Integer.parseInt(line1);
        int iline2 = Integer.parseInt(line2);
        int retans = 1;
        for(int i=0;i<iline1;i++){
        	retans = (retans * 2) < (retans + iline2) ? (retans * 2) : (retans + iline2);
        }
        System.out.println(retans);
    }
}


Measured memory_bytes: 22996
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int answer=0;
            String input_number = sc.nextLine();
            if(input_number.equals("0"))break;
            for(int i=0;i<input_number.length();i++){
                answer += input_number.charAt(i) - '0';
            }
            System.out.println(answer);

        }
    }
}


Measured memory_bytes: 26492
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int> > gpq; //逆順priority_queue
typedef priority_queue<int> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    int N,T;
    cin>>N>>T;
    int mincost=1001;
    for(int i=0;i<N;i++){
        int c,t;
        cin>>c>>t;
        if(t<=T){
            mincost=min(c,mincost);
        }
    }
    if(mincost==1001){
        cout<<"TLE"<<endl;
    }else{
        cout<<mincost<<endl;
    }
}


Measured memory_bytes: 3640
/**
 *   created: 28 April 2019  23:46:46
**/
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef vector< pair<int , int> > vii;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long> pll;
typedef vector< pair<long long , long long> > vll;

#define PB push_back
#define PPB pop_back
#define all(c) (c).begin,(c).end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
// #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================

int main()
{
	// optimizeIO();
	int tc=1;
	// cin>>tc;
	for(int tt=0;tt<tc;tt++){
		int n,q;
		cin>>n>>q;
		string s;
		cin>>s;
		vi res(n);
		rep(i,1,n){
			if(s.substr(i-1,2)=="AC")
				res[i] = res[i-1]+1;
			else
				res[i] = res[i-1];
		}
		int r;
		while(q--){
			int a,b;
			cin>>a>>b;
			a--;
			b--;
			int r = res[b];
			// if(a>0)
				r -= res[a];
			cout<<r<<endl;
		}
		
	}
	return 0;
}




Measured memory_bytes: 1408
#include "bits/stdc++.h"
using namespace std;

int main() {
        int n;
        scanf("%d", &n);
        vector<int> a(n);
        for (int i = 0; i < n; i ++) scanf("%d", &a[i]);
        sort(a.rbegin(), a.rend());
        int h = 0, w = 0;
        while (a[w] > h) h ++, w ++;
        h --, w --;
        int k = w;
        while (h < a[k]) k ++;
        puts(((a[w] - h - 1) & 1 || (k - w - 1) & 1) ? "First" : "Second");
        return 0;
}


Measured memory_bytes: 640
using AtCoderBeginnerContest131.Questions;
using AtCoderBeginnerContest131.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoderBeginnerContest131.Questions
{
    public class QuestionA : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var s = inputStream.ReadLine();
            yield return s[0] == s[1] || s[1] == s[2] || s[2] == s[3] ? "Bad" : "Good";
        }
    }
}


namespace AtCoderBeginnerContest131
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionA();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace AtCoderBeginnerContest131.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace AtCoderBeginnerContest131.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 11092
#include<iostream>
using namespace std;
int main() {
    int n = 0;
    string s;
    cin >> s;
    for(int i = 0; i < (int)s.size(); ++i){
        n += (int)(s[i]) - 48;
    }
    if(atoi(s.c_str()) % n == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n;
  scanf("%d", &n);
  int ans;
  if(n < 10){
    ans = n;
  }else if(n < 100){
    ans = 9;
  }else if(n < 1000){
    ans = 9 + n - 99;
  }else if(n < 10000){
    ans = 909;
  }else if(n < 100000){
    ans = 909 + n - 9999;
  }else{
    ans = 90909;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize("O2") 

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

typedef long long int ll;

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define test(t) int t; cin>>t; while(t--)

void solve()
{
  ll s,w;
  cin>>s>>w;
  if(s>w)
    	cout<<"safe"<<endl;
  else
    	cout<<"unsafe"<<endl;
	
}

int main()
{
     fast;
     //test(t)
          solve();
     return 0;
}

Measured memory_bytes: 3608
import numpy as np

a,b,k = map(int,input().split())
d = min(a,b)
count = 1
for i in range(d+1):
    temp = d-i
    if a%temp == 0 and b%temp == 0:
        if count == k:
            print(temp)
            break
        else:
            count+=1



Measured memory_bytes: 20280
/*
  AtCoder Beginner Contest 088
  C - Takahashi's Information
*/

#include<iostream>
using namespace std;

int c;

int main() {
  int sum = 0, diag = 0;
  for (int i = 0; i < 9; ++i) {
    scanf("%d", &c);
    sum += c;
    if (i == 0 || i == 4 || i == 8) diag += c;
  }

  if (sum == diag * 3) printf("Yes\n");
  else printf("No\n");
  return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  int out = 0;
  int h;
  for(int i = 0; i < n; i++){
    cin >> h;
    if(h >= k){
      out++;
    }
  }
  cout << out;
}

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

int main(){
	long long int n,m,l,A[100][100],B[100][100],i,j,k,C[100][100];
	cin >> n >> m >> l;
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			cin >> A[i][j];
		}
	}
	for(i=0;i<m;i++){
		for(j=0;j<l;j++){
			cin >> B[i][j];
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<l;j++){
			C[i][j]=0;
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<l;j++){
			for(k=0;k<m;k++){
				C[i][j]+=A[i][k]*B[k][j];
			}
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<l;j++){
			cout << C[i][j];
			if(j!=l-1) cout << " ";
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1388
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
 
using namespace std;
 
void GreenBin()
{
  int n;
  long long ans = 0;
  cin >> n;
  vector<string> a(n);
  string s;

  for (int i = 0; i < n; i++)
  {
    cin >> s;
    sort(s.begin(), s.end());
    a[i] = s;
  }
  sort(a.begin(), a.end());

  long long count = 0;
  for (int i = 1; i < n; i++)
  {
    if (a[i - 1] == a[i]) count++;
    else
    {
      count = 0;
    }
    ans = ans + count;
  }
  cout << ans << endl;
  return;
}
 
int main()
{
  GreenBin();
  return 0;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

mint f(int n){
    if(n==0) return 1;
    mint x = f(n/2);
    x *= x;
    if(n%2==1) x*=2;
    return x;
}

mint choose(int n,int a){
    mint x = 1, y = 1;
    rep(i,a){
        x *= n-i;
        y *= i+1;
    }
    return x / y;
}

int main(){
    cout << fixed << setprecision(10);
    ll n,a,b;
    cin >> n >> a >> b;
    mint ans = f(n);
    ans -= 1;
    ans -= choose(n,a);
    ans -= choose(n,b);
    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#define llint long long

using namespace std;

llint n;
llint a[200005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	sort(a+1, a+n+1);
	
	for(int i = 1; i < n; i++){
		if(a[i] == a[i+1]){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>
#include <string.h>

int main(){
	int i=0,x;
	while(1){
		i++;
		scanf("%d",&x);
		if(x==0) break;
		printf("Case %d: %d\n",i,x);
	}
	return 0;
}

Measured memory_bytes: 600
def main():
    s = input()

    if s[0] != 'A':
        print('WA')
        exit()
    
    if s[2:-1].count('C') != 1:
        print('WA')
        exit()  

    s = s[1:]
    s = s.replace('C','')

    if not s.islower():
        print('WA')
        exit()  

    print('AC')

if __name__ == '__main__':
    main()

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

template <int MOD>
struct ModInt {
    using lint = long long;
    int val;

    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };

    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }

    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(lint n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }

    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }

    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }

    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept { return is >> x.val; }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

constexpr int MOD = 1e9 + 7;
using mint = ModInt<MOD>;

template <class T>
struct Combination {
    int max_n;
    std::vector<T> f, invf;

    explicit Combination(int n)
        : max_n(n), f(n + 1), invf(n + 1) {
        f[0] = 1;
        for (int i = 1; i <= n; ++i) {
            f[i] = f[i - 1] * i;
        }

        invf[max_n] = f[max_n].inv();
        for (int i = max_n - 1; i >= 0; --i) {
            invf[i] = invf[i + 1] * (i + 1);
        }
    }

    T fact(int n) const { return f[n]; }
    T invfact(int n) const { return invf[n]; }
    T perm(int a, int b) const {
        return a < b ? T(0) : f[a] * invf[a - b];
    }
    T comb(int a, int b) const {
        return b < 0 || a < b ? T(0) : f[a] * invf[a - b] * invf[b];
    }
};

const Combination<mint> C(10000);

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

int main() {
    int n, k;
    std::cin >> n >> k;

    std::vector<int> xs(k);
    for (auto& x : xs) std::cin >> x;

    auto dp = vec(k + 1, vec(n + 1, mint(0)));
    dp[k][0] = 1;
    for (int d = k - 1; d >= 0; --d) {
        for (int m = n; m >= 0; --m) {
            for (int l = 0; l <= m; ++l) {
                dp[d][m] += dp[d + 1][m - l] * C.comb(m, l) * C.comb(n - l, xs[d] - l);
            }
        }
    }

    std::cout << dp[0][n] << std::endl;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
#include <limits.h>
#include <math.h>

int main() {
  long n;
  scanf("%ld", &n);
  long ans = LONG_MAX;
  for (int i=1; i<sqrt((double)n)+1; i++) {
    if (n%i != 0) continue;
    long a = i-1 + (n/i)-1;
    ans = (ans<a) ? ans : a;
  }
  printf("%ld\n", ans);
  return 0;
}


Measured memory_bytes: 128
double M,N,e,f,g,a[20][3],*x,*y;
n,i,j,v[20];
D(depth,m,c){
	if(m==0){
		for(N=i=0;i<depth-1;i++)for(j=i+1;j<depth;j++)x=a[v[i]],y=a[v[j]],N+=(e=x[0]-y[0])*e+(f=x[1]-y[1])*f+(g=x[2]-y[2])*g;
		if(M<N)M=N;
	}else for(;c<=n-m;c++)v[depth]=c,D(depth+1,m-1,c+1);
}
main(m){
	scanf("%d%d",&n,&m);
	if(m<2)puts("0"),exit(0);
	for(i=0;i<n;i++)for(j=0;j<3;j++)scanf("%lf",a[i]+j);
	M=0;D(0,m,0);
	printf("%f\n",M),exit(0);
}

Measured memory_bytes: 660
#include<cstdio>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#define re(i,a,b) for(int i=a;i<=b;i++)
#define _re(i,a,b) for(int i=a;i>=b;i--)
#define for_edge(x) for(int i=head[x];i;i=e[i].nxt)
#define ll long long
#define maxn 100005
#define inf ((1<<30)+5)
using namespace std;
inline int read(){char c = getchar();int ans = 0,f=1;while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){ans = ans*10 + c - '0';c = getchar();}return f*ans;}
//____________________________________________________________________________________________________________________________________________________________________
struct edge
{
	int nxt,to;ll v;
	edge(int nxt=0,int to=0,ll v=0)
	:nxt(nxt),to(to),v(v){};
}e[maxn*2];
int head[maxn],TOT,n;
inline void add(int x,int y,ll v)
{
	e[++TOT] = edge(head[x],y,v);
	head[x] = TOT;
}
ll sum_dis[maxn],ans;
int size[maxn];
inline ll dfs1(int x,int fa,ll dis)
{
	size[x] = 1;
	ll ans = dis;
	for_edge(x)
	{
		int y = e[i].to ;
		if(y==fa)continue;
		ans += dfs1(y,x,dis+e[i].v );
		size[x] += size[y];
	}
	return ans;
}
void dfs2(int x,int fa)
{
	for_edge(x)
	{
		int y = e[i].to ;
		if(y==fa)continue;
		sum_dis[y] = sum_dis[x] + e[i].v * ( n-2*size[y] );
		dfs2(y,x);
	}
	ll mn = 1e9;int opt = 0;
	//printf("%d %lld\n",x,sum_dis[x]);
	for_edge(x)
	{
		int y  =e[i].to ;
		int sz = size[y]>size[x] ? n - size[x] : size[y] ;
		if(sz*2==n) opt = 1;
		if(sz*2>n) return ;
	}
	for_edge(x)
	{
		int y  =e[i].to ;
		int sz = size[y]>size[x] ? n - size[x] : size[y] ;
		if( !opt || sz*2==n )
			mn = min(mn,e[i].v );
	}
	ans = max(ans,2ll*sum_dis[x]-mn);
}
int main()
{
	n = read();
	re(i,1,n-1)
	{
		int x = read(), y=read();ll v = read();
		add(x,y,v);
		add(y,x,v);
	}
	sum_dis[1] = dfs1(1,0,0);
	ans = 0;
	dfs2(1,0);
	printf("%lld\n",ans);
}

Measured memory_bytes: 8832
#include "bits/stdc++.h"
using namespace std;

int main() {
    
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int w = 0;
    for (int i=0; i<=a; i++) {
		for (int j=0; j<=b; j++) {
			for (int k=0; k<=c; k++) {
				if (i * 500 + j * 100 + k * 50 == x) w++;
			}
		}
	}
	cout << w << endl;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdint.h>
#include <algorithm>
#include <vector>
#include <math.h>


using namespace std;

int main() {
	int n,d;
	
	cin >> n >> d;
	
	vector<vector<int>> x(n,vector<int>(d,0));
	
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < d; j++) {
			cin >> x.at(i).at(j);
		}
	}
	
	int ans = 0;
	int tmp = 0;
	float tmp2 = 0.0;
		
	
	for (int i = 0; i < n; i++){
		for (int j = i+1; j < n; j++) {
			
//			cout << "case(" << i << ", " << j << ")" << endl;
			
			tmp = 0;
			for (int k = 0; k < d; k++) {
				tmp += std::pow(x.at(i).at(k)-x.at(j).at(k), 2.0);
			}
			
	//		cout << "tmp:" << tmp << endl;
			
			tmp2 = std::sqrt(tmp);
			
	//		cout << "tmp2:" << tmp2 << endl;
			
			if (tmp2 - floor(tmp2) == 0.0) {
				ans++;
			}
		}
	}
	
	cout << ans << endl;
	


	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LIM 1+2+4+8+16+32+64+128
#define int long long 
using namespace std;
typedef struct{
  int per;
  int ko;
  int kyoda;
  int konoko;
}TRE;
int ace(int a,int b){
  int ss=0;
  for(int i=b;i<=a;i++){
    ss+=i;
  }
  return(ss);
}
typedef pair<int,int>P;
signed  main(){
  int n;
  while(1){
    cin>>n;
    if(n==0){
      break;
    }
    int pi[n],joi[n-1];
    int sum=0;
    for(int i=0;i<n;i++){
      cin>>pi[i];
      sum+=pi[i];
    }
    for(int i=0;i<n-1;i++){
      cin>>joi[i];
    }
    sort(joi,joi+n-1);
    int now=n-2;
    int sss=n;
    while(now>=0){
      if(((sum+joi[now])*(sss-1))<(sum*sss)){
	break;
      }
      sss--;
      sum+=joi[now];
      now--;
    }
    cout<<sum*sss<<endl;
  }
  return(0);
}



Measured memory_bytes: 4080
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define pb push_back
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005

ll q,a,b;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> q;
    for(int i=1;i<=q;i++){
        cin >> a >> b;
        if(a==1 && b==1){
            cout << 0 << '\n';
            continue;
        }
        ll ans=a*b-1;
        ll l=0,r=1000000000;
        while(l!=r){
            ll mid=(l+r+1)/2;
            if(mid*mid<=ans) l=mid;
            else r=mid-1;
        }
        ans=l;
        if((a*b-1)/ans==ans) ans=2ll*ans-1;
        else ans=2ll*ans;
        if(a==b) ans++;
        cout << ans-1 << '\n';
    }
}


Measured memory_bytes: 256
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    a=int(ST().replace(" ",""))
    if a%4:
        print("NO")
    else:
        print("YES")
if __name__ == '__main__':
    main()

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

import sys

sys.setrecursionlimit(10**7)

# Override `input` function because `stdin.readline()` is 10x faster than built-in `input()`
input = sys.stdin.readline


def read_h(typ=int):
    return list(map(typ, input().split()))


def read_v(n, m=1, typ=int):
    return [read_h(typ) if m > 1 else typ(input()) for _ in range(n)]


def main():
    r, = read_h()
    print(3 * r**2)


if __name__ == '__main__':
    main()


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

int main(){
	int n,m;
	cin >> n >> m;
	int ma=m/n;
	int sum=0;
	int ans=-1;
	for(int j=ma;j>0;j--){
		if(m%j==0){
			ans=j;
			break;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
from queue import deque

s = deque([i for i in input()])
Q = int(input())
state = 0
for _ in range(Q):
    q = input()
    if q[0] == '1':
        if state == 0:
            state = 1
        else:
            state = 0
    else:
        if int(q[2]) == 1:
            if state == 0:
                s.appendleft(q[-1])
            else:
                s.append(q[-1])
        elif int(q[2]) == 2:
            if state == 0:
                s.append(q[-1])
            else:
                s.appendleft(q[-1])

if state == 1:
    s.reverse()
print(''.join(s))


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

using namespace std;

int main()
{
    int n;
    cin>>n;
    string S;
    cin>>S;
    
    char str[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    for(int i=0; i<S.length(); i++){
        S[i] = (S[i] - 'A' + n) % 26 + 'A';
    }
    cout<<S<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <queue>
#include <cmath>
#include <string>
#include <bitset>

using namespace std;

typedef long long ll;

const int MAX_D = 40;

// 桁dp
// (何桁目か, Kより小さいかどうか)
// テーブルにはi桁目まで見たときの最大コストが入る
ll dp[MAX_D + 1][2];

int main(){
    int N;
    ll K;
    cin >> N >> K;
    vector<ll> A(N);
    for(int i = 0; i < N; ++i){
        cin >> A[i];
    }
    cerr << bitset<40>(A[0]) << endl;
    
    // dpテーブルを-1に初期化
    for(int i = 0; i <= MAX_D; ++i){
        for(int j = 0; j < 2; ++j){
            dp[i][j] = -1;
        }
    }
    dp[0][0] = 0;       // 初期値
    
    // ビットごとに調べていく
    for(int i = 0; i < MAX_D; ++i){
        ll mask = (1LL << (MAX_D - i - 1));     // 桁を左から順に見ていく(左から(i+1)桁目を表す)
        
        int cnt = 0;
        for(int j = 0; j < N; ++j){
            // 左から(i+1)桁目のビットが立っているかどうか
            if(A[j] & mask)     cnt++;
        }
        
        // mask = 2^(MAX_D-d-1)
        ll cost0 = mask * cnt;          // Xのi桁目を0にする(Aで(i+1)桁目のbitが立っている個数とmaskを掛ける)
        ll cost1 = mask * (N - cnt);    // Xのi桁目を1にする(Aの各要素の(i+1)桁目のbitを反転させて上の操作をする)
        
        // i桁目まででK未満が確定しているとき(j=1 → j=1)
        if(dp[i][1] != -1){
            // (Xの(i+1)桁目)を0と1から最適な方を選択してコストを計算
            dp[i + 1][1] = max(dp[i + 1][1], dp[i][1] + max(cost0, cost1));
        }
        
        // (i+1)桁目でK未満に確定させるとき
        if(dp[i][0] != -1){
            if(K & mask){   // Kの(i+1)桁目が1ならば、Xの(i+1)桁目を0にする
                dp[i + 1][1] = max(dp[i + 1][1], dp[i][0] + cost0);
            }
        }
        
        // i+1桁目までKと一致しているとき
        if(dp[i][0] != -1){
            if(K & mask){   // Kの(i+1)桁目が1ならば、Xの(i+1)桁目も1にする
                dp[i + 1][0] = max(dp[i + 1][0], dp[i][0] + cost1);
            }
            else{           // Kの(i+1)桁目が0ならば、Xの(i+1)桁目も0にする
                dp[i + 1][0] = max(dp[i + 1][0], dp[i][0] + cost0);
            }
        }
        
        // デバッグ用
        cerr << i+1 << "桁目\t";
        cerr << "cost0=" << cost0 << "\tcost1=" << cost1 << "\t";
        cerr << "dp[" << i+1 << "][0]=" << dp[i + 1][0] << "\tdp[" << i+1 << "][1]=" << dp[i + 1][1] << endl;
    }
    
    cout << max(dp[MAX_D][0], dp[MAX_D][1]) << endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  int N;
  cin >> N;
  vector<string> s(N);
  cin >> s;
  string t;
  cin >> t;
  int a = 0, b = 0;
  for (auto str : s) {
    string mx = str;
    string mi = str;
    for (int j = 0; j < str.size(); j++) {
      if (mx[j] == '?') mx[j] = 'z';
      if (mi[j] == '?') mi[j] = 'a';
    }
    if (mi <= t) b++;
    if (mx < t) a++;
  }
  // dmp(a); dmp(b);
  for (int i = a; i <= b; i++) {
    cout << i + 1;
    if (i + 1 <= b)
      cout << ' ';
    else
      cout << endl;
  }
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();
  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int h,w,gx,gy;
vs a;
vvl b,c;

double f(double x){
	double res=0;
	for(int i=0;i<h;i++) for(int j=0;j<w;j++) if(a[i][j]=='.'||a[i][j]=='s'){
		res+=min(b[i][j]-x,(double)c[i][j]);
	}
	return res;
}

int main(){
	cin>>w>>h;
	a=vs(h,string(w,'A'));
	b=c=vvl(h,vl(w,INF));
	queue<P> q;
	for(int i=0;i<h;i++) for(int j=0;j<w;j++){
		cin>>a[i][j];
		if(a[i][j]=='g'){
			gx=i,gy=j;
			b[i][j]=0;
		}
		if(a[i][j]=='*'){
			q.push({i,j});
			c[i][j]=0;
		}
	}
	while(!q.empty()){
		P p=q.front();
		q.pop();
		int x=p.first,y=p.second;
		for(int i=0;i<4;i++){
			int X=x+dx[i],Y=y+dy[i];
			if(a[X][Y]!='#'&&c[X][Y]==INF){
				c[X][Y]=c[x][y]+1;
				q.push({X,Y});
			}
		}
	}
	q.push({gx,gy});
	while(!q.empty()){
		P p=q.front();
		q.pop();
		int x=p.first,y=p.second;
		for(int i=0;i<4;i++){
			int X=x+dx[i],Y=y+dy[i];
			if((a[X][Y]=='.'||a[X][Y]=='s')&&b[X][Y]==INF){
				b[X][Y]=b[x][y]+1;
				q.push({X,Y});
			}
		}
	}
	double l=0,r=INF;
	for(int i=0;i<200;i++){
		double m=(l+r)/2;
		if(f(m)>=0) l=m;
		else r=m;
	}
	for(int i=0;i<h;i++) for(int j=0;j<w;j++) if(a[i][j]=='s'){
		cout<<syosu(11)<<min((double)b[i][j],c[i][j]+r)<<endl;
	}
}


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

typedef unsigned long long ull;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

  
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  int h,w;
  cin >> h >> w;
  char c[h][w];
  int  ans[h][w];
  memset(ans,-1,sizeof(ans));
  rep(i,h){
    rep(j,w){
      cin >> c[i][j];
    }
  }
  rep(i,h){
    int sum=-1;
    rep(j,w){
      if(c[i][j]=='c'){
        ans[i][j]=0;
        sum=1;
      }
      else{
        if(sum<0)continue;
        else{
          ans[i][j]=sum;
          sum++;
        }
      }
    }
  }
  
  rep(i,h){
    rep(j,w){
      if(j!=0)cout<<" ";
      cout << ans[i][j];
    }
    cout << endl;
  }
  
  
}



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

using namespace std;

typedef long long ll;

template <size_t MAXSIZE> struct DisjointSet {
  int tree[MAXSIZE];

  void makeset(int size = MAXSIZE) {
    memset(tree, -1, sizeof(int) * size);
  }

  void unite(int a, int b) {
    a = find(a), b = find(b);
    if (a == b) return;
    if (tree[a] > tree[b]) tree[a] = b;
    else {
      if (tree[a] == tree[b]) tree[a]--;
      tree[b] = a;
    }
  }

  int find(int node) {
    return tree[node] < 0 ? node : (tree[node] = find(tree[node]));
  }
};

const ll MAX = 111000;
DisjointSet<MAX> dsu;
vector<ll> per[MAX];

void solve(ll test_num) {
  (void) test_num;
  ll N, M;
  cin >> N >> M;
  dsu.makeset(N + 1);
  for (ll i = 1, k, x; i <= N; ++i) {
    cin >> k;
    while (k-- > 0) {
      cin >> x;
      per[x].push_back(i);
    }
  }
  for (auto& ppl : per) {
    for (ll i = 1; i < (ll) ppl.size(); ++i) {
      dsu.unite(ppl[i], ppl[i - 1]);
    }
  }
  for (ll p = 2; p <= N; ++p) {
    if (dsu.find(p) != dsu.find(1)) {
      cout << "NO\n";
      return;
    }
  }
  cout << "YES\n";
}

void init() {

}

int main() {
#ifdef AZN
  freopen("/home/azneye/Documents/Stuff/input.txt", "r", stdin);
#endif
  init();
  ll tests = 1;
  //cin >> tests;
  for (ll test = 1; test <= tests; ++test) {
    solve(test);
  }
  return 0;
}

Measured memory_bytes: 5116
import bisect
A, B, Q = [int(_) for _ in input().split()]
S = [int(input()) for _ in range(A)]
T = [int(input()) for _ in range(B)]
X = [int(input()) for _ in range(Q)]
for x in X:
    i_sl = bisect.bisect_left(S, x)
    i_tl = bisect.bisect_left(T, x)
    D_sr = D_sl = D_tl = D_tr = float('inf')
    if i_sl < A:
        D_sl = S[i_sl] - x
    if i_tl < B:
        D_tl = T[i_tl] - x
    if i_sl:
        D_sr = x - S[i_sl - 1]
    if i_tl:
        D_tr = x - T[i_tl - 1]
    print(
        min([
            max(D_sl, D_tl),
            max(D_sr, D_tr),
            min(D_sl, D_tr) + D_tr + D_sl,
            min(D_tl, D_sr) + D_sr + D_tl
        ]))


Measured memory_bytes: 16236
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

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

  if (a + b < 10) cout << a + b << endl;
  else cout << "error" << endl;


  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n, y;
  cin >> n >> y;
  y /= 1000;
  rep(a,0,n+1) rep(b,0,n+1) {
    if (a + b > n) continue;
    int c = n - a - b;
    if (10*a + b*5 + c == y) {
      printf("%d %d %d\n", a, b, c);
      return 0;
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}

Measured memory_bytes: 3776
s = input()
t = 'keyence'
ans = 0
flag = False
for i in range(len(s)):
    for j in range(i,len(s)):
        tmp = s[:i] + s[j:]
        if tmp == t:
            ans = 1
            flag = True
            break
    if flag:
        break
if ans == 1:
    print('YES')
else:
    print('NO')



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define _rep(n, a, b) for (ll n = (a); n <= (b); ++n)
#define _rev(n, a, b) for (ll n = (a); n >= (b); --n)
#define _for(n, a, b) for (ll n = (a); n < (b); ++n)
#define _rof(n, a, b) for (ll n = (a); n > (b); --n)
#define oo 0x3f3f3f3f3f3f
#define ll long long
#define db double
#define eps 1e-3
#define bin(x) cout << bitset<10>(x) << endl;
#define what_is(x) cerr << #x << " is " << x << endl
#define met(a, b) memset(a, b, sizeof(a))
#define all(x) x.begin(), x.end()
#define pii pair<ll, ll>
#define pdd pair<db, db>
const ll mod = 1e9 + 9;
const db pi = acos(-1.0);
const ll maxn = 5e5+10;
signed main(){
    char c;
    cin >> c;
    if(c >= 'A' && c <= 'Z'){
        cout << "A" << endl;
    }else {
        cout << 'a' << endl;
    }
    
}

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

 int main(){
   int a;
   string s;
   cin >> a >> s;
   
   a<3200 ? cout << "red" : cout << s;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using boost::irange;
using namespace boost::adaptors;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;

int main() {
  int n;
  cin>>n;
  vecint cnt(1001, 0);
  vecint vl(n);
  for(int i:irange(0,n)) {
    int l;
    cin>>l;
    ++cnt[l];
    vl[i] = l;
  }
  for(int i:irange(1,1001)) {
    cnt[i] += cnt[i-1];
  }
  ll ans = 0;
  for(int i:irange(0,n)) {
    int li = vl[i];
    for(int j:irange(li,1001)) {
      --cnt[j];
    }
    for(int j:irange(0,i)) {
      int lj = vl[j];
      int mx = li+lj-1;
      int mn = max(li,lj) - min(li,lj) + 1;
      int total = cnt[min(1000,mx)] - cnt[mn-1];
      ans += total;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
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 (a>b) { a=b; return 1; } return 0; }

class LowestCommonAncestor
{
public:
    const int N;
    vector<vector<int>> G;
    vector<int> parent,depth;
    const int LOG;
    vector<vector<int>> dp;

    LowestCommonAncestor(vector<vector<int>> G):N(G.size()),G(G),parent(N),depth(N),LOG(32-__builtin_clz(N))
    {
        dfs(0,-1,0);
        dp.assign(LOG,vector<int>(N,-1));
        for(int i=0;i<N;i++) dp[0][i]=parent[i];
        for(int i=0;i+1<LOG;i++){
            for(int j=0;j<N;j++){
                if(dp[i][j]==-1) dp[i+1][j]=-1;
                else dp[i+1][j]=dp[i][dp[i][j]];
            }
        }
    }
    void dfs(int v,int p,int d)
    {
        parent[v]=p;
        depth[v]=d;
        for(int u:G[v]) if(u!=p){
            dfs(u,v,d+1);
        }
    }
    int query(int u,int v)
    {
        if(depth[u]>depth[v]) swap(u,v);
        for(int i=0;i<LOG;i++){
            if((depth[v]-depth[u])>>i&1) v=dp[i][v]; 
        }
        if(u==v) return u;
        for(int i=LOG-1;i>=0;i--){
            if(dp[i][u]!=dp[i][v]){
                u=dp[i][u];
                v=dp[i][v];
            }
        }
        return dp[0][u];
    }
};

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

    int N; cin>>N;
    vector<vector<int>> G(N);
    for(int i=0;i<N;i++){
        int k; cin>>k;
        while(k--){
            int j; cin>>j;
            G[i].push_back(j);
            G[j].push_back(i);
        }
    }
    LowestCommonAncestor lca(G);
    int Q; cin>>Q;
    while(Q--){
        int u,v; cin>>u>>v;
        cout<<lca.query(u,v)<<endl;
    }
    return 0;
}


Measured memory_bytes: 38380
/*  TAHMID RAHMAN
    DAMIAN FOREVER
     MATH LOVER
    NEVER GIVE UP
*/
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define pb push_back
#define fi first
#define se second
#define in insert
#define mp make_pair
#define GCD(a,b) __gcd(a,b);
#define endl "\n"
#define FRU freopen("out.txt","w",stdout)
#define FRO freopen("in.txt","r",stdin)
#define INFLL 9223372036854775807
#define debug 0
#define MAXN   100001
#define ar array
const int mxN=2e5;
const int MOD=1e9+7;
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
//Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
int main()
{
    fastio;
    ll l,r,d;
    cin>>l>>r>>d;
    if(l==d)
    {
        cout<<r/d<<endl;
    }
    else
    {
        if(l%d==0)
        {
            cout<<(r/d)-(l/d)+1<<endl;
        }
        else
            cout<<(r/d)-(l/d)<<endl;
    }
}


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

int main() {
	int n;
	cin >> n;
	vector<int> h(n);
	rep(i,n) cin >> h[i];
	reverse(h.begin(),h.end());
	int ans = 0;
	int val = 0;
	for(int i = 1; i < n; i++)
	{
		if(h[i-1] <= h[i]) val++;
		else val = 0;
		ans = max(ans, val);
	}
	cout << ans << endl;
return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
int main(){
  
  ll sx,sy,tx,ty;
  cin>>sx>>sy>>tx>>ty;
  
  ll a=0;ll b=0;ll B=tx-sx;ll A=ty-sy;
  
  rep(i,abs(A)){
   
cout<<'U';
  
 
  }
  rep(i,abs(B)){
 
cout<<'R';

  }
    rep(i,abs(A)){
    
cout<<'D';
 
  }
    rep(i,abs(B)){
   
cout<<'L';
 
  }
     rep(i,1){
  
cout<<'L';
    }
 
  
   rep(i,abs(A)+1){
 
cout<<'U';
  
  } 
    rep(i,abs(B)+1){
    
cout<<'R';
 
  }
     rep(i,1){
   
cout<<'D';

  }
    rep(i,1){
    
cout<<'R';
 
  }
  
      rep(i,abs(A)+1){
   
cout<<'D';

  }
  
    rep(i,abs(B)+1){
   
cout<<'L';
 
  } 
    rep(i,1){
    
cout<<'U';
   
  }
  cout<<endl;
}
  
  

Measured memory_bytes: 256
// ※※※ 解答不能 ※※※
// Factorio氏.
// https://atcoder.jp/contests/code-festival-2017-qualc/submissions/1701367
#include <bits/stdc++.h>
using namespace std;
int d[(1 << 26) + 7];
char s[200020];
int main(){
    memset(d, 0x3f, sizeof d);
    scanf("%s", s);
    int n = strlen(s), b = 0, t = 0;
    d[0] = 0;
    for(int i = 0; i < n; i++){
        b ^= (1 << (s[i] - 'a'));
        t = d[b];
        for(int j = 0; j < 26; j++) t = min(t, d[b ^ (1 << j)]);
        d[b] = min(d[b], t + 1);
    }
    printf("%d\n", max(d[b], 1));
    return 0;
}

Measured memory_bytes: 262528
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class B
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	public void Solve()
	{
		int X = GetInt();
		WriteLine(1000 * (X / 500) + 5 * ((X % 500) / 5));
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

Measured memory_bytes: 11092
X, K, D = $stdin.gets.split.map {|i| i.to_i }

def calc
  if X == 0
    if K % 2 == 0
      return 0
    else
      return D
    end
  end
  xabs = X.abs
  k = xabs / D
  case
  when K <= k
    return xabs - D * K
  else
    dk = K - k
    if dk % 2 == 0
      return xabs - D * k
    else
      return D * (k + 1) - xabs
    end
  end
end

puts calc


Measured memory_bytes: 14328
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}




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

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

int p = max(h,w);
int ans;

if(n % p == 0) ans = n / p ;
else ans = n / p +1;

cout << ans << endl;

return 0;
}

Measured memory_bytes: 256