akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef pair<double, double> line;
#define point line
#define fi first
#define se second
int n;
double a[50005], b[50005], c[50005];
line l[50005];
bool cmp(line x,line y){
	if (x.fi * y.fi < 0) return x.fi <= 0;
	return x.fi >= y.fi;
}
double resx, resy;
vector <point> lst;
int fw[50005];
int fw_get(int x){
	int res = 0; for(;x;x-=x&-x) res+= fw[x]; return res;
}
void fw_upd(int x){
	for(;x<=n;x+=x&-x) fw[x] ++;
}
double solve(){
	sort(l+1,l+n+1,cmp);
	double L = -1e12, R = 1e12;
	for(int _time=0;_time<100;_time++){
		double divide_line = (L+R)/2;
		lst.clear();
		fill(fw,fw+n+5,0);
		
		for(int i=1;i<=n;i++)
			lst.push_back(point((divide_line - l[i].se) / l[i].fi, i));
		sort(lst.begin(), lst.end());
		
		int cnt = 0;
		// cnt equals !inverse equals intersections
		for(int i=0;i<n;i++)
			cnt += fw_get(lst[i].se),
			fw_upd(lst[i].se);
			
		
		if (cnt < ((n * (n-1) / 2)+1) / 2) 
			L = divide_line;
		else
			R = divide_line;
	}
	return L;
}
int main(){
	iostream::sync_with_stdio(0);
	cin >> n;
	for(int i=1;i<=n;i++)
		cin >> a[i] >> b[i] >> c[i], c[i] = -c[i]; // ax + by + c = 0
	for(int i=1;i<=n;i++)
		l[i].fi = - a[i] / b[i],
		l[i].se = - c[i] / b[i];
	resy = solve();
	for(int i=1;i<=n;i++)
		l[i].fi = - b[i] / a[i],
		l[i].se = - c[i] / a[i];
	resx = solve();
	cout << fixed << setprecision(10) << resx << ' ' << resy;
}


Measured memory_bytes: 3192
mt_count=int(input())
heights = list(map(int, input().split()))
count = 0

i=1

for i in range(mt_count):
  check_flag = 1
  for j in range(i):
    if heights[j] > heights[i]:
      check_flag = 0
  if check_flag == 1:
    count += 1

print(count)

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

int main(void){
    string s;
    int k;
    cin >> k >> s;
    string  a[k];
    if (s.size()<=k){
        cout << s << endl;
    }else{
        for (int i = 0; i < k; i++){
            a[i] = s[i];
        }
        //a[k+1] = "...";
        for (int i = 0; i < k; i++) cout << a[i];
        cout << "...";        
   }
    cout << endl;

}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  double L;
  cin >> L;

  double res = 0;

  res = (L/3)*(L/3)*(L/3);

  printf("%.8f\n", res);
}


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

class Program
{
    static void Main()
    {
        List<int> Ans = new List<int>();

        while (true)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            string E = str[1];
            int b = int.Parse(str[2]);

            

            if (E == "?")
            {
                break;
            }
            else
            {
                if (E == "+")
                {
                    Ans.Add(a + b);
                }
                else
                {
                    if (E =="-")
                    {
                        Ans.Add(a - b);
                    }
                    else
                    {
                        if (E == "*")
                        {
                            Ans.Add(a * b);
                        }
                        else
                        {
                            Ans.Add(a / b);
                        }
                    }
                }
            }
            
        }

        for ( int i = 0; i < (Ans.Count) ; i++ )
        {
            Console.WriteLine(Ans[i]);
        }

    }
}

Measured memory_bytes: 9136
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
void print() { cout << "\n"; }
template <class T> void print(const T &x) { cout << x << "\n"; }
template <class T, class... Args> void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
template <class T> void printVector(const vector<T> &v) {
    for(const T &x : v) {
        cout << x << " ";
    }
    cout << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int N, A, B, C;
vector<int> l;

int dfs(int i, int a, int b, int c) {
    if(i == N) {
        if(a == 0 || b == 0 || c == 0) {
            return INF;
        }
        return abs(A - a) + abs(B - b) + abs(C - c);
    }
    int res = INF;
    chmin(res, dfs(i + 1, a + l[i], b, c) + (a == 0 ? 0 : 10));
    chmin(res, dfs(i + 1, a, b + l[i], c) + (b == 0 ? 0 : 10));
    chmin(res, dfs(i + 1, a, b, c + l[i]) + (c == 0 ? 0 : 10));
    chmin(res, dfs(i + 1, a, b, c));
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> A >> B >> C;
    l.resize(N);
    for(int i = 0; i < N; i++) {
        cin >> l[i];
    }
    print(dfs(0, 0, 0, 0));
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import sys

def main() -> int:
    [m, d] = [int(x) for x in sys.stdin.read().split(' ')]
    # 因数分解するよりはかけてしまったほうがはやそう
    ms = [mul(x) for x in range(1, d + 1)]
    months = set(range(1, m + 1))
    ans = len([x for x in ms if x in months])
    print(ans)
    return 0

def mul(x):
    a = int(x // 10)
    b = int(x % 10)
    if a < 2 or b < 2: return 0
    return a * b


if __name__ == "__main__":
    exit(main())

# vim:fenc=utf-8 ff=unix ft=python ts=4 sw=4 sts=4 fdm=indent fdl=0 fdn=1:
# vim: si et cinw=if,elif,else,for,while,try,except,finally,def,class:


Measured memory_bytes: 3064
#include<iostream>
#include<stack>
using namespace std;
int main() {
    stack<int> S;
    int n; cin >> n;
    if (n == 0) cout << 0;
    while (n != 0) {
        if (n % -2 == -1) {
            int tmp = (n % -2);
            n /= -2; n++;
            //cout << n << " " << -tmp << endl;
            S.push(-tmp);
        } else {
            //cout << n / -2 << " " << n % -2 << endl;
            S.push(n % -2);
            n /= -2;
        }
    }
    while (!S.empty() ) {
        cout << S.top();
        S.pop();
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<string>
#include<math.h>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(((a-b)<=d&&(b-a)<=d)&&((b-c)<=d&&(c-b)<=d)||((a-c)<=d&&(c-a)<=d))
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#define rep(i,x) for(int i=0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 10010010010;
typedef pair<ll, ll> P;
using graph = vector<vector<ll>>;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
    if (a < b)swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}

int main() {
    ll N, M;
    cin >> N >> M;
    ll ok = 0;
    ll ng = 0;
    ll q;
    string str;
    vector<bool> yes(N,false);
    vector<ll> num(N, 0);
    rep(i, M) {
        cin >> q >> str;
        if (str == "AC" && yes[q - 1] == false) {
            yes[q - 1] = true;
            ok++;
        }
        else if (str == "WA" && yes[q - 1] == false)num[q - 1]++;
    }
    rep(i,N){
        if (yes[i] == true)ng += num[i];
    }
    cout << ok << " " << ng << endl;
}

Measured memory_bytes: 1024
n=int(input())
a=list(map(int,input().split()))
t=sum(a)
ta=[0]*n
for i in range(n):
  ta[i]=t
  t=t-a[i]
ans=0
for i in range(0,n-1):
  ans=ans+(a[i]*ta[i+1])
  ans=(ans)%(10**9+7)
print(ans)

Measured memory_bytes: 31424
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        if (s[2] == s[3] && s[4] == s[5] ) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }


    }

}


Measured memory_bytes: 23124
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
using namespace std;
int input(){
  int x;
  cin>>x;
  return x;
}
int abs(int x){
  if(x>=0){
    return x;
  }else{
    return -x;
  }
}
int gcd(int x, int y){
	if(x<y){
    return gcd(y,x);
  }
  if(y==0){
    return x;
  }
  return gcd(y,x%y);
}
int moji(char i){
  if(i=='a'){
    return 1;
  }
  if(i=='b'){
    return 2;
  }
  if(i=='c'){
    return 3;
  }
  if(i=='d'){
    return 4;
  }
  if(i=='e'){
    return 5;
  }
  if(i=='f'){
    return 6;
  }
  if(i=='g'){
    return 7;
  }
  if(i=='h'){
    return 8;
  }
  if(i=='i'){
    return 9;
  }
  if(i=='j'){
    return 10;
  }
  if(i=='k'){
    return 11;
  }
  if(i=='l'){
    return 12;
  }
  if(i=='m'){
    return 13;
  }
  if(i=='n'){
    return 14;
  }
  if(i=='o'){
    return 15;
  }
  if(i=='p'){
    return 16;
  }
  if(i=='q'){
    return 17;
  }
  if(i=='r'){
    return 18;
  }
  if(i=='s'){
    return 19;
  }
  if(i=='t'){
    return 20;
  }
  if(i=='u'){
    return 21;
  }
  if(i=='v'){
    return 22;
  }
  if(i=='w'){
    return 23;
  }
  if(i=='x'){
    return 24;
  }
  if(i=='y'){
    return 25;
  }
  if(i=='z'){
    return 26;
  }
  return 100;
  
}




int main() {
  int H,W;
  cin>>H>>W;
  char a[H+2][W+2];
  for(int i=0;i<H+2;i++){
    for(int j=0;j<W+2;j++){
      if(i==0||i==H+1||j==0||j==W+1){
        a[i][j]='#';
      }else{
        cin>>a[i][j];
      }
    }
  }
  for(int i=0;i<H+2;i++){
    for(int j=0;j<W+2;j++){
      cout<<a[i][j];
      if(j==W+1){
        cout<<""<<endl;
      }
    }
  }



  
  


  


  

  




  
  
}

  

  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Tree int h,int l,int r,int L,int R
#define left 2*h,l,(l+r)/2,L,R
#define right 2*h+1,(l+r)/2+1,r,L,R
#define F first
#define S second
#define Pb push_back
using namespace std;
long long n,m,X,Y,H,x[202],y[202],h[202],f[202][202];
main ()
{
	cin>>n;
	
	for (int i=1; i<=n; i++)
	{
		cin>>x[i]>>y[i]>>h[i];
		f[x[i]+1][y[i]+1]=1;
	}

	for (int X=0; X<=100; X++)
		for (int Y=0; Y<=100; Y++)
		{
			int ko=0;
			
			for (int i=1; i<=n; i++)
			{
				if (h[i]==0) continue;
				ko=1;	
				H=h[i]+abs(x[i]-X)+abs(y[i]-Y);
			}
	
			if (!ko)
			{
				for (int X=1; X<=101; X++)
					for (int Y=1; Y<=101; Y++)
						if (!f[X+1][Y] && !f[X-1][Y] && !f[X][Y+1] && !!f[X][Y-1])
						{
							cout<<X-1<<" "<<Y-1<<" "<<1<<endl;
							return 0;	
						}			
			}
			
			ko=0;
	
			for (int i=1; i<=n; i++)
			{
				if (max(0LL,H-abs(x[i]-X)-abs(y[i]-Y))==h[i]) continue;
				
				ko=1;
				break;
			}	
			
			if (H<=0) continue;
			
			if (!ko)
			{
				cout<<X<<" "<<Y<<" "<<H<<endl;
				return 0;
			}
		}
}

Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class BHomework {
        public void solve(int testNumber, InputReader s, PrintWriter w) {
            int n = s.nextInt(), m = s.nextInt();
            long c = 0;
            while (m-- > 0)
                c += s.nextInt();
            if (c > n)
                w.println("-1");
            else
                w.println(n - c);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 33008
def nCr(n, r):
    num, den = 1, 1
    for i in range(n, n-r, -1):
        num = num * i % M       ##;print(num)
    for i in range(1, r+1):
        den = den * i % M       ##;print(den)
    den_inv = pow(den, -1, M)   #;print(num, den, den_inv) 
    return num * den_inv % M

def is_comb():
    a = 1/3 * (2*X - Y)
    b = 1/3 * (-X + 2*Y)
    if a>=0 and b >= 0 and a.is_integer() and b.is_integer():
        return int(a), int(b)
    return 0, 0

M = 10**9 + 7
X, Y  = map(int, input().split())
#X, Y =  103078,  214577
a, b = is_comb()   #; print(a, b)
if a==b==0:
    print(0)
else:
    n, r  = a+b, a
    print(nCr(n, r))

Measured memory_bytes: 9236
use std::io::stdin;
fn get_string() -> String {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

macro_rules! input {
    ($single:ty) => ( get_string().parse::<$single>().unwrap() );
    ($plural:ty,) => ({
        let line = get_string();
        line.split_whitespace().map(|v| v.parse::<$plural>().unwrap()).collect::<Vec<$plural>>()
    });
    ($($plural:ty),+) => ({
        let line = get_string();
        let mut iter = line.split_whitespace();
        ($(iter.next().unwrap().parse::<$plural>().unwrap()),+)
    });
    ($single:ty; $times:expr) => ( (0..$times).map(|_| input!($single)).collect::<Vec<$single>>() );
    ($($plural:ty),+; $times:expr) => ( (0..$times).map(|_| input!($($plural),+)).collect::<Vec<($($plural),+)>>() );
}

#[allow(dead_code)]
fn get_value<T: std::str::FromStr>() -> T {
    get_string().parse().ok().unwrap()
}
#[allow(dead_code)]
fn get_values_for<T: std::str::FromStr>(times: u64) -> Vec<T> {
    (0..times).map(|_| get_value()).collect()
}
#[allow(dead_code)]
fn get_vector<T: std::str::FromStr>() -> Vec<T> {
    get_string()
        .split_whitespace()
        .map(|v| v.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn get_vectors_for<T: std::str::FromStr>(times: u64) -> Vec<Vec<T>> {
    (0..times).map(|_| get_vector()).collect()
}

fn main() {
    let _n = input!(u32);
    let a = input!(u32,);

    let min = a.iter().min().unwrap();
    let max = a.iter().max().unwrap();

    println!("{}", max - min);
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long[] abcde = new long[5];
        for (int i = 0; i < 5; i++) {
            abcde[i] = sc.nextLong();
        }
        sc.close();

        long min = Long.MAX_VALUE;
        for (int i = 0; i < 5; i++) {
            if (abcde[i] < min) {
                min = abcde[i];
            }
        }
        long diff = n / min;
        if (n % min != 0) {
            diff++;
        }
        long ans = 5 + (diff - 1);
        System.out.println(ans);
    }

}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
int n;
int main(){
    //freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int ans = 0;
    cin >> n;
    int a, b;
    for(int i = 0; i < n; i++){
        cin >> a >> b;
        ans += b-a+1;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int a,b,x;
  cin >> a >>b;
  
  x = a*b;
  
  if(x % 2 == 0)
    cout << "Even" << endl;
  else cout << "Odd"<<endl;
  
  
  
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
    int n, q; cin>>n>>q;
    dsu d(n);
    while(q--){
        int t, u, v;
        cin>>t>>u>>v;
        if(t==0){
            d.merge(u, v);
        }else{
            if(d.same(u, v)) cout<<1<<endl;
            else cout<<0<<endl;
        }
    }
    return 0;
}

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


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    long long n; cin >> n;
    long long mod = 1e9+7;
    vector<long long>a(n,0);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    vector<long long>ps(n-1,0);
    ps[n-2] = a[n-1];
    for(int i = n-2; i > 0; i--){
        ps[i-1] = (ps[i] + a[i])%mod;
    }
    long long sm = 0;
    for(int i = 0; i < n-1; i++){
        long long prod = (a[i]*ps[i])%mod;
        sm = (sm + prod)%mod;
        // for(int j = i+1; j < n; j++){
        //     long long prod = (a[i]*a[j])%mod;
        //     sm = (sm + prod)%mod;
        // }
    }
    cout << sm << endl;
    return 0;
}


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

int main(){
	int N, M;
	cin >> N >> M;
	int roads[N];
	for(int i = 0; i < N; i++){
		roads[i] = 0;
	}
	for(int i = 0; i < M * 2; i++){
		int input;
		cin >> input;
		roads[input - 1]++;
	}
	for(int i = 0; i < N; i++){
		cout << roads[i] << endl;
	}
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n;
  cin >> n;
  vi32 mp(n);
  rep(i, n) {
    int p;
    cin >> p;
    p--;
    mp[p] = i;
  }
  int c = 1, sum = 1;
  rep(i, n - 1) {
    if (mp[i] < mp[i + 1]) {
      c++;
    } else {
      c = 1;
    }
    amax(sum, c);
  }
  int ans = n - sum;
  cout << ans << endl;
}


Measured memory_bytes: 1024
#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);
    }

    reverse(a.begin(), a.end());

    for(int i = 0; i < n; i++){
        if(i >= 1){
            cout << " ";
        }
        cout << a.at(i);
    }
    cout << endl;
    
    return 0;

}


Measured memory_bytes: 3088
import java.util.*;
import static java.lang.Math.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a[] = new int[1000001];
        a[1] = sc.nextInt();
        for(int i=2; i<1000001; i++){
            if(a[i-1]%2 == 0){
                a[i] = a[i -1] / 2;
            }else{
                a[i] = 3 * a[i-1] + 1;
            }
            for(int j=1; j<i; j++){
                if(a[i] == a[j]){
                    System.out.println(i);
                    return;
                }
            }
        }
    }
}


Measured memory_bytes: 27860
import scala.io.StdIn.readInt
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args:Array[String]) = {
    val b = new ArrayBuffer[String]
    var n = 0
    while({n=readInt;n} != 0) {
      val s = (1 to Math.sqrt(n).toInt).filter(n%_==0).map{i=>
        if(i!=n/i) i+n/i
        else i
      }
      if(n==s.sum-n) b+="perfect number"
      else if(n>s.sum-n) b+="deficient number"
      else b+="abundant number"
    }
    println(b.mkString("\n"))
  }

}

Measured memory_bytes: 52848
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

char win(char c){
    if(c == 'r'){
        return 'p';
    }
    else if(c == 's'){
        return 'r';
    }
    else {
        return 's';
    }
}

char oth(char c1,char c2)
{
    string list = "rsp";

    REP(i,list.size()){
        if(c1 != list[i] && c2 != list[i]){
            return list[i];
        }
    }
    return 'r';
}

int main(void)
{
    int n, k;
    ll r, s, p;
    string t;
    string w;

    cin >> n >> k;
    cin >> r >> s >> p;
    cin >> t;

    w = t;

    REP(i,n){
        w[i] = win(t[i]);
    }

    vector<vector<char>> table(k);
    vector<vector<char>> orig(k);
    REP(i, k)
    {
        for (int j = 0; i + j < w.size();j+=k){
            table[i].push_back(w[i + j]);
            orig[i].push_back(w[i + j]);
        }
    }


    REP(i,k){
        for (int j = 1; j < table[i].size();j++)
        {
            if(table[i][j] == table[i][j-1]){
                if(j == table[i].size()-1){
                    table[i][j] = win(table[i][j]);
                }
                else{
                    table[i][j] = oth(table[i][j + 1], table[i][j-1]);
                }
            }
        }
    }

    ll sum = 0;

    REP(i,table.size())
    {
        REP(j,table[i].size()){
            if(table[i][j] == 'r' && table[i][j] == orig[i][j]){
                sum += r;
            }
            else if(table[i][j] == 's' && table[i][j] == orig[i][j]){
                sum += s;
            }
            else if(table[i][j] == 'p' && table[i][j] == orig[i][j]){
                sum += p;
            }
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 10112
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a<b?a=b,true:false);}
template<class T>bool chmin(T &a, const T &b){return(a>b?a=b,true:false);}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}



signed main() {

    map<string, int> ma;
    ma["SAT"] = 1;
    ma["FRI"] = 2;
    ma["THU"] = 3;
    ma["WED"] = 4;
    ma["TUE"] = 5;
    ma["MON"] = 6;
    ma["SUN"] = 7;

    string s;
    cin >> s;
    cout << ma[s] << endl;


  
    return 0;
}



Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn mod_pow(a: i64, n: i64, p: i64) -> i64 {
    match n {
        0 => 1,
        n if n % 2 == 0 => {
            let x = mod_pow(a, n/2, p);
            x * x % p
        },
        _ => {
            let x = mod_pow(a, n/2, p);
            a * (x*x % p) % p
        }
    } 
}

fn mod_combination(n: i64, r: i64, p: i64) -> i64 {
    let mut x = 1;
    for i in 0..r {
        x = x *(n - i) % p;
    }
    let mut y = 1;
    for i in 1..r+1 {
        y = y * i % p;
    }
    x * mod_pow(y, p - 2, p) % p
}

const MODULO: i64 = 1_000_000_007;

fn main() {
    let input = read_vec::<i64>();
    let (x, y) = (input[0], input[1]);

    if (x + y) % 3 != 0 {
        println!("0");
        return;
    }

    let n = (2*x - y) / 3;
    let m = (2*y - x) / 3;

    if (2*x - y) % 3 != 0 || (2*y - x) % 3 != 0 {
        println!("0");
        return;
    }

    if n < 0 || m < 0 {
        println!("0");
        return;
    }
    
    let ans = mod_combination(n+m, n, MODULO);
    println!("{}", ans);
}

Measured memory_bytes: 4352
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
 
 
def main():
    N, M = map(int, readline().split())
    d = map(int, read().split())
    AB = list(zip(d, d))
    AB = sorted(AB)
 
    have = 0
    price = 0
    for x, y in AB:
        if M - have < y:
            price += x * (M - have)
            break
 
        else:
            price += x * y
            have += y
 
 
    print(price)
 
main()

Measured memory_bytes: 27496
#include	<cstdio>
#include	<cstring>
#include	<iostream>
#include	<algorithm>

using	namespace	std;
const	int INF = 100000000;
const	int N = 210, M = 1010;

int n, m;
int z[M], d[M][N];
int dl[N][N], ds[N][N];

int main()
{
	while( scanf( "%d%d", &n, &m ) == 2 && n )
	{
		for( int i = 0; i < n; i ++ )
		{
			for( int j = 0; j < n; j ++ )
			{
				if( i == j )
					dl[i][j] = ds[i][j] = 0;
				else
					dl[i][j] = ds[i][j] = INF;
			}
		}
		for( int i = 0; i < m; i ++ )
		{
			char s[2];
			int u, v, t;
			scanf( "%d%d%d%s", &u, &v, &t, s );
			u --, v --;
			if( s[0] == 'L' )
			{
				dl[u][v] = min( dl[u][v], t );
				dl[v][u] = dl[u][v];
			}
			else
			{
				ds[u][v] = min( ds[u][v], t );
				ds[v][u] = ds[u][v];
			}
		}
		int r;
		scanf( "%d", &r );
		for( int i = 0; i < r; i ++ )
		{
			scanf( "%d", &z[i] );
			z[i] --;
		}
		for( int k = 0; k < n; k ++ )
		{
			for( int i = 0; i < n; i ++ )
			{
				for( int j = 0; j < n; j ++ )
				{
					dl[i][j] = min( dl[i][j], dl[i][k] + dl[k][j] );
					ds[i][j] = min( ds[i][j], ds[i][k] + ds[k][j] );
				}
			}
		}
		for( int i = 0; i < r; i ++ )
			for( int j = 0; j < N; j ++ )
				d[i][j] = INF;
		for( int i = 0; i < n; i ++ )
			d[0][i] = ds[z[0]][i] + dl[i][z[0]];
		for( int i = 1; i < r; i ++ )
		{
			for( int j = 0; j < n; j ++ )
			{
				for( int k = 0; k < n; k ++ )
				{
					if( j != k )
						d[i][j] = min( d[i][j], d[i-1][k] + dl[z[i-1]][k] + ds[k][j] + dl[j][z[i]] );
					else
						d[i][j] = min( d[i][j], d[i-1][j] + dl[z[i-1]][z[i]] );
				}
			}
		}
		int ans = INF;
		for( int i = 0; i < n; i ++ )
			ans = min( ans, d[r-1][i] );
		printf( "%d\n", ans );
	}
	return 0;
}

Measured memory_bytes: 2356
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

const int N=1e5+5;
int n,m,ID[N],fa[N],vis[N];
ll A[N],B[N],C[N],dp[N],sum[N];
vector <int> G[N];

template <typename _Tp> inline void IN(_Tp&x) {
	char ch;bool flag=0;x=0;
	while(ch=getchar(),!isdigit(ch)) if(ch=='-') flag=1;
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	if(flag) x=-x;
}
int find(int x) {return x==fa[x]?fa[x]:fa[x]=find(fa[x]);}
bool cmp(int x,int y) {return C[x]<C[y];}
inline void addedge(int u=0,int v=0) {
	IN(u),IN(v),G[u].push_back(v),G[v].push_back(u);
}

int main() {
	IN(n),IN(m);
	for(int i=1;i<=n;++i) fa[i]=ID[i]=i;
	for(int i=1;i<=n;++i) IN(A[i]),IN(B[i]),C[i]=max(A[i]-B[i],(ll)0);
	sort(ID+1,ID+1+n,cmp);
	for(int i=1;i<=m;++i) addedge();
	int u;
	for(int i=1;i<=n;++i) {
		vis[u=ID[i]]=true,sum[u]=B[u],dp[u]=C[u];
		for(auto tmp:G[u]) if(vis[tmp]) {
			int v=find(tmp);
			if(v==u) continue;
			fa[v]=u,sum[u]+=sum[v],dp[u]=min(dp[u],max(dp[v],C[u]-sum[v]));
		}
	}
	printf("%lld\n",dp[ID[n]]+sum[ID[n]]);
	return 0;
}

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

template <typename T>
struct FenwickTree {
	int n; // [1, n]
	vector<T> bit;
	FenwickTree(int n) : n(n), bit(n+1) {}
	T sum(int i) {
		T s = 0;
		while (i > 0) {
			s += bit[i];
			i -= i&-i;
		}
		return s;
	}
	void add(int i, T x) {
		while (i <= n) {
			bit[i] += x;
			i += i&-i;
		}
	}
};

int main() {
	int N, Q;
	cin >> N >> Q;
	vector<int> C(N);
	for (auto& x : C) cin >> x;
	vector<pair<int,int>> LR;
	map<int,map<int,int>> ans;
	for (int i = 0; i < Q; ++ i) {
		int x, y;
		cin >> x >> y;
		LR.push_back({x,y});
		ans[y][x] = 0;
	}
	vector<int> hoge(N+1, -1);
	FenwickTree<int> bit(N);
	for (int p = 1; p <= N; ++ p) {
		int prev = hoge[C[p-1]];
		if (prev != -1) {
			bit.add(prev, -1);
		}
		hoge[C[p-1]] = p;
		bit.add(p, 1);
		if (ans.count(p)) {
			for (auto& x : ans[p]) {
				int q = x.first;
				x.second = bit.sum(p) - bit.sum(q-1);
			}
		}
	}
	for (auto x : LR) {
		cout << ans[x.second][x.first] << endl;
	}
}


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

string str;
string meirei;
int n; //命令数

void pri(int a, int b)
{
	while (a <= b)
	{
		cout << str[a];
		a++;
	}
	cout << endl;
}

void rep(int a, int b, string s)
{
	str.replace(a , (b - a + 1), s);
	//cout << str << endl;
}

void rev(int a, int b)
{
	string han;
	int aa = a, bb = b;
	while (b >= a)
	{
		han += str[b];
		b--;
	}
	
	str.replace(aa, (bb-aa+1), han);
	//cout << han << endl;
	//cout << str << endl;
}


int main()
{

	cin >> str;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> meirei;
		if (meirei == "replace"){
			int a, b;
			string s;
			cin >> a >> b >> s;
			rep(a, b, s);
		}
		else if (meirei == "reverse"){
			int a, b;
			cin >> a >> b;
			rev(a, b);
		}
		else if (meirei == "print"){
			int a, b;
			cin >> a >> b;
			pri(a, b);
		}
	}
	return 0;
}

Measured memory_bytes: 1216
from math import ceil
n=int(input())
P=list(map(int,input().split()))
Q=["*"]*(n+1)

for i in range(n):
    if P[i]==i+1:Q[i]="#"

ans,cnt,point=0,0,0
while cnt!=n+1:
    if Q[cnt]=="#":point +=1
    elif Q[cnt]=="*" and point>=1:
        ans +=ceil(point/2)
        point=0
    cnt +=1

print(ans)

Measured memory_bytes: 13812
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt();
			int [] array = new int [n];
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			int x = sc.nextInt();
			int kazu = 0;
			for(int i = 0; i < n; i++){
				array[i] = sc.nextInt();
			}
			if(n + a + b + c + x == 0){
				break;
			}
			for(int i = 0; i <= 10000; i++){
				if(array[kazu] == x){
					kazu++;
				}
				x = (a * x + b) % c;
				if(kazu == n){
					System.out.println(i);
					break;
				}
				if(i == 10000){
					System.out.println(-1);
				}
			}
		}
	}
}

Measured memory_bytes: 32144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main ()
{
        ll a,b,k;
        cin>>a>>b>>k;
        if (a>k)
        {
                cout<<a-k<<" "<<b<<'\n';
        }
        else if (a==k)
        {
                cout<<0<<" "<<b<<'\n';
        }
        else
        {
                k=k-a;
                if (b>=k)
                {
                        b=b-k;
                }
                else
                {
                        b=0;
                }
                cout<<"0"<<" "<<b<<'\n';
        }
        return 0;
}


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

#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MN = 2e5 + 5, LN = 17, MOD = 998244353, INF = 0x3f3f3f3f, BSZ = 320;
int N;
map<int, int> mpx, mpy;
int cnt[MN][4];
int bit[MN];
ll p2[MN];

void upd(int i, int v) {
    for (; i < MN; i += i & -i) bit[i] += v;
}

int qry(int i) {
    int ret = 0;
    for (; i > 0; i -= i & -i) ret += bit[i];
    return ret;
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> N;
    p2[0] = 1;
    for (int i = 1; i <= N; i++) p2[i] = (p2[i - 1] * 2) % MOD;
    vector<int> xs, ys;
    vector<pii> point;
    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        xs.push_back(x);
        ys.push_back(y);
        point.emplace_back(x, y);
    }
    sort(all(xs));
    xs.erase(unique(all(xs)), xs.end());
    sort(all(ys));
    ys.erase(unique(all(ys)), ys.end());
    for (int i = 0; i < xs.size(); i++) mpx[xs[i]] = i + 1;
    for (int i = 0; i < ys.size(); i++) mpy[ys[i]] = i + 1;
    for (pii &p : point) p.first = mpx[p.first], p.second = mpy[p.second];
    sort(all(point));
    for (int i = 0; i < N; i++) {
        int y = point[i].second;
        cnt[i][0] = qry(y - 1);
        cnt[i][1] = i - qry(y);
        upd(y, 1);
    }
    memset(bit, 0, sizeof(bit));
    reverse(all(point));
    for (int i = 0; i < N; i++) {
        int y = point[i].second;
        cnt[N - i - 1][2] = qry(y - 1);
        cnt[N - i - 1][3] = i - qry(y);
        upd(y, 1);
    }
    ll ret = 0;
    for (int i = 0; i < N; i++) {
        ll v = 0;
        (v += (p2[cnt[i][0]] - 1) * (p2[cnt[i][3]] - 1) % MOD * p2[cnt[i][1]] % MOD * p2[cnt[i][2]] % MOD) %= MOD;
        (v += (p2[cnt[i][1]] - 1) * (p2[cnt[i][2]] - 1) % MOD * p2[cnt[i][0]] % MOD * p2[cnt[i][3]] % MOD) %= MOD;
        ll minus = (p2[cnt[i][0]] - 1) * (p2[cnt[i][3]] - 1) % MOD * (p2[cnt[i][1]] - 1) % MOD * (p2[cnt[i][2]] - 1) % MOD;
        (v += p2[N - 1]) %= MOD;
        v = (v - minus + MOD + MOD) % MOD;
        ret = (ret + v) % MOD;
    }
    cout << ret << '\n';
    return 0;
}


Measured memory_bytes: 27612
#include <iostream>
#include <vector>
#include <memory>
#include <map>
#include <cmath>

class Graph {
  struct Link {
    int from;
    int to;
    int cost;
  };
  struct Vertex {
    std::vector<Link> links;
  };

  public: 
    Graph() : vertex_num(0) {}

    void addLink(const Link &link) {
      links.emplace_back(link);
      vertexes[link.from].links.emplace_back(link);
      vertex_num = std::max(link.to + 1, vertex_num);
    }

    const std::vector<Link> &getLinks() const {
      return links;
    }
    void show() const {
      std::cout << vertex_num << " " << links.size() << std::endl;
      for (const auto &link : links) {
        std::cout << link.from + 1<< " " << link.to+ 1 << " " << link.cost << std::endl;
      }
    }

    void debug_show() const {
      for (const auto &vertex: vertexes) {
        std::cout << "Vertex #" << vertex.first << " link num:" << vertex.second.links.size() << std::endl;
        for (const auto &link: vertex.second.links) {
          std::cout << "  " << link.from << "->" << link.to << " cost: " << link.cost << std::endl;
        }
      }
      std::cout << std::endl;
    }

    int getVertexNum() const {
      return vertex_num;
    }
  private:
    std::vector<Link> links;
    std::map<int, Vertex> vertexes;
    int vertex_num;
};

std::shared_ptr<Graph> getGraph(const int l) {
  auto graph = std::make_shared<Graph>();
  int node_num = 0;
  for (int i = 0; i <= 20; ++i) {
    if (std::pow(2, i) > l) {
      node_num = i - 1;
      break;
    }
  }
  for (int i = 0; i< node_num; ++i) {
    graph->addLink({i, i + 1, 0});
    graph->addLink({i, i + 1, static_cast<int>(std::pow(2, i))});
  }

  int diff = l - static_cast<int>(std::pow(2, node_num));
  if (diff == 0) {
    return graph;
  }

  int cost_add = static_cast<int>(std::pow(2, node_num));
  for (int i = node_num - 1; i >= 0; --i) {
    const auto current_diff = static_cast<int>(std::pow(2, i));
    if (diff >= current_diff) {
      graph->addLink({i, node_num, cost_add});
      cost_add += current_diff;
      diff -= current_diff;
    }
  }

  return graph;
}

int main() {
  int l;
  std::cin >> l;
  const auto graph = getGraph(l);
  graph->show();
  return 0;
}

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

int main() {
  static auto add = [](int a, int b) { return a + b; };
  static auto mul = [](int a, int b) { return a * b; };
  int n;
  while (cin >> n, n) {
    vector<pair<function<int(int, int)>, int>> v;
    v.push_back(make_pair(add, 0));
    for (int i = 0; i < n; i++) {
      string s;
      cin >> s;
      int d = s.size() - 1;
      char c = *s.rbegin();
      while (d < v.size() - 1) {
        int r = v.back().second;
        v.pop_back();
        v.rbegin()->second = v.rbegin()->first(v.rbegin()->second, r);
      }
      if (c == '+') {
        v.push_back(make_pair(add, 0));
      } else if (c == '*') {
        v.push_back(make_pair(mul, 1));
      } else {
        v.rbegin()->second = v.rbegin()->first(v.rbegin()->second, c - '0');
      }
    }
    while (v.size() > 1) {
      int r = v.back().second;
      v.pop_back();
      v.rbegin()->second = v.rbegin()->first(v.rbegin()->second, r);
    }
    cout << v.front().second << endl;
  }
  return 0;
}



Measured memory_bytes: 3188
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};
macro_rules! chmax {
    ($base:expr, $($cmps:expr),+ $(,)*) => {{
        let cmp_max = max!($($cmps),+);
        if $base < cmp_max {
            $base = cmp_max;
            true
        } else {
            false
        }
    }};
}
macro_rules! max {
    ($a:expr $(,)*) => {{
        $a
    }};
    ($a:expr, $b:expr $(,)*) => {{
        std::cmp::max($a, $b)
    }};
    ($a:expr, $($rest:expr),+ $(,)*) => {{
        std::cmp::max($a, max!($($rest),+))
    }};
}
#[fastout]
fn main() {
    input! {//
        r:usize,
        c:usize,
        k:usize,
        rcv:[(Usize1,Usize1,usize);k],
    }
    let mut rcvs = vec![vec![0; c]; r];
    // dbg!(&rcv);
    for &(r, c, v) in rcv.iter() {
        rcvs[r][c] = v;
    }
    // dbg!(&rcvs);
    // rcv.sort();
    let mut dp = vec![vec![vec![0; 4]; c]; r]; // dp[r][c][k]
    let mut ans = 0;

    for rr in 0..r {
        for cc in 0..c {
            for i in 0..=3 {
                if rr + 1 < r {
                    chmax!(dp[rr + 1][cc][0], dp[rr][cc][i]);
                }
                if cc + 1 < c {
                    chmax!(dp[rr][cc + 1][i], dp[rr][cc][i]);
                }
            }
            for i in 0..3 {
                if rr + 1 < r {
                    chmax!(dp[rr + 1][cc][0], dp[rr][cc][i] + rcvs[rr][cc]);
                }
                if cc + 1 < c {
                    chmax!(dp[rr][cc + 1][i + 1], dp[rr][cc][i] + rcvs[rr][cc]);
                }
            }
        }
    }
    dbg!(&dp[r - 1][c - 1][3]);
    let mut ans = dp[r - 1][c - 1][3];
    for i in 0..3 {
        chmax!(ans, dp[r - 1][c - 1][i] + rcvs[r - 1][c - 1]);
    }

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


Measured memory_bytes: 713008
#include<iostream>

using namespace std;

int main(){
    long long q,h,s,d;

    cin>>q>>h>>s>>d;

    if(2*q<h){
        h=2*q;
    }
    if(2*h<s){
        s=2*h;
    }
    if(2*s<d){
        d=2*s;
    }

    long long N;
    cin>>N;

    long long ans=N/2*d+N%2*s;

    cout<<ans<<endl;

}


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

#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;
const int INF = 2e16;
const int MOD = 1e9 + 7;
const int MB = 20;


void solve() {
	int a, b;
	cin >> a >> b;
	if (a < 10 && b < 10) cout << a * b;
	else cout << -1;
}
	

signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	solve();
}

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

n, k = map(int, input().split())
*a, = sorted(map(int, input().split()))

# -+-+-+-prepare combination-+-+-+-
# -+-+-+-START-+-+-+-
fact = [1] * (n + 1)
for x in range(2, n + 1):
    fact[x] = x * fact[x - 1] % MOD

invs = [1] * (n + 1)
invs[n] = pow(fact[n], MOD - 2, MOD)
for x in range(n - 1, 0, -1):
    invs[x] = invs[x + 1] * (x + 1) % MOD


def cmb(n, r):
    if n < r:
        return 0
    return (((invs[r] * invs[n - r]) % MOD) * fact[n]) % MOD


# -+-+-+-END-+-+-+-

ret = 0
for lt, x in enumerate(a):
    gt = n - lt - 1
    mi = cmb(gt, k - 1)
    ma = cmb(lt, k - 1)
    ret = (ret + (ma - mi) * x) % MOD

print(ret)


Measured memory_bytes: 15056
from math import atan, degrees
a, b, x = map(int, input().split())
if pow(a,2)*b == x:
    print(0)
elif b*pow(a,2)/2 <= x:
    print(90-degrees(atan((a/2)/(b-x/pow(a,2)))))
else:
    print(90-degrees(atan((2*x/(a*b))/b)))

Measured memory_bytes: 9384
#include <stdio.h>
int main(){
int a,b,c,d,e;
scanf("%d %d %d %d",&a,&b,&c,&d);
e = a/d;
e += 1;
for(int i = 0;i < e;i++){
	c -= b;
	if(c <= 0){
		printf("Yes");
		break;}
	a -= d;
	if(a <= 0) {
		printf("No");
		break;}
	}

}

Measured memory_bytes: 1732
n = gets.to_i
a = gets.split.map(&:to_i)

l = [a[0]]
r = [a[-1]]
(a.length-1).times do |i|
  l.push(l[i].gcd(a[i+1]))
  r.push(r[i].gcd(a[a.length - i - 2]))
end

max = 0

a.length.times do |i|
  if i == 0
    max = [r[r.length - 2 - i], max].max
    next
  end
  if i == a.length - 1
    max = [l[i-1], max].max
    next
  end 
  max = [l[i-1].gcd(r[r.length - 2 - i]), max].max
end

puts max

Measured memory_bytes: 12696
# ABC142E - Get Everything
import sys
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    p = 1 << N
    INF = 10 ** 10
    dp = [INF] * p
    dp[0] = 0
    for _ in range(M):
        a, _ = map(int, input().split())
        x = sum(1 << (i - 1) for i in map(int, input().split()))
        for y in range(p):
            if dp[x | y] > dp[y] + a:
                dp[x | y] = dp[y] + a
    ans = dp[-1] if dp[-1] != INF else -1
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int a[4000];

int main(){
	int n;
	int sum=0;
	int maxnum=-1;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	cout<<sum-n<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int M; cin >> M;
    ll sum = 0, digit = 0;
    REP(i, 0, M) {
        int d; ll c; cin >> d >> c;
        sum += d * c;
        digit += c;
    }
    cout << digit - 1 + (sum - 1) / 9 << endl;
    return 0;
}

Measured memory_bytes: 256
N=int(input())
target_h=map(int,input().split(' '))


def all_zero(h):
    zero = True
    for hh in h:
        if hh != 0:
            zero = False
            break
    return zero

def div_ary(h):
    arys = []
    zeropos = []

    for i,hh in enumerate(h):
        if hh == 0:
            zeropos.append(i)
    
    if len(zeropos) == 0:
        return [h]
    else:
        tmpary = []
        for i, hh in enumerate(h):
            if hh == 0:
                arys.append(tmpary)
                tmpary = []
            else:
                tmpary.append(hh)
        arys.append(tmpary)
    return arys

#minが0になるまで全体に水やり
def mizuyari(h_ary):
    if len(h_ary) == 0:
        return 0
    else:
        #minまでは水やり
        h_min = min(h_ary)
        for i in range(len(h_ary)):
            h_ary[i] -= h_min
        num = h_min

        #すべてゼロなら回数決定
        if all_zero(h_ary):
            return num
        else:
            #ゼロじゃなければ分割して部分水やり
            arys = div_ary(h_ary)

            for a in arys:
                num += mizuyari(a)
    return num


h_ary = []
for th in target_h:
    h_ary.append(th)
mizunum = mizuyari(h_ary)
print(mizunum)

Measured memory_bytes: 3188
//
//  main.cpp
//  Study
//
//  Created by 佐々木勇星 on 2020/03/12.
//  Copyright © 2020 佐々木勇星. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <map>

using namespace std;


int main(int argc, const char * argv[]) {

    long long n;
    cin >> n;
    long long ans = 0;
    
    for(int i=1; i<n; i++) ans = ans + i;
    
    cout << ans << endl;;
    
    return 0;
    
}


Measured memory_bytes: 256