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

using namespace std;

int calculate_time(const vector<int> &v) {
    int time = 0;
    for (int i = 0; i < v.size(); ++i) {
        if (time % 10) time += 10 - (time % 10);
        time += v[i];
    }
    return time;
}

int main() {
    vector<int> perms(5);
    for (auto &p: perms) {
        cin >> p;
    }
    sort(perms.begin(), perms.end());

    int best = 0xFFFFFFF;
    do {
        best = min(best, calculate_time(perms));
    } while (next_permutation(perms.begin(), perms.end()));

    cout << best << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}

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


int main()
{
  int N; cin >> N;
  int M = (N % 2 ? N : N + 1);
  cout << (N*(N-1)/2 - N / 2) << endl;
  for (int i = 1; i <= N; i++) {
    for (int j = i + 1; j <= N; j++) {
      if (i + j != M && i != j) {
        cout << i << ' ' << j << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1505,p=1000000007;
int read(){
	int f=1,g=0;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int n,f[N][N],d[N][N];
typedef unsigned short us;
us a[N][N],l[N][N],r[N][N];
ll ans;
char ch[N];
inline void chkmin(us &x,us y){if (x>y) x=y;}
inline void chkmax(us &x,us y){if (x<y) x=y;}
int main(){
	n=read();
	for (int i=1;i<=n;i++){
		scanf(" %s",ch+1);
		for (int j=1;j<=n;j++)
		a[i][j]=(ch[j]=='#') ? 0 : (ch[j]-'0');
	}
	memset(l,0x3f,sizeof(l));
	for (int i=n;i;i--)
	for (int j=n;j;j--)
	if (a[i][j]){
		int t=f[i+1][j]+f[i][j+1];
		d[i][j]=max(max(d[i][j+1],d[i+1][j]),i);
		if (!a[i][j+1]){l[j][i]=r[j][i]=j;}
		else if (!a[i+1][j]){
			memcpy(l[j]+i,l[j+1]+i,(n-i+1)*2);
			memcpy(r[j]+i,r[j+1]+i,(n-i+1)*2);
			l[j][i]=j;
		}
		else{
			l[j][i]=j;r[j][i]=r[j+1][i];
			us las=0;
			for (int x=i+1;x<=d[i][j];x++){
				if ((l[j+1][x]<=r[j][x])&&(las<l[j+1][x])) t-=f[x][l[j+1][x]];
				chkmax(las,r[j][x]);
				chkmin(l[j][x],l[j+1][x]);chkmax(r[j][x],r[j+1][x]);
			}
		}
		ans+=a[i][j]*t;
		f[i][j]=a[i][j]+t;
	}
	else{memset(l[j]+i,0x3f,(n-i+1)*2);memset(r[j]+i,0,(n-i+1)*2);}
	printf("%lld\n",ans);
	return 0;
}

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

void main_()
{
    const map<char, int> c2i = { { 'M', 0 }, { 'A', 1 }, { 'R', 2 }, { 'C', 3 }, { 'H', 4 } };

    ll N;
    array<ll, 5> ss = {};
    cin >> N;
    for (ll i = 0; i < N; ++i) {
        string s;
        cin >> s;
        auto it = c2i.find(s[0]);
        if (it != end(c2i)) {
            ss[it->second]++;
        }
    }

    ll ans = 0;
    for (ll i = 0; i < 3; ++i) {
        for (ll j = i + 1; j < 4; ++j) {
            for (ll k = j + 1; k < 5; ++k) {
                ans += ss[i] * ss[j] * ss[k];
            }
        }
    }

    cout << ans << "\n";
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 256
import sys
A,B,N = map(int, input().split())


def calc(a,b,x):
    num = ((a*x)//b)-a*(x//b)
    return num


if B == N:
    X = N-1
    print(calc(A,B,X))
    sys.exit()
if B < N:
    X = B-1
    print(calc(A,B,X))
    sys.exit()
if B > N:
    X = N
    print(calc(A,B,X))
    sys.exit()

Measured memory_bytes: 9132
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

#define N 100001

int parent[N];

void uft_init(int n)
{
  for (int i = 0; i < n; i++)
    parent[i] = -1;
}

int uft_root(int a)
{
  if (parent[a] < 0)
    return a;
  return parent[a] = uft_root(parent[a]);
}

int uft_size(int a)
{
  if (parent[a] >= 0)
    return uft_size(parent[a]);
  return -parent[a];
}

void uft_unite(int a, int b)
{
  int ra = uft_root(a), rb = uft_root(b);
  if (ra == rb)
    return;
  if (uft_size(ra) > uft_size(rb))
  {
    parent[ra] += parent[rb];
    parent[rb] = ra;
  }
  else
  {
    parent[rb] += parent[ra];
    parent[ra] = rb;
  }
}

int main() {
  int n, m, k, a, b;
  scanf("%d%d%d", &n, &m, &k);
  uft_init(n);
  int cnt[n];
  for (int i = 0; i < n; i++)
    cnt[i] = 0;
  for (int i=0; i<m; i++) {
    scanf("%d%d", &a, &b);
    a--;
    b--;
    uft_unite(a, b);
    cnt[a]++;
    cnt[b]++;
  }
  for (int i=0; i<k; i++) {
    scanf("%d%d", &a, &b);
    a--;
    b--;
    if (uft_root(a) == uft_root(b)) {
      cnt[a]++;
      cnt[b]++;
    }
  }
  /*
  for (int i=0; i<n; i++)
    printf("%d %d\n", uft_size(i), cnt[i]);*/
  for (int i=0; i<n; i++)
    printf("%d ", uft_size(i)-cnt[i]-1);
  printf("\n");
  return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <algorithm>
#include <cassert>
#include <string>
#include <climits>
#include <numeric>

#define all(x) begin(x),end(x)

using namespace std;
using ll = long long;

int main()
{
	int N;
	cin >> N;
	vector<string> v(N);
	map<string, int> t;
	bool Unique = true;
	for (int i = 0; i < N; ++i) {
		cin >> v[i];
		t[v[i]] += 1;
		if (t[v[i]] == 2) {
			Unique = false;
		}
	}
	if (!Unique) {
		cout << "No" << endl;
		return 0;
	}

	auto len = v[0].length();
	string tmp = v[0];
	char l = tmp[len-1];
	for (int i = 1; i < N; ++i) {
		tmp = v[i];
		if (tmp[0] != l) {
			cout << "No" << endl;
			return 0;
		}
		len = v[i].length();
		tmp = v[i];
		l = tmp[len-1];
	}

	cout << "Yes" << endl;

}

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

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

const int N = 2e5+10 , mod = 1e9+7;

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   string s , t;
   cin >> s >> t;
   s += t[t.length() - 1];
   if(s == t)
      cout << "Yes";
   else
      cout << "No";
   return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    int N, M; cin >> N >> M;
    vector<int> A(M); for (auto &a : A) cin >> a;
    Int sum = accumulate(begin(A), end(A), 0LL);
    if (N >= sum) {
        cout << N - sum << endl;
    } else {
        cout << -1 << endl;
    }
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  int len = s.size();
  vector<int> smaller;
  int num = 0;
  smaller.push_back(num);
  rep(i, len) {
    if(s[i]=='<') ++num;
    else num = 0;
    smaller.push_back(num);
  }
  
  vector<int> bigger;
  num = 0;
  bigger.push_back(num);
  rep(i, len) {
    if(s[len-i-1]=='>') ++num;
    else num = 0;
    bigger.push_back(num);
  }
  
  reverse(all(bigger));
  
  ll ans = 0;
  rep(i,len+1) {
    ans += max(smaller[i], bigger[i]);
//    cout << smaller[i] << " " << bigger[i] << endl;
  }
  
//  cout << smaller.size() << " " << bigger.size() << endl;
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 8848
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
int main(){
  long long a,b;
  cin>>a>>b;
  
  if(a%2==b%2) cout << (a+b)/2 <<endl;
  else cout <<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    int N;scanf("%d",&N);
    vector<vector<int> > A(N,vector<int>(N-1));
    rep(i,N){
        rep(j,N-1){
            int a;scanf("%d",&a);a--;
            A[i][j]=a;
        }
    }
    vector<int> cur(N,0);
    int all_match=0;
    bool found = 0;
    int res = 0;
    while(1){
        found=0;
        vector<bool> is_match(N,false);
        rep(i,N){
            if(cur[i]==N-1)continue;
            int b = A[i][cur[i]];//相手の番号
            if(is_match[i]||is_match[b])continue;
            if(i==A[b][cur[b]]){//相手の対戦相手と自分が一致したら
                is_match[b]=1;
                is_match[i]=1;
                cur[i]++;
                cur[b]++;
                found=1;
                all_match++;
            }
        }
        if(!found)break;
        res++;
    }
    if(all_match==(N*(N-1))/2)printf("%d\n",res);
    else printf("-1\n");
    return 0;
}

Measured memory_bytes: 6272
#include <cmath>
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>

int main(){
  int N,C;
  std::cin >> N >> C;

  std::vector<std::tuple<int, int, int>> r_arr;
  for(int i = 0; i < N; i++){
    int s,t,c;
    std::cin >> s >> t >> c;
    r_arr.push_back(std::make_tuple(2*s-1,1,c));
    r_arr.push_back(std::make_tuple(2*t,2,c));
  }

  std::sort(r_arr.begin(), r_arr.end());

  int nc = 0, max_nc = 0;
  int ch_arr[30] = {};
  for(auto&& it: r_arr){
    int time,st,ch;
    std::tie(time,st,ch) = it;
    if(st == 1){
      ch_arr[ch]++;
      if(ch_arr[ch] == 1){
        nc++;
      }
    }else{
      ch_arr[ch]--;
      if(ch_arr[ch] == 0){
        nc--;
      }
    }
    max_nc = std::max(max_nc, nc);
  }

  std::cout << max_nc << std::endl;

  return 0;
}



Measured memory_bytes: 4724
import std.stdio, std.conv, std.string, std.algorithm,
       std.math, std.array, std.container, std.typecons;

void main() {
  auto n = readln.chomp.to!int;
  int[][] ab = new int[][](10,10);
  for(int i=1; i<=n; i++) {
    int a = i;
    while(a>=10) a/=10;
    int b = i%10;
    ab[a][b]++;
  }
  long result = 0;
  for(int i=0; i<10; i++) for(int j=0; j<10; j++) {
    result += ab[i][j]*ab[j][i];
  }
  writeln(result);
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#define INF 2147483647
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  cout<<(a+b)%24<<endl;
  return 0;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
l=0
r=0

for i in range(M):
    L,R=map(int,input().split())
    if l<L:
        l=L
    if r==0:
        r=R
    else:
        if r>R:
            r=R
if r>=l:
    print(r-l+1)
else:
    print(0)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
int dy[4] = { 1, 0, -1, 0 }, dx[4] = { 0, 1, 0, -1 };
const ll MOD = 1e9 + 7;
const ll INF = 1e9;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> d(n);
    rep(i, n)
    {
        cin >> d[i];
    }
    ll abc = 0;
    ll cnt = 0;
    sort(d.begin(), d.end());
    cout << d[n / 2] - d[n / 2 - 1] << endl;
    return 0;
}

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

vector<int> t;
int rotate[10][10];
int n,ans;

void solve(vector<int> s,int idx,int cost){
	if(idx == n) ans = cost;
	if(cost >= ans) return;

	if(s[idx] == t[idx]){
		solve(s,idx+1,cost);
	}
	else{
		for(int i=idx;i<n;i++){
			int r = rotate[s[idx]][t[idx]];
			vector<int> next = s;
			for(int j=idx;j<=i;j++) next[j] = (next[j] + 10 + r) % 10;
			solve(next,idx+1,cost+1);
		}
	}
}

int main(void){
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			int d = j - i;
			int x = abs(d);
			if(j < i && x > 10-x)
				d = 10-x;
			else if(j > i && x > 10-x)
				d = -(10-x);

			rotate[i][j] = d;
		}
	}

	while(cin>>n,n){
		vector<int> s(n);
		t = vector<int>(n);

		string a,b;
		cin>>a>>b;
		for(int i=0;i<n;i++){
			s[i] = a[i] - '0';
			t[i] = b[i] - '0';
		}

		ans = 999999999;
		solve(s,0,0);
		cout<<ans<<endl;
	}

	return 0;
}

Measured memory_bytes: 928
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        s: chars
    }
    let ans = match s[2] {
        'N' => if s[0] == 'S' {7} else {6},
        'E' => 5,
        'D' => 4,
        'U' => 3,
        'I' => 2,
        'T' => 1,
        _ => 0
    };
    println!("{}", ans);
}


Measured memory_bytes: 4352
from collections import defaultdict
from collections import deque

class Graph(object):

    def __init__(self):
        self.graph = defaultdict(list)
        self.node = defaultdict(int)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, a, b):
        self.graph[a].append(b)

    def get_nodes(self):
        return self.graph.keys()

def getlist():
	return map(int, input().split())


G = Graph()
N = int(input())
for i in range(N - 1):
	a, b = getlist()
	G.add_edge(a - 1, b - 1)
	G.add_edge(b - 1, a - 1)
	G.node[a - 1] += 1
	G.node[b - 1] += 1

c = getlist()
c = sorted(c)

cnt = []
for i in G.node:
	cnt.append([G.node[i], i])

D = defaultdict(int)
Q = deque()
for i in G.node:
	if G.node[i] == 1:
		Q.append(i)


val = 0
while Q:
	x = Q.popleft()
	D[x] = c[val]
	val += 1
	for i in G.graph[x]:
		G.node[i] -= 1
		if G.node[i] == 1:
			Q.append(i)




M = sum(c) - c[-1]
print(M)

ansL = []
for i in range(N):
	ansL.append(D[i])

ansL = list(map(str, ansL))
print(" ".join(ansL))

Measured memory_bytes: 9196
#include <iostream>
using namespace std;
int main(void){
    int n, a, b;
    cin >> n >> a >> b;
    int t, ans = n;
    for (int i = 0; i < n; i++) {
        cin >> t;
        if(a<=t and t<b) ans--;
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(void){
    int N;
    string S;
    cin >> N >> S;
    int l=S.length();
    string dict="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string out=S;
    for(int i=0;i<l;i++){
        char now=S[i];
        for(int j=0;j<26;j++){
            if(now==dict[j]){
                cout << dict[(j+N)%26];
                break;
            }
        }
    }
    //cout << out << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	int N;
	cin>>N;
	vector<ll> H(N);
	rep(i,N)cin>>H[i];
	string ans = "Yes";
	for (int i = 0; i < N-1; ++i){
		if(H[i]>H[i+1]){
			ans = "No";
			break;
		}
		else if(H[i]== H[i+1]){
			continue;
		}
		else{
			H[i+1]--;
		}
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys
from collections import deque
from bisect import bisect_left

def solve(N: int, A: "List[int]"):
    b = deque([A[0]])
    for a in A[1:]:
        if a <= b[0]:
            b.appendleft(a)
        else:
            idx = bisect_left(b, a)
            b[idx-1] = a
    print(len(b))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 8904
local n=io.read("n")
local t={}
for i=1,n do
    t[i]={io.read("n","n")}
end
table.sort(t,function(a,b)
    return a[1]+a[2]>b[1]+b[2]
end)

local total=0
for i=1,n do
    total=total-t[i][2]
end
for i=1,n,2 do
    total=total+t[i][1]+t[i][2]
end
print(string.format("%d",total))

Measured memory_bytes: 9824
a, b, c = map(int, input().split())
k = int(input())
m = 0
while a >= b:
    b = b*2
    m += 1
    if a< b:
        break

while b >= c:
    c = c*2
    m += 1
    if b < c:
        break
    
if k >= m:
    print("Yes")
else:
    print("No")

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n;cin>>n;
  set<int> st;
  int f = 0;
  for(int i=0;i<n;i++){
    int t;cin>>t;
    if(t<=399)st.insert(0);
    else if(t<=799)st.insert(1);
    else if(t<=1199)st.insert(2);
    else if(t<=1599)st.insert(3);
    else if(t<=1999)st.insert(4);
    else if(t<=2399)st.insert(5);
    else if(t<=2799)st.insert(6);
    else if(t<=3199)st.insert(7);
    else f++;
  }

  if(st.size()==0){
    cout<<1;
  } else {
    cout<<st.size();
  }
  cout<<' ';
  int mx = st.size() + f;
  cout<<mx<<endl;

  return 0;
}


Measured memory_bytes: 256
class UnionFind:
    def __init__(self,n):
        self.ps = [-1]*(n+1)
    def find(self,x):
        if self.ps[x]<0:
            return x
        else:
            self.ps[x]=self.find(self.ps[x])
            return self.ps[x]
    def unite(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if x==y:
            return False
        if self.ps[x]>self.ps[y]:
            x,y = y,x
        self.ps[x] += self.ps[y]
        self.ps[y] = x
        return True
    def same(self,x,y):
        return self.find(x)==self.find(y)
    def size(self,x):
        x = self.find(x)
        return -self.ps[x]

n,m = map(int, input().split())
uf = UnionFind(n+m)
for i in range(1,n+1):
  l = list(map(int, input().split()))
  for j in range(1,1+l[0]):
    uf.unite(i,n+l[j])
for i in range(n+1,n+m+1):
  if uf.size(i) == 1:
    uf.unite(1,i)
print("YES" if uf.size(1) == n+m else "NO")

Measured memory_bytes: 9176
#pragma region header
#include <bits/stdc++.h>
#define all(a) begin(a), end(a)
#define rall(a) rbegin(a), rend(a)
#define rep1(i, n) for (decltype(+n) i = 0; i < (n); i++)
#define rrep1(i, n) for (auto i = n - 1; i > static_cast<decltype(i)>(-1); i--)
#define rep2(i, a, b) for (auto i = (a); i < (b); i++)
#define rrep2(i, a, b) for (auto i = b - 1; i >= a; i--)
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1) (__VA_ARGS__)
#define rrep(...) GET_MACRO(__VA_ARGS__, rrep2, rrep1) (__VA_ARGS__)
#define each(i, a) for (auto &&i : (a))
using namespace std;

using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using vvs = vector<vs>;
using vd = vector<ld>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using vp = vector<pii>;
using vvp = vector<vp>;

template <class T>
void COUT(T x) { cout << x << endl; }

#pragma endregion header

const int vx[] = {0, 1, 0, -1}, vy[] = {1, 0, -1, 0};

void solve() {
  int H, W;
  cin >> H >> W;
  int ch, cw;
  cin >> ch >> cw;
  ch--;
  cw--;
  int dh, dw;
  cin >> dh >> dw;
  dh--;
  dw--;
  vs s(H);
  rep(i, H)cin >> s[i];


  vp jumped;
  jumped.emplace_back(ch, cw);
  vvb used(H, vb(W));
  used[ch][cw] = true;
  function<bool(int, int)> check = [&](int x, int y) {
    if(x < 0 || y < 0 || x >= H || y >= W
      || s[x][y] == '#' || used[x][y])return false;
    used[x][y] = true;
    return true;
  };

  for(int i = 0; !jumped.empty(); i++) {
    queue<pii> q;
    each(p, jumped)q.push(p);
    vp moved;
    while(!q.empty()) {
      auto p = q.front();
      if(p.first == dh && p.second == dw) {
        COUT(i);
        return;
      }
      q.pop();
      moved.push_back(p);
      rep(i, 4) {
        int nx = p.first + vx[i], ny = p.second + vy[i];
        if(check(nx, ny))q.emplace(nx, ny);
      }
    }
    jumped.clear();
    each(p, moved) {
      for(int j = -2; j < 3; j++)for(int k = -2; k < 3; k++) {
        int nx = p.first + j, ny = p.second + k;
        if(check(nx, ny))jumped.emplace_back(nx, ny);
      }
    }
  }
  COUT(-1);
}


#pragma region main
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  solve();
}
#pragma endregion main


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

int main(){
    int N;
    int max = 0;
    int min;
    cin >> N;
    vector<int>  vec(N);
    for (int i = 0; i < N; i++) cin >> vec[i];
    min = vec[0];
    for (int i = 0; i < N; i++){
        if (max < vec[i]) {
            max = vec[i];
        }else if(min > vec[i]){
            min = vec[i];
        }
    }
    int d;
    d = max - min;
    cout << d << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> A(N);
    for (auto& a : A) {
        cin >> a;
    }
    vector<ll> cnt(100001, 0);
    ll sum = 0;
    for (auto& a : A) {
        ++cnt[a];
        sum += a;
    }
    int Q;
    cin >> Q;
    int B, C;
    rep(i, 0, Q) {
        cin >> B >> C;
        sum -= B * cnt[B];
        sum += C * cnt[B];
        cout << sum << endl;
        cnt[C] += cnt[B];
        cnt[B] = 0;
    }
    return 0;
}

Measured memory_bytes: 4784
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int a[] = new int[14];
		int b[] = new int[7];
		for (int i = 0; i < 14; i++) {
			a[i] = stdIn.nextInt();
		}
		for (int i = 0, j = 0; i < 7; i++) {
			b[i] = a[j] - a[j + 1];
			j = j + 2;
		}
		for (int i = 0; i < 7; i++) {
			System.out.println(b[i]);
		}
	}
}

Measured memory_bytes: 17316
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N=2005;
int dp[N][N][2],arr[N],n,Z,W;
int rec(int pos,int last,int turn){
	if(pos==n){
		int a,b;
		if(turn){
			b=arr[n];
			if(last)
				a=arr[last];
			else
				a=Z;
		}
		else{
			a=arr[n];
			if(last)
				b=arr[last];
			else
				b=W;
		}
		return abs(a-b);
	}
	int &ret=dp[pos][last][turn];
	if(~ret)
		return ret;
	ret=rec(pos+1,last,turn);
	if(!turn)
		umax(ret,rec(pos+1,pos,turn^1));
	else
		umin(ret,rec(pos+1,pos,turn^1));
	return ret;	
}
int main(){
    //~ freopen("file.in", "r", stdin);
    memset(dp,-1,sizeof dp);
    scanf("%d%d%d",&n,&Z,&W);
    for(int i=1;i<=n;i++)
		scanf("%d",arr+i);
	printf("%d\n",rec(1,0,0));	
	return 0;
}


Measured memory_bytes: 31744
#include<bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int cmp(int a,int b){
    return a<b;
}
int main(){
    int N,M;
    cin>>N>>M;
    int a[101];
    int sum=0;
    for(int i=1;i<=N;i++){
        cin>>a[i];
        sum+=a[i];
    }
    sort(a+1,a+N+1,cmp);
    if(a[N-M+1]<(sum*1.0/(4*M))) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <random>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using Pt = pair<int, int>;

int main()
{
	int N, K;
	cin >> N >> K;
	vi A(N);
	for (auto& x : A)
		cin >> x;
	int j = 0;
	for (int i = K; i < N; ++i)
	{
		int x = A[j++];
		int y = A[i];
		if (x < y)
		{
			cout << "Yes" << endl;
		}
		else
		{
			cout << "No" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 4048
#include <iostream>
#include <string>
#include <vector>
#include<algorithm>
#include<sstream>
using namespace std;

// p^2 <= N を満たすpのmax
int root_int(int N) {
	int n = 1;
	while(n*n <= N) {
		n++;
	}
	return n - 1;
}

// べき乗
int power(int a, int b) {
	if (b == 0) return 1;
	else return a * power(a, b - 1);
}

int main() {
	int X;
	cin >> X;
	int n = root_int(X);
	int ans = 1;
	for (int i = 2; i <= n; i++) {
		int p = 2;
		while (power(i,p) <= X) p++;

		if (power(i,p-1) > ans) ans = power(i,p-1);
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<utility>
#include<queue>
#include<string>
#define INF 10000000
using namespace std;
typedef pair<int,int> pii;
typedef queue<pii> que;

int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int w,h,dist[1000][1000];
int nx,ny;
string map[1000];

int bfs(){
  que q;
  pii p;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)dist[i][j]=INF;
  q.push(make_pair(0,0));
  dist[0][0]=0;
  while(q.size()!=0){
    p=q.front();q.pop();
    if(p.first==w && p.second==h)break;
    for(int i=0;i<4;i++){
      nx=p.first+dx[i];ny=p.second+dy[i];
      if(0<=nx && nx<w && 0<=ny && ny<h && map[ny][nx]!='1' && dist[ny+dy[i]][nx+dx[i]]==INF){
	q.push(make_pair(nx+dx[i],ny+dy[i]));
	//cout<<"ny is "<<ny<<" nx is "<<nx<<endl;
	//cout<<"dist is "<<dist[p.second][p.first]<<endl;
	map[ny][nx]=1;
	dist[ny+dy[i]][nx+dx[i]]=dist[p.second][p.first]+1;
      }
    }
  }
  return dist[h-1][w-1];
}

int main(){
  while(cin>>w>>h,h){
    cin.ignore();
    w=2*w-1;
    h=2*h-1;
    for(int i = 0;i < h;i++) getline(cin,map[i]);   
    int ans=bfs();
    if(ans!=INF)cout<<ans+1<<endl;
    else cout<<"0"<<endl;
  }
  return 0;
}

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

int main(){
    
    long long int H,W;cin>>H>>W;
    vector<long long int> A(H),B(H),C(H),D(H);
    for(int i=0;i<H;i++){
        cin>>A[i]>>B[i];
        C[i]=A[i];
        D[i]=B[i];
    }
    sort(A.begin(),A.end());
    long long int x=A[H-1],sum=0;
    int j=-5,l=0;
    sort(B.rbegin(),B.rend());
    for(int i=0;i<H;i++){
        if(B[i]<=x){
            break;
        }
        sum+=B[i];
        if(sum>=W){
            j=i;
            break;
        }
        l++;
    }
    if(j>=0) cout<<j+1<<endl;
    else{
        cout<<(W-sum+x-1)/x+l<<endl;
    }
}




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

int main(){
  ll N; cin>>N;
  ll ans=1;
  ll X=pow(10, 18);
  vector<ll> A(N);
  map<ll, ll> H;
  for(ll i=0; i<N; i++){
    ll a; cin>>a;
    A[i]=a;
    H[a]=1;
  }
  if(H.count(0)) ans=0;
  else{
  for(ll i=0; i<N; i++){
    if((X/ans)<A[i]){
      ans=-1;
      break;
    }
    else ans*=A[i];
  }
  }
  cout<<ans<<endl;
}

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

int main() {
	int a, b;
	cin >> a >> b;
	if (a == b)
		cout << "Draw" << endl;
	else {
		if (a == 1 || (b != 1 && a > b))
			cout << "Alice" << endl;
		else
			cout << "Bob" << endl;
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int N; cin>>N; string ans="";
  vector<string> v={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
  while(N>0){N--;
    int rem=N%26; 
    ans+=v[rem]; N/=26;
  }
  reverse(ans.begin(),ans.end());
  cout<<ans;
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 0x3fffffff;


int main(){
	//ios_base::sync_with_stdio(0);
	int N, M;
	int cnt[100005] = {};

	cin >> N >> M;
	rep(i,M){
		int a, b;
		cin >> a >> b;
		cnt[a]++;
		cnt[b]++;
	}

	bool ans = true;
	rep(i,N+1) if( cnt[i] % 2 ) ans = false;

	cout << (ans ? "YES" : "NO") << endl;

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    string s; cin >> s;
    ll len = s.size();
    ll g=0, p=0;
    rep(i,len){
        if(s[i] == 'g') g++;
        else p++;
    }
    cout << len/2 - p << endl;
}

Measured memory_bytes: 512
from bisect import bisect_left
import sys
input = sys.stdin.readline
H,W,m = map(int,input().split())
h = [0]*(H+1)
w = [0]*(W+1)
c = [[-1,10**6] for i in range(H+1)]
for i in range(m):
    a,b = map(int,input().split())
    h[a] += 1
    w[b] += 1
    c[a].append(b)
mh = max(h)
mw = max(w)
hkouho = []
wkouho = []
for i in range(H+1):
    if h[i] == mh:
        hkouho.append(i)
for i in range(W+1):
    if w[i] == mw:
        wkouho.append(i)
for i in range(H+1):
    c[i].sort()
# print(hkouho)
# print(wkouho)
for i in hkouho:
    for j in wkouho:
        # print(c[i],i,j,bisect_left(c[i],j))
        if c[i][bisect_left(c[i],j)] != j:
            print(mh+mw)
            exit()
print(mh+mw-1)

Measured memory_bytes: 82460
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back 
const int mod=1e9+7;
ll dp[110][100010];
ll solve(ll b[],int n,int k){
	 if(k == 0) 
	 return 1;
    if(n == 0|| k < 0)
     return 0;
    if(dp[n][k] != -1) 
    return dp[n][k];
    ll res = solve (b,n - 1, k) % mod + solve (b,n, k - 1) % mod - solve(b,n - 1, k - b[n] - 1) + mod;
    return dp[n][k] = res % mod;
}
int main(){
      ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0);
       int n,k;
         cin>>n>>k;
        ll b[n+1]={0};
        for(int i=1; i<=n; i++)
         { cin>>b[i];  
			  }
			 
       memset(dp,-1,sizeof(dp));
         cout<<solve(b,n,k); 
         //   cout<<n<<" "<<k<<endl;
    }


Measured memory_bytes: 94080
#include <stdio.h>

void bubbleSort(int A[],int N){
  int i,flg=1;
  int count=0;
  int tmp;
  while(flg){
    flg=0;
    for(i=N-1;i>=1;i--){
      if(A[i]<A[i-1]){
	tmp=A[i-1];
	A[i-1]=A[i];
	A[i]=tmp;
	flg=1;
	count++;
      }
    }
  }
  for(i=0;i<N;i++){
    printf("%d",A[i]);
    if(i!=N-1) printf(" ");
  }
  printf("\n%d\n",count);
}

int main(void){
  int i,n;
  scanf("%d",&n);
  int a[n];
  for(i=0;i<n;i++) scanf("%d",&a[i]);
  bubbleSort(a,n);
  return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(ll i = (begin); i < (end); i++)
#define rep(i, n) FOR(i, 0, n)
using ll = long long;
using namespace std;
#define all(x) (x).begin(),(x).end()
using pii = pair<int, int>; using vi = vector<int>; using vl = vector<ll>;

signed main() {
    int x;
    cin >> x;
    int glad;
    glad = x / 500 * 1000;
    x = x % 500;
    glad += x / 5 * 5;
    cout << glad;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,ax[200],ay[200],bx[200],by[200],i,j;
bool bpm(bool bpGraph[200][200], int u, bool seen[], int matchR[])
{
    for (int v = 0; v < n; v++)
    {
        if (bpGraph[u][v] && !seen[v])
        {
            seen[v] = true;
            if (matchR[v] < 0 || bpm(bpGraph, matchR[v], seen, matchR))
            {
                matchR[v] = u;
                return true;
            }
        }
    }
    return false;
}
int maxBPM(bool bpGraph[200][200])
{
    int matchR[n];
    memset(matchR, -1, sizeof(matchR));
    int result = 0;
    for (int u = 0; u < n; u++)
    {
        bool seen[n];
        memset(seen, 0, sizeof(seen));
        if (bpm(bpGraph, u, seen, matchR))
            result++;
    }
    return result;
}
int main()
{
    std::cin.sync_with_stdio(false);
    std::cin.tie(0);
    cin >> n;
    i=0;
    while (i<n)
    {
        cin >> ax[i] >> ay[i];
        i++;
    }
    i=0;
    while (i<n)
    {
        cin >> bx[i] >> by[i];
        i++;
    }
    bool bpGraph[200][200];
    i=0;
    while (i<n)
    {
        j=0;
        while (j<n)
        {
            if (ax[i]<bx[j]&&ay[i]<by[j])
            {
                bpGraph[i][j]=1;
            }
            j++;
        }
        i++;
    }
    cout << maxBPM(bpGraph);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

void Counting_Sort (vector<int> a, vector<int> & b, int k )
{
	vector<int> c(k+1, 0 );
	for (int j = 0; j < a.size(); j++ ){
		c[a[j]]++;
		/* c[i] には i の出現数が記録されている */
	} // end for
	for (int i = 1; i <= k; i++ ){
		c[i] += c[i-1];
		/* c[i] には i 以下の数の出現数が記録されている */
	} // end for
	for (int j = a.size() - 1; j >= 0; j-- ){
		b[c[a[j]]] = a[j];
		c[a[j]]--;
	} // end for		
}

int main()
{
	ios_base::sync_with_stdio(0);
	int n; cin >> n;
	vector<int> a (n, 0 ), b(n + 1, 0 );
	int k = 0;
	rep (i, n ) cin >> a[i], k = max (k, a[i] );

	Counting_Sort (a, b, k );
	for (int i = 1; i <= n; i++ ) cout << b[i] << ( i != n ? ' ' : '\n' );
		
	return 0;
}

Measured memory_bytes: 24648
#[macro_export]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
      n: i32
  }
  
  let h = n / 3600;
  let m = n % 3600 / 60;
  let s = n % 60;
  
 println!("{}:{}:{}", h, m, s);
}


Measured memory_bytes: 5036
require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)

a.uniq!
m = a.min
while a.size > 1
  m = a.min
  a.size.times do |i|
    a[i] %= m #=
  end
  a.uniq!
  a.delete(0)
  a.push(m)
  # p a
end

puts m

Measured memory_bytes: 16204
import java.math.BigInteger;
import java.util.Scanner;

@SuppressWarnings({"unused", "WeakerAccess"})
public class Main {
    // 最大公約数
    long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    // 階乗(n!)
    BigInteger fact(BigInteger n, BigInteger ans) {
        if(n.compareTo(BigInteger.ONE) < 1) return ans;
        return fact(n.subtract(BigInteger.ONE), ans.multiply(n));
    }

    // フィボナッチ数
    BigInteger fib(BigInteger n, BigInteger a, BigInteger b) {
        if(n.equals(BigInteger.ONE)) return a;
        return fib(n.subtract(BigInteger.ONE), b, a.add(b));
    }

    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();

        int now = 1;
        int count = 0;
        while (now < b) {
            now = now + a - 1;
            count++;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 22612
N, K = map(int, input().split())
As = map(int, input().split())
numbers = {}
for A in As:
    if numbers.get(A):
        numbers[A] += 1
    else:
        numbers[A] = 1

sorted_count = sorted(numbers.values(), reverse=True)
print(sum(sorted_count[K:]))

Measured memory_bytes: 41116
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 17 11:58:20 2019
DP_G
@author: maezawa
"""
import sys
sys.setrecursionlimit(10**6)

memo = [-1] * (10**5+100)

def rec(nx):
    if memo[nx] > -1:
        return memo[nx]
    depth = 0
    for edge in edges[nx]:
        nrec = rec(edge) + 1
        if nrec > depth:
            depth = nrec
    memo[nx] = depth
    return depth

n, m = list(map(int, input().split()))
edges = [[] for _ in range(n)]
for _ in range(m):
    x, y = list(map(int, input().split()))
    edges[x-1].append(y-1)
    
maxdepth = 0
for node in range(n):
    depth = rec(node)
    if maxdepth < depth:
        maxdepth = depth
        
print(maxdepth)


Measured memory_bytes: 65200
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9

typedef long long ll;


int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int a[200000];

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int a, int b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

int main() {
	int n;
	char s[101];
	int select[26] = { 0 };
	int cnt;
	int max = 0;

	scanf("%d", &n);
	scanf("%s", s);

	REPS(i, n) {
		cnt = 0;
		m0(select);
		REP(j, n) {
			if (j < i) {
				if (select[s[j] - 'a'] == 0)select[s[j] - 'a']++;
			}
			else {
				if (select[s[j] - 'a'] == 1)cnt++;
				select[s[j] - 'a']+=2;
			}
		}
		//PRINTD(cnt);
		if (max < cnt)max = cnt;
	}
	PRINTD(max);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using edge = struct { int to; ll cost; };
using graph = vector<vector<edge>>;

bool operator < (const edge &e, const edge &f) {
  return ( e.cost != f.cost ) ? e.cost > f.cost : e.to < f.to;
}

const ll INF = 1e18;

graph G;
vector<ll> d;

void dijkstra(int s) {
  int N = G.size();
  priority_queue<edge> pq;
  d.assign(N, INF);
  d[s] = 0;
  pq.push({s, 0});
  while (!pq.empty()) {
    edge e = pq.top(); pq.pop();
    int u = e.to;
    if (d[u] < e.cost) continue;
    for (auto&& v : G[u]) {
      if (d[v.to] > d[u] + v.cost) {
        d[v.to] = d[u] + v.cost;
        pq.push({v.to, d[v.to]});
      }
    }
  }
}

main() {
  int N; cin >> N;
  G.resize(N);
  for (int i = 0; i < N - 1; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    G[a].push_back({b, c});
    G[b].push_back({a, c});
  }
  int Q, K; cin >> Q >> K;
  dijkstra(--K);
  vector<int> x(Q), y(Q);
  for (int i = 0; i < Q; i++) {
    cin >> x[i] >> y[i];
    x[i]--; y[i]--;
  }
  for (int i = 0; i < Q; i++) cout << d[x[i]] + d[y[i]] << endl;
}


Measured memory_bytes: 11120
text = input().split()
dic = dict(zip(text,[0 for i in range(len(text))]))
for i in text:
	dic[i] = dic[i] + 1
max_ = max(dic.values())
for key,value in dic.items():
	if value == max_:
		most = key
max_ = 0
for i in dic.keys():
	if len(i) > max_:
		max_ = len(i)
		amax_ = i
print(most, amax_)




Measured memory_bytes: 5572
#include<bits/stdc++.h>
using namespace std;
#define maxn 1005
struct node{
	int to;
	int id;
	node(int a,int b){
		to=a;
		id=b;
	}
	node(){}
};
int n,m;
int tot;
int vis[maxn];
int bh[maxn][maxn][3];
vector<node> e[maxn];
int u[maxn*maxn*2];
int v[maxn*maxn*2];
void dfs(int root,int fa,int b,int f){
	vis[root]=tot;
	bh[fa][root][f]=b;
	int len=e[root].size();
	for(int i=0;i<len;i++){
		if(vis[e[root][i].to]!=tot)
		dfs(e[root][i].to,fa,b,f);
	}
}
void s(int now){
	tot++;
	vis[now]=tot;
	int len=e[now].size();
//	cout<<now<<" "<<len<<endl; 
	for(int i=0;i<len;i++){
		if(vis[e[now][i].to]!=tot)
		dfs(e[now][i].to,now,e[now][i].id,0);
	}
	reverse(e[now].begin(),e[now].end());
	tot++;
	vis[now]=tot;
//	int len=e[now].size();
	for(int i=0;i<len;i++){
		if(vis[e[now][i].to]!=tot)
		dfs(e[now][i].to,now,e[now][i].id,1);
	}	
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&u[i],&v[i]);
		e[u[i]].push_back(node(v[i],i));
	}
	for(int i=1;i<=n;i++){
		s(i);
	}
	for(int i=1;i<=m;i++){
		if((bh[u[i]][v[i]][0]!=i||bh[u[i]][v[i]][1]!=i) ^ 0 ^ (bh[v[i]][u[i]][0]!=0)){
			puts("diff");
		}
		else{
			puts("same");
		}
	}
}

Measured memory_bytes: 22272
#include <iostream>
#include <string>
using namespace std;
 
int findsum(int n){
  int sum = 0;
  while(n>0){
    sum += n % 10;
    n/=10;
  }
  return sum;
}

int main() {
  int N,a,b;
  cin >> N >> a >> b;
  int total = 0;
  for(int i=1;i<=N;++i){
    int sum=findsum(i);
    if(sum >= a & sum <= b){
      total += i;
    }
  }
  cout << total << endl;
}

Measured memory_bytes: 3604
#include<iostream>
#include<cstdio>

using namespace std;
int main(){
    int W,H,N;
    cin>>W>>H>>N;
    int x[N],y[N],a[N];
    for(int i=0;i<N;++i)cin>>x[i]>>y[i]>>a[i];

    int x_min,x_max,y_min,y_max;
    x_min=0,x_max=W,y_min=0,y_max=H;
    
        for(int i=0;i<N;++i){
            switch (a[i])
            {
            case 1:
                if(x[i]>x_min)x_min=x[i];
                break;
            case 2:
                if(x[i]<x_max)x_max=x[i];
                break;
            case 3:
                if(y[i]>y_min)y_min=y[i];
                break;
            case 4:
                if(y[i]<y_max)y_max=y[i];
                break;
            
            }
        }
    if(x_min>x_max||y_min>y_max){
        cout<<"0";
    }else{
        cout<<(x_max-x_min)*(y_max-y_min);
    }

}


Measured memory_bytes: 3156
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

string s[100];
int f[101][101] = {0};

int getsum(int t, int l, int b, int r){
  return f[b][r] - f[b][l] - f[t][r] + f[t][l];
}
signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int3(n, m, d);
    rep(i, n)cin >> s[i];
    rep(i, n)rep(j, m)if(s[i][j] == '#')f[i + 1][j + 1]++;

    rep(i, n + 1)rep(j, m)f[i][j + 1] += f[i][j];
    rep(j, m + 1)rep(i, n)f[i + 1][j] += f[i][j];

    int res = 0;
    rep(i, n)rep(j, m - d + 1)if(getsum(i, j, i + 1, j + d) == 0)++res;
    rep(j, m)rep(i, n - d + 1)if(getsum(i, j, i + d, j + 1) == 0)++res;

    pri(res);

/*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 3292