akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int maxn=100005;
inline int read(){
	int x=0;char ch=getchar();
	while (!isdigit(ch)) ch=getchar();
	while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x;
}
int n,a[105],sum=0;
int main(){
	n=read();
	for (int i=1;i<=n;++i) a[i]=read(),sum+=a[i];
	if (sum%10){
		printf ("%d\n",sum);
		return 0;
	}
	sort(a+1,a+n+1);
	for (int i=1;i<=n;++i){
		if ((sum-a[i])%10){
			printf ("%d\n",sum-a[i]);
			return 0;
		}
	}
	puts("0");
	return 0;
}


Measured memory_bytes: 256
#include "stdio.h"


int main()
{
	int n,a[10000],m,t[10000],sum=0,i,k;



	scanf("%d", &n);

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

	scanf("%d", &m);

	for (i = 0;i < m;i++) {
		scanf(" %d", &t[i]);


		for (k = 0;k < n;k++) {
			if (a[k] == t[i]) {
				sum++;

				break;

			}
				
		}
	}


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



    return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<vector<pair<int, int>>> edge(N+1, vector<pair<int, int>>());
    for (int i = 0; i < N-1; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        edge[a].push_back({b, c});
        edge[b].push_back({a, c});
    }
    vector<long long> dist(N+1, -1);
    int Q, K;
    cin >> Q >> K;
    dist[K] = 0;
    queue<pair<int, int>> q;
    q.push({K, -1});
    for (int i = 0; i < N; i++) {
        if (q.empty()) break;
        auto p = q.front();
        q.pop();
        int now = p.first;
        int pre = p.second;
        for (pair<int, int> nxt : edge[now]) {
            if (nxt.first == pre) continue;
            dist[nxt.first] = dist[now] + nxt.second;
            q.push({nxt.first, now});
        }
    }
    for (int i = 0; i < Q; i++) {
        int x, y;
        cin >> x >> y;
        printf("%lld\n", dist[x]+dist[y]);
    }
}


Measured memory_bytes: 9204
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
h, w = map(int, raw_input().split())
# 文字列の入力
s = [raw_input() for i in range(h)]

accessible = [(0,0)]
accessible_now = [(0,0)]
n_black = sum([ss.count('#') for ss in s]) 

stroke = 1
while True:
  stroke += 1
  accessible_next = [] 
  for loc in accessible_now:
    for step in [(1,0),(0,1),(-1,0),(0,-1)]:
      loc_next = (loc[0]+step[0],loc[1]+step[1])
      if loc_next == (h-1,w-1):
        print h*w-n_black-stroke 
        exit(0)
      if ((-1 in loc_next) or (loc_next[0]==h) or (loc_next[1]==w)):
        continue
      if loc_next in accessible:
        continue
      if s[loc_next[0]][loc_next[1]] == '#':
        continue
      accessible.append(loc_next)
      accessible_next.append(loc_next)
  accessible_now = accessible_next
  if(len(accessible_next)==0):
    print -1
    exit(0) 


Measured memory_bytes: 2696
N = int(input())
H = list(map(int, input().split()))
ans = 0
r = 0
for i in range(N-2, -1, -1):
    if H[i+1] <= H[i]:
        r += 1
        if r > ans:
            ans = r
    else:
        r = 0
print(ans)


Measured memory_bytes: 85356
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int a[200000];
int main()
{
	int num, kai;
	scanf("%d%d", &num, &kai);
	for (int i = 0; i < num; i++)
	{
		int z;
		scanf("%d", &z);
		a[z - 1]++;
	}
	sort(a, a + num);
	reverse(a, a + num);
	int r = num;
	for (int i = 0; i < kai; i++)r -= a[i];
	printf("%d\n", r);
}

Measured memory_bytes: 896
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
fact = math.factorial
sys.setrecursionlimit(10**9)
INF = 10**9
mod = 10**9+7

N,K = I()
ans = 0
f1 = fact(N-K+1)
f2 = fact(K-1)
for i in range(1,K+1):
    if N-K-i+1 < 0:
        print(0)
        continue
    print((f1*f2//(fact(i)**2//i*fact(N-K-i+1)*fact(K-i)))%mod)

Measured memory_bytes: 80116
n = gets.to_i
a = []
n.times { a << gets.to_i - 1 }

blinked = []
steps = 0
cur = 0
while cur != 1
  steps += 1
  cur = a[cur]
  if blinked[cur]
    puts -1
    exit
  end
  blinked[cur] = true
end

puts steps


Measured memory_bytes: 3892
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

ll ans;
int n;
vector<vector<pi>> e;

int rec(int c, int p, vi &cs){
	int res = 1;
	bool ok = 1;
	vi sz;
	for(pi i : e[c]) if(i.first != p){
		sz.pb(rec(i.first, c, cs));
		res += sz.back();
		ok &= sz.back() * 2 <= n;
	}
	
	int pos = 0;
	for(pi i : e[c]) if(i.first != p){
		ans += 2ll * min(sz[pos], n - sz[pos]) * i.second;
		pos++;
	}
	if(ok && 2 * (n - res) <= n) cs.pb(c);
	
	return res;
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	cin >> n;
	e.resize(n);
	rep(i, n - 1){
		int a, b, c; cin >> a >> b >> c; a--; b--;
		e[a].emplace_back(b, c);
		e[b].emplace_back(a, c);
	}
	vi cs;
	rec(0, 0, cs);
	
	assert(cs.size() <= 2 && cs.size());
	if(cs.size() == 2){
		int a = cs[0], b = cs[1];
		for(pi i : e[a]) if(i.first == b) ans -= i.second;
	}
	else{
		int mn = inf;
		for(pi i : e[cs[0]]) mn = min(mn, i.second);
		ans -= mn;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 16512
def make_divisors(n: int) -> list:
    return_list = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            return_list.append(i)
            if i != n // i:
                return_list.append(n//i)

    return sorted(return_list)

X = int(input())
list = make_divisors(X)
mlist = []
for li in list[::-1]:
    mlist.append(-li)
mlist += list
B = -120
while True:
    for i in mlist:
        if ((B + i) ** 5) - (B ** 5) == X:
            print(B+i,B)
            exit()
    B += 1



Measured memory_bytes: 9344
import java.util.*;

public class Main {
	
	int gcd(int x, int y) {
		if (x < y) {
			int tmp = x;
			x = y;
			y = tmp;
		}
		if (x % y == 0) return y;
		return gcd(y, x%y);
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int y = scan.nextInt();
		System.out.println(new Main().gcd(x,y));
	}

}



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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

vector<ll> ans;

void dfs(ll now) {
    ans.push_back(now);
    if (now > 3234566667) return;
    ll last = now % 10;
    if (last != 0) dfs(now * 10 + last - 1);
    dfs(now * 10 + last);
    if (last != 9) dfs(now * 10 + last + 1);
}

void solve() {
    ll K;
    cin >> K;
    rep2(i, 1, 10) {
        dfs(i);
    }
    sort(ans.begin(), ans.end());
    cout << ans[K - 1] << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 6512
#include <iostream>
#include "math.h"
using namespace std;
int main(int argc, const char * argv[]) {
    int a, b, x;
    int c, d;
    int m;
    string s;
    
    m = 0;
    
    //round up
    cin>> a>>b;
    x = a+b;
    if (x<0){
        x*=-1;
    }
    if (x%2==0){
        x =x/2;
    }
    else{
        x = x/2+1;
    }
    cout << x;
    
    //sea battle
//    x = 0;
//    cin>> a>>b; //w1, h1
//    cin>> c>>d; //w2, h2
//    //find perimiter
//    //add number of corners
//
//    //find perimeter
//    m = m+ a + (2*b) + c + (2*d);
//    //add the difference between the 2 widths
//    x = a-c;
//    m+=x;
//
//    //add number of corners;
//    m+=4;
//    cout << m;
    
    //back to unlock
//    string password = "";
//    bool unlock = false;
//    cin>> password;
//    cin>> a;
//    string enemyWord[a];
//    for (int i = 0; i< a; i++){
//        cin>> enemyWord[i];
//    }
//        //check if there is a direct word that contain paasword
//    for (int i = 0; i < a; i++){
//        if (enemyWord[i] == password){
//            unlock = true;
//        }
//    }
//        //if end and start of word
//    for (int i = 0; i<a; i++ ){
//        if (enemyWord[i][1] == password[0]){
//            for (int j = 0; j< a; j++){
//                if (enemyWord[j][0] == password[1]){
//                    unlock = true;
//                }
//            }
//        }
//    }
//    if (unlock){
//        cout<< "YES";
//    }
//    else {
//        cout << "NO";
//    }
    //good distance
//    m = 0;
//    cin>> a;
//    cin>> b;
//    int points[a][b];
//    for (int i = 0; i< a; i++){
//        for (int j = 0; j< b; j++){
//            cin>> points[i][j];
//        }
//    }
//    for (int i = 0; i< a; i++){
//        for (int j = i+1; j< a; j++){ //comparison of  points
//            if (i==j){
//                continue;
//            }
//            //find distance as a double
//            double distance = 0;
//            for (int h = 0; h< b; h++){
//                distance+=(points[i][h] - points[j][h]) * (points[i][h] - points[j][h]);
//            }
//            // square root it
//            distance = sqrt(distance);
//
//            //see if it is integer;
//            x = 0;
//            x = (int)(distance);
//            if (distance - x == 0){
//                m++;
//            }
//
//
//
//        }
//    }
//    cout << m;
//
    
    
    
    return 0;
}

Measured memory_bytes: 256
using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
      string[] input = ReadLine().Split();
      string a = input[0];
      string b = input[1];
      if (string.Compare(a , b) <0)
      {
        WriteLine("<");
      }
      else if ((string.Compare(a , b) == 0))
      {
        WriteLine("=");
      }
      else
      {
        WriteLine(">");
      }
      
    }
}

Measured memory_bytes: 26128
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n,k;
    in>>n>>k;
    vector<ll> h(n+2);
    Fr(i,n) in>>h[i];
    const ll inf=1ul<<60u;
    vector<vector<ll>> dp(n+2,vector<ll>(k+1,inf));
    dp[0][0]=0;
    Fr(i,n+1){
        fr(j,k+1){
            fr(l,j+1){
                if(i<=l) break;
                dp[i][j]=min(dp[i][j],dp[i-l-1][j-l]+max(0ll,h[i]-h[i-l-1]));
            }
        }
    }
    ll ans{inf};
    fr(j,k+1) ans=min(ans,dp[n+1][j]);
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func main() {
	var n, m int
	fmt.Scanf("%d", &n)
	fmt.Scanf("%d", &m)

	d := float64(m)

	var cnt int

	scn := bufio.NewScanner(os.Stdin)
	scn.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		scn.Scan()
		x, _ := strconv.Atoi(scn.Text())
		scn.Scan()
		y, _ := strconv.Atoi(scn.Text())
		dist := math.Sqrt(float64(x*x + y*y))
		if dist <= d {
			cnt++
		}
	}

	fmt.Println(cnt)
}


Measured memory_bytes: 4988
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------

int h, w;
vector<string> f;
bool visited[500][500] = {false};

ll black = 0;
ll white = 0;
void dfs(int y, int x){
    bool isBlack;
    visited[y][x] = true;
    if(f[y][x] == '#'){
        isBlack = true;
        black++;
    } else {
        isBlack = false;
        white++;
    }

    for(int i = 0; i < 4; i++){
        int nextx = x + dx4[i];
        int nexty = y + dy4[i];
        if(visited[nexty][nextx]) continue;
        if(nextx < 0 || nextx >= w || nexty < 0 || nexty >= h){
            continue;
        }

        if(isBlack){
            if(f[nexty][nextx] == '#'){
                continue;
            }
        } else {
            if(f[nexty][nextx] == '.'){
                continue;
            }
        }

        dfs(nexty, nextx);
    }
}

int main(void){
    cin >> h >> w;

    f.resize(h);

    for(int i = 0; i < h; i++) cin >> f[i];

    ll ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(visited[i][j])continue;
            if(f[i][j] == '#'){
                black = 0;
                white = 0;
                dfs(i, j);
                ans += black * white;
            }
        }
    }

    cout << ans << endl;

}


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

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

            if(S.Length%2!=0)
            {
                Console.WriteLine("No");
                return;
            }
            for(var i=0;i<S.Length;i+=2)
            {
                if(S[i]!='h'|| S[i+1] != 'i')
                {
                    Console.WriteLine("No");
                    return;
                }
            }
            Console.WriteLine("Yes");
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
using namespace std;
using namespace __gnu_pbds;
using ll = int64_t;
using ld = long double;
using ull = uint64_t;
using pl = pair<ll, ll>;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

vector<ll> v;
ll med, n;

int main() {
  ios::sync_with_stdio(0);
  cout.precision(10);

  cin >> n;
  v.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    med += v[i];
    v[i] *= n;
  }

  ll ind = 0;

  for (int i = 1; i < n; i++) {
    if (abs(med-v[i]) < abs(med-v[ind])) {
      ind = i;
    }
  } 
  cout << ind << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,l,ans,numbers[300],kensaku[300],kagi;

int main(){
    cin>>n>>l;
    ans=((n+1)*n)/2+n*l-n;
    for (int i=1; i<=n; i++) {
        numbers[i]=l+i-1;
        kensaku[i]=abs(l+i-1);
    }
    sort(kensaku,kensaku+n+1);
    for (int i=1; i<=n; i++) {
        if (numbers[i]-kensaku[1]==0||numbers[i]+kensaku[1]==0) {
            kagi=i;
            break;
        }
    }
    cout<<ans-numbers[kagi]<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)
vector<vector<char>> s;
vector<vector<int>> ans;
int h, w;
int num = 1;
void cut(int k, int hs, int ws, int hf, int wf)
{
    // cout << " " << num << endl;
    if (k == 1)
    { //色塗り
        repi(i, hf, hs)
        {
            repi(j, wf, ws)
            {
                ans[i][j] = num;
            }
        }
        num++;
    }
    else
    { //切り分け
        //横割り
        int cnt = 0;
        repi(i, hf, hs)
        {
            repi(j, wf, ws)
            {
                if (s[i][j] == '#')
                {
                    cnt++;
                }
            }
            if (cnt > 0 && cnt < k )
            {
                cut(cnt, hs, ws, i + 1, wf);
                cut(k - cnt, i + 1, ws, hf, wf);
                return;
            }
        }
        //縦割り
        cnt = 0;
        repi(j, wf, ws)
        {
            repi(i, hf, hs)
            {
                if (s[i][j] == '#')
                {
                    cnt++;
                }
            }
            if (cnt > 0)
            {
                cut(cnt, hs, ws, hf, j + 1);
                cut(k - cnt, hs, j + 1, hf, wf);
                return;
            }
        }
    }
}
int main()
{
    int k;
    cin >> h >> w >> k;
    s.resize(h, vector<char>(w));
    ans.resize(h, vector<int>(w));

    repi(i, h, 0)
    {
        repi(j, w, 0)
        {
            cin >> s[i][j];
        }
    }

    cut(k, 0, 0, h, w);

    repi(i, h, 0)
    {
        repi(j, w, 0)
        {
            cout << ans[i][j] << ((j + 1) % w ? " " : "\n");
        }
    }
    return 0;
}

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

int main() {

    int H, A;
    cin >> H >> A;

    cout << (H + A - 1) / A << endl;

    return 0;
}

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

int main() {
    int a,b;
    cin >> a >> b;
    if(b%a == 0)cout << a+b << endl;
    else cout << b-a << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

ll mod=1000000007;

const ll INF = 1LL << 60;

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


int main() {
  int k,n;cin >> k >> n;
  int stats;cin >> stats;
  int acur=stats;
  int mx=0;
  int last;
  rep(i,n-1){int a;cin >> a; chmax(mx,abs(a-acur));acur=a;last=a;}
  chmax(mx,stats+(k-last));
  cout << k-mx;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split(' ');
        int N = int.Parse(s[0]);
        int M = int.Parse(s[1]);
        int[] a = new int[N];
        int[] b = new int[N];
        for (int i = 0; i < N; i++)
        {
            s = Console.ReadLine().Split(' ');
            a[i] = int.Parse(s[0]);
            b[i] = int.Parse(s[1]);
        }
        int[] c = new int[M];
        int[] d = new int[M];
        for (int i = 0; i < M; i++)
        {
            s = Console.ReadLine().Split(' ');
            c[i] = int.Parse(s[0]);
            d[i] = int.Parse(s[1]);
        }

        for (int i = 0; i < N; i++)
        {
            int min = int.MaxValue;
            int ans = 0;
            for (int j = 0; j < M; j++)
            {
                int dis = Math.Abs(c[j] - a[i]) + Math.Abs(d[j] - b[i]);
                if (dis < min)
                {
                    min = dis;
                    ans = j + 1;
                }
            }
            Console.WriteLine(ans);
        }
    }
}


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

int main()
{
    int64_t n, a, b;
    cin >> n >> a >> b;
    if (n % (a + b) > a)
    {
        cout << (n / (a + b)) * a + a << endl;
    }
    else
    {
        cout << (n / (a + b)) * a + n % (a + b) << endl;
    }
}

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

#define PRIME 0
#define NOT_PRIME 1

long sieve(long n)
{
    long i, j, *a;
    long count = 0;

    if ((a = calloc(n + 1, sizeof(long))) == NULL) {
        printf("allocation failed\n");
        exit(EXIT_FAILURE);
    }

    for (i = 2; i * i <= n; i++)
        if (a[i] == PRIME)
            for (j = 2 * i; j <= n; j += i)
                a[j] = NOT_PRIME;

    for (i = 2; i <= n; i++)
        if (a[i] == PRIME)
            count++;

    free(a);

    return count;
}

int main(void)
{
    long n;

    while (scanf("%ld", &n) != EOF)
        printf("%ld\n", sieve(n));

    return 0;
}

Measured memory_bytes: 9136
cards = [*1..10]
while gets
    m1, m2, y1 = $_.chomp.split.map(&:to_i)
    left = cards - [m1, m2, y1]
    puts ((left.select{|x| 20 - (m1 + m2) >= x}.size).to_f / (10 - 3) >= 0.5)?"YES":"NO"
end

Measured memory_bytes: 6112
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#include <time.h>
#include <ctype.h>

int cmp(const void *a, const void *b) { return *(int*)a - *(int*)b; }
int max(int a, int b) { return a >= b ? a : b; }
int min(int a, int b) { return a <= b ? a : b; }
int dsum(int x) { int r=0; while(x){ r+=(x%10); x/=10; } return r;}
void swap(int *a, int *b) { int tmp; tmp = *a; *a = *b; *b = tmp; return; }

int main(void) {
  int a,b;
  scanf("%d%d",&a,&b);
  printf("%d\n",abs(b-a));
  return 0;
}


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

using namespace std;

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

	if (a * b > c * d) {
		cout << a * b << endl;
	}
	else {
		cout << c * d << endl;
		return 0;
	}
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
 
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
 
using namespace std;
 
typedef pair<long long int, long long int> P;
long long int INF = 1e18;

#define MAX_V 110000

int N;

struct edge{
	int to;
	long long int cost;
};

vector<edge> G[MAX_V];
long long int d[MAX_V];

// 速さはO(|E|log|V|)

void shortest_path(int s, int V){ // Vは頂点数
	
	priority_queue<P, vector<P>, greater<P> > que;
	
	for(int i = 0; i < V; i++){
		d[i] = INF;
	}
	d[s] = 0;
	
	que.push(P(0, s));
	
	while(!que.empty()){
		
		P p = que.top();
		que.pop();
		
		int v = p.second;
		
		if(d[v] < p.first){
			continue;
		}
		
		for(int i = 0; i < G[v].size(); i++){
			edge e = G[v][i];
			if(d[e.to] > e.cost + d[v]){
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		} // 頂点への最小コストを更新
	}
}

long long int cnt1[310000] = {}, cnt2[310000] = {};

int main(){
	
	long long int N, M, s, t;
	cin >> N >> M >> s >> t;
	s--;
	t--;
	
	for(int i = 0; i < M; i++){
		edge e;
		e.cost = 1;
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		e.to = v;
		G[u].push_back(e);
		e.to = u;
		G[v].push_back(e);
	}
	
	shortest_path(s, N);
	
	for(int i = 0; i < N; i++){
		if(d[i] <= M){
			cnt1[d[i]]++;
		}
	}
	
	int dist = d[t];
	
	shortest_path(t, N);
	
	for(int i = 0; i < N; i++){
		if(d[i] <= M){
			cnt2[d[i]]++;
		}
	}
	
	long long int ans = 0;
	
	for(int i = 0; i <= dist - 2; i++){
		ans += cnt1[i] * cnt2[dist - i - 2];
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 16452
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while (scan.hasNextInt()) {
            int n = scan.nextInt();

            int sosu = 0;
            if (n >= 2) {
                sosu++;// 2の分個数を足しておく
            }
            for (int x = 3; x <= n; x += 2) {
                int notSosuFlag = 0;
                for (int i = 3; i * i <= x && notSosuFlag == 0; i += 2) {
                    if (x % i == 0) {
                        notSosuFlag = 1;
                    }
                }

                if (notSosuFlag == 0) {
                    sosu++;
                }
            }

            System.out.println(sosu);
        }
    }
}



Measured memory_bytes: 26540
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define pp pair<int,int>
#define ll long long
#define ld long double
int inf=100000000;
ll INF=4000000000000000000;
ll MOD=1000000007;


int main() {
   ll n;
   cin >> n;
   ll ans=inf;
   for (ll i=1;i<inf;i++){
      if (i*i>n) break;
      if (n%i==0){
         ll k=max(n/i,i);
         ll u=0;
         while (true){
            u++;
            k=k/10;
            if (k==0) break;
         }
         //if (u==3) cout << i << endl;
         ans=min(ans,u);
      }
   }
   cout << ans << endl;
  }

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	char c[3],a[3];
	for(int i=0;i<3;i++)
		cin>>c[i];
		for(int i=0;i<3;i++)
			cin>>a[i];
	if(c[0]==a[2]&&c[1]==a[1]&&c[2]==a[0])
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
} 

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int H = sc.nextInt();
      	int A = sc.nextInt();
      	if(H%A ==0) System.out.println(H/A);
      	else System.out.println((H/A)+1);
    }
}

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

int main() {
	string s;
	cin >> s;
	int n  = (int)s.size();
	int ans = 1e9;
	for (int i = 1; i  + 1 < n; ++i) {
		int p = (s[i] - '0') * 10 + (s[i + 1] - '0') + (s[i - 1] - '0')*100;
		ans = min(ans,abs(p - 753));
	}
	cout << ans;
}


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

int main() {
	int n,k;
	cin>>n>>k;
	int h[n+1],ans[n+1];
	for(int i=1;i<=n;i++){
	    cin>>h[i];
	    ans[i]=INT_MAX;
	}
	ans[1]=0;
	for(int i=1;i<=n;i++){
	    for(int j=1;j<=k;j++){
	        if(j+i<=n)
	        ans[i+j]=min(ans[i+j],ans[i]+abs(h[i+j]-h[i]));
	    }
	}
// 	for(int i=1;i<=n;i++){
// 	    cout<<
// 	}
cout<<ans[n];
	
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<stack>
using namespace std;
string s;stack<bool>S;
main()
{
	cin>>s;
	int ans=0;
	for(int i=0;i<s.size();i++)
	{
		bool now=s[i]%2;
		if(!S.empty()&&S.top()!=now)
		{
			S.pop();
			ans+=2;
		}
		else S.push(now);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};
constexpr int N_MAX = 1000001;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string s;
    cin >> s;
    int n = s.length();

    bool carried = false;
    vector<vector<ll>> dp(n+1, vector<ll>(2, LINF)), carry(n+1, vector<ll>(2, 0));
    dp[n][0] = 0LL;
    dp[n][1] = 0LL;
    for(int i=n;i>0;--i) {
        for(int j=0;j<2;++j) {
            int digit = int(s[i-1]-'0');
                
            if(dp[i][j] + (digit+carry[i][j])%10 < dp[i-1][0]) {
                carry[i-1][0] = (digit+carry[i][j])/10;
                dp[i-1][0] = dp[i][j] + (digit+carry[i][j])%10;
            }

            if(dp[i][j] + (carry[i][j]?9:10) - digit%10 < dp[i-1][1]) {
                carry[i-1][1] = 1;
                dp[i-1][1] = dp[i][j] + (carry[i][j]?9:10) - digit%10;
            }
        }
    }

    ll ans = min(dp[0][0] + carry[0][0], dp[0][1] + carry[0][1]);
    cout << ans << endl;
}


Measured memory_bytes: 110620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll MOD = 1e9+7;
const static ll INF = 1e14;

ll N;
ll A[23][23];
ll DP[(int)(1e7)];
ll POW[23];

int rec(bitset<23> B, int cnt, int idx){
    if(cnt == N) return DP[idx] = 1;
    if(DP[idx] != -1) return DP[idx];
    
    ll res = 0;
    for(int i = 0; i < N; i++){
        if(A[cnt][i] == 1 && !B[i]) {
            B.set(i);
            res += rec(B, cnt+1, idx+POW[i]);
            res %= MOD;
            B.reset(i);
        }
    }
    return DP[idx] = res%MOD;;

}



int main() {
    cin >> N;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++) cin >> A[i][j];
    }
    for(int i = 0; i <= N; i++) POW[i] = pow(2, i);
    for(int i = 0; i <= POW[N]; i++) DP[i] = -1;
    bitset<23> B = 0;
    cout << rec(B, 0, 0) << endl;

}


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

int main(){
    string s;
    bool f=true;
    cin >> s;
    for(int i=0;i<3;i++){
        if(s[i] == s[i+1]){
            f=false;
        }
    }
    if(f){
        cout << "Good";
    }else{
        cout << "Bad";
    }
}

Measured memory_bytes: 256
import heapq as hq

def bfs(connections:list,s,t):
    inf = float('inf')
    costs =[[inf,inf,inf] for i in connections]
    visited = [[False,False,False] for i in connections]
    costs[s][0]=0
    q =[]
    hq.heappush(q,(0,0,s))

    while q:
        cost,step,node = hq.heappop(q)
        if visited[node][step]:
            continue
        visited[node][step] = True
        
        for target in connections[node]:
            if costs[target][(step+1)%3]>cost+1:
                costs[target][(step+1)%3]=cost+1
                hq.heappush(q,(cost+1,(step+1)%3,target)) 

    ans = costs[t][0]

    if ans == inf:
        print(-1)
    else:
        print(ans // 3)               


    



def resolve():
    N,M = map(int,input().split())

    connections = [[] for i in range(N)]
    for i in range(M):
        u,v = map(int,input().split())
        connections[u-1].append(v-1)

    S,T = map(int,input().split())

    bfs(connections,S-1,T-1)



if __name__ == "__main__":
    resolve()

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

int N;
vector <pair<int, int> > r;
vector <pair<int, int> > b;
vector <int> used;
int ans;

void solve(){
  for(int i=0; i<N; i++){
    for(int j=N-1; j>=0; j--){
      if(used[j]==1)continue;
      if(b[i].first > r[j].second && b[i].second > r[j].first){
        used[j]=1;
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;
}

int main(void){
  cin >> N;
  r.resize(N);
  b.resize(N);
  used.resize(N);

  for(int i=0; i<N; i++){
    int x, y;
    cin >> x >> y;
    r[i]=make_pair(y, x);
  }

  for(int i=0; i<N; i++){
    int x, y;
    cin >> x >> y;
    b[i]=make_pair(x, y);
  }

  sort(r.begin(), r.end());
  sort(b.begin(), b.end());
  solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);i++)
#define Rep(i,a,b) for(int i=(a);i>=(b);i--)
const int N=2e5+7; 
typedef long long LL;
using namespace std;
int n,m,ans;

template<typename T> void read(T &x) {
    T f=1; x=0; char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') f=-1,ch=getchar();
    for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;
}

struct node {
    int l,r;
    friend bool operator <(const node&A,const node&B) {
        return A.r>B.r||(A.r==B.r&&A.l<B.l);
    }
}p[N];

#define lc x<<1
#define rc (x<<1|1)
#define mid ((l+r)>>1)
int sg[N<<2],lz[N<<2];
void build(int x,int l,int r) {
    if(l==r) { sg[x]=-l; return; }
    build(lc,l,mid); build(rc,mid+1,r);
    sg[x]=max(sg[lc],sg[rc]); 
}

void down(int x,int l_len,int r_len) {
    if(l_len) sg[lc]+=lz[x],lz[lc]+=lz[x];
    if(r_len) sg[rc]+=lz[x],lz[rc]+=lz[x];
    lz[x]=0;
}

int qry(int x,int l,int r,int ql,int qr) {
    if(ql>qr) return 0;
    if(l>=ql&&r<=qr) return sg[x];
    down(x,mid-l+1,r-mid);
    if(qr<=mid) return qry(lc,l,mid,ql,qr);
    if(ql>mid) return qry(rc,mid+1,r,ql,qr);
    return max(qry(lc,l,mid,ql,qr),qry(rc,mid+1,r,ql,qr)); 
}

void update(int x,int l,int r,int ql,int qr,int v) {
    if(l>=ql&&r<=qr) {
        sg[x]+=v; lz[x]+=v; return;
    } 
    down(x,mid-l+1,r-mid);
    if(ql<=mid) update(lc,l,mid,ql,qr,v);
    if(qr>mid) update(rc,mid+1,r,ql,qr,v);
    sg[x]=max(sg[lc],sg[rc]); 
}

int main() {
    read(n); read(m); int pp=0;
    For(i,1,n) {
        read(p[i].l); read(p[i].r);
        if(p[i].l==0&&p[i].r>m) pp++,i--,n--;
    }
    sort(p+1,p+n+1);
    build(1,1,m+1); 
    For(i,1,n) {
        update(1,1,m+1,p[i].l+1,m+1,1);
        ans=max(ans,sg[1]+1-(m-p[i].r+1));
    }
    ans=max(n-m,ans)+pp;
    printf("%d\n",ans);
    return 0;
}

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

int main(){
  
  int i,s_size,x,ans=0;
  string s;
  cin >> s;
  
  s_size = s.size();
  x = s_size/2;
  for(i=0;i<x;i++){
    if(s.at(i)!=s.at(s_size-i-1))
      ans++;
  }
  
  cout << ans;
  
}

Measured memory_bytes: 384
import java.util.Scanner;

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

        long a = in.nextLong();
        long b = in.nextLong();

        long d = gcd(a, b);
        long p = 2;
        int cnt = 0;
        while (p * p <= d) {
            if (d % p == 0) cnt++;
            while (d % p == 0) {
                d /= p;
            }
            p++;
        }
        if (d > 1) {
            cnt++;
        }

        System.out.println(cnt + 1);
    }

    private static long gcd(long a, long b) {
        if (b == 0) return a;
        return gcd(b, a % b);
    }
}


Measured memory_bytes: 23764
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

char s[200005];
int cunt[27];

int main()
{
	scanf( "%s", s );
	int len = strlen(s);
	for(int i = 0; i < len; ++i)
		cunt[s[i] - 'a']++;
	unsigned long long ans = 0;
	for(int i = 0; i < 27; ++i)
		for(int j = i + 1; j < 27; ++j)
			ans += 1LL * cunt[i] * cunt[j];
	cout << ans + 1 << endl;
}

Measured memory_bytes: 384
n, q = [int(i) for i in input().split(" ")]
s = input()
qs = [[]] * q

for i in range(0, q):
    qs[i] = input().split(" ")

def dest(i):
    global s
    global n
    global qs
    cur = i
    for qsi in qs:
        if s[cur] == qsi[0]:
            if qsi[1] == "R":
                cur += 1
                if cur >= n:
                    return cur
            else:
                cur -= 1
                if cur < 0:
                    return cur
    return cur

def sL(l, r):
    if l == r:
        return l
    h = (l + r) // 2
    if dest(h) < 0:
        return sL(h + 1, r)
    else:
        return sL(l, h)
    
def sR(l, r):
    global n
    if l == r:
        return l
    h = (l + r) // 2
    if dest(h) < n:
        return sR(h + 1, r)
    else:
        return sR(l, h)
    
print(sR(0, n) - sL(0, n))

Measured memory_bytes: 39472
#include <stdio.h>

int main() {
  long double n, t = 0.0;
  int k;
  scanf("%Lf %d", &n, &k);
  for (int i = 0; i < n; i++) {
    int s = i + 1;
    long double l = 1.0/n;
    while (s < k) {
      s *= 2;
      l *= 1.0/2.0;
    }
    t += l;
  }
  printf("%.12Lf\n", t);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i=1; i < (int)(n); i++)
#define rrep(i, n) for (int i=((int)(n)-1); i>=0; i--)
#define rreps(i, n) for (int i=((int)(n)-1); i>0; i--)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using lint = long long;
using p = pair<int, int>;
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; }

int main() {
  int N; cin >> N;
  vector<double> a(N);
  rep (i, N) cin >> a[i];
  double x = 0;
  rep (i, N) {
    x += 1. / a[i];
  }
  cout << setprecision(15) << 1./x << endl;
  return 0;
}


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

int main() {

    char b;
    cin >> b;

    if (b == 'A') cout << "T";
    if (b == 'T') cout << "A";
    if (b == 'C') cout << "G";
    if (b == 'G') cout << "C";

    return 0;
        
}

Measured memory_bytes: 256
// 500, 100, 50
function main(input) {
  const input_array = input.split("\n");
  const coins_count = input_array.slice(0,3);

  const a = parseInt(input_array[0], 10);
  const b = parseInt(input_array[1], 10);
  const c = parseInt(input_array[2], 10);
  const desired_sum = parseInt(input_array[3], 10);
  
  var answer = 0;
  for(i=0; i<=a; ++i){
    for(j=0; j<=b; ++j){
      for(k=0; k<=c; ++k){
        if (500 * i + 100 * j + 50 * k == desired_sum){
          answer+=1;
        }
      }
    }
  }
  
  console.log(answer);
}
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
#include <iostream>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <unordered_map>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

unordered_map<int,int> cand;

bool check() {
    for (auto& entry:cand) {
        int cnt=entry.second;
        if (cnt<0) return false;
    }
    return true;
}

int main()
{
    int n,m;
    int d,t;
    scanf("%d",&n);
    for (int i=0;i<n;i++) {
        scanf("%d",&d);
        cand[d]++;
    }
    scanf("%d",&m);
    for (int i=0;i<m;i++) {
        scanf("%d",&t);
        cand[t]--; 
    }
    if (check()) printf("YES\n");
    else printf("NO\n");
}


Measured memory_bytes: 8520
#include<iostream>
#include<queue>
#include<functional>
using namespace std;

int main(){
    int n, t;
    while(cin >> n){
        priority_queue<int, vector<int>, greater<int> > pq;
        for(int i = 0; i < n; i++){
            cin >> t;
            pq.push(t); 
        }
        int sum = 0, ans = 0;
        while(!pq.empty()){
            sum += pq.top();
            pq.pop();
            ans += sum;
        }
        cout << ans << endl;
    }
}

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

const int MAXN = 2000;
using bs = bitset<MAXN>;
int N;
vector<int> Tadj[MAXN];
bs onPath[MAXN][MAXN];

int M;
bs Gadj[MAXN];

void dfs(int root, int cur, int prv = -1) {
	onPath[root][cur][cur] = true;
	for (int nxt : Tadj[cur]) {
		if (nxt == prv) continue;
		onPath[root][nxt] = onPath[root][cur];
	}
	for (int nxt : Tadj[cur]) {
		if (nxt == prv) continue;
		dfs(root, nxt, cur);
		onPath[root][cur] |= onPath[root][nxt];
	}
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N >> M;
	for (int i = 0; i < N-1; i++) {
		int a, b; cin >> a >> b; a--, b--;
		//int a = i, b = i+1;
		Tadj[a].push_back(b);
		Tadj[b].push_back(a);
	}
	vector<pair<int, int>> edges;
	for (int i = 0; i < M; i++) {
		int a, b; cin >> a >> b; a--, b--;
		//int a = i%N, b = (i+1)%N;
		Gadj[a][b] = Gadj[b][a] = true;
		edges.emplace_back(a, b);
	}

	for (int i = 0; i < N; i++) {
		dfs(i, i);
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			onPath[i][j] |= onPath[j][i];
		}
	}

	for (int i = 0; i < N; i++) {
		Gadj[i][i] = true;
	}

	for (int e = 0; e < int(edges.size()); e++) {
		int i, j; tie(i,j) = edges[e];
		assert(Gadj[i][j]);
		assert(Gadj[j][i]);
		bs cnds = onPath[i][j] & (Gadj[i] ^ Gadj[j]);
		for (int k = cnds._Find_first(); k < cnds.size(); k = cnds._Find_next(k)) {
			if (Gadj[j][k] == false) {
				Gadj[j][k] = Gadj[k][j] = true;
				edges.emplace_back(j, k);
			} else if (Gadj[i][k] == false) {
				Gadj[i][k] = Gadj[k][i] = true;
				edges.emplace_back(i, k);
			}
		}
	}

	cout << edges.size() << '\n';
	return 0;
}


Measured memory_bytes: 1019500
#include<stdio.h>

int main()
{
    int n;
    long long a, count{};

    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
    {
        scanf("%lld", &a);
        for (; !(a % 2); a /= 2)
            ++count;
    }
    printf("%lld\n", count);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    int k,s;
    cin>>k>>s;
    int cnt=0;
    rep(i,k+1){
        rep(j,k+1){
            if(i+j+k>=s&&i+j<=s) ++cnt;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
data = Array.new()
i = 0


while data[i] = gets do
	i += 1
end



j = 0

number = Array.new()
while out = data[j]
	out = out.chomp
	number[j] = out.to_i
	j += 1
end

ten = Array.new(100,0)
number = number.sort
score = number.uniq

i=0
j=0
k=0

for i in score do
	for j in number do
		if i == j
			ten[k] = ten[k] + 1
		end
	end
	k += 1;
end

max = ten.max

i = 0
k = 0

for i in ten do
	if i == max 
		 p score[k]
	end
	k += 1
end 

Measured memory_bytes: 8628
#include<bits/stdc++.h>
using namespace std ; 
long long int dp[3001][3001][2] ; 
long long int solve(int& n,vector<int>& l,int i,int j,int turn){
    if(i>j){
        //invalid subarray . 
        return 0 ; 
    }
    if(dp[i][j][turn]!=-1){
        return dp[i][j][turn] ; 
    }
    //otherwise . 
    if(turn==0){
        return dp[i][j][turn]=max(l[i]+solve(n,l,i+1,j,1),l[j]+solve(n,l,i,j-1,1)) ; 
    }else{
        return dp[i][j][turn]= min(solve(n,l,i+1,j,0),solve(n,l,i,j-1,0)) ; 
    }

}
int main(){
    int n ; cin>>n ; 
    vector<int> l(n+1) ; 
    for(int i =1 ; i<=n; i++){
        cin>>l[i]  ; 
    }
    //list use karke we can access both ends . 
    long long int sum = 0 ; 
for(int i =1 ; i<=n ; i++){
    sum+=l[i] ; 
}
   memset(dp,-1,sizeof(dp)) ; 
   long long int scorex = solve(n,l,1,n,0) ; 
   long long int scorey = sum-scorex ; 
   cout<<scorex-scorey<<"\n" ; 
   
   return 0 ; 
}


Measured memory_bytes: 141184
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>

using namespace std;


int factor[1005];

int main(){
  int n;cin>>n;
  for(int i=2;i<=n;i++){
    int tmp = i;
    for(int j=2;j<=i;j++){
      while(tmp%j == 0){
        factor[j]++;
        tmp/=j;
      }
    }
  }
  long long ans = 1LL;
  for(int i=2;i<=n;i++){
    ans *= (long long)(factor[i]+1LL);
    ans %= 1000000007LL;
  }
  cout<<ans<<endl;

}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

  char c;
	
  if(scanf("%c", &c)==0) return -1;
  if(c=='A')	putchar('T');
  else if(c=='C')	putchar('G');
  else if(c=='G') putchar('C');
  else putchar('A');
  
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>

using namespace std;

void out_win(char x){
	if(x=='a'){
		cout << "A" << endl;
		return;
	}else if(x=='b'){
		cout << "B" << endl;
		return;
	}else if(x=='c'){
		cout << "C" << endl;
		return ;
	}
}

int main(){
	string SA,SB,SC;
	cin >> SA >> SB >> SC;
	
	int index_a=0,index_b=0,index_c=0;
	
	char now_chr='a';
	
	while(1){
		//a
		if(now_chr=='a'){
			if(index_a>=SA.size()){
				out_win(now_chr);
				return 0;
			}
			now_chr=SA[index_a];
			index_a++;
		//b	
		}else if(now_chr=='b'){
			if(index_b>=SB.size()){
				out_win(now_chr);
				return 0;
			}
			now_chr=SB[index_b];
			index_b++;
		//c	
		}else if(now_chr=='c'){
			if(index_c>=SC.size()){
				out_win(now_chr);
				return 0;
			}
			now_chr=SC[index_c];
			index_c++;
		}
	}
	
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] num = new int[10];
        for(int i=0; i<4; i++){
            int n = sc.nextInt();
            num[n]++;            
        }

        if(num[1] == 1 && num[9] == 1 && num[7] == 1 && num[4] == 1){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 22608
#include<iostream>
using namespace std;
 
int main(){
   int a, b;
   cin >> a >> b;
   int k, l, m;
   k = a+(a-1);
   l = a+b;
   m = b+(b-1);
   cout << max(max(k, l),m) <<endl;
  return 0;
}

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

int main() {
  int k,s,cnt=0;
  cin >> k >> s;
   for(int i=0;i<=k;i++){
     for(int j=0;j<=k;j++){
       int z=s-i-j;
       if(z>=0 && z<=k){
        cnt++;
       }
     }
   }
  cout << cnt <<endl;
}

Measured memory_bytes: 256