akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int dm = 1 << 21;
char dn[dm], * di = dn;
inline void putint(int X) {
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

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


	int N = getint();
	int X[200000];
	rep(i, N) X[i] = getint();
	
	int L = 0;
	int R = 1e9 + 1;
	while (L < R) {
		int H = (L + R) / 2;
		int k = 0;
		rep(i, N) k += X[i] <= H;
		if (k < N / 2) L = H + 1;
		else R = H;
	}
	int L2 = L;
	int R2 = 1e9 + 1;
	while (L2 < R2) {
		int H = (L2 + R2) / 2;
		int k = 0;
		rep(i, N) k += X[i] <= H;
		if (k < N / 2 + 1) L2 = H + 1;
		else R2 = H;
	}
	int K = L;
	int keta1 = 0, keta2 = 0;
	char C1[10], C2[10];
	while (L) {
		*(C1 + keta1) = '0' + L % 10;
		L /= 10;
		keta1++;
	}
	while (L2) {
		*(C2 + keta2) = '0' + L2 % 10;
		L2 /= 10;
		keta2++;
	}

	rep(i, N) {
		if (X[i] > K) {
			for (int i = keta1 - 1; i >= 0; i--)* di++ = (*(C1 + i));
			*di++ = '\n';
		}
		else {
			for (int i = keta2 - 1; i >= 0; i--)* di++ = (*(C2 + i));
			*di++ = '\n';
		}
	}

	fwrite_unlocked(dn, di - dn, 1, stdout);

	Would you please return 0;
}

Measured memory_bytes: 5120
import os
import sys
from collections import defaultdict
adj = defaultdict(list)
col = defaultdict(int)
sys.setrecursionlimit(1000000)
mx=0
edges = {}
def find_color(u , p):
	global mx , now
	cnt =0
	for i in adj[u]:
		cnt = cnt+1
		if i==p:
			continue
		find_color(i , u)
	mx = max(mx, cnt)
now =0
def dfs(u , p, prev):
	global mx, now
	for i in adj[u]:
		if i==p:
			continue
		if now == prev:
			now = (now+1)%mx
		col[edges[i,u]]=now
		now =(now+1)%mx
	for i in adj[u]:
		if i==p:
			continue
		dfs(i , u, col[edges[i, u]])

def main():
	n = int(input())
	for i in range(n-1):
		x, y = map(int , input().split())
		adj[x].append((y))
		adj[y].append((x))
		edges[x,y]=i
		edges[y,x]=i
	find_color(1, 0)
	dfs(1, 0,-1)
	print(mx)
	for i in range(n-1):
		print(col[i]+1)


if __name__ == "__main__":
	main()

Measured memory_bytes: 176904
package main

import "fmt"

func main() {
	var H, W int
	fmt.Scanf("%d %d", &H, &W)

	c := make([]string, H)
	for i := 0; i < H; i++ {
		fmt.Scan(&c[i])
	}

	for _, cc := range c {
		fmt.Println(cc)
		fmt.Println(cc)
	}
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define SUM(n) ((n)+1)*(n)/2
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = (1e9)+7;
 
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

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

  int n;
  cin >> n;
  int a[105];
  rep(i,n){
    cin >> a[i];
  }
  rep(i,n){
    if(a[i]%2==0){
      if(a[i]%3!=0 && a[i]%5!=0){
	  cout<<"DENIED\n";

	return 0;
      }
    }
  }
  cout<<"APPROVED\n";
  return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
import numpy as np
def main():
    n, *a = map(int, read().split())

    p = np.array(a)
    minp = np.minimum.accumulate(p)
    r = np.count_nonzero(minp >= p)
    print(r)

if __name__ == '__main__':
    main()

Measured memory_bytes: 50372
#include<cstdio>
#include<iostream>
#include<cmath>
#define MIN -1000000000
using namespace std;

int main()
{
	int n;
	int A[200000];
	cin >> n;
	for(int i=0;i<n;++i)
	{
		cin >> A[i];
	}
	int min = A[0],max_ans= MIN;
	for (int i = 1; i < n; ++i)
	{
		max_ans = fmax(max_ans, A[i] - min);
		min = fmin(min, A[i]);
	}
	printf("%d\n", max_ans);
	return 0;
}

Measured memory_bytes: 3936
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;

int A, B, C;
int main() {
    cin >> A >> B >> C;
    string ans = "No";
    if (A + B >= C) {
        ans = "Yes";
    }

    cout << ans << endl;
}

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

template <typename T> T gcd(T x, T y) { return( y ? gcd(y, x % y) : x); }
template <typename T> T lcm(T x, T y) { return( x / gcd(x, y) * y); }
template <typename T> void printVec(vector<T> &vec) {
  cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    cout << *it << " ";
  }
  cout << endl;
}

int main() {
  int x[5];

  for (int i = 0; i < 5; i++) {
    cin >> x[i];
    if (x[i] == 0) {
      cout << (i + 1) << endl;
      return 0;
    }
  }
  
	return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;cin>>s;
    if(s=="hi"||s=="hihi"||s=="hihihi"||s=="hihihihi"||s=="hihihihihi")cout<<"Yes";
    else cout<<"No";
    return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;

ll Csum[310000];

int main(){
    int N;
    string S;
    cin >> N >> S;
 
    for(int i = 1; i <= N; i++){
        if(S[i - 1] == 'E'){
            Csum[i] = Csum[i - 1] + 1;
        }else{
            Csum[i] = Csum[i - 1];
        }
        
    }
    
    int ans = N;

    for(int i = 1; i <= N; i++){
        int cnt = (i - 1 - Csum[i - 1]) + (Csum[N] - Csum[i]);
        ans = min(ans, cnt);
    }
 
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3076
import sys

sys.setrecursionlimit(10**9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return [int(x) for x in input().split()]
MOD = 10**9 + 7

N = INT()
A = LIST()
B = LIST()

kill = 0

for i in range(N):
    if A[i] >= B[i]:
        kill += B[i]
    else:
        kill += A[i]
        B[i] -= A[i]
        if A[i+1] < B[i]:
            kill += A[i+1]
            A[i+1] = 0
        else:
            kill += B[i]
            A[i+1] -= B[i]

print(kill)


Measured memory_bytes: 18624
// https://atcoder.jp/contests/abc069/tasks/arc080_a

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

ll N, a, t, f, o;
string r;

int main()
{
  o = f = 0;
  cin >> N;
  REP(i, N)
  {
    cin >> a;
    if (a % 4 == 0)
      f++;
    else if (a % 2 == 0)
      t++;
    else
      o++;
  }

  r = min(o, f) == N / 2 || o <= f ? "Yes" : "No";

  cout << r << '\n';

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  i32 *dp = ALLOC (n + 1, i32);
  dp[0] = 1000000000 + 1;
  i32 len = 0;
  for (i32 i = 0; i < n; ++i) {
    i32 a;
    scanf ("%" SCNi32, &a);
    if (dp[len] >= a) {
      dp[++len] = a;
      continue;
    }
    i32 l = 0;
    i32 r = len;
    while (r - l > 1) {
      i32 m = (l + r) / 2;
      if (dp[m] >= a) {
        l = m;
      } else {
        r = m;
      }
    }
    dp[r] = a;
  }
  printf ("%" PRIi32 "\n", len);
}

int main (void) {
  run();
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  int a[n][26]={};
  for(int i=0;i<n;i++){
    string s;
    cin >> s;
    for(int j=0;j<s.length();j++){
      a[i][s[j]-'a']++;
    }
    if(i>0){
      for(int j=0;j<26;j++){
        a[i][j]=min(a[i-1][j],a[i][j]);
      }
    }
  }
  for(int i=0;i<26;i++){
    for(int j=0;j<a[n-1][i];j++){
      char c='a'+i;
      cout << c;
    }
  }
}



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

ls = [['.' for _ in range(w+2)] for _ in range(h+2)]
for i in range(1,h+1):
  ls[i][1:w+1]=input()

for h in range(1,h+1):
    for w in range(1,w+1):
        if (ls[h][w]=='#'):
            continue
        c = 0
        for x in range(-1,2):
            for y in range(-1,2):
                if (x==0 and y==0):
                    continue
                elif (ls[h+x][w+y]=='#'):
                    c+=1
        ls[h][w]=str(c)
    else:
        print(''.join(ls[h][1:w+1]))

Measured memory_bytes: 3188
#include <stdio.h>
#define INF 1000000
#define white 0
#define black 2
#define gray 1

int n,M[100][100];

void dijkstra();

int main(){
  int i,j,k,c,v,u;
  scanf("%d",&n);
  for(i=0;i<n;i++){ 
    for(j=0;j<n;j++){
      M[i][j]=INF;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&v,&c);
      M[u][v]=c;
    }
  }
  dijkstra();
  
  return 0;
}
void dijkstra(){
  int i,d[100],mincost,color[100],v,u;
  for(i=0;i<n;i++){
    d[i]=INF;
    color[i]=white;
  }
  d[0]=0;
  color[0]=gray;

  while(1){
    mincost=INF;
    u=-1;
    for(i=0;i<n;i++){
      if(color[i]!=black&&d[i]<mincost){
	mincost=d[i];
	u=i;
      }
    }
    if(u==-1)break;
    
    color[u]=black;
    for(v=0;v<n;v++){
      if(color[v]!=black&&M[u][v]!=INF){
	if(d[v]>d[u]+M[u][v]){
	  d[v]=d[u]+M[u][v];
	  color[v]=gray;
	}
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d ",i);
    if(d[i]==INF)printf("-1");
    else printf("%d",d[i]);
    printf("\n");
  }
}



Measured memory_bytes: 2604
import java.util.Arrays;
import java.util.Scanner;

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

        int N = sc.nextInt();
        int[] A = new int[N + 1];
        for (int i = 0; i < A.length; ++i) {
            A[i] = sc.nextInt();
        }
        int[] B = new int[N];
        for (int i = 0; i < B.length; ++i) {
            B[i] = sc.nextInt();
        }

        System.out.println(solve(A, B));

        sc.close();
    }

    static long solve(int[] A, int[] B) {
        B = Arrays.copyOf(B, B.length + 1);

        long result = 0;
        int extraB = 0;
        for (int i = 0; i < A.length; ++i) {
            int defeatNum = Math.min(A[i], B[i] + extraB);

            result += defeatNum;
            extraB = Math.min(B[i], B[i] + extraB - defeatNum);
        }

        return result;
    }
}

Measured memory_bytes: 60408
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int INF = 1e9;
int a[8];
int mp[201][201];
int d[8][201];

int main() {
  int n, m, r;
  cin >> n >> m >> r;
  for (int i = 0; i < r; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < r; i++) {
    for (int j = 0; j <= n; j++) {
      d[i][j] = INF;
    }
  }
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    mp[a][b] = mp[b][a] = c;
  }
  for (int i = 0; i < r; i++) {
    int bg = a[i];
    priority_queue<P> que;
    d[i][bg] = 0;
    que.push(P(0, bg));
    while (!que.empty()) {
      P tp = que.top();
      que.pop();
      if (tp.first > d[i][tp.second]) continue;
      for (int j = 1; j <= n; j++) {
        if (mp[tp.second][j] != 0) {
          if (d[i][tp.second] + mp[tp.second][j] < d[i][j]) {
            d[i][j] = d[i][tp.second] + mp[tp.second][j];
            que.push(P(d[i][j], j));
          }
        }
      }
    }
  }
  /*
  for (int i = 0; i < r; i++) {
    for (int j = 1; j <= n; j++) {
      cout << d[i][j] << " ";
    }
    cout << endl;
  }
  */
  vector<int> b;
  for (int i = 0; i < r; i++) b.push_back(i);
  int ans = INF;
  do{
    int tmp = 0;
    for (int i = 1; i < b.size(); i++) {
      tmp += d[b[i - 1]][a[b[i]]];
    }
    ans = min(ans, tmp);
  } while (next_permutation(b.begin(), b.end()));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
x = int(input())

if x < 600:
    print(8)
    
elif x < 800:
    print(7)

elif x < 1000:
    print(6)
    
elif x < 1200:
    print(5)
    
elif x < 1400:
    print(4)
    
elif x < 1600:
    print(3)
    
elif x < 1800:
    print(2)
    
else:
    print(1)

Measured memory_bytes: 9176
from heapq import heappush, heappop


def main():
    X, Y, _, _, _ = map(int, input().split())

    P = []
    Q = []
    R = []
    for v in input().split():
        heappush(P, -int(v))
    for v in input().split():
        heappush(Q, -int(v))
    for v in input().split():
        heappush(R, -int(v))

    score = 0
    cp = 0
    cq = 0
    cr = 0

    XY = X + Y

    while len(P) > 0 and len(Q) > 0 and len(R) > 0 and cp < X and cq < Y and cp + cq + cr < XY:
        p = -P[0]
        q = -Q[0]
        r = -R[0]
        if r > p and r > q:
            score -= heappop(R)
            cr += 1
        elif p > q:
            score -= heappop(P)
            cp += 1
        else:
            score -= heappop(Q)
            cq += 1

    while len(P) > 0 and len(R) > 0 and cp < X and cp + cq + cr < XY:
        p = -P[0]
        r = -R[0]
        if p >= r:
            score -= heappop(P)
            cp += 1
        else:
            score -= heappop(R)
            cr += 1

    while len(Q) > 0 and len(R) > 0 and cq < Y and cp + cq + cr < XY:
        q = -Q[0]
        r = -R[0]
        if q >= r:
            score -= heappop(Q)
            cq += 1
        else:
            score -= heappop(R)
            cr += 1

    while len(P) > 0 and len(Q) > 0 and cp < X and cq < Y and cp + cq + cr < XY:
        p = -P[0]
        q = -Q[0]
        if p > q:
            score -= heappop(P)
            cp += 1
        else:
            score -= heappop(Q)
            cq += 1

    while cp < X and cp + cq + cr < XY:
        if len(P) > 0:
            score -= heappop(P)
            cp += 1
        else:
            score -= heappop(R)
            cr += 1

    while cq < Y and cp + cq + cr < XY:
        if len(Q) > 0:
            score -= heappop(Q)
            cq += 1
        else:
            score -= heappop(R)
            cr += 1

    print(score)


main()


Measured memory_bytes: 23232
def main():
    h, w = map(int, input().split())
    s = [["" for _ in range(w + 2)]]
    for _ in range(h):
        s.append([""] + list(input()) + [""])
    s.append(s[0])
    f = False
    for i in range(1, h + 1):
        if f:
            break
        for j in range(1, w + 1):
            if s[i][j] == "#":
                if not any(s[i + di][j + dj] == "#" for di, dj in [[0, 1], [1, 0], [0, -1], [-1, 0]]):
                    print("No")
                    f = True
                    break
    if not f:
        print("Yes")


if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use itertools_num::ItertoolsNum;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::iter;
#[allow(unused_imports)]
use superslice::*;

fn run() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let a = sc.read_vec::<usize>(n);

    let mut maxs = vec![0; n + 1];
    for i in 0..n {
        maxs[i + 1] = cmp::max(maxs[i], a[i]);
    }
    let ans = a
        .into_iter()
        .skip(1)
        .zip(maxs.into_iter().skip(2))
        .map(|(x, y)| y - x)
        .sum::<usize>();
    println!("{}", ans);
}

fn main() {
    std::thread::Builder::new()
        .name("run".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(run)
        .unwrap()
        .join()
        .unwrap();
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn read_pairs<T: std::str::FromStr>(&mut self, n: usize) -> Vec<(T, T)> {
        (0..n).map(|_| (self.read(), self.read())).collect()
    }
    pub fn read_pairs_1_indexed(&mut self, n: usize) -> Vec<(usize, usize)> {
        (0..n)
            .map(|_| (self.read::<usize>() - 1, self.read::<usize>() - 1))
            .collect()
    }
    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    pub fn read_char_grid(&mut self, n: usize) -> Vec<Vec<char>> {
        (0..n).map(|_| self.read_chars()).collect()
    }
    pub fn read_matrix<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n)
            .map(|_| (0..m).map(|_| self.read()).collect())
            .collect()
    }
}


Measured memory_bytes: 3984
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int num;
         int n;
     int ans[200010]={0};

   cin>>n;
    for(int i=2; i<=n; i++)
    {
        scanf("%d",&num);

        ans[num]++;
    }
    for(int i=1; i<=n; i++)
    {
        printf("%d\n",ans[i]);
    }
}


Measured memory_bytes: 4568
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

int main() {
  i64 n, q;
  while(cin >> n >> q, n) {
    vector<i64> vec(200);
    rep(i,0,n) {
      i64 m;
      cin >> m;
      rep(j,0,m) {
        i64 a;
        cin >> a;
        vec[a]++;
      }
    }
    pair<i64, i64> ans = {0, 0};

    rep(i,0,200) {
      if(vec[i] >= q) {
        ans = max(ans, pair<i64, i64>(vec[i], -i));
      }
    }
    cout << -ans.second << endl;
  }
}



Measured memory_bytes: 3096
/* ex9_2
   nabe9393 */

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define SIZE 100001
//キュー内の各データの定義
typedef struct node{
  int elem;
  struct node *next;
}node;

//データを追加
void push(node **first, char elem){
  //追加する分の領域を確保
  node *new = calloc(1, sizeof(node));
  if(new == NULL) exit(1);
  new->elem = elem;
  //追加
  new->next = *first;
  *first = new;
}
 
//スタックからデータを取り出す
char pop(node **first){
  char elem;
  node *tmp = *first;
  if(tmp == NULL) exit(1);
  elem = tmp->elem;
  *first = tmp->next;
  //取り出したノードのメモリを解放
  free(tmp);
}
 
 
int main(void){
  //最終的な答え
  int count=0, i;
  char cube[SIZE];
  //ノードの先頭
  node *first=NULL;
  scanf("%s",cube);

  for(i=0;i<strlen(cube);i++){
    if(first==NULL || cube[i]==first->elem){
      //スタックにノードを追加
      push(&first,cube[i]);
    }
    else{
      //スタックからデータを取り出す
      pop(&first);
      //2追加
      count=count+2;
    }
  }
  //答えの出力
  printf("%d\n",count);
  return 0;
}


Measured memory_bytes: 4840
import java.util.*;
class Main{
  public static void main(String[]args){
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    if(a%10==3) System.out.printf("bon");
    else if(a%10==0 || a%10==1 || a%10==6 || a%10==8) System.out.printf("pon");
    else System.out.printf("hon");
  }
}

Measured memory_bytes: 27088
{-# LANGUAGE MultiWayIf #-}

main :: IO ()
main = do
  n <- read <$> getLine :: IO Int
  as <- map read.words <$> getLine :: IO [Int]
  let l4 = length $ filter (\a -> a`mod`4==0) as
      lo = length $ filter odd as
      le = n - l4 - lo
  putStrLn $ if | lo <= l4 -> "Yes"
                | (lo - l4)==1 && le==0 -> "Yes"
                | otherwise -> "No"


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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL<<60;
const ll mod = 1000000007;		

int main() {

	string s;
	cin >> s;

	VLL v(26, 0);

	ll n = s.size();

	REP(i, n) {
		v[s[i] - 'a']++;
	}
	
	ll ans = 0;

	REP(i, 26) {
		ans += v[i] * (n - v[i]);
	}

	ans = ans / 2 + 1;

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main{
    public static void main(String arg[]){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int count;
        int[] str=new int[10000000];//A,C,G,T
        for(int i=0;i<n;i++){
            count=0;
            String a=sc.next();
            String b=sc.next();
            for(int j=0;j<b.length();j++){
                if(b.charAt(j)=='A')count+=1*Math.pow(5,j);
                else if(b.charAt(j)=='C')count+=2*Math.pow(5,j);
                else if(b.charAt(j)=='G')count+=3*Math.pow(5,j);
                else count+=4*Math.pow(5,j);
            }
            if(a.equals("insert")){
                str[count]++;
            }else{
                if(str[count]==0)System.out.println("no");
                else System.out.println("yes");
            }
        }
        sc.close();
    }
}


Measured memory_bytes: 198312
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

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(void) {
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    int slen = (int) S.size();

    vector<int> acc(slen, 0);
    {
        for (int i = 1; i < slen; i++) {
            acc[i] = acc[i - 1];
            if (S[i - 1] == 'A' && S[i] == 'C') {
                acc[i]++;
            }
        }
    }

    for (int i = 0; i < Q; i++) {
        int l, r;
        cin >> l >> r;
        l--;
        r--;
        cout << acc[r] - acc[l] << endl;
    }

    return 0;
}


Measured memory_bytes: 1408
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;

#define rp(i,t) for(int i=0;i<(t);i++)
#define rep(i,s,t) for(int i=(s);i<=(t);i++)
#define rsp(i,s,t) for(int i=(s);i<(t);i++)
#define rrp(i,t,s) for(int i=(t);i>=(s);i--)
#define rcp(i,s,b,d) for(int i=(s);b;d)
#define rgp(i,x) for(int i=h[x];i;i=e[i].t)
#define mst(a,x) memset(a,x,sizeof(a))
#define INF 0x3f3f3f3f
#define N 52
#define E 102

#define Dp puts("")
#define Dw printf
#define Ds printf("#")

typedef long long ll;
struct Edge{int y,t;}e[E];
char ch;
int n,m,x,y,h[N],ep=1,dfn[N],low[N],tm,ans;

inline void read(int &x){x=0;do{ch=getchar();}while(ch<'0'||'9'<ch);do{x=x*10+ch-'0';ch=getchar();}while('0'<=ch&&ch<='9');}
inline void addedge(const int &x,const int &y){e[++ep].y=y;e[ep].t=h[x];h[x]=ep;}

void tarjan(const int &x)
{
	dfn[x]=low[x]=++tm;
	rgp(i,x)if(!dfn[e[i].y])
	{
		e[i^1].y=0;
		tarjan(e[i].y);
		low[x]=min(low[x],low[e[i].y]);
		if(dfn[x]<low[e[i].y])ans++;
	}else low[x]=min(low[x],dfn[e[i].y]);
}

int main(void)
{
	read(n),read(m);
	rep(i,1,m)read(x),read(y),addedge(x,y),addedge(y,x);
	dfn[0]=INF;
	tarjan(1);
	printf("%d",ans);
	return 0;
}


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

int main()
{
    int n, l;
    cin >> n >> l;
    int a;
    if(l < 0 && l + n - 1 < 0) a = 1;
    else if(l < 0 && l + n - 1 >= 0) a = 2;
    else if(l >= 0 && l + n - 1 >= 0) a = 3;

    int ans = 0;

    if(a == 1){
        for(int i = 0; i < n - 1; i++){
            ans += l + i;
        }
    }else if(a == 2){
        for(int i = 0; i < n; i++){
            ans += l + i;
        }
    }else if(a == 3){
        for(int i = 1; i < n; i++){
            ans += l + i;
        }
    }

    cout << ans << endl;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0)
#define mapmax(v) v.rbegin()->first
#define mapmin(v) v.begin()->first
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<string> vs;

typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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;}

void YES(bool b) {cout << (b?"YES\n":"NO\n");}
void Yes(bool b) {cout << (b?"Yes\n":"No\n");}
void yes(bool b) {cout << (b?"yes\n":"no\n");}
void Yay(bool b) {cout << (b?"Yay!\n":":(\n");}

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,k;
	double ans=0.0;
	cin >> n >> k;
	vd p(n),tmp(n+1);
	rep(i,n){
		cin >> p[i];
		p[i]=(p[i]+1)/2;
	}
	tmp[0]=0;
	rep(i,n){
		tmp[i+1]=p[i];
		tmp[i+1]+=tmp[i];
	}
	rep(i,n-k+1){
		chmax(ans,tmp[i+k]-tmp[i]);
	}
	cout << DOUBLE << ans << endl;
	return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <string>
#include <cstring>
#include <cctype>
#include <ctime>
#include <climits>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <tuple>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <complex>
#include <random>
#include <cassert>
#include <chrono>
#include <cstdint>
#include <functional>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#ifndef M_PI
#define M_PI 3.141592653589793238462643383279
#endif

#define int long long

#define mp make_pair
#define mt make_tuple
#define fr first
#define sc second
#define pb push_back
#define pp pop_back
#define all(x) x.begin(), x.end()
#define get0 get<0>
#define get1 get<1>
#define get2 get<2>
#define get3 get<3>

#define debug(x) cerr << #x << " = " << x << ", line = " << __LINE__ << endl

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef tuple<long long, long long, long long> tlll;
typedef tuple<int, int, int> tiii;
typedef tuple<int, int, int, int> tiiii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MOD = 1e9 + 7;



int32_t main()
{
#ifdef chikibambony
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int j = 0; j < n; ++j) {
        cin >> b[j];
    }
    reverse(all(b));
    int c = -1;
    for (int i = 0; i < n; ++i) {
        if (a[i] == b[i]) {
            c = a[i];
            break;
        }
    }
    int l = 0;
    for (int i = 0; i < n; ++i) {
        if (a[i] == c && b[i] == c) {
            l = i;
            break;
        }
    }
    int r = -1;
    for (int i = n - 1; i >= 0; --i) {
        if (a[i] == c && b[i] == c) {
            r = i;
            break;
        }
    }

    for (int i = 0; i < n; ++i) {
        if (a[i] != c && b[i] != c && l <= r) {
            swap(b[i], b[l]);
            ++l;
        }
    }

    if (l <= r) {
        cout << "No\n";
        return 0;
    }

    cout << "Yes\n";

    for (int i = 0; i < n; ++i) {
        cout << b[i] << ' ';
        assert(b[i] != a[i]);
    }
    cout << "\n";

    return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i=0; i < N; i++){
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    auto n = unique(A.begin(), A.end());
    if (n == A.end()){
        cout << "YES" << endl;
    } else{
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int a, b;
  cin >> a >> b;

  int ans = (a - 1) * (b - 1);

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;



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

	if (n % 2 == 1) {
		cout << n * 2 << endl;
		return 0;
	}
	else {
		cout << n << endl;
		return 0;
	}
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count=0
for c1 in range(0,c+1):
    for b1 in range(0,b+1):
        for a1 in range(0,a+1):
            if a1*500+b1*100+c1*50==x:
                count=count+1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

signed main() {
  INIT;
  VAR(string,s);
  bool ok = s[0]==s[1] || s[1]==s[2] || s[2]==s[3];
  OUT((ok?"Bad":"Good"))BR;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<vector>

using namespace std;

int W,H;

int g[7][7];
int cg[7][7];
int ly,lx;

bool inside(int y,int x){
  return 0<=y&&y<H&&0<=x&&x<W;
}

bool neighbor(int y,int x){
  return abs(y-ly)+abs(x-lx)==1;
}
  
void ff(int y,int x){
  if(inside(y,x)&&cg[y][x]==0){
    for(int i=0;i<4;i++){
      cg[y][x]=1;
      ff(y+(~i&i-1),x+(i?2-i:0));
    }
  }
}

bool dfs(int y,int x,int r){
  if(r==1)return neighbor(y,x);
  g[y][x]=1;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(g[i][j]==0){
	copy(g[0],g[7],cg[0]);
	ff(i,j);
	for(int k=0;k<H;k++){
	  for(int l=0;l<W;l++){
	    if(cg[k][l]==0){
	      goto fail;
	    }
	  }
	}
	for(int i=0;i<4;i++){
	  int ny=y+(~i&i-1);
	  int nx=x+(i?2-i:0);
	  if(inside(ny,nx)&&g[ny][nx]==0){
	    for(int j=0;j<4;j++){
	      if(i==j)continue;
	      int oy=y+(~j&j-1);
	      int ox=x+(j?2-j:0);
	      if(inside(oy,ox)&&g[oy][ox]==0&&!neighbor(oy,ox)){
		int c=0;
		for(int k=0;k<4;k++){
		  int ony=oy+(~k&k-1);
		  int onx=ox+(k?2-k:0);
		  c+=inside(ony,onx)&&g[ony][onx]==0;
		}
		if(c<2)goto next;
	      }
	    }
	    if(dfs(ny,nx,r-1))return true;
	  next:
	    ;
	  }
	}
	goto fail;
      }
    }
  }
 fail:
  g[y][x]=0;
  return false;
}
    

int main(){
  while(cin>>W>>H,W){
    int c=0;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	cin>>g[i][j];
	if(g[i][j]==0){
	  ly=i;
	  lx=j;
	  c++;
	}
      }
    }
    cout<<((c&&dfs(ly,lx,c))?"Yes":"No")<<endl;
  }
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define INF 0x7fffffff
#define LL_INF 0x7fffffffffffffff
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

int main(void)
{
	int n, m; cin >> n >> m;
	if(n % 2 == 1) {
		for(int i=1;i<=m;i++) {
			cout << i << " " << n + 1 - i << endl;
		}
	}
	else {
		for(int i=1;i<=m;i++) {
			if(i % 2 == 1) {
				cout << (i + 1) / 2 << " " << n + 1 - (i + 1) / 2 << endl;
			}
			else {
				cout << n / 2 - (i / 2) << " " << n / 2 + (i / 2) << endl;
			}
		}
	}



	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

string s[51];

int h, w;
int dy[4] = {1, -1, 0, 0};
int dx[4] = {0, 0, 1, -1};
bool contain(int y, int x){
   return (0 <= y && y < h && 0 <= x && x < w);
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> h >> w;
    rep(i, 0, h) cin >> s[i];
    bool f = true;
    rep(i, 0, h){
        rep(j, 0, w){
            if(s[i][j] == '.') continue; 
            int cnt = 0;
            rep(k, 0, 4){
                int ny = i + dy[k];
                int nx = j + dx[k];
                if(!contain(ny, nx)) continue;
                if(s[ny][nx] == '#') cnt++;
            }
            if(cnt == 0) f = false;
        }
    }
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//for(int i = 0; i < n; i++)
 
int main() {
  int n, a, p;
  cin >> a >> p;
  vector<int> w(n);
  /*for(int i = 0; i < n; i++) {
    cin >> w.at(i);
    s += w.at(i);
  }
  for(int i = 0; i < n; i++){
    ss += w.at(i);
    if(ss * 2 < s) ;
    else if(ss * 2 == s) break;
    else {
      ans = min(abs(ss * 2 - s), abs((ss - w.at(i)) * 2 - s));
      break;
    }
  }*/
  cout << (a * 3 + p) / 2 << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
struct abc {
	int aa, bb, cc;
	bool operator < (const abc&T) const {
		return(aa < T.aa || (aa == T.aa && bb < T.bb) || (aa == T.aa && bb == T.bb && cc < T.cc));
	}
	bool operator == (const abc&T) const {
		return(aa == T.aa && bb == T.bb);
	}
} ans[200005];
using namespace std;
int N, KK, LL, i, j, k, l, m, n, pt1[200005], pt2[200005], s1[200005], s2[200005], z;
int sz[200005], ans2[200005];
int find1(int aa) {
	if(pt1[aa] != aa) 
		pt1[aa] = find1(pt1[aa]);
	return(pt1[aa]);
}
int find2(int bb) {
	if(pt2[bb] != bb) 
		pt2[bb] = find2(pt2[bb]);
	return(pt2[bb]);
}
int main() {
	scanf("%d%d%d", &N, &KK, &LL);
	for(i = 1; i <= N; i++) {
		pt1[i] = i;
		pt2[i] = i;
		s1[i] = 1;
		s2[i] = 1;
	}
	for(i = 0; i < KK; i++) {
		scanf("%d%d", &j, &l);
		if(find1(j) == find1(l)) continue;
		s1[find1(l)] += s1[find1(j)];
		pt1[find1(j)] = find1(l);
	}
	
	for(i = 0; i < LL; i++) {
		scanf("%d%d", &j, &l);
		if(find2(j) == find2(l)) continue;
		s2[find2(l)] += s2[find2(j)];
		pt2[find2(j)] = find2(l);
	}
	for(i = 1; i <= N; i++) {
		pt1[i] = find1(i);
		pt2[i] = find2(i);
		ans[i].aa = pt1[i];
		ans[i].bb = pt2[i];
		ans[i].cc = i;
	}
//	for(i = 1; i <= N; i++) printf("%d %d\n", pt1[i], pt2[i]);
	
	sort(ans + 1, ans + N + 1);
	sz[1] = 1;
	for(i = 2; i <= N; i++) if(ans[i] == ans[i - 1]) {
		sz[i] = sz[i - 1] + 1;
	} else {
		sz[i] = 1;
	}
	for(i = N - 1; i >= 1; i--) 
	if(ans[i] == ans[i + 1]) sz[i] = sz[i + 1];
	
	//for(i = 1; i <= N; i++) printf("%d %d %d %d\n", ans[i].aa, ans[i].bb, ans[i].cc, sz[i]);
	
	for(i = 1; i <= N; i++) ans2[ans[i].cc] = sz[i];
	
	for(i = 1; i < N; i++) printf("%d ", ans2[i]);
	printf("%d\n", ans2[N]);
}

Measured memory_bytes: 7808
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
struct UnionFind{
  vector<int> par;
  vector<int> sizes;
  UnionFind(int n) : par(n), sizes(n, 1) {
    rep(i,n) par[i] = i;
  }
  int root(int x) {
    if (x == par[x]) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (sizes[x] < sizes[y]) swap(x, y);
    par[y] = x;
    sizes[x] += sizes[y];
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int size(int x) {
    return sizes[root(x)];
  }
};
int main(){
	int N;
	char S[203][203];
	scan(N);
	UnionFind uf(N*2);
	rep(i,N){
		scan(S[i]);
		for(int j=i+1;j<N;j++){
			if(S[i][j]=='1'){
				uf.unite(i,j+N);
				uf.unite(i+N,j);
			}
		}
	}
	bool bipartite = true;
	rep(i,N){
		if(uf.same(i,N+i)) bipartite = false;
	}
	int A[203][203];
	fill(A[0],A[203],INF);
	rep(i,N) A[i][i]=0;
	rep(i,N){
		rep(j,N){
			if(S[i][j]=='1'){
				A[i][j]=1;
			}
		}
	}
	if(bipartite){
		rep(k,N){
			rep(i,N){
				rep(j,N){
					if(k==i||k==j) continue;
					if(A[i][j]>A[i][k]+A[k][j]) A[i][j]=A[i][k]+A[k][j];
				}//添字の順番はWikipedia通りにやってまふ
			}
		}
		int dmax=0;
		rep(i,N) rep(j,N) if(A[i][j]<INF) dmax=max(dmax,A[i][j]);
		prin(dmax+1);
	}
	else{
		prin(-1);
	}
	return 0;
}


Measured memory_bytes: 512
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)*}
    };
}

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, 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")
    };
}

fn dfs(u: usize, n: usize, adj: &Vec<Vec<usize>>, visited: &mut Vec<bool>) -> usize {
    let mut flg = true;
    for b in visited.iter() {
        if !*b {
            flg = false;
        }
    }
    if flg {
        return 1;
    }

    let mut ret = 0;
    for v in adj[u].iter() {
        if visited[*v] {
            continue;
        }
        visited[*v] = true;
        ret += dfs(*v, n, adj, visited);
        visited[*v] = false;
    }
    return ret;
}

fn main() {
    input!{
        n: usize,
        m: usize,
        edges: [(usize1, usize1); m]
    }
    let mut adj = vec![vec![]; n];
    for e in edges {
        adj[e.0].push(e.1);
        adj[e.1].push(e.0);
    }
    let mut visited = vec![false; n];
    visited[0] = true;
    println!("{}", dfs(0, n, &adj, &mut visited));
}


Measured memory_bytes: 4352
#include<math.h>
#include<time.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
int main()
{
	int a,b,c,i,sum=0;
	scanf("%d %d %d",&a,&b,&c);
	for(i=a;i<=b;i++)
		if(c%i==0)
			sum++;
	printf("%d\n",sum);
	return 0;
}


Measured memory_bytes: 2120
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 11 17:09:47 2020

@author: sd18016
"""   

import sys

W, H, N = map(int, input().split())
list_x = []

for i in range(N):
    x = list(map(int, input().split()))
    list_x.append(x)
    
O = [0,0]
MU = [W, H]

for i in range(N):
    if list_x[i][2] == 1:
        if list_x[i][0] > O[0]:
            O[0] = list_x[i][0]
    elif list_x[i][2] == 2:
        if list_x[i][0] < MU[0]:
            MU[0] = list_x[i][0]
    elif list_x[i][2] == 3:
        if list_x[i][1] > O[1]:
            O[1] = list_x[i][1]
    elif list_x[i][2] == 4:
        if list_x[i][1] < MU[1]:
            MU[1] = list_x[i][1]
            
W_ans = MU[0]-O[0]
H_ans = MU[1]-O[1]

if W_ans <0 or H_ans<0:
    print("0")
else:
    ans = W_ans*H_ans
    print(ans)
            



"""
for i in range(N):
    if list_x[i][2] == 1:
        de = list_x[i][0]
        S -= de*H
        W -= de
    elif list_x[i][2] == 2:
        de = W - list_x[i][0]
        S -= de*H
        W -= de
    elif list_x[i][2] == 3:
        de = list_x[i][1]
        S -= de*W
        H -= de
    else:
        de = H - list_x[i][1]
        S -= de*W
        H -= de

print(S)
"""

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define erep(i, n) for (int i = 0; i <= (n); i++)
#define erep1(i, n) for (int i = 1; i <= (n); i++)
using namespace std;
using ll = long long;


int main() {
    int n;
    cin >> n;
    ll x = 1;
    erep1(i, n) {
        x *= i;
        if (x > 1000000007){
            x %= 1000000007;
            continue;
        }
    }
    cout << x << endl;
}

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

int main() {
  int N,K,X,x;
  cin>>N>>K;
  X=0;
  for(int i=0;i<N;i++){
    cin>>x;
    if(x<=K/2){
      X+=x;
    }
    else{
      X+=(K-x);
    }
  }
    cout<<2*X<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main() {
    char str[200];
    char ans[200];
    int i, j;
    i = j = 0;
    scanf("%[^\n\r]", str);
    ans[j++] = str[0];
    for (i = 1; str[i - 1] != ' '; i++) {
    }
    ans[1] = str[i];
    printf("A%cC\n", ans[1]);
    return 0;
}

Measured memory_bytes: 128
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class Read>void in(Read &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
ll n,k,a[1000005];
ll check(ll mid){
	ll sum=0;
	for(int i=0;i<n;i++){
		if(a[i]==0){
			if(mid>=0)sum+=n-1;
			continue;
		}
		if(a[i]<0){
			ll tot=mid/a[i];
			if(tot*a[i]>mid)tot++;
			int id=lower_bound(a,a+n,tot)-a;
			sum+=n-id;
			if(id<=i)sum--;
		}
		else{
			ll tot=mid/a[i];
			if(tot*a[i]>mid)tot--;
			int id=upper_bound(a,a+n,tot)-a-1;
			if(id<0)continue;
			sum+=id+1;
			if(id>=i)sum--;
		}
	}
	return sum/2;
}
int main(){
	in(n);in(k);
	for(int i=0;i<n;i++)in(a[i]);
	sort(a,a+n);
	ll lo=-1e18,hi=1e18;
	while(lo<hi){
		ll mid=lo+(hi-lo)/2;
		if(check(mid)>=k)hi=mid;
		else lo=mid+1;
	}
	cout<<lo<<endl;
	return 0;
}


Measured memory_bytes: 1792
def main():
    h, w, k = map(int, input().split())
    c = []
    for i in range(h):
        c.append(list(input()))

    ans = 0
    for i in range(2**h):
        for j in range(2**w):
            count = 0
            for ii in range(h):
                for jj in range(w):
                    if not (i >> ii & 1 or j >> jj & 1) and c[ii][jj] == "#":
                        count += 1
            if count == k:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 74076