akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int sx,sy,tx,ty;
	cin>>sx>>sy>>tx>>ty;
	int y=ty-sy;
	int x=tx-sx;
	for(int i=0;i<y;i++)
	cout<<'U';
	for(int i=0;i<x;i++)
	cout<<'R';
	for(int i=0;i<y;i++)
	cout<<'D';
	for(int i=0;i<x;i++)
	cout<<'L';
	cout<<'L';
	for(int i=0;i<y+1;i++)
	cout<<'U';
	for(int i=0;i<x+1;i++)
	cout<<'R';
	cout<<'D';
	cout<<'R';
	for(int i=0;i<y+1;i++)
	cout<<'D';
	for(int i=0;i<x+1;i++)
	cout<<'L';
	cout<<'U';
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from collections import deque
import sys

f_inf = float("inf")

# Input#
# n = int(input())
h, w = map(int, input().split())
c_h, c_w = map(int, input().split())
d_h, d_w = map(int, input().split())

grid = []

d = deque()


for i in range(h + 1):
    if i == 0:
        array_tmp = "#" * w
    else:
        array_tmp = str(input().strip())
    array_tmp = "#" + array_tmp
    grid.append(list(array_tmp))


grid[c_h][c_w] = 0

d.append((c_h, c_w))


def check(tar_h, tar_w):
    if tar_h > h or tar_h < 1:
        return -1
    if tar_w > w or tar_w < 1:
        return -1
    if grid[tar_h][tar_w] == ".":
        return f_inf
    if grid[tar_h][tar_w] == "#":
        return -1
    else:
        return grid[tar_h][tar_w]


while len(d) != 0:
    tar_h, tar_w = d.popleft()
    tar_num = grid[tar_h][tar_w]
    if tar_num == "#":
        continue

    for i in range(5):
        for j in range(5):
            checknum = check(tar_h + i - 2, tar_w + j - 2)
            if checknum > tar_num:
                if (
                    (i == 2 and j == 1)
                    or (i == 2 and j == 3)
                    or (i == 1 and j == 2)
                    or (i == 3 and j == 2)
                ):
                    grid[tar_h + i - 2][tar_w + j - 2] = tar_num
                    d.appendleft((tar_h + i - 2, tar_w + j - 2))
                    if tar_h == d_h and tar_w == d_w:
                        print("{}".format(tar_num))
                        sys.exit()
                else:
                    if checknum > tar_num + 1:
                        grid[tar_h + i - 2][tar_w + j - 2] = tar_num + 1
                        d.append((tar_h + i - 2, tar_w + j - 2))

if check(d_h, d_w) == f_inf:
    ans = -1
else:
    ans = check(d_h, d_w)

print("{}".format(ans))


Measured memory_bytes: 165764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, x, y;
    cin >> n >> x >> y;
    x--;
    y--;
    vector<vector<int>> g(n);
    rep(i, 0, n - 1) {
        g[i].push_back(i + 1);
        g[i + 1].push_back(i);
    }
    g[x].push_back(y);
    g[y].push_back(x);

    int ans[n - 1] = {};
    rep(i, 0, n) {
        queue<int> que;
        int dist[n] = {};
        rep(j, 0, n) dist[j] = -1;
        dist[i] = 0;
        que.push(i);
        while (!que.empty()) {
            int v = que.front();
            que.pop();
            for (auto nv : g[v]) {
                if (dist[nv] != -1) continue;
                dist[nv] = dist[v] + 1;
                que.push(nv);
            }
        }
        rep(j, i + 1, n) {
            ans[dist[j]]++;
        }
    }

    rep(i, 1, n - 1) {
        cout << ans[i] << endl;
    }
    cout << ans[0] << endl;
    return 0;
}


Measured memory_bytes: 384
// AtCoder ABC129: C - Typical Stairs
// 2019.9.4 bal4u

#include <stdio.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

#define MOD 1000000007
int N;
char f[100005];
int dp[100005];

int main()
{
	int i, M;
	
	N = in(), M = in();
	memset(f, 1, N+1);
	while (M--) f[in()] = 0;
		
	dp[0] = 1; if (f[1]) dp[1] = 1;
	for (i = 2; i <= N; i++) if (f[i]) dp[i] = (dp[i-1] + dp[i-2]) % MOD;
	printf("%d\n", dp[N]);
	return 0;
}


Measured memory_bytes: 640
import java.io.*;

class Main {
	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		try{
			String s = reader.readLine();
			char[] c = s.toCharArray();
			int n = c.length;
			int ans = 0;
			if(n % 2 == 0){
				for(int i = 0; i < (n / 2); i++){
					if(c[i] != c[(n - 1) - i]){
						ans ++;
					}
				}
			}else{
			for(int i = 0; i < (n - 1) / 2; i++){
				if(c[i] != c[(n - 1) - i]){
					ans ++;
				}
			}
		}
		System.out.println(ans);
		} catch(IOException e) {
			System.out.println(e);
		} 
	}
}

Measured memory_bytes: 23380
line = gets.chomp.split.map(&:to_f)

p1 = [line[0], line[1]]
p2 = [line[2], line[3]]

x = p2[0] - p1[0]
y = p2[1] - p1[1]

l = ((x * x) + (y * y)) ** 0.5

puts l

Measured memory_bytes: 8824
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    using R = double;

    int n, K; cin >> n >> K;

    R res = 0.0;
    rep(i, 1, n+1){
        int cur = 1;
        int X = i;
        while(X < K){
            cur *= 2;
            X *= 2;
        }
        res += 1.0 / n / cur;
    }

    cout.precision(12);
    cout << fixed << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;cin>>n>>m;
  priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<>>que;
  for(int i=0;i<n;i++){
    ll a,b;cin>>a>>b;
    que.push(mp(a,b));
  }
  ll ans = 0;
  while(!que.empty()){
    ll va = que.top().F;
    ll num = que.top().S;
    que.pop();
    if(num >= m){
      ans += m * va;
      break;
    }else{
      m-=num;
      ans += num*va;
    }
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}

/* main */

ll N,M;
vll adj;
ll memo[100010];

ll dfs(ll n){
    if(adj[n].size() == 0)return 0;
    if(memo[n])return memo[n];
    ll ans = 0;
    for(auto x:adj[n])chmax(ans,dfs(x)+1);
    return memo[n] = ans;
}

signed main(){
    cin >> N >> M;
    adj.resize(N);
    FOR(i,0,M){
        ll x,y;
        cin >> x >> y;
        x--;
        y--;
        adj[x].pb(y);
    }
    ll ans = 0;
    FOR(i,0,N)chmax(ans,dfs(i));
    cout << ans << endl;
}

Measured memory_bytes: 8576
/*
	Failure is not the reason for you to stop trying 
	   it is actually a remainder that you should 
			KEEP GOING 
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define E endl
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int dp[N];
signed main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		char s, t;
		cin>>s>>t;
		string ss,tt;
		int n ,m;
		n = s-'0';
		m = t-'0';
		while(m--)ss+=s;
		while(n--)tt+=t;
		cout <<min(ss,tt)<<endl;
	
	}
	
	cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
///////////////////////////////////////////
const long long int INF = INT32_MAX;
const long long int Mod = 1000000007;
const long long int mod = 100000;//10^5
using ll = long long int; //long long int は64bit
using ci = const int; using vi = vector<int>; using Vi = vector<long long int>; using pii = pair<int,int>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
#define np nullptr
template<class T>bool chmax(T &former, const T &b) { if (former<=b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define fill(x,num) memset(x,num,sizeof(x));
typedef vector<vector<ll> > matrix;
//       cin.tie(0);ios::sync_with_stdio(false);
void cinit(){cin.tie(0);ios::sync_with_stdio(false);}
//////////////////////////^^ *Emile ^^^//////////////////////////////////////////////////////

int main(){
	ll n,m;cin>>n>>m;
	vi v;ll aa;
	rep(i,m){
		cin>>aa;v.pb(aa);
	}
	sort(all(v));
	vi vd;
	if(m==1){
		cout<<v[v.size()-1]-v[0]<<endl;
		return 0;
	}
	rep(i,v.size()-1){
		vd.pb(v[i+1]-v[i]);
	}
	Sort(vd);
	ll ans = v[v.size()-1]-v[0];
	rep(i,n-1){
		if(i>=vd.size()){break;}
		ans -= vd[i];
	}
	cout<<ans<<endl;
	return 0;
}

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

//Function Macros:
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type Definitions:
typedef long long ll;
typedef unsigned long long ull;

//Constants:
const int INF = 2e9;
const int MOD = 1e9 + 7;

//Global Variables:

//Prototype Declarations:
int gcd(int, int);

//================ Main Loop ================
int main()
{
    string S;
    cin >> S;
    if(S=="Sunny")
        cout << "Cloudy" << endl;
    else if(S=="Cloudy")
        cout << "Rainy" << endl;
    else
        cout << "Sunny" << endl;
    
    return 0;
}
//===========================================

//Functions:
int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}

Measured memory_bytes: 256
N = int(input())
L = list(map(int,input().split()))


L.sort()
#print(L)
cnt = 0
for i in range(N):
    a = L[i]
    for j in range(i+1,N):
        b = L[j]
        if b == a :
            continue
        for k in range(j+1,N):
            c = L[k]
            if  c == b :
                continue
            elif a + b <= c :
                break
            else:
                # print([a,b,c])
                cnt += 1
print(cnt)

Measured memory_bytes: 8988
N = gets.to_i
A = N.times.map do
  gets.to_i.times.map { gets.split.map!(&:to_i) }
end

max_honests = 0
(1 << N).times do |i|
  valid = true
  honests = 0
  is_honests = []
  N.times do |n|
    next if i[n] == 0

    honests += 1
    next unless valid

    A[n].each do |a|
      if a[1] != i[a[0] - 1]
        valid = false
        break
      end
    end
  end

  max_honests = honests if valid && max_honests < honests
end

puts max_honests


Measured memory_bytes: 3836
N = int(input())
H = [int(i) for i in input().split()]
max_left = [0 for i in range(N)]
for i in range(1,N):
  max_left[i] = max(max_left[i-1], H[i-1])
res = 0
for i in range(N):
  if H[i] >= max_left[i]:
    res += 1
print (res)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 998244353;

int power(ll a, ll b=mod-2){
  ll res=1;
  while(b>0){
  if(b & 1) res=res*a%mod;
  a=a*a%mod;
  b>>=1;
  }
return res;
}

int main(){
  ll n,m,k;
  cin >> n >> m >> k;
  vector<ll>num(n);
  num[0]=m;
  for(int i=1; i<n; i++){
    num[i]=(m-1)*num[i-1];
    num[i]%=mod;
  }
  reverse(num.begin(),num.end());
  //cout << num[0] << endl;
  
  vector<ll>c(k+1);
  ll ans=0;
  ll bunsi=1;
  
  for(ll i=1; i<=n-1; i++){
    bunsi*=i;
    bunsi%=mod;
  }
  
  //cout << bunsi << endl;
  c[0]=bunsi;
  for(int i=1; i<=k; i++){
   c[i]=c[i-1];
   c[i]*=i;
   c[i]%=mod;
   //cout << c[i] << " ";
   c[i]*=power(n-i,mod-2);
   c[i]%=mod;
   //cout << c[i] << endl;
  }
  
  for(int i=0; i<=k; i++){
    ll x=bunsi;
    x*=power(c[i],mod-2);
    x%=mod;
    //cout << power(c[i],mod-2) << " ";
    x*=num[i];
    x%=mod;
    ans+=x;
    ans%=mod;
    //cout << num[i] << " " << ans << endl;
  }
  
  cout << ans << endl;
  
  return 0;
}
  
  


Measured memory_bytes: 6436
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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; }
const int INF = 1e9;
const LL LLINF = 1e16;

vector<LL> slide_max(vector<LL> &a, int k){
    deque<LL> deq;
    vector<LL> b;
    rep(i, a.size()){
        while(!deq.empty() && a[deq.back()] <= a[i]) deq.pop_back();
        deq.push_back(i);
        b.push_back(a[deq.front()]);
        if(i-k+1 >= 0 && deq.front() == i-k+1) deq.pop_front();
    }
    return b;
}

int main(){
    int n,m,k;
    cin >> n >> m >> k;
    vector<LL> a(n);
    rep(i, n) cin >> a[i];

    vector<LL> dp = a;
    REP(j, 2, k+1){
        vector<LL> mx = slide_max(dp, m);
        REP(i, j-1, n){
            dp[i] = j*a[i] + mx[i-1];
        }
        // repe(i, dp) cout << i << " "; cout << endl;
    }
    cout << *max_element(dp.begin()+k-1, dp.end()) << endl;


}

Measured memory_bytes: 3680
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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; }

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


#define FACSIZE 2002

ll invfac[FACSIZE];
ll fac[FACSIZE];

ll mod_pow(ll ,ll );
ll mod_add(ll ,ll );
ll mod_mul(ll ,ll );
ll mod_div(ll ,ll );
void make_fact(ll );
void make_invfact(ll );



int main(void){

  ll n;
  cin>>n;
  ll num=1LL<<n;
  vector<ll> s(num);
  rep(i,num) cin>>s[i];

  sort(begin(s),end(s),greater<ll>());

  //for(auto x:s) cout << x << " ";
  //cout << endl;

  map< ll,ll,greater<ll> > mRest;
  map< ll,ll,greater<ll> > mCur;
  map< ll,ll,greater<ll> > mAdd;
  mCur[s[0]]=1;
  for(ll i=1;i<num;i++) mRest[ s[i] ]++;

  for(ll i=0;i< n ; i++ ){
    mAdd.clear();
    for(auto p:mCur){
      for(int j=0;j<p.second;j++){
        auto itr = mRest.lower_bound(p.first);
        if(itr==end(mRest)){
          cout << "No" << endl;
          return 0;
        }
        if(itr->first == p.first) itr++;
        if(itr==end(mRest)){
          cout << "No" << endl;
          return 0;
        }
        ll key=itr->first;
        //cout << p.first  << "," << key << endl;
        mRest[key]--;
        if(mRest[key]==0) mRest.erase(key);
        mAdd[key]++;
      }
      
    }
    for(auto p:mAdd){
      mCur[p.first]+=p.second;
    }
    //cout << endl;

  }
  cout << "Yes" << endl;

  return 0;

}

ll mod_pow(ll x,ll r){
  if(r==0) return 1;
  else if(r==1) return x%mod;
  else if(r%2==0){
    ll t=mod_pow(x,r/2)%mod;
    return t*t %mod;
  } 
  else{
    ll t=mod_pow(x,r/2)%mod;
    ll k= t*t %mod;
    return k*x%mod;
  } 
}
ll mod_add(ll a,ll b){
  return (a+b)%mod;
}

ll mod_mul(ll a,ll b){
  return (a*b)%mod;
}

ll mod_div(ll a,ll b){
  return mod_mul(a,mod_pow(b,mod-2));
}

void make_fact(ll n){
  fac[0]=1;
  rep(i,n){
    fac[i+1]=mod_mul(fac[i],i+1);
  }  
}

void make_invfact(ll n){
  invfac[n]= mod_pow( fac[n] ,mod-2);
  for(int i=n-1;i>=0;i--){
    invfac[i]=mod_mul(invfac[i+1],i+1);
  }

}


Measured memory_bytes: 26880
from random import randrange

def score(c,s,t):
    ans = 0
    scorelast = [0] * 26
    for i in range(d,365):
        ans += s[i][t[i]]
        scorelast[t[i]] = i + 1
        for j in range(26):
            ans -= c[j] * (i + 1 - scorelast[j])
    return ans

def diffscore(old,q,c,s,t):
    cq = c[q]
    scorelast = [0] * 2
    diff = 0
    for i in range(365):
        if t[i] == q:
            diff += s[i][q]
            scorelast[0] = i + 1
        elif t[i] == old:
            diff += s[i][old]
            scorelast[1] = i + 1
        diff -= cq * (i + 1 - scorelast[0])
        if cq != old:
            diff -= c[old] * (i + 1 - scorelast[1])

    return diff
D = int(input())
c = list(map(int,input().split()))
s = []
for i in range(D): s.append(list(map(int,input().split())))
d = 0
t = []
last = [-1] * 26
for i in range(D):
    maximum = 0
    maxs = 0
    for j in range(26):
        if maximum < s[i][j] + c[j] * (i - last[j]):
            maxs = j
            maximum = s[i][j] + c[j] * (i - last[j])
    last[maxs] = i
    t.append(maxs)

for i in range(20000):
    d = randrange(D)
    q = randrange(26)
    old = t[d]
    before = diffscore(old,q,c,s,t)
    t[d] = q
    if before > diffscore(old,q,c,s,t): t[d] = old
for i in t: print(i + 1)


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

using namespace std;

const int MOD = 1000000007;

int main(void) {
    int i, j;
    int a[3][3];
    int n;
    int b;

    for(i = 0; i < 3; i++) {
        for(j = 0; j < 3; j++) {
            cin >> a[i][j];
        }
    }
    cin >> n;
    for(int k = 0; k < n; k++) {
        cin >> b;

        for(i = 0; i < 3; i++) {
            for(j = 0; j < 3; j++) {
                if(a[i][j] == b) {
                    a[i][j] = 0;
                    b = 0;
                    break;
                }
            }
            if(b == 0) {
                break;
            }
        }
    }

    bool f = true;
    for(i = 0; i < 3; i++) {
        f = true;
        for(j = 0; j < 3; j++) {
            if(a[i][j] != 0) {
                f = false;
                break;
            }
        }
        if(f) {
            cout << "Yes" << endl;
            return 0;
        }

        f = true;
        for(j = 0; j < 3; j++) {
            if(a[j][i] != 0) {
                f = false;
                break;
            }
        }
        if(f) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    f = true;
    for(i = 0; i < 3; i++) {
        if(a[i][i] != 0) {
            f = false;
            break;
        }
    }
    if(f) {
        cout << "Yes" << endl;
        return 0;
    }

    f = true;
    for(i = 0; i < 3; i++) {
        if(a[i][2 - i] != 0) {
            f = false;
            break;
        }
    }
    if(f) {
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
    return 0;
}


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

ll dp[100*1000+5];
vector<ll> tree[100*1000+5];
bool visited[100*1000+5];

ll N,M;

void dfs(ll u){
	visited[u] = true;
	dp[u] = 0;
	if (tree[u].size() == 0) return;
	for(ll v: tree[u]){
		if(!visited[v]){
			dfs(v);
		}
		dp[u] = max(dp[u], 1+dp[v]);
	}
}



void solve(){
	memset(visited, false, sizeof visited);
	for(ll u = 0;u<N;u++){
		if(!visited[u]){
			dfs(u);
		}
	}

}


int main(){
	cin>>N>>M;
	for(ll i = 0;i<=N;i++)dp[i] = 0;
	
	ll x,y;
	for(ll i = 0;i<M;i++){
		cin>>x>>y;
		tree[x-1].push_back(y-1);
	}
	solve();
	ll ans = 0;
	for(ll i = 0;i<N;i++) ans = max(ans, dp[i]);
	cout<<ans<<endl;
}



Measured memory_bytes: 8576
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <map>
#include <sstream>
#include <utility>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vecto) vecto.begin(), vecto.end()
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
using ll = long long;

int const MOD = 1e9 + 7;

template <class T>
T GCD(T a, T b)
{
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}

template <class T>
T LCM(T a, T b)
{
    return (a * b) / GCD(a, b);
}

template <class T>
T max_(std::vector<T> vec)
{
    std::sort(all(vec));
    return vec.at(vec.size() - 1);
}
template <class T>
T min_(std::vector<T> vec)
{
    std::sort(all(vec));
    return vec.at(0);
}

void ans(bool t_or_f)
{
    if (t_or_f == true)
        std::cout << "Yes" << std::endl;
    else
        std::cout << "No" << std::endl;
}

void Ans(bool t_or_f)
{
    if (t_or_f == true)
        std::cout << "YES" << std::endl;
    else
        std::cout << "NO" << std::endl;
}

using namespace std;

////////////////////////////////////////////////////////////////////

int main(){
    int n;
    cin >> n;
    vector<int> vec(n);
    rep(i,n){
        cin >> vec[i];
    }
    int cnt = 0;
    int i = 1;
    while (i != 2){
        cnt++;
        i = vec[i - 1];
        if (cnt >= n){
            break;
        }
    } 
    if (cnt < n){
        cout << cnt << endl;
    }
    else{
        cout << -1 << endl;
    }
}

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

typedef vector<int> vec;
typedef vector<vec> mat;

int N, MOD, a, b, c, t;

mat mul(mat &A, mat &B){
  mat C(A.size(), vec(B[0].size()));
  for(int i = 0; i < A.size(); i++){
    for(int k = 0; k < B.size(); k++){
      for(int j = 0; j < B[0].size(); j++){
        C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
      }
    }
  }
  return C;
}

mat pow(mat A, int n){
  mat B(A.size(), vec(A.size()));

  for(int i = 0; i < A.size(); i++){
    B[i][i] = 1;
  }
  while(n > 0){
    if(n & 1) B = mul(B, A);
    A = mul(A, A);
    n >>= 1;
  }
  return B;
}

int main(){
  while(cin >> N >> MOD >> a >> b >> c >> t, N){
    mat mt;

    for(int i = 0; i < N; i++){
      vec v(1);
      cin >> v[0];
      mt.push_back(v);
    }

    mat A(N, vec(N));

    for(int i = 0; i < N; i++){
      A[i][i] = b;
      if(i - 1 >= 0) A[i][i - 1] = a;
      if(i + 1 < N)  A[i][i + 1] = c;
    }

    A = pow(A, t);
    mt = mul(A, mt);

    for(int i = 0; i < mt.size(); i++){
      if(i != 0) cout << " ";
      cout << mt[i][0];
    }
    cout << endl;
  }
}

Measured memory_bytes: 1284
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<pii, lint> ppl;
typedef pair<lint, lint> pll;
typedef complex<double> xy_t;
typedef vector<lint> poly;

const lint INF = 1e18;

int main(){
    int n, m;
    lint L;
    scanf("%d%d%lld", &n, &m, &L);
    lint d[n][n];
    rep(i, n){
        rep(j, n) d[i][j] = INF;
        d[i][i] = 0;
    }
    rep(i, m){
        int a, b;
        lint c;
        scanf("%d%d%lld", &a, &b, &c);
        --a; --b;
        d[a][b] = d[b][a] = c;
    }
    rep(k, n)rep(i, n)rep(j, n)if(d[i][k] < INF && d[k][j] < INF){
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    }

    lint c[n][n];
    rep(i, n){
        rep(j, n) c[i][j] = d[i][j] <= L ? 1 : INF;
        c[i][i] = 0;
    }
    rep(k, n)rep(i, n)rep(j, n)if(c[i][k] < INF && c[k][j] < INF){
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
    }

    int q;
    scanf("%d", &q);
    while(q--){
        int u, v;
        scanf("%d%d", &u, &v);
        printf("%lld\n", c[u-1][v-1] < INF ? c[u-1][v-1]-1 : -1);
    }
}

Measured memory_bytes: 1920
import java.util.*;
import java.io.*;
 
public class Main{
    static PrintWriter out = new PrintWriter(System.out);
 
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int K = Integer.parseInt(sc.next());
        int i = 1;
        int A = N;
        while(A >= K){
            A = A/K;
            i++;
        }
        System.out.println(i);
       
    }
} 

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007
int main(){
	fast;
	ll x;
	cin>>x;
	if(x<=6)
	{
		cout<<1;
		return 0;
	}
	if(x<=11)
	{
		cout<<2;
		return 0;
	}
	ll ans=x/11;
	ans=2*ans;
	if(x%11<=6&&x%11>0)
		cout<<ans+1;
	else if(x%11>6)
		cout<<ans+2;
	else
		cout<<ans;
		
	return 0;
}



Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
double solve(double a)
{
    return (a + 1) / 2;
}

int main()
{
    int n, k;
    cin >> n >> k;
    vector<double> p(n);
    for (int i = 0; i < n; i++)
        cin >> p.at(i);
    double ans = 0;
    double tmp = 0;
    for (int j = 0; j < k; j++)
        tmp += solve(p[j]);
    ans = tmp;
    for (int i = 1; i <= n - k; i++)
    {
        tmp += solve(p[i + k-1]);
        tmp -= solve(p[i - 1]);
        if (tmp > ans)
            ans = tmp;
    }
    cout << fixed<<ans << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;
int main(){
    int a,b,C;
    double S,L,h,c,x;
    cin>>a>>b>>C;
    x=(acos(-1)/180)*C;
    S=a*b*sin(x)/2;
    c=sqrt(a*a+b*b-2*a*b*cos(x));
    L=a+b+c;
    h=b*sin(x);
    printf("%f %f %f\n",S,L,h);
    return 0;
    
}



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

fn main() {
    let h: usize = read();
    let w: usize = read();
    let k: usize = read();
    let s: Vec<Vec<char>> = (0..h).map(|_| read::<String>().chars().collect()).collect();

    let mut ans: Vec<Vec<usize>> = vec![vec![0; w]; h];

    let mut cnt = 1;
    let mut blank: Vec<usize> = vec![];
    for i in 0..h {
        let mut found = false;
        for j in 0..w {
            if s[i][j] == '#' {
                found = true;
                ans[i][j] = cnt;
                cnt += 1;
            } else if j > 0 && ans[i][j-1] > 0 {
                ans[i][j] = ans[i][j-1];
            }
        }
        if !found {
            blank.push(i);
        }
    }
    for i in 0..h {
        for j in (0..w).rev() {
            if ans[i][j] == 0 && j < w-1 && ans[i][j+1] > 0 {
                ans[i][j] = ans[i][j+1];
            }
        }
    }
    for i in 0..blank.len() {
        let i = blank[i];
        if i > 0 && ans[i-1][0] > 0 {
            for j in 0..w {
                ans[i][j] = ans[i-1][j];
            }
        }
    }
    for i in (0..blank.len()).rev() {
        let i = blank[i];
        if i < h-1 && ans[i+1][0] > 0 {
            for j in 0..w {
                ans[i][j] = ans[i+1][j];
            }
        }
    }

    for i in 0..h {
        for j in 0..w {
            if j > 0 {
                print!(" ");
            }
            print!("{}", ans[i][j]);
        }
        println!();
    }
}

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


Measured memory_bytes: 4860
#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=0,sum=0,x=0,y,z=0,m=1,n=0,ans=0,cnt=0;
	cin>>tc;
	db la=0;
	int arr[tc][2];
	for(int i=0;i<tc;i++)
			cin>>arr[i][0]>>arr[i][1];

	for(int i=0;i<tc-1;i++){
		for(int j=i+1;j<tc;j++){
			db p=(arr[i][0]-arr[j][0])*(arr[i][0]-arr[j][0]);
			db q=(arr[i][1]-arr[j][1])*(arr[i][1]-arr[j][1]);
			
			la+=sqrt(p+q);
			cnt++;
		}
	}
	printf("%.10f\n",la*(tc-1)/cnt );
}

Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using P = pair<lint, int>;

const lint INF = 1e18;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n, m, s, t; cin >> n >> m >> s >> t;
  s--; t--;
  struct edge { int to, y, s; };
  vector< vector<edge> > G(n, vector<edge>());
  for (int i = 0; i < m; i++) {
    int u, v, a, b; cin >> u >> v >> a >> b;
    u--; v--;
    G[u].push_back(edge{v, a, b});
    G[v].push_back(edge{u, a, b});
  }
  
  vector<lint> dy(n, INF), ds(n, INF);
  queue<P> pq;
  dy[s] = 0;
  pq.push(P(0, s));
  while (not pq.empty()) {
    P p = pq.front(); pq.pop();
    int v = p.second;
    if (dy[v] < p.first) continue;
    for (auto&& e : G[v]) {
      if (dy[v] + e.y < dy[e.to]) {
        dy[e.to] = dy[v] + e.y;
        pq.push(P(dy[e.to], e.to));
      }
    }
  }

  ds[t] = 0;
  pq.push(P(0, t));
  while (not pq.empty()) {
    P p = pq.front(); pq.pop();
    int v = p.second;
    if (ds[v] < p.first) continue;
    for (auto&& e : G[v]) {
      if (ds[v] + e.s < ds[e.to]) {
        ds[e.to] = ds[v] + e.s;
        pq.push(P(ds[e.to], e.to));
      }
    }
  }

  vector<lint> res(n);
  const lint N = 1e15;
  for (int i = 0; i < n; i++) {
    res[i] = N - dy[i] - ds[i];
  }
  for (int i = n - 2; i >= 0; i--) {
    res[i] = max(res[i], res[i + 1]);
  }
  for (int i = 0; i < n; i++) {
    cout << res[i] << '\n';
  }
  return 0;
}


Measured memory_bytes: 11008
#include <cstdio>
#include <cmath>
#include <iostream>
using namespace std;
typedef double d;

d heron(d a,d b,d c){
  d s = (a+b+c)/2;
  return sqrt(s*(s - a)*(s - b)*(s - c));
}
int main(){
  d x1,y1,x2,y2,x3,y3;
  char c;
  d sum = 0.0;
  cin >> x1 >>c>> y1>> x2 >> c >> y2;
  while( cin >> x3 >> c >> y3){
    double a = sqrt(pow(x1 - x2,2) + pow(y1 - y2,2));
    double b = sqrt(pow(x1 - x3,2) + pow(y1 - y3,2));
    double c = sqrt(pow(x2 - x3,2) + pow(y2 - y3,2));
    sum +=  heron(a,b,c);
    x2 = x3,y2 = y3;
  }
  printf("%.6f\n",sum);
}

Measured memory_bytes: 1240
S = input()
easy_in_odd = ["R", "U", "D"]
easy_in_even = ["L", "U", "D"]
is_easy = True
count = 1
for move in list(S):
    if count % 2 == 1 and move not in easy_in_odd:
        is_easy = False
        break
    elif count % 2 == 0 and move not in easy_in_even:
        is_easy = False
        break
    count += 1

if is_easy:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<iostream>

using namespace std;
const int MAX_N=1e5+5;

long long pow(long long x,long long n){
  long long re=1;
  while(n>0){
    if(n&1)re*=x;
    x=x*x;
    n>>=1;
  }
  return re;
}

long long dp[MAX_N][2][2];
long long K[50];
long long sum[50];
int main(){
  long long n,k;
  cin>>n>>k;
  int tmp=0;
  long long t_k=k;
  while(t_k>0){
    K[tmp++]=t_k&1;
    t_k>>=1;
  }
  for(int i=0;i<n;i++){
    long long a;
    cin>>a;
    tmp=0;
    while(a>0){
      sum[tmp++]+=a&1;
      a>>=1;
    }
  }
  for(int i=49;i>=1;i--){
    if(K[i-1]==1)dp[i-1][1][1]=max(dp[i][1][1],dp[i][0][1])+(n-sum[i-1])*pow(2,i-1);
    else dp[i-1][1][1]=0;
    if(dp[i][1][0]>0 || dp[i][0][0]>0)dp[i-1][1][0]=max(dp[i][1][0],dp[i][0][0])+(n-sum[i-1])*pow(2,i-1);
    if(K[i-1]==0)dp[i-1][0][1]=max(dp[i][1][1],dp[i][0][1])+sum[i-1]*pow(2,i-1);
    else dp[i-1][0][1]=0;
    if(K[i-1]==1)dp[i-1][0][0]=max(dp[i][1][1],max(dp[i][0][1],max(dp[i][1][0],dp[i][0][0])))+sum[i-1]*pow(2,i-1);
    else if(dp[i][1][0]>0 || dp[i][0][0]>0)dp[i-1][0][0]=max(dp[i][1][0],dp[i][0][0])+sum[i-1]*pow(2,i-1);
  }
  cout<<max(dp[0][1][1],max(dp[0][1][0],max(dp[0][0][1],dp[0][0][0])))<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stdio.h>
#include<deque>
#include<map>
#include<queue>
#include<cmath>

typedef long long ll;

#define debug(x) cout << #x << "=" << x << endl;
#define debug_arr(a, n) for(ll i = 0; i < n; i++)cout << a[i] << " "
#define inf 100000000000
#define loop(i,n) for(ll i = 0; i < n; i++)
#define graph vector<vector<ll>>
#define P pair<ll,ll>

using namespace std;

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

ll dividLimit(ll n,ll a){
    while(n % a == 0){
        n /= a;
    }
    return n;
}

int main(){
    ll a,b,gcdNum,result = 0,current = 2;
    cin >>a >>b;

    gcdNum = gcd(a,b);

    result ++;
    while(1){
        if(gcdNum % current == 0){
            gcdNum = dividLimit(gcdNum, current);
            result ++;
        }
        if(gcdNum < current * current){
            if(gcdNum != 1)result ++;
            break;
        }
        current ++;
    }
    
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools


#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]

N = int(input())
A = [int(i) for i in input().split()]
Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]
Num = [0]*(10**5)
ans = 0

for i in range(len(A)):
  #print(A[i])
  Num[A[i]-1] += 1
  ans += A[i]

for i in range(Q):
  ans -= BC[i][0]*Num[BC[i][0]-1]
  temp = Num[BC[i][0]-1]
  Num[BC[i][0]-1] = 0
  ans += temp*BC[i][1]
  Num[BC[i][1]-1] += temp
  print(ans)


Measured memory_bytes: 99336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll a,b,c;
    cin >> a >> b >> c;
    ll ans=0;
    if(b+a>=c){
        ans=b+c;
    }
    else {
        ans=b*2+a+1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604
#include<stdio.h>
int main()
{
    int a,y=0;
    scanf("%d",&a);
    if(a<=999 && a>=100)
    for(int i=0;i<3;i++)
    {
        int n;
        n=a%10;
        if(n==7)
            y=1;
        a=a/10;
    }
    if(y)
        printf("Yes");
    else
        printf("No");
}


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

int main() {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
    string s;
    cin>>s;
    int n = s.size();
    for(int i = 0;i < n;i++) {
        if((i+1)%2 != 0) {
            if(s[i] == 'R' || s[i] == 'U' || s[i] == 'D') continue;
            else {cout<<"No\n";
            return 0;}
        }
        else {
            if(s[i] == 'L' || s[i] == 'U' || s[i] == 'D') continue;
            else {cout<<"No\n";
            return 0;}
        }
    }
    cout<<"Yes\n";
}

Measured memory_bytes: 256
import itertools


n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

l = list(itertools.permutations(p))

l.sort()

p_i = 0
q_i = 0

for i in range(len(l)):
    if list(l[i]) == p:
        p_i = i
    if list(l[i]) == q:
        q_i = i

print(abs(p_i - q_i))




Measured memory_bytes: 8052
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
void dump(int* ptr,int length){
	for(int i=0;i<length;i++){
		cout << *(ptr+i);
		if(i+1<length)cout << ' ';
		else cout << endl;
	}
}
int N;
int a[55],b[55];
struct edge{
	int to,mod;
	edge(){}
	edge(int to,int mod):to(to),mod(mod){}
};
vector<edge> g[55];
bool s[55];
bool w[55];
bool used[55];
void dfs(int v){
	// cout << v << ' ';
	used[v] = true;
	for(int i=0;i<g[v].size();i++){
		edge e = g[v][i];
		if(s[e.mod]&&!used[e.to])dfs(e.to);
	}
}
bool check(){
	for(int i=0;i<N;i++){
		memset(used,false,sizeof(used));
		dfs(a[i]);
		// cout << endl;
		// cout << b[i] << ' ' << used[b[i]] << endl;
		if(!used[b[i]])return false;
	}
	return true;
}

int main(){
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> a[i];
	}
	for(int i=0;i<N;i++){
		cin >> b[i];
	}
	for(int i=1;i<=50;i++){
		for(int j=i;j<=50;j++){
			// cout << j << " mod: " << i << " to: " << j%i << endl;
			g[j].pb(edge(j%i,i));
		}
	}
	for(int i=50;i>0;i--){
		for(int j=50;j>0;j--){
			s[j] = w[j];
		}
		// for(int j=1;j<=50;j++){
		// 	cout << w[j] << ' ';
		// }
		// cout << endl;
		for(int j=1;j<i;j++)s[j] = true;
		if(!check())w[i]=true;
	}
	for(int i=1;i<=50;i++){
		s[i] = w[i];
	}
	if(!check()){
		cout << -1 << endl;
	}else{
		ll ans = 0ll;
		for(int i=1;i<=50;i++){
			if(w[i])ans += (1ll<<i);
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n, d;
	cin >> n >> d;
	vector< vector<int> > v(n, vector<int>(d));
	for(int i = 0; i < n; i++){
		for(int j = 0; j < d; j++){
			cin >> v[i][j];
		}
	}
	int ans = 0;
	for(int i = 0; i < n; i++){
		for(int j = i+1; j < n; j++){
			int norm = 0;
			for(int k = 0; k < d; k++){
				norm += (v[i][k] - v[j][k])*( v[i][k] - v[j][k]);			
			}
			bool flag = false;
			for(int k1 = 0; k1 <= norm; k1++){
				if(k1*k1 == norm)flag = true;
			}
			if(flag) ans += 1;
		}
	}

	cout << ans << endl;
	
}

Measured memory_bytes: 256
from itertools import chain, combinations


def powerset(iterable):
    s = list(iterable)
    return chain.from_iterable(combinations(s, r) for r in range(len(s) + 1))


def s_to_num(s):
    numlst = list(map(int, s))
    res = 0
    for i in numlst:
        res *= 10
        res += i
    return res


s = input()
length = len(s)
res = 0
for i in powerset(range(1, length)):
    if not i:
        res += int(s)
    else:
        jlst = [0] + list(i) + [length]
        for j in range(len(jlst) - 1):
            res += s_to_num(s[jlst[j]:jlst[j + 1]])
print(res)


Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

const ll INF = 10010010010010;

int main() {
	ll N, K;
	cin >> N >> K;

	vector <ll> A(N);
	for (int ii = 0; ii < N; ++ii){
		cin >> A[ii];
	}
	sort(A.begin(), A.end());

	vector <ll> F(N);
	for (int ii = 0; ii < N; ++ii){
		cin >> F[ii];
	}
	sort(F.rbegin(), F.rend());

	//二分探索
	ll l = -1;
	ll r = INF;
	while(l+1 < r) {
		ll mid = (l + r) / 2;
		ll sum = 0;
		for (int ii = 0; ii < N; ++ii){
			sum += max(0LL, A[ii] - mid / F[ii]);
		}
		if (sum <= K){
			r = mid;
		} else {
			l = mid;
		}
	}

	cout << r << "\n";

	return 0;
}


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


void solve(long long N, long long X, long long T){
    cout << (N + X - 1) / X * T << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long X;
    scanf("%lld",&X);
    long long T;
    scanf("%lld",&T);
    solve(N, X, T);
    return 0;
}


Measured memory_bytes: 3656
N = int(input())
ans = N
for i in range(N+1):
    count = 0
    ret = i
    while ret > 0 :
        count += ret % 6
        ret //= 6
    ret = N - i
    while ret > 0 :
        count += ret % 9
        ret //= 9
    ans = min(ans, count)
print(ans)


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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<v_char > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<v_double > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
using namespace std; 

int main(void)
{
    int n, m;
    cin >> n >> m;

    cout << n*(n-1)/2 + m*(m-1)/2;
    return 0;
}
/** tcoder **/


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int s = sc.nextInt();
        ArrayList<Integer> data = new ArrayList<Integer>();
        data.add(s);
        boolean judge = false;
        
        int i=1;
        while(judge == false){
            if(data.get(i-1)%2 == 0){
                int tmp1 = data.get(i-1)/2;
                if(data.contains(tmp1)){
                    System.out.println(i+1);
                    judge = true;
                }
                data.add(tmp1);
            }else{
                int tmp2 = 3*data.get(i-1)+1;
                if(data.contains(tmp2)){
                    System.out.println(i+1);
                    judge = true;
                }
                data.add(tmp2);
            }
            
            i++;
            
        }
    }
}


Measured memory_bytes: 35716
import java.util.Scanner;

public class Main {

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

        int X = scanner.nextInt();

        if (X == 3 || X == 5 || X == 7) {
            System.out.println("YES");
            return;
        }

        System.out.println("NO");

    }

}


Measured memory_bytes: 22228
N=int(input())
S = [input() for i in range(N)]

a=S.count('AC')
b=S.count('WA')
c=S.count('TLE')
d=S.count('RE')

print("AC x ",a)
print("WA x ",b)
print("TLE x ",c)
print("RE x ",d)


Measured memory_bytes: 16192
X,N = list(map(int, input().split()))
p= list(map(int, input().split()))

i=[0]*201
for n in range(201):
    i[n]=n-99

ans=list(set(i) ^ set(p))
ans.sort()
dif=100
count=0
for j in range(201-N):
    dif_now=abs(X-ans[j])
    if dif>dif_now:
        dif=dif_now
        count=ans[j]
print(count)

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

typedef long long int ll;
//Factors of an num
/*
vector<ll> fact(ll n){
	vector<ll>v;
	for(int i=1;i*i<=n;i++){
		if(n%i ==0){
			v.push_back(i);
		
		if(i!=n/i)
			v.push_back(n/i);
	    }
	}

	return v;
}
*/


/*
Seive Of Eratos..
int N=1e5;
vector<bool> isprime(N+1,true);
void pri(int n){
	for(int i=2;i*i<=n;i++){
		if(isprime[i]){
			for(int j=i*i;j<=n;j+=i){
				isprime[j]=false;
			}
		}
	}
	return;
}
*/

/*
//Prime Factors
vector<bool> isprime(1e6+1,true);
 vector<int> primes;
 void sieve()
 {

    ll  i,j;
    isprime[0] = false;
    isprime[1] = false;

    for(i=2; i<=1e6 ;i++)
  {

    if(isprime[i])
    {

      primes.push_back(i);

      for(j=i*i; j<=1e6; j+=i)
      {
        isprime[j]=false;
      }

    }

  }
}

vector<int> primefactors(int  N)

 {

    vector<int> factors;
    ll pf_idx = 0, pf=primes[pf_idx];

    while(pf*pf<=N)
    {
        while(N % pf == 0)
        {
            N/=pf;
            factors.push_back(pf);
        }
        pf = primes[++pf_idx];
    }
    
    if(N != 1) factors.push_back(N);
    return factors;
}
 */   




int main(){
	 
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t;
    cin>>s;
    cin>>t;
    int c=s.length()-t.length();
    int mx=INT_MAX;
    for(int i=0;i<c+1;i++){
        int cnt=0;
        for(int j=0;j<t.length();j++){
            if(s[i+j]!=t[j]){
                cnt++;
            }
        }
        mx=min(mx,cnt);
    }
    cout<<mx;
    return 0;
}


Measured memory_bytes: 3656