akhauriyash/Code-Regression huggingface dataset:
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
vector<vector<int>>go;
vector<int>zi;
class UF{
public:
	vector<int>go;
	UF(int in){go.res(in);for(int i=0;i<in;i++){go[i]=i;}}
	int find_uf(int a){
		if(go[a]==a){return a;}
		return go[a]=find_uf(go[a]);
	}
	void uni_uf(int a,int b){go[find_uf(a)]=find_uf(b);}
};
int dfs(int ter,int per){
	//cerr<<ter<<per<<endl;
	int kozi=zi[ter];
	for(auto it:go[ter]){
		if(it==per){continue;}
		kozi+=dfs(it,ter);
	}
	if(per==-1){return 0;}
	if(kozi%2==1){cout<<ter+1<<" "<<per+1<<endl;return 0;}
	else{cout<<per+1<<" "<<ter+1<<endl;return 1;}
}
int main(void){
	//m<=100 で 300点あげていいと思う
	int n,m,i;cin>>n>>m;
	if(m%2){cout<<"-1"<<endl;return 0;}
	zi.res(n);
	go.res(n);
	UF uni(n);
	for(i=0;i<m;i++){
		int a,b;cin>>a>>b;
		a--;b--;
		if(uni.find_uf(a)==uni.find_uf(b)){
			cout<<a+1<<" "<<b+1<<endl;
			zi[a]++;continue;
		}
		uni.uni_uf(a,b);
		go[a].pub(b);
		go[b].pub(a);
	}
	dfs(0,-1);
	return 0;
}

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

using namespace std;

typedef long long ll;

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

    vector<int> N(3);
    N.push_back(A);
    N.push_back(B);

    bool flagA = false;
    bool flagB = false;
    bool flagC = false;
    for (int n : N)
    {
        if(n == 1){
            flagA = true;
        }else if(n == 2){
            flagB = true;
        }else if(n == 3){
            flagC = true;
        }
    }

    if(!flagA) cout << "1" << endl;
    if(!flagB) cout << "2" << endl;
    if(!flagC) cout << "3" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#define ll long long
#define add push_back
 
using namespace std; 


int main() {

    ios::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);

    int t;  t = 1; //cin >> t;
    while(t--){
        ll n; cin >> n;
        vector<ll> v(n);
        map<ll,int> freq;
        ll curr = 0;
        for(int i = 0; i < n; i++){
            cin >> v[i];
            curr += v[i];
            freq[v[i]]++;
        }
        ll q; cin >> q;
        while(q--){
            ll a,b; cin >> a >> b;
            ll dif = b - a;
            curr += dif * freq[a];
            freq[b] += freq[a];
            freq[a] = 0;
            cout << curr << endl;
        }
    }
    return 0;
}

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

int main(void){
  string a,b,c,d,e; 
  cin >> a >> b >> c >> d >> e;

  if(a == "0"){
    cout << "1" << endl;
  }
   if(b == "0"){
    cout << "2" << endl;
  }
   if(c == "0"){
    cout << "3" << endl;
  }
   if(d == "0"){
    cout << "4" << endl;
  }
   if(e == "0"){
    cout << "5" << endl;
  }
  
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll smallest_multiple(ll d, ll lb) {
	if(lb % d == 0) {
		return lb;
	} else {
		return lb + d - lb % d;
	}
};
int main() {
	int n;
	cin >> n;
	ll t, a;
	cin >> t >> a;
	for(int i = 1; i < n; i++) {
		ll tt, aa;
		cin >> tt >> aa;
		ll new_t1 = smallest_multiple(tt, t), new_a1 = new_t1 / tt * aa;
		ll new_a2 = smallest_multiple(aa, a), new_t2 = new_a2 / aa * tt;
		ll best_sum = numeric_limits<ll>::max();
		if(new_a1 > a and new_t1 + new_a1 < best_sum) {
			t = new_t1, a = new_a1, best_sum = t + a;
		} 
		if(new_t2 > t) {
			t = new_t2, a = new_a2, best_sum = t + a;
		}
	}
	cout << t + a << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
int n;
int i;
int a[200];
int b[200];
int num=1;

scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
for(i=0;i<n;i++){
b[i]=0;
if(a[i]%2==1){
num=0;
}
}

for(i=0;i<n;i++){
   while(a[i]%2==0){
    b[i]=b[i]+1;
    a[i]=a[i]/2;
   }
}
if(num==0){
printf("%d",num);
}
else{
num=b[0];
for(i=0;i<n-1;i++){
if(b[i]>b[i+1]){
num=b[i+1];
}
}

printf("%d",num);
}
return 0;
}

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

const int N=110;
int a[N],n,m;
int oddnum[2];

int main()
{
    int odd=0,tot=0;
    scanf("%d%d",&n,&m);
    oddnum[0]=1;oddnum[1]=m;
    for(int i=1;i<=m;i++)
    {
        scanf("%d",a+i);
        if(~a[i]&1) continue;
        oddnum[odd++]=i;
        if(odd>2) return puts("Impossible"),0;
    }
    swap(a[1],a[oddnum[0]]);
    swap(a[m],a[oddnum[1]]);
    if(m==1&&a[1]==1) return puts("1\n1\n1"),0;
    for(int i=1;i<=m;i++) printf("%d ",a[i]);
    if(m==1) return printf("\n2\n%d 1\n",a[1]-1),0;
    printf("\n%d\n%d ",a[m]>1?m:m-1,a[1]+1);
    for(int i=2;i<m;i++) printf("%d ",a[i]);
    if(a[m]>1) printf("%d\n",a[m]-1);
    return 0;
}

Measured memory_bytes: 764
#include<stdio.h>
int main(void)
{
	int A, B;
	scanf("%d%d", &A, &B);

	if (A < 6) {
		printf("0");
	}
	else if (A >= 6 && A < 13) {
		printf("%d", B / 2);
	}
	else
		printf("%d", B);


	return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
#define go(u) for(int i = head[u], v = e[i].to; i; i=e[i].lst, v=e[i].to)
#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define pb push_back
#define re(x) memset(x, 0, sizeof x)
inline int gi() {
    int x = 0,f = 1;
    char ch = getchar();
    while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar();}
    while(isdigit(ch)) { x = (x << 3) + (x << 1) + ch - 48; ch = getchar();}
    return x * f;
}
template <typename T> inline bool Max(T &a, T b){return a < b ? a = b, 1 : 0;}
template <typename T> inline bool Min(T &a, T b){return a > b ? a = b, 1 : 0;}
const int N = 1e5 + 7;
int n, E, T;
LL f[N], x[N];
int q[N], hd = 1, tl;
int main() {
#ifdef fwat
#endif
	n = gi(), E = gi(), T = gi();
//	if(n > 2000) return puts("gg"), 0;
	memset(f, 0x3f, sizeof f); f[0] = 0;
	rep(i, 1, n) x[i] = gi();
	LL mi = 1e18;
	q[++tl] = 0;
	for(int i = 1, j = 0; i <= n; ++i) {
		for(; j < i && 2 * (x[i] - x[j + 1]) >= T; ++j) Min(mi, f[j] - 2 * x[j + 1]);
		Min(f[i], mi + 2 * x[i]);
		while(hd <= tl && 2 * (x[i] - x[q[hd] + 1]) >= T) ++hd;
		if(hd <= tl)
			Min(f[i], f[q[hd]] + T);
		for(; hd <= tl && f[i] <= f[q[tl]]; --tl);
		q[++tl] = i;
	}
	printf("%lld\n", f[n] + E);
	return 0;
}

Measured memory_bytes: 2176
#include <stdio.h>

int main(void){
  int ki = 0,gu = 0;
  int i,K;
  
  scanf("%d",&K);
  for(i = 1;i <= K; ++i){
    if(i % 2)	++ki;
    else ++gu;
  }
  printf("%d\n",ki * gu);
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<set>
#include<string>
#include<vector>
#include<queue>

using namespace std;

/*
//1
int main(){
	int d, c;
	cin >> d >> c;

	cout << d*c << endl;

	return 0;
}
*/

/*
//2
int main(){
	int c1, c5, c10,c50,c100, c500;
	cin >> c1 >>  c5 >> c10 >> c50 >> c100 >> c500;
	int x = c1 + c5*5 + c10*10 + c50*50 + c100*100 + c500*500;
	if(x>=1000) cout << 1 << endl;
	else cout << 0 << endl;

	return 0;
}*/



//3
/*
int main(){
	int N;
	cin >> N;
	for(int i=0; i<N; i++){
		int k, p;
		cin >> k >> p;
		int x = k%p;
		if(x == 0) x = p;
		cout << x << endl;

	}

	return 0;
}
*/



//4
int main(){
	int N, M;
	int times[300];
	cin >> N;
	for(int i=0; i<N; i++){
		int h, m;
		cin >> h >> m;
		times[i] = 60*h + m;
	}
	cin >> M;
	for(int i=0; i<M; i++){
		int h, m;
		cin >> h >> m;
		times[N+i] = 60*h + m;
	}
	sort(times, times+N+M);

	int n = -1;
	for(int i=0; i< N+M; i++){
		if(times[i] == n) continue;
		int h, m;
		h = times[i]/60;
		m = times[i]%60;
		
		if(m < 10){
			if(n == -1) cout << h << ":0" << m;
			else cout << " " << h << ":0" << m;
		}
		else{
			if(n == -1) cout << h << ":" << m;
			else cout << " " << h << ":" << m;
		}

		n = times[i];
	}
	cout << endl;

	return 0;
}


//=====

/*
//5
int main(){
	int N,M,p;
	cin >> N >> M >> p;
	int left = -1;
	int right = N;
	int mini,ma;
	vector<int> all;
	for(int i=0; i<M; i++){
		int tmp;
		cin >> tmp;
		all.push_back(tmp);
	}
	sort(all.begin(), all.end());
	for(int i=0; i<M; i++){
		int tmp = all[i];
		if(tmp < p) left = tmp;
		if(tmp > p && tmp < right) right = tmp;
		if(i == 0) mini = tmp;
		if(i == M-1) ma = tmp;
	}

	if(left == -1) left = N-ma;
	if(right == N) right = N+mini;

	cout << (N-max(p-left,right-p))*100 << endl;

	return 0;
}
*/

/*
//6
int main(){


	return 0;
}
*/

/*
//7
int main(){


	return 0;
}
*/

/*
//8
int main(){


	return 0;
}
*/

/*
//9
int main(){


	return 0;
}
*/

/*
//10
int main(){


	return 0;
}
*/


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

string candidates[4] = {"dream", "dreamer", "erase", "eraser"};

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

    reverse(s.begin(), s.end());
    for (int i = 0; i < 4; i++) reverse(candidates[i].begin(), candidates[i].end());

    bool ok = true;
    for (int i = 0; i < s.size();) {
        bool hasCandidate = false;
        for (int j = 0; j < 4; j++) {
            if (s.substr(i, candidates[j].size()) == candidates[j]) {
                hasCandidate = true;
                i += candidates[j].size();
                break;
            }
        }

        if (!hasCandidate) {
            ok = false;
            break;
        }
    
    }
    
    if (ok) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;

}

Measured memory_bytes: 512
io = STDIN
n,m=io.gets.split.map(&:to_i)
ar=[]   #no,p,y
m.times do |i|
  ar << [i+1,*io.gets.split.map(&:to_i)]
end
ary=[]
chunk= ar.sort_by{|no,p,y|[p,y]}.chunk{|no,p,y|p}.to_a
chunk.each do |pr,ar|
  sort=ar.sort_by{|no,p,y|y}
  srt=sort.map.with_index(1){|(no,p,y),i|[no,p,y,i]}
  srt.each do |no,p,y,i|
    ary << [no,p,i]
  end
end
ary.sort_by{|x,y,z|x}.each{|x,y,z|puts "%#06d%#06d"%[y,z]}


Measured memory_bytes: 45652
use std::io;


/// https://beta.atcoder.jp/contests/abc076/tasks/abc076_c
/// Dubious Document 2
fn main() {
    let s = read_one::<String>().chars().collect::<Vec<char>>();
    let t = read_one::<String>().chars().collect::<Vec<char>>();

    if t.len() > s.len() { println!("UNRESTORABLE"); return; }

    let mut ans = Vec::new();
    for i in 0..s.len() - t.len() + 1 {
        let mut buf = s.clone();
        let mut flg = true;
        // println!("{:?}", &buf[i..i + t.len()]);
        // check if s contains t
        for j in 0..t.len() {
            if !(buf[i + j] == '?' || buf[i + j] == t[j]) { flg = false; }
        }
        if !flg { continue; }
        // replace 
        for j in 0..t.len() {
            buf[i + j] = t[j];
        }
        ans.push(buf.iter().map(|&c| if c == '?' { 'a' } else { c }).collect::<Vec<_>>());
    }
    ans.sort();
    if ans.len() > 0 {
        for c in &ans[0] {
            print!("{}", c);
        }
        println!();
    } else {
        println!("UNRESTORABLE");
    }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
 

int main(){
    int n;cin >> n;
    vector<P> a;
    for (int i = 0; i < n; i++) {
        LL k;cin >> k;
        a.pb(mp(k,0LL));
    }
    for (int i = 0; i < n; i++) {
        LL k;cin >> k;
        a.pb(mp(k,1LL));
    }
    sort(ALL(a));
    LL sa=0,sb=0,ans=1;
    for (int i = 0; i < 2*n; i++) {
        if(a[i].sc==0){
            if(sb>0){
                ans = ans * sb % mod;
                sb--;
            }
            else sa++;
        }
        else{
            if(sa>0){
                ans = ans * sa % mod;
                sa--;
            }
            else sb++;
        }
    }
    cout << ans%mod << endl;
    return 0;
}


Measured memory_bytes: 6512
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	int N, x;
	cin >> N >> x;
	int width = N * 2 - 1;
	if(x == 1 or x == width) {
		cout << "No" << endl;
		return 0;
	}

	cout << "Yes" << endl;
	if(N == 2) {
		rep(i, 1, 4) cout << i << endl;
		return 0;
	}

	int rsl[width];
	memset(rsl, 0, sizeof(rsl));
	rsl[N - 2] = x - 1;
	rsl[N - 1] = x;
	rsl[N] = x + 1;

	int pos = 0, i = 1;
	while(pos < width) {
		if(i == x or i == x - 1 or i == x + 1) {
			i++;
			continue;
		}

		if(rsl[pos] != 0) {
			pos++;
			continue;
		}

		rsl[pos] = i;
		pos++;
		i++;
	}

	rep(i, 0, width) cout << rsl[i] << endl;
	
}


Measured memory_bytes: 2304
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong n, k;
llong a[100005];

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

    llong g = __gcd(a[0], a[1]);
    for (int i = 2; i < n; i++) {
        g = __gcd(g, a[i]);
    }

    bool f = false;
    for (int i = 0; i < n; i++) {
        if (a[i] >= k && k % g == 0) f = true;
    }

    if (f) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;

    return 0;
}


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

int main(){
    int n,m;
    cin>>n>>m;
    set<int> as;
    map<int,int> ws;
    for(int i=0 ;i<m; i++){
        int p;
        string s;
        cin>>p>>s;
        if(s == "AC"){
            as.insert(p);
        }else if(s == "WA"){
            if(as.count(p))continue;
            ws[p]++;
        }
    }

    int cntac = 0;
    int cntwc =0;
    for(auto itr = as.begin();itr != as.end();++itr){
        cntac++;
        if(ws[*itr]>0)cntwc += ws[*itr];
    }
    cout << cntac << " " << cntwc <<endl;

}

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

int L,R,d;

int main(){
	cin>>L>>R>>d;
	if(L%d==0){
		cout<<(R/d)-(L/d)+1<<'\n';
	}else{
		cout<<(R/d)-(L/d)<<'\n';
	}
}

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

const int MAXN = 1e5 +2;
int n, a[MAXN], b[MAXN], c[MAXN];

int main(){
 //   freopen(".in", "r", stdin);

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

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

    for(int i=2; i<=n; i++){
        a[i] += max(b[i-1], c[i-1]);
        b[i] += max(a[i-1], c[i-1]);
        c[i] += max(b[i-1], a[i-1]);
    }

    cout << max(a[n], max(b[n], c[n])) << '\n';

    return 0;
}

Measured memory_bytes: 1408
#include "iostream"
#include "unordered_map"

using namespace std;

int main(int argc, char const *argv[]) {

  unordered_map<int, int> t;
  int x, a, b, c;//a: 500, b: 100, c: 50
  cin >> a >> b >> c >> x;

  //O(n^2)
  for(int i = 0; i <= a; i++){
    for(int j = 0; j <= b; j++){
      int tmp = i * 500 + j * 100;
      if(tmp <= 20000){
        t[tmp] = t.count(tmp) > 0 ? t[tmp] + 1 : 0;
      }
    }
  }

  //for(auto i : t)
    //cout << i.first << " " << i.second << endl;

  int res = 0;
  for(int i = 0; i <= c; i++){
    int tmp = x - i*50;
    int times = t[tmp];
    if(times != 0)
      res += times ;
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
N,K = map(int,input().split())
MOD = pow(10,9)+7

def cmb(n, r, p):
  if (r < 0) or (n < r):
    return 0
  r = min(r, n - r)
  return fac[n]*finv[r]*finv[n-r]%p

fac = [-1]*(N+1); fac[0] = 1; fac[1] = 1 #階乗
finv = [-1]*(N+1); finv[0] = 1; finv[1] = 1 #階乗の逆元
inv = [-1]*(N+1); inv[0] = 0; inv[1] = 1 #逆元
for i in range(2,N+1):
  fac[i] = fac[i-1]*i%MOD
  inv[i] = MOD - inv[MOD%i]*(MOD//i)%MOD
  finv[i] = finv[i-1]*inv[i]%MOD

A = list(map(int,input().split()))
A.sort()
ans = 0
for i in range(N):
  MIN = cmb(N-1-i,K-1,MOD)
  MAX = cmb(i,K-1,MOD)
  #print(i,A[i],MAX,MIN)
  temp = A[i]*(MAX-MIN)
  ans = (ans+temp)%MOD
print(ans%MOD)

Measured memory_bytes: 91568
#include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;
struct Pos { int x, y; };
struct State { int d, x, y; };

vector<Pos> Node;
vector<string> B;
int dist[11][11];
const int INF = 1<<29;

int dirs[] = { -1, 0, 1, 0, -1 };
void bfs(int i)
{
    Pos p = Node[i];
    int vis[21][21] = {};

    queue<State> Q;
    Q.push({ 0, p.x, p.y });
    while (Q.size()) {
        State v = Q.front(); Q.pop();
        if (vis[v.x][v.y]) continue;
        vis[v.x][v.y] = 1;
        char b = B[v.y][v.x];
        if (b >= '0' && b <= '9') {
            dist[i][b-'0'] = v.d;
            dist[b-'0'][i] = v.d;
        }

        loop (4, i) {
            int x = v.x + dirs[i], y = v.y + dirs[i+1];
            if (x >= 0 && x < B[0].size() && y >= 0 && y < B.size()) {
                if (B[y][x] != 'x' && !vis[x][y]) {
                    Q.push({ v.d + 1, x, y });
                }
            }
        }
    }
}

int memo[11][2000];
int dfs(int curr, int vis)
{
    if (memo[curr][vis] != -1) return memo[curr][vis];
    int n = Node.size();
    if (vis == ((1 << n) - 1)) return 0;
    int ans = INF;
    loop (n, i) {
        if (vis >> i & 1) continue;
        ans = min(ans, dist[curr][i] + dfs(i, vis | 1 << i));
    }
    memo[curr][vis] = ans;
    return ans;
}

int main()
{
    while (1) {
NG:
        fill(dist[0], dist[10]+11, INF);
        int w, h; cin >> w >> h;
        if (!w) break;

        B = vector<string>(h);
        loop (h, i) cin >> B[i];

        Node = vector<Pos>(1);
        loop (h, y) loop (w, x) {
            if (B[y][x] == 'o') {
                B[y][x] = '0';
                Node[0] = { x, y };
            }
            if (B[y][x] == '*') {
                B[y][x] = '0' + Node.size();
                Node.push_back({ x, y });
            }
        }

        loop (Node.size(), i) bfs(i);

        loop (Node.size(), i) {
            if (dist[0][i] == INF) {
                cout << -1 << endl;
                goto NG;
            }
        }

        fill(memo[0], memo[10] + 2000, -1);
        cout << dfs(0, 1) << endl;
    }
    return 0;
}

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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

template <typename A, typename B>
string to_string(pair<A, B> p){
    return "(" + to_string(p.fi) + ", " + to_string(p.se) + ")";
}

template <typename T>
string to_string(T v){
    string s = "{";
    bool first = true;
    for(const auto & x : v){
        if(!first) s += ", ";
        first = false;
        s += to_string(x);
    }
    return s + "}";
}

void debug_out(){ cerr << endl;}
template <typename First, typename... Next>
void debug_out(First F, Next... N){
    cerr << " " << to_string(F);
    debug_out(N...);
}

#ifdef LOCAL
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 1
#endif

const int N = 1e6 + 6;
bool np[4*N];

void siev(){
    np[1] = true;
    for(int i = 2; i * i < N; i++){
        if(!np[i]) for(int j = i * i; j < N; j += i) np[j] = true;
    }
}

int main(){
    fcin;
    int x;
    cin >> x;

    siev();

    while(true){
        if(!np[x]) return cout << x << endl, 0;
        x++;
    }

    return 0;
}



Measured memory_bytes: 1280
# =map(int,input().split())
n=int(input())
a=[int(input()) for i in range(n)]
import sys
ans=sum(a)
x=a.sort()
for i in range(n):
    if ans%10==0:
        if i==0:
            ans-=a[i]
        else:
            ans+=a[i-1]
            ans-=a[i]
    else:
        print(ans)
        sys.exit()
if ans%10==0:
    print(0)


    

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define _LIBCPP_DEBUG 0
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;
int INF = 1 << 30;
    
int main(void){

    double R; cin>>R;
    printf("%lf",R*2*M_PI);

}


Measured memory_bytes: 3752
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
  char suit;
  int value;
};

struct Card L[MAX/2+2], R[MAX/2+2];

void merge(struct Card A[], int n, int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for(int i=0;i<n1;i++) L[i] = A[left + i];
  for(int i=0;i<n2;i++) R[i] = A[mid  + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for(k=left; k<right; k++) {
    if(L[i].value <= R[j].value) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(struct Card A[], int n, int left, int right) {
  if(left+1 < right) {
    int mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}

int partition(struct Card A[], int n, int p, int r) {
  int i, j;
  struct Card t, x;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++) {
    if(A[j].value <= x.value) {
      i++;
      t=A[i]; A[i]=A[j]; A[j]=t;
    }
  }
  t=A[i+1]; A[i+1]=A[r]; A[r]=t;
  return i+1;
}

void quickSort(struct Card A[], int n, int p, int r) {
  int q;
  if(p<r) {
    q = partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}

int main() {
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d", &n);

  for(i=0;i<n;i++) {
    scanf("%s %d",S,&v);
    A[i].suit =  B[i].suit  = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++) {
    // マージソートとクイックソートの結果を比べる
    if(A[i].suit != B[i].suit) stable = 0;
  }

  if(stable==1) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++) {
    printf("%c %d\n",B[i].suit,B[i].value);
  }

  return 0;
}

Measured memory_bytes: 4192
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define f(i, n)         for(int i=0; i<n; i++)
#define fo(i, k, n)     for(int i=k; i<n; i++)
#define forr(i, a, b)   for(int i=a; i<=b; i++)
#define rf(i,n)         for(int i=n;i>=0;i--)
typedef unsigned long long ull;
typedef pair<int ,int> pr;
#define MAX 100005
#define INF 1000000009
#define   sq(n)         (n*n)
#define p(n) cout<<n<<endl
#define pb push_back
#define py cout<<"YES"<<endl;
#define pn cout<<"NO"<<endl;
#define __FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
ll lcm ( ll a, ll b )
{
    return ( a / __gcd ( a, b ) ) * b;
}
int main()
{
    __FastIO;

      char ch;
      cin>>ch;
      if(ch>=65 && ch<=90)
      {
          cout<<"A"<<endl;
      }
      else
      {
          cout<<"a"<<endl;
      }
    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  for(;;){
    int n;
    cin >> n;
  
    if(n==0)return 0;
    vector<pair<int,int> > v(n);

    for(int i=0;i<n;++i){
      int a,b;
      cin >> a >> b;
      v[i] = make_pair(b,a);
    }

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

    int omosa=0;
    for(int i=0;i<n;++i){
      if(omosa>v[i].first){
	cout << "No" << endl;
	break;
      }
      else{
	omosa += v[i].second;
	if(omosa>v[i].first){
	  cout << "No" << endl;
	  break;
	}
      }
      if(i==n-1)
	cout << "Yes" << endl;
    }
    
  }
  return 0;
}

Measured memory_bytes: 1188
#include <iostream>
using namespace std;
int main(){
  double xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2;
  bool judge;
  while(cin >> xa1 >> ya1 >> xa2 >> ya2 >> xb1 >> yb1 >> xb2 >> yb2){
    judge=false;
    if((xb1<=xa1&&xa1<=xb2)&&(yb1<=ya1&&ya1<=yb2)) judge=true;
    if((xb1<=xa2&&xa2<=xb2)&&(yb1<=ya2&&ya2<=yb2)) judge=true;
    if((xa1<=xb1&&xb1<=xa2)&&(ya1<=yb1&&yb1<=ya2)) judge=true;
    if((xa1<=xb2&&xb2<=xa2)&&(ya1<=yb2&&yb2<=ya2)) judge=true;
    if((xb1<=xa1&&xa1<=xb2)&&(yb1<=ya2&&ya2<=yb2)) judge=true;
    if((xb1<=xa2&&xa2<=xb2)&&(yb1<=ya1&&ya1<=yb2)) judge=true;
    if((xa1<=xb1&&xb1<=xa2)&&(ya1<=yb2&&yb2<=ya2)) judge=true;
    if((xa1<=xb2&&xb2<=xa2)&&(ya1<=yb1&&yb1<=ya2)) judge=true;
    if(((xb1<=xa1)&&(xa1<=xb2)&&(xb1<=xa2)&&(xa2<=xb2))&&((ya1<=yb1&&yb1<=yb2)&&(ya1<=yb2&&yb2<=yb2))) judge=true;
    if(((xa1<=xb1)&&(xb1<=xa2)&&(xa1<=xb2)&&(xb2<=xa2))&&((yb1<=ya1&&ya1<=ya2)&&(yb1<=ya2&&ya2<=ya2))) judge=true;
    if(judge) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int h, w;
	cin >> h >> w;
	vector<string> a(h);
	rep(i, h) cin >> a[i];
	vector<bool> resh(h), resw(w);
	rep(i, h) {
		bool ok = true;
		rep(j, w) {
			if (a[i][j] == '#') ok = false;
		}
		if (ok) resh[i] = true;
	}
	rep(i, w) {
		bool ok = true;
		rep(j, h) {
			if (a[j][i] == '#') ok = false;
		}
		if (ok) resw[i] = true;
	}
	rep(i, h) {
		if (resh[i]) continue;
		rep(j, w) {
			if (resw[j]) continue;
			cout << a[i][j];
		}
		cout << endl;
	}
	return 0;
}


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

int main()
{
    int N, K;
    cin >> N >> K;
    int p[N];
    for (int i = 0; i < N; i++) {
        cin >> p[i];
    }
    sort(p, p + N);

    int ans = 0;
    for (int i = 0; i < K; i++) {
        ans += p[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;


void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!long).array;
    A.sort();

    long ans = 0;
    foreach (i; iota(N, 3*N, 2)) {
        ans += A[i];
    }

    ans.writeln;
}


Measured memory_bytes: 14948
#include<bits/stdc++.h>
#define int long long
#define pb emplace_back
#define mp make_pair
#define mt make_tuple
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define revrep(i,n) for(long long i=n-1;i>=0;i--)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator<int> output (cout," ")
#define endl '\n'
#define f first
#define s second
#define PI 3.141592653589793
#define MOD 1000000007
#define set0(x) memset(x,0,sizeof(x))
#define set1(x) memset(x,1,sizeof(x))
using namespace std;
typedef vector<int> vi;
typedef list<int> li;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef tuple<int, int, int> iii;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
template<typename P> P dectobin(P a){if(a==0)return 0; else return(a%2 + 10*dectobin(a/2));}
template<typename Y> Y bintodec(Y a){int ans=0,b=1,t=a; while (t){int ld=t%10; t/=10;ans+=ld* b;b=b*2;} return ans; }
template<typename H> H modExp(H x, H n){ int r=1; while(n>0){if(n%2==1){r=(r*x)%MOD;}x=(x*x)%MOD;n/=2;}return r;}
template<typename T> T isPowerOfTwo(T x){return x && (!(x & (x - 1)));}	
template<typename T> T lcm(T a,T b) {return a*b/gcd(a,b);}
//template<typename T> T extendedEuclid(T A,T B){if(B==0){d=A; x=1;y=0;}else{ extendedEuclid(B,A%B);int temp=x; x=y; y=temp-(A
//B)*y;}}
int32_t main(){
	boost;osit;
	int n;
	cin>>n;
	int arr[n];
	rep(i,0,n) cin>>arr[i];
	int dp[n];
	dp[0]=0;
	dp[1]=abs(arr[1]-arr[0]);
	rep(i,2,n){
		dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1792
import sys
input = sys.stdin.readline
from collections import deque
 
H, W = map(int, input().split())
S = [list(input().split()[0]) for _ in range(H)]
 
def bfs(S, H, W, start):
    INF = -1
    stack=deque([start])
    distance = [[INF]*W for _ in range(H)]
    distance[start[1]][start[0]] = 0
    while stack:
        x, y = stack.popleft()
        for i, j in [(1,0),(0,1),(-1,0),(0,-1)]:
            next_x = x + i
            next_y = y + j
            if not(0 <= next_x < W and 0 <= next_y < H):
                continue
            if S[next_y][next_x] != '#' and distance[next_y][next_x] == -1:
                stack.append([next_x, next_y])
                distance[next_y][next_x] = distance[y][x] + 1
    return max(map(max, distance))
 
ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] != "#":
            ans = max(ans, bfs(S, H, W, (j, i)))
print(ans)

Measured memory_bytes: 3316
#include <stdio.h>

int main()
{
	int N, D;
	static int X[10][10];
	scanf("%d%d", &N, &D);

	for (int i = 0; i < N; i++) {
		for (int k = 0; k < D; k++) {
			scanf("%d", &X[i][k]);
		}
	}

	auto calc_len2 = [D](int *x1, int *x2) -> int {
		int sum = 0;
		for (int k = 0; k < D; k++) {
			sum += (x1[k] - x2[k]) * (x1[k] - x2[k]);
		}
		return sum;
	};

	int ans = 0;
	for (int a = 0; a < N; a++) {
		for (int b = a + 1; b < N; b++) {
			int len2 = calc_len2(X[a], X[b]);
			for (int t = 1; t * t <= len2; t++) {
				if (t * t == len2) {
					ans++;
				}
			}
		}
	}
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 128
N = int(input())
B = list(map(int, input().split()))

ans = []
while B:
    flag = False
    idx = -1
    for i in range(len(B)):
        if B[i] == i+1:
            flag = True
            idx = i
    else:
        if flag:
            ans.append(B[idx])
            B.pop(idx)
        else:
            print(-1)
            exit(0)

for i in reversed(range(N)):
    print(ans[i])


Measured memory_bytes: 9200
#include <stdio.h>

int main(){
  int n,i,j,k,m,a[12][12],c[12],x,mm=10000000,d[12],e;
  scanf("%d",&n);
  scanf("%d",&m);
  scanf("%d",&x);
  for(i=0;i<n;i++){
    scanf("%d",&c[i]);
    for(j=0;j<m;j++){
      scanf("%d",&a[i][j]);
    }
  }
  for(i=1;i<(1<<n);i++){
    e=0;
    for(j=0;j<m;j++){
      d[j]=0;
    }
    for(j=0;j<n;j++){
      if(i&(1<<j)){
        e+=c[j];
        for(k=0;k<m;k++){
          d[k]+=a[j][k];
        }
      }
    }
    for(j=0;j<m;j++){
      if(d[j]<x) break;
    }
    if((j==m)&(e<mm)) mm=e;
  }
  if(mm==10000000) mm=-1;
  printf("%d",mm);
  return(0);
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1e9 + 7;
const int N = 200006;
const ll INF = 1e18;
ll ans = 0;
vector<ll> dp(2005, -1);

ll go(int cur_sum) {

    ll &ans = dp[cur_sum];
    if(ans != -1) {
        return ans;
    }

    ans = 0;
    
    if(cur_sum < 3 && cur_sum > 0) {
        return 0;
    }

    for(int i = 3; i <= cur_sum; i++) {
        ans += go(cur_sum - i);
        ans %= mod;
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int s;
    cin >> s;
    dp[0] = 1;
    cout << go(s) << '\n';

    return 0;
}

Measured memory_bytes: 3680
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    
    for i in range(H):
        for j in range(W):
            if i == 0 or i == H-1 or j == 0 or j == W-1:
                print("#", end="")
            else:
                print(".", end="")
        print()
    print()


Measured memory_bytes: 7004
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

ll min(ll a, ll b) {return a < b ? a : b;}
ll min(int a, ll b) {return a < b ? a : b;}
ll min(ll a, int b) {return a < b ? a : b;}
ll min(int a, int b) {return a < b ? a : b;}

ll max(ll a, ll b) {return a > b ? a : b;}
ll max(int a, ll b) {return a > b ? a : b;}
ll max(ll a, int b) {return a > b ? a : b;}
ll max(int a, int b) {return a > b ? a : b;}

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()
#define int long long

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k, s;
    cin >> n >> k >> s;
    if (s == 1000000000)
    {

    for (int i = 0; i < k; i++) cout << s << " ";
    for (int i = 0; i < n - k; i++) cout << 1 << " ";
    return 0;
    }
    for (int i = 0; i < k; i++) cout << s << " ";
    for (int i = 0; i < n - k; i++) cout << 1000000000 << " ";
}


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


int main() {
    
    int r, d, x;
    cin >> r >> d >> x;
    rep(i,10) {
        x = r*x-d;
        cout << x << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

int a,b,c;

int main(){
    cin>>a>>b>>c;
    out(a*b/2);
}


Measured memory_bytes: 256
n,m = map(int,input().split())
ans = 0
sita = 10**(n-1)
ue = 10**n
s_make = [False] * n

for i in range(m):
    # 読みにくかったためtuple→sとcへ。(問題文のsiとciに合わせてます)
    s, c = map(int,input().split())
    if s == 1 and c == 0 and n != 1:
        ans = -1
        break
    
    # int(str(ans)[s-1])→左からs桁目を取り出してる
    c_need = (ans // (10 ** (n - s))) % 10
    
    if not s_make[s - 1]:
        ans += c * (10**(n-s))
    elif c_need != c:
        ans = -1
    s_make[s - 1] = True
if ans >= ue or ans==-1 :
    ans = -1
elif ans < sita and n != 1:
    ans += sita
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;

struct UnionFind {
  vector<int> par;  // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  vector<int> rank;

  UnionFind(int N) : par(N), rank(N) {  //最初は全てが根であるとして初期化
    for (int i = 0; i < N; i++) {
      par[i] = i;
      rank[i] = 0;
    }
  }

  int root(int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) {  // xとyの木を併合
    x = root(x);
    y = root(y);
    if (x == y) return;

    if (rank[x] < rank[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if (rank[x] == rank[y]) rank[x]++;
    }
  }

  bool same(int x, int y) {  // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

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

  UnionFind f(n);

  vector<set<int>> dame(n);

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    f.unite(a, b);
    dame[a].insert(b);
    dame[b].insert(a);
  }

  for (int i = 0; i < k; i++) {
    int c, d;
    cin >> c >> d;
    c--;
    d--;
    if (!f.same(c, d)) continue;
    dame[c].insert(d);
    dame[d].insert(c);
  }

  vector<int> graphsize(n, 0);
  for (int i = 0; i < n; i++) {
    graphsize[f.root(i)]++;
  }

  for (int i = 0; i < n; i++) {
    cout << graphsize[f.root(i)] - dame[i].size() - 1 << " ";
  }
  cout << endl;
}

Measured memory_bytes: 27780
n = int(input())

pairs = [[i for i in range(1, n + 1)] for _ in range(n)]

ans = []
if n % 2 == 0:
    for i in range(n-1):
        for j in range(i + 1, n):
            x = pairs[i][j]
            if x == n - i:
                continue
            ans.append((i + 1, x))
else:
    for i in range(n-1):
        for j in range(i + 1, n):
            x = pairs[i][j]
            if x == n - i-1:
                continue
            ans.append((i + 1, x))

print(len(ans))
for x, y in ans:
    print(x, y)


Measured memory_bytes: 3996
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
using namespace std;
int main() {
	int a, b;
	while(cin>>a>>b&&a!=0&&b!=0){
		int h = 0, g = 0, s = 0,o=b-a;
		while (o >= 1000) {
			s++;
			o -= 1000;
		}
		while (o >= 500) {
			g++;
			o -= 500;
		}
		while (o >= 100) {
			h++;
			o -= 100;
		}
		cout << h << " " << g << " " << s << endl;
	}
}

Measured memory_bytes: 3060
N=int(input())
P=[int(i)-1 for i in input().split()]
M=30000
R=[0 for i in range(N)]
for i in range(N):
    R[P[i]]=i+1
A=[str(M*i) for i in range(1,N+1)]
B=[str(M*(N+1-i)+R[i-1]) for i in range(1,N+1)]
print(" ".join(A))
print(" ".join(B))


Measured memory_bytes: 8436
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main( void )
{
    int r, D, x;
    cin >> r >> D >> x;

    int before = x;
    for(int i=0;i<10;i++){
        int now = r * before - D;
        cout << now << "\n";
        before = now; 
    }
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int tmp;

        if(a>b){
        tmp=a;
        a=b;
        b=tmp;
    }
        if(b>c){
        tmp=b;
        b=c;
        c=tmp;
        }
        if(a>b){
        tmp=a;
         a=b;
        b=tmp;
        }
        System.out.println(a+" "+b+" "+c);
    }
}



Measured memory_bytes: 26408
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
using namespace std;
int main()
{
  int m1, m2, d1,d2;
  cin >> m1 >> d1 >> m2 >> d2;
  if(m1 != m2){
    cout << 1 << endl;
  }else{
    cout << 0 << endl;
  }

}


Measured memory_bytes: 256
N,E[24][21];T0(f,c){int i,s=0;for(i=2;i<=N;i++)if(i-f&&E[c][i])s+=T0(c,i)+2*E[c][i];return s;}T1(f,c,l){int i,s=E[c][l]+T2(c,l);for(i=2;i<=N;i++)if(i-f&&i-l&&E[c][i])s+=T0(c,i)+2*E[c][i];return s;}T2(f,c){int l,t,m=1e9;for(l=2;l<=N;l++)if(l-f&&E[c][l]){t=T1(f,c,l);if(t<m)m=t;}return m-1e9?m:0;}main(t){for(;scanf("%d",&N)*N;memset(E,0,2e3)){int i,j,n[21]={0},a,b;for(i=N;--i;n[a]++,n[b]++)scanf("%d%d%d",&a,&b,&t),E[a][b]=E[b][a]=t;for(i=2;i<=N;i++)for(j=N+1;n[i]<2&&--j;)E[i][j]=E[j][i]=0;printf("%d\n",T2(0,1));}}

Measured memory_bytes: 0
from itertools import product


def abc173c_h_and_v():
    h, w, k = map(int, input().split())
    c = [input() for _ in range(h)]
    cnt = 0
    for hp in product(range(2), repeat=h):
        for wp in product(range(2), repeat=w):
            a = [c[i][j] for j in range(w) if wp[j] == 1 for i in range(h) if hp[i] == 1]
            if k == a.count('#'):
                cnt += 1
    print(cnt)

abc173c_h_and_v()

Measured memory_bytes: 9136
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j]
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能

struct Unionfind{
    vector<int> data;
    Unionfind(int size): data(size, -1) {}
    bool unite(int x, int y){
        x=root(x);
        y=root(y);
        if(x!=y){
            if( data[y] < data[x] ) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x!=y;
    }
    bool same(int x, int y){
        return root(x) == root(y);
    }
    int root(int x){
        return (data[x] < 0)? x : data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};

int main(){
    int n,k,l; cin >> n >> k >> l;
    Unionfind uni(n),unii(n);
    rep(i,k){
        int p,q; cin >> p >> q;
        p--; q--;
        uni.unite(p,q);
    }
    rep(i,l){
        int s,t; cin >> s >> t;
        s--; t--;
        unii.unite(s,t);
    }
    map<P,int> mp;
    rep(i,n) mp[{uni.root(i),unii.root(i)}]++;
    rep(i,n) cout << mp[{uni.root(i),unii.root(i)}] << endl;
}


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

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPr(i, n) for(int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for(int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for(int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
    cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
    int x12345;                                                                \
    cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
const long long MOD = 1e9 + 7;
///////////////////////////////////////////////
// for template
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////
/// 🍈( '-' 🍈 |AC|
int main() {
    // R < G < B
    int A, B, C;
    cin >> A >> B >> C;
    int K;
    cin >> K;
    bool ok = false;
    FORq(k, 0, K) {
        FORq(a, 0, 7) {
            FORq(b, 0, 7) {
                FORq(c, 0, 7) {
                    if(a + b + c != k)
                        continue;

                    int Ax = A;
                    int Bx = B;
                    int Cx = C;

                    REP(i,a){Ax *= 2;}
                    REP(i,b){Bx *= 2;}
                    REP(i,c){Cx *= 2;}

                    if ((Ax < Bx) and (Bx < Cx)) ok = true;
                }
            }
        }
    }

    if (ok) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 3560
using System;
using System.Linq;
using System.Collections.Generic;

namespace ABC
{
    class ProgramA
    {
        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(" ");
            var t = double.Parse(inputs[0]);
            var x = double.Parse(inputs[1]);
            var result = t / x;
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 27564
# Author: cr4zjh0bp
# Created: Sat Mar  7 12:40:36 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

A, B = na()
ans = -1
for i in range(10100):
    if int(i * 0.08) == A and int(i * 0.1) == B:
        ans = i
        break

print(ans)

Measured memory_bytes: 3188
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    
    int ab = (b-a)%2;
    int nn = n%2;
    
    if(ab == 1) System.out.println("Borys");
    else if(ab == 0) System.out.println("Alice");

  }
}

Measured memory_bytes: 35704