akhauriyash/Code-Regression huggingface dataset:
//Link : https://atcoder.jp/contests/abc152/tasks/abc152_f

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

#define N 51
#define M 8
vector<int> edge[N];
int a[N],b[N];

int anc[N];
int parEdge[N],depth[N];

void dfs(int node,int par) {
  for(int i=0;i<edge[node].size();++i) {
    int eid = edge[node][i];
    int ch = a[eid]^b[eid]^node;
    if(ch==par) {
      continue;
    }
    anc[ch] = node;
    depth[ch] = depth[node] + 1;
    parEdge[ch] = eid;
    dfs(ch,node);
  }
}

#define EDGE 20
int x[EDGE],y[EDGE];
bool isColored[N];
void paint(int u,int v) {
  if(depth[u]<depth[v]) {
    swap(u,v);
  }
  int diff = depth[u] - depth[v];
  for(int i=0;i<diff;++i) {
    isColored[parEdge[u]] = true;
    u = anc[u];
  }
  while(u!=v) {
    isColored[parEdge[u]] = true;
    isColored[parEdge[v]] = true;
    u = anc[u];
    v = anc[v];
  }
}
ll color(int bit,int n,int m) {
  ll ret = 1;
  memset(isColored,0,sizeof(isColored));
  for(int i=0;i<m;++i) {
    if(bit&(1<<i)) {
      paint(x[i],y[i]);
    }
  }
  for(int i=0;i<n-1;++i) {
    if(!isColored[i]) {
      ret = ret*2;
    }
  }
  return ret;
}
int bitCount(int x) {
  int ret = 0;
  while(x>0) {
    ++ret;
    x = x&(x-1);
  }
  return ret;
}
void solve() {
  int n;scanf("%d ", &n);
  ll ret = 1;
  for(int i=0;i<n-1;++i) {
    scanf("%d %d ", &a[i],&b[i]);
    edge[a[i]].push_back(i);
    edge[b[i]].push_back(i);
    ret *= 2;
  }
  dfs(1,0);
  int m;scanf("%d ", &m);
  for(int i=0;i<m;++i) {
    scanf("%d %d ", &x[i],&y[i]);
    paint(x[i],y[i]);
  }
  for(int i=1;i<(1<<m);++i) {
    int bc = bitCount(i);
    if(bc&1) {
      ret -= color(i,n,m);
    } else {
      ret += color(i,n,m);
    }
  }
  printf("%lld\n", ret);
}
int main() {
    //freopen("input.txt","r",stdin);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  ll N,A,B;
  cin>>N>>A>>B;
  ll t = N/(A+B);
  cout << t*A + min(A,N%(A+B)) << endl;
  return 0;
}



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

using namespace std;
int main()
{
	int n;
	
	cin>>n;
	n%=10;
	if(n==0||n==1||n==6||n==8){
	    cout<<"pon";
	}else if(n==3){
	    cout<<"bon";
	}else{
	    cout<<"hon";
	}
}


Measured memory_bytes: 3588
class dice:
    men = [0] * 7
    def __init__(self, li):
        self.men = [0] + li
    def move0(self, a, b, c, d):
        self.men[a], self.men[b], self.men[c], self.men[d] = self.men[b], self.men[c], self.men[d], self.men[a]
    def move(self, h):
        if h == "N":
            self.move0(1, 2, 6, 5)
        elif h == "S":
            self.move0(1, 5, 6, 2)
        elif h == "W":
            self.move0(1, 3, 6, 4)
        elif h == "E":
            self.move0(1, 4, 6, 3)
        elif h == "O":
            self.men[1], self.men[6], self.men[2], self.men[5] = self.men[6], self.men[1], self.men[5], self.men[2]
        elif h == "L":
            self.move0(2, 3, 5, 4)
        elif h == "R":
            self.move0(2, 4, 5, 3)
        elif h == "B":
            self.men[3], self.men[4], self.men[2], self.men[5] = self.men[4], self.men[3], self.men[5], self.men[2]
    def move2(self, a, b):
        if self.men[1] != a:
            for i, s in [(2, "N"), (3, "W"), (4, "E"), (5, "S"), (6, "O")]:
                if self.men[i] == a:
                    self.move(s)
                    break
        if self.men[2] != b:
            if b == self.men[3]:
                self.move("L")
            elif b == self.men[4]:
                self.move("R")
            else:
                self.move("B")
saikoro = dice(list(map(int, input().split())))
for _ in range(int(input())):
    saikoro.move2(*map(int, input().split()))
    print(saikoro.men[3])



Measured memory_bytes: 5608
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int W = sc.nextInt();
		long[] w = new long[n];
		int[] v = new int[n];
		for(int i = 0; i < n; i++){
		    w[i] = sc.nextLong();
		    v[i] = sc.nextInt();
		}
		
		// 計算
		long result = 0;
		long[][] dp = new long[n+1][100001];
		for(int i = 0; i < n+1; i++){
		    Arrays.fill(dp[i], 1001001001);
		}
		dp[0][0] = 0;
		for(int i = 1; i <= n; i++){
		    for(int j = 0; j < dp[0].length; j++){
		        if(j-v[i-1] >= 0){
		            dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i-1]] + w[i-1]);
		        }else{
		            dp[i][j] = dp[i-1][j];
		        }
		    }
		}
		for(int i = 0; i < dp[0].length; i++){
		    if(dp[n][i] <= W) result = max(result, i);
		}

		
		// 出力
		System.out.println(result);
	}
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define m0(x) memset(x, 0, sizeof(x))

int dx4[4] = {1, 0, -1, 0}, dy4[4] = {0, 1, 0, -1};

map<int64_t, int> prime_factor(int64_t n)
{
    map<int64_t, int> ret;
    for (int64_t i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

int main()
{
    ll n, p, ans = 1;
    cin >> n >> p;

    for (auto pf : prime_factor(p))
    {
        ll f=pf.first;
        ll s=pf.second;
        ll cnt=s/n;
        ans*=pow(f,cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#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 ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1e9+100;
const ll MOD = 1e9;
const double EPS = 1e-10;
const bool debug = 0;
//------------------------------//

int N;
multiset<int> ss;
int M;
int T[212345];

int main() {
	cin >> N;
	REP(i, N) {
		int a;
		scanf("%d", &a);
		ss.insert(a);
	}
	
	cin >> M;
	REP(i, M) scanf("%d", T + i);
	
	bool ans = true;
	REP(i, M) {
		if (ss.empty() || ss.find(T[i]) == ss.end()) {
			ans = false;
			break;
		}
		ss.erase(ss.find(T[i]));
	}
	
	puts(ans ? "YES" : "NO");
	
	return 0;
}


Measured memory_bytes: 10368
#include<iostream>
#include<string>
using namespace std;
int main(void){
  string a;
  cin >> a;
  if(a == "a" || a == "e" || a == "i" || a == "o" || a == "u")
  cout<<"vowel"<<endl;
  else cout<<"consonant"<<endl;
  return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
int main(){
	int n, l, sum = 0, ans = 1e9, res = 0;
	cin >> n >> l;
	for(int i = 1; i <= n; i++){
		sum += i + l - 1;
	}
	for(int i = 1; i <= n; i++){
		if(ans > abs(i + l - 1)){
			ans = abs(i + l - 1);
			res = sum - (i + l - 1);
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int SZ=100005;
vector<int> ev[SZ],od[SZ];
int ans[SZ];
void dfs(int x, int b, int c){
	ans[x]=c;
	for(int nxt:ev[x]){
		if(nxt==b) continue;
		dfs(nxt,x,c);
	}
	c=(c==1?0:1);
	for(int nxt:od[x]){
		if(nxt==b) continue;
		dfs(nxt,x,c);
	}
}
int main(void){
	int n; scanf("%d",&n);
	for(int i=1;i<n;i++){
		int a,b,c; scanf("%d %d %d",&a,&b,&c);
		if(c%2==0){
			ev[a].push_back(b);
			ev[b].push_back(a);
		}
		else{
			od[a].push_back(b);
			od[b].push_back(a);
		}
	}
	dfs(1,0,0);
	for(int i=1;i<=n;i++) printf("%d\n",ans[i]);
	return 0;
}

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

long long int max(vector<long long int> k,int n){
  long long int max=0;
  for(int i=0;i<n;i++){
    if(max<k.at(i))max=k.at(i);
  }
  return max;
}

long long int min(vector<long long int> k,int n){
  long long int min=99999999999;
  for(int i=0;i<n;i++){
    if(min>k.at(i))min=k.at(i);
  }
  return min;
}

int main(){
  int n;
  cin >> n;
  vector<long long int> a(n);
  for(int i=0;i<n;i++)cin >> a.at(i);
  cout << max(a,n)-min(a,n) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <queue>
#include <stack>
#include <vector>
#define loop(n) for(ll i=0;i<n;i++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
typedef long long int ll;


int main()
{
    fastio;
    ll n;
	cin>>n;
	ll arr[n];
	for(ll i=0;i<n;i++)
		cin>>arr[i];
	
	ll dp[n];
	dp[0] = 0;
	dp[1] = abs(arr[1] - arr[0]);
	for(ll i=2;i<n;i++)
	{
		dp[i] = min(dp[i-1] + abs(arr[i] - arr[i-1]),dp[i-2] + abs(arr[i-2] - arr[i]));
	}
	cout<<dp[n-1]<<endl;
    
    return 0;
}


Measured memory_bytes: 5140
package main

import "fmt"

func main() {
	var T string
	fmt.Scan(&T)
	for i := 0; i < len(T); i++ {
		if T[i] == '?' {
			fmt.Print("D")
		} else {
			fmt.Print(string(T[i]))
		}
	}
	fmt.Println()
}


Measured memory_bytes: 6192
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using ld=long double;
using VI=vector<ll>;
using VD=vector<ld>;
using VVI=vector<VI>;
using VC=vector<char>;
using VVC=vector<VC>;
using VS=vector<string>;
using PLL =pair<ll,ll>;
using PLD=pair<ld,ld>;
using VPLL=vector<PLL>;
#define print(x) std::cout<<x<<"\n"
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repd(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SZ(x) ((ll)(x).size())
#define MAX(x) *max_element((x).begin(),(x).end())
#define MIN(x) *min_element((x).begin(),(x).end())
#define SORTR(x) sort((x).rbegin(),(x).rend())
#define SORT(x) sort((x).begin(),(x).end())
#define SUM(x) accumulate((x).begin(),(x).end(), 0)
#define FILL(x,a) fill(x.begin(),x.end(),a)
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

const ll INF = 1e18;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;
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; }
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll GCD(VI v){ll a = v[0]; for (ll i = 1; i<SZ(v); i++) {a = gcd(a, v[i]);} return a;}
ll LCM(VI v){ll a = v[0]; for (ll i = 1; i<SZ(v); i++) {a = lcm(a, v[i]);} return a;}
VI Bit2Vector(const ll bit, ll n) {	VI s;	rep(i,n) if (bit & (1 << i)) s.push_back(i); return s;}


void Main()
{
	ll n,m,l,w; ll res=0;
	string s,t,u; string sres="No or NO";

	cin>>n>>w;
	VI wei(n),val(n);
	rep(i, n)	cin >> wei[i]>>val[i];

 	VVI dp(n+1,VI(100010,0));
	rep(j,n){
		rep(i,w+1){
			if(i>=wei[j])	chmax(dp[j+1][i],dp[j][i-wei[j]]+val[j]);
			chmax(dp[j+1][i],dp[j][i]);
		}
	}
	res=MAX(dp[n]);
	cout << res << "\n";
	return;
}

int main()
{
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

int main(){
  int n,k; cin >> n >> k;
  string s; cin >> s;

  int ans = 0;
  int right = 0;
  int cnt = 0;
  rep(left, n){
    while(right < n && cnt + (1 - (s[right] - '0')) <= k){
      if(s[right] == '0'){
        cnt++;
        while(right < n && s[right] == '0') right++;
      }
      else right++;
    }
    chmax(ans,right-left);

    if(s[left] == '0'){
      cnt--;
      while(s[left] == '0')left++;
      left--;
    }
  }

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


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    int r,c;
    cin>>r>>c;
    string s[r];
    for (int i=0;i<r;i++){
        cin>>s[i];
        s[i]="#"+s[i]+"#";
    }
    for (int i=0;i<c+2;i++)
        cout<<"#";
    cout<<endl;
    for (int i=0;i<r;i++)
        cout<<s[i]<<endl;
    for (int i=0;i<c+2;i++)
        cout<<"#";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n,m,j,ans=0;
  string s;
  while(1){
    ans=0;
    cin >> n;
    if(n==0) break;
    cin >> m  >> s;
    for(int i=0;i<m;i++) {
      if(s[i]!='I')continue;
      for(j=0;i<m-2;i+=2,j++){
	if(s[i+1]!='O'||s[i+2]!='I') break;
	if(j>=n-1){
	  ans++;
	}
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 2108
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

template< typename Monoid >
struct SegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;

  int sz;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }

  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }
};

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,q; cin >> n >> q;
    SegmentTree<LL> seg(n,[](LL a, LL b){
        return a+b;
    },0);
    REP(i,q){
        LL c,x,y; cin >> c >> x >> y;
        if(c == 0) seg.update(x-1,seg[x-1]+y);
        else cout << seg.query(x-1,y) << endl;
    }


}


Measured memory_bytes: 4856
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
template<typename T =ll> using v = vector<T>;
template<typename T =ll> using vv = v<v<T>>;
template<typename T=ll,typename U=ll> using p = pair<T,U>;
template<typename T> T chmin(T &a,T b) {return a=min(a,b);}
template<typename T> T chmax(T &a,T b) {return a=max(a,b);}
const ll INF = (ll)1e9;


int main(){
    int n,a,b,c,d;
    cin >> n >> a >> b >> c >> d;
    string s;  cin >> s;
    s="#"+s+"#";
 
    auto search = [&s](int st,int en){
        for(int i=st;i<en;i++){
            if(s[i]=='#'&&s[i+1]=='#') return false;
        }
        return true;
    };

    if(!search(a,c)||!search(b,d)){
        cout << "No"<<endl;
        return 0;
    }
    

    if(c>d){
        for(int i=b;i<=d;i++){
            if(s[i-1]=='.'&&s[i]=='.'&&s[i+1]=='.'){
                cout << "Yes" << endl;
                return 0;
            }
        }
        cout << "No"<<endl;
        return 0;
    }

    cout << "Yes"<<endl;    

    return 0;
}

Measured memory_bytes: 772
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main()
{
	cout << fixed << setprecision(10);
	LLI n;
	cin >> n;
	if (n % 2 == 1)
	{
		cout << 0;
		return 0;
	}

	LLI c5 = 0;
	for (LLI i = 10; i <= n; i *= 5)
	{
		c5 += n / i;
		c5 = c5;
	}
	cout << c5;
	return 0;
}

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

const int MOD = 1000000007;
vector<vector<int>> G;
vector<vector<long long>> dp;

void dfs(int cur, int prev) {
  dp.at(cur).at(0) = 1;
  dp.at(cur).at(1) = 1;
  for (int nx : G.at(cur)) {
    if (nx == prev) continue;
    dfs(nx, cur);
    long long tmp = (dp.at(nx).at(0) + dp.at(nx).at(1)) % MOD;
    dp.at(cur).at(0) = dp.at(cur).at(0) * tmp % MOD;
    dp.at(cur).at(1) = dp.at(cur).at(1) * dp.at(nx).at(0) % MOD;
  }
}

int main() {
  int N; cin >> N;
  G.resize(N);
  for (int i = 0; i < N-1; i++) {
    int x, y; cin >> x >> y; x--; y--;
    G.at(x).push_back(y);
    G.at(y).push_back(x);
  }
  // dp[i][j] := 頂点 i に色 j を塗ったとき、i を根とする部分木の塗り方の総数
  dp = vector<vector<long long>>(N, vector<long long>(2, 0));
  dfs(0, -1);
  long long ans = (dp.at(0).at(0) + dp.at(0).at(1)) % MOD;
  cout << ans << endl;
}

Measured memory_bytes: 19584
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
signed main(void){
    itn n,m; cin>>n>>m;
    vector <int> deg(n); 
    
    rep(i,m) {int a,b; cin>>a>>b; a--; b--; 
        deg[a]++; deg[b]++;
    }
    rep(i,n){
        if(i == 0) continue;
        if(deg[i]%2 == 1) {cout<<"NO"<<endl; return 0;}
    }
    cout<<"YES"<<endl;
}


Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define pb push_back
#define fi first
#define se second
const int N=1e6+10;
const int mod7=1e9+7;
const int mod=998244353;
const double pi=3.14;
void read(int &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0') if(ch=='-') d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9') a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
void read(ll &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0') if(ch=='-') d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9') a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
int main()
{
    int a,b;
    read(a),read(b);
    int x=4*a-b;
    if(x%2!=0) return puts("No"),0;
    x/=2;
    if(x<0) return puts("No"),0; 
    int y=a-x;
    if(y>=0) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 3588
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}



int main(){
    int a,b;cin>>a>>b;
    int l,s;
    if(a>b)l = a,s = b;
    else l = b,s = a;
    if(l==s)cout<<l+s;
    else cout<<l*2-1;
}



Measured memory_bytes: 256
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	int n;
	cin >> n;
	cout << static_cast<double>(2 * n) * PI << endl;
	return 0;
}


Measured memory_bytes: 3788
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
#include <iomanip>

using namespace std;
using ll = long long;

int main(){
    
    int s;
    cin >> s;
    
    int a=s;
    int i=1;
    if(s == 1 || s == 2){
        cout << 4 << endl;
        return 0;
    }
    
    while(a!=4){
        if(a%2==0){
            a = a/2;
        }else{
            a = 3*a+1;
        }
        i++;
    }
    
    
    cout << i+3 << endl;
    return 0;
}



Measured memory_bytes: 256
#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 whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;


int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];

    sort(s.begin(), s.end());
    int ans = 0;
    rep(i, n) {
        if (i==0) {
            ans ++;
            continue;
        }
        if (s[i-1]!=s[i]) ans ++;
    }
   
    
    
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9536
#include<bits/stdc++.h>
using namespace std;
const int MAX = 2e5;
int height[MAX];
int memo[MAX];
int n, k;

int dp(int idx){
    if(idx >= n){
        return 2e9;
    }
    if(idx == n-1){
        return 0;
    }
    int& res = memo[idx];
    if(res != 2e9){
        return res;
    }
    for(int i = 1; i <= k; i++){
        res = min(res, dp(idx+i) + abs(height[idx] - height[idx+i]));
    }
    return res;
}

int main(){
    for(int i = 0; i < MAX; i++) memo[i] = 2e9;
    scanf("%d %d", &n, &k);
    for(int i = 0; i < n; i++){
        scanf("%d", &height[i]);
    }
    printf("%d", dp(0));
    return 0;
}


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

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

#define MOD 1000000007

using namespace std;

int main(){
	int n;
	int ans=0;
	
	cin >> n;
	
	long long int a[n];
	
	for(int i=0; i<n; i++)	cin >> a[i];
	
	for(int i=0; i<n; i++){
		while(a[i]%2==0){
			ans++;
			a[i]/=2;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
using namespace std;
typedef pair <int, int> pii;
int main()
{

	//int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	long long a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0, ans = 0;
	//cout << LONG_MAX << endl;
	string s, t;
	//long long n, A[1000000000];
	long long n, m;
	//int   y[100001], z[100001], x[10001] = {};
	//pii y[100001];
	//pair<int, float> pii[100001];
	int x[100];
	cin >> s;
	cin >> a ;
	for ( b = 0; b < a; b++)
	{
		if (s[b]!='1')
		{
			cout << s[b] << endl;
			return 0;
		}

	}

	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;

	cout << 1 << endl;

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
namespace Atcoder_0404
{
    class Program
    {
        static void Main(string[] args)
        {
            var first = GetInput_string()[0];
            var sec = GetInput_string()[0];
            if (first.Length+1 == sec.Length
                &&first==sec.Substring(0,first.Length))
            {
                Console.WriteLine("Yes");
            }
            else
            {

                Console.WriteLine("No");
            }
        }

        
        #region input
        

        static string[] GetInput_string()
        {
            var input = Console.ReadLine().Split(' ');
            return input;
        }

        static int[] GetInput_int()
        {
            var input = GetInput_string();
            var result = new int[input.Length];
            for (int i = 0; i < result.Length; i++)
            {
                result[i] = int.Parse(input[i]);
            }
            return result;
        }
        static long[] GetInput_long()
        {
            var input = GetInput_string();
            var result = new long[input.Length];
            for (int i = 0; i < result.Length; i++)
            {
                result[i] = long.Parse(input[i]);
            }
            return result;
        }
        #endregion
        #region sonota
        static void Swap_array<T>(T[] target, int a, int b)
        {
            T temp = target[a];
            target[a] = target[b];
            target[b] = temp;
        }
        static void Swap_list<T>(List<T> target, int a, int b)
        {
            T temp = target[a];
            target[a] = target[b];
            target[b] = temp;
        }
        /// <summary>
        /// 最大公約数
        /// </summary>
        public static int GCD(int a, int b)
        {

            /* 自然数 a > b を確認・入替 */
            if (a < b)
            {
                int tmp = a;
                a = b;
                b = tmp;
            }

            /* ユークリッドの互除法 */
            int r = a % b;
            while (r != 0)
            {
                a = b;
                b = r;
                r = a % b;
            }
            return b;
        }

        /// <summary>
        /// 最小公倍数
        /// </summary>
        public static int LCM(int a, int b)
        {
            int x = a * b;
            b = GCD(a, b);
            return x / b;

        }
        #endregion

        static long mod = 1000000000 + 7;
    }

}

Measured memory_bytes: 25816
import sys
input = sys.stdin.readline
#input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')
#import numpy as np

from collections import deque

def main():
	n=II()
	A=LI()
	B=[0]*(n+1)
	for i in A:
		B[i]+=1

	ans=0
	for i in B:
		ans+=i*(i-1)//2
	#print(ans)
	for i in A:
		print(ans-B[i]+1)









if __name__ == "__main__":
	main()

Measured memory_bytes: 77772
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 5;
#define rep(i , j , n) for(long long i = j ; i <= n ; i++)
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string a , b;
    cin >> a >> b;
    string c = a + b;
    int A = stoi(c);
    set < int > res;
    for(int i = 1 ; i <= 1000 ; i++) {
        res.insert(i * i);
    }
    if(res.find(A) == res.end()) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << 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;

typedef long long ll;

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 main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	string s, t;
	cin >> s >> t;

	int n = s.size();

	int ans = 0;
	rep(i, n){
		if(s[i] != t[i]) ans++;
	}

	cout << ans << endl;
}


Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 1e18
#define gap " "
#define pi 2 * acos (0.0)

int main()
{
    
    int a;
    cin>> a;
    int temp= a/1000;
    if (temp*1000==a) cout<< "0\n";
    else{
        cout<< (temp+1)*1000-a << endl;
    }
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string we;
  cin >> we;
  
  if(we == "Sunny"){
    
    cout << "Cloudy" << endl;
  }
    if(we == "Cloudy"){
    
    cout << "Rainy" << endl;
  }
    if(we == "Rainy"){
    
    cout << "Sunny" << endl;
  }
}
  

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};

fn main() {
  let n: usize = read();
  let m: usize = read();
  let mut ans = vec![0; m];
  let mut uf = UnionFind::new(n);

  let mut ab: Vec<(usize, usize)> = vec![];
  for _ in 0..m {
    let a: usize = read();
    let b: usize = read();
    ab.push((a, b));
  }

  ans[m - 1] = n * (n - 1) / 2;
  for i in (1..m).rev() {
    let (a, b) = ab[i];
    let (a, b) = (a - 1, b - 1);
    let na = uf.size(a);
    let nb = uf.size(b);
    if uf.union(a, b) {
      ans[i - 1] = ans[i] - na * nb;
    } else {
      ans[i - 1] = ans[i];
    }
  }

  for a in ans {
    println!("{}", a);
  }
}


struct UnionFind {
  parent: Vec<usize>,
  size: Vec<usize>,
}
impl UnionFind {
  fn new(n: usize) -> UnionFind {
    UnionFind {
      parent: (0..n).collect(),
      size: vec![1; n],
    }
  }
  fn find(&mut self, x: usize) -> usize {
    if self.parent[x] == x {
      x
    } else {
      let p = self.parent[x];
      self.parent[x] = self.find(p);
      self.parent[x]
    }
  }
  fn union(&mut self, x: usize, y: usize) -> bool {
    let mut x = self.find(x);
    let mut y = self.find(y);
    if x == y {
      false
    } else {
      if self.size[x] < self.size[y] {
        std::mem::swap(&mut x, &mut y);
      }
      self.parent[y] = x;
      self.size[x] += self.size[y];
      true
    }
  }
  fn size(&mut self, x: usize) -> usize {
    let p = self.find(x);
    self.size[p]
  }
}


Measured memory_bytes: 11516
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
using namespace std;
int INF = 1001001001;
int main(){
	int n, x;
	cin >> n >> x;
	vector<int> l(n);
	rep(i,n) cin >> l[i];
	int count=1;
	int d=0;
	rep(i,n){
		d += l[i];
		if(d>x) break;
		count++;
	}
	cout << count << endl;

	return 0;
}


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

#define FOR(i,a,n) for (int i = a; i < (int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define whole(f,x,...) ([&](decltype((x)) whole) { \
    return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
template<typename T> bool chmin(T &a, const T &b) {if (a > b) { a = b; return true; }return false;}
template<typename T> bool chmax(T &a, const T &b) {if (a < b) { a = b; return true; }return false;}

using ll = int_fast64_t;

constexpr ll INF = (1e9);
constexpr ll MOD = (1e9+7);

int main() {
  int n, m; cin >> n >> m;
  vector<ll> x(n); REP(i,n) cin >> x[i];
  vector<ll> y(m); REP(i,m) cin >> y[i];
  ll xsum = 0, ysum = 0;
  REP(i,n) xsum += (2*i-n+1)%MOD * x[i]%MOD;
  REP(i,m) ysum += (2*i-m+1)%MOD * y[i]%MOD;
  cout << xsum%MOD * (ysum%MOD) %MOD << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+100;
#define fr(i,low,up) for(register int i = low;i <= up; ++i)
#define nfr(i,low,up) for(register int i = low;i >= up; --i)

int n,k;
int p[N];
int sum[N];
bool flag = false;
set<int> s1;
int main(){
   int ans = 0;
   scanf("%d%d",&n,&k);
   fr(i,1,n){
      scanf("%d",p+i);
      sum[i] = p[i] > p[i-1];
   }
   fr(i,1,n)sum[i] += sum[i-1];
   fr(i,1,k)s1.insert(p[i]);

   if(sum[k]-sum[1] == k-1)flag = true;
   ans = 1;
   fr(i,1,n-k){
      s1.insert(p[i+k]);
      if(p[i] != *s1.begin() || p[i+k] != *--s1.end()){
         if(sum[i+k]-sum[i+1] != k-1)++ans;
         else if(!flag && sum[i+k]-sum[i+1] == k-1)++ans,flag = true;
      }
      s1.erase(p[i]);
   }
   printf("%d\n",ans);
   return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(void) {
    string s;
    cin >> s;
    string a;
    a.push_back(s[0]);
    a.push_back(s[1]);
    a.push_back(s[2]);
    a.push_back(s[3]);
    if (a == "YAKI") cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.{BufferedReader, InputStream, InputStreamReader, PrintWriter}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}
import scala.collection.mutable.{ArrayBuffer, ListBuffer}

object Main {
  val MOD = 1000000007
  val out = new PrintWriter(System.out)
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N = sc.nextInt()

    val A = Array.fill[Int](N)(sc.nextInt())
    val Max = A.zipWithIndex.maxBy(_._1)
    val Min = A.zipWithIndex.minBy(_._1)

    def process(z: Int, range: Range) = {
      out.println(2 * N)
      val s = range.head
      rep(2){ out.println(s"$z $s") }
      range zip range.drop(1) foreach { case (i, j) =>
        rep(2){ out.println(s"$i $j") }
      }
    }

    if (abs(Max._1) > abs(Min._1)) {
      process(Max._2 + 1, 1 to N)
    } else {
      process(Min._2 + 1, (1 to N).reverse)
    }
  }


  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
    def nextLong(): Long = next.toLong
    def nextChar(): Char = next.charAt(0)
  }

  private def rep(n: Int)(f: => Unit): Unit = {
    (0 until n) foreach (_ => f)
  }
}


Measured memory_bytes: 27084
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

int main() {
	//string s[100], res = "";
	//int N, M;
	//int a[60], b[60], res[60] = { 0 };
	string S;
	cin >> S;
	int y = 700;
	for (int i = 0; i < S.size(); ++i) {
		if (S[i] == 'o') {
			y += 100;
		}
	}
	cout << y << endl;
	return 0;

}


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


template<typename T>
struct Kruskal {
    struct Edge {
        int from, to;
        T cost;
        Edge(int from, int to, T cost) : from(from), to(to), cost(cost){}
        bool operator<(const Edge& e) const {
            return cost < e.cost;
        }
    };
    struct UF {
    vector<int> r, p;
        UF() = default;
        UF(int sz) : r(sz, 1), p(sz){ iota(begin(p), end(p), 0LL); }
        int find(int x){
            return (x == p[x] ? x : p[x] = find(p[x]));
        }
        bool same(int x, int y){
            return find(x) == find(y);
        }
        void unite(int x, int y){
            x = find(x), y = find(y);
            if(x == y) return;
            if(r[x] < r[y]) swap(x, y);
            r[x] += r[y];
            p[y] = x;
        }
    };
    vector<Edge> es;
    UF uf;
    Kruskal() = default;
    Kruskal(int n) : uf(n){}
    void addEdge(int u, int v, T c){
        es.emplace_back(u, v, c);
    }
    T build(){
        sort(begin(es), end(es));
        T res = 0;
        for(auto& e : es){
            if(!uf.same(e.from, e.to)){
                res += e.cost;
                uf.unite(e.from, e.to);
            }
        }
        return res;
    }
};


int V, E;
Kruskal<int> G;


int main(){
    cin >> V >> E;
    G = Kruskal<int>(V);
    for(int i = 0;i < E;++i){
        int s, t, w;
        cin >> s >> t >> w;
        G.addEdge(s, t, w);
    }

    int ans = G.build();

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4528
l,r = gets.split(" ").map{|i|i.to_i}
if  r-l > 2018 then
	puts 0
else
	min = 2018
		for p in l..r-1 do
			for q in p+1..r do
				if (p*q)%2019 < min then
					min = (p*q)%2019
				end
			end
		end
        puts min
end

Measured memory_bytes: 1788
import java.util.*;
 
public class Main {
  static int n;
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      n = sc.nextInt();
      int[] h = new int[n];
      int min = Integer.MAX_VALUE;
      for (int i = 0; i < n; i++) {
          h[i] = sc.nextInt();
      }
      int ans = 0;
      int active = 0;
      for (int i = 0; i < n; i++) {
        if (active >= h[i]) {
          active = h[i];
        } else {
          ans += h[i] - active;
          active = h[i];
        }
      }
      System.out.println(ans);
    }
}

Measured memory_bytes: 23764
use std::io::{self, BufRead};

fn main() {
  let stdin = io::stdin();
  let mut lines = stdin.lock().lines();
  let line = lines.next().unwrap();
  let vec: Vec<i64> = line.unwrap().split(' ').map(|x| x.parse().unwrap()).collect();
  let res = vec[0] % vec[1];
  let ans = std::cmp::min(res, vec[1] - res);
  println!("{}", ans);
}

Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int main(int argc, char const* argv[]) {
    int a, b;
    cin >> a >> b;
    if (a > 8 || b > 8) {
        cout << ":(" << endl;
    } else {
        cout << "Yay!" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <chrono>
#include <regex>
using namespace std;
#define len(_x) (sizeof((_x)) / sizeof(_x)[0])
#define ll long long
#define fastIO  ios_base::sync_with_stdio(false); cin.tie(0); 
#define Ichar(_x) char _x;scanf("%c",&_x);
#define Iint(_x) int _x;scanf("%d",&_x); 
#define Ill(_x)  ll _x;scanf("%lld",&_x);
#define inc(a,b,x)(x)>a && (x)<b	
#define incE(a,b,x)(x)>=a && (x)<=b	
#define fileIO 	freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);


ll modo(ll a)
{
	return a % (int)(1e9+7);
}




int main()
{
	Iint(n);
	Iint(s); Iint(t);
	while (n--)
	{
		Iint(a);
		t += (s - 1) / a+1;
	}
	std::cout << t;
	


	return 0;

}





Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
#include<map>
#include<bitset>
#include<assert.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<set>
#include<queue>
#define long long long
using namespace std;
const int N=1e6,mod=1e9+7;
int aa[N+2],bb[N+2];
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  int n;cin>>n;long ans=0;
  for(int i=1;i<=n;i++)
  {
    cin>>aa[i];//ans+=(aa[i]/2);aa[i]%=2;
  }
  for(int i=1;i<n;i++)
  {
    ans+=aa[i]/2;aa[i]%=2;
    if(aa[i]==0)continue;
    if(aa[i+1])
      ans++,aa[i+1]--;
  }
  ans+=aa[n]/2;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 4352
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long n = sc.nextInt();
		
		
		for(long i = 1;i <= n;i++){
			long x = i;
			if(x % 3 == 0){
				System.out.print(" "+i);
				continue;
			}
			
			if(x % 10 == 3){
				System.out.print(" "+i);
				continue;
			}
			
			for(x /= 10;x != 0;x /= 10){
				if(x % 10 == 3){
					System.out.print(" "+i);
					break;
				}
			}
		}
		
		System.out.print("\n");
		
		sc.close();
	}
}

Measured memory_bytes: 24236
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include<cmath>
#include <ctype.h>
#include <stdlib.h>
#include <vector>
#include <math.h>
#include <stack>
#define ll long long
#define endl '\n'
#define PI 3.14159265
using namespace std;
int frq[26];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("stand.in","r",stdin);
    //freopen("stand.in","w",stdout);
    string n;
    cin >> n;
    if (int(n[n.size() - 1] - '0') == 2 || int(n[n.size() - 1] - '0') == 4 || int(n[n.size() - 1] - '0') == 5 || int(n[n.size() - 1] - '0') == 7 || int(n[n.size() - 1] - '0') == 9) {
        cout << "hon";
    }
    else if(int(n[n.size() - 1] - '0') == 0 || int(n[n.size() - 1] - '0') == 1 || int(n[n.size() - 1] - '0') == 6 || int(n[n.size() - 1] - '0') == 8) {
        cout << "pon";
    }
    else if (int(n[n.size() - 1] - '0') == 3) {
        cout << "bon";
    }
}
   

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


int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<int> p(a), q(b), r(c);
  rep(i,a) cin >> p[i];
  rep(i,b) cin >> q[i];
  rep(i,c) cin >> r[i];
  sort(rng(p)); reverse(rng(p));
  sort(rng(q)); reverse(rng(q));
  rep(i,x) r.push_back(p[i]);
  rep(i,y) r.push_back(q[i]);
  sort(rng(r)); reverse(rng(r));
  ll ans = 0;
  rep(i,x+y) ans += r[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5612
#include <cmath>
#include <iostream>
using namespace std;
int main() {
  int h, w, f, d;
  while (cin >> h >> w, h) {
    d = h*h + w*w;
    f = 1;
    ++h;
    while (f) {
      for (int i = h; i*i < d; ++i) {
	w = sqrt(d-i*i);
	if (w <= i) break;
	else if (w*w + i*i == d) {
	  cout << i << " " << w << endl;
	  f = 0;
	  break;
	}
      }
      h = 1;
      ++d;
    }
  }
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(int (i) = 1; (i) < (n); ++(i))
#define rrep1(i,n) for(int (i) = (n) - 1; (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;
#define all(x) (x).begin(),(x).end()

ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

int main()
{
    ll l,r,ans = 2018;
    cin >> l >> r;
    nfor(i, l, r + 1){
        nfor(j, i + 1, r + 1){
            ans = min((i * j) % 2019, ans);
            if (ans == 0) {
                cout << 0 << endl;
                return 0;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import numpy as np
 
N, K = map(int, input().split())
 
def get_x(n, K):
    if n >= K:
        return 0
    else:
        x_raw = np.log2(K) - np.log2(n)
        return np.ceil(x_raw)

def get_prob(n, K):
    x = get_x(n, K)
    if x == 0:
        return 1
    else:
        return (1/2)**x
    
ans = np.mean([get_prob(n, K) for n in range(1, N+1)])
 
print(ans)

Measured memory_bytes: 14300
package main

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

var sc = bufio.NewScanner(os.Stdin)

const initBufSize, maxBufSize = 10000, 1000000

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextInts(n int) []int {
	res := make([]int, n)
	for i := range res {
		res[i] = nextInt()
	}
	return res
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func abs(n int) int {
	return int(math.Abs(float64(n)))
}

func pow(r, n int) int {
	return int(math.Pow(float64(r), float64(n)))
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initBufSize), maxBufSize)
	n := nextInt()
	k := nextInt()
	sum := 0
	for i := 1; i <= n; i++ {
		sum += i
	}
	//N+1個選ぶ時の最大値と最小値
	max, min := sum, sum
	//選ぶ数を1つずつ減らしながら和の最大値と最小値を求める
	i := n + 1
	maxCalc := 0
	minCalc := n
	ans := 0
	for i >= k {
		//最大値はK⇒N+1の順に減少
		//最小値はN+1⇒Kの順に減少
		if i < n+1 {
			max -= maxCalc
			min -= minCalc
			maxCalc++
			minCalc--
		}
		//fmt.Println("i:", i, "max:", max, "min:", min)
		temp := 0
		temp = max - min + 1
		ans += temp % (1000000000 + 7)
		i--
	}
	fmt.Println(ans % (1000000000 + 7))
}


Measured memory_bytes: 1756