akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>

#define rep(i,n)         for(int i=(int)0; i<(int)n; i++)
#define REP(i,m,n)       for(int i=(int)m; i<(int)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define prt(var)         cout << var << endl
#define prtd(n, var)     cout << fixed << setprecision(n) << var << endl
#define prt2(v1, v2)     cout << v1 << " " << v2 << endl
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << endl
#define prtall(var)      rep(i,var.size()){cout << var[i] << " ";} cout << endl

//----------------------------------------------------------------

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

  arr(a,n);

  int num=0;
  rep(i,n){
    if(a[i]==num+1){
      num++;
    }
  }

  if(num==0){
    prt(-1);
  } else {
    prt(n-num);
  }
}


Measured memory_bytes: 1024
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1 for _ in range(n)]  # 各要素の親 自分が根の場合は -1 * (木の要素数)

    def root(self, x):  # xが属する木の根を返す
        if self.parents[x] < 0:  # 自分が根の場合
            return x
        else:
            self.parents[x] = self.root(self.parents[x])
            return self.parents[x]

    def merge(self, x, y):  # xが属する木とyが属する木を合体する
        x_root = self.root(x)  # xの根
        y_root = self.root(y)  # yの根

        if x_root == y_root:  # 同じ木に属する
            return

        if self.parents[x_root] > self.parents[y_root]:  # x_rootの要素数 > y_rootの要素数 にしたい
            x_root, y_root = y_root, x_root

        self.parents[x_root] += self.parents[y_root] # x_rootにy_rootを合体
        self.parents[y_root] = x_root


def main():
    h, w = map(int, input().split())
    grid = [list(input()) for _ in range(h)]
    black_list = []
    uf = UnionFind(h * w)

    for r in range(h):
        for c in range(w):
            if grid[r][c] == "#":
                black_list.append([r, c])
            for dr, dc in [[0, 1], [1, 0]]:
                nr = r + dr
                nc = c + dc
                if not (0 <= nr < h and 0 <= nc < w):
                    continue
                if grid[r][c] != grid[nr][nc]:
                    # 0 to h*w-1 に変換
                    uf.merge(r * w + c, nr * w + nc)

    ans = 0
    black_dict = dict()
    for r, c in black_list:  # それぞれの黒マスに対して
        z = uf.root(r * w + c)  # 根を求める
        if z in black_dict:  # それぞれの木に何個黒マスがあるか
            black_dict[z] += 1
        else:
            black_dict[z] = 1

    for index, size in enumerate(uf.parents):
        if size < 0:  # それぞれの木に対して
            if index not in black_dict:  # 黒マス0コは無視
                continue
            ans += black_dict[index] * (- size - black_dict[index])  # 黒マス x 白マス

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 108660
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Arrays;
import java.util.Collections;
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int A = scan.nextInt();
    int P = scan.nextInt();
    A = (A * 3 + P) / 2;
    System.out.println(A);
  }
}


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

const ll p = 998244353;

string a, b;
int k, s, val[10005][10005];
ll fact[10005], invfact[10005];

ll exp(ll x, ll k) {
	if (k == 0)
		return 1;
	if (k%2 == 1)
		return x*exp(x, k-1)%p;
	ll y = exp(x, k/2);
	return y*y%p;
}

ll inv(ll x) { return exp(x, p-2); }

ll binom(ll x, ll y) {
	if (x < 0 || y < 0 || x < y)
		return 0;
	return fact[x]*invfact[y]%p*invfact[x-y]%p;
}

int main() {
	cin >> a >> b;
	for (int i = 0; i < a.length(); ++i) {
		k += (a[i] - '0');
		s += (a[i] - '0')*(b[i] - '0');
	}

	s = k-s;

	for (int i = 0; i < 10005; ++i) {
		if (i == 0)
			fact[i] = invfact[i] = 1;
		else {
			fact[i] = i*fact[i-1]%p;
			invfact[i] = inv(fact[i]);
		}
	}

	for (int i = 0; i < 10005; ++i)
		for (int j = 0; j < 10005; ++j) {
			if (i == 0 && j == 0) {
				val[i][j] = 1;
				continue;
			} if (i > 0) {
				val[i][j] = (val[i][j] + 1LL*i*i*val[i-1][j])%p;
			} if (j > 0) {
				val[i][j] = (val[i][j] + 1LL*i*j*val[i][j-1])%p;
			}
		}

	ll ans = 0;

	for (int t = 0; t <= k-s; ++t) {
		ans = (ans + binom(k, s+t)*val[s][t]%p*fact[k-s-t]%p*fact[k-s-t]%p*binom(k-s, t));
		ans %= p;
	}

	cout << ans << endl;
}

Measured memory_bytes: 391552
use strict;
use warnings;

my $n = <>;
chomp $n;

my $in = <>;
chomp $in;
my @data = split(/ /, $in);

my $dir = 0;
my $pre = shift @data;
my $cnt = 1;
foreach (@data){
	if ($pre == $_){
	}elsif ($pre < $_){
		# 増加
		my $lDir = 1;
		if ($dir == 0){
			$dir = $lDir;
		}else{
			if ($dir != $lDir){
				$dir = 0;
				$cnt++;
			}
		}
	}else{
		# 減少
		my $lDir = 2;
		if ($dir == 0){
			$dir = $lDir;
		}else{
			if ($dir != $lDir){
				$dir = 0;
				$cnt++;
			}
		}
	}
	
	$pre = $_;
}

print $cnt."\n";


exit;


Measured memory_bytes: 17316
from sys import stdin, setrecursionlimit
input = stdin.buffer.readline

class UnionFind:
    def __init__(self, n):
        self.root = [i for i in range(n + 1)]
        self.size = [1] * (n + 1)
    def find(self, x):
        y = self.root[x]
        if x == y:
            return x
        else:
            z = self.find(y)
            self.root[x] = z
            return z
    def union(self, x, y):
        rx = self.find(x)
        ry = self.find(y)
        sx = self.size[rx]
        sy = self.size[ry]
        if rx == ry:
            return 0
        else:
            if sx >= sy:
                self.root[ry] = rx
                self.size[rx] = sx + sy
            else:
                self.root[rx] = ry
                self.size[ry] = sx + sy
        return sx * sy
    def check(self):
        print([self.find(i) for i in range(1, len(self.root))])

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]

uf = UnionFind(N)

for a, b in AB:
    uf.union(a, b)

cnt = [0] * (N + 1)
for i in range(1, N + 1):
    cnt[uf.find(i)] += 1
    
print(max(cnt))

Measured memory_bytes: 117320
#include <bits/stdc++.h> 
using namespace std; 
#define fori(i,k,n) for (int i = k; i < (n); i++)
int main(void) {
    int N;
    cin >> N;
    int arr[4] = {0};
    fori(i,0,N) {
        string s;
        cin >> s;
        if (s == "AC") arr[0]++;
        if (s == "WA") arr[1]++;
        if (s == "TLE") arr[2]++;
        if (s == "RE") arr[3]++;
    }
    cout << "AC x " << arr[0] << "\n";
    cout << "WA x " << arr[1] << "\n";
    cout << "TLE x " << arr[2] << "\n";
    cout << "RE x " << arr[3] << "\n";
    return 0;
}



Measured memory_bytes: 3592
#include <iostream>
#include <stdio.h>
#include <set>
#define llint long long

using namespace std;

llint n, m;
llint a[1005], mask[1005];
llint dp[1005][1<<12];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	llint b;
	for(int i = 1; i <= m; i++){
		cin >> a[i] >> b;
		llint x;
		for(int j = 0; j < b; j++){
			cin >> x;
			x--;
			mask[i] |= (1<<x);
		}
	}
	
	llint N = 1 << n;
	for(int i = 0; i <= m; i++){
		for(int j = 0; j < N; j++){
			dp[i][j] = 1e18;
		}
	}
	dp[0][0] = 0;
	for(int i = 0; i < m; i++){
		for(int j = 0; j < N; j++){
			dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
			dp[i+1][j|mask[i+1]] = min(dp[i+1][j|mask[i+1]], dp[i][j] + a[i+1]);
		}
	}
	if(dp[m][N-1] > (1e18)/2) cout << -1 << endl;
	else cout << dp[m][N-1] << endl;
	
	return 0;
}

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

int main() {
	int mi = 10, ans = 0;
	for(int i=0;i<5;i++) {
		int x; scanf("%d", &x);
		
		int rem = x%10;
		if(rem>0)
			mi = min(mi, rem);
		ans += (x-1)/10+1;
	}
	printf("%d\n", ans*10 - 10 + mi);
	
	return 0;
}

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

typedef long long ll;

char a, b;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> a >> b;
    if (a == 'H') {
        cout << b << endl;
    } else {
        if (b == 'H')
            cout << 'D' << endl;
        else
            cout << 'H' << endl;
    }

    return 0;
}



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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    string S;
    cin >> S;
    ll N = S.size();

    bool ok = true;
    rep(i, N / 2) {
        if (S[i] == S[N - 1 - i]) {
            continue;
        } else {
            ok = false;
        }
    }

    string T = "";
    rep2(i, 0, (N - 1) / 2) {
        T += S[i];
    }
    N = T.size();
    rep(i, N / 2) {
        if (T[i] == T[N - 1 - i]) {
            continue;
        } else {
            ok = false;
        }
    }
    N = S.size();
    string X = "";
    rep2(i, (N + 3) / 2 - 1, N) {
        X += S[i];
    }
    N = X.size();
    rep(i, N / 2) {
        if (X[i] == X[N - 1 - i]) {
            continue;
        } else {
            ok = false;
        }
    }
    cout << (ok ? "Yes" : "No") << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


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

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

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
    ios::sync_with_stdio(false);
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll ans = 0;

    if (k <= a) {
        ans = k;
    } else if (k <= a + b) {
        ans = a;
    } else {
        ans = a - (k - a - b);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3652
#include <stdlib.h>
#include <stdio.h>

int INFTY = 1000000000;
int counter = 0;

void merge(int A[], int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    int L[n1];
    int R[n2];
    for(int i=0; i<n1; i++) L[i] = A[left + i];
    for(int i=0; i<n2; i++) R[i] = A[mid + i];
    L[n1] = INFTY;
    R[n2] = INFTY;
    int i = 0;
    int j = 0;
    for(int k=left; k<right; k++){
        if(L[i] <= R[j]){
            A[k] = L[i];
            i = i + 1;
            counter = counter + 1;
        }
        else{
            A[k] = R[j];
            j = j + 1;
            counter = counter + 1;
        }
    }
}

void mergeSort(int A[], int left, int right){
    if(left+1 < right){
        int mid = (left + right)/2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int main(int argc, char** argv) {
    int N;
    scanf("%d",&N);
    int arr[N];
    for(int i=0; i<N; i++) scanf("%d", &arr[i]);


    mergeSort(arr, 0, N);

    for(int k=0; k<N-1; k++){
        printf("%d ",arr[k]);
    }
    printf("%d\n", arr[N-1]);
    printf("%d\n", counter);
    return 0;
}


Measured memory_bytes: 5648
#include<bits/stdc++.h>
using namespace std;
using ll=long long int;
ll mod=1e9+7;
int main()
{
    ll n;
    cin>>n;
    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
        if(n%i==0)
        {
            ans+=n/i-1;

        }
        else
        {
            ans+=n/i;
        }
        

    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 3632
import collections
n=int(input())
a=[]
for i in range(n):
    a.append(input())
a=list(collections.Counter(a).most_common())
b=a[0][1]
c=[]
for i in range(len(a)):
    c.append(a[i][0])
    if i+1==len(a):
        break
    if a[i+1][1]!=b:
        break
c=sorted(c)
for i in range(len(c)):
    print(c[i])

Measured memory_bytes: 45036
#include<cstdio>

using namespace std;

int main(){
    int n, y;
    scanf("%d %d", &n, &y);
    for(int i = 0; i * 10000 <= y; i++){
        for(int j = 0; i * 10000 + j * 5000 <= y; j++){
            if (y - (i * 10000 + j * 5000) == (n - i - j) * 1000){
                printf("%d %d %d\n", i, j, n - i - j);
                return 0;
            }
        }
        
    }
    puts("-1 -1 -1");
    
}

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

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

    if(a > b){
        tmp = a; a = b; b = tmp;
    }
    if(a > c){
        tmp = a; a = c; c = tmp;
    }
    if(b > c){
        tmp = b; b = c; c = tmp;
    }

    cout << a << " " << b << " " << c << endl;

    return 0;
}

Measured memory_bytes: 3088
from collections import deque

n,m=map(int,input().split())

INF=100050

q=deque()

class Room:
    def __init__(self,num):
        self.number=num
        self.frontier=True
        self.neighbor=[]
        self.arrow=0
        self.deepness=INF

    def set(self,room):
        self.neighbor.append(room)
    
    def search(self,num,deps):
        self.arrow=num
        self.deepness=deps
        self.frontier=False

    def dfs(self):
        for i in self.neighbor:
            if rooms[i].frontier:
                rooms[i].search(self.number,self.deepness+1)
                q.append(i)

rooms=[]
for i in range(n+1):
    rooms.append(Room(i))

for _ in range(m):
    a,b=map(int,input().split())
    rooms[a].set(b)
    rooms[b].set(a)

q.append(1)
while q:
    rooms[q.popleft()].dfs()


print("Yes")
for i in range(2,len(rooms)):
    if rooms[i].frontier==False:
        print(rooms[i].arrow)


Measured memory_bytes: 55520
let main = (standardInput) => {
    let lenghtList = standardInput.split(' ');
    let varticalLength = Number.parseInt(lenghtList[0]);
    let horizonLength = Number.parseInt(lenghtList[1]);

    console.log(varticalLength * horizonLength + ' ' + 2 * (varticalLength + horizonLength));
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8'));



Measured memory_bytes: 15380
#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define fi                      first
#define se                      second
#define pb                      push_back
#define pbb                     pop_back
#define mp                      make_pair
#define pii     	            pair<int,int>
#define all(x)                  x.begin(), x.end()
#define mem(array, value)       memset(array, value, sizeof(array))
#define fastRead 	            ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#ifdef Lollipop
    #define line                    cout << "\n===================\n"
    #define trace(...)              __f( #__VA_ARGS__ , __VA_ARGS__ )
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " = " << arg1 << "\n";
    }
    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 line
    #define trace(...)
#endif

const int nax = 2e5 + 5;
string ara[nax];
map<string, int> MP;
map<string, bool> mark;
vector<string> res;
int n;

int main ()
{
    #ifdef Lollipop
        //freopen ("input.txt", "r", stdin);
        //freopen ("output.txt", "w", stdout);
    #endif
    //fastRead;
    cin >> n;
    int mx = 0;
    for (int i = 0; i < n; i++){
        cin >> ara[i];
        MP[ara[i]]++;
        mx = max(mx, MP[ara[i]]);
    }
    for (int i = 0; i < n; i++){
        if (MP[ara[i]] == mx && !mark[ara[i]]){
            mark[ara[i]] = true;
            res.pb(ara[i]);
        }
    }
    sort(all(res));
    for (auto x : res){
        cout << x << endl;
    }
    return 0;
}




Measured memory_bytes: 40816
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

int main() {
  vector<int> v(3);
  for (int i = 0 ; i < 3; ++i) {
    cin >> v.at(i);
  }
  sort(v.begin(), v.end(), greater<int>());
  cout << (v.at(0)*10 + v.at(1)) + v.at(2) << endl; 
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    Main(){
	Scanner sc = new Scanner(System.in);

	while(sc.hasNext()){
	    int n = sc.nextInt(), mx, mn;
	    if(n == 0) break;
	    mx = mn = -1;

	    for(int j = 0; j < n; j++){
		int tmp = 0;
		for(int i = 0; i < 5; i++)
		    tmp += sc.nextInt();
		if(mx == -1 || mx < tmp) mx = tmp;
		if(mn == -1 || mn > tmp) mn = tmp;
	    }

	    System.out.println(String.valueOf(mx) + " " + String.valueOf(mn));
	}
    }

    public static void main(String[] args){
	new Main();
    }
}

Measured memory_bytes: 12000
let (n, m, q) = Scanf.scanf "%d %d %d\n" @@ fun n m p -> (n, m, p)

let arr = Array.init q (fun _ -> Scanf.scanf "%d %d %d %d\n" @@ fun a b c d -> (a - 1, b - 1, c, d))

let ans = ref 0

let rec loop i v ts =
  if i = n then begin
    let sum = ref 0 in
    Array.iter (fun (a, b, c, d) -> sum := !sum + if ts.(b) - ts.(a) = c then d else 0) arr;
    ans := max !ans !sum
  end
  else begin
    ts.(i) <- v;
    for j = v to m do
      loop (i + 1) j ts;
    done
  end

let () =
  for i = 1 to m do
    loop 0 i @@ Array.make n 0
  done;
  print_int !ans

Measured memory_bytes: 5864
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#define lli long long int
#define ld long double
#define fop(i,m,n) for (int i=(m);i<(n);i++)
#define FOP(i,m,n) for (int i=(m)-1;i>=(n);--i)
#define test(x) cout << #x << ' ' << x << endl;
#define printv(a) {\
    for (auto y : a) cout << y << ' ';\
    cout << '\n';\
}
#define eb emplace_back
#define pb push_back
#define mp make_pair 
#define mt make_tuple
#define pii pair<int,int> 
#define pll pair<lli,lli>
#define tiii tuple<int,int,int>
#define all(a) a.begin(), a.end()
#define X first
#define Y second
#define oset tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update>
#define readfile freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); 
auto SEED = chrono::steady_clock::now().time_since_epoch().count();
mt19937 rng(SEED);
const int mod = 998244353, x = 864197532, N = 20, logN = 18, K = 350, all = (1 << N) - 1;

int main () {
	int n, k;
	cin >> n >> k;
	vector <int> len(n);
	fop (i,0,n) cin >> len[i];
	auto ask = [&](int x) {
		lli ans = 0;
		fop (i,0,n) {
			ans += ((len[i] - 1) / x);
		}
		return ans <= k;
	};
	int l = 0, r = 1e9 + 87;
	while (r - l > 1) {
		(ask(l + r >> 1) ? r : l) = l + r >> 1;
	}
	cout << r << endl;
}

Measured memory_bytes: 3980
x, y = map(int, input().split())

ans = 0
diff = y-x
abs_diff = abs(abs(y)-abs(x))

ans += abs_diff

if abs_diff == diff:
    ans += 0

elif diff == -1*(abs_diff):
    ans += 2
    if x == 0 or y == 0:
        ans -= 1
else:
    ans += 1

print(ans)


Measured memory_bytes: 3060
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var cin = new Scanner2();
			string s = cin.Next();
			int n = s.Length;
			var sb = new StringBuilder();
			for (int i = 0; i < n; i++) {
				sb.Append("x");
			}

			Console.WriteLine(sb.ToString());
		}
	}

	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private readonly Func<string> reader_;
		private string[] buf_;
		private int index_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}

Measured memory_bytes: 13140
loop do
	t = gets
	if t == nil
		break
	end
	
	if t.to_i == 0
		break
	end
	
	m, n = t.split().map{|d| d.to_i}
	a = []
	m.times do
		a << gets
	end
	
	b = []
	n.times do
		b << gets
	end
	b = b.map{|d| d.to_i}
	
	m.times do |r|
		ans = 0
		at = a[r].split().map{|d| d.to_i}
		n.times do |c|
			ans += (at[c] * b[c])
		end
		puts ans
	end
end

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

even_odd = [0, 0]
count_R = [0]*N
for i in range(N):
    if S[i] == 'R':
        even_odd[i%2] += 1
    if S[i] == 'L':
        count_R[i] += even_odd[i%2]
        count_R[i-1] += even_odd[1-i%2]
        even_odd = [0, 0]

S = S[::-1]
even_odd = [0, 0]
count_L = [0]*N
for i in range(N):
    if S[i] == 'L':
        even_odd[i%2] += 1
    if S[i] == 'R':
        count_L[i] += even_odd[i%2]
        count_L[i-1] += even_odd[1-i%2]
        even_odd = [0, 0]

count = [r+l for r, l in zip(count_R, count_L[::-1])]
print(' '.join(map(str, count)))

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

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; }
typedef long long ll;

int main() {
    ll n; cin >> n;
    vector<ll> s(n);
    for(ll i = 0; i < n; i++) {
        cin >> s.at(i);
    }
    for (ll j = 0; j < n-1; j++) { cout << s.at(j) << ' '; }
    cout << s.at(n-1) << endl;
    for(ll i = 1; i < n; i++) {
        for(ll j = i; j > 0; j--) {
            if(s.at(j) < s.at(j-1)) swap(s.at(j), s.at(j-1));
        }

        for (ll j = 0; j < n-1; j++) { cout << s.at(j) << ' '; }
        cout << s.at(n-1) << endl;
    }
    
    return 0;
}




Measured memory_bytes: 3112
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;
    ll d;
    cin >> d;
    cout << "Christmas";
    if(d == 24)
      cout << " Eve"<<endl;
    if(d == 23)
      cout << " Eve Eve"<<endl;
    if(d == 22)
      cout << " Eve Eve Eve"<<endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
using namespace std;
#define LOCAL  1
#define UPLOAD 2
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
template <class T = long long> T input(){T x;cin >> x;return x;}
template <class T> void output(T x){cout << x << endl;}
#define debug(x) cerr << #x<< ": " << x<< '\n';

#define ll long long

int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
  int N = input();
  vector<int> A;
  
  for(int i=0;i<N;i++){
    A.push_back(input());
  }

  vector<int> B;
  B.resize(N);

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

  for(auto iter:B){
    cout << iter << " ";
  }
  cout << endl;
  

  return 0;
}

Measured memory_bytes: 1784
def matDot(A,B,MOD):
    N,M,L = len(A),len(A[0]),len(B[0])
    
    res = [[0]*L for i in range(N)]

    for i in range(N):
        for j in range(L):
            s = 0
            for k in range(M):
                s = (s + A[i][k]*B[k][j]) % MOD
            res[i][j] = s
    
    return res

def matPow(A,x,MOD):
    N = len(A)
    res = [[0]*N for i in range(N)]
    
    for i in range(N):
        res[i][i] = 1
    
    for i in range(x.bit_length()):
        if (2**i) & x:
            res = matDot(res,A,MOD)
        A = matDot(A,A,MOD)
    
    return res

n,k = map(int,input().split())
mod = 10**9+7

a = [list(map(int,input().split())) for i in range(n)]

b = matPow(a,k,mod)

ans = 0
for i in range(n):
    for j in range(n):
        ans = (ans+b[i][j])%mod

print(ans)

Measured memory_bytes: 41324
#include<bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define pb push_back
#define Ceil(a,b)              ((a)+(b)-1)/(b)
#define MrGAFs                 file();
#define rep(i,limits)          for(int i = 0;i<(limits);++i)
#define allr(v)                ((v).rbegin()), ((v).rend())
#define all(v)                 ((v).begin()), ((v).end())
#define endl                   "\n"
#define sz(v)	               ((int)((v).size()))
#define dep(x)		       cout << #x << " = " << x << endl ;
#define rt(v)                  return cout<<v,0;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int oo = INT_MAX;
const ll OO = LLONG_MAX;
using namespace std;
int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
int dx1[] = { -1, 1, 0, 0 };
int dy1[] = { 0, 0, -1, 1 };

	//classes
        void file (){
      #ifndef ONLINE_JUDGE 
         freopen ("in.txt", "r", stdin);
   //     x = freopen ("out.txt", "w", stdout);
      #else
#endif
  ios_base::sync_with_stdio (false);
  cout.tie (NULL);
  cin.tie (NULL);
}
  /******Functions*********/

  /******Main Function*********/
int main (){
  MrGAFs
 int n,m ;
  cin >> n >> m ;
   vector <int> v (n); 
   vector <bool> b (n, true);
   for(int i =0 ; i < n; ++i )cin >> v[i];
	int q,u , ans =0;
while(m--){
cin >> q >>u ;
q-- ,u-- ; 

if (v[q]<=v[u])b[q] =false ;
if (v[q]>=v[u])b[u] =false ;

}
for (auto i:b ) ans+=i;
cout << ans ;
}


Measured memory_bytes: 3704
N = int(input())
dia = [0]*(N-1)
for i in range(N-1):
    c,s,f = map(int,input().split())
    dia[i] = (c,s,f)
for i in range(N-1):
    time = 0
    for j in range(i,N-1):
        c,s,f = dia[j]
        if time > s:
            x = (time - s)/f
            if x.is_integer():
                s += int(x)*f
            else:
                s += int(x+1)*f
        time =  s + c
    print(time)
print(0)










Measured memory_bytes: 43884
N, M = map(int, input().split())
x = []
y = []
z = []
for i in range(N):
  a, b, c = map(int, input().split())
  x += [a]
  y += [b]
  z += [c]

ans = 0

for xs in [-1,1]:
  for ys in [-1,1]:
    for zs in [-1,1]:
      p = []
      for n in range(N):
        p += [xs*x[n]+ys*y[n]+zs*z[n]]
      p.sort(reverse = 1)
      ans = max(ans, sum(p[:M]))
      
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define eps DBL_EPSILON
#define moder 10007
#define int long long
#define ll long long
#define INF LLONG_MAX/3
#define P std::pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
int n;
string s,mis,mas;
signed main(){
	cin>>n;
	cout<<0<<endl;
	cin>>s;
	if(s=="Vacant")return 0;
	mis=s;
	cout<<n-1<<endl;
	cin>>s;
	if(s=="Vacant")return 0;
	mas=s;
	int mi=0,ma=n-1;
	while(true){
		int md=(mi+ma)/2;
		cout<<md<<endl;
		cin>>s;
		if(s=="Vacant")return 0;
		if((md-mi)%2==0&&mis!=s){
			ma=md;
			mas=s;
		}
		if((md-mi)%2==1&&mis==s){
			ma=md;
			mas=s;
		}
		if((ma-md)%2==0&&mas!=s){
			mi=md;
			mis=s;
		}
		if((ma-md)%2==1&&mas==s){
			mi=md;
			mis=s;
		}
	}
	return 0;
}

Measured memory_bytes: 976
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    double v;
    cin>>n;
    std::deque<double> deq;
    for (int i=0;i<n;i++) {
        cin>>v;
        deq.emplace_back(v);
    }
    sort(deq.begin(),deq.end());
    for (int j=0;j<n-1;j++) {
        double tmp1=deq.front();
        deq.pop_front();
        double tmp2=deq.front();
        deq.pop_front();
        deq.emplace_front((tmp1+tmp2)/2);
    }
    cout<<deq[0]<<endl;
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int n = sc.nextInt();
    int max = 105;
    Set<Integer> set = new HashSet<>();
    for (int i = 0; i < n; i++) {
      set.add(sc.nextInt());
    }

    int ans = -1;
    if (set.isEmpty()) {
      ans = x;
    } else {
      for (int i = 0; i <= max; i++) {
        if (!set.contains(i) && Math.abs(ans - x) > Math.abs(i - x)) {
          ans = i;
        }
      }
    }
    System.out.println(ans);
    System.out.flush();
    sc.close();
  }
}


Measured memory_bytes: 36016
#include<bits/stdc++.h>
#define EPS 1e-10
#define equals(a,b) (fabs((a)-(b)) < EPS)
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long ll;
using namespace std;

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

struct Point {
    double x,y;
    Point(){}
    Point(double x,double y): x(x),y(y){}
    Point operator+(Point p) {return Point(x+p.x,y+p.y);}
    Point operator-(Point p) {return Point{x-p.x,y-p.y};}
    Point operator*(double k) {return Point{x*k,y*k};}
    Point operator/(double k) {return Point{x/k,y/k};}
    double norm(){return x*x+y*y;}
    double abs(){sqrt(norm());}
    bool operator == (const Point &p) const {return equals(x,p.x)&&equals(y,p.y);}
};

typedef Point P;

struct Segment {
    P p1,p2;
    Segment(){}
    Segment(P p1, P p2):p1(p1),p2(p2){}
};

double dot(P a, P b) {return a.x*b.x+a.y*b.y;}
double cross(P a, P b) {return a.x*b.y-a.y*b.x;}

int ccw(P p0, P p1, P p2) {
    P a = p1-p0; P b = p2-p0;
    if (cross(a,b) > EPS) return COUNTER_CLOCKWISE;
    if (cross(a,b) < -EPS) return CLOCKWISE;
    if (dot(a,b) < -EPS) return ONLINE_BACK;
    if (a.norm() < b.norm()) return ONLINE_FRONT;
    return ON_SEGMENT;
}

int main() {
    map<int, string> mp;
    mp[COUNTER_CLOCKWISE] = "COUNTER_CLOCKWISE";
    mp[CLOCKWISE] = "CLOCKWISE";
    mp[ONLINE_BACK] = "ONLINE_BACK";
    mp[ONLINE_FRONT] = "ONLINE_FRONT";
    mp[ON_SEGMENT] = "ON_SEGMENT";
    double x0,y0,x1,y1;
    cin>>x0>>y0>>x1>>y1;
    P p0(x0,y0), p1(x1,y1);
    int q; cin>>q;
    rep(i,q) {
        double x2,y2;
        cin>>x2>>y2;
        P p2(x2,y2);
        cout << mp[ccw(p0,p1,p2)] << endl;
    }
}


Measured memory_bytes: 3288
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937_64 mt64(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/

int n;
P p[114514];
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> p[i].first; p[i].second = i;
	}
	sort(p, p + n);
	rep(i, n)cout << p[i].second + 1 << " ";
	cout << endl;
}

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

int main() {
	
	string s;
	cin>>s;
	int k = 0;
	int n = s.size();
	for(int i = 0; i < n-1; i++)
	{
		bool check = false;
		if(n-i > 2)
		{
			if(s[i]==s[i+1] and s[i+1] == s[i+2] and s[i] == '0')
			{
				s[i+1] = '1';
				k++;
				i++;
				check = true;
			}
			else if(s[i]==s[i+1] and s[i+1] == s[i+2] and s[i] == '1')
			{
				s[i+1] = '0';
				k++;
				i++;
				check = true;
			}
		}
		if(!check)
		{
			if(s[i] == s[i+1])
			{
				if(s[i] == '0')
				{
					s[i+1] = '1';
					k++;
				}
				else
				{
					s[i+1] = '0';
					k++;
				}
			}
		}
	}
	cout<<k;
	
	return 0;
}

Measured memory_bytes: 3724
n=int(input())
a=[int(c) for c in input().split()]
a.sort()
ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
       if a[i]==a[j]:
           continue    
       for k in range(j+1,n):
           
           if a[k]!=a[i] and a[k]!=a[j]:
              
                if a[i]+a[j]>a[k]:
                    ans+=1

print(ans)

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

int F[102][102] = { 0 };

void DFS(int Y, int X, int c) {
	//cout << Y << " " << X << endl;
	if (F[Y][X] != c)
		return;
	F[Y][X] = 10;
	DFS(Y - 1, X, c);//???
					 //DFS(Y - 1, X+1, A_ito);//??????
	DFS(Y, X + 1, c);//???
					 //DFS(Y + 1, X+1, A_ito);//??????
	DFS(Y + 1, X, c);//???
					 //DFS(Y + 1, X-1, A_ito);//??????
	DFS(Y, X - 1, c);//???
					 //DFS(Y - 1, X-1, A_ito);//??????
}


int main()
{
	int xs, ys, xg, yg, n;
	int c, d, x, y;
	int W = 1, H = 1;

	while (true) {
		cin >> W >> H;
		if ((W == 0) && (H == 0)) {
			break;
		}
		cin >> xs >> ys >> xg >> yg >> n;
		for (int i = 1;i <= n;i++) {
			cin >> c >> d >> x >> y;
			if (d == 1) {
				F[y    ][x    ] = c;
				F[y    ][x + 1] = c;
				F[y + 1][x    ] = c;
				F[y + 1][x + 1] = c;
				F[y + 2][x    ] = c;
				F[y + 2][x + 1] = c;
				F[y + 3][x    ] = c;
				F[y + 3][x + 1] = c;
			}
			if (d == 0) {
				F[y    ][x    ] = c;
				F[y + 1][x    ] = c;
				F[y    ][x + 1] = c;
				F[y + 1][x + 1] = c;
				F[y    ][x + 2] = c;
				F[y + 1][x + 2] = c;
				F[y    ][x + 3] = c;
				F[y + 1][x + 3] = c;
			}
		}
		if (F[ys][xs] != 0)
			DFS(ys, xs, F[ys][xs]);

		if (F[yg][xg] == 10) {
			cout << "OK" << endl;
		}
		else { cout << "NG" << endl; }
		for (int i = 1;i <= H;i++) {
			for (int j = 1;j <= W;j++) {
				F[i][j] = 0;
			}
		}

	}

	return 0;
}

Measured memory_bytes: 3112
p,M,f=pow,1000003,[1]
for i in range(1,M):f.append(f[i-1]*i%M)
for _ in'_'*input():x,d,n=map(int,raw_input().split());t=x*p(d,M-2,M)%M;print([p(x,n,M),M/(t+n)*t and f[t+n-1]*p(f[t-1],M-2,M)*p(d,n,M)%M][d>0])

Measured memory_bytes: 108908
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int max = 0, pmax = 0;
		int n = sc.nextInt();
		int pos=0,flag=0;
		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			max = Math.max(max, a[i]);
		}
		for (int i = 0; i < n; i++) {
			if(a[i]==max&&flag==0) {
			pos=i;
			flag=1;
			break;
			}
		}
		for (int i = 0; i < n; i++)if (i!=pos)pmax = Math.max(pmax, a[i]);
		int i;
		for (i = 0; i < n; i++) {
			if(pmax==max){
				System.out.println(max);
			}else  {
				if (max == a[i])System.out.println(pmax);
				else System.out.println(max);
			}  
		}
	}
}

Measured memory_bytes: 94480
from bisect import bisect
s = list(input())
t = list(input())
lenT = len(t)
lenS = len(s)
alp = []

for i in range(26):
  array = []
  now = chr(ord('a') + i)
  for j in range(lenS):
    if s[j] == now:
      array.append(j)
  alp.append(array)

count,now = 0,-1

for i in range(lenT):
  j = ord(t[i])-ord('a')
  if alp[j]:
    next = bisect(alp[j],now)
    if next == len(alp[j]):
      count += 1
      now = alp[j][0]
    else:
      now = alp[j][next]
  else:
    print(-1)
    exit()

ans = count*lenS+now+1

print(ans)

Measured memory_bytes: 14276
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  cin >> H >> W;
  vector< vector<char> > A(H, vector<char>(W));
  for ( int i = 0; i < H; i++){
      for ( int k = 0; k < W; k++){
          cin >> A.at(i).at(k);
      }
  }
  
  vector<bool> A_row(H,false);
  vector<bool> A_col(W,false);

  for(int i = 0; i < H; i++){
      for(int k = 0; k < W; k++){
          if(A.at(i).at(k) == '#') A_row.at(i) = true;
      }
  }

  for(int k = 0; k < W; k++){
      for(int i = 0; i < H; i++){
          if(A.at(i).at(k) == '#') A_col.at(k) = true;
      }
  }
 
  for ( int i = 0; i < H; i++){
      if(A_row.at(i) == true){
          for ( int k = 0; k < W; k++){
              if(A_col.at(k) == true){
                  cout << A.at(i).at(k);
              }
          }
      }
      cout << endl;
      
  }
  return 0;


}

Measured memory_bytes: 256
//given n integers and an integer m such that n>m then there exits a pair
//(a-b) such that (a-b)%m==0


#include<bits/stdc++.h>
using namespace std;
typedef  long long int ll;
const ll M=1000000007;
void solve(){
ll n;
cin>>n;
ll a[n];
for(int i=0;i<n;i++)cin>>a[i];
ll ans=0;
for(int i=0;i<n-1;i++){
    if(a[i]>a[i+1])ans+=(a[i]-a[i+1]),a[i+1]=a[i];
}
cout<<ans;
}

int main(){
 int t=1;
 //cin>>t;
 while(t--){
        solve();
        cout<<endl;
 }
}


Measured memory_bytes: 5184
# AOJ ITP2_6_B: Includes
# Python3 2018.6.24 bal4u

n = int(input())
a = set(list(map(int, input().split())))
m = int(input())
b = set(list(map(int, input().split())))
print(1 if b.issubset(a) else 0)


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

ll f(int pos, int k, vector<int> &v, vector<int> &pt){
  if(k == 0) return 0;
  int cnt = 1, npos = v[pos];
  ll npt = pt[npos];
  vector<ll> mxpt(v.size()+1);
  mxpt[0] = 0;
  mxpt[1] = max((ll)0,npt);
  while(npos != pos){
    npos = v[npos];
    npt += pt[npos];
    ++cnt;
    mxpt[cnt] = max(mxpt[cnt -1], npt);
  }
  ll ans;
  if(npt < 0) ans = mxpt[min(k,cnt)];
  else{
    ans = max((ll)k/cnt *npt -npt +mxpt[cnt], (ll)k/cnt *npt +mxpt[k%cnt]);
  }
  return ans;
}

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> pn(n), pt(n);
  for(int i=0; i<n; ++i){
    cin >> pn[i];
    --pn[i];
  }
  bool isplus = false;
  for(int i=0; i<n; ++i){
    cin >> pt[i];
    if(pt[i] >= 0) isplus = true;
  }
  if(!isplus){
    int ans = -1001001001;
    for(int i=0; i<n; ++i){
      ans = max(ans, pt[i]);
    }
    cout << ans << endl;
    return 0;
  }
  
  ll ans = 0;
  for(int i=0; i<n; ++i){
    int pos = i, cnt = k;
    ll nans = 0;
    vector<bool> ok(n,true);
    while(ok[pos] && cnt > 0){
      ok[pos] = false;
      pos = pn[pos];
      nans += pt[pos];
      ans = max(ans, nans);
      --cnt;
    }
    //cout << "i:" << i+1 << " pos:" << pos+1 << " 残り回数:" << cnt << " 現pt" << nans << endl;
    nans += f(pos,cnt,pn,pt);
    //cout << "-答え" << nans << endl;
    ans = max(ans, nans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3660
// clang-format

#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;

using lli = long long int;
int main() {
  std::string S;
  std::cin >> S;
  lli ans= S.size();
  lli N=S.size();
  rep(i, S.size()-1)
  {
    if(S[i]!=S[i+1])
    ans = min(ans, max(i+1,  N- i-1));
  }
  cout << ans<<endl;

  return 0;
}

Measured memory_bytes: 512
#!/usr/bin/env python3
#エクサウィザーズ2019 A

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

a,b,c = LI()
if a == b and b == c and c == a:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <bitset>
#include <unordered_map>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <cstring>
#include <cmath>

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

vector<vector<int> > nodes;

void dfs(int parent, int current, int distances[], int distance = 0){
    distances[current] = distance;
    for(int to : nodes[current]){
        if( to == parent ){
            continue;
        }
        dfs(current, to, distances, distance+1);
    }
}

int main(){
    int N, u, v;
    cin >> N >> u >> v;
    u--;
    v--;
    nodes.resize(N);
    
    rep(i, N-1){
        int from, to;
        cin >> from >> to;
        from--;
        to--;
        nodes[from].push_back(to);
        nodes[to].push_back(from);
    }
    int distance_from_aoki[N], distance_from_takahashi[N];
    dfs(-1, u, distance_from_takahashi);
    dfs(-1, v, distance_from_aoki);

    int ans = 0;
    rep(i,N){
        if( distance_from_takahashi[i] < distance_from_aoki[i] ){
            ans = max(ans, distance_from_aoki[i] - 1);
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 11648
"use strict";

function main(input) {
  input = input.trim().split(" ");
  let A = Number(input[0]); // 2
  let B = Number(input[1]); // 1
  let K = Number(input[2]); // 1

  if (A > 0) {
    if (A > K) {
      A = A - K;
      K = 0;
    } else {
      K = K - A;
      A = 0;
    }
  }
  if (B > 0) {
    if (B > K) {
      B = B - K;
      K = 0;
    } else {
      K = K - B;
      B = 0;
    }
  }
  console.log(A, B);
}

main(require("fs").readFileSync("/dev/stdin", "utf-8"));


Measured memory_bytes: 29540
#include <algorithm>
#include <vector>
#include <iostream>

using namespace std;

#define INF (1ULL << 60)

struct Node {
    unsigned long long adj_cost;
    int next_node;

    Node(unsigned long long adj_cost, int next_node) {
        this->adj_cost = adj_cost;
        this->next_node = next_node;
    }
};

void depth_first_search(int current_node, int prev_node, unsigned long long total_cost, 
                        vector<vector<Node>> &nodes, vector<unsigned long long> &dist) {
    dist[current_node] = total_cost;
    for (auto n: nodes[current_node]) {
        if (n.next_node == prev_node) {
            continue;
        }
        depth_first_search(n.next_node, current_node, n.adj_cost + total_cost, nodes, dist);
    }
}

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

    vector<vector<Node>> nodes(N, vector<Node>(0, {INF, -1}));
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        unsigned long long c;
        cin >> a >> b >> c;
        a--;
        b--;
        nodes[a].emplace_back(c, b);
        nodes[b].emplace_back(c, a);
    }

    int Q, K;
    cin >> Q >> K;
    K--;

    vector<unsigned long long> dist_to_K(N, INF);
    depth_first_search(K, -1, 0, nodes, dist_to_K);

    for (int i = 0; i < Q; i++) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        cout << dist_to_K[x] + dist_to_K[y] << endl;
    }
    return 0;
}

Measured memory_bytes: 17408
from sys import stdin


def main():
    _ = int(stdin.readline().rstrip())
    Ls = [int(x) for x in stdin.readline().rstrip().split()]
    max_ = max(Ls)
    Ls.remove(max_)
    print('Yes' if max_ < sum(Ls) else 'No')


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#!/usr/bin/env python3
import sys
from collections import defaultdict
from collections import deque


def solve(N: int, X: "List[int]", Y: "List[int]"):
    adj = defaultdict(list)
    done = set()
    for x, y in zip(X, Y):
        xnode = (x, 0)
        ynode = (y, 1)
        adj[xnode].append(ynode)
        adj[ynode].append(xnode)

    points_to_add = 0    
    for x, y in zip(X, Y):
        xnode = (x, 0)
        ynode = (y, 1)
        if xnode in done or ynode in done:
            continue
        x_count = 1
        y_count = 0
        done.add(xnode)
        Q = deque()
        Q.append(xnode)
        while len(Q) > 0:
            node = Q.pop()
            for node_next in adj[node]:
                if node_next in done:
                    continue
                if node_next[1] == 0:
                    x_count += 1
                else:
                    y_count += 1
                Q.append(node_next)
                done.add(node_next)
        points_to_add += x_count * y_count
    print(points_to_add - N)
        
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    x = [int()] * (N)  # type: "List[int]" 
    y = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, x, y)

if __name__ == '__main__':
    main()


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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl

const ll inf = -1e18;

ll dp[1 << 16];
ll cost[1 << 16];
ll a[16][16];

int main() {
    int N; cin >> N;
    rep(i, N) {
        rep(j, N) {
            cin >> a[i][j];
        }
    }

    for (int i = 1; i < (1 << N); ++i) {
        ll c = 0;
        rep(j, N) rep(k, j) {
            if (((i >> j) & 1) && ((i >> k) & 1)) { 
                c += a[j][k];
            }
        }
        cost[i] = c;
    }

    rep(i, 1 << N) dp[i] = inf;
    dp[0] = 0;

    for (int i = 1; i < (1 << N); ++i) {
        for (int j = i; j > 0; j = ((j-1) & i)) {
            dp[i] = max(dp[i], dp[i^j] + cost[j]);
        }
    }

    cout << dp[(1 << N) - 1] << endl;

    return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,x;
  int ans=0;
  
  cin >> a >> b >> c >>x;
  
  for(int i=0;i<=a&&x/500+1;i++){
    for(int j=0;j<=b&&x/100+1;j++){
      for(int k=0;k<=c&&k/50+1;k++){
        if(500*i+100*j+50*k==x){
          ans++;
        }
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3580