akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

#define INF 2000000000
#define MAX_V 10



bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin>>n;
    vec<ll> a(n);
    rep(i,n) cin>>a[i];
    
    ll four=0,odd=0;
    rep(i,n){
        if(a[i]%4==0) four++;
        if(a[i]%2!=0) odd++;
    }
    if(four>=odd) cout<<"Yes"<<endl;
    else {
        if(odd-four<=1 && odd+four==n) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main{

    public static void main(String args[]){

        Scanner sc = new Scanner(System.in);

        String s = sc.next();

        if(s.equals("Sunny")) System.out.println("Cloudy");
        else if(s.equals("Cloudy")) System.out.println("Rainy");
        else System.out.println("Sunny");

    }

}


Measured memory_bytes: 22356
class Point
    attr_accessor :x, :y, :h
    def initialize(x, y, h)
        @x = x
        @y = y
        @h = h
    end

    def dist(p2)
        (self.x - p2.x).abs + (self.y - p2.y).abs
    end

    def to_s
        [@x, @y, @h].join(" ")
    end
end

N = gets.to_i
points = []
N.times do 
    points << Point.new(*gets.split.map(&:to_i))
end

(0..100).each do |cx|
    (0..100).each do |cy|
        c = Point.new(cx, cy, nil)
        match = true
        points.sort_by{|point| point.dist(c)}.each do |point|
            if !c.h
                c.h = point.dist(c) + point.h
            elsif c.h >= point.dist(c)
                match = false if c.h != point.dist(c) + point.h
            else
                match = false if point.h != 0
            end
        end
        if match
            puts c
            exit
        end
    end
end

Measured memory_bytes: 2808
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N, K, P[101010], Q[101010];
vector<string> A;

string inv(string a)
{
	string ret;
	for (int i = 0; i < a.size(); ++i) {
		ret.push_back((char)(a[a.size() - 1 - i] ^ 32));
	}
	return ret;
}
string concat(string a, string b)
{
	reverse(b.begin(), b.end());
	while (a.size() > 0 && b.size() > 0 && (a.back() ^ b.back()) == 32) {
		a.pop_back();
		b.pop_back();
	}
	reverse(b.begin(), b.end());
	return a + b;
}

vector<int> inv(const vector<int> &perm)
{
	vector<int> ret(N, -1);
	for (int i = 0; i < N; ++i) ret[perm[i]] = i;
	return ret;
}
vector<int> app(const vector<int> &a, const vector<int> &b)
{
	vector<int> ret(N, -1);
	for (int i = 0; i < N; ++i) {
		ret[i] = a[b[i]];
	}
	return ret;
}
vector<int> power(const vector<int> &a, int p)
{
	vector<int> ret = a, pp = a;
	--p;
	for (int i = 0; i < 30; ++i) {
		if ((p >> i) & 1) {
			ret = app(ret, pp);
		}
		pp = app(pp, pp);
	}
	return ret;
}

vector<vector<int>> sols;

int main()
{
	scanf("%d%d", &N, &K); --K;
	for (int i = 0; i < N; ++i) {
		scanf("%d", P + i); --P[i];
	}
	for (int i = 0; i < N; ++i) {
		scanf("%d", Q + i); --Q[i];
	}

	{
		vector<int> tmp;
		for (int i = 0; i < N; ++i) tmp.push_back(P[i]);
		sols.push_back(tmp);
	}
	{
		vector<int> tmp;
		for (int i = 0; i < N; ++i) tmp.push_back(Q[i]);
		sols.push_back(tmp);
	}
	for (int i = 2; i < 12; ++i) {
		sols.push_back(app(sols[i - 1], inv(sols[i - 2])));
		//for (int j = 0; j < N; ++j) printf("%d ", sols[i][j]);
		//puts("");
	}
	
	vector<int> res;
	if (K < 10) {
		res = sols[K];
	} else {
		int dec = (K - 3) / 6;
		K -= dec * 6;
		vector<int> hoge = app(app(inv(sols[0]), sols[1]), app(sols[0], inv(sols[1])));
		hoge = power(hoge, dec);
		res = app(inv(hoge), app(sols[K], hoge));
	}
	for (int i = 0; i < N; ++i) printf("%d%c", res[i] + 1, i == N - 1 ? '\n' : ' ');
	return 0;
}


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

using namespace std;

using ll = long long;
#define MOD 1000000007

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

    vector<ll> a(n + 2);

    for (int i = 1; i <= n; i++) {
        a[i + 1] = a[i] + i;
    }

    int ans = 0;
    for (int i = k; i <= n; i++) {
        ans = (ans + a[n + 1] - a[n + 1 - i] - a[i] + 1) % MOD;
    }

    cout << ans + 1 % MOD << endl;

    return 0;
}

Measured memory_bytes: 4752
#include<stdio.h>
int main(){
  int N,data[100],flag,i,x,count=0;
  scanf("%d",&N);
  for(i=0; i<N; i++){
    scanf("%d",&data[i]);
  }
  flag=1;
  while(flag==1){
    flag=0;
    for(i=N-1; i>=1; i--){
      if(data[i]<data[i-1]){
	x=data[i];
	data[i]=data[i-1];
	data[i-1]=x;
	flag=1;
	count++;
      }
    }
  }
  
  for(i=0; i<N; i++){
    if(i==N-1) printf("%d",data[i]);
    else printf("%d ",data[i]);
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2108
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

func main() {
	N := nextInt()
	s := nextString()

	s += string(s[0])
	starts := [][]string{{"S", "S"}, {"S", "W"}, {"W", "S"}, {"W", "W"}}
	for _, start := range starts {
		animals := make([]string, N+2)
		animals[0] = start[0]
		animals[1] = start[1]
		for i := 1; i <= N; i++ {
			if animals[i] == "S" {
				if s[i] == 'o' {
					if animals[i-1] == "S" {
						animals[i+1] = "S"
					} else {
						animals[i+1] = "W"
					}
				} else {
					if animals[i-1] == "S" {
						animals[i+1] = "W"
					} else {
						animals[i+1] = "S"
					}
				}
			} else {
				if s[i] == 'o' {
					if animals[i-1] == "S" {
						animals[i+1] = "W"
					} else {
						animals[i+1] = "S"
					}
				} else {
					if animals[i-1] == "S" {
						animals[i+1] = "S"
					} else {
						animals[i+1] = "W"
					}
				}
			}
		}

		if animals[0] == animals[N] && animals[1] == animals[N+1] {
			fmt.Println(strings.Join(animals[:N], ""))
			return
		}
	}

	fmt.Println(-1)
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextString() string {
	sc.Scan()

	return sc.Text()
}

// ---------- Input.


Measured memory_bytes: 6272
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;

int main(int argc, char *argv[])
{
  int n, w, d;
  cin >> n >> w >> d;
  vector<pair<int,int>> ps;
  // mapping to the south-west corner 
  auto mapping0 = [](int x, int y) {
    return x - y;
  };
  // mapping in one of four directions
  auto mappingX = [w,d,&mapping0](int x, int y, int dir) {
    switch(dir) {
    case 0 : { // (-1, -1)-direction
      int o = mapping0(x, y);
      return o; // o >= 0 ? o : w + w + d + d + o; // normalization
    }
    case 1 : { // (1, -1)-direction
      int o = mapping0(w-x, y); // flipping in x
      return w - o; // o >= 0 ? w - o : w + (- o);
    }
    case 2 : { // (1, 1)-direction
      int o = mapping0(w-x, d-y); // flipping in x and y
      return w + d + o; // o >= 0 ? w + d + o : w + d + o;
    }
    case 3 : { // (-1, 1)-direction
      int o = mapping0(x, d-y); // flipping in y
      return w + d + w - o; // o >= 0 ? w + d + w - o : w + d + w + -o;
    }
    return -1;
    }
  };
  // mapping to a range
  auto make_range = [w,d,&mappingX](int x, int y, char c) {
    switch(c){
    case 'N': return make_pair(mappingX(x, y, 2), mappingX(x, y, 3));
    case 'E': return make_pair(mappingX(x, y, 1), mappingX(x, y, 2));
    case 'S': {
      int s = mappingX(x, y, 0);
      int e = mappingX(x, y, 1);
      return make_pair(s, e);
    }
    case 'W': {
      int s = mappingX(x, y, 3);
      int e = mappingX(x, y, 0) + w + w + d + d;
      if(e > w + w + d + d) {
        s -= + w + w + d + d;
        e -= + w + w + d + d;
      }
      return make_pair(s, e);
    }
    }
    return make_pair(-10, -10);
  };
  
  auto sw = [](const pair<int,int> p) {
    return make_pair(p.second, p.first);
  };
  
  for(int i = 0; i < n; i++) {
    int x, y, d;
    char c;
    cin >> x >> y;
    cin >> c;
    ps.push_back(sw(make_range(x, y, c)));
  }
  // a desk = a range on walls
  // a lock = a point on walls
  // todo: put points so that every range contains a point

  // sort the ranges
  sort(ps.begin(), ps.end());

  // shrink the region (endpoint ee) by the range r
  auto wrap = [d,w](bool aug, int a) {
    return aug ? a + d + d + w + w : a;
  };

  auto contains = [d,w,&ps](int i, int x) {
    int s = ps[i].second;
    int e = ps[i].first;
    if(s <= x && x <= e) return true;
    int y = x + d + d + w + w;
    if(s <= y && y <= e) return true;
    int z = x - (d + d + w + w);
    if(s <= z && z <= e) return true;
    return false;
  };

  // locating clocks from i's view
  auto count = [&ps,n,&wrap,&contains](const int ii){
    int i = ii;
    int k = 0;
    int cnt = 0;
    while(k < n) {
      int e = ps[i].first; //wrap(i < ii, ps[i].first);
      int kk = k;
      k++;
      i = (i + 1) % n;
      while(k < n && contains(i, e)) {
        i = (i + 1) % n;
        k++;
      }
      cnt++;
    }
    return cnt;
  };
  

  int cnt = n; // at most n
  // possible starting points
  for(int i = 0; i < n; i++) {
    cnt = min(cnt, count(i));
  }
  cout << cnt << endl;
  return 0;
}




Measured memory_bytes: 3112
import java.util.Scanner;

/**
 * コンソールテスト用Main クラス
 *
 * @author RisaTozawa
 */
public class Main {

	/* コンストラクタ */
	Main() {
	//何もしない
	}

	/**
	 * Atcorder 提出
	 * @return
	 *
	 */

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

		/* 何泊したいかを入力 */
		int goukei= 0;
		int n = sc.nextInt();
		int k = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();


		/* 滞在期間がK以下の場合 */
		if (n < k) {
			goukei =  n * x;
		} else {
			goukei = k * x;
			goukei = (n-k) * y + goukei;

		}


		System.out.println(goukei);
	}

}


Measured memory_bytes: 23252
n1,t1=gets.chomp.split(" ").map(&:to_i);

ret=Array.new
n1.times do | val |
  c,t = gets.chomp.split(" ").map(&:to_i);
  if t <= t1
    ret.push c
  end
end
if ret.size == 0
  puts "TLE"
  exit 0
end
a= ret.sort.first
puts a

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

int main(){
  int n;
  cin >> n ;
  vector<int> a(n);
  rep(i,n){ cin >> a[i]; }
  
  ll ansa=0; 
  ll sum=a[0];
  if(a[0]==0){ansa=1; sum=1;}
  bool pm = (sum>0?true:false);
  for(int i=1; i<n; i++){
    sum += a[i];
    if(pm){
      if(sum>=0){
        ansa += sum+1;
        sum = -1;
      }
      pm = false;
    } else {
      if(sum<=0){
        ansa += abs(sum)+1;
        sum = 1;
      }      
      pm = true;
    }
  }

  ll ansb=abs(a[0])+1;
  sum= (a[0]>0?-1:1);
  if(a[0]==0){ansb=1; sum=-1;}
  pm = (sum>0?true:false);
  
  for(int i=1; i<n; i++){
    sum += a[i];
    if(pm){
      if(sum>=0){
        ansb += sum+1;
        sum = -1;
      }
      pm = false;
    } else {
      if(sum<=0){
        ansb += abs(sum)+1;
        sum = 1;
      }      
      pm = true;
    }
  }
  
//  cout << ansa<< " " <<ansb << endl;
  cout << min(ansa,ansb) << endl;
  return 0;
}


Measured memory_bytes: 640
//https://atcoder.jp/contests/abc114/tasks/abc114_b

#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <bitset>


using namespace std;
int main(){
	string s;
	int d,ans;
	ans=10000;
	cin>>s;
	for(int i=0; i<s.length()-2; i++){
		d=abs(753-atoi(s.substr(i,3).c_str()));
		ans=min(ans,d);
	}
	
	cout<<ans<<endl;
}






Measured memory_bytes: 256
h,w=map(int,input().split())
C=[list(map(int,input().split())) for i in range(10)]
A=[list(map(int,input().split())) for j in range(h)]
#warshall_floyd法:最短経路を全探索で求める
for k in range(10):
    for i in range(10):
        for j in range(10):
            C[i][j]=min(C[i][j],C[i][k]+C[k][j])

cost=[C[i][1] for i in range(10)]+[0]
cnt=0
for i in range(h):
    for j in range(w):
        cnt +=cost[A[i][j]]
print(cnt)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main() {
  int n,max1,max2 = 0;
  cin >> n;
  vector<int> a(n);
  vector<int> cp(n);
  rep(i,n) cin >> a[i];
  cp = a;
  sort(cp.begin(),cp.end(),greater<int>());
  max1 = cp[0];
  max2 = cp[1];
  rep(i,n) {
    if(a[i] != max1) cout << max1 << endl;
    else cout << max2 << endl;
  }
  return 0;
}

Measured memory_bytes: 3200
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))


#A2 = sorted(A)
#B2 = sorted(B)
#C2 = sorted(C)


def numadd(up, down):
    array = []
    count = 0
    last = 0
    for i in range(0,N):
        while down[i] > up[count]:
            count = count + 1
            if count == N:
                count = count - 1
                last = 1
                break
        array.append(count + last)
    return array

B3 = numadd(sorted(A),sorted(B))
C3 = numadd(sorted(B),sorted(C))

B4 = [B3[0]]
for i in range(0,N-1):
    B4.append(B4[i] + B3[i+1])

ans = 0
for i in range (0,N):
    if C3[i] > 0:
        ans = ans + B4[C3[i]-1]

print(ans)

Measured memory_bytes: 29172
N=int(input())


X=[1]+[6**i for i in range(1,7)]+[9**i for i in range(1,6)]
X.sort()
X.reverse()

ANS=1000000







for i_0 in range(max(N//X[0]-3,0),N//X[0]+1):
    N_0=N-X[0]*i_0
    for i_1 in range(max(N_0//X[1]-3,0),N_0//X[1]+1):
        N_1=N_0-X[1]*i_1
        for i_2 in range(max(N_1//X[2]-3,0),N_1//X[2]+1):
            N_2=N_1-X[2]*i_2
            for i_3 in range(max(N_2//X[3]-3,0),N_2//X[3]+1):
                N_3=N_2-X[3]*i_3
                for i_4 in range(max(N_3//X[4]-3,0),N_3//X[4]+1):
                    N_4=N_3-X[4]*i_4
                    for i_5 in range(max(N_4//X[5]-3,0),N_4//X[5]+1):
                        N_5=N_4-X[5]*i_5
                        for i_6 in range(max(N_5//X[6]-3,0),N_5//X[6]+1):
                            N_6=N_5-X[6]*i_6
                            for i_7 in range(max(N_6//X[7]-3,0),N_6//X[7]+1):
                                N_7=N_6-X[7]*i_7
                                for i_8 in range(max(N_7//X[8]-3,0),N_7//X[8]+1):
                                    N_8=N_7-X[8]*i_8
                                    for i_9 in range(max(N_8//X[9]-3,0),N_8//X[9]+1):
                                        N_9=N_8-X[9]*i_9
                                        i_10=N_9//6
                                        N_10=N_9-X[10]*i_10
                                        if ANS>i_0+i_1+i_2+i_3+i_4+i_5+i_6+i_7+i_8+i_9+i_10+N_10:
                                            ANS=i_0+i_1+i_2+i_3+i_4+i_5+i_6+i_7+i_8+i_9+i_10+N_10


                                            




print(ANS)
        
    


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i=0; i<n; ++i) cin >> a[i];
	sort(a.begin(),a.end());

	vector<int> dp(a[n-1]+1,1);
	for(int i=0; i<n; ++i){
		if(dp[a[i]]==0) continue;
		if(i>0 && a[i]==a[i-1]){
			dp[a[i]]=0;
			continue;
		}
		for(int j=2*a[i]; j<=a[n-1]; j+=a[i]){
			dp[j]=0;
		}
	}
	int ans=0;
	for(int i=0; i<n; ++i){
		ans += dp[a[i]];
	}

	cout << ans << endl;
}

Measured memory_bytes: 7948
#include<iostream>
#include<cstdio>
#define _USE_MATH_DEFINES
#include<math.h>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<map>
#include<unordered_map>
#include<set>
#include <algorithm>
#include <utility>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::set;
using std::vector;
using std::pair;
using std::make_pair;
using std::priority_queue;

typedef unsigned long long ull;
typedef long long ll;

#define Prime1 1000000007
#define Prime2 9999973

#define INF 0x7fffffffffffffff

ull i, j, k, l, m, n;
ull H, W, Q;
ull a, b, c, x, y;
ull K, L, N, M;
string str;

struct Work {
	ll time;
	ll sime;
	Work(ll A, ll B) {
		time = A;
		sime = B;
	}
	bool operator<(const Work &rhs)const {
		return sime != rhs.sime ? sime > rhs.sime:time > rhs.time;
	}
};

int main()
{
	vector<Work> works;
	ll A, B;
	cin >> N;
	for (i = 0; i < N; ++i)
	{
		cin >> A >> B;
		works.push_back(Work(A, B));
	}
	sort(works.begin(), works.end());

	ll t = works[0].sime;
	for (auto w : works)
	{
		if (t > w.sime)
		{
			t = w.sime;
		}
		if (t < w.time)
		{
			cout << "No";
			return 0;
		}
		t -= w.time;
	}
	cout << "Yes";
	return 0;
}


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

#define ll long long
#define sp ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cps CLOCKS_PER_SEC
#define mod (ll)1000000007
#define f first
#define s second
#define debug1(x) cout<<x<<"\n"
#define debug2(x,y) cout<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define nl cout<<"\n";
#define pq priority_queue
#define inf 0x3f3f3f3f
#define test cout<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define mxn 200005

int b[22][22];
int dp[(1<<21)+5][22];
int n;


int solve(int mask,int a){
if(a==n)return 1;
if(dp[mask][a]!=-1)return dp[mask][a];
ll w=0;
for(int i=0; i<n;++i){
    if(mask&(1<<i))continue;
    if(b[a][i])
    w=(w+solve(mask|(1<<i),a+1))%mod;
}
return (dp[mask][a]=w);
}

int main(){
sp;
cin>>n;
for(int i=0; i<n;++i)
    for(int j=0; j<n; ++j)cin>>b[i][j];
    memset(dp,-1,sizeof dp);
cout<<solve(0,0);
return 0;}


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

const int N = 110;
int n, x, ans, a[N];

template <class T> inline void in(T &x) {
	x = 0; int f = 0; char ch = getchar();
	for (; ch<'0' || ch>'9';) {if (ch=='-') f=-1; ch = getchar();}
	for (; ch>='0' && ch<='9';) x = x*10 + ch-'0', ch = getchar();
	x = f ? -x : x;
}

int main() {
	in(n), in(x);
	for (int i = 1; i <= n; ++i) in(a[i]);
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; ++i) {
		x -= a[i];
		if (x < 0) break;
		++ans;
	}
	if (x > 0) --ans;
	printf("%d\n", ans);
	return 0;
}

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

using ll = long long;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
    int N;
    cin >> N;
    vector<vector<int>> d(N, vector<int>(N, INF));
    string S;
    rep(i, N) {
        cin >> S;
        rep(j, N) {
            if (i == j) d[i][j] = 0;
            if (S[j] == '1') d[i][j] = 1;
        }
    }
    rep(k, N) {
        rep(i, N) {
            rep(j, N) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
    /*rep(i, N) {
        rep(j, N) {
            cout << d[i][j] << " ";
        }
        cout << endl;
    }*/
    int ans = -1;
    rep(i, N) {
        int maxd = 0;
        bool f = false;
        rep(j, N) {
            maxd = max(maxd, d[i][j] + 1);
            rep(k, N) {
                if (d[j][k] != 1) continue;
                if (abs(d[i][j] - d[i][k]) != 1) {
                    f = true;
                    break;                    
                }
            }
            if (f) break;
        }
        if (!f) ans = max(ans, maxd);
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
def inpl(): return [int(i) for i in input().split()]

N, C, K = inpl()
A = []
for _ in range(N):
    A.append(int(input()))
A = list(sorted(A))
bus = 0
st = -K-1
nop = 0
for i in A:
    if st + K < i or nop == C:
        bus += 1
        st = i
        nop = 1
    else:
        nop += 1
print(bus)

Measured memory_bytes: 8656
S = input()
while len(S) >= 5:
    if S[:7] == 'dreamer':
        S = S[11:] if S[7:11] == 'aser' else S[10:] if S[7:10] == 'ase' else S[7:]
    elif S[:6] == 'eraser':
        S = S[6:]
    elif S[:5] in ['dream','erase']:
        S = S[5:]
    else:
        break
print('YES') if S == '' else print('NO')

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

void solve(long long D){
	if (D == 22) {
		printf("Christmas Eve Eve Eve\n");
	}
	if (D == 23) {
		printf("Christmas Eve Eve\n");
	}
	if (D == 24) {
		printf("Christmas Eve\n");
	}
	if (D == 25) {
		printf("Christmas\n");
	}
}

int main(){
	long long D;
	scanf("%lld",&D);
	solve(D);
	return 0;
}


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

void fnInput(vector<int> &rvnPodr, vector<int> &rvnIodrSeq)
{
  int nMaxSiz;

  cin >> nMaxSiz;
  rvnPodr.resize(nMaxSiz + 1);
  rvnIodrSeq.resize(nMaxSiz + 1);

  for (int i = 1; i < nMaxSiz + 1; i++)
    cin >> rvnPodr[i];

  int nNode;
  for (int i = 1; i < nMaxSiz + 1; i++)
  {
    cin >> nNode;
    rvnIodrSeq[nNode] = i;
  }
}

void fnPostOrder(const vector<int> &cnrvnPodr, const vector<int> &cnrvnIodrSeq, int nLeft, int nRight)
{
  static int stnx = 1;
  static int stnPrt = 0;

  if (nLeft == nRight) return;

  int nNode = cnrvnPodr[stnx++];
  int nMid = cnrvnIodrSeq[nNode];

  fnPostOrder(cnrvnPodr, cnrvnIodrSeq, nLeft, nMid);
  fnPostOrder(cnrvnPodr, cnrvnIodrSeq, nMid + 1, nRight);

  if (stnPrt++) cout << " ";
  cout << nNode;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> vnPodr, vnIodrSeq;
  fnInput(vnPodr, vnIodrSeq);

  fnPostOrder(vnPodr, vnIodrSeq, 1, vnPodr.size());
  cout << endl;
  return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const long long INF = 1LL << 58;
struct Edge
{
    ll s, t, d;
};
typedef vector<vector<Edge>> Graph;
typedef vector<pii> vpii;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

signed main()
{
    string S;
    cin >> S;
    int cnt = 0;
    REP(i, int(S.size() / 2))
    {
        if (S[i] != S[S.size() - 1 - i])
            cnt++;
    }
    cout << cnt << endl;

    return 0;
    // system("pause");
}

Measured memory_bytes: 256
"use strict"

function main(input) {
  input = input.split(/\n/).map(v => ~~v)
  let set = new Set()
  for (let i = 1; i < input.length-1; i++) {
    //
    if (set.has(input[i])) {
      set.delete(input[i])
    } else {
      set.add(input[i])
    }
  }
  console.log(set.size)
}
main(require("fs").readFileSync("/dev/stdin", "utf8"))

Measured memory_bytes: 30980
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N,Z,W; cin >> N >> Z >> W;
    vector A(N,0);
    rep(i,N) cin >> A.at(i);
    if (N == 1) {
        cout << abs(A[0] - W) << endl;
    } else
        cout << max(abs(A[N-1] - W), abs(A[N-1]-A[N-2])) << endl;
}


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

#define vec              vector<int>
#define vecll            vector<ll>
#define vecd             vector<double>
#define vecst            vector<string>
#define vecb             vector<bool>
#define v2(v,n,m,init)   vector<vector<int>>  v(n, vector<int>(m, init))
#define vb2(v,n,m,init)  vector<vector<bool>> v(n, vector<bool>(m, init))
#define vll2(v,n,m,init) vector<vector<ll>>   v(n, vector<ll>(m, init))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
template <typename T>
bool chmax(T &a, const T& b){if(a<b){a=b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a>b){a=b; return true;} return false;}
//------------------------------------------------------------------

int main(void){
  int m;
  cin >> m;
  vecll d(m), c(m);
  rep(i,m){
    cin >> d[i] >> c[i];
  }

  ll sum=0;
  ll keta=0;
  rep(i,m){
    keta += c[i];
    sum += d[i]*c[i];
  }

  prt(keta-1+(sum-1)/9);
}


Measured memory_bytes: 6408
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define COUTDOUBLE(d,i) cout << setprecision((i)) << (d) << endl;
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}
#define MREP(i,m) for(auto i=(m).begin(); i != (m).end(); ++i) // auto key = i->first;auto value = i->second;

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;
I MAX = LONG_MAX;
I MIN = LONG_MIN;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s,t;
  cin >> s >> t;
  cout << t << s << endl;
  return 0;
}



Measured memory_bytes: 256
a, b = map(int, input().split())
c = []
for i in range(a):
    c.append(list(input()))
x = y = 0
while True:
    c[x][y] = "."
    if x == a - 1 and y == b - 1:
        break
    d = False
    if x + 1 < a and not d:
        if c[x+1][y] == "#":
            d = not d
            x += 1
    if y + 1 < b and not d:
        if c[x][y + 1] == "#":
            d = not d
            y += 1
    if not d:
        print("Impossible")
        exit()
p = True
for i in range(a):
    if "#" in c[i]:
        print("Impossible")
        exit()
print("Possible")


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<string>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
#define W(x) cout<<x<<endl;
#define Debug(x) cout<<"#DEBUG "<<x<<endl;
#define INF (1<<29)
using namespace std;
int min(int x,int y){if(y<x)return y;else return x;}
int max(int x,int y){return x+y-min(x,y);}
int fact(int x){int i=1;rep(j,x){i*=(j+1);} return i;}
int main()
{
    int d,n;
    cin>>d>>n;
    if(n==100)
    {
        cout<<101;
        rep(i,d)
        {
            cout<<0<<0;
        }
        cout<<endl;
    }
    else
    {
        cout<<n;
        rep(i,d)
        {
            cout<<0<<0;
        }
        cout<<endl;
    }
        
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int binarySearch(int *,int, int);

int main(){
int i,n,q,s[100000+10],t,sum=0;

scanf("%d",&n);
for(i = 0; i < n ; i++){
scanf("%d",&s[i]);
}
scanf("%d",&q);
for(i = 0 ; i < q; i++){
  scanf("%d",&t);
if(s[binarySearch(s,t,n)] == t)sum++;
}
printf("%d\n",sum);

return 0;
}

int binarySearch(int *a,int key,int n){
int left = 0;
int right = n;
int mid;

while(left < right){
  mid = (left + right)/2;
  if(a[mid] == key) return mid;
  else if (key < a[mid]) {
    right = mid;
  }
  else {
    left = mid + 1;
  }
}
return 0;
}



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

const int MAXN = 200005;
const int MOD = 1000000007;

int n, c[MAXN], a[MAXN], dp[MAXN];

int main(){
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
		scanf("%d", &c[i]);
		
	for(int i = n; i >= 0; i--){
		if(i == n)dp[i] = 1;
		else{
			if(i + 1 == n || c[i + 1] != c[i])a[c[i]] = (a[c[i]] + dp[i + 1]) % MOD;
			dp[i] = a[c[i]];
		}
	}
	printf("%d\n", dp[0]);
		
	return 0;
}


Measured memory_bytes: 6164
import math

n = int(input())
end = math.ceil((-1 + (1 + 8 * n)**(0.5)) / 2)
ans = [j for j in range(1,end+1)]
sum_to_end = ( end ** 2 + end ) // 2

if sum_to_end != n:
    ans.remove(sum_to_end - n)

print(*ans, sep = "\n")

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

#define itn int
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

using namespace std;

inline int nxt() {
	int x;
	scanf("%d", &x);
	return x;
}

int main() {
	int n = nxt();
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		a[i] = nxt();
	}

	long long l = 2, r = 2;
	reverse(all(a));
	for (int x : a) {
		l = (l + x - 1) / x;
		r = r / x;
		if (l > r) {
			puts("-1");
			return 0;
		}

		l *= x;
		r = r * x + x - 1;
	}

	cout << l << " " << r << "\n";

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int> ;
using vi = vector<int> ;
using vll = vector<long long>;

int main(){
  int n; cin >> n;
  string s; cin >> s;

  if(n % 2 != 0){
    cout << "No" << endl;
  }
  else{
    string t = s.substr(0, n/2);
    t = t+t;
    if(s == t){cout << "Yes" << endl;}
    else{cout << "No" << endl;}
  }
}


Measured memory_bytes: 256
#include <stdio.h>

#define ARR_LIMIT 10000

void InputNumber(int* number, int limitLow, int limitHigh);
void Get(int* numArr, int size, int* minimum, int* maximum, long* sum);

int main(void) {
    int n;
    int idx;
    int numArr[ARR_LIMIT];

    int minimum;
    int maximum;
    long sum;

    InputNumber(&n, 1, 10000);

    for (idx = 0; idx < n; idx++) {
        InputNumber(&numArr[idx], -1000000, 1000000);
    }

    Get(numArr, n, &minimum, &maximum, &sum);

    printf("%d %d %ld\n", minimum, maximum, sum);
}

void InputNumber(int* number, int limitLow, int limitHigh) {
    int x;
    do {
        scanf("%d", &x);
    } while(x < limitLow || x> limitHigh);
    *number = x;
}

void Get(int* numArr, int size, int* minimum, int* maximun, long* sum) {
    int min = *numArr;
    int max = *numArr;
    long su = *numArr++;
    int idx;

    for (idx = 1; idx < size; idx++) {
        int curNum = *numArr;

        if (curNum < min) {
            min = curNum;
        }

        if (curNum > max) {
            max = curNum;
        }

        su += curNum;

        numArr++;
    }

    *minimum = min;
    *maximun = max;
    *sum = su;
}


Measured memory_bytes: 2108
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <sstream>

using namespace std;


#define exp 5*1E15

signed main()
{
	string s;
	long long x;
	cin >> s >> x;

	if (x == 1)
	{
		cout << s[0] << "\n";
		return 0;
	}
	
	int curchar = 0;
	if (s[curchar] != '1')
	{
		cout << s[curchar] << "\n";
		return 0;
	}

	while (curchar+1 != x)
	{
		curchar++;
		if (s[curchar] != '1')
		{
			cout << s[curchar] << "\n";
			return 0;
		}
	}
	cout << 1 << "\n";


	
}

Measured memory_bytes: 256
s = input()
k = int(input())
key = s[0]
count = 1
sum_count = 0
list1=[]
ans = 0
ans2 =0
for i in range(1,len(s)):
    if key == s[i]:
        count += 1
    else:
        list1.append(count)
        count = 1
        key = s[i]
list1.append(count)
if len(list1) == 1:
    print(list1[0]*k//2)
elif s[0] == s[len(s)-1]:
    ans += (list1[0]+list1[len(list1)-1])//2*(k-1)
    for i in range(1,len(list1)-1):
        ans2 += list1[i]//2
    print(ans2*k+ans+list1[0]//2+list1[len(list1)-1]//2)
else:
    for i in range(len(list1)):
        ans += list1[i]//2
    print(ans*k)

Measured memory_bytes: 3192
import java.util.*;

public class Main {

	char [] []table = {
			{},
			{'.', ',', '!', '?', ' '},
			{'a', 'b','c'},
			{'d', 'e', 'f'},
			{'g', 'h', 'i'},
			{'j', 'k', 'l'},
			{'m', 'n', 'o'},
			{'p', 'q','r','s'},
			{'t', 'u', 'v'},
			{'w','x','y','z'},
	};

	private void doit() {
		Scanner sc = new Scanner(System.in);
		int dataset = sc.nextInt();
		while(dataset-- > 0){
			String s = sc.next();
			StringBuilder sb = new StringBuilder();
			int len = s.length();
			int now = -1, ind = -1;
			for(int i = 0; i < len; i++){
				if(s.charAt(i) == '0'){
					if(now != -1){
						sb.append(table[ind][now]);
						now = -1;
					}
				}
				else{
					ind = s.charAt(i) - '0';
					now = (now + 1) % table[ind].length;
				}
			}
			System.out.println(sb.toString());
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

Measured memory_bytes: 21524
(function main( input )
{
  var lines = input.trim().split('\n');
  
  lines.map(Number).sort( function(a,b){ return b-a; } ).slice( 0, 3 ).forEach( function(v){ console.log(v); } );
})( require('fs').readFileSync( '/dev/stdin', 'utf8' ) );

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

int main() {
    int n;
    string s, t;
    cin >> n >> s >> t;

    for (int i = 0; i < n; i++) {
        cout << s.at(i) << t.at(i);
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  long long int a,b,c,d=0,f,g,h;
  cin>>a>>b;
  cout<<(a-1)*(b-1);
}

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

namespace ACTest
{
    class AOJ500
    {
        static void Main(string[] args)
        {
            int num = 1;
            int[] totalScore = new int[2];
            int[] roundScore = new int[2];
            while (num != 0)
            {
                totalScore = Enumerable.Repeat<int>(0, 2).ToArray();
                //int[,] roundScore = new int[num, 2];

                num = int.Parse(Console.ReadLine());
                for (int i = 0; i < num; i++)
                {
                    ///totalScore = Enumerable.Repeat<int>(0, 2).ToArray();
                    string[] input = Console.ReadLine().Split(' ');
                    roundScore[0] = int.Parse(input[0]);
                    roundScore[1] = int.Parse(input[1]);
                    if (roundScore[0] > roundScore[1])
                    {
                        totalScore[0] += roundScore[0] + roundScore[1];
                    }
                    else if (roundScore[0] < roundScore[1])
                    {
                        totalScore[1] += roundScore[0] + roundScore[1];
                    }
                    else
                    {
                        totalScore[0] += roundScore[0];
                        totalScore[1] += roundScore[1];
                    }


                }
                if (num != 0)
                {
                    Console.WriteLine(totalScore[0] + " " + totalScore[1]);
                }
                
            }
            //while (true) ;
        }

    }
}

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

int main(){
    int N, T;
    int c, t, a;
    a = 2000;

    cin >> N >> T;

    for(int i = 0; i < N; i++){
        cin >> c >> t;
        if(t <= T && c < a){
            a = c;
        }
    }
    if(a == 2000){
        cout << "TLE" << endl;
    }else{
        cout << a << endl;
    }

    return 0;
}



Measured memory_bytes: 256
from collections import deque
N = int(input())
H = list(map(int, input().split()))
q = deque(H)
min = q.pop()
flag=True
for _ in range(N-1):
    r = q.pop()
    if min >= r:
        min = r
    elif r-min == 1:
        continue
    else:
        print('No')
        flag=False
        break
if flag:
    print('Yes')
    


Measured memory_bytes: 14780
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#define MAX_N 300007

long long N, sum;
long long a[MAX_N];

inline long long aabs (long long x) {return x < 0 ? -x : x;}

int main () {
    scanf("%lld", &N);
    for (int i = 1;i <= N; ++i) scanf("%lld", a + i), a[i] -= i;
    std::sort(a + 1, a + N + 1);
    for (int i = 1;i <= N; ++i)
        sum += aabs(a[i] - a[N / 2 + 1]);
    printf("%lld\n", sum);
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

int main(){

    int n, t;
    cin >> n >> t;
    vector<pair<int, int>> v(n);
    REP(i,n){
        cin >> v[i].first >> v[i].second;
    }

    int result=65535;

    REP(i,n){
        if(v[i].second<=t){
            result = min(result, v[i].first);
        }
    }

    if(result==65535){
        cout << "TLE" << endl;
    }else{
        cout << result << endl;
    }

    return 0;
}

Measured memory_bytes: 1016
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
#define pb push_back
const int MOD=1e9+7;
const int INF=1e15;


signed main(){
    int N;cin>>N;
    vector<int>A(N);
    map<int,int>memo;
    REP(i,N){
        cin>>A[i];
        memo[A[i]]++;
    }
    sort(A.rbegin(),A.rend());
    int M=A[0]/2;
    vector<int>B(N);
    B=A;
    REP(i,N){
        B[i]=abs(A[i]-M);
    }
    sort(B.begin(),B.end());
    if(memo[B[0]+M]>=2||(memo[B[0]+M]==1&&A[0]!=B[0]+M))cout<<A[0]<<" "<<B[0]+M<<endl;
    else cout<<A[0]<<" "<<abs(B[0]-M)<<endl;
}

Measured memory_bytes: 8064
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  char op;
  int n,t;
  cin >> n;
  while(true){
    cin >> op;
    if(op == '=') break;
    else {
      cin >> t;
      if(op == '+') n = n + t;
      if(op == '-') n = n - t;
      if(op == '*') n = n * t;
      if(op == '/') n = n / t;
    }
  }
  cout << n << endl;
  return 0;
}

Measured memory_bytes: 1164
import itertools

n=int(input())
xlist=[]
ylist=[]
z=[]
kyori=0
for i in range(n):
  a=[]
  a=list(map(int,input().split()))
  xlist.append(a[0])
  ylist.append(a[1])
  z.append(i)
for v in itertools.permutations(z):
  for i in range(1,n):
    kyori += ((xlist[v[i-1]]-xlist[v[i]])**2+(ylist[v[i-1]]-ylist[v[i]])**2)**0.5
print(kyori/len(list(itertools.permutations(z))))
    
    
    
    
    



Measured memory_bytes: 8052
ans = []
4.times do
    ans << [("0"*10).split(""),("0"*10).split(""),("0"*10).split("")]
end

n = gets.to_i
n.times do
  a,b,c,d = gets.split.map(&:to_i)
  ans[a-1][b-1][c-1]  = (d + (ans[a-1][b-1][c-1]).to_i).to_s
end

ctn = 0
ans.each do |arr|
  puts " " + arr[0].join(" ")
  puts " " +arr[1].join(" ")
  puts " " +arr[2].join(" ")

  puts "####################" if ctn <= 2
  ctn += 1
end


Measured memory_bytes: 6900
#2019/10/22
x, y = map(int, open(0).read().split())
# print(x,y)
list_a = [1,3,5,7,8,10,12]
list_b = [4,6,9,11]
if ((x in list_a) and (y in list_a)) or ((x in list_b) and (y in list_b)):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 2940
#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 getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#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 ll inf =1LL << 62;
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) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int n; cin >> n;
    vll a(n); for(auto& e : a) cin >> e;

    ll cur = a[0];
    int r = 1;

    ll res = 0LL;
    rep(l, n){
        while(r < n and (cur & a[r]) == 0LL){
            cur |= a[r];
            r++;
        }
        res += r - l;

        cur &= ~a[l];
    }

    cout << res << endl;

    return 0;
}


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

using namespace std;
 
int main() {
  int n;
  int m;
  int a;
  cin >> n;
  cin >> m;
  vector<int> vct(n);
  for(int i=0;i<2*m;i++){
    cin >>a;
    vct[a-1]++;
  }
  
  for(int i=0;i<n;i++){
        cout <<vct[i]<<endl;  
  }



  }     



Measured memory_bytes: 3580
#pragma GCC optimize("Ofast")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

ll N, Q;
vector<vector<int>> path;
vector<int> parent,pl;

void dfs(int pos, int prev) {
	if(prev !=-1)pl[pos] += pl[prev];
	for (int i = 0; i < path[pos].size(); i++) {
		if (path[pos][i] != prev) {
			dfs(path[pos][i], pos);
		}
	}
}

int main() {
	cin >> N >> Q;
	path = vector<vector<int>>(N+1, vector<int>());
	parent = pl = vector<int>(N + 1, 0);

	for (int i = 0; i < N - 1; i++) {
		ll a, b;
		cin >> a >> b;
		path[a].push_back(b);
		path[b].push_back(a);
	}
	for (int i = 0; i < Q; i++) {
		int p, x;
		cin >> p >> x;
		pl[p] += x;
	}

	dfs(1, -1);
	for (int i = 0; i < N; i++) {
		if (i != N - 1)cout << pl[i + 1] << " ";
		else cout << pl[i+1] << endl;
	}

}

Measured memory_bytes: 21120
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <cstdlib>
#include <cmath>
#include <functional>

#define INF 1000000000000000000
using namespace std;
typedef long long ll;


int main() {
	ll w,v;
	int n;
	vector<ll> V[4];
	ll W;
	vector<ll> ans[4];
	ll A = 0;
	cin >> n >> W;
	cin >> w >> v;
	const ll w1 = w;
	V[0].push_back(v);
	for (int i = 1; i < n; i++) {
		cin >> w >> v;
		int idx = (int)(w - w1);
		V[idx].push_back(v);
	}
	for (int i = 0; i < 4; i++) {
		sort(V[i].begin(), V[i].end(),greater<long long>());
	}
	
	for (int i = 0; i < 4; i++) {
		ans[i].push_back(0);
		for (unsigned int j = 0; j < V[i].size(); j++) {
			ans[i].push_back(ans[i][j] + V[i][j]);
		}
	}

	for (unsigned int i0 = 0; i0 <= V[0].size(); i0++) {
		for (unsigned int i1 = 0; i1 <= V[1].size(); i1++) {
			for (unsigned int i2 = 0; i2 <= V[2].size(); i2++) {
				for (unsigned int i3 = 0; i3 <= V[3].size(); i3++) {
					if (W >= w1 * (i0 + i1 + i2 + i3) + (i1 + 2 * i2 + 3 * i3)) {
						A = max(A, ans[0][i0] + ans[1][i1] + ans[2][i2] + ans[3][i3]);
					}
				}
			}
		}
	}
	cout << A << endl;

	return 0;
}

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

using namespace std;

#define ll long long
#define ld long double
#define pll pair <ll , ll>

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair

#define X first
#define Y second

#define LB(x) ((x) & -(x))
#define BIT(a , b) (((a)>>(b)) & 1)

const ll MAXN=2e5+10;
const ll Mod=1e9+7;

vector <ll> w;

pll a[MAXN];

ll b[MAXN];
ll e[MAXN];
ll dp[MAXN];
ll ps[MAXN];
ll pm[MAXN];
ll sm[MAXN];

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

	ll n;
	cin>>n;

	for(ll i=1;i<=n;i++)
    {
        cin>>a[i].X>>a[i].Y;
        w.pb(a[i].Y);
    }

    sort(a+1 , a+n+1);

    sort(w.begin() , w.end());
    w.resize(unique(w.begin() , w.end())-w.begin());

    for(ll i=1;i<=n;i++)
    {
        b[i]=lower_bound(w.begin() , w.end() , a[i].Y)-w.begin()+1;
    }

    for(ll i=1;i<=n;i++)
    {
        pm[i]=max(pm[i-1] , b[i]);
    }

    sm[n+1]=n+1;

    for(ll i=n;i>=1;i--)
    {
        sm[i]=min(sm[i+1] , b[i]);
    }

    dp[0]=1;
    ps[0]=1;

    for(ll i=1;i<=n;i++)
    {
        e[i]=e[i-1];

        while (pm[e[i]]+1<sm[i+1])
        {
            e[i]++;
        }

        dp[i]=ps[i-1]-(e[i]>=2 ? ps[e[i]-2] : 0)+(sm[i+1]==1)+Mod;
        dp[i]%=Mod;

        ps[i]=ps[i-1]+dp[i];
        ps[i]%=Mod;
    }

    cout<<dp[n];
}


Measured memory_bytes: 14448
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <math.h>
#include <sstream>
#include <deque>
#include <string>
#include <cctype>
#include <cstring>
#include <cstdio>
const int M = 1e9 + 7;
#define ll long long int
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
using namespace std;


int main()
{
    fastio

    ll n;
    cin>>n;

    ll a=0,b=0,c=0,d=0;

    while(n--)
    {
        string s;
        cin>>s;

        if(s=="AC")
        {
            a++;
        }

        if(s=="WA")
        {
            b++;
        }

        if(s=="TLE")
        {
            c++;
        }

        if(s=="RE")
        {
            d++;
        }




    }

    cout<<"AC"<<" "<<"x"<<" "<<a<<"\n";
     cout<<"WA"<<" "<<"x"<<" "<<b<<"\n";
      cout<<"TLE"<<" "<<"x"<<" "<<c<<"\n";
       cout<<"RE"<<" "<<"x"<<" "<<d<<"\n";


        




 


       


 

        return 0;
    }

Measured memory_bytes: 3648