akhauriyash/Code-Regression huggingface dataset:
"""from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd"""
S=input()
x,y=map(int,input().split())

Xlst=[]
Ylst=[]
count=0
flag=0
for s in S:
    if s=="F":
        count+=1
    else:
        if flag:
            if count:
                Ylst.append(count)
            flag=0
        else:
            if count:
                Xlst.append(count)
            flag=1
        count=0
if flag:
    if count:
        Ylst.append(count)
else:
    if count:
        Xlst.append(count)

if S[0]=="T":
    numx=set([0])
else:
    numx=set([Xlst[0]])
nlst=set()
c=0
for i in range(0 if 0 in numx else 1,len(Xlst)):
    X=Xlst[i]
    if c%2==0:
        while numx:
            a=numx.pop()
            nlst.add(a+X)
            nlst.add(a-X)
    else:
        while nlst:
            a=nlst.pop()
            numx.add(a+X)
            numx.add(a-X)
    c+=1
if x in numx|nlst:
    numx=set([0])
    nlst=set()
    c=0
    for X in Ylst:
        if c%2==0:
            while numx:
                a=numx.pop()
                nlst.add(a+X)
                nlst.add(a-X)
        else:
            while nlst:
                a=nlst.pop()
                numx.add(a+X)
                numx.add(a-X)
        c+=1
    if y in numx|nlst:
        print("Yes")
    else:
        print("No")
else:
    print("No")


Measured memory_bytes: 43756
IDENTIFICATION DIVISION.
       PROGRAM-ID. test1.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 INP PIC X(100).
       01 A PIC 99999.
       01 B PIC 99999.
       01 temp1 PIC 9999.
       01 temp2 PIC 9999.
       01 N PIC 9999.
       PROCEDURE DIVISION.
       MAIN.
        ACCEPT INP.
        PERFORM VARYING temp1 FROM 1 BY 1 UNTIL INP(temp1:1)=SPACE
        END-PERFORM.
        SUBTRACT 1 FROM temp1.
        MOVE INP(1:temp1) TO A.
        ADD 2 TO temp1.
        PERFORM VARYING temp2 FROM temp1 BY 1 UNTIL INP(temp2:1)=SPACE
        END-PERFORM.
        COMPUTE N=temp2 - temp1.
        MOVE INP(temp1:N) TO B.
        IF A < B THEN
            DISPLAY "0"
        ELSE
            DISPLAY "10"
        END-IF.
        STOP RUN.


Measured memory_bytes: 384
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        //int n = sc.nextInt();
        String s = sc.next();
        int n = s.length();
        int [] a = new int[n + 1];
        for (int i = 1; i <= n; i++) a[i] = s.charAt(i - 1) - '0';
        long res = Integer.MAX_VALUE;
        for (int i = 1; i <= n - 1; i++) if (a[i] != a[i + 1]) res = Math.min(res, Math.max(i, n - i));
        out.println(res == Integer.MAX_VALUE ? n : res);
        out.close();
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

Measured memory_bytes: 35536
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <climits>
using namespace std;
#define MOD int(1e9 + 7)
#define INF (long long)(1e18)

int main()
{
    cout.precision(18);

    long long N;
    cin >> N;

    long long c = 100;
    long long a = 0;
    while(c < N){
        a++;
        c *= 1.01;
    }

    cout << a << endl;

}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

string ans="CODEFESTIVAL2016";
string s;

int main(){
	cin.sync_with_stdio(false);
	cin>>s;
	int res=0;
	rep(i,s.length()){
		if(s[i]!=ans[i])res++;
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
    int A, B, ans;
    cin >> A >> B;
    if(A >= B){
        if(B==1) ans = 0;
            else ans  = 1;
    }
    else{
        ans = 1 + (B-A)/(A-1);
        if((B-A) % (A-1) != 0) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

using ll = long long;

const ll MOD = 1e9 + 7;

ll fib_t[1000];

ll fib(int n) {
    if (n < 0) return 1;
    if (fib_t[n] > 0) return fib_t[n];
    return fib_t[n] = (fib(n - 1) + fib(n - 2)) % MOD;
}

// 行列の積(正方行列を仮定)
vector<vector<ll>> matmul(vector<vector<ll>> a, vector<vector<ll>> b) {
    int l = a[0].size();

    vector<vector<ll>> ret(l, vector<ll>(l, 0));

    for (int i = 0; i < l; ++i) {
        for (int j = 0; j < l; ++j) {
            for (int k = 0; k < l; ++k) {
                ret[i][j] += a[i][k] * b[k][j];
                ret[i][j] %= MOD;
            }
        }
    }

    return ret;
}

// ダブリングによる行列累乗
vector<vector<ll>> matpow(vector<vector<ll>> m, int n) {
    int l = m[0].size();

    // 単位行列を返す
    if (n == 0) {
        for (int i = 0; i < l; ++i) {
            for (int j = 0; j < l; ++j) {
                m[i][j] = (i == j);
            }
        }
        return m;
    }

    if (n == 1) return m;

    if (n % 2) {
        return matmul(matpow(m, n - 1), m);
    } else {
        auto half = matpow(m, n / 2);
        return matmul(half, half);
    }
}

int main() {
    fib_t[0] = 1, fib_t[1] = 1;

    int H, W, K;
    cin >> H >> W >> K;
    --K;
    // 以降縦棒の番号は0-indexedで扱う

    vector<vector<ll>> pat(W, vector<ll>(W, 0));

    // 左に移動するパターン
    for (int i = 1; i < W; ++i) {
        pat[i - 1][i] = fib(i - 1) * fib(W - i - 1) % MOD;
    }

    // 右に移動するパターン
    for (int i = 0; i < W - 1; ++i) {
        pat[i + 1][i] = fib(i) * fib(W - i - 2) % MOD;
    }

    // 真下に移動するパターン
    for (int i = 0; i < W; ++i) {
        pat[i][i] = fib(i) * fib(W - i - 1) % MOD;
    }

    auto res = matpow(pat, H);

    cout << res[K][0] << endl;

    return 0;
}


Measured memory_bytes: 256
w = input()
T = []

while True:
    t = list(input().split())
    if t == ['END_OF_TEXT']:

        break
    else:
        t = [s.lower() for s in t]
        T.append(t)

total = 0
for line in T:
    total += line.count(w.lower())

print (total)



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

int main() {
	// your code goes here
	int N; 
	cin >> N;
	string s = to_string(N);
	if(s[0] == s[1] && s[0] == s[2])
		cout << "Yes";
	else if (s[1] == s[2] && s[1] == s[3])
		cout << "Yes";
	else 
		cout << "No";
//	cout << "No";
					
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from fractions import gcd
a, b, c, d = map(int, input().split())
l = c * d // gcd(c, d)
a -= 1
nac = a // c
nad = a // d
nal = a // l
nbc = b // c
nbd = b // d
nbl = b // l
na = nac + nad - nal
nb = nbc + nbd - nbl
print(b - a - (nb - na))


Measured memory_bytes: 5076
n = int(input())
s = list(str(input()))

score = 0

for i in range(1,n-1):
    if s[i] == 'R':

        g = 0
        g_l = []
        for j in range(i):
            if s[j] == 'G':
                g += 1
                g_l.append(i-j)
        b = 0         
        b_l = []
        for j in range(i,n):
            if s[j] == 'B':
                b += 1
                b_l.append(j-i)
                
        common = set(g_l) & set(b_l)
        score += b*g - len(common)

for i in range(1,n-1):
    if s[i] == 'R':

        g = 0
        g_l = []
        for j in range(i):
            if s[j] == 'B':
                g += 1
                g_l.append(i-j)
        b = 0         
        b_l = []
        for j in range(i,n):
            if s[j] == 'G':
                b += 1
                b_l.append(j-i)
                
        common = set(g_l) & set(b_l)
        score += b*g - len(common)

for i in range(1,n-1):
    if s[i] == 'G':

        g = 0
        g_l = []
        for j in range(i):
            if s[j] == 'R':
                g += 1
                g_l.append(i-j)
        b = 0         
        b_l = []
        for j in range(i,n):
            if s[j] == 'B':
                b += 1
                b_l.append(j-i)
                
        common = set(g_l) & set(b_l)
        score += b*g - len(common)

for i in range(1,n-1):
    if s[i] == 'G':

        g = 0
        g_l = []
        for j in range(i):
            if s[j] == 'B':
                g += 1
                g_l.append(i-j)
        b = 0         
        b_l = []
        for j in range(i,n):
            if s[j] == 'R':
                b += 1
                b_l.append(j-i)
                
        common = set(g_l) & set(b_l)
        score += b*g - len(common)

for i in range(1,n-1):
    if s[i] == 'B':

        g = 0
        g_l = []
        for j in range(i):
            if s[j] == 'R':
                g += 1
                g_l.append(i-j)
        b = 0         
        b_l = []
        for j in range(i,n):
            if s[j] == 'G':
                b += 1
                b_l.append(j-i)
                
        common = set(g_l) & set(b_l)
        score += b*g - len(common)

for i in range(1,n-1):
    if s[i] == 'B':

        g = 0
        g_l = []
        for j in range(i):
            if s[j] == 'G':
                g += 1
                g_l.append(i-j)
        b = 0         
        b_l = []
        for j in range(i,n):
            if s[j] == 'R':
                b += 1
                b_l.append(j-i)
                
        common = set(g_l) & set(b_l)
        score += b*g - len(common)
        
print(score)


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

# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 31 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 32 "<command-line>" 2
# 1 "<stdin>"

using namespace std;

# 1 "../IO/io.h" 1
inline int readInt() {
    int v;
    int r = scanf("%d", &v);
    return v;
}

inline long long readLong() {
    long long v;
    int r = scanf("%lld", &v);
    return v;
}

inline vector<int> readVecInt(int n) {
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        a[i] = readInt();
    }
    return a;
}


inline void printLine(int v) {
    printf("%d\n", v);
}

inline void printLine(long long v) {
    printf("%lld\n", v);
}

inline void printLine(const vector<int> &a) {
    for (int v: a) {
        printf("%d ", v);
    }
    printf("\n");
}

inline void printLine(const string &s) {
    printf("%s\n", s.c_str());
}
# 5 "<stdin>" 2

using State = vector<pair<int, pair<int, int>>>;

vector<bool> calc(State &a) {
    sort(a.begin(), a.end());
    int n = a.size();
    vector<bool> res(n, true);
    set<pair<int, int>> all;
    int i = 0;
    for (int sz = 0; sz <= n; sz++) {
        while (i < n && a[i].first == sz) {
            all.insert(a[i].second);
            i++;
        }
        while (all.size() > sz) {
            auto it = all.begin();
            res[it->second] = false;
            all.erase(it);
        }
    }
    return res;
}

void solve() {
    int n = readInt();
    State aL, aR;
    vector<pair<int, int>> a;
    for (int i = 0; i < n; i++) {
        int k = readInt();
        int l = readInt();
        int r = readInt();
        a.push_back({l, r});
        aL.push_back({k, {l-r, i}});
        aR.push_back({n-k, {r-l, i}});
    }
    auto maskL = calc(aL);
    auto maskR = calc(aR);
    long long ans = 0;
    for (int i = 0; i < n; i++) {

        int l = a[i].first;
        int r = a[i].second;
        if (maskL[i] && maskR[i]) {
            ans += max(l, r);
        } else if (maskR[i]) {
            ans += r;
        } else {
            ans += l;
        }
    }
    cout << ans << endl;
}

int main() {
    int t = readInt();
    while (t--) {
        solve();
    }
}


Measured memory_bytes: 19012
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v) cout << i << ' ' << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vin2(v, w) for (ll i = 0; i < v.size(); ++i) cin >> v[i] >> w[i];
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; }
int dx[] = { 0, 0, -1, 1 };
int dy[] = { 1, -1, 0, 0 };
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }

int main()
{
	//printf("使用可能な最大スレッド数：%d\n", omp_get_max_threads());

	long long int N, D;
	cin >> N >> D;
	vector<long long int> X(N), Y(N);
	vin2(X, Y);
	int cnt = 0;
	rep(i, N){
		if(X.at(i)* X.at(i) + Y.at(i)* Y.at(i) <= D * D){
			cnt++;
		}
	}
	cout << cnt;
}

Measured memory_bytes: 6424
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using System.Runtime.CompilerServices;


static class P
{
    static void Main()
    {
        var nm = Console.ReadLine().Split().Select(int.Parse).ToList();
        var a = Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).ToList();
        Console.WriteLine(a.Zip(a.Skip(1), (x, y) => y - x).OrderByDescending(x => x).Skip(nm[0] - 1).Sum());
    }
}



Measured memory_bytes: 23264
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin>>n;
  vector<string> s(n);
  for(int i=0;i<n;i++) cin>>s[i];
  sort(s.begin(),s.end());
  
  int a[n]={-1};
  int count=0;
  int maxs=-1;
  for(int i=0;i<n;i++){
    count++;
   if(i!=(n-1)){
     if(s[i]!=s[i+1]){
   	a[i]=count;
       maxs=max(maxs,a[i]);
     count=0;
     }
   }
   else{
    	a[i]=count;
      maxs=max(maxs,a[i]);
    }
  }
 
  for(int i=0;i<n;i++){
    if(a[i]==maxs) cout<<s[i]<<endl;
  }
}

Measured memory_bytes: 15104
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;

class Program
{
    static void Main()
    {
        string[] input;
        input = ReadLine().Split(' ');
        int N = int.Parse(input[0]);
        int H = int.Parse(input[1]);
        var attacks = new List<Tuple<int, int>>();
        for(int i = 0; i<N; i++)
        {
            input = ReadLine().Split(' ');
            attacks.Add(new Tuple<int, int>(int.Parse(input[0]), int.Parse(input[1])));
        }

        var max = attacks.Max(x => x.Item1);
        int count = 0;
        int h = H;
        foreach(var item in attacks.OrderByDescending(x => x.Item2).Where(x => x.Item2 > max))
        {
            count++;
            h -= item.Item2;
            if(h <= 0)
            {
                WriteLine(count);
                return;
            }
        }

        count += (int)Math.Ceiling((double)h / (double)max);
        WriteLine(count);
    }
}


Measured memory_bytes: 25036
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		try {
			int N = sc.nextInt();
			int M = sc.nextInt();
			int ans = (N * (N - 1) / 2) + (M * (M - 1) / 2);
			System.out.println(ans);

		} finally

		{
			sc.close();
		}
	}

}


Measured memory_bytes: 21076
//#pragma GCC         optimize("O3")
#include            <bits/stdc++.h>
#include            <ext/pb_ds/assoc_container.hpp>
#include            <ext/pb_ds/tree_policy.hpp>
#define FastIO      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define pb          push_back
#define mp          make_pair
#define mem(x,i)    memset(x,i,sizeof(x))
#define ff          first
#define ss          second
#define popcount(x) __builtin_popcount(x)
#define all(x)      x.begin(),x.end()
#define Case(t)     for(int ks=1;ks<=t;ks++)
#define fileout     freopen("output.txt","w",stdout)
#define filein      freopen("input.txt","r",stdin)
#define D(x)        cerr<< __LINE__ <<": "<< #x << " = "<<(x) <<'\n';
#define endl        '\n'

using namespace std;
using namespace __gnu_pbds;

using ll  = long long;
using ld  = long double;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;

const int INF    = 0x3f3f3f3f;
const ll LL_INF  = 0x3f3f3f3f3f3f3f3f;
const double PI  = acos(-1);
const double eps = 1e-4;
const int mod    = 1e9+7;
const int mx     = 5e5+5;
template <typename T>  using orderedSet =
    tree<T, null_type, less_equal<T>,
    rb_tree_tag, tree_order_statistics_node_update>;//find_by_order,order_of_key*/

/*------------------------------Graph Moves----------------------------*/
//const int fx[]= {+1,-1,+0,+0};
//const int fy[]= {+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/

//ll powmod(ll a,ll b){ll res=1;a%=mod;assert(b>=0);for(; b; b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
/*----------------------BitMask-----------------------------------------*/
//inline int setBit(int N,int pos){return N=N | (1<<pos);}
//inline int resetBit(int N,int pos){return N= N & ~(1<<pos);}
//inline bool checkBit(int N,int pos){return (bool) (N& (1<<pos));}
char arr[103][103];
int dis[103][103];
int main()
{
    int h,w;
    cin>>h>>w;
    for(int i=0;i<h;i++) cin>>arr[i];
    mem(dis,INF);
    dis[0][0]=(arr[0][0]=='#');
    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            if(!i && !j) continue;
            else if(!i) dis[i][j]=dis[i][j-1]+(arr[i][j]!=arr[i][j-1]);
            else if(!j) dis[i][j]=dis[i-1][j]+(arr[i][j]!=arr[i-1][j]);
            else dis[i][j]=min(dis[i-1][j]+(arr[i-1][j]!=arr[i][j]),dis[i][j-1]+(arr[i][j]!=arr[i][j-1]));
        }
    }
    cout<<(dis[h-1][w-1]+1)/2<<endl;
}


Measured memory_bytes: 3680
#include <algorithm>
#include <cstdio>

using namespace std ;

const int N=1e6+10 ;

int f[N] , g[N] , a[N] ;
int n ;
int main ()
{
    int i ;
    scanf("%d",&n);
    for ( i=1 ; i<=n ; i++ ) scanf("%d",a+i);
    for ( i=1 ; i<=n ; i++ ) f[i]=max(f[i-1],a[i]);
    for ( i=n ; i>=1 ; i-- ) g[i]=max(g[i+1],a[i]);
    for ( i=1 ; i<=n ; i++ ) printf("%d\n",max(f[i-1],g[i+1]));
    return 0 ;
}

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

typedef long long ll;

ll p5(ll n){
    return n * n * n * n * n;
}

ll power[2005];
ll X;

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> X;
    for(int i = 0;i <= 2000;i++){
        power[i] = p5(i - 1000);
    }
    for(int B = -1000;B <= 1000;B++){
        ll val = p5(B);
        int id = lower_bound(power, power + 2001, X + val) - power;
        if(power[id] == X + val){
            cout << id - 1000 << " " << B << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3668
//Between a and b ...
#include <bits/stdc++.h>
using namespace std;

long long f(long long n,long long d){
    if(n==-1)   return 0;
    else        return n/d+1;
}
int main(){
   long long a,b,x;
   cin>>a>>b>>x;
   cout<<(f(b,x)-f(a-1,x))<<endl;
   return 0;
}

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

int main() {
  int N, f, sum, M;
  cin >> N;
  sum = 0;
  M = N;
  for (int i=0; i < 9; i++) {
  f += M % 10;
  M = (M - M % 10) / 10;
  }
  if (N % f == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long a, b;
	cin >> a >> b;
	
	long long d, r;
	double f;
	d = a/b;
	r = a%b;
	f = a*1.0/b;
//	cout << d << " " << r << " " << f << endl;	
	printf("%d %d %.5f\n", d, r, f);
	
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n,d;
vector<vector<ll> > v;

bool check(int I,int J){
    ll num = 0;
    rep(i,d){
        num += (v[I][i] - v[J][i])*(v[I][i] - v[J][i]);
    }
    // cout << num << endl;
    rep(i,200){
        if(i*i == num)return true;
    }
    return false;
}

int main(){
    cin >> n >> d;
    v.resize(n,vector<ll>(d));
    rep(i,n){
        rep(j,d)cin >> v[i][j];
    }
    ll ans = 0;
    rep(i,n){
        FOR(j,i+1,n){
            ans += check(i,j);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const double eps = 1e-18;
double DegreeToRadian(double degree){
return degree * M_PI / 180.0;
}

lli a, b, h, m;

int main(void){
    cin >> a >> b >> h >> m;
    double th;
    if(60*h < 11*m){
        th = DegreeToRadian((11*m-60*h)/2.0)+eps;
    }else{
        th = DegreeToRadian((60*h-11*m)/2.0)+eps;
    }
    double ans = sqrt(a*a+b*b-2*a*b*cos(th))+eps;
    cout << fixed << setprecision(10);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4200
/*
    Auther: ghoshashis545 Ashis Ghosh
    College: Jalpaiguri Govt Enggineering College
*/
#include<bits/stdc++.h>
#include<string>
#include<algorithm>
using namespace std;
#define ll int
#define int long long
#define ld long double
#define ff first
#define ss string 
#define se second
#define alt(v) v.begin(),v.end()
#define ralt(v) v.rbegin(),v.rend()
#define pb emplace_back
#define mp make_pair
#define fab(i,a,b) for(int i=(a);i<(b);i++)
#define fba(i,a,b) for(int i=(b);i>=(a);i--)
int mod=1000000007;
// int mod=998244353;
int dx[]={-1,1,0,0};
int dy[]={0,0,1,-1};
bool test =0;

char grid[10][10];
int h,w,k;
void solve()
{
    cin>>h>>w>>k;
    int total=0;
    for(int i=0;i<h;++i)
        for(int j=0;j<w;++j)
        {
            cin>>grid[i][j];
            if (grid[i][j]=='#')
                total++;
        }

    int ans=0;
    // i from 0 to 2^(h+w)
    for(int i=0;i<(1LL<<(h+w));i++)
    {
        // used for avoiding overlapping
        set<pair<int,int>>st;

        // if binary repesents of i is '10001011.....(w+h) bits'
        // then we assume (w+h)th bit for row 1, (w+h-1) bit for row 2,.....
        // (w+1)th bit  for row h and wth bit for column 1,(w-1)th bit for col 2,
        // 1st bit for column w. 

        // (w+h)th bit-> (w+1)th bit for row 0 to row h-1
        // wth bit -> 1st bit for column 0 to w-1

        //  Now, when we right shift i by 0 then we get (h+w)th bit,similarl right shift i by 1 we get (h+w-1)bit
        //  simalarly when we right shift i by (h+w-1) we get 1st bit.



        // for row 
        // we get bit from (w+h)th -> (w+1)th 
        for(int j=0;j<h;j++)
        {
            if((i>>j)&1) // jth bits from right side
            {
                int row=j;
                for(int col=0;col<w;col++)
                    if(grid[row][col]=='#')
                        st.insert({row,col});
            }
        }

        // for column
        // we get bit from wth -> 1st
        for(int j=h;j<(h+w);j++)
        {
            if((i>>j)&1)
            {
                int col=j-h;
                for(int row=0;row<h;row++)
                    if(grid[row][col]=='#')
                        st.insert({row,col});
            }
        }

        int c1=total-st.size();

        if(c1==k)
            ans++;
    }

    cout<<ans;

}











signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif
    int t=1;
    if(test)
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
using namespace std;
using Graph = vector<vector<int>>;

Graph g;
map<pair<int, int>, int> color;
int ma;
void dfs(int u, int p, int c) {
    int uu = u, pp = p;
    if (uu > pp) swap(uu, pp);
    color[{uu, pp}] = c;
    int nc = 1;
    for (int v: g[u]) if (v != p) {
        if (nc == c) nc++;
        ma = max(ma, nc);
        dfs(v, u, nc++);
    }
}

int main() {
    int n; cin >> n;
    g.resize(n);
    vector<pair<int, int>> edges(n - 1);
    for (int i = 0; i < n - 1; i++) {
        int a, b; cin >> a >> b; a--, b--;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
        if (a > b) swap(a, b);
        edges[i] = {a, b};
    }
    dfs(0, -1, 0);
    cout << ma << endl;
    for (auto &e: edges) cout << color[e] << endl;
    return 0;
}

Measured memory_bytes: 13056
#include<bits/stdc++.h>
using namespace std;
#pragma region Macros
#define ios\
    ios::sync_with_stdio(false);\
    cin.tie(nullptr);
#define VEC(type, name, size)\
    V<type> name(size);\
    IN(name)
#define VVEC(type, name, h, w)\
    VV<type> name(h, V<type>(w));\
    IN(name)
#define INT(...)\
    int __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LL(...)\
    ll __VA_ARGS__;\
    IN(__VA_ARGS__)
#define STR(...)\
    string __VA_ARGS__;\
    IN(__VA_ARGS__)
#define CHAR(...)\
    char __VA_ARGS__;\
    IN(__VA_ARGS__)
#define DOUBLE(...)\
    DOUBLE __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LD(...)\
    LD __VA_ARGS__;\
    IN(__VA_ARGS__)
template <class T> void scan(T &a) { cin >> a; }
template <class T> void scan(vector<T> &a) { for(auto &i : a) scan(i); }
template <class T, class L> void scan(pair<T, L> &p){ scan(p.first); scan(p.second); }
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &... tail) { scan(head); IN(tail...); }
template <class T> inline void print(T x){ cout << x << '\n';}
#define ll long long
#define ld long double
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false; }
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true; }return false; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T Roundup_div(T x, T y) {return (x+(y-1))/y;}
template <typename T> T pow(T a, long long n, T e = 1) {T ret = e; while (n) {if (n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
const ll INF = 1e18;
#pragma endregion

using P = pair<int,int>;

int main(){
    ios;
    INT(n);
    VEC(int, a, n);
    VEC(int, b, n);
    priority_queue<P> q;
    REP(i, n){
        if(b[i] > a[i]) q.push({b[i],i});
        if(b[i] < a[i]){
            print(-1);
            return 0;
        }
    }
    ll cnt = 0;
    while(SZ(q)){
        P p = q.top(); q.pop();
        ll s = p.second;
        ll sum = b[(s ? s - 1 : n - 1)] + b[(s == n - 1 ? 0 : s + 1)];
        ll t = (b[s] - a[s]) / sum;
        if(!t){
            print(-1);
            return 0;
        }
        cnt += t;
        b[s] -= t * sum;
        if(a[s] != b[s]) q.push({b[s], s});
    }
    print(cnt);
}

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

int main ()
{
    int n,l;
    cin>>n>>l;
    vector<string> st(n);
    for(int i=0;i<n;i++)
    {
        cin>>st.at(i);
    }
    sort(st.begin(),st.end());

    for(int i=0;i<n;i++)
    {
        cout<<st.at(i);
    }
}

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

using namespace std;
# define M_PI 3.14159265358979323846
# define epsi 1e-9
# define F first
# define S second
# define REP(i,a,b) for(int i=a;i<=b;i++)
# define my_sizeof(type) ((char *)(&type+1)-(char*)(&type))
using ll = long long int;
const int MOD = 1e9 + 7;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++)
    {
        int temp;
        cin>>temp;
        h[i]=temp;
    }
    int dp[n];
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
    }
    cout<<dp[n-1];
}

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

using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> n;
    double x = (double)n / 1.08;
    int t = (x + 0.999);
    int y = t*1.08;
    //cout << y << endl;
    if(y == n)
        cout << t << endl;
    else
    cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define PI 3.1415926535897932
#define MOD 1000000007;
using namespace std;
long long GCD(long long A,long long B){
  if(B==0){
    return A;
  }
  else{
    return GCD(B,A%B);
  }
}
long long LCM(long long A,long long B){
  long long g=GCD(A,B);
  return A/g*B;
}
long long num_order(long long X){
  long long ans=0;
  while(true){
    if(X==0){
      break;
    }
    else{
      X/=10;
      ans++;
    }
  }
  return ans;
}
int main() {
  
  long long N;
  cin>>N;
  
  vector<long long> A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  
  vector<long long> app(200000);
  for(int i=0;i<N;i++){
    app[A[i]-1]++;
  }
  
  
  long long sum=0;
  for(int i=0;i<200000;i++){
    sum+=(app[i]*(app[i]-1)/2);
  }
  
  
  for(int i=0;i<N;i++){
    cout<<sum-(app[A[i]-1]-1)<<endl;
  }
}

Measured memory_bytes: 6404
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
int a,b,c;
int main() {
	//freopen("1.txt","r",stdin);
	read(a); read(b); read(c);
	printf("%d\n",min(min(a+b,b+c),a+c));
	return 0;
}

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

//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef set<int> si;
typedef set<ll> sll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;

const double pi = acos(-1.0);
const long long INF = 2e18;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define in insert
#define endl "\n"

#define sqr(a) ((a) * (a))
#define jor(a) !(a&1)// jor means EVEN number
#define bjor(a) (a&1)// bjor means ODD number

#define all(a)  a.begin(), a.end()
#define mem(arr, b) memset(arr, b, sizeof(arr)) //memset only for -1 and 0
//fill(a, a+n, 5) //fill for any value

#define for0(i,b) for(int i=0;i<(b);i++)
#define for1(i,b) for(int i=1;i<=(b);i++)
#define forab(i,a,b) for(int i=(a);i<=(b);i++)
#define forba(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fileRead freopen("input.txt", "r", stdin);
#define fileWrite freopen("output.txt", "w", stdout);

void print(int a[], int n){ // for testing or debugging
    for(int i=0;i<n;i++)cout<<a[i]<<" "; cout<<endl;
}

//-----------------------------------------------------------------------

int const mx = 100005;
int a[mx], b[mx], c[mx], N;

int dpA[mx], dpB[mx], dpC[mx];

int fun(char ch, int n){
    /// base case
    if(n==0){
        if(ch=='a') return max(b[0], c[0]);
        if(ch=='b') return max(a[0], c[0]);
        if(ch=='c') return max(a[0], b[0]);
    }

    /// memoization
    if(ch=='a' and dpA[n]!=-1) return dpA[n];
    if(ch=='b' and dpB[n]!=-1) return dpB[n];
    if(ch=='c' and dpC[n]!=-1) return dpC[n];

    if(ch=='a'){
            dpA[n] = a[n] + max(fun('b', n-1), fun('c', n-1));
            return dpA[n];
    }
    if(ch=='b'){
            dpB[n] = b[n] + max(fun('a', n-1), fun('c', n-1));
            return dpB[n];
    }
    if(ch=='c'){
            dpC[n] = c[n] + max(fun('a', n-1), fun('b', n-1));
            return dpC[n];
    }
}


int main()
{
    IOS;
    //fileRead;
    int tc = 1;
    //cin>>tc;
    while(tc--)
    {
        mem(dpA, -1), mem(dpB, -1), mem(dpC, -1);

        cin>>N;
        for0(i,N) cin>>a[i]>>b[i]>>c[i];

        cout<<max({ fun('a', N-1), fun('b', N-1), fun('c', N-1) });
    }
}


Measured memory_bytes: 10496
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

char table[3][4];

int main(){

	for(int row = 0; row < 3; row++){
		scanf("%s",table[row]);
	}

	for(int i = 0; i < 3; i++){
		printf("%c",table[i][i]);
	}

	printf("\n");

	return 0;
}


Measured memory_bytes: 256
a,b,c=map(int,input().split())
ans=0
for i in range(10000):
    if a%2==0 and b%2==0 and c%2==0:
        tmp1=b//2+c//2
        tmp2=a//2+c//2
        tmp3=a//2+b//2
        a,b,c=tmp1,tmp2,tmp3
        ans+=1
    else:
        break

if ans==10000:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <functional>
#include <stdexcept>
#include <streambuf>
#include <exception>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <typeinfo>
#include <utility>
#include <complex>
#include <numeric>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <cstring>
#include <locale>
#include <memory>
#include <iosfwd>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <ios>
#include <new>
#include <set>
 
//#define int long long
#define ll long long 
#define F first
#define S second
#define make make_pair
#define pb push_back
#define sz(x) (ll)(x.size()) 
#define all(x) x.begin (), x.end ()

using namespace std;

typedef long double ld;

const int MOD = (int)1e9 + 7;
const int N = (int)1e5 * 5 + 22;
const ll INF = (ll)1e18;
const double eps = (double)1e-6;

int n, a[N], x;
pair <int, int> p[N];
int main () {
    #ifdef Maga
        freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        p[i] = make(a[i], i);    
    }
    sort(p + 1, p + 1 + n);
    for (int i = 1; i <= n; ++i) {
        cout << p[i].S << " ";
    }

    return 0;
}

Measured memory_bytes: 3840
import sys
N,M=map(int,input().split())
L=[i for i in map(int,input().split())]
D=[]
if N >= M or M==1 :
    print(0)
    sys.exit()

L.sort()
for i in range(0,M-1) :
    D.append(abs(L[i]-L[i+1]))
D.sort(reverse=True)
print(sum(D[N-1:]))

Measured memory_bytes: 13832
#include<bits/stdc++.h>
const int maxn=2e5+5;
using namespace std;
typedef long long ll;
char s[maxn];
int a[maxn];
int main()
{
    scanf("%s",s);
    int l=strlen(s);
    ll ans=0;
    ll bb=0;
    for(int i=0;i<l;i++)
    {
        if(s[i]=='B')bb++;
        else
        ans+=bb;

    }
    printf("%lld\n",ans);

    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        new Main().compute();
    }
 
    void compute() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int ans=1;
        for(int i=0;i<N;i++){
            ans=Math.min(ans+K,ans*2);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
//Har Har Mahadev
using namespace std;
#include <bits/stdc++.h>
#define booga cout << "booga" << endl
#define ll long long int
#define pb push_back
#define mp make_pair
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " -> " << a << endl;
	err(++it, args...);
}

void testcase(){
	int k;
	cin >> k;
	set<int> yet;
	int s = 7,cnt = 1;
	while(true){
		if(s % k == 0){
			cout << cnt;
			return;
		}
		if(yet.count(s)){
			break;
		}
		yet.insert(s);
		s *= 10;
		s += 7;
		s %= k;
		cnt++;
	}
	cout << -1;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	while(t--){
		testcase();
	}
	return 0;
}


Measured memory_bytes: 50492
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

void dfs(int v, int p, int d, vector<vector<int>> &G, vector<int> &dist) {
    dist[v] = d;
    for(auto nv : G[v]) {
        if(nv == p)
            continue;
        dfs(nv, v, d + 1, G, dist);
    }
}

int main() {
    int N, u, v;
    cin >> N >> u >> v;
    u--, v--;
    vector<vector<int>> G(N);
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    vector<int> udist(N);
    vector<int> vdist(N);
    dfs(u, -1, 0, G, udist);
    dfs(v, -1, 0, G, vdist);

    int dest = -1, destd = 0, ed = INF;
    rep(i, N) {
        if(udist[i] < vdist[i]) {
            if(destd < vdist[i]) {
                dest = i;
                destd = vdist[i];
            }
        }
    }

    cout << vdist[dest] - 1 << endl;

    return 0;
}

Measured memory_bytes: 12928
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int INF=1e9;
typedef pair<int,int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 int GCD(ll a,ll b){return b?GCD(b,a%b):a;}
 int main(){
     int N;
     cin>>N;
     cout<<(N-2)*180<<endl;
 }

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

const int INF = 1 << 30;
int dx[] = {
  1, 0, -1, 0
};
int dy[] = {
  0, 1, 0, -1
};
   
int x[300];
int y[300];

int main(){
  int n;
  while(cin >> n  && n){
    x[0] = y[0] = 0;
    int id, d;
    for(int i = 1; i < n;i++){
      cin >> id >> d;
      x[i] = x[id] + dx[d];
      y[i] = y[id] + dy[d];
    }
    int hx = -INF, lx = INF, hy = -INF, ly = INF;
    for(int i = 0; i < n; i++){
      hx = max(hx, x[i]);
      hy = max(hy, y[i]);
      lx = min(lx, x[i]);
      ly = min(ly, y[i]);
    }
    cout << hx - lx + 1 << " " << hy - ly + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 0
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

N = int(input())
K = int(input())
Xs = list(mi())

ans = 0
for x in Xs:
  ans += min(x, abs(x-K))*2

print(ans)



Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std; 
inline bool IsAddable(int iNum, int iLBound, int iUBound){ 
    int iSum = 0; 
    while (iNum){ 
        iSum += iNum % 10; 
        iNum /= 10; 
    }
    return (iLBound <= iSum && iSum <= iUBound); 
}
int main(){
    ios::sync_with_stdio(false); 
    int iEnd, iLB, iUB; 
    cin >> iEnd >> iLB >> iUB; 
    register int i; 
    register long long iSum = 0; 
    for (i = 1; i <= iEnd; ++i){ 
        if (IsAddable(i, iLB, iUB)) 
            iSum += i; 
    }
    cout << iSum << endl; 
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long k;
long long j,o;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>k;
	j=k/2;
	o=k-j;
	cout<<j*o<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;
#define dump(a) cout << (a) << endl;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<int> x(n), y(n), h(n);
    for( int i = 0; i < n; i++ ) cin >> x[i] >> y[i] >> h[i];
    for( int i = 0; i <= 100; i++ ) {
        for( int j = 0; j <= 100; j++ ) {
            int l = 0;
            while( h[l] == 0 ) l++;
            int H = h[l]+abs(x[l]-i)+abs(y[l]-j);
            bool res1 = true;
            for( int k = 0; k < n; k++ ) {
                if( h[k] == 0 ) continue;
                int b = h[k]+abs(x[k]-i)+abs(y[k]-j);
                if( H != b ) res1 = false;
            }
            bool res2 = true;
            if( res1 ) {
                for( int k = 0; k < n; k++ ) {
                    if( h[k] != max(H-abs(x[k]-i)-abs(y[k]-j), 0) ) {
                        res2 = false;
                    }
                }
                if( res2 ) {
                    cout << i << " " << j << " " << H << endl;
                }
            }
        }
    }
    return 0;  
}

Measured memory_bytes: 256
from collections import Counter
n, k = map(int, input().split())
ans = 0
mod = Counter([i%k for i in range(1,n+1)])
for a in range(k):
    b = (k-a)%k
    if 2*b%k !=0: continue
    ans += mod[a]*mod[b]*mod[b]
print(ans)

Measured memory_bytes: 20704
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll ans = 0, n;std::cin >> n;
  vll a(n);re(i, n) scanf("%lld", &a[i]);
  map<ll, ll> m;
  set<ll> z;
  set<ll> Btable;
  // table
  vll table;
  rep(i, 2, 2500){
    bool flag = true;
    for(ll j=2;j*j<=i;j++) if(i%j==0) flag = false;
    if(flag) table.push_back(i);
  }
  rep(i, 2, 100001){
    bool flag = true;
    for(ll j=2;j*j<=i;j++) if(i%j==0) flag = false;
    if(flag) Btable.insert(i);
  }
  Btable.insert(1);
  re(i, n) for(ll j=0;j<table.size();j++) {
    ll k = table[j]*table[j]*table[j];
    if(k>a[i]) break;
    while(a[i]%k==0) a[i]/=k;
  }
  for(int i=0;i<n;i++){
    if(m.find(a[i])==m.end()) m.emplace(a[i], 1);
    else {
      ll t = m.at(a[i]);
      m.erase(a[i]);
      m.emplace(a[i], t+1);
    }
  }
  if((*m.begin()).first==1) ans++, m.erase(m.begin());

  for(auto itr = m.begin();itr!=m.end();itr++){
    if(z.find((*itr).first)!=z.end()) continue;
    ll now = (*itr).first, pat = 1;
    //-------------------------------------------------------------------
    for(int j=0;j<table.size();j++){
      int c = 0;
      while(now%table[j]==0) now/=table[j], c++;
      if(c!=0) pat *= (c==1?table[j]*table[j]:table[j]);
    }
    ll p = sqrt(now);
    if(p*p==now) pat *= p;
    else{
      if(now>=5000000) pat = -1;
      else pat *= now*now;
    }
    //-------------------------------------------------------------------
    if(m.find(pat)==m.end()) ans += (*itr).second;
    else{
      z.insert(pat);
      ans += max((*itr).second, m.at(pat));
    }
  }

  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 7680