akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main() {
  int a;
  int b;
  int c;
  cin >> a >> b >> c;
  if(a < b && b < c) {
    cout << "Yes" << endl;
      } else {
    cout << "No" << endl;
  }
  return 0;
}
  


Measured memory_bytes: 3096
#include<stdio.h>
#define g -3
#define w -2
#define b -1

int temp[101],d[101],f[101];
int time,N;
int A[101][101];

void DFS();

void DFSvisit(int u){
  int v;

  temp[u]=g;
  time++;
  d[u]=time;

  for(v=1;v<=N;v++){
    if(A[u][v]==0){
      continue;
    }
    if(temp[v]==w){
      DFSvisit(v);
    }
  }  
  
  temp[u] = b;
  f[u] = ++time;
}

void DFS(){
  int i;
  for(i=1;i<=N;i++){
    temp[i] = w;
  }

  time=0;

  for(i=1;i<=N;i++){
    if(temp[i]==w){
      DFSvisit(i);
    }
  }
}

int main (){

  int i,j,k,n,u;

  for(i=1;i<101;i++){
    for(j=1;j<101;j++){
      A[i][j] = 0;
    }
  }

  scanf("%d",&N);

  for(i=1;i<=N;i++){ 
    scanf("%d %d",&n,&k); 
    for(j=1;j<=k;j++){
      scanf("%d",&u);
      A[n][u] = 1;
    }
  }

  DFS();
   for(i=1;i<=N;i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }

  return 0;
}

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

n = 1

M = N
while M // 10 != 0:
    M //= 10
    n += 1
# nはNの桁数

c = N // (10 ** (n - 1))  # cはNの最高位
d = N % 10  # dはNの最低位


def f(a, b):  # N以下の最高位a、最低位bの正整数の個数
    if a < c:
        if a == b:
            return ((10 ** (n - 1)) // 9) + 1
        else:
            return ((10 ** (n - 1)) // 9)
    elif a > c:
        if a == b:
            if n == 1:
                return 0
            else:
                return ((10 ** (n - 2)) // 9) + 1
        else:
            if n == 1:
                return 0
            else:
                return ((10 ** (n - 2)) // 9)
    else:
        if a == b:
            if n == 1:
                return 1
            elif n == 2:
                if b <= d:
                    return 2
                else:
                    return 1
            else:
                if b <= d:
                    return 2 + (10 ** (n - 2)) // 9 + (N - c * (10 ** (n - 1))) // 10
                else:
                    return 1 + (10 ** (n - 2)) // 9 + (N - c * (10 ** (n - 1))) // 10
        else:
            if n == 1:
                return 0
            elif n == 2:
                if b <= d:
                    return 1
                else:
                    return 0
            else:
                if b <= d:
                    return 1 + (10 ** (n - 2)) // 9 + (N - c * (10 ** (n - 1))) // 10
                else:
                    return 0 + (10 ** (n - 2)) // 9 + (N - c * (10 ** (n - 1))) // 10


ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        ans += f(i, j) * f(j, i)

print(ans)

Measured memory_bytes: 38384
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	length, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	array := strings.Split(sc.Text(), " ")

	fmt.Println(strings.Join(array, " "))

	for i := 0; i < length-1; i++ {

		for j := i + 1; j > 0; j-- {
			val2, _ := strconv.Atoi(array[j])
			val3, _ := strconv.Atoi(array[j-1])
			if val3 > val2 {
				array[j-1] = strconv.Itoa(val2)
				array[j] = strconv.Itoa(val3)
			} else {
				break
			}
		}
		fmt.Println(strings.Join(array, " "))
	}
}



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

int main(){
  string a;
  cin >> a;
  int cou = 0;
  int ans = 0;
  for(int i = 0; i < a.size(); i++){
    if(a[i] == 'A' || a[i] == 'C' || a[i] == 'G' || a[i] == 'T'){
      cou++;
      ans = max(ans, cou);
    }
    else{
      cou = 0;
    } 
  }
  cout << ans << endl;
}

  
  
  

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;
#define ll long long
#define inf 0x7fffffff
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a+b>c+d) cout<<"Left"<<"\n";
	else if(a+b==c+d) cout<<"Balanced"<<"\n";
	else if(a+b<c+d) cout<<"Right"<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>
#include<queue>
#include<utility>
#include<cmath>
#include<sstream>
#include<istream>
#include<numeric>
#include<stdlib.h>

using namespace std;

int main()
{

  int a, b, c;
  cin >> a >> b >> c;

  if((a+b) == c){
    cout << "Yes" << endl;
  }
  else if((a+c) == b){
    cout << "Yes" << endl;
  }
  else if((b+c) == a){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 3528
#include<bits/stdc++.h>
using namespace std;
#define loop(i,x,z) for (int i=x;i<z;i++)
int n, m, h[100002];
set<int>ed[100002];
bool vis[100002];
void dfs(int num)
{
	vis[num] = 1;
	bool flag = 1;
	for (auto it : ed[num])
	{
		if (h[it] - h[num] >= 0)flag = 0;
		if (!vis[it]) dfs(it);
	}
	if (flag)m++;
}
int main()
{
	cin >> n >> m;
	loop(i, 1, n + 1)cin >> h[i];
	while (m--)
	{
		int a, b;
		cin >> a >> b;
		ed[a].insert(b);
		ed[b].insert(a);
	}
	m = 0;
	loop(i, 1, n + 1)if (!vis[i])dfs(i);
	cout << m;
}

Measured memory_bytes: 20232
#include<iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int a[n];
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int b[2 * 100000 + 1] = {0};
    int st = n / 2;
    if (n % 2 == 0) {
        b[st] = a[0];
        for (int i = 1; i < n; ++i) {
            int cont;
            if (i % 2 == 0) {
                cont = 1;
                cont *= i / 2;
            } else {
                cont = -1;
                cont *= i / 2 + 1;
            }
            b[st + cont] = a[i];
        }
    } else {
        b[st] = a[0];
        for (int i = 1; i < n; ++i) {
            int cont;
            if (i % 2 == 0) {
                cont = -1;
                cont *= i / 2;
            } else {
                cont = 1;
                cont *= i / 2 + 1;
            }
            b[st + cont] = a[i];
        }
    }
    for (int i = 0; i < n; ++i) {
        cout << b[i] << " ";
        if (i == n - 1) cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
inline bool chmin (int& a, int b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
class low_link_tree {
	int n;
	int tmr;
	int rt = 0;
	vector<int> ord;
	vector<int> low;
	set<int> atc;
	set<pair<int, int>> bdg;
	vector<vector<int>> grh;
public:
	low_link_tree (
		vector<vector<int>> const& grh
	)
	: n(grh.size())
	, ord(n, -1)
	, low(n, -1)
	, grh(grh)
	{
		dfs(0, 0);
	}
	void dfs (
		int crr
	,	int prt
	) {
		int cnt = 0;
		ord[crr] = low[crr] = tmr++;
		for (int nxt : grh[crr]) {
			if (ord[nxt] == -1) {
				cnt++;
				dfs(nxt, crr);
				chmin(low[crr], low[nxt]);
				if (crr != rt && ord[crr] <= low[nxt]) atc.insert(crr);
				if (ord[crr] < low[nxt]) bdg.emplace(min(crr, nxt), max(crr, nxt));
			}
			if (nxt != prt) chmin(low[crr], ord[nxt]);
		}
		if (crr == rt && cnt > 1) atc.insert(crr);
	}
	auto const &order() {return ord;}
	auto const &low_link() {return low;}
	auto const &articulation_points() {return atc;}
	auto const &bridges() {return bdg;}
};
int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> grh(n);
	for (int i = 0; i < m; i++) {
		int s, t;
		cin >> s >> t;
		grh[s].push_back(t);
		grh[t].push_back(s);
	}
	auto bdg = low_link_tree(grh).bridges();
	for (auto it = bdg.begin(); it != bdg.end(); it++) {
		cout << it->first << ' ' << it->second << '\n';
	}
	cout << flush;
	return 0;
}


Measured memory_bytes: 5008
#include<iostream>
#include<string.h>
using namespace std;
long long a[1005],num[105];
int main()
{
	long long n,m,sum,q,w;
	cin>>n;
	sum=0;
	memset(a,0,sizeof(a));
	memset(num,0,sizeof(num));
	for(int i=1;i<=n;i++)
	{
	    cin>>a[i];
	    sum+=a[i];
	}
	cin>>m;
	for(int j=1;j<=m;j++)
	{
		cin>>q>>w;
		num[j]=sum-a[q]+w;
	}
	for(int j=1;j<=m;j++)
	cout<<num[j]<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>


using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	long long m = 1e9 + 7;
	vector<long long> a(n + 2);
	for (int i = 1; i <= n + 1; ++i)
	  a[i] = a[i - 1] + i;
	long long s = 0;
	for (int i = k; i <= n + 1; ++i) {
		long long l = a[i] - a[0];
		long long h = a[n + 1] - a[n - i + 1];
		s = (s + h - l + 1) % m;
  }
	cout << s << endl;
  return 0;
}


Measured memory_bytes: 4840
import Control.Monad
import Data.List as List
import Debug.Trace
import Data.Map as Map hiding (map, filter)
import Data.Sequence (elemIndexR)

type Region = (Int, Int, Int, Int)

main = do
  n <- liftM read getLine
  replicateM n analyze

analyze = do
  [h, w] <- liftM (map read . words) getLine
  image <- getImage h w
  let (suspicious, m) = nonRect image
  let (suspicious', _) = nonRect $ transpose image
  let tiles = nub $ concat $ image
  let loops = any (\a -> overlayLoops image tiles a []) tiles
  putStrLn $ if suspicious || suspicious' || loops then "SUSPICIOUS" else "SAFE"

overlayLoops image tiles a visited =
  any (\b -> b `elem` visited || overlayLoops image tiles b (b:visited)) $ filter (\b -> overlays image b a) $ filter ((/=) a) tiles

-- a overlays b
overlays :: [[Char]] -> Char -> Char -> Bool
overlays image a b =
  let y0 = minimum $ findIndices (elem b) image
      y1 = maximum $ findIndices (elem b) image
      x0 = minimum $ concatMap (elemIndices b) image
      x1 = maximum $ concatMap (elemIndices b) image
  in a `elem` [ image !! y !! x | y <- [y0..y1], x <- [x0..x1] ]

nonRect :: [[Char]] -> (Bool, Map (Char, Char) Int)
nonRect xs = nonRect' (zipWith (\xs ys -> xs `zip` ys) (init xs) (tail xs)) 0 empty

nonRect' :: [[(Char, Char)]] -> Int -> Map (Char, Char) Int -> (Bool, Map (Char, Char) Int)
nonRect' [] _ m = (False, m)
nonRect' (trans:tt) i m =
  let (newM, ok) = List.foldl ( \(m, ok) (x, y) ->
                            if not ok
                              then (m, False)
                              else
                                if x == y
                                  then (m, True)
                                  else if i /= findWithDefault i (x, y) m
                                    then (m, False)
                                    else (Map.insert (x, y) i m, True)
                          ) (m, True) trans
  in
    if not ok
      then (True, newM)
      else nonRect' tt (i+1) newM

getImage h w = do
  replicateM h getLine

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

ll big[100010];

int main(){
    ll N;cin>>N;
    ll a[100010],b[100010];
    rep(i,0,N)cin>>a[i];
    rep(i,0,N)cin>>b[i];
    ll cn=0,cn2=0;
    rep(i,0,N){
        if(a[i]>b[i]){
            big[i]=1;
            cn+=a[i]-b[i];
        }
        else{
            cn2+=(b[i]-a[i])/2;
        }
    }
    if(cn2>=cn)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}







Measured memory_bytes: 512
use std::collections::VecDeque;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let m: usize = sc.read();
    let mut graph = vec![vec![]; n];
    for _ in 0..m {
        let a = sc.read::<usize>() - 1;
        let b = sc.read::<usize>() - 1;
        graph[a].push(b);
    }

    let mut ans = vec![];
    for start in 0..n {
        let mut q = VecDeque::new();
        let mut dist = vec![n; n];
        let mut prev = vec![n; n];
        dist[start] = 0;
        q.push_back(start);
        while let Some(v) = q.pop_front() {
            for &next in graph[v].iter() {
                if dist[next] > dist[v] + 1 {
                    dist[next] = dist[v] + 1;
                    prev[next] = v;
                    q.push_back(next);
                } else {
                    let mut cur = v;
                    let mut path = vec![cur];
                    while cur != next && cur != start {
                        cur = prev[cur];
                        path.push(cur);
                    }
                    if cur == next && (ans.is_empty() || ans.len() > path.len()) {
                        ans = path;
                    }
                }
            }
        }
    }

    if ans.is_empty() {
        sc.write("-1\n");
    } else {
        sc.write(format!("{}\n", ans.len()));
        for ans in ans.into_iter() {
            sc.write(format!("{}\n", ans + 1));
        }
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();

        int num = Integer.parseInt(a + b);

        int s = (int)Math.sqrt(num);

        if(s * s == num){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

struct Mod {
    static constexpr auto kMod = 1000000007L;
    static constexpr auto kIMod = 1000000005L;

    // can be implicitly converted
    Mod(int64_t n) : n(n) {}

    Mod operator*(Mod m) const {
        return (n * (m.n % kMod)) % kMod;
    }

    Mod& operator*=(Mod m) {
        *this = *this * m;
        return *this;
    }

    Mod pow(int64_t p) {
        if (p == 0) {
            return 1;
        }
        if (p == 1) {
            return n;
        }

        int64_t r = this->pow(p/2).n;
        if (p % 2 == 0) {
            return r * r % kMod;
        } else {
            return (r * r % kMod) * n % kMod;
        }
    }

    Mod operator/(Mod m) const {
        if (n == 0) {
            return 0;
        }

        return *this * m.pow(kIMod);
    }

    Mod& operator/=(Mod m) {
        *this = *this / m;
        return *this;
    }

    Mod operator+(Mod m) const {
        return (n + m.n) % kMod;
    }

    Mod& operator+=(Mod m) {
        *this = *this + m;
        return *this;
    }

    int64_t n;
};


main() {
    int64_t n, m, k;
    cin >> n >> m >> k;

    Mod ans = 1;
    for (auto i : irange(1L, n * m + 1)) {
        ans *= i;
    }

    for (auto i : irange(1L, k + 1)) {
        ans /= i;
    }

    for (auto i : irange(1L, n * m - k + 1)) {
        ans /= i;
    }

    cerr << ans.n << endl;

    ans *= n + m;
    ans *= k;
    ans *= k - 1;

    cerr << ans.n << endl;

    ans /= 6;

    cout << ans.n << endl;
}

Measured memory_bytes: 256
n = int(input())
a_s = list(map(int, input().split()))
count_a = [0] * (n+1)

for a in a_s:
  count_a[a] += 1

choices = sum(map(lambda x: x*(x-1)//2, count_a))

for a in a_s:
  print(choices - (count_a[a]-1))


Measured memory_bytes: 81612
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
//1-indexed
#include<vector>
template<typename T>
struct BIT{
	int n;
	vector<T>bit;
	BIT(int n_=0,T a=0):n(n_),bit(n_+1,a){}
	T sum(int i)
	{
		T ans=0;
		for(;i>0;i-=i&-i)ans+=bit[i];
		return ans;
	}
	void add(int i,T a)
	{
		if(i==0)return;
		for(;i<=n;i+=i&-i)bit[i]+=a;
	}
};
int n;
char c[4040];
int x[4040],idb[2020],idw[2020];
int dp[2020][2020];
int cb[2020],cw[2020];
main()
{
	cin>>n;
	for(int i=0;i<n+n;i++)
	{
		cin>>c[i]>>x[i];
		if(c[i]=='B')idb[x[i]]=i+1;
		else idw[x[i]]=i+1;
	}
	for(int i=0;i<=n;i++)for(int j=0;j<=n;j++)dp[i][j]=1e9;
	dp[0][0]=0;
	BIT<int>b(n+n);
	for(int i=0;i<=n;i++)
	{
		BIT<int>w(n+n);
		for(int j=0;j<n;j++)
		{
			w.add(idw[j+1],1);
			dp[i][j+1]=min(dp[i][j+1],dp[i][j]+idw[j+1]-b.sum(idw[j+1])-w.sum(idw[j+1]));
		}
		if(i<n)
		{
			b.add(idb[i+1],1);
			BIT<int>w(n+n);
			for(int j=0;j<=n;j++)
			{
				dp[i+1][j]=min(dp[i+1][j],dp[i][j]+idb[i+1]-b.sum(idb[i+1])-w.sum(idb[i+1]));
				w.add(idw[j+1],1);
			}
		}
	}
	cout<<dp[n][n]<<endl;
}

Measured memory_bytes: 16128
N, M, K = map(int, input().split())
ans = [0] * (N + 1)
child = {i:[] for i in range(1, N+1)}
isChecked = [0] * (N + 1)
isBlocked = [set() for _ in range(N+1)]

for _ in range(M):
    a, b = map(int, input().split())
    child[a].append(b)
    child[b].append(a)
    
for _ in range(K):
    c, d = map(int, input().split())
    isBlocked[c].add(d)
    isBlocked[d].add(c)
    
for i in range(1, N+1):
    if isChecked[i]:
        continue
    isChecked[i] = 1
    x = set([i])
    ch = child[i].copy()
    while ch:
        c = ch.pop()
        if isChecked[c]:
            continue
        isChecked[c] = 1
        x.add(c)
        ch.extend(child[c])
    for j in x:
        ans[j] = len(x) - 1 - len(child[j]) - len(x & isBlocked[j])
        
print(*ans[1:])

Measured memory_bytes: 73012
#include<stdio.h>
#include<string.h>
int main() {
	char s[101], p[101], r[202];
	scanf("%s", s);
	scanf("%s", p);
	strcpy(r, s);
	strcat(r, s);
	if (strstr(r, p) == NULL) {
		printf("No\n");
	}
	else {
		printf("Yes\n");
	}
	return 0;
}

Measured memory_bytes: 540
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#ifndef _DEBUG
#define main_ main
#endif
#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)

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

template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
	return left.second > right.second;
}

void init_global() {}

int main_() {
	int A, B;
	cin >> A >> B;

	int ans = (A + B) % 24;

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


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

string s;
int intervalCount = 1;
int main() {
    ios_base::sync_with_stdio(false);
    
    cin >> s;
    
    for (int i = 0; i < s.length()-1; i++) {
        if (s[i] == s[i+1])
            continue;
        else
            intervalCount++;
            
    }
    
    cout << intervalCount - 1 << endl;
    
    return 0;
}

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

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

    map<string, int> S;
    string s;
    for (int i = 0; i < N; i++)
    {
        cin >> s;
        S[s]++;
    }

    int maxv = 0;
    for (auto x : S)
    {
        maxv = max(maxv, x.second);
    }

    for (auto x : S) {
        if (x.second == maxv) {
            cout << x.first << endl;
        }
    }


}

Measured memory_bytes: 25216
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <iomanip>
#include <deque>
#include <cassert>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <chrono>
#include <ctime>
#include <random>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <iterator>
#include <climits>
using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
#define INF 2001001001
#define MOD 1000000007

ll N,A,B;

ll try1(ll a, ll b){
  ll T=min(a-1,b-1);
  a-=T;
  b-=T;
  if (a>1)
    a--;
  else
    b--;
  T++;
  T+=abs((a-b)/2);
  return T;
}

ll tryN(ll a, ll b){
  ll T=min(N-a,N-b);
  a+=T;
  b+=T;
  if (a<N)
    a++;
  else
    b++;
  T++;
  T+=abs((a-b)/2);
  return T;
}

int main()
{
  //ios_base::sync_with_stdio(0);cin.tie(0);
  //freopen (".in","r",stdin);
  cin>>N>>A>>B;
  ll diff=abs(A-B);
  if (diff%2==0)
    cout<<diff/2<<endl;
  else
    cout<<min(try1(A,B),tryN(A,B))<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=998244353,MAX=100005,INF=1<<28;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int A,B;cin>>A>>B;
        
        if(A==0&&B==0) break;
        
        double ans=INF;
        
        for(int i=0;i<=A;i++){
            ans=min(ans,abs(hypot(i,A-i)-B));
        }
        
        cout<<ans<<endl;
    }
}



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

using namespace std;







int main(){

	int n, m; cin >> n >> m;


	vector <int> a(m), b(m), mask(m), p(n);


	p[0] = 1;

	for(int i = 1; i < n; i++){
		p[i] = p[i - 1] << 1;
	}

	vector < vector <int> > c(m);


	for(int i = 0; i < m; i++){
		cin >> a[i] >> b[i];

		c[i].resize(b[i]);

		for(int j = 0; j < b[i]; j++){
			cin >> c[i][j];
		}
	}

	// cout << "HERE" << endl;

	const int INF = 1e9;

	vector <int> dp((1 << 12), INF);

	dp[0] = 0;

	for(int i = 0; i < m; i++){
		for(int j = 0; j < b[i]; j++){
			mask[i] += p[c[i][j] - 1];
		}
		dp[mask[i]] = min(dp[mask[i]], a[i]);
	}

	// cout << "HERE" << endl;


	for(int i = 0; i < (1 << 12); i++){
		if(dp[i] != INF){
			for(int j = 0; j < m; j++){
				dp[i | mask[j]] = min(dp[i | mask[j]], dp[i] + a[j]);
			}
		}
	}

	// cout << "HERE" << endl;

	cout << (dp[(1 << n) - 1] == INF ? -1 : dp[(1 << n) - 1]) << endl;


	return 0;
}

Measured memory_bytes: 384
N, M = map(int, input().split(" "))
A = list(map(int, input().split(" ")))

A.sort()

D = []
for i in range(M):
    B, C = map(int, input().split(" "))
    D.append((C, B))

#D = list(D_dict)
D.sort(reverse=True)

D_index = 0
D_index_max = len(D)

ans = 0

ct_D_i = 0
ct_D_i_max = D[0][1]

ct_D_total = 0

for i in range(N):
    a = A[i]
    d = D[D_index][0]
    if a > d:
        break

    A[i] = d


    ct_D_i += 1
    if ct_D_i >= ct_D_i_max:
        D_index += 1
        if D_index >= D_index_max:
            break

        ct_D_i = 0
        ct_D_i_max = D[D_index][1]




print(sum(A))

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

struct Mat{
	  int r,c;
};

int main(){

	  int n; cin >> n;
	  vector<Mat> Mats(n);
	  for(int i=0; i<n; i++)
			cin >> Mats[i].r >> Mats[i].c;

	  int dp[n][n] = {};
	  for(int i=0; i<n; i++)
			for(int j=0; j<n; j++)
				  if(i==j) dp[i][j] = 0;
				  else dp[i][j] = INT_MAX;

	  for(int w=1; w<n; w++){
			for(int i=0; i+w<n; i++){
				  int j = i+w;
				  for(int k=i; k<j; k++){
						int num_prod = Mats[i].r * Mats[k+1].r * Mats[i+w].c;
						dp[i][i+w] = min(dp[i][i+w], dp[i][k] + dp[k+1][i+w] + num_prod);
				  }
			}
	  }
/*
	  for(int i=0; i<n; i++){
			for(int j=0; j<n; j++)
				  cout << dp[i][j] << " ";
			cout << endl;
	  }
*/	  
	  cout << dp[0][n-1] << endl;
	  
			
}

Measured memory_bytes: 3096
#include<stdio.h>
int main(void){
    int n;
    int b[1000];
    scanf("%d",&n);
    for(int i=0;i<n-1;i++){
        scanf("%d",&b[i]);
    }
    int a[1000]={};

    a[0]=b[0];
    a[n-1]=b[n-2];
    int cnt=1;
    int ans=0;
    while(1){
        if(cnt==n-1){
            break;
        }
        if(b[cnt]>=b[cnt-1]){
            a[cnt]=b[cnt-1];
        }else{
            a[cnt]=b[cnt];
        }
        cnt++;
    }
    for(int i=0;i<n;i++){
        ans+=a[i];
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
from collections import Counter

n = int(input())
dl = list(map(int, input().split()))
m = int(input())
tl = list(map(int, input().split()))

dc = Counter(dl)
tc = Counter(tl)

for k in tc:
    if dc[k]<tc[k]:
        print("NO")
        exit()
print("YES")

Measured memory_bytes: 57048
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring> 
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
 
using namespace std;

#define mod 1000000007

int main()
{
    int n;
    cin >> n;
    long long int t[100001], a[100001];
    for(int i = 0; i < n; i++){
        cin >> t[i];
    }
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    long long int ans = 1;
    long long int leftmin = t[0], rightmin = a[0];
    long long int maxheight = -1;
    if(t[n - 1] != a[0]) ans = 0;
    for(int i = 1; i < n - 1; i++){
        if(t[i - 1] == t[i] && a[i] == a[i + 1]){
            ans = (ans * min(leftmin, rightmin)) % mod;
        } else {
            if(t[i - 1] != t[i] && a[i] != a[i + 1]){
                if(t[i] == a[i]){
                    if(maxheight > 0) ans = 0;
                    else maxheight = t[i];
                } else {
                    ans = 0;
                }
            } else if(t[i - 1] != t[i] && a[i] == a[i + 1] && t[i] > a[i]){
                ans = 0;
            } else if(t[i - 1] == t[i] && a[i] != a[i + 1] && t[i] < a[i]){
                ans = 0;
            }
            leftmin = max(leftmin, t[i]);
            rightmin = min(rightmin, min(a[i], a[i + 1]));
        }
        // cout << leftmin << " " << rightmin << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1920
from collections import deque

n = int(input())
a = [list(map(lambda x:int(x)-1,input().split())) + [-1] for _ in range(n)]

l,day = [0]*n,[0]*n

que = deque([i for i in range(n)])

while que:
    u = que.popleft()
    v = a[u][l[u]]
    if a[v][l[v]] == u:
        day[u] = max(day[u],day[v]) + 1
        day[v] = day[u]
        l[u] += 1
        l[v] += 1
        que.append(u)
        que.append(v)

if any(x != n-1 for x in l):
    print(-1)
    exit()

print(max(day))


Measured memory_bytes: 36984
#!/usr/bin/env python3
import sys, math, fractions, itertools


def solve(N: int):
    k = math.floor(math.log10(N))
    counter = 0
    if k == 0:
        counter = N
    if k == 1:
        counter = 9
    if k == 2:
        counter = 9 + (N - 99)
    if k == 3:
        counter = 909
    if k == 4:
        counter = 909 + (N - 9999)
    if k == 5:
        counter = 90909
    print(counter)
    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
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5560
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
#define pb push_back
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(false);
        cout << setprecision(15) << fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

template <typename T>
struct WeightedUnionFind {
    vector<int> parent;
    vector<int> rank;
    vector<T> diff_weight;
    WeightedUnionFind(int n) : parent(n, -1), rank(n, 0), diff_weight(n, 0) {}

    // weight(y) - weight(x) = w となるようにマージ
    void unite(int x, int y, T w) {
        w = weight(y) - weight(x) - w;
        // weight(y) - weight(x) = w を満たすために w を修正(これから変更するのはroot間のdiff)
        x = root(x), y = root(y);
        if (x != y) {
            if (rank[x] > rank[y]) swap(x, y), w = -w;
            if (rank[x] == rank[y]) rank[y]++; // rank
            parent[y] += parent[x];  // size
            parent[x] = y;
            diff_weight[x] = w;
        }
    }
    
    int root(int x) {
        if (parent[x] < 0) return x;
        int r = root(parent[x]);
        diff_weight[x] += diff_weight[parent[x]];
        return parent[x] = r;
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    T weight(int x) {
        root(x);  // 経路圧縮＆重み更新
        return diff_weight[x];
    }

    // weight(y) - weight(x)
    T diff(int x, int y) {
        return weight(y) - weight(x);
    }
};
signed main() {
    int N, M;
    cin >> N >> M;
    WeightedUnionFind<int> wuf(N);
    REP(i, M) {
        int l, r, d;
        cin >> l >> r >> d;
        l--, r--;
        if (wuf.same(l, r)) {
            if (wuf.diff(l, r) != d) {
                cout << "No" << endl;
                return 0;
            }
        } else {
            wuf.unite(l, r, d);
        }
    }
    cout << "Yes" << endl;
    return 0;
}



Measured memory_bytes: 2560
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
ll gcd(ll a,ll b){if(a<b)swap(a,b);ll c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int keta(ll n){
  int k=1;
  while(n/10>0){
    n/=10; k++;
  }
  return k;
}

int main(){
  ll n; cin>>n;
  int ans=INF;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      int d=keta(n/i);
      ans=min(d,ans);
    }
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct hopcroft{
	vector<int> dist, pair_l, pair_r;
	vector<bool> seen;
	vector<vector<int>> to;
	int n1, n2;
	hopcroft(int n1, int n2) : n1(n1), n2(n2){
		to.resize(n1);
		pair_l.assign(n1, -1);
		pair_r.assign(n2, -1);
		dist.resize(n1);
		seen.resize(n1);
	}
	void add_edge(int u, int v){
		to[u].push_back(v);
	}
	bool bfs(){
		fill(dist.begin(), dist.end(), -1);
		queue<int> q;
		for (int i = 0; i < n1; i++){
			if (pair_l[i] == -1){
				dist[i] = 0;
				q.push(i);
			}
		}
		bool reach_minus = false;
		while (!q.empty()){
			int u = q.front();
			q.pop();
			for (int adj : to[u]){
				int radj = pair_r[adj];
				if (radj == -1){
					reach_minus = true;
				} else if (dist[radj] == -1){
					dist[radj] = dist[u] + 1;
					q.push(radj);
				}
			}
		}
		return reach_minus;
	}
	bool dfs(int u){
		seen[u] = true;
		for (int adj : to[u]){
			int radj = pair_r[adj];
			if (radj == -1 || (!seen[radj] && dfs(radj))){
				pair_l[u] = adj;
				pair_r[adj] = u;
				return true;
			}
		}
		return false;
	}
	int max_matching(){
		int res = 0;
		while (bfs()){
			fill(seen.begin(), seen.end(), false);
			for (int i = 0; i < n1; i++)
				if (pair_l[i] == -1 && dfs(i))
					res++;
		}
		return res;
	}
};
const int maxn = 111;
int g[maxn][maxn];
int cnt[maxn][maxn];
int res[maxn][maxn];
vector<int> ready[maxn][maxn];
int main(){
	int n, m; cin >> n >> m;
	for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) cin >> g[i][j];
	for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) g[i][j]--;
	for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) cnt[i][g[i][j] / m]++;
	for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) ready[i][g[i][j] / m].push_back(g[i][j]);
	for(int i = 0; i < m; i++){
		int nds = 0;
		hopcroft ho(n, n);
		for(int j = 0; j < n; j++){
			for(int k = 0; k < n; k++){
				if(cnt[j][k]){
					ho.add_edge(j, k);
				}
			}
		}
		assert(ho.max_matching() == n);
		for(int j = 0; j < n; j++){
			int val = ho.pair_l[j];
			res[j][i] = ready[j][val].back();
			ready[j][val].pop_back();
			cnt[j][val]--;
		}
	}
	for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) printf("%d%c", res[i][j] + 1, " \n"[j + 1 == m]);
	for(int i = 0; i < m; i++){
		vector<int> tmp;
		for(int j = 0; j < n; j++) tmp.push_back(res[j][i]);
		sort(tmp.begin(), tmp.end());
		for(int j = 0; j < n; j++) res[j][i] = tmp[j];
	}
	for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) printf("%d%c", res[i][j] + 1, " \n"[j + 1 == m]);
	return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <bitset>
#include <vector>

using namespace std;

const int bitsz = 4194304;

int main()
{

    int n, s = 0, rez = 0, x;
    cin >> n;

    vector<int> v(n + 1);

    bitset<bitsz> bs;

    bs[0] = 1;
    for (int i = 1; i <= n; i++) {
      cin >> x;
      s += x;
      bs |= bs << x;
    }

    for (int i = 0; i <= s / 2; i++)
      if (bs[i]) {
        rez = s - i;
      }

    cout << rez << "\n";
}


Measured memory_bytes: 1792
Scanf.scanf "%d" (fun n ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    let dp = Array.make_matrix n 2 0 in
    dp.(0).(0) <- 0;
    dp.(0).(1) <- a.(0);
    dp.(1).(0) <- 0;
    dp.(1).(1) <- max dp.(0).(1) a.(1);

    for i = 2 to n - 1 do
        if i mod 2 = 1 then (
            dp.(i).(0) <- max dp.(i - 1).(0) (dp.(i - 2).(0) + a.(i));
            dp.(i).(1) <- max dp.(i - 1).(1) (dp.(i - 2).(1) + a.(i))
        ) else (
            dp.(i).(0) <- max dp.(i - 1).(1) (dp.(i - 2).(0) + a.(i));
            dp.(i).(1) <-                     dp.(i - 2).(1) + a.(i)
        )
    done;
    Printf.printf "%d\n" dp.(n - 1).((n + 1) mod 2)
)

Measured memory_bytes: 14584
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long 
#define M 1000000007
#define P pair<int,int>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) FOR(i,0,n)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

int a,b,sa=1,sb=1;
char c[100][100];

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

  rep(i,100){
    rep(j,100){
      if(i<50) c[i][j]='#';
      else c[i][j]='.';
    }
  }

  for(int i=0;i<50;i+=2){
    for(int j=0;j<100;j+=2){
      if(sa==a) break;
      c[i][j]='.';
      sa++;
    }
    if(sa==a) break;
  }
  for(int i=51;i<100;i+=2){
    for(int j=0;j<100;j+=2){
      if(sb==b) break;
      c[i][j]='#';
      sb++;
    }
    if(sb==b) break;
  }

  cout<<100<<' '<<100<<endl;
  rep(i,100){
    rep(j,100){
      cout<<c[i][j];
    }
    cout<<endl;
  }

  return 0;
}



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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m,ans;
    cin >> n >> m;
    for(int i = m/n;i > 0;i --){
        if(m % i == 0) {ans = i;break;}
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        String S = scan.next();
        List<Character> list = new ArrayList<Character>();
        char[] data = S.toCharArray();
        char current = ' ';
        for (int i = 0; i < N; i++) {
            if (current != data[i]) {
                if (current != ' ') {
                    list.add(current);
                }
                current = data[i];

            }
        }
        list.add(current);
        System.out.println(list.size());
    }
}


Measured memory_bytes: 27720
#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;
//imit
int main(void){
    long n,m;
    cin >> n >> m;
    
    vector<pair<long,long>> vec(n);//??
    
    for(int i = 0;i < n;i++){
          cin >> vec[i].first >> vec[i].second;
    }
    
    sort(vec.begin(),vec.end());//??
    
    long ans = 0;
    
    for(int i = 0;i < n;i++){
          ans += vec[i].first * min(m,vec[i].second);
          m -= min(vec[i].second,m);
          if(m == 0)break;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4820
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

struct UnionFind {

	vi data;

	UnionFind(int n = 0) {
		data.assign(n, -1);
	}

	int find(int k) {
		if (data[k] < 0) return k;
		return data[k] = find(data[k]);
	}
	bool unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y) return false;
		if (data[x] > data[y]) swap(x, y);
		data[x] += data[y];
		data[y] = x;
		return true;
	}
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int k) { return -data[find(k)]; }

};

int main() {

	int n;
	cin >> n;
	V<T> xy, yx;
	rep(i, n) {
		int x, y;
		cin >> x >> y;
		xy.push_back(T(x, y, i));
		yx.push_back(T(y, x, i));
	}
	sort(all(xy));
	sort(all(yx));

	V<T> dis;

	rep(i, n - 1) {
		int v, vv, d;
		v = get<2>(xy[i]);
		vv = get<2>(xy[i + 1]);
		d = get<0>(xy[i + 1]) - get<0>(xy[i]);
		dis.push_back(tie(d, v, vv));

		v = get<2>(yx[i]);
		vv = get<2>(yx[i + 1]);
		d = get<0>(yx[i + 1]) - get<0>(yx[i]);
		dis.push_back(tie(d, v, vv));
	}

	UnionFind uf(n);

	ll ans = 0;
	sort(all(dis));

	rep(i, dis.size()) {
		int v = get<1>(dis[i]);
		int vv = get<2>(dis[i]);
		if (uf.same(v, vv))continue;
		uf.unite(v, vv);
		ans += get<0>(dis[i]);
	}
	
	cout << ans << endl;

}

Measured memory_bytes: 7212
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>
#include<utility>

using namespace std;

vector<bool> p(100001);
vector<int> sum(100001);

int main() {
  for(int i = 0; i < 100001; i++) p[i] = true;
  p[0] = false;
  p[1] = false;
  for(int i = 3; i < 100001; i++) {
    for(int j = 2; j * j <= i; j++) {
      if(i % j == 0) p[i] = false;
    }
  }
  sum[0] = 0;
  sum[1] = 0;
  sum[2] = 0;
  for(int i = 3; i < 100001; i++) {
    if(p[i] && p[(i + 1) / 2]) sum[i] = sum[i - 1] + 1;
    else sum[i] = sum[i - 1];
  }
  int q;
  cin >> q;
  for(int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    cout << sum[r] - sum[l - 1] << endl;
  }
  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		long L = sc.nextLong();
		long R = sc.nextLong();
		if(R - L >= 2019) {
			System.out.println(0);
		} else {
			long ans = Long.MAX_VALUE;
			for(long i = L; i <= R; i++) {
				for(long j = i + 1; j <= R; j++) {
					ans = Math.min(ans, (i * j) % 2019);
				}
			}
			System.out.println(ans);
		}
	}
}


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

int main(){
	int a, b, c, x, y;
	scanf("%d%d%d%d%d", &a, &b, &c, &x, &y);
	if (c << 1 >= a + b){
		printf("%d\n", a * x + b * y);
		return 0;
	}
	int min = std::min(x, y);
	int cost = c * min * 2;
	x -= min, y -= min;
	cost += std::min(c << 1, a) * x;
	cost += std::min(c << 1, b) * y;
	printf("%d\n", cost);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int a, b;
string s, t, u;
int main() 
{
  cin>>s>>t>>a>>b>>u;
  if(u==s)
  {
    cout<<a-1<<" "<<b;
  }
  else
  {
    cout<<a<<" "<<b-1;
  }
  cout<<endl;
}

Measured memory_bytes: 256
//21171_somesh || asomesh999

#include<bits/stdc++.h>
using namespace std;
#define fr(i,a,b) for(long long i=a;i<b;i++)
#define io ios::sync_with_stdio(false);cin.tie(NULL);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
long int mod=1000000007;

int main()
{
	io
	#ifdef CODE
		clock_t startTime = clock();
		freopen("input.txt","r",stdin);
	#endif

	ll n;
	cin >> n;
	if ((n / 100) == 7 || (n / 10) % 10 == 7 || n % 10 == 7) {
		cout << "Yes";
	} else {
		cout << "No";
	}

	#ifdef CODE
		cerr << endl <<setprecision(20)<< double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " seconds." << endl;
	#endif
	return 0;
}


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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long[] pow26 = new long[14];
        for(int i=1;i<14;i++){
            pow26[i] = pow26[i-1] + (long) Math.pow(26, i);
        }
        int length = 0;
        for(int i=0;i<14;i++){
            if(n > pow26[i] && n <= pow26[i+1]){
                length = i+1;
                break;
            }
        }
        //length=桁数
        int x = (int) (n % 26);
        x = x == 0 ? 26 : x;
        String s = String.valueOf((char)(x+96));
        n -= 26;
        for(int i=1;i<length;i++){
            long z = n % (long)Math.pow(26, i+1);
            z = z == 0 ? (long)Math.pow(26, i+1) : z;
            int y = (int)((z-1) / (long)Math.pow(26, i)) + 1;
            s = String.valueOf((char)(y+96)) + s;
            n -= (long)Math.pow(26, i+1);
        }
        System.out.println(s);

    }
}


Measured memory_bytes: 27080
#include<stdio.h>
#include<ctype.h>
i;int main(){
	char str[1000];
	fgets(str,1000,stdin);
	for(i=0;str[i]!='\0';i++)printf("%c",isalpha(str[i])?toupper(str[i]):str[i]);
	exit(0);
}

Measured memory_bytes: 0
object Main{
  def main(args: Array[String]) : Unit = {
    System.err.println("ok")
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val happy = 
      (1 to n).map{
        _ => (sc.nextInt,sc.nextInt,sc.nextInt)
      }


    val fin = happy.foldLeft((0,0,0)) { (acc, h) =>
      (
        Math.max(acc._2,acc._3) + h._1,
        Math.max(acc._1,acc._3) + h._2,
        Math.max(acc._1,acc._2) + h._3
      )  
    }
    println(Seq(fin._1,fin._2,fin._3).max)
  }
}



Measured memory_bytes: 113512
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
int main() {
	ll N, ans = 0;
	cin >> N;
	vector<ll> d(N);
	for (ll i = 0; i < N; i++) {
		cin >> d[i];
	}
	for (ll i = 0; i < N-1; i++)
	{
		for (ll k = i+1; k < N; k++) {
			ans += d[i]*d[k];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
use proconio::{fastout, input};
use std::cmp::max;

#[fastout]
fn main() {
    input! {
        n:i32,
        m: usize,
        a: [i32; m],
    }

    let sum: i32 = a.iter().sum();
    let ans = max(n - sum, -1);

    println!("{}", ans);
}


Measured memory_bytes: 2200
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
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 ;

int main(){
	string s;
	cin>>s;
	sort(s.begin(),s.end());
	if(s=="abc")cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

using namespace std;

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;
const int MAX = 100000;
long long a[MAX],b[MAX],c[MAX], dp_a[MAX], dp_b[MAX], dp_c[MAX];

void solve() {
  int N;
  int lastE; 
  long long value=-INF;
  cin >> N ;
  for(int i=0;i<N;i++){
    cin >> a[i] >> b[i] >> c[i];
  }
  for(int i=0;i<MAX;i++){
    dp_a[i] = -INF;
    dp_b[i] = -INF;
    dp_c[i] = -INF;
  }
  dp_a[0] = a[0];
  dp_b[0] = b[0];
  dp_c[0] = c[0];
  for(int i=0; i<N;i++){
    chmax(dp_b[i+1], dp_a[i]+b[i+1]);
    chmax(dp_c[i+1], dp_a[i]+c[i+1]);
    chmax(dp_a[i+1], dp_b[i]+a[i+1]);
    chmax(dp_c[i+1], dp_b[i]+c[i+1]);
    chmax(dp_b[i+1], dp_c[i]+b[i+1]);
    chmax(dp_a[i+1], dp_c[i]+a[i+1]);
  }
  cout << max({dp_a[N-1],dp_b[N-1],dp_c[N-1]}) <<endl;
  return;
}
 
int main() {
    solve();
    return 0;
}

Measured memory_bytes: 8276
from bisect import bisect_left, bisect_right, insort_left
import sys
readlines = sys.stdin.readline
def main():

	n = int(input())
	s = list(input())
	q = int(input())

	d = {}
	flag = {}
	for i in list('abcdefghijklmnopqrstuvwxyz'):
		d.setdefault(i, []).append(-1)
		flag.setdefault(i, []).append(-1)
	for i in range(n):
		d.setdefault(s[i], []).append(i)
	for i in range(q):
		q1,q2,q3 = map(str,input().split())
		if q1 == '1':
			q2 = int(q2) - 1
			if s[q2] != q3:
				insort_left(flag[s[q2]],q2)
				insort_left(d[q3],q2)
				s[q2] = q3
		else:
			ans = 0
			q2 = int(q2) - 1
			q3 = int(q3) - 1
			if q2 == q3:
				print(1)
				continue
			for string,l in d.items():
				res = 0
				if d[string] != [-1]:
					left = bisect_left(l,q2)
					right = bisect_right(l,q3)
				else:
					left = 0
					right = 0
				if string in flag:
					left2 = bisect_left(flag[string],q2)
					right2 = bisect_right(flag[string],q3)
				else:
					left2 = 0
					right2 = 0
				if left != right:
					if right - left > right2 - left2:
						res = 1
				ans += res
				#print(string,l,res)
			print(ans)
if __name__ == '__main__':
	main()

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

int X[5010], Y[5010];
vector<vector<int>> G;
vector<vector<bitset<5010>>> dp;

bool dfs(int key){
    int sum=0;
    for(int i=0; i<G[key].size(); ++i){
        if(!dfs(G[key][i])) return false;
        sum += X[G[key][i]]+Y[G[key][i]];
    }
    dp[key].resize(G[key].size()+1);
    dp[key][0][0]=1;
    for(int i=1; i<5010; ++i) dp[key][0][i]=0;
    for(int i=0; i<G[key].size(); ++i){
        dp[key][i+1]=(dp[key][i]<<(X[G[key][i]]))|(dp[key][i]<<(Y[G[key][i]]));
    }
    for(int i=X[key]; i>=0; --i){
        if(dp[key][G[key].size()][i]){
            Y[key]=sum-i;
            return true;
        }
    }
    return false;
}

int main(void){
    int N;
    cin >> N;
    G.resize(N);
    dp.resize(N);
    for(int i=1; i<N; ++i){
        int P;
        cin >> P;
        G[P-1].emplace_back(i);
    }
    for(int i=0; i<N; ++i) cin >> X[i];
    cout << (dfs(0) ? "" : "IM") << "POSSIBLE" << endl;
    return 0;
}


Measured memory_bytes: 2688