akhauriyash/Code-Regression huggingface dataset:
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han Elmuzaffer Daima
//Bismillahirrahmanirrahim

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long int lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(lo i=1;i<=n;i++)
#define mid (start+end)/2
#define ort (bas+son)/2

const lo MAX = -1000000000000000000; 
const lo MIN = 1000000000000000000; 
const lo inf = 1000000000; 
const lo KOK = 100000; 
const lo LOG = 30; 
const lo li = 500005; 
const lo mod = 1000000007; 

lo n,m,cev,b,a[li],k,r,g,dp[5][li];
string s;
vector<lo> v;

inline lo f(lo sira,lo kac){
	if(kac>n) return 0;
	lo cevv=0;
	if(sira>3){
		if(kac==n) return 1;
		return 0;
	}
	if(~dp[sira][kac]) return dp[sira][kac];
	if(sira==1){
		for(lo i=0;i<=3000;i++){
			cevv+=f(sira+1,kac+i*r);
		}
	}
	if(sira==2){
		for(lo i=0;i<=3000;i++){
			cevv+=f(sira+1,kac+i*g);
		}
	}
	if(sira==3){
		for(lo i=0;i<=3000;i++){
			cevv+=f(sira+1,kac+i*b);
		}
	}
	return dp[sira][kac]=cevv;
}

int main(void){
	memset(dp,-1,sizeof(dp));
	scanf("%lld %lld %lld %lld",&r,&g,&b,&n);
	
	printf("%lld\n",f(1,0));
	return 0;
}


Measured memory_bytes: 20736
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_ARRAY_MAX		200000									// 最大配列数

// 内部変数
static int si1Array[D_ARRAY_MAX];								// 配列
static int siACnt;												// 配列数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpT, *szpFpA;
#endif

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i;
	char lc1Buf[1024], lc1Out[1024];

	// テストファイルオープン
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpT = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#endif

	// 配列数取得
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
	sscanf(lc1Buf, "%d", &siACnt);

	// 配列取得・合計取得
	long long llSum1 = 0;
	for (i = 0; i < siACnt; i++) {
#ifdef D_TEST
		fscanf(szpFpT, "%d", &si1Array[i]);
#else
		fscanf(stdin, "%d", &si1Array[i]);
#endif
		llSum1 += (long long)si1Array[i];
	}
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif

	// 初期値
	llSum1 -= (long long)si1Array[siACnt - 1];
	long long llSum2 = si1Array[siACnt - 1];
	long long llMin = llabs(llSum1 - llSum2);

	// 全パターンチェック
	for (i = siACnt - 2; i > 0; i--) {
		llSum1 -= (long long)si1Array[i];
		llSum2 += (long long)si1Array[i];
		long long llVal = llabs(llSum1 - llSum2);
		if (llMin > llVal) {
			llMin = llVal;
		}
	}

	// 結果セット
	sprintf(lc1Out, "%lld\n", llMin);

	// 結果表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpT);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <vector>
#include <limits.h>
#include <cmath>
#include <map>
#include <iomanip>
using namespace std;
using ll=long long;
using P=pair<int,int>;
int main(){
    int l;
    cin>>l;
    vector<int> e;
    int p=19;
    while(l>0){
       if(l-pow(2,p)>=0){
           e.push_back(p);
           l-=pow(2,p);
       }
       p--;
    }
    int mx=e[0];
    int n=mx+1;
    int m=2*mx+e.size()-1;
    cout<<n<<" "<<m<<endl;
    for(int i=0;i<n-1;i++){
        cout<<i+1<<" "<<i+2<<" "<<0<<endl;
        cout<<i+1<<" "<<i+2<<" "<<pow(2,i)<<endl;
    }
    int now=pow(2,mx)-1;
    for(int i=1;i<e.size();i++){
        cout<<e[i]+1<<" "<<n<<" "<<now+1<<endl;
        now+=pow(2,e[i]);
    }
}

Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))
dp = [0] * (k + 1)

for i in range(k + 1):
    if dp[i] == 0:
        for j in a:
            if i + j > k:
                break
            else:
                dp[i + j] = 1

print("First" if dp[k] else "Second")

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  int K = nextLong();
  int N = nextInt();
  vector<int> A(N);
  REP(i, N) A[i] = nextInt();
  int ma = 0;
  for (int i = 0; i < N-1; i++) {
    chmax(ma, A[i+1] - A[i]);
  }
  chmax(ma, A[0] + K - A[N-1]);
  int ans = K - ma;
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 1024
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
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BComparingStrings solver = new BComparingStrings();
        solver.solve(1, in, out);
        out.close();
    }

    static class BComparingStrings {
        public void solve(int testNumber, FastReader s, PrintWriter out) {
            int a = s.nextInt();
            int b = s.nextInt();

            if (a < b) {
                for (int i = 0; i < b; i++) {
                    out.print(a);
                }
            } else {
                for (int i = 0; i < a; i++) {
                    out.print(b);
                }
            }
        }

    }

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

        public FastReader(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: 23252
use std::io::prelude::*;

fn input<T>() -> T
    where T: std::str::FromStr {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let a = input::<i64>();
    let b = input::<i64>();
    let c = input::<i64>();
    println!("{}", c - if c <= a-b {c} else {a-b});
}

#[allow(unused_doc_comments)]
#[cfg(test)]
mod tests {
    #[test]
    fn tester() {
        let inputs = [
("
 6 4 3
", "
1
"),

("
 8 3 9
", "
4
"),

("
 12 3 7
","
0
"),
        ];

        for (input, expected) in inputs.iter() {
            call(input, expected.to_string());
        }
    }

    fn call<T: AsRef<str>>(input: T, expected: String) {
        use std::process::{Command, Stdio};
        use std::io::{Read, Write};

        let mut cmd_ls = Command::new("echo")
            .arg(input.as_ref())
            .stdout(Stdio::piped())
            .spawn()
            .unwrap();
        let mut cmd_grep = Command::new("cargo")
            .arg("run")
            .stdin(Stdio::piped())
            .stdout(Stdio::piped())
            .spawn()
            .unwrap();

        if let Some(ref mut stdout) = cmd_ls.stdout {
            if let Some(ref mut stdin) = cmd_grep.stdin {
                let mut buf: Vec<u8> = Vec::new();
                stdout.read_to_end(&mut buf).unwrap();
                stdin.write_all(&buf).unwrap();
            }
        }

        let res = cmd_grep.wait_with_output().unwrap().stdout;

        let res_string: String = String::from_utf8(res.to_vec()).unwrap();

        // convert '\n' into space
        let actual = res_string
            .replace("\n", " ")
            .trim_end_matches(' ')
            .trim_start_matches(' ')
            .to_owned();
        let expected = expected
            .replace("\n", " ")
            .trim_end_matches(' ')
            .trim_start_matches(' ')
            .to_owned();

        // split into a vector
        let actual = actual
            .split(' ')
            .map(|s| s.parse::<f64>().unwrap())
            .collect::<Vec<_>>();
        let expected = expected
            .split(' ')
            .map(|s| s.parse::<f64>().unwrap())
            .collect::<Vec<_>>();

        assert_eq!(actual, expected);
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
int main(){
	long n,x;
	cin>>n>>x;
	vector<long> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	long ans=0;
	for(int i=0;i<n-1;i++){
		if(a[i]+a[i+1]>x){
			ans+=a[i]+a[i+1]-x;
			if(a[i]>x){
				a[i+1]=0;
			}else{
				a[i+1]=x-a[i];
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

const ll MOD = 1e9+7;
ll rui[200001];
ll a[200000];
int main()
{
	int n;
	ll ans=1e14-1;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	rui[0]=0;
	for(int i=0;i<n;i++)
		rui[i+1]=rui[i]+a[i];
	for(int i=1;i<n;i++)
	{
		ll l=rui[i];
		ll r=rui[n]-rui[i];
		ans=min(ans,abs(r-l));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3328
import java.util.*;
import java.io.*;

public class Main{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        
        PrintWriter out = new PrintWriter(System.out);
        while(true){
            int height = Integer.parseInt(in.next()), width = Integer.parseInt(in.next());
            
            if(height == 0 && width == 0) break;

            draw_rect(height, width, out);
        }

        out.flush();
    }

    static void draw_rect(int height, int width, PrintWriter out){
        for(int i = 0; i < height; i++){
            for(int j = 0; j < width; j++)out.print("#");
            out.println();
        }
        out.println();
    }
}


Measured memory_bytes: 28080
#include<bits/stdc++.h>
using namespace std;
double a[25][25];
int main()
{
	double n,m,sum=0,ans=0;
	cin>>n>>m;
	for(int i=1;i<=n;i++)	
		for(int j=1;j<=m;j++)
			cin>>a[i][j];		
	for(int i=1;i<=n-1;i++)	
	{
		for(int k=1;i+k<=n;k++)
		{
			for(int j=1;j<=m;j++)
				sum+=(a[i][j]-a[i+k][j])*(a[i][j]-a[i+k][j]);
			if(sqrt(sum)==floor(sqrt(sum)))
				ans++;
			sum=0;	
		}	
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FASTIO cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define ll long long int
#define F first
#define S second
#define pll pair<ll,ll>
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define pb push_back

struct compare {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		if ((a.S - a.F) != (b.S - b.F)) return ((a.S - a.F) > (b.S - b.F));
		else return (a.F < b.F);
	}
};

int main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	FASTIO;
	ll n, wmax, i, j; cin >> n >> wmax;
	vl v(n), w(n), dp(wmax + 1, -1);
	//vvl dp(n + 1, vl(wmax + 1, -1));
	for (i = 0; i < n; i++) cin >> w[i] >> v[i];
	dp[0] = 0;
	for (i = n - 1; i >= 0; i--) {
		vl ndp(wmax + 1, -1);
		for (j = 0; j <= wmax; j++) {
			if (dp[j] != -1) ndp[j] = dp[j];
			if ((w[i] <= j) && dp[j - w[i]] != -1) ndp[j] = max(ndp[j], dp[j - w[i]] + v[i]);
		}
		dp = ndp;
	}
	ll ans = dp[0];
	for (i = 1; i <= wmax; i++) {
		ans = max(ans, dp[i]);
	}
	cout << ans << endl;

}

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

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define all(x) x.begin(), x.end()

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}

const int MAXN = 110;
int n, m;
char a[MAXN][MAXN];
int dp[MAXN][MAXN];

void read() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cin >> a[i][j];
		}
	}
}

const int INF = 1e9 + 10;



void build() {
	for (int i = 0; i < MAXN; i++)
		for (int j = 0; j < MAXN; j++)
			dp[i][j] = INF;
}

int used[MAXN][MAXN];

vector<int> dx = {-1, 0};
vector<int> dy = {0, -1};

bool check(int x, int y) {
	return x >= 1 && x <= n && y >= 1 && y <= m;
}

void build(int x, int y, int c) {
	used[x][y] = c;
	queue<pair<int, int>> q;
	q.push({x, y});
	while (!q.empty()) {
		x = q.front().first;
		y = q.front().second;
		q.pop();
		for (int i = 0; i < 2; i++) {
			int nx = x + dx[i], ny = y + dy[i];
			if (!check(nx, ny)) continue;
			if (used[nx][ny] == c) continue;
			if (a[nx][ny] == '.') continue;
			used[nx][ny] = c;
			q.push({nx, ny});
		}
	}
}

void calc() {
	dp[0][0] = dp[0][1] = dp[1][0] = 0;
	int c = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (a[i][j] == '.') {
				dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]);
			}
			else {
				build(i, j, c);
				for (int x = 1; x <= i; x++) {
					for (int y = 1; y <= j; y++) {
						//if (x == i && y == j) continue;
						if (a[x][y] == '.') continue;
						if (used[x][y] != c) continue;
						chkmin(dp[i][j], dp[x - 1][y] + 1);
						chkmin(dp[i][j], dp[x][y - 1] + 1);
					}
				}
				c++;
			}
		}
	}
	/*cout << "dp = " << endl;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}*/
}

int ans;

void run() {
	build();
	calc();
	ans = dp[n][m];
}

void write() {
	cout << ans << endl;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	read();
	run();
	write();
	return 0;
}

Measured memory_bytes: 384
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns          #-}
{-# LANGUAGE CPP                   #-}
{-# LANGUAGE LambdaCase            #-}
{-# LANGUAGE MagicHash             #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE MultiWayIf            #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE TupleSections         #-}
{-# LANGUAGE TypeFamilies          #-}
{-# LANGUAGE ViewPatterns          #-}

import           Control.Applicative
import           Control.Exception
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString             as B
import qualified Data.ByteString.Builder     as B
import qualified Data.ByteString.Char8       as C
import qualified Data.ByteString.Internal    as B
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import qualified Data.Foldable               as F
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import qualified Data.List                   as L
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Storable         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           GHC.Exts
import qualified System.IO                   as IO
import           Unsafe.Coerce

main :: IO ()
main = do
    [h, w] <- map read.words <$> getLine :: IO [Int]
    B.PS p 0 l <- C.hGetNonBlocking IO.stdin (h*(w+1))
    let mat = U.unsafeFromForeignPtr0 p l
    print $ solve h (w+1) mat

solve :: Int -> Int -> U.Vector Word8 -> Int
solve h w mat = subtract 3 . U.maximum $ U.zipWith (+) lr ud
  where
    trans :: U.Vector Int -> U.Vector Int
    trans m = U.unsafeBackpermute m $ U.generate (h * w) $ \ij ->
        let (i, j) = quotRem ij w
        in j * h + i

    lr :: U.Vector Int
    lr = U.concatMap (\i ->
        let row = U.unsafeSlice (i * w) w mat
        in U.zipWith (+)
            (U.postscanl' (\acc c -> if c /= B.c2w '.' then 0 else acc + 1) 0 row)
            (U.postscanr' (\c acc -> if c /= B.c2w '.' then 0 else acc + 1) 0 row)
        )
        $ U.generate h id

    ud :: U.Vector Int
    ud = trans
        . U.concatMap (\j ->
            let column = U.map (U.unsafeIndex mat) $ U.iterateN h (+w) j
            in U.zipWith (+)
                (U.postscanl' (\acc c -> if c /= B.c2w '.' then 0 else acc + 1) 0 column)
                (U.postscanr' (\c acc -> if c /= B.c2w '.' then 0 else acc + 1) 0 column)
        )
        $ U.generate w id


Measured memory_bytes: 70780
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <map>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; ++i)
typedef long long ll;
typedef pair<int,int> pii;
int main(){
    string s;
    cin >> s;
    int n =(int) s.length();
    string hoge;
    int ans = 0;
    int g=0,p=0;
    rep(i,n){
        if(p<g){
            hoge += 'p';
            p++;
        }else{
            hoge += 'g';
            g++;
        }
    }
    //cout << hoge << endl;
    rep(i,n){
        if(s[i]==hoge[i]){
            continue;
        }else{
            if(s[i]=='p'){
                ans--;
            }else{
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
	while(1){
		int n;
		cin>>n;
		if(n==0) break;
		int a[100];
		lp(i,n){
			cin>>a[i];
		}
		int count=0;
		char x;
		scanf("%c",&x);
		while(1){
			scanf("%c",&x);
			if('A'<=x&&'z'>=x){
				lp(i,a[count]){
					x--;
					if(x==64) x=122;
					if(x==96) x=90;
				}
				cout<<x;
				count++;
				if(count==n) count=0;
			}
			else break;
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 3148
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

//#include <tuple>

//#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long
#define pb push_back

int main() {
  int h, n;
  cin >> h >> n;
  vector<int> a(n), b(n);

  rep(i, n) {
    cin >> a[i] >> b[i];
  }

  vector<ll> dp(h + 1, 1LL<<60);
  dp[0] = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < h; j++) {
      // hpがjにおいて、ダメージa[i]を与えた時のhpを求める
      int k = j + a[i];
      // もしそれ以上の値になる場合は最大値にする
      if (k > h) k = h;
      // もともと入っている値とダメージを与えた場合を比較する
      dp[k] = min(dp[k], dp[j] + b[i]);
    }
  }
  cout << dp[h] << endl;
}


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

#define OnlineJudge1

#define loop(x,a,n) for(int x = a;x < n;x++)
#define NumofDigits(n) ((int)log10(n)+1)
#define CountofNumber(array,n,x)  (upper_bound(array, array+n, x)-lower_bound(array, array+n, x))
#define readline(s) getline(cin,s)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define EPS 1e-7
//#define modulo ll (1e9 + 7)
#define modulo ll (1e6 + 3)
const long double PI = 3.141592653589793238L;


typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,ll> pill;

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

#define time__(d) \
    for ( \
        auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \
        blockTime.second; \
        debug("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false \
    )

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
#ifdef OnlineJudge
    freopen("in.in","r",stdin);
    freopen("out.txt","w",stdout);
#endif
}

int main(){
    init();
    ll n;
    cin >> n;
    cout << 2 * n / __gcd(2ll,n);
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vcha;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)

int main() {
	vcha s(2), t(2);
	int ans = 0;
	rep(i, 3) {
		cin >> s[i];
	}
	rep(i, 3) {
		cin >> t[i];
	}
	rep(i, 3) {
		if (s[i] == t[i])ans++;
	}
	cout << ans << endl;
}

// abc : 141 , aoj : ITP1_6_D
//sort, abs, swap, reverse, max, min
//__gcd, substring, erase, push_back,stoll、stoi

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define INF 1000000000
using namespace std;
int n,mp[100010],dp[100010];
bool visited[100010];

int mk_mp(int ima){
  if(visited[ima]||mp[ima]==-INF) return -INF;
  visited[ima]=1;
  if(mp[ima]!=0) mp[ima]=max(-INF,mp[ima]+mk_mp(ima+mp[ima]));
  if(mp[ima]<-10000000) mp[ima]=-INF;
  visited[ima]=0;
  return mp[ima];
}

int main(){
  cin >> n;
  for(int i=0;i<n;i++)cin>>mp[i];
  for(int i=0;i<n;i++)mp[i]=mk_mp(i);
  for(int i=1;i<=n;i++)dp[i]=-1;

  int cnt=0;
  while(dp[n-1]==-1){
    cnt++;
    for(int i=0;i<n;i++){
      if(dp[i]!=cnt-1)continue;
      for(int j=1;j<=6;j++){
	int nx=i+j;
	while(mp[nx]!=-INF&&mp[nx]!=0)nx+=mp[nx];
	if(mp[nx]!=-INF&&dp[nx]==-1)dp[nx]=cnt;
      }
    }
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 4640
#include <bits/stdc++.h>
 using namespace std;
 typedef long long ll;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;

 int main() {
     int N, K;
     cin >> N >> K;
     vector<int> A(K);
     rep(i, 0, K) cin >> A.at(i);
     cout << ceil((N - 1.0) / (K - 1.0)) << endl;
 }


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

int main(void){
  int n,t;
  int ary[100000];
  
  cin >> n;
  for (int i=1; i<=n; i++){
    cin >> t;
    ary[t-1] = i;
  }
  cout << ary[0];
  for (int i=1; i<n; i++){
    cout << " " << ary[i];
  } cout << endl;
  return 0;
}


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

print(0, flush = True)
s = input()
if s == "Vacant": exit()
else:
    reference_state = s
    opposite_state = ("Male" if s == "Female" else "Female") 
    low, high = 0, N
    count = 1
    while count < 20:
        mid = (low + high)//2
        expected_state = (reference_state if mid % 2 == 0 else opposite_state)
        print(mid, flush = True)
        s = input()
        if s == "Vacant":
            break
        else:
            if s == expected_state: low = mid
            else: high = mid
            count += 1


Measured memory_bytes: 3660
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int n,x,a[4333],mn[5111];
LL ans=Linf;
int main()
{
	get2(n,x);for(int i=1;i<=n;i++){get1(a[i]);a[i+n]=a[i];mn[i+n]=a[i];}
	for(int t=0;t<n;t++)
	{
		LL cur=1ll*t*x;
		for(int i=n+1;i<=n+n;i++)cur+=mn[i]=min(mn[i],a[i-t]);
		ans=min(ans,cur);
	}
	printendl(ans);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int dp[100001];
vector<int> adj[100001];
bool visited[100001];


int dfs(int node)
{
    if(visited[node]) return  dp[node];
    if(adj[node].size()==0) 
    {
        visited[node]=true;
        dp[node] = 0;
        return 0 ;
    }
    visited[node] = true;

    for(auto &sub: adj[node])
    {
        dp[node] = max(dp[node] , 1 + dfs(sub) );
    }
    return dp[node];

}

int main()
{

    int v;
    int e;
    cin >> v;
    cin >> e;
    for (int i = 0; i <= v; i++)
    {
        dp[i] = 0;
        visited[i] = false;
    }
    for (int i = 1; i <= e; i++)
    {
        int a;
        int b;
        cin >> a;
        cin >> b;
        adj[a].push_back(b);
    }

    for (int i = 1; i <= v; i++)
    {
        if(!visited[i])
        {
            dfs(i);
        }
    }

    int *ma;
    ma = max_element(dp, dp + (v + 1));
    cout << *ma << "\n";
}

Measured memory_bytes: 7552
#include <stdio.h>

int main()
{
    int N;
    int d[50];

    int point = 0;

    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &d[i]);
    }

    for (int i = 0; i < N-1; i++) {
        for (int j = i+1; j < N; j++) {
            point += d[i] * d[j];
        }
    }

    printf("%d\n", point);

    return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
ll n;
 
int main() {
  cin >> n;
  string wrong = ":(";
  ll kariX1 = floor(n/1.08);
  ll kariX2 = ceil(n/1.08);
  ll ans = (floor(kariX1*1.08) == n) ? kariX1
          :(floor(kariX2*1.08) == n) ? kariX2 : 0;
  if(ans != 0){
    cout << ans << endl;
  }else{
    cout << wrong << endl;
  }
  return 0;
}

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

int main() {
	int N;cin >> N;
	string S = ((N == 0)?"0":"");
	for (;N!=0;(N-=(abs(N)%2))/=-2)S=((abs(N)%2)?"1":"0")+S;
	cout << S << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int n; cin >> n;
    string s; cin >> s;
    if(n >= 3200) cout << s << endl;
    else cout << "red" << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
# N: 処理する区間の長さ

data0 = [0]*(N+1)
data1 = [0]*(N+1)
# 区間[l, r)に x を加算
def _add(data, k, x):
    while k <= N:
        data[k] += x
        k += k & -k
def add(l, r, x):
    _add(data0, l, -x*(l-1))
    _add(data0, r, x*(r-1))
    _add(data1, l, x)
    _add(data1, r, -x)

# 区間[l, r)の和を求める
def _get(data, k):
    s = 0
    while k:
        s += data[k]
        s %= MOD
        k -= k & -k
    return s
def query(l, r):
    return _get(data1, r-1) * (r-1) + _get(data0, r-1) - _get(data1, l-1) * (l-1) - _get(data0, l-1)

MOD = 998244353


lr = [list(map(int, input().split())) for _ in range(K)]

dp = [0] * (N+10)
add(1, 2, 1)
for i in range(1, N+1):
    dp[i] = query(i, i+1) % MOD
    for l, r in lr:
        if i+l > N+1: continue
        add(l+i, min(i+r+1, N+1), dp[i])
    

print(dp[N])


Measured memory_bytes: 74340
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-09 16:33:37
*/

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

#define all(x) (x).begin(),(x).end()
#define rev(x) greater<x>()
#define MOD 1000000007
#define INF 1000000000

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;
    }
}

LL modpower(LL n, LL m, LL mod)
{
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod)
{
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod)
{
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

int gcd(int k, int l)
{
    if (l > 0) return gcd(l, k%l);
    else return k;
}

struct UnionFind
{
    vector<int> par;

    UnionFind(int n) : par(n) {
        for (int i = 0; i < n; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main()
{
    int n, m;
    cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    cin >> m;
    vector<string> t(m);
    for (int i = 0; i < m; i++) {
        cin >> t[i];
    }

    map<string, int> bl, rd;
    for (int i = 0; i < n; i++) bl[s[i]]++;
    for (int i = 0; i < m; i++) rd[t[i]]++;

    int ans = 0;
    for (const auto &x : bl) {
        int pt = x.second - rd[x.first];
        if (pt > ans) ans = pt;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  int L,R;
  cin >> L >> R;
  int l_mod = L%2019;
  int r_mod = R%2019;
  vector<vector<int> > table(2019,vector<int>(2019));
  rep(i,2019)rep(j,2019) table[i][j] = (i*j) % 2019;
  int ans = 2019;
  if(L/2019 != R/2019){
    cout<<0<<endl;
    return 0;
  }
  for(int i=l_mod;i<r_mod;i++)
    for(int j=i+1;j<=r_mod;j++)
      ans = min(ans,table[i][j]);
  cout<< ans << endl;
}



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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

bool isSame(string S, string T){
    rep(i,S.size()){
        if(S[i] != T[i]) return false;
    }
    return true;
}

int main()
{
    string S, T; cin >> S >> T;
    if(isSame(S, T)) cout << "Yes" << endl;
    else cout << "No" << endl;
}   

Measured memory_bytes: 3632
import java.util.*

fun main(args: Array<String>) {
    val cin = Scanner(System.`in`)
    val N = cin.nextInt()
    val Y = cin.nextInt()

    for (x in 0..N) {
        for (y in 0..N-x) {
            val z = N - x - y
            if(10000*x + 5000*y + 1000*z == Y) {
                println("%d %d %d".format(x,y,z))
                return
            }
        }
    }
    println("-1 -1 -1")
}

Measured memory_bytes: 31396
#include<bits/stdc++.h>  
typedef long long ll;  
using namespace std;  
const ll INF = 1LL<<32;  
int n,e;  
ll dp[110][110];  
void floyd(){  
    for(int k = 0 ; k<n ; k++){  
        for(int i = 0 ; i<n ; i++){  
            if(dp[i][k] == INF)  
                continue;  
            for(int j = 0 ; j<n ; j++){  
                if(dp[k][j] == INF)  
                    continue;  
                dp[i][j] = min(dp[i][j] , dp[i][k]+dp[k][j]);  
            }  
        }  
    }  
}  
int main(){  
    
    cin>>n>>e;  
      
    for(int i = 0 ; i<n ; i++){  
        for(int j = 0 ; j<n ; j++){  
            if(i == j)  
                dp[i][j] = 0;  
            else  
                dp[i][j] = INF;   
        }  
    }  
      
    for(int i = 0 ; i<e ; i++){  
        int s,t,d;  
        cin>>s>>t>>d;  
        dp[s][t] = d;  
    }  
      
    floyd();  
      
    bool flag = 0;  
    for(int i = 0 ; i<n ; i++){  
        if(dp[i][i] < 0){  
            flag = 1;  
            break;  
        }  
    }  
    if(flag){  
        cout<<"NEGATIVE CYCLE"<<endl;  
    }  
    else{  
        for(int i = 0 ; i<n ; i++){  
            for(int j = 0 ; j<n ; j++){  
                if(j) cout<<" ";  
                if(dp[i][j] == INF){  
                    cout<<"INF";  
                }  
                else  
                    cout<<dp[i][j];  
            }  
            cout<<endl;  
        }  
    }  
      
    return 0;  
}  



Measured memory_bytes: 3196
#include<bits/stdc++.h>
#define mp make_pair
#define F first
#define S second
using namespace std;

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<int> vi;

const int MAXN = 102;
int n;
double x[MAXN], y[MAXN], s1, s2, s3, s00;

int main(){
//	freopen(".in", "r", stdin);
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin >> n;
	for(int i=0; i<n; i++)
		cin >> x[i];
	for(int i=0; i<n; i++)
		cin >> y[i];

	for(int i=0; i<n; i++){
		double d = abs(x[i] - y[i]);
		s1 += d;
		s2 += d*d;
		s3 += d*d*d;
		s00 = max(s00, d);
	}

	cout << setprecision(6) << fixed;

	cout << s1 << '\n' << pow(s2, 1.0/2) << '\n' << pow(s3, 1.0/3) << '\n' << s00 << '\n';

	return 0;
}


Measured memory_bytes: 3428
import numpy as np
N = int(input())
p = np.array(list(map(int, input().split())))
v = p == np.arange(1, N + 1)
# print('v', v)
ans = 0
for i in range(N):
    if i == N - 1 and v[i]:
        ans += 1
        continue
    if v[i]:
        v[i], v[i + 1] = False, False
        ans += 1
print(ans)


Measured memory_bytes: 23416
import numpy as np
import fractions

def q74(N, X, x):
    y = np.array(x)
    z = abs(y - X)
    
    ans = z[0]
    for i in range(1, N):
        ans = fractions.gcd(ans, z[i])
    return ans


N, X= [int(i) for i in input().split()]
x = [int(i) for i in input().split()]


print(q74(N, X, x))

Measured memory_bytes: 25000
#if 0
date +%Y.%m.%d

题解先咕着。
#endif
#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long lolong;
inline int input() { int x; scanf("%d", &x); return x; }

lolong dfs(lolong a, lolong b, lolong d) {
	if(not a) return d == 0 ? 10 : 0;
	if(d < 0) d = - d;
	lolong c = a * b;
	int x = d / c;
	int max = b == 1 ? 9 : 10;
	if(a == 9)
		return x * c == d ? std::max(max - x, 0) : 0;
	lolong res = std::max(max - x, 0) * dfs(a / 100, b * 10, d - x * c);
	x ++;
	res += std::max(max - x, 0) * dfs(a / 100, b * 10, d - x * c);
	debug("%lld, %lld, %lld: %lld\n", a, b, d, res);
	return res;
}

int main() {
	lolong ans = 0, d = input();
	for(lolong a = 999999999999999999; a; a /= 10)
		ans += dfs(a, 1, d);
	printf("%lld\n", ans);
}

Measured memory_bytes: 128
class Queue(object):

    def __init__(self):
        self.queue_list = []

    def enqueue(self, value):
        self.queue_list.append(value)

    def dequeue(self):
        try:
            # 先頭をとりだす
            value = self.queue_list.pop(0)
        except IndexError:
            value = None

        return value
N = int(input())

pair = []
tree = {}

for _ in range(N-1):
    a, b = list(map(int, input().split(" "))) 
    if a in tree.keys():
        tree[a].append(b)
    else:
        tree[a] = [b]
        
    if b in tree.keys():
        tree[b].append(a)
    else:
        tree[b] = [a]
    pair.append([a,b])
    
c = list(map(int, input().split(" ")))
c.sort(reverse=True)
c = c[:N+2]


queue = Queue()
tree_l = {}
for key in tree.keys():
    tree_l[key] = len(tree[key])

ans = {}
max_node = max((v, k) for k, v in tree_l.items())[1]
ans[max_node] = c[0]
used = [max_node]
cnt = 0

candi = {}
for i in tree[max_node]:
    candi[i] = tree_l[i]

for k, v in sorted(candi.items(), key=lambda x: -x[1]):
    queue.enqueue(k)
    used.append(k)

while True:
    node = queue.dequeue()
    cnt += 1
    ans[node] = c[cnt]
    
    if cnt == N-1:
        break
    
    candi = {}
    for i in tree[node]:
        candi[i] = tree_l[i]
    for k, v in sorted(candi.items(), key=lambda x: -x[1]):
        if k not in used:
            queue.enqueue(k)
            used.append(k)
total = 0
for a, b in pair:
    if ans[a] > ans[b]:
        total += ans[b]
    else:
        total += ans[a]
        
print(total)
for i in range(1, N, 1):
    print(ans[i], end=" ")

print(ans[N])

Measured memory_bytes: 8584
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<vector>
#define inf 2147483647
#define rep(i,a,b) for(int i=a;i<b;i++)
#define  rr read()
#define ll long long
#define repb(i,a,b) for(int i=a;i<=b;i++)
#define CloseIo   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
int read()
{
    char ch = getchar();
	int x = 0, f = 1;
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while('0' <= ch && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}
const int N=1e5+5;
int a[N];
int main()
{
int n=rr;
for(int i=0;i<n;i++)
a[i]=rr;
int ans=0;
for(int i=1;i<n-1;i++)
{
	if(a[i]>a[i-1]&&a[i]<a[i+1]||a[i]<a[i-1]&&a[i]>a[i+1])
	ans++;
}
cout<<ans;
}




Measured memory_bytes: 256
import bisect

n = int(input())
l = sorted([int(x) for x in input().split()])

res = (n * (n-1) * (n-2)) // 6
for i in range(n-2):
    a = l[i]
    for j in range(i+1, n-1):
        b = l[j]
        res -= n - bisect.bisect_left(l, a+b)

print(res)

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>

const int N = 10001, E = 100001;

struct Edge{
	int u, v, cost;
	bool operator<(const Edge& e) const {
		return cost < e.cost;
	}
};

int rank[N], par[N];
Edge edge[E];
int n, e;

void init(int n){
	for(int i = 0; i < n; ++i){
		par[i] = i;
		rank[i] = 0;
	}
}

int find(int x){
	if(par[x] == x)return x;
	else return par[x] = find(par[x]);
}

void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x == y) return;
	
	if(rank[x] < rank[y]){
		par[x] = y;
	}else{
		par[y] = x;
		if(rank[x] == rank[y])++rank[x];
	}
}

bool same(int x, int y){
	return find(x) == find(y);
}

long long kruskal(){
	std::sort(edge, edge + e);
	init(n);
	long long res = 0;
	for(int i = 0; i < e; ++i){
		if(!same(edge[i].u, edge[i].v)){
			unite(edge[i].u, edge[i].v);
			res += edge[i].cost;
		}
	}
	return res;
}
	
int main(){
	std::cin >> n >> e;
	
	for(int i = 0; i < e; ++i){
		int a, b, c;
		std::cin >> a >> b >> c;
		edge[i] = {a, b, c};
	}
	
	std::cout << kruskal() << std::endl;

	return 0;
}

Measured memory_bytes: 4340
n = gets.chomp.to_i
hArr = gets.chomp.split.collect{ |item| item.to_i}

maxc = 0
nowc = 0
nowh = hArr[0]
1.upto(n-1) do |ni|
  if hArr[ni] <= nowh
    nowc += 1
    nowh = hArr[ni]
    maxc = nowc if nowc >= maxc
  else
    maxc = nowc if nowc >= maxc
    nowh = hArr[ni]
    nowc = 0
  end
end

puts maxc


Measured memory_bytes: 9604
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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 (b<a) { a=b; return 1; } return 0; }

ll N,x,pre,A,ans;

int main(){
    cin>>N>>x;
    rep(i,N){
        cin>>A;
        if(i){
            if(pre+A>x){
                    ans+=pre+A-x;
                    if(x-pre<0)pre=0;
                    else pre=x-pre;
            }
            else pre=A;
        }
        else pre=A;

    }
    out(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
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;
}

template <class T> vector<T> factoring(T N) {
    vector<T> ans;
    T mx = N;
    T i  = 2;
    while (i * i <= N) {
        if (N % i == 0) {
            ans.push_back(i);
            N /= i;
        } else {
            i++;
        }
    }
    ans.push_back(N);
    return ans;
}

template <class T> vector<T> divisor(T N) {
    vector<T> ans;
    for (T i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ans.push_back(i);
            if (i != 1 && i * i != N) {
                ans.push_back(N / i);
            }
        }
    }
    ans.push_back(N);

    return ans;
}

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

    ll N;
    cin >> N;

    auto div = divisor(N);
    int ans  = INF32;
    REP(i, div.size()) {
        ll a = div[i];
        ll b = N / a;
        if (N % a != 0 || b < a)
            continue;
        string str = to_string(b);
        chmin(ans, (int)str.size());
    }

    std::cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<iomanip>
#include <set>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <queue>
#include <stack>
using namespace std;

const int NN=1e5+10;



int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    double ans=0;
    for(int i=1;i<=n;i++){
        int t=i;
        double numm=1.0/n;
        while(t<k){
            numm=numm*0.5;
            t=t<<1;
        }
        ans+=numm;
    }
    cout<<setprecision(12)<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
vector<vector<int> > nyu(int h, int w) {
	vector<vector<int> > a(h + 2, vector<int>(w + 2, h*w + 1));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a[i + 1][j + 1];
		}
	}
	return a;
}
vector<int> nyu1(int n) {
	vector<int> c(n);
	for (int i = 0; i < n; i++) {
		cin >> c[i];
	}
	return c;
}
int main() {
	int n;
	cin >> n;
	vector<int> p(n);
	p = nyu1(n);
	sort(p.begin(), p.end());
	p[n - 1] = p[n - 1] / 2;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += p[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

#include<algorithm>


using namespace std ;



int ans[ 100 + 1 ][ 10000 + 1 ] ;

int w ;
int v ;


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


	int i ,j ;
	for( i = 1 ; i <= n ; ++i )
	{
		scanf( "%d %d" ,&v ,&w ) ;


		for ( j = 1 ; j <= W ; ++j )
		{
			ans[ i ][ j ] = j - w < 0 ? ans[ i - 1 ][ j ] : max( ans[ i - 1 ][ j ], ans[ i - 1 ][ j - w ] + v );
		}
	}


	printf( "%d\n" ,ans[ n ][ W ] ) ;


	return 0 ;
}

Measured memory_bytes: 6644
import bisect
import sys
import math
from collections import deque
from heapq import heappush, heappop

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29

DIV = (10**9) + 7


def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV()


def cumsum(As):
    s = 0
    for a in As:
        s += a
        yield s


sys.setrecursionlimit(200005)


def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost


def main():
    H1,M1,H2,M2,K = isRaw()
    D = (H2*60+M2)-(H1*60+M1)
    print(max(0,D-K))

main()


Measured memory_bytes: 65920