akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <unordered_map>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
#ifdef LBT
    freopen("test.in", "r", stdin);
    int nol_cl = clock();
#endif

    int N, M;
    scanf("%d%d", &N, &M);
    vector<int> C(N), cnt(M);
    for (int i = 0; i < N; ++i) {
        scanf("%d", &C[i]);
        ++cnt[--C[i]];
    }
    vector<vector<vector<int>>> G(2, vector<vector<int>>(M));
    vector<int> ans = cnt;
    for (int i = 1; i < N; ++i)
        if (C[i] != C[i - 1]) {
            G[i & 1][C[i]].push_back(C[i - 1]);
            G[i & 1][C[i - 1]].push_back(C[i]);
        }
    vector<vector<int>> adjAns(2, vector<int>(M));
    vector<int> ccnt(N + 1);
    for (int c : cnt) ++ccnt[c];
    int mx = *max_element(cnt.begin(), cnt.end());
    if (M > 1) {
        for (int t = 0; t <= 1; ++t) {
            for (int i = 0; i < M; ++i) {
                --ccnt[cnt[i]];
                for (int j : G[t][i]) {
                    --ccnt[cnt[j]--];
                    ++ccnt[cnt[j]];
                }

                // cerr << t << ' ' << i << ": "; for (int k = 0; k <= N; ++k) cerr << ccnt[k] << ' '; cerr <<
                // '\n';
                adjAns[t][i] = mx;
                while (!ccnt[adjAns[t][i]]) --adjAns[t][i];
                ++ccnt[cnt[i]];
                for (int j : G[t][i]) {
                    --ccnt[cnt[j]++];
                    ++ccnt[cnt[j]];
                }
            }
        }
    }
    for (int i = 1; i < N; ++i)
        if (C[i] != C[i - 1]) {
            ans[C[i]] = max(ans[C[i]], cnt[C[i]] + adjAns[!(i & 1)][C[i]]);
            ans[C[i - 1]] = max(ans[C[i - 1]], cnt[C[i - 1]] + adjAns[!(i & 1)][C[i - 1]]);
        }

    for (int i = 0; i < M; ++i) printf("%d\n", N - ans[i]);

#ifdef LBT
    LOG("Time: %dms\n", int((clock() - nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
    return 0;
}


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

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

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin >> n >> m;
    vector<int> x(m);
    vector<int> y(m);
    for(int i = 0; i < m; i++) {
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
    }
    vector<bool> r(n,false);
    vector<int> t(n,1);
    r[0]=true;

    for(int i = 0; i < m; i++) {
        if(r[x[i]]){
            if(t[x[i]]==1){
                r[x[i]]=false;
            }
            r[y[i]]=true;
        }
        t[x[i]]--;
        t[y[i]]++;
    }

    int cnt=0;
    for(int i = 0; i < n; i++) {
        if(r[i]) cnt++;
    }
    cout << cnt << "\n";

    return 0;
}

Measured memory_bytes: 4396
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<math.h>
#include<list>
#include<complex>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vtype(type) vector<type>
#define vvtype(type) vector<vector<type>>
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,x) unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;


ll const MOD = 1e9 + 7;
ll mod_p(ll x, ll y) {
	x %= MOD;
	y %= MOD;
	return (x + y + MOD) % MOD;
}

ll mod_m(ll x, ll y) {
	x %= MOD;
	y %= MOD;
	return x * y%MOD;
}

ll mod_pow(ll x, ll t) {
	x %= MOD;
	if (t == 0) {
		return 1;
	}
	else {
		ll v = mod_pow(x, t / 2);
		if (t % 2 == 0) {
			return v * v % MOD;
		}
		else {
			return v * v%MOD * x %MOD;
		}
	}
}

ll mod_inv(ll x) {
	return mod_pow(x, MOD - 2);
}

struct edge
{
	long long to; ll name;
	bool operator<(const edge& rhs) const {
		return name > rhs.name;
	}
};

ll const MAX = 1e5 + 5;
vector<vector<edge>> G(MAX);
vll s(MAX);
vll ans(MAX);
vll visited(MAX, 0);
vll weight(MAX, 1);
vll difsum(MAX, 0);
ll pending = 0;
ll pendingnode = 0;

void dfs(ll start, ll n) {
	visited[start] = 1;
	for (auto x : G[start]) {
		if (visited[x.to]) {
			continue;
		}
		else {
			dfs(x.to, n);
			ll next = x.to;
			weight[start] += weight[next];
			ll weightdif = weight[next] * 2 - n;
			ll lengdif = s[next] - s[start];
			if (weightdif) {
				ll tmp = -lengdif / weightdif;
				ans[x.name] = tmp;
				difsum[start] += tmp * weight[next] + difsum[next];
			}
			else {
				pending = x.name;
				pendingnode = weight[next];
				difsum[start] += difsum[next];
			}
		}
	}
}

int main() {
	ll n;
	cin >> n;
	REP(i, 1, n - 1) {
		ll a, b;
		cin >> a >> b;
		G[a].push_back({ b,i });
		G[b].push_back({ a,i });
	}
	REP(i, 1, n) {
		cin >> s[i];
	}
	dfs(1, n);
	if (pending) {
		ans[pending] = (s[1] - difsum[1]) / pendingnode;
	}
	REP(i, 1, n - 1) {
		cout << ans[i] << endl;
	}
}

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

  
int main(){
 ll n;
  cin >> n;
  if(n%2==1) cout << 2*n <<endl;
  else  cout << n <<endl;
}

Measured memory_bytes: 256
/// Kazuki Hoshino


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
//#define endl '\n'
typedef tree<
int,
null_type,less<int>,
rb_tree_tag,tree_order_statistics_node_update>
ordered_set;
ld t,x;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
cin >> t >> x;
cout << t/x << endl;

return 0;}
///....



Measured memory_bytes: 256
import sys
import collections

while True:
    N, Q = map(int, sys.stdin.readline().split())
    if N == 0:
        break
    counter = collections.Counter()
    for i in xrange(N):
        date = map(int, sys.stdin.readline().split())
        if date[0] != 0:
            counter.update(date[1:])
    
    if len(counter) == 0:
        print 0
        continue
    
    result = counter.most_common()
    largest = result[0][1]
    
    ret = -1
    if largest < Q:
        print 0
    else:
        smallest = 100
        for n, c in result:
            if c < largest:
                break
            if n < smallest:
                smallest = n
        print smallest

Measured memory_bytes: 4624
//
// Created by seriru on 2020/06/28.
//

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

typedef long long ll;

constexpr int CONTEST_COUNT = 26;
ll ans = 1000000;
int score = 0;
int D;

int main() {
  cin >> D;
  vector<int> C(CONTEST_COUNT);
  vector<vector<int>> S(D, vector<int>(CONTEST_COUNT));
  vector<int> T(D);
  vector<int> Last(CONTEST_COUNT);
  for (int i = 0; i < CONTEST_COUNT; ++i) {
    cin >> C[i];
  }

  for (int i = 0; i < D; ++i) {
    for (int j = 0; j < CONTEST_COUNT; ++j) {
      cin >> S[i][j];
    }
  }

  for (int i = 0; i < D; ++i) {
    cin >> T[i];
    T[i]--;

    int nowScore = 0;
    int today = i+1;

    nowScore += S[i][T[i]];
    Last[T[i]] = today; // 今日の日付に変更
    for (int k = 0; k < CONTEST_COUNT; ++k) {
      nowScore -= (today - Last[k]) * C[k];
    }

    score += nowScore;

    cout << score << endl;
  }
}

Measured memory_bytes: 3600
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	private static Scanner sc = new Scanner(System.in);
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p(long ans) {System.out.println(ans);};
	public static void main(String[] args) {
		//int N=sc.nextInt();
		int a[][]=new int[3][3];
		
		for(int i1=0;i1<3;i1++) {
			for(int i2=0;i2<3;i2++) {
				a[i1][i2]=sc.nextInt();
			}
		}
		int N=sc.nextInt();
		int b[]=new int[N];
		for(int i=0;i<N;i++) {
			b[i]=sc.nextInt();
		}
		
		for(int i1=0;i1<3;i1++) {
			for(int i2=0;i2<3;i2++) {
				for(int k=0;k<N;k++) {
					if(a[i1][i2]==b[k]) {
						a[i1][i2]=0;
					}
				}
			}
		}
		int ctn=0;
		for(int i1=0;i1<3;i1++) {
			if(a[i1][0]==a[i1][1]&&a[i1][1]==a[i1][2]) {
				ctn++;
				break;
			}
		}
		for(int i1=0;i1<3;i1++) {
			if(a[0][i1]==a[1][i1]&&a[1][i1]==a[2][i1]) {
				ctn++;
				break;
			}
		}
		if(a[0][0]==a[1][1]&&a[2][2]==a[1][1]) {
			ctn++;}else if(a[0][2]==a[1][1]&&a[1][1]==a[2][0]) {
				ctn++;
			}
		System.out.println(ctn > 0 ? "Yes" : "No");
	}
	
}

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

int main() {

  int n;
  cin >> n;

  for ( int i = 0; i < n; i++ ) {

    int b = 0;
    int c = 0;
    int input;
    bool flag = false;
    for ( int j = 0; j < 10; j++ ) {
      cin >> input;

      if ( input < b && input < c ) flag = true;
      if ( flag ) continue;

      if ( input < b ) {
	c = input;
      }else if ( input < c ) {
	b = input;
      }else {
	if ( b < c ) {
	  c = input;
	}else {
	  b = input;
	}
      }

    }

    if ( flag ) {
      cout << "NO" << endl;
    }else {
      cout << "YES" << endl;
    }

  }

  return 0;

}

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

int main(){
	int n;
	cin>>n;
	int a[n][n];
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			cin>>a[i][j];
		}
	}
	int mas = 1<<n;
	int dp[n+1][mas]; //finished the (k-1)^th
	memset(dp,-1,sizeof(dp));
	dp[0][0] = 1;
	
	for(int i=0; i<n; i++){
		for(int j=0; j<mas; j++){
			if(dp[i][j]==-1) continue;
			for(int k=0; k<n; k++){
				int val = j^(1<<k);
				if(val!=j&&a[i][k]==1){
					if(dp[i+1][val]==-1) dp[i+1][val] = dp[i][j];
					else dp[i+1][val] += dp[i][j];
					dp[i+1][val] %= 1000000007;
				} 
			}
		}
	}
	
	/*for(int i=0; i<=n; i++){
		for(int j=0; j<mas; j++){
			cout<<dp[i][j]<<' ';
		}
		cout<<endl;
	}*/
	if(dp[n][mas-1]==-1)cout<<0;
	else cout<<dp[n][mas-1];
}

Measured memory_bytes: 180480
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>>
#define CO cout<<
#define EN <<endl
#define all(x) (x).begin(),(x).end()
using namespace std;
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}
typedef long long ll;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

int main() {
	int n, y; CI n >> y;
	int ans[3] = {-1,-1,-1};
	if (10000 * n < y) REP(i, 3)ans[i] = -1;
	else {
			REP(i,n+1){
				if (i * 10000 > y)break;
				REP(j, n+1-i) {
					if (i * 5000 > y)break;
					REP(k, n+1-i-j) {
						if (i + j + k == n && i * 10000 + j * 5000 + k * 1000==y)ans[0] = i, ans[1] = j, ans[2] = k;
					}
				}
		}
	}

	REP(i, 3) { if (i == 3)CO ans[i] EN; CO ans[i] << " "; }
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>
#include <new>

using namespace std;

#define EPS (1e-9)
#define INF (1e9)
#define MOD (ll)(1e9 + 7)
#define PI (acos(-1))
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i, n) REP(i,0,n)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" ; "IMPOSSIBLE")

using ll = long long int;

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

ll beki(ll a, ll b) {
    ll tmp = 1;
    rep(i, b) tmp *= a;
    return tmp;
}

ll modPow(ll x, ll a) {
    if (a == 1) return x;
    if (a % 2) return (x * modPow(x, a - 1)) % MOD;
    ll t = modPow(x, a / 2);
    return ((t % MOD) * (t % MOD)) % MOD;
}

ll modInv(ll x) {
    return modPow(x, MOD - 2);
}

string S;
int Q;

int main() {
    cin >> S;
    cin >> Q;

    bool hanten[2] = { true, false };
    rep(i, Q) {
        int T;
        cin >> T;
        if (T == 1) {
            hanten[0] = !hanten[0];
            hanten[1] = !hanten[1];
        }
        else {
            int F;
            string C;
            cin >> F >> C;
            if (hanten[F - 1]) S.insert(0, C);
            else S += C;
        }
        //cout << S << endl;
    }
    if (hanten[0]) cout << S << endl;
    else rep(i, S.length()) cout << S[S.length() - 1 - i];
}

Measured memory_bytes: 3932
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define F first
#define S second
#define fast std::ios_base::sync_with_stdio(false)
#define mod 1000000007
#define pi 3.14159265
int main() {
	fast;
	lli b;
	cin>>b;
	stack<char>s;
	while(b>0){
		    if(b%26==0){
	            s.push('z');
	            b -= 26;
		    }
	        else
	            s.push('a'-1+b%26);
	        b/=26;
		}
	while(!s.empty()){
	        cout<<s.top();
	        s.pop();
		}
	
	return 0;
}

Measured memory_bytes: 3672
# def test():



# l = map(int, raw_input().split())

# if __name__ == "__main__":
#l = map(int, raw_input().split())
list_S = list(input())
# print(list_S)

num = 0
for s in list_S:
    if(s == "+"):  num = num + 1
    if(s == "-"):  num = num - 1

print(num)


Measured memory_bytes: 2940
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def dfs(graph, nd, toprogy, is_visited):
    is_visited.add(nd)
    for adj in graph[nd]:
        if adj not in is_visited:
            dfs(graph, adj, toprogy, is_visited)

    toprogy.appendleft(nd)

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, M] = [int(input_raw[0]), int(input_raw[1])]
    graph = {}
    inv_graph = {}
    for i in range(1, N + 1):
        graph[i] = []
        inv_graph[i] = []

    for i in range(N - 1 + M):
        input_raw = read_func().strip().split()
        [a, b] = [int(input_raw[0]), int(input_raw[1])]
        graph[a].append(b)
        inv_graph[b].append(a)

    sys.setrecursionlimit(200000)
    toprogy = deque([])
    is_visited = set([])
    for i in range(1, N + 1):
        if i not in is_visited:
            dfs(graph, i, toprogy, is_visited)

    toprogical_order = {}
    for i in range(N):
        toprogical_order[toprogy[i]] = i + 1

    for i in range(1, N + 1):
        max_toprogy = 0
        true_parent = 0
        for pare in inv_graph[i]:
            if pare not in toprogical_order:
                continue
            if max_toprogy < toprogical_order[pare]:
                max_toprogy =toprogical_order[pare]
                true_parent = pare
        print true_parent

if __name__ == '__main__':
    main()


Measured memory_bytes: 111560
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
        where <T as FromStr>::Err: Debug
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
        where <T as FromStr>::Err: Debug
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

fn main() {
    let nab: Vec<u64> = util::gets();
    let a = nab[1];
    let b = nab[2];

    let mut x: Vec<u64> = util::gets();
    x.sort();

    let a = x.windows(2)
        .map(|v| v[1] - v[0])
        .map(|d| a * d)
        .map(|l| min(l, b))
        .sum::<u64>();

    println!("{}", a);
}


Measured memory_bytes: 6396
#include<iostream>
#include<cstdio>
using namespace std;
int a,b,c,i;
int main(){
    scanf("%d%d%d",&a,&b,&c);
    for(i=1;i<=b;i++)
    {
        if((a*i)%b==c){printf("YES\n");return 0;}
    }
    printf("NO\n");
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{

 int a, b, c;

 scanf("%d %d %d" ,&a, &b, &c);

 if(a < b ){

  if(b < c){

   printf("%d %d %d\n" ,a, b, c);

   }

  else {

    if(a < c ){

     printf("%d %d %d\n",a, c, b);

    }

     else{

      printf("%d %d %d\n",c, a, b);
   }
  }
 }
 else{

  if(a < c){

   printf("%d %d %d\n" ,b, a, c);

  }

  else{
    
    if(b < c){

   printf("%d %d %d\n" ,b, c, a);

  }

  else{

   printf("%d %d %d\n" ,c, b, a);

   }
  }
 }
 return 0;

}

Measured memory_bytes: 1812
# 2019-11-12 16:33:33(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    s = sys.stdin.readline().rstrip()
    mm = int(s[5:7])
    dd = int(s[8:10])
    if mm <= 4 and dd <= 30:
        print('Heisei')
    else:
        print('TBD')


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define SPACE " "
#define pff first.first
#define pfs first.second
#define psf second.first
#define pss second.second

int main(){

	int N, M, Q;
	cin >> N >> M >> Q;
	int train[505][505];
	for(int i = 0; i <= N; i ++){
		for(int j = 0; j <= N; j ++){
			train[i][j] = 0;
		}
	}
	int l, r;
	for(int i = 0; i < M; i ++){
		cin >> l >> r;
		train[l][r] ++;
	}
	for(int i = 1; i <= N; i ++){
		for(int j = 1; j <= N; j ++){
			train[i][j] = train[i][j] + train[i - 1][j] + train[i][j - 1] - train[i - 1][j - 1];
		}
	}
	int p, q;
	for(int i = 0; i < Q; i ++){
		cin >> p >> q;
		cout << train[q][q] - train[q][p - 1] - train[p - 1][q] + train[p - 1][p - 1] << endl;
	}

	return 0;
}

Measured memory_bytes: 2048
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.rmi.server.ExportException;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Main m = new Main();
        m.solve();
    }
    private void solve() throws Exception {
        FastScan scan = new FastScan(System.in);
        int N = scan.scanInt();
        List<Path>[] graph = new List[N];
        for (int i = 0; i < N; i++) {
            graph[i] = new ArrayList<>();
        }
        for (int i = 0; i < N - 1; i++) {
            int a = scan.scanInt()-1;
            int b = scan.scanInt()-1;
            long c = scan.scanLong();
            Path p1 = new Path(b, c);
            graph[a].add(p1);
            Path p2 = new Path(a, c);
            graph[b].add(p2);
        }
        int Q = scan.scanInt();
        int K = scan.scanInt()-1;
        Queue<Integer> queue = new ArrayDeque<>();
        long[] distances = new long[N];
        boolean[] visited = new boolean[N];
        Arrays.fill(distances, Long.MAX_VALUE);
        distances[K] = 0;
        queue.add(K);
        while(!queue.isEmpty()) {
            int current = queue.poll();
            visited[current] = true;
            List<Path> neighbors = graph[current];
            for (Path p : neighbors) {
                if (visited[p.to]) {
                    continue;
                }
                distances[p.to] = distances[current] + p.cost;
                queue.add(p.to);
            }
        }
        for (int i = 0; i < Q; i++) {
            int from = scan.scanInt() - 1;
            int to = scan.scanInt() - 1;
            System.out.println(distances[from] + distances[to]);
        }
    }

    class Path {
        int to;
        long cost;
        Path(int to, long cost) {
            this.to = to;
            this.cost = cost;
        }
    }
    class FastScan {
        BufferedReader br;
        StringTokenizer st;
        FastScan(InputStream is) {
            InputStreamReader isr = new InputStreamReader(is);
            this.br = new BufferedReader(isr);
        }
        String next() throws IOException {
            while (this.st == null || !this.st.hasMoreTokens()) {
                this.st = new StringTokenizer(br.readLine().trim());
            }
            return st.nextToken();
        }
        long scanLong() throws IOException {
            return Long.parseLong(this.next());
        }
        int scanInt() throws IOException {
            return Integer.parseInt(this.next());
        }
        double scanDouble() throws IOException {
            return Double.parseDouble(this.next());
        }
        char scanCharacter() throws IOException {
            return this.next().charAt(0);
        }
        String nextLine() throws IOException {
            return br.readLine().trim();
        }
    }
}


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

int main()
{
    while (true)
    {
        int N;
        cin>>N;
        if (N==0)
            break;
        int ans = 1;
        bool ok = false;
        for (int i=0; i<N; i++)
        {
            int k;
            cin>>k;
            if (k>0)
                ans++;
            if (k>=2)
                ok = true;
        }
        if (ok)
            cout<<ans<<endl;
        else
            cout<<"NA"<<endl;
    }
}

Measured memory_bytes: 1160
def main():
    n, sum = list(map(int,input().split()))
    x_max = sum // 10000
    for x in reversed(range(0, x_max + 1)):
        for y in range(n - x + 1):
            z = n - x - y
            if 10000 * x + 5000 * y + 1000 * z == sum:
                    print(x, y, z)
                    return 0
    print('-1 -1 -1')
    return 0

main()

Measured memory_bytes: 3060
import sys
input=sys.stdin.readline
def two(x):
	p=bin(x)
	ans=p[2:]
	if len(ans)<n:
		ans="0"*(n-len(ans))+ans
	return ans
n=int(input())
aa=[]
aaa=[]
for i in range(n):
	a=int(input())
	aaa.append(a)
	qw=[]
	for j in range(a):
		x,y=map(int,input().split())
		qw.append([x,y])
	aa.append(qw)
anst=0
for i in range(2**n):
	p=two(i)
	flag=True
	syojiki=[]
	for u in range(n):
		if p[u]=="1":
			syojiki.append(1)
		else:
			syojiki.append(0)
	ans=p.count("1")
	for j in range(n):
		if flag==False:
			break
		if p[j]=="0":
			continue
		for k in range(aaa[j]):
			if aa[j][k][1]==0:
				if syojiki[aa[j][k][0]-1]==1:
					flag=False
					break
				syojiki[aa[j][k][0]-1]=0
			else:
				if syojiki[aa[j][k][0]-1]==0:
					flag=False
					break
				syojiki[aa[j][k][0]-1]=1
	if flag:
		anst=max(anst,ans)
print(anst)







Measured memory_bytes: 3064
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
#define inf 1000000000000000000
#define norm 0
#define mod 1000000007
#define IO                    \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
using namespace std;
ll fact[3000];
ll invfact[3000];
ll faspow(ll base, ll pow)
{
    if(pow==0)return 1;
    else if (pow ==1)return base;
    ll x=faspow(base,pow/2.0);
   x=(((x)%mod)*((x)%mod))%mod;
    if(pow%2)x*=(base%mod);
    x%=mod;
    return x;
}
ll inv(ll x)
{
    return faspow(x,mod-2);
}
void fill()
{
    fact[0]=1;
    invfact[0]=inv(fact[0]);
    for(int i=1;i<2050;i++)
    {
        fact[i]=((fact[i-1])*(i))%mod;
    }
}
ll ncr(ll n,ll r)
{
    ll a=fact[n],b=inv(fact[n-r]),c=inv(fact[r]);
    //cout<<a<<" "<<b<< " "<<c<<endl;
    return (a*b%mod*c%mod)%mod;
}
ll sss[2005][2005];
ll ss(ll num , ll dig)
{
    if(dig==0)return 1;
    if(sss[num][dig]!=-1)return sss[num][dig];
    ll res=0;
    for(int i=0;i<=dig;i++)
    {
        res+=ss(num-i,dig-1);
    }
    return sss[num][dig]= res;
}
int main()
{
    IO
    memset(sss,-1, sizeof(sss));
    fill();
    ll n,k;
    cin>>n>>k;
    for(int i=1;i<=k;i++)
    {
        ll num=ncr(k-1,i-1);
        ll add=i-1;
        ll freeseg=n-k;
        ll num2=ncr(freeseg+1,i);
       // cout<<num2<<endl;
        cout<<(num*num2)%mod<<endl;
    }
    return 0;
}



Measured memory_bytes: 31744
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
#define int long long
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
    const int MAX =200005;
const int MOD =1000000007;

signed main(){
int n,q;
cin>>n>>q;
int t,u,v;
dsu d(n);
for(int i=0;i<q;i++){
  cin>>t>>u>>v;
  if(t){
    if(d.same(u,v))cout<<1<<endl;
    else cout<<0<<endl;
  }else{
    d.merge(u,v);
  }
}
}

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

#define ll long long

bool isThere(int arr[], int ctr, int n)
{
	for(int i = 0; i < n; i++) {
		if(arr[i] == ctr) return true;
	}
	return false;
}

int main(void) 
{
	int x, n;
	cin >> x >> n;
	int arr[n];
	for(int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	
	int ctr1 = x;
	bool flag = true;
	while(flag) {
		if(isThere(arr, ctr1, n)) {
			ctr1++;
			continue;
		} else {
			flag = false;
		}
	}
	
	
	int ctr2 = x;
	flag = true;
	while(flag) {
		if(isThere(arr, ctr2, n)) {
			ctr2--;
			continue;
		} else {
			flag = false;
		}
	}
	
	int diff1 = abs(x - ctr1);
	int diff2 = abs(x - ctr2);
	
	//cout << diff1 << " " << diff2 << endl;
	
	if(diff1 == diff2) {
		if(ctr1 > ctr2) cout << ctr2 << endl;
		else cout << ctr1 << endl;
	} else if(diff1 > diff2) {
		cout << ctr2 << endl;
	} else {
		cout << ctr1 << endl;
	}
}


Measured memory_bytes: 3596
import java.util.*;

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

        int n = sc.nextInt();
        long ans = 0;

        for(long i = 1; i <= n; i++){
            ans += i * (n / i) * (n / i + 1) / 2;
        }

        System.out.println(ans);

    }
}


Measured memory_bytes: 35736
function main(input) {
  var n = input[0].split(" ")[0]-0;
  var m = input[0].split(" ")[1]-0;
  var map = [];
  for(var i=0;i<m;i++) map.push(0);
  input.filter((v,i)=>i>0).forEach(v=>{
    v.split(" ").filter((w,i)=>i>0).forEach(w=>{
      map[w-1]++;
    });
  });
  map.sort((a,b)=>a-b);
  console.log(map.filter(v=>v==n).length);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


Measured memory_bytes: 7628
package main

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

func solve() {
	s := getString()
	idx := len(s)

	ans := "YES"
	for idx > 0 {
		ng := true

		if idx >= 5 {
			if (s[idx-5:idx] == "dream") || (s[idx-5:idx] == "erase") {
				idx -= 5
				continue
			}
		}
		if idx >= 6 {
			if s[idx-6:idx] == "eraser" {
				idx -= 6
				continue
			}
		}
		if idx >= 7 {
			if s[idx-7:idx] == "dreamer" {
				idx -= 7
				continue
			}
		}

		if ng {
			ans = "NO"
			break
		}
	}
	fmt.Fprintln(wr, ans)
}

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

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	buf := 200001
	sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

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

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func getRunes() []rune {
	return []rune(getString())
}


Measured memory_bytes: 768
W=input()
count=1
w=[]

for j in range(len(W)):
    w.append(W[j])

w.sort()

w.append("")

for i in range(len(w)-1):
    if w[i]==w[i+1]:
        count+=1
    else:
        if count %2 !=0:
            print("No")
            exit()
        else:
            count=1

print("Yes")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  char a[4];
  
  cin>>a;
  if(a[0]==a[1]&&a[1]==a[2]||a[3]==a[1]&&a[1]==a[2])
    cout << "Yes" <<endl;
  else cout << "No" <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int x,y;
  cin>>x>>y;
   
  int sum=0;
  if(x==3)
    sum+=100000;
  else if(x==2)
    sum+=200000;
  else if(x==1)
    sum+=300000;
  
  if(y==3)
    sum+=100000;
  else if(y==2)
    sum+=200000;
  else if(y==1)
    sum+=300000;
 
   if(x==1&&y==1)
    sum+=400000;
  
  cout<<sum<<endl;
  
  return 0;
}

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

using namespace std;

const int L = 3000;
int lcs[L + 1][L + 1];
pair<int, int> construct[L + 1][L + 1];
char s[L + 1];
char t[L + 1];
char dummy = '.';

int main() {
    ios_base::sync_with_stdio(false);

    cin >> (s + 1);
    cin >> (t + 1);

    s[0] = dummy, t[0] = dummy;

    int ns = strlen(s) - 1;
    int nt = strlen(t) - 1;

    lcs[0][0] = 0;

    for (int i = 1; i <= ns; i++) {
        for (int j = 1; j <= nt; j++) {
            if (s[i] == t[j]) {
                lcs[i][j] = lcs[i - 1][j - 1] + 1;
                construct[i][j] = make_pair(i - 1, j - 1);
            }
            else {
                if (lcs[i][j - 1] > lcs[i - 1][j]) {
                    lcs[i][j] = lcs[i][j - 1];
                    construct[i][j] = make_pair(i, j - 1);
                }
                else {
                    lcs[i][j] = lcs[i - 1][j];
                    construct[i][j] = make_pair(i - 1, j);
                }
            }
        }
    }

    stack<char> res;
    
    int x = ns;
    int y = nt;

    while (x != 0 && y != 0) {
        int nx = construct[x][y].first;
        int ny = construct[x][y].second;
        if (x != nx && y != ny) {
            res.push(s[x]);
        }
        x = nx, y = ny;
    }

    while (!res.empty()) {
        cout << res.top();
        res.pop();
    }

    cout << '\n';

    return 0;
}


Measured memory_bytes: 105856
import java.util.*;

public class Main {
  public static void main(String[] args){
    int count = 0;
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] num = new int[N];
    for(int i=0; i < N; i++){
    num[i] = sc.nextInt();
  }
  for(int i=0; i < N; i++){
      if(num[num[i]-1] == i+1){
        count++;          
      }
  }
  System.out.println(count/2);
  }
}

Measured memory_bytes: 51012
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int ans = 0;
            while (n > 0) {
                if (n % 2 != 0) {
                    if (n % 3 == 0 && n % 5 == 0 && n % 7 == 0) ans++;
                    if (n % 3 == 0 && n % 5 == 0 && n % 11 == 0) ans++;
                    if (n % 3 == 0 && n % 5 == 0 && n % 13 == 0) ans++;
                    if (n % 27 == 0 && n % 5 == 0) ans++;
                    if (n % 27 == 0 && n % 7 == 0) ans++;
                }
                n--;
            }

            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 21716
#include<iostream>
#include<vector>
#include<stack>
#include<list>
using namespace std;

stack<long long> sta;
list<long long>::iterator t;
long long k;

void trans_tree(list<long long> pre_adj[], bool val[], long long dad[]){
    sta.push(1);
    while(!sta.empty()){
        k = sta.top();
        sta.pop();
        for(t = pre_adj[k].begin(); t != pre_adj[k].end(); ++t){
            if(!val[*t]){
                sta.push(*t);
                dad[*t] = k;
                val[*t] = 1;
            }
        }
    }
}

void tree_add(list<long long> adj[], long long counta[]){
    sta.push(1);
    while(!sta.empty()){
        k = sta.top();
        sta.pop();
        for(t = adj[k].begin(); t != adj[k].end(); ++t){
            sta.push(*t);
            counta[*t] += counta[k];
        }
    }
}

int main(){
    //input
    long long N, Q;
    cin >> N >> Q;
    long long a, b;
    long long j, k;
    list<long long> pre_adj[N+1];
    for(j = 1; j <= N-1; j++){
        cin >> a >> b;
        pre_adj[a].push_back(b);
        pre_adj[b].push_back(a);
    }
    bool val[N+1];
    val[1] = 1;
    for(j = 2; j <= N; j++){
        val[j] = 0;
    }
    long long dad[N+1];
    trans_tree(pre_adj, val, dad);
    list<long long> adj[N+1];
    for(j = 2; j <= N; j++){
        adj[dad[j]].push_back(j);
    }
    long long counta[N+1];
    for(j = 1; j <= N; j++){
        counta[j] = 0;
    }
    long long p, x;
    for(k = 0; k < Q; k++){
        cin >> p >> x;
        counta[p] += x;
    }

    //calc
    tree_add(adj,counta);
    
    //answer
    for(j = 1; j <= N; j++){
        cout << counta[j] << " ";
    }
    cout << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 30968
W,H = map(int,input().split())
edges = []
for i in range(W):
    p = int(input())
    edges.append((p,0))
for i in range(H):
    q = int(input())
    edges.append((q,1))
edges.sort(key = lambda x:x[0])
ans = 0
w = W+1
h = H+1
for a,b in edges:
    if b == 0:
        w -= 1
        ans += h*a
    else:
        h -= 1
        ans += w*a
print(ans)

Measured memory_bytes: 98380
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

const int N = 1000 * 100 + 1000; 
int T[N][3];
int H[N][3];

#define INF 10000000001

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

	for(int i = 1; i <= n; i ++){
		//T[i][0] = T[i][1] = T[i][2] = INF;
		int hi; 
		cin >> H[i][0] >> H[i][1] >> H[i][2];
	}
	
	T[1][0] = H[1][0];
	T[1][1] = H[1][1];
	T[1][2] = H[1][2];

	for(int i = 1; i <= n; i ++){
		for(int j = 0; j < 3; j ++){
			for(int k = 0; k < 3; k ++){
				if (j != k){
					T[i+1][k] = max(H[i+1][k] + T[i][j], T[i+1][k]); 
				}
			}
		}
	}
	cout << max(max(T[n+1][0], T[n+1][1]), T[n+1][2]) << endl;


	int s; cin >> s; 
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());

typedef long long ll;

int main(){
  string s;
  cin >>s;
  cout << s[0] << s.size()-2 << s[s.size()-1] << endl;
}

Measured memory_bytes: 256
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

#https://note.nkmk.me/python-union-find/

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
n,m=MI()
lis=[LI() for i in range(m)]
u=UnionFind(n)
def com(x):
    return (x*(x-1))//2
ans=[]
for i in range(m):
    j=m-i-1
    #print(u.group_count())
    x,y=-u.parents[u.find(lis[j][0]-1)],-u.parents[u.find(lis[j][1]-1)]
    u.union(lis[j][0]-1,lis[j][1]-1)
    z=-u.parents[u.find(lis[j][0]-1)]
    delta=com(z)-com(x)-com(y)
    #print(x,y,z)
    #print(max(delta,0))
    ans.append(max(delta,0))
#print(ans)
val=[com(n) for i in range(m)]
for i in range(m-1):
    val[i+1]=val[i]-ans[i]
#print(val)
for i in range(m):
    j=m-i-1
    print(val[j])
    



Measured memory_bytes: 103440
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
//#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言

int main()
{
	int n;
	cin >> n;
	int i;

	vector<int>cnt(4);

	for (i = 0; i < n; i++)
	{
		string s;
		cin >> s;
		if (s == "AC")
		{
			cnt.at(0)++;
		}
		if (s == "WA")
		{
			cnt.at(1)++;
		}
		if (s == "TLE")
		{
			cnt.at(2)++;
		}
		if (s == "RE")
		{
			cnt.at(3)++;
		}
	}
	cout << "AC x " << cnt.at(0) << endl;
	cout << "WA x " << cnt.at(1) << endl;
	cout << "TLE x " << cnt.at(2) << endl;
	cout << "RE x " << cnt.at(3) << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    map<int, int> mp;
    int n, m;
    cin >> n >> m;
    int c1 = 0, c2 = 0;
    while(m--){
        int x;
        string s;
        cin >> x >> s;
        if(mp[x] == -1) continue;
        if(s[0] == 'A'){
            c1++;
            c2 += mp[x];
            mp[x] = -1;
        }
        else{
            mp[x]++;
        }
    }
    cout << c1 << ' ' << c2;

    return 0;
}


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

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  string s;
  cin >> s;
  int cur = 0;
  vector<int> RL, ans(s.length(), 0);
  int cntR = 0, cntL = 0, start = 0;
  rep(i, s.length()) {
    if (s[i] == 'R') cntR++;
    else if (s[i] == 'L') cntL++;
    if (s[i] == 'R' && s[i+1] == 'L') RL.emplace_back(i);
    else if ((s[i] == 'L' && s[i+1] == 'R')) {
      ans[RL.back()] = cntL/2 + cntR - cntR/2;
      ans[RL.back()+1] = cntR/2 + cntL - cntL/2;
      cntR = 0; cntL = 0;
    }
  }
  ans[RL.back()] = cntL/2 + cntR - cntR/2;
  ans[RL.back()+1] = cntR/2 + cntL - cntL/2;
  rep(i, s.length()) {
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
// please, read the question correctly (do you need set or multiset)???
const int N=200010; //check the limits, dummy
int a[N];
ll n, m;
int main(){
	// int t;
	// while(){
	ll d, x, y, cnt=0;
		scanf("%lld%lld",&n,&d);
		for(int i=0; i<n; ++i){
			scanf("%lld%lld",&x,&y);
			if(x*x+y*y<=d*d){
				++cnt;
			}
		}
		cout<<cnt<<endl;
	// }
}

Measured memory_bytes: 3680
S = input()
T = input()
min_change = 10**9
for posi_1 in range(len(S)-len(T)+1):
  tmp = 0
  for posi_2 in range(len(T)):
    if S[posi_1+posi_2] != T[posi_2]:
      tmp += 1
  min_change = min(tmp, min_change)
print(min_change)

Measured memory_bytes: 8896
#include <stdio.h>                                                              
                                                                                
int main(void)                                                                  
{                                                                               
  int a,b;                                                                      
  scanf("%d %d",&a,&b);                                                         
  printf("%d %d %f",a / b,a % b,(double) a / b);                                
  return 0;                                                                     
}  

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

int main(){
  int N,X;
  cin>>N>>X;
  int a[N];
  int d[N+1];
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  d[0]=0;
  int ans=0;
  for(int i=1;i<N+1;i++){
    d[i]=d[i-1]+a[i-1];
    if(d[i]<=X){
      ans++;
    }
  }
  cout<<ans+1<<endl;
  return 0;
}

  
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>

#define rep_ui(k,n)      for(ui  i = (k); i < (n); ++i)
#define rep_si(k,n)      for(int i = (k); i < (n); ++i)
#define rep_ul(k,n)      for(ul  i = (k); i < (n); ++i)
#define rep_sl(k,n)      for(ll  i = (k); i < (n); ++i)
#define rep_ui_down(k,n) for(ui  i = (k); i > (n); --i)
#define rep_si_down(k,n) for(int i = (k); i > (n); --i)
#define rep_ul_down(k,n) for(ul  i = (k); i > (n); --i)
#define rep_sl_down(k,n) for(ll  i = (k); i > (n); --i)

#define rep_uj(k,n)      for(ui  j = (k); j < (n); ++j)
#define rep_sj(k,n)      for(int j = (k); j < (n); ++j)
#define rep_uj_down(k,n) for(ui  j = (k); j > (n); --j)
#define rep_sj_down(k,n) for(int j = (k); j > (n); --j)

#define rep(k,n)         rep_ui(k,n)

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vc)
{
  for (auto it = vc.begin(); it != vc.end(); ++it)
  {
    if (std::next(it) == vc.end())
      os << *it;
    else
      os << *it << ' ';
  }
  return os;
}

template<class T1, class T2>
inline
std::ostream & operator<<(std::ostream & os, const std::pair<T1, T2> & p)
{
  return os << p.first << ' ' << p.second;
}

void solve(void)
{
  using std::string;
  using std::vector;
  using std::map;
  using std::pair;
  using std::cin;
  // string S{}; std::cin >> S;
  // ui N{}; cin >> N;
  ull N{}; cin >> N;

  ull min{std::numeric_limits<ull>::max()};
  rep_ul(0, 5)
  {
    ull tmp{}; cin >> tmp;
    min = std::min(min, tmp);
  }

  ull ans = (N + min - 1) / min + 4;

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

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 256
k, a, b = map(int, input().split())
add2 = b - a
s = 1
if add2 <= 2:
    s += k
else:
    if k + 1 <= a:
        s += k
    else:
        s = a
        k -= a - 1
        s += add2 * (k // 2)
        s += k % 2
    
print(s)

Measured memory_bytes: 2940
S = input()
T = input()

flag = False
def dfs(x, y):
    if y >= len(T):
        global flag
        flag = True
        return
    elif not S[x] in (T[y], '?'):
        return
    
    dfs(x+1, y+1)


ans = "UNRESTORABLE"
for i in range(len(S) - len(T) + 1)[::-1]:
    if S[i] in (T[0], '?'):
        dfs(i, 0)
        if flag:
            ans = S[:i] + T + S[i+len(T):]
            ans = ans.replace('?', 'a')
            break

print(ans)

Measured memory_bytes: 3064
import sys
def fastio():
    from io import StringIO
    from atexit import register
    global input
    sys.stdin = StringIO(sys.stdin.read())
    input = lambda : sys.stdin.readline().rstrip('\r\n')
    sys.stdout = StringIO()
    register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var, sep = ' ', end = '\n'):
    print(*var, file=sys.stderr, end = end, sep = sep)

INF = 10**20
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
# from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br

n, m = I()

a = [0] * (n + 1)
b = [0] * (n + 1)

for i in range(m):
    p, v = input().split()
    p = int(p)
    if b[p] == 0 and v == 'WA':
        a[p] += 1
    elif b[p] == 0 and v == 'AC':
        b[p] = 1

ans = 0
for i in range(n + 1):
    if b[i] == 1:
        ans += a[i]
print(sum(b), ans)

Measured memory_bytes: 8364
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<deque>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>
#include<functional>
using namespace std;
int x,y,z,k;
long long a[1005],b[1005],c[1005];
priority_queue<pair<long long,pair<int,pair<int,int> > > > q;
int main()
{
	scanf("%d %d %d %d",&x,&y,&z,&k);
	for(int i=0;i<x;i++)
		scanf("%lld",&a[i]);
	for(int i=0;i<y;i++)
		scanf("%lld",&b[i]);
	for(int i=0;i<z;i++)
		scanf("%lld",&c[i]);
	sort(a,a+x);
	sort(b,b+y);
	sort(c,c+z);
	q.push(make_pair(a[x-1]+b[y-1]+c[z-1],make_pair(x-1,make_pair(y-1,z-1))));
	int i=0;
	int pa=-1,pb=-1,pc=-1;
	while(i<k)
	{
		long long num=q.top().first;
		int ai=q.top().second.first;
		int bi=q.top().second.second.first;
		int ci=q.top().second.second.second;
		q.pop();
		if(pa!=ai||pb!=bi||pc!=ci)
		{
			i++;
			printf("%lld\n",num);
			pa=ai;
			pb=bi;
			pc=ci;
			if(ai>0)
				q.push(make_pair(num-a[ai]+a[ai-1],make_pair(ai-1,make_pair(bi,ci))));
			if(bi>0)
				q.push(make_pair(num-b[bi]+b[bi-1],make_pair(ai,make_pair(bi-1,ci))));
			if(ci>0)
				q.push(make_pair(num-c[ci]+c[ci-1],make_pair(ai,make_pair(bi,ci-1))));
		}
	}
	return 0;
}


Measured memory_bytes: 512
def main():
    lim = 1e18
    n = int(input())
    nums = list(map(int,str(input()).split(" ")))
    if 0 in nums:
        print(0)
        return
    ans = 1
    for num in nums:
        ans *= num
        if ans > lim:
            print(-1)
            return
    print(ans)
    return

main()


Measured memory_bytes: 21784