akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

class Dice2{
	private int[] number = new int[6]; //Diceの方向には何の数字かを示す
										//初期値の順番と一緒：上面①、その下②、その右③、その左④、その上⑤、その反面⑥（Indexと一個違い）

	//コンストラクタ
	public Dice2(int[] n) {
		for (int i=0; i< 6; i++)number[i] = n[i];
	}

	public int getDice(int no) {
		return number[no];
	}

	public void roll(String target) {
		int [] w = new int[6];  //仮のway
		int a = target.length();
		for (int i=0; i<a; i++) {
			for (int j=0; j< 6; j++) w[j] = number[j];  //コピーする
			String t = target.substring(i, i+1);
			switch(t) {
			case "N":
				number[4] = w[0];
				number[0] = w[1];
				number[1] = w[5];
				number[5] = w[4];
				break;
			case "E":
				number[2] = w[0];
				number[0] = w[3];
				number[3] = w[5];
				number[5] = w[2];
				break;
			case "S":
				number[4] = w[5];
				number[0] = w[4];
				number[1] = w[0];
				number[5] = w[1];
				break;
			case "W":
				number[2] = w[5];
				number[0] = w[2];
				number[3] = w[0];
				number[5] = w[3];
				break;
			}
		}
	}

	public void rollUntilAB(int A,int B) {
		while ((number[0]!=A)||(number[1]!=B)) {
			if (number[0]!=A) {
				if (number[2] == A) roll("W"); //Aが③の時：W
				else if (number[3] == A) roll("E"); //Aが④の時：E
				else roll("N"); //Aが③④にない場合、ひたすらN移動
			}else {  //Aは①面にあって、Bは②にない
				if (number[2] == B) roll("WSE");  //Bが③の時：W→S→E
				else if (number[4] == B) roll("ESW");  //Bが④の時：E→S→W
				else roll("SENWSE");  //Bが⑤の時：S→E→N→Bが③になる→W→S→E
			}
		}
	}
}

class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner (System.in)){

			int [] n = new int[6];
			for (int i=0; i<6; i++) n[i] = sc.nextInt(); //diceの数字を取得
			Dice2 dice2 = new Dice2(n);
			int times = sc.nextInt();
			int [] result = new int[times];
			for (int i=0; i< times; i++) {
				result[i] = -1;
				int A = sc.nextInt();
				int B = sc.nextInt();
				dice2.rollUntilAB(A, B);
				result[i] = dice2.getDice(2);  //右を出力
			}
			for (int i=0; i< times; i++) {
				System.out.println(result[i]);  //結果出力
			}
		}
	}
}



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

using namespace std;
const int N = 1e6+100;
int a[N];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++){
		if(a[i]>a[i-1]){
			a[i]--;
		}
	}
	for(int i=1;i<=n-1;i++){
		if(a[i]>a[i+1]){
			puts("No");return 0;
		}
	}
	puts("Yes");
	return 0;
}

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

using ll= long long;
void max_self(ll& a,ll b){
  a = max(a,b);
}
void min_self(ll& a,ll b){
  a = min(a,b);
}
const ll INF = 1e18L + 5;


int main(){
  int N,W;
  cin>>N>>W;
  // dp[i] is miniumum weight with val i 
  vector<int> wt(N),val(N);
  for(int i=0;i<N;i++){
      cin>>wt[i]>>val[i];
  }
  ll sum_value = 0;
  for(auto i:val){
      sum_value+=i;
  }
  vector<ll> dp(sum_value+1,INF);
  dp[0] = 0;
  for(int i=0;i<N;i++){
    for(auto value_already=sum_value-val[i];value_already>=0;value_already--){
      min_self(dp[value_already+val[i]],dp[value_already]+wt[i]);
    }
  }
  ll result = 0;
  for(ll i=0;i<=sum_value;i++){
    if(dp[i]<=W){
        max_self(result,i);
    }
  }
  cout<<result;
}


Measured memory_bytes: 1024
#[allow(unused_imports)]
use std::{cmp::Reverse, collections::*};

#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Chars, Usize1},
};

#[allow(unused_imports)]
use itertools::Itertools;

#[allow(unused_imports)]
use num::Integer;

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

    let mut max = 0;
    let mut sum = 0;
    for i in 0..n {
        if a[i] < max {
            sum += max - a[i];
        } else {
            max = a[i];
        }
    }
    println!("{}", sum);
}


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

using i64 = int64_t;

int main(){
    vector<int> v;
    for(int i=0;i<10;++i){
        int h;
        cin >> h;
        v.push_back(h);
    }
    sort(v.rbegin(), v.rend());
    for(int i=0;i<3;++i){
        cout << v[i] << endl;
    }

    return 0;
}



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

int main(){
	int n,m;
	cin>>n>>m;
	
	int cnt[m]={0};
	for(int i=0;i<n;i++){
		int k=0;
		cin>>k;
		for(int j=0;j<k;j++){
			int tp;
			cin>>tp;
			cnt[tp-1]++;
		}
	}
	int ans=0;
	for(int i=0;i<m;i++){
		if(cnt[i]==n) ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn dfs(n: usize, m: i32, path: &mut Vec<i32>, all: &mut Vec<Vec<i32>>) {
    if path.len() >= n {
        all.push(path.clone());
        return;
    }
    let &last = path.last().unwrap_or(&1);
    for i in last..m + 1 {
        path.push(i);
        dfs(n, m, path, all);
        path.pop();
    }
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        n: usize, m: i32, q: usize,
        abcd: [(usize1, usize1, i32, i64); q],
    }
    let mut all = vec![];
    dfs(n, m, &mut vec![], &mut all);
    let mut ma = 0;
    for v in all {
        let mut sum = 0;
        for &(a, b, c, d) in &abcd {
            if v[b] - v[a] == c {
                sum += d;
            }
        }
        ma = max(ma, sum);
    }
    puts!("{}\n", ma);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 7556
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3") 
#pragma GCC optimization ("unroll-loops")
 
// #include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
// const ll RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
// gp_hash_table<int, int> table;
 
#define ll  long long
#define vii vector< ll >
#define pb push_back
#define pii pair<ll,ll>
#define ppi pair<pii,ll>
#define pip pair<ll,pii>
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define ins insert
#define ld long double
#define lp(l,r) for(i=l;i<=r;++i)
 
#define lpj(l,r) for(j=l;j<=r;++j)
#define lpr(l,r) for(i=r;i>=l;--i)
#define lprj(l,r) for(j=r;j>=l;--j)
 
#define swap(a,b){ auto _t=a;a=b,b=_t;}
#define flush() cout.flush()
#define popcount __builtin_popcount
#define die() return 0;
#define sz() size() 


 
 
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define MD          1000000007
#define M           100011
#define N           20
#define fftmod      998244353
#define EPS         (double)1e-10
 
long long  md=MD;
ll inf=1e18;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); 
 
 
inline ll exp(ll a,ll b){if(a==0&&b==0)return 1ll;if(a==0)return 0ll;ll r=1LL;while(b>0){if(b&1){r=(r%md)*(a%md);r=(r+md)%md;}b/=2;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;if(a==0)return b;return gcd(b,a%b);}
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (ll)r;}
 
using cd=complex<double>;
const double PI=acos(-1);
 
inline ll rand(ll l,ll r){
    return l+rng()%(r-l+1);
}



int main(){

 
     
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
   // ifstream fin("input.txt");ofstream fout("outut.txt");
    ll t,i,j,m,n,s,z,k,p;string s1,s2;ll q;ll x,y;
    cin>>n>>k;
    vii v;
    lp(1,n){
    	char ch;
    	cin>>ch;
    	if(ch=='L')v.pb(0);
    	else v.pb(1);
    }
    p=0;
    i=0;
    x=0;
    vii po;
    while(i<n){
    	j=i;po.pb(v[i]);
    	x++;
    	while(j<n&&v[j]==v[i])++j;
    	p+=(j-i-1);
    	i=j;
    }
    // trace(p);
    i=1;
    while(i<po.sz()&&k){
    	po[i]=po[i-1];
    	if(k==0)break;
    	// trace(i,p);
    	p+=2;
    	k--;
    	i+=2;
    }
    if(po.sz()%2==0&&po[0]==po.back())--p;
    cout<<p<<"\n";








}



Measured memory_bytes: 2548
a, b = map(int, input().split())

if a <= 0 <= b:
    print('Zero')
    exit()

if a > 0:
    print('Positive')
    exit()

if a == b:
    print('Positive')
    exit()

print('Negative' if len(range(a, b+1)) % 2 else 'Positive')


Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Text;

namespace atcoder_ARC061C
{
    class MainClass
    {
		static char[] numbers = new char[20];
		static int[] plusArray = new int[20];
		static long sum = 0;
		static List<int[]> AllplusList = new List<int[]>();
		//static bool[] plusArray = new bool[20];
        public static void Main(string[] args)
        {
			numbers = Console.ReadLine().ToCharArray();
			for (int i = 0; i < numbers.Length - 1; i++)
			{
				plusArray[i] = 0;
			}
			Adder(0);

			Console.WriteLine(sum);
		}
        
		private static void Adder(int currentIndex)
		{
			if (currentIndex >= numbers.Length - 1)
			{
				StringBuilder numberString = new StringBuilder();
				for (int i = 0; i < numbers.Length; i++)
				{
					numberString.Append(numbers[i]);
					if (plusArray[i] == 1 || i == numbers.Length - 1)
					{
						sum += long.Parse(numberString.ToString());
						numberString.Clear();
					}
				}

				return;
			}

			Adder(currentIndex + 1);
			plusArray[currentIndex] = 1;
			Adder(currentIndex + 1);
			plusArray[currentIndex] = 0;

			return;
		}
    }
}


Measured memory_bytes: 13268
#include<stdio.h>
#include<stdlib.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head=1, tail, n;

void enqueue(P x){
  Q[tail] = x;
  if(tail + 1 == LEN) tail = 0;
  else tail++;
}

P dequeue(){
  P x;
  x = Q[head];
  if(head + 1 == LEN) head = 0;
  else head++;
  return x;
}


int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  //  for(i=1;i<=n;i++) printf("%s %d\n",Q[i].name,Q[i].t);

  tail = i;
  while(head!=tail)
    {
      if(Q[head].t - q <= 0)
	{
	  elaps += Q[head].t;
	  printf("%s %d\n",Q[head].name,elaps);
	  u =  dequeue();
	}
      else
	{
	  elaps += q;
	  Q[head].t -= q;
	  //printf("%s %d %d\n",Q[head].name,Q[head].t,elaps);
	  u = dequeue();
	  enqueue(u);
	}
    }

  
  return 0;
}



Measured memory_bytes: 11848
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
#include <queue>
using namespace std;
typedef long long ll;

const ll MOD = 1e9+7;
priority_queue<ll> que;
int main()
{
	int n,m;
	ll ans=0;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		ll a;
		cin>>a;
		que.push(a);
	}
	for(int i=0;i<m;i++)
	{
		ll b=que.top();que.pop();
		b/=2;
		que.push(b);
	}
	while(!que.empty())
	{
		ans+=que.top();que.pop();
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1400
import java.util.*;
import java.util.stream.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		System.out.println(IntStream.rangeClosed(1, 9).anyMatch(i -> n % i == 0 && n / i <= 9) ? "Yes" : "No");
	}
}


Measured memory_bytes: 30164
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x);putchar(' ');}
inline void pr2(int x){write(x);putchar('\n');}
const int MAXN=300005;
int n,A,B;
int a[MAXN];
int main()
{
	n=read();A=read();B=read();
	int up1=n/A;if(n%A)up1++;
	int up2=n/B;if(n%B)up2++;
	if(A<up2||B<up1||A+B>n+1)return puts("-1"),0;
	for(int i=1;i<=B;i++)a[i]=B-i+1;
	for(int i=B+1,nxt=0,ls=1;i<=n;i=nxt+1)
	{
		if(ls+1+(n-i+1-B)>A)
		{
			nxt=i+B-1;
			for(int j=i,cnt=nxt;j<=nxt;j++)a[j]=cnt--;
			ls++;
		}
		else
		{
			nxt=n-(A-ls-1);
			for(int j=i,cnt=nxt;j<=nxt;j++)a[j]=cnt--;
			for(int j=nxt+1;j<=n;j++)a[j]=j;
			nxt=n;
		}
	}
	for(int i=1;i<=n;i++)pr1(a[i]);
	return 0;
}


Measured memory_bytes: 3328
A,B,M = map(int,input().split())

a = list(map(int,input().split()))
b = list(map(int,input().split()))

xyc = [map(int, input().split()) for _ in range(M)]
x, y, c = [list(i) for i in zip(*xyc)]

price1 = min(a) + min(b)
price2 = []

for i in range(M):
  xi = x[i] - 1
  yi = y[i] - 1
  price_tmp = a[xi] + b[yi] - c[i]
  price2.append(price_tmp)
  
price2 = min(price2)

if price1 > price2:
  print(price2)
else:
  print(price1)

Measured memory_bytes: 80556
#include <cmath>
#include<iostream>
#include <functional>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <iomanip>
using namespace std;
 
int main(){    
  long long A,B,K,a,b;
  cin >> A >> B >> K;

  if(A>K){
    cout << A-K <<" "<< B << endl;
  }
  else{
    a = K-A;
    b = B-a;
    if(b <0){
      cout << "0" << " " << "0" << endl;
    }
    else{
      cout << "0" << " " << b << endl;
    }
  }
  
}


Measured memory_bytes: 256
#include <cassert>
#include <functional>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <iterator>
#include <queue>
#include <utility>

using namespace std;

#define MH 100
int H, W;
string F[MH];

bool input() {
    cin >> H >> W;
    if (H == 0 && W == 0) return false;
    for (int i = 0; i < H; i++) cin >> F[i];
    return true;
}

void dfs(int y, int x, char c) {
    static const int dy[] = {0, 1, 0, -1},
                     dx[] = {1, 0, -1, 0};
    F[y][x] = 'x';
    for (int i = 0; i < 4; i++) {
        int ny = y + dy[i],
            nx = x + dx[i];
        if (ny < 0 || ny >= H) continue;
        if (nx < 0 || nx >= W) continue;
        if (F[ny][nx] == c) {
            dfs(ny, nx, c);
        }
    }
}

void solve() {
    int ans = 0;
    for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
            if (F[y][x] == 'x') continue;
            ans++;
            dfs(y, x, F[y][x]);
        }
    }
    cout << ans << endl;
}

int main() {
    while (input()) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 2160
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#include<queue>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

signed main() {
	int N,M;
	cin >> N;
	map<string,int> Blue;
	map<string,int> Red;
	for(int i = 0;i < N;i++) {
		string S;
		cin >> S;
		Blue[S]++;
	}
	cin >> M;
	for(int i = 0;i < M;i++) {
		string S;
		cin >> S;
		Red[S]++;
	}
	int ret = 0;
	for(auto x:Blue) {
		string S = x.first;
		ret = max(ret,x.second - Red[S]);
	}
	cout << ret << endl;
}

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

using namespace std;

long long int NcR(int n, int r) 
{ 
  
    // p holds the value of n*(n-1)*(n-2)..., 
    // k holds the value of r*(r-1)... 
    long long p = 1, k = 1; 
  
    // C(n, r) == C(n, n-r), 
    // choosing the smaller value 
    if (n - r < r) 
        r = n - r; 
  
    if (r != 0) { 
        while (r) { 
            p *= n; 
            k *= r; 
  
            // gcd of p, k 
            long long m = __gcd(p, k); 
  
            // dividing by gcd, to simplify product 
            // division by their gcd saves from the overflow 
            p /= m; 
            k /= m; 
  
            n--; 
            r--; 
        } 
  
        // k should be simplified to 1 
        // as C(n, r) is a natural number 
        // (denominator should be 1 ) . 
    } 
  
    else
        p = 1; 
  
    // if our approach is correct p = ans and k =1 
    return p; 
} 

int main() {
  int n;
  string s;
  map<string, long long int> store;
  long long int result = 0;
  cin>>n;
  while(n--) {
    cin>>s;
    sort(s.begin(), s.end());
    store[s]++;
  }
  for(auto it=store.begin();it!=store.end();it++) {
    if(it->second>1) result+=NcR(it->second, 2);
  }
  cout<<result;
}
  

Measured memory_bytes: 11136
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << '\n';
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

long long N, K; 
vector<long long> A, F, cost;

bool isOK(long long score) {
    long long k = 0;
    for (int i = 0; i < N; i++) {
        long long a = cost[i] - score;
        if (a > 0) k += (a + F[i] - 1) / F[i];
    }
    //print("k:", k, "score:", score);
    if (k <= K) return true;
    else return false;
}

void solve() {
    cin >> N >> K;
    A.resize(N); F.resize(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < N; i++) cin >> F[i];

    sort(A.rbegin(), A.rend());
    sort(F.begin(), F.end());

    cost.resize(N);
    long long ma = 0;
    for (int i = 0; i < N; i++) {
        cost[i] = A[i] * F[i];
        ma = max(ma, cost[i]);
    }

    long long ok = ma;
    long long ng = -1;

    while (abs(ok - ng) > 1) {
        long long mid = (ok + ng) / 2;
        if (isOK(mid)) ok = mid;
        else ng = mid;
    }

    cout << ok << '\n';
}

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

    solve();

    return 0;
}

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

typedef long long ll;
const ll LL_MAX (1LL<<60);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

//ll gcd(ll a, ll b)
//{
//    if (a < b) swap(a,b);
//    if (a%b==0) return b;
//    else return gcd(b, a%b);
//}

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

    ll n;
    cin >>n;
    vector<ll> a(n);
    rep(i,0,n) cin >> a[i];

    vector<ll> c2(n, 0);

    rep(i,0,n)
    {
        ll c(0);
        ll y(2);
        while (true)
        {
            if (a[i]%y==0)
            {
                c++, y *=2;
                //cout << a[i] << y << endl;
            }
            else
                break;
        }

        c2[i] = c;
    }

    ll _sum(0);
    rep(i,0,n) _sum+=c2[i];

    cout << _sum << endl;

    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>  
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
using namespace std;
int main(){
  long long n,m;
  cin>>n>>m;
  if ((n >= 2) and (m >= 2)){
  cout<<(n - 2) * (m - 2);
  system ("pause");
  return 0;
  }
  if (n * m == 1){
  cout<<"1";
  system ("pause");
  return 0;
  }
  cout<<n * m - 2;
  system ("pause");
  return 0;
  }
  

Measured memory_bytes: 504
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}
using namespace std;
typedef long long LL;
pair<LL,LL> solve(int n,int m)
{
	if(n%2==0 || m%2==0) return MP(1LL, 1LL);
	LL tmp = (LL)n*m;
	return MP(tmp/2+1, tmp/2);
}
int main()
{
	int t,n,m;
	RI(t);
	while(t--)
	{
		RI(n,m);
		
		int g = __gcd(n,m);
		n /= g;
		m /= g;

		auto ans = solve(n,m);
		if((n+m)%2==0)
			printf("%lld %lld\n", ans.F, ans.S);
		else
		{
			if(g%2==0) printf("1 1\n");
			else printf("%lld %lld\n", ans.F, ans.S);
		}
	}
	return 0;
}

Measured memory_bytes: 1172
from functools import reduce
import math

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

# parity check and get max
x, y = coord[0]
p = (x + y) & 1
limit = 0
for x, y in coord:
    if p != (x + y) & 1:
        print(-1)
        exit()
    lim = abs(x) + abs(y)
    if lim > limit:
        limit = lim

limit = round(math.log2(limit))
if p == 1:
    d = [2 ** i for i in reversed(range(limit + 1))]
else:
    d = [1] + [2 ** i for i in reversed(range(limit + 1))]

print(len(d))
print(reduce((lambda acc, dist: str(acc) + " " + str(dist)), d))

for x, y in coord:
    u = x + y
    v = x - y

    command = ""
    for i in range(len(d)):
        if u >= 0 and v >= 0:
            command += "R"
            u -= d[i]
            v -= d[i]
        elif u >= 0 > v:
            command += "U"
            u -= d[i]
            v += d[i]
        elif u < 0 <= v:
            command += "D"
            u += d[i]
            v -= d[i]
        elif u < 0 and v < 0:
            command += "L"
            u += d[i]
            v += d[i]

    print(command)

Measured memory_bytes: 4068
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        Scanner scn= new Scanner(System.in);
        int n = scn.nextInt();
        int k =scn.nextInt();
        int[] x=new int[n];
        int total=0;
        for(int i=0;i<n;i++){
            x[i]=scn.nextInt();
            if(x[i]>k-x[i]){
                total+=k-x[i];
            }else{
                total+=x[i];
            }
        }

        System.out.println(total*2);
    }
}


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

int main(){
    int a,b;
    cin >> a >> b;
    if (a == b)
    {
        cout << "Draw" <<endl;
    }
    else
    {
        switch (a)
        {
        case 1:
            cout << "Alice" << endl;
            break;
        
        default:
        if (b == 1)
        {
         cout << "Bob" << endl;
        }else
        {
            string winner = (a > b)? "Alice" : "Bob";
            cout << winner << endl;
        }
            break;
        }
    }
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"

using namespace std;

//constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

vector< int > z_algorithm(const string &s) {
	vector< int > prefix(s.size());
	for (int i = 1, j = 0; i < s.size(); i++) {
		if (i + prefix[i - j] < j + prefix[j]) {
			prefix[i] = prefix[i - j];
		}
		else {
			int k = max(0, j + prefix[j] - i);
			while (i + k < s.size() && s[k] == s[i + k]) ++k;
			prefix[i] = k;
			j = i;
		}
	}
	prefix[0] = (int)s.size();
	return prefix;
}

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

	string ss, t;
	cin >> ss >> t;
	string s;
	while (s.size() < t.size()) {
		s += ss;
	}
	s += ss;
	string u = t + s;
	auto v = z_algorithm(u);
	vector<vector<int>>tapi(ss.size(), vector<int>(22, -1));
	for (int i = 0; i < ss.size(); i++) {
		if (v[i + t.size()] >= t.size())tapi[i][0] = (i + t.size()) % ss.size();
	}
	for (int i = 1; i < 22; i++) {
		for (int j = 0; j < ss.size(); j++) {
			if (tapi[j][i - 1] != -1)tapi[j][i] = tapi[tapi[j][i - 1]][i - 1];
		}
	}
	int ans = 0;
	for (int i = 0; i < ss.size(); i++) {
		int nn = i;
		int ret = 0;
		for (int j = 21; j >= 0; j--) {
			if (tapi[nn][j] == -1)continue;
			ret += 1 << j;
			nn = tapi[nn][j];
		}
		ans = max(ans, ret);
	}
	if (ans >= 1 << 21)ans = -1;
	cout << ans << endl;
}

Measured memory_bytes: 71112
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, count = 0, nowH, rightH, ans = 0;
  cin >> N >> nowH;
  for(int i = 1; i < N; i++){
    cin >> rightH;
    if(nowH >= rightH){
      count += 1;
      if(count > ans) ans = count;
    } else count = 0;
    nowH = rightH;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int,int>;


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;

int main() {
    ll a , b , c;
    cin >> a >> b >> c;
    ll d = c - a - b;
    if(d > 0 && d * d > 4 * a * b){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#pragma GCC optimize("O3")

#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>
#include <cstring>
#include <numeric>
#include <set>
#include <queue>
#include <deque>
#include <array>
#include <string>
#include <cmath>
#include <random>
#include <ctime>
#include <map>
#include <functional>
#include <bitset>
#include <complex>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>

#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()
#define pb push_back

using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using ld = long double;

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, M;
	cin >> n >> M;
	vector<vi> g(n);
	for (int i = 0; i < n - 1; i++) {
		int u, v; cin >> u >> v; --u; --v; g[u].pb(v); g[v].pb(u);
	}
	vi dp(n, 1);
	function<void(int, int)> dfs = [&](int v, int p) {
		for (int to : g[v]) {
			if (to != p) {
				dfs(to, v);
				dp[v] = (ll)dp[v] * (dp[to] + 1) % M;
			}
		}
	};
	dfs(0, -1);
	vi ans(n);
	function<void(int, int, int)> solve = [&](int v, int p, int up_black) {
		ans[v] = (ll)dp[v] * (up_black + 1) % M;
		up_black++;
		if (p != -1) {
			int pt = 0;
			while (g[v][pt] != p) {
				pt++;
			}
			g[v].erase(g[v].begin() + pt);
		}
		int k = sz(g[v]);
		vi suf(k + 1);
		suf.back() = up_black;
		for (int i = k - 1; i >= 0; i--) {
			int to = g[v][i];
			suf[i] = (ll)suf[i + 1] * (dp[to] + 1) % M;
		}
		int pref = 1;
		for(int i = 0; i < k; i++) {
			int to = g[v][i];
			solve(to, v, (ll)pref * suf[i + 1] % M);
			pref = (ll)pref * (dp[to] + 1) % M;
		}
	};
	solve(0, -1, 0);
	for (auto v : ans) {
		cout << v << '\n';
	}
}


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

int n, k;
int tab[100005];
int DP[100005];

int absol(int a){
    if(a < 0) return a * (-1);
    else return a;
}

int main(){
    scanf("%d %d", &n, &k);
    for(int i = 1; i <= n; i++) scanf("%d", &tab[i]);
    for(int i = 1; i <= n; i++) DP[i] = 2000000000;
    DP[1] = 0;
    for(int i = 2; i <= n; i++){
        for(int j = max(1, i - k); j < i; j++){
            DP[i] = min(DP[i], DP[j] + absol(tab[i] - tab[j]));
        }
    }
    printf("%d", DP[n]);
    return 0;
}


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

const ll mod = 1000000007;
const double eps = 1e-8;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int main() {
    int N;
    cin >> N;
    string s = to_string(N);
    if (s[0] == '7' || s[1] == '7' || s[2] == '7') {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
#define lcm(x, y) ((x) * (y) / __gcd((x), (y)))
#define sz(a) (long long)((a).size())
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define debug(x) cout << #x << " : " << x << endl
#define part cout << "----------------------------------\n";
#define mp make_pair
#include <iostream>

#define fastinput                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

LL POW(LL x, LL y)
{
    LL ans = 1;
    LL base = x;
    while (y)
    {
        if (y & 1)
        {
            ans *= base;
        }
        base = base * base;
        y = y >> 1;
    }
    return ans;
}

int main()
{
    fastinput;
    LL n, i, j, k, t, temp,tc;
    string s;
    cin>>k>>s;
    LL len=s.length();
    string a="";
    for(i=0;i<min(k,len);i++)
    {
        a+=s[i];
    }

    if(len>k)
    {
        a+="...";

    }
    cout<<a<<endl;

    return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#define ll long long int
#define FOR(i,a,b) for(ll (i)=(a);i<(ll)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define rep1(i,n) FOR(i,1,n)
#define outi(a) printf("%lld\n",(a))
#define pb push_back
using namespace std;
inline ll read()
{
    ll x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
    return x;
}
//****************************

//****************************
void solve();
int main()
{
  //freopen("input.txt", "r", stdin);
  ll a = read(), b = read();
  ll c = a%b;
  cout << min(min(c, abs(c+b)), abs(c-b)) << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cassert>

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const int MAXN=1E5+10;

int n,cnt1,cnt2,k;
ll b[MAXN],a[MAXN];
int sum[MAXN];
ll Ans=1ll<<60;

int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1,x;i<=n;i++)
	{
		scanf("%d",&x);
		if(x<0) a[++cnt1]=-x;
		else if(x>0) b[++cnt2]=x;
		else --k;
	}
	sort(a+1,a+cnt1+1);
	for(int i=1;i<=cnt1;i++)
	{
		if(i+cnt2>=k)
			Ans=min(Ans,a[i]+a[i]+b[k-i]);
	}
	if(cnt2>=k) Ans=min(Ans,b[k]);
	for(int i=1;i<=cnt2;i++)
	{
		if(i+cnt1>=k)
			Ans=min(Ans,b[i]+b[i]+a[k-i]);
	}
	if(cnt1>=k) Ans=min(Ans,a[k]);
	printf("%lld\n",Ans);
}

Measured memory_bytes: 1024
package main

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

func main() {
	n := getInt()

	candidate := [4]int{0, 3, 5, 7}
	count := 0
L:
	for _, c1 := range candidate {
		for _, c2 := range candidate {
			for _, c3 := range candidate {
				for _, c4 := range candidate {
					for _, c5 := range candidate {
						for _, c6 := range candidate {
							for _, c7 := range candidate {
								for _, c8 := range candidate {
									for _, c9 := range candidate {
										for _, c10 := range candidate {
											numsOf753 := [10]int{c1, c2, c3, c4, c5, c6, c7, c8, c9, c10}
											flags := map[int]bool{3: false, 5: false, 7: false}
											for _, v := range numsOf753 {
												flags[v] = true
											}
											if !flags[3] || !flags[5] || !flags[7] {
												continue
											}
											flag := true
											for i := 1; i < 10; i++ {
												if numsOf753[i] == 0 && numsOf753[i-1] != 0 {
													flag = false
													break
												}
											}
											if !flag {
												continue
											}

											x := 0
											for i, v := range numsOf753 {
												x += v * pow(10, 10-i-1)
											}
											if x > n {
												break L
											}

											count++
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}

	fmt.Println(count)
}

func pow(a, b int) int {
	x := float64(a)
	y := float64(b)
	return int(math.Pow(x, y))
}

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

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


Measured memory_bytes: 5504
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    map<pair<char, char> , ll> mp;
    rep(i,1,N+1){
        string S = to_string(i);
        ll sz = S.size();
        char c1 = S[0], c2 = S[sz-1];
        mp[{c1,c2}]++;
    }
    ll ans = 0;
    rep(i,1,N+1){
        string S = to_string(i);
        ll sz = S.size();
        char c1 = S[0], c2 = S[sz-1];
        ans += mp[{c2,c1}];
    }
    print(ans);
    

}

Measured memory_bytes: 256
n = int(input().strip())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0

for i in range(n):
    if (a[i] <= b[i]):
        ans += a[i]
        b[i] -= a[i]
        a[i] = 0

        if (a[i + 1] <= b[i]):
            ans += a[i + 1]
            a[i + 1] = 0
        else:
            ans += b[i]
            a[i + 1] -= b[i]
    else:
        ans += b[i]
        a[i] -= b[i]

print(ans)


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

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

using namespace std;





void one_case() {
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    for (int i = 0; i < min(t.size(), s.size()); ++i) {
        if (s[i] > t[i]) {
            cout << "No\n";
            return;
        }
        if (s[i] < t[i]) {
            cout << "Yes\n";
            return;
        }
    }

    if (s.size() < t.size()) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

}


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


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

    return 0;
}


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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N, K;
int R, S, P;
string T;
signed main() {
    cin >> N >> K;
    cin >> R >> S >> P;
    cin >> T;
    int ans = 0;
    rep(i, K) {
        int dpr = 0, dps = 0, dpp = 0;
        for (int cur = i; cur < N; cur += K) {
            int a = dpr, b = dps, c = dpp;
            dpr = max(b, c);
            dps = max(a, c);
            dpp = max(a, b);
            if (T[cur] == 'r') { dpp += P; }
            if (T[cur] == 's') { dpr += R; }
            if (T[cur] == 'p') { dps += S; }
        }
        ans += max({dpr, dps, dpp});
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
N = int(input())
A = list(map(int, input().split()))

ans = 0
f = 0
t = -1
tmp = 0
while f < N:
  nt = t + 1
  if f == nt or (nt < N and tmp + A[nt] == tmp ^ A[nt]):
    tmp += A[nt]
    t = nt
  else:
    l = nt - f
    ans += l
    tmp -= A[f]
    f += 1
print(ans)

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

int main() {
    int K;
    std::cin >> K;

    int64_t sum = 0;
    for (int i = 1; i <= K; ++i) {
        for (int j = 1; j <= K; ++j) {
            for (int k = 1; k <= K; ++k) {
                sum += std::gcd(std::gcd(i, j), k);
            }
        }
    }

    std::cout << sum << std::endl;

    return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
int main()
{
    long h,n,i;
    long a;
    scanf("%ld%ld", &h, &n);
    for(i = 0; i < n; i++){
        scanf("%ld", &a);
        h -= a;
    }
    if(h <= 0){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
/* long long or int */
/* inline & usighed & sighned main */
/* xx 396 */

#include<bits/stdc++.h>
using namespace std;

const int MAX_N=1e5+10;

stack <int> S;
int N,M,deg[MAX_N],dist[MAX_N];
vector <int> G[MAX_N];

signed main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>N>>M;
	for(int i=0;i<M;i++){
		int X,Y; cin>>X>>Y; X--; Y--;
		G[X].push_back(Y); deg[Y]++;
	}
	for(int i=0;i<N;i++) if(deg[i]==0) S.push(i);
	while(!S.empty()){
		int fr=S.top(); S.pop();
		for(int i=0;i<G[fr].size();i++){
			int to=G[fr][i]; deg[to]--;
			dist[to]=max(dist[to],dist[fr]+1);
			if(deg[to]==0) S.push(to);
		}
	}
	cout<<(*max_element(dist,dist+N))<<endl;
	return 0;
}

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

int main(){
    int n; cin>>n;
    vector<int> v(n); vector<int> c(n);
    int ans = 0;
    for(int i=0; i<n; i++){
        cin >> v[i];
    }
    for(int i=0; i<n; i++){
        cin >> c[i];
    }
    for(int i=0; i<n; i++){
        if(v[i]-c[i]>0) ans += v[i]-c[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace ConsoleApp2
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int[] times = Read(Console.ReadLine());

            int M = times.Max();

            int ans = times.Sum();

            Console.WriteLine(ans - M);


        }


        private static string ReplaceOneChar(string S ,int index,string newS)
        {
            string s1 = S.Substring(0, index-1);
            string s2 = S.Substring(index);
            return s1 + newS + s2;
        }

        private static int[] Read(string input)
        {
            string[] inputs = input.Split(' ');
            int num = inputs.Length;
            int[] ints = new int[num];
            for (int i = 0; i < num; i++)
            {
                ints[i] = int.Parse(inputs[i]);
            }
            
            return ints;
        }


    }
}


Measured memory_bytes: 13268
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e4 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}



int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r;

      bool flag=false;

      string str;


       cin>>n;

     vector<plll>v;

       for(i=0; i<n; i++)
       {
           cin>>a>>b>>c;

          v.pb({a+b,{a,c}});
       }

       sort(vll(v));

       ll mx=0,dp[Max+2]={};



     for(auto x : v)
     {
         ll solid=x.F,w=x.S.F,v=x.S.S;

         for(i=solid-w; i>=0; i--)
         {
              dp[i+w]=max(dp[i+w],dp[i]+v);

              mx=max(mx,dp[i+w]);
         }
     }

     cout<<mx<<endl;




}



Measured memory_bytes: 3868
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++)
	cin>>a[i];
	sort(a,a+n);
	ll ans=0;
	ans+=a[n-1];
	ll cnt=n-2,i=n-2;
	while(cnt>1)
	{
		ans+=2*a[i];
		cnt-=2;
		i--;
	}
	if(cnt==1)
	ans+=a[i];
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 5236
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner in = new java.util.Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		
		int add = a+b;
		int sub = a-b;
		int p = a*b;
		if(add >= sub && add >= p) {
			System.out.print(add);
		}else if (sub >= add && sub >= p) {
			System.out.print(sub);
		}else {
			System.out.print(p);
		}
		System.out.print("");
	
		in.close();
		
	}
}


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

using namespace std;

int main(){
	int a, b, c, d;
	scanf("%d %d %d %d", &a, &b, &c, &d);
	
	bool st1 = abs(a - b) <= d && abs(c - b) <= d;
	bool st2 = abs(a - c) <= d;
	
	printf( st1 or st2 ? "Yes\n" : "No\n");
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

internal static class ConsoleReader
{
    public static string Get() { return Console.ReadLine(); }
    public static int GetInteger() { return int.Parse(Console.ReadLine()); }
    public static IEnumerable<int> GetIntegers() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)); }
}

namespace AtCoderBeginnerContest
{
    internal class Program
    {
        public static int N { get; private set; }
        public static string S { get; private set; }

        private static void Main() { var result = GetResult(); Debug.WriteLine(result); Console.WriteLine(result); }

        private static object GetResult()
        {
            N = ConsoleReader.GetInteger();
            S = ConsoleReader.Get();

            return string.Join("", S.Select(x => GetAfter(x)));
        }

        private static char GetAfter(char x)
        {
            for (int i = 0; i < N; i++)
            {
                x = Next(x);
            }
            return x;
        }

        private static char Next(char x)
        {
            switch (x)
            {
                case 'A': return 'B';
                case 'B': return 'C';
                case 'C': return 'D';
                case 'D': return 'E';
                case 'E': return 'F';
                case 'F': return 'G';
                case 'G': return 'H';
                case 'H': return 'I';
                case 'I': return 'J';
                case 'J': return 'K';
                case 'K': return 'L';
                case 'L': return 'M';
                case 'M': return 'N';
                case 'N': return 'O';
                case 'O': return 'P';
                case 'P': return 'Q';
                case 'Q': return 'R';
                case 'R': return 'S';
                case 'S': return 'T';
                case 'T': return 'U';
                case 'U': return 'V';
                case 'V': return 'W';
                case 'W': return 'X';
                case 'X': return 'Y';
                case 'Y': return 'Z';
                case 'Z': return 'A';
                default: throw new NotImplementedException();
            }
        }
    }
}


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

lli n, k;

int main(void){
	cin >> n >> k;
	lli ans = k;
	n--;
	while(n--) ans*=k-1;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3596