akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define mod 1000000007
#define INF 1000000000
#define LLINF 2000000000000000000LL

#define SIZE 100000

int x2[7] ={0,1,2,4,8,16,32};
int mo[5] = {0,-1,0,1,0};
int mo8[9] = {0,1,1,-1,1,0,-1,-1,0};

int main(){
    int w,h,n;
    int sx,sy;
    int l,px,py;
    int mm[50][20][20]={0};
    int visit[50][20][20][32]={0};
    int bumb_x[5],bumb_y[5];
    
    scanf("%d%d%d%d%d",&w,&h,&n,&sx,&sy);
    
    sx--;
    sy--;
    
    for(int i=0;i<n;i++){
        scanf("%d",&l);
        
        for(int j=0;j<l;j++){
            scanf("%d%d",&px,&py);
            
            px--;
            py--;
            
            if(j<l-1){
                mm[j][py][px] |= 1 << i;
            }else{
                bumb_x[i] = px;
                bumb_y[i] = py;
            }
        }
    }
    
    queue<pair<int,pair<int,int> > > q1;
    
    q1.push({mm[0][sy][sx],{sx,sy}});
    
    for(int i=0;i<=h+w+3;i++){
        queue<pair<int,pair<int,int> > > q2;
        
        //cerr << i << endl;
        
        while(q1.size()){
            pair<int,pair<int,int> > p = q1.front();
            q1.pop();
            
            int nowv = p.first;
            int nowx = p.second.first;
            int nowy = p.second.second;
            
            //cerr << nowv << " " << nowx << " " << nowy << endl;
            
            bool flag = false;
            
            for(int j=0;j<n;j++){
                if(bumb_x[j] == nowx && bumb_y[j] == nowy) flag = true;
            }
            
            if(flag) continue;
            
            if(visit[i][nowx][nowy][nowv]) continue;
            visit[i][nowx][nowy][nowv] = true;
            
            if(nowv == (1<<n)-1){
                printf("%d\n",i);
                return 0;
            }
            
            for(int j=0;j<8;j++){
                int tox = nowx+mo8[j];
                int toy = nowy+mo8[j+1];
                
                if(0<=tox && tox<w && 0<=toy && toy<h)
                    q2.push({nowv|mm[i+1][toy][tox],{tox,toy}});
            }
            
            q2.push({nowv|mm[i+1][nowy][nowx],{nowx,nowy}});

        }
        
        q1 = q2;
    }
    
    puts("-1");
    
    return 0;
}

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

using namespace std;

typedef struct block{
 int s, e, x;
}block;

bool cmp(block a, block b){
    if(a.x == b.x){
        return a.s < b.s;
    }
    return a.x < b.x;
}

const int N = 1000 * 100 * 2 + 7;

int sgTree[N * 4];
block blocks[N];
int pessoas[N];
    int n, q;
void build(int id, int l, int r){
    if(l == r){
        sgTree[id] = 1e9;
        return;
    }
    sgTree[id] = 1e9;
    int m = (l + r)/2;
    build(id * 2, l, m);
    build(id * 2 + 1, m + 1, r);
}

void update(int id, int l, int r, int x, int y, int v){
    if(x <= l && r <= y){
        sgTree[id] = min(sgTree[id], v);
    }else if(l > y || r < x){
        return;
    }else{
        int m = (l + r) / 2;
        sgTree[id * 2] = min(sgTree[id], sgTree[id * 2]);
        sgTree[id * 2 + 1] = min(sgTree[id], sgTree[id * 2 + 1]);
        update(id * 2, l, m, x, y, v);
        update(id * 2 + 1, m + 1, r, x, y, v);
    }
}

int leftmost(int val){
    int ini = 1, fim = q;
    int ret = q + 1;
    while(ini <= fim){
        int m = (ini + fim)/2;
        if(val <= pessoas[m]){
            ret = min(ret, m);
            fim = m - 1;
        }else{
            ini = m + 1;
        }
    }
    return ret;
}

int rightmost(int val){
    int ini = 1, fim = q;
    int ret = 0;
    while(ini <= fim){
        int m = (ini + fim)/2;
        if(val > pessoas[m]){
            ret = max(ret, m);
            ini = m + 1;
        }else{
            fim = m -1;
        }
    }
    return ret;
}

int query(int id, int l, int r, int pos){
    if(l == r){
        return sgTree[id];
    }
    int m = (l + r) / 2;
    sgTree[id * 2] = min(sgTree[id], sgTree[id * 2]);
    sgTree[id * 2 + 1] = min(sgTree[id], sgTree[id * 2 + 1]);
    if(pos <= m){
        return query(id * 2, l, m, pos);
    }else{
        return query(id * 2 + 1, m + 1, r, pos);
    }
}

int main(){
    scanf("%d %d", &n, &q);
    for(int i = 0; i < n; i++){
        scanf("%d %d %d", &blocks[i].s, &blocks[i].e, &blocks[i].x);
    }
    sort(blocks, blocks + n, cmp);

    for(int i = 1; i <= q; i++){
        scanf("%d", &pessoas[i]);
    }
    build(1, 1, q);
    for(int i = 0; i < n; i++){
        int idx = leftmost(blocks[i].s - blocks[i].x);
        int idy = rightmost(blocks[i].e - blocks[i].x);
        if(idx > idy)continue;
        update(1, 1, q, idx, idy, blocks[i].x);
    }

    for(int i = 1; i <= q; i++){
        printf("%d\n", query(1, 1, q, i) == 1e9 ? -1 : query(1, 1, q, i));
    }
    return 0;
}

Measured memory_bytes: 8064
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<numeric>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)
#define INF 1000000000
#define MOD 1000000007
typedef  long long ll;
using namespace std;

ll conv(ll n,ll r){
    if(r == 0 || n==r){
        return 1;
    }
    return conv(n-1,r)+conv(n-1,r-1);
}

int a[15][29];

void solve(void){
    ll l,r;
    cin >> l >> r;
    ll la = l%2019;
    ll ra = r%2019;
    bool flag = false;
    ll l3 = l/3,r3 = r/3;
    ll l673 = l/673,r673 = r/673;
    if( r3-l3 > 0 && r673-l673>0) flag = true;
    ll ans = 1000000;
    ll tmp;
    if(flag){
        cout << 0 << endl;
    }else{
        for(int i = la;i < ra;i++){
            for(int j = i+1;j < ra+1;j++){
                tmp = i*j%2019;
                ans = min(ans,tmp);
            }
        }
        cout << ans << endl;
    }

}


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



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n);
	std::vector<int> x(n);
	std::vector<std::vector<int>> g(n);
	for(int i = 1; i < n; i++) {
		int p; scanf("%d", &p);
		
		g[p - 1].push_back(i);
	}
	for(int i = 0; i < n; i++) scanf("%d", &x[i]);
	
	std::function<void (int&, int)> chmin = [](int& v, int x) {
		if(v == -1) {
			v = x;
			return;
		}
		if(x == -1) return;
		v = std::min(v, x);
	};
	
	bool ans = true;
	const int INF = -1;
	auto dp = make_v<int>(n, 2);
	std::function<void (int)> solve = [&](int v) {
		if(!ans) return;
		for(auto e: g[v]) solve(e);
	
		if(g[v].size() == 0) {
			dp[v][0] = dp[v][1] = 0;
			return;
		}
		for(int color = 0; color < 2; color++) {
			auto dp2 = make_v<int>(g[v].size() + 1, x[v] + 1);
			for(int i = 0; i < dp2.size(); i++) {
				for(int j = 0; j < dp2[i].size(); j++) dp2[i][j] = INF;
			}
			dp2[0][0] = 0;
			
			for(int i = 0; i < g[v].size(); i++) {
				int e = g[v][i];
				for(int j = 0; j < dp2[i].size(); j++) {
					if(dp2[i][j] == INF) continue;

					{
						if(j + x[e] <= x[v]) {
							chmin(dp2[i + 1][j + x[e]], dp2[i][j] + dp[e][color]);
						}
					} {
						if(j + dp[e][1 - color] <= x[v]) {
							chmin(dp2[i + 1][j + dp[e][1 - color]], dp2[i][j] + x[e]);
						}
					}
				}
			}
			
			int ret = 1 << 30;
			for(int i = 0; i <= x[v]; i++) chmin(ret, dp2[g[v].size()][i]);
			if(ret == (1 << 30)) {
				ans = false;
				return;
			}
			dp[v][color] = ret;
		}
	};
	solve(0);
	
	if(ans) printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");
	return 0;
}


Measured memory_bytes: 1344
def main():
    DOUBLING_ROWS = 60  # 2**60 > 10**18
    n, k = [int(x) for x in input().split()]
    table = []  # [start][teleporting]
    table_append = table.append
    table_append([int(x) - 1 for x in input().split()])  # 2**0 teleport
    for _ in range(DOUBLING_ROWS):
        pre = table[-1]
        table_append([pre[x] for x in pre])
    now = 0
    for i, row in enumerate(table):
        if ((1 << i) & k) > 0:
            now = row[now]
    return now + 1


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 113836
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int main()
{
	int N,ans=200000;
	char s[300000];
	int a[200000],b[200000];
	
	cin >> N;
	cin >> s;
	
	if(s[0]=='.')a[0] = 1;
	if(s[N-1]=='#')b[N-1] = 1;
	
	for(int i=1;i<N;i++){
		if(s[i]=='.')a[i] =  a[i-1]+1;
		else a[i] = a[i-1];
		
		if(s[N-i-1]=='#')b[N-i-1] = b[N-i]+1;
		else b[N-i-1] = b[N-i];
	}
	
	for(int i=0;i<N;i++){
		if( ans > N - a[i] - b[i])ans = N - a[i] - b[i];
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ld(a) while(a--)
#define tci(v,i) for(auto i=v.begin();i!=v.end();i++)
#define tcf(v,i) for(auto i : v)
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator
#define INF 		0x3f3f3f3f
#define LLINF       1000111000111000111LL
#define PI 			3.14159265358979323
#define endl '\n'
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
const int N=1000006;
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef tuple<int,int,int> iii;
typedef set<int> si;
typedef complex<double> pnt;
typedef vector<pnt> vpnt;
typedef priority_queue<ii,vii,greater<ii> > spq;
const ll MOD=1000000007LL;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
template<typename T> T power(T x,T y,ll m=MOD){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}
int32_t main(){
	int n; cin>>n;
	vi v;
	int sum=0,ct=0;
	rep(i,0,n){
		int x; cin>>x;
		sum+=x;
		if(x%10==0){
			++ct;
		}
		else v.eb(x);
	}
	sort(all(v));
	if(v.size()==0){
		cout<<"0"; return 0;
	}
	if(sum%10!=0) cout<<sum;
	else cout<<sum-v[0];
}



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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);


int main(){
  int N,Z,W;
  cin >> N >> Z >> W;
  vector<int> a(N);
  REP(i,N)cin >> a[i];

  if(N==1){
    cout << abs(a[N-1]-W) << endl;
  }else{
    cout << max(abs(a[N-1]-W), abs(a[N-2]-a[N-1])) << endl;
  }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  cin >> H >> W;

  vector<char> row(H),col(W);
  vector<vector<char>> mae(H, vector<char>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> mae.at(i).at(j);
      if(mae.at(i).at(j)=='#') {
        row.at(i)=1;
      }
    }
  }    

  for(int i=0;i<W;i++){
    for(int j=0;j<H;j++){
      if(mae.at(j).at(i)=='#') {
        col.at(i)=1;
      }
    }
  }  
 
  bool flag;
  
  for(int i=0;i<H;i++){
    flag=false;
    for(int j=0;j<W;j++){   
      if(row.at(i)==1&&col.at(j)==1) {
        flag=true;
        cout << mae.at(i).at(j);
      }
    }
    if(flag)cout<<endl;
  } 
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
flag = 0
check_ans = 0
check_in = 0
x = 1

if n == 1:
    if a[0] == 0:
        print(1)
    else:
        print(0)
elif n % 2 == 0:
    for i in range(n):
        check_ans += 2 * x - 1
        check_in += a[i]
        if check_ans != check_in:
            flag = 1
            print(0)
            break
        if i % 2 == 1:
            x += 1
    if flag == 0:
        print((2**int(n/2)) % (10**9+7))
else:
    for i in range(1, n):
        check_ans += 2 * x
        check_in += a[i]
        if check_ans != check_in:
            flag = 1
            print(0)
            break
        if i % 2 == 0:
            x += 1
    if flag == 0:
        print((2**int((n-1)/2)) % (10**9+7))


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

fn main() {
    let n: usize = read();
    let a: Vec<i64> = (0..n).map(|_| read()).collect(); 

    let mut ans: i64 = 1 << 60;
    let mut rui: Vec<i64> = vec![0; n+1];
    for i in 0..n {
        rui[i+1] = a[i] + rui[i];
    }

    for i in 0..n {
        let l = rui[i+1];
        let r = rui[n] - l;
        let d = if l < r {r-l} else {l-r};
        ans = std::cmp::min(ans, d);
    }
    println!("{}", ans);
}

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


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

public class Main
{
    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok;

    public void go() throws IOException
    {
        ntok();
        int n = ipar();
        int[][] mat = new int[n][n-1];
        for (int i = 0; i < n; i++)
        {
            ntok();
            for (int e = 0; e < n-1; e++)
            {
                mat[i][e] = ipar()-1;
            }
        }
        int left = n * (n-1);
        LinkedList<State> queue = new LinkedList<>();
        for (int i = 0; i < n; i++)
        {
            queue.add(new State(i, 1));
        }
        int day = 0;
        HashSet<Integer> play = new HashSet<>();
        int[] pIndex = new int[n];
        HashSet<State> visited = new HashSet<>();
        while (!queue.isEmpty())
        {
            State curr = queue.remove();
            if (visited.contains(curr))
            {
                continue;
            }
            visited.add(curr);
            if (curr.day != day)
            {
                day++;
                for (int x : play)
                {
                    pIndex[x]++;
                    left--;
                }
                play.clear();
            }
            if (pIndex[curr.p] == n-1)
            {
                continue;
            }
            int opp = mat[curr.p][pIndex[curr.p]];
            if (pIndex[opp] == n-1)
            {
                continue;
            }
            if (mat[opp][pIndex[opp]] == curr.p)
            {
                queue.add(new State(curr.p, curr.day+1));
                queue.add(new State(opp, curr.day+1));
                play.add(curr.p);
                play.add(opp);
            }
        }
        if (left == 0)
        {
            out.println(day-1);
        }
        else
        {
            out.println(-1);
        }

        out.flush();
        in.close();
    }

    private class State
    {
        int p, day;
        
        public State(int p, int day)
        {
            this.p = p;
            this.day = day;
        }

        public int hashCode()
        {
            return p + day * 1000;
        }

        public boolean equals(Object obj)
        {
            if (obj instanceof State)
            {
                State other = (State)obj;
                return other.p == p && day == other.day;
            }
            return false;
        }
    }

    public void ntok() throws IOException
    {
        tok = new StringTokenizer(in.readLine());
    }

    public int ipar()
    {
        return Integer.parseInt(tok.nextToken());
    }

    public long lpar()
    {
        return Long.parseLong(tok.nextToken());
    }

    public double dpar()
    {
        return Double.parseDouble(tok.nextToken());
    }

    public String spar()
    {
        return tok.nextToken();
    }

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


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

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

  int ans_even = n*(n-1)/2;
  int ans_odd = (m)*(m-1)/2;
  
  cout << ans_even + ans_odd << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <complex>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
typedef pair<int,int> P;
vector<P> e,f;
int main(){
	int N,W,H,inf=1e9;
	cin>>N>>W>>H;
	int a=inf,b=0,c=inf,d=0;
	rep(i,N){
		int x,y,w;
		cin>>x>>y>>w;
		e.pb(P(max(0,x-w),min(W,x+w)));
		f.pb(P(max(0,y-w),min(H,y+w)));
	}
	sort(all(e));
	sort(all(f));
	int r=0;
	bool ok=false;
	bool can=true;
	rep(i,N){
		if(r<e[i].fs) can=false;
		else r=max(r,e[i].sc);
	}
	if(can&&r==W) ok=1;
	r=0;
	can=true;
	rep(i,N){
		if(r<f[i].fs) can=false;
		else r=max(r,f[i].sc);
	}
	if(can&&r==H) ok=1;
	if(ok) puts("Yes");
	else puts("No");
}

Measured memory_bytes: 2904
A, B = map(int, input().split())

count = 0
for i in range(A // 10000, B // 10000 + 1):
    for j in range(0, 10):
        for k in range(0, 10):
            t = i * 10000 + j * 1000 + k * 100 + j * 10 + i
            if A <= t <= B:
                count += 1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define itn int
#define nibu(K,x) binary_search(K.begin(),K.end(),x)
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define si(x) x.size()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define out(x) cout<<x<<endl
#define in(x) cin>>x
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
using ll = long long;
using pll = pair<ll,ll>;
using psi = pair<string,int>;
using pis = pair<int,string>;
using vl = vector<ll>;
using vs = vector<string>;

int main() {
	string S;
  in(S);
  int N = si(S);
  bool f = true;
  if(S[0] != 'A') f = false;
  int count =0;
  for(int i=2;i<N-1;i++){
    if(S[i] =='C') count++;
  }
  if(count != 1) f = false;
  vector<char>  E = {'A','C','q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m'};
  for(int i=0;i<N;i++){
    bool g = false;
   for(int j=0;j<28;j++){
    if(S[i] == E[j]) g = true; 
   }
    if(g == false) f = false;
  }
  if(f) out("AC");
  else out("WA");
}

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

void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}

signed main() {
    int N;
    cin >> N;
    vector<vector<int>> adj(N);
    for (int i = 0; i < N; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int lglg;
            cin >> lglg;
            adj[i].push_back(lglg - 1);
        }
    }
    queue<int> q;
    vector<bool> visited(N);
    vector<int> distance(N);
    visited[0] = true;
    distance[0] = 0;
    q.push(0);
    while (!q.empty()) {
        int s = q.front();
        q.pop();
        // process node s
        for (auto u : adj[s]) {
            if (visited[u]) continue;
            visited[u] = true;
            distance[u] = distance[s] + 1;
            q.push(u);
        }
    }
    REP(i, N) {
        if (i != 0 && distance[i] == 0) {
            cout << i + 1 << " " << -1 << endl;
            continue;
        }
        cout << i + 1 << " " << distance[i] << endl;
    }
}


Measured memory_bytes: 3172
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        sc.close();

        // 作れる最大値
        int max = n - 2;
        if (n >= 3) {
            max += (n - 3) * (n - 2) / 2;
        }
        if (max < k) {
            // 可能より多く作らなくてはならない
            System.out.println(-1);
            return;
        }
        int del = k - max;
        int path = n - 1 - del;
        System.out.println(path);
        p(1, 2);
        for (int i = 3; i <= n; i++) {
            // 先にpathを構成して消していく
            p(2, i);
        }
        int count = 0;
        if (count == -del) {
            return;
        }
        for (int i = 3; i <= n; i++) {
            for (int j = i + 1; j <= n; j++) {
                p(i, j);
                count++;
                if (count == -del) {
                    return;
                }
            }
        }
        for (int i = 3; i <= n; i++) {
            p(1, i);
            count++;
            if (count == -del) {
                return;
            }
        }
    }

    static void p(int a, int b) {
        System.out.println(a + " " + b);
    }
}


Measured memory_bytes: 24020
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include <iomanip>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  string S;
  cin>>S;
  int count=0;
  for(int i=0;i<4;i++){
    if(S[i]=='2') count++;
  }
  cout<<count;
return 0;}


Measured memory_bytes: 3624
import itertools
import math

N = int(input())
town = list(itertools.permutations(range(N)))
dis = []
for i in range(N):
    s = tuple(map(int,input().split()))
    dis.append(s)
    
ans = 0
for i in town:
    for j in range(len(i)-1):
        calc =  math.sqrt((dis[i[j]][0]-dis[i[j+1]][0])**2 + (dis[i[j]][1]-dis[i[j+1]][1])**2) 
        ans += calc
    
print(ans/len(town))

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

using namespace std;

typedef long long ll;

int main () {
  int n;
  string s;
  cin >> n >> s;
  s.push_back('#');
  int ans = 0;
  for (int i = 0; i + 1 < s.size(); ++i) {
		if (s[i] != s[i + 1]) {
			++ans;
		}
	}
	cout << ans;
}


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

int main(){
    int n, x;
    
    cin >> n;
    
    for(int i = 1; i <= n; i++){
        if(i % 3 == 0){
            cout << " " << i;
        }
        else{
            x = i;
            while(x > 0){
                if(x % 10 == 3){
                    cout << " " << i;
                    break;
                }
                else{
                    x /= 10;
                }
            }
        }
    } 
    cout << endl;
}


Measured memory_bytes: 3116
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int total = 1;
		int bs = 1;
		for (int i = 0; i < n; i++) {
			int b = sc.nextInt();
			if (b % 2 == 0) {
				bs *= 2;
			}
			total *= 3;
		}
		System.out.println(total - bs);
	}
}


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

int main() {
  int n,ac=0,wa=0,tle=0,re=0;
  cin>>n;
  string s;
  for (int i=0;i<n;i++){
    cin>>s;
    if (s=="AC") ac++;
    if (s=="WA") wa++;
    if (s=="TLE") tle++;
    if (s=="RE") re++;
  }
  cout<<"AC x "<<ac<<endl;
  cout<<"WA x "<<wa<<endl;
  cout<<"TLE x "<<tle<<endl;
  cout<<"RE x "<<re<<endl;
  return 0;
}

Measured memory_bytes: 3624
/*
String[]の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
負の数の割り算は絶対値が小さいほうに切り捨てられるex.-1/2=0ので、ある値>kみたいな式だとバグらせやすいので注意
ある値>=kとして、切り上げた値をとるべき
toLowerCase()はアルファベット以外に対して行ってもエラーにはならない
ArrayDequeではpopとpushはStackと同じ操作になる
//import static java.lang.System.*; はしばらく使わなそう(使うとしてもexit(0)のためだけ)←return;でよさそう
最後にout.flush()またはout.close()をするのを忘れずに！
Point2D p2d=new Point2D.Double(d1,d2);
//import static java.lang.System.*;
*/
//入力終了→Ctrl+D
import java.util.*;
import java.io.*;
import java.awt.*;
import java.awt.geom.Point2D;
import static java.lang.Math.*;
public class Main{
    public static void main(String[] args) {
        while (true) {
            int n = sc.nextInt();
            if (n == 0) break;
            char[][] c = new char[n][1100];

            for (int i = 0; i < n; i++) {
                String s = sc.next();
                int l = s.length();
                for (int j = 0; j < l; j++) {
                    c[i][j] = s.charAt(j);
                }
                int p = 0;
                while (c[i][p] == '.') p++;
                if (p > 0) c[i][p - 1] = '+';
            }

            for (int i = 0; i < n; i++) {
                if (c[i][0] != '.' && c[i][0] != '+' && c[i][0] != '|') {
                    continue;
                }
                int p = 0;
                int b = i;
                while (c[i][p] != '+') {
                    p++;
                }
                if (p == 0) continue;
                if (c[i - 1][p - 1] == '|') continue;
                while (b < n && c[b][p - 1] == '.') {
                    //out.println(i+" "+b+" "+p+" "+c[b][p-1]+" !!!!!");
                    b++;
                }
                if (b == n || b == i || c[b][p - 1] != '+') continue;
                for (int j = i; j < b; j++) {
                    c[j][p - 1] = '|';
                }
            }

            for (int i = 0; i < n; i++) {
                for (int j = 0; j < 1100; j++) {
                    if ((int) c[i][j] == 0) break;
                    out.print(c[i][j] == '.' ? ' ' : c[i][j]);
                }
                out.println();
            }

        }
        out.close();
    }

    static PrintWriter out = new PrintWriter(System.out);

    static class sc {
        static Scanner s = new Scanner(System.in);

        static String next() {
            return s.next();
        }

        static String nextLine() {
            return s.nextLine();
        }

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

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

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

        static boolean hasNext() {
            return s.hasNext();
        }

        static boolean hasNextInt() {
            return s.hasNextInt();
        }

    }

}


Measured memory_bytes: 109848
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

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

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

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

typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

int main()
{
    int N;
    scanf("%d", &N);

    vector<vector<int>> G;

    if (N & 1)
    {
        G.push_back({ N });
        int l = 1, r = N - 1;
        while (l < r)
        {
            G.push_back({ l,r });
            l++;
            r--;
        }
    }
    else
    {
        int l = 1, r = N;
        while (l < r)
        {
            G.push_back({ l,r });
            l++;
            r--;
        }
    }

    vector<PII> res;

    REP(i, G.size())FOR(j, i + 1, G.size())for (int u : G[i])for (int v : G[j])
        res.push_back(MP(u, v));

    printf("%d\n", res.size());
    for (const auto & p : res)
        printf("%d %d\n", p.first, p.second);

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
    if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
    }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



int main(){
  int n;
  cin>>n;
  
  vector<ll> p(n);
  rep(i,n){
    cin>>p[i];
  }

  ll sum=p[0];
  repo(i,n){
    sum^=p[i];
  }

  rep(i,n){
    ll x=sum^p[i];
    cout << x;
    if(i!=n-1) cout << " ";
    else cout << endl;
  }

}


Measured memory_bytes: 4784
import java.util.ArrayList;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N - 1];
		int[] b = new int[N - 1];
		long[] c = new long[N - 1];
		for(int i = 0; i < N - 1; i++) {
			a[i] = sc.nextInt() - 1;
			b[i] = sc.nextInt() - 1;
			c[i] = sc.nextLong();
		}
		int Q = sc.nextInt();
		int K = sc.nextInt() - 1;
		int[] x = new int[Q];
		int[] y = new int[Q];
		for(int i = 0; i < Q; i++) {
			x[i] = sc.nextInt() - 1;
			y[i] = sc.nextInt() - 1;
		}
		sc.close();
		long[] d = dijkstra(N, K, a, b, c, true);
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < Q; i++) {
			long ans = d[x[i]] + d[y[i]];
			sb.append(ans).append("\n");
		}
		System.out.print(sb.toString());
	}
	/**
	 * ダイクストラ法 (優先度付きキュー)
	 * @param N 頂点数
	 * @param t 始点
	 * @param from, to 辺
	 * @param cost 辺のコスト
	 * @param flag true なら無向辺、 false なら有向辺
	 * @return d t から各頂点への最短距離
	 */
	public static long[] dijkstra(int N, int t, int[] from, int[] to, long[] cost, boolean flag) {
		final int WHITE = 0;
	    final int GRAY = 1;
	    final int BLACK = 2;
	    final long INF = 100000000000000l;
		long[] d = new long[N];
		int[] color = new int[N];
		@SuppressWarnings("unchecked")
		ArrayList<Node>[] adj = new ArrayList[N];
		for(int i = 0; i < N; i++) {
			d[i] = INF;
			color[i] = WHITE;
			adj[i] = new ArrayList<Node>();
		}
		int E = from.length;
		for(int i = 0; i < E; i++) {
			adj[from[i]].add(new Node(to[i], cost[i]));
			if(flag)adj[to[i]].add(new Node(from[i], cost[i]));

		}
		Queue<Node> pq = new PriorityQueue<Node>(new MyComparator());
		d[t] = 0;
		pq.add(new Node(t, 0l));
		while(!pq.isEmpty()) {
			Node f = pq.poll();
			int u = f.id;
			color[u] = BLACK;
			if(d[u] < f.cost) continue;
			for(int j = 0; j < adj[u].size(); j++) {
				int v = adj[u].get(j).id;
				if(color[v] == BLACK) continue;
				d[v] = d[u] + adj[u].get(j).cost;
				pq.add(new Node(v, d[v]));
				color[v] = GRAY;
			}
		}
		return d;
	}
	static class Node{
		int id;
		long cost;
		public Node(int id, long cost) {
			this.id = id;
			this.cost = cost;
		}
	}
	static class MyComparator implements Comparator<Node>{
		@Override
        public int compare(Node v1, Node v2) {
			if(v1.cost < v2.cost) {
				return -1;
			}else if(v1.cost == v2.cost) {
				return 0;
			}else {
				return 1;
			}
		}
	}
}

Measured memory_bytes: 167412
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
const int mod=1e9+7;
const int N=4001;
int f[N],inv[N];
int ncr(int n,int r)
{
	if(n<r)return 0;
	int res=f[n]*inv[r];
	res%=mod;
	res*=inv[n-r];
	return res%=mod;
}
int modp(int a,int b)
{
	if(b==0)return 1;
	int u=modp(a,b/2);
	u=(u*u)%mod;
	if(b&1)return (a*u)%mod;
	return u;
}
int fi(int n,int r)
{
	return ncr(n-1+r,r);
}
int32_t main()
{
	int s=in();
	int cur=s/3;
	f[0]=1;
	for(int i=1;i<N;i++)f[i]=(f[i-1]*i)%mod;
	inv[N-1]=modp(f[N-1],mod-2);
	for(int i=N-2;i>=0;i--)inv[i]=(inv[i+1]*(i+1))%mod;
	
	int ans=0;
	for(int i=1;i<=cur;i++)
	{
		int rem=s-3*i;
		if(rem<0)continue;
		ans+=fi(i,rem);
		ans%=mod;
	}
	cout<<ans;
	
	
}


Measured memory_bytes: 3712
#include <iostream>
int main() {
    std::string s; std::cin >> s;
    int pre = (s[0] - '0') * 10 + s[1] - '0';
    int sec = (s[2] - '0') * 10 + s[3] - '0';
    bool pp = 0 < pre && pre < 13;
    bool ss = 0 < sec && sec < 13;
    if (pp && !ss) {
        std::cout << "MMYY" << std::endl;
    } else if (!pp && ss) {
        std::cout << "YYMM" << std::endl;
    } else if (pp && ss) {
        std::cout << "AMBIGUOUS" << std::endl;
    } else {
        std::cout << "NA" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
sc = {}
for m2 in range(m):
    sc[m2]=input().split()
ok_list= []
for al in range(0, 10**(n)):
    ynli = []
    li = list(str(al))
    if len(li) == n:
        for mm in range(m):
            if li[int(sc[int(mm)][0])-1] != sc[int(mm)][1]:
                ynli.append("NO")
        if "NO" in ynli:
            pass
        else:
            ok_list.append(al)
    else:
        pass
if ok_list == []:
    print(-1)
else:
    print(min(ok_list))

Measured memory_bytes: 3064
#include <stdio.h>
int max(int x, int y) {
	return x > y ? x : y;
}
int main() {
	int w, h, n, x, y, a;
	int X1, Y1, X2, Y2;
	scanf("%d%d%d", &w, &h, &n);
	X1 = Y1 = 0;
	X2 = w;
	Y2 = h;
	for (int i = 0; i < n; i++) {
		scanf("%d%d%d", &x, &y, &a);
		switch (a) {
			case 1:
				if (X1 < x)
					X1 = x;
				break;
			case 2:
				if (X2 > x)
					X2 = x;
				break;
			case 3:
				if (Y1 < y)
					Y1 = y;
				break;
			case 4:
				if (Y2 > y)
					Y2 = y;
				break;
			default:
				break;
		}
	}
	printf("%d\n", max(0, X2 - X1) * max(0, Y2 - Y1));
	return 0;
}

Measured memory_bytes: 128
// 3_abc060_c
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
#define MOD (1000000007)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, t;
    cin >> n >> t;
    vector<int> a(n);
    rep(i, n){
        cin >> a[i];
    }

    int b = a[0];
    ll ans = t;

    for(int i = 1; i < n; i++){
        int c = a[i];
        if(a[i] - b >= t){
            ans += t;
        }else{
            ans += c - b;
        }
        b = c;
    }

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


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

int main()
{
  int counter = 0 ;
  string S;
  cin >> S;
  sort(S.begin(),S.end());
  if( S[0] == S[1] && S[2] == S[3] && S[2] != S[1] ) cout <<"Yes" << endl;
  else cout <<  "No" <<  endl; 
}

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

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> x(200);
	rep(i, n)cin >> x.at(i);
	int sum = 0;
	rep(i, n) {
		if (x.at(i) > k)sum += k - x.at(i);
		else {
			sum += min(x.at(i) * 2, (k - x.at(i)) * 2);
		}
	}
		cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#define FI(i, a, b) for (int i = (a); i <= (b); ++i)
#define FD(i, b, a) for (int i = (b); i >= (a); --i)
#define DEBUG(x) cerr << #x << ": " << (x) << endl;

int main() {
  int n;
  cin >> n;
  vector<int> x(n + 1), y(n + 1);
  FI(i,1,n) scanf("%d%d", &x[i], &y[i]);
  double len = 0;
  auto calc = [&](int i, int j) {
    return sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
  };
  FI(i,1,n) FI(j,i+1,n) {
    double dis = calc(i, j);
    len += dis;
  }
  printf("%.9f\n", len * 2 / n);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using P = pair<int,int>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}




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

    int R = 0;
    vector<pair<int,int>> Rvec;
    rep(i,S.size()){
        if(S[i] == 'R') R++;
        if(S[i] == 'L'){
            Rvec.push_back(make_pair(i,R));
            R = 0;
        }
    }

    int L = 0;
    vector<pair<int,int>> Lvec;
    for(int i = S.size() - 1; i >= 0 ; i-- ){
        if(S[i] == 'L') L++;
        if(S[i] == 'R'){
            Lvec.push_back(make_pair(i,L));
            L = 0;
        }
    }

    vector<int> ans(S.size());
    rep(i,Rvec.size()){
        if(Rvec[i].second%2 == 1){
            ans[Rvec[i].first] += Rvec[i].second/2;
            ans[Rvec[i].first - 1] += Rvec[i].second/2 + 1;
        }
        else{
            ans[Rvec[i].first] += Rvec[i].second/2;
            ans[Rvec[i].first - 1] += Rvec[i].second/2;
        }
    }

    rep(i,Lvec.size()){
        if(Lvec[i].second%2 == 1){
            ans[Lvec[i].first] += Lvec[i].second/2;
            ans[Lvec[i].first + 1] += Lvec[i].second/2 + 1;
        }
        else{
            ans[Lvec[i].first] += Lvec[i].second/2;
            ans[Lvec[i].first + 1] += Lvec[i].second/2;
        }
    }

    rep(i,S.size()) cout << ans[i] << endl;

    return 0;
}
//Ctrl+Shift+Bでコンパイルと実行を行ってデバッグすること

Measured memory_bytes: 1976
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;

int32_t main(){
    IOS;
    int n,t;
    cin>>n>>t;
    for(int i=0;i<t;i++){
        int x; cin>>x;
        n-=x;
    }
    if(n>=0) cout<<n<<endl;
    else cout<<-1<<endl;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main(){
    int K,A,B;
    cin >> K;
    cin >> A >> B;
    int a = (A-1)/K;
    int b = B/K;
    if(b-a>0)cout << "OK" << endl;
    else cout << "NG" << endl;
}

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

int cmpnum(const void * n1, const void * n2)
{
	if (*(long *)n1 > *(long *)n2)
	{
		return -1;
	}
	else if (*(long *)n1 < *(long *)n2)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

int main(void){

  int n;
  scanf("%d", &n);
  long a[n];
  for (int i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }
  qsort(a, n, sizeof(long), cmpnum);
  int answer = 0;
  int count = 0;
  for (int i = 0; i < n-1; i++) {
    count++;
    if (a[i] != a[i+1]) {
      if (count%2 != 0) {
        answer++;
      }
      count = 0;
    }
  }
  count++;
  if (count%2 != 0) {
    answer++;
  }
  printf("%d\n", answer);

  return 0;
}

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

int main() {
  ll n, t;
  cin >> n >> t;
  vector<ll> a(n, 0LL);
  vector<ll> m(n, 0LL);
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  m[n-1] = a[n-1];
  for(int i=n-2; i>=0; i--) {
    m[i] = max(a[i], m[i+1]);
  }
  vector<ll> d(n, 0LL);
  ll dmax = -1;
  for(int i=0; i<n; i++) {
    d[i] = m[i]-a[i];
    dmax = max(dmax, d[i]);
  }
  int ans = 0;
  for(int i=0; i<n; i++) {
    if(dmax==d[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    map<char, int> ms, mt;

    for (int i = 0; i < (int)s.size(); ++i) {
        ms[s[i]]++;
        mt[t[i]]++;
    }
    vector<int> ns, nt;
    for (auto &p : ms) {
        ns.push_back(p.second);
    }
    for (auto &p : mt) {
        nt.push_back(p.second);
    }
    sort(ns.begin(), ns.end());
    sort(nt.begin(), nt.end());
    if (ns == nt) {
        cout << "Yes"
             << "\n";
    } else {
        cout << "No"
             << "\n";
    }
    return 0;
}

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



int main(){
	int dp[60][60];
	int map[60][60]={0};
	for(int i=0;i<60;i++){
		for(int j=0;j<60;j++){
			dp[i][j]=INT_MAX;
		}
	}
	string s;
	int H,W;
	cin>>H>>W;
	for(int i=0;i<H;i++){
		cin>>s;
		for(int j=0;j<s.size();j++){
			map[i+1][j+1]=s[j]-'0';
		}
	}
	dp[1][1]=0;
	for(int i=1;i<=H;i++){
		for(int j=1;j<=W;j++){
			dp[i][j]=min(dp[i][j],min(dp[i-1][j],dp[i][j-1]))+map[i][j];
		}
	}
	cout<<dp[H][W]<<endl;
	
}

Measured memory_bytes: 1236
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

int a,b,res=(1<<30)-1;

void calc(int x,int y,int v){
	if (x<=y){
		res=min(res,abs(x-y)+v);
	}
}

int main(){
	a=IN(),b=IN();
	calc(a,b,0);
	calc(a,-b,1);
	calc(-a,b,1);
	calc(-a,-b,2);
	printf("%d\n",res);
}

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

struct point{
	double x;
	double y;
};

int ccw(point p0, point p1, point p2){
	double dx1, dx2, dy1, dy2;
	dx1 = p1.x - p0.x;
	dy1 = p1.y - p0.y;
	dx2 = p2.x - p0.x;
	dy2 = p2.y - p0.y;
	if(dx1 * dy2 > dy1 * dx2){
		return 1;
	}else if(dx1 * dy2 < dy1 * dx2){
		return -1;
	}else return 0;
}

int main(){
	point p1, p2, p3, p0;
	while(cin >> p1.x >> p1.y >> p2.x >>p2.y
		>> p3.x >> p3.y >> p0.x >> p0.y)
	{
		if(ccw(p0,p1,p2) && ccw(p0,p2,p3) && ccw(p0, p3, p1)){
			if((ccw(p0, p1, p2 ) != ccw(p0, p1, p3))
				&& (ccw(p0, p2, p1) != ccw(p0, p2, p3)))
				cout << "YES" << endl;
			else cout << "NO" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
	return 0;
}

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

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

	vector<long long> s(A+2), t(B+2);

	s[0] = t[0] = -1e18;
	s[A+1] = t[B+1] = 1e18;

	for(int i=1; i<A+1; ++i) cin >> s[i];
	for(int i=1; i<B+1; ++i) cin >> t[i];

	while(Q--){
		long long x; cin >> x;

		long long ans = 1e18;

		auto a = lower_bound(s.begin(), s.end(), x);
		auto b = lower_bound(t.begin(), t.end(), x);

		ans = min(ans, max(*a - x, *b - x));
		ans = min(ans, max(x - *(a - 1), x - *(b - 1)));
		ans = min(ans, min(x-*(a-1) + *b - *(a-1), *a-x + *a-*(b-1)));
		ans = min(ans, min(x-*(b-1) + *a - *(b-1), *b-x + *b-*(a-1)));

		cout << ans << endl;
	}
}


Measured memory_bytes: 2944
from itertools import permutations
from math import factorial

N = int(input())
town = {}
route = permutations(range(0,N))

for i in range(N):
    town[i] = tuple(map(int,input().split()))

Sum = 0

for v in route:
    for i in range(N-1):
        Sum += ((town[v[i+1]][0] - town[v[i]][0])**2 + (town[v[i+1]][1] - town[v[i]][1])**2)**(0.5)

ans = Sum/factorial(N)

print(ans)

Measured memory_bytes: 74380