akhauriyash/Code-Regression huggingface dataset:
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::BTreeMap;

fn main() {
    input!(a: usize, b: usize, c: usize, d: usize);
    let total = b;
    let c_mlt = total / c;
    let d_mlt = total / d;
    let cd_mlt = total / (c / gcd(c, d) * d);
    let ans1 = total - (c_mlt + d_mlt - cd_mlt);

    let left = a;
    let c_mlt_l = a / c;
    let d_mlt_l = a / d;
    let cd_mlt_l = left / (c / gcd(c, d) * d);
    let ans2 = left - (c_mlt_l + d_mlt_l - cd_mlt_l);
    if a % c == 0  || a % d == 0 {
        println!("{}", ans1 - ans2);
    } else {
        println!("{}", ans1 + 1 - ans2);
    }
}

pub fn gcd<T>(x: T, y: T) -> T
where
    T: PartialEq + Copy + std::ops::Rem<Output = T> + std::convert::From<u8>,
{
    if y == T::from(0u8) {
        x
    } else {
        gcd(y, x % y)
    }
}


Measured memory_bytes: 4352
N = int(input())
S = input()
tmp = S[-1]
index = 0
ans = ''
cnt1 = 0
cnt2 = 0
for i in range(N):
    if S[i] == '(':
        cnt1 += 1
    elif cnt1 == 0:
        cnt2 += 1
    else:
        cnt1 -= 1

print('(' * cnt2 + S + ')' * cnt1)

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

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1)/b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }

int nmax=200000; // 2*(10^5)
vvec g(nmax);



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n;
    cin>>n;
    int memo;
    rep(i,100000){
        if(i*(i+1)/2>=n){
            memo=i;
            break;
        }
    }
    for(int i=memo;i>=1;i--){
        if(n>=i){
            n-=i;
            cout<<i<<endl;
        }
    }
}

Measured memory_bytes: 4992
#include <stdio.h>
#define N 101
#define WHITE 0
#define GRAY 1
#define BLACK 2

// 隣接行列
int M[N][N];

int color[N], d[N], f[N], tt;
int n, u, v, k;

// 再帰関数による深さ優先探索
void dfs_visit(int u) {
  color[u] = GRAY;
  d[u] = ++tt;  // 最初の訪問
  for (int i = 1; i <= n; i++) {
    if (M[u][i] == 0) continue;
    if (color[i] == WHITE) {
      dfs_visit(i);
    }
  }
  color[u] = BLACK;
  f[u] = ++tt;  // 訪問完了
}

void dfs() {

  // 初期化
  for (int i = 1; i <= n; i++) {
    color[i] = WHITE;
  }
  tt = 0;

  for (int i = 1; i <=n; i++) {
    if (color[i] == WHITE) {
      dfs_visit(i);
    }
  }

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

int main() {
  scanf("%d", &n);

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      M[i][j] = 0;
    }
  }

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

  dfs();

  return 0;
}



Measured memory_bytes: 2108
P = []
S = []
for i in range(2):
    pp, ss  = map(int, input().split())
    P.append(pp)
    S.append(ss)

A = P[0]
V = S[0]
B = P[1]
W = S[1]
T = int(input())

def run():
	if A < B:
		c = (B + W*T) - (A + V*T)
		if c <= 0 :
			return 'YES'
		else :
			return 'NO'
	elif A > B:
		c =  (A - V*T) - (B - W*T)
		if c <= 0 :
			return 'YES'
		else :
			return 'NO'
	else :
		return 'YES'
print(run())

Measured memory_bytes: 9224
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>

int main() {
    long long n;

    std::cin >> n;

    std::vector<long long> a(n), b(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i] >> b[i];
    }

    long long ans = 0;
    for (int i = n - 1; i >= 0; i--) {
        ans += (b[i] - (a[i] + ans) % b[i]) % b[i];
    }

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

Measured memory_bytes: 1792
n=int(input())
l=list(map(int,input().split()))
dp=[0]*n
dp[1]=abs(l[1]-l[0])
for i in range(2,n):
    dp[i]=min(dp[i-2]+abs(l[i]-l[i-2]),dp[i-1]+abs(l[i]-l[i-1]))
print(dp[-1])


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

int main(){
	int N;
	cin >> N;
	vector <long> A(N);
	for(int i = 0; i < N; i++) cin >> A.at(i);
	sort(A.begin(), A.end());
	reverse(A.begin(), A.end());
	long edge1 = 0, edge2 = 0;
	long tmp1 = 0, tmp2 = 0;
	for(int i = 0; i < N; i++){
		if(!edge1 && tmp1 != A.at(i)) tmp1 = A.at(i);
		else if(!edge1) edge1 = A.at(i);
		else if(!edge2 && tmp2 != A.at(i)) tmp2 = A.at(i);
		else if(!edge2) edge2 = A.at(i);
		if(edge1 && edge2) break;
	}
	long long ans = edge1 * edge2;
	cout << fixed;
	cout << setprecision(20) << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001001001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

int main()
{
    ll n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        --a[i];
    }
    ll after_min = 0;
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            if (a[i] > a[j])
            {
                ++after_min;
            }
        }
    }
    ans = (after_min * k) % MOD;
    vector<int> nums(2000);
    for (auto num : a)
    {
        ++nums[num];
    }
    reverse(nums.begin(), nums.end());
    ll cnt = 0;
    ll mins = 0;
    for (int i = 0; i < 2000; i++)
    {
        mins = (mins + nums[i] * cnt) % MOD;
        cnt += nums[i];
    }
    ll sig = (k * (k - 1) / 2) % MOD;
    ans = (ans + (mins * sig) % MOD) % MOD;
    cout << ans << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
};

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

int main() {
  vector<int> v;
  for(int i=0; i<10; i++) {
    int x;
    cin >> x;
    v.push_back(x);
  }
  sort(v.begin(),v.end(), greater<int>());
  for(int i=0; i<3; i++)
    cout << v[i] << endl;
}

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

max_index=-1
max_number=-1
second_number=-1
max_count=0
i=0
while(i<N):
    a=int(input())
    if(max_number<a):
        second_number=max_number
        
        max_number=a
        max_index=i
        max_count=0
    elif(max_number==a):
        max_count+=1
        max_index=-1
    elif(second_number<a):
        second_number=a
    i+=1

j=0
while(j<N):
    if(j==max_index and max_count==0):
        print(second_number)
    else:
        print(max_number)
    j+=1

Measured memory_bytes: 55640
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
    int a  , b, c;
    cin >> a >> b >> c;
    if (a<=c&&c<=b) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    //cout << ans << endl;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

main :: IO ()
main = do
    [a, b] <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    putStrLn $ if any (\x -> x `mod` 3 == 0) [a, b, a + b] then "Possible" else "Impossible"


Measured memory_bytes: 380
n,m = map(int,input().split())
lis1 = []
lis2 = []
ans = "IMPOSSIBLE"
for i in range(m):
    a,b = map(int,input().split())
    if a == 1:
        lis1.append(b)
    else:
        lis2.append((a,b))
lis2 = set(lis2)        
for j in lis1:
    if (j,n) in lis2:
        ans = "POSSIBLE"
    else:
        pass

print(ans)

Measured memory_bytes: 42288
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list=new ArrayList<String>(Arrays.asList(s.split("")));
		List<Integer> list=new ArrayList<Integer>();
		//int[] array = new int[1000000000*2];
		int n = sc.nextInt();
		for(int i=0;n>i;i++) {
			int a = sc.nextInt();
			list.add(a);
		}

		double answer=1000000000;
		for(int i=0;100>i;i++) {
			double count=0;
			for(int j=0;list.size()>j;j++) {
				count=count+Math.pow(i-list.get(j), 2);
			}
			if(count<=answer)
				answer=count;
		}
		System.out.println((int)answer);
	}
}

Measured memory_bytes: 23508
import java.util.Scanner;

public class Main implements Runnable {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Thread(null, new Main(), "", 128 * 1024 * 1024).start();
    }

    public void run() {
        int n = sc.nextInt();
        long sum = 0;
        for (int i = 0; i < n; i++) {
            sum += sc.nextLong() - 1;
        }
        System.out.println(sum);
    }
}


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

int main(){
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    reverse(a.begin(), a.end());
    for (int i = 0; i < n-1; i++){
        cout << a[i] << " ";
    }
    cout << a[n-1] << endl;
} 


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int CASES = 3;

void solve() {
    ll N; cin >> N;
    vector<ll> a(N);
    ll sum = 0;
    for(int i = 0; i < N; ++i){
        cin >> a[i];
        sum ^= a[i];
    }
    for (int i = 0; i < N; ++i) {
        cout << (sum ^ a[i]);
        if(i == N - 1) cout << endl;
        else cout << " ";
    }
}

int main() {
#ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt", "input5.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
#else

    solve();

#endif
    return 0;
}


Measured memory_bytes: 4844
#include <bits/stdc++.h>
#define i_love_u_Phuong ios_base::sync_with_stdio(0); cin.tie(0);
using ll = long long;
using namespace std;
using ld = long double;
const int MAXN=1e5+5;
vector<int> fen(MAXN,0);
string s;

int main()
{
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
#endif // ONLINE_JUDGE
    i_love_u_Phuong;
    int n,q;
    cin >> n >> q;
    cin >> s;
    vector<int> dp(n+1,0);
    for(int i=0; i<n-1; ++i)
    {
        if (s[i+1]=='C' && s[i]=='A') dp[i]++;
        if (i>0) dp[i]+=dp[i-1];
    }
    dp[n-1]=dp[n-2];
  	vector<int> res;
    while(q--)
    {
        int u,v;
        cin >> u >> v;
        u--;
        v--;
        int ans=dp[v];
        if (s[v]=='A' && dp[v]-dp[v-1]==1) ans--;
        if (u==0) res.push_back(ans); else
        res.push_back(ans-dp[u-1]);
    }
  	for(auto x:res) cout << x << '\n';
    return 0;
}



Measured memory_bytes: 2248
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

int X,Y;

int main(){
    cin>>X>>Y;

    int ans=X+Y/2;

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int W, H, N; cin >> W >> H >> N;
  int H1 = 0, H2 = H, W1 = 0, W2 = W;
  for(int i = 0; i < N; i++) {
    int x, y, z; cin >> x >> y >> z;
    if(z == 1) W1 = max(x, W1);
    else if(z == 2) W2 = min(W2, x);
    else if(z == 3) H1 = max(y, H1);
    else H2 = min(y, H2);
  }
  int count = 0;
  for(int i = W1; i < W2; i++) {
    for(int j = H1; j < H2; j++) {
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

N = int(input())

w = [input() for i in range(3)]

c = 0

for i in range(N):
    if w[0][i]!=w[1][i]:
        c += 1
    
    if (w[0][i]!=w[2][i]) and (w[1][i]!=w[2][i]):
        c += 1

print(c)



Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	double x=0,y=0,rad=M_PI/2;
	int a,b;
	while(1){
		cin>>a;
		cin.ignore();
		cin>>b;
		if(!a&&!b)break;
		x += a*cos(rad);
		y += a*sin(rad);
		rad -= b*M_PI/180;
	}
	cout<<(int)x<<endl<<(int)y<<endl;
	return 0;
}

Measured memory_bytes: 1164
#include <stdio.h>

int main(){
	int hills[10], top[3], i, j, tmp;
	for (i = 0;i < 10;i++)scanf("%d", &hills[i]);
	
	for (i = 1;i < 10;i++){
		tmp = hills[i];
		for (j = i;j > 0 && hills[j - 1] < tmp;j--)
			hills[j] = hills[j - 1];
		hills[j] = tmp;
	}
	
	for (i = 0;i < 3;i++) printf("%d\n", hills[i]);
	
	return 0;
}

Measured memory_bytes: 600
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define PP(p) cout<<(p)<<" ";
#define pb push_back
#define mp make_pair
#define INF 1e18

typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef pair<int, int> pi;
//int dy[8]={1,1,1,0,-1,-1,-1,0};
//int dx[8]={-1,0,1,1,1,0,-1,-1};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};

int N,M;
int a,b;
int X;
int p[100];

void input(){
    cin>>X>>N;
    rep(i,N)cin>>p[i];
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    int d = INF;
    int ans=X;
    for(int i=-1;i<=101;i++){
        int tmp=d;
        rep(j,N){
            if(i==p[j])goto e;
        }

        d=min(d,abs(X-i));
        if(tmp!=d){
         ans=i;
        }
        e:;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
  int n, l;
  cin >> n >> l;
  int minn, maxn, ans=0;
  for (int i=0; i<n; i++) {
    if (i==0) minn=l;
    if (i==n-1) maxn=l;
    ans+=l;
    l++;
  }
  if (0<minn) cout << ans-minn << endl;
  else if (maxn<0) cout << ans-maxn << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"
#define mod	1000000007
ll fac_mod(ll n){
	ll res=1;
	for(ll i=2 ; i<=n ; i++){
		res = (res*i)%mod;
		}
	return res%mod;
	}
int main()
{
	ll n,ans;
	cin>>n;
	ans = fac_mod(n);
	cout<<ans<<nw;
	
	return 0;
}

Measured memory_bytes: 256
sub f{my$p=$h[my$c=$c[$_]-=my$r=$s=$v[++$_]=1];$v[$_--]or$a[$c]-=-$s*(-$s+($s=($r+=&f)-$h[$c]+$p))for@$_;$a[$c]+=$s*(@a-($h[$c]+=$s))+1;$r}@a=(0)x<>;@c=glob<>;map{push@$_,$z[--$|]for@z=split}<>;f;print"@a"

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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  int i;
  for(i = 0; i < n; i++)
  {
    cin >> a.at(i);
    a.at(i) *= 2;
  }
  vector<long long> f(n);
  long long sum = 0;
  for(i = 0; i < n; i++)
  {
    if(i%2==0)sum += a.at(i);
    else sum-= a.at(i);
  }
  f.at(0) = sum/2;
  for(i = 0; i < n-1; i++)
  {
    f.at(i+1) = a.at(i)-f.at(i);
  }
  for(i = 0; i < n; i++)
  {
    if(i == 0)cout << f.at(0);
    else cout << " " << f.at(i);
  }
  cout << endl;
}

Measured memory_bytes: 2432
implicit none
integer :: a,b,c,d

read*,a,b,c,d

if( abs(c-a)<=d )then
  print*,'Yes'
  stop
end if

if( abs(b-c)<=d .and. abs(b-a)<=d )then
  print*,'Yes'
  stop
end if
print*,'No'
end

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

int main()
{
    long long n, a[200000], ans = 0;
    cin >> n;
    for (int in = 0; in < n; in++)
        cin >> a[in];
    sort(a, a + n);

    for (int i = 1; i < n; i++)
    {
        ans += a[n - (i / 2) - 1];
    }

    cout << ans << endl;
}

Measured memory_bytes: 5196
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int h, w;
  cin >> h >> w;
  int c[10][10];
  for(int i = 0; i < 10; i++) {
    for(int j = 0; j < 10; j++) {
      cin >> c[i][j];
    }
  }
  for(int k = 0; k < 10; k++) {
    for(int i = 0; i < 10; i++) {
      for(int j = 0; j < 10; j++) {
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
      }
    }
  }

  ll ans = 0;
  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++) {
      int a;
      cin >> a;
      if(a != -1) {
        ans += c[a][1];
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>  // std::sort, std::unique
using namespace std; 

int main() {
    int n,m;
    int i,j;
    int line,linesum=0;
    cin >> n >> m;
    vector<vector<int>> a(n,vector<int>(m));
    vector<int> row(m,0);
    for ( i = 0; i < n; i++)
    {
        line = 0;
        for ( j = 0; j < m; j++)
        {
            cin >> a[i][j];
            line += a[i][j];
            row[j] += a[i][j];
        } 
        linesum += line;
        a[i].push_back(line);
    }
    row.push_back(linesum);
    a.push_back(row);
    for ( i = 0; i < n+1; i++)
    {
        for ( j = 0; j < m+1; j++)
        {
            cout << a[i][j];
            if(j < m) cout << " ";
        }
        cout << endl;
        
    }
    
    return 0;
}


Measured memory_bytes: 3180
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;
using TextReader = System.IO.TextReader;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var N = consoleReader.Int;
            return Math.Pow(N, 3);
        }


        #region いつもの
        private readonly ConsoleReader consoleReader;
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program(new ConsoleReader(Console.In)).Calc()); static string AllLines<T>(IEnumerable<T> source) => string.Join("\n", source);
        #endregion
    }
#pragma warning disable
    public class ConsoleReader
    {
        private string[] ReadLineSplit() => textReader.ReadLine().Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries);
        private string[] line = Array.Empty<string>();
        private int linePosition;
        private TextReader textReader;
        public ConsoleReader(TextReader tr) { textReader = tr; }
        public int Int => int.Parse(String);
        public long Long => long.Parse(String);
        public double Double => double.Parse(String);
        public string String
        {
            get
            {
                if (linePosition >= line.Length)
                {
                    linePosition = 0;
                    line = ReadLineSplit();
                }
                return line[linePosition++];
            }
        }
        public class SplitLine
        {
            private string[] splited;
            public SplitLine(ConsoleReader cr) { splited = cr.ReadLineSplit(); cr.line = Array.Empty<string>(); }
            public int[] Int => String.Select(x => int.Parse(x)).ToArray();
            public int[] Int0 => String.Select(x => int.Parse(x) - 1).ToArray();
            public long[] Long => String.Select(x => long.Parse(x)).ToArray();
            public double[] Double => String.Select(x => double.Parse(x)).ToArray();
            public string[] String => splited;
        }
        public SplitLine Split => new SplitLine(this);
        public class RepeatReader : IEnumerable<ConsoleReader>
        {
            ConsoleReader cr; int count;
            public RepeatReader(ConsoleReader cr, int count) { this.cr = cr; this.count = count; }
            public IEnumerator<ConsoleReader> GetEnumerator() => Enumerable.Repeat(cr, count).GetEnumerator();
            System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator();

            public IEnumerable<string> String => this.Select(cr => cr.String);
            public IEnumerable<int> Int => this.Select(cr => cr.Int);
            public IEnumerable<int> Int0 => this.Select(cr => cr.Int - 1);
            public IEnumerable<long> Long => this.Select(cr => cr.Long);
            public IEnumerable<double> Double => this.Select(cr => cr.Double);
        }
        public RepeatReader Repeat(int count) => new RepeatReader(this, count);
    }
}

Measured memory_bytes: 13140
#include<stdio.h>
#include<string.h>
#include<stdlib.h>


typedef struct dlobj{
  int key;
  struct dlobj *next;
  struct dlobj *prev;
}dlobj;


typedef struct dlist{
  dlobj *head;
  dlobj *tail;
  int size;
}dlist;


dlist *mk_dlist(){
  dlist *p;
  p=malloc(sizeof(dlist));
  p->head=NULL;
  p->tail=NULL;
  p->size=0;
  return p;
}


void insert(dlist *L,int x){
  dlobj *p;
  p=malloc(sizeof(dlobj));
  p->key=x;
  p->next=L->head;
  if(L->head!=NULL) L->head->prev=p;
  else L->tail=p;
  L->head=p;
  p->prev=NULL;
}

void delete(dlist *L,int x){
  dlobj *p;
  p=L->head;
  while(p!=NULL){
    if(p->key==x){
      if(p->next!=NULL) p->next->prev=p->prev;
      else L->tail=p->prev;
      if(p->prev!=NULL) p->prev->next=p->next;
      else L->head=p->next;
      break;
    }
    p=p->next;
  }
}

void delete_f(dlist *L){
  if(L->head!=NULL){
    if(L->head->next==NULL) L->tail=NULL;
    L->head=L->head->next;
    if(L->head!=NULL) L->head->prev=NULL;
  }
}

void delete_l(dlist *L){
  if(L->tail!=NULL){
    if(L->tail->prev==NULL) L->head=NULL;
    L->tail=L->tail->prev;
    if(L->tail!=NULL) L->tail->next=NULL;
  }
}



int main(){
  int i;
  int n;
  char c[13];
  int x;
  dlist *L;
  L=mk_dlist();
  
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%*[\n]%s",c);
    if(c[0]=='i'){
      scanf("%*[^1-9]%d",&x);
      insert(L,x);
    }
    else if(c[6]=='F') delete_f(L);
    else if(c[6]=='L') delete_l(L);
    else{
      scanf("%*[^1-9]%d",&x);
      delete(L,x);
    }
  }
  

  dlobj *p;
  p=L->head;
  if(p!=NULL){
    printf("%d",p->key);
    p=p->next;
  }
  while(p!=NULL){
    printf(" %d",p->key);
    p=p->next;
  }
  printf("\n");
  return 0;
}
      
    



Measured memory_bytes: 36064
// ABC102B - Maximum Difference

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

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

	sort(A.begin(), A.end());

	cout << A[N - 1] - A[0] << endl;

	return 0;
}


Measured memory_bytes: 384
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
 
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  1000000007
const int N = 200005;
#define FAST ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);srand(time(NULL));
ll d, x, y;
void extendedEuclid(ll A, ll B) {
    if(B == 0) {
        d = A;
        x = 1;
        y = 0;
    }
    else {
        extendedEuclid(B, A%B);
        ll temp = x;
        x = y;
        y = temp - (A/B)*y;
    }
}
ll modInverse(ll A)
{
    extendedEuclid(A,MOD);
    return (x%MOD+MOD)%MOD;   
}
ll fact[N],inv[N];
void solve()
{
	ll n,k;
	cin >> n >> k;
	fact[0] = inv[0] = 1;
	for(ll i=1;i<N;i++)
	{
		fact[i] = (fact[i-1] * i) %MOD;
		inv[i] = modInverse(fact[i]);
	}
	ll ans = 0;
	k = min(k,n-1);

	for(ll i=k;i>=0;i--)
	{
		ll temp = (fact[n] * inv[n-i])%MOD;
		temp = (temp * inv[i])%MOD;
		ll temp1 = (fact[n-1] * inv[n-i-1])%MOD;
		temp1 = (temp1 * inv[i])%MOD;
		ans = (ans + (temp1*temp)%MOD)%MOD;
	}
	cout<<ans;
}

int32_t  main()
{
    FAST;
    ll t = 1;
    //  cin >> t;
    while(t--)
    {
    	solve();
    }
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define lp(i, n) for (int i = 0; i < (n) ; ++i)
#define sz(v) (ll)(v).size()
#define int long long
#define mod 1000000007

void solve() {
        lp(i, 5) {
                int x; cin >> x;
                if (!x) cout << i+ 1<< "\n";
        }
}

int32_t main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        int t = 1;
        //cin >> t;
        lp(i, t) {
                solve();
        }
return 0;
}


Measured memory_bytes: 3608
s = input()
l = len(s)
K = int(input())
def com(x,y):
    child = 1
    mother = 1
    for i in range(y):
        child = child * (x-i)
        mother = mother * (i+1)
    if x == 1 and y >=2:
        return 0
    else:    
        return int(child / mother)
tasumae = (9**K)*com(l-1,K) #与えられた数字よりも一桁少ない999999999・・・までの個数
li = list(s)
doko = []
if l < K:
    print(0)
    exit()
if K == 1:
    print(tasumae+int(li[0]))
    exit()
for i in range(1,l):
    if li[i] != "0":
        doko.append(i)
if K == 2:
    if not doko:
        print(tasumae)
        exit()
    ans = int(li[doko[0]]) + 9*(l-1-doko[0]) + tasumae + (int(li[0])-1)*com(l-1,1)*9
    print(ans)
    exit()
if len(doko) == 0:
    print(tasumae)
    exit()
if len(doko) == 1:
    ans = (int(li[0])-1)*com(l-1,2)*(9**2) + (int(li[doko[0]])-1) * 9 * (l-1-doko[0]) + com(l-1-doko[0],2)*(9**2) + tasumae
    print(ans)
    exit()
ans = (int(li[0])-1)*com(l-1,2)*(9**2) + (int(li[doko[0]])-1) * 9 * (l-1-doko[0]) + int(li[doko[1]]) + 9*(l-1-doko[1]) + com(l-1-doko[0],2)*(9**2) + tasumae
print(ans)

Measured memory_bytes: 3188
a,b,c = gets.split.map(&:to_s)
while true do
  break if b == "?"
  if b == "+"
    puts a.to_i + c.to_i
  elsif b == "-"
    puts a.to_i - c.to_i
  elsif b == "*"
    puts a.to_i * c.to_i
  else
    puts a.to_i / c.to_i
  end
  a,b,c = gets.split.map(&:to_s)
end



Measured memory_bytes: 6860
#include<stdio.h>
#include<cstdlib>
#include<cmath>

typedef struct {
    double x;
    double y;
}P;

int koch(int, P, P);

int main(){
    int n;
    P p1 = {0,0}, p2 = {100,0};
    scanf("%d",&n);
    
    printf("%.8lf %.8lf\n",p1.x, p1.y);
    koch(n, p1, p2);
    printf("%.8lf %.8lf\n",p2.x, p2.y);
    
    return 0;
}



int koch(int n, P p1, P p2){
    P s, t, u;
    if(n == 0) return 0;
    
    s.x = (2*p1.x + 1*p2.x) / 3;
    s.y = (2*p1.y + 1*p2.y) / 3;
    t.x = (1*p1.x + 2*p2.x) / 3;
    t.y = (1*p1.y + 2*p2.y) / 3;
    
    u.x = (t.x - s.x) * cos(M_PI/3) - (t.y - s.y) * sin(M_PI/3) + s.x;
    u.y = (t.x - s.x) * sin(M_PI/3) + (t.y - s.y) * cos(M_PI/3) + s.y;
    
    koch(n-1, p1, s);
    printf("%.8lf %.8lf\n",s.x, s.y);
    koch(n-1, s, u);
    printf("%.8lf %.8lf\n",u.x, u.y);
    koch(n-1, u, t);
    printf("%.8lf %.8lf\n",t.x, t.y);
    koch(n-1, t, p2);
    
    return 1;
}




Measured memory_bytes: 2680
#include<stdio.h>
int main(void)
{
	int n,t,a,h,w,j,i;
	w=0;
	while(1){
	scanf("%d",&n);
	if(n==0) break;
	scanf("%d",&t);
	for(i=0;i<t;i++){
	scanf("%d %d",&a,&h);
	w+=h-a;
	}
	if(w>=n){
		printf("OK\n");
		}
	else{
		j=n-w;
		printf("%d\n",j);
		}
	w=0;
	}
	return 0;
}	

Measured memory_bytes: 1040
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define reps(i, n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define repi(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
ll f(ll x){
    if(x==-1) return 0;
    int y=x%4;
    if(y==0) return x;
    if(y==1) return 1;
    if(y==2) return 1^x;
    else return 0;
}
int main(){
    ll a,b;
    cin>>a>>b;
    cout<<(f(b)^f(a-1))<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//const ll INF = 1LL << 60;
//const int INF = 1001001001;

int main(void){
    int n;
    cin >> n;
    int a[n];
    REP(i,n) cin >> a[i];
    int ans=0,cnt=1;
    REP(i,n){
        if(cnt==a[i])cnt++;
        else ans++;
    }
    if(ans==n) ans=-1;
    cout << ans;

    return 0;
}

Measured memory_bytes: 4412
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long; 
using ld = long double;
#define endl "\n"
//#define int long long
#define all(V) V.begin(),V.end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
const int MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const int inf = 1 << 25;
constexpr long double pi = 3.141592653589793238462643383279;
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll fact_mod(ll n, ll mod) {
    ll f = 1; for (int i = 2; i <= n; i++) f = f * (i % mod) % mod;
    return f;
}
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}
ll keta(ll n) {
    if (n == 0) return 1;
    ll count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {
    ll sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
ll mch(ll n) {
    if (n == 1) return 1;
    else return n * mch(n - 1);
}
ll pow_mod(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = (res * x) % mod; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % mod;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}
ll inv_mod(ll a, ll mod) { //逆元
    ll b = mod, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod;
    if (u < 0) u += mod;
    return u;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }
    return true;
}

//宣言とか

/*signed*/int main(void) {
    string s; cin >> s;
    if (s == "hi" || s == "hihi" || s == "hihihi" || s == "hihihihi" || s == "hihihihihi") cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3624
N = gets.to_i
D = gets.chomp.split(" ").map(&:to_i)

cD = []
D.each{|s|
  if cD[s].nil? then
    cD[s] = 1
  else
    cD[s] += 1
  end
}

ans = 1
if D[0] != 0 then
  ans = 0
elsif  cD[0] > 1 then
  ans = 0
else
  for i in 1...cD.length do
    if cD[i].nil? then
      ans = 0
      break
    else
      ans *= cD[i-1] ** cD[i]
    end
  end
end

p ans.modulo(998244353)


Measured memory_bytes: 47728
#include<bits/stdc++.h>
#include <iostream>
#include <numeric>
#include <math.h>
#define ll long long 
#define ull long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll,ll>
#define dd long long
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;++i)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld",&x)
#define clr(x,val) memset(x,val,sizeof(x))
#define pr(x) printf("%lld\n",x) 
#define gc getchar
#define pdd pair<dd,dd>
#define prec(x) cout<<fixed<<setprecision(x)
#define fre freopen("input.txt","r",stdin),freopen("output.txt","w",stdout)
using namespace std;


int main(){
   //boost;
   ll v=0;
   string s;
   cin>>s;
   ll n=s.size();
   for(ll i=0;i<n;i++){
   	  v=v+(s[i]-'0');
   }
   if(v%9)cout<<"No";
   else cout<<"Yes";
}

    


Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pll pair<ll,ll>
#define sll set<ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define vpl vector<pll>
#define gll greater<ll>
#define spl set<pll>
#define prq priority_queue
#define mp make_pair
#define pb push_back
#define rapido ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long int ll;
typedef long double ld;
ll mx=INT_MAX;
ll mn=INT_MIN;
ll mod=1e9+7;
const ll maxs=1e6+6;
ll max2d=1e3+3;
ll INF = 9e18;

int main(){
    rapido;
    ll n;
    cin>>n;
    vll GCD;
    for(ll i=1; i<=n; i++)
        for(ll j=1; j<=n; j++)
            GCD.pb(__gcd(i,j));
    ll sum = 0;
    for(auto it : GCD)
        for(ll i=1; i<=n; i++)
            sum += __gcd(it , i);
    cout<<sum<<"\n";
    return 0;
}

Measured memory_bytes: 3896
#pragma GCC optimize "trapv"
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define ld long double
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define repp(i,a,n) for(int i=a;i<n;i++)
#define all(v) v.begin(),v.end()
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
int main()
{
    fio;
    int t=1;
    //cin>>t;
    while(t--)
    {
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        ll x=a*c;
        ll y=b*c;
        ll z=a*d;
        ll w=b*d;
        cout<<max(x,max(y,max(z,w)))<<endl;
    }
}

Measured memory_bytes: 3636
from sys import stdin
input = stdin.readline

def main():
    N, K = map(int, input().rstrip().split())
    P = list(map(int, input().rstrip().split()))
    P = list(map(lambda x: x -1, P))
    C = list(map(int, input().rstrip().split()))
    ans = -10**18
    for i in range(N):
        x = i
        s = []
        total = 0
        while(True):
            x = P[x]
            s.append(C[x])
            total += C[x]
            if x == i:
                break
        l = len(s)
        t = 0
        for j in range(l):
            t += s[j]
            if j + 1 > K:
                break
            now = t
            if total > 0:
                e = (K - j - 1) // l
                now += total * e
            ans = max(ans, now)
    print(ans)

if __name__ == "__main__":
    main()
    


Measured memory_bytes: 84384
#include <iostream>
#include <algorithm>
#include <queue>
#define f first
#define s second
#define INF (1e9)
#define N 7
using namespace std;
typedef pair<int,int> P;
int bfs(int,int,int,int,int,int);
bool check(int,int,int,int,int,int);
int w,h,data[N][N],d[N][N],cnt[N][N];
int dy[4]={-1,0,1,0};
int dx[4]={0,1,0,-1};
typedef struct data{
  int cy,cx,wy,wx;
} dat;

int main(){
  int sy,sx,gy,gx,wy,wx,ans;
  while(1){
    cin>>w>>h;
    if(!w&&!h) break;
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++){
	cin >> data[i][j];
	if(data[i][j]==2) sy=i,sx=j;
	else if(data[i][j]==3) gy=i,gx=j;
	else if(data[i][j]==4) wy=i,wx=j;
	d[i][j]=INF;
      }
    ans=bfs(sy,sx,wy,wx,gy,gx);
    cout << ans << endl;
  }
  return 0;
}

int bfs(int sy,int sx,int wy,int wx,int gy,int gx){
  queue<dat > q;
  int flag;
  dat k={sy,sx,wy,wx};
  q.push(k);
  d[sy][sx]=0;
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++) cnt[i][j]=0;
  while(!q.empty()){
    dat u=q.front();
    q.pop();
    flag=0;
    for(int i=0;i<4;i++){
      int ny=u.cy+dy[i],nx=u.cx+dx[i];
      if(ny<0||nx<0||h<=ny||w<=nx||data[ny][nx]==1) continue;
      if(check(u.wy,u.wx,u.cy-dy[i],u.cx-dx[i],u.cy,u.cx)){
	d[ny][nx]=d[u.cy][u.cx]+1;
	cnt[nx][ny]++;
	if(cnt[nx][ny]==10000){
	  flag=1;
	  break;
	}
	if(d[gy][gx]!=INF){
	  flag=2;
	  break;
	}
	dat t={ny,nx,u.cy-dy[i],u.cx-dx[i]};
	q.push(t);
      }
    }
    if(flag) break;
  }
  if(flag==2) return d[gy][gx];
  if(flag) return -1;
  if(d[gy][gx]!=INF) return d[gy][gx];
  return -1;
}

bool check(int sy,int sx,int gy,int gx,int xy,int xx){
  if(gy<0||gx<0||h<=gy||w<=gx) return false;
  if(data[gy][gx]==1) return false;
  bool c[N][N];
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++) c[i][j]=false;
  queue<P > q;
  q.push(make_pair(sy,sx));
  c[sy][sx]=true;
  while(!q.empty()){
    P u=q.front();
    q.pop();
    for(int i=0;i<4;i++){
      int ny=u.f+dy[i],nx=u.s+dx[i];
      if(ny<0||nx<0||h<=ny||w<=nx||data[ny][nx]==1||(ny==xy&&nx==xx)) continue;
      if(c[ny][nx]==true) continue;
      c[ny][nx]=true;
      q.push(make_pair(ny,nx));
    }
  }
  if(c[gy][gx]==true) return true;
  return false;
}

Measured memory_bytes: 1356
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(){
  int i, j, num, top = 0;
  char s[200][6];
  int a[100];
  
  for(i = 0;(scanf("%s", s[i])) != EOF;i++)
    {
      if(s[i][0] == '+')
	{
	  top--;
	  a[top-1] = a[top-1] + a[top];
	}
      else if(s[i][0] == '-')
	{
	  top--;
	  a[top-1] = a[top-1] - a[top];
	}
      else if(s[i][0] == '*')
	{
	  top--;
	  a[top-1] = a[top-1] * a[top];
	}
      else
	{
	  a[top] = atoi(s[i]);
	  top++;
	}
    }
  printf("%d\n", a[top-1]);
      
  return 0;
}




Measured memory_bytes: 2096
# tempt
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np
MOD = 998244353

N = int(readline())
D = np.array(read().split(),np.int32)

if D[0] != 0:
    print(0)
    exit()

counter = np.bincount(D,minlength=N)

if counter[0] != 1:
    print(0)
    exit()

arr = counter[D[1:] - 1]

def cumprod(arr,MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
    for n in range(1,Lsq):
        arr[n] *= arr[n-1,-1]; arr[n] %= MOD
    return arr.ravel()[:L]

answer = cumprod(arr,MOD)[-1]
print(answer)

Measured memory_bytes: 18432
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		int N = sc.nextInt();

		int[] V = new int[N];
		int[] C = new int[N];

		for (int i = 0; i < C.length; i++) {
			C[i] = sc.nextInt();
		}

		for (int i = 0; i < V.length; i++) {
			V[i] = sc.nextInt();
		}

		int max = 0;
		for (int i = 0; i < (1<<N); i++) {
			int Xsum = 0;
			int Ysum = 0;
			for (int j = 0; j < N; j++) {
				if (((i>>j) & 1)==1) {
					//合致
					Xsum += C[j];
					Ysum += V[j];
				}
			}
			if (Xsum-Ysum >= max) {
				max = Xsum-Ysum;
			}
		}

		System.out.println(max);

		sc.close();
	}

}


Measured memory_bytes: 27160
#include <iostream>
#include <math.h>

using namespace std;

int main () {
    long long n;
    cin >> n;
    for (long long i = (long long) sqrt(n) + 1; i > 0; i--) {
        if (n % i == 0) {
            cout << (i + n / i - 2) << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(x) for x in input().split()]

cou = 1 
high = [a[0]]

for i in range(n-1):
    mmhigh = max(high)
    aa = a[i + 1]
    
    if mmhigh <= aa:
        high.append(aa)
        cou += 1
    else:
        pass
      
print(cou)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string>
#include<queue>

using namespace std;

bool pairCompare(const pair<int,int> fe, const pair<int,int> se){
  return (fe.first < se.first);
}
// bool lbCompare(const pair<int,int> fe, const pair<int,int> se){
//   return (fe.first < se.first);
// }

int main(){
  int n, m;
  cin >> n >> m;
  vector< pair<int, int> > ab[100001];
  auto c = [](pair<int, int> a, pair<int, int> b){ return a.second < b.second;};
  priority_queue<pair<int, int>, vector<pair<int, int> > ,  decltype(c) > q(c);
  for(int i = 0; i < n ; i++){
    int a, b;
    cin >> a >> b;
    ab[a].push_back(make_pair(a, b));
  }

  long long ans = 0;

  for(int i = 1; i <= m ; i++){
    for(int j = 0; j < ab[i].size() ; j++) q.push(ab[i][j]);
    if(q.empty()) continue;
    ans += q.top().second;
    q.pop();
    // vector< pair<int, int> >::iterator it1 = lower_bound(ab.begin(), ab.end(), make_pair(i, 0) , lbCompare);
    //
    // if(it1 == ab.end()) continue;
    // ans += ab[(it1-ab.begin())].second;
    // cout << ab[(it1-ab.begin())].first << " " << ab[(it1-ab.begin())].second << endl;
    // ab.erase(it1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 5632
fun solve(ABC: List<Int>) {
    val abc = ABC.distinct()
    if (abc.count() == 2) {
        println("Yes")
    } else {
        println("No")
    }
}

fun main() {
//    val S = readLine()!!
//    val N = readLine()!!.toInt()
//    val (N, M) = readLine()!!.split(" ").map { it.toInt() }
    val ABC = readLine()!!.split(" ").map { it.toInt() }
    solve(ABC)
}

Measured memory_bytes: 36496
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <functional>
#include <cmath>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

int main()
{
    ll n;
    cin >> n;
    n--;
    string res = "";
    while (true)
    {
        char c = (n % 26) + 'a';
        n = n / 26;
        res = c + res;
        if (n == 0)
        {
            break;
        }
        else
        {
            n--;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 3120
const main = (input) => {
  const args = input.trim().split("\n");
  const [N, K] = args[0]
    .trim()
    .split(" ")
    .map((n) => parseInt(n, 10));

  const byAsc = (a, b) => a - b;
  const [...p] = args[1]
    .trim()
    .split(" ")
    .map((n) => parseInt(n, 10))
    .sort(byAsc);

  const bySum = (a, c) => a + c;
  const sum = p.filter((_, i) => i < K).reduce(bySum);

  console.log(sum);
};

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29808
#include<iostream>
#include<string>

int main() {
	std::string s;
	std::cin >> s;
	
	if (s == "RRR") std::cout << 3 << std::endl;
	if (s == "RRS") std::cout << 2 << std::endl;
	if (s == "RSR") std::cout << 1 << std::endl;
	if (s == "SRR") std::cout << 2 << std::endl;
	if (s == "RSS") std::cout << 1 << std::endl;
	if (s == "SRS") std::cout << 1 << std::endl;
	if (s == "SSR") std::cout << 1 << std::endl;
	if (s == "SSS") std::cout << 0 << std::endl;
	
	return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll n;
  cin >> n;
  ll x=0;
  ll i=n;
  while(n!=x){
    if(i*(i-1)/2<(n-x)){
      x +=i;
      cout << i << endl;
    }
    i--;
  }
}

Measured memory_bytes: 256