akhauriyash/Code-Regression huggingface dataset:
def main():
    n, m = map(int, input().split())
    num = [0] * n
    reserved = [False] * n
    for _ in range(m):
        s, c = map(int, input().split())
        s -= 1
        if reserved[s]:
            if c != num[s]:
                print(-1)
                exit()
        else:
            reserved[s] = True
            num[s] = c
    if n > 1 and not reserved[0]:
        num[0] = 1
    if n > 1 and num[0] == 0:
        print(-1)
    else:
        print("".join(map(str, num)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 61284
import java.util.*

fun main(args: Array<String>) {
    val sc=Scanner(System.`in`)
    var k=sc.next()
    var count:Int=0
   if(k[0]=='R' && k[1]=='R' && k[2]=='R')
   {
        count=3
   }
    if(k[0]=='R' && k[1]=='R' && k[2]!='R')
    {
        count=2
    }
    if(k[1]=='R' && k[2]=='R' && k[0]!='R')
    {
        count=2
    }
    if(k[0]=='R' && k[1]!='R' && k[2]=='R')
    {
        count=1
    }
    if(k[0]!='R' && k[1]=='R' && k[2]!='R')
    {
        count=1
    }
    if(k[0]=='R' && k[1]!='R' && k[2]=='R')
    {
        count=1
    }
    if(k[0]=='R' && k[1]!='R' && k[2]!='R')
    {
        count=1
    }
    if(k[0]!='R' && k[1]!='R' && k[2]=='R')
    {
        count=1
    }
    println(count)
}



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

int main() {
  int N;
  scanf("%d", &N);
  
  vector<pair<string,int>> SP(N);
  vector<pair<string,int>> SPcopy(N);
  for (int i = 0; i < N; ++i) {
    cin >> SP[i].first;
    cin >> SP[i].second;
  }

  for (int i = 0; i < N; ++i){
    SP[i].second = 100 - SP[i].second;
  }

  for (int i = 0; i < N; ++i){
    SPcopy[i].first = SP[i].first;
    SPcopy[i].second = SP[i].second;
  }

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

  for (int i = 0; i < N; ++i){
    int hold = 1;
    for (int j = 0; j < N; ++j){
      if(SP[i].first == SPcopy[j].first && SP[i].second == SPcopy[j].second){
        break;
      }
      hold++;
    }

    cout << hold << endl;

  }
}



Measured memory_bytes: 256
from collections import defaultdict

max_x = 1000000000

if __name__ == '__main__':
    s = int(input())
    if s == max_x * max_x:
        print(0,0,max_x,0,0,max_x)
    else:
        y1, rem = divmod(s, max_x)
        y1 += 1
        rem = max_x - rem
        print(0,0,max_x,1,rem,y1)


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

signed main() {
  cin.tie(0); ios::sync_with_stdio(false);
  struct vertex { int i, par, dep, x, y; vector<int> chi; };
  int n; cin >> n;
  vector<vertex> tree(n);
  for (int i = 0; i < n; i++) {
    tree[i].i = i;
  }
  tree[0].par = 0;
  for (int i = 1; i < n; i++) {
    int p; cin >> p; p--;
    tree[i].par = p;
    tree[p].chi.push_back(i);
  }
  for (int i = 0; i < n; i++) {
    int x; cin >> x;
    tree[i].x = x;
  }
  for (int i = 0; i < n; i++) {
    int t = i, d = 0;
    while (t != 0) {
      t = tree[t].par;
      d++;
    }
    tree[i].dep = d;
  }
  sort(tree.begin(), tree.end(), [](auto a, auto b) { return a.dep > b.dep; });
  vector<int> acc(n);
  for (int i = 0; i < n; i++) acc[tree[i].i] = i;
  auto minw = [&](int i) {
    set<int> s1, s2;
    s1.insert(0);
    for (auto&& c : tree[acc[i]].chi) {
      for (auto&& s : s1) {
        s2.insert(s + tree[acc[c]].x);
        s2.insert(s + tree[acc[c]].y);
      }
      s1 = s2;
      s2.clear();
    }
    if (*s1.begin() > tree[acc[i]].x) return -1;
    return tree[acc[i]].x - *(--upper_bound(s1.begin(), s1.end(), tree[acc[i]].x));
  };
  for (auto&& v : tree) {
    int w = minw(v.i);
    if (w < 0) {
      cout << "IMPOSSIBLE" << '\n';
      return 0;
    } else {
      int s = 0;
      for (auto&& c : v.chi) s += tree[acc[c]].x + tree[acc[c]].y; 
      v.y = w - v.x + s;
    }
  }
  cout << "POSSIBLE" << '\n';
  return 0;
}

Measured memory_bytes: 5504
#include <iostream>
#include <vector>

using namespace std;

int main()
{

    int N, X;
    cin >> N >> X;
    vector<int> L(N, 0);

    for(auto&& x: L){
        cin >> x;
    }

    int D = 0;
    int count = 0;
    for (int i = 0; i < N; ++i){
        D = D + L[i];
        if( D <= X ){
            ++count;
        }
    }

    cout << count+1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MIN(x,y) (x)>(y)?(y):(x)

int main(void) {
	long long n,m,cnt;

	scanf("%lld %lld",&n,&m);
	
	cnt = MIN(n,m/2);
	
	n -= cnt;
	m -= cnt*2;
	
	cnt += m/4;
	
	printf("%lld\n",cnt);
	
	return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    string str;
    cin>>str;
    for(int i=0;i<(int)str.size();i++)
        if(str[i]==',')str[i]=' ';
    cout<<str<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl
#define int ll

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, N = 1e10 + 7, M = sqrt(N) + 5;

int np[M];

map<int, int> cnt, sq, inv;
vi primes;

pi normalize(int n) {
	int norm = 1, want = 1;
	for(int prime:primes) {
		if(n % prime == 0) {
			int cnt = 0;
			while(n % prime == 0) cnt++, n /= prime;
			cnt %= 3;
			if(cnt == 1) {
				norm *= prime;
				want *= prime * prime;
			} else if(cnt == 2) {
				norm *= prime * prime;
				want *= prime;
			}
		}
	}
	norm *= n;
	if(sq[n]) {
		want *= sq[n];
	} else {
		want *= n * n;
	}
	return {norm, want};
}

signed main()
{
	IO_OP;

	sq[1] = 1;
	for(int i = 2; i < M; i++) {
		if(np[i]) continue;
		sq[i*i] = i;
		if(i*i*i <= N) primes.PB(i);
		for(int j = i * i; j < M; j += i) {
			np[j] = 1;
		}
	}
	int n;
	cin >> n;
	bool hasone = false;
	for(int i = 0; i < n; i++) {
		int s;
		cin >> s;
		pi get = normalize(s);
		if(get.F == 1) {
			hasone = true;
			continue;
		}
		cnt[get.F]++;
		inv[get.F] = get.S;
		inv[get.S] = get.F;
	}
	int ans = 0;
	for(pi p:cnt) {
		ans += max(cnt[p.F], cnt[inv[p.F]]);
		cnt[p.F] = cnt[inv[p.F]] = 0;
	}
	ans += hasone;
	cout << ans << endl;
	
}





Measured memory_bytes: 31616
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        String s = scan.next();
        int Ccount = 0;
        if(s.charAt(0) != 'A'){
            System.out.println("WA");
            System.exit(0);
        }
        for(int i = 1; i < s.length(); i++){
            if(i >= 2 && i < s.length() - 1){
                char c = s.charAt(i);
                if(c == 'C')Ccount++;
                else if(c >= 'A' && c <='Z'){
                    System.out.println("WA");
                    System.exit(0);
                }
            }
            else {
                char c = s.charAt(i);
                if(c >= 'A' && c <= 'Z'){
                    System.out.println("WA");
                    System.exit(0);
                }
            }
        }
        if(Ccount == 1)System.out.println("AC");
        else System.out.println("WA");
        return;
    }
}                                                                    

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
typedef long long ll;
const int MOD = 1000000007; 
 
int main() {
    int n;
    cin >> n;
    vector<vector<double>> dis(n, vector<double>(n, 0));
    vector<pair<int, int>> xy;
    for(int i = 0; i < n; ++i) {
        int x,y;
        cin >> x >> y;
        xy.push_back({x, y});
    }
    for(int i = 0; i < n-1; ++i) {
        for(int j = i+1; j < n; ++j) { 
            double xd = xy[i].first - xy[j].first;
            double yd = xy[i].second - xy[j].second;
            double d = sqrt(xd*xd+yd*yd);
            dis[i][j] = dis[j][i] = d;
        }
    }
    vector<int> inds(n);
    iota(inds.begin(), inds.end(), 0);
    double ans = 0; 
    int count = 0; 
    do {
        for(int i = 0; i < n-1; ++i) {
            ans += dis[inds[i]][inds[i+1]];
        }
        ++count;
    } while(next_permutation(inds.begin(), inds.end()));
    ans /= count;
    cout << setprecision(16) << ans << endl;
    return 0;
}

Measured memory_bytes: 384
a = input()
if int(a) < int(2):
    print(a)
elif int(a) > int(1) and int(a) < int(4):
    print(2)

elif int(a) > int(3) and int(a) < int(8):
    print(4)

elif int(a) > int(7) and int(a) < int(16):
    print(8)

elif int(a) > int(15) and int(a) < int(32):
    print(16)

elif int(a) > int(31) and int(a) < int(64):
    print(32)

elif int(a) > int(63):
    print(64)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int main() {
	int n;
	double d;
	cin>>n>>d;
	int ans = 0;
	for(int i=0;i<n;i++) {
		double x,y,dist;
		cin>>x>>y;
		dist = sqrt(pow(x,2)+pow(y,2));
		debug()<<imie(dist);
		if(dist<=d) {
			ans++;
		}
	}
	cout<<ans;
}


Measured memory_bytes: 3808
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<utility>
#include<string.h>
#include<set>
#include<stdlib.h>
#include<string>
#include<utility>
#include<stack>
using namespace std;

vector<int> ve;
vector<int> vo;
int odd[100001];
int even[100001];
int a,b;
int x,y;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int x;
		scanf("%d",&x);
		if(i%2) {odd[x]++;}
		else {even[x]++;}
	}
	for(int i=0;i<=100000;i++){
		if(a<odd[i]) {a=odd[i];x=i;}
	}
	for(int i=0;i<=100000;i++){
		if(b<even[i]) {b=even[i];y=i;}
	}
	if(x==y){
		a=0; b=0;
		int x1=0;
		int y1=0;
		for(int i=0;i<=100000;i++){
			if(a<odd[i] && i!=x) {a=odd[i];x1=i;}
		}
		for(int i=0;i<=100000;i++){
			if(b<even[i] && i!=y) {b=even[i];y1=i;}
		}
		int k=max(odd[x]+even[y1],odd[x1]+even[y]);
		cout<<n-k;
	}else{
		cout<<n-odd[x]-even[y];
	}
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

typedef struct node *link;
struct node{
	int v;
	link next;
	link prev;
};

link head=NULL;
link tail=NULL;

void insert(int v){
	link x = malloc(sizeof(*x));
	x->v = v; x->next=NULL; x->prev=NULL; 
	if(head==NULL){
		head=x; tail=x;
	}else{
		head->prev=x;
		x->next=head;
		head=x;
	}
}

link search(int v){
	link t;
	for(t=head;t!=NULL;t=t->next){
		if(t->v==v)return t;
	}
	return NULL;
}

void deleteFirst(){
	head=head->next;
	if(head==NULL){
		//free(tail);
		tail=NULL;
	}else head->prev=NULL;
}

void deleteLast(){
	tail=tail->prev;
	if(tail==NULL){
		//free(head);
		head=NULL;
	}else tail->next=NULL;
	
}

void delete(int v){
	link next,prev;
	link t=search(v);
	if(t==NULL)return;
	if(t==head)deleteFirst();
	else if(t==tail)deleteLast();
	else{
		next=t->next;
		prev=t->prev;
		next->prev=prev;
		prev->next=next;
		//t->prev->next=t->next;
		//t->next->prev=t->prev;
		free(t);
	}
}

void Print(){
	link t;
	for(t=head;t!=NULL;t=t->next){
		if(t->next==NULL)
			printf("%d\n",t->v);
		else
			printf("%d ",t->v);
	}
}
void PrintR(){
	link t;
	for(t=tail;t!=NULL;t=t->prev){
		if(t->prev==NULL)
			printf("%d\n",t->v);
		else
			printf("%d ",t->v);
	}
}

void FreeList(){
	link next;
	if(head==NULL)return;
	while(head->next!=NULL){
		next=head->next;
		free(head);
		head=next;
	}
}

int main(void){
	int n,i;
	char c[20];
	int x;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s",c);
		
		if(!strcmp(c,"insert")){
			scanf("%d",&x);
			insert(x);
		}else if(!strcmp(c,"delete")){
			scanf("%d",&x);
			delete(x);
		}else if(!strcmp(c,"deleteFirst")){
			deleteFirst();
		}else if(!strcmp(c,"deleteLast")){
			deleteLast();
		}
		//printf("head:%d\ntail:%d\n",head->v,tail->v);
		//Print();
		//PrintR();
	}
	Print();
	FreeList();
	return 0;
}

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

int main() {
    ll N, M; cin >> N >> M;
    if (abs(N - M) > 1) {
        cout << 0 << endl;
        return 0;
    }

    if (N < M) swap(N, M);
    // N! * M!
    ll MOD = (ll)pow(10,9) + 7;
    ll res = 1;
    bool even = ((N+M) % 2 == 0);
    while (N > 0) {
        res *= N;
        res %= MOD;
        N--;
    } 
    while (M > 0) {
        res *= M;
        res %= MOD;
        M--;
    }
    if (even) {
        res *= 2;
        res %= MOD;
    }
    cout << res << endl;
}


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

bool cmp(int a,int b){
        return a>b;
}


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

    //Insert code
    
    int a=0,b=0,c=0,d=0;
    for (int i=1;i<=4;i++){
        int tmp;
        cin>>tmp;
        if (tmp==1) a++;
        else if (tmp==9) b++;
        else if (tmp==7) c++;
        else  d++;
    }

    //cout<<a<<b<<c<<d;

    if (a!=1 || b!=1 || c!=1 || d!=1){
        cout<<"NO";
    } else cout<<"YES";

    //End code


    cerr << "\nTime elapsed: " << 1000*clock() / CLOCKS_PER_SEC << "ms\n";
    
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  string s,t,ans;
  cin >> s >> t;
  for (int i = 0; i < n; i++) {
		 ans += s[i];
         ans += t[i]; 
	}
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Data.List

calc = calc' 0

calc' :: Integer -> Integer -> [(Integer, Integer)] -> Integer
calc' ret n [(a, b)] = ret + a * n
calc' ret n ((a, b):xs)
  | n < b = ret + a * n
  | otherwise = calc' (ret + a * b) (n - b) xs

main = do
  (n:m:_) <- map read . words <$> getLine
  pairs <- sort <$> (replicateM n $ do
    (a:b:_) <- map read . words <$> getLine
    return (a, b))
  print $ calc (fromIntegral m) pairs


Measured memory_bytes: 111868
#include <bits/stdc++.h>
#define FASTIO
#define endl "\n" // Since endl forces a buffer flush which slows down large I/O operations.
#define ff first
#define ss second
#define pb push_back
#define input(c, n)             \
	for (int i = 0; i < (n); i++) \
		cin >> (c)[i];
#define exit_message(s) return 0 * printf(s)
#define show(c)           \
	for (auto i : (c))      \
		cout << i << " "; \
	cout << "\n";
#define display(c, n)           \
	for (int i = 0; i < (n); i++) \
		cout << (c)[i] << " ";    \
	cout << "\n";
#define forl(i, a, n) for (int (i) = (a); (i) < (n); (i)++)
#define dugbe(k) cout << "-\t> " << #k << " = " << k << "\n";

/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/

using namespace std;
typedef long long ll;
typedef pair<int, int> pr;
typedef pair<ll, ll> prll;
typedef vector<int> vi;
typedef vector<ll> vill;
typedef vector<pr> vpr;
ifstream in("input.txt");
const ll mod = 1e9 + 7;

ll mod_pow(ll a, ll b)
{
	if (b == 0)
		return 1LL;

	ll res = mod_pow(a, b >> 1);
	res = (res * res) % mod;
	if (b & 1LL)
		res = (res * a) % mod;

	return res;
}

const int N = 21 + 5;
const int SZ = 2100000;

int n;
int a[N][N];
int dp[N][SZ];
bool vis[N];

int solve(int idx, int mask)
{
	if (idx > n)
		return 1;

	int &memo = dp[idx][mask];
	if (memo != -1)
		return memo;

	memo = 0;
	for (int i = 1; i <= n; i++)
	{
		int temp = 1 << (i - 1);
		// cerr << "temp : " << bitset<32>(temp) << " mask : " << mask << "\n";
		if (a[idx][i] == 1 && (mask & temp) == 0)
		{
			// cerr << "entry\n";
			mask ^= temp;
			memo += solve(idx + 1, mask);
			memo %= mod;
			mask ^= temp;
		}
	}
	// cerr << "idx : " << idx << " memo : " << memo << "\n";
	return memo;
}

int32_t main()
{
#ifdef FASTIO
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#endif
	// freopen("in.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	memset(dp, -1, sizeof dp);

	cin >> n;
	forl(i, 1, n + 1)
	{
		forl(j, 1, n + 1)
		{
			cin >> a[i][j];
		}
	}

	int mask = 0;
	int ans = solve(1, mask);
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 213632
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
    int n;
    cin >> n;
    vector<int>a(n);
    map<int,int>mp;
    bool flag = 1;
    set<int> st;
    rep(i,n){
        cin >> a[i];
        if(n%3!=0){
            if(a[i]!=0){
                flag = 0;
            }
        }
        st.insert(a[i]);
        mp[a[i]]++;
    }
   
    if(!flag){
        cout << "No" << endl;
        return 0;
    }
    if(mp.size()>=4){
        cout << "No" << endl;
        return 0;
    }
    
    vector<int> v;
    for(auto x:st){
        v.push_back(x);
    }
    if(v.size()==2){
        if(v[0]!=0){
            cout << "No" << endl;
        }else  if(mp[v[1]]!=2*mp[v[0]]){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
        return 0;
    }
    if(v.size()==1){
        if(v[0]!=0){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if((v[0]^v[1])!=v[2]){
            cout << "No" << endl;
            return 0;
        }
        if(mp[v[0]]==mp[v[1]]&&mp[v[1]]==mp[v[2]]){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 7808
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<bitset>
using namespace std;
const int inf = 1001001000;

void print(vector<vector<int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

class SizeUnionFind{
public:
	vector<int> _size;
	SizeUnionFind(){}
	SizeUnionFind(int n){
		this->_size = vector<int>(n,-1);
	}
	int root(int x){
		if (this->_size[x] < 0) return x;
		this->_size[x] = root(this->_size[x]);
		return this->_size[x];
	}
	int unite(int x, int y){
		int rx = this->root(x);
		int ry = this->root(y);
		if (rx == ry) return true;
		this->_size[ry] += this->_size[rx];
		this->_size[rx] = ry;
		return false;
	}
	int same(int x, int y){
		int rx = this->root(x);
		int ry = this->root(y);
		return rx == ry;
	}
	int size(int x){
		return -this->_size[this->root(x)];
	}
};

int main(){
	int n, m; cin >> n >> m;
	vector<pair<int,int>> e;
	for (int i = 0; i < m ;i++){
		int a, b; cin >> a >> b;
		e.push_back(pair<int,int>(a-1,b-1));
	}
	int ans = 0;
	for (int i = 0; i < m; i++){
		SizeUnionFind uf(n);
		for (int j = 0; j < m; j++){
			if (i==j) continue;
			uf.unite(e[j].first,e[j].second);
		}
		if (i == 0){
			if (uf.size(1) != n) ans++;
		} else {
			if (uf.size(0) != n) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
using namespace std;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
                
    #ifndef _LOCAL          
    #endif // _LOCAL

    char c;
    cin >> c;
    if (c >= 'A' && c <= 'Z') cout << "A\n";
        else cout << "a\n";

    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
typedef long long LL;
const int N = 100003;
const LL C = 2e17;
template<typename T>
inline void read(T &x){
    int ch = getchar(); x = 0; bool f = false;
    for(;ch < '0' || ch > '9';ch = getchar()) f |= ch == '-';
    for(;ch >= '0' && ch <= '9';ch = getchar()) x = x * 10 + ch - '0';
    if(f) x = -x;
}
template<typename T>
inline bool chmax(T &a, const T &b){if(a < b) return a = b, 1; return 0;}
template<typename T>
inline bool chmin(T &a, const T &b){if(a > b) return a = b, 1; return 0;}
int n;
LL x[N], y[N];
bool qry(LL a, LL b, LL c){return c >= a && (C - a - b & c - a) == c - a;}
bool qry(LL c){
    bool ans = false;
    for(Rint i = 0;i < n;++ i) ans ^= qry(x[i], y[i], c);
    return ans;
}
void calc(LL m, LL v, bool res[3]){
    bool dp[2][3][60] = {0}; dp[1][0][59] = true;
    for(Rint i = 58;~i;-- i){
        int w = 1 + (i & 1);
        for(Rint j = 0;j < 3;++ j){
            dp[0][j][i] ^= dp[0][j][i + 1];
            dp[!(v>>i&1)][j][i] ^= dp[1][j][i + 1];
            if(m>>i&1){
                dp[0][(j+w)%3][i] ^= dp[0][j][i + 1];
                if(v>>i&1) dp[1][(j+w)%3][i] ^= dp[1][j][i + 1];
            }
        }
    }
    for(Rint i = 0;i < 3;++ i) res[i] = dp[0][i][0] ^ dp[1][i][0];
}
void calc(LL m, LL l, LL r, bool res[3]){
    chmax(l, 0ll); chmin(r, m);
    if(l > r){res[0] = res[1] = res[2] = 0; return;}
    bool sr[3] = {0}, vr[3] = {0};
    if(l) calc(m, l-1, sr); calc(m, r, vr);
    for(Rint i = 0;i < 3;++ i) res[i] = vr[i] ^ sr[i];
}
LL solve(LL l, LL r){
    if(l == r) return l;
    LL mid = l + r >> 1; bool res[3] = {0}, tmp[3] = {0};
    for(Rint i = 0;i < n;++ i){
        calc(C - x[i] - y[i], l - x[i], mid - x[i], tmp);
        int tt = (x[i] % 3 + 3) % 3;
        for(Rint j = 0;j < 3;++ j) res[(j+tt)%3] ^= tmp[j];
    }
    if(res[0] || res[1] || res[2]) return solve(l, mid);
    return solve(mid + 1, r);
}
int main(){
    read(n);
    for(Rint i = 0;i < n;++ i){read(x[i]); read(y[i]);}
    LL lst = solve(-1e17, 3e17), rst = lst;
    for(Rint i = 58;~i;-- i) if(qry(lst-(1ll<<i))) lst -= 1ll<<i;
    for(Rint i = 58;~i;-- i) if(qry(rst+(1ll<<i))) rst += 1ll<<i;
    printf("%lld %lld\n", lst, C - rst);
} // ntfnmsl

Measured memory_bytes: 3920
def main():
    N, X = map(int, input().split())
    m = [0 for _ in range(N)]
    for i in range(N):
        m[i] = int(input())

    sum_m = sum(m)
    min_m = min(m)
    return N + (X-sum_m)//min_m

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



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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
//Write From this Line

const int mod = 1e9+7;
int dp[100100][2];
int main()
{
	string s;
	cin >> s;
	dp[0][0] = 1;
	rep(i,s.size()){
		// a + b == 0 (a も b も0)
		if(s[i] == '0'){
			dp[i+1][0] = dp[i][0];
			dp[i+1][1] = dp[i][1];
		} else {
			dp[i+1][1] = (dp[i][0] + dp[i][1]) % mod;
		}
		 // a + b == 1 にする
		 if(s[i] == '0'){
			 (dp[i+1][1] += (2 * dp[i][1]) % mod) %= mod; //  a, b のどっちが1か
		 } else {
			 (dp[i+1][0] += dp[i][0] * 2 % mod) %= mod;
			 (dp[i+1][1] += dp[i][1] * 2 % mod)%= mod;
		 }
	}
	int ans = (dp[s.size()][0] + dp[s.size()][1]) % mod;
	cout << ans << endl;
}


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

ab, start_b, end_a, b_a = 0, 0, 0, 0

if n == 1:
  print(input().count('AB'))
else:
  for _ in range(n):
    chars = input()
    if 'AB' in chars:
      ab += chars.count('AB')
    if chars[0] == 'B':
      if chars[-1] == 'A':
        b_a += 1
      else:
        start_b += 1
    elif chars[-1] == 'A':
      end_a += 1
  if start_b + end_a == 0 and b_a:
    print(ab + b_a - 1)
  else:
    print(ab + b_a + min(start_b, end_a))


Measured memory_bytes: 3064
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>

int main(){
  int N, M;
  scanf("%d",&N);
  scanf("%d",&M);
  std::vector<std::pair<long long, int> > drink(N);
  for (int i=0; i<N; i++){
    scanf("%lld",&drink[i].first);
    scanf("%d",&drink[i].second);
  }
  std::sort(drink.begin(), drink.end());
  long long ans = 0;
  int current = 0;
  int counter = 0;
  while(current<M){
    //printf("drink[%d].first=%lld, drink[%d].second=%d\n",counter,drink[counter].first,counter,drink[counter].second);
    ans += drink[counter].first * std::min(drink[counter].second, M-current);
    current += std::min(drink[counter].second, M-current);
    counter++;
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define int     long long
#define F       first
#define S       second
#define _READ   freopen("input.txt","r", stdin);
#define _FAST   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
void solve()
{
    int n,m,x;
    cin>>n>>m>>x;
    vector<int> c(n);
    vector<vector<int>> ar(n,vector<int>(m));
    for(int i=0;i<n;i++)
    {
        cin>>c[i];
        for(int j=0;j<m;j++)
            cin>>ar[i][j];
    }
    int ans=1e15;
    for(int i=0;i<(1ll<<n);i++)
    {
        vector<int> temp(m,0);
        int cur_cost=0ll;
        for(int j=0;j<n;j++)
        {
            if((i&(1ll<<j))!=0)
            {
                cur_cost+=c[j];
                for(int k=0;k<m;k++)
                    temp[k]+=ar[j][k];
            }
        }
        for(int j=0;j<m;j++)
            if(temp[j]<x)
                cur_cost=1e15+1;
        ans=min(ans,(int)cur_cost);
    }
    if(ans==(int)1e15)
        cout<<"-1";
    else
        cout<<ans;
}
int32_t main()
{
    clock_t tStart = clock();
    #ifndef ONLINE_JUDGE
    _READ
    #endif
    
    solve();
    
    #ifndef ONLINE_JUDGE
    cout<<fixed<<setprecision(5)<<"\nTime taken: "<<(double)(clock() - tStart)/CLOCKS_PER_SEC;
    #endif
    
    return 0;
}
/*
===FOR N-Dimensional Vector===
https://codeforces.com/blog/entry/76149
g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined a.cpp -o a -D_GLIBCXX_DEBUG
*/

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <memory.h>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <queue>
#include <stack>
#include <cstdio>
#include <bitset>

using namespace std;

#define nfs ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f first
#define s second
#define m_p make_pair
#define pb push_back
#define ii pair<int,int>
#define iii pair<int,pair<int,int> >
#define ll long long
#define ull unsigned long long
#define ld long double
#define ef else if
#define loc(x) (x).begin(),(x).end() 
#define locR(x) (x).rbegin(),(x).rend()
#define no puts("NO")
#define yes puts("YES")
#define ex puts("-1")
#define en puts("")
#define _ cout  
#define __ <<
#define outV(v) for(int i = 0 ; i < v.size() ; i++)cout << v[i] << ' ';
#define outA(x,l,r) for(int i = l ; i < r ; i++)cout << x[i] << ' ';

const ld EPS = 1e-18;
const double DEPS = 1e-9;
const ld PI = 3.141592653589793238;
const ull MOD = 1e9 + 7;
const int N = (int)(5e5) + 1;


ll gcd(ll fx, ll fy)
{
	if (!fy) return fx;
	return gcd(fy, fx % fy);
}

inline void fill(int* ar, int sz, int val)
{
	for (int i = 0; i < sz; i++)
	{
		ar[i] = val;
	}
}

int a[N], k, n;
ll dp[N];

int main()
{
	cin >> n >> k;
	memset(dp, -1, sizeof(dp));
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", a + i);
	}

	dp[n] = 0;
	for (int i = n - 1; i >= 1; i--)
	{
		dp[i] = 1e9;
		for (int j = 1; j <= k; j++)
		{
			if (i + j == n)
			{
				dp[i] = min(dp[i], 1ll * abs(a[i] - a[n]));
			}
			else if(i + j < n)
			{
				dp[i] = min(dp[i], dp[i + j] + 1ll * abs(a[i] - a[i + j]));
			}
		}
	}

	cout << dp[1] << endl;
}

Measured memory_bytes: 4480
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

int n;
int pre[41], in[41];
vector<int> post;
int pos = 0;

// 木a[left..right]を左と右の部分木に分ける
void recon(int left, int right) {
    // 終了条件
    if (left >= right) return;

    int root, root_pos;
    root = pre[pos++];
    for (int i = left; i < right; i++) {
        if (in[i] == root) {
            root_pos = i;
        }
    }
    recon(left, root_pos);      // 左部分木
    recon(root_pos + 1, right); // 右部分木
    post.emplace_back(root);
}

int main() {
    cin >> n;
    rep(i, n) cin >> pre[i];
    rep(i, n) cin >> in[i];

    recon(0, n);
    for (int i = 0; i < post.size(); i++) {
        if (i != post.size() - 1) {
            cout << post[i] << ' ';
        } else {
            cout << post[i] << endl;
        }
    }
}



Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
const int mx = 100005;
int n, a, b;
int p[mx], yp[mx];
long long ans, nmy[mx];
void ufini(int n){ fill(p, p+n, -1);}
int find(int x){return (p[x] < 0 ? x : p[x] = find(p[x]));}
void uni(int x, int y){
    x = find(x); y = find(y);
    if(x != y){
        if(x < y) swap(x, y);
        nmy[x] += nmy[y];
        p[x] += p[y];
        p[y] = x;
    }
}
int main(){
    scanf("%d", &n);
    fill(p, p+mx, -1);
    fill(yp, yp+mx, -1);
    rep(i,n){
        scanf("%d%d", &a, &b);
        if(yp[b] == -1){
            yp[b] = find(a);
            nmy[yp[b]]++;
        }else uni(a, yp[b]);
    }
    rep(i,mx) if(find(i) == i) ans -= nmy[i] * p[i];
    printf("%lld\n", ans - n);
}

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

int main()
{
	int n, m;
	cin >> n >> m;
	vector<vector<int>> ss(m);
	vector<int> ps(m);
	for (auto &s : ss)
	{
		int k;
		cin >> k;
		for (int i = 0; i < k; i++)
		{
			int x;
			cin >> x;
			s.emplace_back(x - 1);
		}
	}
	for (auto &p : ps)
	{
		cin >> p;
	}

	int ans = 0;
	for (int i = 0; i < (1 << n); i++)
	{
		bool f = true;
		for (int j = 0; j < m; j++)
		{
			int cnt = 0;
			for (int x : ss[j])
			{
				if ((i >> x) & 1)
				{
					cnt++;
				}
			}
			f &= (cnt % 2) == ps[j];
		}
		if (f)
		{
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
h,w=list(map(int,input().split()))

a=[]
for i in range(h):
    a.append(input())

dp=[[0 for i in range(w)] for j in range(h)]
dp[0][0]=1

for i in range(h):
    for j in range(w):
        if i>0 and a[i-1][j]!="#":
            dp[i][j]+=dp[i-1][j]
        if j>0 and a[i][j-1]!="#":
            dp[i][j]+=dp[i][j-1]

print(dp[h-1][w-1]%(10**9+7))


Measured memory_bytes: 158452
while True :
    H, W = map(int, input().split())
    if H == 0 and W == 0 :
        break
    else :
        for i in range(H):
            if i == 0 or i == H - 1 :
                if i == 0 :
                    print("#" * W)
                else :
                    print("#" * W + "\n")
            else :
                print("#" + "." * (W - 2) + "#")



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

using namespace std;

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

    int k,n;
    cin>>n;

    k=n%10;

    if(k==2 || k==4 || k==5 || k==7 || k==9)
        cout<<"hon\n";
    else if(k==0 || k==1 || k==6 || k==8)
        cout<<"pon\n";
    else
        cout<<"bon\n";
    return 0;
}


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

using namespace std;

typedef long long ll;

ll mod;

ll powimod(ll x,ll n,ll mod){
    ll res=1;
    while(n){
        if(n&1) res=(res*x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return res;
}

ll powi(ll x,ll n){
    ll res=1;
    while(n){
        if(n&1) res*=x;
        x*=x;
        n>>=1;
    }
    return res;
}

vector<int> z_function(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    return z;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    ll l[n];
    for(ll i=0;i<n;i++)
    {
    cin>>l[i];
    }
    sort(l,l+n);
    ll ans=0;
    for(ll i=0;i<n-2;i++)
    {
    for(ll j=i+1;j<n-1;j++)
    {
    for(ll k=j+1;k<n;k++)
    {
    if(l[i]==l[j]||l[j]==l[k]) continue;
    if(l[i]+l[j]>l[k]) ans++;
    }
    }
    }
    cout<<ans;
}


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

from collections import deque

N = int(input())
A = [int(x) for x in input().split()]

"""
・x < M > y → x+y-Mに取り替える
・V字型に帰着
・貪欲

"""

B = deque() # 修正後
for a in A:
    B.append(a)
    while True:
        if len(B) < 3:
            break
        x,y,z = B[-3], B[-2], B[-1]
        if x <= y >= z:
            B.pop()
            B.pop()
            B[-1] = x + z - y
            continue
        break

pts = [0,0]
player = 0
while B:
    if B[0] > B[-1]:
        pts[player] += B[0]
        B.popleft()
    else:
        pts[player] += B[-1]
        B.pop()
    player ^= 1

answer = pts[0] - pts[1]
print(answer)

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

#define SZ(a) ((int)a.size())
#define ALL(a) a.begin(), a.end()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define fst first
#define snd second

void dout() { cerr << endl; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s, t;
    cin >> s >> t;
    vector<vector<pair<int, int>>> dp(SZ(s) + 1, vector<pair<int, int>>(SZ(t) + 1));
    for (int i = 1; i <= SZ(s); i++)
    {
        for (int j = 1; j <= SZ(t); j++)
        {
            dp[i][j] = max({MP(dp[i - 1][j].fst, 0), 
                            MP(dp[i][j - 1].fst, 1),
                            MP(dp[i - 1][j - 1].fst + (s[i - 1] == t[j - 1]), -1)});
        }
    }
    int x = SZ(s);
    int y = SZ(t);
    string ans;
    while (x > 0 && y > 0)
    {
        int from = dp[x][y].snd;
        if (from == 0)
            x--;
        if (from == 1)
            y--;
        if (from == -1)
        {
            ans += s[x - 1];
            x--;
            y--;
        }
    }
    reverse(ALL(ans));
    cout << ans;
    return 0;
}

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

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int N = in.i();
        int[] b = in.ii(N);
        int[] ans = new int[N];
        for (int i = N - 1, j; i >= 0; i--) {
            for (j = i; j >= 0; j--) {
                if (j + 1 == b[j]) {
                    ans[i] = b[j];
                    for (int k = j + 1; k <= i; k++) {
                        b[k - 1] = b[k];
                    }
                    break;
                }
            }
            if (j == -1) {
                System.out.println(-1);
                return;
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < N; i++) {
            sb.append(ans[i]).append('\n');
        }
        System.out.print(sb);
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    int i() {
        int k = next() - '0';
        boolean minus = k == -3;
        int n = minus ? 0 : k;
        while (0 <= (k = next() - '0') && k <= 9) n = 10 * n + k;
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        int k = next() - '0';
        boolean minus = k == -3;
        long n = minus ? 0 : k;
        while (0 <= (k = next() - '0') && k <= 9) n = 10 * n + k;
        return minus ? -n : n;
    }

    char[] s(final int N) {
        char[] s = new char[N];
        for (int i = 0; i < N; i++) {
            s[i] = next();
        }
        next();
        return s;
    }

    public int read(char[] cbuf) {
        int i;
        char c;
        for (i = 0; (c = next()) != ' ' && c != '\n'; i++) cbuf[i] = c;
        return i;
    }

    public String readLine() {
        try {
            return super.readLine();
        } catch (IOException e) {
            return null;
        }
    }
}


Measured memory_bytes: 32412
num = map(int,raw_input().split())
for x in xrange(0,2):
    for i in xrange(0,2):
        if num[i] > num[i+1] :
            tmp = num[i]
            num[i] = num[i+1]
            num[i+1] = tmp
strnum = map(str,num)
print strnum[0]+" "+strnum[1]+" "+strnum[2]

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

int main(void){
    int cost[10][10];
    int h, w;
    cin >> h >> w;
    for(int i=0; i<10; i++){
        for(int j=0; j<10; j++){
            cin >> cost[i][j];
        }
    }
    
    for(int k=0; k<10; k++){
        for(int i=0; i<10; i++){
            for(int j=0; j<10; j++){
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
            }
        }
    }

    int ans = 0;
    for(int i=0; i<h*w; i++){
        int n;
        cin >> n;
        if(n != -1){
            ans += cost[n][1];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#define rep(k,i,n) for(int i=k;i<n;++i)
using namespace std;
int main(void){
    // Your code here!
    string S,T;
    int ans=0;
    cin>>S>>T;
    rep(0,i,S.length()){
        if(S.substr(i,1)==T.substr(i,1)){
            ++ans;
        }
    }
    cout<<ans<<endl;
}


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

int main(){
  vector <string> S(3);
  for(int i=0;i<3;i++){
    cin >> S.at(i);
  }
  vector < queue <char> > vq(3);
  for(int i=0;i<3;i++){
    for(char c: S.at(i)){
      vq.at(i).push(c);
    }
  }
  int x=0;
  bool flag=true;
  while(flag){
    for(int i=0;i<3;i++){
      if(x==i){
        if(vq.at(i).empty()){
          flag=false;
          break;
        }else{
          if(vq.at(i).front()=='a'){
            x=0;
          }else if(vq.at(i).front()=='b'){
            x=1;
          }else{
            x=2;
          }
          vq.at(i).pop();
        }
      }
    }
  }
  if(x==0){
    cout << 'A' << endl;
  }else if(x==1){
    cout << 'B' << endl;
  }else{
    cout << 'C' << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.time.Year;
import java.util.*;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

    // input
    static int n;
    static int m;
    static int x[];
    static int y[];
    static int z[];

    /**
     * input
     */
    static void input(){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        x = new int[m];
        y = new int[m];
        z = new int[m];

        for(int i=0;i<m;i++){
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
            z[i] = sc.nextInt();
        }
        sc.close();
    }
 

    // global
    static int[] ans;

    private static class UnionFindTree {

        private static int[] par;
        private static int[] rank;
        private static int size;

        UnionFindTree(int n){
            this.par = new int[n];
            this.rank = new int[n];

            for(int i=0;i<n;i++){
                this.par[i] = i;
            }
            this.size = n;
        }

        int find(int x) {
            if (this.par[x] == x) {
                return x;
            } else {
                return par[x] = this.find(par[x]);
            }
        }

        void unite(int x, int y) {
            x = this.find(x);
            y = this.find(y);
            if (x == y) return;

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

        boolean same(int x, int y) {
            return false;
        }

        int size(){
            return this.size;
        }
    }


    /**
     * solver
     */
    static void solve(){

        UnionFindTree uft = new UnionFindTree(2*(n+1));

        for(int i=0;i<m;i++){
            if (z[i] % 2 == 1) {
                uft.unite(x[i], y[i]+n);
                uft.unite(x[i]+n, y[i]);
            } else {
                uft.unite(x[i], y[i]);
                uft.unite(x[i]+n,y[i]+n);
            }
        }

        System.out.println((uft.size()-2)/2);
    }


    public static void main(String args[]) {

        input();

        solve();
    }
}


Measured memory_bytes: 95116
#include<stdio.h>

int main(void)
{
  int h,w;
  for(;;)
  {
    scanf("%d %d", &h, &w);
    if(h==0 && w==0){
      break;
    }
    int i,j;
    for (i=0; i<h; ++i) {
      for (j = 0; j < w;  ++j) {
        putchar('#');
      }
      puts("");
    }
    puts("");
  }
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;

int main(){

  ll n;cin>>n;
  ll a[n];
  map<ll,ll>mp;
  rep(i,1,n){
    cin>>a[i];
    mp[a[i]]++;
  }
  rep(i,1,n+1){
    out(mp[i]);
  }


  return 0;
}


Measured memory_bytes: 17696
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

#define abs(N) ((N>0)?N:-1*N)
#define min(A,B) ((A>B)?B:A)
#define max(A,B) ((A<B)?B:A)
#define print(S) (cout << S)
#define println(S) (cout << S << endl)

int main(){
	int n;
	cin >> n;
  int i = 1;
 CHECK_NUM:
  int x = i;
  if ( x % 3 == 0 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
 INCLUDE3:
  if ( x % 10 == 3 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
  x /= 10;
  if ( x ) goto INCLUDE3;
 END_CHECK_NUM:
  if ( ++i <= n ) goto CHECK_NUM;

  cout << endl;
}



Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    int X[n], Y[m];
    if (x > y)
    {
        puts("War");
        return 0;
    }
    repi(i, n, 0)
    {
        cin >> X[i];
        if (X[i] >= y)
        {
            puts("War");
            return 0;
        }
    }
    repi(i, m, 0)
    {
        cin >> Y[i];
        if (Y[i] <= x)
        {
            puts("War");
            return 0;
        }
    }
    repi(i, n, 0)
    {
        repi(j, m, 0)
        {
            if (X[i] >= Y[j])
            {
                puts("War");
                return 0;
            }
        }
    }
    puts("No War");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define SZ(x) ((int)(x.size()))
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))


const double pi = 4*atan(1);
using namespace std;
typedef long long ll;

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

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

	int n,m;
	cin >> n >> m;

	vector<bool> reaches(n);
	vector<vector<int>> adj(n,vector<int>());

	while(m--){
		int a, b;
		cin >> a >> b;
		a--;b--;

		if (b == n-1) {
			reaches[a]=true;
		}
		if (a == 0) {
			adj[a].pb(b);
		}
	}

	for (auto v : adj[0]) {
		if (reaches[v]) {
			cout << "POSSIBLE\n";
			return 0;
		}
	}


	cout << "IMPOSSIBLE" << "\n";

}


Measured memory_bytes: 8540
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
typedef complex<double> P;

char c;
double x,y,xx,yy,xxx,yyy,xxxx,yyyy;

double cr(P a, P b) {
  return (a.real() * b.imag() - a.imag() * b.real());
}

int main(){
	while(cin>>x>>c>>y>>c>>xx>>c>>yy>>c>>xxx>>c>>yyy>>c>>xxxx>>c>>yyyy){
		P a=P(x,y),b=P(xx,yy),c=P(xxx,yyy),d=P(xxxx,yyyy);
		int C=cr(d-a,b-a)>0&&cr(a-b,c-b)>0&&cr(b-c,d-c)>0&&cr(c-d,a-d)>0||cr(d-a,b-a)<0&&cr(a-b,c-b)<0&&cr(b-c,d-c)<0&&cr(c-d,a-d)<0;
		cout<<(C?"YES":"NO")<<endl;
	}
}

Measured memory_bytes: 0