akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
#include<vector>
using namespace std;
vector<int> st[2];
main(){

  int n;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    int b[10];
    for(int j=0;j<10;j++){
      scanf("%d",&b[j]);
    }
    bool f=false;
    st[0].push_back(b[0]);
    for(int j=1;j<10;j++){
      if(st[0].back() < b[j] )
	st[0].push_back(b[j]);
      else if( st[1].empty() )
	st[1].push_back(b[j]);
      else if( st[1].back() < b[j] )
	st[1].push_back(b[j]);
      else {
	f=true;
	break;
      }
      //  printf("%d : %d  <- %d\n",st[0].back(),st[1].back(),b[j]);
    }    
    
    st[0].clear();
    st[1].clear();
    
    if(!f) printf("YES\n");
    else printf("NO\n");
  }
}

Measured memory_bytes: 0
#include <stdio.h>
#include <math.h>

int main()
{
	int n;
	double big=0,small=0,gou=0;
	double a[10000]={0};

	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%lf",&a[i]);
		if(i==0){
			big=a[i];
			small=a[i];
		}
		else if(big<a[i]) big=a[i];
		else if(small>a[i]) small=a[i];
		
		gou+=a[i];
	}
	printf("%.0lf %.0lf %.0lf\n",small,big,gou);

	return 0;
}

Measured memory_bytes: 2784
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n = readi()
t = readl()
k = list(t)
k.sort()

flg = False
for i in range(n):
    if t[i] != k[i]:
        if flg == False:
            flg = True
            for j in range(i, n):
                if t[j] == k[i]:
                    w = t[j]
                    t[j] = t[i]
                    t[i] = t[j]
        else:
            print("NO")
            exit()
print("YES")


Measured memory_bytes: 7240
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    fastio
    ll n,m,k;
    cin>>n>>m>>k;
    ll a[n],b[m];
    for(ll i=0;i<n;++i) cin>>a[i];
    for(ll j=0;j<m;++j) cin>>b[j];
    ll asum[n+1],bsum[m+1];
    asum[0]=0,bsum[0]=0;
    for(ll i=0;i<n;++i) asum[i+1]=asum[i]+a[i];
    for(ll i=0;i<m;++i) bsum[i+1]=bsum[i]+b[i];
    ll cnt=0;
    ll j=m;
    for(ll i=0;i<n+1;++i){
        //if(asum[i]==0 || bsum[j]==0) break;
        if(asum[i]>k) break;
        while(bsum[j]>k-asum[i]) --j;
            //while(asum[i]+bsum[j]>k){
                //cout<<asum[i]<<" "<<bsum[j]<<'\n';
            //cout<<asum[i]<<" "<<bsum[j]<<'\n';
        cnt=max(cnt,i+j);
            //cout<<i<<" "<<j<<'\n';
    }
    cout<<cnt;
    return 0;
}

Measured memory_bytes: 9896
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def calc(x):
    ret = (1, x)
    for i in range(1, 10**6+1):
        if i*i > x:
            break
        if x % i == 0:
            if i + x //i < ret[0]+ret[1]:
                ret = (i, x//i)
    return ret

def main():
    n = ri()
    ret = calc(n)
    print(ret[0]+ret[1]-2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		char[] s = sc.next().toCharArray();

		int R_count = 0;
		int B_count = 0;

		for( char word : s) {
			if(word == 'R') {
				R_count++;
			}else if(word == 'B') {
				B_count++;
			}
		}

		if(R_count > B_count) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 22228
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {

    void solve() throws IOException {
        int n = ni(), m = ni();
        String[] a = nsa(n);
        String[] b = nsa(m);

        for (int i = 0; i <= n - m; i++) {
            for (int j = 0; j <= n - m; j++) {
                boolean flg = true;
                for (int k = 0; k < m; k++) {
                    for (int l = 0; l < m; l++) {
                        if (a[i + k].charAt(j + l) != b[k].charAt(l)) {
                            flg = false;
                        }
                    }
                }
                if (flg) {
                    out.println("Yes");
                    return;
                }
            }
        }

        out.println("No");
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 23636
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class Main{
    public static Scanner scan  = new Scanner(System.in);
    public static void main(String[]args){
        int n;
        String s,t;

        n=nextInt();
        s=next();
        t=next();
        char[] arr = new char[2*n];
        for(int i=0;i<n;i++){
            arr[2*i]=s.charAt(i);
            arr[2*i+1]=t.charAt(i);
        }
        for(char a:arr){
            System.out.printf("%c",a);
        }
    }



    public static int nextInt(){
        return Integer.parseInt(scan.next());
    }
    public static long nextLong(){
        return Long.parseLong(scan.next());
    }
    public static String next(){
        return scan.next();
    }
    public static double nextDouble(){
        return Double.parseDouble(scan.next());
    }
    public static float nextFloat(){
        return Float.parseFloat(scan.next());
    }

    //Yes or No
    public static void yesNo(boolean flag){
        if(flag) System.out.println("Yes");
        else System.out.println("No");
    }
    public static void print(Object a){
        System.out.println(a);
    }
}

Measured memory_bytes: 23124
#include<stdio.h>
int main(void)
{
   int h,w,n,ain[10000]={0},i1,i2,aout[100][100]={0},x=0,y=0;
   scanf("%d",&h);
   scanf("%d",&w);
   scanf("%d",&n);
   for(i1=0;i1<n;i1++){
      scanf("%d",&ain[i1]);
      for(i2=0;i2<ain[i1];i2++){
        if(x>=w) {y++;x--;}
        else if(x<0) {y++;x++;}
        {if(y%2) aout[y][x--]=i1+1;
         else aout[y][x++]=i1+1;
        }
      }
    }
    for(i1=0,i2=0;i1<h;i1++){
        for(i2=0;i2<w;i2++)
            printf("%d ",aout[i1][i2]);
        printf("\n");}
    return 0;
}

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

const ll mod = 1000000007;
const double eps = 1e-8;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int main() {
    int N;
    cin >> N;
    vector<ll> L(N), R(N);
    for (int i = 0; i < N; ++i) cin >> L[i] >> R[i];
    sort(L.rbegin(), L.rend());
    sort(R.begin(), R.end());

    ll mx = max(0LL, -2 * R[0]);
    ll k = 0;
    for (int i = 0; i < N; ++i) {
        k += 2 * L[i];
        mx = max({mx, k, k - 2 * R[i]});
        if (i+1 < N) mx = max(mx, k - 2 * (R[i] + R[i+1]));
        k -= 2 * R[i];
    }
    cout << mx << endl;

    return 0;
}

Measured memory_bytes: 1792
from math import ceil

# 入力
N = int(input())
A = [int(input()) for i in range(N)]

MOD = 998244353


S = sum(A)
# 赤色の整数の和がiとなるような塗り方の個数
dp = [0 for _ in range(S + 1)]
dp[0] = 1
# 赤色の整数の和がi, 他の整数がすべて青色となるような塗り方の個数
dp2 = [0 for _ in range(S // 2 + 1)]
dp2[0] = 1

# 動的計画法により、dp, dp2を求める
for a in A:
    for i in range(S, a - 1, -1):
        dp[i] = (2 * dp[i] + dp[i - a]) % MOD
    for i in range(a - 1, -1, -1):
        dp[i] = (2 * dp[i]) % MOD
    for i in range(S // 2, a - 1, -1):
        dp2[i] = (dp2[i] + dp2[i - a]) % MOD

# 全ての塗り方の個数から、条件を満たさない塗り方の個数を差し引いて解を求める
ans = (3**N - 3 * sum(dp[ceil(S / 2):]) + (
    3 * dp2[S // 2] if S % 2 == 0 else
    0
)) % MOD

# 出力
print(ans)


Measured memory_bytes: 43888
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  scanf("%d", &N);
  int a[N];
  for (int i = 0; i < N; ++i) {
    scanf("%d", &a[i]);
  }
  int b[N];
  for (int i = 0; i < N; ++i) {
    b[i] = a[i];
    if(b[i]<0) b[i] *= -1; 
  }
 
  int mincount = 0;
  for (int i = 0; i < N; ++i) {
    if(a[i]<0) ++mincount;
  }
 
  long long  sum = 0;
 
  if(mincount%2==0) {
    for (int i = 0; i < N; ++i) {
      sum += b[i];
    }
  }
  else{
 
    int min = 1000000000;
    for (int i = 0; i < N; ++i) {
      if(b[i]<min) min = b[i];
    }
 
    for (int i = 0; i < N; ++i) {
      sum += b[i];
    }
 
    sum -= 2*min;
  }
 
  cout << sum << endl;

}

Measured memory_bytes: 1024
#include <iostream>
#include <deque>
#include <algorithm>
using namespace std;


int main(){
	int i;
	int l[3];
	cin >> i;

	while(i>0){
		for(int j=0; j<3; j++){
			cin >> l[j];
		}

		sort(l,l+3);

		if(l[0]*l[0] + l[1]*l[1] == l[2]*l[2]){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}

		i--;
	}

	return 0;
}

Measured memory_bytes: 1168
<?php

$input = trim(fgets(STDIN));
$input = explode(" ", $input);
$s = $input[0];
$input = trim(fgets(STDIN));
$input = explode(" ", $input);
$t = $input[0];

$alphabet = 'abcdefghijklmnopqrstuvwxyz';
$length = strlen($alphabet);
$searched = [];

for ($i=0; $i < $length; $i++) { 
	$a_tmp = $alphabet[$i];
	$s_offset = 0;
	$t_offset = 0;
	$s_prev = '';
	$t_prev = '';
	$first = true;
	while (true) {
		$pos = strpos($s, $a_tmp, $s_offset);
		if ($pos === false) {
			break;
		}
		if ($t_prev == '') {
			$t_prev = $t[$pos];
		}
		$t_tmp = $t[$pos];
		if ($t_prev !== $t_tmp) {
			echo 'No';
			exit(0);
		}

		$s_offset = $pos + 1;
	}
	while (true) {
		$pos = strpos($t, $a_tmp, $t_offset);
		if ($pos === false) {
			break;
		}
		if ($s_prev == '') {
			$s_prev = $s[$pos];
		}
		$s_tmp = $s[$pos];
		if ($s_prev !== $s_tmp) {
			echo 'No';
			exit(0);
		}

		$t_offset = $pos + 1;
	}
}

echo 'Yes';


Measured memory_bytes: 4728
//周♂雨扬是最强的！！！
//大佬祝您AK
//沈哲♂贝是最强的！！！
/*#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<fstream>
using namespace std;
int n,m;
int a[403][403];
int point[403],vis[403],tong[403];
inline bool pd(int x){
	while(1){
		for(int i=1;i<=n;i++){
			int j=point[i];
			while(j<=m){
				if(vis[a[i][j]]){
					j++;
				}else{
					point[i]=j;
					tong[a[i][j]]++;
					break;
				}
			}
			if(j==m+1){
				return 0;
			}
		}
		bool yes=false;
		for(int i=1;i<=m;i++){
			if(tong[i]>x){
				yes=true;
				vis[i]=1;
			}
			tong[i]=0;
		}
		if(yes==false){
			return 1;
		}
	}
	return 1;
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}
	for(int i=1;i<=m;i++){
		vis[i]=0;
	}
	int ans=m;
	for(int k=1;k<=m;k++){
		for(int i=1;i<=m;i++){
			tong[i]=0;
		}
		for(int i=1;i<=n;i++){
			int j=point[i];
			while(j<=m){
				if(vis[a[i][j]]){
					j++;
				}else{
					point[i]=j;
					tong[a[i][j]]++;
					break;
				}
			}
			if(j>=m+1){
				break;
			}
		}
		int nowans=0,now;
		bool yes=false;
		for(int i=1;i<=m;i++){
			if(tong[i]>nowans&&!vis[i]){
				now=i;
				nowans=tong[i];
			}
		}
		cout<<nowans<<endl;
		vis[now]=1;
		ans=min(ans,nowans);
	}
	cout<<ans<<endl;
	int l=1,r=m;
	while(l<r){
		int mid=(l+r)/2;
		for(int i=1;i<=n;i++){
			point[i]=1;
		}
		for(int i=1;i<=m;i++){
			vis[i]=0;
		}
		if(pd(mid)){
			r=mid;
		}else{
			l=mid+1;
		}
	}
	bool yes=false;
	if(pd(r)){
		yes=true;
		cout<<r<<endl;
	}else{
		yes=true;
		cout<<l<<endl;
	}
	if(yes==false){
		cout<<m<<endl;
	}
	return 0;
}

in:
4 5
5 1 3 4 2
2 5 3 1 4
2 3 1 4 5
2 5 4 3 1
out:
2

in:
3 3
2 1 3
2 1 3
2 1 3
out:
3

*/
//沈♂哲贝是最强的！！！
//大佬祝您AK
//周♂雨扬是最强的！！！
#include<string.h>
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
int a[303][303],point[303],tong[303];
int n,m,ans;
bool vis[303],yes;
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}
	for(int i=1;i<=n;i++){
		point[i]=1;
		tong[a[i][1]]++;
	}
	yes=1,ans=1e9;
	while(yes){
		int k=0;
		for(int i=1;i<=m;i++){
			if(tong[i]>tong[k]){
				k=i;
			}
		}
		ans=min(ans,tong[k]);
		vis[k]=1;
		for(int i=1;i<=n;i++){
			while(vis[a[i][point[i]]]){
				tong[a[i][point[i]]]--;
				point[i]++;
				tong[a[i][point[i]]]++;
			}
			if(point[i]!=m+1){
				yes&=true;
			}else{
				yes&=false;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}
/*

in:
4 5
5 1 3 4 2
2 5 3 1 4
2 3 1 4 5
2 5 4 3 1
out:
2

in:
3 3
2 1 3
2 1 3
2 1 3
out:
3

*/

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

using namespace std;

#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define allarr(a) a , a + n
#define ll long long
#define ull unsigned long long 
#define pb push_back
#define fastio ios_base::sync_with_stdio(false) ; cin.tie(NULL); cout.tie(NULL)
typedef pair<int, int> pi;
typedef pair<ll,ll> pll; 
typedef pair<int,pi> trp ;
typedef vector<pi> vpi;
typedef vector<pll> vpll ;
ll _abs (ll x ) { return (x>0?x:-x); }

ll ans ; 
int n  , m , k , x , p[11] ;
vector<int> s[12] ; 

void solve ( int i , vector<bool> v ){
	if( i == n ){
		int c= 0 ; 
		bool ok = 1 ;
		//for(bool b : v ) cout<<b<<" "; 
		//cout<<endl;
		for(int i=0 ; i < m ; i++ ){
			c=0 ; 
			for(int j : s[i] ){
				if ( v[j] ) c ++ ;  
			}
			if( c % 2 != p[i] ) ok=0 ;  
		} if(ok)ans ++ ; 
	return ; 
	}
	v.pb(0) ; 
	solve(i+1,v); 
	v.pop_back() ; 
	v.pb(1); 
	solve(i+1,v); 
}

int main(){
cin>>n>>m; 
for(int i = 0 ; i < m ; i++ ){
	cin>>k ; 
	for(int j = 0 ; j < k ; j++ ){
		cin>>x ; 
		x--; 
		s[i].pb(x); 
	}
} 
for(int i = 0 ; i < m ; i++ ){
	cin>>p[i] ; 
}
solve(0,{}); 
cout<<ans<<endl; 
}


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

using namespace std;
typedef long long ll;

int main(){
    string s;
    cin >> s;
    for(int i = 0; i < 3; i++){
        if(s[i] == '7'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3596
#include <iostream> 
#include <vector> 
#include <algorithm> 
#include <climits>
using namespace std;


using P = pair<int,int>;
struct SegmentTree{
  private:
  int n;
  vector<P> node;
  public:
  SegmentTree(vector<P> v){
    int sz = v.size();
    n = 1;
    while(n<sz) n *= 2;
    node.resize(2*n-1,P(INT_MAX,INT_MAX));
    for(int i=0; i<sz; i++) node[i+n-1] = v[i];
    for(int i=n-2; i>=0; i--) node[i] = min(node[2*i+1],node[2*i+2]);
  }
  void update(int x,int val){
    x += (n-1);
    node[x] = P(val,x);
    while(x>0){
      x = (x-1)/2;
      node[x] = min(node[2*x+1],node[2*x+2]);
    }
  }
  // [a,b)
  P getmin(int a,int b,int k=0,int l=0,int r=-1){
    if(r < 0) r = n;
    if(r <= a || b <= l) return P(INT_MAX,INT_MAX);
    if(a <= l && r <= b) return node[k];
    P vl = getmin(a,b,2*k+1,l,(l+r)/2);
    P vr = getmin(a,b,2*k+2,(l+r)/2,r);
    return min(vl,vr);
  }
};


vector<vector<int>> G;
vector<int> Eulartour;
void dfs(int v,int p=-1){
  Eulartour.emplace_back(v);
  for(int nv: G[v]){
    if(nv == p) continue;
    dfs(nv,v);
    Eulartour.emplace_back(v);
  }
}

vector<int> depth;
void dfs2(int v,int p=-1){
  for(int nv: G[v]){
    if(nv == p) continue;
    depth[nv] = depth[v] + 1;
    dfs2(nv,v);
  }
}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  G.resize(N);
  for(int i=0; i<N; i++){
    int K;
    cin >> K;
    for(int k=0; k<K; k++){
      int c;
      cin >> c;
      G[c].emplace_back(i);
      G[i].emplace_back(c);
    }
  }
  dfs(0);


  vector<int> fst(N,-1);
  for(int i=0; i<Eulartour.size(); i++){
    if(fst[Eulartour[i]] == -1) fst[Eulartour[i]] = i;
  }

  depth.resize(N);
  depth[0] = 0;
  dfs2(0);

  // P = pair<int,int>
  vector<P> p(Eulartour.size());
  for(int i=0; i<Eulartour.size(); i++){
    p[i].first = depth[Eulartour[i]];
    p[i].second = Eulartour[i];
  }

  SegmentTree seg(p);

  int Q;
  cin >> Q;
  for(int q=0; q<Q; q++){
    int u,v;
    cin >> u >> v;
    if(fst[u] > fst[v]) swap(u,v);
    P LCA = seg.getmin(fst[u],fst[v]+1);
    cout << LCA.second << "\n";
  }

  return 0;
}


Measured memory_bytes: 21584
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>

using namespace std;
#define LL long long

LL L[90];
int main() {
    L[0] = 2;
    L[1] = 1;
    int n;
    cin >> n;
    for(int i=2; i<=n; i++) L[i] = L[i-1] + L[i-2];
    cout << L[n] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,n) REP(i,0,n)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using namespace std;
typedef long long ll;

int main() {
    int A, B;
    cin >> A >> B;
    if (A * B % 2 == 1)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=(ll)(1e9+7);

int main(){
    int n,h,w;
    cin>>n>>h>>w;
    int ans=0;
    for(int i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        if(x>=h && y>=w)
            ans++;
    }
    cout<<ans;


    return 0;
}

Measured memory_bytes: 256
from sys import stdin
import sys
import numpy as np
import collections
from functools import cmp_to_key
import heapq
sys.setrecursionlimit(100000)

##  input functions for me
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##
class union_find:
    def __init__(self, n):
        self.N = n
        self._parent = [i for i in range(self.N)]
        self._mem = [1] * self.N
        self.compo = self.N

    def parent(self, a):
        if self._parent[a] == a:
            return a
        self._parent[a] = self.parent(self._parent[a])
        return self._parent[a]

    def united(self,a, b):
        return self.parent(a) == self.parent(b)
    
    def unite(self,a, b):
        a = self.parent(a)
        b = self.parent(b)
        if(a == b): return False
        if self._mem[a] > self._mem[b]: a, b = b, a
        self._parent[a] = b
        self._mem[b] += self._mem[a]
        self.compo -= 1
        return True
    
    def is_root(self,a):
        return a == self._parent[a]
    def mem_cnt(self,a):
        return self._mem[self.parent(a)]
    def dump(self):
        print(self._parent)



def main():
    N = ri()
    X = [0] * N
    Y = [0] * N
    for i in range(N):
        X[i], Y[i] = rip()
    
    uf = union_find(N)
    di = dict()
    for i in range(N):
        if not X[i] in di: di[X[i]] = i
        uf.unite(i, di[X[i]])
    di.clear()
    for i in range(N):
        if not Y[i] in di: di[Y[i]] = i
        uf.unite(i, di[Y[i]])

    hx = [set() for i in range(N)]
    hy = [set() for i in range(N)]
    for i in range(N):
        hx[uf.parent(i)].add(X[i])
        hy[uf.parent(i)].add(Y[i])
    
    tot = 0
    for i in range(N):
        tot += len(hx[i]) * len(hy[i])
    
    print(tot - N)



if __name__ == "__main__":
    main()


Measured memory_bytes: 80092
/*
Alfonso2 Peterssen (mukel)
8 - 1 - 2008
SPOJ "DQUERY"
Online algorithm
Preprocessing: O(n lg n)
Query: O(lg n)
Memory: O(n lg n)
*/
#include <cstdio>
#include <map>
 
using std::map;
 
const int
	MAXN = 600000,
	MAXLGN = 16;
 
int N, Q;
map< int, int > pos;
int tree[MAXN];
int cant;
struct node {
	int val, L, R, size;
} buff[2 * MAXN * MAXLGN];
 
int build( int lo, int hi ) {
	if ( lo > hi ) return 0;
 
	int idx = ++cant;
	
	int mid = ( lo + hi ) / 2;
	buff[idx] = (node){ mid, build( lo, mid - 1 ), build( mid + 1, hi ), 0 };
	return idx;
}
 
int update( int x, int val, int amount ) {
 
	if ( x == 0 ) return 0;
 
	int idx = ++cant;
	
	int L = buff[x].L;
	int R = buff[x].R;
	if ( val < buff[x].val ) L = update( L, val, amount );
	if ( val > buff[x].val ) R = update( R, val, amount );
	
	buff[idx] = (node){ buff[x].val, L, R, buff[x].size + amount };
 
	return idx;
}
 
int query( int x, int val ) {
	if ( val < buff[x].val )
		return query( buff[x].L, val ) + buff[x].size -	buff[ buff[x].L ].size;
 
	if ( val > buff[x].val )
		return query( buff[x].R, val );
 
	return buff[x].size - buff[ buff[x].L ].size;
}
 
int main() {
 
	scanf( "%d %d", &N, &Q );
 
	tree[0] = build( 1, N );
	for ( int i = 1; i <= N; i++ ) {
		int x, posx;
		scanf( "%d", &x ); posx = pos[x];
		if ( posx != 0 )
			tree[i] = update( update( tree[i - 1], posx, -1 ), i, +1 );
		else
			tree[i] = update( tree[i - 1], i, +1 );
		pos[x] = i;
	}
 
	// scanf( "%d", &Q );
	while ( Q-- ) {
		int lo, hi;
		scanf( "%d %d", &lo, &hi );
		printf( "%d\n", query( tree[hi], lo ) );
	}
 
	return 0;
}

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

int main()
{
    int N;
    vector<int> a, b, c;
    vector<vector<int>> h;
    cin >> N;
    a.resize(N);
    b.resize(N);
    c.resize(N);
    h.resize(N, vector<int>(3));
    for (int i = 0; i < N;i++){
        cin >> a[i] >> b[i] >> c[i];
    }

    h[0][0] = a[0];
    h[0][1] = b[0];
    h[0][2] = c[0];

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

    int h_max = max(h[N - 1][0], max(h[N - 1][1], h[N - 1][2]));

    cout << h_max << endl;
}

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

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    if((a<c&&c<b)||(b<c&&c<a)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


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

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

  bool res = false;
  int counter = 0;

  int d1, d2;
  rep(i, n) {
    cin >> d1 >> d2;
    if (d1 == d2) {
      counter++;
    } else {
      counter = 0;
    }

    if (counter >= 3) res = true;
  }

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

  return 0;
}



Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 7;
const double pi = acos(-1);
const int mod = 998244353;

int main(){
	ll n,m;
	scanf("%lld %lld",&n,&m);
	if(n == 1 || m == 1){
		cout << 1 << endl;
		return 0;
	}
	ll x = n / 2;
	ll y = m / 2;
	if(n%2) x++;
	if(m%2) y++;
	cout << x * y + (n/2)*(m/2)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	ll n, k;
	cin >> n >> k;
	if (k & 1) cout << (n / k)*(n / k)*(n / k) << '\n';
	else {
		ll m = (n + k / 2) / k;
		cout << (n / k)*(n / k)*(n / k) + m * m * m << '\n';
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;
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;
}

int main() {
	int a, b, t;
	cin >> a >> b >> t;
	int time = ((float)t + 0.5f)/a;
	cout << time*b << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <complex>

int main() {
    double a, b, C;
    std::cin >> a >> b >> C;

    C = C * 2 * std::acos(-1) / 360;

    double h = b * sin(C);
    double S = a * h * 0.5;
    double c = std::abs(std::complex<double>(a, 0) - std::complex<double>(b * cos(C), b * sin(C)));
    double L = a + b + c;

    std::cout << std::fixed << std::setprecision(20);
    std::cout << S << std::endl;
    std::cout << L << std::endl;
    std::cout << h << std::endl;
}


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

const int N = 1e6 + 5;
const int inf = 0x3f3f3f3f;

int n, x[N][2];
vector <int> g[N];
int id[2][N], siz;
int tot;

void init(int tp, int n, const vector <pair <int, int> > &v) {
	memset(id[tp], -1, sizeof(id[tp]));
	siz = 1;
	while (siz <= n) siz <<= 1;
	for (int i = 1; i < siz; ++ i)
		id[tp][i] = tot ++;
	for (int i = 0; i < n; ++ i)
		id[tp][i + siz] = v[i].second;
	for (int i = 2; i < (siz << 1); ++ i) {
		if (!~id[tp][i]) continue;
		if (!tp) g[id[tp][i >> 1]].push_back(id[tp][i]);
		else g[id[tp][i]].push_back(id[tp][i >> 1]);
	}
}

void Add(int tp, int i, int a, int b, int l, int r, int v) {
	if (l <= a && b <= r) {
		if (!tp) g[v].push_back(id[tp][i]);
		else g[id[tp][i]].push_back(v);
		return ;
	}
	if (r <= a || b <= l) return ;
	int m = (a + b) >> 1;
	Add(tp, i << 1, a, m, l, r, v);
	Add(tp, i << 1 | 1, m, b, l, r, v);
}

int dfn[N], cnt;
int scc[N], cc;
vector <int> rg[N];
bool vis[N];

void dfs(int u) {
	vis[u] = 1;
	for (int i = 0; i < g[u].size(); ++ i) {
		int v = g[u][i];
		if (!vis[v]) dfs(v);
	}
	dfn[-- cnt] = u;
}

void rdfs(int u) {
	scc[u] = cc;
	for (int i = 0; i < rg[u].size(); ++ i) {
		int v = rg[u][i];
		if (!~scc[v]) rdfs(v);
	}
}

void Scc() {
	for (int i = 0; i < tot; ++ i) rg[i].clear();
	for (int i = 0; i < tot; ++ i)
		for (int j = 0; j < g[i].size(); ++ j)
			rg[g[i][j]].push_back(i);
	memset(vis, 0, sizeof(vis));
	cnt = tot;
	for (int i = 0; i < tot; ++ i)
		if (!vis[i]) dfs(i);
	cc = 0;
	memset(scc, -1, sizeof(scc));
	for (int i = 0; i < tot; ++ i) {
		int u = dfn[i];
		if (!~scc[u]) {
			rdfs(u);
			++ cc;
		}
	}
}

bool check(int d) {
	tot = n * 2;
	vector <pair <int, int> > v;
	for (int i = 0; i < n; ++ i) {
		v.push_back(make_pair(x[i][0], i));
		v.push_back(make_pair(x[i][1], i + n));
	}
	sort(v.begin(), v.end());
	init(0, n * 2, v); init(1, n * 2, v);
	for (int i = 0; i < n; ++ i) {
		int l = lower_bound(v.begin(), v.end(), make_pair(x[i][0] - d + 1, -inf)) - v.begin();
		int r = upper_bound(v.begin(), v.end(), make_pair(x[i][0] + d - 1, inf)) - v.begin();
		int m = lower_bound(v.begin(), v.end(), make_pair(x[i][0], i)) - v.begin();
		Add(0, 1, 0, siz, l, m, i + n); Add(0, 1, 0, siz, m + 1, r, i + n);
	}
	for (int i = 0; i < n; ++ i) {
		int l = lower_bound(v.begin(), v.end(), make_pair(x[i][1] - d + 1, -inf)) - v.begin();
		int r = upper_bound(v.begin(), v.end(), make_pair(x[i][1] + d - 1, inf)) - v.begin();
		int m = lower_bound(v.begin(), v.end(), make_pair(x[i][1], i + n)) - v.begin();
		Add(0, 1, 0, siz, l, m, i); Add(0, 1, 0, siz, m + 1, r, i);
	}
	Scc();
	for (int i = 0; i < tot; ++ i)
		g[i].clear();
	for (int i = 0; i < n; ++ i)
		if (scc[i] == scc[i + n]) return 0;
	return 1;
}

int main() {
	ios :: sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; ++ i)
		cin >> x[i][0] >> x[i][1];
	int lb = 0, rb = inf;
	while (lb < rb) {
		int md = (lb + rb + 1) >> 1;
		if (check(md)) lb = md;
		else rb = md - 1;
	}
	cout << lb << endl;
	return 0;
}

Measured memory_bytes: 80828
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll h,w,k,ans=INF;cin>>h>>w>>k;

  V<string> v(h);
  rep(i,0,h)cin>>v[i];

  V<int> gind(h,0);
  V<int> num(h,0);
  rep(i,0,(1<<h)){
    int cnt=0;
    rep(j,0,h-1){
      if(i&(1<<j)){
        cnt++;
      }
      gind[j+1]=cnt;
    }

    ll res=cnt;

    num.assign(h,0);
    rep(j,0,w){
      bool ovf=false;
      rep(l,0,h){
        if(v[l][j]=='1'){
          num[gind[l]]++;
          if(k<num[gind[l]]){
            ovf=true;
          }
        }
      }
      
      if(ovf){
        res++;
        num.assign(h,0);
        rep(l,0,h){
          if(v[l][j]=='1')num[gind[l]]++;
        }

        rep(l,0,h){
          if(num[l]>k)res=LINF;
        }
      }
    }

    //if(chmin(ans,res))cerr<<i<<ENDL;
    chmin(ans,res);
  }
  cout<<ans<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
long long helper(vector<long long> &vec,vector<vector<long long>> &dp,long long l,long long r)
{
	if(l==r)return 0;
	if(l+1==r)return dp[l][r]=vec[l]+vec[r];
    if(dp[l][r]!=-1)return dp[l][r];
	long long ans=LLONG_MAX,sum=0;
	for (long long i = l; i<=r; ++i)
	{
		sum+=vec[i];
	}
	for (long long i = l; i < r; ++i)
	{
		ans=min(ans,sum+helper(vec,dp,l,i)+helper(vec,dp,i+1,r));
	}
	return dp[l][r]=ans;
}

int main()
{
	long long n;
	cin>>n;
	vector<long long> vec(n,0);
	for(long long i=0;i<n;i++)
		cin>>vec[i];
	vector<vector<long long>> dp(n,vector<long long>(n,-1));
	
	cout<<helper(vec,dp,0,n-1);
}


Measured memory_bytes: 1536
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int tmp,count;
        while(scan.hasNext()){
            tmp=scan.nextInt()+scan.nextInt();
            for(count = 1;tmp>=10;count++,tmp/=10);
            System.out.println(count);
        }
    }
}

Measured memory_bytes: 20568
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    vector<int> length(n);
    for(int i=0; i<n; i++){
        cin >>length.at(i);
    }
    sort(length.begin(),length.end());
    int c=0;
    for(int i=0;i<n-1;i++){
        c+=length.at(i);
    }
    if(c>length.at(n-1)){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}


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

typedef long long ll;

struct cube{
  string a[6];

  int count=1;
  
  void move_N(){
    string b[6]=a;
    a[0]=b[1];
    a[1]=b[2];
    a[2]=b[3];
    a[3]=b[0];
  }

  void move_E(){
    string b[6]=a;
    a[4]=b[1];
    a[1]=b[5];
    a[5]=b[3];
    a[3]=b[4];
  }

  void move_R(){
    string b[6]=a;
    a[4]=b[2];
    a[2]=b[5];
    a[5]=b[0];
    a[0]=b[4];
  }

  bool operator == (const cube &C){return C.a==a;}

  void rotate(){
    move_R();
    if(count%4){}
    else if(count/4<4){
      move_N();
    }
    else if(count/4==4){
      move_E();
    }
    else if(count/4==5){
      move_E();
      move_E();
    }
    count++;
  }

  cube(vector<string> &A){
    a[0]=A[5];
    a[1]=A[2];
    a[2]=A[0];
    a[3]=A[3];
    a[4]=A[1];
    a[5]=A[4];
  }

  cube(){}

  void init(vector<string> &A){
    for(int i=0;i<6;i++){a[i]=A[i];}
  }

  void operator = (const cube &C){
    for(int i=0;i<6;i++){a[i]=C.a[i];}
    count=C.count;
  }
};

vector<cube> C(6);
ll n;
ll mi=1e18;

ll count(){
  ll cost=0;
  for(int i=0;i<6;i++){
    map<string,ll> M;
    ll mx=0;
    for(int t=0;t<n;t++){
      M[C[t].a[i]]++;
      mx=max(mx,M[C[t].a[i]]);
    }
    cost+=n-mx;
  }
  return cost;
}

void dfs(ll d){
  C[d].count=1;
  if(d==n-1){
    for(int i=0;i<24;i++){
      mi=min(mi,count());
      C[d].rotate();
    }
    return;
  }
  else{
    for(int i=0;i<24;i++){
      dfs(d+1);
      C[d].rotate();
    }
  }
}

int main(){
  while(cin>>n && n){
    mi=1e9;
  vector<vector<string>> a(n,vector<string>(6));
  for(int i=0;i<n;i++){
    for(int t=0;t<6;t++){
      cin>>a[i][t];
    }
  }
  if(n==1){cout<<0<<endl; continue;}
  for(int i=0;i<n;i++){C[i]=cube(a[i]);}
  dfs(1);
  cout<<mi<<endl;
  
  }
  return 0;
}



Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
#define ll long long
inline int read() {
	int f=1,x=0;char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-') f=-1;ch=getchar();}
	while(isdigit(ch)) {x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int main() {
	int a,b,c;
	a=read();b=read();c=read();
	if(c<a&&c>b||c>a&&c<b) printf("Yes");
	else printf("No");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) { 
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

const int TABLE_SIZE = 200000 + 10;
ll table[TABLE_SIZE];


const ll MOD = 1000 * 1000 *1000 + 7 ;
inline void chadd(ll &a, const ll b) { a = (a + b) % MOD;}
inline ll add(const ll a, const ll b){ return (a + b) %  MOD;}
inline void chsub(ll &a, const ll b) { a = (a - b + MOD) % MOD;}
inline ll sub(const ll a, const ll b){ return (a - b + MOD) % MOD; }
inline void chmul(ll &a, const ll b) { a = (a * b) %  MOD;}
inline ll mul(const ll a, const ll b){ return (a * b) %  MOD;}

void init() {
  table[0] = 1LL;
  for(int i = 1; i < TABLE_SIZE; i++) {
    table[i] = mul(table[i-1], 2LL);
  }
}

ll gcd(ll m, ll n) {
  while(n != 0LL) {
    ll r = m % n;
    m = n;
    n = r;
  }
  return m;
}

int main() {
  init();
  int N; cin>>N;
  map<pll, pll> cnt;
  ll zero = 0;
  REP(i,N) {
    ll a, b; cin>>a>>b;
    if(a == 0LL || b == 0LL) {
      if(a+b == 0LL) zero++;
      else if(a == 0LL) cnt[make_pair(0,1)].first ++;
      else if(b == 0LL) cnt[make_pair(0,1)].second ++;
    } else {
      ll c = gcd(a, b);
      a /= c; b /= c;
      if(a < 0) {
	a = -a; b = -b;
      }
      if(b > 0) {
	pll p = make_pair(a, b);
	cnt[p].first++;
      } else {
	pll p = make_pair(-b, a);
	cnt[p].second++;
      }
    }
  }
  ll ans = 1LL;
  for(auto p: cnt) {
#ifdef DEBUG
    cout << p.first.first << " " << p.first.second <<
      "->" <<
      p.second.first << " " << p.second.second << endl;
#endif
      ll c = p.second.first;
      ll d = p.second.second;
      ll cc = table[(int)c] - 1LL;
      ll dd = table[(int)d] - 1LL;
      ll work = 1LL + cc + dd;
      chmul(ans, work);
#ifdef DEBUG
      cout << work << "," << ans << endl;
#endif
  }
  chadd(ans, zero);
  chsub(ans, 1LL);
  //  cout << "Answer=";
  cout << ans << endl;
  return 0;
}


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

struct UnionFind{
    vector<int> par;

    UnionFind(int n) : par(n,-1) { }
    void init(int n) { par.assign(n,-1); }

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

    bool issame(int x,int y){
        return root(x)==root(y);
    }

    bool merge(int x,int y){
        x=root(x);
        y=root(y);
        if(x==y) return false;
        if(par[x]>par[y]) swap(x,y);
        par[x]+=par[y];
        par[y]=x;
        return true;
    }

    int size(int x){
        return -par[root(x)];
    }
};

int main() {
    int n,m;
    cin>>n>>m;
    int a[m],b[m];
    rep(i,m){
        cin>>a[i]>>b[i];
        a[i]--,b[i]--;
    }

    int ans=0;
    rep(i,m){
        UnionFind uf(n);
        rep(j,m){
            if(j==i) continue;
            uf.merge(a[j],b[j]);
        }
        if(!uf.issame(a[i],b[i])) ans++;
    }

    cout<<ans<<endl;    
}



Measured memory_bytes: 256
import re  # 正規表現

s = input()

# re.sub(pattern, word, line) はlineのうち、patternに一致する部分をwordに変換します。
s = re.sub('eraser', '', s)
s = re.sub('erase', '', s)
s = re.sub('dreamer', '', s)
s = re.sub('dream', '', s)
print('YES' if len(s) == 0 else 'NO')


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

int main(void){
  int N,i;
  int* p;
  int count=0;
  scanf("%d",&N);
  int first_num=N,first_val,second_num=N,second_val;
  p=(int*)malloc(sizeof(int)*N);
  for(i=0;i<N;i++){
    scanf("%d",&p[i]);
    if((i+1)!=p[i]){
      count++;
      if(first_num==N){
        first_num=(i+1);
        first_val=p[i];
      }else{
        if(second_num==N){
          second_num=(i+1);
          second_val=p[i];
        }
      }
    }
  }
  if(count==0){
    printf("YES\n");
  }else{  
     if(count==2){
       if((first_num==second_val)&&(first_val==second_num)){
          printf("YES\n");
        }else{
          printf("NO\n");
        }
      }else{
        printf("NO\n");
    }
  }
  return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    char c; cin >> c;
    cout << (char) (c + 1) << endl;

    return 0;
}


Measured memory_bytes: 256
using System;

class itp1_3_b
{
	static void Main(string[] args)
	{
		int i = 1;
		while (true)
		{
			string str = Console.ReadLine();
			int x = int.Parse(str);
			if (x == 0)
			{
				break;
			}
			Console.WriteLine("Case " + i + ": " + x);
			i++;
		}
	}
}

Measured memory_bytes: 5812
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int,int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=1e9+7;
//
//
struct poi{
  int X;int Y;int Z;
  bool operator<(const poi&R)const{
    return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
  }
};
//
//
int main(){
	int H,W;
	char A[100][100];
	int c[26];
	fill(c,c+26,0);
	cin>>H>>W;
	FOR(i,0,H){
		FOR(j,0,W){
			cin>>A[i][j];
			c[A[i][j]-'a']++;
		}
	}
	int cnt=0;
	if(H%2==0&&W%2==0){
		FOR(i,0,26){
			if(c[i]%4!=0){
				Yes(0);
				return 0;
			}
		}
		Yes(1);
	}else{
		VE V;
		FOR(i,0,26){
			if(c[i]%4!=0){
				V.PB(c[i]);
			}
			cnt+=(c[i]/4)*4;
		}
		int o=0;
		FOR(i,0,(int)V.size()){
			if(V[i]%2==1){
				o++;
			}
		}
		if(H%2==1&&W%2==1){
			if(cnt<(H-1)*(W-1)){
				Yes(0);
			}else if(o==1){
				Yes(1);
			}else{
				Yes(0);
			}
		}else{
			int che;
			if(H%2==1){
				che=(H-1)*W;
			}else{
				che=(W-1)*H;
			}
			if(cnt<che){
				Yes(0);
			}else if(o==0){
				Yes(1);
			}else{
				Yes(0);
			}
		}
	}
	return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin)-1;i>=(end);i--)
#define IREP(i, n) IFOR(i,n,0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" << v[0]; FOR(i_debug, 1, v.size()){ cout << "," << v[i_debug]; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
// #define f first
// #define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;


template<typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) { REP(i, a.size()) {cin >> a[i]; a[i]--;} }

ll mod = 1000000007;

int main()
{
	ll N;
	ll ans = 0;
	cin >> N;
	vec A(N, -1);
	mat x(N, vec(N, -1));
	mat y(N, vec(N, -1));

	REP(i, N) {
		cin >> A[i];
		REP(j, A[i]) {
			cin >> x[i][j] >> y[i][j];
			x[i][j]--;
		}
	}

	vec stat(N, -1);
	IREP(i, pow(2, N)) {
		ll anstemp = 0;
		// debug(i);
		REP(j, N) {
			stat[j] = (i >> j) % 2;
			// debug(stat[j]);
		}
		REP(j, N) {
			REP(k, A[j]) {
				if (stat[j] == 1 && stat[x[j][k]] != y[j][k]) {
					anstemp = -1;
					// debug(ans);
				}
			}
		}
		if (anstemp == -1) {
			anstemp = 0;
			continue;
			// debug(ans);
		}
		else {
			REP(i, N) {
				anstemp += stat[i];
			}
			ans = max(anstemp, ans);
		}
	}


	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
//2015
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main(void){
	int i,ad[4]={0},e=0,f=0,sum=0;
	for(i=0;i<4;i++){
		cin>>ad[i];
	}
	cin>>e;
	cin>>f;
	sort(ad,ad+4,greater<int>());//降順,昇順＝＝sort(ad,ad+4);
	for(i=0;i<3;i++){
		sum+=ad[i];
	}
	if(e<f){
		sum+=f;
	}
	else{
		sum+=e;
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 3140
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;

public class Main {
	public static void main(String[] args) {
		ArrayList<Integer> mountain = new ArrayList<Integer>();
		try {
			BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));

			int line;
			for (int i = 0; i < 10; i++) {
				line = Integer.parseInt(stdReader.readLine());
				mountain.add(line);
			}

			Collections.sort(mountain);

			for (int i = 9; i >= 7; i--) {
				System.out.println(mountain.get(i));
			}
		} catch (IOException e) {

		}
	}
}

Measured memory_bytes: 9364
#include <iostream>
#include <cmath>
#include <vector>
#include <unordered_map>

using namespace std;
using Map = unordered_map<int, int>;

int get_smallest_hop(int i, const vector<int>&vec, Map&memo)
{
  if (i == 0) return 0;
  if (i == 1) return abs(vec[0] - vec[1]);
  int p1, p2;
  if (memo.find(i-1)!=memo.end()) {
    p1 = memo[i-1];
  } else {
   	p1 = memo[i-1] = get_smallest_hop(i-1, vec, memo);
  }
  if (memo.find(i-2)!=memo.end()) {
    p2 = memo[i-2];
  } else {
   	p2 = memo[i-2] = get_smallest_hop(i-2, vec, memo);
  }
  return min(abs(vec[i-1]-vec[i])+p1,
             abs(vec[i-2]-vec[i])+p2);
}


int main()
{
  int n; cin >> n;
  vector<int> h;
  
  for (int i = 0; i < n; ++i) {
    int v; cin >> v;
    h.push_back(v);
  }
  
  Map memo;
  cout << get_smallest_hop(n-1, h, memo);
  return 0;
}

Measured memory_bytes: 11024
#include<bits/stdc++.h>
using namespace std;
#define int ll
#define ll long long
const ll mod = 998244353;
ll power(ll x, ll y, ll p) {
	ll res = 1ll;
	x = x % p;
	while (y) {
		if (y & 1ll)res = (res * x) % p;
		y = y >> 1ll;
		x = (x * x) % p;
	}
	return res;
}
signed main(){
  int n;
  string s;
  cin>>n>>s;
  if(n%2)return cout<<"No",0;
  n/=2;
  for(int i=0;i<n;++i)
    if(s[i]!=s[i+n])return cout<<"No",0;
  return cout<<"Yes",0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,t;
    cin>>n>>a;
    a=a*2+1;
    t=n/a;
    if(n%a==0)
    {
        cout<<t<<endl;
    }
    else{
            t++;
        cout<<t<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
def main():

    x,y = tuple([int(t)for t in input().split()])

    b = y-2*x
    if b<0:
        print("No")
        return
    if b%2==1:
        print("No")
        return
    b //= 2

    if x-b<0:
        print("No")
        return
    print("Yes")
    

if __name__ == "__main__":
    main()

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

int main(){
    int N;
    cin >> N;
    // vector<string> S(N);
    // for(int i = 0; i < N; i++)cin >> S.at(i);
    // sort(S.begin(),S.end());
    // for(int i = 0; i < N; i++)cout << S.at(i) << endl;
    
    //STLのコンテナmapを使用する。
    map<string,int> S;
    int max_value = 0;
    for(int i = 0; i < N; i++){
        string tmp;
        cin >> tmp;
        if(S.count(tmp)){
            S[tmp]++;
        }else{
            S[tmp] = 1;
        }
        max_value = max(max_value,S.at(tmp));
    }
    
    for(auto p : S){
        auto k = p.first;
        auto v = p.second;
        if(v==max_value){
            cout << k << endl;
        }
    }
}

Measured memory_bytes: 25216