akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
using P=pair<long long,long long>;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll gcd(ll x, ll y){
  if(x%y==0)return y;
  return gcd(y,x%y);
}
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}
vector<vector<ll>>G(MAX);
vector<bool>seen(MAX,false);
vector<ll> ans(MAX);

void dfs(int p,int v){
  seen[v]=true;
  if(v!=0)ans[v]+=ans[p];
  for(auto nv:G[v]){
    if(!seen[nv]) dfs(v,nv);
  }
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  int n,q;
  cin >> n >> q;
  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  rep(i,q){
    int p,x;
    cin >> p >> x;
    p--;
    ans[p]+=x;
  }
  dfs(0,0);
  rep(i,n){
    if(i!=0)cout<<" ";
    cout << ans[i];
  }
  
}


Measured memory_bytes: 34048
#include<stdio.h>

int main() {
	int m = 0, f = 0, r = 0;
	for(int i=0;i<50;i++){
		char grade;
		scanf("%d %d %d", &m, &f, &r);
		if ((m == -1) && (f == -1) && (r == -1)) {
			break;
		}
		int score = m + f;
		if (m * f < 0) {
			grade = 'F';
		}
		else if (score >= 80) {
			grade = 'A';
		} else if (score >= 65) {
			grade = 'B';
		} else if (score >= 50) {
			grade = 'C';
		} else if (score >= 30) {
			grade = (r >= 50) ? 'C' : 'D';
		} else {
			grade = 'F';
		}
		printf("%c\n", grade);
	}

	return 0;
}



Measured memory_bytes: 2052
#include "bits/stdc++.h"
#include <random>
#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<pii> v(n);
  REP(i, n) cin >> v[i].first >> v[i].second;
  sort(ALL(v), [&](pii a, pii b) {return pii(a.first + a.second, a.second) < pii(b.first + b.second, b.second); });
  vector<int> x(n + 1);
  x[0] = -INF;
  REP(i, n) x[i + 1] = v[i].first + v[i].second;
  vi dp(n + 1, -INF);
  dp[0] = 0;
  REP(i, n) {
    int c = upper_bound(ALL(x), v[i].first - v[i].second) - x.begin();
    c--;
    dp[i + 1] = max(dp[c] + 1, dp[i]);
  }
  cout << dp[n] << endl;
}


Measured memory_bytes: 1792
s = input()
n = len(s)

a = "10" * (n // 2) + ("1" if n % 2 == 1 else "")
b = "01" * (n // 2) + ("0" if n % 2 == 1 else "")

sum_a = 0
for i in range(n):
    if s[i] != a[i]: sum_a += 1

sum_b = 0
for i in range(n):
    if s[i] != b[i]: sum_b += 1

print(min(sum_a, sum_b))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  int N = s.length();
  int M = t.length();
  vector<vector<int>> dp(N + 1, vector<int>(M + 1, 0));

  FOR(i, 1, N + 1) {
    FOR(j, 1, M + 1) {
      if(s[i - 1] == t[j - 1]) {
        dp[i][j] = dp[i - 1][j - 1] + 1;
      } else {
        dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
      }
    }
  }
  // dpテーブルを逆からたどる
  string ans = "";
  int x = N;
  int y = M;
  while(x > 0 && y > 0) {
    if(dp[x][y] == dp[x - 1][y]) {
      x--;
    } else if(dp[x][y] == dp[x][y - 1]) {
      y--;
    } else {
      x--;
      y--;
      ans.push_back(s[x]);
    }
  }
  reverse(all(ans));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 35584
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
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;}
Graph G(100010);

int dfs(int idx,int par){
  int ret=0;
  FORE(to,G[idx]){
    if(to==par) continue;
    ret+=dfs(to,idx);
  }
  if(ret>=2){
    co("First");
    exit(0);
  }
  
  if(ret==0) return true;
  else return false;
}

int main(){
  int N;
  cin>>N;
  REP(i,N-1){
    int a,b;
    cin>>a>>b;
    --a,--b;
    G[a].PB(b);
    G[b].PB(a);
  }
  
  if(dfs(0,-1)) co("First");
  else co("Second");
  return 0;
}

Measured memory_bytes: 5760
A=list(input())
N=len(A)

if A[-1]=="1":
    print(-1)
elif A[0]!="1" or A[-2]!="1":
    print(-1)
else:
    for i in range(N-1):
        if A[i]!=A[N-2-i]:
            print(-1)
            exit()
    X=1
    Y=0
    #print(A)
    for i in range(N-1):
        if A[i]=="1":
            print(Y+1,X+1)
            Y=X
            X+=1
        else:
            print(X+1,Y+1)
            X+=1

Measured memory_bytes: 5228
import java.io.PrintWriter;
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());
        sc.close();

        int C = A - 2 * B;
        if (C < 0)
            C = 0;
        
        PrintWriter out = new PrintWriter(System.out);
        out.println(C);
        out.flush();
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
typedef long long ll;
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=1e5+10;
int a[maxn];
int main(){
	int ans=1e9;
	int n=read(),m=read();
	REP(i,1,n) a[i]=read();
	int u=upper_bound(a+1,a+n+1,0)-a-1;
	REP(i,0,m){
		if(u-i<0) continue;
		if(u+m-i>n) continue;
		int x=-a[u-i+1],y=a[u+m-i];
		if(m-i==0) y=0;
		if(i==0) x=0;
		chkmin(ans,min(x+2*y,y+2*x));
	}
	printf("%d\n",ans);
	return 0;
}

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

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

	long long int sum = 0;
	vector<long long int> vec(1e5, 0);
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		vec[a]++;
		sum += a;
	}

	int q;
	cin >> q;

	for (int i = 0; i < q; i++) {
		long long int b, c;
		cin >> b >> c;

		sum -= vec[b] * b;
		sum += vec[b] * c;

		vec[c] += vec[b];
		vec[b] = 0;

		cout << sum << endl;
	}
}

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}
std::vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend
#define all(x) (x).begin(),(x).end()
#define size_t ll
int n,m;bool can=false,ck[200000]={false};
vector<int> b;
int main(){
  cin >> n >> m;
  for (size_t i = 0; i < m; i++) {
    int am,bm;
    cin >> am >> bm;
    if(am == 1)ck[bm]=true;
    if(bm == n)b.push_back(am);
  }
  for (size_t i = 0; i < b.size(); i++) {
    if(ck[b[i]])can = true;
  }
  cout << (can ? "POSSIBLE":"IMPOSSIBLE") << endl;
}


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

int main()
{
	int64_t a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;

	int64_t inf = (1LL << 60);

	int64_t ans = inf;

	for (int64_t i = 0; i <= 2 * max(x, y); i += 2)
	{
		ans = min(ans, c * i + a * max<int64_t>(0, (x - i / 2)) + b * max<int64_t>(0, (y - i / 2)));
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3620
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        sc.close();

        // 主処理
        boolean judge = s.matches("[a-z]");
        String result = judge ? "a" : "A";

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


Measured memory_bytes: 35676
#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>

int main()
{
    int x, a, b;
    std::cin >> x >> a >> b;
    int tmp = (x - a) / b;
    int ans = x - a - (b * tmp);
    std::cout << ans << std::endl;

    return 0;
}

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

int main() {
  static int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin >> k;
  cout << a[k - 1] << endl;
  return 0;
}

Measured memory_bytes: 256
eval'N,A,B='+`dd`.split*?,
A*=t=(A+B).pow -2+M=10**9+7,M
B*=t
a=A.pow N,M
b=B.pow N,M
S=0
[g=1,*(1...N).map{g=g*_1%M}].map{S+=_1.pow(M-2,M)*(a+b)*100*t=t*N%M
N+=1
a=a*B%M
b=b*A%M}
p S%M

Measured memory_bytes: 33904
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define MOD 1000000007
using namespace std;

long n;
ll   x;
vector<ll> a;

ll solve( long k )
{
    ll  ans = (n + k) * x;
    long i;
    for(i=1; i<=n; i++) {
        long curr = n-i;
        long m = ((i-1)/k+1);
        ans += a[curr] * (m>1? 2*m+1: 5);
    }
    return ans;
}

int main(int argc, char* argv[])
{
    scanf("%ld%lld", &n, &x);

    a.resize(n);
    long i;
    for(i=0; i<n; i++) {
        scanf("%lld", &a[i]);
    }
   
    long kk=1, mm=n;
    ll   kk_val=solve(kk);
    ll   mm_val=solve(mm);
    while(mm-kk>2) {
        long dif = (mm-kk)/3;
        long m0 = kk + dif;
        long m1 = m0 + dif;
        ll   m0_val = solve(m0);
        ll   m1_val = solve(m1);
        if(m0_val > m1_val) {
            kk = m0;  kk_val = m0_val;
        }
        else {
            mm = m1;  mm_val = m1_val;
        }
    }

    ll  min = MIN(kk_val, mm_val);
    for(i=kk+1; i<mm; i++) {
        ll val = solve(i);
        min = MIN(min, val);
    }
    printf("%lld\n", min);

    return 0;
}


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

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define sz size()
#define S second
#define F first
#define all(x) x.begin(), x.end()

typedef pair < int, int > pii;
typedef vector < int >  vi;
typedef vector < vector < int > >  vvi;

void solve(){
    int x;
    cin >> x;
    cout << 1 - x;
}

signed main() {
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}





Measured memory_bytes: 3592
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#include <numeric>
#include <math.h>

#define user spaesk
#define pi acos(-1)
#define int long long int
#define ld long double
#define ff first
#define ss second
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

typedef vector<vector<int> > matrix ;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const int ths = 1LL << 40;
const int NN = 5e3 + 6;

const int maxN = 1000007;

///abc 167_e
///standard

int f[N];

int modexp(int a, int n ) {

    int r = 1;
    while(n) {
        if(n & 1) {
            r = (r * a) % cmod;
        }
        a = (a * a) % cmod;
        n >>= 1;
    }
    return r;
}

int ncr(int n, int r) {

    if(n < r)
        return 1;
    int ans = (f[n] % cmod * modexp(f[r], cmod - 2) % cmod * modexp(f[n - r], cmod - 2) % cmod) % cmod;
    return ans;
}

void solve()
{

    int n, m, k;
    cin>>n>>m>>k;
    f[0] = 1;
    f[1] = 1;
    for(int i = 2; i < N; i ++) {
        f[i] = f[i - 1] * i;
        f[i] %= cmod;
    }
    int ans = 0;
    for(int i = 0; i <= k; i ++) {
        ans += (ncr(n - 1, i) % cmod  * m % cmod * modexp(m - 1, n - i - 1) % cmod);
        ans %= cmod;
    }
    cout<<ans;
    cout<<"\n";
    return ;
}

/*
*/

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

    int t = 1;
//    cin>>t;
    while(t --)
    {
        solve();
    }
    return 0;
}


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

int main() {
  string s;
  const char *sd = NULL;
  int n = 0;
  cin >> s;
  if (s.length() != 3) {
  	return 1;
  }
  sd = s.data();
  for (int i = 0; i < 3; i++) {
  	if (sd[i] == '1') {
      n++;
    }
  }
  cout << n << endl;
}

Measured memory_bytes: 256
S = input().rstrip()
T = input().rstrip()

abc = ["a","b","c","d","e","f",
       "g","h","i","j","k","l",
       "m","n","o","p","q","r",
       "s","t","u","v","w","x",
       "y","z"]

for i in range(len(abc)):
  t = S + abc[i]
  if t == T:
    print("Yes")
    break
else:
  print("No")

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

using namespace std;
using ll = long long;

void init();
void solve();

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__  "YES"
#define FALSE__ "NO"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a
#define lcoutln(a) cout << a << endl
#define lcerr(a) cerr << a
#define lcerrln(a) cerr << a << endl
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif
#define MOD 1000000007
#define PI 3.141592653589793238462643383

signed main()
{
	init();
	solve();
}
int N;
vector<ll> v;
void init()
{
	cin >> N;
	v.resize(N);
	rep(i, N) cin >> v[i];
}

void solve()
{
	int st = 0;
	int en = 1;
	ll res = 0;
	ll check = v[0];
	while (st != N) {
		while ((check & v[en]) == 0 && en < N) {
			check |= v[en++];
		}
		res += en - st;
		check ^= v[st];
		st++;
	}
	cout << res << endl;
}

Measured memory_bytes: 1792
n=int(input())
P=[int(i) for i in input().split()]
Q=[int(i) for i in input().split()]
import itertools
ct=1
for c in itertools.permutations(range(n),n):
  c=list(c)
  for i in range(n):
    if P[i]-1==c[i]:
      continue
    else:
      break
  else:
    a=ct
  for i in range(n):
    if Q[i]-1==c[i]:
      continue
    else:
      break
  else:
    b=ct
  ct+=1
print(abs(a-b))




Measured memory_bytes: 3064
h,w=map(int,input().split())
l=[input() for i in range(h)]

ans=[]

for i in range(h):
    if "#" in l[i]:
        ans.append(l[i])
        
for i in range(w):
    if all([ans[j][i]=="." for j in range(len(ans))]):
        for k in range(len(ans)):
            ans[k]=list(ans[k])
            ans[k][i]=""

for i in range(len(ans)):
    print("".join(ans[i]))

Measured memory_bytes: 3064
a, b, h, m = gets.chomp.split.map(&:to_f)
theta = ((h * 60 + m)/(12.0 * 60) - m / 60).abs * 2 * Math::PI
puts "%.10f" % [Math::sqrt(a * a + b * b - 2 * a * b * Math::cos(theta))]

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

struct city {
    int P;
    int Y;
    int i;

    bool operator<(const city &another) const {
        if (P == another.P)
            return Y < another.Y;
        else
            return P < another.P;
    };
};

int main() {
	int N,M;
	cin >> N >> M;
  vector<city> c(M);
  vector<string> ans(M); 
  rep(i,M){
    cin >> c[i].P >> c[i].Y;
    c[i].i = i;
  }
  sort(all(c));

  int before = -1;
  int count = 0;
  rep(i,M){
    int ci = c[i].P;
    int no = ci == before ? count + 1 : 1;
    before = ci;
    count = no;
    int len = to_string(ci).size();
    int lenNo = to_string(no).size();
    int index = c[i].i;
    ans[index] = ("000000" + to_string(ci)).substr((6+len)-6,6)
              + ("000000" + to_string(no)).substr((6+lenNo)-6,6);
  }

  rep(i,M) cout << ans[i] << endl;
}

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

int main() 
{
    int n;
    cin >> n;
    vector<ll> v;
    for (int i=0; i<n; i++)
    {
        ll a; 
        cin >> a;
        v.push_back(a);
    }
    sort(v.begin(), v.end());
    auto it = unique(v.begin(), v.end());
    if (it - v.begin() == v.size())
        cout << "YES";
    else 
        cout << "NO";
    return 0;
}

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

int main()
{
	int a, b, c, d;
	int t;

	cin >> a >> b >> c >> d;

	if (a < c)
	{
		if (b < d)
		{
			t = b - c;
		} else {
			t = d - c;
		}
	} else {
		if (b < d)
		{
			t = b - a;
		} else {
			t = d - a;
		}
	}

	if (t < 0)
	{
		cout << 0 << endl;
	} else {
		cout << t << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] x = new int[N];
        int[] X = new int[N];
        int s = 0;
        long ans = Long.MAX_VALUE;
        for (int i = 0; i < N; i++) {
            x[i] = sc.nextInt();
            X[i] = Math.abs(x[i]);
        }
        for (int i = 0; i <=N - K; i++) {
            int num = Math.abs(x[i] - x[i + K - 1]) + Math.min(X[i], X[i + K - 1]);
            if(ans>num){
                ans=num;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 49672
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;

int main()
 {
 	int a,b;
 	cin>>a>>b;
 	if(2*b>=a)
 		cout<<"0"<<endl;
 	else
 		cout<<a-2*b<<endl;
 	return 0;
}
 	
 					

Measured memory_bytes: 3644
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define sort(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
#define P pair<int,int>
#define mk make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }



int main() {
	int n, s = 0;
	cin >> n;
	vector<int> x(8);
	rep(i, n) {
		int a;
		cin >> a;
		if (a >= 3200) {
			s++;
		}
		else {
			x[a / 400]++;
		}
	}
	int ans = 0;
	rep(i, 8) {
		if (x[i] > 0) {
			ans++;
		}
	}
	cout << max(ans,1) << " " << ans + s << endl;
	return 0;
}



Measured memory_bytes: 256
// https://atcoder.jp/contests/abc076/tasks/abc076_c
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main(){
    string S, T, X = "";
    cin >> S >> T;
    reverse(S.begin(), S.end());
    reverse(T.begin(), T.end());

    // キー判別部分と残りの?を梅るる部分で分ける
    bool flag = false;
    for(int i = 0; i < S.size(); i++){
        bool flag_ = true;
        for(int j = 0; j < T.size(); j++){
            if(S[i+j] !='?' && S[i+j] != T[j]){
                flag_ = false;
                break;
            }
        }
        if(flag_) {
            flag = true;
            X += S.substr(0, i);
            X += T;
            X += S.substr(i+T.size());
            break;
        }
    }
    reverse(X.begin(), X.end());
    for(int i = 0; i < X.size(); i++){
        if(X[i] == '?') X[i] = 'a';
    }
    if(flag) cout << X << endl;
    else cout << "UNRESTORABLE" << endl;
    
}

Measured memory_bytes: 256
def main():
    from itertools import accumulate
    from collections import Counter
    N = int(input())
    A = [int(i) for i in input().split()]
    S = list(accumulate([0] + A))
    # print(S)
    c = Counter(S)
    ans = 0
    for v in c.values():
        ans += v*(v-1)//2
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 41620
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <cmath>
#include <sstream>
#include <map>
#define F first
#define S second
#define FOR(i,n) for(int i=0;i<(int)n;i++)
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define FORI(i,k,n) for(int i=k;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
using namespace std;
typedef pair<double, double> pdd;
typedef pair<int, int> pii;
typedef pair< int , pair<int, int> > pip;
typedef unsigned long long ull;
const double EPS = 10e-6;
const int MMM=1000000007;

ull pow(ull m,ull n)
{
	if(n==0)return 1;
	if(n%2==1)return pow(m*m%MMM,n/2)*m%MMM;
	return pow(m*m%MMM,n/2)%MMM;
}
int main()
{
	ull n,m;
	cin>>m>>n;
	cout<<pow(m,n)%MMM<<endl;
}

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

using namespace std;

int main()
{
  int n, m, s, t, u;

  while(cin>>n>>m && (n+m)){
    s = 0;
    for(int i = 0; i < n; i++){
      t = 0;
      for(int j = 0; j < m; j++){
	cin >> u;
	t += u;
      }
      s = max(t, s);
    }

    cout << s << endl;
  }

  return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <fstream>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int,int> PI;
typedef vector<PI> VPI;
typedef unsigned long long ull;
typedef long long ll;

#define FOR(i, n) for(int i=0;i<(n);++i)
#define REP(i,s,n) for(int i=s;i<=n;++i)
#define SZ(x) ((int)(x).size())
#define LOOP(i,x) FOR(i,SZ(x))
#define IT(it,x) for(typeof((x).begin()) it = (x).begin();it!=(x).end();++it)
#define ALL(x) (x).begin(), (x).end()
#define ST first
#define ND second
#define MP make_pair
#define PB push_back
#define gc getchar

const int INF = 1e9 + 5;
const int MAXN = 1e3 + 5;
const int MOD = 1e9 + 7;

string grid[MAXN];
int ways[MAXN][MAXN];
bool visited[MAXN][MAXN];

int dfs(int x, int y) {
	if (x < 0 || y < 0 || grid[x][y] == '#') return 0;
	if (x == 0 && y == 0) return 1;
	if (visited[x][y]) return ways[x][y];
	visited[x][y] = true;

	int left = dfs(x - 1, y);
	int up = dfs(x, y - 1);
	ways[x][y] = (left + up) % MOD;

	return ways[x][y];
}

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

	int rows, cols;
	cin >> rows >> cols;
	for (int i = 0; i < rows; i++) cin >> grid[i];
	dfs(rows, cols);
	cout << ways[rows - 1][cols - 1] << endl;

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define foreach(it, S) for (__typeof (S.begin()) it = S.begin(); it != S.end(); it++)
#define all(x) x.begin(), x.end()
#define endl '\n'
#define _ ios_base :: sync_with_stdio(false); cin.tie(NULL);

#ifdef inputf
# define fname ""
#else
# define fname "" // <- Here
#endif

#ifndef lcl
# define cerr if (0) cout
#endif

template <typename T> T gcd(T a, T b) {
	return b ? gcd (b, a % b) : a;
}

#define dlong long double

const dlong eps = 1e-30;
const int MAXN = (1 << 20) + 256;
const int MOD = (int)1e9 + 7, INF = (int)1e9;
const ll INFLL = (ll)1e18;

int main() { // _
	#ifdef lcl
		freopen(fname".in", "r", stdin);
		freopen(fname".out", "w", stdout);
	#endif

	string s; cin >> s;

	vector <char> st;

	int cnt = 0;

	for (auto c : s) {
		if (!st.empty() && st.back() == 'S' && c == 'T')
			st.pop_back(), ++cnt;
		else
			st.push_back(c);
	}

	cout << st.size() << endl;
	return 0;
}


Measured memory_bytes: 772
#include <iostream>
#include <iomanip>

#include <vector>
#include <string>
#include <iterator>
#include <algorithm>

typedef long long ll;
const long double PI = (acos(-1));
const long long MOD = 1000000007;
#define rep(i,n) REP(i,0,n)
#define REP(i,x,n) for(int i=x;i<n;++i)

using namespace std;

// change min/max
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; }

template<class T> void output(std::vector<T> & A) {
    const int n = A.size();
    for (int i = 0; i < n - 1; ++i) {
        std::cout << A[i] << " ";
    }
    std::cout << A[n - 1] << std::endl;
}

#define MAX 100001
const int NIL = -1;
struct Node { int parent = NIL, left = NIL, right = NIL; };
Node node[MAX];
int depth[MAX];
int height[MAX];

// to change
int setHeight(int currentNb) {
    int hleft = 0, hright = 0;
    if (node[currentNb].left != NIL) {
        hleft = setHeight(node[currentNb].left) + 1;
    }
    if (node[currentNb].right != NIL) {
        hright = setHeight(node[currentNb].right) + 1;
    }
    height[currentNb] = std::max(hleft, hright);
    return height[currentNb];
}

void setDepth(int currentNb, int currentDepth) {
    depth[currentNb] = currentDepth;
    if (node[currentNb].left  != NIL) setDepth(node[currentNb].left , currentDepth + 1);
    if (node[currentNb].right != NIL) setDepth(node[currentNb].right, currentDepth + 1);
}

int getSib(int currentNb) {
    const int nbParent = node[currentNb].parent;
    if (nbParent == NIL) return NIL;
    if (node[nbParent].left != currentNb) {
        return node[nbParent].left;
    }
    else {
        return node[nbParent].right;
    }
}

int getDegree(int currentNode) {
    int cnt = 0;
    if (node[currentNode].left  != NIL) ++cnt;
    if (node[currentNode].right != NIL) ++cnt;
    return cnt;
}

string nodeType(int currentNb) {
    if (node[currentNb].parent == NIL) return "root";
    if (getDegree(currentNb) == 0) return "leaf";
    return "internal node";
}

void printNodes(int nbNode) {
    rep(i, nbNode) {
        cout << "node " << i << ": parent = " << node[i].parent << ", ";
        cout << "sibling = " << getSib(i) << ", degree = " << getDegree(i) << ", ";
        cout << "depth = " << depth[i] << ", height = " << height[i] << ", " << nodeType(i);
        cout << endl;
    }
}

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

    int n; cin >> n;
    rep(i, n) {
        int nbNode;  cin >> nbNode;
        int nbLeft;  cin >> nbLeft;
        int nbRight; cin >> nbRight;
        node[nbNode].left  = nbLeft;  node[nbLeft].parent = nbNode;
        node[nbNode].right = nbRight; node[nbRight].parent = nbNode;
    }

    // find the root
    int root;
    rep(i, n) {
        if (node[i].parent == NIL) root = i;
    }

    setDepth(root, 0);
    setHeight(root);
    printNodes(n);

    return 0;
}



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

int main(void)
{
  string S;
  cin >> S;
  
  if(S[0]==S[1]||S[1]==S[2]||S[2]==S[3])cout << "Bad" << endl;
  else cout << "Good" << endl;
  
  return 0;
}




Measured memory_bytes: 256
(let* ((lst (concatenate 'list (read-line)))
       (a (car lst))
       (b (caddr lst)))

  (defun f (x y)
    (if (char= x #\H)
      y
      (if (char= y #\H)
        #\D
        #\H)))

  (format t "~A~%"
          (f a b)))


Measured memory_bytes: 24468
#include<stdio.h>
#define FREE 0
#define NOT_FREE 1
#define N 8

int row[N],col[N],dpos[N*2-1],dneg[N*2-1];
int arr[N][N];

void putqueen(int );
void printBoard();

void putQueen(int i){
  int j;
  if(i==N){
    printBoard();
    return;
  }
  for(j=0;j<N;j++){
    if(col[j]==NOT_FREE||dpos[i+j]==NOT_FREE||dneg[i-j+N-1]==NOT_FREE)
      continue;
    row[i]=j;
    col[j]=NOT_FREE;
    dpos[i+j]=NOT_FREE;
    dneg[i-j+N-1]=NOT_FREE;
    putQueen(i+1);
    col[j]=FREE;
    dpos[i+j]=FREE;
    dneg[i-j+N-1]=FREE;
  }
}

void printBoard(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(arr[i][j]==2){
        if(row[i]!=j) return;
      }
    }
  }

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
  return;
}

int main(){
  int i,n,a,b;
   
  for(i=0;i<N;i++){
    row[i]=FREE;
    col[i]=FREE;
  }
  for(i=0;i<N*2-1;i++){
    dpos[i]=FREE;
    dneg[i]=FREE;
  }
   
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&a,&b);
    arr[a][b]=2;
  }
  putQueen(0);
  return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int a[2001][51];
const int C=38;
int k = C;
int n = k*(k-1)+1; 
int cnt[2001];

bool check_valid(int x)
{
	memset(cnt,0,sizeof(cnt));
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			int pos=0;
			vi vec;
			for(int z=0;z<x;z++)
			{
				cnt[a[i][z]]++;
				cnt[a[j][z]]++;
				vec.pb(a[i][z]);vec.pb(a[j][z]);
				if(cnt[a[i][z]]==2)
				{
					pos++;
				}
				if(cnt[a[j][z]]==2)
				{
					pos++;
				}
				if(pos>=2) return false;
			}
			for(int z=0;z<vec.size();z++) cnt[vec[z]]=0;
			//cerr<<i<<' '<<j<<' '<<pos<<'\n';
		}
	}
	return 1;
}


int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	/*
	int st=0;
	for(int i=0;i<k;i++)
	{
		int iter=0;
		do
		{
			int cur=st;
			for(int j=0;j<n;j++)
			{
				a[cur][i]=j;
				cur++;
				if(cur>=n) cur-=n;
			}
			st=(st+1)%n;
			iter++;
			if(iter>=n) 
			{
				cout<<i+1<<' '<<"NO\n"; return 0;
			}
		}while(!check_valid(i+1));
		cout<<"ROW "<<i+1<<" COMPLETE"<<endl;
	}
	assert(check_valid(k));
	*/
	for(int i=0;i<k;i++)
	{
		a[i][0]=0;
	}
	for(int i=1;i<k;i++)
	{
		for(int j=k+(i-1)*(k-1);j<k+i*(k-1);j++)
		{
			a[j][0]=i;
		}
	}
	int cur=1;
	for(int i=0;i<k;i++)
	{
		for(int j=1;j<k;j++)
		{
			a[i][j]=cur++;
		}
	}
	cur=k;
	for(int j=1;j<k;j++)
	{
		int diff=j-1;
		for(int z=0;z<k-1;z++)
		{
			int curx=k;
			int curd=z;
			for(int zz=0;zz<k-1;zz++)
			{
				a[curx+curd][j]=cur;
				curx+=k-1;
				curd+=diff;curd%=(k-1);
			}
			cur++;
		}
	}
	//assert(check_valid(k));
	cout<<n<<' '<<k<<'\n';
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<k;j++)
		{
			cout<<a[i][j]+1;
			if(j+1<k) cout<<' ';
		}
		cout<<'\n';
	}
}	


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

int main() {
  int a,b;
  cin >> a >> b;
  bool c=true;
  vector<int> vec{0,1,3,1,2,1,2,1,1,2,1,2,1};
  
  if(vec.at(a)!=vec.at(b)){
    c=false;
  }
  
  if(c){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }  
}

Measured memory_bytes: 256
def has_eight_elements(n):
    if n%2 == 1 and sum([int(n%i==0) for i in range(1,n+1)]) == 8:
        return 1
    else:
        return 0
    
print(sum([has_eight_elements(x) for x in range(1,int(input())+1,2)]))

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

int main(int, char**) {
    ios_base::sync_with_stdio(0); cin.tie(NULL);

    lint N, A, B;
    cin >> N >> B >> A;
    
    lint x = N / (A + B);
    lint y = N % (A + B);
    
    cout << (x*B + min(y, B)) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// __uint128_t
const ll MOD = 1e9+7;

// a^n mod を計算する
ll modpow(ll a, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    ll N; cin >> N;
    vector<vector<ll>> DP(N+1, vector<ll>(4));
    if(N == 1) { cout << 0 << endl; return 0; }
    DP[1][0] = 0, DP[1][1] = 1, DP[1][2] = 1, DP[1][3] = 8;

    for(int i = 2; i <= N; i++){
        DP[i][0] = (DP[i-1][0]*10 + DP[i-1][1] + DP[i-1][2])%MOD;
        DP[i][1] = (DP[i-1][1]*9 + DP[i-1][3])%MOD;
        DP[i][2] = (DP[i-1][2]*9 + DP[i-1][3])%MOD;
        DP[i][3] = (DP[i-1][3]*8)%MOD;
    }
    cout << DP[N][0] << endl;


}



Measured memory_bytes: 73320
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
int s, h[200005], i, dp[200005] = {}, J1, J2;
int main(){
	cin >> s;
	for (i = 0; i < s; ++i)cin >> h[i];
	dp[1] = abs(h[1] - h[0]);
	for (i = 2; i < s; ++i){
		J1 = abs(h[i] - h[i - 1]) + dp[i - 1];
		J2 = abs(h[i] - h[i - 2]) + dp[i - 2];
		dp[i] = min(J1, J2);
	}
	cout << dp[s - 1];
}

Measured memory_bytes: 1024
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	int[] p=new int[200000];
	{
		Arrays.fill(p, -1);
	}
	
	int root(int x) {
		return p[x]==-1?x:(p[x]=root(p[x]));
	}
	
	void unite(int x,int y) {
		x=root(x);y=root(y);
		if (x!=y) p[x]=y;
	}
	
	boolean equiv(int x,int y) {
		return root(x)==root(y);
	}
	
	void run() {
		FastScanner sc=new FastScanner();
		int N=sc.nextInt();
		int Q=sc.nextInt();
		PrintWriter pw=new PrintWriter(System.out);
		while (Q-->0) {
			int t=sc.nextInt();
			int u=sc.nextInt();
			int v=sc.nextInt();
			if (t==0) unite(u,v);
			else pw.println(equiv(u,v)?1:0);
		}
		pw.flush();
	}
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}


Measured memory_bytes: 40420
package main

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

func main() {
	sc := NewScanner()
	A, B, H, M := sc.NextFloat(), sc.NextFloat(), sc.NextFloat(), sc.NextFloat()

	L := H/12.0*360 + M/60.0*30
	S := M / 60 * 360

	x1 := A * math.Sin(L/180*math.Pi)
	y1 := A * math.Cos(L/180*math.Pi)

	x2 := B * math.Sin(S/180*math.Pi)
	y2 := B * math.Cos(S/180*math.Pi)

	ans := math.Sqrt(math.Pow(x1-x2, 2) + math.Pow(y1-y2, 2))
	fmt.Println(ans)
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 1728
import collections

n,q=map(int,input().split())
cnt=[0]*(n+1)
g=[[] for _ in range(n+1)]
for _ in range(n-1): #木グラフの隣接リストを作成
 a,b=map(int,input().split())
 g[a].append(b)
 g[b].append(a)
for _ in range(q): #各頂点についてcount[v]を計算
 v,val=map(int,input().split())
 cnt[v]+=val
q=collections.deque()
q.append(1) #DFSのスタックによる実装、まずスタックに始点1を積む
checked=[0]*(n+1) #各頂点を見たかどうかのフラグを持っておく
while q:
 v=q.pop()
 checked[v]=1 #頂点を見たかどうかのフラグを更新する
 for u in g[v]:
   if checked[u]==1: #vの子ノードuについて、まだ見ていない頂点であればcount[u]をcount[u]+=count[v]として更新する
     continue
   cnt[u]+=cnt[v]
   q.append(u) #スタックに子ノードuを積む
print(*cnt[1:]) #各頂点のcountが答えとなる

Measured memory_bytes: 56160
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>

using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    int z;
    if (a+b < 2*c)
    {
        //aとbをそれぞれ買う
        cout << a * x + b * y << endl;
    } else {
        z = min(x, y);
        if (z == x) {
            if (b < 2*c) 
            {
                cout << b * (y-z) + z * 2 * c << endl;
            } 
            else 
            {
                cout << y * 2 * c << endl; 
            }
        } 
        else {
            if (a < 2*c) 
            {
                cout << a * (x-z) + z * 2 * c << endl;
            } 
            else 
            {
                cout << y * 2 * c << endl; 
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include<functional>
#include<queue>
#include<regex>
#include<time.h>
#include<type_traits>

using namespace std;


#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl

#define Tof(x) (x) ? Yes : No
#define TOF(x) (x) ? YES : NO
#define tof(x) (x) ? yes : no

using ll = long long;

constexpr ll MOD = 1000000007;
constexpr ll INF = 1050000000;
constexpr long long LONGINF = 1005000000000000000;



/*for文でx,yを上下左右確認するやつだよ。正直使いづらいよ。

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


for (int i = 0; i < 4; i++) {
	int ny = y + dy[i];
	int nx = x + dx[i];
}

*/


/*繰り返し二乗法だよ。modもとってくれるよ。n^kをmodで割った余りでやってくれるよ。

ll POW_MOD(ll n, ll k, ll mod) {
	ll r = 1;

	for (; k > 0; k >>= 1) {
		if (k & 1) {
			r = (r * n) % mod;
		}
		n = (n * n) % mod;
	}
	return r;
}

*/



/*まだ使えないテクニックのメモだよ。

for (int bit = 0; bit < (1<<n); ++bit)//bit全探索用のfor文だよ

*/


int main() {
	int k, x; cin >> k >> x;
	int i;
	for (i = x - k + 1; i < x +  k - 1; i++) {
		cout << i << " ";
	}

	cout << i << endl;


	return 0;
}


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

int main() {
   string s, t, u;
   int a, b;
   cin >> s >> t >> a >> b >> u;

   map<string, int> ball;
   ball[s] = a;
   ball[t] = b;

   ball[u]--;

   cout << ball[s] << " " << ball[t] << endl;
}

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

#define stirng string
#define vvi vector<vector<int>>
#define vi vector<int>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const int inf = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  int ans = 0;
  if (s[0] == '0') {
    for (int i = 0; i < s.size(); i++) {
      if (i % 2 == 0 && s[i] != '0') {
        ans++;
      } else if (i % 2 == 1 && s[i] != '1') {
        ans++;
      }
    }
  } else {
    for (int i = 0; i < s.size(); i++) {
      if (i % 2 == 0 && s[i] != '1') {
        ans++;
      } else if (i % 2 == 1 && s[i] != '0') {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512