akhauriyash/Code-Regression huggingface dataset:
from collections import deque
N,M,P = map(int, input().split())
R = []
R2 = {}
R3 = {}
OPT = [float("inf")]*(N+1)
for _ in range(M):
    A,B,C = map(int, input().split())
    R.append([A,B,-C+P])
    if not B in R2:
        R2[B] = []
    if not A in R3:
        R3[A] = []
    R3[A].append(B)
    R2[B].append(A)

visited_N = [0]*(N+1)
visited_N[N] = 1
queue = deque()
queue.append(N)

while queue != deque():
    tmp = queue.pop()
    if tmp in R2:
        for i in R2[tmp]:
            if visited_N[i] == 0:
                visited_N[i] = 1
                queue.append(i)    

visited_1 = [0]*(N+1)
visited_1[1] = 1
queue = deque()
queue.append(1)

while queue != deque():
    tmp = queue.pop()
    if tmp in R3:
        for i in R3[tmp]:
            if visited_1[i] == 0:
                visited_1[i] = 1
                queue.append(i)    

visited = [0]*(N+1)
for i in range(N):
    visited[i+1] = visited_N[i+1]*visited_1[i+1]
                
OPT[1] = 0
OPT_tmp = OPT

for _ in range(N-1):
    for i in range(M):
        tmp_r = R[i]
        if visited[tmp_r[0]] == 1 and visited[tmp_r[1]] == 1:
            if OPT[tmp_r[0]] + tmp_r[2] < OPT[tmp_r[1]]:
                OPT[tmp_r[1]] = OPT[tmp_r[0]] + tmp_r[2]
    OPT = OPT_tmp
tmp_opt = OPT[N]

flag = 0
for i in range(M):
    tmp_r = R[i]
    if visited[tmp_r[0]] == 1 and visited[tmp_r[1]] == 1:
        if OPT[tmp_r[0]] + tmp_r[2] < OPT[tmp_r[1]]:
            flag = 1
    
if flag:
    answer = -1
else:
    answer = max(0,-tmp_opt)

print(answer)

Measured memory_bytes: 55256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <cstdlib>
#include <math.h>

using namespace std;

typedef long long ll;
#define rep(i, n) for(long (i) = 0; (i) < (long) (n); (i)++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,a,b) for(long i=(a);i<(b);i++)
#define rrep1(i,a,b) for(long i=(a);i<=(b);i++)
#define rrrep(i,a,b) for(long i=(a);i>=(b);i--)
#define define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define X first
#define Y second
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int> >

const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const ll LINF = 1e18;

int printYes() {
    cout << "Yes" << endl;
    return 0;
}

int printNo() {
    cout << "No" << endl;
    return 0;
}

int ans;

int printAns() {
    cout << ans << endl;
    return 0;
}


int pow(int x) {
	if (x == 0) {
		return 1;
	}
	else {
		return pow(x - 1) * 2;
	}
}

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;
    if (N < 105) {
        cout << 0;
        return 0;
    } else if (N<135)
    {
        cout << 1;
        return 0;
    } else if (N < 165) {
        cout << 2;
        return 0;
    } else if (N<189) {
        cout << 3;
    }else if (N<195) {
        cout << 4;
    } else
    
    {
        cout <<5;
        return 0;
    }
    
    
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {

	N := oneInt()

	var sum int
	for a := 1; a <= N; a++ {
		for b := 1; b <= N; b++ {
			for c := 1; c <= N; c++ {
				sum += gcd(gcd(a, b), c)
			}
		}
	}

	fmt.Print(sum)

}

func exp(val int) float64 {
	var temp float64
	for index := 1; index <= val; index++ {
		temp += float64(index)
	}
	return temp / float64(val)
}

func searchAbove(slice []int, target int, index int) int {
	for i := index + 1; i < len(slice); i++ {
		v := slice[i]
		if v >= target {
			return i
		}
	}
	return -1
}

var sc = bufio.NewScanner(os.Stdin)

func oneInt() int {
	var a int
	fmt.Scan(&a)
	return a
}
func oneStr() string {
	var a string
	fmt.Scan(&a)
	return a
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func scanNums() (nums []int) {
	s := nextLine()
	numStr := strings.Split(s, " ")

	for _, n := range numStr {
		i, _ := strconv.Atoi(n)
		nums = append(nums, i)
	}
	return nums
}

func scanStrings() (strs []string) {
	s := nextLine()
	list := strings.Split(s, " ")
	strs = append(strs, list...)
	return strs
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / gcd(a, b)
}


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

int n;

void countingSort(int a[], int b[], int k) {
  int c[k + 1];
  for (int i = 0; i < k + 1; i++) {
    c[i] = 0;
  }

  for (int i = 0; i < n; i++) {
    c[a[i]]++;
  }

  for (int i = 1; i < k + 1; i++) {
    c[i] += c[i - 1];
  }

  for (int i = n - 1; i >= 0; i--) {
    b[c[a[i]] - 1] = a[i];
    c[a[i]]--;
  }
}

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

  int maxi = a[0];
  for (int i = 0; i < n; i++) {
    maxi = max(a[i], maxi);
  }
  int b[n];
  countingSort(a, b, maxi);

  cout << b[0];
  for (int i = 1; i < n; i++) {
    cout << ' ' << b[i];
  }
  cout << endl;
}

Measured memory_bytes: 18716
import random
s_given = list(input())
t_given = list(input())

s_len = len(s_given)
t_len = len(t_given)
s_sorted = sorted(s_given)
t_sorted = sorted(t_given, reverse=True)

for i in range(t_len):
    if s_sorted[i] < t_sorted[i]:
        print('Yes')
        break
    elif s_sorted[i] > t_sorted[i]:
        print('No')
        break
    if i == t_len - 1:
        print('No')
        break
    elif i == s_len - 1 :
        print('Yes')
        break


Measured memory_bytes: 3824
import java.util.*

class Scanner(`in`: java.io.InputStream) {
    private val reader = java.io.BufferedReader(java.io.InputStreamReader(`in`))
    private var tokenizer: StringTokenizer? = null

    fun next(): String {
        if (tokenizer?.hasMoreTokens() != true) {
            tokenizer = StringTokenizer(reader.readLine())
        }
        return tokenizer!!.nextToken()
    }

    fun nextLine(): String {
        return if (tokenizer?.hasMoreTokens() != true) {
            reader.readLine()
        } else tokenizer!!.nextToken("\n")
    }
}

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

////////////////////////////////////////////////////////////////////////

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val M = sc.next().toInt()

        val h = (M / 2 + (M % 2)) * 2
        val h2 = (M / 2) * 2 + 1

        var n = 0
        for (i in 0 until h / 2) {
            if (n == M) break
            val a = i + 1
            val b = h - i
            pw.println("$a $b")
            n++
        }
        for (i in 0 until h2 / 2) {
            if (n == M) break
            val a = h + i + 1
            val b = h + h2 - i
            pw.println("$a $b")
            n++
        }
    }
}


Measured memory_bytes: 45796
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int M = scan.nextInt();
        HashMap<Integer, List<Integer>> graph = new HashMap<Integer, List<Integer>>();
        for (int i = 0; i < M; i++) {
            int f = scan.nextInt()-1;
            int t = scan.nextInt()-1;
            if(!graph.containsKey(f)) {
                graph.put(f, new ArrayList<>());
            }
            graph.get(f).add(t+1000000);
            if(!graph.containsKey(f+1000000)) {
                graph.put(f+1000000, new ArrayList<>());
            }
            graph.get(f+1000000).add(t+2000000);
            if(!graph.containsKey(f+2000000)) {
                graph.put(f+2000000, new ArrayList<>());
            }
            graph.get(f+2000000).add(t);
        }
        int S = scan.nextInt() - 1;
        int T = scan.nextInt() - 1;
        int[][] d_S = dijkstra(graph, N, S);
        if (d_S[T][0] == 100000000) {
            System.out.println(-1);
        } else {
            System.out.println(d_S[T][0]/3);
        }
    }
    public int[][] dijkstra(HashMap<Integer, List<Integer>> graph, int N, int S) {
        int[][] d = new int[N][3];
        boolean[][] used = new boolean[N][3];
        for (int i = 0; i < N; i++) {
            Arrays.fill(d[i], 100000000);
            Arrays.fill(used[i], false);
        }
        d[S][0] = 0;
        Queue<Integer> q = new LinkedList<>();
        q.add(S);
        while(!q.isEmpty()) {
            int p = q.poll();
            int x = p % 1000000;
            int y = p / 1000000;
            if (used[x][y]) {
                continue;
            }
            used[x][y] = true;
            List<Integer> nexts = graph.get(p);
            if (nexts == null) {
                continue;
            }
            for (int n : nexts) {
                int nx = n % 1000000;
                int ny = n / 1000000;
                d[nx][ny] = Math.min(d[nx][ny], d[x][y] + 1);
                q.add(n);
            }
        }
        return d;
    }
}


Measured memory_bytes: 156796
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
int d[200];
int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>d[i];
  }
  int ans=0;
  ll sum=0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      ans=d[i]*d[j];
      sum+=ans;
    }
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define INF 999999999
typedef long long ll;
using namespace std;
int main() {
    string S;
    cin >> S;
    int A[4];
    char op[3];
    int sum;
    REP(i, 4) {
        A[i] = S[i] - '0';
    }
    REP(i, 8) {
        sum = A[0];
        FOR(j, 0, 3) {
            if(i & (1 << j)) sum += A[j+1];
            else sum -= A[j+1];
        }
        if(sum == 7) {
            cout << A[0];
            FOR(j, 0, 3) {
                if(i & (1 << j)) op[j] = '+';
                else op[j] = '-';
                cout << op[j];
                cout << A[j+1];
            }
            cout << "=7" << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>

using namespace std;

typedef pair<int,int> P;
typedef pair<int,P> T;

vector<T> V;
deque<int> G[100];

int n;
bool isVisited[100];
bool isConnected(){
    queue<int> Q;
    fill(isVisited,isVisited+n,false);
    Q.push(0);
    int cnt=1;
    isVisited[0]=true;
    while(!Q.empty()){
        int v=Q.front(); Q.pop();
        for(deque<int>::iterator ite=G[v].begin();ite!=G[v].end();ite++){
            int to=*ite;
            if(!isVisited[to]){
                cnt++;
                isVisited[to]=true;
                Q.push(to);
            }
        }
    }
    return cnt==n;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int m;
    while(cin>>n>>m,n){
        if(m==0){
            if(n==1) cout<<0<<endl;
            else cout<<-1<<endl;
            continue;
        }
        V.clear();
        for(int i=0;i<m;i++){
            int a,b,w;
            cin>>a>>b>>w;
            a--,b--;
            V.push_back(T(w,P(a,b)));
        }
        sort(V.begin(),V.end());
        for(int i=0;i<100;i++){
            G[i].clear();
        }
        //???????????¨?????????O(VE)
        int head=0,tail=0;
        P p = V[0].second;
        G[p.first].push_back(p.second);
        G[p.second].push_back(p.first);
        int ans=10001;
        while(true){
            while(!isConnected()){
                // cout<<"tail: "<<tail<<endl;
                tail++;
                if(tail==m) break;
                p=V[tail].second;
                G[p.first].push_back(p.second);
                G[p.second].push_back(p.first);
            }
            if(tail==m) break;
            while(isConnected()){
                int silmness=V[tail].first-V[head].first;
                // cout<<"head: "<<head<<", silmness: "<<silmness<<endl;
                ans=min(ans,silmness);
                p=V[head++].second;
                G[p.first].pop_front();
                G[p.second].pop_front();
            }
        }
        if(ans==10001)ans=-1;
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3416
def attacks(k, healths):
    if k == 0:
        return sum(healths)

    healths.sort()
    return sum(healths[:-k])


if __name__ == '__main__':
    n, k = ([int(s) for s in input().split()])
    healths = [int(s) for s in input().split()]

    print(attacks(k, healths))

Measured memory_bytes: 26024
n,k=map(int,input().split())
arr=list(map(int,input().split()))
for i in range(n):
  arr[i]=(arr[i]+1)/2
tmp=sum(arr[:k])
ans=tmp
for i in range(k,n):
  tmp+=(arr[i]-arr[i-k])
  ans=max(ans,tmp)
print(ans)

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

typedef long long ll;
typedef vector<ll> vl;

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

	int n = s.size();

	if (s[0] == s[n - 1]) {
		if (n % 2 == 0) {
			cout << "First" << endl;
		}
		else {
			cout << "Second" << endl;
		}
	}
	else {
		if (n % 2 == 1) {
			cout << "First" << endl;
		}
		else {
			cout << "Second" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

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

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

ll n, a, b;

int main(){
	ll x = 0, ans = 0;
	cin >> n >> a >> b;
	REP(i, n){
		ll num;
		cin >> num;
		if (x != 0){
			ans += min((num - x)*a, b);
		}
		x = num;
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define pb push_back
#define mk make_pair

using namespace std;
typedef long long ll;

int main() {
	fastio;
	ll n;
	cin>>n;
	vector<ll> a(n);
	ll sum = 0;
	for(ll i=0;i<n;i++){
		cin>>a[i];
		a[i] -= i+1;
		
	}
	sort(a.begin(),a.end());
	if(n%2){
		for(ll i=0;i<n;i++){
			sum += abs(a[i]-a[n/2]); 
		}
		cout<<sum<<"\n";
	}
	else{
		ll s1 = 0,s2 = 0;
		for(ll i=0;i<n;i++){
			s1 += abs(a[i]-a[n/2]); 
		}
		
		cout<<s1<<"\n";
	}
	
	
	
}

Measured memory_bytes: 1792
import re
s = input()
if len(s) < 7 or len(s) > 107:
    print('NO')
else:
    if re.match('^keyence.*',s) or re.match('.*keyence$',s) or re.match('^k.*eyence$',s) or re.match('^ke.*yence$',s) or re.match('^key.*ence$',s) or re.match('^keye.*nce$',s) or re.match('^keyen.*ce$',s) or re.match('^keyenc.*e$',s):
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define MOD 1000000007
typedef long long ll;
int n;
vector<vector<int>> v(200005);
bool visit[200005];
int d[200005], child_num[200005];
ll f[200005], ans[200005];

int dfs(int start, int depth)
{
	int ret = 0;
	visit[start] = true;
	d[start] = depth;
	for(int i : v[start]){
		if(!visit[i]) {
			ret += dfs(i, depth+1);
		}
	}
	return child_num[start] = ret + 1;
}

ll power(ll a, ll n) {
	ll res = 1;
	while(n > 0) {
		if(n & 1) {
			res *= a;
			res %= MOD;
		}
		a *= a;
		a %= MOD;
		n >>= 1;
	}
	return res;
}

void get_ans(int start)
{
	if(child_num[start]==1) return;
	ans[1] = (ans[1] * (f[child_num[start] -1])) % MOD;
	for(int i : v[start]) {
		if(d[i] < d[start]) continue;
		ans[1] *= power(f[child_num[i]], MOD - 2);
		ans[1] %= MOD;
		get_ans(i);
	}
}

void dfs2(int start)
{
	visit[start] = true;
	for(int i : v[start]){
		if(!visit[i]) {
			ans[i] = (ans[start] * f[child_num[i]] ) % MOD;
			ans[i] = (ans[i] * power(f[n - child_num[i]], MOD - 2))  % MOD;
			ans[i] = (ans[i] * f[n - child_num[i]-1])  % MOD;
			ans[i] = (ans[i] * power(f[child_num[i] -1], MOD - 2)) % MOD;
			dfs2(i);
		}
	}
}

int main(void)
{
	cin >> n;
	f[0] = 1; ans[1] = 1;
	for(int i=1;i<=n;i++) {
		f[i] = (f[i-1] * i) % MOD;
	}
	int from, to;
	for(int i=1;i<n;i++){
		scanf("%d %d", &from, &to);
		v[from].pb(to);
		v[to].pb(from);
	}
	dfs(1, 0);
	get_ans(1);
	for(int i=1;i<=n;i++) visit[i] = false;
	dfs2(1);
	for(int i=1;i<=n;i++) cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 18804
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,m1,m2;
  cin >> N;
  m1 = (N % 1000) % 111;
  m2 = (N / 10) % 111;
  if(m1 == 0 || m2 == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
from collections import deque
n , m = map(int,input().split())
tuuro = [[] for i in range(n+1)]
for i in range(m):
    a,b = map(int,input().split())
    tuuro[a].append(b)
    tuuro[b].append(a)
ans = [-1 for i in range(n+1)]

print("Yes")

d = deque()
d.append(1)
ans[1] = 0
while d:
    now = d.popleft()
    for i in tuuro[now]:
        if ans[i] == -1:
            ans[i] = now
            d.append(i)

for i in range(2,n+1):
    print(ans[i])

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



int main()
{	
	ll a,b,cnt=0;
	cin>>a>>b;
	while(a<=b/2)
	{
		a*=2;
		cnt++;
	}
	cout<<cnt+1<<endl;
	return 0;
}

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

  int N , M ;
  int ans = 0 ;
  cin >> N >> M ;
  if(N==M) rep(i,N) cout << N ;
  if(N>M)  rep(i,N) cout << M ;
  if(N<M)  rep(i,M) cout << N ;
 }
  

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

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=n; i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll N;
ll M;
ll imos[100010];
ll ans;
int main() {
	cin >> N>> M;
	REP(i,0,M){
		ll L, R;
		cin >> L >> R;
		imos[L-1]++;
		imos[R]--;
	}
	REP(i,0,N){
		imos[i+1] += imos[i];
		if(imos[i]==M) ans++;
	}
	p(ans);
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using in6 = int64_t;
using ind = double;
using pii = pair<int,int>;
using psi = pair<string,int>;
using vpi = vector<pii>;
using vps = vector<psi>;
#define rep(i, n) for (in6 i = 0; i < (in6)(n); i++)
#define repa(i,a,n) for(in6 i = a; i < (in6)(n); i++)
#define repdown(i,n) for(in6 i = n; i > 0; i--)
#define kyun ios::sync_with_stdio(false)
#define hinata cout << "\n"
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define inf 2147483647

int main() {
  kyun;
  int n;
  cin >> n;
  in6 ans = 0;
  repa(i,1,n+1) {
    if(i % 3 != 0 && i % 5 != 0) ans += i;
  }
  cout << ans;
  hinata;
}


Measured memory_bytes: 3608
#include <stdio.h>

int main(){
  int a,i,n;
  int max = -1000001,min = 1000001;
  double sum =0;
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
  	scanf("%d",&a);
    
    if(a<min){
    	min = a;
    }
    if(a>max){
    	max = a;
    }
    sum +=a;
  }
  
  printf("%d %d %.0f\n",min,max,sum);

  return 0;
}


Measured memory_bytes: 2064
#include <bits/stdc++.h>
#define ll long long
#define _69e27 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int N = 3e3+5, M=1e5+5, oo=0x3f3f3f3f, mod = 1e9+7;

int n;
double mem[N][N];
double arr[N];

double solve(int i, int cnt){
    if(i == n){
        if(cnt >= (n+1)/2) return 1.00;
        else return 0.00;
    }
    if(mem[i][cnt] != -1.00) return mem[i][cnt];
    double op1 = solve(i+1, cnt)*(1.00-arr[i]);
    double op2 = 0.00;
     op2 = solve(i+1, cnt+1)*arr[i];
    return mem[i][cnt] = op1+op2;
}

int main()
{
    _69e27
    cin >> n;
    for(int i = 0; i<n; i++)
        cin >> arr[i];
    for(int i=0; i<=n; i++){
        for(int j=0; j<=n; j++)
            mem[i][j] = -1.00;
    }


    cout << fixed << setprecision(10) << solve(0, 0);
    return 0;
}


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

#define      ll     long long int

int powerTwo(int x)
{
    int c = 0;
    while (x % 2 == 0) {
        x /= 2;
        c++;
    }
    return c;
}

int main()
{
    int n, i, j, k, mn = 1e9;
    cin >> n;
    for (i = 1; i <= n; i++) {
        cin >> j;
        mn = min(mn, powerTwo(j));
    }
    cout << mn << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    cout << max(0LL, ((n - 1) * b + a) - (b + (n - 1) * a) + 1) << endl;
    return 0;
}


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

struct expr
{
  typedef enum { NODE, LEAF } expr_type;
  expr_type type;
  int len;
  vector<expr> cs;
  string genom;
};

typedef string::const_iterator Iterator;
pair<expr,Iterator> parse_one(Iterator it, const Iterator& last)
{
  if (it == last) {
    throw "eof";
  }
  if ('A' <= *it &&  *it <= 'Z') {
    string genom;
    while (it != last && 'A' <= *it &&  *it <= 'Z') {
      genom += *it;
      ++it;
    }
    expr e;
    e.type = expr::LEAF;
    e.len = 1;
    e.genom = genom;
    return make_pair(e, it);
  } else {
    int len = 0;
    while (it != last && '0' <= *it && *it <= '9') {
      len = 10*len + (*it - '0');
      ++it;
    }
    if (*it == '(') {
      ++it;
      expr e;
      e.type = expr::NODE;
      e.len = len;
      while (*it != ')') {
        pair<expr,Iterator> p = parse_one(it, last);
        e.cs.push_back(p.first);
        it = p.second;
      }
      ++it;
      return make_pair(e, it);
    } else {
      expr e;
      e.type = expr::LEAF;
      e.len = len;
      e.genom = *it;
      ++it;
      return make_pair(e, it);
    }
  }
}

expr parse(Iterator it, const Iterator& last)
{
  expr e;
  e.type = expr::NODE;
  e.len = 1;
  while (it != last) {
    const pair<expr,Iterator> p = parse_one(it, last);
    e.cs.push_back(p.first);
    it = p.second;
  }
  return e;
}

string expand(const expr& e, unsigned idx)
{
  if (e.type == expr::NODE) {
    string t = "";
    for (vector<expr>::const_iterator it(e.cs.begin()); it != e.cs.end(); ++it) {
      t += expand(*it, idx);
      if (t.size() > idx) {
        return t.substr(0, idx+1);
      }
    }
    string g = "";
    for (int i = 0; i < e.len; i++) {
      g += t;
      if (g.size() > idx) {
        return g.substr(0, idx+1);
      }
    }
    return g.substr(0, idx+1);
  } else {
    string g = "";
    for (int i = 0; i < e.len; i++) {
      g += e.genom;
    }
    return g.substr(0, idx+1);
  }
}

int main()
{
  string s;
  unsigned idx;
  while (cin >> s >> idx && s != "0") {
    const expr e = parse(s.begin(), s.end());
    const string t = expand(e, idx);
    if (idx < t.size()) {
      cout << t[idx] << endl;
    } else {
      cout << "0" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3772
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

#define int long long

template<typename A, size_t N, typename T>

void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//ここにグローバル変数宣言

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//ここに関数宣言


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int N;
string S;

int ac=0,wa=0,tle=0,re=0;

cin>>N;

REP(i,N){
	cin>>S;
	if (S=="AC"){ac++;}
	if (S=="WA"){wa++;}
	if (S=="TLE"){tle++;}
	if (S=="RE"){re++;}
}

cout<<"AC x "<<ac<<endl;
cout<<"WA x "<<wa<<endl;
cout<<"TLE x "<<tle<<endl;
cout<<"RE x "<<re<<endl;




}

Measured memory_bytes: 3624
import itertools
N, M, Q = map(int, input().split())
a = []
b = []
c = []
d = []
for q in range(Q):
    aq, bq, cq, dq = map(int, input().split())
    a.append(aq)
    b.append(bq)
    c.append(cq)
    d.append(dq)

max_answer = 0
for A in itertools.combinations_with_replacement(range(1, M + 1), N):
    # print(A)
    answer = 0
    for i in range(Q):
        # print(a[i], b[i], c[i], d[i])
        if A[b[i]-1] - A[a[i]-1] == c[i]:
            answer += d[i]
    # print(answer)
    if max_answer < answer:
        max_answer = answer
print(max_answer)

Measured memory_bytes: 9040
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;
int K;

void input() {
  cin >> N >> K;
  va.resize(N + 1);
  rep(i, 0, N - 1) {
    cin >> va[i];
    va[i]--;
  }
  // va[i]--;
  //};
  ;
}
void solve() {
  //連続する部分列の和 % K == 連続する部分列の要素数
  // O(N)
  // 条件より，要素数はK-1以下
  // MOD　K してよさそう
  // each(x, va) x %= K;
  vb.resize(N + 1);
  // partial_sum(all(va), vb.begin());
  // rep(i, 0, N - 1) { vb[i + 1] = (vb[i] + va[i] + K - 1); }
  rep(i, 1, N) {
    vb[i] = vb[i - 1] + va[i - 1];
    vb[i] %= K;
  }

  // K

  int ans = 0;
  map<int, int> mp;
  //  mp[0] = 1;

  rep(j, 0, N) {
    if (j - K >= 0) {
      mp[vb[j - K]]--;
    }
    ans += mp[vb[j]];
    mp[vb[j]]++;
  }
  cout << ans << endl;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 15872
N = int(input())
H = list(map(int,input().split(" ")))

#DPテーブル作成
dp = [0]*(len(H))

dp[0] = 0
dp[1] = abs(H[1] - H[0])
for i in range(2,len(H)):
    dp[i] = min(dp[i-2] + abs(H[i-2] - H[i]) ,dp[i-1] + abs(H[i-1] - H[i]))

print(dp[len(H)-1])
# print(dp)

Measured memory_bytes: 13980
P = int(input())
res= []
for i in range(P):
  a, b = input().split()
  res.append((a,int(b)))
res2 = sorted(res, key = lambda x:x[1], reverse = True)
res3 = sorted(res2, key = lambda x:x[0])
for j in range(P):
  print(str(res.index(res3[j])+1))

Measured memory_bytes: 3060
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define dcml(n) fixed<<setprecision(n)
using namespace std;
int main(void){
    ll N;cin>>N;
    if(N&2==1){
        cout<<0<<"\n";
        exit(0);
    }//else
    vi A(N);
    REP(i,N)cin>>A[i];
    sort(ALLv(A));

    ll m=N/2-1;
    if(A[m]==A[m+1]){
        cout<<0<<"\n";
        exit(0);
    }//else
    cout<<A[m+1]-A[m]<<"\n";
}

Measured memory_bytes: 1024
#include <stdio.h>
 
int main()
{
   int w,h,x,y,r;
   scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
   if(w-r>=x&&r<=x&&h-r>=y&&r<=y){
    printf("Yes\n");
   }else{
    printf("No\n");
    }
}


Measured memory_bytes: 2624
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long t[] = new long[n];
		long a[] = new long[n];
		for (int i = 0; i < n; i++) {
			t[i] = sc.nextInt();
			a[i] = sc.nextInt();
		}

		for (int i = 1; i < n; i++) {
			long tr, ar, r;
			tr = (t[i] == 0 ? 1 : ((t[i - 1] - 1) / t[i] + 1));
			ar = (a[i] == 0 ? 1 : ((a[i - 1] - 1) / a[i] + 1));
			r = (tr > ar ? tr : ar);
			t[i] *= r;
			a[i] *= r;
		}

		System.out.println(t[n - 1] + a[n - 1]);
	}
}


Measured memory_bytes: 13340
s=gets.chomp.split("")
t=gets.chomp.split("")

idx=Hash.new { |h, k| h[k] = [] }

s.each_with_index do |c,i|
  idx[c] << i
end
l = []
t.each do |c|
  if idx[c].size == 0
    puts -1
    exit
  end

  if l.size == 0
    prev = -1
  else
    prev = l[-1]
  end
  
  tmp = idx[c].bsearch {|x| x >  prev}
  if tmp == nil
    l << idx[c][0]
  else
    l << tmp
  end
end

prev=Float::INFINITY
cnt = 0
l.each do |v|
  if prev >= v
    cnt += 1
  end
  prev = v
end
puts s.size * (cnt-1) + l[-1] + 1

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

#define endl "\n"

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;

void solve()
{
	int n;
	cin >> n;
	ll sum = 0;
	int a;
	unordered_map<int, int> f;
	for (int i = 0; i < n; i++)
	{
		cin >> a;
		f[a]++;
		sum += a;
	}

	int q;
	cin >> q;
	int b, c;
	while (q--)
	{
		cin >> b >> c;
		sum -= (ll)b * f[b];
		sum += (ll)c * f[b];
		f[c] += f[b];
		f[b] = 0;
		cout << sum << "\n";
	}
}


int main()
{

	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

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

	int t = 1;
	// cin >> t;
	while (t--)
	{
		solve();
	}

	return 0;
}




Measured memory_bytes: 7164
N = int(input())
rs = [tuple(map(int,input().split())) for i in range(N)]
bs = [tuple(map(int,input().split())) for i in range(N)]

bs.sort()
rs.sort(key=lambda x:-x[1])

removed = [0]*N
ans = 0
for bx,by in bs:
    for ri in range(N):
        if removed[ri]: continue
        rx,ry = rs[ri]
        if rx < bx and ry < by:
            removed[ri] = 1
            ans += 1
            break
print(ans)

Measured memory_bytes: 3188
n=int(input())
a=list(map(int,input().split()))
ps=0
xs=0
c=0
j=0
for i in range(n):
  ps+=a[i]
  xs^=a[i]
  while ps!=xs:
    ps-=a[j]
    xs^=a[j]
    j+=1
  c+=i-j+1
print(c)

Measured memory_bytes: 31808
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<set>
#include<regex>
#include<ctype.h>
using namespace std;

int main(void) {
	
	string s;
	cin >> s;
	int ans = 0, tmp = 0;

	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') tmp++;
		else {
			ans = max(ans, tmp);
			tmp = 0;
		}
	}
	
	cout << max(ans, tmp) << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
#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--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}
/*================================*/
#if DEBUG
#define SIZE 100
#else
#define SIZE 223450
#endif

int N,Q,K;
int A,B,C;

int calc(int a)  {
    if (a <= 599 ) return 8 ;
    if (a <= 799 ) return 7 ;
    if (a <= 999 ) return 6 ;
    if (a <= 1199) return 5 ;
    if (a <= 1399) return 4 ;
    if (a <= 1599) return 3 ;
    if (a <= 1799) return 2 ;
    if (a <= 1999) return 1 ;
    return 0;
}

void solve() {
    cin>>N;
    cout << calc(N) << endl;
}



Measured memory_bytes: 3644
n = gets.chomp.to_i
a_arr = gets.chomp.split(" ").map(&:to_i).sort_by{|x| x} + [10 ** 9 + 1]
b_arr = gets.chomp.split(" ").map(&:to_i).sort_by{|x| x}
c_arr = gets.chomp.split(" ").map(&:to_i).sort_by{|x| x} + [10 ** 9 + 1]

result = 0
a_i = 0
c_i = 0
b_arr.each do |b|
  (a_i..n).each do |i|
    if a_arr[i] >= b
      a_i = i
      break
    end
  end
  (c_i..n).each do |i|
    if c_arr[i] > b
      c_i = i
      break
    end
  end
  result += a_i * (n - c_i)
end

puts result


Measured memory_bytes: 29912
#include<iostream>
#include<math.h>
#include <algorithm>
#include<float.h>
#include <limits>
#include <vector> 
#include <numeric>
using namespace::std;
int main(){

int N;
cin>>N;
  int *p = new int[N];
  for(int i=0;i<N;i++){
    cin>>p[i];
  }
  int count=0;
  for(int i=0;i<N-1;i++){
    if(p[i]!=i+1){
      count++;
    }
    
  }
  if(count<3){
    cout<<"YES";
  }else{
    cout<<"NO";
  }

}


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

using namespace std;
int main()
{
	double N, K;
	cin >> N >> K;
	double ans = 0;
	for(int i = 1; i <= N; i++)
	{
		double temp = 1.0 / N;
		int cur = i;
		while(cur < K)
		{
			cur *= 2;
			temp *= 0.5;
		}
		ans += temp;
	}
	printf("%.12f", ans);
	return 0;
}


Measured memory_bytes: 256
#include <map>
#include <cstdio>
#include <cstring>
#include <algorithm>

int n;
int w[233333];
bool vis[233333];

int main(){
	int ans = 0;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", &w[i]);
	std::sort(w + 1, w + n + 1);
	for(int i = 30; i >= 0; i--){
		int tmp = 1 << i;
		int le = 1, ri = n, k;
		for(; le < ri; ){
			while(vis[le]) le++;
			while(vis[ri] || w[ri] >= tmp) ri--;
			if(le >= ri) break;
			k = tmp - w[ri];
			if(k == w[le]) vis[le] = vis[ri] = 1, ans++;
			else if(w[le] < k) le++;
			else ri--;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1152
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

int main(void)
{
    int a, b;
    cin >> a >> b;
    int ans = a + b;
    ans = max(ans, a - b);
    ans = max(ans, a*b);

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

Measured memory_bytes: 256
N=int(input())

ans = 0
rate = 380000.0
b = 0

for i in [0]*N:
	x,u = input().split(' ')
	if u == 'JPY':
		x = int(x)
		ans += x
	else:
		x = float(x)
		b += x

ans = float(ans)
ans += b * rate
print(ans)





Measured memory_bytes: 2940
#include<stdio.h>
#include<string.h>

#define M 1046527/* your task*/
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
  else return 0;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1+(key % (M-1));/* your task */; }

int find(char str[]){
  long long key, i, h;
    /* your task */
  key = getKey(str);
  for(i=0;;i++){
    h = (h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0) return 1;
    else if(strlen(H[h])==0) return 0;
  }
    return 0;
}

int insert(char str[]){
  long long key, i, h;
    /* your task */
  key = getKey(str);
  for(i=0;;i++){
        h = (h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0) return 1;
    else if(strlen(H[h])==0){
      strcpy(H[h],str);
      return 0;
    }
  }
    return 0;
  
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}



Measured memory_bytes: 16104
//ABC154A
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	string s, t, u;
	int a, b;
	cin >> s >> t >> a >> b >> u;
	if(u == s){
		a--;
	}else if(u == t){
		b--;
	}
	cout << a << " " << b << endl;
	return 0;
}

Measured memory_bytes: 256
import math
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

# Union-Find #
def init(n):
    for i in range(N):
        par[i]=i
        rnk[i]=0
def find(x):
    if par[x]==x:
        return x
    else:
        par[x]=find(par[x])
        return par[x]
def unite(x,y):
    x=find(x)
    y=find(y)
    if x==y:
        return
    if (rnk[x]<rnk[y]):
        par[x]=y
    else:
        par[y]=x
        if(rnk[x]==rnk[y]):
            rnk[x]+=1
def same(x,y):
    return find(x)==find(y)



N,M = IL()
xyz = [IL() for i in range(M)]

used = [False]*(N+1)

par=[0 for i in range(N+1)]
rnk=[0 for i in range(N+1)]

init(N)

for x,y,z in xyz:
    unite(x,y)

ans = 0
for i in range(1,N+1):
    if used[find(i)] == False:
        ans += 1
        used[find(i)] = True

print(ans)

Measured memory_bytes: 42120
#include<bits/stdc++.h>
using namespace std;
char c[5][5];
string s;
inline int read()
{
	int num=0,flag=1;
	char c=getchar();
	for (;c<'0'||c>'9';c=getchar())
	if (c=='-') flag=-1;
	for (;c>='0'&&c<='9';c=getchar())
	num=(num<<3)+(num<<1)+c-48;
	return num*flag;
}
int main()
{
	for (int i=1;i<=3;++i)
	{
		for (int j=1;j<=3;++j)
		c[i][j]=getchar();
		getline(cin,s);
	}
	for (int i=1;i<=3;++i)
	for (int j=1;j<=3;++j)
	if (i==j) printf("%c",c[i][j]);
	return 0;
}

Measured memory_bytes: 256
def doCommand(command, key, list)
  command == 'insert' ? list.unshift(key) :
    command == 'delete' ? list.index(key) && list.delete_at(list.index(key)) :
    command == 'deleteFirst' ? list.shift : list.pop
end

n = gets.to_i
list = []
n.times do
  command, key = gets.chomp.split(' ').map(&:to_s)
  doCommand(command, key, list)
end

puts list.join(' ')

Measured memory_bytes: 99280
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>

using std::cin;
using std::cout;
using std::endl;

int cal_ltor(std::string str) {
	int num_l = 0;
	bool plus = true;
	for (int i = 0; i < str.length(); i++) {
		if ( i%2 == 0 ) {
			if ( plus ) {
				num_l += (int)(str[i] - '0');
			}
			else {
				num_l *= (int)(str[i] - '0');
			}
		}
		else {
			if ( str[i] == '+' ) {
				plus = true;
			}
			else {
				plus = false;
			}
		}
	}
	return num_l;
}

int cal_multi(std::string str) {
	int num_p = 0;
	int l = str.length();
	std::vector<bool> cal(l, true);
	for (int i = 0; i < l; i++) {
		if (str[i] == '*') {
			int end = i;
			int mv = 0;
			int pro = 1;
			while ( end < l && str[end] != '+') {
				end++;
				mv++;
			}
			for (int j = i-1; j < end; j++) {
				if ( j%2 == 0 ) {
					pro *= (int)(str[j] - '0');
					cal[j] = false;
				}
			}
			num_p += pro;
			i += end - i;
		}
	}
	for (int i = 0; i < l; i++) {
		if ( cal[i] && i%2 == 0 ) {
			num_p += (int)(str[i] - '0');
		}
	}
	return num_p;
}

int main(void) {
	std::string str;
	cin >> str;
	int num_l = cal_ltor(str);
	int num_p = cal_multi(str);

	int ans;
	cin >> ans;
	if ( ans == num_l && ans == num_p ) {
		cout << "U" << endl;
	}
	else if ( ans == num_l ) {
		cout << "L" << endl;
	}
	else if ( ans == num_p ) {
		cout << "M" << endl;
	}
	else {
		cout << "I" << endl;
	}
	return 0;
}

Measured memory_bytes: 3172
c n r = product [n-r+1..n] `div` product [1..r]
main = do
  [n,p] <- map read . words <$> getLine
  as <- map read . words <$> getLine
  let e = sum [1 | a <- as, even a]
      o = n - e
  print $ sum [
    c e x * c o y |
    x <- [0..e], 
    y <- [0..o],
    y `mod` 2 == p]

Measured memory_bytes: 1020
#include<iostream>
using namespace std;
int main(){
  int n;
  int i;
  int card[4][13]={{}};
  cin >> n;
  char a;
  int b;
  for(i=0;i<n;i++) {
    cin >> a >> b;
    switch(a){
    case 'S':
      card[0][b-1]=1;
      break;
    case 'H':
      card[1][b-1]=1;
      break;
    case 'C':
      card[2][b-1]=1;
      break;
    case 'D':
      card[3][b-1]=1;
      break;
    }
  }
  for(i=0;i<52;i++) {
    switch(i/13){
    case 0:
      if(card[0][i%13]==0) cout << "S " << i+1 << endl;
      break;
    case 1:
      if(card[1][i%13]==0) cout << "H " << i%13+1 << endl;
      break;
    case 2:
      if(card[2][i%13]==0) cout << "C " << i%13+1 << endl;
      break;
    case 3:
      if(card[3][i%13]==0) cout << "D " << i%13+1 << endl;
      break;
    }
  }
  
  return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 998244353
#define EPS 1e-10
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define first_more_idx(ve, num) upper_bound(all(ve), num)-ve.begin() // idx = first_more_idx(ve,num); if(idx = ve.size()) , then not exist
#define first_lessequal_idx(ve, num) lower_bound(all(ve), num)-ve.begin()
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > // only sort first param
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}
ll dx[]={0, 0, -1, 1};
ll dy[]={1, -1, 0, 0};// up,down,left right

ll N ;
vector<ll> D;
ll dist[112345];
ll max_dist = 0 ;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> N ;
    
    rep(i, N){
        ll inp; cin >>inp;
        D.pb(inp);
        max_dist = max(inp, max_dist);
        dist[inp] ++;
    }
    
    if(D[0] != 0 or dist[0] != 1){
        cout << 0 << endl;
        return 0;
    }
    
    ll ans = 1 ;
    for(int i = 1; i <= max_dist; i++){
        cerr << dist[i-1] << " " << dist[i] << endl;
        ans *= power(dist[i-1], dist[i]) ;
        ans %= MOD;
    }
    
    cout << ans  << endl;
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 2168
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, A: int, B: int, C: int, D: int, S: str):
    
    if A<C<B<D:
        for i in range(A-1,C-1):
            if S[i] == S[i+1] == "#":
                print(NO)
                return
        for i in range(B-1,D-1):
            if S[i] == S[i+1] == "#":
                print(NO)
                return     
        print(YES)
        return
    
    if A<B<C<D:
        for i in range(A-1,C-1):
            if S[i] == S[i+1] == "#":
                print(NO)
                return
        for i in range(B-1,D-1):
            if S[i] == S[i+1] == "#":
                print(NO)
                return     
        print(YES)
        return

    if A<B<D<C:
        for i in range(B-1,D):
            if S[i-1] == S[i] == S[i+1] == ".":
                print(YES)
                return   
        print(NO)
        return     

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, A, B, C, D, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3700