akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)

int N;
string S;
int K;

signed main(){
	cin>>N>>S>>K;
	char c=S[K-1];
	REP(i,S.size()){
		if(c!=S[i]){
			S[i]='*';
		}
	}
	cout<<S<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(void){

    int a,b,C;
    double L,h,c2,S,c;
    double PI=acos(-1);
    scanf("%d %d %d", &a,&b,&C);
    
    S=0.5*sin(C*PI/180)*a*b;
    c2=a*a+b*b-2*a*b*cos(C*PI/180);
    c=sqrt(c2);
    L=a+b+c;
    h=2*S/a;
    printf("%f %f %f\n",S,L,h);
    return 0;
}



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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vld vector < ld >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < long , long >
# define pDD pair < D , D >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10f",n);
# define line cout<<"\n";

const ld pie = 3.14159265358979 ;
const ll mod = 1e9 + 7 ;

string vow = "aeiou";

void solve ( int test_case )
{
    string s , t ;
    cin >> s >> t ;

    int cnt = 0 ;
    for ( int i=0 ; i < 3 ; i++ )
        cnt += (s[i] == t[i] ) ;

    cout << cnt ; line
}

int main()
{
    int t = 1;
    //cin >> t;

    for ( int i=0 ; i<t ; i++ ) solve(i);
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

from collections import deque

N = int(input())

A = [0 for i in range(N)]
for i in range(N) :
    L = list(map(int,input().split()))
    for j in range(len(L)) :
        L[j] -= 1
    A[i] = deque(L)

#print(A)
ans = 0
flg = 0

zuru = 0

while flg == 0 :
    zuru += 1
    cnt = 0
    cnt2 = 0
    flg = 1

    if zuru >= 10**4 :
        ans = 499500
        print(ans)
        exit()
    
    for i in range(N) :
        if len(A[i]) == 0 :
            cnt += 1
        elif A[i][0] == -1 :
            A[i].popleft()
        elif A[i][0] < i :
            cnt2 += 1
            continue
        elif i == A[A[i][0]][0] :
            a = A[i].popleft()
            A[a][0] = -1
            flg = 0
        else :
            cnt2 += 1
    if cnt == N :
        flg = 1
    elif flg == 0 :
        ans += 1
    elif (N-cnt) == cnt2 :
        ans = -1

print(ans)


Measured memory_bytes: 72412
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    s = input()

    cnt_B = 0
    res = 0
    for i in s:
        if i == "B":
            cnt_B += 1

        if i == "W":
            res += cnt_B

    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3500
n,k = map(int, input().split())
ans = 0
for b in range(k+1,n+1):
    r = n//b
    ans += (b-k)*r
    if (n-r*b-k + 1)>0:
        ans += (n - r*b - k + 1)

if k == 0:
    ans =n**2

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
typedef pair<int,int> P;
struct UnionFind{
    vector<int> par,depth;
    UnionFind(int n){
        par.resize(n); depth.resize(n);
        for(int i=0; i<n; i++){
            par[i]=i;
            depth[i]=0;
        }
    }
    int find(int x){
        if(par[x]==x){
            return x;
        }
        else{
            return par[x]=find(par[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(depth[x]<depth[y]) swap(x,y);
        if(depth[x]==depth[y]) depth[x]++;
        par[y]=x;
    }
};
int main() {
    int n,k,l;
    cin >> n >> k >> l;
    UnionFind ufa(n);
    UnionFind ufb(n);
    map<P,int> mp;
    for(int i=0; i<k; i++){
        int p,q;
        cin >> p >> q;
        p--;q--;
        ufa.unite(p,q);
    }
    for(int i=0; i<l; i++){
        int r,s;
        cin >> r >> s;
        r--;s--;
        ufb.unite(r,s);
    }
    for(int i=0; i<n; i++){
        mp[P(ufa.find(i),ufb.find(i))]++;
    }
    for(int i=0; i<n; i++){
        cout << mp[P(ufa.find(i),ufb.find(i))] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 15104
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args){

		solve_abc165_b();
	}
  
  	public static void solve_abc165_b(){
		
		Scanner sc = new Scanner(System.in);
		
		long N = sc.nextLong();
		int K = sc.nextInt();
		
		String N2 = Long.toString(N,K);
		
		//System.out.println(N2);
		System.out.println(N2.length());
	}
}

Measured memory_bytes: 25044
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

template<class T>
bool is_prime(T x)
{
    if (x == 2) {
        return true;
    }

    if (x % 2 == 0) {
        return false;
    }

    for (T i = 3; i * i <= x; i += 2) {
        if (x % i == 0) {
            return false;
        }
    }

    return true;
}

int num(int m, const unordered_map<int, int>& primes)
{
    return count_if(begin(primes), end(primes), [m](const auto& p){ return p.second >= m-1; });
}

int main()
{
    int N;
    cin >> N;

    unordered_map<int, int> primes;
    for (int i = 2; i <= 100; ++i) {
        if (is_prime(i)) {
            primes[i] = 0;
        }
    }

    for (int i = 1; i <= N; ++i) {
        int n = i;
        for (auto&& p : primes) {
            while (n % p.first == 0) {
                p.second++;
                n /= p.first;
            }
        }
    }

    int ans = 0;

    ans += num(75, primes);
    ans += num(25, primes) * (num(3, primes) - 1);
    ans += num(15, primes) * (num(5, primes) - 1);
    ans += num( 5, primes) * (num(5, primes) - 1) * (num(3, primes) - 2) / 2;

    cout << ans << endl;

    return 0;
}


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

using namespace std;

int N,M;
vector<pair <int,int> > data; 

int main(){
  cin >> N >> M;
  vector<vector<int> > A(N+1); 
  for(int i=0;i<M;i++){
    int a ,b;
    cin>>a>>b;
    data.push_back(make_pair(a,b));
    A[a].push_back(b);
  }
  
  for(int i=0;i<N+1;i++){
    sort(A[i].begin(),A[i].end());
  }
  for(int i=0;i<M;i++){
    int l = data[i].first;
    auto idx = lower_bound(A[l].begin(),A[l].end(),data[i].second);
    printf("%06d%06lu\n",l,idx-A[l].begin()+1);
  }
}


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

int main(void)
{
	char in, len, i;
	while ((in = fgetc(stdin)) != EOF) {
		if (in == '@') {
			len = fgetc(stdin) - '0';
			in = fgetc(stdin);
			for (i = 0; i < len; i++)
				fputc(in, stdout);
		} else {
			fputc(in, stdout);
		}
	}
	exit(0);
}

Measured memory_bytes: 524
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptor/reversed.hpp>
#include<boost/operators.hpp>
#include<boost/dynamic_bitset.hpp>
namespace adaptor = boost::adaptors;
template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;
namespace lib
{
	template<class T>constexpr T pow(T val, std::uint64_t p)
	{
		auto ret = T(1);
		for (auto i : boost::irange(0, 63))
		{
			if (p & (1ULL << i))
			{
				ret *= val;
			}
			val *= val;
		}
		return ret;
	}
	template<std::uint64_t Mod>class modnum :
		private boost::addable<modnum<Mod>>,
		private boost::subtractable<modnum<Mod>>,
		private boost::multipliable<modnum<Mod>>,
		private boost::dividable<modnum<Mod>>
	{
		std::uint64_t val;
		void clamp()
		{
			val %= Mod;
		}
	public:
		modnum() = default;
		modnum(std::int64_t v) :val()
		{
			if (v < 0)
			{
				v += (std::abs(v) / Mod + 1) * Mod;
			}
			val = v;
			clamp();
		}
		modnum(std::uint64_t v) :val(v)
		{
			clamp();
		}
		modnum(std::int32_t v) :modnum(static_cast<std::int64_t>(v))
		{

		}
		modnum(std::uint32_t v) :modnum(static_cast<std::uint64_t>(v))
		{

		}
		friend std::ostream& operator<<(std::ostream & os, modnum const& num)
		{
			return os << num.val;
		}
		auto& operator+=(modnum const& rhs)
		{
			val += rhs.val;
			clamp();
			return *this;
		}
		auto& operator-=(modnum const& rhs)
		{
			val += Mod - rhs.val;
			clamp();
			return *this;
		}
		auto& operator*=(modnum const& rhs)
		{
			val *= rhs.val;
			clamp();
			return *this;
		}
		auto& operator/=(modnum const& rhs)
		{
			val *= pow(rhs, Mod - 2).val;
			clamp();
			return *this;
		}
		auto const& operator*()const
		{
			return val;
		}
	};
}
const std::size_t size = 1000003;
using mod_t = lib::modnum<size>;

mod_t run(mod_t x, mod_t d, std::uint64_t n, std::vector<mod_t>const& fact)
{
	if (*d == 0)
	{
		return lib::pow(x, n);
	}
	auto k = x / d;
	if (*(mod_t() - k) < n)
	{
		return 0;
	}
	return lib::pow(d, n)* fact[*k + n - 1] / fact[*k - 1];
}

void Main()
{
	std::vector<mod_t> fact(size);
	fact[0] = 1;
	for (auto i : boost::irange<std::size_t>(1, size))
	{
		fact[i] = fact[i - 1] * i;
	}
	int Q;
	std::cin >> Q;
	for (auto i : boost::irange(0, Q))
	{
		int x, d;
		std::uint64_t n;
		std::cin >> x >> d >> n;
		std::cout << run(x, d, n, fact) << std::endl;
	}
}

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

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

int main(void) {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < n; ++ i) {
        cout << s[i] << t[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {

	int N;
	scanf("%d", &N);
	 if (N % 1000 == 0) {
		puts ("0");
	} else{
		printf ("%d\n", ((N/1000) + 1) * 1000 - N);
	}
	
	return 0;
}

Measured memory_bytes: 1724
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function root(uf::Array{Int,1},x);s=x;while uf[s]>0;s=uf[s];end;s;end
function same(uf::Array{Int,1},x,y);root(uf,x)==root(uf,y)?true:false;end
function unite(uf::Array{Int,1},x,y);l=root(uf,x);r=root(uf,y);if l<r;uf[l]+=uf[r];uf[r]=l;elseif l>r;uf[r]+=uf[l];uf[l]=r;end;end

function main()
	n = readline() |> parseInt
	e = [Int[] for i in 1:n]
	da = Array{Int}(2,n-1)
	for i in 1:n-1
		da[:,i] = readline() |> split |> parseMap
		push!(e[da[1,i]],da[2,i])
		push!(e[da[2,i]],da[1,i])
	end
	c = -ones(Int,n)
	c[1] = 0
	d = -ones(Int,n)
	d[n] = 0
	s = Int[1]
	while !isempty(s)
		now = shift!(s)
		for i in 1:length(e[now])
			if c[e[now][i]] < 0
				push!(s,e[now][i])
				c[e[now][i]] = c[now]+1
			end
		end
	end
	s = Int[n]
	while !isempty(s)
		now = shift!(s)
		for i in 1:length(e[now])
			if d[e[now][i]] < 0
				push!(s,e[now][i])
				d[e[now][i]] = d[now]+1
			end
		end
	end
	th = div(c[n],2)
	ti = c[n]-th
	o = 1
	p = n
	for i in 2:n-1
		if c[i]==th && d[i]==ti
			o = i
		end
		if c[i] == th+1 && d[i] == ti-1
			p = i
		end
	end
	uf = -ones(Int,n)
	for i in 1:n-1
		if da[:,i] != [o,p] && da[:,i] != [p,o]
			unite(uf,da[1,i],da[2,i])
		end
	end
	println(uf[root(uf,1)]<uf[root(uf,n)]?"Fennec":"Snuke")
end

main()

Measured memory_bytes: 176932
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define mod 1000000007
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define MAXX 1000000000000000000


int hei[100005], good = 0, v[100005];
std::vector<std::vector<int> > adj(100005);

void dfs(int x)
{
	int fl = 1;
	v[x] = 1;
	for(auto it : adj[x])
	{
		if(!v[it])
		{
			dfs(it);
		}
		if(hei[it] >= hei[x])
		{
			fl = 0;
		}
	}
	if(fl)
	{
		good++;
	}
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n,i,j,x,y,p,q,m;
	cin >> n >> m;

	for(i=1;i<=n;i++)
	{
		cin >> hei[i];
	}
	
	while(m--)
	{
		cin >> x >> y;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	
	for(i=1;i<=n;i++)
	{
		if(adj[i].size() == 0)
		{
			good++;
		}
		else if(!v[i])
		{
			dfs(i);
		}
	}
	cout << good;
	return 0;
}

Measured memory_bytes: 12172
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    int r;
    cin >> r;

    if (r < 1200) {
        cout << "ABC" << endl;
    } else if (r < 2800) {
        cout << "ARC" << endl;
    } else {
        cout << "AGC" << endl;
    }

    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)

using namespace std;
using ll = long long;
typedef pair<int, int> Pair;

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

  vector<int> dp(n);
  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);
  
  if (n > 2) {
    for (int i = 2; i < n; i++) {
      int cost1 = abs(h[i] - h[i - 1]);
      int cost2 = abs(h[i] - h[i - 2]);
      dp[i] = min(dp[i - 1] + cost1, dp[i - 2] + cost2);
    }
  }
  int ans = dp[n-1];
  cout << ans << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

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

		while(scan.hasNext()){
			char sur[][] = new char[8][8];
			int p=0, c=0;
			boolean judge = false;
			char t = ' ';

			for(int i=0; i<8; i++){
				sur[i] = scan.next().toCharArray();
			}

			for(int i=0; i<8; i++){
				for(int j=0; j<8; j++){
					if(sur[i][j] == '1'){
						judge=true;
						c += p;
					}
					if(judge)
						p++;
				}
			}

			if(c==18){t = 'A';}
			else if(c==48){t = 'B';}
			else if(c==6){t = 'C';}
			else if(c==30){t = 'D';}
			else if(c==20){t = 'E';}
			else if(c==34){t = 'F';}
			else if(c==16){t = 'G';}

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

Measured memory_bytes: 20044
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
    cin >> first;
    IN(rest...);
    return;
}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
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; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

const int MOD = 1000000007;

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

int main() {
   SS(ll,a,b)
   p(max(a+b,max(a-b,a*b)));
}

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

Measured memory_bytes: 128
h, w = gets.split.map(&:to_i)
c = gets.split.map(&:to_i)
d = gets.split.map(&:to_i)
s = Array.new(h + 4) { Array.new(w + 4, -1) }
h.times do |j|
  gets.chomp.chars.each_with_index do |t, i|
    if t == '.'
      s[j + 2][i + 2] = 0
    end
  end
end
u = [[-2, -2], [-2, -1], [-2, 0], [-2, 1], [-2, 2],
    [-1, -2], [-1, -1], [-1, 1], [-1, 2],
    [0, -2], [0, 2],
    [1, -2], [1, -1], [1, 1], [1, 2],
    [2, -2], [2, -1], [2, 0], [2, 1], [2, 2]
  ]
que = []
wqu = []
que << [c[0] + 1, c[1] + 1]
s[c[0] + 1][c[1] + 1] = 1
while que.size > 0 || wqu.size > 0
  while que.size > 0
    y, x = que.shift
    cnt = s[y][x]
    if s[y + 1][x] == 0
      s[y + 1][x] = cnt
      que << [y + 1, x]
    elsif s[y + 1][x] == -1
      wqu << [y, x]
    end
    if s[y - 1][x] == 0
      s[y - 1][x] = cnt
      que << [y - 1, x]
    elsif s[y - 1][x] == -1
      wqu << [y, x]
    end
    if s[y][x + 1] == 0
      s[y][x + 1] = cnt
      que << [y, x + 1]
    elsif s[y][x + 1] == -1
      wqu << [y, x]
    end
    if s[y][x - 1] == 0
      s[y][x - 1] = cnt
      que << [y, x - 1]
    elsif s[y][x - 1] == -1
      wqu << [y, x]
    end
  end
  while wqu.size > 0
    y, x = wqu.shift
    cnt = s[y][x]
    u.each do |j, i|
      if s[y + j][x + i] == 0
        s[y + j][x + i] = cnt + 1
        que << [y + j, x + i]
      end
    end
  end
end
puts s[d[0] + 1][d[1] + 1] - 1

Measured memory_bytes: 25824
#  --*-coding:utf-8-*--

def main():
    N, Q = map(int, input().split())
    V = [[] for _ in range(N)]

    for i in range(N-1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        V[a].append(b)
        V[b].append(a)

    P = [None]*N
    S = [0]
    P[0] = -1

    while len(S) > 0:
        parntNode = S.pop()
        for childNode in V[parntNode]:
            if P[childNode] == None:
                P[childNode] = parntNode
                S.append(childNode)


    X = [0]*N
    for i in range(Q):
        p, x = map(int, input().split())
        X[p-1] += x

    Y = [None]*N
    Y[0] = X[0]
    
    for i in range(1, N):
        if Y[i] != None:
            continue

        T = []
        node = i

        while Y[node] == None:
            T.append(node)
            node = P[node]

        s = Y[node]

        for j in reversed(T):
            s += X[j]
            Y[j] = s
        
    print(' '.join(map(str, Y)))
    

if __name__ == '__main__':
    main()



Measured memory_bytes: 73640
#include <bits/stdc++.h>
using namespace std;
#define ROUNDUP(divisor,dividend) (divisor + (dividend - 1)) / dividend
string s,s1,s2; int a,b,temp; bool ym=false,my=false;
int main(){
  cin >> s;
  temp = stoi(s);
  a = temp / 100;
  b = temp % 100;
  if(b <= 12 && 0 < b){
    ym = true;
  }
  if(a <= 12 && 0 < a){
    my = true;
  }
  cout << (ym && my ? "AMBIGUOUS" : ym ? "YYMM" : my ? "MMYY" : "NA") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

typedef pair<int,int> P;
typedef long long ll; 

ll mod = 1e9 + 7;

int main(){
	int n,m;
	cin >> n>> m;
	if(n==m)cout << "Yes" <<endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
s=input()
sf=int(s[:2])
sl=int(s[2:])

if (sf>12 or sf==0) and sl<=12 and 0!=sl:
  print("YYMM")
elif (sl>12 or sl==0) and sf<=12 and 0!=sf:
  print("MMYY")
elif sf<=12 and sl<=12 and sf*sl!=0:
  print("AMBIGUOUS")
else:
  print("NA")


Measured memory_bytes: 3060
n,k = (int(i) for i in input().split())
num,x,N,ans,f = 0,[],n,0,1
while f:
    if k==1: f = 0
    if n>=k: x.append((n-k+1,num))
    n,k,num = min(n,k-1),(k+1)//2,num+1
for i,j in x: ans+=(2**(num-j))*i
print(1.0*ans/(N*(2**num)))

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
 
int main() {
  int h, w;
  while (true) {
    cin >> h >> w;
    if (h == 0 && w == 0) break;
     
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if (i % 2 == 0) {
          if (j % 2 == 0) {
            cout << "#";
          } else {
            cout << ".";
          }
        } else {
          if (j % 2 == 0) {
            cout << ".";
          } else {
            cout << "#";
          }          
        }
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1152
let replace s =
  let len = String.length s in
  let rec loop s2 = function
      i when i = len -> s2
    | i ->
       if s2.[i] = 'H' then
         if i + 6 < len && String.sub s i 7 = "Hoshino" then
           begin
             Bytes.set s2 (i+6) 'a';
             loop s2 (i+7)
           end
         else loop s2 (i+1)
       else
         loop s2 (i+1)
  in loop s 0
;;

let () =
  let n = read_int () in
  for i = 0 to n-1 do
    Printf.printf "%s\n" (read_line () |> replace)
  done
;;

Measured memory_bytes: 2132
package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	A := sc.NextIntArray()

	sort.Ints(A)

	fmt.Println(A[N-1] - A[0])

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int k[]={1,1,2,6,24,120,720,5040,40320};
int solve()
{
    int a[10];
    for(int i=0;i<n;i++)
        cin >> a[i];
    int index=0;
    for(int i=0;i<n;i++)
    {
        int t=0;
        for(int j=i+1;j<n;j++)
            if(a[j]<a[i])t++;
        index+=t*k[n-i-1];
        //cout << t << " "<<index << endl;
    }
    return index;
}
int main()
{
    cin >> n;
    cout << abs(solve()-solve()) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{   int n,d;
    scanf("%d%d",&n,&d);
    int x[n][d],ans=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            scanf("%d",&x[i][j]);
        }
    }
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            long lensq=0;
            for(int k=0;k<d;k++){
                lensq+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }
            double t=sqrt(lensq);
            t=floor(t);
            if(t*t==lensq)ans++;
            
        }
    }
    printf("%d",ans);

    return 0;
}


Measured memory_bytes: 128
#include<cstdio>
using namespace std;
long long m,v[100001];
long long ans=1,cnt=0,p=0,k=1;
int main()
{
	scanf("%lld",&m);
	for(int i=1;i<=m;i++)
	{
	scanf("%lld",&v[i]);
	int z=(v[i-1]+1)/2-(i-1);
	while(z<p)
	{
		ans=ans*cnt%1000000007;
		cnt--;
		p--;
		k++;
	}
	cnt++;
	}
	for(;k<=m;k++)
	ans=ans*(cnt--)%1000000007;
	printf("%lld",ans);
}

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

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int count[4] = {};
    
    for(int i=0; i<3; i++){
        int a,b;
        cin >> a >> b;
        
        count[a-1]++;
        count[b-1]++;
    }
    
    int count1 = 0, count2 = 0;
    
    for(int i=0; i<4; i++){
        switch (count[i]){
            case 1 : count1++; break;
            case 2 : count2++; break;
        }
    }
    
    if(count1 == 2 && count2 == 2){
        puts("YES");
    }else{
        puts("NO");
    }
    
    return 0;
}


Measured memory_bytes: 256
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
minimum = 10**5
ans = 0
for i in range(N):
    if minimum > abs(A - (T-H[i] * 0.006)):
        minimum = abs(A - (T-H[i] * 0.006))
        ans = i+1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = (int)1e9 + 7;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    string a, b, c;
    cin >> a >> b >> c;
    
    int ans = 0;
    REP(i, n){
        map<char, int> mp;
        mp[a[i]]++;
        mp[b[i]]++;
        mp[c[i]]++;
        int cnt = 0;
        for(auto x : mp) cnt = max(cnt, x.second);
        ans += 3 - cnt;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h1 = sc.nextInt();
		int m1 = sc.nextInt();
		int h2 = sc.nextInt();
		int m2 = sc.nextInt();
		int k = sc.nextInt();
		int awakeningTime = 0;
		if(m2 >= m1) {
			awakeningTime = 60 * (h2 -h1) + (m2 -m1);
		}else {
			awakeningTime = 60 * (h2 -h1-1) + (m2 + (60 - m1));
		}
		System.out.println(awakeningTime - k);
	}

}

Measured memory_bytes: 27004
n,m=map(int,input().split())
templ=[0]*m
temp=[]
tempb=[]
ans=0
for i in range(0,m):
  a,b=map(int,input().split())
  templ[i]=[a,b]
  if a==1:
    if b==n:
      print("POSSIBLE")
      ans=1
      break
    else:
      temp.append(b)
  if b==n:
    tempb.append(a)
if len(temp)>=1 and ans==0:
  temp=set(temp)
  tempb=set(tempb)
  c = temp&tempb
  #c = [x for x in temp if x in tempb]
  if len(c)>=1:
    print("POSSIBLE")
  else:
    print("IMPOSSIBLE")
  """
  for i in range(0,len(tempb)):
    if tempb[i] in temp:
      print("POSSIBLE")
      break
  """
else:
  print("IMPOSSIBLE")            
    

Measured memory_bytes: 44708
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().Solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    Random rnd = new Random();
    Stopwatch sw = new Stopwatch();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";


    void Solve()
    {
        int N = cin.Nextint;
        var S = new char[N][];
        for (int i = 0; i < N; i++)
        {
            S[i] = cin.Next.OrderBy(j => j).ToArray();
        }

        string ans = "";

        var M = new int[N];

      
        while (M[0] < S[0].Length)
        {
            var u = S[0][M[0]];
            bool flag = true;
            for (int i = 1; i < N; i++)
            {
                while(M[i] < S[i].Length && S[i][M[i]] < u)
                {
                    M[i]++;
                }
                if (M[i] >= S[i].Length)
                {
                    flag = false;
                    break;
                }

                if (S[i][M[i]] > u)
                {
                    flag = false;
                    break;
                }

            }
            if (flag)
            {
                M = M.Select(i => i + 1).ToArray();
                ans += u;
            }
            else
            {
                M[0]++;
            }
        }

        WriteLine(ans);


    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] Scan { get { return ReadLine().Split(); } }
    public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } }
    public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } }
    public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } }
    public string Next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return Next;
        }
    }
    public int Nextint { get { return int.Parse(Next); } }
    public long Nextlong { get { return long.Parse(Next); } }
    public double Nextdouble { get { return double.Parse(Next); } }
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1000;

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

int n, m, ans;
char s[MAXN+10][MAXN+10];
int dist[MAXN+10][MAXN+10];

struct Queue
{
    int y, x, t;
};
queue<Queue> Q;

int main()
{
    int i, j;

    scanf("%d%d", &n, &m);
    for(i=1; i<=n; i++) scanf("%s", s[i]+1);

    for(i=1; i<=n; i++) for(j=1; j<=m; j++) if(s[i][j]=='#') Q.push({i, j, 0});
    while(!Q.empty())
    {
        Queue T=Q.front();
        Q.pop();
        ans=max(ans, T.t);

        for(i=0; i<4; i++)
        {
            int ny=T.y+dy[i], nx=T.x+dx[i];
            if(!(1<=ny && ny<=n && 1<=nx && nx<=m)) continue;
            if(s[ny][nx]=='.')
            {
                Q.push({ny, nx, T.t+1});
                s[ny][nx]='#';
            }
        }
    }
    printf("%d", ans);
}


Measured memory_bytes: 15248
for _ in[0]*int(input()):
 X,z=input(),[]
 for y in input():
  s=i=0
  for k in z:
   t=X.find(y,s)+1
   if t<1:break
   if t<k:z[i]=t
   s=k;i+=1
  else:
   t=X.find(y,s)+1
   if t:z+=[t]
 print(len(z))


Measured memory_bytes: 5620
#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    int a, b;
    cin >> a >> b;
    cout << (a + b + 1) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String S = sc.next();
		String T = sc.next();
		System.out.println(T.substring(0, T.length()-1).equals(S) ? "Yes" : "No");
		
		sc.close();
	}
}


Measured memory_bytes: 27000
#include<bits/stdc++.h>
using namespace std;
const int N=200005,M=1e9+7;
int n,a[N],dp[N],s[N];
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)scanf("%d",&a[i]);
	int m=1;
	for (int i=2;i<=n;i++)
		if (a[i]!=a[i-1])a[++m]=a[i];
	dp[0]=1;
	for (int i=1;i<=m;i++){
		dp[i]=(s[a[i]]+dp[i-1])%M;
		(s[a[i]]+=dp[i-1])%=M;
	}
	printf("%d\n",dp[m]);
}


Measured memory_bytes: 2560
import java.util.*;
import java.math.*;

class Main{
	public static void main(String Args[]){
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		BigInteger A = new BigInteger(str);
		str = sc.next();
		BigInteger B = new BigInteger(str);
		System.out.println(A.multiply(B));
	}
}



Measured memory_bytes: 26624
#include <iostream>
#include<vector>
using namespace std;
#include<set>
#include<algorithm>
#include<string>
int main(){
	int n;
	int b;
	long long int sum = 0;
	vector<long long int>a;
	cin >> n;
		for (int i = 0; i < n * 3; i++) {
			cin >> b;
			a.push_back(b);
		}	
		sort(a.begin(), a.end());
		for (int j = n+1;j < 3*n;j+=2) {
			sum += a[j-1];
		}
		cout << sum;
		
}

Measured memory_bytes: 6000
#include <bits/stdc++.h>
#define lowbit(i) ((i)&(-i))
#define ls (p << 1)
#define rs (p << 1 | 1)
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MAXN = 3e6 + 15;
const ll M = 1e9 + 7;
ll F[MAXN + 15], Finv[MAXN + 15], inv[MAXN + 15]; 
void init() {
    inv[1] = 1;
    for(int i = 2; i <= MAXN; i++) {
        inv[i] = (M - M / i) * 1ll * inv[M % i] % M;
    }
    F[0] = Finv[0] = 1;
    for(int i = 1; i <= MAXN; i++) {
        F[i] = F[i - 1] * 1ll * i % M;
        Finv[i] = Finv[i - 1] * 1ll * inv[i] % M;
    }
}
ll comb(int n, int m) {
	if(m < 0 || m > n) return 0;
    else return F[n] * 1ll * Finv[n - m] % M * Finv[m] % M;
} 
ll quick_pow(ll a, ll b) {
    if(a == 1) return 1;
    ll res = 1;
    while(b > 0) {
        if(b & 1) res = (res * a) % M;
        a = (a * a) % M;
        b >>= 1;
    }
    return res;
}
int main() {
#ifdef CitricAcid
    freopen ("input.txt", "rt", stdin);
#endif

    init();
    int k;
    string s;
    scanf("%d", &k);
    cin >> s;
    int n = s.length();
    ll res = 0;
    for(int i = 0; i <= k; i++) {
        res = (res + (quick_pow(26, i) * comb(n + k - i - 1, n - 1) % M * quick_pow(25, k - i) % M)) % M;
    }
    printf("%lld\n", res);


#ifdef CitricAcid
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}
/*
# author : CitricAcid
# date : 2020/07/27
*/

Measured memory_bytes: 75724
loop do
    n, m, s, g1, g2 = gets.split.map(&:to_i)
    break if n == 0 || m == 0 || s == 0 || g1 == 0 || g2 == 0
    s -= 1
    g1 -= 1
    g2 -= 1
    cost = Array.new(n).map{Array.new(n, 10000001)}
    m.times do
        d = gets.split.map(&:to_i)
        cost[d[0]-1][d[1]-1] = d[2]
    end
    n.times do |k|
        n.times do |i|
            n.times do |j|
                if i == j
                    cost[i][j] = 0
                    next
                end
                cost[i][j] = cost[i][k] + cost[k][j] if cost[i][k] + cost[k][j] < cost[i][j]
            end
        end
    end
    min = 10000001
    n.times do |i|
        min = [min, cost[s][i] + cost[i][g1] + cost[i][g2]].min
    end
    puts min
end

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

using namespace std;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s,t="qwertasdfgzxcvb";

    while(1){
        cin>>s;

        if(s=="#")break;

        int ans=0;
        bool p=true;//右ならtrue

        for(int i=0;i<t.size();i++){
            if(s[0]==t[i])p=false;
        }

        for(int i=1;i<s.size();i++){
            for(int j=0;j<t.size();j++){
                if(s[i]==t[j]){
                    if(p)ans++;
                    p=false;
                    break;
                }
                if(j==t.size()-1){
                    if(!p)ans++;
                    p=true;
                }
            }
        }

        cout<<ans<<endl;

    }

}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  int c = 0;
  cin >> s;
  
  if (s[0] == s[1] && s[0] == s[2] 
      || s[1] == s[2] && s[2] == s[3])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;

}

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

using namespace std;

using ab_t = std::pair<int, int>;

int main() {
  int n;
  int64_t k;
  std::cin >> n >> k;
  std::vector<ab_t> abArray(n);
  for (auto& ab : abArray) {
    std::cin >> ab.first >> ab.second;
  }
  std::sort(
      abArray.begin(), abArray.end(),
      [](const auto& lhs, const auto& rhs) { return lhs.first < rhs.first; });
  for (const auto& ab : abArray) {
    k -= ab.second;
    if (k <= 0) {
      std::cout << ab.first << std::endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,k;
const int N=150;
char s[N];
ll dp[N][4][2];
int main()
{
    scanf("%s",s+1);
    scanf("%d",&k);
    n=strlen(s+1);
    dp[0][0][1]=1;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=3;j++)
        {
            for(int h=0;h<=1;h++)
            {
                int f;
                if(h==0)
                    f=9;
                else
                    f=s[i]-'0';
                if(j==k) f=0;
                for(int m=0;m<=f;m++)
                {
                    dp[i][j+((m==0)?0:1)][h&&((m==f)?1:0)]+=dp[i-1][j][h];
                }
            }
        }
    }
    printf("%lld\n",dp[n][k][1]+dp[n][k][0]);
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def main():
    N = int(input())
    S = defaultdict(int)
    for _ in range(N):
        s = ''.join(sorted(list(input())))
        if s in S:
            S[s] += 1
        else:
            S.update({s:0})
    cnt = 0
    for k,v in S.items():
        if v == 0:
            continue
        elif v == 1:
            cnt += v
        else:
            cnt += combinations_count(v+1,2)
    print(cnt)

if __name__ == '__main__':
    main()

Measured memory_bytes: 100772
#include <string>
#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
 	string S;
  string A = "2019/04/30";
  cin >> S;
  
  if(S > A){
    cout << "TBD";
  }else{
    cout << "Heisei";
  }
  return 0;
}

Measured memory_bytes: 256
import itertools

N = int(input())

myseq = [ n for n in range(1, N+1)]

#print(myseq)

mylsit =  list(itertools.permutations(myseq))

p = tuple(map(int, input().split()))
P = mylsit.index(p)
q = tuple(map(int, input().split()))
Q = mylsit.index(q)
print(abs(P-Q))

Measured memory_bytes: 8052
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split("");
    int ans = 0;
    for(int i=0; i<4; i++) {
      if(str[i].equals("+"))
        ans++;
      else
        ans--;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=55;
int a[N],b[N],c[N],d[N];
vector<int>v;
ll res=0;
int n,m,q;

void cal(int j,int prv){
   // cout<<j<<endl; 
    if((int)v.size()==n){
        ll ans=0;
       /* for(int i=0;i<n;i++)cout<<v[i]<<" ";
        cout<<endl;*/ 
       for(int i=0;i<q;i++){ 
           if(v[b[i]]-v[a[i]]==c[i])ans+=d[i];
       }
     res=max(res,ans);
     return ;
    }
    for(int i=prv;i<=m;i++){
        v.push_back(i);
        cal(j+1,i);
        v.pop_back();
    }
}


 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>m>>q;
    for(int i=0;i<q;i++){ 
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        a[i]--;
        b[i]--;
    }
    cal(0,1);
    cout<<res<<'\n';
    
    
    
    
    return 0;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int H, W, K; cin >> H >> W >> K;
	int x1, y1, x2, y2;  cin >> y1 >> x1 >> y2 >> x2;
	--x1, --x2, --y1, --y2;
	vector<string> grid(H); cin >> grid;

	queue<Pi> que;
	vvvint mc(H, vvint(W, vint(4, INF))); //方向を持てば問題が怒らない(やさしくなる)
	mc[y1][x1][0] = mc[y1][x1][1] = mc[y1][x1][2] = mc[y1][x1][3] = 0;
	que.emplace(y1, x1);

	while (!que.empty()) {
		int y, x;
		tie(y, x) = que.front(); que.pop();
		//cout << y << " " << x << endl;
		for (int i = 0; i < 4; i++) {
			int ny = y + dy[i], nx = x + dx[i];
			int j = 0;
			//cout << " " << ny << " " << nx << endl;
			while (j < K && isin(ny, nx, H, W) && grid[ny][nx] != '@') {
				int val = min({mc[ny][nx][0], mc[ny][nx][1], mc[ny][nx][2], mc[ny][nx][3]});
				int val2 = min({mc[y][x][0], mc[y][x][1], mc[y][x][2], mc[y][x][3]});

				if (val <= val2) break;
				if (mc[ny][nx][i] <= val2 + 1) break;

				mc[ny][nx][i] = val2 + 1;
				//cout << "  " << ny << " " << nx << endl;
				que.emplace(ny, nx);
				j++;
				ny += dy[i], nx += dx[i];
			}
			//cout << "END" << endl;
		}
	}

	//cout << y2 << " " << x2 << endl;

	int ans = min({mc[y2][x2][0], mc[y2][x2][1], mc[y2][x2][2], mc[y2][x2][3]});

	cout << (ans == INF ? -1 : ans) << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 113560
#include <bits/stdc++.h>
#include <queue>
#define ll long long int
using namespace std;


const int N = 3e5 + 10;
ll n, k, arr[N], a;
bool ok;

int main(int argc, char** argv) {
    cin >> n>>k;
    if (n % k)cout << 1;
    else cout << 0;
    return 0;
}

Measured memory_bytes: 256
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input())
    a = list(int(_) for _ in input().split())
    cnt = 0
    for i in range(N):
        cnt += a[i] - 1
    print(cnt)
    
if __name__ == '__main__':
    main()


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

int main()
{
	int n;
	cin >> n;
	vector<string> s;
	for (int i = 0; i < n; i++) {
		string t;
		cin >> t;
		s.push_back(t);
	}
	sort(s.begin(), s.end());
	int cnt = 0;
	for (int i = 1; i < n; i++) {
		if (s[i - 1] != s[i])
			cnt++;
	}
	cout << cnt + 1 << endl;
	return 0;
}

Measured memory_bytes: 11656
#include <iostream>
#define FOR0(var, max) for (ui var = 0; var < max; ++var)

using namespace std;

using ui = unsigned int;
using uc = unsigned char;

const static ui NMAX = 20;

static ui Ai[NMAX];
static ui Bi[NMAX];
static ui Ci[NMAX];

static ui N;

int main(int ac, char **av) {
  cin >> N;
  FOR0(i, N) {
    cin >> Ai[i];
  }
  FOR0(i, N) {
    cin >> Bi[i];
  }
  FOR0(i, N - 1) {
    cin >> Ci[i];
  }
  ui prev = 100;
  ui res = 0;
  FOR0(i, N) {
    ui cur = Ai[i] - 1;
    res += Bi[cur];
    if (prev < NMAX && prev + 1 == cur) {
      res += Ci[prev];
    }
    prev = cur;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
import bisect
import itertools


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, readline().split()))
    a = list(map(int, readline().split()))
    a.sort()
    cor_v = a[0] * 2
    inc_v = a[-1] * 2 + 1
    while - cor_v + inc_v > 1:
        bin_v = (cor_v + inc_v) // 2
        cost = 0
        #条件を満たすcostを全検索
        for i in range(n-1, -1, -1):
            cost += n - bisect.bisect_left(a, bin_v - a[i])
            if cost >= m:
                break
        #costが制約を満たすか
        if cost >= m:
            cor_v = bin_v
        else:
            inc_v = bin_v
    acm = list(itertools.accumulate([0] + a))
    t = 0
    c = 0
    for i in range(n):
        p = bisect.bisect_left(a, cor_v - a[i])
        t += acm[-1] - acm[p] + a[i] * (n - p)
        c += n - p
    print(t - (c - m) * cor_v)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 54576