akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(); //number of member
        int m = sc.nextInt(); //number of relationship 
        int m_x = 0;
        ArrayList<Set<Integer>> list = new ArrayList<Set<Integer>>();
        Queue<Integer> que = new ArrayDeque<>();
        for(int i=0;i<=n;i++){
            Set<Integer> set = new HashSet<Integer>();
            list.add(set);  //n+1回配列を作っておく
        }
        for(int i=0;i<m;i++){
            int a = sc.nextInt();
            int b = sc.nextInt();
            list.get(a).add(b);
            list.get(b).add(a);
        }
        
        Monmo momo = new Monmo(n);
        
        for(int i=1;i<=n;i++){
            int count=1;
            //if(!list.get(i))
            if(momo.belong(i))continue;
            for(int j : list.get(i)){
                que.add(j);
                momo.belong(j);
            }
            while(que.peek() != null){
                //System.out.println(que);
                int back_que = que.poll();
                count++;
                //System.out.println(back_que + " count:" + count);
                for(int j : list.get(back_que)){
                    if(momo.belong(j)){}
                    else que.add(j);
                }
            }
            //System.out.printf("%n");
            if(m_x<count)m_x=count;
        //momo.shutu();
        }
        System.out.println(m_x);
    }
}

class Monmo {
    ArrayList<Integer> guru = new ArrayList<Integer>();
    
    Monmo(int n){
        for(int i=0;i<=n;i++){
            guru.add(0); //属するナンバー格納用
        }
    }
    boolean belong(int g){
        if(guru.get(g) != 0){
            return true;
        }else{
            guru.set(g,1);
            return false;
        }
    }
    void shutu(){
        System.out.println(guru);
    }
}


Measured memory_bytes: 128840
import copy
import sys
a = [int(i) for i in list(input())]

op = ['+', '-']
cmb = [[]]
for i in range(3): #op1-3
    tmp = len(cmb)
    for i in range(tmp):
        cmb.append(copy.deepcopy(cmb[i]))
    for j in range(2):
        for k in range(j * tmp, (j + 1) * tmp):
            cmb[k].append(op[j])

#print(cmb)

for i in range(len(cmb)):
    _sum = a[0]
    for j in range(1, 4):
        if cmb[i][j-1] == '+':
            _sum += a[j]
        else:
            _sum -= a[j]
    #print(cmb[i], _sum)
    if _sum == 7:
        ans = str(a[0])
        for j in range(1, 4):
            ans += cmb[i][j-1] + str(a[j])
        ans += '=7'
        print(ans)
        sys.exit()

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()
#define chmax(x,y) x=max(x,y)




int main(){
    string s; cin>>s;
    vector<int> p(4);
    rep(i,4) p[i]=s[i]-'0';
    rep(i,1<<3){
        int kari=p[0];
        rep(j,3){
            if(i>>j&1){
                kari+=p[j+1];
            }else{
                kari-=p[j+1];
            }
        }
        if(kari==7){
            string ans;
            ans+=s[0];
            rep(j,3){
                if(i>>j&1){
                    ans+='+';
                    ans+=s[j+1];
                }else{
                    ans+='-';
                    ans+=s[j+1];
                }
            }
            ans+="=7";
            cout<<ans<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 3624
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons, std.functional;

void main() {
    auto tmp = readln.split.to!(int[]);
    iota(tmp[0], tmp[1]+1).filter!(i => i.to!string.pipe!(str => str.length.iota.all!(j => str[j] == str[$-j-1]))).walkLength.writeln;
}



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

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(vi a(5);cin>>a[0],a[0];){
		repi(i,1,5) cin>>a[i];
		int flg=0;
		rep(i,5)
			flg|=1<<(a[i]-1);
		if(flg==7 || __builtin_popcount(flg)==1)
			rep(i,5) cout<<3<<endl;
		else if(flg==3)
			rep(i,5) cout<<(a[i]==1?1:2)<<endl;
		else if(flg==5)
			rep(i,5) cout<<(a[i]==3?1:2)<<endl;
		else if(flg==6)
			rep(i,5) cout<<(a[i]==2?1:2)<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int s = sc.nextInt();
        final long mod = 1000000007;
        //s個の〇に仕切りを入れて数列を作る
        //dp[i]はi番目を最後に仕切りを入れる場合の数
        long dp[] = new long [s + 1];
        dp[0] = 1;
        
        for(int i = 1; i < s + 1; i++){
            for(int j = 0; j < i - 3 + 1; j++){
                dp[i] += dp[j];
                dp[i] %= mod;
            }
        }
        //正解を出力
        System.out.println(dp[s]);
    }
}


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

#define int long long
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()

const int mod = 1e9+7;
const int inf = 2e18;

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

	int n,k;
	cin>>n>>k;
	int a[n+4];

	for (int i = 1; i<=n; ++i)
	{
		cin>>a[i];
	}	


	int pos = 1;
	int inics = 0;
	int cs;
	if(pos==a[pos])
	{
		cout<<1<<'\n';
		return 0;
	}

	vector<bool> mp(n+2,false);

	int start_point;

	int tot_size = 0;

	vector<int> res;
	//res.pb(-1);

	while(1)
	{	
		if(mp[pos]==true)
		{
			start_point = pos;break;
		}
		mp[pos] = true;	
		res.pb(pos);
		tot_size++;
		pos = a[pos];
	}

	int posi = 1;
	//vector<bool> vis(n+2,false);
	int dist = 0;
	//int cs = 0;
	while(1)
	{	
		if(posi==start_point)
		{
			break;
		}
		dist++;
		posi = a[posi];
	}
	
	cs = tot_size-dist;
	// cout<<cs<<'\n';
	// for(int i:res)
	// {
	// 	cout<<i<<" ";
	// }
	// cout<<'\n';

	if(k<=dist)
	{
		cout<<res[k]<<'\n';
	}
	else
	{
	int len = res.size();
	cout<<res[dist+(k-dist)%cs]<<'\n';
	}
	return 0;
}	

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

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

    int n;
    cin>>n;
    int a[n];
    bool allzero=true;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]!=0) allzero=false;
    }
    bool pos=true;
    if(allzero){
        cout<<"Yes"<<endl;
        return 0;
    }
    if(n%3){
        cout<<"No"<<endl;
        return 0;
    }

    sort(a,a+n);
    int b=a[0],c=a[n-1];
    if(b!=0){
        int t=-1;
        int cnt1=0,cnt2=0,cnt3=0;
        if(c==b) pos=false;
        bool el=false;
        for(int i=0;i<n;i++){
            if(a[i]==b) cnt1++;
            else if(a[i]==c) cnt2++;
            else if(t==-1) {
                t=a[i];
                cnt3++;
            }
            else if(a[i]==t) cnt3++;
            else el=true;
        }
        if(el) pos=false;
        if(cnt1!=n/3 || cnt2!=n/3 || cnt3!=n/3) pos=false;
        if(b!=(c^t)) pos=false;
    }   
    else {
        int cntzero=0,cnt=0;
        for(int i=0;i<n;i++){
            if(a[i]==b) cntzero++;
            else if(a[i]==c) cnt++;
            else pos=false;
        }
        if(cnt!=2*n/3 || cntzero!=(n/3)) pos=false;
    } 
    if(pos) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
}

Measured memory_bytes: 640
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String A = sc.next();
		String B = sc.next();
		String S = sc.next();
		if(S.matches("[0-9]{"+A+"}-[0-9]{"+B+"}")) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		sc.close();
	}
}


Measured memory_bytes: 22740
n = gets.to_i

# (1..n).to_a.permutation(n).each_with_object({}) { |nums, hash|
#   hash[nums] = nums.each.with_index.inject(0) { |result, (num, i)| result + (i + 1) % num }
# }

puts (n - 1) * n / 2


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

#define ll long long
#define ld long double
#define pi 3.14159265359

int main(){
    int N; cin >> N;
    vector<ll> A(N + 1), B(N);
    ll cnt = 0, Bv = 0;
    for (int i = 0; i < N + 1; i++) {
        cin >> A.at(i);
    }
    for (int i = 0; i < N; i++) {
        cin >> B.at(i);
    }
    for (int i = 0; i < N; i++) {
        if (Bv == 0) {
            if (A.at(i) >= B.at(i)) {
                cnt += B.at(i);
                Bv = 0;
            }
            else {
                cnt += A.at(i);
                Bv = B.at(i) - A.at(i);
            }
        }
        else {
            if (A.at(i) >= Bv) {
                cnt += Bv;
                A.at(i) -= Bv;
                if (A.at(i) >= B.at(i)) {
                cnt += B.at(i);
                Bv = 0;
                }
                else {
                    cnt += A.at(i);
                    Bv = B.at(i) - A.at(i);
                }
            }
            else {
                cnt += A.at(i);
                Bv = B.at(i);
            }
        }
    }
    if (Bv > 0) {
        if (A.at(N) > Bv) {
            cnt += Bv;
        }
        else {
            cnt += A.at(N);
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 1920
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner input = new Scanner(System.in);
        String line = input.nextLine();
        String[] array = line.split("");

        int ans = 0;

        for(int i = 0; i < 4; i++){
        	if(array[i].equals("+")){
        		ans++;
        	}else if(array[i].equals("-")){
        		ans--;
        	}
        }
        System.out.println(ans);
	}

}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};




int main(){
    vector<int> a(3,0);
    int p,q;cin >> p >> q;
    a[p-1]++,a[q-1]++;
    for (int i = 0; i < 3; i++) {
        if(!a[i]){
            cout << i+1 << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
N, M = gets.split(" ").map(&:to_i)

maxL = 1
minR = N
M.times do
  l, r = gets.split(" ").map(&:to_i)
  maxL = [maxL, l].max
  minR = [minR, r].min
end

puts [0, (minR - maxL + 1)].max


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

int main(){
    char c;
    cin >> c;
    char ans = c+1;
    cout << ans << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include<iostream>
#include<string>

#define rep(i, b) for(int i = 0; i < b; i++)

using namespace std;

int main(){
	string flic;
	cin >> flic;

	rep(i, flic.size()){
		bool nflag = false;
		switch((int)(flic[i] - '0')){
			case 1:
				break;
			case 2:
				cout << 'k';
				break;
			case 3:
				cout << 's';
				break;
			case 4:
				cout << 't';
				break;
			case 5:
				cout << 'n';
				break;
			case 6:
				cout << 'h';
				break;
			case 7:
				cout << 'm';
				break;
			case 8:
				cout << 'y';
				break;
			case 9:
				cout << 'r';
				break;
			case 0:
				if(flic[i+1] == 'U'){
					cout << 'n';
					nflag = true;
				}else cout << 'w';
		}
		i++;
		if(nflag) cout << 'n';
		else{
			if(flic[i] == 'T') cout << 'a';
			else if(flic[i] == 'L') cout << 'i';
			else if(flic[i] == 'U') cout << 'u';
			else if(flic[i] == 'R') cout << 'e';
			else if(flic[i] == 'D') cout << 'o';
		}
	}
	cout << endl;
}

Measured memory_bytes: 1176
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
    
    static FastScanner sc = new FastScanner();
    static PrintWriter pw = new PrintWriter(System.out);
    
    public static void main(String args[]) {
        int n = sc.nextInt();
        pw.println((int)Math.pow(n,3));
        pw.flush();
    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte()) return buffer[ptr++];
            else return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
            return hasNextByte();
        }

        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}



Measured memory_bytes: 20820
N = int(input())
pair = dict()
ans = 0
for a in range(2, int(N**(1/2))):
    if N % a != 0:
        continue
    ex = 0
    while N % a == 0:
        ex += 1
        N = N//a
    pair[a] = ex
if N != 1:
    pair[N] = 1
for k in pair.values():
    i = 1
    while k >= i:
        ans += 1
        k -= i
        i += 1
print(ans)


Measured memory_bytes: 9460
#include <bits/stdc++.h>
using namespace std;
void print(vector<int> v) {
  for (size_t i = 0; i < v.size(); i++) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}
int main() {
  int n;
  cin >> n;
  vector<int> a;
  for (int i = 1; i <= n; i++) a.push_back(i);
  do {
    print(a);
  } while (next_permutation(a.begin(), a.end()));
  return 0;
}


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

public class Main {
  static String[] result = new String[] {
    "YYMM", "MMYY", "AMBIGUOUS", "NA" 
  };
  
  static int type(int s) {
    if (0 <= s && s <= 99) {
      if (1 <= s && s <= 12) {
        return 1; // M
      }
      return 0; // Y
    }
    throw new RuntimeException();
  }

  public static void main(String ... args) throws Exception {
    int n = 0, k = 0;
    String s;
    try (BufferedReader isr = new BufferedReader(new InputStreamReader(System.in))) {
      String buf = isr.readLine();
      System.err.println(buf);
      /*
      String[] input = buf.split(" ");
      n = Integer.parseInt(input[0]);
      k = Integer.parseInt(input[1]);
      buf = isr.readLine();
      System.err.println(buf);
      */
      s = buf;
    }

    String s1 = s.substring(0,2);
    String s2 = s.substring(2,4);
    int l = type(Integer.parseInt(s1));
    int r = type(Integer.parseInt(s2));
    System.err.println(l);
    System.err.println(r);

    int res = 0;
    if ((l & r) == 1) {
      res = 2;
    } 
    if ((l | r) == 0) {
      res = 3;
    }
    if ((l ^ r) == 1) {
      if (l == 1) {
        res = 1;
      } else {
        res = 0;
      }
    }
    System.out.println(result[res]);
  }

}


Measured memory_bytes: 21076
#include <stdio.h>

int main(void){
	int n;
	scanf("%d", &n);
	int *a = malloc(sizeof(int) * n)
		, *b = malloc(sizeof(int) * n)
		, *c = malloc(sizeof(int) * n);
	for(int i = 0; i < n; i++)
		scanf("%d", a + i);
	for(int i = 0; i < n; i++)
		scanf("%d", b + i);
	for(int i = 0; i < n - 1; i++)
		scanf("%d", c + i);
	int sum = 0;
	for(int i = 0; i < n; i++)
		sum += b[a[i] - 1];
	for(int i = 0; i < n - 1; i++)
		if(a[i] + 1 == a[i + 1])sum += c[a[i] - 1];
	printf("%d\n", sum);
	return 0;
}


Measured memory_bytes: 2152
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1000000000
#define  pow(x) pow(10,(x)) 
typedef long long int LL;
const int MOD = 1000000007;
//sort(all(x))とするとソートできるよ

int main(){
    LL L,R;cin >> L >> R;
    if(R-L >= 2019){
        cout << 0 << endl;
    }
    else{
        LL mi = 2018;
        LL r;
        LL l;
        rep(i,R-L){
            l = (L + i) % 2019;
            for(int j = i+1;j <= R-L;j++){
                r = (L + j) % 2019;
                mi = min(mi,(l * r) % 2019);
            }
        }
        cout << mi << endl;
    }
}

Measured memory_bytes: 256
import sys
import numpy as np
#import math
# for AtCoder
import fractions
from collections import deque 
from functools import reduce

def lcm_base(x, y):
    return (x * y // fractions.gcd(x, y))

def lcm_list(numbers_list):
    return reduce(lcm_base, numbers_list, 1)

# N 
n = int(input())

# a1 . . . an
a = list(map(int, input().split()))

lcm_1 = lcm_list(a) - 1
m = np.mod(lcm_1, a)
print(m.sum())


Measured memory_bytes: 15240
N = int(input())
W = []
for i in range(N):
    W.append(list(input()))

cnt = 0

for i in range(1, N):
    if W[i][0] != W[i - 1][-1]:
        cnt = 1

W.sort()
for i in range(1, N):
    if W[i] == W[i - 1]:
        cnt = 1

if cnt == 1:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 3060
n=int(input())
a=list(map(int,input().split()))
if a[0]!=0:
    if n==0 and a[0]==1:
        print(1)
    else:
        print(-1)
    exit()
l=[[] for _ in range(n+1)]
l[0]=[1,1]
l[n]=[a[n],a[n]]
for i in reversed(range(1,n)):
    if l[i+1][0]%2==1:
        l[i]=[l[i+1][0]//2+a[i]+1,l[i+1][1]+a[i]]
    else:
        l[i]=[l[i+1][0]//2+a[i],l[i+1][1]+a[i]]
ans=[0]*(n+1)
ans[0]=1
for i in range(1,n+1):
    if ans[i-1]*2>=l[i][0]:
        ans[i]=min((ans[i-1]-a[i-1])*2,l[i][1])
    else:
        print(-1)
        exit()
print(sum(ans))


Measured memory_bytes: 33328
#include <bits/stdc++.h>
using namespace std;
int n, m;
const int N = 200000;
int vis[N], inp[N];
int path[N], fs, top;
vector <int> bi[N];
int main()
{
    cin >> n >> m;
    for (int i = 1; i <= m; ++ i)
    {
        int a, b;
        cin >> a >> b;
        bi[a].push_back(b);
        bi[b].push_back(a);
    }

    fs = 1;
    while (fs)
    {
        path[++ top] = fs; inp[fs] = 1;
        int nx = 0;
        for (int i = 0; i < bi[fs].size(); ++ i)
            if (!inp[bi[fs][i]]) {nx = bi[fs][i]; break;}
        fs = nx;
    }

    int md = top;
    fs = 1;
    while (fs)
    {
        path[++ top] = fs; inp[fs] = 1;
        int nx = 0;
        for (int i = 0; i < bi[fs].size(); ++ i)
            if (!inp[bi[fs][i]]) {nx = bi[fs][i]; break;}
        fs = nx;
    }

    cout << top - 1 << "\n";
    for (int i = md; i >= 2; -- i) cout << path[i] << " ";
    for (int i = md + 1; i <= top; ++ i) cout << path[i] << " ";
}


Measured memory_bytes: 10112
#include<iostream>
#include<map>
#include<string>
using namespace std;int main(){int n,m,p;string s,t;for(;cin>>n,n;){map<string,int>P;for(;n--;cin>>P[s])cin>>s;for(cin>>n;n--;){cin>>s>>m;for(p=0;m--;p+=P[t])cin>>t;P[s]=min(P[s],p);}cin>>s;cout<<P[s]<<endl;}}

Measured memory_bytes: 0
n = int(input())
day, choco = map(int,input().split())
P = [int(input()) for _ in range(n)]
ans = choco + n
for i in range(n):
    p = day // P[i]
    if day % P[i] == 0:
        p -= 1
    if p > 0:
        ans += p
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main() {
  int n; cin >> n;
  vi arr(n);
  rep(i,n) {
    cin >> arr[i];
    --arr[i];
  }

  int ans = 0;
  rep(i,n) {
    if (arr[i] == i) {
      ++ans;
      ++i;
    }
  }

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


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main()
{
    int n=0;
    cin>>n;
    int v[n];
    int c[n];
    int temp;
    int sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    for(int i2=0;i2<n;i2++)
    {
        cin>>c[i2];
    }
    for(int i3=0;i3<n;i3++)
    {
        temp=v[i3]-c[i3];
        if(temp>0)
        {
            sum+=temp;
        }
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 256
//Author rahuliitkgp
/*A thing of beauty is a joy forever,
Its loveliness increases,
it will never pass into nothingness.*/
//Men at Work :)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;

#define ff              first
#define ss              second
#define SZ(x)           ((int)(x).size())
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void cpp() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int main() {
	cpp();
	string s, t;
	cin >> s >> t;
	vector<vector<ll> > dp(s.size() + 1, vector<ll>(t.size() + 1, 0));
	for (int i = 1; i <= s.size(); i++) {
		for (int j = 1; j <= t.size(); j++) {
			if (s[i - 1] == t[j - 1]) {
				dp[i][j] = dp[i - 1][j - 1] + 1;
			}
			else {
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	}
	int i = s.size();
	int j = t.size();
	string ans;
	while (i > 0 && j > 0) {
		if (s[i - 1] == t[j - 1]) {
			ans += s[i - 1];
			i--;
			j--;
		}
		else if (dp[i - 1][j] > dp[i][j - 1]) i--;
		else j--;
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
	return 0;
}





Measured memory_bytes: 70784
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  long long int s=0;
  for(int i=0;i<n-1;i++){
    if(a[i]>a[i+1])
    {
        s=s+abs(a[i+1]-a[i]);
        a[i+1]=a[i];
    }
  }
  cout<<s;
}


Measured memory_bytes: 4392
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a,x,b) (a<=x && x<=b)
#define WS std::cout<<" ";
#define NL std::cout<<"\n"
#define OUT(dist) std::cout<<(dist);
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;



int main(){
    INIT;
    int a, b; cin >> a >> b;
    REP(k,std::max(a,b)+1) {
        if(abs(a-k) == abs(b-k)) { cout << k; return 0;}
    }
    cout << "IMPOSSIBLE";
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair <int, int>
#define sz(a) (int)(a.size()) 
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)

using namespace std;

void Fast_Read_Out()
{
	// for fast read and out cin/cout
	ios_base::sync_with_stdio(0);
	cin.tie(), cout.tie();
}

void Random()
{
	// it is srand(time(0)), but a little bit better
	unsigned int seed;
	asm("rdtsc" : "=A" (seed));
	srand(seed);        
}

unsigned int Time()
{
	 unsigned int time = clock() / 1000.00;
	 return time;
}

const int inf = int(1e9) + 123;

int main ()
{
	#ifdef JUDGE
		freopen("input.txt", "r", stdin);
	#endif 
	Random();
	Fast_Read_Out();
	// code begins here
	int n, a;
	cin >> n >> a;
	if(n % 500 > a) cout << "No";
	else cout << "Yes";
	// program execution time
	#ifdef JUDGE
//		cout << Time() << endl;
	#endif
}

Measured memory_bytes: 256
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

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, 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 main() {
    input!{
        o: chars,
        e: chars,
    }
    for i in 0..e.len() {
        print!("{}{}", o[i], e[i])
    }
    if o.len() > e.len() {
        print!("{}", o.last().unwrap())
    }
    println!();
}


Measured memory_bytes: 4352
A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())
dist = V-W
if A < B:
    if A+V*T >= B+W*T:
        print('YES')
    else:
        print('NO')
else:
    if A-V*T <= B - W*T:
        print('YES')
    else:
        print('NO')

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

int main() {
    int a,b;
    cin >> a >> b;
    int d = b-a;
    int B = (d+1)*d/2;
    cout << B - b << endl;
}


Measured memory_bytes: 256
#include<iostream>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<algorithm>
    #include<string>
    using namespace std;
    #define INF 10000000;
     
    int main() {
        int N,T,A;
        int findID;
        double memo,min = INF;
        cin >> N >> T >> A;
        vector<int> H(N);
        vector<int> copy(N);

        for(int i=0;i<N;i++)cin >> H[i];
        for(int i=0;i<N;i++){
            memo = T-H[i]*0.006-A;
            if(memo<0)memo *=-1;
            if(min > memo){
                min = memo;
                findID = i+1;

            }
        }
        
        cout << findID <<endl;
        
    }

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

int main(void) {
  ll N;
  cin >> N;
  ll A[1LL << 18];
  REP(i, 0, 1LL << N) scanf("%lld", A + i);

  ll ans = 0;
  REP(k, 1, 1LL << N) {
    ll p = 0, q = 0;
    ll i = k;
    do {
      ll w = max({ p, q, A[i] });
      q = p + q + A[i] - w - min({ p, q, A[i] });
      p = w;
      i = (i - 1) & k;
    } while(i != k);
    ans = max(ans, p + q);
    printf("%lld\n", ans);
  }
}

Measured memory_bytes: 5120
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 100000001;
ll t[100010][50];
const ll mod = 1000000007;
void Reconciled() {
	
	int n,m;
	cin >> n >> m;
	ll res = 0;
	if (abs(n - m) > 1) {
		cout << 0 << endl;
		return;
	}
	int p;
	if (n == m) {
		p = 2;
	}
	else {
		p = 1;
	}

	ll np = 1;
	ll mp = 1;
	int mx = max(n, m);
	for (int i = 2; i <= mx; i++)
	{
		if (i == mx && n != m) {
			np *= i;
			np %= mod;
		}
		else {
			np *= i;
			np %= mod;
			mp *= i;
			mp %= mod;
		}
	}

	res = (np * mp) % mod;
	res *= p;
	res %= mod;
	cout << res << endl;

}

int main() {
	Reconciled();

	return 0;
}



Measured memory_bytes: 256
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] winp = new int[n];
		for(int i=0;i<n;i++)winp[i]=0;		
		for(int i=0;i<(n*(n-1)/2);i++){
			int t1 = sc.nextInt();
			int t2 = sc.nextInt();
			int p1 = sc.nextInt();
			int p2 = sc.nextInt();
			if(p1 > p2){
				winp[t1-1] += 3;
			}else if(p1 < p2){
				winp[t2-1] += 3;
			}else{
				winp[t1-1] ++;
				winp[t2-1] ++;
			}
		}
		int[] rnk = new int[winp.length];
		for(int i=0;i<rnk.length;i++){
			int cnt = 1;
			for(int j=0;j<rnk.length;j++){
				if(winp[i]<winp[j]){
					cnt++;
				}
			}
			rnk[i] = cnt++;
		}
		for(int i=0;i<n;i++){
			System.out.println(rnk[i]);
		}
	}
}	

Measured memory_bytes: 41932
#include <iostream> 
#include <cstdio> 
#include <fstream> 
#include <algorithm> 
#include <cmath> 
#include <deque> 
#include <vector> 
#include <queue> 
#include <string> 
#include <cstring> 
#include <map> 
#include <stack> 
#include <set> 
typedef  long long ll;
const int  maxn = 110000;
const int mod = 1000000007;
using namespace std;
int n, m,ans;
struct node
{
	int time, v;
}a[maxn];
bool cmp(node a, node b)
{
	return a.time > b.time;
}
priority_queue<int,vector<int>,greater<int> >p;
int main()
{
	cin >> n>>m;
	for (int i = 1; i <= n; i++)
	{
		scanf("%d %d", &a[i].time, &a[i].v);
	}
	sort(a + 1, a + 1 + n, cmp);
	for (int i = 1; i <= n; i++)
	{
		if (a[i].time <= m - p.size())
		{
			p.push(a[i].v);
		}
		else
		{
			int t = p.top();
			if (a[i].time <= m - p.size() + 1&&p.size())
			{
				if (a[i].v > t)
				{
					p.pop();
					p.push(a[i].v);
				}
			}
		}
	}
	while (p.size())
	{
		ans += p.top();
		p.pop();
	}
	printf("%d", ans);
}


Measured memory_bytes: 1660
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;

#define INF 1e+9
#define MAX_V 300

struct edge {
    int to;
    int cost;
};
using P = pair<ll, ll>;
int main(){
  int n;cin>>n;
  vector<pair<ll,ll>> ball(n);
  for(int i=0;i<n;i++){
    ll x,y;cin>>x>>y;
    ball[i]=make_pair(x,y);
  }
  sort(ball.begin(),ball.end());
  /*
  for(int i=0;i<n;i++){
    cout<<ball[i].first<<" "<<ball[i].second<<endl;
  }
  */
  ll min=50;
  if(n==1){cout<<1<<endl;return 0;}
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      ll d_x=ball[j].first-ball[i].first;
      ll d_y=ball[j].second-ball[i].second;
      vector<bool> seen(n,false);
      int ow=0;
      seen[ow]=true;
      int count=1;
      int seen_num=1;
      int xt=1;
      while(true){
        if(ball[xt].first-ball[ow].first==d_x&&ball[xt].second-ball[ow].second==d_y&&seen[xt]==false){
          seen[xt]=true;
          ow=xt;
          seen_num++;
          xt++;
        }else{
          xt++;
        }
        if(xt>=n){
          for(int i=0;i<n;i++){
            if(seen[i]==false){
              ow=i;
              seen[ow]=true;
              seen_num++;
              xt=ow+1;
              count++;
              break;
            }
          }
        }
        if(seen_num==n){
          break;
        }
      }
      if(count<min){
        min=count;
      }
    }
  }
  cout<<min<<endl;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,k;cin>>n>>k;
    int h[n];
    int ans=0;
    for(int i=0;i<n;i++){
        cin>>h[i];
        if(h[i]>=k)ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
 
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

ll gcd(ll a, ll b){
  return b ? gcd(b, a%b) : a;
}
vector<pair<ll, int>> factorize(ll n) {
    vector<pair<ll, int>> res;
    for(ll i=2; i*i<=n; i++) {
        if (n % i) continue;
        res.emplace_back(i, 0);
        while (n%i == 0) {
            n /= i;
            res.back().second++;
        }
    }
    if(n != 1) res.emplace_back(n, 1);
    return res;
}
int main() {
    ll a, b; cin >> a >> b;
    ll g = gcd(a, b);
    // gの素因数を数え上げる
    auto f = factorize(g);
    cout << f.size()+1 << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		
		if(A + B > C + D) {
			System.out.println("Left");
		} else if(A + B == C + D) {
			System.out.println("Balanced");
		} else {
			System.out.println("Right");
		}
	}
}


Measured memory_bytes: 22996
#include <iostream>
#include <string>
typedef long long ll;
using namespace std;

int main()
{
	int N;
	string S;
	cin >> N;
	cin >> S;
	if(N%2!=0) {
		cout << "No" << endl;
		return 0;
	}
	for(int i = 0; i < N/2; i++) {
		if(S[i]!=S[N/2+i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int a[3][3];
	rep(i, 3) rep(j, 3) cin >> a[i][j];
	int n;
	cin >> n;
	while (n--) {
		int b;
		cin >> b;
		rep(i, 3) rep(j, 3) {
			if (a[i][j] == b) a[i][j] = 0;
		}
	}
	rep(i, 3) {
		int p = 0;
		rep(j, 3) p += a[i][j];
		if (p == 0) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	rep(j, 3) {
		int p = 0;
		rep(i, 3) p += a[i][j];
		if (p == 0) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	int p = 0, q = 0;
	rep(i, 3) {
		p += a[i][i];
		q += a[2 - i][i];
	}
	if (p == 0 or q == 0) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	ll q=sqrt(n);
	if(q!=1000000000){
		q++;
	}
	ll p=q*q-n;
	cout << "0 0 1 "<< q << " "<< q<< " "<< p<<endl; 
	//cout << abs(q*q-p);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int subo[200005];

int main()
{
  using std::cin;
  cin.sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++)
  {
    int cur;
    cin >> cur;
    subo[cur]++;
  }
  for (int i = 1; i <= n; i++)
  {
    std::cout << subo[i] << std::endl;
  }
  return 0;
}

Measured memory_bytes: 4364
fun main(args: Array<String>) {
    val s = readLine() ?: return
    val k = readLine()?.toInt() ?: return

    // sの長さがk以下の場合は全組み合わせ（最大で15）を試してk番目のものを出力
    if (s.length <= k) {
        println(allSubstring(s).sorted()[k - 1])
        return
    }

    // sに含まれる最小文字があるindex
    val minCharIndexes = mutableListOf<Int>()

    // ここで有効なminCharIndexについて考える
    // minCharIndexがs.length-1と等しく（つまりs.last()で）、かつkが5だった場合
    // このminCharから始まる有効なsubstringを作ることができない
    // 従って、最初から s.substring(0, s.length-k）の範囲での最小文字を探して、
    // それを文字列sにおける最小文字とする
    val minChar = s.substring(0, s.length - k + 1).min() ?: return

    for ((i, c) in s.withIndex()) {
        if (c == minChar && i <= s.length - k) {
            minCharIndexes += i
        }
    }

    val result = mutableSetOf<String>()

    // s.length - k, s.length の範囲に1~5番目に小さいsubstringがある可能性があるため、
    // この範囲でつくれるsubstringをセットする
    result.addAll(allSubstring(s.substring(s.length - k, s.length)))

    for (i in 1..k) {
        for (minIndex in minCharIndexes) {
            val substring = s.substring(minIndex, minIndex + i)
            result += substring
        }
    }

    println(result.sorted()[k - 1])
}

private fun allSubstring(s: String): Set<String> {
    val allSubstring = mutableSetOf<String>()
    for (i in s.indices) {
        for (j in i..s.length) {
            if (i == j) continue
            allSubstring += s.substring(i, j)
        }
    }
    return allSubstring
}

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

struct unionFind {
  int n;
  vector<int> v, s;

  unionFind(){};

  unionFind(int _n) {
    n = _n;
    v.resize(n, -1);
    s.resize(n, 1);
  }

  int root(int i) {
    if (v[i] == -1)
      return i;
    else
      return v[i] = root(v[i]);
  }

  void join(int i, int j) {
    int ri = root(i);
    int rj = root(j);
    if (ri == rj) return;
    if (s[ri] < s[rj]) swap(ri, rj);
    v[rj] = ri;
    s[ri] += s[rj];
  }

  int size(int i) { return s[root(i)]; }

  bool connected() { return size(0) == n; }
};

int main() {
  int n, m;
  cin >> n >> m;
  int ans = 0;
  vector<int> a(m), b(m);

  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    a[i] = x;
    b[i] = y;
  }

  for (int i = 0; i < m; i++) {
    auto u = unionFind(n);
    for (int j = 0; j < m; j++) {
      if (j != i) u.join(a[j], b[j]);
    }

    // for(int i=0;i<n;i++)cout<<u.root(i)<<" ";
    // cout<<endl;
    // for(int i=0;i<n;i++)cout<<u.size(i)<<" ";
    // cout<<endl;

    if (!u.connected()) ans++;
  }
  //      cout<<endl;
  cout << ans << endl;
}

Measured memory_bytes: 256
S=list(input())
N=len(S)-1

all_sum=0
def dfs(l,N,S):
    X=[[] for n in range(N+1)]
    X[0]=[S[0]]
    cnt=0
    temp=0
    if len(l)==N:
        global all_sum
        for n in range(N):
            if l[n]==0:
                X[cnt].append(S[n+1])
            else:
                cnt+=1
                X[cnt].append(S[n+1])
        for i in range(N+1):
            if X[i]!=[]:
                temp+=int("".join(X[i]))
        all_sum+=temp         
        return
    else:
        for n in range(2):
            l.append(n)
            dfs(l,N,S)
            l.pop()
dfs([],N,S)
print(all_sum)

Measured memory_bytes: 3064
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      a: i64,
      b: i64,
    }
    if a == 0 || b == 0 {
        return puts!("{}\n", "Zero");
    }

    if a < 0 && b > 0 {
        return puts!("{}\n", "Zero");
    }

    if a > 0 {
        return puts!("{}\n", "Positive");
    }

    if (b-a) % 2 == 0 {
        return puts!("{}\n", "Negative");
    } else {
        return puts!("{}\n", "Positive");
    }
}


Measured memory_bytes: 4352
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#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 <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;
const int INF = (int)1e8;

int n;
map<int,int> mp;

int tohash(string &s){
	int a = 0;
	FOR(i,n){
		a *= 4;
		if(s[i] == 'r') a += 1;
		else if(s[i] == 'g') a += 2;
		else a += 3;
	}
	return a;
}

int decodeC(int hash,int i){
	return (hash >> (2*i)) & 3;
}

bool OK(int hash){
	int c = decodeC(hash,0);
	for(int i = 1; i < n; i++)
		if(decodeC(hash,i) != c) return false;
	return true;
}

void setC(int& hash,int i,int v){
	hash = (hash & ~(3 << (2*i))) | (v << (2*i));
}

typedef pair<int,int> P;

int main(){
	string s;
	while(cin>>s,s!="0"){
		n = sz(s);
		mp.clear();
		mp[tohash(s)] = 0;

		int ans = -1;

		priority_queue<P,vector<P>,greater<P> > q;
		q.push(P(0,tohash(s)));

		while(!q.empty()){
			P p = q.top(); q.pop();
			int v = p.second;
			if(mp[v] < p.first) continue;

			if(OK(v)){
				ans = p.first;
				break;
			}

			for(int i = 0; i < n-1; i++){
				int hash = p.second;
				int c = decodeC(hash , i) ^ decodeC(hash, i + 1);
				if(c == 0) continue;
				setC(hash,i,c);
				setC(hash,i+1,c);
				if(mp.find(hash) == mp.end() ||  mp[hash] > p.first + 1){
					mp[hash] = p.first + 1;
					q.push(P(p.first + 1,hash));
				}
			}
		}

		if(ans == -1) puts("NA");
		else cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1820
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: usize, h: [usize; n]);

    let mut count = 0;
    let mut max = 0;
    for i in 0..h.len() - 1 {
        if h[i] >= h[i + 1] {
            count += 1;
            if max < count {
                max = count;
            }
        } else {
            count = 0;
        }
    }

    println!("{}", max);
}


Measured memory_bytes: 3752
from collections import defaultdict
n = int(input())
li = []
for _ in range(n):
  s = input()
  temp = []
  dd = defaultdict(lambda:0)
  for i in s:
    dd[i] += 1
  for key in dd:
    temp.append((key, dd[key]))
  temp.sort()
  li.append(temp)
li.sort()
ans = 0
k = 0
for i in range(n):
  if i == n-1:
    ans += (k*(k+1))//2
  else:
    if li[i] == li[i+1]:
      k += 1
    else:
      ans += (k*(k+1))//2
      k = 0
print(ans)

Measured memory_bytes: 75436