akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if ((A + B) < (C + D))
    cout << "Right" << endl;
  if ((A + B) > (C + D))
    cout << "Left" << endl;
  if ((A + B) == (C + D))
    cout << "Balanced" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#define INF 1<<20
using namespace std;
int main() {
  int n; cin >> n;
  double p[510], q[510];
  for (int i = 1; i <= n; ++i) cin >> p[i];
  for (int i = 0; i < n + 1; ++i) cin >> q[i];
  double sump[501] = {}, sumq[501] = {}, dp[510][510] = {};
  for (int i = 1; i <= n; ++i) sump[i] = sump[i - 1] + p[i];
  sumq[0] = q[0];
  for (int i = 1; i <= n; ++i) sumq[i] = sumq[i - 1] + q[i];
  for (int i = 1; i <= n; ++i)
    for (int j = i; j <= n; ++j) dp[i][j] = INF;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n - i + 1; ++j) {
      int x = i + j - 1;
      for (int k = j; k <= x; ++k) {
	double sum = sump[x] - sump[j - 1]+sumq[x];
	if (j >= 2) sum -= sumq[j - 2];
	if (dp[j][x] > sum + dp[j][k - 1] - p[k] + dp[k + 1][x]) dp[j][x] = sum + dp[j][k - 1] - p[k] + dp[k + 1][x];
      }
    }
  }
  cout << dp[1][n] + 1 << endl;
  return 0;
}



Measured memory_bytes: 5344
#include <stdio.h>
#include <math.h>
//#define D(fmt,...) fprintf(stderr, fmt, ##__VA_ARGS__)
#define D(fmt,...) 
#define P(fmt,...) fprintf(stdout, fmt, ##__VA_ARGS__)


int gcd (int a, int b) {
  int small = a < b ? a : b;
  int big = a < b ? b : a;
  int gcd  = 1;
  int i = 1;
  for (i = 2; i < small; i++) {
    int countA = 0;
    while (small % i == 0) {
      countA++;
      small /= i;
    }
    int countB = 0;
    while (big % i == 0) {
      countB++;
      big /= i;
    }
    if (countA != 0 && countB != 0) {
      int count = countA < countB ? countA:countB;
      D("%d ^ %d = %f\n", i, count, floor(pow(i, count)));
      gcd *= floor(pow(i,count));
    }
    D("i=%d\n", i);
  }

  return gcd;
}

int lcm (int a, int b, int g) {
  int lcm = 0;
  int min = a < b ? a : b;
  int x = a / g;
  int y = b / g;
  return g * x * y;
}
		      
int main (int ac, char **av)
{
  while(feof(stdin) == 0) {
    int a, b = 0;
    fscanf(stdin, "%d %d\n", &a, &b);
    int g = gcd(a, b);
    P("%d %d\n", g, lcm(a, b, g));
  }
  return 0;
}

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

int arr[199][199];
int reg[199];

int main() {
	int a,b;
	cin>>a>>b;
	for(int i=0;i<a;i++) {
		for(int j=0;j<b;j++) {
			cin>>arr[i][j];
		}
	}
	for(int i=0;i<a;i++) {
		int sum=0,c=0;
		for(int j=0;j<b;j++) {
			if(c!=0) cout<<" ";
			cout<<arr[i][j];
			sum+=arr[i][j];
			reg[j]+=arr[i][j];
			c++;
		}
		cout<<" "<<sum;
		reg[b]+=sum;
		cout<<endl;
	}
	int c=0;
	for(int i=0;i<=b;i++) {
		if(c!=0) cout<<" ";
		cout<<reg[i];
		c++;
	}
	cout<<endl;
}


Measured memory_bytes: 3144
import java.util.Scanner;
public class Main {
public static void main(String[]srgs) {
	Scanner s=new Scanner(System.in);
	int a=s.nextInt();
	int b=s.nextInt();
	int c=s.nextInt();
	if(a+b+1>c) {
		System.out.println(b+c);
	}
	else {
		System.out.println(a+b+1+b);
	}
	}
}


Measured memory_bytes: 22996
#include<iostream>
using namespace std;
int main(){
    int h, w;
    cin >> h >> w;
    int s[h][w];

    for(int i=0; i<h; i++){
        string str;
        cin >> str;
        for(int j=0; j<w; j++){
            if(str[j] == '.') s[i][j] = 0;
            else s[i][j] = 9;
        }
    }


    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            int mine = 0;
            for(int k=-1; k<2; k++){
                if((i+k >= 0) && (i+k <h)){
                    for(int l=-1; l<2; l++){
                        if((j+l>=0)&&(j+l<w)){
                            if(s[i+k][j+l] >= 9)mine++;
                        }
                    }
                }
            }
            s[i][j]+=mine;
        }
    }

    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(s[i][j] >=9) cout << "#";
            else cout << s[i][j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, m, x, y int
	fmt.Scan(&n, &m, &x, &y)
	for i := 0; i < n; i++ {
		var v int
		fmt.Scan(&v)
		if x < v {
			x = v
		}
	}
	for i := 0; i < m; i++ {
		var v int
		fmt.Scan(&v)
		if v < y {
			y = v
		}
	}
	if x < y {
		fmt.Println("No War")
		return
	}
	fmt.Println("War")
}


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

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

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

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

    vector<int> c(n);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            c[i] += a[i][j] * b[j];
        }
        cout << c[i] << endl;
    }
}


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

int main() {
  int N, a, b, c, d;
  cin >> N;
  a = N / 1000;
  b = (N - a*1000)/100;
  c = (N - a*1000 - b*100)/10;
  d = N - a*1000 - b*100 - c*10;

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

Measured memory_bytes: 256
import java.util.Scanner;
import java.math.BigDecimal;

public class Main {
    public static void main(String args[]) {

        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();

        int d = a / b;
        int r = a % b;
        double f = (double)a / (double)b;
        String sf = BigDecimal.valueOf(f).toPlainString();

        System.out.println(d + " " + r + " " + sf);
    }
}



Measured memory_bytes: 26704
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

a,b=nm()
tmp1=max(a,b)
tmp2=min(a,b)
ans=[]
for i in range(tmp1):
    ans.append(str(tmp2))

print(''.join(ans))
        
    

Measured memory_bytes: 64592
use std::io;
//use std::collections::HashMap;
//use std::collections::BinaryHeap;
//use std::collections::HashSet;
//use std::mem; // mem::swap(&mut x,&mut y);
use std::cmp; // cmp::max,cmp::min

// Rust memo: https://hackmd.io/i0lQY1OKTDW1t66TECOmiw?both

#[allow(dead_code)]
fn read_line() -> String{
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
fn read_charvec() -> Vec<char>{
    read_line().chars().collect()
}

#[allow(dead_code)]
fn read_ints() -> Vec<i64>{
    let s = read_line();
    let split:Vec<&str> = s.split(" ").collect();
    split.iter().map(|&x| x.to_string().parse().unwrap()).collect()
}

#[allow(dead_code)]
fn read_int() -> i64{
    read_ints()[0]
}

#[allow(dead_code)]
fn reverse(s: &String) -> String{
    s.chars().rev().collect::<String>()
}

#[allow(dead_code)]
fn read_lines(n:i64) -> Vec<String>{
    let mut xs = Vec::new();

    for _i in 0..n{
        xs.push(read_line());
    }

    xs
}

#[allow(dead_code)]
fn read_ints2(n:i64) -> Vec<i64>{
    read_lines(n).iter().map(|x| x.parse().unwrap()).collect()
}

#[allow(dead_code)]
fn arange(start:i64,end:i64,step:i64) -> Vec<i64>{
    let mut ret = Vec::new();
    let mut i = start;

    while i < end{
        ret.push(i);
        i += step;
    }

    ret
}

#[allow(dead_code)]
const DXS : [i64; 4] = [0,0,1,-1];
#[allow(dead_code)]
const DYS : [i64; 4]  = [1,-1,0,0];
#[allow(dead_code)]
const INF : i64 = 999999999;
#[allow(dead_code)]
const N_PRIME : i64 = 1000000007;

////////////////////////////////////////////////

fn main(){
    let mut xs = read_ints();
    xs.sort();
    println!("{}",xs[2]*10+xs[1]+xs[0]);
}


Measured memory_bytes: 4352
use std::collections::VecDeque;
// D
fn main() {
    input! {
        n: usize,
        ab: [(usize, usize);n-1]
    }
    let mut edges = vec![vec![]; n];
    for i in ab {
        edges[i.0 - 1].push(i.1 - 1);
        edges[i.1 - 1].push(i.0 - 1)
    }

    let mut ldist = vec![0; n];
    let mut stack = Vec::new();
    let mut visited = vec![false; n];
    stack.push((0, 0));
    visited[0] = true;
    while let Some((node, dist)) = stack.pop() {
        ldist[node] = dist;
        for &next in &edges[node] {
            if !visited[next] {
                visited[next] = true;
                stack.push((next, dist + 1));
            }
        }
    }
    let mut rdist = vec![0; n];
    let mut stack = Vec::new();
    let mut visited = vec![false; n];
    stack.push((n - 1, 0));
    visited[n - 1] = true;
    while let Some((node, dist)) = stack.pop() {
        rdist[node] = dist;
        for &next in &edges[node] {
            if !visited[next] {
                visited[next] = true;
                stack.push((next, dist + 1));
            }
        }
    }
    let mut p = 0i64;
    for i in 1..n - 1 {
        if ldist[i] <= rdist[i] {
            p += 1;
        } else {
            p -= 1;
        }
    }
    if p > 0 {
        println!("Fennec");
    } else {
        println!("Snuke");
    }
}

#[macro_export(local_inner_maccros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[macro_export(lcal_inner_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

#[macro_export(lcal_inner_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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


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

//dp[??\???][?????\][????????\]
int dp[110][4][4]={};
int det[110]={};
int main(){
	int N,K;
	cin>>N>>K;
	int tmp;
	for(int i=0;i<K;i++){
		cin>>tmp;
		cin>>det[tmp];
	}
	if(det[1]!=0){
		if(det[2]!=0){
			for(int i=1;i<=3;i++){
				dp[3][i][det[2]]=1;
			}
			if(det[1]==det[2])dp[3][det[2]][det[2]]=0;
		}
		else{
			for(int i=1;i<=3;i++){
				for(int j=1;j<=3;j++){
					dp[3][i][j]=1;
				}
			}
			dp[3][det[1]][det[1]]=0;
		}
	}
	else if(det[2]!=0){
		for(int i=1;i<=3;i++){
			dp[3][i][det[2]]=3;
		}
		dp[3][det[2]][det[2]]=2;
	}
	else{
		for(int i=1;i<=3;i++){
			for(int j=1;j<=3;j++){
				if(i==j) dp[3][i][j]=2;
				else dp[3][i][j]=3;
			}
		}
	}
	if(det[3]!=0)for(int i=1;i<=3;i++){
		if(det[3]!=i)for(int j=1;j<=3;j++){
			dp[3][i][j]=0;
		}
	}

	for(int i=3;i<N;i++){
		if(det[i+1]==0)for(int j=1;j<=3;j++){
			for(int k=1;k<=3;k++){
				if(j==k) dp[i+1][j][k]=dp[i][k][1]+dp[i][k][2]+dp[i][k][3]-dp[i][k][k];
				else dp[i+1][j][k]=dp[i][k][1]+dp[i][k][2]+dp[i][k][3];
				dp[i+1][j][k]%=10000;
			}
		}
		else{
			for(int k=1;k<=3;k++){
				if(det[i+1]==k) dp[i+1][det[i+1]][k]=dp[i][k][1]+dp[i][k][2]+dp[i][k][3]-dp[i][k][k];
				else dp[i+1][det[i+1]][k]=dp[i][k][1]+dp[i][k][2]+dp[i][k][3];
				dp[i+1][det[i+1]][k]%=10000;
			}
		}
	}

	int sum=0;
	for(int i=1;i<=3;i++){
		for(int j=1;j<=3;j++){
			sum+=dp[N][i][j];
		}
	}
	cout<<sum%10000<<endl;
	return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<set>
using namespace std;
int stoi(string x){stringstream ss;ss<<x;int tmp;ss>>tmp;return tmp;}
string itos(int x){stringstream ss;ss<<x;return ss.str();}
int main(){
	int ta[100][100],sum[100];
	int n,all;
	while(cin>>n,n){
	all=0;
	for(int i=0;i<100;i++)sum[i]=0,fill(ta[i],ta[i]+100,0);
	for(int i=0;i<n;i++)for(int j=0;j<n;j++)cin>>ta[i][j];
	for(int i=0;i<n;i++){
		int tnow=0;
		for(int j=0;j<n;j++){
		string ss=itos(ta[i][j]);
		for(int i=0;i<5-ss.size();i++)cout<<" ";	
		cout<<ta[i][j];
		sum[j]+=ta[i][j];
		tnow+=ta[i][j];
		all+=ta[i][j];
		}
		string ss=itos(tnow);
		for(int i=0;i<5-ss.size();i++)cout<<" ";
		cout<<tnow<<endl;
	}
	for(int i=0;i<n;i++){
	string ss=itos(sum[i]);
	for(int i=0;i<5-ss.size();i++)cout<<" ";
	cout<<sum[i];
	if(i==n-1){ss=itos(all);for(int i=0;i<5-ss.size();i++)cout<<" ";}
	}
	cout<<all<<endl;
	}

	return 0;
}

Measured memory_bytes: 1260
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
  ll n,d;
  cin>>n>>d;
  ll a,b;
  int count=0;
  while(n--)
  {
    cin>>a>>b;
    if((a*a+b*b)<=(d*d))
      count++;
    

    
  }
  cout<<count<<endl;
  

  
  
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <numeric>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600
#define MOD 1000000007
#define long long long

const int MAX_PRIME = 1000;
vector<int> primes;
bool isPrime[MAX_PRIME+1];
// sieve of Erastosthenes
inline void prime_list(){
  const int sz = MAX_PRIME;
  fill(isPrime, isPrime+sz+1, true);
  isPrime[0]=isPrime[1]=false;
  for(int i=4;i<=sz;i+=2) isPrime[i]=false;
  primes.pb(2);
  for(int i=3; i<=sz; i+=2){
    if(isPrime[i]){
      primes.pb(i);
      for(long j=(long)i*i; j<=sz; j+=i) isPrime[j]=false;
    }
  }
}

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

  map<int, int> m;
  repl(i,2,n+1){
    int j=i;
    for(auto p : primes){
      if(j<p) break;
      while(j%p==0){j/=p; m[p]++;}
    }
    if(j!=1) m[j]++;
  }

  long res=1;
  for(auto p : m){
    res*=(p.se+1);
    res %=MOD;
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<int> v;
typedef vector<ll> vll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
const int INF = 1001001001;
const int mINF = -1001001001;
const int mod = 1000000007;
// << fixed << setprecision(0) <<
// sort(ALL(),greater<int>());


int main() {
  int n;
  cin >> n;
  v a(n);
  REP(i,n) cin >> a[i];
  sort(ALL(a),greater<int>());
  int al=0,bo=0;
  REP(i,n) {
    if(i%2==0) {
      al+=a[i];
    } else {
      bo+=a[i];
    }
  }
  cout << al-bo << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
template <class T, class U>ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >>p.second ;
	return is;
}
template <class T>istream& operator>>(istream& is,  vector<T>& v) {
	rep(i, v.size()) {
		is >> v[i];
	}
	return is;
}
ll mod                = 1e9 + 7;
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	ll ans=0LL;
	cin >>n;
	V a(n);
	V sum(n, 0LL);
	cin >> a;
	rep(i, n) { sum[i] += a[i]; 
	if(i!=0){
		sum[i] += sum[i - 1];
		sum[i] %= mod;
	}}
	//clog << sum << endl;
	rep(i, n) { 
		if(i!=0){
		ans += sum[i-1] * a[i];
		ans %= mod;
		}
	}
	cout<<ans<<endl;
}
/*
累積和
*/

Measured memory_bytes: 6424
n , x = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
for i in range(1,n):
    if a[i-1] + a[i] > x:
        p = a[i-1] + a[i] - x

        if a[i] - p >= 0:
            a[i] -= p
            ans += p
        elif a[i] - p < 0:
            a[i] = 0
            a[i-1] -= p - a[i]
            ans += p
print(ans)

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

int gcd (int a, int b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}


int main(){
    int n;
    ll res,sum=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++ ){
                int temp = gcd(i,j);
                res=gcd(temp,k);
                sum = sum + res;
            }
        }
    }
    cout<<sum;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a, b)*b;}
const int IINF=(1<<30);
const ll LLINF = 1LL<<60;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n;cin >> n;
  int hoge[100000] = {0};
  int tmp;
  int ans = 0;
  for (int i = 0; i < n; i++){
    cin >> tmp;
    if(tmp > 100000){
      ans += 1;
      continue;
    }
    hoge[tmp - 1] += 1;
  }

  // int ans = 0;
  for(int i = 0; i < 100000; i++){
    // cout << "hoge" << endl;
    if(hoge[i] >= i + 1){
      ans += hoge[i] - (i + 1);
    }else{
      ans += hoge[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline


class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]


N, M = map(int, input().split())
A = []
B = []
for _ in range(M):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

T = UnionFind(N)
ans = [0]*M
ans[M-1] = N*(N-1)//2
for i in reversed(range(M-1)):
    a = A[i+1]
    b = B[i+1]
    if T.isSameGroup(a, b):
        ans[i] = ans[i+1]
    else:
        ans[i] = ans[i+1] - T.Count(a) * T.Count(b)
    T.Unite(a, b)

for i in range(M):
    print(ans[i])


Measured memory_bytes: 17844
#include <iostream>
#include <vector>

using namespace std;

int main() {
	long long int n, m;
	while (cin >> n >> m) {
		if (n == 0 && m == 0) {
			break;
		}
		vector<long long int> a(n);
		for (long long int i = 0; i < n; i++) {
			cin >> a[i];
		}
		long long int ans = -1;
		for (long long int i = 0; i < n; i++) {
			for (long long int j = i+1; j < n; j++) {
				if (a[i] + a[j] <= m&& ans <= a[i] + a[j]) {
					ans = a[i] + a[j];
				}
			}
		}
		if (ans == -1) {
			cout << "NONE" << endl;
		}
		else {
			cout << ans << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
typedef pair<int,ll> Pil;
typedef pair<ll,ll> Pll;
typedef pair<string,int> Psi;
typedef pair<Psi,int> Psii;

const int inf=1000000000;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main() {
	int n;
	cin>>n;
	int p[n];
	rep(i,n)cin>>p[i];
	int r=0;
	rep(i,n-2){
		if((p[i]<p[i+1]&&p[i+1]<p[i+2])||(p[i]>p[i+1]&&p[i+1]>p[i+2]))r++;
	}
	cout<<r<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
using namespace std;
const int MAXN = 2e6 + 5;
char s[MAXN];
long long a[MAXN];
long long vis[1000];
int main()
{
    scanf("%s",s+1);
    int n = strlen(s+1);
    int t = 0;
    long long ans = 0;
    for(int i = 1; i <= n; i++) {
        vis[s[i]]++;
    }
    for(int i = 'a'; i <= 'z'; i++) if(vis[i] != 0) a[++t] = vis[i];
    for(int i = 1; i < t; i++){
        for(int j = i + 1; j <= t; j++){
            ans += a[i] * a[j];
        }
    }
    printf("%lld\n",ans+1);
}

Measured memory_bytes: 2304
#include <iostream>

using namespace std;

const int MAX_N = 2000001;

using ll = long long int;

int N;
ll A[MAX_N];

int main(void) {
    cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }

    ll S = 0;
    for (int i = 0; i < N; ++i) {
        S += A[i];
    }

    ll TS = 0;
    for (int i = 0; i < N; ++i) {
        TS += A[i];
        if (TS > S / 2) {
            ll ans = abs(2 * TS - S);
            TS -= A[i];
            ans = min(abs(2 * TS - S), ans);
            cout << ans << endl;
            return 0;
        }
    }

    cout << "NA" << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1<<20,INF=1<<20;
const long double eps=1e-13;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,K;cin>>N>>K;
    vector<long double> x(N),y(N),c(N);
    for(int i=0;i<N;i++) cin>>x[i]>>y[i]>>c[i];
    
    long double left=0.0,right=1e6;
    
    if(K==1){
        cout<<0<<endl;
        return 0;
    }
    
    if(K==2){
        long double ans=INF;
        for(int i=0;i<N;i++){
            for(int j=i+1;j<N;j++){
                ans=min(ans,(hypot(x[i]-x[j],y[i]-y[j])*c[i]*c[j])/(c[i]+c[j]));
            }
        }
        cout<<setprecision(25)<<ans<<endl;
        return 0;
    }
    
    for(int q=0;q<100;q++){
        long double mid=(left+right)/2.0;
        bool ok=false;
        
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                if(i==j) continue;
                int cnt=0;
                long double ri=mid/c[i],rj=mid/c[j];
                if(ri>rj+eps) continue;
                if(hypot(x[i]-x[j],y[i]-y[j])>ri+rj+eps) continue;
                
                long double x1=x[j]-x[i],y1=y[j]-y[i],a=(x1*x1+y1*y1+ri*ri-rj*rj)/2.0;
                
                long double xx=(a*x1+y1*sqrt((x1*x1+y1*y1)*ri*ri-a*a))/(x1*x1+y1*y1);
                long double yy=(a*y1-x1*sqrt((x1*x1+y1*y1)*ri*ri-a*a))/(x1*x1+y1*y1);
                
                xx+=x[i];
                yy+=y[i];
                
                if(hypot(x1,y1)+ri<rj+eps) continue;
                
                for(int k=0;k<N;k++){
                    if(hypot(xx-x[k],yy-y[k])<=mid/c[k]+eps) cnt++;
                }
                if(cnt>=K) ok=true;
            }
        }
        
        for(int i=0;i<N;i++){
            int cnt=0;
            for(int k=0;k<N;k++){
                if(hypot(x[i]-x[k],y[i]-y[k])<=mid/c[k]+eps) cnt++;
            }
            if(cnt>=K) ok=true;
        }
        
        if(ok) right=mid;
        else left=mid;
    }
    
    cout<<setprecision(25)<<right<<endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
//cervello|Phoenix
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define all(x) x.begin(),x.end()
#define mod 1000000007

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ll n,k; cin>>n>>k;
  queue<int> dq;
  for(int i=0;i<k;i++){
    int x; cin>>x;
    dq.push(x);
  }
  for(int i=k;i<n;i++){
    int x; cin>>x;
    int val=dq.front();
    dq.pop();
    if(val<x)
      cout<<"Yes\n";
    else
      cout<<"No\n";
    dq.push(x);
  }
  return 0;
}

Measured memory_bytes: 4052
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)

const int maxn = 200005;

int n, d;
int a[maxn];
vector <pair <ll, pair <int, int> > > edges;

struct union_find {
	int fa[maxn], siz[maxn];
	union_find() {
		for (int i = 0; i < maxn; ++ i)
			fa[i] = i, siz[i] = 1;
	}
	int find(int x) {
		return fa[x] == x ? x : fa[x] = find(fa[x]);
	}
	void merge(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return ;
		if (siz[x] < siz[y]) swap(x, y);
		fa[y] = x;
		siz[x] += siz[y];
	}
} dsu;

void solve(int l, int r) {
	if (l + 1 == r) return ;
	int m = (l + r) >> 1;
	vector <pair <ll, int> > lft, rgt;
	for (int i = l; i < m; ++ i)
		lft.pb(mp(a[i] + 1LL * (m - i) * d, i));
	for (int i = m; i < r; ++ i)
		rgt.pb(mp(a[i] + 1LL * (i - m) * d, i));
	sort(lft.begin(), lft.end());
	sort(rgt.begin(), rgt.end());
	for (int i = 0; i < lft.size(); ++ i)
		edges.pb(mp(lft[i].first + rgt[0].first, mp(lft[i].second, rgt[0].second)));
	for (int i = 0; i < rgt.size(); ++ i)
		edges.pb(mp(lft[0].first + rgt[i].first, mp(lft[0].second, rgt[i].second)));
	solve(l, m); solve(m, r);
}

int main() {
	scanf("%d %d", &n, &d);
	for (int i = 0; i < n; ++ i) scanf("%d", &a[i]);
	solve(0, n);
	sort(edges.begin(), edges.end());
	ll ans = 0;
	for (int i = 0; i < edges.size(); ++ i) {
		ll d = edges[i].first;
		int u = edges[i].second.first;
		int v = edges[i].second.second;
		if (dsu.find(u) != dsu.find(v)) {
			ans += d;
			dsu.merge(u, v);
		}
	}
	printf("%lld\n", ans);
	return 0;
}


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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int a,b;

    char s[14] = {};

    Scd2(a,b);
    Scs(s);

    bool ans = true;
    Rep(i,a+b+1){
        if( i == a ) {
            if( s[i] != '-' ){
                ans = false;
                break;
            }
        }else{
            if( s[i] > '9' || s[i] < '0' ){
                ans = false;
                break;
            }
        }
    }

    YesNo(ans);

    return 0;
}



Measured memory_bytes: 256
MAX_NUM = 10 ** 9 + 7

N = input()
memo = [{} for _ in range(N + 1)]

# def ok(last4):
#   if 'AGC' in last4 or \
#   'GAC' in last4 or \
#   'ACG' in last4 or \
#   last4[0] == 'A' and last4[2:] == 'GC' or \
#   last4[:2] == 'AG' and last4[-1] == 'C':
#     return False
#   return True

def ok(last4):
  for i in range(4):
    t = list(last4)
    if i >= 1:
      t[i - 1], t[i] = t[i], t[i - 1]
    if 'AGC' in ''.join(t):
      return False
  return True

def dfs(cur, last3):
  if cur == N:
    return 1

  if last3 in memo[cur]:
      return memo[cur][last3]

  res = 0
  for c in 'ACGT':
    last4 = last3 + c
    if ok(last4):
      res = (res + dfs(cur + 1, last4[1:])) % MAX_NUM

  memo[cur][last3] = res
  return res

print dfs(0, 'TTT')

Measured memory_bytes: 3332
n = gets.chomp.to_i
k = gets.chomp.to_i
array = gets.chomp.split(' ').map(&:to_i)
sum = 0

array.each do | x |
  if x > k - x
    sum += (k - x) * 2
  else
    sum += x * 2
  end
end

print(sum)


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

typedef long long s64;
#define rep(i,l,r) for(int i=l;i<=r;++i)
const int N=2e5+5;
struct Pr
{
	int c0,c1;
};
Pr p[N];
bool operator <(const Pr &a,const Pr &b)
{
	return (s64)a.c1*b.c0>(s64)b.c1*a.c0;
}
bool operator ==(const Pr &a,const Pr &b)
{
	return (s64)a.c1*b.c0==(s64)b.c1*a.c0;
}

namespace BING
{
int fa[N];
int find(int x)
{
	return x==fa[x]?x:fa[x]=find(fa[x]);
}
};
namespace TREE
{
int fa[N];
};

struct Heap
{
	priority_queue<pair<Pr,int> >a,b;
	void push(int x)
	{
		a.push({p[x],x});
	}
	void del(int x)
	{
		b.push({p[x],x});
	}
	bool empty()
	{
		while(!b.empty()&&a.top()==b.top()){a.pop();b.pop();}
		return a.empty();
	}
}heap;

int main()
{
#ifdef kcz
	freopen("1.in","r",stdin);
#endif
	int n;
	cin>>n;
	rep(i,2,n)scanf("%d",TREE::fa+i);
	rep(i,1,n)
	{
		int v;
		scanf("%d",&v);
		if(v)p[i].c1=1;
		else p[i].c0=1;
	}
	rep(i,1,n)BING::fa[i]=i;
	s64 ans=0;
	rep(i,2,n)heap.push(i);
	while(!heap.empty())
	{
		int x=heap.a.top().second;heap.a.pop();
		int y=BING::find(TREE::fa[x]);
		if(y!=1)heap.del(y);
		ans+=(s64)p[y].c1*p[x].c0;
		BING::fa[x]=y;
		p[y].c0+=p[x].c0;p[y].c1+=p[x].c1;
		if(y!=1)heap.push(y);
	}
	cout<<ans;
}

Measured memory_bytes: 11760
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i < n; i++)
#define rep3(i, x, n) for(int i = x; i > n; i--)
const long long MOD = 1e9+7;
const long long INF = 1e15;
typedef long long ll;
typedef pair<ll, ll> P;


int main(){
    ll N;
    cin >> N;
    if(N%2 == 0) cout << N/2 - 1 << endl;
    else cout << N/2 << endl;
}

Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    ans = float('INF')
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            c = max(len(str(i)), len(str(n//i)))
            if c < ans:
                ans = c
    print(ans)
    # divisors.sort()
    return divisors

n = int(input())
div = make_divisors(n)


Measured memory_bytes: 39024
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================








int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================

	
	int N, K;
	cin >> N >> K;


	int keta = 1;
	int beki = 1;
	while (true) {

		if (N < beki) {
			cout << keta-1;
			return 0;
		}

		keta += 1;
		beki *= K;


	}


}


Measured memory_bytes: 256
#include<cstdio>

int main(void){
char s[1200];

fgets(s,sizeof(s),stdin);

char a,A;
a='a';
A='A';
int c;
c=A-a;

int i;
for(i=0;i<sizeof(s);i++){
	if((s[i]>=a)&&(s[i]<=a+25)){
		s[i]=s[i]+c;
	} else if((s[i]>=A)&&(s[i]<=A+25)){
		s[i]=s[i]-c;
	};
};


	printf("%s",s);


return 0;
}

Measured memory_bytes: 2660
#include<iostream>
#include<algorithm>
#include<utility>
using namespace std;
const long mod=1e9+7;
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
int N,K;
pair<long,long>A[2<<17];
main()
{
	cin>>N>>K;
	for(int i=0;i<N;i++)
	{
		cin>>A[i].second;
		A[i].first=abs(A[i].second);
	}
	sort(A,A+N);
	reverse(A,A+N);
	if(A[K-1].second==0)
	{
		cout<<0<<endl;
		return 0;
	}
	int cnt=0;
	for(int i=0;i<K;i++)if(A[i].second<0)
	{
		cnt++;
	}
	long ans=1;
	for(int i=0;i<K;i++)ans=ans*A[i].first%mod;
	if(cnt%2==0)
	{
		cout<<ans<<endl;
		return 0;
	}
	int pi=K-1,ni=K-1,pj=K,nj=K;
	while(pi>=0&&A[pi].second<0)pi--;
	while(ni>=0&&A[ni].second>0)ni--;
	while(pj<N&&A[pj].second<=0)pj++;
	while(nj<N&&A[nj].second>=0)nj++;
	if(ni>=0&&pj<N&&pi>=0&&nj<N)
	{
		//pj/ni<=>nj/pi
		if(A[pi].first*A[pj].first>A[ni].first*A[nj].first)
		{
			cout<<ans*A[pj].first%mod*power(A[ni].first,mod-2)%mod<<endl;
		}
		else
		{
			cout<<ans*A[nj].first%mod*power(A[pi].first,mod-2)%mod<<endl;
		}
	}
	else if(ni>=0&&pj<N)
	{
		cout<<ans*A[pj].first%mod*power(A[ni].first,mod-2)%mod<<endl;
	}
	else if(pi>=0&&nj<N)
	{
		cout<<ans*A[nj].first%mod*power(A[pi].first,mod-2)%mod<<endl;
	}
	else if(A[N-1].second==0)
	{
		cout<<0<<endl;
	}
	else
	{
		long now=1;
		for(int i=0;i<K;i++)now=now*A[N-i-1].first%mod;
		cout<<(mod-now)%mod<<endl;
	}
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; ++i)

using namespace std;
using ll = long long;
const string YES = "Yes";
const string NO = "No";

void solve(string N) {
  ll sum(0);
  REP(i, N.length())
    sum += (N[i] - '0');
  cout << (sum % 9 ? NO : YES) << endl;
}

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

  string N;
  cin >> N;

  solve(N);

  return 0;
}


Measured memory_bytes: 3864
n = int(input())
alist=list(map(int,input().split()))
blist=list(map(int,input().split()))
clist=list(map(int,input().split()))
clist.append(0)
ans = 0
for i in range(0,n):
    ans += blist[alist[i] - 1]
    if i != n-1 :
        if alist[i] +1 == alist[i+1]:
            ans += clist[alist[i] - 1]


print(ans)

Measured memory_bytes: 3064
# INPUT
n, m, l = map(int, input().split())

matrix_A = []
matrix_B = []
matrix_C = [[0 for i in range(l)] for j in range(n)]

for _ in range(n):
    matrix_A.append(list(map(int, input().split())))

for _ in range(m):
    matrix_B.append(list(map(int, input().split())))

# CALC, OUTPUT
for cnt_n in range(n):
    for cnt_l in range(l):

        for cnt_m in range(m):

            matrix_C[cnt_n][cnt_l] += matrix_A[cnt_n][cnt_m] * matrix_B[cnt_m][cnt_l]

# OUTPUT
for cnt_n in range(0, n):
    print(f"{matrix_C[cnt_n][0]}", end="")
    
    for cnt_l in range(1, l):
        print(f" {matrix_C[cnt_n][cnt_l]}", end="")

    print()



Measured memory_bytes: 7084
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int a,b,k,f,t;

	cin>>a>>b>>k;
    
    if(a<=k)
    {
     k=k-a;
     a=0;
     b=b-k;
       if(b<0)
         {
             b=0;
         }
     cout<<a<<" "<<b;
    }
    else if(a>k)
    {
    a=a-k;
    cout<<a<<" "<<b;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int M;

template<class T> class Matrix
{
 public:
    vector<vector<T>> A;
    Matrix(int n):A(n,vector<T>(n)){}
    Matrix(int n,int m):A(n,vector<T>(m)){}

    vector<T>& operator[](int i){ return A[i]; }
    int height(){ return A.size(); }
    int width(){ return A[0].size(); }
    static Matrix I(int n){
        Matrix mat(n);
        for(int i=0;i<n;i++) mat[i][i]=1;
        return mat;
    }
    Matrix& operator*=(Matrix& B){
        int H=height(), W=B.width(), K=width();
        vector<vector<T>> C(H,vector<T>(W));
        for(int i=0;i<H;i++) for(int j=0;j<W;j++)
            for(int k=0;k<K;k++) C[i][j]+=A[i][k]*B[k][j],C[i][j]%=M;
        A.swap(C);
        return *this;
    }
    Matrix operator*(Matrix& B){ return Matrix(*this)*=B; }
    Matrix pow(int K){
        Matrix res=Matrix::I(height());
        Matrix B=*this;
        while(K>0){
            if(K&1) res*=B; B*=B; K>>=1;
        }
        return res;
    }
};

void solve()
{
    int N,A,B,C,T; cin>>N>>M>>A>>B>>C>>T;
    if(N==0) exit(0);
    Matrix<int> a(N);
    for(int i=0;i<N;i++){
        if(i-1>=0) a[i][i-1]=A;
        a[i][i]=B;
        if(i+1<N) a[i][i+1]=C;
    }
    a=a.pow(T);
    Matrix<int> b(N,1);
    for(int i=0;i<N;i++){
        cin>>b[i][0];
    }
    a*=b;
    for(int i=0;i<N;i++){
        cout<<a[i][0]<<(i==N-1? '\n':' ');   
    }
}
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    while(true){
        solve();
    }
}


Measured memory_bytes: 3116
#include <iostream>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a%3==0 || b%3==0 || (a+b)%3==0)
	{
		cout<<"Possible"<<endl;
	}
	else
	{
		cout<<"Impossible"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

int n,m,q;
int a[50],b[50],c[50],d[50];

int calc(vector<int>v){
    int ret=0;
    rep(i,q){
        if(v[b[i]]-v[a[i]]==c[i]) ret+=d[i];
    }
    return ret;
}
int dfs(vector<int> &v){
    if(v.size()==n){
        return calc(v);
    }
    int ans=0;
    int prev=v.empty()?1:v.back();
    for(int i=prev;i<=m;i++){
        v.pb(i);
        chmax(ans,dfs(v));
        v.pop_back();
    }
    return ans;
}
signed main(){
    cin >> n >> m >> q;
    rep(i,q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--; b[i]--;
    }
    vector<int> v;
    cout << dfs(v) << endl;
}


Measured memory_bytes: 3624
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    char[]s = S.toCharArray();
 
        int purasu=0;   
        for(int i=0; i<4; i++){
            if(s[i]=='+'){
                purasu++;               
            }
}
        int mainasu = 4-purasu;
        
    System.out.println(purasu-mainasu);
      }
}


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

#define pb push_back
#define mp make_pair
#define ll long long int
#define all(x) x.begin(), x.end()

void solve() {

    int n, m;
    cin >> n >> m;
    int start, end;
    // range of ID cards
    // init
    start = 1;
    end = n;

    for (size_t i = 0; i < m; i++)
    {
        int x, y;
        cin >> x >> y;

        start = max(start, x);
        end = min(end, y);

        // cout << "start: " << start << " end: " << end << "\n"; 

        if(start > end) {
            cout << 0 << "\n";
            return;
        }
    }

    cout << end - start + 1 << "\n";
    

}

int main() {
    ios_base::sync_with_stdio(false);

    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG 

int main(){
    string s;
    cin>>s;
    int n=s.size();
    ll ans=0;
    for(int bit=0; bit<(1<<n-1);bit++){
        ll count=s[0]-'0';
        rep(i,n-1){
            if(bit&(1<<i)) {
                ans+=count;
                count=s[i+1]-'0';
            }
            else{
                count*=10;
                count+=s[i+1]-'0';
            }
        }
        ans+=count;
    }
    cout<<ans<<endl;

}

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

char S[10010];

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

	cin >> N >> S;
	for(int i = 0; S[i]; i++) cout << (char)((S[i] - 'A' + N) % 26 + 'A');
	return 0;
}


Measured memory_bytes: 256
import random

def down_score(d, c, last_d, score):
    sum = 0
    for i in range(26):
        sum += c[i]*(d-last_d[i])
        
    return (score - sum)

def main():
    D = int(input())

    c = list(map(int, input().split()))

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

    #print(c)

    #print(s)

    last_d = [0 for i in range(26)]
    
    ans = []
    
    score = 0
    
    for i in range(D):
        max = 0
        idx = 0
        for j in range(26):
            if max < (s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2) and c[j] != 0:
                max = s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2
                idx = j
            elif max == (s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2) and c[j] * (i-last_d[j])*(i-last_d[j]+1)/2 > c[idx]* (i-last_d[idx])*(i-last_d[idx]+1)/2:
                idx = j
            elif max == (s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2) and c[j] * (i-last_d[j])*(i-last_d[j]+1)/2 == c[idx]* (i-last_d[idx])*(i-last_d[idx]+1)/2:
                x = random.random()
                if x < 0.5:
                    idx = j
        last_d[idx] = i+1
        score += s[i][j]
        down_score(i+1,c,last_d,score)
        
        ans.append(idx)

    for i in range(D):
        print(ans[i]+1)

if __name__ == "__main__":
    main()

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

int main() {
  
  int N;
  

  cin >> N;

  vector <int>vec(N);

  for( int i = 0; i<N;i++){
    cin >> vec.at(i);
  }

  string res = "APPROVED";
  
  for( int i = 0; i<N;i++){
    if(vec.at(i)%2 == 0){
      if(vec.at(i) %3 == 0 || vec.at(i) % 5 == 0){
         //OK  
      }
      else{
        res = "DENIED";
        break;
      }
    }
  }
  cout << res << endl;
}






Measured memory_bytes: 256
import sys
import math

def input():
    return sys.stdin.readline()[:-1]

def main():
    N, A, B = map(int,input().split())
    X = sorted(list(map(int,input().split())))
    Y = [0 for k in range(N)]
    for k in range(1,N):
        Y[k-1] = X[k] - X[k-1]
    Y = sorted(Y)
    ans = 0
    for e in Y:
        ans += min(e*A,B)
    print(ans)

if __name__ == '__main__':
    main()


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

ll pow5(ll x) {
    return x*x*x*x*x;
}

int main() 
{
    ll x; cin >> x;
    for (ll a = -200; a <= 200; a++) {
        for (ll b = -200; b <= 200; b++) {
            if (pow5(a) - pow5(b) == x) {
                cout << a << ' ' << b << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3592
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] arg) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.valueOf(scanner.nextLine());
        ArrayList<String> stringList = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            stringList.add(scanner.nextLine());
        }
        ArrayList<String> commonList = new ArrayList<String>(Arrays.asList(stringList.get(0).split("")));

        for (int i = 1; i < n; i++) {
            StringBuffer sb = new StringBuffer(stringList.get(i));
            for (int j = 0; j < commonList.size(); j++) {
                String s = commonList.get(j);
                if (sb.indexOf(s) > -1) {
                    sb.deleteCharAt(sb.indexOf(s));
                } else {
                    commonList.remove(j);
                    j--;
                }
            }
        }

        String[] commonArray = commonList.toArray(new String[commonList.size()]);
        Arrays.sort(commonArray);

        StringBuffer ans = new StringBuffer();
        for (String s : commonArray) ans.append(s);
        System.out.println(ans.toString());
    }
}


Measured memory_bytes: 22996
#include<cstdio>
using namespace std;
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1,j=m+1;i<j;i++,j--)
		printf("%d %d\n",i,j);
	for(int i=m+2,j=2*m+1;i<j;i++,j--)
		printf("%d %d\n",i,j);
	return 0;
}

Measured memory_bytes: 1692