akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define clear(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


int main()
{
	int n, m, r, q;
	while (scanf("%d%d", &n, &m), n)
	{
		scanf("%d", &r);
		static int stu[10010][750];
		for (int i = 0; i < m; ++i)
			for (int j = 0; j < 750; ++j)
				stu[i][j] = 0;
		while (r--)
		{
			int t, n, m, s;
			scanf("%d%d%d%d", &t, &n, &m, &s);
			if (s == 0)
				s = -1;
			stu[m][t - 540] += s;
		}

		scanf("%d", &q);
		while (q--)
		{
			int s, e, m, res = 0;
			scanf("%d%d%d", &s, &e, &m);
			s -= 540, e -= 540;
			for (int t = 0, in = 0; t < e; ++t)
			{
				in += stu[m][t];
				if (t >= s && in > 0)
					++res;
			}
			printf("%d\n", res);
		}
	}
}

Measured memory_bytes: 28000
n = int(input())
tableh = [0 for _ in range(n)]
tableuk = [0 for _ in range(n)]

for i in range(n):
    a = int(input())
    for _ in range(a):
        x, y = map(int, input().split())
        x -= 1
        if y == 1:
            tableh[i] |= 1 << x
        else:
            tableuk[i] |= 1 << x

ans = 0


def popcount(n):
    return bin(n)[2:].count('1')


def same(x, y):
    return popcount(x) + popcount(y) == popcount(x ^ y)

for i in range(1 << n):
    honest = 0
    unkind = 0
    for j in range(n):
        if (i >> j) & 1 != 0:  # P_j is honest
            honest |= tableh[j]
            unkind |= tableuk[j]
    if ((~i & honest) == 0) and ((i & unkind) == 0):
        ans = max(ans, popcount(i))

print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define REP(i, N) for(int i = 0; i < N; ++i)
#define REEP(i, N) for(int i = N - 1; i >= 0; --i)
#define ALL(a) (a).begin(),(a).end()
#define FOR(i,m,n) for(int i = m; i < n; ++i)
#define RFOR(i,m,n) for(int i = n - 1; i >= m; --i)
#define CIN(a) cin >> a
#define CIN2(a, b) cin >> a >> b
#define CIN3(a, b, c) cin >> a >> b >> c
#define COUT(a) cout << a << endl
#define COUT2(a, b) cout << a << " " << b << endl
#define COUT3(a, b, c) cout << a << " " << b << " " << c << endl
#define pb push_back
#define PB push_back
#define VINT(v, n) vector<int> v(n); REP(i, n) { v[i] = 0 }
#define VINT2(v, n, m) vector<vector<int> > v(n, vector<int>(m)); REP(i, n) { REP(j, m) { v[i][j] = 0 } }
#define VCHAR(v, n) vector<char>v(n)
#define KIRIAGE(a, b) a += (b - a % b) % b
#define CEIL(c, a, b) if(a % b == 0) { c = a / b;} else { c = a / b + 1;}
#define sp(n) setprecision(n)
#define INF 1000000000
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef long long ll;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
	vector<int> v(26, 0);
	string w;
	CIN(w);
	REP(i, w.size()) {
		char c;
		c = w[i];
		++v[c - 'a'];
	}
	bool f = true;
	REP(i, 26) {
		if(v[i] % 2 != 0) {
			f = false;
			break;
		}
	}
	if(f) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int a;
	cin >> a;
	while (a >= 10)a %= 10;
	if (a == 2 || a == 4 || a == 5 || a == 7 || a == 9)cout << "hon"; 
	if (a == 0 || a == 1 || a == 6 || a == 8)cout << "pon"; 
	if (a == 3)cout << "bon"; 
	return 0;
}

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

ll n;
int main()
{
    int t;
    cin >> t;
    if (t >= 30)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <algorithm>
#include <string>

using namespace std;

string divide[4] = {"dream","dreamer","erase","eraser"};

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

    reverse(s.begin(),s.end());
    for(int i = 0;i < 4;i++)
        reverse(divide[i].begin(),divide[i].end());

    bool can = true;
    for(int i = 0;i < s.size();){
        bool can2 = false;
        for(int j = 0;j < 4;j++){
            string d = divide[j];
            if(s.substr(i,d.size()) == d){
                can2 =true;
                i += d.size();
            }
        }
        if(!can2){
            can = false;
            break;
        }
    }

    if(can)
        cout << "YES" << endl;
    else
    {
        cout << "NO"  << endl;
    }
    
    

}

Measured memory_bytes: 3760
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>

using namespace std;

int a = 0, b = 0, c = 100, d = 0, e = 0, n = 0, maxy = 0, mini = 9999, ans = 0, counter = 0, sur = 0;
std::vector<unsigned long long int> vec{}, vecniki{};
int yoko = 0, tate = 0;
int arraykun[2300] = {}, nyan[200] = {}, koji[50][50];
std::string output, output2, str, input;
int kakunou[50][50] = { 53 }, moji[50];
bool okada = false, sink = false, backsink = false;
char one, two;
int dp(int i, int j) {
	bool okada = true;
	if (i == 0 || j == 0) {
		okada = false;
		return 0;
	}
	if (koji[i][j] == -1) {
		okada = false;
		return 0;
	}
	if (i == 1 && j == 1) {
		okada = false;
		return 1;
	}
	if (okada) {
		return dp(i - 1, j) + dp(i, j - 1);
	}

}
int main()
{

	cin >> input;
	for (int i = 0; i < input.size() - 2; i++) {
	
		str = input.substr(i, 3);
		sur = std::stoi(str);
		ans = std::abs(sur - 753);

		if (ans < mini) {
			mini = ans;
		}
		str = {};
	}
	cout << mini << endl;
}






Measured memory_bytes: 256
import sys
import math
from collections import deque
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def S(): return sys.stdin.readline()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h,w): return [[i for j in range(w)] for k in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)


S = input()
num = [0]*(len(S)+1)
p = 1
d = {}
d[0] = 1
for i in range(len(S)-1,-1,-1):
    num[i] = int(S[i])*p + num[i+1]
    p = p*10%2019
    mod = num[i]%2019
    d[mod] = d.get(mod,0)+1
ans = 0
for i in d:
    m = d[i]
    ans += int(m*(m-1)/2)
print(ans)


Measured memory_bytes: 75068
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    char[] c = sc.next().toCharArray();
    int[] cnt = new int[26];
    Map<Character,Integer> map = new HashMap<>();
    Map<Integer,Character> map2 = new HashMap<>();
    int k=0;
    for(char x='a';x<='z';x++){
      map.put(x,k);
      map2.put(k,x);
      k++;
    }
    for(int i=0;i<c.length;i++)cnt[map.get(c[i])]++;
    for(int i=0;i<26;i++){
      if(cnt[i]==0){
        for(int j=0;j<c.length;j++)System.out.print(c[j]);
        System.out.println(map2.get(i));
        return;
      }
    }
    int idx = 0;
    for(int i=25;i>=1;i--){
      if(c[i-1]<=c[i]){
        idx=i;
        break;
      }
    }
    if(idx==0){
      System.out.println(-1);
      return;
    }
    char min = 'z';
    for(int i=idx;i<26;i++){
      if(c[idx-1]<c[i]&&c[i]<min){
        min=c[i];
      }
    }
    for(int i=0;i<idx-1;i++)System.out.print(c[i]);
    System.out.println(min);
  }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
   ll n,k,sum=0;
   cin>>n>>k;
   ll a[n];
   for(int i=0;i<n;i++)cin>>a[i];
   sort(a,a+n);
   for(int i=0;i<k;i++)sum+=a[i];
   cout<<sum<<endl;

}


Measured memory_bytes: 3592
#include <stdio.h>

int main() {
	long long n;
	long long hasil=1;
	
	scanf("%lld", &n);
	long long input[n];
	
	for(int i=0; i<n; i++){
		scanf("%lld", &input[i]);
	}
	
	for(int i=0; i<n; i++){
		if(input[i]==0){
			printf("0\n");
			return 0;
		}
	}
	
	for(int i=0; i<n; i++){
		if(input[i]<=1000000000000000000/hasil){
			hasil *= input[i];
		}
		else {
			printf("-1\n");
			return 0;
		}
	}
	
	printf("%lld\n", hasil);
	
	
	
	return 0;
}

Measured memory_bytes: 2416
#include <bits/stdc++.h>
using namespace std;typedef long long ll;typedef vector<ll> vl;typedef vector<vl> vvl;typedef pair<ll,ll> pl;typedef vector<pl> vp;const ll INF=1001001001;const ll LINF=1001001001001001001;const ll D4[]={0,1,0,-1,0};const ll D8[]={0,1,1,0,-1,-1,1,-1,0};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;}
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()

void solve(long long X, long long Y, long long Z){
    cout<<Z<<' '<<X<<' '<<Y<<endl;
}

int main(){
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    long long Z;
    scanf("%lld",&Z);
    solve(X, Y, Z);
}


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

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

    long long n;
    cin >> n;
    map<long long, long long> mp;
    long long t = 0;
    for(long long i = 0; i < n; i++){
        long long a;
        cin >> a;
        t += a;
        mp[a]++;
    }

    long long q;
    cin >> q;
    while(q--){
        long long b, c;
        cin >> b >> c;
        long long b_count = mp[b];
        t -= b * b_count;
        t += c * b_count;
        mp[b] = 0;
        mp[c] += b_count;
        cout << t << endl;
    } 

    return 0;
}

Measured memory_bytes: 9452
n = list(map(int, list("0" + input())))
ans = 0
for i in range(len(n)):
    check = int(n[-i-1])
    if 0 <= check <= 4:
        ans += check
    elif 6 <= check <= 9:
        ans += 10 - check
        temp = 2
        while n[-i-temp] == 9:
            n[-i-temp] = (int(n[-i-temp]) + 1) % 10
            temp += 1
        else:
            n[-i-temp] = (int(n[-i-temp]) + 1) % 10
    else:
        ans += 5
        check2 = n[-i-2]
        if check2 >= 5:
            temp2 = 2
            while n[-i-temp2] == 9:
                n[-i-temp2] = (int(n[-i-temp2]) + 1) % 10
                temp2 += 1
            else:
                n[-i-temp2] = (int(n[-i-temp2]) + 1) % 10
print(ans)

Measured memory_bytes: 20708
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

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

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

n = I()
def base(n, b, digits="abcdefghijklmnopqrstuvwxyz"):
    s = []
    while n>0:
        n -= 1
        s.append( digits[(n%b)] )
        n //= b
    return ''.join(reversed(s))

ans = base(n,26)

print(ans)

Measured memory_bytes: 72704
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

public class Main {

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		StringBuilder builder = new StringBuilder();
		int n = Integer.parseInt(reader.readLine());
		Deque<Integer> deque = new ArrayDeque<Integer>();
		for (int i = 0; i < n; i++) {
			String[] line = reader.readLine().split(" ");
			String name = line[0];

			if (name.equals("deleteFirst"))
				deque.pollFirst();
			else if (name.equals("deleteLast"))
				deque.pollLast();
			else {
				int num = Integer.parseInt(line[1]);
				if (name.equals("insert"))
					deque.push(num);
				else
					deque.remove(num);
			/*System.out.println(deque.stream().map(String::valueOf)
					.collect(Collectors.joining(", ", "[", "]")));*/
			}
		}
		int size = deque.size();
		for (int i = 0; i < size; i++) {
			if (0 < i)
				builder.append(" ");
			builder.append(deque.pollFirst());
		}
		System.out.println(builder);
	}
}

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

int main(){
  int a,b;
  cin >>a>>b;
  if (a%3==0 || b%3==0 || (a+b)%3==0){
    cout << "Possible" << endl;
  }
  else {
    cout << "Impossible" << endl;
  }
}


Measured memory_bytes: 256
using System;

class Program{
	private static void Main()
    {
      int n = int.Parse(Console.ReadLine());
      string[] str = Console.ReadLine().Split(' ');
      
      int[] a = new int[n];
      for(int i = 0; i < n; i++)
      {
        a[i] = int.Parse(str[i]);
      }
      
      int num = 0;
      int count = 0;
      
      for(int i = 0; i < n; i++)
      {
        if(a[i] != num + 1)
          count++;
        else
          num++;
        
        if(i == n - 1 && num == 0)
          count = -1;
      }
      
      Console.WriteLine(count);
    }
}


Measured memory_bytes: 31068
import numpy as np
import itertools
N, M = map(int, input().split())
x = [0] * N
y = [0] * N
z = [0] * N
for i in range(N):
    x[i], y[i], z[i] = map(int, input().split())

x = np.array(x)
y = np.array(y)
z = np.array(z)

ans = 0
vals = []
for op1,op2,op3 in itertools.product([-1,1],repeat=3):
    #print(op1,op2,op3)
    s = x*op1 + y*op2 + z*op3
    #print(s)
    s.sort()
    vals.append(s[N-M:].sum())


print(max(vals))

Measured memory_bytes: 13676
#include<bits/stdc++.h>
using namespace std;
int main() {
  long h,w;
  cin>>h>>w;
  if (h==1 || w==1) cout<<1<<endl;
  else if (h%2==0 || w%2==0) cout<<h*w/2<<endl;
  else cout<<(h*w+1)/2<<endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	//	"strings"
)

func main() {
	sc := NewScanner()

	n := sc.NextInt()
	k := sc.NextInt()
	q := sc.NextInt()

	arr := make([]int, n)
	for i := 0; i < q; i++ {
		tmp := sc.NextInt()
		arr[tmp-1]++
	}
	//	fmt.Printf("%+v\n", arr) // output for debug
	for i := 0; i < n; i++ {
		if q-(k+arr[i]) < 0 {
			fmt.Printf("Yes\n") // output for debug
		} else {
			fmt.Printf("No\n") // output for debug
		}
	}
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 3456
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var S = ReadLine();
            var K = Sarray()[0];
            var i = 0;
            for (i = 0; i < S.Length; ++i)
                if (S[i] != '1') break;
            if (K <= i)
                WriteLine(1);
            else
                WriteLine(S[i]);
        }


        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 28220
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N, T, A;
    cin >> N >> T >> A;
    int e = 1,ans;
  double f = 1e9;
    for(int i = 0; i < N; i++){
      int H;
      cin >> H;
      double b = T - H * 0.006;
        if(abs(A - b) < f){
          ans = e;
          f = abs(A - b);
        }
      e++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;
typedef vector<LL> 		VL;
typedef unsigned long long int ULL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define LET(x,a) __typeof(a) x(a)

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
//Works for forward as well as backward iteration

#define gu getchar
#define pu putchar
#define si(n) cin>>n
#define dout(n) cout<<n<<"\n"
//# define M_PI           3.14159265358979323846264338327950288

#define DRT() int t; si(t); while(t--)

#define PlUSWRAP(index,n) index = (index+1)%n		//index++; if(index>=n) index=0
#define MINUSWRAP(index,n) index = (index + n -1)%n 	//index--; if(index<0) index=n-1
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)	//Round off d to nearest integer

#define FLUSHN while(gu()!='\n')
#define FLUSHS while(gu()!=' ')

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
LL cnt[41];
int main() {
	#ifndef ONLINE_JUDGE
    freopen("../input.txt", "r", stdin);
    freopen("../output.txt", "w", stdout);
	#endif
	srand(chrono::steady_clock::now().time_since_epoch().count());
	off;
	LL n,k;
	cin>>n>>k;
	LL a;
	rep(i,0,n){
		cin>>a;
		int ind = 0;
		while(a){
			if(a&1)
				cnt[ind]++;
			a = a>>1;
			ind++;
		}
	}
	LL ans = 0;
	for(int i=40;i>=0;i--){
		if((2*cnt[i] < n) && (k >= ((LL)1 << i))){
			// cout<<"i : "<<i<<"\n";
			ans += (n - cnt[i]) * ((LL)1 << i);
			k -= ((LL)1 << i);
		}	
		else{
			ans += cnt[i] * ((LL)1 << i);
		}
	}
	cout<<ans;
  	return 0;
}

Measured memory_bytes: 3664
// #include <atcoder/all>
// using namespace atcoder;
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
using namespace std;
using ll = long long;
template<typename T>
inline bool chmax(T& a, const T& b) {
    if (a < b){
        a = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
/**
 * @brief 多次元 vector の作成
 * @author えびちゃん
 */
namespace detail {
    template<typename T, int N>
    auto make_vec(vector<int>& sizes, T const& x) {
        if constexpr (N == 1) {
            return vector(sizes[0], x);
        } else {
            int size = sizes[N-1];
            sizes.pop_back();
            return vector(size, make_vec<T, N-1>(sizes, x));
        }
    }
}
template<typename T, int N>
auto make_vec(int const(&sizes)[N], T const& x = T()) {
    vector<int> s(N);
    for (int i = 0; i < N; ++i) s[i] = sizes[N-i-1];
    return detail::make_vec<T, N>(s, x);
}
__attribute__((constructor))
void fast_io() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int main() {
    int n;
    cin >> n;
    int cnt = 0;
    bool ans = false;
    rep(i, n) {
        int a, b;
        cin >> a >> b;
        if (a == b) {
            cnt++;
        } else {
            cnt = 0;
        }
        if (cnt >= 3) ans = true;
    }
    cout << (ans ? "Yes\n" : "No\n");
}

Measured memory_bytes: 3636
#include<iostream>
#include<map>
#include<string>
#include<algorithm>
#include<sstream>
using namespace std;

map<int,int>ta;
int t[1111];

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

    for(int i=0;i<n;i++){
        for(int j=0;j<6;j++){
            if(i+j>=n)break;
            string tmp="";
            for(int k=i;k<=i+j;k++)tmp+=(t[k]+'0');
            int hoge;
            stringstream ss;
            ss<<tmp;
            ss>>hoge;
            ta[hoge]++;
        }
    }    
    for(int i=0;i<=10000000;i++){
        if(ta[i]==0){
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3380
from itertools import permutations
N = input()
P = tuple([int(_) for _ in input().split()])
Q = tuple([int(_) for _ in input().split()])
pl = list(permutations(P))
pl.sort()
ql = list(permutations(Q))
ql.sort()

pi = pl.index(P)+1
qi = ql.index(Q)+1
print(abs(pi-qi))


Measured memory_bytes: 83032
#include <iostream>
#include <vector>
using namespace std;
int main( void )
{
	while ( 1 )
	{
		char c;
		vector <int> a(10);
		vector <int> b(10);

		if ( !( cin >> c ) )
			break;
		a[0] = (int)(c-'0');
		for ( int i = 1; i < 10; i++ )
		{
			cin >> c;
			a[i] = (int)(c-'0');
		}

		for ( int i = 10; i > 1; i-- )
		{
			for ( int j = 0; j < i; j++ )
			{
				b[j] = ( a[j] + a[j+1] ) % 10;
			}
			a = b;
		}

		cout << a[0] << endl;

	}
	return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		int testNum;
		int judgeAC = 0;
		int judgeWA = 0;
		int judgeTLE = 0;
		int judgeRE = 0;


		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

		try {
			testNum =Integer.parseInt(reader.readLine());

			for (int i = 0; i < testNum; i++) {
				String judge = reader.readLine();
//				if (judge == "AC") {
//					judgeAC++;
//				}
				if (judge.equals("AC")) {
					judgeAC++;
				}
				else if (judge.equals("WA")) {
					judgeWA++;
				}
				else if (judge.equals("TLE")) {
					judgeTLE++;
				}
				else if(judge.equals("RE")) {
					judgeRE++;
				}
			}
			System.out.println("AC x "+judgeAC);
			System.out.println("WA x "+judgeWA);
			System.out.println("TLE x "+judgeTLE);
			System.out.println("RE x "+judgeRE);

		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}

	}

}


Measured memory_bytes: 42928
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;
int main(){
    string n;cin>>n;
    cout<<"ABC"<<n<<endl;
    return 0;
}


Measured memory_bytes: 3600
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}

debug dbg;

class AABD {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    int n;
	    in >> n;
	    if(n < 1000) out << "ABC" << endl;
	    else out << "ABD" << endl;
	}
};


int main() {
	AABD solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

public class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();
		int max=0;
		for(int i=0; i<N; i++) {
			int in=sc.nextInt();
			int out=sc.nextInt();
			M-=(out-in);
			if(M<0) {
				pl(0);
				System.exit(0);
			}
			else {
				max=Math.max(max, M);
			}
		}
		pl(max);
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
}



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

int main() {
    int n, a[10000];
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int min =  1000000;
    int max = -1000000;
    long long sum = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] < min) {
            min = a[i];
        }
        if (a[i] > max) {
            max = a[i];
        }
        sum += a[i];
    }
    printf("%d %d %lld\n", min, max, sum);
    return 0;
}


Measured memory_bytes: 3208
#include<bits/stdc++.h>
#define ll long long
#define rep(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
int main()
{
  string s;
  int w,a;
  cin >> s;
  cin >> w;
  rep(i,s.length())if(w*i<s.length())cout<<s[w*i];
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
#ifdef LOCAL
#define debug(x) cerr << #x << ": " << x << endl
#else
#define debug(x)
#endif
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int N;
int d[50];

signed main(){
	cin >> N;
	rep(i, N) cin >> d[i];

	int ans = 0;
	rep(i, N){
		rep(j, N){
			if(i >= j) continue;
			ans += d[i] * d[j];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES // M_PIなどの定義を使用するのに必要
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>
#include <limits>

using namespace std;

int main()
{
  int64_t K, A, B;

  cin >> K >> A >> B;

  for (int64_t i = A; i <= B; i++) {
    if (i % K == 0) {
      cout << "OK";
      return 0;
    }
  }

  cout << "NG";
  return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<cstdio>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#include<numeric>
#include<queue>
#include<functional>
#include<cassert>
#include<set>
#define rep(a,b) for(int a=0;a<b;++a)
#define REP(a,b,c,d) for(int a=b;a<c;a+=d)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define mod 1000000007
using namespace std;
using ll = long long;
using p_i = pair<int, int>;
int main() {
	ll N, M;	cin >> N >> M;
	ll ans = (1900 * M + 100 * (N - M))*pow(2, M);
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

//Triangle of Blocks
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		boolean[] tri = new boolean[1000001];
		for(int i=1;i*(i+1)>>1<=1000000;i++){
			tri[i*(i+1)>>1] = true;
		}
		int[] a = new int[1000001];
		for(;;){
			int n = sc.nextInt();
			if(n==0)break;
			int sum = 0;
			for(int i=1;i<=n;i++){
				a[i] = sc.nextInt();
				sum+=a[i];
			}
			if(tri[sum]){
				int res = 0;
				int R = n;
				boolean f = false;
				while(res <= 10000){
					f = true;
					for(int i=1;i<=R&&f;i++)f&=i==a[i];
					if(f)break;
					int L = 1;
					for(int i=1;i<=R;i++){
						if(a[i]==1)continue;
						a[L++] = a[i]-1;
					}
					a[L] = R;
					R = L;
					res++;
				}
				if(f){
					System.out.println(res); continue;
				}
			}
			System.out.println(-1);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 27748
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

long long MOD = 1e9+7;
int MAX_INT = 1e9;

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

  string S;
  cin >> S;
  string hitachi = "";
  for(int i = 0; i < 5 ; i++) {
    hitachi += "hi";
    if(hitachi == S) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;

  return 0;
}


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

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

    vector<int> a(n),b(n-1);
    for(int i=0; i<n-1; i++){
        cin>>b[i];
    }

    int sum=0;
    a[n-1]=b[n-2];
    sum+=a[n-1];

    for(int i=n-2; i>0; i--){
        if(b[i-1]>b[i]){
            a[i]=b[i];
        }else{
            a[i]=b[i-1];
        }
        sum+=a[i];
    }

    a[0]=b[0];
    sum+=a[0];

    cout<<sum<<endl;
}


Measured memory_bytes: 256
#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>

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

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int m;
string s;
vector<string> vs;

int main(){
	cin >> m;
	REP(i, m){
		vs.clear();
		//ll ans = 0;
		cin >> s;
		FOR(j, 1, s.size()){
			string t[4];
			t[0] = s.substr(0, j);
			t[1] = s.substr(j, s.size() - j);
			t[2] = t[0]; t[3] = t[1];
			reverse(ALL(t[2])); reverse(ALL(t[3]));
			REP(i, 4){
				REP(j, 4){
					if (i % 2 == 0){
						if (j % 2 == 1 && find(ALL(vs), t[i] + t[j]) == vs.end()){
							vs.push_back(t[i] + t[j]);
						}
					}
					else {
						if (j % 2 == 0 && find(ALL(vs), t[i] + t[j]) == vs.end()){
							vs.push_back(t[i] + t[j]);
						}
					}
				}
			}
		}
		cout << vs.size() << endl;
	}
}

Measured memory_bytes: 1276
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int N;
char S[100000]={'\0'};
scanf("%d",&N);
scanf("%s",&S);
int i=0;
int count=1;

while (i<N-1){
    if (S[i]==S[i+1]) {i++;}
    else if (S[i]!=S[i+1]) {count++;i++;}
}
printf("%d",count);
 return EXIT_SUCCESS;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"io"
	"log"
	"os"
)

func solve(in io.Reader, out io.Writer) error {
	content := make([]byte, 0)

	for i := 0; i < 3; i++ {
		var txt string
		fmt.Fscan(in, &txt)
		content = append(content, txt[i])
	}

	fmt.Fprintln(out, string(content))
	return nil
}

func main() {
	err := solve(os.Stdin, os.Stdout)
	if err != nil {
		log.Fatal(err)
	}
}


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

int main(){
    ll N; cin >> N;
    ll ans = 0;
    vector<ll> V(N);
    rep(i, 0, N) cin >> V[i];
    rep(i, 0, N) ans += V[i] - (i + 1);

    cout << ans << endl;
}


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

using namespace std;

vector<long long> getPrime(int maxN){
    vector<int> p(maxN+1, 1);
    vector<long long> res(1, 2);
    for(int i=3;i<=maxN;i+=2){
        if(!p[i]) continue;
        res.push_back(i);
        for(int j=2*i;j<=maxN;j+=i) p[j] = 0;
    }
    return res;
}

int main(){
    auto primes = getPrime(100000);
    map<long long, int> sqr;
    for(auto& p : primes) sqr[p*p] = p;
    int N;
    while(cin >> N){
        vector<pair<pair<long long, long long>, int>> vp;
        for(int i=0;i<N;i++){
            long long s; cin >> s;
            long long a[3] = {1, 1, 1};
            for(int j=0;j<primes.size();j++){
                if(primes[j] * primes[j] * primes[j] > s) break;
                int cnt = 0;
                while(s % primes[j] == 0){
                    cnt = (cnt == 2 ? 0 : cnt+1);
                    s /= primes[j];
                }                
                a[cnt] *= primes[j];
            }
            if(sqr.count(s)){
                a[2] *= sqr[s];
            } else {
                a[1] *= s;
            }
            bool rev =(a[1] > a[2]);
            if(rev) swap(a[1], a[2]);
            vp.emplace_back(make_pair(a[1], a[2]), rev ? -1 : 1);
        }
        sort(vp.begin(), vp.end());
        int res = 0;
        for(int i=0;i<vp.size();){
            int j = i;
            int a = 0, b = 0;
            while(j < vp.size() && vp[i].first == vp[j].first){
                if(vp[j].second == 1) a++;
                else b++;
                ++j;
            }
            if(vp[i].first.first == vp[i].first.second) ++res;
            else res += max(a, b);
            i = j;
        }
        cout << res << endl;
    }
}

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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

void bfs(const vvi& G, vi& d, int root) {
    int n = G.size();

    queue<int> q;
    vb seen(n, false);

    q.push(root);
    seen[root] = true;
    d[root] = 0;

    while (!q.empty()) {
        int curr = q.front();
        q.pop();

        for (int next : G[curr]) {
            if (seen[next]) { continue; }

            q.push(next);
            seen[next] = true;
            d[next] = d[curr] + 1;
        }
    }
}

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

    int n, u, v;
    cin >> n >> u >> v;
    --u;
    --v;

    vvi G(n);
    rep(i, 0, n - 1) {
        int a, b;
        cin >> a >> b;
        G[a - 1].push_back(b - 1);
        G[b - 1].push_back(a - 1);
    }

    // O(n)
    vi from_u(n, -1), from_v(n, -1);
    bfs(G, from_u, u);
    bfs(G, from_v, v);

    // uとvの間の距離．
    int dist = from_u[v];

    int ans = 0;
    rep(i, 0, n) {
        // uとvの直線上にある場合．
        if (from_u[i] + from_v[i] == dist) {
            ans = max(ans, dist - 1);
            continue;
        }

        // uとvの間にあり，直線上にない場合．
        int d = abs(from_u[i] - from_v[i]);
        if (d < dist) {
            if (from_u[i] < from_v[i]) {
                int tmp = from_u[i] + d - 1;
                ans = max(ans, tmp);
            }
            continue;
        }

        // uとvの間にない場合．
        if (from_u[i] < from_v[i]) {
            int tmp = from_u[i] + dist - 1;
            ans = max(ans, tmp);
        }
    }

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

Measured memory_bytes: 6656
import sys
def input():return sys.stdin.readline()[:-1]
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())

D=N()
c=[0]+L()
s=[[0]*27]+[[0]+L() for i in range(D)]

dp=[]
T=[0]
ld=[0]*(27)
for i in range(1,D+1):
    ma=0
    t=0
    for j in range(1,27):
        tmp=s[i][j]+(i-ld[j])*(D-i+1)*c[j]
        if tmp>ma:
            ma=tmp
            t=j
    T.append(t)
    ld[t]=i
        
sc=sum(c)
def point():
    ld=[0]*(27)
    score=-sc*((D+1)*D//2)
    for i in range(1,D+1):
        t=T[i]
        score+=s[i][t]+(i-ld[t])*(D-i+1)*c[t]
        ld[t]=i
    return score

now=point()
import random
for i in range(500000):
    d1,q1=random.randrange(1,D+1),random.randrange(1,27)
    d2,q2=random.randrange(1,D+1),random.randrange(1,27)
    old1=T[d1]
    old2=T[d2]
    T[d1]=q1
    T[d2]=q2
    new=point()
    if new>now:
        now=new
    else:
        T[d1]=old1
        T[d2]=old2

for i in T[1:]:
    print(i)

Measured memory_bytes: 84168
from collections import defaultdict
a = int(input())
dic = defaultdict(int)
l = []
for i in range(a):
    l.append("".join(sorted(list(input()))))
    dic[l[-1]]+=1
s = 0
L = set(l)
for j in L:
    i = dic[j]
    s+=i*(i-1)/2
print(int(s))


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

int main()
{	
	char r[5], a[5];

	cin >> r >> a;

	while (atoi(r) != 0 || atoi(a) != 0) {
		int h = 0, b = 0;

		for (int i = 0; i < 4; i++) {
			for(int j = 0; j < 4; j++)
				if (r[i] == a[j]) {
					if (i == j)
						h++;
					else
						b++;
				}
		}

		cout << h << " " << b << endl;
		cin >> r >> a;
	}

	return 0;
}



Measured memory_bytes: 3000
import itertools
from collections import Counter
 
N = int(input())
V = [int(x) for x in input().split()]
EV_counter = Counter(V[::2])
OD_counter = Counter(V[1::2])
 
# 1種類しかないとき対策
EV_counter[-1] = 0
OD_counter[-2] = 0
 
# 上位2種しか使う必要がない
EV = EV_counter.most_common(2)
OD = OD_counter.most_common(2)
 
answer = N
for (k1,v1), (k2,v2) in itertools.product(EV,OD):
    if k1 == k2:
        continue
    x = (N - v1 - v2)
    if answer > x:
        answer = x

print(answer)

Measured memory_bytes: 18528
# https://atcoder.jp/contests/abc100/tasks/abc100_d

from itertools import product

N, M, *XYZ = map(int, open(0).read().split())

P = tuple(product((1, -1), repeat=3))

A = [[] for _ in range(8)]
for x, y, z in zip(*[iter(XYZ)] * 3):
    for i, (a, b, c) in enumerate(P):
        A[i].append(a * x + b * y + c * z)

cand = []
for i in range(8):
    A[i].sort(reverse=True)
    cand.append(sum(A[i][:M]))

print(max(cand))


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

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

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

    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    REP(i, N) cin >> A[i];
    if (*max_element(ALL(A)) < K) {
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    int g = 0;
    for (int a : A) g = gcd(g, a);
    if (K % g == 0) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
}

Measured memory_bytes: 640
n = int(input())
a = list(map(int, input().split()))

if n == 2:
  print(max(a), min(a))
  exit()

n = max(a)

temp = n / 2
dif = 10 ** 9
r = -1
for i in a:
  if abs(temp - i) < dif:
    dif = abs(temp-i)
    r = i

print(n, r)

Measured memory_bytes: 14432
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int mxN = 2e5 + 5;
int vis[mxN];
// ll id[mxN];
ll cnt = 0;
vector<ll> g[mxN];
void dfs(int u,int pt){
    vis[u] = 1;
    // cout<<u<<'\n';
    for(auto it : g[u]){
        if(it==pt || vis[it]!=0)
            continue;
        // id[it] = id[u];
        cnt++;
        dfs(it,u);
    }
}
void solve(){
    ll n,m;
    cin>>n>>m;
    // vector<ll> g[n];
    for(int i =0;i<m;i++){
        int x,y;
        cin>>x>>y;
        x--;
        y--;
        g[x].pb(y);
        g[y].pb(x);
    }
    // cout<<"hi";
    ll ans = 0;
    
    ll mxid = 0;
    for(int i =0;i<n;i++){
        if(!vis[i]){
            // ans++;
            // id[i] = ans;
            cnt = 1;
            dfs(i,-1);
            mxid = max(cnt,mxid);
            // cout<<i<<'\n';
        }
    }
    // for(int i =0;i<n;i++){
    //     cout<<id[i]<<" ";
    //     mxid = max(mxid,id[i]);
    // }
    cout<<mxid<<'\n';
}
int main(){
    IOS
    int tt;
    tt = 1;
    // cin>>tt;
    while(tt--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 24700
#include <iostream>

using namespace std;

int main()
{
    long long h,n,a,sum=0;
    cin>>h>>n;
    for (long long i=0;i<n;i++){
        cin>>a;
        sum+=a;
    }
    if (sum>=h) cout<<"Yes";
    else cout<<"No";
    

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int
#define fastscan ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define error(x) cout << #x <<": " << x <<"\n"
#define exit exit(0);

using namespace std;



int32_t main(){

    fastscan;

    int n,k;

    cin >> n >> k;

    if((k << 1) - 1 <= n){
        cout << "YES\n";
    }else{
        cout << "NO\n";
    }

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int[] p = new int[n];
		for (int i = 0; i < n; i++)
			p[i] = in.nextInt();
		System.out.println(solve(p));
		in.close();
	}

	private static int solve(int[] p) {
		int r = 0;
		for (int i = 1; i < p.length - 1; i++)
			if (p[i - 1] < p[i] && p[i] <= p[i + 1])
				r++;
			else if (p[i] > p[i + 1] && p[i] <= p[i - 1])
				r++;
		return r;
	}
}


Measured memory_bytes: 21844