akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define LL long long
const int mod = 1e9 + 7;
LL ans = 1LL, n, k, x, y;
vector<int> g[100005];

void dfs(int v, int par, int l, LL x) {
    if(x < 0) {ans = 0; return;}
    ans *= x; ans %= mod;

    if(l < 2) {
        int cnt = 1;
        for(int u : g[v]) {
            if(u == par) continue;
            dfs(u, v, l+1, x-cnt);
            cnt++;
        }
    }
    else {
        x = k - 2;
        int cnt = 0;
        for(int u : g[v]) {
            if(u == par) continue;
            dfs(u, v, l+1, x-cnt);
            cnt++;
        }
    }
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    cin >> n >> k;
    for(int i = 0; i < n-1; i++) {
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }    
    dfs(1, 0, 1, k);
    cout << ans;
}

Measured memory_bytes: 14808
n, m = map(int, input().split())
a = list(map(int, input().split()))
sou = 0
for i in a:
    sou += i
line = sou/(4*m)
count = 0
for i in a:
    if i >= line:
        count+=1
if count>= m:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <vector>
// #include <unordered_map>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <climits>

using namespace std;

#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define FOR(i, j, k) for(int i=j ; i<k ; i++)
#define RFOR(i, j, k) for(int i=j ; i>=k ; i--)
#define REP(i, j) FOR(i, 0, j)
#define RREP(i, j) RFOR(i, j, 0)
#define PI 3.1415926535897932384626433832795
typedef long long int ll;
typedef unsigned long long int  ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<ll> vll;
typedef vector<vi> vvi;

#define UNION_FIND_MAX_N 100005
int par[UNION_FIND_MAX_N];
int ran[UNION_FIND_MAX_N];

void init(int n){
    for(int i=0; i<n; i++){
        par[i] = i;
        ran[i] = 0;
    }
}

int find(int x){
    if( par[x] == x ) return x;
    else return par[x] = find(par[x]);
}

void unite(int x, int y){
    x = find(x);
    y = find(y);
    if( x == y ) return;

    if( ran[x] < ran[y] ){
        par[x] = y;
    } else {
        par[y] = x;
        if( ran[x] == ran[y] ) ran[x]++;
    }
}

bool same(int x, int y){
    return find(x) == find(y);
}


#define MAX_E 200010

struct edge {
    long long u, v, cost;
    edge(){};
    edge(long long a, long long b, long long c){
        u = a;
        v = b;
        cost = c;
    }
};

bool comp(const edge& e1, const edge& e2) {
    return e1.cost < e2.cost;
}

edge es[MAX_E];
int V, E;

long long kruskal(){
    sort(es, es + E, comp);
    init(V);
    long long res = 0;
    for (int i = 0; i < E; i++) {
        edge e = es[i];
        if (!same(e.u, e.v)) {
            unite(e.u, e.v);
            res += e.cost;
        }
    }
    return res;
}
#define INF (1<<31)

int main() {
    
    int N; cin >> N;
    vector<pii> pa(N), pb(N);

    REP(i, N) {
        int a, b;
        cin >> a >> b;
        pa[i] = make_pair(a, i);
        pb[i] = make_pair(b, i);
    }

    sort(pa.begin(), pa.end());
    sort(pb.begin(), pb.end());

    REP(i, N-1) {
        es[i]   = edge(pa[i].second, pa[i+1].second, pa[i+1].first-pa[i].first);
        es[i+N] = edge(pb[i].second, pb[i+1].second, pb[i+1].first-pb[i].first);
    }

    V = N;
    E = N*2;

    ll res = kruskal();

    cout << res << endl;


    return 0;
}




Measured memory_bytes: 7804
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int S, s1, s2, s3;
  cin >> S;
  if(S % 2 == 0){
    s3 = 0;
  } else {
    s3 = 1;
  }
  
  if((S - s3) / 10 % 2 == 0){
    s2 = 0;
  } else {
    s2 = 1;
  }
  
  if(S > 99){
    s1 = 1;
  } else {
    s1 = 0;
  }
  
  
  cout << s1 + s2 +s3 << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const ll MOD = 1000000007;
const int INF = 2000000000;

const int MAX_V = 200;

int d[MAX_V][MAX_V];
int V, E;

void warshall_floyd() {
  for (int k = 0; k < V; k++) {
    for (int i = 0; i < V; i++) {
      for (int j = 0; j < V; j++) {
        if (d[i][k] == INF || d[k][j] == INF) {
          continue;
        }
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

int R;
vector<int> r;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> V >> E >> R;
  r.resize(R);
  for (int i = 0; i < R; i++) {
    int ri;
    cin >> ri;
    ri--;
    r[i] = ri;
  }
  sort(r.begin(), r.end());

  for (int i = 0; i < V; i++) {
    for (int j = 0; j < V; j++) {
      if (i == j) {
        d[i][j] = 0;
      } else {
        d[i][j] = INF;
      }
    }
  }
  for (int i = 0; i < E; i++) {
    int ai, bi, ci;
    cin >> ai >> bi >> ci;
    ai--;
    bi--;
    d[ai][bi] = ci;
    d[bi][ai] = ci;
  }
  warshall_floyd();

  int ans = INF;
  do {
    int sum = 0;
    bool flag = true;
    for (int i = 1; i < R; i++) {
      if (d[r[i - 1]][r[i]] == INF) {
        flag = false;
        break;
      }
      sum += d[r[i - 1]][r[i]];
    }

    if (flag) {
      ans = min(ans, sum);
    }
  } while (next_permutation(r.begin(), r.end()));

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
def distance(a_lst, b_lst):
    n = len(a_lst)
    tmp_distance = 0

    for i in range(n):
        a = a_lst[i]
        b = b_lst[i]

        tmp_distance += (a - b) ** 2

    distance = (tmp_distance) ** (1/2)
    return distance


def main():
    n, d = map(int, input().split())
    x_lst = [0] * n
    count = 0

    for i in range(n):
        x_lst[i] = list(map(int, input().split()))

    for i in range(n-1):
        a_lst = x_lst[i]

        for j in range(i+1, n):
            b_lst = x_lst[j]

            if distance(a_lst, b_lst) == int(distance(a_lst, b_lst)):
                count += 1

    print(count)


if __name__ == '__main__':
    main()

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

vector<ll> vt[sz];
ll dp[sz];
ll vis[sz];

ll dfs(ll node)
{
    vis[node]=1;

    for(ll i=0; i<vt[node].size() ; i++)
    {
        if(vis[vt[node][i]]==0)dfs(vt[node][i]);

        dp[node]=max(dp[node],1+dp[vt[node][i]]);
    }
}

void solve(ll n)
{
    for(ll i=0;i<=n;i++)
    {
        if(vis[i]==0)dfs(i);
    }
}
int main()
{
    ll n,eg,u,v,i,j,k=-1;

    cin>>n>>eg;

    while(eg--)
    {
        cin>>u>>v;
        vt[u].push_back(v);
    }

    solve(n);

    for(i=1;i<=n;i++)
    {
        k=max(k,dp[i]);
    }
    cout<<k<<endl;

    return 0;

}


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

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
constexpr int DX[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int sign(int x) { return (x > 0) - (x < 0); }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const deque<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const set<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

signed main() {
  string N;
  cin>>N;
  int x=0;
  rep(i,N.length()){
    (x+=N[i]-'0')%=9;
  }
  if(x==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 3712
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int gcd(int x, int y){
    return y?gcd(y,x%y):x;
}

int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> l(n), r(n);
    rep(i,n-1) l[i+1] = gcd(l[i],a[i]);
    for(int i = n-1; i >= 1; i--) r[i-1] = gcd(r[i],a[i]);
    int ans = 1;
    rep(i,n) ans = max(ans,gcd(l[i],r[i]));
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1408
use proconio::input;
use proconio::marker::{Bytes, Chars};
use std::cmp::{max, min};

fn main() {
    input! {
        n: usize,
        A: [isize; n],
    }
    let mut s = vec![0; n+1];
    let mut ans = std::isize::MAX;
    for i in 0..n {
        s[i+1] = s[i] + A[i];
    }
    for i in 0..n-1 {
        ans = min(ans, (s[i+1] - (s[n] - s[i+1])).abs())
    }
    println!("{}", ans);
}

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

int main()
{
	while (true) {
		string s;
		int m;
		cin >> s >> m;
		if (s == "-") break;
		queue<char> q;
		for (int i = 0; i < s.size(); i++) q.push(s[i]);
		for (int i = 0; i < m; i++) {
			int h;
			cin >> h;
			for (int j = 0; j < h; j++) {
				int tmp = q.front();
				q.pop();
				q.push(tmp);
			}
		}
		while (!q.empty()) {
			cout << q.front();
			q.pop();
		}
		cout << endl;
	}
}


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

template<typename T>
struct BellmanFord{
    const T inf=numeric_limits<T>::max();
    struct edge{
        int u,v; T w;
        edge(int u,int v,T w):u(u),v(v),w(w){}
    };
    int n;
    vector<vector<int>> G;
    vector<int> check,reach;
    vector<edge> es;
    BellmanFord(int n):n(n),G(n),check(n),reach(n,1){}
    void add_edge(int u,int v,T w){
        es.emplace_back(u,v,w);
        G[u].emplace_back(v);
    }
    vector<T> build(int s,int &neg_loop){
        vector<T> d(n,inf);
        d[s]=0;
        for (int i=0;i<n;++i){
            bool update=false;
            for (auto e:es){
                if (!reach[e.u]||!reach[e.v]||d[e.u]==inf) continue;
                if (d[e.u]+e.w<d[e.v]){
                    d[e.v]=d[e.u]+e.w;
                    update=true;
                }
            }
            if (!update) break;
            if (i==n-1){neg_loop=1; return d;}
        }
        neg_loop=0; return d;
    }
    void dfs(int v){
        if (check[v]) return;
        check[v]=1;
        for (int u:G[v]) dfs(u);
    }
    T shortest_path(int s,int t,int &neg_loop){
        for (int i=0;i<n;++i){
            fill(check.begin(),check.end(),0);
            dfs(i);
            reach[i]=check[t];
        }
        return build(s,neg_loop)[t];
    }
};

// https://atcoder.jp/contests/abc061/tasks/abc061_d

void ABC061_D(){
    int N,M; cin >> N >> M;

    BellmanFord<long long> BF(N);
    for (int i=0;i<M;++i){
        int a,b,c; cin >> a >> b >> c;
        BF.add_edge(--a,--b,-c);
    }

    int neg;
    long long ans=BF.shortest_path(0,N-1,neg);
    if (neg) cout << "inf" << '\n';
    else cout << -ans << '\n';
}

// https://atcoder.jp/contests/abc137/tasks/abc137_e

void ABC137_E(){
    int N,M,P; cin >> N >> M >> P;

    BellmanFord<int> BF(N);
    for (int i=0;i<M;++i){
        int A,B,C; cin >> A >> B >> C;
        BF.add_edge(--A,--B,P-C);
    }

    int neg;
    int ans=BF.shortest_path(0,N-1,neg);
    cout << (neg?-1:max(0,-ans)) << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ABC137_E();
}

Measured memory_bytes: 3912
#include<stdio.h>
#include<math.h>

double p_x(int);

int x[100], y[100], n;

int main(){
  int i, max=0;
    
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&x[i]);
  for(i=0;i<n;i++) scanf("%d",&y[i]);

  printf("%.6f\n",p_x(1));
  printf("%.6f\n",p_x(2));
  printf("%.6f\n",p_x(3));

  for(i=1;i<n;i++){
    if(fabs(x[i]-y[i])>fabs(x[max]-y[max])) max=i;
  }
  
  printf("%.6f\n",fabs(x[max]-y[max]));

  return 0;
}


double p_x(int p){
  int i;
  double dxy=0.0;
  
  for(i=0;i<n;i++) dxy+=pow(fabs(x[i]-y[i]),p);
  
  return pow(dxy,(double)1/p);
}


Measured memory_bytes: 2052
#include <iostream>

int main ()
{
	int h[10]{};

	for (int i = 0; i < 10 ; i++) {
		std::cin >> h[i];
	}
	for (int i = 0; i < 9; i++) {
		int pv = h[i];
		int k = i;
		for (int j=i+1 ; j<10 ; j++){
			if (h[j] < pv) {
				pv = h[j];
				k = j;
			}
		}
		int sw = h[i];
		h[i] = h[k];
		h[k] = sw;
	}
	std::cout << h[9] << std::endl;
	std::cout << h[8] << std::endl;
	std::cout << h[7] << std::endl;
}

Measured memory_bytes: 3080
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <functional>
#include <numeric>
//#include "bits/stdc++.h"
using namespace std;
//using namespace std::vector;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)

#define huge 1000000007
typedef long long int ll;
ll gcd(ll a, ll b);

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll D = 0;
	ll M = 0;
	//ll M = 0;
	ll a[100] = {};
	ll b[100] = {};
	ll c[100] = {};
	ll d[100] = {};

	//ll v[3] = {};
	//ll *c, *s, *n;
	string S,T,U[52];
	ll count = 10;
	ll count2 = 0;
	ll sum = 0;
	ll min = 100000000000000;
	ll max = 0;
	ll smax = 0;
	ll max2 = 0;
	ll smax2 = 0;
	int tmax = 0;
	int tmax2 = 0;
	int flag = 0;
	char temp,head;
	//int is = 0;
	
	
	//char p;


	

	

	//cin >> S;
	
	//b = (ll *)malloc(M * sizeof(ll));
	//vector<pair<int,int>> ch(50);

	
	cin >> N;
	
	if (N > 100000000)
		max = 100000000;
	else
		max = N;


	for (ll i = 1; i*i <= N;++i) {

		if (N%i == 0) {
			//cout << i << "," << N / i << endl;

			min = std::max(i , N/i);

			//cout << min << endl;

			if(min<10)
				sum = 1;
			if (min >= 10) 
				sum = 2;
			if (min >= 100)
				sum = 3;
			if (min >= 1000)
				sum = 4;
			if (min >= 10000)
				sum = 5;
			if (min >= 100000)
				sum = 6;
			if (min >= 1000000)
				sum = 7;
			if (min >= 10000000)
				sum = 8;
			if (min >= 100000000)
				sum = 9;
			if (min >= 1000000000)
				sum = 10;
			
			//cout << sum << endl;

			if (count >= sum)
				count = sum;
			else
				break;
			



		}

	}
	cout << count << endl;
	
	//x = (ll *)malloc((N+1) * sizeof(ll));
	//c = (ll *)malloc((N) * sizeof(ll));
	//cin >> D >> G;
	//vector<pair<int,int>> tr(M);
	//vector<pair<int,int>> qes(Q);
	//sort(c.begin(), c.end());
	
	//cout << c[2] - c[1] << endl;

	

	/*A = N / 1000;
	N %= 1000;
	B = N / 100;
	N %= 100;
	C = N / 10;
	N %= 10;
	D = N;*/
	


	return 0;

}

ll gcd(ll a, ll b) {
	
	/* 自然数 a > b を確認・入替 */
	if (a<b) {
		ll tmp = a;
		a = b;
		b = tmp;
	}
	ll x = b;
	ll y = a;
	/* ユークリッドの互除法 */
	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}


	return y/b*x;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' || ch > '9') && ch != '-') ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

int const MAXN = 1e5 + 5;
int h[MAXN], ans[MAXN];

int main() {
  
#ifdef LOCAL
  FILEIO("a");
#endif

  int n, m; read(n), read(m);
  for (RI i = 1; i <= n; ++i) read(h[i]);
  for (RI i = 1, x, y; i <= m; ++i) {
    read(x), read(y);
    if (h[x] >= h[y]) ans[y] = 1;
    if (h[y] >= h[x]) ans[x] = 1;
  }
  int tot = 0;
  for (RI i = 1; i <= n; ++i) tot += !ans[i];
  printf("%d\n", tot);

  return 0;
}

// created by Daniel yuan


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

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


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

int main(){
  int n;
  cin >> n;
  int Sn = 0;
  int N = n;
  while(n > 0){
    Sn += n%10;
    n /= 10;
  }
  if(N%Sn == 0) cout  << "Yes" <<endl;
  else cout << "No" << endl;
}
  

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

int main(){

    ll x, y;

    scanf("%lld%lld", &x, &y);

    if(x == y){

        ll ans = 0;
        printf("%lld", ans);

    }


    else if(x == 0 || y == 0){


        if(x < 0)  cout << x*-1;

        if(x > 0) cout << x + 1;

        if(y > 0) cout << y;

        if(y < 0) cout << y*-1 + 1;

    }


    else if(x < 0 && y < 0){

        if(x > y){

            ll ans = x - y + 2;
            printf("%lld", ans);

        }

        if(x < y){

            ll ans = y - x;
            printf("%lld", ans);

        }

    }


    else if(x > 0 && y < 0){

        if(x >= y*-1){

            ll ans = x + y + 1;
            printf("%lld", ans);
        }

        if(x < y*-1){

            ll ans = y*-1 - x + 1;
            printf("%lld", ans);

        }

    }


    else if(x < 0 && y > 0){

        if(x*-1 < y){

            ll ans = y + x + 1;
            printf("%lld", ans);

        }

        if(x*-1 >= y){

            ll ans = x*-1 - y + 1;
            printf("%lld", ans);

        }

    }


    else if(x > 0 && y > 0){

        if(x > y){


            ll ans = x - y + 2;
            printf("%lld", ans);

        }

        if(x < y){

            ll ans = y - x;
            printf("%lld", ans);

        }

    }

    return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;

ll mod_pow(ll x, ll n) {
	ll ret = 1;
	while (n) {
		if (n % 2)ret = ret * x%mod;
		x = x * x%mod; n >>= 1;
	}
	return ret;
}
ll num[2000];
void solve() {
	int n, k; cin >> n >> k;
	vector<int> v;
	rep1(i, 100000) {
		if (n%i == 0) {
			v.push_back(i);
			v.push_back(n / i);
		}
	}
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	rep(i, v.size()) {
		int d = (v[i] + 1) / 2;
		ll sum = mod_pow(k, d);
		rep(j, i) {
			if (v[i] % v[j] == 0) {
				sum -= num[j];
				if (sum < 0)sum += mod;
			}
		}
		num[i] = sum;
	}
	ll ans = 0;
	rep(i, v.size()) {
		if (v[i] % 2 == 0) {
			ans = (ans + num[i] * v[i] / 2) % mod;
		}
		else {
			ans = (ans + (num[i] * v[i])) % mod;
		}
		//cout << num[i] << endl;
		//ans = (ans + num[i] * ((v[i]+1)/2)) % mod;
	}
	cout << ans << endl;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
	return 0;
}


Measured memory_bytes: 384
export class Main {
  static main(input): string {
    const tmp: string[] = input.split("\n");
    const n: number = parseInt(tmp[0]);
    const aList: number[] = tmp[1].split(" ").map(int => parseInt(int));
    const ballNumSet: Set<number> = new Set();
    const result: number[] = [];
    for (let i = n - 1; i >= 0; i--) {
      const num: number = i + 1;
      let isOne: boolean = aList[i] == 1;
      for (let j = 2, len = Math.min(n / num); j <= len; j++) {
        if (ballNumSet.has(num * j)) {
          isOne = !isOne;
        }
      }
      if (isOne) {
        ballNumSet.add(num);
        result.push(num);
      }
    }
    return `${result.length}\n${result.join(" ")}`;
  }
}
 console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));

Measured memory_bytes: 32124
#include<bits/stdc++.h>
using namespace std;
int n,a[100003],b[100003];
int main()
{
	cin>>n;
	for(int i=1; i<=n; i++)
	{
		cin>>a[i];
		b[a[i]]=i;
	}
	for(int i=1; i<=n; i++)
		cout<<b[i]<<" ";
	return 0;
}

Measured memory_bytes: 1536
#pragma GCC optmize ("O3,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define spIO ios::sync_with_stdio(false);cin.tie(0)
typedef long long ll;
typedef long double ld;
int n, r;
int main()
{
	spIO;
	cin >> n >> r;
	if (n >= 10)
		cout << r;
	else
	{
		cout << r + 1000 - 100 * n;
	}
}

Measured memory_bytes: 256
def read_input():
    n, t = map(int, input().split())
    alist = list(map(int, input().split()))

    return n, t, alist


def submit():
    n, t, alist = read_input()

    takahashi_cap = [0]
    curr_min = alist[0]

    for i in range(1, n):
        a = alist[i]
        takahashi_cap.append(a - curr_min)
        if a < curr_min:
            curr_min = a

    takahashi_max = max(takahashi_cap)
    print(len([t for t in takahashi_cap if t == takahashi_max]))


if __name__ == '__main__':
    submit()


Measured memory_bytes: 15060
import sys,math
sr = sys.stdin.readline
def I(i=0):return [int(x)-i for x in sr().split()]
L1,L2 = [],[]

N,D,A = I()
for i in range(N):
    X,H = I()
    L1.append([X,math.ceil(H/A)])
L1 = sorted(L1)
j = 1
L2 = [-1]*N
for i in range(N):
    lim = L1[i][0] + 2*D
    for k in range(j,N):
        if L1[k][0] > lim:
            L2[i] = k-1
            j = k-1
            break
        elif k == N-1:
            L2[i] = N-1
            j = N-1
ans = 0
a,s = 0,0
for i in range(N):
    x,h = L1[i]
    h -= a
    if h > 0:
        ans += h
        a += h
        L1[i][1] = h
    else:
        L1[i][1] = 0
    while s < N and L2[s] <= i:
        a -= L1[s][1]
        s += 1
print(ans)

Measured memory_bytes: 44144
s=list(str(input()))
k=int(input())
n=len(s)
alpha2num=lambda c: ord(c)-ord('a')+1
for i in range(n):
    s[i]=alpha2num(s[i])

c=k
for i in range(n):
    if c-(27-s[i])>=0:
        if s[i]+c>26 and s[i]!=1:
            c=c-(27-s[i])
            s[i]=1
#print(s[-1],c)
s[-1]+=c%26
num2alpha=lambda c: chr(c+96)
for i in range(n):
    s[i]=num2alpha(s[i])

print("".join(map(str,s)))

Measured memory_bytes: 63364
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
const ll mod=1000000007;
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)

int main() {
	int a,b,c,k;cin>>a>>b>>c>>k;
	int out;
	if(k<=a){
		out =k;
	} else if(k<=a+b){
		out = a;
	} else {
		out = 2*a + b - k;
	}
	cout << out << endl;
  return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<array>

using namespace std;
int main(){
  string a;
  int x=0,y=0;
  cin >> a;
  for(int i = 0;i < a.size();i++){
    if(a[i]=='A'){
      x = i;
      break;
    } 
  }
  for(int i = a.size()-1;i >= 0;i--){
    if(a[i]=='Z'){
      y = i;
      break;
    } 
  }
  cout << y-x+1 << endl;
}


Measured memory_bytes: 640
loop {
    n, q = gets.split.map(&:to_i)
    break if n + q == 0
    d = Hash.new
    n.times do
        s, a, b = gets.split
        a, b = [a, b].map(&:to_i)
        d[(b - a + 1)..b] = s
    end
    q.times do
        a = gets.to_i
        flag = false
        d.each do |r, s|
            if r.include?(a)
                puts [s, a - r.begin + 1].join(' ')
                flag = true
            end
        end
        puts "Unknown" if !flag
    end
}


Measured memory_bytes: 6960
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int a,b,c,d,e,f;
  cin>>a>>b>>c;
  d=max({a,b,c});
  e=min({a,b,c});
  f=a+b+c-d-e;
  cout<<d*10+e+f<<endl;
}


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

int main(){
    int n, ans = 0;
    string s;
    cin >> n >> s;

    for(int i = 0; i < n; i++){
        string x = s.substr(0,i);
        string y = s.substr(i);
        vector<bool>  a1(26), a2(26) ;
        rep(j, x.size()) if(x[j] == '?') continue; else a1[x[j] - 'a']= true;
        rep(j, y.size()) if(y[j] == '?') continue; else a2[y[j] - 'a']= true;
        int cnt = 0;
        rep(i,26) if(a1[i]&&a2[i]) cnt++;
        ans = max(ans, cnt);
    }

    cout << ans << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <iomanip>
#include <numeric>
#include <bitset>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;

typedef long long ll;

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

  int n;
  string s;

  cin >> n >> s;

  if (n & 1) {
    cout << "No" << endl;
  } else {
    if ( s.substr(0, n/2) == s.substr(n/2, n) ) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
n = int(input())
list_in_Num = map(int, input().split())
num_list = list(list_in_Num)
oddIndexandoddNum = 0
for i, num in enumerate(num_list, start=1):
    if num % 2 == 1 and i % 2 == 1:
        oddIndexandoddNum += 1
print(oddIndexandoddNum)

Measured memory_bytes: 9072
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
int const INF = 1001001001;


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

int N,M;
cin >> N >> M;
vi a(N);
rep(i,N) cin >> a[i];
int sum = 0;
rep(i,N) sum += a[i];
int cnt = 0;
rep(i,N) {
    if(4*M*a[i] >= sum) cnt++;
}
if(cnt >= M) cout << "Yes" << endl;
else cout << "No" << endl;

return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, X[101];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N) cin >> X[i];
	sort(X, X + N);

	int ans = inf;
	rep(P, 1, 101) {
		int tot = 0;
		rep(i, 0, N) tot += (X[i] - P) * (X[i] - P);
		chmin(ans, tot);
	}
	cout << ans << endl;
}







Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::HashSet;
use std::cmp;
use std::f64::consts;

fn main() {
    let n: i64 = read();
    let target: i64 = read();

    let mut ans: (i64,i64,i64) = (-1,-1,-1);
    for man in 0..n+1 {
        for gosen in 0..n-man+1 {
            let sen = n - man - gosen;

            if (man*10000 + gosen*5000 + sen*1000) == target {
                ans = (man,gosen,sen);
            }
        }
    }

    println!("{} {} {}", ans.0, ans.1, ans.2);
}

fn calc_distance(x: i32, y: i32, target_x: i32, target_y: i32) -> i32 {
    let diff_x = (target_x - x).abs();
    let diff_y = (target_y - y).abs();

    return diff_x + diff_y;
}

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

// 最大公約数
fn gcd(a: i32, b: i32) -> i32 {
    match b {
        0 => a,
        _ => gcd(b, a % b)
    }
}

// 最小公倍数
fn lcm(a: i32, b: i32) -> i32 {
    a * b / gcd(a, b)
}

// 階乗
fn kaijou(n: i32)->i32 {
    if n == 1 {
        return n;
    }
    return n * kaijou(n-1);
}

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

int main() {
	int n,i,j;
	double sum;
	cin >> n;

	for (int m = 0; m < n; m++) {
		cin >> i;
		sum += 1.0/(double)i;
	}

	sum = 1.0 / sum;

	cout << sum << endl;
}

Measured memory_bytes: 256
import static java.util.Arrays.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	void solve() {
		double t1 = sc.nextDouble();
		double s1 = sc.nextDouble();
		double t2 = sc.nextDouble();
		double s2 = sc.nextDouble();
		if (t1 == -1 && s1 == -1 && t2 == -1 && s2 == -1) return;

		final double r = 6378.1;
		double[] p = get(t1, s1);
		double[] q = get(t2, s2);
		double dot = p[0] * q[0] + p[1] * q[1] + p[2] * q[2];
		double c = Math.acos(dot);
		double ans = r * c;
		System.out.printf("%d\n", (int)(ans + 0.5));
	}

	double[] get(double t, double s) {
		double x = Math.cos(s / 180.0 * Math.PI) * Math.cos(t / 180.0 * Math.PI);
		double y = Math.sin(s / 180.0 * Math.PI) * Math.cos(t / 180.0 * Math.PI);
		double z = Math.sin(t / 180.0 * Math.PI);
		return new double[]{x, y, z};
	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	MyScanner sc = null;
	PrintWriter out = null;
	public void run() throws Exception {
		sc = new MyScanner(System.in);
		out = new PrintWriter(System.out);
		for (;sc.hasNext();) {
			solve();
			out.flush();
		}
		out.close();
	}

	class MyScanner {
		String line;
		BufferedReader reader;
		StringTokenizer tokenizer;

		public MyScanner(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}
		public void eat() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					line = reader.readLine();
					if (line == null) {
						tokenizer = null;
						return;
					}
					tokenizer = new StringTokenizer(line);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
		public String next() {
			eat();
			return tokenizer.nextToken();
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		public boolean hasNext() {
			eat();
			return (tokenizer != null && tokenizer.hasMoreElements());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
	}
}

Measured memory_bytes: 17152
#include <cstdio>
#define NIL -1
#define MAXN 100000

typedef struct {
	int parent;
	int left;
	int right;
} Node, Tree;

void readTree(Tree T[], int n)
{
	//data format: id, k, c1, c2, ..., ck
	int id, k, c;
	int p = NIL; 	//parent
	int left = NIL;
	
	for (int i = 0; i < n; i++) {
		scanf("%d %d", &id, &k);
		int j;
		for (j = 0; j < k; j++) {
			scanf("%d", &c);
			if (j == 0) {
				T[id].left = c;
				left = T[id].left;
			}
			else {	//更新每个结点的右兄弟 
				T[left].right = c;	
				left = c;
			}
			T[c].parent = id;
		}
	}
}

void getDepth(Tree T[], int depth[], int n)
{
	for (int i = 0; i < n; i++) {
		int d = 0;
		int id = i;
		while (T[id].parent != NIL) {
			id = T[id].parent;
			d++;
		}
		depth[i] = d; 
	}
}

void printTree(Tree T[], int depth[], int n)
{
	for (int i = 0; i < n; i++) {
		printf("node %d: parent = %d, depth = %d, ", i, T[i].parent, depth[i]);
		if (T[i].parent == NIL) {
			printf("root");
		}
		else if (T[i].left == NIL) {
			printf("leaf");
		}
		else {
			printf("internal node");
		}
		printf(", [");
		
		for (int j = 0, c = T[i].left; c != NIL; j++) {
			if (j > 0) {
				printf(", ");
			
			}
			printf("%d", c);
			c = T[c].right;
		}
		printf("]\n");
	}
}

int main(void)
{
	int n;
	Tree T[MAXN];
	int depth[MAXN];
	
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		T[i].parent = T[i].left = T[i].right = NIL;
	}
	readTree(T, n);
	getDepth(T, depth, n);
	printTree(T, depth, n);
	
	return 0;
}
/*
7
0 3 1 2 3
1 1 4
2 1 5
3 0
4 1 6
5 0
6 0
*/


Measured memory_bytes: 4244
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        static long MAX = 1000000000;
        long S;
        long x1 = 0, y1 = 0;
        long x2, y2, x3, y3;

        void solve(InputReader in, PrintWriter out) {
            S = in.nextLong();

            // find x2
            for (long i = 1; i <= MAX; ++i) {
                if (i*i >= S) {
                    x2 = i;
                    break;
                }
            }

            // find y3
            for (long i = x2; i >= 0; --i) {
                if (x2*i < S) {
                    y3 = i + 1;
                    break;
                }
            }

            long excess = x2*y3 - S;

            // find x3 and y2
            if (excess == 0) {
                y2 = 0;
                x3 = 0;
            } else {
                for (long i = 1; i <= y3; ++i) {
                    if (excess % i == 0 && excess / i <= MAX) {
                        y2 = i;
                        x3 = excess / i;
                        break;
                    }
                }
            }

//            out.println(x2*y3 - x3*y2);
            out.println(String.format("%d %d %d %d %d %d", x1, y1, x2, y2, x3, y3));
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

        int[] nextIntArray(int size) {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

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

        long[] nextLongArray(int size) {
            long[] arr = new long[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }
    }
}

Measured memory_bytes: 22996
#include <stdio.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
	int z;
	scanf("%d", &z);
	int l = 0;
	while ((1 << (l + 1)) - 1 < z)
		++l;
	--l;
	int n = l + 2;
	vector<vector<int> > e;
	int at = 0;
	for (int i = n - 2; i >= 0; --i) {
		e.push_back({ i,i + 1,1 << at++ });
		e.push_back({ i,i + 1,0 });
	}
	z -= (1 << (l + 1));
	int rem = 0;
	rem += (1 << (l + 1));
	while (z > 0) {
		l = 0;
		while ((1 << (l + 1)) - 1 < z)
			++l;
		--l;
		e.push_back({ 0,n - 1 - l - 1 ,rem });
		z -= (1 << (l + 1));
		rem += (1 << (l + 1));
	}
	printf("%d %d\n", n, e.size());
	for (auto x : e)
		printf("%d %d %d\n", x[0] + 1, x[1] + 1, x[2]);
	return 0;
}

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

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

	string s;
	cin >> s;
	int len = s.length();
	for(int i = 0; i < len; i++) {
		if(i != len - 1) {
		  cout << "x";
		}else {
			cout << "x" << endl;
		}
	}
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

from operator import itemgetter

n = readint()

ans = 10**10

only = [[[]for i in range(2*10**5+1)]for j in range(4)]
plus = [[[]for i in range(4*10**5+1)]for j in range(4)]
minus = [[[]for i in range(4*10**5+1)]for j in range(4)]
a = ['D','U','L','R']
for i in range(n):
    x,y,z = readstrs()
    x = int(x)
    y = int(y)
    b = a.index(z)
    if b<2:
        only[b][x].append(y)
    else:
        only[b][y].append(x)
    plus[b][x+y].append(x)
    minus[b][x-y].append(x)

def keisan(a,b,ans):
    a.sort()
    b.sort()
    k = 0
    j = 0
    while k<len(a) and j<len(b):
        if a[k]>b[j]:
            ans = min(ans,a[k]-b[j])
            j += 1
        else:
            k += 1
    return ans

for m in [0,2]:
    for i in range(2*10**5+1):
        a = only[m][i]
        b = only[m+1][i]
        if a and b:
            ans = keisan(a,b,ans)

if ans != 10**10:
    ans/=2

for p,q in [[2,1],[0,3]]:
    for i in range(4*10**5+1):
        a = minus[p][i]
        b = minus[q][i]
        if a and b:
            ans = keisan(a,b,ans)

for p,q in [[1,3],[2,0]]:
    for i in range(4*10**5+1):
        a = plus[p][i]
        b = plus[q][i]
        if a and b:
            ans = keisan(a,b,ans)

if ans == 10**10:
    print('SAFE')
else:
    print(int(ans*10))


Measured memory_bytes: 249196
n, m = map(int, input().split())
flags = [False]*n
num_ac = 0
num_wa = 0
wa_list = [0]*n

for i in range(m):
    p, s = input().split()
    p = int(p)
    if flags[p-1]:
        continue
    else:
        if s=='WA':
            wa_list[p-1] += 1
        else:
            flags[p-1] = True
            num_ac += 1
            num_wa += wa_list[p-1]

print(num_ac, num_wa)

Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e18 + 3)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}
const int n_max  = 53;

int dp[n_max][n_max][n_max * n_max];

signed main(){
    int n , k;
    cin >> n >> k;
    REP(i,n+1) REP(j,n+1) REP(k,(n + 1) * (n + 1)) dp[i][j][k] = 0;
    dp[0][0][0] = 1;

    REP(i,n){
        REP(j,i+1){
            REP(k,n * n){
                int tmp = dp[i][j][k];
                Add(dp[i+1][j][ min( n * n + 1, k+ 2 * j)],tmp);
                Add(dp[i+1][j+1][ min(n * n + 1,k + 2 * j)],tmp);
                if(j > 0){
                    Add(dp[i+1][j][min(n * n + 1, k + 2 * j)] , (j * tmp) % MOD);
                    Add(dp[i+1][j-1][min(n * n + 1,k + 2 * j)] , (j * j * tmp) % MOD);
                    Add(dp[i+1][j][min(n * n + 1,k + 2 * j) ] , (j * tmp) % MOD);
                }
            }
        }
    }

    cout << dp[n][0][k] << endl;
}

Measured memory_bytes: 59648
#ifdef _MSC_VER
#pragma warning(disable : 4996)
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif
 
#include <limits.h>
#include <math.h>
#include <time.h>
 
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
using namespace std;
 
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout << (x) << '\n'
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i, v.size()) cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template <typename T1, typename T2> inline void chmin(T1& a, T2 b) {
	if (a > b) a = b;
}
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) {
	if (a < b) a = b;
}
typedef pair<int, int> pii;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7;
constexpr int MAX = 200020;
const double pi = acos(-1);
constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;
 
 
void solve() {
	int n;
	cin>>n;
	set<string> s;
	string a;
	while(n--)
	{
		cin>>a;
		s.insert(a);
	}
	cout<<s.size();
}
 
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// int q; cin >> q;
	// while (q--)
	solve();
}

Measured memory_bytes: 19300
<?php

fscanf(STDIN, "%d", $n);
list($one, $two) = explode(" ", trim(fgets(STDIN)));
$map_o = str_split($one);
$map_t = str_split($two);

for($i=0;$i<$n;$i++){
    echo $map_o[$i].$map_t[$i];
}



Measured memory_bytes: 4728
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    return iterator.next().unwrap().chars()
        .filter(|c| *c == '2')
        .count()
        .to_string();
}


Measured memory_bytes: 2124
#include<bits/stdc++.h>
using namespace std;
#define int unsigned long long int
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef vector<int>         vi;
const int mod = 1000000007;






int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    map<int,int> m;
    for(int i =0;i<n;i++){
        int no;
        cin>>no;
        m[no]++;
    }
    int ans = 1;
    int cnt =0;
    for(auto it = m.rbegin();it!=m.rend();it++){

            if(it->second >= 4 && cnt==0){
                cout<< it->first *(it->first)<<endl;
                return 0;
            }
            else if(it->second >=2){
                ans = ans*(it->first);
                cnt++;
                if(cnt==2){
                    cout<<ans<<endl;
                    return 0;
                }

            }
    }
    cout<<0<<endl;



    }















































Measured memory_bytes: 6528
local n = io.read("*n")
local t = {}
for i = 1, 100000 do
  t[i] = 0
end
for i = 1, n do
  local a = io.read("*n")
  t[a] = t[a] + 1
end
local ret = 0
for i = 1, 100000 do
  ret = ret + t[i] * i
end
local q = io.read("*n")
for iq = 1, q do
  local b, c = io.read("*n", "*n")
  ret = ret + (c - b) * t[b]
  print(ret)
  t[c] = t[c] + t[b]
  t[b] = 0
end


Measured memory_bytes: 6996