akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <sstream>
#include <fstream>

using namespace std;

#define A first
#define B second
#define all(x) (x).begin(), (x).end

typedef long long ll;
constexpr int MOD = 1000000007;
constexpr int MAX_SIZE = 1e5 + 5;
vector<int> adj[MAX_SIZE];
int dp[MAX_SIZE];
bool visited[MAX_SIZE];

void dfs(int v){
  visited[v] = true;
  for(int u: adj[v]){
    if(!visited[u]) dfs(u);
    dp[v] = max(dp[v], dp[u] + 1);
  }
}

void solve() {
  int N, M;
  cin >> N >> M;
  for(int i = 0; i < M; i++){
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
  }
  for(int i = 1; i <= N; i++){
    if(!visited[i]) dfs(i);
  }
  int ans = 0;
  for(int i = 1; i <= N; i++){
    ans = max(ans, dp[i]);
  }
  cout << ans;

}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int T;
  T = 1;
  //cin >> T;
  while(T--){
    solve();
  }
}

Measured memory_bytes: 12212
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; n>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'
template <class T> bool updmax(T& a, T b) { if (b > a) { a = b; return true;} return false;}
template <class T> bool updmin(T& a, T b) { if (b < a) { a = b; return true;} return false;}

int main() {
    fastio;
    ll ans=0;
    ll a,b;
    cin >> a >> b;
    ans = a*b / gcd(a,b);
    cout << ans << endl;
}

Measured memory_bytes: 3624
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
  
x, y = map(int,input().split())
x_pr = prime_factorize(x)
y_pr = prime_factorize(y)
z = set(x_pr) & set(y_pr)
print(len(z)+1)

Measured memory_bytes: 3064
#![allow(unused)]

use std::{cell, cmp, collections, convert, fmt, io, iter, ops, str};

use cell::{Cell, RefCell};
use cmp::Ordering::{Equal, Greater, Less};
use collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};
use io::{Read, Write};

#[cfg(feature = "debug")]
macro_rules! debug {
    ($($args: tt)*) => { eprint!($($args)*) };
}

#[cfg(feature = "debug")]
macro_rules! debugln {
    ($($args: tt)*) => { eprintln!($($args)*) };
}

#[cfg(not(feature = "debug"))]
macro_rules! debug {
    ($($args:tt)*) => {};
}

#[cfg(not(feature = "debug"))]
macro_rules! debugln {
    ($($args:tt)*) => {};
}

macro_rules! imax {
    ($v:expr) => {
        $v.iter().max().unwrap()
    };
}

macro_rules! vmax {
    ($x: expr, $y: expr) => { cmp::max($x, $y) };
    ($x: expr, $($args: expr),*) => { cmp::max($x, vmax!($($args),*)) };
}

macro_rules! imin {
    ($v:expr) => {
        $v.iter().min().unwrap()
    };
}

macro_rules! vmin {
    ($x: expr, $y: expr) => { cmp::min($x, $y) };
    ($x: expr, $($args: expr),*) => { cmp::min($x, vmin!($($args),*)) };
}

fn main() {
    let tasks = parse_vec::<i32>();

    println!("{}", imax!(tasks) - imin!(tasks));
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test() {
        //
    }
}

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().to_owned()
}

fn read_word() -> String {
    const CAPACITY: usize = 16;

    let mut stdin = io::stdin();
    let mut byte: [u8; 1] = [0];

    loop {
        let mut buf = Vec::with_capacity(CAPACITY);

        loop {
            let res = stdin.read(&mut byte);

            if res.unwrap_or(0) == 0 || byte[0] <= b' ' {
                break;
            } else {
                buf.push(byte[0]);
            }
        }

        if !buf.is_empty() {
            return String::from_utf8(buf).unwrap();
        }
    }
}

fn parse_line<T: str::FromStr>() -> T {
    read_line().parse().ok().unwrap()
}

fn parse_word<T: str::FromStr>() -> T {
    read_word().parse().ok().unwrap()
}

fn parse_vec<T: str::FromStr>() -> Vec<T> {
    read_line()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn flush() {
    io::stdout().flush();
}

fn next_prime(x: i32) -> i32 {
    for i in (x + 1).. {
        if is_prime(i) {
            return i;
        }
    }

    panic!("attempt to add with overflow");
}

fn is_prime(x: i32) -> bool {
    let ceil = f64::from(x).sqrt().ceil() as i32;
    x == 2 || (2..(ceil + 1)).all(|i| x % i != 0)
}

fn bit_high(bits: u64, pos: u64) -> bool {
    bits & (1 << pos) != 0
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int N;
    cin >> N;
    cout << (N - 2) * 180 << endl;
}

Measured memory_bytes: 256
import sys

# input処理を高速化する
input = sys.stdin.readline

def main():
    N = int(input())
    lst_a = list(map(int, input().split()))
    one, two, three = lst_a.count(1), lst_a.count(2), lst_a.count(3)

    # dp[i][j][k] := 残り1個の皿がi枚、2個の皿がj枚、3個の皿がk枚の状態から、
    # 寿司をすべてなくすのに必要な操作回数の期待値
    dp = [[[0.0] * (N+1) for _ in range(N+1)] for _ in range(N+1)]

    for k in range(three + 1):
        for j in range(two + three + 1  - k):
            for i in range(one + two + three + 1 - k -j):
                if i == 0 and j == 0 and k == 0:
                    continue
                tmp = N * 1.0
                if i > 0:
                    tmp += i * dp[i -1][j][k]
                if j > 0:
                    tmp += j * dp[i + 1][j - 1][k]
                if k > 0:
                    tmp += k * dp[i][j + 1][k -1]
                dp[i][j][k] = tmp / (i + j + k)

    print(dp[one][two][three])


main()

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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT_ON(bit, i) (((bit >> i) & 1) > 0)

typedef long long LL;
template<typename T> std::vector<T> make_v(size_t a){return std::vector<T>(a);}
template<typename T,typename... Ts> auto make_v(size_t a, Ts... ts){ return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}    // C++14
template<typename T,typename V> typename std::enable_if<std::is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename std::enable_if<std::is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }
template<typename T> T &chmin(T &a, const T &b) { return a = std::min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = std::max(a, b); }

template<class T> inline std::vector<T> unique(std::vector<T> v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    return v;
}
// 初項s, 交差dのn個の数列の和
long long sum_of_arithmetic_progression(long long s, long long d, long long n) {
    return n * (2 * s + (n - 1) * d) / 2;
}

const int INF = 1 << 30;
const double EPS = 1e-9;
const long double PI = acos(-1.0);
const std::vector<int> dy4 = {0, -1, 0, 1}, dx4 = {1, 0, -1, 0};
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };


using namespace std;

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

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


    auto H = make_v<int>(N);
    FOR(i, 0, N) {
        cin >> H[i];
    }

    auto dp = make_v<LL>(N + 100);
    fill_v(dp, LONG_LONG_MAX);
    dp[0] = 0;
    FOR(i, 0, N) {

        FOR(j, 1, K + 1) {
            if (i + j < N) {
                chmin(dp[i + j], dp[i] + abs(H[i] - H[i + j]));
            }
        }
    }
    print(dp[N - 1]);

    return 0;
}



Measured memory_bytes: 1408
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
      
N,M=map(int,input().split())
uf=UnionFind(N)
for i in range(M):
  a,b=map(int,input().split())
  uf.union(a-1,b-1)
print(uf.group_count()-1)

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

int main(){
    string s;
    cin >> s;

    for(auto i = 0; i < s.size() / 2; i++){
        if(s[i] != s[s.size() - i - 1]) {
            cout << "No" << endl;
            return 0;
        }
    }

    string tmp_front = s.substr(0, s.size() / 2);
    string tmp_back = s.substr(s.size() / 2 + 1, s.size() / 2);
    for(auto i = 0; i < tmp_front.size() / 2; i++) {
        if (tmp_front[i] != tmp_front[tmp_front.size() - i - 1]) {
            cout << "No" << endl;
            return 0;
        }
    }
    for(auto i = 0; i < tmp_back.size() / 2; i++) {
        if(tmp_back[i] != tmp_back[tmp_back.size() - i - 1]) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

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

using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	int ansac = 0, answa = 0;
	int cnt[100000 + 100] = {};
	for (int i = 0; i < M; i++) {
		int p;
		char c1, c2;
		cin >> p >> c1 >> c2;
		p--;
		if (c1 == 'A' && cnt[p] != -1) {
			ansac++;
			answa += cnt[p];
			cnt[p] = -1;
		}
		else if (c1 == 'W' && cnt[p] != -1) {
			cnt[p]++;
		}
	}
	cout << ansac << " " << answa << endl;
	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long LL;
#define M(a,b) memset(a,b,sizeof(a))
#define pb push_back
const int maxn = 100000+10;
const LL mod = 1000000007;
int a[maxn];
int cnt[maxn];
int main() {

    int n;
    scanf("%d",&n);
    for (int i=1;i<=n;++i) {
        scanf("%d",a+i);
        ++cnt[a[i]];
    }
    int ans=0;
    for (int i=1;i<=n;++i) {
        if (cnt[a[i]]>=2) {
            ans+=cnt[a[i]]-1;
            cnt[a[i]]=0;
        }
    }
    (ans&1)&&(++ans);
    printf("%d\n",n-ans);
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>

long long int power(long long int x, long long int n, long long int M) {
	long res =1;
	if(n > 0){
		res = power(x, n / 2, M);
		if(n % 2 == 0){
			res = (res * res) %M;
		}else{
			res = (((res * res) % M) * x) % M;
		}
	}
	return res;
}
int main() {
	long long int m, n;
	scanf("%lld %lld", &m, &n);
	printf("%lld\n", power(m, n, 1000000007));
	return 0;
}


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

int main() {
    int N,T;
    int count=0;
    cin >>N>>T;
    map<int,int>mp;
    for(int i=0;i<N;i++){
        int c,t;
        cin >>c>>t;
        mp[c]=t;
        if(t>T)mp.erase(c);
        else count++;
    }
    if(count ==0){
    cout<<"TLE"<<endl;
    return 0;
    }
    for(auto p:mp){
        cout <<p.first<<endl;
        break;
    }
}

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

using namespace std;
typedef long long ll;
ll t , k,n,x , y , a, b,c , d ,sum;
string s;
char ch;
int main()
{

    cin >> n>>k;
    int arr[n];
    for(int i = 0 ; i < n ;i++)cin >> arr[i];
    sort(arr, arr+n);
    for(int i = 0 ; i  < k ;i++)
    {
        x+=arr[i];
    }
    cout <<x;
    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<iomanip>
int main()
{
	int a, b;
	std::cin >> a >> b;
	std::cout << std::fixed << std::setprecision(10);
	std::cout << a / b << ' ' << a - a / b*b << ' ' << (double)a / b << std::endl;
	return 0;
}


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

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

    int a,b,c;
    cin>>a>>b>>c;

    int q = a - b;
    if(q<=c){
        cout << c - q << endl;
    }else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
map<int,int> a;
vector<int> b;
int main()
{
  int i,n,sum=0,k;
  cin>>n;
  for(i=1;i<=n;i++)
  {
    cin>>k;
    if(a[k]==0) 
	  b.push_back(k);
    a[k]++;
  }
  for(i=0;i<b.size();i++) 
    if(a[b[i]]>=b[i]) 
	  sum+=a[b[i]]-b[i]; 
	else 
	  sum+=a[b[i]];
  cout<<sum;
  return 0;
}

Measured memory_bytes: 5112
#include<bits/stdc++.h>
using namespace std;
int main()
{
    float d,t,s;
    cin>>d>>t>>s;
    float res=d/s;
    if(res<=t)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
     
} 

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

// Define
using ll = int64_t;
using ul = uint64_t;
using ld = long double;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ul MAX = ULONG_MAX;
const char nl = '\n';

#define elif else if
#define def inline auto
#define run __attribute__((constructor)) def _

// Debug
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i < _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i > _##i; --i)
#define rep(i, n) inc(i, 0, n)
#define be(c) begin(c), end(c)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("-O3")
#pragma GCC target("avx")

// Math
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

signed main(){
    using pii = pair<int, int>;
    int N, M;
    cin >> N >> M;
    map<int, set<pii>> mss;
    rep(i, M) {
        int p, y;
        cin >> p >> y;
        mss[p].insert(make_pair(y, i));
    }
    vector<int> ps(M), ys(M);
    for(const auto& e : mss) {
        int ord = 0;
        for(const auto& s: e.second) {
            int index = s.second;
            ps[index] = e.first;
            ys[index] = ++ord;
        }
    }
    rep(i, M) {
        printf("%06d%06d\n", ps[i], ys[i]);
    }
}


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

using namespace std;
using ll = long long;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long N, std::vector<std::string> s){
  ll ans = 0;
  ll a = 0;
  ll b = 0;
  ll c = 0;
  for(int i=0; i<N; i++) {
    if(*s[i].begin() == 'B' and *s[i].rbegin() != 'A')
      b++;
    if(*s[i].begin() != 'B' and *s[i].rbegin()=='A')
      a++;
    if(*s[i].begin() == 'B' and *s[i].rbegin()=='A')
      c++;
      
    for(int j=0; j+1<s[i].size(); j++) {
      if(s[i][j]=='A' and s[i][j+1]=='B')
	ans++;
    }
  }
  if(a==0 and b==0 and c > 0)
    std::cout << ans+c-1 << std::endl;
  else if(a==0 and b==0 and c==0)
    std::cout << ans << std::endl;
  else
    std::cout << ans+min(a+c, b+c) << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  std::vector<std::string> s(N);
  for(int i = 0 ; i < N ; i++){
    std::cin >> s[i];
  }
  solve(N, std::move(s));
  return 0;
}


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

using namespace std;

long long A[200001], S[200001];

long long sum(int l, int r)
{
  return S[r] - S[l - 1];
}

int main()
{
  int N;
  scanf("%d", &N);
  
  A[0] = S[0] = 0;
  for (int i = 1; i <= N; i++) {
    scanf("%lld", A + i);
    S[i] = A[i] + S[i - 1];
  }
  
  long long ans = 1e18;
  int lpt = 1, rpt = 3;
  for (int i = 2; i <= N - 2; i++) {
    while (lpt != i - 1 && abs(sum(1, lpt + 1) - sum(lpt + 2, i)) < abs(sum(1, lpt) - sum(lpt + 1, i))) lpt++;
    if (rpt == i) rpt++;
    while (rpt != N - 1 && abs(sum(i + 1, rpt + 1) - sum(rpt + 2, N)) < abs(sum(i + 1, rpt) - sum(rpt + 1, N))) rpt++;
    long long t[4] = {sum(1, lpt), sum(lpt + 1, i), sum(i + 1, rpt), sum(rpt + 1, N)};
    ans = min(ans, *max_element(t, t + 4) - *min_element(t, t + 4));
  }
  
  printf("%lld\n", ans);
  
  return 0;
}


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

siritolist = []

for i in range(N):
    W = input()
    siritolist.append(W)

for i in range(1, len(siritolist)):
    back_word = list(siritolist[i-1])
    word = list(siritolist[i])
    if back_word[-1] == word[0] and i > 1:
        for j in range(i-1):
            if siritolist[i] == siritolist[j]:
                print('No')
                exit()
    elif back_word[-1] != word[0]:
        print('No')
        exit()

print('Yes')

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    # divisors.sort()
    return divisors

ans = 0
for i in range(1, N+1, 2):
    # print(i)
    divs = make_divisors(i)
    if len(divs) == 8:
        ans += 1

print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)  
#define rep(i,n) for(ll (i)=0;(i)<(n);++(i))
#define ref(i,a,b) for (ll (i)=(a); (i)<=(b); ++(i))
#define INF 0xFFFFFF
#define endl '\n'
#define pp printf("Case %d: \n",t)
const unsigned int mod = 1e9+7;
const int mx=100005;
const int maxInt = 2147483647;
long long int dp[mx];
long long int a[mx];
ll n,k;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin >> n >> k;
    rep(i,n)cin >> a[i];
    rep(i,mx)dp[i]=1000000005;
    dp[0]=0;
    for(int i=1;i<n;++i){
    	for(int j=1;j<=k;++j)
 	   		if((i-j)>=0){
    			dp[i]=min(dp[i-j]+abs(a[i]-a[i-j]),dp[i]);
    			//cout << dp[i] << "  ";
		 	}			
    }

    cout << dp[n-1] << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define endl '\n'
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define mod 1000000007
#define FASTIO ios::sync_with_stdio(0); cin.tie(0);
#define REP(i,a,b) for(int i=a;i<b;i++)

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

int main(){
    FASTIO
    int x,y,b;
    cin>>x>>y;
    REP(a,0,x+1){
      b=x-a;
      if(2*a+4*b==y){cout<<"Yes";return 0;}
    }
    cout<<"No";
    return 0;
}


Measured memory_bytes: 3608
import java.io.*;
import java.util.StringTokenizer;
 
class Main {
  public static void main(String args[]) {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String buf;
    try {
      while ((buf = br.readLine())!=null) {
        double x[] = new double[4];
        double y[] = new double[4];
        StringTokenizer st = new StringTokenizer(buf);
        for (int i=0;i<4;i++) {
          x[i] = Double.parseDouble(st.nextToken());
          y[i] = Double.parseDouble(st.nextToken());
        }
        double vx[] = new double[2];
        double vy[] = new double[2];
        vx[0] = x[1]-x[0];
        vy[0] = y[1]-y[0];
        vx[1] = x[3]-x[2];
        vy[1] = y[3]-y[2];
        double  dif = vx[0]*vx[1]+vy[0]*vy[1];
        if (Math.abs(Math.round(dif*Math.pow(100000,2)))==0) System.out.println("YES");
        else System.out.println("NO");
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

Measured memory_bytes: 24360
n,k=map(int,input().split())
r,s,p=map(int,input().split())
T=input()

#じゃんけんの実装
def R(i):
    if T[i-1]==("s"):
        return r
    else:
        return 0
def S(i):
    if T[i-1]==("p"):
        return s
    else:
        return 0

def P(i):
    if T[i-1]==("r"):
        return p
    else:
        return 0

dp=[[0]*3 for _ in range(n+1)]
dp[0][0],dp[0][1],dp[0][2]=0,0,0
for i in range(1,k+1):
    dp[i][0]=max(dp[i-1][0],dp[i-1][1],dp[i-1][2])+R(i)
    dp[i][1]=max(dp[i-1][0],dp[i-1][1],dp[i-1][2])+S(i)
    dp[i][2]=max(dp[i-1][0],dp[i-1][1],dp[i-1][2])+P(i)
    
#dp[n回目のジャンケンか][どの手で勝つか]=n回目のジャンケン後の点数の最大値
for i in range(0,n-k):
    if T[i]!="r":
        dp[i+k+1][2]=max(dp[i+k])+P(i+k+1)
    else:
        if dp[i+1][2]==0:
            dp[i+k+1][2]=max(dp[i+k])+P(i+k+1)
    if T[i]!="s":
        dp[i+k+1][0]=max(dp[i+k])+R(i+k+1)
    else:
        if dp[i+1][0]==0:
            dp[i+k+1][0]=max(dp[i+k])+R(i+k+1)

    if T[i]!="p":
        dp[i+k+1][1]=max(dp[i+k])+S(i+k+1)
    else:
        if dp[i+1][1]==0:
            dp[i+k+1][1]=max(dp[i+k])+S(i+k+1)

    
print(max(dp[n]))


Measured memory_bytes: 22476
#include<bits/stdc++.h>
using namespace std;
 
int n,a[109],b[109];
void gg(){
	puts("Impossible"); exit(0);
}
int main(){
	scanf("%d",&n);
	int i,m=0;
	for (i=1; i<=n; i++){
		scanf("%d",&a[i]); b[a[i]]++;
		m=max(m,a[i]);
	}
	for (i=0; i<=m; i++){
		if (!b[max(i,m-i)]) gg();
		b[max(i,m-i)]--;
	}
	int mn=m+3>>1;
	for (i=0; i<mn; i++) if (b[i]) gg();
	puts("Possible");
	return 0;
}

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




public class Main
{
	
	
	
	static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));	

	static int n;
	static int[] val,wght;
	static long[][] dp;

	// static int find(int weight,int indx)
	// {
	// 	if(weight<=0 || indx>=n)
	// 		return 0;
	// 	if(dp[weight][indx]>0)
	// 		return dp[weight][indx];
	// 	if(wght[indx]<=weight)
	// 		return dp[weight][indx]=Math.max(val[indx]+find(weight-wght[indx],indx+1),find(weight,indx+1));
	// 	return dp[weight][indx]=find(weight,indx+1);

	// }
	

		
	public static void main(String[] args)throws IOException{
		

			int t=1;
			while(t-->0)
			{
				String[] s=br.readLine().split(" ");
				n=Integer.parseInt(s[0]);
				int w=Integer.parseInt(s[1]);
				val=new int[n];
				wght=new int[n];
				dp=new long[w+1][n];

				for(int i=0;i<n;i++)
				{
					s=br.readLine().split(" ");
					wght[i]=Integer.parseInt(s[0]);
					val[i]=Integer.parseInt(s[1]);
				}

				for(int i=1;i<=w;i++)
				{
					for(int j=0;j<n;j++)
					{
						if(j!=0)
						{
							if(wght[j]<=i)
							{
								dp[i][j]=Math.max(val[j]+dp[i-wght[j]][j-1],dp[i][j-1]);
							}
							else
								dp[i][j]=dp[i][j-1];
						}
						else
						{
							if(wght[0]<=i)
								dp[i][j]=val[j];
						}
					}
				}


				System.out.println(dp[w][n-1]);


			}








	}
	
}

Measured memory_bytes: 126416
"""
何回足されるかで考えればよい。
真っ二つに切っていく。

各項は必ずM未満。
M項以内に必ずループが現れる。
"""
N,X,M = map(int,input().split())
memo1 = set()
memo2 = []
ans = 0
a = X
flag = True
rest = N
while rest > 0:
    if a in memo1 and flag:
        flag = False
        for i in range(len(memo2)):
            if memo2[i] == a:
                loopStart = i
        setSum = 0
        for i in range(loopStart,len(memo2)):
            setSum += memo2[i]**2 % M
        loopStep = len(memo2)-loopStart
        loopCount = rest // loopStep
        ans += loopCount*setSum
        rest -= loopCount*loopStep
    else:
        memo1.add(a)
        memo2.append(a)
        ans += a
        a = a**2%M
        rest -= 1

print(ans)

Measured memory_bytes: 80000
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

ll a[10001],b[10001];
int main(){
    int n;
    ll lsum=0,rsum=0;
    cin>>n;
    rep(i,n) cin>>a[i];
    rep(i,n) cin>>b[i];
    rep(i,n){
        ll x=b[i]-a[i];
        if(x<0) lsum+=-x;
        if(x>0) rsum+=x/2*2;
    }
    if(rsum>=lsum*2) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

signed main(void){
  
  int N,A,B; cin >> N >> A >> B;
  int c = N/(A+B);
  
  int ans = c*A;
  
  int res = N%(A+B);
  
  ans += min(res,A);
  
  cout << ans << endl;
  
  return 0;
}


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

int main() {
  int N ;
  cin >> N  ;
  
  if ( N < 10){
     cout << N << endl;
  }
  
  else if ( 10 <= N && N < 100 ){
    cout << 9 << endl;
  }
  
  else if ( 100<= N && N < 1000 ) {
    cout << 9 + N - 99 << endl;
  }
  
  else if ( 1000 <= N && N < 10000 ){
    cout << 9 + 900 << endl;
  }
  
  else if ( 10000 <= N && N < 100000 ){
    cout << 909 + N - 9999 << endl;
  }
  
  else if ( N == 100000){
    cout << 90909 << endl;
  }
  
}

  

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string a[200010];
int main()
{
	int n,ans=1;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	for(int i=2;i<=n;i++)
	{
		if(a[i]!=a[i-1])
		{
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9884
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define rep(i,n) for(int i=0;i<(n);i++)

const int inf = -1*((1<<31)+1);

using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(20);
    int N,ans = inf;
    cin >> N;
    vector<int> A(N),B(N);
    rep(i,N)cin >> A[i];
    rep(i,N)cin >> B[i];
    for(int bit = 0 ;bit<(1<<N);bit++){
        //bitが1になっていたら裏を使う
        vector<int> ura(N);
        for(int i=0;i<N;i++){
            //もしも、bitのi bit目が立っていたら、そのカードは裏面を使う
            if((bit>>i)&1)ura[i] = 1;
        }
        int even = 0,odd = 0; 
        //evenは偶数番目に置いたカードの枚数
        //oddは奇数番目に置いたカードの枚数

        vector<pair<int,int>> e,o;
        //eは偶数番目に使うカードの集合
        //oは奇数番目に使うカードの集合

        for(int i=0;i<N;i++){
            //i番目のカードについて考える
            if(i%2==0){
                //偶数番目のカードについて
                if(ura[i]){
                    //もしも裏面を使う場合は
                    //奇数番目に置く必要がある
                    odd++;
                    o.push_back({B[i],i});
                    //ここのiは何番目のカードかの情報
                    //最後に条件を満たす数列を作った場合に、操作回数を求めるのに使う
                }else{
                    //偶数番目に置く必要がある
                    e.push_back({A[i],i});
                    even++;
                }
            }else{
                //奇数番目のカードについて
                if(ura[i]){
                    //もしも裏面を使う場合は偶数番目に配置する必要がある
                    e.push_back({B[i],i});
                    even++;
                }else{
                    o.push_back({A[i],i});
                    odd++;
                }
            }
        }
        if(odd!= (N/2))continue;//奇数番目に置くカードの枚数が N/2じゃなかったらその置き方はできない
        sort(ALL(e));//とりあえず条件を満たすようにソートする
        sort(ALL(o));//とりあえず条件を満たすようにソートする
        //偶数、奇数と並べていく
        int evennow = 0,oddnow = 0;
        vector<pair<int,int>> p;
        for(int i=0;i<N;i++){
            if(i%2==0){
                p.push_back(e[evennow]);
                evennow++;
            }else{
                p.push_back(o[oddnow]);
                oddnow++;
            }
        }
        bool ok = 1;
        //ここでは、pが条件を満たす数列かどうかを判別する
        for(int i=0;i<N-1;i++){
            if(p[i].first>p[i+1].first)ok = 0;
        }
        if(!ok)continue;
        //pが条件を満たす数列だった場合は、操作回数を求める
        int cnt = 0;
        for(int i=0;i<N;i++){
            for(int j=i+1;j<N;j++){
                //何か自分より右にあるindex番号が小さいやつの個数を足していくと
                //バブルソートのスワップ回数になるらしい
                //証明はまだしらない
                if(p[i].second>p[j].second)cnt++;
            }
        }
        ans = min(ans,cnt);
    }
    if(ans==inf)ans = -1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long s;
  cin >> s;
  long i;
  long a,b,c,d;
  a = 1000000000;
  b = 1;
  c = (1000000000-s%1000000000)%1000000000;
  d = (s+c)/1000000000;
  cout << 0 << " " << 0 << " " << a << " " << b << " " << c << " " << d << endl;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n = int(input())
    r = []
    while n > 0:
        n -= 1
        t1 = n % 26
        r.append(chr(t1+97))
        n = n // 26
    r2 = "".join(r[::-1])
    print(r2)

if __name__ == '__main__':
    main()

Measured memory_bytes: 61548
#input
A, B = map(int, input().split())

#output
import math

def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors
A1 = prime_factors(A)
B1 = prime_factors(B)        
C = set(A1) & set(B1)

print(len(C)+1)

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

#define REP(i,n,m) for(int i=n;i<m;i++)
#define rep(i,n) REP(i,0,n)

typedef pair<int,int> P;

int x,y,z,v[4];
P t[100];
double dp[100][5002];

int main(void){
	while(cin>>x>>y>>z,x){
		memset(dp,0,sizeof(dp));
		memset(t,0,sizeof(t));
		rep(i,x) cin>>v[i];
		rep(i,z){
			int n,e,a;
			cin>>n>>e>>a;
			t[n].first = e;
			t[n].second = a;
		}

		dp[0][0] = 1.0;

		rep(i,y){
			rep(j,4902){
				rep(k,x){
					int ni = i + v[k];

					if(t[i].first == 0){
						dp[ni][j] += dp[i][j] * (1.0 / x);
					}
					else if(t[i].first == 1){
						ni += t[i].second;
						dp[ni][j] += dp[i][j] * (1.0 / x);
					}
					else{
						int nj = (t[i].first==2 ? j + t[i].second : j - t[i].second);
						if(nj < 0) nj = 0;
						dp[ni][nj] += dp[i][j] * (1.0 / x);
					}
				}
			}
		}

		double ans = 0;
		REP(i,y,y+30) REP(j,1,5002){
			if(dp[i][j] > 0){
				ans += dp[i][j] * j;
			}
		}
		cout<<(int)ans<<endl;
	}

	return 0;
}

Measured memory_bytes: 4772
#include <algorithm>
#include <cassert>
#include <iostream>
#include <queue>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

bool is_maybe_month(int d) { return (1 <= d) && (d <= 12); }

bool is_maybe_year(int d) { return (0 <= d) && (d <= 99); }

void solve(int fd, int sd) {
  if (is_maybe_month(fd) && is_maybe_month(sd)) {
    cout << "AMBIGUOUS";
  } else if (is_maybe_month(fd) && !is_maybe_month(sd)) {
    cout << "MMYY";
  } else if (is_maybe_month(sd) && !is_maybe_month(fd)) {
    cout << "YYMM";
  } else {
    cout << "NA";
  }
}

int main(int argc, char const *argv[]) {
  char fd[3];
  char sd[3];
  char c[5];

  cin >> c;
  fd[0] = c[0];
  fd[1] = c[1];
  fd[2] = '\0';
  sd[0] = c[2];
  sd[1] = c[3];
  sd[2] = '\0';

  // cout << fd << endl;
  // cout << sd << endl;
  // cout << atoi(fd) << endl;
  // cout << atoi(sd) << endl;

  solve(atoi(fd), atoi(sd));

  return 0;
}


Measured memory_bytes: 256
K, N = map(int, input().split())
A = list(map(int, input().split()))

max_d = 0

for a in range(1, N):
    d = A[a] - A[a-1]
    if d > max_d:
        max_d = d
last_d = K - A[-1] + A[0]
if last_d > max_d:
    max_d = last_d
print(K - max_d)

Measured memory_bytes: 32372
#coding:utf-8
H,W=map(int,input().split())

while not(H==0 and W==0):
    for i in range(0,H):
        for j in range(0,W):
            if (i+j)%2==0:
                print("#",end="")
            else:
                print(".",end="")
        print("")
    print("")

    H,W=map(int,input().split())

Measured memory_bytes: 8952
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		new Main();
	}

	public Main() {
		while(sc.hasNext()){
			new aoj0067().doIt();
		}
	}
	class aoj0067 {
		boolean map[][] = new boolean [12][12];
		int movex[] ={0,1,0,-1};
		int movey[] ={1,0,-1,0};
		void dfs(int x,int y){
			map[y][x] = false;
			for(int i = 0;i < 4;i++){
				if(x + movex[i] >= 0 && x + movex[i] < 12 && y + movey[i] >= 0 && y + movey[i] < 12){
					if(map[y + movey[i]][x + movex[i]] == true)dfs(x + movex[i],y + movey[i]);
				}
			}
		}
		void doIt() {
			int result = 0;
			for(int i = 0;i < 12;i++){
				String str = sc.next();
				char ctr[] = str.toCharArray();
				for(int j = 0;j < 12;j++){
					if(ctr[j] == '1')map[i][j] = true;
					else map[i][j] = false;
				}
			}
			for(int i = 0;i < 12;i++){
				for(int j = 0;j < 12;j++){
					if(map[i][j] == true){
						dfs(j,i);
						result++;
					}
				}
			}
			System.out.println(result);
		}
	}
}

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

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key2){
  NodePointer jun;
  for(jun = nil;jun->next != nil;jun=jun->next){
    if(jun->next->key == key2) return jun;
  }

  return NULL;

}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  if(t == nil) return;
  t->next->prev = t->prev;
  t -> prev->next=t->next;
  free(t);
}

void deleteFirst(){
  deleteNode(nil->next);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void delete(int key){
  NodePointer ayana;
  if((ayana=listSearch(key))!=NULL){
    deleteNode(ayana->next);
  }

}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);

  init();

  for ( i = 0; i < n; i++ ){
    scanf("%s",com);
    if(strlen(com)<7){
      scanf("%d",&key);
    }
    if ( com[0] == 'i' ) {insert(key); np++; size++;}

    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();

  return 0;
}

Measured memory_bytes: 31788
#include<cstdio>
#include<string>
#include<cmath>
#include<algorithm>
int main()
{
	int a,b,c,i,n,m;
	scanf("%d",&a);
	b=sqrt(a);
	c=b*b;
	if(c==a)
		printf("%d\n",a);
	else
		for(i=a;i>=1;i--)
		{
			n=sqrt(i);
			m=n*n;
			if(m==i)
			{
				printf("%d\n",i);
				i=0;
			}
		}
return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
 
int main(){
  int N;
  cin>>N;
  vector<int> B(N-1);
  rep(i,N-1) cin>>B[i];
  vector<int> A(N);
  A[0]=B[0];
  for(int i=1;i<N-1;i++){
    A[i]=min(B[i-1],B[i]);
  }
  A[N-1]=B[N-2];
  int sum=0;
  for(int i=0;i<N;i++) sum+=A[i];
  cout<<sum<<endl;
}

Measured memory_bytes: 3588
using System;
using System.IO;
using System.Text;

namespace cswork {
    class Program {
        static void Main (string[] args) {
            // string str = Util.ReadFile ();
            string str = Console.ReadLine();

            switch (str) {
                case "ABC":
                    Console.WriteLine ("ARC");
                    break;
                case "ARC":
                    Console.WriteLine ("ABC");
                    break;
            }
        }
    }

        class Util {
        public static string ReadFile () {
            StreamReader sr = new StreamReader (@"C:\data\data.txt", Encoding.UTF8);
            string str = sr.ReadToEnd ();
            sr.Close ();

            return str;
        }
    }
}

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

bool used[310][310];
int board[310][310];
int dr[] = { 1, 1, 0, -1, -1, 0 };
int dc[] = { 0, 1, 1, 0, -1, -1 };


int main() {
    int t, n;
    while (cin >> t >> n, t) {
        fill(board[0], board[310], 1e8);
        fill(used[0], used[310], false);
        int x[301], y[301];
        rep(i, n) {
            cin >> x[i] >> y[i];
            x[i] += 150, y[i] += 150;
            board[y[i]][x[i]] = -1;
        }
        int r, c;
        cin >> c >> r;
        c += 150, r += 150;
        used[r][c] = true;
        queue<P> que;
        que.push(make_pair(r, c));
        board[r][c] = 0;
        while (que.size()) {
            P p = que.front(); que.pop();
            rep(d, 6) {
                int nr = p.first + dr[d], nc = p.second + dc[d];
                if (nr < 0 or nc < 0 or nr > 300 or nc > 300 or board[nr][nc] == -1 or used[nr][nc]) continue;
                used[nr][nc] = true;
                que.push(make_pair(nr, nc));
                board[nr][nc] = min(board[nr][nc], board[p.first][p.second] + 1);
            }
        }
        int ans = 0;
        rep(r, 300) rep(c, 300) {
            if (board[r][c] >= 0 and board[r][c] <= t) ans++;
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3568
n, m = map(int, input().split())

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

count = 0

sum_A = sum(A)

for a in A : 
    if a >= (sum_A/(4*m)) : 
        count += 1
        
if count >= m : 
    print('Yes')
else : 
    print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <cassert>
#include <iomanip>
#include <utility>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <string>

using namespace std;

typedef long long ll;
typedef pair<int, int> p_i;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repext(i, a, b) for (int i = a; i < b; i++)
#define reprev(i, n) for (int i = n - 1; i >= 0; i--)
#define repextrev(i, a, b) for (int i = b - 1; i >= a; i--)

#define repv(values) for (auto v : values)

#define vec_all(vec) vec.begin(), vec.end()
#define sum(vec) accumulate(vec_all(vec), 0)
#define srt(vec) sort(vec_all(vec))

// vectorデバッグ
template <typename T>
void dump_vec(vector<T> vec)
{
    rep(i, vec.size())
    {
        cout << i << ": " << vec[i] << endl;
    }
}

// --- notice ---
// intの和はllにしろ

int main()
{
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n) {
        cin >> h[i];
    }

    vector<int> mov(n, 0);
    repext(i, 1, n) {
        if (h[i] <= h[i - 1]) {
            mov[i] = mov[i - 1] + 1;
        }
    }

    int cnt = 0;
    rep(i, n) {
        if (cnt < mov[i]) {
            cnt = mov[i];
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1024
n = int(input())
x = input()
one_num = x.count('1')

ans_reduce,ans_add = 0,0
for i in range(n):
    if(one_num>1):
        ans_reduce = (ans_reduce+pow(2,n-i-1,one_num-1)*(1 if x[i] == '1' else 0))%(one_num-1)
    ans_add = (ans_add+pow(2,n-i-1,one_num+1)*(1 if x[i] == '1' else 0))%(1+one_num)

for i in range(n):
    now_one = one_num + (-1 if x[i] == '1' else 1)
    if(now_one == 0):
        print(0)
        continue
    num = ((ans_reduce if x[i] == '1' else ans_add) + pow(2,n-i-1,now_one)*(-1 if x[i] == '1' else 1))%now_one
    ans = 1
    while(num!=0):
        ans += 1
        num = num % bin(num).count('1')
    print(ans)


Measured memory_bytes: 9364
n,m=map(int,input().split())
mat=[]
dx=[0,0,-1,1]
dy=[1,-1,0,0]
for i in range(n):
    mat.append(list(input().strip()))
f=0 
for i in range(n):
    for j in range(m):
        if mat[i][j]=='#':
            f=0 
            for k in range(4): 
                if 0<=i+dx[k]<n and 0<=j+dy[k]<m and mat[i+dx[k]][j+dy[k]]=='#': 
                    f=1  
            if not f:
                print('No')
                exit()
print('Yes')


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  int a1, a2, a3;
  cin >> a1 >> a2 >> a3;
  cout << max({a1, a2, a3}) - min({a1, a2, a3});
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;

int main() {
    int n; cin >> n;
    vector<int> line(n);
    for(int i = 0; i < n; i++){
        cin >> line[i];
    }
    sort(line.begin(), line.end());

    int sum = 0;
    for(int i = 0; i < n-1; i++){
        sum += line[i];
    }

    if(line[n-1] < sum) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define MM(i, n, m) for (int i = m; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;
/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
*/
int main()
{
    char c;
    cin >> c;
    cout << char(c + 1) << endl;
    return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<int, int>;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

int main() {
  int N; cin >> N;
  vector<ll> D(N); REP(i, N) cin >> D[i];
  int M; cin >> M;
  vector<ll> T(M); REP(i, M) cin >> T[i];
  map<ll, ll> m;
  REP(i, N) m[D[i]]++;
  string ans = "YES";
  REP(i, M) {
    if(m[T[i]] > 0) {
      m[T[i]]--;
    } else if(m[T[i]] <= 0) {
      ans = "NO";
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 18804
// garnab27
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define ll int64_t
#define F first
#define S second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
ll modex(ll a,ll b,ll p){ll res=1;a%=p;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b>>=1;}return res;}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
 
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(NULL);cout.tie(NULL);	
 
	string s;
	cin>>s;

	int a=0, b=0;
	for(char c:s) {
		if(c=='A') a++;
		else b++;
	}

	if(a==3 || b==3) cout<<"No";
	else cout<<"Yes";
 
 
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
using namespace std;
using ll = long long;
using d = double;

int main(){
  string s,t;
  cin >>s>>t;

  int c=0; //t

  rep(i,s.size()-t.size()+1){
    int q=0;//個数
    rep(j,t.size()){
      if(s[i+j]==t[j])++q;
    }
    c=max(c,q);
  }
  if(c==t.size()) return cout << 0 << endl,0;
  int ans=t.size()-c;
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3604
N, Q = gets.split.map(&:to_i)

children = Array.new(N + 1) { [] }

(N-1).times do
  a, b = gets.split.map(&:to_i)
  children[a] << b
  children[b] << a
end

scores = Array.new(N, 0)

Q.times do
  q, x = gets.split.map(&:to_i)
  scores[q-1] += x
end

queue = [1]
finished = Array.new(N + 1, false)
while queue.size > 0
  node = queue.pop
  finished[node] = true
  children[node].each do |child|
    next if finished[child]
    scores[child-1] += scores[node-1]
    queue << child
  end
end

puts scores.join(' ')

Measured memory_bytes: 26236
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please


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

	
	int N;
	cin >> N;
	int A[100001] = {};
	rep(i, N) {
		int a;
		cin >> a;
		A[a - 1]++;
		A[a]++;
		A[a + 1]++;
	}
	co(*max_element(A, A + 100001));

	Would you please return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
        using namespace std;
     
        int main(){
        	long long n,k;
        	cin>>n>>k;
        	long long x[n];
        	long long res = 1000000000,cnt = 0;
        	for(long long i=0;i<n;i++){
        		cin>>x[i];
        		cnt = max(cnt,x[i]);
        	}
        	if(x[0]>=0){
        		//全部プラス
        		res = x[k-1];
        	}else if(cnt <= 0){
        		//全部マイナス
        		res = abs(x[(n-k)]);
        	}else{
        		for(long long i=0;i<(n-k+1);i++){
        			if(x[i]<0&&x[i+k-1]>0){
        				res = min(min(abs(x[i]*2) + abs(x[i+k-1]),abs(x[i]) + abs(x[i+k-1] *2)),res);
        			}else if(x[i]<=0&&x[i+k-1]<=0){
        				res = min(abs(x[i]),res);
        			}else{
        				res = min(res,x[i+k-1]);
        			}
        			//cout<<"i:"<<i<<"res:"<<res<<endl;
        		}
        	}
     
        	cout<<res<<endl;
     
        }

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

using namespace std;

int n, h, d;
int fct[2000000];
int f[2000000];
const int mod = 1000000007;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> h >> d;
  fct[0] = 1;
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    fct[i] = 1ll * fct[i - 1] * i % mod;
    sum += fct[i];
    if (sum >= mod) {
      sum -= mod;
    }
  }
  f[0] = fct[n];
  int csum = 1ll * fct[n] * sum % mod;
  for (int i = 1; i <= h; i++) {
    if (i == h) {
     for (int j = i - 1; j >= max(0, h - d); j--) {
       f[i] += f[j];
       if (f[i] >= mod) {
         f[i] -= mod;
       }
     }
    } else {
      f[i] = csum;
      csum += 1ll * f[i] * sum % mod;
      if (csum >= mod) {
        csum -= mod;
      }
      if (i >= d) {
        csum -= 1ll * f[i - d] * sum % mod;
        if (csum < 0) {
          csum += mod;
        }
      }
    }
  }
  cout << f[h] << "\n";
  return 0;
}

Measured memory_bytes: 10496