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

ll dp[3000][3000][4], ans = 0;

int r, c, k, v[3000][3000];

int main() {
	cin >> r >> c >> k;
	for (int i = 0; i < k; ++i) {
		int x, y, z;
		cin >> x >> y >> z;
		v[x - 1][y - 1] = z;
	}

	for (int i = 0; i < r; ++i)
		for (int l = 0; l < 4; ++l)
			for (int j = 0; j < c; ++j) {
				if (j + 1 < c)
					dp[i][j + 1][l] = max(dp[i][j + 1][l], dp[i][j][l]);
				if (i + 1 < r)
					dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][l]);

				if (v[i][j] && l < 3) {
					if (j + 1 < c)
						dp[i][j + 1][l + 1] = max(dp[i][j + 1][l + 1],
								dp[i][j][l] + v[i][j]);
					if (i + 1 < r)
						dp[i + 1][j][0] = max(dp[i + 1][j][0],
								dp[i][j][l] + v[i][j]);
				}
			}

	for (int l = 0; l < 3; ++l) {
		ans = max(ans, dp[r - 1][c - 1][l] + v[r - 1][c - 1]);

	}

	ans = max(ans, dp[r - 1][c - 1][3]);

	cout << ans << endl;

}


Measured memory_bytes: 319920
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int mod=1e9+7;
const int INF =LONG_LONG_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    vector<bool>dp(k+1,0);
    for(int i=0;i<=k;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(i>=a[j]&&dp[i-a[j]]==false)
                dp[i]=true;
        }

    }
   if(dp[k])
    cout<<"First";
   else cout<<"Second";
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
long long n,i,j,a,b,c,d,x,ans,sum;
char s[200005];
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	x=n;
	while(x>=1){
		if(s[x]=='A'){
			ans+=sum;
			x--;
		}
		else if(s[x]=='C'&&s[x-1]=='B'){
			sum++;
			x-=2;
		}
		else{
			sum=0;
			x--;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include <cassert>
    #include <cmath>
    #include<cstdint>

    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<int,int>;

    int main(){
       ll n,m;cin>>n>>m;
       vector<ll> div;
       for(int i=1;i*i<=m;i++){
           if(m%i==0){
               div.push_back(i);
               if(i != m/i)div.push_back(m/i);
           }
       }
       ll mx = 0;
       m = m/n;
       for(auto d : div){
           if(d>m)continue;
           mx = max(d,mx);
       }
       cout<<mx;
    }
    


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int main() {

  int n;
  cin >> n;
  vec1 l(n);
  for(int i = 0; i < n; i++) {
    cin >> l.at(i);
  }

  sort(l.begin(), l.end());
  reverse(l.begin(), l.end());
  int tmp = 0;
  for(int i = 1; i < n; i++) {
    tmp = tmp + l.at(i);
  }
  if(l.at(0) < tmp) {
    cout << "Yes" << endl;
    return 0;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
	
   Scanner sc = new Scanner(System.in);
   
     String S = sc.next();
     if(S.equals("Sunny")) {
     System.out.println("Cloudy");
   }else if(S.equals("Cloudy")) {
	   System.out.println("Rainy");
   }else {
	   System.out.println("Sunny");
   }
}
}

Measured memory_bytes: 22228
import Control.Monad (replicateM)

main :: IO ()
main = do
  [n, m, c] <- fmap (map (read :: String -> Int) . words) $ getLine
  bs <- fmap (map (read :: String -> Int) . words) $ getLine
  ass <- fmap (map (map (read :: String -> Int) . words)) $ getNLine_ n
  print $ (length . filter (> 0) . map ((+ c) . sum . zipWith (*) bs)) ass
 
-- 複数行入力
getNLine_ :: Int -> IO [String]
getNLine_ n = replicateM n getLine

Measured memory_bytes: 1020
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AizuRangeSumQuery solver = new AizuRangeSumQuery();
        solver.solve(1, in, out);
        out.close();
    }

    static class AizuRangeSumQuery {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int q = in.nextInt();

            int[] a = new int[n];
            int[] b = new int[4 * n];

            build(0, 0, n - 1, a, b);

            while (q-- != 0) {
                int o = in.nextInt();
                int l = in.nextInt() - 1;
                int r = in.nextInt() - 1;

                if (o == 0) {
                    update(0, 0, n - 1, l, r + 1, a, b);
                } else {
                    out.printf("%d\n", query(0, 0, n - 1, l, r, b));
                }
            }
        }

        private void build(int n, int s, int e, int[] a, int[] b) {
            if (s == e) {
                b[n] = a[s];
            } else {
                int m = (s + e) / 2;
                build(2 * n + 1, s, m, a, b);
                build(2 * n + 2, m + 1, e, a, b);

                b[n] = b[2 * n + 1] + b[2 * n + 2];
            }
        }

        private void update(int n, int s, int e, int idx, int val, int[] a, int[] b) {
            if (s == e) {
                a[idx] += val;
                b[n] += val;
            } else {
                int m = (s + e) / 2;
                if (s <= idx && idx <= m) {
                    update(2 * n + 1, s, m, idx, val, a, b);
                } else {
                    update(2 * n + 2, m + 1, e, idx, val, a, b);
                }

                b[n] = b[2 * n + 1] + b[2 * n + 2];
            }
        }

        private long query(int n, int s, int e, int l, int r, int[] b) {
            if (r < s || e < l) {
                return 0;
            } else if (l <= s && e <= r) {
                return b[n];
            } else {
                int m = (s + e) / 2;
                long s1 = query(2 * n + 1, s, m, l, r, b);
                long s2 = query(2 * n + 2, m + 1, e, l, r, b);

                return s1 + s2;
            }
        }

    }
}




Measured memory_bytes: 142516
def CountingSort(A, k):
    C = [0] * (k+1)
    n = len(A)
    
    for a in A:
        C[a] = C[a] + 1


    for i in range(1, k+1):
        C[i] = C[i] + C[i-1]

    B = [0] * n
    for a in A:
        rank = C[a]
        B[rank  - 1] = a
        C[a] = C[a] - 1

    return B

n = int(input())
A = [int(i) for i in input().split()]

ans = CountingSort(A, 10000)
print(' '.join([str(i) for i in ans]))

    
        



Measured memory_bytes: 241484
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

struct score{
  ll min = 0;
  ll max = 0;
};

void solve(ll N, ll M){
  ll S, k, c;
  vector<score> score(N + 10);
  for(int i = 0; i < M; i++) {
    scanf("%lld %lld", &S, &k);
    if(k == 1) {
      cin >> c;
      score[c].min += S;
      score[c].max += S;
    } else {
      for(int i = 0; i < k; i++){
	scanf("%lld", &c);
	score[c].max += S;
      }
    }
  }
  
  ll ans = 0;
  for(int i = 1; i <= N; i++){
    for(int j = 1; j <= N; j++){
      if(i == j) continue;
      ans = max(ans, score[i].max - score[j].min + 1);
    }
  }
  printf("%lld\n", ans);
}

int main(){
  int N, M;
  while(scanf("%d %d", &N, &M)) {
    if(N == 0 && M == 0) break;
    solve(N, M);
  }
  return 0;
}



Measured memory_bytes: 3320
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll n;
  cin >> n;

  ll ans = (n * (n - 1)) / 2;

  cout << ans << ln;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
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;
}

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main(){
    ll X; cin >> X;
    bool stop = true;
    while(stop){
        if(IsPrime(X)){
            cout << X << endl;
            stop = false;
            break;
        }
        X += 1;
    }
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use std::iter::*;

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);


    let x1: f64 = sc.read();
    let y1: f64 = sc.read();
    let x2: f64 = sc.read();
    let y2: f64 = sc.read();
    println!("{:.09}", (x1 - x2).hypot(y1 - y2));
}



Measured memory_bytes: 5156
fun main(args: Array<String>) = println(run {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    val a = readLine()!!.split(" ").map { it.toInt() }

    val min = (a.sum()/(4.0*m))
    if (a.filter { it.toDouble() >= min }.count() >= m) "Yes" else "No"
})

Measured memory_bytes: 37600
A=input()
N=len(A)
D={}
for i in range(N):
    a=A[i]
    if a in D:
        D[a]+=1
    else:
        D[a]=1

#print(D)
ans=N*(N-1)//2
for v in D.values():
    ans-=v*(v-1)//2

print(ans+1)

Measured memory_bytes: 3500
import { createInterface } from 'readline';

const main = (lines: string[]) => {
  console.log(solve(lines));
};

export const solve = (lines: string[]): string => {
  const { A, B } = parseLines(lines);

  const N1: number[] = [];
  for (let i = 1; i < 1001; i++) {
    if (Math.floor(i * 0.08) === A) {
      N1.push(i);
    }
  }

  const N2: number[] = [];
  for (let i = 1; i < 1001; i++) {
    if (Math.floor(i * 0.1) === B) {
      N2.push(i);
    }
  }

  const N = N1.find(n1 => N2.findIndex(n2 => n1 === n2) !== -1);

  return (N || -1).toString();
};

const parseLines = (lines: string[]) => {
  const [A, B] = lines[0].split(' ').map(e => +e);
  const obj = { A, B };
  debug(obj);
  return obj;
};

const debug = (message?: any, ...optionalParams: any[]) => {
  if (!!process.env.LOCAL_DEBUG) {
    console.log(message, ...optionalParams);
  }
};

if (!process.env.LOCAL_DEBUG) {
  const { stdin: input, stdout: output } = process;
  input.resume();
  input.setEncoding('utf8');
  const lines: string[] = [];
  createInterface({ input, output })
    .on('line', line => lines.push(line))
    .on('close', () => main(lines));
}


Measured memory_bytes: 7756
#include <stdio.h>
int a,b=2000,c;

int main(void){
	for(;c<3;++c)scanf("%d",&a),b=(a<b)?a:b;
	scanf("%d%d",&a,&c),a=(a<c)?a:c;
	printf("%d\n",a+b-50);
	return 0;
}

Measured memory_bytes: 592
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <set>
#include <functional>
#include <cmath>
#include <set>
#include <map>


//マクロ
#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 RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
#define All(a) (a).begin(),(a).end()
#define RAll(a) (a).rbegin(),(a).rend()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF 1e9
#define INFL 1e18
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
using Graph = vector<vector<int>>;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数
vector<ll> ans = vector<ll>(2001, 0);

//使用する関数
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;
}

ll dfs(int n) {
	if (ans[n] != 0)return ans[n];
	FOR(i, 3, n - 2) {
		ans[n] += dfs(n - i);
		ans[n] %= MOD;
	}
	ans[n] += 1;
	return ans[n];
}

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

	int s;
	cin >> s;

	if (s < 3) {
		cout << "0" << endl;
		return 0;
	}

	ans[0] = 0;
	ans[1] = 0;
	ans[2] = 0;
	ans[3] = 1;
	ans[4] = 1;
	ans[5] = 1;

	cout << dfs(s) << endl;
}

Measured memory_bytes: 3684
#include <stdio.h>
#include <string.h>
int main(void){
    // Your code here!
    char s[100000], t[100000], u[100000];
    int n, i;
    
    scanf("%d",&n);
    scanf("%s",s);
    
    for(i=0;i<n/2;i++){
        t[i]=s[i];
        t[i+n/2]=t[i];
    }
    if(strcmp(s,t)==0) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n + 1];
        int[] b = new int[n];
        long counter = 0;
        for (int i = 0; i < n + 1; i++) {
            a[i] = sc.nextInt();
            counter += a[i];
        }
        for (int i = 0; i < n; i++) {
            b[i] = sc.nextInt();
        }
        sc.close();

        // 倒す処理
        for (int i = 0; i < n; i++) {
            if (a[i] >= b[i]) {
                a[i] -= b[i];
            } else {
                a[i + 1] = Math.max(0, a[i + 1] - (b[i] - a[i]));
                a[i] = 0;
            }
        }

        // 回答
        long ans = counter;
        for (int i = 0; i < n + 1; i++) {
            ans -= a[i];
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 64800
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    string s;
    cin >> s;
    int g=0,p=0;
    for(int i=0;i<s.size();i++){
        if(s[i] == 'g') g++;
        else p++;
    }
    int n = s.size();
    cout << n/2-p << endl;
}

Measured memory_bytes: 512
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using LayoutKind = System.Runtime.InteropServices.LayoutKind;
using static Reader;

public static class P
{
    static int col;
    static List<Edge>[] graph;
    public static void Main()
    {
        int n = NextInt;
        graph = Enumerable.Repeat(0, n).Select(_ => new List<Edge>()).ToArray();
        List<Edge> edges = new List<Edge>();
        for (int i = 0; i < n - 1; i++)
        {
            var edge = new Edge() { From = NextInt - 1, To = NextInt - 1 };
            graph[edge.To].Add(edge);
            graph[edge.From].Add(edge);
            edges.Add(edge);
        }
        col = graph.Max(x => x.Count);
        Console.WriteLine(col);

        dfs(0, int.MaxValue, -1);
        Console.WriteLine(string.Join("\n", edges.Select(x => x.Color)));
    }

    static void dfs(int node, int from, int fromColor)
    {
        int color = 1;
        for (int i = 0; i < graph[node].Count; i++)
        {
            var edge = graph[node][i];
            var to = edge.From ^ edge.To ^ node;
            if (to == from) continue;
            if (color == fromColor) color++;
            edge.Color = color;
            dfs(to, node, color);
            color++;
        }
    }
}

class Edge
{
    public int From;
    public int To;
    public int Color;
}


static class Reader
{
    const int BUF_SIZE = 1 << 12;
    static Stream Stream = Console.OpenStandardInput();
    static byte[] Buffer = new byte[BUF_SIZE];
    static int ptr = 0;
    static void Move() { if (++ptr >= Buffer.Length) { Stream.Read(Buffer, 0, BUF_SIZE); ptr = 0; } }


    public static int NextInt
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        get
        {
            int res = 0; while (Buffer[ptr] < 48) Move();
            do { res = res * 10 + (int)(Buffer[ptr] ^ 48); Move(); } while (48 <= Buffer[ptr]);
            return res;
        }
    }
}


Measured memory_bytes: 39580
#![allow(unused_imports)]
#![allow(dead_code)]

use std::thread;
use std::io::{ self, Read };
use std::fmt;
use std::iter::Iterator;
use std::cmp::*;
use std::collections::*;
use std::str::*;

#[derive(Default)]
struct Input {
    buf: Vec<String>
}

impl Input {
    fn new() -> Input {
        Input { buf: Vec::new() }
    }

    fn read<T: FromStr>(&mut self) -> T 
    where <T as FromStr>::Err: fmt::Debug {
        self.next().unwrap().parse::<T>().unwrap()
    }

    fn read_bytes(&mut self) -> Vec<u8> {
        self.next().unwrap().into_bytes()
    }

    fn read_n<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where <T as FromStr>::Err: fmt::Debug {
        let mut v = Vec::new();
        for _ in 0..n { v.push(self.read::<T>()); }
        v
    }
}

impl Iterator for Input {
    type Item = String;
    fn next(&mut self) -> Option<String> {
        while self.buf.is_empty() {
            let mut s = String::new();
            let _res = io::stdin().read_line(&mut s);
            self.buf = s.split_whitespace().map(|s| s.to_owned()).collect::<Vec<_>>();
            self.buf.reverse();
        }
        self.buf.pop()
    }
}

struct UnionFind {
    c: Vec<(usize, usize)>
}

impl UnionFind {
    fn new(n: usize) -> UnionFind {
        UnionFind { c: (0..n).map(|u| (u, 1)).collect::<Vec<_>>() }
    }

    fn root(&self, u: usize) -> usize {
        let v = self.c[u].0;
        if u == v { u } else { self.root(v) }
    }

    fn is_same(&self, u: usize, v: usize) -> bool {
        self.root(u) == self.root(v)
    }

    fn size(&self, u: usize) -> usize {
        self.c[u].1
    }

    fn unite(&mut self, u: usize, v: usize) {
        let ru = self.root(u);
        let rv = self.root(v);
        let su = self.size(ru);
        let sv = self.size(rv);
        if su > sv {
            self.c[rv].0 = ru;
            self.c[ru].1 = su + sv;
        } else {
            self.c[ru].0 = rv;
            self.c[rv].1 = su + sv;
        }
    }
}

fn run() {
    let mut ip = Input::new();
    let n = ip.read::<usize>();
    let m = ip.read::<usize>();
    let mut p = ip.read_n::<usize>(n);
    p.insert(0, 0);
    let mut uf = UnionFind::new(n + 1);
    for _ in 0..m {
        let u = ip.read::<usize>();
        let v = ip.read::<usize>();
        uf.unite(u, v);
    }
    let mut s = 0;
    for u in 1..n + 1 {
        if uf.is_same(u, p[u]) {
            s += 1;
        }
    }
    println!("{}", s);
}

fn main() {
    let _ = thread::Builder::new()
        .stack_size(10 * 1024 * 1024)
        .spawn(run).unwrap()
        .join();
}

Measured memory_bytes: 14588
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	int now=abs(a-b);
	if(now%2)printf("Borys\n");
	else printf("Alice\n");
	return 0;
}

Measured memory_bytes: 384
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
cd = [list(map(int, input().split())) for _ in range(m)]
for i in range(n):
    num = 0
    ans = float('inf')
    for j in range(m):
        man = abs(ab[i][0]-cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if man < ans :
            ans = man
            num = j
    print(num+1)

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> people(N);
  for(int i = 0; i < N; i++){
    cin >> people.at(i);
  }
  long long min = 1000000000;
  for(int i = 0; i < 100; i++){
    long long sum = 0;
    for(int j = 0; j < N; j++){
      sum += (people.at(j) - i) * (people.at(j) - i);
    }
    if(min >= sum){
      min = sum;
    }
  }
  cout << min <<endl;
}


Measured memory_bytes: 256
import java.io.BufferedInputStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        //System.setIn(Main.class.getResourceAsStream("input"));
        Scanner sc = new Scanner(new BufferedInputStream(System.in));
        int n = sc.nextInt();
        int m = sc.nextInt();
        int v = sc.nextInt();
        int p = sc.nextInt();
        sc.nextLine();
        int[] a = toArray(sc.nextLine());
        Arrays.sort(a);
        int barrier = a[n-p];
        int result = 0;
        for (int i = n-1-p; i >= 0; i--) {
            boolean isCandidate;
            if(a[i]+m < barrier) break;

            else if(v <= i + p && a[i]+m >= barrier) {
                isCandidate = true;
            }

            else {
                int remainder = v - i - p;
                int concurrent = n - i - p;
                // 10 4 7
                long total = ((long)remainder)*m;
                for (int j = 0; j < concurrent; j++) {
                    total -= (a[i]+m-a[j+i+1]);
                    if(total <= 0) break;
                }
                isCandidate = (total <= 0);
            }
            if(isCandidate) result++;
            else break;
        }
        System.out.println(result+p);
    }

    private static int[] toArray(String text) {
        return Arrays.stream(text.split("\\s")).mapToInt(Integer::valueOf).toArray();
    }

}

Measured memory_bytes: 49256
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;
    const int mod = 1000000007;

    // long long dp[n+10][2][2] = {};
    vector<vector<vector<ll>>> dp(n+1, vector<vector<ll>>(2, vector<ll>(2, 0)));
    dp[0][0][0] = 8;
    dp[0][0][1] = 1;
    dp[0][1][0] = 1;
    dp[0][1][1] = 0;

    for(int i = 1; i < n+1; ++i){
        dp[i][0][0] = (dp[i-1][0][0] * 8) % mod;
        dp[i][0][1] = ((dp[i-1][0][1] * 9) % mod + dp[i-1][0][0]) % mod;
        dp[i][1][0] = ((dp[i-1][1][0] * 9) % mod + dp[i-1][0][0]) % mod;
        dp[i][1][1] = ((dp[i-1][1][1] * 10) % mod + dp[i-1][0][1]%mod + dp[i-1][1][0]%mod) % mod;
    }

    cout << (dp[n-1][1][1]) % mod << endl;

    return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

typedef pair<int, int> pii;

int main() {
	int h, w;
	
	while (cin >> h >> w, h || w) {
		string str[100];
		REP(i, h) cin >> str[i];
		
		int ans = 0;
		REP(i, h) REP(j, w) {
			if (str[i][j] != '.') {
				ans++;
				
				queue<pii> q;
				q.push(pii(j, i));
				
				while (!q.empty()) {
					int x = q.front().first, y = q.front().second;
					q.pop();
					if (str[y][x] == '.') continue;
					
					int dx[4] = {1,0,-1,0};
					int dy[4] = {0,1,0,-1};
					REP(k, 4) {
						int nx = x + dx[k], ny = y + dy[k];
						if (!(nx >= 0 && nx < w && ny >= 0 && ny < h)) continue;
						if (str[y][x] != str[ny][nx]) continue;
						q.push(pii(nx, ny));
					}
					str[y][x] = '.';
				}
				
			}
		}
		
		cout << ans << endl;
	}
	return 0;
}

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

int main() {
  ll N;
  cin >> N;
  vector<pair<ll, ll>> A(N);
  for (auto &p : A) cin >> p.first >> p.second;
  
  ll count = 0;
  for (ll i = N-1; i >= 0; i--) {
    ll by = (A[i].first + count) % A[i].second;
    if (by != 0) by = A[i].second -by;
    count += by;
  }
  
  cout << count << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000001
#define INFL 1000000000000000001
string s;
int ans=1;
int main(void){
	cin>>s;
	int n=s.size();
	int p=0;
	while(p<n-1){
		if(s[p]!=s[p+1])p++,ans++;
		else{
			if(p+1==n-1)p++;
			else if(p+1==n-2)p+=2,ans++;
			else p+=3,ans+=2;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	char S[5];
	scanf("%s", S);

	int i, flag = 0;
	for (i = 1; i < 4; i++)
		if (S[i] == S[i - 1])
			flag = 1;
	puts(flag ? "Bad" : "Good");
	return 0;
}


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

string s;
int li[4];

int main(){
	cin >> s;
	for(int i=0;i<s.size();i++){
		li[s[i]-'a']++;
	}
	sort(li,li+3);
	if(li[2] - li[0] <= 1) printf("YES\n");
	else printf("NO\n");
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <map>
using namespace std;
int main()
{
  int N;
  cin >> N;
  int A, B;
  map<int, int> mp;
  for (int i = 0; i < N; i++)
  {
    cin >> A >> B;
    mp[A] = B;
  }
  int count = 0;
  long ans = 0;
  for (auto a : mp)
  {
    if (count == N - 1)
      ans += a.first + a.second;
    count++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define AfterDecimal(n) cout << fixed << setprecision(n);
#define pb push_back
#define pp(a, b) pair <a, b>
#define ll long long int
#define ld long double
#define all(a) a.begin(), a.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
#define itr iterator
#define bits(x) __builtin_popcount(x)
#define fori(n)  for (ll i = 0; i < n; i++)
#define forj(n)  for (ll j = 0; j < n; j++)
#define fork(n)  for (ll k = 0; k < n; k++)
#define vll vector <ll>
#define mll map <ll, ll>
#define vpll vector <pll>
 
 
using namespace __gnu_pbds;
using namespace std;
 
template <class T> T printr(T p){ cout << p << '\n'; return 0; }
template <class T> T printe(T p){ cout << p << '\n'; exit(0); }
template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
 
 
//template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef tree<int, null_type, less<int>, rb_tree_tag,  
            tree_order_statistics_node_update>  
    ordered_set;  
 
#ifdef LOCAL
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << "# "<< name << " = " << arg1 << '\n';
}
template<typename Arg1, typename... Args>
void __f(const char* names, Arg1 && arg1, Args &&... args){
        const char* comma = strchr(names + 1 ,',');
        cout << "# ";
        cout.write(names, comma - names)<< " = " << arg1 << " | ";
        __f(comma + 1, args...);
}
#else
#define debug(...) 36
#endif
 
ll power(ll x, ll y, ll p){ 
   ll res = 1;
   x = x % p;  
   while (y > 0) {
      if (y & 1) 
         res = (res * x) % p; 
      y = y >> 1;
      x = (x * x) % p; 
   }
   return res;
}
 
const ll INF = (ll)(8e18);
const ll MOD = (ll)(1e9 + 7);
const ll HMOD = (ll)4222234727;
const ll hashprime = (ll)31;
 
const int maxn = 200010;

vector <ll> h;

int32_t main(){
    IOS;
    #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    ll k,n; cin >> n >> k;
    for(int i = 1; i <= n; i++){
        ll x; cin >> x;
        h.push_back(x);
    }
    sort(all(h));
    reverse(all(h));
    ll ans = 0;
    for(int i = min(k, n); i < n; i++) ans += h[i];
    cout << ans << '\n';
    #ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}


Measured memory_bytes: 2420
def inpl():
    return list(map(int, input().split()))


N = int(input())
H = inpl()
H[0] -= 1
for i in range(1, N):
    if H[i] > H[i - 1]:
        H[i] -= 1
    elif H[i] == H[i - 1]:
        continue
    else:
        print("No")
        exit()

print("Yes")


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

int main(){
	string s;
	int a, b;
	
	cin >> a >> b;
	cin >> s;
	
	for (int i=0; i<s.size(); i++){
		if (i==a){
		   if (s[i]!='-'){
		      cout<< "No";
		      return 0;
		   }
		}
		else if (!isdigit(s[i])) {
		   cout << "No";
		   return 0;
	    }
	} 
	
	cout << "Yes";
	return 0;
}


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

using namespace std;

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;

constexpr int MAXS = 100;

char S[MAXS + 2];
char keyence[] = "keyence";

int main() {
	cin >> S;
	int mS = strlen(S), pref = 0, suf = 1;
	while(S[pref] == keyence[pref])
		pref++;
	while(suf <= 7 && suf <= mS && S[mS - suf] == keyence[7 - suf])
		suf++;
	suf--;
	if(pref + suf >= 7)
		goto yes;
	for(int i = 0; i + 7 <= mS; i++) {
		for(int j = 0; j < 7; j++)
			if(S[i + j] != keyence[j])
				goto no;
		goto yes;
no:;
	}
	cout << "NO" << endl;
	return 0;
yes:
	cout << "YES" << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)
import math

def main():
    a, b, x = map(int, input().split())
    k = x / (a ** 2)
    if 2 * k > b:
        tan = 2 * (k - b) / a
        print(abs(math.degrees(math.atan(tan))))
    else:
        tan = (b ** 2) / (2 * a * k)
        print(abs(math.degrees(math.atan(tan))))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;

int main() {
    string s;
    long long cnt=0,w_c=0;
    cin >> s;
    for(int i = 0; i < (int)s.size(); i++)
    {
        if (s[i] == 'W') {
            cnt += i - w_c;
            w_c++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, k;
  int d;
  int a;
  int r[100];
  int ans = 0;
  for(int i = 0;i < 100;i++){
    r[i] = 0;
  }
  cin >> n >> k;
  for(int i = 0;i < k;i++){
    cin >> d;
    for(int j = 0;j < d;j++){
      cin >> a;
      r[a - 1] = 1;
    }
  }
  for(int i = 0;i < n;i++){
    if(r[i] == 0){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A, B;
  cin >> N >> A >> B;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
	cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  int j = 0, k = N - 1;
  while(1) {
	if (a.at(j) > A) {
      break;
    }
    j++;
  }
  while(1) {
	if (a.at(k) < B + 1) {
      break;
    }
    k--;
  }
  cout << min(min(j, k + 1 - j), N - k - 1) << endl;
}

Measured memory_bytes: 256
/*
  author: ruruvuvu
  GitHub account: colon-ku

  created at: 2019-12-16 21:37:08
*/

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

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

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

    int ans;
    if (a <= 5) ans = 0;
    else if (a <= 12) ans = b/2;
    else ans = b;

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


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

void c3() {
	int N;
	cin >> N;
	vector<int> hs[2] {vector<int>(N), vector<int>(N)};
	for (int i = 0; i < N*2; ++i) {
		cin >> hs[i >= N][i % N];
	}
	long long r = 1;
	bool meet = false;
	for (int i = 0; i < N; ++i) {
		bool fail = false;
		if (!meet) {
			if (hs[1][i] >= hs[0][i] && (i == 0 || (hs[0][i] >= hs[0][i-1] && hs[1][i] == hs[1][i-1]))) {
				if (i > 0 && hs[0][i] == hs[0][i-1])
					r = r * hs[0][i] % 1000000007;
			} else
				fail = true;
			// cout << hs[0][i] << ',' << hs[1][i] << endl;
		} else {
			if (hs[0][i] >= hs[1][i] && (hs[0][i] == hs[0][i-1] && hs[1][i] <= hs[1][i-1])) {
				if (i < N - 1 && hs[1][i] == hs[1][i+1])
					r = r * hs[1][i] % 1000000007;
			} else
				fail = true;
			// cout << hs[0][i] << ',' << hs[1][i] << endl;
		}
		if (hs[0][i] == hs[1][i])
			meet = true;
		// cout << r << endl;
		if (fail) {
			cout << 0 << endl;
			return;
		}
	}
	if (!meet)
		cout << 0 << endl;
	else
		cout << r << endl;
}

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


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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    i64 N;
    cin >> N;

    vector<i64> A(N);
    rep(i,0,N) cin >> A[i];

    auto ok=[&](i64 x){
        map<i64,i64> mp;
        rep(i,1,N){
            if(A[i]>A[i-1]) continue;
            if(x==1) return false;
            while(!mp.empty() and mp.rbegin()->first>=A[i]) mp.erase(mp.rbegin()->first);
            i64 p=A[i]-1;
            while(mp.find(p)!=mp.end()){
                ++mp[p];
                if(mp[p]==x){
                    mp.erase(p);
                    --p;
                    if(p==-1) return false;
                    continue;
                }
                p=-1;
                break;
            }
            if(p!=-1) mp[p]=1;
        }

        return true;
    };

    i64 lb=0,ub=inf64;
    while(ub-lb>1){
        i64 mid=(lb+ub)/2;
        if(ok(mid)) ub=mid;
        else lb=mid;
    }

    cout << ub << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 1792
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val K, Q = sc.nextInt
  val Ds = List.fill(K)(sc.nextLong)
  val NXMs = List.fill(Q)((sc.nextInt, sc.nextInt, sc.nextInt))

  NXMs.foreach{case (n, x, m) =>
    val ds = Ds.map{case d => if (d%m == 0) m else d%m}
    val al = x%m + ((n - 1)/K)*ds.sum + ds.take((n - 1)%K).sum
    val ans = n - 1 - al/m
    println(ans)
  }
}

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

int main() {
    string s, t;
    cin>>s>>t;
    int s1 = (int)s.length(), s2 = (int)t.length();
    vector<vector<int>> dp(s1+1, vector<int>(s2+1, -1));
    // vector<vector<pair<int,int>>> parent(s1+1, vector<pair<int,int>>(s2+1));
    dp[0][0] = 0;
    // parent[0][0] = {0, 0};
    for (int i=1; i<=s1; i++) {
        for (int j=1; j<=s2; j++) {
            if (s[i-1]==t[j-1]) {
                dp[i][j] = 1+dp[i-1][j-1];
                // parent[i][j] = {i-1, j-1};
            } else {
                if (dp[i-1][j]>dp[i][j-1]) {
                    // parent[i][j] = {i-1, j};
                    dp[i][j] = dp[i-1][j];
                } else {
                    // parent[i][j] = {i, j-1};
                    dp[i][j] = dp[i][j-1];
                }
            }
        }
    }
    // if (dp[s1][s2]==0) {
    //     printf("\n");
    // } else {
        stack<char> st;
        int ix = s1, iy = s2;
        while (ix>0 && iy>0) {
            if (s[ix-1]==t[iy-1]) {
                st.push(s[ix-1]);
                ix--, iy--;
            } else if (dp[ix][iy-1]>dp[ix-1][iy]) {
                iy--;
            } else {
                ix--;
            }
        }
        while (!st.empty()) {
            printf("%c", st.top());
            st.pop();
        }
        printf("\n");
    // }
}

Measured memory_bytes: 35584
#include<iostream>
#include<cstring>
using namespace std;
const int N=2000005;
int f[N],a[N];
int main()
{
	//freopen("input.txt","r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >>n;
	for(int i=1;i<=n;i++)cin >>a[i];
	//for(int i=1;i<=n;i++)cout <<a[i]<<' ';cout <<endl;
	f[0]=0,f[1]=1==a[1],f[2]=(a[1]==1||a[2]==2)?1:0;
	for(int i=3;i<=n;i++)
	{
		if(a[i]==i)
			f[i]=f[i-2]+1;
		else f[i]=f[i-1];
	}
	cout <<f[n]<<endl;
	//for(int i=1;i<=n;i++)cout <<f[i]<<' ';
	return 0;
}

Measured memory_bytes: 4736
#include<stdio.h>
#define NUM 50

int main(void)
{
  int N,i,j,tmp;
  int num[NUM];
  double ans=0;
  
  scanf("%d",&N);
  
  for(i=0;i<N;i++){
    scanf("%d",&num[i]);
  }
  
  for(i=0;i<N-1;i++){
    for(j=i+1;j<N;j++){
      if(num[i]>num[j]){
        tmp = num[i];
        num[i] = num[j];
        num[j] = tmp;
      }
    }
  }
  
  ans = num[0];
  
  for(i=1;i<N;i++){
    ans = (ans + num[i])/2;
  }
  
  printf("%5.3f",ans);
  
  return 0;
  
}
    

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b,c,d; cin>>a>>b>>c>>d;
	if (a+b>c+d) cout<<"Left\n";
	else if (a+b<c+d) cout<<"Right\n";
	else cout<<"Balanced"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define ll long long
using namespace std;

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

	ll a,b;
	cin >> a >> b;

	ll ans, curr;
	for(ll i=a; i<=b; i++){
		for(ll j=i+1; j<=b; j++){
			curr = ((i%2019)*(j%2019))%2019;
			ans = min(curr, ans);
			if(ans==0){
				cout << 0;
				return 0;
			}
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }


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

  int n;
  cin >> n;
  vector<ll> x(n), y(n);
  rep(i, n) cin >> x[i] >> y[i];
  if(n == 1) {
    cout << 1 << endl;
    return 0;
  }
  vector<pll> pq;
  rep(i, n) {
    rep(j, n) {
      if ((x[i] - x[j]) != 0 || (y[i] - y[j]) != 0)
        pq.push_back(pll(x[i]-x[j], y[i]-y[j]));
    }
  }

  int ans = 60;
  for (auto&& k: pq) {
    ll cnt = 0;
    rep(i, n) {
      rep(j, n) {
        if (x[i] + k.first == x[j] && y[i] + k.second == y[j]) {
          cnt++;
        }
      }
    }
    cmin(ans, n-cnt);
  }
  cout << ans << endl;
}


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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using llu = long long unsigned int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// 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("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &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 (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int N;
    Scd(N);

    vi a(N);
    Rep(i,N) Scd(a[i]);

    const ll LINF =  1e15;
    const ll NINF = -1e15;

    vector<vl> dpv(N+1,vl(N+1,NINF));
    function<ll(int,int)> dp = [&]( int l , int r ){
        if( l+r == N ) return dpv[l][r] = 0LL;
        if( dpv[l][r] != NINF ) return dpv[l][r];
        ll tmp;
        bool jiro = (l+r)%2;
        if( jiro ){
            tmp = LINF;
            tmp = min( dp(l+1,r)-a[  l  ], tmp );
            tmp = min( dp(l,r+1)-a[N-r-1], tmp );
        } else {
            tmp = NINF;
            tmp = max( dp(l+1,r)+a[  l  ], tmp );
            tmp = max( dp(l,r+1)+a[N-r-1], tmp );
        }
        return dpv[l][r] = tmp;
    };

    printf ("%lld\n", dp(0,0) );


    return 0;
}



Measured memory_bytes: 71040
conv_lst = [(1,1,1), (-1,1,1), (1,-1,1), (1,1,-1), (-1,-1,1), (-1,1,-1), (1,-1,-1), (-1,-1,-1)]

def conv_sort(conv_tuple, xs, ys, zs):
  sum_lst = []
  for x, y, z in zip(xs, ys, zs):
    sum_lst.append(x * conv_tuple[0] + y * conv_tuple[1] + z * conv_tuple[2])
  sum_lst = sorted(sum_lst, reverse=-1)
  return sum_lst

n, m = [int(elem) for elem in input().split()]
xs = []
ys = []
zs = []
for i in range(0, n):
  x, y, z = [int(elem) for elem in input().split()]
  xs.append(x)
  ys.append(y)
  zs.append(z)

res_lst = []
for conv_tuple in conv_lst:
  sum_lst = conv_sort(conv_tuple, xs, ys, zs)
  res_lst.append(sum(sum_lst[:m]))
res_lst = sorted(res_lst, reverse=-1)
print(res_lst[0])

Measured memory_bytes: 3188
package main
import (
  "fmt"
  "os"
)
func main() {
  var n int
  fmt.Scan(&n)
  var a [][]int = make([][]int,n)
  for i:=0;i<n;i++ {
    a[i] = make([]int,n)
    for j:=0;j<n;j++ {
      fmt.Scan(&a[i][j])
    }
  }
  var m int64
  for i:=0;i<n-1;i++ {
    for j:=i+1;j<n;j++ {
      var ok bool = true
      for k:=0;k<n;k++ {
        if a[i][k]+a[k][j] < a[i][j] {
          fmt.Println(-1)
          os.Exit(0)
        } else if a[i][k]+a[k][j] == a[i][j] &&
        !(k == i || k == j) {
          ok = false
        }
      }
      if ok { m += int64(a[i][j]) }
    }
  }
  fmt.Println(m)
}

Measured memory_bytes: 6784
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
	cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	cout << head;
	if (sizeof...(tail) != 0) cout << " ";
	print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
	for (auto& a : vec) {
		cout << a;
		if (&a != &vec.back()) cout << " ";
	}
	cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
	for (auto& vec : df) {
		print(vec);
	}
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	auto N = IN();
	vector<i64> A(N + 2, 0);
	i64 total = 0;
	for (i64 i = 1; i <= N; ++i)
	{
		cin >> A[i];
		total += abs(A[i] - A[i - 1]);
	}
	total += abs(A[N]);

	for (i64 i = 1; i <= N; ++i)
	{
		i64 org = abs(A[i + 1] - A[i]) + abs(A[i] - A[i - 1]);
		i64 aft = abs(A[i + 1] - A[i - 1]);
		print(total + (aft - org));
	}
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


Measured memory_bytes: 2176
#!/usr/bin/env python3
import sys

MOD = 998244353  # type: int


def solve(N: int, M: int, K: int):

    ncomb = [0]*N

    ans = 1
    ncomb[0] = 1
    for i in range(1, N):
        ans *= (N- i) * pow(i,MOD-2,MOD)
        ans %= MOD
        ncomb[i] = ans
    
    answer = 0
    for i in range(K+1):
        answer += M*pow(M-1,N-1-i,MOD)*ncomb[i]
        answer %= MOD
    
    print(answer)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, M, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 16800
#include<bits/stdc++.h>
#define ll long long
#define t ll t; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

int main(void){
  fast;
  // Code from here....
  ll n, x, p;
  cin>>n>>x>>p;
  ll ans = ceil(1.0*n/x);
  ans = ans*p;
  cout<<ans;
}

Measured memory_bytes: 3660