akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJ.Volume1
{
    class SaleResult
    {
        public static void Main()
        {
            while (true)
            {
                int line_cnt = int.Parse(Console.ReadLine());
                if (line_cnt == 0) { break; }

                var emp = new Dictionary<int, ulong>();
                for (int i = 0; i < line_cnt; i++)
                {
                    var input = Console.ReadLine().Split(' ');
                    int id = int.Parse(input[0]);
                    int price = int.Parse(input[1]);
                    int qty = int.Parse(input[2]);

                    if (emp.ContainsKey(int.Parse(input[0]))) { emp[id] += (ulong)(price * qty); }
                    else { emp.Add(id, (ulong)(price * qty)); }
                }

                bool na = true;
                foreach (var e in emp)
                {
                    if (e.Value >= 1000000)
                    {
                        Console.WriteLine(e.Key);
                        na = false;
                    }
                }
                if (na) { Console.WriteLine("NA"); }
            }
        }
    }
}

Measured memory_bytes: 9812
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <algorithm>
#include <numeric>
#include <math.h>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)

typedef long long ll;
typedef long long int lli;

int main() {
    int N, M, C, res;
    cin >> N >> M >> C;
    vector<int> B;
    res = 0;
    for  (int i = 0; i < M; i++) {
        int Bi;
        cin >> Bi;
        B.push_back(Bi);
    }
    for (int i = 0; i < N; i++) {
        int ans = 0;
        for (int j = 0; j < M; j++) {
            int ANM;
            cin >> ANM;
            ans += ANM * B.at(j);
        }
        ans += C;
        if (ans > 0) {
            res++;
        }
    }

    cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define all(x) x.begin(),x.end()
#define fast  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int N = 1e5+1;
signed main(){
    fast;
    int n,m;
    cin>>n>>m;
    int h[n+1];
    int good[n+1];
    for(int i = 1;i<=n;i++){
        cin>>h[i];
        good[i] = 1;
    }
    for(int i = 1;i<=m;i++){
        int u,v;
        cin>>u>>v;
        if(h[u]<=h[v]){
            good[u] = 0;
        }
        if(h[v]<=h[u]){
            good[v] = 0;
        }
    }
    int ans = 0;
    for(int i = 1;i<=n;i++){
        if(good[i])
            ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 5176
#include <stdio.h>

int main(void){
    
  int i,n;
  scanf("%d",&n);
  int x[n];

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

Measured memory_bytes: 596
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<list>
using namespace std;
static const int MAX = 100000;
static const int INFTY = (1<<29);

vector<int> G[MAX];
list<int> out;

bool V[MAX];
int N;
int indeg[MAX];

void bfs(int s){
    queue<int> q;
    q.push(s);
    V[s] = true;
    while(!q.empty()){
        int u = q.front();q.pop();
        out.push_back(u);
        for(int i=0;i<G[u].size();i++){
            int v = G[u][i];
            indeg[v]--;
            if(indeg[v] == 0 && !V[v]){
                V[v] = true;
                q.push(v);
            }
        }
    }
}
void tsort(){
    for(int i=0;i<N;i++){
        indeg[i] = 0;
    }
    for(int u=0;u<N;u++){
        for(int i=0;i<G[u].size();i++){
            int v = G[u][i];
            indeg[v]++;
        }
    }

    for(int u=0;u<N;u++){
        if(indeg[u] == 0 && !V[u]) bfs(u);
    }

    for(list<int>::iterator it = out.begin();it!=out.end();it++){
        cout << *it << endl;
    }
}
int main(){
    int s,t,M;
    cin >> N >> M;
    for(int i=0;i<N;i++) V[i] = false;
    for(int i=0;i<M;i++){
        cin >> s >> t;
        G[s].push_back(t);
    }
    tsort();
    return 0;
}



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))

#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)

#define All(x) (x).begin(),(x).end()

#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))

#define Unique(v) v.resize(unique(All(v)) - v.begin())

#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)

#define End '\n'
#define Out(x) cout<<(x)<<End
#define OutP(p, sep, end) cout<<p.first<<sep<<p.second<<end

template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lb std::lower_bound
#define ub std::upper_bound

#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);

	int a, b;

	cin >> a >> b;

	if (b % a == 0) Out(a + b);
	else Out(b - a);
	
	return 0;
}


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

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


int main(){
    int x,y,z;
    while(cin>>x>>y>>z){
        if(x==0&&y==0&&z==0)break;
        
        pii ev[100];
        int v[5];
        
        rep(i,100)ev[i]=make_pair(-1,-1);
        
        rep(i,x) cin>>v[i];
        rep(i,z){
            int a,b,c;
            cin>>a>>b>>c;
            ev[a]=make_pair(b,c);
        }
        
        double dp[100][6000];
        rep(i,100)rep(j,6000)dp[i][j]=0;
        
        dp[0][0]=1;
        
        rep(i,y){
            rep(j,6000){
                if(dp[i][j]==0)continue;
                rep(k,x){
                    if(ev[i].first==1){
                        dp[i+v[k]+ev[i].second][j]+=dp[i][j]/x;
                    }
                    else if(ev[i].first==2){
                        dp[i+v[k]][ max( 0 , j+ev[i].second ) ]+=dp[i][j]/x;
                    }
                    else if(ev[i].first==3){
                        dp[i+v[k]][ max( 0 , j-ev[i].second ) ]+=dp[i][j]/x;
                    }
                    else{
                        dp[i+v[k]][j]+=dp[i][j]/x;
                    }
                }
            }
        }

        double ans = 0;
        for(int i=y;i<y+20;i++){
            rep(j,6000){
//                cout<<dp[i][j]<<" "<<j<<endl;
                ans+=dp[i][j]*j;
            }
        }
        cout<<(int)ans<<endl;
    }
}

Measured memory_bytes: 5848
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

int a,p;
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>a>>p;
    p+= a*3;
    cout<<p/2<<newl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    vector<int> num(3);
    for(int i=0;i<3;i++){
        cin >> num[i];
    }
    sort(num.begin(),num.end());
    cout << num[0] << " " << num[1] << " " << num[2] << endl;
}


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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    int ans = 0;
    rep(i, N){
        int a; cin >> a;
        while(a % 2 == 0){
            a/=2;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

// https://gist.githubusercontent.com/shibh308/f7ab83aa58b95322f0c5a353121bdecb/raw/b19dcf74b08f80f601d7a5792f2578b6ff9155bf/template.cpp
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;

#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

#define ALL(obj) (obj).begin(),(obj).end()

#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class... Tail>
void CINT(istream& cins, Tail&&... tail){
    return;
}
template <class Head,class... Tail>
void CINT(istream& cin, Head&& head,Tail&&... tail){
    cin>>head;
    CINT(cin, move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(cin,__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(cin,__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(cin,__VA_ARGS__)

template <class T = ll>
T IN(){T x;cin>>x;return (x);}

template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
    VECCIN(head);
    VT2(move(tail)...);
}

template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
    seco[head]=IN();
    VT3(head,move(tail)...);
}

#define VCEACH(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__);
#define VCREP(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__);

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int,V,greater<int>>

#define pb(a) push_back(a)
#define mp make_pair

class ABeginner {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        CIN(n,r);
        COUT(n>=10?r:(r+100*(10-n)));
    }
};

int main() {
	ABeginner solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

#ifdef DEBUG
#include "../include/debug.hpp"
#else
#define debug(...) 42
#define rdfile(...) 42
#endif

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // rdfile("_input.txt");

    int N, M;
    cin >> N >> M;

    int K, A;
    bitset<31> bs;

    for (int i=0; i<N; ++i) {
        cin >> K;
        bitset<31> bs2;
        while (K--) {
            cin >> A;
            bs2.set(A);
        }
        bs = (i == 0) ? (bs | bs2) : (bs & bs2);
    }

    cout << bs.count() << endl;

    return 0;
}

Measured memory_bytes: 256
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop, heapify
import copy
# import numpy as np
import sys
from functools import lru_cache
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)

# 1 2 3
# a, b, c = LI()


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]

@lru_cache(maxsize=None)
def dp(i, j):
    if i == 0:
        return 0 if j == 0 else -INF
    if j == 0:
        return max(dp(i - 1, 0) + a[i-1], dp(i - 1, 1) - a[i-1])
    else:
        return max(dp(i - 1, 0) - a[i - 1], dp(i - 1, 1) + a[i - 1])


n = I()
a = LI()
print(dp(n, 0))


Measured memory_bytes: 344528
#include<stdio.h>

struct Node_struct{int id, par, dep, left, right, sib, height;};
typedef struct Node_struct Node;
Node node[200000];

int dfs(int pos, int dep){
  node[pos].dep = dep;
  int a = 0, b = 0;
  if(node[pos].left != -1) a = dfs(node[pos].left, dep + 1);
  if(node[pos].right != -1) b = dfs(node[pos].right, dep + 1);
  node[pos].height = a < b? b:a;
  return node[pos].height + 1;
}

void print(int pos,int type){
  if(type == 0) printf(" %d", pos);
  if(node[pos].left != -1) print(node[pos].left, type);
  if(type == 1) printf(" %d", pos);
  if(node[pos].right != -1) print(node[pos].right, type);
  if(type == 2) printf(" %d", pos);
}

int main(){
  int i, j, k;
  int N;
  int id, left, right;
  int deg;
  int root;
  scanf("%d", &N);
  for(int i=0;i<N;i++) node[i].par = node[i].left = node[i].right = node[i].sib = -1;
  
  for(i=0;i<N;i++){
    scanf("%d %d %d", &id, &left, &right);
    node[id].id = id;
    node[id].left = left;
    node[id].right = right;
    if(left != -1) node[left].par = id, node[left].sib = right;
    if(right != -1) node[right].par = id, node[right].sib = left;
  }
  
  for(i=0;i<N;i++) if(node[i].par == -1) root = i;
  printf("Preorder\n");
  print(root, 0);
  printf("\n");
  
  printf("Inorder\n");
  print(root, 1);
  printf("\n");
  
  printf("Postorder\n");
  print(root, 2);
  printf("\n");  
  
  return 0;
}



Measured memory_bytes: 2108
///Astalavista Code........~CodeSlayer007
#include <bits/stdc++.h>
using namespace std;
#include <vector>
#include <iterator>
typedef  long long int ll;
typedef  long double ld;
#define PT(x) cout << (#x) << " is " << (x) << endl;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
#define SPD_emergency ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int M = 1000000007;
#define int long long
void PV( vi v) { for(ll i=0 ; i<v.size() ; i++) cout<< v[i] << " "; cout<< endl;}
void PA( int v[] , int n ){ for(ll i=0 ; i<n ; i++)cout<< v[i] << " " ; cout<< endl;}
 int rn(double d ){
  int k=floor(d);
  return k;
 }
signed  main(){
     SPD_emergency
   //ll t; cin>> t; while(t--)
    {
        string s,s1;;
        cin>>s;
        int i , j , k , l ,f=0;
        int q;
        cin>>q;
        while(q--){
            cin>>k;
            if(k==1)f=1-f;
            else {
                char c;
                cin>>j;
                cin>>c;
                if(j==1){
                    if(f==0) s1 = s1 + c;
                    else s=s+c;
                }
                else {
                     if(f==1) s1 = s1 +  c;
                    else s=s+c;
                }
            }
        }
        if(f==0){
            reverse(s1.begin(),s1.end());
            s1=s1+s;
            cout<<s1<<endl;
        }else {
          reverse(s.begin(),s.end());
          s=s+s1;
          cout<<s<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 1764
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long n = scan.nextInt();
		long ans = 1;
		for (int i = 1; i <= n; i++) {
			ans = (ans * i) % 1000000007;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


# @mt
def slv(N, A):
    
    L = [-A.pop(0)]
    ma = L[0]
    for a in A:
        if ma <= -a:
            ma = -a
            L.append(ma)
            continue
        i = bisect.bisect_right(L, -a)
        L[i] = -a
        ma = L[-1]
    return len(L)



def main():
    N = read_int()
    A = [read_int() for _ in range(N)]
    print(slv(N, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 73560
import math
import fractions

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

#a = list(map(int, input().split()))

s = input()

a = ""
for i in range(len(s)):
    a+= 'x'

print(a)


















Measured memory_bytes: 64748
using System;

namespace test{
    class atcorder123{
        static void Main (string[] args)
        {
            int a,b,c;
            string[] str = Console.ReadLine().Split(' ');
             a = int.Parse(str[0]);
             b = int.Parse(str[1]);
             c = int.Parse(str[2]);

             int n =0;

             for(int x=1; x<=a; ++x)
             {
                 int p = x;
                 int q = p%10;
                 while(p>=10)
                 {
                     p = p/10;
                     q = q+p%10;
                 }
                 if(b<=q && q<=c)
                 {
                     n = n+x;
                 }
                 
             }
             Console.WriteLine(n);
        




            
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define si(v) v.size()
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (n); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

using ll = long long;
using ld = long double;
using namespace std;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  set<int> se;
  rep(i, 3) {
    int a; cin >> a;
    se.emplace(a);
  }

  cout << si(se) << '\n';

  return (0);
}

Measured memory_bytes: 3608
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"

using namespace std;

typedef long int li;
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pt;

#define fi first
#define se second
#define dump(x) cout << #x << " = " << x << endl
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

li n, a[100107], dp[100107], k;

int main () {
    fastIO;
    cin >> n >> k;
    for(li i = 0; i < n; i ++) { cin >> a[i]; dp[i]=1e9; }
    dp[0]=0;
    for(li i = 0; i < n; i ++) {
        for(li j = 1; j <= k; j ++) {
            dp[i+j]=min(dp[i+j], dp[i]+abs(a[i]-a[i+j]));
        }
    }
    cout << dp[n-1];
}


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

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)

#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000

using namespace std;
typedef long long ll;

int main() {
    string T;
    cin >> T;

    if (T[0] == '?'){
        if (T[1] == 'D'){
            T[0] = 'P';
        }else{
            T[0] = 'D';
        }
    }

    FOR(i, 1, T.length() - 1){
        if (T[i] == '?'){
            if (T[i-1] == 'P'){
                T[i] = 'D';
            }else if (T[i+1] == '?' || T[i+1] == 'D'){
                T[i] = 'P';
            }else{
                T[i] = 'D';
            }
        }
    }
    ll last_index = T.length()-1;
    if (T[last_index] == '?'){
        T[last_index] = 'D';
    }
    cout << T;

}

Measured memory_bytes: 3748
import heapq
n=int(input())
inf=10000000000000
#始まりと終わりを保持
#同じオブジェクトにするやつで一時間溶かした、しね
ans=[[-1,-1] for i in range(n)]
ans[-1][1]=0
ans[0][0]=0
t=list(map(int,input().split()))
v=list(map(int,input().split()))
v2=[]
for i in range(n):
    heapq.heappush(v2,(v[i],i))
for i in range(n):
    #print(ans)
    y=heapq.heappop(v2)
    #print(y[1])
    #print(ans[y[1]])
    #print(y)
    #始まりをまずは決める
    if ans[y[1]][0]==-1:
        #print(2)
        now1=0
        ansi1=inf
        for j in range(y[1]-1,-1,-1):
            #print(ans1)
            if ans[j][1]!=-1:
                ansi1=min(ansi1,ans[j][1]+now1)
            now1+=t[j]
            if ans[j][0]!=-1:
                ansi1=min(ansi1,ans[j][0]+now1)
        now1=0
        for j in range(y[1],n):
            if ans[j][0]!=-1:
                ansi1=min(ansi1,ans[j][0]+now1)
            now1+=t[j]
            if ans[j][1]!=-1:
                ansi1=min(ansi1,ans[j][1]+now1)  
        ans[y[1]][0]=min(ansi1,y[0])
        ans[y[1]-1][1]=ans[y[1]][0]
        #print(ansi1)
    if ans[y[1]][1]==-1:
        #print(3)
        now2=0
        ansi2=inf
        for j in range(y[1],-1,-1):
            if ans[j][1]!=-1:
                ansi2=min(ansi2,ans[j][1]+now2)
            now2+=t[j]
            if ans[j][0]!=-1:
                ansi2=min(ansi2,ans[j][0]+now2)
        now2=0
        for j in range(y[1]+1,n):
            if ans[j][0]!=-1:
                ansi2=min(ansi2,ans[j][0]+now2)
            now2+=t[j]
            if ans[j][1]!=-1:
                ansi2=min(ansi2,ans[j][1]+now2)  
        ans[y[1]][1]=min(ansi2,y[0])
        ans[y[1]+1][0]=ans[y[1]][1]
        #print(ansi2)
answer=0
for i in range(n):
    h=min((t[i]+sum(ans[i]))/2,v[i])
    answer+=((h**2-ans[i][0]**2)/2)
    answer+=((h**2-ans[i][1]**2)/2)
    answer+=(h*(t[i]+sum(ans[i])-2*h))
print(answer)
#print(ans)



Measured memory_bytes: 3296
fun main(args: Array<String>) {
    val (x, y, z, k) = readLine()!!.split(' ').map { it.toInt() }
    val cakesA = readLine()!!.split(' ').map { it.toLong() }.sortedDescending()
    val cakesB = readLine()!!.split(' ').map { it.toLong() }.sortedDescending()
    val cakesC = readLine()!!.split(' ').map { it.toLong() }.sortedDescending()

    val queue = PriorityQueue()
    queue.push(Cakes(cakesA[0] + cakesB[0] + cakesC[0], 0, 0, 0))

    repeat(k) {

        val cakes = queue.pop()
        println(cakes.value)

        val (a, b, c) = cakes.indices()

        if (a + 1 < x) {
            queue.push(Cakes(cakesA[a + 1] + cakesB[b] + cakesC[c], a + 1, b, c))
        }

        if (b + 1 < y) {
            queue.push(Cakes(cakesA[a] + cakesB[b + 1] + cakesC[c], a, b + 1, c))
        }

        if (c + 1 < z) {
            queue.push(Cakes(cakesA[a] + cakesB[b] + cakesC[c + 1], a, b, c + 1))
        }

    }

}

private data class Cakes(val value: Long, val a: Int, val b: Int, val c: Int) {

    fun indices(): Triple<Int, Int, Int> {
        return Triple(a, b, c)
    }

}

private class PriorityQueue {

    private val heap = mutableListOf<Cakes>()

    private var size = 0

    private val set = mutableSetOf<Cakes>()

    fun push(cakes: Cakes) {
        if (set.contains(cakes)) return

        var i = size++

        while (i > 0) {
            val p = (i - 1) / 2

            if (heap[p].value >= cakes.value) break

            if (i < heap.size) {
                heap[i] = heap[p]
            } else {
                heap.add(i, heap[p])
            }

            i = p
        }

        if (i < heap.size) {
            heap[i] = cakes
        } else {
            heap.add(i, cakes)
        }

        set.add(cakes)
    }

    fun pop(): Cakes {
        val ret = heap[0]

        val x = heap[--size]
        var i = 0

        while (i * 2 + 1 < size) {
            val l = i * 2 + 1
            val r = i * 2 + 2

            val j = if (r < size && heap[l].value < heap[r].value) {
                r
            } else {
                l
            }

            if (heap[j].value <= x.value) break

            heap[i] = heap[j]
            i = j
        }

        heap[i] = x

        return ret
    }

}

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

int main() {
  string s;
  cin >> s;
  if (s[0] == s[1] && s[1] == s[2]){
    cout << "No" << endl;
  } else{
    cout << "Yes" << endl;

  }
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)


int main(void)
{
	ll n,c;
	cin >> n >> c;
	vector<P> vs(n);
	rep(i, n) {
		cin >> vs[i].first >> vs[i].second;
	}
	vector<ll> cs1(n+1, 0);
	vector<ll> mcs1(n + 1, 0);
	rep(i, n) {
		cs1[i + 1] = cs1[i] + vs[i].second;
		mcs1[i + 1] = max(mcs1[i], cs1[i + 1] - vs[i].first);
	}
	vector<ll> cs2(n + 1, 0);
	vector<ll> mcs2(n + 1, 0);
	rep(i, n) {
		cs2[i + 1] = cs2[i] + vs[n-1-i].second;
		mcs2[i + 1] = max(mcs2[i], cs2[i + 1] - (c - vs[n-1-i].first));
	}
	ll m = max(0LL, max(mcs1[n], mcs2[n]));
	rep(i, n) {
		auto m1 = mcs1[i + 1] + mcs2[n - 1 - i] - vs[i].first;
		auto m3 = mcs2[i + 1] + mcs1[n - 1 - i] - (c - vs[n - 1 - i].first);
		m = max(m, m1);
		m = max(m, m3);
	}
	cout << m << endl;
	return 0;
}


Measured memory_bytes: 4992
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] r = new int[n];
    for(int i = 0; i < n; i++) {
      r[i] = sc.nextInt();
    }
    int max = r[1] - r[0];
    int min = r[0];
    for(int i = 1; i < n; i++) {
      min = Math.min(min, r[i - 1]);
      max = Math.max(max, r[i] - min);
    }
    System.out.println(max);
  }
}



Measured memory_bytes: 100908
#include<stdio.h>
int main(void)
{
	int a, b, c, i, n=0;
	scanf("%d%d%d", &a, &b, &c);
	for(i=a;i<=b;i++){
		if(c%i==0) n++;
	} 
	printf("%d\n", n);
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;
int main() {
    int i,j,n,b,c,x,y;
    int flag=0;
    int sum=0;
    int souwa=0;
    int max=0;
    int temp;
    string s;
    cin>>s;
    n=s.size();
    for(i=n-1; i>0; --i){
        if(s[i]=='m'){
            --i;
            if(s[i]=='a'&&i>0){
                --i;
                if(s[i]=='e'&&i>0){
                    --i;
                    if(s[i]=='r'&&i>0){
                        --i;
                        if(s[i]!='d'){flag=1;break;}
                    }
                    else{flag=1;break;}
                }
                else{flag=1;break;}
            }
            else{flag=1;break;}
        }
        else if(s[i]=='r'){
            --i;
            if(s[i]=='e'&&i>0){
                --i;
                if(s[i]=='m'&&i>0){//dreamerルート
                    --i;
                    if(s[i]=='a'&&i>0){
                        --i;
                        if(s[i]=='e'&&i>0){
                            --i;
                            if(s[i]=='r'&&i>0){
                                --i;
                                if(s[i]!='d'){flag=1;break;}
                            }
                            else{flag=1;break;}
                        }
                        else{flag=1;break;}
                    }
                    else{flag=1;break;}
                }
                else if(s[i]=='s'&&i>0){//eraserルート
                    --i;
                    if(s[i]=='a'&&i>0){
                        --i;
                        if(s[i]=='r'&&i>0){
                            --i;
                            if(s[i]!='e'){flag=1;break;}
                        }
                        else{flag=1;break;}
                    }
                    else{flag=1;break;}
                }
                else{flag=1;break;}

            }
            else{flag=1;break;}
        }
        else if(s[i]=='e'){
            --i;
            if(s[i]=='s'&&i>0){
                --i;
                if(s[i]=='a'&&i>0){
                    --i;
                    if(s[i]=='r'&&i>0){
                        --i;
                        if(s[i]!='e'){flag=1;break;}
                    }
                    else{flag=1;break;}
                }
                else{flag=1;break;}
            }
            else{flag=1;break;}
        }
        else{flag=1;break;}
    }
    if(flag==1){cout<<"NO";}
    else{cout<<"YES";}
    return 0;
}

Measured memory_bytes: 512
import sys
N=int(input())
A=list(map(int,input().split()))
if A[0]>=2:
  print(-1)
  sys.exit()
if A[0]==1:
  left=0
else:
  left=1
ans=A[N]
P=[1 for i in range(N+1)]
for i in range(1,N+1):
  point=left*2
  P[i]=point
  if point-A[i]<0:
    print(-1)
    sys.exit()
  left=point-A[i]
root=A[N]
for i in range(N,0,-1):
  root=min(P[i-1],root+A[i-1])
  ans+=root
print(ans)    

Measured memory_bytes: 674268
import java.util.Scanner;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    char[] b = a.toCharArray();
    boolean ans = false;
    if(b[2] == b[3] && b[4] == b[5]) ans = true;
    if(ans){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 23124
import java.util.Arrays;
import java.util.Scanner;

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

        int n = sc.nextInt();
        int k = sc.nextInt();

        boolean[] isHate = new boolean[10];
        Arrays.fill(isHate, false);
        for (int i = 0; i < k; i++) {
            isHate[sc.nextInt()] = true;
        }

        long num = n;
        while (isContainsHateNumber(isHate, num) >= 0) {
            num++;
        }
        System.out.println(num);
    }

    private static int isContainsHateNumber(boolean[] isHate, long num) {
        int digitNum = Long.toString(num).length();
        for (int i = 0; i < digitNum; i++) {
            int digit = Integer.parseInt(String.valueOf(Long.toString(num).charAt(i)));
            if (isHate[digit]) return i;
        }
        return -1;
    }
}


Measured memory_bytes: 18412
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int n;
    cin >> n;
    cout << n * 800 - (n / 15) * 200 << endl;
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
h = list(map(int, input().split()))
li = []
for m in range(M):
  a, b = map(int, input().split())
  if h[a-1] < h[b-1]:
    li.append(a)
  elif h[a-1] == h[b-1]:
    li.append(a)
    li.append(b)
  else:
    li.append(b)

answer = N - len(set(li))
print(answer)

Measured memory_bytes: 19984
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int inf=1e9+7;//0x3f
//
int main(){
	int A[3];
	cin>>A[0]>>A[1]>>A[2];
	sort(A,A+3);
	cout<<A[2]*10+A[1]+A[0]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int N; cin >> N;
  ll a[N]; rep(i,N) cin >> a[i];
  ll b[N]; rep(i,N) cin >> b[i];
  ll result = 0;
  rep(dig,29) {
    ll d = (1ull<<dig);
    ll ta[N]; rep(i,N) ta[i] = a[i] % (d*2);
    ll tb[N]; rep(i,N) tb[i] = b[i] % (d*2);
    sort(tb,tb+N);
    ll count = 0;
    rep(i,N) {
      auto l1 = lower_bound(tb, tb+N , d-ta[i]);
      auto r1 = lower_bound(tb, tb+N , d*2-ta[i]);
      auto l2 = lower_bound(tb, tb+N, d*3-ta[i]);
      auto r2 = lower_bound(tb, tb+N, d*4-ta[i]);
      count += (r1-l1)+(r2-l2);
    }
    result += count%2 * d;
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 8576
using System;
using System.Linq;

public class ABC158_C {
	private static void Main(string[] args) {
		var input = ReadIntsAsArray();
		var a = input[0];
		var b = input[1];

		var minA = (int)Math.Ceiling(a * 12.5D);
		var maxA = (int)Math.Ceiling((a + 1) * 12.5D) - 1;
		var minB = b * 10;
		var maxB = (b + 1) * 10 - 1;

		var answer = -1;

		for (int i = minA; i <= maxA; i++) {
			if ((minB <= i) && (i <= maxB)) {
				answer = i;
				break;
			}
		}

		Console.WriteLine(answer);
	}

	private static int[] ReadIntsAsArray() => Console.ReadLine().Trim().Split().Select(x => int.Parse(x)).ToArray();
}

Measured memory_bytes: 13396
n,m = map(int,input().split())
l = []
for i in range(m):
    l.append(list(map(int,input().split())))
ans = 0
lmax = 0
rmin = float('inf')
for i in l:
    if i[0]>lmax:
        lmax = i[0]
    if i[1]<rmin:
        rmin = i[1]
if lmax <= rmin:
    ans = rmin - lmax + 1
print(ans)


Measured memory_bytes: 27344
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll x,ll y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
int main(){
    ll a,b,c;
    cin >> a >> b;
    c = gcd(a,b);
    vector<pair<ll,int>> f;
    for(ll i=2;i*i<=c;i++){
        if(c%i) continue;
        int d=0;
        while(c%i==0){
          c/=i;
          d++;
        } 
        f.emplace_back(i,d);
    }
    if(c!=1) f.emplace_back(c,1);
    cout << f.size()+1 << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        var a = Primes(1000000);
        while (true)
        {
            var np = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var n = np[0];
            var p = np[1];
            if (n == -1) break;
            var arr = a.SkipWhile(x => x <= n).Take(p).ToArray();
            List<int> list = new List<int>();
            for (int i = 0; i < arr.Length; i++)
            {
                for (int j = i; j < arr.Length; j++)
                {
                    list.Add(arr[i] + arr[j]);
                }
            }
            list.Sort();
            Console.WriteLine(list[p - 1]);
        }
    }


    public static IEnumerable<int> Primes(int n)
    {
        if (n < 2) yield break;
        yield return 2;
        ulong[] bitArray = new ulong[(n + 1) / 2 / 64 + 1];

        int[] smallPrimes = { 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61 };
        foreach (var prime in smallPrimes)
        {
            if (n < prime) yield break;
            yield return prime;

            ulong[] mask = new ulong[prime];
            for (int j = (prime - 3) >> 1; j < (prime << 6); j += prime)
                mask[j >> 6] |= 1UL << j;

            int maskInd = 0;
            for (int i = 0; i < bitArray.Length; i++)
            {
                bitArray[i] |= mask[maskInd];
                if (++maskInd >= prime) maskInd = 0;
            }
        }

        int[] deBruijnIndex = { 0, 1, 59, 2, 60, 40, 54, 3, 61, 32, 49, 41, 55, 19, 35, 4, 62, 52, 30, 33, 50, 12, 14, 42, 56, 16, 27, 20, 36, 23, 44, 5, 63, 58, 39, 53, 31, 48, 18, 34, 51, 29, 11, 13, 15, 26, 22, 43, 57, 38, 47, 17, 28, 10, 25, 21, 37, 46, 9, 24, 45, 8, 7, 6 };
        int maxInd = n / 2;
        for (int i = 0; i < bitArray.Length; i++)
        {
            for (ulong bit = ~bitArray[i]; bit != 0; bit &= bit - 1)
            {
                int index = i << 6 | deBruijnIndex[((bit & (~bit + 1)) * 0x03F566ED27179461UL) >> 58];
                int prime = (index << 1) + 3;
                if (n < prime) yield break;
                yield return prime;
                for (int ind = index; ind <= maxInd; ind += prime)
                    bitArray[ind >> 6] |= 1UL << ind;
            }
        }
    }
}


Measured memory_bytes: 34152
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ra = 101, rb = -1;
        while(n--!=0){
            int a = sc.nextInt(), b = sc.nextInt();
            if(rb < b || rb==b && a < ra){
                ra = a;
                rb = b;
            }
        }
        System.out.println(ra+" "+rb);
    }
}

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

#define int long long
#define debug(x) cout<<#x<<" "<<x<<endl;

const int N=1e6+5;
const double eps=1e-9;
const int INF=1e18;

int a[N];

signed main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int n,k;
    cin>>n>>k;
    n%=k;
    cout<<min(n,abs(n-k))<<endl;
    return 0;
}

//Created Time  :2020/4/4 20:00:15


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#define ll long long

using namespace std;
typedef pair<int, int> P;

int main()
{
    ll x, k, d;
    cin >> x >> k >> d;
    ll b = k;
    k = max(k - abs(x) / d, 0ll);
    if (x > 0)
    {
        x -= min(b, abs(x) / d) * d;
    }
    else
    {
        x += min(b, abs(x) / d) * d;
    }
    if (k % 2 == 0)
    {
        cout << abs(x) << endl;
    }
    else
    {
        cout << d - abs(x) << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main() {
  string S;
  cin >> S;

  if( (S[0]==S[1]&&S[1]==S[2])||(S[1]==S[2]&&S[2]==S[3]) ) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n,k1,k2,k3;
  int flag=0;
  
  scanf("%d",&n);
  
  k1=n%10;
  k2=n-k1;
  k2=k2%100;
  k2=k2/10;
  k3=n-(k2*10)-k1;
  k3=k3/100;
  
  if(k1==7)
    flag=1;
  if(k2==7)
    flag=1;
  if(k3==7)
    flag=1;
  
  if(flag==1)
    printf("Yes");
  else if(flag==0)
    printf("No");
  
  return 0;
}

Measured memory_bytes: 1708
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


vector<vector<ll>> e;
vector<ll> d;
void dfs(ll r,ll dst){
    d[r]=dst;
    for(ll to: e[r]){
        if(d[to]==-1)dfs(to,d[r]+1);
    }
}
vector<ll> limvis;
ll ans;
void limdfs(ll r, ll dst){//深さdst以上のところだけでDFS
    limvis[r]=0;
    ans=max(ans,d[r]);
    for(ll to:e[r]){
        if(limvis[to]==-1&&d[to]>=dst)limdfs(to,dst);
    }
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,u,v;cin>>n>>u>>v;u--;v--;
    
    e=vector<vector<ll>>(n,vector<ll>());
    d=vector<ll>(n,-1);
    rep(i,n-1){
        ll a,b;cin>>a>>b;a--;b--;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    dfs(v,0);
    ll limdst = d[u]-(d[u]-1)/2;
    limvis=vector<ll>(n,-1);
    ans=0;
    limdfs(u,limdst);
    cout<<ans-1;


    return 0;
}

Measured memory_bytes: 9984
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <deque>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

const int mod = 1000000007;
const int N = 23000001;

deque<pii > v;

LL _pow(LL a, LL b) {
  if(!b) return 1;
  if(b == 1) return a;
  if(b == 2) return a * a % mod;
  if(b & 1) {
    return a * _pow(a,b-1) % mod;
  }
  return _pow(_pow(a,b/2),2);
}

int main() {
  int n;
  S(n);
  int ans = 0;
  rep(i,1,n/8+1) {
    if(n % i == 0) {
      ans += _pow(10, n / i) - _pow(10, (n / i) - 1) - (i - 1);
      ans %= mod;
      if(ans < 0) ans += mod;
    } else {
      ans++;
      if(ans >= mod) ans -= mod;
    }
  }
  int d = 1;
  int sm = 0;
  int p = 0;
  v.pb(mp(0,0));
  int idx = 0;
  rep(i,1,N) {
    if(i == 10 || i == 100 || i == 1000 || i == 10000 || i == 100000 || i == 1000000 || i == 10000000) {
      d++;
      p = 0;
    }
    sm += d;
    p += d;
    v.pb(mp(sm,i));
    while(v.front().FF + n < sm) v.pop_front();
    if(v.front().FF + n == sm && i - v[idx].SS > n / 8) {
      ans++;
      if(ans == mod) ans = 0;
    }
  }
  P(ans);
  return 0;
}


Measured memory_bytes: 117928
import sys

h, w = map(int, input().split())

s = [list(map(str, input())) for i in range(h)]

dx = [1, 0, -1, 0, 1, -1, 1, -1]
dy = [0, 1, 0, -1, 1, 1, -1, -1]

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            continue
        num = 0
        for k in range(8):
            ni = i + dy[k]
            nj = j + dx[k]

            if ni < 0 or ni >= h:
                continue
            if nj < 0 or nj >= w:
                continue
            if s[ni][nj] == '#':
                num += 1
        
        s[i][j] = str(num)

for i in range(len(s)):
    print(''.join(s[i]))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using vs=vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    	((ll)1ll<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.141592653589793

template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
    int n;
    cin>>n;
    rep(i,100){
        if(n<4*i)break;
        if((n-4*i)%7==0){cout<<"Yes"<<endl; return 0;}
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>

using namespace std;

int main()
{
	for(int a;scanf("%d",&a),a;){
		vector<int> card;
		card.push_back(a);
		while(getchar()!='\n'){
			int b;
			scanf("%d",&b);
			card.push_back(b);
		}

		int cnt1=0,total=0;
		for(int i=0;i<card.size();i++){
			if(card[i]==1)	cnt1++;
			total+=card[i]>10?10:card[i];
		}

		for(int i=0;i<cnt1;i++,total+=10)
			if(total+10>21)	break;

		printf("%d\n",total>21?0:total);
	}

	return 0;
}

Measured memory_bytes: 0