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

using namespace std;
#define reg register
#define rep(i, a, b) for (reg int i = (int) a; i <= (int) b; i++)
#define rev(i, a, b) for (reg int i = (int) a; i >= (int) b; i--)
#define _r read()

inline int read();

int main() {
	int n = _r, k = _r;
	if (k * 2 - 1 > n) cout << "NO" << endl;
	else cout << "YES" << endl;
	return 0;
}

inline int read() {
	reg int a = 0, c = getchar(), s = c == '-';
	while (!isdigit(c)) c = getchar();
	while (isdigit(c)) a = (a << 1) + (a << 3) + (c ^ 48), c = getchar();
	return s ? -a : a;
}


Measured memory_bytes: 256
def resolve():
    S = input()
    T = input()
    smap = {}
    tmap = {}
    for i in range(len(S)):
        if S[i] in smap: 
            if smap[S[i]] != T[i]:
                print("No")
                return
        else:
            smap[S[i]] = T[i]
        
        if T[i] in tmap: 
            if tmap[T[i]] != S[i]:
                print("No")
                return
        else:
            tmap[T[i]] = S[i]

    print("Yes")
    return


if '__main__' == __name__:
    resolve()

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


using namespace std;

int main(){
    int k,n;
    cin >> k >> n;
    int a[n];
    rep(i,n) cin >> a[i];
    int mx = 0;
    rep(i,n-1){
        mx = max(mx,a[i+1]-a[i]);
    }
    mx = max(mx,a[0]+k-a[n-1]);
    cout << k-mx << endl;

    return 0;    
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define maxn 100086

using namespace std;

int n, m;
int x, y;
vector<pair<int, int> > v[maxn];
int col[maxn];
long long ans;
int sum;
int cnt[3];
bool tag;


void dfs(int i){
	cnt[col[i]]++, sum += v[i].size();
	for(int j = 0;j < v[i].size();j++){
		int to = v[i][j].first, val = v[i][j].second;
		if(col[to] == -1) col[to] = (col[i] + val + 3) % 3, dfs(to);
		else if((col[i] + val + 3) % 3 != col[to]) tag = true;
	}
}

int main(){
	scanf("%d%d", &n, &m);
	while(m--){
		scanf("%d%d", &x, &y);
		v[x].push_back({y, 1}), v[y].push_back({x, -1});
	}
	memset(col, -1, sizeof(col));
	for(int i = 1;i <= n;i++){
		if(col[i] ^ -1) continue;
		memset(cnt, 0, sizeof(cnt)), tag = false, sum = 0;
		col[i] = 0, dfs(i);
		if(tag) ans += 1ll * (cnt[0] + cnt[1] + cnt[2]) * (cnt[0] + cnt[1] + cnt[2]);
		else if(!cnt[0] || !cnt[1] || !cnt[2]) ans += sum >> 1;
		else ans += 1ll * cnt[0] * cnt[1] + 1ll * cnt[1] * cnt[2] + 1ll * cnt[2] * cnt[0];
	}
	printf("%lld", ans);
}

Measured memory_bytes: 14316
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

using ll = long long int;

int main(void) {
  int n, x;
  cin >> n >> x;
  vector<int> v(n);
  int d = 0;
  int prev = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    d = prev + v[i];
    prev = d;
    if (d > x) {
      std::cout << i + 1 << std::endl;
      return 0;
    }
  }
  if(d > x)
    std::cout << n << std::endl;
  else
    std::cout << n+1 << std::endl;


  return 0;
}


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

int main(void){
    // Your code here!
    char S[200001];
    char ref[] = "ABC";
    char tok[] = "BCA";
    char BC[] = "BC";
    int endflag = 0, N = 0, Acount = 1, BCcount = 0;
    long count = 0;
    
    scanf("%s",S);
    N = strlen(S);
    
    while(endflag == 0)
    {
        endflag = 1;
        for(int i = 0; i < N-2; i++)
        {
            if(strncmp(ref, &S[i], 3) == 0)
            {
                endflag = 0;
                while(S[i-Acount] == 'A')
                {
                    Acount++;
                }
                while(strncmp(BC, &S[i+3+BCcount*2], 2) == 0)
                {
                    BCcount++;
                }
                
                for(int j = 0; j <= BCcount; j++)
                {
                    strncpy(&S[i-(Acount-1)+2*j], BC, 2);
                }
                for(int j = i - (Acount-1) + 2 + 2*BCcount; j <= i+3+BCcount*2-1; j++)
                    S[j] = 'A';
                
                count += (long)Acount * (BCcount+1);
                    
                Acount = 1;
                BCcount = 0;
                
            }
            //printf("%s\n",S);
            //printf("%ld\n",count);
        }
    }
    printf("%ld\n",count);
}


Measured memory_bytes: 384
import itertools
n = int(input())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
pp = int("".join(map(str, p)))
qq = int("".join(map(str, q)))
ppp = 0
qqq = 0

for i in itertools.permutations(p,n):
  j = int("".join(map(str, i)))
  if pp > j:
    ppp += 1
for i in itertools.permutations(q,n):
  j = int("".join(map(str, i)))
  if qq > j:
    qqq += 1
    
print(abs(ppp-qqq))

Measured memory_bytes: 68592
import java.io.*; 
import java.util.*; 

public class Main{ 
	
	static class FastReader{ 
		BufferedReader br; 
		StringTokenizer st; 

		public FastReader() 
		{ 
			br = new BufferedReader(new
					InputStreamReader(System.in)); 
		} 

		String next() 
		{ 
			while (st == null || !st.hasMoreElements()) 
			{ 
				try
				{ 
					st = new StringTokenizer(br.readLine()); 
				} 
				catch (IOException e) 
				{ 
					e.printStackTrace(); 
				} 
			} 
			return st.nextToken(); 
		} 

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

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

		double nextDouble() 
		{ 
			return Double.parseDouble(next()); 
		} 

		String nextLine() 
		{ 
			String str = ""; 
			try
			{ 
				str = br.readLine(); 
			} 
			catch (IOException e) 
			{ 
				e.printStackTrace(); 
			} 
			return str; 
		} 
	}

	public static void main(String[] args) 
	{ 
        FastReader sc = new FastReader(); 
        //PrintWriter out = new PrintWriter(System.out); 

        int n = sc.nextInt();
        long w = sc.nextLong();
        int maxv = 0;
        long[][] arr = new long[n+1][2];
        
        for(int i=1;i<=n;i++){
        	for(int j=0;j<2;j++){
        		arr[i][j] = sc.nextLong();
        		if(j!=0)
        			maxv += (int)arr[i][j];	
        	}
        }

        long[][] dp = new long[n+1][maxv+1];
        for(int i=0;i<=n;i++)
        	for(int v=0;v<=maxv;v++){
        		if(v!=0)
        			dp[i][v] = 1000000000000025L;
        		else
        			dp[i][v] = 0L;
        	}

        for(int i=1;i<=n;i++){
        	for(int v=0;v<=maxv;v++){
            	if(arr[i][1]<=v)
            		dp[i][v] = Math.min( dp[i-1][v], dp[i-1][v-(int)arr[i][1]] + arr[i][0] );
            	else
            		dp[i][v] = dp[i-1][v];
            	
        	}
        }

        long ans = 0L;
        for(int v=maxv;v>=0;v--)
        	if(dp[n][v]<=w){
        		ans = Math.max(ans, v);
        }

        System.out.println(ans);
        //out.close();
	}
}


Measured memory_bytes: 127444
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int A, B;
    cin >> A >> B;
    int ans = -1;
    rep(i, 10000){
        int a = i*8/100, b = i*10/100;
        if(a == A && b == B){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}

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

const int N = 1e5 + 5;

string s1, s2;
int n, m;
string s;

int main() {
    ios::sync_with_stdio(false);
    cin >> s1 >> s2;
    cin >> n >> m;
    cin >> s;
    if (s == s1) {
        cout << n - 1 << " " << m << endl;
    } else if (s == s2){
        cout << n << " " << m - 1<< endl;
    }
    return 0;
}

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

int main() {
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  vector<int> x(N);
  vector<int> y(M);

  for(int i=0;i<N;i++) {
    cin >> x[i];
  }

  for(int i=0;i<M;i++) {
    cin >> y[i];
  }

  if(X >= Y) {
    cout << "War" << endl;
  } else {

    int max = *max_element(x.begin(), x.end());
    int min = *min_element(y.begin(), y.end());

    bool war = true;
    for(int i=max+1;i<=min;i++) {
      if(i > X && i <= Y) {
        war = false;
        break;
      }
    }

    if(war) {
      cout << "War" << endl;
    } else {
      cout << "No War" << endl;
    }

    return 0;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<ll, ll>
#define nyan "(=^･ω･^=)"
#define read_input         freopen("in.txt","r", stdin)
#define print_output       freopen("out.txt","w", stdout)
typedef long long ll;
typedef long double ld;
using namespace std;

int n, m;
int g[1005][1005];
int dp[1005][1005][2];

int answer(int i, int j, int now) {
	if(i > n || j > m) return 1e9+7;
	if(i == n && j == m) return 0;
	if(dp[i][j][now] != -1) return dp[i][j][now];

	int ans = 1e9+7;
	if(now == 0) {
		if(g[i+1][j] == 0) ans = min(ans, answer(i+1, j, now));
		else ans = min(ans, answer(i+1, j, now ^ 1) + 1);

		if(g[i][j+1] == 0) ans = min(ans, answer(i, j+1, now));
		else ans = min(ans, answer(i, j+1, now ^ 1) + 1);
	}

	else {
		if(g[i+1][j] == 1) ans = min(ans, answer(i+1, j, now));
		else ans = min(ans, answer(i+1, j, now ^ 1));

		if(g[i][j+1] == 1) ans = min(ans, answer(i, j+1, now));
		else ans = min(ans, answer(i, j+1, now ^ 1));
	}

	return dp[i][j][now] = ans;
}

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

    for(int i = 1; i <= n; i++) {
    	for(int j = 1; j <= m; j++) {
    		char ch; cin >> ch;
    		g[i][j] = (ch == '#');
    	} getchar();
    }

    memset(dp, -1, sizeof dp);

    int ans = 1e9+7;
    if(g[1][1] == 0) ans = answer(1, 1, 0);
    else ans = answer(1, 1, 1) + 1;

    cout << ans << endl;

    return 0;  
}

Measured memory_bytes: 10496
n, m = map(int, input().split())
p = list(map(int, input().split()))
graph = [[] for i in range(n+1)]
for i in range(m):
    x, y = map(int, input().split())
    graph[x].append(y)
    graph[y].append(x)
group = [0] * (n + 1)
ans = 0

for i, num in enumerate(p, 1):
    space = [i]
    for point in space:
        if not group[point]:
            group[point] = i
            space.extend(graph[point])
    ans += (group[num] == group[i])
print(ans)

Measured memory_bytes: 28260
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int N;
    cin >>N;
    int d[N];

    for (int i = 0; i < N; ++i) {
        cin>>d[i];
    }
    sort(d, d+N);
    cout<<d[N/2]-d[(N/2-1)]<<endl;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
void trace(int *a,int n)
{
    for(int i=0;i<n;++i)
    {
        cout<<a[i];
        if(i!=n-1)
        {
            cout<<" ";
        }
    }
    cout<<endl;
}
void Insertion(int *a,int n)
{
    int i,j,tmp;
    for(int i=0;i<n;++i)
    {
        tmp=a[i];
        j=i-1;
        while(j>=0&&a[j]>tmp)
        {
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=tmp;
        trace(a,n);
    }
}
int main()
{
    int n;
    cin>>n;
    int a[105];
    for(int i=0;i<n;++i)
    {
        cin>>a[i];
    }
    Insertion(a,n);
    return 0;
}


Measured memory_bytes: 3116
using System;
using static System.Console;
using static System.Math;

public class Hello{
    public static void Main(){
        string[] input = ReadLine().Split(' ');
        int kazu = int.Parse(input[0]);
        string[] suji = ReadLine().Split(' ');
//        int max = int.Parse(input[1]);
        int[] suuji = new int[kazu];
        for(int i=0;i<kazu;i++){
            suuji[i] = int.Parse(suji[i]);
        }
        for(int i=0;i<kazu*2;i++){
            for(int j=0;j<kazu-1;j++){
                if(suuji[j] < suuji[j+1]){
                    int temp = suuji[j];
                    suuji[j] = suuji[j+1];
                    suuji[j+1] = temp;
                }
            }
        }
        
        int a=int.Parse(input[1]);
        int ans = 0;
        for(int i=0;i<a;i++){
            ans+= suuji[i];
        }
        WriteLine(ans);
    }
}

Measured memory_bytes: 11092
#include "bits/stdc++.h"
using namespace std;


string st;
int a;
int getnum() {
	int num=0;
	while (a != st.size()&&isdigit(st[a])) {
		num*=10;
		num+=st[a]-'0';
		a++;
	}
	return num;
}
vector<int>kou() {
	vector<int>v(10);
	if (st[a] == 'x') {
		a++;
		if (a == st.size() || st[a] != '^') {
			v[1]=1;
		}
		else {

			assert(st[a] == '^');
			a++;
			int n(getnum());
			v[n] = 1;
		}
	}
	else {
		int kei(getnum());
		if (a == st.size() || st[a] == '+' || st[a] == '-') {
			v[0]=kei;
			
		}
		else {
			assert(st[a]=='x');
			a++;
			if (a == st.size() || st[a] == '+' || st[a] == '-') {
				v[1]=kei;
			}
			else {
				assert(st[a]=='^');
				a++;
				int num(getnum());
				v[num]=kei;
			}
		}
	}
	return v;
}
vector<int>takou() {
	vector<int>v(kou());
	while(a != st.size()) {
		bool plus=true;
		plus=st[a]=='+';
		a++;
		vector<int>w(kou());
		if (plus) {
			for (int i = 0; i < 10; ++i) {
				v[i]+=w[i];
			}
		}
		else {
			for (int i = 0; i < 10; ++i) {
				v[i]-=w[i];
			}
		}
	}
	return v;
		
}
long long int pow_int(long long int a, int b) {
	if(b==0)return 1;
	else {
		return a*pow_int(a,b-1);
	}
}
int main() {
	cin>>st;
	a=0;
	auto v(takou());
	vector<long long int>anss;
	for (long long int i = -4000; i <= 4000; ++i) {
		long long int sum=0;
		for (int j = 0; j <= 5; ++j) {
			sum+=pow_int(i,j)*v[j];
		}
		if (sum == 0) {
			anss.push_back(i);
		}
	}
	reverse(anss.begin(),anss.end());

	for (auto ans : anss) {
		cout<<"(x";
		if (ans > 0) {
			cout<<"-"<<ans;
		}
		else {
			cout<<"+"<<-ans;
		}
		cout<<")";
	}
	cout<<endl;

	return 0;
}

Measured memory_bytes: 3216
import collections

n,m,k = map(int,raw_input().split(' '))


parent = range(0, n+1)
sizes = [1] * (n + 1)
hd = [1] * (n + 1) 

def f(parent, u):
	if parent[u] != u:  parent[u] = f(parent, parent[u])
	return parent[u]

for a,b in [map(int, raw_input().split(' ')) for _ in range(m)]:

	pa,pb = f(parent, a), f(parent, b)
	hd[a] +=1
	hd[b] +=1

	if pa != pb:
		if sizes[pa] >= sizes[pb]:
			parent[pb] = pa
			sizes[pa] += sizes[pb]
		else:
			parent[pa] = pb
			sizes[pb] += sizes[pa]

for c,d in [map(int, raw_input().split(' ')) for _ in range(k)]:
	pc,pd = f(parent, c), f(parent, d)
	if (pc == pd):
		hd[c] += 1
		hd[d] += 1

print ' '.join([str(sizes[f(parent,u)] - hd[u])  for u in range(1, n+1)])

Measured memory_bytes: 58780
#pragma region Header
#ifdef DEBUG
#include "debug.hpp"
#else
#define NDEBUG
#define debug(...)
#define IFD(...)
#endif
#include <utility>
#include <cstdint>
#include <cmath>
#include <cassert>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <functional>
#include <algorithm>
#include <numeric>
#include <stdexcept>
#include <sstream>
#include <iostream>
#include <iomanip>
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define repd(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = static_cast<int>(a); i <= static_cast<int>(b); ++i)
#define FORD(i, b, a) for (int i = static_cast<int>(b); i >= static_cast<int>(a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
template <class T>
bool chmax(T &a, T const &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, T const &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

void dfs(vector<int> &ts, vector<int> &tsinv, vector<vector<int>> const &adjs, int &i, int s)
{
    if (tsinv[s] >= 0)
    {
        return;
    }

    for (auto t : adjs[s])
    {
        dfs(ts, tsinv, adjs, i, t);
    }

    ts[i] = s;
    tsinv[s] = i;
    ++i;
    return;
}

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

    int n, m;
    cin >> n >> m;
    vector adjs(n, vector<int>());
    rep(i, m)
    {
        int s, t;
        cin >> s >> t;
        --s;
        --t;
        adjs[s].push_back(t);
    }

    vector<int> ts(n, -1), tsinv(n, -1);
    {
        int i = 0;
        rep(s, n)
        {
            dfs(ts, tsinv, adjs, i, s);
        }
    }

    debug(ts);
    debug(tsinv);

    vector dp(n, 0);
    int ans = -1;
    rep(i, n)
    {
        int s = ts[i];
        for (auto t : adjs[s])
        {
            int j = tsinv[t];
            chmax(dp[i], dp[j] + 1);
        }

        chmax(ans, dp[i]);
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 13040
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int a = sc.nextInt();

		// 計算
		long result = a + a*a + a*a*a;

		// 出力
		System.out.println(result);
	}

	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}



Measured memory_bytes: 25296
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
 
using namespace std;
typedef long long int lli;
const int MAX=1e5;
 
int main(){
	string s;
	cin>>s;
	int l=(int)s.length();
	int ans=l;
	for(char c='a';c<='z';c++){
		int m=0;
		rep(i,l)if(s[i]==c)m++;
		int d[102];
		rep(i,m+2)d[i]=0;
		d[0]=-1;
		d[m+1]=l;
		int x=0;
		rep(i,l)if(s[i]==c){
			x++;
			d[x]=i;
		}
		int pat=-1;
		rep(i,m+1)pat=max(pat,d[i+1]-d[i]-1);
		ans=min(ans,pat);
	}
	cout<<ans<<endl;
}

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

int main(){
	string s;
	int ans1=0,ans2=0;
	cin>>s;
	for(int i=0;i<s.size();i++)
		if(i%2==s[i]-'0')ans1++;
	ans2=s.size()-ans1;
	cout<<min(ans1,ans2)<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
using namespace std;
string s;
int ans[100000],n;
int main(){
    cin>>s;
    n=s.size();
    int x;
    for(int i=0;i<n;i++){
        if(s[i]=='R')x=i;
        else ans[x+(i-x)%2]++;
    }for(int i=n-1;i>=0;i--){
        if(s[i]=='L')x=i;
        else ans[x-(x-i)%2]++;
    }
    for(int i=0;i<n;i++){
        if(i)cout<<" ";
        cout<<ans[i];
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

int main(){
    int A,B,C;
    cin >> A >> B >> C;

    if(A <= C && C <= B)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;        
    }
}



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

int main() {
  int n,m,x;cin>>n>>m>>x;
  vector<int>a(m);
  rep(i,m)cin>>a[i];
  int l=0,r=0;
  rep(i,m){
    if(a[i]<x)l++;
    else r++;
  }
  cout<<min(l,r)<<endl;
}

Measured memory_bytes: 3620
N = int(input())
import math
import itertools

A = [list(map(int, input().split())) for _ in range(N)]

A = list(itertools.permutations(A))

sum = 0

for i in A:
    for j in range(N):
        if j+1==N:
            break
        sum = sum + (((i[j][0]-i[j+1][0])**2+(i[j][1]-i[j+1][1])**2)**0.5).real

print((sum/math.factorial(N)).real)


Measured memory_bytes: 10100
from collections import defaultdict
class UnionFind(object):
  def __init__(self,n=1):
    self.par = [i for i in range(n)]
    self.rank = [0 for _ in range(n)]
    self.size = [1 for _ in range(n)]


  def find(self,x):
    if self.par[x] == x:
      return x
    else:
      self.par[x] =  self.find(self.par[x])
      return self.par[x]

  def union(self,x,y):
    x = self.find(x)
    y = self.find(y)
    if x != y :
      if self.rank[x] <self.rank[y]:
        x,y = y,x
      if self.rank[x] == self.rank[y]:
        self.rank[x] += 1
      self.par[y] = x
      self.size[x] +=self.size[y]

  def is_same(self,x,y):
    return self.find(x)==self.find(y)
  
  def get_size(self,x):
    x = self.find(x)
    return self.size[x]

N, K, L = map(int, input().split())

# 道路のUnionFind
uf1 = UnionFind(N)
for i in range(K):
    p, q = map(int, input().split())
    uf1.union(p - 1, q - 1)
 
# 鉄道のUnionFind
uf2 = UnionFind(N)
for i in range(L):
    r, s = map(int, input().split())
    uf2.union(r - 1, s - 1)
 
# 道路と鉄道の連結の組み合わせ（根のペアのカウント）
c = defaultdict(int)
for i in range(N):
    c[(uf1.find(i), uf2.find(i))] += 1
ans = ""

# 回答を出力
for i in range(N):
    ans += str(c[(uf1.find(i), uf2.find(i))]) + " "
print(ans)

Measured memory_bytes: 59096
// tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
// define
#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()
// typedef
typedef long long lint;
typedef double Double;
typedef pair<int, int> pii;
//
typedef vector< int > Array;
typedef vector< Array > Matrix;
typedef vector< Double > DArray;
typedef vector< DArray > DMatrix;
typedef vector< string > SArray;
typedef vector< pii > PArray;
// popcount
inline int POPCNT(int _x) { return __builtin_popcount(_x); }
inline int POPCNT(lint _x) { return __builtin_popcountll(_x); }
// inf
const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
// eps
Double EPS = 1e-9;
// in range
inline bool in_range(int _v, int _mx, int _mi) { return _mi <= _v && _v < _mx; }
inline bool in_range(Double _v, Double _mi, Double _mx) { return -EPS < _v - _mi && _v - _mx < EPS; }
inline bool in_range(int _x, int _y, int _W, int _H) { return 0 <= _x && _x < _W && 0 <= _y && _y < _H; }
// neighbor clockwise
const int DX[4] = {0,1,0,-1}, DY[4] = {-1,0,1,0};
const int DX_[8] = {0,1,1,1,0,-1,-1,-1}, DY_[8] = {-1,-1,0,1,1,1,0,-1};
// variable update
inline void modAdd(int& _a, int _b, int _m) { _a = (_a + _b) % _m; }
inline void modAdd(lint& _a, lint _b, lint _m) { _a = (_a + _b) % _m; }
inline void minUpdate(int& _a, int _b) { _a = min(_a, _b); }
inline void minUpdate(lint& _a, lint _b) { _a = min(_a, _b); }
inline void maxUpdate(int& _a, int _b) { _a = max(_a, _b); }
inline void maxUpdate(lint& _a, lint _b) { _a = max(_a, _b); }

int n;

void solve() {
	int A = 0, B = 0;
	
	for_(i,0,n) {
		int a, b; cin >> a >> b;
		
		if (a > b) A += (a + b);
		else if (a < b) B += (a + b);
		else A += a, B += b;
	}
	
	cout << A << " " << B << endl;
}

int main() {
	while (cin >> n, n) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
using namespace std;
int r,c;
char mm[1100][1100];
int m[1100][1100];
int o = 1e9+7;
int dp(){
	m[0][0] = 1;
	for(int i = 0;i<r;i++){
		for(int j = 0;j<c;j++){
			if(mm[i][j] == '#') continue;
			if(i-1 >= 0){
				m[i][j]=((m[i][j]%o) + (m[i-1][j]% o) ) % o;
			}
			if(j-1>=0){
				m[i][j]=((m[i][j]%o) + (m[i][j-1]% o) ) % o;
			}
		}
	}
//	for(int i = 0;i<r;i++){
//		for(int j = 0;j<c;j++){
//			cout<<m[i][j]<<" ";
//		}cout<<"\n";
//	}
	return m[r-1][c-1];
}
int main(){
	cin>>r>>c;
	for(int i = 0;i<r;i++){
		for(int j = 0;j<c;j++){
			cin>>mm[i][j];
		}
	}
	cout<<dp()<<"\n";
	
	return 0;
}

Measured memory_bytes: 5632
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=sum(b)
for i in range(n-1):
    if a[i]+1==a[i+1]:
        ans+=c[a[i]-1]
print(ans)


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

int main()
{
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; i++)
        cin >> h[i];

    int ans = 0;
    int now = 0;
    for (int i = 0; i < n; i++)
    {
        if (h[i] <= now)
            now = h[i];
        else
        {
            ans += h[i] - now;
            now = h[i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    private static final PrintStream so = System.out;
    private static final Scanner     sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        int g = sc.nextInt();
        
        int[] p = new int[n];
        int[] comp = new int[n];
        int[] maxUnComp = new int[n];
        
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
            maxUnComp[i] = 100*(i+1) * (p[i] - 1);
            comp[i] = maxUnComp[i] + 100*(i+1) + sc.nextInt();
        }
        
        int ans = Integer.MAX_VALUE;
        for (int bits = 0; bits < 1 << n; bits++) {
            int sumS = sum(comp, bits, n); // score
            int sumQ = sum(p   , bits, n); // number of questions to solve
            int idx = firstIdxOf0(bits, n);
            int needed = g - sumS;

            if (idx != -1 && needed <= maxUnComp[idx]) {
                sumQ += Math.max(floor(needed, 100*(idx + 1)), 0);
                ans = Math.min(ans, sumQ);
            }
            if (idx == -1 && needed <= 0) {
                ans = Math.min(ans, sumQ);
            }
        }
        so.println(ans);
    }
    
    static int floor(int a, int b) {
        return (a + b - 1) / b;
    }
    
    static int sum(int[] a,int bits, int numBits) {
        int sum = 0;
        int mask = 1;
        
        for (int i = 0; i < numBits; i++) {
            if (((bits >> i) & mask) == 1) {
                sum += a[i];
            }
        }
        return sum;
    }
    
    static int firstIdxOf0(int bits, int numBits) {
        int mask = 1;
        for (int i = 1; i <= numBits; i++) {
            int shifted = bits >> (numBits - i);
            if ((shifted & mask) == 0) {
                return (numBits - i);
            }
        }
        return -1;
    }
}


Measured memory_bytes: 21844
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n, d;
    cin >> n >> d;

    d = d * 2 + 1;

    cout << (n + d - 1) / d << endl;


    return 0;
}


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

int main() {
  int a,b;
  cin >> a >> b;
  
  if(a != 1 && b != 1){
    if(a < b){
      cout << "Bob" << endl;
    }
    
    else if(a == b){
      cout << "Draw" << endl;
    }
    
    else{
      cout << "Alice" << endl;
    }
  }
  
  else if(a == 1 || b == 1){
    if(a == 1 && b != 1){
      cout << "Alice" << endl;
    }
    
    else if(a != 1 && b == 1){
      cout << "Bob" << endl;
    }
    
    else{
      cout << "Draw" << endl;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f
#define pb push_back
#define eps 1e-8
#define PI 3.1415926535898
using namespace std;
const ll maxn = 1e6 + 5;
ll num[maxn],n,m,a,b,c,t,k;
string str;
int main()
{
    cin >> k;
    cin >> a >> b;
    for(int i = a; i <= b; i++){
        if(i % k == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}



Measured memory_bytes: 3632
#include <iostream>
using namespace std;
constexpr int mod = 1000000007;
int n, inv[1000009], val[1000009];
int main() {
	cin >> n;
	inv[1] = 1;
	int cur = 1;
	for (int i = 2; i <= n; i++) {
		inv[i] = 1LL * inv[mod % i] * (mod - mod / i) % mod;
		cur = 1LL * cur * (i - 1) % mod;
	}
	for (int i = n - 1; 2 * i - n >= 0; i--) {
		cur = 1LL * cur * inv[i] % mod * inv[i + 1] % mod * (2 * i - n + 2) % mod * (2 * i - n + 1) % mod;
		val[i] = cur;
	}
	int ret = 0;
	for (int i = n - 1; 2 * i - n >= 0; i--) {
		ret = (ret + 1LL * (val[i] - val[i - 1] + mod) * i) % mod;
	}
	cout << ret << "\n";
	return 0;
}

Measured memory_bytes: 6144
#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;

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ull unsigned long long
#define ld long double

#define mod 1000000007
#define EULER 2.7182818284
#define INF 1000000000

#define pb push_back
#define ins insert
#define IT iterator
#define PQ priority_queue
#define    nl           "\n"
#define fi first
#define se second
#define maxe max_element
#define mine min_element
#define er erase
#define lb lower_bound
#define ub upper_bound

#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define pi pair<int,int>
#define pll pair<ll,ll>


#define mem(v,i) memset(v,i,sizeof(v)) // v is array. To set all elements to 0 or -1 only. mem(arr,0);


#define repab(i,a,b) for(int i=(a);i<=(b);i++)
#define reprab(i,a,b) for(int i=(a);i>=(b);i--)
#define repll(i,a,b) for(ll i=(a);i<=(b);i++)
#define rep(i,n) for(int i=(0);i<(n);i++)
#define repr(i,n) for(int i=(n);i>=0;i--)
#define bs bitset
#define bpc(a) __builtin_popcount(a)
#define tc int t;cin>>t;while(t--)
template<typename T> void TIME(T start, T end)
{
#ifndef ONLINE_JUDGE
    double time_taken =  chrono::duration_cast<chrono::nanoseconds>(end - start).count();
    time_taken *= 1e-9;
    cout << "\nExecuted in: " << fixed
         << time_taken << setprecision(9);
    cout << " sec";
#endif
}

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

ll max(ll a,ll b)
{
    if(a>b)return a;return b;
}
ll min(ll a,ll b)
{
    if(a<b)return a;return b;
}

ll mypow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
    if(b==0)
    return a;
    return gcd(b,a%b);
}
//..............................!!!!!!Get ready to fight!!!!!!............................


int main()
{   
     auto start = chrono::high_resolution_clock::now();
    fast
    ll x,y;
    cin>>x>>y;
    ll p=y-2*x,q=4*x-y;
    if(p>=0&&p%2==0&&q>=0&&q%2==0)
    cout<<"Yes\n";
    else
    cout<<"No\n";
    auto end = chrono::high_resolution_clock::now();
    TIME(start, end);
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ll N;
	cin >> N;
	-- N;
	int l = 1;
	ll s = 26;
	for (;;) {
		if (N < s) {
			string res;
			for (int i = 0; i < l; ++ i) {
				res += 'a' + N % 26;
				N /= 26;
			}
			reverse(res.begin(), res.end());
			cout << res << endl;
			break;
		} else {
			N -= s;
			s *= 26;
			++ l;
		}
	}
}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<bitset>
#include<sstream>
#include<list>
#include<climits>

using namespace std;
#define rep(i,i0,n) for(int i=(i0);i<(int)(n);++i)
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vii;
typedef long long ll;


int main(){
    int h,w;cin>>h>>w;
    vector<string> s(h);
    rep(i,0,h)cin>>s[i];
    int dx[4]={1,0,-1,0};
    int dy[4]={0,1,0,-1};
    bool flag=true;
    rep(i,0,h)rep(j,0,w)if(s[i][j]=='#'){
        bool flag1 = false;
        rep(k,0,4){
            int x = i + dx[k];
            int y = j + dy[k];
            if(0<=x&&x<h&&0<=y&&y<w&&s[x][y]=='#')flag1=true;
        }
        if(!flag1){
            flag=false;
            break;
        }
    }
    string ret= flag? "Yes": "No";
    cout<<ret<<endl;
	return 0;
}



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

struct node
{
  struct node *rt;
  struct node *lt;
  struct node *pt;
  int key;
};
typedef struct node *Node;

Node root;

void insert(int k)
{
  Node y = NULL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->lt = NULL;
  z->rt = NULL;

  while (x != NULL)
  {
    y = x;
    if (z->key < x->key) x = x->lt;
    else x = x->rt;
  }
  z->pt = y;

  if (y == NULL) root = z;
  else if (z->key < y->key) y->lt = z;
  else y->rt = z;
}

void inorder(Node u)
{

  if (u == NULL)
    return;
  inorder(u->lt);
  printf(" %d", u->key);
  inorder(u->rt);
}
void preorder(Node u)
{

  if (u == NULL)
    return;
  printf(" %d", u->key);
  preorder(u->lt);
  preorder(u->rt);
}
Node find(int key)
{
  Node X = root;

  while (1)
  {
    if (X == NULL) return NULL;
    if (X->key == key) return X;
    if (X->key < key)  X = X->rt;
    else X = X->lt;
  }
  }


Node treeSuccessor(Node A)
{
  Node X;
  Node B;
  A = A->rt;
  while (A->lt != NULL)A = A->lt;
  
  return A;
}

void treeDelete (Node X)
{
  Node B;
  Node child;

  if (X->rt == NULL && X->lt == NULL)
  {
    if (X->pt->rt == X)X->pt->rt = NULL;
    else X->pt->lt = NULL;
    free(X);
  }

  else if (X->rt != NULL && X->lt != NULL)
  {
    B = treeSuccessor(X);
    X->key = B->key;
    treeDelete(B);
  }

  else
  {
    if (X->rt==NULL)child=X->lt;
    else child=X->rt;

    if (X->pt==NULL)
    {
      child->pt=NULL;
      return;
    }
    if (X->pt->key < X->key) X->pt->rt=child;
    else X->pt->lt=child;
    child->pt=X->pt;
    free(X);
  }
}

int main()
{
  int n, i, x,count = 0;;
  char com[10];
  scanf("%d", &n);
  
  for (i = 0; i < n; i++)
  {
    scanf("%s", com);
    if (com[0] == 'i')
    {
      scanf("%d", &x);
      insert(x);
    }
    else if (com[0] == 'f')
    {
      scanf("%d", &x);
      
      if (count) printf("\n");
      if (find(x) != NULL)printf("yes\n");
      else printf("no\n");
    }
    else if (com[0] == 'd')
    {
      scanf("%d", &x);
      treeDelete (find(x));
    }
    else if (com[0] == 'p')
    {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}



Measured memory_bytes: 20496
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int Y = sc.nextInt();
    for (int i = 0; i <= N; i++) {
      for (int j = 0; j <= N - i; j++) {
        int k = N - i - j;
        int total = 10000 * i + 5000 * j + 1000 * k;
        if (total == Y) {
          System.out.println(i + " " + j + " " + k);
          return;
        }
      }
    }
    System.out.println("-1 -1 -1");
  }
}


Measured memory_bytes: 23764
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
#define MK make_pair
const ll E=1e18+7;
const ll MOD=1000000007;




int main(){
    ll a,b;
    cin>>a>>b;
    cout<<(a+b)%24<<endl;
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

int main(int argc, const char * argv[]) {
    // insert code here...
    //int a,b,c;
    //string s;
    //int a;
    //cin>>a;
    
    //int b = a / 500;
    //int c = (a % 500) / 5;
    
    //cout << b * 1000 + c * 5 << endl;
    //return 0;
    
    //c
    /*
    int k,n;
    int* a = new int[n];
    cin >> k >>n;
    for(int i = 0; i<n;i++)
    {
        cin >> a[i];
    }
    
    int b=0;
    for(int i = 0; i<n-1;i++)
    {
        if(b < a[i+1]-a[i])
        {
            b = a[i+1]-a[i];
        }
    }
    
    if(b < a[0] + k - a[n-1])
    {
        cout << a[n-1]-a[0] << endl;
        delete[] a;
        return 0;
    }
    else
    {
        cout << k - b << endl;
        delete[] a;
        return 0;
    }
     */
    
    //d
    int n,x,y;
    cin >> n >>x>>y;
    int* a = new int[n];
    
    for(int i =0;i<n;i++)
    {
        a[i] = 0;
    }
    for(int i =0;i<n;i++)
    {
        for(int j =i+1;j<n;j++)
        {
            int k = j-i;
            int t = abs(i-x+1) + 1 + abs(j-y+1);
            if(j-i < abs(i-x+1) + 1 + abs(j-y+1))
            {
                a[k-1]++;
            }
            else
            {
                a[t-1]++;
            }
        }
        
    }
    
    
    
    for(int i =0;i<n-1;i++)
    {
        cout << a[i] << endl;
    }
    delete[] a;
    return 0;
    
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int n,a,b,c,i;
  
  scanf("%d",&n);

    for(i=0;i<n;i++)
      {
	scanf("%d %d %d",&a,&b,&c);
	
	if((a*a+b*b==c*c)||(a*a+c*c==b*b)||(b*b+c*c==a*a))
	  {
	    printf("YES\n");
	  }    
	else
	  {
	    printf("NO\n");
	  }
      }
    return 0;
}

Measured memory_bytes: 0
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

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

struct node{
  int x, y, p, q, dir, dis;
  bool operator<(const node &n) const{ return dis > n.dis; }
};

string s[105];
int d[105][105][11][11][4];

signed main(void)
{
  int h, w, a;
  cin >> h >> w >> a;
  REP(i, h) cin >> s[i];
  int sx, sy, gx, gy;
  REP(i, h) REP(j, w) {
    if(s[i][j] == 'S') sx = j, sy = i;
    else if(s[i][j] == 'G') gx = j, gy = i;
  }

  memset(d, -1, sizeof(d));
  priority_queue<node> que;
  que.push((node){sx, sy, 0, 0, 2, 0});
  while(que.size()) {
    node v = que.top(); que.pop();
    //cout << v.x << " " << v.y << " " << v.p << " " << v.q << " " << v.dir << " " << v.dis << endl;
    if(v.x == gx && v.y == gy) {
      cout << v.dis << endl;
      return 0;
    }
    if(d[v.x][v.y][v.p][v.q][v.dir] >= 0) continue;
    d[v.x][v.y][v.p][v.q][v.dir] = v.dis;
    REP(i, 3) {
      int di = (v.dir+i+3)%4;
      //cout << "d:" << di << endl;
      if(v.x == sx && v.y == sy && v.dis && dy[di] != 0) continue;
      if(v.x == sx && v.y == sy && v.dir != di) continue;
      bool isp = (v.dir+di) == 3, isq = (v.dir+di)%4 == 1;
      //cout << "p:" << isp << " q:" << isq << " " << di << endl;
      if(isp && v.p >= a) continue;
      if(isq && v.q >= a) continue;
    //  cout << dx[di] << " " << dy[di] << " " << endl;
      int x = v.x + dx[di], y = v.y + dy[di];
      //Anaconda3\cout << i << " " << x << " " << y << " " << endl;
      if(IN(0, w, x) && IN(0, h, y) && s[y][x] != '#') {
        que.push((node){x, y, v.p+isp, v.q+isq, di, v.dis+isp+isq});
        //cout << "a" << endl;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 24772
#include <iostream>
using namespace std;
int main(void){
  int n,x,y;
  cin >> n >> x >> y;
  if(max(x,y)-(n-min(x,y))>0){
    cout << min(x,y) << " " << max(x,y)-(n-min(x,y)) << endl;
  }else{
    cout << min(x,y) << " " << 0 << endl;
  }
  return 0;  
}


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

ll A, B;

int main() {
    
    int N, A, x, y, max_honest, honest_count;
    cin >> N;
    vector<int> honests(N, 1);
    vector<vector<int>> say(N, vector<int>(N, 2));
    for(int i=0;i<N;i++){
        cin >> A;
        for(int j=0;j<A;j++){
            cin >> x >> y;
            say.at(i).at(x-1) = y;
        }
    }
    max_honest = 0;
    for(int i=0;i<(1<<N);i++){
        // initialize honests
        honest_count = 0;
        for(int j=0;j<N;j++){
            x = (i / (1<<j)) % 2;
            honests.at(j) = x;
            honest_count += x;
        }
        // check is it ok?
        bool ok = true;
        for(int j=0;j<N;j++){
            if(honests.at(j)==0){
                continue;
            }
            for(int k=0;k<N;k++){
                if(say.at(j).at(k) != 2 && say.at(j).at(k) != honests.at(k)){
                    ok = false;
                    break;
                }
            }
            if(!ok){
                break;
            }
        }
        if(ok){
            max_honest = max(max_honest, honest_count);
        }
    }
    cout << max_honest << endl;
    return 0;

}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n,k = map(int, input().split())
al = list(map(int, input().split()))

# def f(x):
#     res = 0
#     for a in al:
#         res += a^x
#     return res
# res = 0
# for x in range(k+1):
#     res = max(res, f(x))
# print(res)
maxd = 50
dp = [[-1, -1] for _ in range(maxd+1)]
dp[0][0] = 0

for d in range(maxd):
    s1 = 0
    s0 = 0
    c = 1<<(maxd-d-1)
    for a in al:
        if a&c>0:
            s0 += c
        else:
            s1 += c

    if dp[d][1]!=-1:
        dp[d+1][1] = max(dp[d+1][1], dp[d][1]+max(s1,s0))
    if dp[d][0]!=-1:
        if k&c>0:
            dp[d+1][1] = max(dp[d+1][1], dp[d][0]+s0)
            dp[d+1][0] = max(dp[d+1][0], dp[d][0]+s1)
        else:
            dp[d+1][0] = max(dp[d+1][0], dp[d][0]+s0)
# print(dp)
print(max(dp[maxd][0], dp[maxd][1]))


Measured memory_bytes: 14620
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int N;
  std::cin >> N;
  bool flag = 1;
  char tmp = '.';
  std::vector<string> S(N);
  range(i, N){
    string s;
    std::cin >> s;
    if(s[0] == tmp || tmp == '.'){
      tmp = s[s.size()-1];
      S[i] = s;
      range(j, i) if(S[j] == s) flag = 0;
    }else flag = 0;
  }
  (flag == 1)?std::cout << "Yes" << '\n':std::cout << "No" << '\n';
  return 0;
}


Measured memory_bytes: 256
n=int(input())
A,C,G,T,M=0,1,2,3,10**9+7
r=range
dp=[[[[0]*4for k in r(4)]for j in r(4)]for i in r(n+1)]
dp[0][T][T][T]=1
for i in r(1,n+1):
  for j in r(4):
    for k in r(4):
      for l in r(4):
        for m in r(4):
          if any(t==(k,l,m)for t in((A,G,C),(A,C,G),(G,A,C)))or(j,l,m)==(A,G,C)or(j,k,m)==(A,G,C):continue
          dp[i][k][l][m]=(dp[i][k][l][m]+dp[i-1][j][k][l])%M
print(sum(dp[n][i][j][k]for i in r(4)for j in r(4)for k in r(4))%M)

Measured memory_bytes: 3316
#include <iostream>
using namespace std;
int main(){
  long long L[87],N;
  L[0]=2;L[1]=1;
  cin >> N;
  for(int i=2;i<=N;i++){
    L[i]=L[i-1]+L[i-2];
  }
  cout << L[N] << endl;
  return 0;
}


Measured memory_bytes: 256
'use strict';

function main(stdin) {
  const input = stdin;
  const former = parseInt(input.slice(0, 2), 10);
  const latter = parseInt(input.slice(2), 10);

  function test(n) {
    if (n < 1 || n > 12) return false;
    else return true;
  }

  const f = test(former);
  const l = test(latter);

  if (f) {
    if (l) console.log('AMBIGUOUS');
    else console.log('MMYY');
  } else {
    if (l) console.log('YYMM');
    else console.log('NA');
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline bool chmin(A &a,const B &b){if(a>b){a=b;return true;}else{return false;}}
template<typename A,typename B>inline bool chmax(A &a,const B &b){if(a<b){a=b;return true;}else{return false;}}

int main()
{
    ll N;
    vll A(5);
    cin >> N;
    cin >> A;
    ll ans = 0;
    ll C;
    for(int i=0; i<5; i++){
        if(i == 0){
            C = A[i];
            ans = N/A[i];
            if(0 != N%A[i])ans++;
        }else{
            if(C > A[i]){
                C = A[i];
                ans = N/A[i] + i;
                if(0 != N%A[i])ans++;
            }else{
                ans++;
            }
        }
    }
    cout << (ans) << endl;
}

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

#include <boost/algorithm/string/join.hpp>
using boost::algorithm::join;

#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((ll)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int N, L;
  cin >> N >> L;
  vector<string> S(N);
  rep(i, N) {
    cin >> S[i];
  }
  sort(all(S));
  string ans = join(S, "");
  cout << ans << endl;
}

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

int main()
{
  string S;
  cin >> S;
  string s1(S.size(), '0');
  string s2(S.size(), '1');

  for (int i = 0; i < S.size(); i++)
  {
      if (i%2==0)
      {
          s1[i] = '1';
          s2[i] = '0';
      }
  }
  //cout << s2 <<  endl;
  //cout << s1 <<endl;

  int ans1 = 0, ans2 = 0;
  for (int i = 0; i < S.size(); i++)
  {
      if (s1[i] !=S[i])
      {
          ans1++;
      }
      if (s2[i] !=S[i])
      {
          ans2++;
      }
  }
    if (ans1<ans2)
        cout << ans1 <<endl;
    else
        cout <<ans2<<endl;

  return 0;
}


Measured memory_bytes: 512