akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdarg.h>
#include<malloc.h>

int mod(int, int);
void decode(int, char str[100][100]);
void convert(int, char str[100][100]);

int main()
{
	int i, j, k, n, c;
	char str[100][100];

	scanf("%d%*c", &n);

	for(i=0; i<n; i++){

		for(j=0; j<100; j++)
			for(k=0; k<100; k++)
				str[j][k] = 0;
		j=0;
		k=0;
		while(1){
			c = getchar();
			if(c == ' '){
				j++;
				k=0;
			} else if(c == '\n') {
				j++;
				break;
			} else {
				str[j][k] = c;
				k++;
			}
		}

		decode(j, str);

	}
	return 0;
}

int mod(int x, int y)
{	
	while(x < 0)		
		x += y;
	return x % y;
}

void convert(int j, char str[100][100])
{

	int i, k;

	for(i=0; i<j; i++){
		for(k=0; k<100; k++){
			if(str[i][k] >= 'a' && str[i][k]<= 'z')
				str[i][k] -= 'a';
		}
	}

	return;

}

void decode(int j, char str[100][100])
{
	int i, k, len[100];
	int alpha[12] = {1,3,5,7,9,11,15,17,19,21,23,25};
	int alpha_inv[12] = {1,9,21,15,3,19,7,23,11,5,17,25};
	int a, b;
	
	for(i=0; i<j; i++)
		len[i] = strlen(str[i]);

	convert(j, str);

	for(i=0; i<j; i++){
		if(len[i] == 4){
			for(a=0; a<12; a++){
				for(b=0; b<26; b++){
					if(mod((alpha_inv[a] * (str[i][0] - b)), 26) == 19){
						if(mod((alpha_inv[a] * (str[i][1] - b)), 26) == 7){
							if(mod((alpha_inv[a] * (str[i][2] - b)), 26) == 8){
								if(mod((alpha_inv[a] * (str[i][3] - b)), 26) == 18){
									goto OUT;
								}
							}
							else if(mod((alpha_inv[a] * (str[i][2] - b)), 26) == 0){
								if(mod((alpha_inv[a] * (str[i][3] - b)), 26) == 19){
									goto OUT;
								}
							}
						}
					}
				}
			}
		}
	}
OUT:

	for(i=0; i<j; i++){
		for(k=0; k<len[i]; k++){
			str[i][k] = mod(alpha_inv[a] * (str[i][k] - b), 26);
			str[i][k] += 'a';
		}
	}

	for(i=0; i<j; i++){
		printf("%s", str[i]);
		if(i != j-1)
			printf(" ");
	}
	printf("\n");

	return;
}

Measured memory_bytes: 616
import heapq

N = int(input())
a = map(int,input().split())


heap = []
max_val = -10001
for i in a:
    if i > max_val:
        max_val = i
    heapq.heappush(heap,i)
log = []

min_val = heapq.heappop(heap)
for _ in range(N-2):
    tg = heapq.heappop(heap)
    if tg < 0:
        log.append([max_val, tg])
        max_val -= tg
    else:
        log.append([min_val, tg])
        min_val -= tg
    
print(max_val - min_val)
log.append([max_val,min_val])
for l in log:
    print(l[0],l[1])

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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

void ALLIN1_NUMBER(vector<ll>& V)
{
    for(auto& x : V)
    {
        cin >> x;
    }
}

template<class T>
void OUT0(T N)
{
    cout << N << endl;
}

static const double pi = acos(-1.0);

double Cos(double D)
{
    return cos(pi/180 * D);
}

int main()
{
    int H1,M1,H2,M2,K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;

    int wake_minutes = H2*60 + M2 - (H1*60 + M1);

    OUT0(wake_minutes-K);

    return 0;
}

Measured memory_bytes: 3680
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; i++ )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
const ll mod2=1e9+9 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

int main(){
  ll h,w;
  cin>>h>>w;
  vector<pli> v;
  rep(i,h){
    ll x;cin>>x;
    v.push_back({x,0});
    }
  rep(i,w){
    ll x;cin>>x;
    v.push_back({x,1});
    }
  h++;w++;
  sort(v.begin(),v.end());
  ll ans=0;
  for(auto x:v){
    if(x.second){
      ans+=h*x.first;
      w--;
      }
    else {
      ans+=w*x.first;
      h--;
      }
    }
  cout<<ans<<endl;  
  return 0;
}


Measured memory_bytes: 6256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<climits>
#define MOD 1000000007
typedef long long ll;
using namespace std;

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

vector<ll> primeFactorize(ll n){
  vector<ll> v;
  if(n%2==0){
    bool flag1 = false; 
    while(n%2==0){
      flag1 = true;
      n = n / 2;
    }
    if(flag1) v.push_back(2);
  }
  for(ll i=3;i*i<=n;i+=2){
    bool flag2 = false;
    while(n%i==0){
      flag2 = true;
      n = n / i;
    }
    if(flag2) v.push_back(i);
  }
  if(n!=1) v.push_back(n);
  
  return v;
}

int main(){
  ll A,B; cin >> A >> B;
  ll g = gcd(A,B);

  vector<ll> p = primeFactorize(g);
  cout << p.end() - p.begin() + 1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int binary(int r);
int n;
 
int S[100000];
 
int main(void)
{
 
  int i,n2,cou = 0;
 
   int S2[50000];
  scanf("%d",&n);
 
  for(i = 0; i < n; i++){
  scanf("%d", &S[i]);
  }
 
  scanf("%d",&n2);
 
  for(i = 0; i < n2; i++){
  scanf("%d", &S2[i]);
  }
 
 
 
 for(i = 0; i < n2; i++){
   if(binary(S2[i]) == 1){
    cou++;
      }
 
  }
 
  printf("%d\n",cou);
  return 0;
}
 
 
int binary(int key){
  int mid;
 
  int  L = 0,R = n;
  while (L < R){
    mid = (L + R)/2;
    if(S[mid] == key)  return 1;
    else if (key < S[mid])R = mid;
    else L = mid + 1;
  }
    return 0;
 
  }

Measured memory_bytes: 1180
n = int(input())
x = list(map(int, input().split()))
t = 10 ** 9 + 7
for i in range(101):
  c = i
  tt = 0
  for j in range(n):
    tt += ((x[j] - c) ** 2)
  t = min(t, tt)
print(t)
   
    

Measured memory_bytes: 38640
#include <iostream>
#include <vector>
#include <limits>

int main () {

    int n, m, x;
    std::cin >> n >> m >> x;
    std::vector<int> c(n);
    std::vector< std::vector<int> > a(n, std::vector<int>(m));
    for(int i = 0; i < n; i++) {
        std::cin >> c[i];
        for(int j = 0; j < m; j++) {
            std::cin >> a[i][j];
        }
    }

    int ans = std::numeric_limits<int>::max();
    for (int mask = 0; mask < (1 << n); mask++) {
        std::vector<int> skills(m, 0);
        int cost = 0;
        for(int i = 0; i < n; i++) {
            if ((mask >> i) & 1) {
                cost += c[i];
                for(int j = 0; j < m; j++) {
                    skills[j] += a[i][j];
                }
            }
        }
        bool ok = true;
        for (int j = 0; j < m; j++) {
            if (skills[j] < x) ok = false;
        }
        if(ok) ans = std::min(ans, cost);
    }

    if(ans == std::numeric_limits<int>::max()) std::cout << -1 << std::endl;
    else std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 3192
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

type StackData struct {
	data interface{}
	next *StackData
}

type Stack struct {
	sp  *StackData
	top int
}

func NewStack() *Stack {
	return &Stack{top: 0}
}

func (s *Stack) Push(data interface{}) {
	s.sp = &StackData{data: data, next: s.sp}
	s.top++
}

func (s *Stack) Pop() interface{} {
	if s.top > 0 {
		item := s.sp.data
		s.sp = s.sp.next
		s.top--
		return item
	}
	return nil
}

func (s *Stack) Peek() interface{} {
	if s.top > 0 {
		return s.sp.data
	}
	return nil
}

func (s *Stack) IsEmpty() bool {
	if s.top == 0 {
		return true
	}
	return false
}

func (s *Stack) Size() int {
	return s.top
}

type Pair struct {
	p   int64
	num int64
}

func primeFactorize(n int64) *Stack {
	s := NewStack()
	for p := int64(2); p*p <= n; p++ {
		if n%p != 0 {
			continue
		}
		num := int64(0)
		for n%p == 0 {
			num++
			n /= p
		}
		s.Push(Pair{p: p, num: num})
	}
	if n != 1 {
		s.Push(Pair{n, 1})
	}
	return s
}

const MOD = 1000000007

func main() {
	sc.Split(bufio.ScanWords)

	N := int64(nextInt())
	ans := int64(1)
	m := map[int64]int64{}
	for i := int64(2); i <= N; i++ {
		vec := primeFactorize(i)

		for !vec.IsEmpty() {
			p := vec.Pop().(Pair)
			m[p.p] += p.num
		}
	}

	for _, v := range m {
		ans *= (v + 1)
		ans %= MOD
	}
	fmt.Println(ans)
}


Measured memory_bytes: 768
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;


int main(){
  int n,a,b;
  scanf ("%d",&n);
  if(n==1){
    printf("Hello World\n");
  }
  else{
    scanf ("%d",&a);
    scanf ("%d",&b);
    printf("%d\n",a+b);
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef struct node {
  struct node *r;
  struct node *l;
  struct node *p;
  int key;
}Node;
Node *root;



void insert(Node *z){
  Node *y = NULL;
  Node *x = root;
  while(x!=NULL){
    y=x;
    if((z->key)<(x->key))x=x->l;
    else x=x->r;
  }
  z->p=y;
  if(y==NULL)root=z;
  else if(z->key<y->key)y->l=z;
  else y->r=z;
}
void inorder(Node *node){
  if(node==NULL){
    return;
  }
  inorder(node->l);
  cout<<" "<<node->key;
  inorder(node->r);
}
void preorder(Node *node){
  if(node==NULL){
    return;
  }
    cout<<" "<<node->key;
    preorder(node->l);
    preorder(node->r);
}
int main(){
  int n,i;
  Node *tmp;
  string str;
  cin>>n;
  for(i=0;i<n;i++){
    cin>>str;
    if(str=="insert"){
      tmp=(Node *)malloc(sizeof(Node));
      tmp->p=tmp->l=tmp->r=NULL;
      cin>>tmp->key;
      
      insert(tmp);
    }
    else{
      inorder(root);
      cout<<endl;
      preorder(root);
      cout<<endl;
    }
  }


  return 0;
}



Measured memory_bytes: 26584
//Doubly Liked List
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node
{
    int key;
    struct node *next;
    struct node *prev;
};
typedef struct node *NodePointer;
NodePointer nil;
NodePointer listSearch(int key)
{
    NodePointer i;
    for (i = nil; i->next != nil; i = i->next)
    {
        if (i->next->key == key)
            return i->next;
    }
    return NULL;
}
void init()
{
    nil = malloc(sizeof(struct node));
    nil->next = nil;
    nil->prev = nil;
}
void printList()
{
    NodePointer cur = nil->next;
    int isf = 1;
    while (1)
    {
        if (cur == nil)
            break;
        if (isf == 0)
            printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
        isf = 0;
    }
    printf("\n");
}
void deleteNode(NodePointer t)
{
    t->next->prev = t->prev;
    t->prev->next = t->next;
    free(t);
}
void deleteFirst()
{
    NodePointer t = nil->next;
    if (t == nil)
        return;
    deleteNode(t);
}
void deleteLast()
{
    NodePointer i;
    i = nil->prev;
    deleteNode(i);
}
void delete (int key)
{
    NodePointer i;
    i = listSearch(key);
    if (i != NULL)
        deleteNode(i);
}
void insert(int key)
{
    NodePointer x;
    x = malloc(sizeof(struct node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}
int main()
{
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    scanf("%d", &n);
    init();
    for (i = 0; i < n; i++)
    {
        scanf("%s%d", com, &key);
        if (com[0] == 'i')
        {
            insert(key);
            np++;
            size++;
        }
        else if (com[0] == 'd')
        {
            if (strlen(com) > 6)
            {
                if (com[6] == 'F')
                    deleteFirst();
                else if (com[6] == 'L')
                    deleteLast();
            }
            else
            {
                delete (key);
                nd++;
            }
            size--;
        }
    }
    printList();
    return 0;
}


Measured memory_bytes: 32972
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
s = input()
if re.fullmatch("A?KIHA?BA?RA?",s):
    print("YES")
else:
    print("NO")


Measured memory_bytes: 10096
#include<iostream>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<iomanip>
using namespace std;
int main(){
	long long int a,b,x;
	cin >> a >> b >> x;
	if(a%x==0)
		cout << (b/x)-(a/x)+1<< endl;
	else
		cout << (b/x)-(a/x) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstring>
using namespace std;
double dp[301][301][301];
double solve(int x,int y,int z,int n)
{  if(x<0||y<0||z<0)
    return 0;
	if(x==0&&y==0&&z==0)
	  return 0;
	  if(dp[x][y][z]>-0.9)
	  return dp[x][y][z];
	  	double exp=n+x*solve(x-1,y,z,n)+y*solve(x+1,y-1,z,n)+z*solve(x,y+1,z-1,n);
	return dp[x][y][z]=exp/(x+y+z);
	
}
int main()
{ memset(dp,-1,sizeof(dp));
	int n;
	cin>>n;
	int one=0,two=0,three=0;
	int x;
	for(int i=0;i<n;i++)
	 { cin>>x;
	  if(x==1)
	 	one++;
	 	else if(x==2)
	 	 two++;
	 	 else 
		  three++;
	 }
	 cout<<fixed<<setprecision(12)<<solve(one,two,three,n);
	
}


Measured memory_bytes: 213376
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
#include <vector>
using namespace std;
typedef long long lint;
typedef unsigned int uint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool flag=c=='-';
	flag?c=getchar():0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return flag?-i:i;
}
template<class T1,class T2>inline void apmax(T1 &a,const T2 &b){if(a<b)a=b;}
template<class T1,class T2>inline void apmin(T1 &a,const T2 &b){if(b<a)a=b;}
const int N=310;
int a[N][N],n,m;
int pt[N];
vector<int>stu[N];
bool vis[N];
inline bool check(uint mx){
	for(int i=1;i<=m;i++){
		stu[i].clear();
		vis[i]=false;
	}
	for(int i=1;i<=n;i++){
		pt[i]=1;
		stu[a[i][1]].push_back(i);
	}
	while(true){
		int x=1;
		for(;x<=m&&stu[x].size()<=mx;x++);
		if(x>m)return true;
		vis[x]=true;
		for(int i=0,ti=stu[x].size();i<ti;i++){
			int cur=stu[x][i];
			for(int &j=pt[cur];j<=m&&vis[a[cur][j]];j++);
			if(pt[cur]>m)return false;
			stu[a[cur][pt[cur]]].push_back(cur);
		}
		stu[x].clear();
	}
}
int main(){
	n=ni,m=ni;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			a[i][j]=ni;
		}
	}
	int l=1,r=n;
	while(l<r){
		int m=(l+r)>>1;
		if(check(m)){
			r=m;
		}else{
			l=m+1;
		}
	}
	printf("%d\n",l);
	return 0;
}

Measured memory_bytes: 1280
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var h = ReadLineIntSpilit();
            var a = ReadLineIntSpilit();
            var att = 0;

            for (int i = 0; i < a.Length; i++) {
                att += a[i];
            }

            Console.WriteLine(((h[0] - att) <= 0) ? "Yes" : "No");
            ReadLine();
        }

        //メモ

        //降順
        //var sort = array.OrderBy(x => -x).ToArray();

        //最大公約数
        static int gcd(int a, int b)
        {
            if (a > b) {
                return gcd(b, a);
            }

            while (b != 0) {
                var remainder = a % b;
                a = b;
                b = remainder;
            }

            return a;
        }

        //最小公倍数
        static int lcm(int a, int b) => a * b / gcd(a, b);

        /// <summary>
        /// コンビネーション
        /// </summary>
        static int nCm(int n, int m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * nCm(n - 1, m - 1) / m;
        }

        public static string ReadLine() => Console.ReadLine();
        public static int ReadLineInt() => int.Parse(Console.ReadLine());
        public static long ReadLineLongInt() => long.Parse(Console.ReadLine());
        public static string[] ReadLineStringSplit(char a = ' ') => ReadLine().Split(a).ToArray();
        public static int[] ReadLineIntSpilit(char a = ' ') => ReadLine().Split(a).Select(x => int.Parse(x)).ToArray();
        public static long[] ReadLineLongSpilit(char a = ' ') => ReadLine().Split(a).Select(x => long.Parse(x)).ToArray();
        static string[] GetAplhaLowerArray() => new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
        static string[] GetAplhaUpperArray() => new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
    }
}


Measured memory_bytes: 19680
fn read<T: std::str::FromStr>() -> T {
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).ok();
	s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
	read::<String>().split_whitespace()
		.map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
	(0..n).map(|_| read_vec()).collect()
}

pub trait LexicalPermutation {
	/// Return `true` if the slice was permuted, `false` if it is already
	/// at the last ordered permutation.
	fn next_permutation(&mut self) -> bool;
}
impl<T> LexicalPermutation for [T] where T: Ord {
	/// Original author in Rust: Thomas Backman <serenity@exscape.org>
	fn next_permutation(&mut self) -> bool {
		// These cases only have 1 permutation each, so we can't do anything.
		if self.len() < 2 { return false; }

		// Step 1: Identify the longest, rightmost weakly decreasing part of the vector
		let mut i = self.len() - 1;
		while i > 0 && self[i-1] >= self[i] {
			i -= 1;
		}

		// If that is the entire vector, this is the last-ordered permutation.
		if i == 0 {
			return false;
		}

		// Step 2: Find the rightmost element larger than the pivot (i-1)
		let mut j = self.len() - 1;
		while j >= i && self[j] <= self[i-1]  {
			j -= 1;
		}

		// Step 3: Swap that element with the pivot
		self.swap(j, i-1);

		// Step 4: Reverse the (previously) weakly decreasing part
		self[i..].reverse();

		true
	}
}

fn main() {
	let n: usize = read();
	let mut a = vec![];
	let mut b = vec![];
	for _ in 0..n {
		let tmp: usize = read();
		a.push(tmp);
		b.push(tmp);
	}
	let max = a.iter().max().unwrap();
	b.sort_by(|a, b| b.cmp(a));

	let mut multi = false;
	if b[1] == *max { multi = true; }
	if multi {
		for _ in 0..n {
			println!("{}", max);
		}
	} else {
		for i in 0..n {
			if a[i] == *max {
				println!("{}", b[1]);
			} else {
				println!("{}", max);
			}
		}
	}
}


Measured memory_bytes: 11320
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll q;
  cin >> q;
  multiset<ll> set1={};//aたちの中で、sortしたときの前半分
  multiset<ll> set2={};//aたちの中で、sortしたときの後ろ半分

  ll p,a,b;
  cin >> p >> a >> b;
  set1.insert(a);
  ll s=b;

  for(int i=1;i<q;i++){
    cin >> p;
    if(p==1){
      cin >> a >> b;
      s+=b;
      if(set1.size()==set2.size()){
        if(a<*prev(set1.end())){
          s+=abs(a-*prev(set1.end()));          
          set1.insert(a);
        }
        else if(a>*set2.begin()){
          s+=abs(a-*set2.begin());
          ll f=*set2.begin();
          set1.insert(f);
          set2.erase(set2.begin());
          set2.insert(a);
        }
        else{
          set1.insert(a);
        }
      }
      else{
        if(a>=*prev(set1.end())){
          s+=abs(a-*prev(set1.end()));
          set2.insert(a);
        }
        else{
          s+=abs(a-*prev(set1.end()));
          ll f=*prev(set1.end());
          set2.insert(f);
          set1.erase(prev(set1.end()));
          set1.insert(a);
        }
      }
    }
    else{
        cout << *prev(set1.end()) << " " << s << endl;
    }
  }

}

Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <algorithm>
#include <iomanip> //cout << fixed << setprecision(12) << ans << endl;
using namespace std;
 
#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--)
#define loop(i, l, r) for(int i = l; i < r; i++)
#define rloop(i, l, r) for(int i = l; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vec_i;

const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
const int INF = 1e9;
const int MOD = 1e9+7;

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

	cout << c - min(c, a - b) << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int N = 1e5+5;
int a[15];
int main()
{
	int n,even=0;
	scanf("%d",&n);
	int tmp=pow(3,n);
	//cout<<tmp<<endl;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]%2==0) even++;
	}
	int ans=tmp-pow(2,even);
	cout<<ans<<endl;
	
} 

Measured memory_bytes: 256
import java.io.*;
import java.util.ArrayList;
import java.*;
public class Main{
	public static void main(String args[]){
    double a=0,b=0,c=0,i=0,n=0,j=0,m=0;
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));



    while(true){
    try{
      i = 0;
      String line = reader.readLine();
      n = Double.parseDouble(line);
      if (n == 0.0) {
        break;
      }
      Double bar[] = new Double[(int)n];
      line = reader.readLine();
      for(String splitted: line.split(" ")){
        bar[(int)i] = Double.parseDouble(splitted);
        i++;
      }
      a = 0;
      for(b=0;b<n;b++){
        a += bar[(int)b];
      }
      m = a / n;

      c = 0;
      for(b=0;b<n;b++){
        c += Math.pow((bar[(int)b] - m),2);
      }
      j = c / n;
      System.out.println(String.format("%.8f", Math.sqrt(j)));
      





		}catch(Exception e){
      break;
    }





  }



  
	}
}


Measured memory_bytes: 26680
#include<bits/stdc++.h>
///...................................*****.................................................///
/// Author : Tanvir Ahmed ///
/// Department of Computer Science ///
/// & Engineering ///
/// Comilla University , Bangladesh. ///
///...................................*****.................................................///

/*....................................Values................................................*/
#define inf 1<<30
#define p5 100007
#define p6 1000007
#define PI acos(-1)
#define M 1000000007

/*....................................Functions.............................................*/
#define sqr(x) x*x
#define sc scanf
#define pf printf
#define scin(x) sc("%d",&(x))
#define scin2(x,y) sc("d",&(x),&(y))
#define scin3(x,y,z) sc("d%d",&(x),&(y),&(z))
#define scln(x) sc("%lld",&(x))
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(v) v.begin(), v.end()
#define ok cout << "ok" << endl
#define mem(x,y) memset(x,y,sizeof(x))
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

/*...................................Data_Types............................................*/
#define lli long long int
#define ull unsigned long long int
#define pii pair < int, int>
#define pll pair < ll, ll>
#define veci vector<int>
#define vecl vector<long long int>
#define vecp vector< pair<int,int> >
#define mapstrint map< string , int >
#define mapstrstr map< string , string >
#define mapint map< int, int >
#define uset unordered_set
#define umap unordered_map
#define pq priority_queue

#define pb push_back
#define mp make_pair
#define ss stringstream

/*.....................................Loops...............................................*/
#define rep( i , a , b ) for( i=a ; i<b ; i++)
#define rev( i , a , b ) for( i=a ; i>=b ; i--)
#define repx( i ,a,b, x) for( i=a ; i<b ; i+=x)

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

//int month[]={31,28,31,30,31,30,31,31,30,31,30,31};
//long power(long int x, long int y){ int temp; if( y == 0) return 1; temp = power(x, y/2); if (y%2 == 0) return temp*temp; else return x*temp*temp; }
/*lli gcd(lli x,lli y)
{
if(x==0) return y;
return gcd(y%x,x);
}*/
/*
int dx[5] = {1, -1, 0, 0 };
int dy[5] = {0, 0, 1, -1};
*/

using namespace std;

int node,edge,dp[100005];
vecl vec[100005];

int dynamic(int start)
{
    if(dp[start] != -1)
        return dp[start];
    int mx = 0;
    for(int i=0; i<vec[start].size(); i++)
    {
        int v=vec[start][i];
        mx = max(mx,1+dynamic(v));
    }
    return dp[start] = mx;
}

int main()
{
    scin(node);
    scin(edge);
    for(int i=1; i<=edge; i++)
    {
        int u,v;
        scin(u),scin(v);
        vec[u].pb(v);
    }
    memset(dp,-1,sizeof(dp));
    int mx=0;
    for(int i=1; i<=node; i++)
    {
        mx = max(mx,dynamic(i));
    }
    cout<<mx<<endl;
    return 0;
}


Measured memory_bytes: 8192
#include<iostream>
#include<queue>
#include<cstdio>
#include<vector>
#include<cassert>
#include<cstdlib>
#include<algorithm>
#include<ctime>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

class st{
public:
  int now,cost;
  bool operator<(const st a)const{
    return cost > a.cost;
  }
};

struct Edge{int f,t,c;};

const int N = 3000;
const int inf = (1<<25);
int cost[N];
vector<Edge> edge[N];
void dijkstra(int n,vector<int> s){
  priority_queue<st> Q;
  rep(i,n)cost[i] = inf;
  rep(i,s.size()){
    cost[s[i]] = 0;
    Q.push((st){s[i],0});
  }
  while(!Q.empty()){
    st now = Q.top();Q.pop();
    if (cost[now.now] != now.cost)continue;
    rep(i,edge[now.now].size()){
      int next = edge[now.now][i].t;
      int nec = now.cost + edge[now.now][i].c;
      if (cost[next] > nec){
	cost[next] = nec;
	Q.push((st){next,nec});
      }
    }
  }
}

int solve(int n,vector<int> &s){
  dijkstra(n,s);
  double ans = 0;
  rep(i,n)ans = max(ans,(double)cost[i]);
  rep(i,n){
    rep(j,edge[i].size()){
      int f = edge[i][j].f,t=edge[i][j].t,l=edge[i][j].c;
      int a = max(cost[f],cost[t]),b=min(cost[f],cost[t]);
      if (b+l <= a)continue;
      double tmp = ((a-b)+l)*0.5;
      //cout << f <<" " <<t <<" " << tmp << endl;
      ans = max(ans,min(cost[f]+tmp,cost[t]+tmp));
    }
  }
  //cout << ans << endl;
  printf("%d\n",(int)(ans+0.5));
}

main(){
  int n,m,q;
  while(cin>>n>>m>>q){
    vector<int> s(q);
    rep(i,n)edge[i].clear();
    rep(i,m){
      int f,t,c;
      cin>>f>>t>>c;
      f--;t--;
      edge[f].push_back((Edge){f,t,c});
      edge[t].push_back((Edge){t,f,c});
    }
    rep(i,q)cin>>s[i],s[i]--;
    solve(n,s);
  }
}

Measured memory_bytes: 0
import sys
from collections import Counter

input = sys.stdin.readline

S = input().strip()
T = input().strip()

dic_s = Counter([i for i in S])
dic_t = Counter([i for i in T])

arr_s = sorted([i for i in dic_s.values()])
arr_t = sorted([i for i in dic_t.values()])

if arr_s == arr_t:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 5928
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);
        int n = scn.nextInt();
        int m = scn.nextInt();
        int l = scn.nextInt();
        int[][] a = new int[n][m], b = new int[m][l];
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                a[i][j] = scn.nextInt();
            }
        }
        for(int i = 0; i < m; i++) {
            for(int j = 0; j < l; j++) {
                b[i][j] = scn.nextInt();
            }
        }
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < l; j++) {
                long v = 0;
                for(int k = 0; k < m; k++) {
                    v += a[i][k] * b[k][j];
                }
                System.out.print((j > 0 ? " " : "") + v);
            }
            System.out.println();
        }
    }
}

Measured memory_bytes: 44856
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b)
{
  if (b == 0)
  {
    return a;
  }
  return gcd(b, a % b);
}
int main()
{
  int a, b;
  cin >> a >> b;
  cout << gcd(a, b) << endl;
  return 0;
}



Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(cnt,e) for(ll cnt=0;cnt<e;cnt++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT64_MAX;

ll i,j,k;


int main(){
   string S;
   cin>>S;
   ll m=0;
   V a(S.length()+1);

   a[0]=0;
   ll cnt=0;
   ll peak=0;
   bool jud=true;
   while(true){
       while(S[cnt]=='<'&&cnt<S.length()){
           cnt++;
       }
      
       for(ll p=peak+1;p<=cnt;p++){
           a[p]=a[p-1]+1;
       }
       peak=cnt;
       while(S[cnt]=='>'&&cnt<S.length()){
           cnt++;
       }
       if(a[peak]-(cnt-peak)>=0){
           a[cnt]=0;
           for(ll i=cnt-1;i>peak;i--)a[i]=a[i+1]+1;
           peak=cnt;
       }
       else{
           a[cnt]=0;
           for(ll i=cnt-1;i>=peak;i--)a[i]=a[i+1]+1;
           peak=cnt;
       }
       if(cnt>=S.length())break;

   }
   ll ans=0;
   rep(i,S.length()+1)ans+=a[i];
   if(S[S.length()-1]=='<')ans+=a[S.length()-1]+1;

   cout<<ans<<endl;
}

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

#define ll long long

int main(){
    ll n;
    cin>>n;
    ll arr[n];
    unordered_map<ll,ll>mp;
    ll count = 0;
    for (int i=0;i<n;++i){
        cin>>arr[i];
        mp[arr[i]]++;
        count+=arr[i];
    }
    ll q;
    cin>>q;
    while(q--){
        ll b,c;
        cin>>b>>c;
        if (mp[b]){
            count-=b*mp[b];
            count+=mp[b]*c;
            mp[c]+=mp[b];
            mp[b]=0;
        }
        cout<<count<<"\n";
    }

    
}

Measured memory_bytes: 7668
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll &b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll &b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
ll num=1, ans=0, count=0, sum=0;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S;
  cin >> S;
  bool T=0;
  rep(i, 3) if(S[i]=='7') T=1;
  if(T) cout << "Yes" << '\n';
  else cout << "No" << '\n';
  return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
typedef long long lint;

namespace utils{
	template <class T> inline void apn(T &x,const T y){x=x<y?x:y;}
	template <class T> inline void apx(T &x,const T y){x=x>y?x:y;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=c=='-'&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

int main(){
	const int n=nxi(),m=nxi();
	printf("%d\n",(1<<m)*(n*100+m*1800));
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
ll n,m,l,x[66],y[66],z[66],last;
int main()
{
	cin>>l;
	n=20;
	for(ll i=2;i<=n;i++)
	{
		if((1<<(i-1))<=l)
			m++,x[m]=i-1,y[m]=i,z[m]=(1<<(i-2)),last+=z[m];
		m++,x[m]=i-1,y[m]=i,z[m]=0;
	}
	for(ll i=n;i>=1;i--)
		if(((l-1-last)>>(i-1))&1)
			m++,x[m]=i,y[m]=n,z[m]=last+1,last+=(1<<(i-1));
	cout<<n<<" "<<m<<endl;
	for(ll i=1;i<=m;i++)
		cout<<x[i]<<" "<<y[i]<<" "<<z[i]<<endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())

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

for i, ai in enumerate(a):
    cnt = 0
    for j, bj in enumerate(b):
       cnt += ai[j] * bj
    print(cnt)


Measured memory_bytes: 6016
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}


int main(){
    ll n,ans=0;
    cin >> n;
    for (ll i=1;i<=n;i++){
        if (i%3 and i%5){
            ans+=i;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
import java.io.IOException;
import java.io.PrintWriter;
import java.io.InputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main {
    static class Reader {
        private BufferedReader br;
        private StringTokenizer token;

        protected Reader(InputStream obj) {
            br = new BufferedReader(new InputStreamReader(obj));
            token = null;
        }
        protected String next() {
            while (token == null || !token.hasMoreElements()) {
                try {
                    token = new StringTokenizer(br.readLine());
                } catch (IOException e) {e.printStackTrace();}
            }
            return token.nextToken();
        }
        protected int[] nextIntArr(int n) {
            int[] arr = new int[n];
            for (int i=0; i<n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }
        protected int nextInt() {return Integer.parseInt(next());}
    }


    public static void main(String[] args) throws IOException {
        Reader in = new Reader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
//        int[][] arr = new int[n][3];
        boolean sol_present = true;
        for (int i=0; i<n; i++) {
            int t = in.nextInt(), x = in.nextInt(), y = in.nextInt();
            int z = x+y;
            if ((z&1) == 0 && (t&1) == 0) {
                if (t<z) {sol_present = false;}
            }
            else if ((z&1) == 1 && (t&1) == 1){
                if (t<z) {sol_present = false;}
            }
            else {
                sol_present = false;
            }
        }
        if (sol_present) out.printf("%s\n", "Yes");
        else out.printf("%s\n", "No");
        out.close();
    }
}

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

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
constexpr int INF = 1<<30;
constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  int N;
  cin >> N;
  vll A(N);
  for (int i=0; i<N; i++) {
    cin >> A[i];
  }

  ll ret = A[0]-1;
  ll p = 2;

  for (int i=1; i<N; i++) {
    if (A[i] == p) {
      p++;
      continue;
    }

    ll q = A[i]/p;
    if (q==0) {
      continue;
    }

    ll r = A[i]%p;
    if (r==0) {
      q--;
    }
    ret += q;

//cerr << "i " << i << ", ret " << ret << ", p " << p << " --- " << A[i] << endl;
  }

  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int main(){
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    int diff = h * 5 - m;
    double arg = abs(diff) * acos(-1.0) / 30.0;
    if(diff > 0) arg += m * acos(-1.0) / 360.0;
    else arg -= m * acos(-1.0) / 360.0;
    double ans = sqrt(a*a + b*b - 2*a*b*cos(arg));
    printf("%.24lf\n", ans);
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

using ll = long long int;
using P = pair<int,int>;

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; }

const ll INF=(ll)1e19;
//const int INF=(1<<30);

int main(){
  string s;
  cin >> s;
  cout << (stoi(s.substr(5,2)) <= 4 ? "Heisei" : "TBD") << endl;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
main(){
    char c[3][3];
    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            cin >> c[i][j];
        }
    }
    cout << c[0][0] << c[1][1] << c[2][2] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll w,h,n;
    cin>>w>>h>>n;
    ll x1=0,y1=0,x2=w,y2=h;
    while(n--){
        ll x,y;
        cin>>x>>y;
        ll a;
        cin>>a;
        if(a==1){
            if(x>x1)
                x1=x;
        }
        else if(a==2){
            if(x<x2)
                x2=x;
        }
        else if(a==3){
            if(y>y1)
                y1=y;
        }
        else if(a==4){
            if(y<y2)
                y2=y;
        }
    }
    if((x1>x2) || (y1>y2))
        cout<<0<<endl;
    else
        cout<<(x2-x1)*(y2-y1)<<endl;
}


Measured memory_bytes: 256
def solve(shoki):
    global n,k,p,c
    sude=[-1]*n
    sude[shoki]=0
    ten=[0]
    now=shoki
    ishuu_kai=0
    ishuu_ten=0
    for i in range(n):
        now=p[now]
        if(sude[now]<0):
            sude[now]=i+1
            ten.append(ten[-1]+c[now])
        else:
            ten.append(ten[-1]+c[now])
            ishuu_kai=i+1-sude[now]
            ishuu_ten=ten[-1]-ten[sude[now]]
            break
    #print(shoki)
    #print(ten,ishuu_kai,ishuu_ten)
    if(ishuu_ten>0):
        now=shoki
        for i in range(ishuu_kai):
            ten[i]+=((k-i)//ishuu_kai)*ishuu_ten
            now=p[now]

    #print(ten,ishuu_kai,ishuu_ten)
    if(k>ishuu_kai):
        return max(ten)
    else:
        return max(ten[1:k+1])


n,k=map(int,input().split())
p=list(map(int,input().split()))
c=list(map(int,input().split()))

for i in range(n):
    p[i]-=1


ans=[]
for i in range(n):
    ans.append(solve(i))

print(max(ans))

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

int main() {
    ll n;
    cin >> n;
    vector<pair<ll,ll>> a(n);
    rep(i, 0, n) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a.begin(), a.end(), greater<pair<ll,ll>>());
    vector<vector<ll>> dp(n+10, vector<ll>(n+10, 0));
    rep(i, 0, n) {
        rep(l, 0, i+1) {
            ll r = i - l;
            dp[l+1][r] = max(dp[l+1][r], dp[l][r] + a[i].first * (a[i].second - l));
            dp[l][r+1] = max(dp[l][r+1], dp[l][r] + a[i].first * ((n-1 - r) - a[i].second));
        }
    }
    ll ans = 0;
    rep(i, 0, n+1) ans = max(ans, dp[i][n-i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 34888
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int a[100],n,k,ans=0;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
/*a+=b
	a=a+b;*/
	sort(a,a+n);
	for(int i=n-1;i>=n-k;i--){
		ans+=a[i];
	}
	
	cout<<ans<<endl;
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define MOD (int)1e9+(int)7
#define INF 2147483647
typedef long long ll;
typedef unsigned long long ull;
//dark power
//#define int ll
//define Error、大抵は、セミコロン忘れとか、Defineは関係ない
//komennto C+udekaijo

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c;
	cin>>a>>b>>c;
	if((b/a)>c){
		cout<<c;
		return 0;
	}else cout<<int(b/a)<<endl;
	return 0;
}


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

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

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int H, W, N; cin >> H >> W >> N;
	if (H < W) swap(H, W);
	int i = 0;
	while (i * H < N) ++i;
	print(i);
}

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

int main(){
	int a,b;
	cin >>a>>b;
	if(a>=b){
		for(int i =0;i<a;i++){
			cout << b;
		}
	}else{
		for(int i =0;i<b;i++){
			cout << a;
		}
	}
	return 0;
}

Measured memory_bytes: 256
/* C++14(GCC5.4.1) */
#include <bits/stdc++.h>
using namespace std;
using ll=long long;

int main(void){
    // 入力
    ll N; cin >> N;
    vector< pair<ll,ll> > jobs(N);
    for(int i=0; i<N; i++){
        // 締め切り順にソートしたいのでfirstにBを入れる
        cin >> jobs[i].second >> jobs[i].first;
    }
    // 仕事を締め切り順にならべかえる
    sort(jobs.begin(),jobs.end());

    // feasibleはできるかどうかのflag
    bool feasible=true;
    ll time=0;

    // 順番に仕事をこなす
    for(int i=0; i<N; i++){
        time+=jobs[i].second;
        if(time > jobs[i].first){
            feasible = false;
        }
    }

    // feasible=trueのままなら "Yes"
    if(feasible) cout << "Yes" << "\n";
    else cout << "No" << "\n";

    return 0;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n,a,b;
	cin>>n>>a>>b;
	string s;
	cin>>s;
	int j = 0;vector<int>v(a),c(a);
	for(int i = 0; i<s.length(),j<a; i++)
		if(s[i]=='o')
		{
			v[j++]=i;
			i += b;
		}
	j = a-1;
	for(int i = s.length()-1; i>=0,j>=0; i--)
		if(s[i]=='o')
		{
			c[j--]= i;
			i -=b;
		}
	for(int i = 0; i<a; i++)
	{
		if(v[i]==c[i])
			cout<<v[i]+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 3348
#include  <iostream>
#include <algorithm>

int main() {

	int n; std::cin >> n;
	long long int max = 0;
	long long int ans = 0;

	for (int i = 0; i < n; ++i) {

		long long int a; std::cin >> a;
		max = std::max(a, max);
		ans += max - a;

	}

	std::cout << ans<< std::endl;

	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int k, n;
  cin >> k >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; ++i) {
    cin >> a.at(i);
    if (i > 0) {
      b.at(i) = a.at(i) - a.at(i-1);
    }
  }
  b.at(0) = a.at(0) + (k - a.at(n-1));
  int m = 0;
  for (int i = 0; i < n; ++i) {
    if (b.at(i) > m) {
      m = b.at(i);
    }
  }
  cout << k - m << endl;
  return 0;
}



Measured memory_bytes: 1920