akhauriyash/Code-Regression huggingface dataset:
from collections import Counter

n = int(input())
v = [int(x) for x in input().split()]
h = n//2

odds = Counter(v[::2])
evens = Counter(v[1::2])

least_odds = odds.most_common(2)
least_evens = evens.most_common(2)
if len(least_odds) == 1:
    least_odds.append((-1,0))
if len(least_evens) == 1:
    least_evens.append((-1,0))

if least_odds[0][0] == least_evens[0][0]:
    keep = max(least_odds[0][1]+least_evens[1][1], least_odds[1][1]+least_evens[0][1])
else:
    keep = least_odds[0][1]+least_evens[0][1]

print(n-keep)

Measured memory_bytes: 18656
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;


int main(void){
	ll n;
	cin >> n;
	ll ans=0;
	for(int i=1;i<n;i++){
		ans += i;
	}

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


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class ABC
{
    public static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int minimum = int.MaxValue;
        for (int i = 0; i < N-1; i++)
        {
            if (A[i] < 0)
            {
                A[i] = -A[i];
                A[i + 1] = -A[i + 1];
            }
            if (Math.Abs(A[i]) < minimum) minimum = Math.Abs(A[i]);
        }
        if (Math.Abs(A[N - 1]) < minimum) minimum = Math.Abs(A[N - 1]);

        long answer = 0;

            for (int i = 0; i < N; i++)
            {
            answer += Math.Abs(A[i]);
            }

        if (A[N - 1] >= 0) Console.WriteLine(answer);
        else Console.WriteLine(answer - 2 * minimum);


    }



    public static int GCD2(int a, int b)
    {
        if (a % b == 0) return b;
        else return GCD2(b, a % b);
    }

}

Measured memory_bytes: 32220
n = int(input())
d = [[0]* 9 for _ in range(9)]
for num in range(1, n+1):
    str_num = str(num)
    if str_num[-1] != "0":
        start = int(str_num[0]) - 1
        end = int(str_num[-1]) - 1
        d[start][end] += 1

ans = 0
for i in range(9):
    for j in range(9):
        ans += d[i][j] * d[j][i]

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < n; i++) 

using namespace std;

int main() {
    char a, b, c;
    cin >> a >> b >> c;

    if (a == b && b == c) {
        cout << "No" << endl;
        return 0;
    }
    else if (a != b != c) {
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
using System;
 
class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
         
        string[] str0 = Console.ReadLine().Split(' ');
        int[] s = new int[n];
        for (int i = 0; i < n; i++)
        {
            s[i] = int.Parse(str0[i]);
        }
 
        int q = int.Parse(Console.ReadLine());
         
        string[] str1 = Console.ReadLine().Split(' ');
        int[] t = new int[n];
        for (int i = 0; i < q; i++)
        {
            t[i] = int.Parse(str1[i]);
        }

		Array.Sort(s);
 
        int count = 0;
        for (int i = 0; i < q; i++)
        {
            if (BinarySearch(t[i], s))
			{
				count ++;
			}
        }
 
        Console.WriteLine(count);
    }

	static bool BinarySearch(int x, int[] a)
	{
		int l = 0, r = a.Length;

		for (; r - l > 0; )
		{
			int i = (l + r) / 2;
			if (a[i] == x)
			{
				return true;
			}
			else if (a[i] < x)
			{
				l = i + 1;
			}
			else
			{
				r = i;
			}

		}
		return false;
	}
}


Measured memory_bytes: 27620
#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
typedef long long ll;

ll n, q, t, a, b, sl, sr, sb;
priority_queue<ll> lt, rt;
int main() {
	cin >> q;
	while(q--) {
		scanf("%lld", &t);
		if(t==1) {
			scanf("%lld%lld", &a, &b);
			sb += b;
			if(lt.size()<=rt.size()) {
				rt.push(-a);
				sr += a;
				a = -rt.top(); rt.pop();
				sr -= a;
				lt.push(a);
				sl += a;
			} else {
				lt.push(a);
				sl += a;
				a = lt.top(); lt.pop();
				sl -= a;
				rt.push(-a);
				sr += a;
			}
		} else {
			printf("%lld %lld\n", lt.top(), sb + sr-sl + lt.top()*(lt.size()!=rt.size()));
		}
	}
	return 0;
}

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int A;
int B;
int main(){
  int h, res;
  rd(A);
  rd(B);
  h = B - A;
  res = h * (h+1) / 2 - B;
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// int A, B;
// {
//   int h, res;
//   rd(A,B);
//   h = B - A;
//   res = h * (h+1) / 2 - B;
//   wt(res);
// }


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
# coding: utf-8
from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe


# my functions here!
#標準エラー出力
def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)
def debug(x):
    print(x,file=sys.stderr)
def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
    
#どっかで最悪計算量の入力データを用意する関数を作ろう？
"""
"""

#solution:
def dis2(a,p):
    return (a-p)**2
#input
N,=pin()
X=sorted(list(pin()))

ans=0
mx=100000000
for p in range(X[0],X[-1]+1):
    temp=0
    for x in X:
        temp+=dis2(x,p)
    if temp < mx:
        ans=p
        mx=temp
print(mx)
#print(["No","Yes"][cond])
#print([["NA","YYMM"],["MMYY","AMBIGUOUS"]][cMMYY][cYYMM])
"""
#printデバッグ消した？
#前の問題の結果見てないのに次の問題に行くの？
"""
"""
お前カッコ閉じるの忘れてるだろ
"""

Measured memory_bytes: 70636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
char s[200005];
int n, p, dp, m=1;
long long cnt;
map<int,int> mp;
int main(){
	scanf("%d%d\n%s", &n, &p, s);
	mp[0]++;
	for(int i=n-1; i>=0; i--){
		(dp += m*(s[i]-'0')) %= p;
		mp[dp]++;
		(m *= 10) %= p;
		if(p == 2 && ((s[i]-'0')%2 == 0)) cnt += i+1;
		else if(p == 5 && ((s[i]-'0')%5 == 0)) cnt += i+1;
	}
	if(p != 2 && p != 5){
		for(auto it: mp) cnt += (long long)it.second * (it.second - 1) / 2;
	}
	printf("%lld\n", cnt);
}

Measured memory_bytes: 896
from collections import deque

N = int(input())

G = [[] for i in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    G[a - 1].append(b - 1)
    G[b - 1].append(a - 1)
    
C = sorted([int(i) for i in input().split()])

print(sum(C) - max(C))
    
Q = deque()
Q.append(N - 1)
order = []
visited = [False] * N
while len(Q) != 0:
    q = Q.popleft()
    visited[q] = True
    c = C.pop()
    order.append([q, c])
    for g in G[q]:
        if visited[g] == False:
            Q.append(g)

sorted_order = sorted(order)
ans2 = []
for i in range(N):
    ans2.append(sorted_order[i][1])
    
print(' '.join(map(str, ans2)))

Measured memory_bytes: 50264
n = int(input())
s = input()
S = len(s)
l = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
m = "ABCDEFGHIJKLMNOQPRSTUVWXYZ"
old_word = 0
new_word = 0
ans = []
#print(S)
#print(l[n])
#print(m[n])

for i in range(S):
    old_word = l.index(s[i])
    #print(old_word)
    new_word = old_word + n
    #print(new_word)
    if new_word > 25:
        new_word = new_word - 26
    ans.append(l[new_word])


#print(l.index("B"))
print("".join(ans))

Measured memory_bytes: 3188
#include <iostream>
#include <tuple>
#include <vector>
#include <algorithm>
using namespace std;
using lint = long long;
vector<tuple<long double, lint>> arr;
vector<unsigned long long> ans;
lint ten[16];
int K;
long double S(lint v) {
    int ret = 0;
    for(lint i = 1; v / i; i *= 10) {
        ret += (v / i) % 10;
    }
    return double(ret);
}

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>K;
    ten[0] = 1;
    for(int i = 1; i < 16; i++) ten[i] = ten[i-1] * 10;
    for(int i = 1; i <= 15; i++) {
        for(int j = 1; j < min(ten[i], ten[4]); j++) {
            unsigned long long val = ten[i-1] - 1 + ten[i-1] * j;
            if(val <= 1e15) arr.emplace_back(val/S(val), val);
        }
    }
    sort(arr.begin(), arr.end());
    lint mv = 0;
    for(int i = 0; i < arr.size(); i++) {
        lint v, idx;tie(v, idx) = arr[i];
        if(idx > mv) {
            ans.push_back(idx);
            mv = idx;
        }
    }
    for(int i = 0; i < K; i++) {
        cout<<ans[i]<<'\n';
    }
    return 0;
}

Measured memory_bytes: 6256
#include "bits/stdc++.h"
using namespace std;

int main() {
	string N;
	cin >> N;
	if (N[0] == N[1] && N[1] == N[2] || N[1] == N[2] && N[2] == N[3])
		cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

int main(){
  int a,b,c;
  int i;
  int cnt = 0;

  cin >> a >> b >>c;

  for (i = a ;i <= b ; i++) {
    /* code */
    if (c%i == 0){
      cnt++;
    }
  }
  cout << cnt << '\n';
  return 0;
}



Measured memory_bytes: 3100
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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; }


int main(){
    int n; cin >> n;
    string s, t; cin >> s >> t;
    ll res = 1, index = 0, bef;
    if(s[0]==t[0]){
        res *= 3;
        index++;
        bef = 1;
    }else{
        res *= 6;
        index+=2;
        bef = 2;
    }
    for(index; index<n; index++){
        if(bef == 1 && s[index] == t[index]){
            res = res * 2 % MOD;
        }
        else if(bef == 2 && s[index] == t[index]){
            bef = 1;
        }else if(bef == 1 && s[index] != t[index]){
            res = res * 2 % MOD;
            bef = 2;
            index++;
        }
        else{
            res = res * 3 % MOD;
            bef = 2;
            index++;
        }
    }
    cout << res << ln;

}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<cmath>
#include<limits.h>
#include<algorithm>
#include<cstring>
using namespace std;

const long long inf=1e12;

int main()
{
  int n,t;
  cin>>n>>t;
  long long pricesum=0;
  
  vector<int> w(n),p(n);
  for(int i=0;i<n;i++)
  {
    cin>>w[i]>>p[i];
    pricesum+=p[i];
  }
  vector<long long> newdp(pricesum+1),olddp(pricesum+1,inf);
  
  
  olddp[0]=0;
  for(int i=1;i<=n;i++)
  {
    for(int j=0;j<=pricesum;j++)
    {
      if(j>=p[i-1])
      {
        newdp[j]=min(w[i-1]+olddp[j-p[i-1]],olddp[j]);
      }
      else
        newdp[j]=olddp[j];
      
  }
    olddp=newdp;
  }
    long long ans=LLONG_MIN;
    long long ansprice=0;
    for(int j=1;j<=pricesum;j++)
      {
          if((olddp[j]<=t)&&(ans+olddp[j]>ans))
          {
              ans=ans+olddp[j];
              ansprice=j;
          }
          
          
      }
    
  cout<<ansprice<<endl;
  return 0;
}


Measured memory_bytes: 1792
N = int(input())
D,X = map(int,input().split())
ans = 0
for i in range(N):
    A = int(input())
    sankasya_i = 0
    j = 0
    while(True):
        day = A*j+1
        j+=1
        if(day > D):
            break
        sankasya_i += 1
    ans += sankasya_i
print(ans+X)


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;

int main() {
    
	int n, d, x;
	cin >> n >> d >> x;
	for (int i=0; i<n; i++) {
		int f;
		cin >> f;
		for (int j=1; j<=d; j+=f) x++;
	}
	cout << x << endl;
	
}


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

int main() {

  int n, r;
  int card[64];
  int card2[64];
  int p, c;

  for(;;) {
    std::cin >> n >> r;
    if( n == 0 && r == 0 ) {
      break;
    }

    for(int i = 0; i < n; ++i) {
      card[i] = n-i;
    }

    for(int i = 0; i < r; ++i) {
      std::cin >> p >> c;

      for(int j = 0; j < p-1; ++j) {
	card2[j+c] = card[j];
      }

      for(int j = p-1; j < c+p-1; ++j) {
	card2[j-p+1] = card[j];
      }

      for(int j = 0; j < c+p-1; ++j) {
	card[j] = card2[j];
      }
    }
    std::cout << card[0] << std::endl;
  }
  
  return 0;
}

Measured memory_bytes: 1160
n  = STDIN.gets.chomp.to_i
a  = STDIN.gets.chomp.split(/\s/).map { |e| e.to_i }
 
z = Array.new(n, 0)
 
a.each do |i|
	z[i - 1] += 1
end
 
all = 0
z.each do |i|
	all += i * (i - 1) / 2
end
 
a.each do |i|
	puts all - (z[i - 1] - 1)
end

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

int main(){
    int n,m,ans=0;
    cin >> n >> m;
    vector<int> v[10],p(m);
    for(int i = 0;i < m;i ++){
        int k;
        cin >> k;
        for(int j = 0;j < k;j ++){
            int s;
            cin >> s;
            s --;
            v[s].push_back(i);
        }
    }
    for(int i = 0;i < m;i ++){
        cin >> p[i];
    }

    // {0, 1, ..., n-1} の部分集合の全探索
    for (int bit = 0; bit < (1<<n); ++bit){
        map<int,int> mp;
        bool isok = 1;
        for(int i = 0;i < n;i ++){
            if(bit & (1<<i)){
                for(int j = 0;j < v[i].size();j ++){
                    mp[v[i][j]] ++;
                }
            }
        }
        for(int i = 0;i < m;i ++){
            if(mp[i]%2!=p[i]) {isok=0;break;}
        }
        if(isok) ans ++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def check(li,N):
    for i in range(N):
        if (s[i]=='o' and li[i]==0)or(s[i]=='x' and li[i]==1):
            if(li[(i+1)%N]!=-1 and li[(i+1)%N]!=li[i-1]):
                return False
            else:
                li[(i+1)%N]=li[i-1]
        elif (s[i]=='o' and li[i]==1)or(s[i]=='x' and li[i]==0):
            if(li[(i+1)%N]!=-1 and li[(i+1)%N]==li[i-1]):
                return False
            else:
                li[(i+1)%N]=int(not li[i-1])
    return True
    
def output(li):
    for i in range(N):
        if li[i]==1:
            print('W',end='')
        else:
            print('S',end='')
    print()

N=int(input())
s=input()
for i in range(2):
    for j in range(2):
        li=[-1]*N
        li[0]=i
        if(i==0 and s[0]=='o')or(i==1 and s[0]=='x'):
            li[-1]=j;li[1]=j
        elif(i==1 and s[0]=='o')or(i==0 and s[0]=='x'):
            li[-1]=j;li[1]=j^1
        if(check(li,N)):
            output(li)
            exit()
print(-1)

Measured memory_bytes: 60760
#include<bits/stdc++.h>
using namespace std;
#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--)
typedef long long LL;
int main(){
	LL A,B,C;
	LL K;
	cin>>A>>B>>C>>K;
	if(K%2==0){
		cout<<A-B<<endl;
	}else{
		cout<<B-A<<endl;
	}
	return(0);
}

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

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

    string W;
    cin >> W;

    int count = 0;
    while (1) {
        string tmp;
        cin >> tmp;
        if (tmp == "END_OF_TEXT") {
            break ;
        }
        std::transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower);
        if (tmp.size() == W.size() ) {
            if (tmp.find(W) != std::string::npos) {
                count++;
            }
        }
    }
    cout << count << '\n';
    return 0;
}


Measured memory_bytes: 3232
S = input()
eS = list(" ".join(S))
exp = len(S)-1

res = 0
for i in range(2**exp):
    eS = list(" ".join(S))
    for j in range(exp):
        if (i >> j) & 1:
            eS[2*j+1] = "+"
    res += eval("".join(eS).replace(" ", ""))

print(res)

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

inline ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}

inline ll lcm(ll a, ll b) {
    return max(a, b) / gcd(a, b) * min(a, b);
}

int main() {
    int n; cin >> n;
    ll res = 1;
    for (int i = 0; i < n; i++) {
        ll t; cin >> t;
        res = lcm(res, t);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
x=[]
listA=[]
for i in range(0,M):
  x=list(map(int,input().split()))
  listA.append(x)
listB=[]
listC=[]
for i in range(0,M):
  listB.append(listA[i][0])
  listC.append(listA[i][1])
x=0
if max(listB)>min(listC):
  print(0)
else:
  print(abs(max(listB)-min(listC))+1)


Measured memory_bytes: 29080
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define REPI(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) REPI(i,0,n)

typedef long long ll;

int SURP = 1000000007;

int main(){
	int M,N;

	cin >> M >> N;
	bool a[M+2][N+2] = {0};
	REP(i,M){
		REP(j,N){
			char c;
			cin >> c;
			if(c == '#') a[i+1][j+1] = true;
		}
	}

	string ret = "Yes";
	REPI(i,1,M+1){
		REPI(j,1,N+1){
			if(a[i][j]){
				if( !(a[i-1][j] || a[i+1][j] || a[i][j-1] || a[i][j+1]) ){
					ret = "No";
					break;
				}
			}
		}
	}

	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 256
import math

def main():
  N = int(input())
  A = list(map(int, input().split()))
  
  for i in range(0, N):
    if A[i] % 2 == 0: #偶数だったら
      if A[i] % 3 != 0 and A[i] % 5 != 0: #3でも5でも割れないとき
        print('DENIED')
        return
  
  print('APPROVED')
  
  
main()

Measured memory_bytes: 9168
class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]


def main():
    n, m = map(int, input().split())
    p = list(map(int, input().split()))
    xy = [list(map(int, input().split())) for _ in range(m)]
    tree = UnionFind(n)
    for x, y in xy:
        tree.Unite(x, y)

    root = [[] for _ in range(n+1)]
    f_root = []
    for i in range(n):
        x = tree.Find_Root(p[i])
        root[x].append(i+1)
        f_root.append(x)
    out_put = 0
    for i in range(n):
        if f_root[i]==f_root[p[i]-1]:
            out_put += 1
    print(out_put)

if __name__=="__main__":
    main()

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

public class Main {
	static FastReader f = new FastReader();
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		//int t = f.nextInt();
		//while(t-- > 0)
			solve();
		out.close();
	}

	static void solve() {
		int n = f.nextInt(), m = f.nextInt();

		Dsu dsu = new Dsu(n);
		while(m-- > 0) {
			dsu.join(f.nextInt() - 1, f.nextInt() - 1);
		}

		HashSet<Integer> set = new HashSet<>();
		for(int i=0;i<n;i++) {
			set.add(dsu.getPar(i));
		}

		out.println(set.size() - 1);
	}

	static class Dsu {
		int[] size;
		int[] par; 
		Dsu(int n) {
			size = new int[n];
			par = new int[n];
			for(int i=0;i<n;i++) {
				size[i] = 1;
				par[i] = i;
			}
		}

		int getPar(int x) {
			if(x == par[x]) {
				return x;
			}
			return par[x] = getPar(par[x]);
		}


		void join(int a, int b) {
			a = getPar(a);
			b = getPar(b);
			if(a != b) {
				if(size[a] < size[b]) {
					int t = a;
					a = b;
					b = t;
				}
				size[a] += size[b];
				par[b] = a;
			}
		}
 	}


	static class FastReader {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;

		String next() {
			while(st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch(IOException ioe) {
					ioe.printStackTrace();
				}
			}
			return st.nextToken();
		}

		String nextLine() {
			String s = "";
			try {
				s = br.readLine();
			} catch(IOException ioe) {
				ioe.printStackTrace();
			}

			return s;
		}

		int  nextInt() {
			return Integer.parseInt(next());
		}

		long  nextLong() {
			return Long.parseLong(next());
		}
	}
}

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

int main(){
	unsigned long long int n, m, a;
	cin >> n >> m;
	vector<pair<int, int>> b(n + 1, make_pair(0, 0));
	for (int i = 0; i < m; ++i){
		cin >> a;
		b[a].second = 1;
	}
	b[0].first = 1;
	for (int i = 0; i <= n; ++i){
		if (i + 1 <= n && b[i + 1].second != 1)
			b[i + 1].first = (b[i + 1].first + b[i].first) % 1000000007;
		if (i + 2 <= n && b[i + 2].second != 1)
			b[i + 2].first += (b[i + 2].first + b[i].first) % 1000000007;
	}
	cout << b[n].first << endl;
	return 0;
}

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

int main(void) {
	int N;
	string S, T;
	cin >> N >> S >> T;
	string ans = "";
	for (int i = 0; i < N; ++i) {
		ans += S[i];
		ans += T[i];
	}
	cout << ans << '\n';
	return 0;
}


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

string s, t;
int Rs[30], Rt[30];

int CtoN(char c) {
    int num = c -'a';
    return num;
}

int main() {
    cin >> s >> t;
    int N = s.size();

    for (int i = 0; i < 30; i++) {
        Rs[i] = -1; Rt[i] = -1;
    }

    int flag = 0;
    for (int i = 0; i < N; i++) {
        int temp = CtoN(s[i]);
        if (Rs[temp] < 0) {
            Rs[temp] = CtoN(t[i]);
        }else{
            flag = !(Rs[temp] == CtoN(t[i]));
        }

        temp = CtoN(t[i]);
        if (Rt[temp] < 0) {
            Rt[temp] = CtoN(s[i]);
        }else{
            flag = !(Rt[temp] == CtoN(s[i]));
        }
        if(flag) break;
    }

    string ans = flag ? "No" : "Yes";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 776
# input = sys.stdin.readline

def resolve():
    N, K = map(int, input().split())
    L = [0] * (10 ** 5 + 1)
    for i in range(N):
        a, b = map(int, input().split())
        L[a] += b

    cnt = 0
    for i in range(10 ** 5 + 1):
        if cnt+L[i] >= K:
            print(i)
            break
        else:
            cnt += L[i]


resolve()

Measured memory_bytes: 5736
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int n,m,k;
int main(){
    cin>>n>>m>>k;
    cout<<min(n*m,k)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1<<30;
int n,m;
vector<string>in,tmp;
int dx[]={1,1,1,0,0,-1,-1,-1};
int dy[]={1,0,-1,1,-1,1,0,-1};
vp t,nt;
bool f(int a,int b){
	int c=in[a][b]-'0';
	int co=0;
	rep(i,8){
		int x=a+dx[i];
		int y=b+dy[i];
		if(in[x][y]=='.')co++;
	}
	if(co>=c){
		tmp[a][b]='.';
		return true;
	}
	return false;
}
bool F(bool e){
	nt=vp(0);
	tmp=in;
	bool h=false;
	if(!e){
		rep(i,n)rep(j,m)if(in[i][j]!='.'&&f(i,j))h=true,nt.pb(pii(i,j));
	}else{
		rep(i,t.size())rep(j,8){
			int x=t[i].first+dx[j];
			int y=t[i].second+dy[j];
			if(tmp[x][y]!='.'&&f(x,y))h=true,nt.pb(pii(x,y));
		}
	}
	in=tmp;
	t=nt;
	return h;
}
int main(){
	cin>>n>>m;
	in=vector<string>(n);
	rep(i,n)cin>>in[i];
	int co=0;
	if(F(0)){
		co++;
		while(F(1))co++;
	}
	cout<<co<<endl;
}

Measured memory_bytes: 3120
N = int(input())
A = [0] + list(map(int,input().split())) + [0]

F = [0]
for i in range(1, N+1):
    F.append(abs(A[i] - A[i-1]) + F[i-1])

B = [0]
for i in range(1, N+1):
    B.append(abs(A[N+1-i] - A[N+2-i]) + B[i-1])
B.reverse()

for i in range(1, N+1):
    print(abs(A[i+1]-A[i-1]) + F[i-1] + B[i])

Measured memory_bytes: 17044
#include <algorithm>
#include <chrono>
#include <iostream>
#include <vector>

using namespace std;
using namespace std::chrono;

int main() {
  auto start = high_resolution_clock::now();

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  vector<int> a(3 * n);
  for (int i = 0; i < 3 * n; ++i)
    cin >> a[i];
  sort(a.begin(), a.end(), greater<int>());

  long long ans = 0;
  for (int i = 1; i <= 2 * n; i += 2)
    ans += a[i];

  cout << ans << endl;

  cerr << "Total execution time : " << duration_cast<milliseconds>(high_resolution_clock::now() - start).count() << " ms" << endl;

  return 0;
}


Measured memory_bytes: 1408
s=int(input())
mod=10**9+7
P=[1 for i in range(10**6+1)]
for i in range(10**6):
  P[i+1]=P[i]*(i+1)%mod

def comb(a,b):
    if a>=b:
        return P[a]*pow(P[a-b],mod-2,mod)*pow(P[b],mod-2,mod)%mod
    else:
        return 0
ans=0
t=s//3
for i in range(1,t+1):
  ans+=comb(s-2*i-1,i-1)
  ans%=mod
print(ans)

Measured memory_bytes: 140096
S = input()
N = len(S)

map_ = [-1] * 2019
map_[0] = 0
ans = 0
now = 0
for i in range(0, N):
    now = (now + int(S[N - i - 1]) * pow(10, i, 2019)) % 2019
    map_[now] += 1
    ans += map_[now]

print(ans)


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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
#define test cout<<"test"<<endl;
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
const ll zero=0;
using P = pair<ll, ll>;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}


struct z{
  ll x;
  ll y;
  ll l;
};

int main(){
  ll i,j,o;
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll h,w,k;cin>>h>>w>>k;
  ll a[h][w];
  ll buf1,buf2;
  for(i=0;i<h;i++){
    string s;
    cin>>s;
    for(j=0;j<w;j++){
      if(s[j]=='#')a[i][j]=0;
      else if(s[j]=='.')a[i][j]=1;
      else {
        a[i][j]=1;
        buf1=i;
        buf2=j;
      }
    }
  }
  queue<struct z> p;
  vector<vector<ll>>d(h,vector<ll>(w,0));
  p.push({buf1,buf2,zero});
  while(!p.empty()){
    ll x=p.front().x;
    ll y=p.front().y;
    ll l=p.front().l;
    if(l==k+1)break;
    if(d[x][y]==0&&a[x][y]==1){
      if(x==0||x==h-1||y==0||y==w-1){res1=1;break;}
      d[x][y]=1;
      if(x<=h-2)p.push({x+1,y,l+1});
      if(y<=w-2)p.push({x,y+1,l+1});
      if(x>=1)p.push({x-1,y,l+1});
      if(y>=1)p.push({x,y-1,l+1});
      chmin(res1,(min(min(h-1-x,x),min(w-1-y,y))+k-1)/k+1);
    }
    p.pop();
  }
  cout<<res1<<endl;



  return 0;
}

Measured memory_bytes: 10368
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

int main() {
	ll a, b, k;
	cin >> a >> b >> k;
	if (a >= k) {
		cout << a - k << " " << b << endl;
	} else if (a + b >= k) {
		cout << "0 " << a + b - k << endl;
	} else {
		cout << "0 0" << endl;
	}
	return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
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; }

int main() {
    ll x; cin >> x;
    ll ans = 0;
    ans += x / 500 * 1000;
    x %= 500;
    ans += x / 5 * 5;
    cout << ans << endl;
}


Measured memory_bytes: 3524
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  	int a,b;
  	cin>>a>>b;
  	cout<<max({a+b,a-b,a*b});
    
    return 0;
    
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	
	using namespace std;
	int main()
	{
		std::ios::sync_with_stdio(false);
		string s, t;
		cin>>s>>t;
		int ans =INT_MAX;
		int ns =s.length(), nt =t.length();
		for (int i =0;i<=ns -nt;i++) {
		    int ct =0;
		    for(int j =0;j<nt;j++)
		    {
		        if(s[i+j]!=t[j])
		        ct++;
		    }
		    ans = min(ans, ct);
		}
		cout<<ans<<endl;
		return 0;
	
	}


Measured memory_bytes: 3668
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
set<ll> setK;

//* prime factorization in O(sqrt(n))
map<ll, ll> prime_factor(ll n){
    map<ll, ll> res;
    for(ll i=2; i*i <= n; i++){ //* n shrinks during the for-loop!
        while(n % i == 0){
            ++res[i];
            n /= i;
        }
    }
    if(n != 1) {
        ++res[n];
    }
    return res;
}

void solve(long long N){
    if(N == 2){
        cout << 1<<endl; return;
    }
    ll N1 = N-1;
    setK.insert(N); setK.insert(N-1);
    //* find factor of N-1
    for(ll i=2; i*i <= N1; i++){
        if(N1 % i == 0) {
            setK.insert(i);
            setK.insert(N1/i);
        }
    }
    /*
    for(auto x: setK) cout<<x << " ";
    cout<<endl;
    */
    //* check N
    for(ll i=2; i*i <= N; i++){
        ll tmpN = N;
        while(tmpN % i == 0){
            tmpN /= i;
        }
        if(tmpN % i == 1) setK.insert(i);
    }


    cout<<setK.size()<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
amax = 0
for i in range(N):
    kame = 0
    for i2 in range(i+1):
        kame+=A1[i2]
    for i2 in range(N-i):
        kame+=A2[-i2-1]
    if amax<kame:
        amax=kame
print(amax)


Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF (1LL<<60)
#define MOD1 1000000007
#define MAX_N (1 << 17)


void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{
    ll aa;
    ll bb;
}frequent;

int main(void){
    // char ;
    ll n,ans=0;
    scanf("%lld",&n);
    ll a[100000]={};
    rep(i,0,n){
        ll b;
        scanf("%lld",&b);
        a[b-1]++;
    }
    sortdown(a,100000);
    ll c=0;
    rep(i,0,100000){
        if(a[i]<=1) break;
        c+=a[i]-1;
    }
    if(c%2){
        ans=n-c-1;
    }else{
        ans=n-c;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1404
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
using namespace std;
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;}
template <class T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007;
const ll MAX = 510000;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
    string a,b;
    cin >> a >> b;
    string c = a+b;
    int n = stoi(c);
    rep(i,100100) {
        if (i*i == n) {
            cout << "Yes" << "\n";
            return 0;
        }
    }
    cout << "No" << "\n";

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <math.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
using namespace std;
#define rep(I,N) for(int I = 0; I < (int)(N); I++)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int memo[8][8];
int a, b;

void dfs(int depth, P p, string S){
	if(depth == 0 && p.first == a && p.second == b){
		cout << S << endl;
		return;
	}
	int nowa = p.first;
	int nowb = p.second;
	//if((nexta == 5 && nowb <= 3) || (nextb == 5 && nowa <= 3))return;
	//if(a > nexta || b > nextb)return;
	if(nowa >= 4 && nowb >= 4){
		if(nowa+1 <= a)dfs(depth-1, P(nowa+1, nowb), S+'A');
		if(nowb+1 <= b)dfs(depth-1, P(nowa, nowb+1), S+'B');
	}else{
		if(nowa+1 <= a && nowb != 5 && nowa+1 != 6)dfs(depth-1, P(nowa+1, nowb), S+'A');
		if(nowb+1 <= b && nowa != 5 && nowb+1 != 6)dfs(depth-1, P(nowa, nowb+1), S+'B');
	}
	//dfs(depth-1, )
	//if(memo[][])
}

int main(void){
	cin >> a >> b;
	P p = P(0, 0);
	string s;
	dfs(a+b, p, s);
	return 0;
}

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

public class Main {

  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    int n = input.nextInt();
    int k = input.nextInt();
    int[] xyz = new int[n];
    for (int i = 0; i < n; i++) {
      xyz[i] = input.nextInt();
    }
    Arrays.sort(xyz);
    long ans = 0;
    for (int i = n - k - 1; i >= 0; i--) {
      ans += xyz[i];
    }
    System.out.print(ans);
  }

}


Measured memory_bytes: 63816
#include<bits/stdc++.h> 
using namespace std;
#define N 1000100
#define k 100000000 
#define F (rt<<1)
#define s int
#define G (rt<<1|1)
#define o first
#define u second
#define I push_back
#define K return
#define X void
struct J{s a,b,H;}p[N];typedef pair<s,s> pa;bool operator < (J x,J y){if (x.a==y.a) K x.b>y.b;K x.a>y.a;}priority_queue<J> q;s n,i,a[N],A,t[N];pa m[N<<3];vector
 e[N],ans;X E(pa &x,pa y) {x.o=min(x.o,y.o),x.u=min(x.u,y.u);}X c(s rt,s l,s r){m[rt].o=k;m[rt].u=k;if (l==r){if (l&1) m[rt].o=a[l];else m[rt].u=a[l];K ;}s D=(l+r)/2;c(F,l,D);c(G,D+1,r);E(m[rt],m[F]),E(m[rt],m[G]);}pa b(s rt,s l,s r,s x,s y){if (x<=l&&r<=y) K m[rt];s D=(l+r)/2;pa C=make_pair(k,k);if(x<=D) E(C,b(F,l,D,x,y));if (y>=D+1) E(C,b(G,D+1,r,x,y));K C;}s d(s l,s r){s f,w,h,z;if (l&1){f=b(1,1,n,l,r).o,h=t[f];w=b(1,1,n,h+1,r).u,z=t[w];}else{f=b(1,1,n,l,r).u,h=t[f];w=b(1,1,n,h+1,r).o,z=t[w];}p[++A].a=f,p[A].b=w,p[A].H=A;s B=A;if (h!=l)e[B].I(d(l,h-1));if(h+1!=z)e[B].I(d(h+1,z-1));if (z!=r)  e[B].I(d(z+1,r));K B;}s main(){scanf("%d",&n);for (i=1;i<=n;i++)scanf("%d",&a[i]),t[a[i]]=i;c(1,1,n);d(1,n);q.push(p[1]);while (!q.empty()){s x=q.top().H;q.pop();printf("%d %d ",p[x].a,p[x].b);for (i=0;i<(s)e[x].size();i++)q.push(p[e[x][i]]);}}

Measured memory_bytes: 54912
n = int(input())
upper = list(map(int, input().split()))
lower = list(map(int, input().split()))

max_amount = 0
for i in range(n):
    temp_variable = sum(upper[:i+1]) + sum(lower[i:])
    if temp_variable > max_amount:
        max_amount = temp_variable
    else:
        pass
print(max_amount)

Measured memory_bytes: 3060
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val l = sc.nextInt()
    val lst = mutableListOf<String>()
    for (i in 0 until n) {
        val s = sc.nextLine()
        lst.add(s)
    }
    lst.sort()
    println(lst.joinToString(""))
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 31396
#include <cstdio>
#include <algorithm>
using namespace std;

int n;
int a[101];
int ans = 1e9;

int main(){
	scanf("%d", &n);
	for(int i=0; i<n; ++i) scanf("%d", &a[i]);
	for(int i=-100; i<=100; ++i){
		int tmp = 0;
		for(int j=0; j<n; ++j) tmp += (a[j] - i) * (a[j] - i);
		ans = min(ans, tmp);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <numeric>
#include <array>
#include <queue>
#include <set>
using namespace std;
using ll = long long int;
#define REP(i,n) for(int i=0;i<n;i++)

int main()
{
    int N, M;
    cin >> N >> M;
    int L_max=1, R_min=N;

    REP(i, M)
    {
        int L, R;
        cin >> L >> R;
        if (L_max < L)
        {
            L_max = L;
        }
        if (R_min > R)
        {
            R_min = R;
        }
    }

    if (L_max > R_min)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << R_min - L_max + 1 << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

int main(void) {
    Int l, r, d;
    cin >> l >> r >> d;
    if (l % d == 0) {
        cout << r / d - l / d + 1 << endl;
    } else {
        cout << r / d - l / d << endl;
    }
    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define ARRAY_LENGTH (100010)

// Infinity value
const long long INF = 1LL << 60;

template<class T>
bool chmin(T& a, T b){
  if(a > b){
    a = b;
    return true;
  }else{
    return false;
  }
}

int main(void)
{
  int N, K;
  long long H[ARRAY_LENGTH];
  long long dp[ARRAY_LENGTH];

  std::cin >> N >> K;

  // Input costs
  for(int i = 0;i < N;i++){
    std::cin >> H[i];
  }

  // Initialize DP
  for(int i = 0;i < ARRAY_LENGTH;i++){
    dp[i] = INF;
  }

  // Initial condition
  dp[0] = 0;

  // Loop
  for(int i = 1;i < N;i++){
    for(int k = 1;k <= K;k++){
      if(i >= k){
        chmin(dp[i], dp[i-k] + abs(H[i] - H[i-k]));
      }
    }
  }

  std::cout << dp[N-1] << std::endl;

  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(int argc, char const *argv[]){
   int a,b,c;
   scanf("%d%d%d",&a,&b,&c );
   if ((a == 1 && b == 1 && c == 0)||(a == 0 && b == 0 && c == 1)) {
      /* code */
      printf("Open\n" );
   } else {
      /* code */
      printf("Close\n" );
   }
   return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int n;
int a[100005];
int ans[100005];
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        ans[a[i]-1]=i+1;
    }
    for(int i=0;i<n;i++){
        cout<<ans[i];
        if(i==n-1){
            cout<<endl;
        }else{
            cout<<" ";
        }
    }
    
}


Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;
int main(){
  int N;
  cin >> N;

  vector<ll> A(N);

  for(int i = 0;i < N;i++)cin >> A[i];

  vector<ll> x(N,0);
  for(int i = 0;i < N;i++){
    if(i % 2 == 0)x[0] += A[i];
    else x[0] -= A[i];
  }
  x[0] /= 2;

  for(int i = 1;i < N-1;i++){
    x[i] = A[i-1] - x[i-1];
  }

  x[N-1] = A[N-1] - x[0];

  for(int i = 0;i < N;i++)cout << 2 * x[i] << endl;
}


Measured memory_bytes: 2944
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue> //C++
#include <string> //C++
#include <iostream> //C++
#include <vector> //C++
#include <algorithm> //C++
using namespace std; //C++
#define rep(i, a, n) for (i = (a); i < (n); i++)







int main()
{
	long long int w;
	
	cin >> w;
	long long int i=2;
	long long int j;
	long long int t=0;
	long long int min = w;
	
	int k=0;
	

	for (i = 3; i <= sqrt(w); i+=2) {
		if (w % i == 0 ||w%2==0) k = 1;
	}
	if (k == 0 || w==2) {
		cout << w - 1;
		return 0;
	}
	i = 2;


	while(i<=sqrt(w)) {
		if (w % i == 0) {
			j = (w / i);
			
			t = i + j - 2;

			if (t < min) min=t;

		}
		i++;
		
	}
	cout << min;
	
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<unordered_set>
using namespace std;

int main(){
	string s;
	unordered_set<char> set;
	cin >> s;
	for(auto c: s){
		if(set.count(c)) {
			cout << "no";
			return 0;
		} else {
			set.insert(c);
		}
	}
	cout << "yes";
	return 0;
}



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

int main() {
	int N;cin>>N;
	int a[114514],x[114514],y[114514];bool b=true;
	a[0]=0;x[0]=0;y[0]=0;
	for(int i=1;i<=N;i++){
		cin>>a[i]>>x[i]>>y[i];
		int k=abs(x[i-1]-x[i])+abs(y[i-1]-y[i]);
		if(k>a[i]-a[i-1]||k%2!=(a[i]-a[i-1])%2)b=false;
	}
	if(b)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 1408
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 
 
	public static void main(String[] args) { 
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int P = input.nextInt();
		int numEven = 0;
		int numOdd = 0;
		long ans = 0;
		long chooseAns = 0;
		for (int i = 0; i < N; i++) {
			int x = input.nextInt();
			if (x%2==0) numEven++;
			else numOdd++;
		}
		ans++;
		for (int i = 0; i < numEven; i++) { //Any subset of even numbers is good
			ans*=2;
		} //Subset answer
		if (P==0) {
			for (int choose = 2; choose <= numOdd; choose+=2) { //Subsets of even number of odds
				int diff1 = choose;
				int diff2 = numOdd-choose;
				int numMultiply = Math.min(diff1, diff2);
				long curAns = 1;
				for (long factor = numOdd; factor > numOdd-numMultiply; factor--) {
					curAns*=factor;
				}
				for (long i = 1; i <= numMultiply; i++) {
					curAns/=i;
				}
				chooseAns+=curAns;
			}
			chooseAns++; //Empty set considered
			ans*=chooseAns;
		}else {
			for (int choose = 1; choose <= numOdd; choose+=2) { //Subsets of odd number of odds
				int diff1 = choose;
				int diff2 = numOdd-choose;
				int numMultiply = Math.min(diff1, diff2);
				long curAns = 1;
				for (long factor = numOdd; factor > numOdd-numMultiply; factor--) {
					curAns*=factor;
				}
				for (long i = 1; i <= numMultiply; i++) {
					curAns/=i;
				}
				chooseAns+=curAns;
			} //Empty set actually fails this condition since >= 1 odd is needed for odd sum
			ans*=chooseAns;
		}
		System.out.println(ans);
	}	
}


Measured memory_bytes: 23124