akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict

n,m=map(int,input().split(' '))
paths=defaultdict(list)
ins=[0]*(n+1)
for _ in range(m):
    x,y=map(int,input().split(' '))
    paths[x].append(y)
    ins[y]+=1

no_in=[y for y in range(1,n+1) if ins[y]==0]
depth=[0]*(n+1)
while no_in:
    x=no_in.pop()
    for y in paths[x]:
        ins[y]-=1
        depth[y]=max(depth[y],depth[x]+1)
        if ins[y]==0:
            no_in.append(y)

print(max(depth))

Measured memory_bytes: 67160
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		Map<String, Boolean> map = new LinkedHashMap<>();
		String image = null;
		for(int i = 0;i < 4; i++){
			switch(i){
				case 0:
					image = "S";
					break;
				case 1:
					image = "H";
					break;
				case 2:
					image = "C";
					break;
				case 3:
					image = "D";
					break;
			}
			for(int j = 1; j <= 13; j++){
				map.put(image + " " + String.valueOf(j), false);
			}
		}
		int n = sc.nextInt();
		for(int i = 0; i <= n; i++){
			map.put(sc.nextLine(), true);
		}
		for(String data: map.keySet()){
			if(!map.get(data)){
				System.out.println(data);
			}
		}
	}
}



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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

const int    INF = 1000000000;
const ll     MOD = 1000000007LL;
const double EPS = 1E-12;

struct Point : public complex<double>
{
public:
  Point() { this->real(0);  this->imag(0); }
  Point(const double& x, const double& y) { this->real(x);  this->imag(y); }
  Point(const complex<double> w)  { this->real(w.real());  this->imag(w.imag()); }
  inline double dot(Point p){ return (conj(*this) * p).real(); }  // ??????
  inline double det(Point p){ return (conj(*this) * p).imag(); }  // ??????
};

namespace std
{
  inline bool operator < (const Point& a, const Point& b)
  {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
typedef vector<Point> Polygon;
inline Point currPoint(vector<Point> P, int i){ return P[i]; }
inline Point nextPoint(vector<Point> P, int i){ return P[(i+1)%P.size()]; }
inline Point diffPoint(vector<Point> P, int i){ return nextPoint(P, i) - currPoint(P, i); }

double W, H;
double dx;

inline void update(Point& here)
{
  minup(here.real(), W);    minup(here.imag(), H);
  maxup(here.real(), 1.0);  maxup(here.imag(), 1.0);
}

int main()
{
  while((cin >> W >> H) && W){
    string cmd;
    Point dz = Point(0.0, 1.0);
    Point here = Point(1.0, 1.0);
    while(cin >> cmd){
      if(cmd == "STOP"){
        cout << here.real() << " " << here.imag() << endl;
        break;
      }
      if(cmd == "RIGHT"){ dz *= Point(0, -1.0);  continue; }
      if(cmd == "LEFT" ){ dz *= Point(0,  1.0);  continue; }
      cin >> dx;
      if(cmd == "FORWARD" ) here += dx * dz;
      if(cmd == "BACKWARD") here -= dx * dz;
      update(here);
    }
 }

  return 0;
}

Measured memory_bytes: 1300
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    string a, b, c;
    cin >> a >> b >> c;
    cout << "A" << b[0] << "C";
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};


bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int N,cnt=0;
  char n;
  string S;
  cin >> S;
  n = S[0];
  REP(i,S.size()){
    if(n != S[i]){
      n = S[i];
      cnt++;
    }
  }
  
  cout << cnt << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[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(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

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

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
const int MOD = 1000000007;
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


Measured memory_bytes: 512
def comb_mod(n, k, p):
    """
    nCk mod p
    """
    numerator = 1
    denominator = 1
    for i in range(k):
        numerator *= n - i
        numerator %= p
        denominator *= i + 1
        denominator %= p
    return numerator * pow(denominator, p-2, p) % p

mod = 10**9 + 7
n, a, b = map(int, input().split())
result = pow(2, n, mod) - 1

for i in (a, b):
    result -= comb_mod(n, i, mod)
result %= mod

print(result)

Measured memory_bytes: 3064
N = int(input())
S = input()

sumW = [0 for _ in range(N + 1)]
sumE = [0 for _ in range(N + 1)]

for i, s in enumerate(S) :
    sumW[i + 1] = sumW[i]
    sumE[i + 1] = sumE[i]
    if s == 'W' :
        sumW[i + 1] += 1
    else :
        sumE[i + 1] += 1

ans = float('inf')
for i, s in enumerate(S) :
    count = sumW[i] + (sumE[N] - sumE[i + 1])
    ans = min(ans, count)

print(ans)

Measured memory_bytes: 17872
#include<cstdio>
#include<vector>
#include<iostream>
#include<algorithm>

using namespace std;

int main()

{
	vector<int>data;

	int n;

	cin>>n;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		data.push_back(a);
	}

	sort(data.begin(), data.end());

	int distance =data[data.size() - 1]-data[0];

	cout << distance << endl;

	return 0;
}

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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
#define trav(a, x) for (auto& a : x)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

const int MAX_N = 205;

int N, M, R;
ll d[MAX_N][MAX_N];
int RR[10];
const ll INF = 1000000000000;
ll ans, dist;
bool pick[10];
VI order;

void perm(int idx) {
    if (idx == R) {
        if (dist < ans) ans = dist;
    }
    if (dist > ans) return;
    for (int i = 0; i < R; i++) {
        if (pick[i]) continue;
        pick[i] = true;
        order.pb(RR[i]);
        int dd = 0;
        if (idx > 0) {
            dd = d[order[idx]][order[idx - 1]];
        }
        dist += dd;
        perm(idx + 1);
        pick[i] = false;
        order.pop_back();
        dist -= dd;
    }
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> N >> M >> R;
    REP(i, R) cin >> RR[i];
    REP(i, N + 2) REP(j, N + 2) {
        if (i == j) d[i][j] = 0;
        else d[i][j] = INF;
    }
    int x, y, w;
    REP(i, M) {
        cin >> x >> y >> w;
        d[x][y] = w;
        d[y][x] = w;
    }
    for (int k = 1; k < N + 1; k++) {
        for (int i = 1; i < N + 1; i++) {
            for (int j = 1; j < N + 1; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    ans = LLONG_MAX;
    perm(0);
    cout << ans << endl;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {

	int n, t, a; cin >> n >> t >> a;
	double x = 100000000000;
	int ans;
	for (int i = 0; i < n; i++) {
		double h; cin >> h;
		double e;
		e = t - h * 0.006;
		double tmp = abs(e - a);
		if (chmin(x, tmp)) {
			ans = i + 1;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3712
#include "bits/stdc++.h"
using namespace std;
const int maxn = 2020;
struct histogram_solver{
    static const int factor_h = 1;
    static const int factor_w = 1;
    static long long solve(vector<int> values){
        stack<int> s;
        int i = 0;
        long long ans = 0;
        while(i < values.size()){
            if(s.empty() || values[s.top()] <= values[i]) s.push(i++);
            else{
                int tp = s.top(); s.pop();
                long long area = 1ll * (values[tp] + factor_h) *
                    ((s.empty() ? i : i - s.top() - 1) + factor_w);
                ans = max(ans, area);
            }
        }
        while(!s.empty()){
            int tp = s.top(); s.pop();
            long long area = 1ll * (values[tp] + factor_h) *
                ((s.empty() ? i : i - s.top() - 1) + factor_w);
            ans = max(ans, area);
        }
        return ans;
    }
};
char g[maxn][maxn];
int M(){
    int n, m;
    if(!(cin >> n >> m)) return 0;
    for(int e = 0; e < n; e++)
        scanf("%s", g[e]);
    int ans = max(n, m);
    vector<int> histo(m - 1, 0);
    for(int e = 0; e < n - 1; e++){
        for(int f = 0; f < m - 1; f++){
            int cnt = 0;
            cnt += (g[e][f] == '#');
            cnt += (g[e+1][f] == '#');
            cnt += (g[e][f+1] == '#');
            cnt += (g[e+1][f+1] == '#');
            if(cnt % 2 == 0) histo[f]++;
            else histo[f] = 0;
        }
        ans = max(ans, (int)histogram_solver::solve(histo));
    }
    cout << ans << endl;
    return 1;
}
int main(){
    while(M());
    return 0;
}


Measured memory_bytes: 4352
import itertools
n = int(input())
x, y = [], []
for i in range(n):
    xi, yi = map(int, input().split())
    x.append(xi)
    y.append(yi)
d = 0
for i in range(n):
    for j in range(n):
        d += ((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2) ** 0.5
print(d / n)
    



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

using namespace std;
#define INF (1<<28)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long
int stat;

int check(vector<int> a,int n){
  lp(i,a.size()){
    if(a[i]==n){
      return i+1;
    }
  }
  return 0;
}

int calc(vector<int> a,vector<int> b,int c[],int pos){
  /*cout<<a.size()<<" "<<b.size()<<" "<<pos<<endl;
  int hoge;
  cin>>hoge;*/
  if(b.size()==0){
    return 0;
  }
  if(a.size()==0) return 1;
  vector<int> tr;
  if(pos==0) tr=a;
  else tr=b;
  int eg=0;
  bool sc=pos;
  lp(i,14){
    if(i==0)continue;
    //if(stat>0)return 0;
    if(c[i]==1)continue;
    if(i!=1){
      if(c[i-1]==1&&check(tr,i)){
        eg=1;
        tr.erase(tr.begin()+(check(tr,i)-1));
        c[i]=1;
        if(pos==0) {
          sc|=calc(tr,b,c,1);
        }
        else sc&=calc(a,tr,c,0);
        c[i]=0;
        tr.push_back(i);
      }
    }
    if(i!=13){
      if(c[i+1]==1&&check(tr,i)){
        eg=1;
        tr.erase(tr.begin()+(check(tr,i)-1));
        c[i]=1;
        if(pos==0) {
          sc|=calc(tr,b,c,1);
        }
        else sc&=calc(a,tr,c,0);
        c[i]=0;
        tr.push_back(i);
      }
    }
  }
  if(eg==0){
      if(pos==0)sc=calc(a,b,c,1);
      else sc=calc(a,b,c,0);
  }
  return sc;
}


signed main(){
  int n;
  cin>>n;
  vector<int> a,b;
  lp(i,n){
    stat=0;
    a.clear();
    b.clear();
    int c[14];
    lp(j,14)c[j]=0;
    lp(j,6){
      int x;
      cin>>x;
      c[x]=1;
      a.push_back(x);
    }
    lp(j,14){
      if(j==0||j==7) continue;
      if(c[j]==0) b.push_back(j);
      c[j]=0;
    }
    c[7]=1;
    stat=calc(a,b,c,0);
    if(stat==0) cout<<"no"<<endl;
    else cout<<"yes"<<endl;
  }
  return 0;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> arr(N);
  for(int i=0; i<N; i++){
    cin >> arr.at(i);
  }
  int64_t max_abs=-1;
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      if(i==j){
        continue;
      }
      if(max_abs < abs(arr.at(i)-arr.at(j))){
        max_abs = abs(arr.at(i)-arr.at(j));
      }
    }
  }
  cout << max_abs << endl;
}

Measured memory_bytes: 3572
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  ll n;
  cin >> n;
  cout << n * (n - 1) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

const int mod=998244353,N=305;
int nm,m,n,f[N][N][N],ans,sum[N],a[N];
char s[N];

signed main(){
	scanf("%s",s+1);read(m);
	n=strlen(s+1);s[++n]='0';
	for(int i=1;i<=n;i++){
		if(s[i]=='0') nm++;
		else a[nm+1]++;
	}
	for(int i=1;i<=nm;i++) sum[i]=sum[i-1]+a[i];
	m=min(m,sum[nm]);
	f[0][0][0]=1;
	for(int i=1;i<=nm;i++) 	for(int j=sum[i];j<=sum[nm];j++){
		int lim=min(j,sum[nm]-sum[i-1]);
		for(int k=0;k<=m;k++) for(int bi=0;bi<=lim;bi++) if(max(0,bi-a[i])<=k)
			f[i][j][k]=(f[i][j][k]+f[i-1][j-bi][k-max(0,bi-a[i])])%mod;
	}
	for(int i=0;i<=m;i++) ans=(ans+f[nm][sum[nm]][i])%mod;
	write(ans);
}

Measured memory_bytes: 30624
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

// using namespace __gnu_pbds;
using namespace std;

#define fbo find_by_order
#define ook order_of_key
#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// void initiate_random() { mt19937_64 rng(std::chrono::system_clock::now().time_since_epoch().count()); }

// /mnt/c/Users/vince/Desktop/POST-IOI/Codeforces/Regular/670

int main()
{
	// ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	// freopen("input.in", "r", stdin);

	string s; cin >> s;
	cout << s.substr(0,3) << "\n";
}

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

#define     Boost               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define     all(cont)           cont.begin(),cont.end()
#define     rall(cont)          cont.rbegin(),cont.rend()
#define     foreach(cont)       for(auto &value: cont)
#define     show(val)           cout<< #val << " -> " << val << endl
#define     flush               cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define     Case                cout<< "Case "<< ++cs << ": "
#define     mk                  make_pair
#define     pb                  push_back
#define     ff                  first
#define     ss                  second

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

const ll INF = (1LL<<60)-1 ;




//#define DEBUG
int main()
{
    Boost;

    #ifdef DEBUG
    freopen("input.txt","r",stdin);    // Read
    freopen("output.txt","w",stdout);  // Write
    #endif

    int n ;
    cin>> n ;
    bool flag = false ;
    while(n!=0){
        int tt = n%10 ;
        if(tt==7) flag = true ;
        n /= 10 ;
    }

    if(flag) cout<< "Yes" << endl ;
    else cout<< "No" << endl ;

    return 0;
}




Measured memory_bytes: 3640
from heapq import *
#->: 型注釈
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    
    #要素xが属するグループの根を返す
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    #xのグループとyのグループを併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

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

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

N = int(input())
X = []
for i in range(N):
    x, y = map(int, input().split())
    X.append((x, y, i))

X.sort(key=lambda x: x[0])

H = []
heapify(H)
for i in range(N-1):
    x1, j1 = X[i][0], X[i][2]
    x2, j2 = X[i+1][0], X[i+1][2]
    heappush(H,(x2-x1, j1, j2))
    # print(x1, x2)
    # print("=--")

X.sort(key=lambda x: x[1])


for i in range(N-1):
    y1, j1 = X[i][1], X[i][2]
    y2, j2 = X[i+1][1], X[i+1][2]
    heappush(H,(y2-y1, j1, j2))
    # print(y1, y2)

ans = 0
# print(H)
uf = UnionFind(N)
while H:
    w,s,t = heappop(H)
    if uf.find(s) != uf.find(t):
        uf.union(s,t)
        ans += w
print(ans)


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

int main(){
    int k = 0;
    while(k <= 310){
        int H,W;
        cin >> H >> W;
        if(H == 0 && W == 0) break;
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                cout << '#';
                if(j == W-1) cout << endl;
            }
        }
        cout << endl;
        k++;
    }
    return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

struct edge{ll to, col, len;};
struct query{ll col, id, cff, y;};
ll n;
vector<vector<edge> > v(100001);
vector<ll> ans;
vector<vector<query> > qs(100001);
ll past[100001][20];
ll dist[100001], euc[100001];


void dfs(int now, int count, ll sum = 0, int p = -1){
	past[now][0] = p;
	dist[now] = count;
	euc[now] = sum;
	for(auto& e:v[now]){
		if(e.to == p)continue;
		dfs(e.to, count+1, sum + e.len, now);
	}
	return;
}

void dinit(){
	for(int j=0;j<19;j++)for(int i=0;i<n;i++)if(past[i][j] != -1) past[i][j+1] = past[past[i][j]][j];
	return;
}

ll par(ll now, ll m){
	for(int i=0, j=1;j<=m;i++,j*=2) if(m&j) now = past[now][i];
	return now;
}

ll lca(ll a,ll b){
	if(dist[a] < dist[b]) b = par(b, dist[b] - dist[a]);
	else if(dist[a] > dist[b]) a = par(a, dist[a] - dist[b]);
	ll le = -1, ri = dist[a], mid;
	while(ri - le > 1){
		mid = (ri + le) / 2;
		if(par(a,mid) == par(b,mid)) ri = mid;
		else le = mid;
	}
	return par(a, ri);
}

ll dis(ll a, ll b){ return euc[a] + euc[b] - euc[lca(a, b)] * 2;}

ll cnt[100001];
ll sum[100001];

void dfs2(int now, int p = -1){
	for(auto q: qs[now]){
		ll x = -sum[q.col];
		x += q.y*cnt[q.col];
		ans[q.id] += x*q.cff;
	}
	for(auto& e: v[now]){
		if(e.to == p) continue;
		cnt[e.col]++; sum[e.col] += e.len;
		dfs2(e.to, now);
		cnt[e.col]--; sum[e.col] -= e.len;
	}
}

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    memset(past,-1,sizeof(past));
    int q;
    cin >> n >> q; ans.resize(q);
    for(int i=1;i<n;i++){
    	int a, b, c, d;
    	cin >> a >> b >> c >> d;
    	a--;b--;
    	v[a].push_back({b,c,d});
    	v[b].push_back({a,c,d});
    }
    dfs(0, 0);
    dinit();
    for(int i=0;i<q;i++){
    	ll x, y, a, b;
    	cin >> x >> y >> a >> b;
    	a--;b--;
    	qs[a].push_back({x,i,1,y});
    	qs[b].push_back({x,i,1,y});
    	qs[lca(a,b)].push_back({x,i,-2,y});
    	ans[i] = dis(a,b);
    }
    dfs2(0);
    for(auto& i:ans) cout << i << endl;
    return 0;
}


Measured memory_bytes: 49136
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

// constexpr int MOD = 1e9+7;

using P = pair<string, pair<int, int>>;

int main(void){
    Cin(int, n);
  	vector<P> a(n);
  	For(i, n){
      cin >> a[i].first >> a[i].second.first;
      a[i].second.second = i+1;
      a[i].second.first *= -1;
    }
  	Sort(a);
  	For(i, n){
  	    Cout(a[i].second.second);
  	}
}

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

using Float = double;
using Point = complex<Float>;

vector<Point> ps;

const Float radius = 1.0;
const Float EPS = 1e-8;

int calc(Point c){
	int ret = 0;
	for(const Point &p : ps){
		if(abs(p - c) <= radius + EPS) ret++;
	}
	return ret;
}

signed main(){
	int n;
	while(cin >> n,n){
		ps.clear();
		for(int i = 0;i < n;i++){
			Float x,y;
			cin >> x >> y;
			ps.emplace_back(x,y);
		}
		int ans = 1;
		for(int i = 0;i < n;i++){
			for(int j = i + 1;j < n;j++){
				if(abs(ps[i] - ps[j]) >= radius * 2) continue;
				Point mid = (ps[i] + ps[j]) / 2.0;
				Point vect = Point(imag(ps[i] - ps[j]),-real(ps[i] - ps[j]));
				Float dist = sqrt(1.0 - norm(mid - ps[i]));
				ans = max(ans,max(calc(mid + vect / abs(vect) * dist),calc(mid - vect / abs(vect) * dist)));
			}
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3208
S = input()
l = []
pattern = [format(i, 'b').zfill(4) for i in range(2 ** 4)]

for i in pattern:
    tmp = list(map(int, list(i)))
    l.append('A' * tmp[0] + 'KIH' + 'A' * tmp[1] + 'B' + 'A' * tmp[2] + 'R' + 'A' * tmp[3])

if S in l:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
 
#define CASES int t;cin>>t;while(t--)
#define REP(i, val, b) for (int i = val; i < b; ++i)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
 
int main() {
	fastio
	string s;
	cin >> s;
	vector<bool> A(26, 0);
	REP(i,0,3) {
		A[s[i]-'a'] = true;
	}
	if (A[0] && A[1] && A[2]) cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
	int i, n, l[100]={ }, longest, sum=0;
	scanf("%d", &n);
	for(i=0; i<n; i++)
		scanf("%d", &l[i]);
	longest=l[0];
	for(i=0; i<n; i++) {
		if(longest<l[i])
			longest=l[i];
		sum+=l[i];
	}
	sum-=longest;
	if(longest<sum)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

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

template <class T> using V = vector<T>;

using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;


#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) __lcm(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;



int main() {
  ll a,b,c;
  	ci(a>>b>>c);
  ll x;
  	ci(x);
  
  ll ans=0;
  
  FOR(i,0,a+1){
    FOR(j,0,b+1){
      FOR(k,0,c+1){
        if(500*i+100*j+50*k==x){
          ans++;
        }
      }
    }
  }
  co(ans)
}

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

constexpr int INSUU = 64;
constexpr int SOSUU = 1000000;

int Eratosthenes(int* primes){
  primes[0] = 2;
  primes[1] = 3;
  primes[2] = 5;
  primes[3] = 7;
  int prime_p = 4;
  for(int p = 11; p <= SOSUU; p+=2){
    bool is_prime = true;
    for(int i = 0; i < prime_p && primes[i] < 1000; i++){
      if((p % primes[i]) == 0){
	is_prime = false;
	break;
      }
    }
    if(is_prime){
      primes[prime_p++] = p;
    }
  }
  return prime_p;
}
int main(){
  int primes[SOSUU/2];
  int prime_count = Eratosthenes(primes);
  int n;
  while(cin >> n){
    int i = 0;
    for(; i < prime_count; i++){
      if(n < primes[i]){
	cout << i << endl;
	break;
      }
    }
    if(prime_count == i){
      cout << prime_count << endl;
    }
  }
}

Measured memory_bytes: 1472
#include<iostream>
using namespace std;
string s;
main()
{
  cin>>s;
  for(int i=1;i<s.size();i++)
  {
    if(s[i-1]==s[i])
    {
      cout<<i<<" "<<i+1<<endl;
      return 0;
    }
    if(i>1&&s[i-2]==s[i])
    {
      cout<<i-1<<" "<<i+1<<endl;
      return 0;
    }
  }
  cout<<"-1 -1"<<endl;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int digit(int N){
    int s=0;
    while(N>0){
    s+=N%10;
    N/=10;
    }
    return s;
}
int main(void){
    int N,a,b,i,sum=0,dsum;
    cin>>N>>a>>b;
    for(i=1;i<=N;i++){
        dsum = digit(i);
       if( a<= dsum&& b>= dsum)
       sum+=i;
    }
    cout << sum <<endl;
}

Measured memory_bytes: 256
#include <numeric>
#include <iostream>
#include <cstdio>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

typedef long long ll;

using namespace std;

int main(){
  string s; cin >> s;
  const int n = s.size();

  vector<int> cnt('z' - 'a' + 1);

  REP(i,n) cnt[s[i] - 'a']++;

  vector<int> q;
  int bad = 0;
  for(char c = 'a'; c <= 'z'; c++){
    q.push_back(cnt[c - 'a'] / 2);
    if(cnt[c - 'a'] % 2 != 0){
      bad++;
    }
  }

  if(bad > 1){
    puts("0");
  }else{
    int next = accumulate(q.begin(), q.end(), 0);
    ll ans = 1;

    while(next != 0){
      bool flag = true;

      REP(i,q.size()) if(q[i] > 1){
        if(ans % q[i] == 0){
          ans /= q[i]--;
          flag = false;
        }
      }

      if(flag){
        ans *= next--;
      }
    }

    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
 
typedef long long LL;
const int mod = 1000000007;
const int MAXN = 100005;
LL num[MAXN];
LL fact[MAXN];
LL my_pow(LL a, LL b)
{
    LL sum=1;
    while(b>0)
    {
        if(b&1)
            sum=sum*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return sum%mod;
}
void init()
{
    fact[0]=1;
    for(int i=1;i<MAXN;++i)
       fact[i]=fact[i-1]*i%mod;
}
LL comb(LL a, LL b)
{
    if(b>a)
        return 0;
    return fact[a] *  my_pow(fact[b] * fact[a-b] % mod, mod-2) % mod;
}
int main()
{
   int n, k;
   init();
   scanf("%d %d", &n, &k);
   for(int i=0;i<n;++i)
       scanf("%lld", &num[i]);
   LL ans=0;
   sort(num, num+n);
   for(int i=0;i<n-k+1;++i)
   {
       ans = (ans + (num[n-i-1]-num[i])%mod*comb(n-i-1,k-1)%mod)%mod;
       //printf("%d %d %lld\n", n-i-1, k-1, (num[n-i-1]-num[i])*comb(n-i-1,k-1)%mod);
   }
   printf("%lld\n" ,(ans % mod + mod)%mod);
   return 0;
}

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

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

  int counter = 0;

  for(int i = 0; i <= k; ++i){
    for(int j = 0; j <= k; ++j){
      int l = s - (i + j);

      if(l >= 0 && l <= k) ++counter;
      else continue;
    }
  }

  cout << counter << endl;

  return 0;
  
}


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

int main(){
  int64_t N,D;
  cin >> N >> D;
  int ans=0;
  for(int i=0;i<N;i++){
    int64_t X,Y;
    cin >> X >> Y;
    if(X*X+Y*Y<=D*D){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3612
N = int(input())
dic = {}
for _ in range(N):
    s = input()
    dic.setdefault(s, 0)
    dic[s] += 1
ans = list(dic.items())
ans.sort(key=lambda x: (-x[1], x[0]))
m = ans[0][1]
print("\n".join(i[0] for i in ans if i[1] == m))

Measured memory_bytes: 63768
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int a[] = new int[4];
    for(int i=3;i>=0;i--){
      a[i] = N %10;
      N = N/10;
    }
    int count = 0;
    for(int i=0;i<3;i++){
      if(a[i] == a[i+1]){
        if(a[1] == a[2]){
          count++;
        }
      }
    }
    if(count >= 2){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 21588
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
  
ll N,K,L,R;
ll a[40];
  
vector< P > x,y;
  
void pt(int si,int ti,vector< P > &x){
  int num=ti-si;
  for(int S=0;S<(1<<num);S++){
    ll sum=0,cnt=0;
    for(int j=0;j<num;j++)
      if(S>>j&1)
        sum+=a[si+j],cnt++;
    x.push_back(P(cnt,sum));
  }
}
  
int main(){
  cin>>N>>K>>L>>R;
  for(int i=0;i<N;i++)cin>>a[i];
  pt(0,N/2,x);
  pt(N/2,N,y);
  
  sort(y.begin(),y.end());
    
  ll ans=0;
  for(int i=0;i<(int)x.size();i++){
    vector< P > :: iterator itl,itr;
    itl=lower_bound(y.begin(),y.end(),P(K-x[i].first,L-x[i].second));
    itr=upper_bound(y.begin(),y.end(),P(K-x[i].first,R-x[i].second));
    ans+=(itr-itl);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 43756
#include <iostream>
#include <string>
#include <cctype>
#include <array>
#include <algorithm>

int main ()
{
  std::string str;
  std::array<int, 27> count;
  count.fill(0);

  auto assign = [&](auto c){
                  c = std::tolower(c);
                  auto i = static_cast<int>(c) - static_cast<int>('a');
                  if ((i>=0) && (i<26))
                    count.at(i) += 1;
                };

  while ((std::cin >> str))
    {
      std::for_each(str.begin(), str.end(), assign);
    }

  for (int i=0; i<26; i++)
    {
      auto c = static_cast<char>(static_cast<int>('a') + i);
      std::cout << c << " : " << count.at(i) << std::endl;
    }
}



Measured memory_bytes: 3184
#include<bits/stdc++.h>
using namespace std;
char a[100005];
int x=0,y=0,ans=0;
int main()
{
    cin>>a;
    for (int i=0;i<sizeof(a);i++)
     if (x==y){x++; if(a[i]=='p') ans--;}    
     else{y++; if(a[i]=='g') ans++;}         
    printf("%d\n",ans);                      
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <algorithm>
typedef long long ll;

int main(void) {
  ll i, j, k, n, a, h = 0, t;
  scanf("%lld%lld", &n, &k);
  ll sum[n + 1];
  sum[0] = 0;
  for(i = 1; i <= n; ++i) {
    scanf("%lld", &a);
    sum[i] = sum[i - 1] + a;
  }
  t = sum[n];
  while( 1 ) {
    ll *p = sum + 1, now = (t + h) / 2;
    for(i = 0; i < k; ++i) {
      p = std::upper_bound(p, sum + n + 1, now + *(p - 1));
      if(p == sum + n + 1) break;
    }
    if(p == sum + n + 1) t = now;
    else h = now;
    if(t - h == 1) break;
  }
  printf("%lld\n", t);
  return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<vector<int>> f (n,vector<int>(10));
    vector<vector<int>> p (n,vector<int>(11));
    for(int i=0; i<n; i++){
        for(int j=0; j<10; j++){
            cin >> f.at(i).at(j);
        }
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<11; j++){
            cin >> p.at(i).at(j);
        }
    }
    ll ans = -1000000100;
    for(int i=1; i<(1 << 10); i++){
        ll prof = 0;
        for(int j=0; j<n; j++){
            ll count = 0;
            for(int k=0; k<10; k++){
                if(((i>>k)&1) && f.at(j).at(k)){
                    count++;
                }
            }
            prof += p.at(j).at(count);
        }
        if(prof > ans){
            ans = prof;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#define MOD 1000000007;
using namespace std;

string b, t;
long long dp[1005][1005] = { 0 };

int main() {
	cin >> t >> b;
	int bs = b.size();
	int ts = t.size();
	for (int j = 0; j < t.size(); j++) {
		if (j > 0) dp[0][j] += dp[0][j - 1];
		if (b[0] == t[j]) dp[0][j]++;
	}
	for (int i = 1; i < b.size(); i++) {
		for (int j = 0; j < t.size(); j++) {
			dp[i][j] = dp[i][j - 1];
			if (b[i] == t[j]) {
				dp[i][j] = dp[i - 1][j - 1] + dp[i][j - 1];
			}
			dp[i][j] %= MOD;
		}
	}
	cout << dp[bs - 1][ts - 1] << endl;
	return 0;
}


Measured memory_bytes: 11076
n=int(input())
l=list('abcdefghijklmnopqrstuvwxyz')
s=[]#格納よう
i=1#桁数
while n>26**i:
  n-=26**i
  i+=1
n-=1
while i!=0:
  p=n//26**(i-1)
  n=n%26**(i-1)
  s.append(l[p])
  i-=1

print(''.join(s))

Measured memory_bytes: 9192
n = int(input())
ans = 0
music = []
for i in range(n):
    s, t = input().split()
    music.append([s,t])

x = input()
flag = 0
for i in range(n):
    if flag == 1:
        ans += int(music[i][1])
    if music[i][0] == x:
        flag = 1

print(ans)


Measured memory_bytes: 38384
#include<iostream>
#include<cstdio>
#include<string.h>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cmath>
using namespace std;
#define ll long long
void read(__int128 &x)
{
    x = 0;
    char ch;
    int flag = 1;
    while ((ch = getchar()))
    {
        if (ch == '-') flag = -1;
        if (ch >= '0' && ch <= '9') break;
    }
    x = ch - '0';
    while ((ch = getchar()) >= '0' && ch <= '9')
    {
        x = x * 10 + ch - '0';
    }
    x *= flag;
}

void out(__int128 x)
{
    if (x < 0)
    {
        x = -x;
        putchar('-');
    }
    if (x >= 10) out(x / 10);
    putchar(x % 10 + '0');
}
ll quick(ll a, ll b)
{
    ll ans = 1;
    while(b)
    {
        if(b & 1)
            ans = ans * a;
        a = a * a;
        b >>= 1;
    }
    return ans;
}
ll a, b, x;

int main()
{


    ll b = -100;
    ll x;
    cin >> x;
    while(true)
    {
        //  cnt++;
        b++;
        ll b_5 = quick(b, 5);
        ll a_15 = pow(b_5 + x, 1.0 / 5.0);
        ll a_5 = quick(a_15, 5);
        if(a_5 == b_5 + x)
        {
            cout << a_15 << " " << b  << endl;
            break;
        }

    }
}



Measured memory_bytes: 4072
/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=10000;
int main()
{
	int n,ans=0;scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int X;scanf("%d",&X);
		while(X%2==0)
			X/=2,ans++;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll ;
typedef double db;
const double pi = 3.141592654;
#define pb         push_back
#define forab(i,a,b)       for(int i=(a);i<=(b);i++)
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)
#define pcase(z,x)     printf("Case %ld: %lld\n",z,x)
#define nw	 "\n"
#define mod 1000000007

int main(void)
{
	CIN;
	ll tc,l,k,sum=0,x=0,y,z=0,m=1,n=0,ans=0,cnt=0;
	string s,t;
	cin>>s;
	cout<<s.rfind('Z')-s.find('A')+1;
}

Measured memory_bytes: 3752
#include <stdio.h>
#include <string.h>

int main(void)
{
  char p[200];
  char s[100];
  int len;
  int i;

  scanf("%s%s", p, s);

  len = strlen(p);

  for(i = 0; i < len - 1; i++)
    p[len + i] = p[i];

  p[len + i] = '\0';
  
  if(strstr(p, s) == NULL)
    printf("No\n");
  else
    printf("Yes\n");

  return 0;
}

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

    #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
    #define uint unsigned int
    #define lli long long int
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define pii pair<int,int>
    #define all(x) (x).begin(), (x).end()
    #define forn(i, n)  for(int i=0;i<n;++i)
    #define rforn(i,start) for(int i = start; i >= 0;--i)
    #define forsn(i,start,end) for(int i=start;i<end;++i)
    #define rforsn(i,start,end) for(int i=start;i>=end;--i)
    #define debug(x) cout<<#x<<" = "<<x<<"\n";
    const int CONST = 1e9 + 7;
    const double pi = 3.14159265358979323846;

    int32_t main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);

        #ifndef ONLINE_JUDGE
        //    freopen("input.txt", "r", stdin);
        //  freopen("output.txt","w",stdout);
        #endif
        
        int x, n;
        cin>>x>>n;
        vector<int> p(n);
        forn(i, n){
            cin>>p[i];
        }
        set<int> num(all(p));
        int ans=0, diff=INT_MAX;
        forsn(i, -103, 103){
            if(num.count(i)==0 && abs(x-i)<diff){
                ans = i;
                diff= abs(x-i);
            }
        }
        cout<<ans;
        // sort(all(p));
        // auto it = lower_bound(all(p), x);

    }


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

int main(){
    string s,t ;
    cin >> s >> t ;
    bool ok = true ;
    for(int i=0;i<s.size();i++){
        ok = true ;
        for(int j=0;j<t.size();j++){
            if(s.at((i+j)%s.size())!=t.at(j)){
                ok = false ;
                break ;
            }
        }
        if(ok){
            cout << "Yes" << endl ;
            return 0 ;
        }
    }
    cout << "No" << endl ;
}


Measured memory_bytes: 3184
#!/usr/bin/env python3


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

N, M = map(int, input().split())

if M%N == 0:
    print(M//N)
else:
    D = sorted(make_divisors(M))[::-1]
    for d in D:
        if M//d >= N:
            print(d)
            break



Measured memory_bytes: 38640
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  int N;
  while(cin >> N, N){
    vector<int> c(N+1); FOR(i,0,N) scanf("%d",&c[i]);
    c[N] = 10;
    // i??????????????´??????
    int ans = 1e9;
    FOR(i,0,N) {
      // 2?????????
      FOR(j,1,4) {
        vector<int> chain = c;
        if(chain[i] == j) continue;
        chain[i] = j;
        FOR(k,0,10000) {
          bool del = false;
          int cnt = 0;
          FOR(l,0,(int)chain.size()-1) {
            if(chain[l] == chain[l+1]) cnt++;
            else {
              if(cnt >= 3) {
                chain.erase(chain.begin() + l - cnt, chain.begin() + l + 1);
                del = true;
                break;
              }
              cnt = 0;
            }
          }
          if(!del) {
            ans = min(ans, (int)chain.size() - 1);
            break;
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9+7;

#define rep(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

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

  int ans = 0;
  for (int i = 1; i < S.size(); ++i) {
    if (S[i-1] != S[i]) ans++;
  }

  cout << ans << endl;
}

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

int main(){
  int n, a, min = 1000000, max = -1000000;
  long long sum = 0;
  cin >> n;
  for (int i=1; i<=n; i++){
    cin >> a;
    if (a < min) min = a;
    if (a > max) max = a;
    sum += a;
  }
  cout << min << " " << max << " " << sum << endl;
  return 0;
}

Measured memory_bytes: 3080
using System;
using System.Linq;

public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var min = a.Min();
        var max = a.Max();
        Console.WriteLine(2 * n);
        if (min + max < 0)
        {
            var minInd = Array.IndexOf(a, min) + 1;
            Console.WriteLine($"{minInd} {minInd}");
            for (int i = 1; i <= n; i++) Console.WriteLine($"{minInd} {i}");
            for (int i = n; i >= 2; i--) Console.WriteLine($"{i} {i - 1}");
        }
        else
        {
            var maxInd = Array.IndexOf(a, max) + 1;
            Console.WriteLine($"{maxInd} {maxInd}");
            for (int i = 1; i <= n; i++) Console.WriteLine($"{maxInd} {i}");
            for (int i = 1; i <= n - 1; i++) Console.WriteLine($"{i} {i + 1}");
        }
    }
}


Measured memory_bytes: 13280
s=gets.chomp
n=s.size
(n/2).times do |i|
  if s[i]!=s[-1-i]
    puts "No"
    exit
  end
end
s1=s[0..(n-1)/2-1]
s2=s[(n+3)/2-1..-1]
(s1.size/2).times do |i|
  if s1[i]!=s1[-1-i]
    puts "No"
    exit
  end
end
(s2.size/2).times do |i|
  if s2[i]!=s2[-1-i]
    puts "No"
    exit
  end
end
puts "Yes"


Measured memory_bytes: 1788
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
    int a,b;
    cin >> a >> b;
    if(a > b)cout << a-1;
    else cout << a;
    return 0;
}


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

using namespace std;

typedef long long LL;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	string S; cin >> S;
	vector<int> b(26,0);
	for(auto c : S) b[c-'a'] = 1;
	int n = S.size()-1;
	if(n < 25){
		repp(i,0,26) if(!b[i]){
			S += i+'a';
			break;
		}
	} else {
		while(n >= 0){
			repp(c,S[n]-'a'+1,'z'-'a'+1) if(!b[c]){
				S[n] = c+'a';
				S = S.substr(0,n+1);
				n = -10;
			}
			b[S[n]-'a'] = 0;
			--n;
		}
	}
	if(n == -1) cout << -1 << endl;
	else cout << S << endl;
}


Measured memory_bytes: 256
mod=998244353
def modpow(a,r):
    ret=1
    while r>0:
        if r%2==1:
            ret*=a
            ret%=mod
        a*=a
        a%=mod
        r//=2
    return ret
n=int(input())
ds=[int(i) for i in input().split()]
if ds[0]!=0:
    print(0)
else:
    ma=max(ds)
    cnt=[0 for i in range(ma+1)]
    for i in ds:
        cnt[i]+=1
    if cnt[0]!=1 or min(cnt)==0:
        print(0)
    else:
        res=1
        for i in range(1,ma+1):
            res*=modpow(cnt[i-1],cnt[i])
            res%=mod
        print(res)

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

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


Measured memory_bytes: 256
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <complex>
typedef long long int LL;
using namespace std;

// 插入此處

int main() {
    int n;
    scanf("%d", &n);
    printf("%d\n", n % 2 == 0 ? n : 2 * n);
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-
import collections
n = int(input())
c = input()

#方針は、全て同じ色にする or 左側にR右側にW
cnt = collections.Counter(c)
w_cnt = cnt['W']
r_cnt = cnt['R']
w_right_cnt = w_cnt
r_right_cnt = r_cnt
w_left_cnt = 0
r_left_cnt = 0
if w_cnt == n or r_cnt == n:
    print(0)
    exit()
ans = n
for i in range(n):
    #仕切りの両側のWとRの数を数える
    if c[i] == 'W':
        w_left_cnt += 1
        w_right_cnt -= 1
    if c[i] == 'R':
        r_left_cnt += 1
        r_right_cnt -= 1
    #解説PDFの・が2つの部分を調べる
    if w_left_cnt <= r_right_cnt:
        ans = min(r_right_cnt, ans)
    elif w_left_cnt > r_right_cnt:
        ans = min(w_left_cnt, ans)
print(ans)

Measured memory_bytes: 9612