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

using ll=long long; 

struct P{
	int idx;
	string s;
	int p;
	
	bool operator<(const P& opp){
		return ((s==opp.s)?p>opp.p:s<opp.s);
	}
};

void solve(){
	int n;
	cin>>n;
	string s;
	int p;

	vector<P>a;
	for(int i=0; i<n; i++){
		cin>>s>>p;
		P elem={i+1, s, p};
		a.push_back(elem);
	}
	sort(a.begin(), a.end());
	for(int i=0; i<n; i++){
		cout<<a[i].idx<<endl;
	}
}

signed main(){
	//while(1)
	solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef long long ll;
const long long MOD=1e09+7;



#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vi vector<int>


int main(){
  


  double a,b,h,m;
  cin>>a>>b>>h>>m;
  
  double kakudo=abs((60*h+m)*0.5-6*m);
  if (kakudo>180){
    kakudo=360-kakudo;
  }
  
  const double pi=3.14159265358979;
  
  kakudo=(kakudo*pi)/180;
  
  double answer;
  
  answer=sqrt(a*a+b*b-2*a*b*cos(kakudo));
  
  cout<<fixed<<setprecision(15);
  
  cout<<answer<<endl;
  
  
  
  

  
  
  
  
  
  
      
 

  
}

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

using namespace std;


bool isPalindrome(string s){
	for (int i=0;i<s.length()/2;i++)
		if(s[i]!=s[s.length()-1-i])
			return false;
	return true;
}

int main(){

	string s;
	cin >> s;
	string a = s.substr(0,s.length()/2);
	string b = s.substr(s.length()/2+1,s.length()/2);
	if(isPalindrome(s) and isPalindrome(a) and isPalindrome(b))
		cout << "Yes";
	else
		cout << "No";
}

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

typedef pair <int, int> ii;

const int Maxn = 100005;
const int Inf = 1000000007;

int n;
int a[Maxn], b[Maxn];
int ind;
int mn = -Inf, mx = Inf;
vector <ii> seq;
int res;

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &a[i], &b[i]);
        if (b[i] < b[ind]) ind = i;
    }
    seq.push_back(ii(a[ind], b[ind]));
    for (int i = 0; i < n; i++)
        if (i != ind && a[i] > a[ind]) seq.push_back(ii(a[i], b[i]));
    sort(seq.begin(), seq.end());
    for (int i = 0; i < n; i++) if (i != ind)
        res = max(res, b[i] - a[i] + 1 + max(0, b[ind] - seq.back().first + 1));
    while (seq.size() > 1) {
        ii p = seq.back(); seq.pop_back();
        mn = max(mn, p.first); mx = min(mx, p.second);
        res = max(res, max(0, mx - mn + 1) + max(0, b[ind] - seq.back().first + 1));
    }
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 2168
import java.io.*;
import java.util.StringTokenizer;

public class Main{
	public static void main(String [] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
	
		StringTokenizer st = new StringTokenizer(br.readLine());

		for(int i=1;i<6;i++){
			int cur = Integer.parseInt(st.nextToken());
			if(cur == 0){
				bw.write(i+"");
				break;
			}
		}

		bw.flush();
		bw.close();
		br.close();
	}
}

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

int main(){
    int n;
    cin >> n;
    int sum=0;
    rep(i, n){
        int a;
        cin >> a;
        sum += a -1;
    }
    out(sum);
}

Measured memory_bytes: 256
#include <iostream>
#include <set>

int main() {
    std::set<int> s;
    int Q;
    std::cin >> Q;
    for (int q = 0; q < Q; ++q) {
        int t, x;
        std::cin >> t >> x;
        if (t == 0) {
            s.insert(x);
            std::cout << s.size() << std::endl;
        } else {
            std::cout << s.count(x) << std::endl;
        }
    }
}


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

int main() {
    long long int N, K;
    cin >> N >> K;  //入力

    vector<long long int> H(N);

    for (int i = 0; i < N; i++) {
        cin >> H.at(i);
    }

    sort(H.begin(), H.end());
    reverse(H.begin(), H.end());

    if (K > N) {
        K = N;
    }

    for (int i = 0; i < K; i++) {
        H.at(i) = 0;
    }

    long long int count = 0;

    for (int i = 0; i < N; i++) {
        count += H.at(i);
    }

    cout << count << endl;
}


Measured memory_bytes: 1792
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.util.Set;

public class Main {

	static void exec(MyScanner in, PrintWriter out) {
		int A = in.nextInt();
		int B = in.nextInt();
		int C = in.nextInt();
		Set<Integer> s = new HashSet<>(Arrays.asList(A, B, C));
		out.println(s.size() == 1 ? "Yes" : "No");
	}

	public static void main(String[] args) {
		PrintWriter w = new PrintWriter(System.out);
		exec(new MyScanner(System.in), w);
		w.flush();
	}

	static class MyScanner {
		static final int BUFFER_SIZE = 1024;
		private final InputStream in;
		private final byte[] buffer = new byte[BUFFER_SIZE];
		private int point;
		private int readLength;
		MyScanner(InputStream in) {
			this.in = in;
		}
		private int readByte() {
			if (point < readLength) {
				int result = buffer[point];
				point += 1;
				return result;
			}
			try {
				readLength = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (readLength == -1) {
				return -1;
			}
			point = 1;
			return buffer[0];
		}
		static boolean isPrintableCharExceptSpace(int c) {
			return 33 <= c && c <= 126;
		}
		String next() {
			StringBuilder b = new StringBuilder();
			int c = readByte();
			while (!(c == -1 || isPrintableCharExceptSpace(c))) {
				c = readByte();
			}
			if (c == -1) {
				throw new NoSuchElementException();
			}
			do {
				b.appendCodePoint(c);
				c = readByte();
			} while (c != -1 && isPrintableCharExceptSpace(c));
			return b.toString();
		}
		long nextLong() {
			int c = readByte();
			while (!(c == -1 || isPrintableCharExceptSpace(c))) {
				c = readByte();
			}
			if (c == -1) {
				throw new NoSuchElementException();
			}
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long result = 0L;
			do {
				if (!('0' <= c && c <= '9')) {
					throw new InputMismatchException();
				}
				result = result * 10L + (c - '0');
				c = readByte();
			} while (c != -1 && isPrintableCharExceptSpace(c));
			return minus ? -result : result;
		}
		int nextInt() {
			long n = nextLong();
			if (Integer.MIN_VALUE <= n && n <= Integer.MAX_VALUE) {
				return (int) n;
			}
			throw new InputMismatchException();
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
	}

}


Measured memory_bytes: 23124
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

const ll INF=1e15;

int main() {
    ll N, M;
    cin >> N >> M; //頂点数と辺数の入力
    ll p;
    cin >> p;
    const ll NMAX = 3000;
    const ll MMAX = 5500;
    ll a[MMAX], b[MMAX];
    ll c[MMAX];
    for (int i = 0; i < M; ++i) {
        cin >> a[i] >> b[i] >> c[i]; //辺およびその重みの入力
        c[i]-=p;
        c[i]*=-1;
    }
    ll dist[NMAX];
    for (int i = 0; i < N; ++i) {
        dist[i] = INF;
    }
    dist[0] = 0;
    for (int loop = 0; loop < N - 1; ++ loop) {
        for (int i = 0; i < M; ++i) {
            if (dist[a[i] - 1] == INF) continue;
            if (dist[b[i] - 1] > dist[a[i] - 1] + c[i]) {
                dist[b[i] - 1] = dist[a[i] - 1] + c[i];
            }
        }
    }
    ll ans = dist[N - 1];
    bool negative[NMAX];
    for (int i = 0; i < N; ++i) {
        negative[i] = false;
    }
    for (int loop = 0; loop < N ; ++ loop) {
        for (int i = 0; i < M; ++i) {
            if (dist[a[i] - 1] == INF) continue;
            if (dist[b[i] - 1] > dist[a[i] - 1] + c[i]) {
                dist[b[i] - 1] = dist[a[i] - 1] + c[i];
                negative[b[i] - 1] = true;
            }
            if (negative[a[i] - 1] == true) {
                negative[b[i] - 1] = true;
            }
        }
    }
    if (negative[N - 1]) cout << "-1" << endl;
    else cout << max(0LL,-ans) << endl;
    return 0;
}

Measured memory_bytes: 3796
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cstdlib>
#include<cassert>
#include<random>
using namespace std;
int main(){
    int d[100];
    int N;
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> d[i];
    }
    sort(d,d+N);
    int old = d[0];
    int ans = 1;
    for(int i=1; i<N; i++){
        if(old < d[i]) ans++;
        old = d[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
l = list(map(int,input().split()))
ans = 0
for i in range(len(l)):
  for j in range(i+1,len(l)):
    for k in range(j+1,len(l)):
      if l[i] != l[j] and l[j] != l[k] and l[k] != l[i]:
        a = [l[i],l[j],l[k]]
        a.sort()
        if a[0]+a[1] > a[2]:
          ans += 1
print(ans)

Measured memory_bytes: 9032
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

void solve(std::string S){
    string s1 = S.substr(0, 2);
    string s2 = S.substr(2);
    int n1 = stoi(s1);
    int n2 = stoi(s2);
    if (n1 == 0) {
        if (n2 >= 1 && n2 <= 12) cout << "YYMM" << '\n';
        else cout << "NA" << '\n';
    }
    else if (n1 > 12) {
        if (n2 >= 1 && n2 <= 12) cout << "YYMM" << '\n';
        else cout << "NA" << '\n';
    } else {
        if (n2 >= 1 && n2 <= 12) cout << "AMBIGUOUS" << '\n';
        else cout << "MMYY" << '\n';
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
#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 pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

typedef complex<int> ci;
string ep;
int cur,overf=10000;
bool flag=false;
bool check(ci c){
    if(abs(c.real())>overf||abs(c.imag())>overf) return true;
    return false;
}
ci expression();
ci factor();
ci term();
ci expression(){
    ci res=factor();
    while(ep[cur]=='+'||ep[cur]=='-'){
        int tcur=cur++;
        if(ep[tcur]=='+') res +=factor();
        if(ep[tcur]=='-') res -=factor();
        if(check(res)) flag=true;
    }
    return res;
}
ci factor(){
    ci res=term();
    while(ep[cur]=='*'){
        int tcur=cur++;
        if(ep[tcur]=='*') res *=term();
        if(check(res)) flag=true;
    }
    return res;
}
ci term(){
    ci res;
    if(ep[cur]=='('){
        cur++;
        res=expression();
        cur++;
    }
    else if(ep[cur]=='i'){
        res=ci(0,1);
        cur++;
    }
    else{
        while(isdigit(ep[cur])){
            res=res*10+(ep[cur]-'0');
            ++cur;
            if(check(res)) flag=true;
        }
    }
    return res;
}
int main(){
    while(cin>>ep){
        flag=false;
        cur=0;
        ci ans=expression();
        if(flag) cout<<"overflow"<<endl;
        else{
            int rl=ans.real(),ig=ans.imag();
            if(rl==0&&ig!=0) cout<<ig<<'i'<<endl;
            else{
                cout<<rl;
                if(ig>0) cout<<'+';
                if(ig!=0) cout<<ig<<'i';
                cout<<endl;
            }
        } 
    }
    return 0;
}

Measured memory_bytes: 3056
#include <cstdio>
#include <cmath>
using namespace std;
const int N=1e5+5;
const int E=N<<1;
const int mod=1e9+7;
int n,u,v;
int a[N],b[N];
int d1[N],d2[N];
int h[N],nx[E],to[E];
int ec;
int ans;
void ae(int u,int v)
{
	ec++;
	nx[ec]=h[u];
	to[ec]=v;
	h[u]=ec;
}
void dfs(int u,int f,int d[])
{
	d[u]=d[f]+1;
	for (int i=h[u];i;i=nx[i])
		if (to[i]!=f)
			dfs(to[i],u,d);
}
int main()
{
	scanf("%d%d%d",&n,&u,&v);
	for (int i=1;i<n;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
		ae(a[i],b[i]);
		ae(b[i],a[i]);
	}
	dfs(u,0,d1);
	dfs(v,0,d2);
	for (int i=1;i<=n;i++)
		if (d1[i]<d2[i]&&d2[i]-2>ans)
			ans=d2[i]-2;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 10328
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#define INF 1000000000
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define all(x) (x).begin(),x.end()
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;

int main(){
  long long sum=0;
  int n,t[105],m;
  cin>>n;
  rep(i,n){
    cin>>t[i];
    sum+=t[i];
  }
  cin>>m;
  rep(i,m){
    int p,x;
    cin>>p>>x;
    cout<<sum+x-t[p-1]<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    while(t)
    {
        string s;
        cin>>s;
        int n=s.length();
        bool p=false;
        for(int i=0;i<n-1;i++)
        {
            if(s[i]!=s[i+1])
            {
                p=true;
                break;
            }
        }
        if(p)
        {
            cout<<"Yes";
        }
        else
        {
            cout<<"No";
        }
        t--;
    }
    return 0;
}







Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <new>

using namespace std;
	
int main(){
    long long N,M;
    cin >> N >> M;

    if(N == M){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    cin >> n;
    {
        string t;
        getline(cin, t);
    }
    for(int i=0;i<n;i++) {
        string s1, s2;
        getline(cin, s1);
        getline(cin, s2);
        vector<int> v1(s2.size()+1, 0);
        vector<int> v2(s2.size()+1, 0);
        for(auto c1=s1.cbegin(); c1!=s1.cend(); ++c1) {
            int i = 1;
            for(auto c2=s2.cbegin(); c2!=s2.cend(); ++c2,i++) {
                auto m = max(v1[i], v2[i-1]);
                m = max(m, v1[i-1] + (*c1 == *c2 ? 1 : 0));
                v2[i] = m;
            }
            /*
            for(auto t=v1.begin();t!=v1.end();++t) {
                cout << *t << " ";
            }
            cout << endl;
            */
            swap(v1, v2);
        }
        cout << v1[s2.size()] << endl;
    }
}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

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

    reverse(all(s));

    vec d(n+1);

    lint res = 0;

    lint cur = 1;
    for (int i = 1; i <= n; i++) {
        int nd = s[i-1] - '0';
        d[i] = (d[i-1] + cur * nd) % p;
        cur *= 10;
        cur %= p;
    }

    if (p == 2 || p == 5) {
        rep(i, n) {
            int nd = s[i] - '0';
            if (nd % p == 0) {
                res += (n - i);
            }
        }
    }
    else {
        map<int, int> mp;
        rep(i, n+1) mp[d[i]]++;
        for (auto&& ps : mp) {
            lint v = ps.second;
            res += v * (v-1) / 2;
        }
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1668
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;
typedef tuple<int,int,int> TP;

template<typename T>
T Pow(T a,T b) {
    T ret = 1;
    for(int i = 0;i < b;i++) {
        ret *= a;
    }
    return ret;
}
 
ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}
 
ll RS(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P < 0) {
        return 0;
    }
    if(P%2==0){
        ll t = RS(N, P/2, M);
        return t*t % M;
    }
    return N * RS(N, P-1, M) % M;
}

int main() {
    int A,B;
    cin >> A >> B;
    cout << A * B << endl;
}

Measured memory_bytes: 3596
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>

using namespace std;
int n;
int num[100100];
vector<pair<int,int>>sortednum;
int par[100010];
map<int,int>ppid;

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

void primenum(int inow, int NUM){
	for(int i=2; i*i<=NUM; i++){
		if(NUM%i==0){
			if(ppid.count(i)==0){
				ppid[i]=inow;
			}
			else{
				par[neid(ppid[i])]=inow;
			}
			while(NUM%i==0)NUM/=i;
		}
	}
	if(NUM!=1){
		if(ppid.count(NUM)==0){
			ppid[NUM]=inow;
		}
		else{
			par[neid(ppid[NUM])]=inow;
		}

	}
}

int main(){
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> num[i];
		sortednum.push_back(make_pair(num[i],i));
		par[i]=i;
		primenum(i,num[i]);
	}

	sort(sortednum.begin(),sortednum.end());
	int ans=1;

	for(int i=0; i<n; i++){
		if(neid(i)!=neid(sortednum[i].second)){
			ans=0;
			break;
		}
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 5444
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define gc getchar
#define pb push_back
#define eb emplace_back
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
int n;
LL arr[100005],a,b,beda;
int main()
{
	cin>>n>>a>>b;
	beda=a-b;
	for(int i=1;i<=n;i++)
		cin>>arr[i];
	LL bawah=1,atas=1000000000,mid;
	while(bawah<=atas)
	{
		mid=(bawah+atas)>>1;
		LL totalkurang=mid*b,totala=0;
		for(int i=1;i<=n;i++)
		{
			if(arr[i]<=totalkurang)
				continue;
			totala+=(arr[i]-totalkurang+beda-1)/beda;		//diceil
		}
		
		if(totala<=mid)
			atas=mid-1;
		else
			bawah=mid+1;
	}
	cout<<bawah<<endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;

int main()
{
    int N, D, X;
    cin >> N >> D >> X;
    int eaten = 0;
    for (int i = 0; i < N; ++i)
    {
        int Ai;
        cin >> Ai;
        for (int d = 1; d <= D; ++d)
        {
            if ((d - 1) % Ai == 0)
                ++eaten;
        }
    }
    cout << eaten + X << endl;
    return 0;
}

Measured memory_bytes: 256
/**
 *  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_D
 */
#include <iostream>
#include <vector>

using namespace std;

pair<long, vector<int> >
mergeandcount(const vector<int> A, const vector<int> B)
{
    auto itA = A.cbegin();
    auto itB = B.cbegin();
    long count = 0;
    vector<int> C;
    while (itA != A.end() && itB != B.end()) {
        if (*itB < *itA) {
            C.push_back(*itB);
            count += distance(itA, A.end());
            advance(itB, 1);
        } else {
            C.push_back(*itA);
            advance(itA, 1);
        }
    }
    if (itA != A.end()) {
        C.insert(C.end(), itA, A.end());
    } else {
        C.insert(C.end(), itB, B.end());
    }
    return make_pair(count, C);
}

pair<long, vector<int> >
sortandcount(const vector<int> L)
{
    if (L.size() == 1) { return make_pair(0, L); }

    int m = L.size() / 2;
    vector<int> A(L.cbegin(), L.cbegin() + m);
    vector<int> B(L.cbegin() + m, L.cend());
    pair<long, vector<int> > rA = sortandcount(A);
    pair<long, vector<int> > rB = sortandcount(B);
    pair<long, vector<int> > rC = mergeandcount(rA.second, rB.second);
    return make_pair(rA.first + rB.first + rC.first, rC.second);
}

int
main()
{
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n; cin.ignore();

    vector<int> A(n);
    for (int i = 0; i < n; i++) {
        cin >> A[i]; cin.ignore();
    }

    cout << sortandcount(A).first << endl;

    return 0;
}

Measured memory_bytes: 8700
#include<cctype>
#include<string>
#include<algorithm>
#include<iostream>
#include<set>
#include<regex>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<ctime>
#include<vector>
#include<bitset>
#include<cstdio>
#include<numeric>
#include<utility>
#include<sstream>
#include<cstdlib>
#include<iomanip>
#include<cstring>
#include<map>
#include<functional>
#include<unordered_map>
#define _USE_MATH_DEFINES
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define endl "\n"
typedef long long int lli;
typedef unsigned long long int uli;
const uli mod = 1e9 + 7;
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);


    int a, b, w;
    cin >> w >> a >> b;
    if(a > b)
        swap(a, b);
    if( a + w >= b) {
        cout << 0 << endl;
        return 0;
    }
    else {
        cout << b - a - w << endl; 
    }

}

Measured memory_bytes: 256
#include <cstdio>
#include <complex>
#include <vector>
#include <cmath>
using namespace std;

#define EPS 1e-7

typedef complex<double> P;

double dist(P a, P b)
{
	return abs(a-b);
}

double angle(P a, P b, P c)
{
	return arg((c-b)/(b-a));
}

double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

bool isequal(double a, double b)
{
	return fabs(a-b) < EPS;
}

int main()
{
	int N;
	while(scanf("%d", &N), N)
	{
		vector<P> v(N);
		vector<bool> used(N, false);
		for(int i=0; i<N; i++)
		{
			int x,y;
			scanf("%d%d", &x,&y);
			v[i]=P(x,y);
		}

		double ans=0;
		P a=P(0,-1),b=P(0,0);
		for(int i=0; i<N; i++)
		{
			int select=-1;
			double alg=0;
			for(int j=0; j<N; j++)
			{
				if(used[j]) continue;
				if(ccw(a,b,v[j]) > 0) continue;
				
				double t=angle(a,b,v[j]);
				if(select==-1)
				{
					alg=t;
					select=j;
				}
				else if(isequal(alg,t))
				{
					if(dist(b,v[j]) < dist(b, v[select]))
						select=j;
				}
				else if(t>alg)
				{
					alg=t;
					select=j;
				}
			}
			
			used[select]=true;
			a=b; b=v[select];
			ans+=dist(a,b);
		}

		printf("%.1lf\n", ans);
	}
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#define INF 100000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;

static const double EPS = 1e-8;

const int tx[] = {0,1,0,-1};
const int ty[] = {-1,0,1,0};

const static ll N = 1001;

short fib_table[10000000];

int fib(int n){
	if(n==-1 || n==0) return 1;
	else if(fib_table[n]!=-1) return fib_table[n];
	else return (fib_table[n] = ((fib(n-1) % N) + (fib(n-2) %N)) % N);
}

int main(){
	memset(fib_table,-1,sizeof(fib_table));

	int V,d;
	while(~scanf("%d %d",&V,&d)){
		int rank[N];
		int par[N];

		vector<int> fibs;
		for(int i=1;i<=V;i++){
			fibs.push_back(fib(i));
		}

		sort(fibs.begin(),fibs.end());
		int res=1;
		for(int i=1;i<fibs.size();i++){
			if(fibs[i]-fibs[i-1]>=d) res++;
		}

		cout << res << endl;
	}
}

Measured memory_bytes: 0
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

MX = 2005


def nd(i, j, k, s, d):
    if k >= len(s[i]):
        return True
    return d[i][j][k]


def main():
    s = [''] * 3
    s[0] = input().rstrip('\n')
    s[1] = input().rstrip('\n')
    s[2] = input().rstrip('\n')
    s.sort()
    ans = MX*3
    for ss in itertools.permutations(s):
        d = [[[False for _ in range(MX)] for _ in range(3)] for _ in range(3)]
        for i in range(3):
            for j in range(i+1, 3):
                for k in range(len(ss[i])):
                    check = True
                    for ni in range(k, len(ss[i])):
                        nj = ni-k
                        if nj >= len(ss[j]):
                            break
                        if ss[i][ni] == '?' or ss[j][nj] == '?':
                            continue
                        if ss[i][ni] != ss[j][nj]:
                            check = False
                            break
                    d[i][j][k] = check

        for x in range(MX):
            for y in range(MX):
                if not nd(0, 1, x, ss, d):
                    continue
                if not nd(1, 2, y, ss, d):
                    continue
                if not nd(0, 2, x+y, ss, d):
                    continue
                now = max(len(ss[0]), x+len(ss[1]), x+y+len(ss[2]))
                ans = min(ans, now)
    print(ans)


main()


Measured memory_bytes: 52976
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
 
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
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(){
	double i, j, k, l;
	cin >> i >> j >> k >> l;
	cout << fixed << setprecision(8);
	cout << (double)sqrt(pow(i - k, 2.0) + pow(j - l, 2.0)) << endl;
}

Measured memory_bytes: 1280
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = int(input())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7

import collections

lcm_pf = collections.defaultdict(int)
for i, v in enumerate(a):
    j = 2
    pf = {}
    while j ** 2 <= v:
        ext = 0
        while v % j == 0:
            ext += 1
            v //= j
        if ext:
            pf[j] = ext
            lcm_pf[j] = max(lcm_pf[j], ext)
        j += 1
    if v != 1:
        pf[v] = 1
        lcm_pf[v] = max(lcm_pf[v], 1)

lcm = 1
for p in lcm_pf:
    lcm = lcm * (p ** lcm_pf[p])

ans = 0
for v in a:
    ans = ans + (lcm // v)
print(ans % MOD)


Measured memory_bytes: 75032
#include <iostream>
#include <vector>
#include <string>
using ll = long long;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rep2(i, s, n) for(ll i = s; i < n; i++)
using namespace std;

string jan = "rsp";
int main(){
  int n, k, r, s, p;
  string t;
  cin >> n >> k;
  cin >> r >> s >> p;
  cin >> t;
  int ans = 0;
  rep(i, n){
    if (i - k < 0){
      if (t[i] == jan[0]) ans += p;
      else if (t[i] == jan[1]) ans += r;
      else if (t[i] == jan[2]) ans += s;
    }
    else {
      if (t[i] == t[i-k]){
        t[i] = 'a';
        continue;
      }
      if (t[i] == jan[0]) ans += p;
      else if (t[i] == jan[1]) ans += r;
      else if (t[i] == jan[2]) ans += s;
    }
  }
  cout << ans << endl;
  
  return 0;
}

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

int main()
{
  int res=0;
  char d[4];
  cin >> d;

  char prev='*';
  int cnt = 1;
  rep(i,4) {
    if (prev == d[i]) {
      cnt++;
      res=max(cnt,res);
    }
    else cnt=1;
    prev=d[i];
  }
  if(res>=3) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
n,m = map(int,input().split())

cd = []
isOk = True
for i in range(m):
    x,y = map(int,input().split())
    if(x > n):
        isOk = False
        break
    if(x==1 and y==0 and n!=1):
        isOk = False
        break
    if([x,y] in cd):
        continue
    for a,b in cd:
        if(a==x):
            isOk=False
    cd.append([x,y])

word = ['0']*n
if(not isOk):
    print(-1)
else:
    for x,y in cd:
        word[x-1] = str(y)

    if(n==1):
        print(''.join(word))
    else:
        if(word[0]=='0'):
            word[0]='1'
        print(''.join(word))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    int p[n],a[102]={0},max,con[101]={0};
    for(int i=0;i<n;i++) cin>>p[i];
    sort(p,p+n);
    for(int j=0;j<n;j++) con[p[j]]++;
    for(int i=p[n-1];i>=1;i--){
      a[i]=a[i+1]+con[i];
      if(a[i]>=i){
        max=i;
        break;  
      }  
    }
  cout<<max<<endl;
}

Measured memory_bytes: 3120
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N,M = map(int,input().split())
ABC = [list(map(int,input().split())) for _ in range(M)]

g = [[0 for _ in range(N)] for _ in range(N)]

for a,b,c in ABC:
    g[a-1][b-1] = c

from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
csg = csgraph_from_dense(g)
d = floyd_warshall(csg, directed=False)

ans = 0
for a,b,c in ABC:
    if c != d[a-1][b-1]:
        ans += 1

print(ans)

Measured memory_bytes: 14252
#include <stdint.h>
#include <algorithm>
#include <bitset>
#include <functional>
#include <iostream>
#include <string>
#include <vector>

int gcd(int a, int b) {
  if (a < b) return gcd(b, a);
  if (a % b) return gcd(b, a % b);
  return b;
}

int main(int argc, char *argv[]) {
  using namespace std;
  int64_t N, K;
  vector<int> A;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    int v;
    cin >> v;
    A.push_back(v);
  }
  if (K > *max_element(A.begin(), A.end())) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  int g = A[0];
  for (int i = 1; i < N; i++) {
    g = gcd(g, A[i]);
  }
  if (K % g) {
    cout << "IMPOSSIBLE" << endl;
  } else {
    cout << "POSSIBLE" << endl;
  }
  return 0;
}


Measured memory_bytes: 892
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val a = (1..n).map { sc.nextInt() }


  val dis = mutableListOf<Int>()
  dis.add(Math.abs(a[0]))
  for (i in 0 until n-1) {
    val tmp = Math.abs(a[i+1] - a[i])
    dis.add(tmp)
  }
  dis.add(Math.abs(a[n-1]))

  val sum = dis.sum()

  val list = mutableListOf<Int>()
  list.add(0)
  list.addAll(a)
  list.add(0)

  val ans = mutableListOf<Int>()
  for (i in 1 until list.size - 1) {
    val pre = list[i-1]
    val now = list[i]
    val suf = list[i+1]

    val tmp = sum - Math.abs(now - pre) - Math.abs(suf - now) + Math.abs(suf - pre)
    ans.add(tmp)

  }

  println(ans.joinToString("\n"))

}

Measured memory_bytes: 65632
#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(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

int main() {
	int A, B, C; cin >> A >> B >> C;
	puts(A + B >= C ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int N , M, A;
    cin >> N >> M;
    for(int i=0; i<M; i++){
        cin >> A;
        N = N - A;
    }
    if(N<0)
        N = -1;
    cout << N << endl;
    return 0;
}

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

int main(void){
    // Your code here!
    int N;
    cin >> N;
    int last = 0;
    for(int i=0; i<N; i++) {
        int v;
        cin >> v;
        if(last == v) continue;
        if(last == v-1) continue;
        if(last < v) {
            last = v-1;
            continue;
        }
        cout << "No" << endl;
        return 0;
    }
    
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
using P = pair<int,int>;
using ivec = vector<int>;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }


const int MOD=1000000007;
int INF=100100100100100;
int slv(int n){
  int m=n/4*4;
  int res=0;
  for(int i=m;i<=n;i++)res^=i;
  return res;
}
        
signed main(){
  int a,b;
  cin>>a>>b;
  cout<<(slv(b)^slv(a-1))<<endl;
  return 0;
}

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

int main()
{
	#define int long long int
	int n,k;
	cin>>n>>k;
	int h[n+1];
	for(int i=1;i<=n;i++)
		cin>>h[i];
	int dp[n+1];
	dp[1]=0;
	dp[2]=abs(h[2]-h[1]);
	
	for(int i=3;i<=n;i++)
	{	dp[i]=INT_MAX;
		for(int j=1;j<=min(k,i-1);j++)
			{
			dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
		}
	}
	cout<<dp[n]<<endl;


}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
ll dist[1010][1010];
ll is_visit[1010][1010] = {};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H,W;
    cin >> H >> W;
    char c[1010][1010];
    rep(i,0,H){
        rep(j,0,W){
            cin >> c[i][j];
        }
    }
    queue<ll> qq;
    rep(i,0,H){
        rep(j,0,W){
            if(c[i][j] == '#') qq.push(i*W+j);
            if(c[i][j] == '#'){
                dist[i][j] = 0;
            }else{
                dist[i][j] = INF;
            }
        }
    }
    ll dh[4] = {0,0,1,-1};
    ll dw[4] = {1,-1,0,0};

    while(not qq.empty()){
        ll p = qq.front();
        qq.pop();
        ll i = p/W;
        ll j = p%W;
        // if(dist[i][j] != INF) continue;
        rep(k,0,4){
            ll hh = i + dh[k];
            ll ww = j + dw[k];
            if(hh >= 0 && hh < H && ww >= 0 && ww < W){
                if(dist[hh][ww] == INF){
                    dist[hh][ww] = dist[i][j] + 1;
                    qq.push(hh*W+ww);
                }
            }

        }

    }
    ll ans = 0;
    rep(i,0,H){
        rep(j,0,W){
            ans = max(ans, dist[i][j]);
        }
    }
    // rep(i,0,H){
    //     rep(j,0,W){
    //         cout << dist[i][j] << " \n"[j==W-1];
    //     }
    // }
    print(ans);


}

Measured memory_bytes: 19216
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);        
        int n = stdIn.nextInt();
        int x = stdIn.nextInt();
        int count = 1;
        int sum = 0;
        while(n-- > 0){
            sum += stdIn.nextInt();
            if(x < sum) break;
            count++;
        }
        System.out.println(count);

    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){

string s;
cin>>s;
ll n=s.size();
if(n==2 && s[0]==s[1]){
  return cout<<1<<" "<<2,0;
}
for(int i=0;i<n-2;i++){
  if(s[i]==s[i+1]){
    return cout<<i+1<<" "<<i+2,0;
  }
  if(s[i]==s[i+2]){
    return cout<<i+1<<" "<<i+3,0;
  }
}
cout<<-1<<" "<<-1<<endl;
return 0;
}


Measured memory_bytes: 3720
#include <iostream>
#include<vector>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i++){
          cin >> a[i];
    }
    long ans = 0;
    for(int i = 1;i < n;i++){
          if(a[i - 1] > a[i]){
                int t = a[i - 1] - a[i];
                ans += t;
                a[i] += t;
          }
    }
    cout << ans << endl;
}


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

string solve() {
    string S;
    cin >> S;
    if ( S == "Sunny") return "Cloudy";
    if ( S == "Cloudy") return "Rainy";
    else return "Sunny";
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
const int mod=1e9+7;
#define pb push_back
#define pii pair<ll,ll>
#define pi pair<int ,int> 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i,a,n) for(int i=a;i>=n;i-- )


int main()

{  
    ll n;
    cin>>n;
    ll x=n/2;
    if(n%2!=0){x++;}
    cout<<x;
    return 0;
}

Measured memory_bytes: 256
from heapq import nlargest

x,y,z,k = map(int,input().split())
A,B,C = [list(map(int,input().split())) for _ in [0]*3]

AB = nlargest(k,[a+b for a in A for b in B])
ABC = nlargest(k,[ab+c for ab in AB for c in C])
print("\n".join(map(str,ABC)))

Measured memory_bytes: 160480
res = ['-']
for mak in range(12) :
    tem = ['0' for temp in range(10)]
    res.append(tem)

for mak in range(int(input())) :
    a, b, c, d    = [int(temp) for temp in input().split()]
    res[((a - 1) * 3) + b][c - 1] = str(int(res[((a - 1) * 3) + b][c - 1]) + d)

for mak in range(1,13) :
    if mak != 1 and mak % 3 == 1 :
        print(('#' * 20))
    print('', ' '.join(res[mak]))

Measured memory_bytes: 7696
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
#include <set>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define PRIME1 99999883
#define PRIME2 99999893
#define EPS 0.00000001
using namespace std;

struct Info{
	Info(int arg_work,int arg_count){
		work = arg_work;
		count = arg_count;
	}
	int work,count;
};

int main(){

	int N,M;
	scanf("%d %d",&N,&M);

	vector<Info> V[N+1];
	int table[M+1];

	int s,t,e;

	while(true){
		scanf("%d %d %d",&s,&t,&e);
		if(s == 0 && t == 0 && e == 0)break;

		V[s].push_back(Info(t,e));
	}

	int L,sum;
	scanf("%d",&L);

	for(int loop = 0; loop < L; loop++){
		for(int i = 1; i <= M; i++)scanf("%d",&table[i]);

		sum = 0;
		for(int k = 0; k < V[1].size();k++){
			sum += table[V[1][k].work]*V[1][k].count;
		}
		printf("%d",sum);

		for(int i = 2; i <= N; i++){
			sum = 0;
			for(int k = 0; k < V[i].size();k++){
				sum += table[V[i][k].work]*V[i][k].count;
			}
			printf(" %d",sum);
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 4268
'''
Created on 2020/09/07

@author: harurun
'''
from dataclasses import *
@dataclass
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write

  N,Q=map(int,pin().split())
  uf=UnionFind(N)
  for i in range(Q):
    t,u,v=map(int,pin().split())
    if t==0:
      uf.union(u, v)
    else:
      if uf.same(u,v):
        print(1)
      else:
        print(0)
  return 
main()

Measured memory_bytes: 13412
from collections import Counter

n = int(input())
num_list = list(map(int,input().split()))
cntr = Counter(num_list).most_common()
ans = 0

for num,cnt in sorted(cntr,reverse=True):
    if cnt >= 4 and ans == 0:
        ans = num*num
        break
    elif cnt >= 2 and ans == 0:
        ans = num
    elif cnt >= 2:
        ans *= num
        break
print(ans)

Measured memory_bytes: 21540
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
using namespace std;

const int MAX = 100;

int main() {
	int N;
	string str[MAX];

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

	bool ans = true;
	set<string> s;

	for (int i = 1; i < N; i++) {
		if (str[i - 1][str[i - 1].length() - 1] != str[i][0]) {
			ans = false;
			break;
		}
	}

	for (int i = 0; i < N; i++) {
		if (s.count(str[i])) {
			ans = false;
			break;
		}
		s.insert(str[i]);
	}



	if (ans)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

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

using namespace std;

typedef pair<int, int> P;

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

    int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
    int w,h;
    while(cin>>w>>h,w||h){
        vector<vector<int> > field(100,vector<int>(100,0));
        for(int i=0;i<h;i++){
            string s;cin>>s;
            for(int j=0;j<w;j++){
                if(s[j]=='B') field[i][j]=1;
                else if(s[j]=='W') field[i][j]=-1;
            }
        }
        vector<vector<int> > black(100,vector<int>(100,0)),
                            white(100,vector<int>(100,0));
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(field[i][j]==1){
                    queue<P> q;
                    q.push(P(i,j));
                    while(!q.empty()){
                        P p=q.front();q.pop();
                        int y=p.first,x=p.second;
                        for(int k=0;k<4;k++){
                            int ny=y+dy[k],nx=x+dx[k];
                            if(nx<0||w<=nx||ny<0||h<=ny) continue;
                            if(field[ny][nx]!=0) continue;
                            if(black[ny][nx]) continue;
                            black[ny][nx]=1;q.push(P(ny,nx));
                        }
                    }
                }
                if(field[i][j]==-1){
                    queue<P> q;
                    q.push(P(i,j));
                    while(!q.empty()){
                        P p=q.front();q.pop();
                        int y=p.first,x=p.second;
                        for(int k=0;k<4;k++){
                            int ny=y+dy[k],nx=x+dx[k];
                            if(nx<0||w<=nx||ny<0||h<=ny) continue;
                            if(field[ny][nx]!=0) continue;
                            if(white[ny][nx]) continue;
                            white[ny][nx]=1;q.push(P(ny,nx));
                        }
                    }
                }
            }
        }
        int bl=0,wh=0;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(black[i][j]^white[i][j]){
                    bl+=black[i][j];wh+=white[i][j];
                }
            }
        }
        cout<<bl<<" "<<wh<<endl;
    }
    
}

Measured memory_bytes: 3324
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long ll;

int main(){
	long long x;
	scanf("%lld",&x);
	long long f = -1;
	for (ll i = 1; ;i ++){
		long long t = i * i * i * i * i - x;

		for (ll j = 0; ;j ++){
			ll  k = j * j * j * j * j;
			if (k == abs(t)){
				f = j;
				break;
			}
			if (k > abs(t)) break;
		}
		if (f != -1){
			if (t < 0) f = -f;
			printf("%lld %lld\n",i,f);
			return 0;
		}
	}
}

Measured memory_bytes: 3800
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi >
#define INF 1e9
#define MOD 1e9+7
typedef long long llong;
using namespace std;

int n,m;
vvi a;//a[i][j]はiにつながる頂点の配列.
vi dp;//dp[i]はiまでの有向パスの最長の長さ.

int f(int i){
	if(dp[i]!=0) return dp[i];
	REP(j,a[i].size()){
		dp[i]=max(dp[i],f(a[i][j])+1);//再帰.終端はa[i].size()が0のとき.
	}
	return dp[i];
}

int main(){
	cin>>n>>m;
	
	a.reserve(n+1);
	REP(i,m){
		int x,y;
		scanf("%d%d",&x,&y);
		a[y].push_back(x);
	}
	
	dp.reserve(n+1);
	fill(dp.begin(),dp.begin()+n+1,0);//point??????????reserveの解釈がいまいち...
	for(int i=1;i<=n;++i){
		REP(j,a[i].size()){
			dp[i]=max(dp[i],f(a[i][j])+1);
		}
	}
	
	int ans=0;
	for(int i=1;i<=n;++i){
		ans=max(ans,dp[i]);
	}
	
	cout<<ans<<endl;
}//解答参考.

Measured memory_bytes: 10624
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mem(arr,v) memset(arr,v,sizeof(arr))
/*bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
} */
int main()
{
     string s1,s2;
     cin>>s1>>s2;
     s1+=s2;
     ll n,pp;
     stringstream s;
     s<<s1;
     s>>n;
     pp=sqrt(n);
     if(pp*pp==n)
        cout<<"Yes"<<endl;
     else
        cout<<"No"<<endl;
}




Measured memory_bytes: 256
#include <stdio.h>
int main(void){

    int H,W,i,j;
    while(1){
    
        scanf("%d %d",&H,&W);
        if(H == 0 && W == 0)break;
        else{
          for(i=1;i<=H;i++){
              for(j=1;j<=W;j++){
                  putchar('#');
              }
            printf("\n"); 
          }
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 576
n = int(input())
grid = []
if n == 1:
    print(1)
    exit()
for _ in range(n):
    x,y = map(int,input().split())
    grid.append((x,y))
S = set(grid)
ans = float("inf")
for i in range(n-1):
    for j in range(i+1,n):
        cnt = 0
        p = grid[i][0]-grid[j][0]
        q = grid[i][1]-grid[j][1]
        for k in range(n):
            if (grid[k][0]-p,grid[k][1]-q) in S:
                cnt += 1
        else:
            ans = min(n-cnt,ans)
print(ans)

Measured memory_bytes: 3064