akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};


int main() {
 ll N;
ll A;
ll B;
cin >>N>>A>>B;
  vl X(N);
  rep(i,N) {
cin >>X.at(i);
  }
  
  ll sum=0;
  rep(i,N-1) {
    if((X.at(i+1)-X.at(i))*A<=B) {
      sum+=(X.at(i+1)-X.at(i))*A;
    }
    else {
      sum +=B;
    }
  }
  
  
  cout<<sum<<endl;
}


Measured memory_bytes: 1024
n = int(input())
c = list(input())

pos_r = set()
for i in range(n):
    if c[i] == 'R':
        pos_r.add(i)

ans = 0
num_r = len(pos_r)
for ri in pos_r:
    if ri >= num_r:
        ans += 1
print(ans)


Measured memory_bytes: 27772
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define all(a) (a).begin(), (a).end()
 
int main() {
  int X, A;
  cin >> X >> A;
  if(X < A) puts("0");
  else puts("10");
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
std::string s;
std::map<char,char> map;
int l,hl;
int main()
{
	map['b']='d';
	map['d']='b';
	map['p']='q';
	map['q']='p';
	std::cin>>s;
	if(s.length()&1)
	{
		puts("No");
		return 0;
	}
	l=s.length();
	hl=l>>1;
	for(int i=0;i<hl;++i)
		if(map[s[i]]!=s[l-i-1])
		{
			puts("No");
			return 0;
		}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 512
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n, k1 = f()

    pts = []
    sety = set()
    setx = set()
    for i in range(n):
        x, y = f()
        pts.append((x,y))
        setx.add(x)
        sety.add(y)
    
    minarea = int(1e19)

    xlist = list(setx)
    ylist = list(sety)
    xl = len(xlist)
    yl = len(ylist)

    ylist = sorted(ylist)
    xlist = sorted(xlist)

    xindx = dict(zip(xlist, range(xl)))

    for i in range(yl):
        for j in range(i+1, yl):
            cnt = [0] * xl
            for l in range(n):
                if pts[l][1] >= ylist[i] and pts[l][1]<=ylist[j]:
                    cnt[xindx[pts[l][0]]] += 1


            head = 0
            end = 0
            total = 0
            while end<xl:
                total += cnt[end]

                while total >= k1:
                    minarea = min(minarea, (ylist[j] - ylist[i]) * (xlist[end] - xlist[head]))
                    total -= cnt[head]
                    head += 1

                end += 1
    
    print(minarea)
                    








solve()


Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) std::memset(arg,n,sizeof(arg))
#define mp(a,b) std::make_pair(a,b)
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
str s;
int main(){
  cin>>s;
  int ss=s.size(),j=0;
  bool f=true;
  while(j<ss){
    if(s[j]=='d'){
      if(ss-j>=5){
	if(s[j+1]=='r'&&s[j+2]=='e'&&s[j+3]=='a'&&s[j+4]=='m'){
	  j+=5;
	  if(ss==j) break;//dream確定
	  else{
	    if(s[j]=='d') continue;//dream確定
	    else if(ss-j>=2){
	      if(s[j]=='e'&&s[j+1]=='r'){
		j+=2;
		if(ss==j) break;//dreamer確定
		else if(s[j]=='d'||s[j]=='e') continue;//dreamer確定
		else if(s[j]=='a') j-=2;//dream確定
		else{
		  f=false;
		  break;
		}
	      }
	      else{
		f=false;
		break;
	      }
	    }
	  }
	}
	else{
	  f=false;
	  break;
	}
      }
      else{
	f=false;
	break;
      }
    }
    else if(s[j]=='e'){
      if(ss-j>=5){
	if(s[j+1]=='r'&&s[j+2]=='a'&&s[j+3]=='s'&&s[j+4]=='e'){
	  j+=5;
	  if(ss==j) break;//erase確定
	  else{
	    if(s[j]=='d'||s[j]=='e') continue;//erase確定
	    else if(s[j]=='r') j++;//eraser確定
	  }
	}
	else{
	  f=false;
	  break;
	}
      }
      else{
	f=false;
	break;	
      }
    }
    else{
      f=false;
      break;
    }
  }
  if(f) prin("YES");
  else prin("NO");
  return 0;
}


Measured memory_bytes: 512
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
from time import time

def is_prime(n):
    if n == 1:
        return 0
    i = 2
    while i**2 <= n:
        if n % i == 0:
            return 0
        i += 1
    return 1

def main():
    q = int(input().strip())
    n = 10**5
    ary = [0] * (n+1)
    ary2 = [0] * (n+1)
    arys = [0] * (n+2)
    for i in range(2, n+1):
        ary[i] = is_prime(i)
    for i in range(1, n+1):
        ary2[i] = ary[i] & ary[(i+1)//2]
    for i in range(1, n+2):
        arys[i] = arys[i-1] + ary2[i-1]
    # print(ary[:20])
    # print(ary2[:20])
    # print(arys[:20])
    for i in range(q):
        l, r = map(int, input().strip().split())
        print(arys[r+1] - arys[l])

if __name__ == '__main__':
    main()


Measured memory_bytes: 52824
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint s, w;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> s >> w;
	if(w >= s)  cout << "unsafe" << endl;
	else  cout << "safe" << endl;
	
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n), cp(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cp[i] = a[i];
  }
  sort(cp.begin(), cp.end());
  for (int i = 0; i < n; i++) {
    if (cp[n - 1] == a[i]) {
      cout << cp[n - 2] << endl;
    } else {
      cout << cp[n - 1] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3200
def tpsort(n,lst):
    parent=[0]*(n+1)
    child=[[] for _ in range(n+1)]
    for p,c in lst:
        child[p].append(c)
        parent[c]+=1
    ans=[]
    que=[]
    for i in range(1,n+1):
        if parent[i]==0:
            que.append(i)
    while que:
        h=que.pop()
        ans.append(h)
        for u in child[h]:
            parent[u]-=1
            if parent[u]==0:
                que.append(u)
    return ans
N,m=map(int,input().split())
data=[list(map(int,input().split())) for i in range(m)]
t=[[] for i in range(N+1)]
for p,c in data:
    t[p].append(c)
s=tpsort(N,data)
dp=[0]*(N+1)
for v in s:
    for r in t[v]:
        dp[r]=max(dp[v]+1,dp[r])
print(max(dp))

Measured memory_bytes: 90584
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

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

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

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

fn main() {
    input!{
        n: usize,
        mut v: [u64; n],
    }
    let mut even = BTreeMap::new();
    let mut odd = BTreeMap::new();

    for (i, v_) in v.iter().enumerate() {
        if i % 2 == 0 {
            *even.entry(v_).or_insert(0) += 1;
        } else if i % 2 != 0 {
            *odd.entry(v_).or_insert(0) += 1;
        }
    }

    let mut even: Vec<_> = even.iter().collect();
    let mut odd: Vec<_> = odd.iter().collect();
    even.sort_by_key(|k| k.1);
    odd.sort_by_key(|k| k.1);
    even.reverse();
    odd.reverse();

    println!(
        "{}",
        if even[0].0 != odd[0].0 {
            n - even[0].1 - odd[0].1
        } else {
            min(
                n - even[0].1 - if odd.len() > 1 { *odd[1].1 } else { 0usize },
                n - odd[0].1 - if even.len() > 1 { *even[1].1 } else { 0usize },
            )
        }
    );
}


Measured memory_bytes: 10492
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
#include "dbgtoki.hpp"
#define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
#define DUMP(i)
#endif

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
#define dis distance
#define so sort
#define rev reverse
#define pub push_back
#define sec second
#define fir first

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector <int> > vvi;
const int EPS = 1e-9;
const int MOD = 1e9+7;
const int INF = (1 << 30);

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vi L(2*n);
	REP(i,2*n){
		cin >> L[i];
	}
	so(ALL(L));
	DUMP(L);
	int ans = 0;
	for(int i = 0; i < 2*n;i+=2){
		ans += L[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main(){
    lint h, w;
    scanf("%lld%lld", &h, &w);
    if(h == 1 || w == 1){
        printf("%d\n", 1);
    }
    else if(h%2 == 1 && w%2 == 1){
        printf("%lld\n", w*(h-1)/2 + (w+1)/2);
    }
    else{
        printf("%lld\n", h*w/2);
    }
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


int n;
int a[100000];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	rep(i, n)cin >> a[i];

	long long ans1,ans2;
	ans1=ans2=0;

	int s=0;
	rep(i,n){
		if (i & 1){
			int x = max(1-(s+a[i]), 0);
			ans1 += x;
			s += a[i]+x;
		}
		else{
			int x = max((s+a[i])+1, 0);
			ans1 += x;
			s += a[i] - x;
		}
	}
	s=0;
	rep(i, n){
		if ((i & 1)==0){
			int x = max(1 - (s+a[i]), 0);
			ans2 += x;
			s += a[i] + x;
		}
		else{
			int x = max((s+a[i]) + 1, 0);
			ans2 += x;
			s += a[i] - x;
		}
	}



	cout<<min(ans1,ans2)<<endl;

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdlib>
using namespace std;

typedef pair<int,int> P; //x, y

class State{
public:
  int x, y, bit, cost;

  State(){}
  State(int _x, int _y, int _bit, int _cost){
    x = _x;
    y = _y;
    bit = _bit;
    cost = _cost;
  }

  bool operator<(const State &st)const{
    return cost > st.cost;
  }
};

int w, h;
int sx, sy, gx, gy;
int cost[102][102];
bool closed[102][102][1 << 5];
char t[102][102];
vector<P> mv;

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

void solve(){
  priority_queue<State> open;
  open.push(State(sx, sy, 0, 0));
  memset(closed, 0, sizeof(closed));

  while(!open.empty()){
    State st = open.top();
    open.pop();

    if(closed[st.y][st.x][st.bit]) continue;
    closed[st.y][st.x][st.bit] = true;

    if(st.x == gx && st.y == gy && st.bit == (1 << mv.size()) - 1){
      cout << st.cost << endl;
      break;
    }

    for(int i = 0; i < 4; i++){
      int nx = st.x + dx[i];
      int ny = st.y + dy[i];
      int nbit = st.bit;
      if(nx < 0 || w <= nx || ny < 0 || h <= ny || t[ny][nx] == '#') continue;

      int idx = find(mv.begin(), mv.end(), P(nx, ny)) - mv.begin();

      if(idx < mv.size()){
	nbit |= (1 << idx);
      }

      open.push(State(nx, ny, nbit, st.cost + (t[st.y][st.x] - '0')));
    }
  }
}

void show(){
  for(int i = 0; i < h; i++){
    cout << t[i] << endl;
  }
}

int main(){
  while(cin >> w >> h){
    mv.clear();

    for(int i = 0; i < h; i++){
      cin >> t[i];

      for(int j = 0; j < w; j++){
	if(t[i][j] == 'S'){
	  sx = j;
	  sy = i;
	  t[i][j] = '.';
	}
	else if(t[i][j] == 'G'){
	  gx = j;
	  gy = i;
	  t[i][j] = '.';
	}
	else if(t[i][j] == 'M'){
	  mv.push_back(P(j, i));
	  t[i][j] = '.';
	}
      }
    }

    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
	if(t[i][j] == '.'){
	  t[i][j] = '1';
	}
	else if(t[i][j] == '#'){
	  for(int my = -2; my <= 2; my++){
	    for(int mx = -2; mx <= 2; mx++){
	      if(mx == 0 && my == 0) continue;

	      int cost = 4 - max(abs(mx), abs(my));
	      int x = j - mx;
	      int y = i - my;

	      if(x < 0 || w <= x || y < 0 || h <= y) continue;

	      if(t[y][x] == '.' || t[y][x] != '#' && cost + '0' > t[y][x]){
		t[y][x] = cost + '0';
	      }
	    }
	  }
	}
      }
    }
    solve();
  }
}

Measured memory_bytes: 1796
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;

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

int a[200010];
int ai[200010];
int bi[200010];

int main() {
    int n;
    cin >> n;
    rep(i, n) {
        cin >> a[i];
    }
    rep(i, n) {
        if (i % 2 == 0) {
            ai[i / 2] = a[i];
        }
        else {
            bi[i / 2] = a[i];
        }
    }
    if (n % 2 == 0) {
        for (int i = n / 2 - 1; i >= 0; i--) {
            cout << bi[i] << ' ' ;
        }
        for (int i = 0; i < n / 2; i++) {
            cout << ai[i] << ' ' ;
        }
    }
    else {
        for (int i = n / 2; i >= 0; i--) {
            cout << ai[i] << ' ';
        }
        for (int i = 0; i < n / 2; i++) {
            cout << bi[i] << ' ';
        }
    }
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,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;
}


template <class T>
class SegTree {
    int n;// 葉の数
    vector<T> data;// データを格納するvector
    T def; // 初期値かつ単位元
    function<T(T, T)> operation; // 区間クエリで使う処理
    function<T(T, T)> update;// 点更新で使う処理

    T find(int a, int b) {
        ll val_left = def, val_right = def;
        for (a += (n - 1), b += (n - 1); a < b; a >>= 1, b >>= 1)
        {
            if ((a & 1) == 0){
                val_left = operation(val_left, data[a]);
            }
            if ((b & 1) == 0){
                val_right = operation(val_right, data[--b]);
            }
        }
        return operation(val_left, val_right);
    }
    public:
    // _n:必要サイズ, _def:初期値かつ単位元, _operation:クエリ関数,
    // _update:更新関数
    SegTree(size_t _n, T _def, function<T(T, T)> _operation,
        function<T(T, T)> _update=[](T a,T b){return b;})
        : def(_def), operation(_operation), update(_update) {
        n = 1;
        while (n < _n) {
            n *= 2;
        }
        data = vector<T>(2 * n - 1, def);
    }
    void set(int i, T x) { data[i + n - 1] = x; }
    void build() {
        for (int k=n-2;k>=0;k--) data[k] = operation(data[2*k+1],data[2*k+2]);
    }
    // 場所i(0-indexed)の値をxで更新
    void change(int i, T x) {
        i += n - 1;
        data[i] = update(data[i], x);
        while (i > 0) {
            i = (i - 1) / 2;
            data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
        }
    }

    // [a, b)の区間クエリを実行
    T query(int a, int b) {
        //return _query(a, b, 0, 0, n);
        return find(a,b);
    }

    // 添字でアクセス
    T operator[](int i) {
        return data[i + n - 1];
    }
};


int main(){
    ll n;cin >> n;
    vl p(n);rep(i,n)cin >> p[i];
    SegTree<ll> st(n,0LL,[](ll a,ll b){return max(a,b);});
    vl dp(n);
    rep(i,n){
        ll a;cin >> a;
        dp[i]=a+st.query(0,p[i]);
        st.change(p[i]-1,dp[i]);
    }
    cout << *max_element(all(dp)) <<endl;
}

Measured memory_bytes: 10332
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <tuple>
#include <math.h>
#include <iomanip>

using namespace std;

class Sover {
};

int main()
{
	while (true) {
		int n;
		cin >> n;
		if (n == 0)break;

		int length = n * 5 + 10;
		vector<vector<bool>> grid(length, vector<bool>(5, false));

		for (int i = 0; i < n; i++) {
			int d, p, q;
			cin >> d >> p >> q;
			q--;
			int bottom = length - 1;
			if (d == 1) {
				for (; bottom >= 0; bottom--) {
					bool interrupt = false;
					for (int j = 0; j < p; j++) {
						if (grid[bottom][q+j])interrupt = true;
					}
					if (interrupt)break;
				}

				for (int j = 0; j < p; j++)grid[bottom + 1][q + j] = true;
			}
			else {
				while (bottom >= 0 && !grid[bottom][q])bottom--;

				for (int j = 0; j < p; j++)grid[bottom + 1 + j][q] = true;
			}

			int shift_cnt = 0;
			for (int j = bottom + 1; j < length; j++) {
				bool full = true;
				for (int k = 0; k < 5; k++) {
					if (!grid[j][k]) {
						full = false;
						break;
					}
				}
				if (full) {
					shift_cnt++;
					for (int k = 0; k < 5; k++) {
						grid[j][k] = false;
					}
				}
				else {
					for (int k = 0; k < 5; k++) {
						grid[j - shift_cnt][k] = grid[j][k];
						if (shift_cnt > 0)grid[j][k] = false;
					}
				}
			}
		}

		int res = 0;
		for (int i = 0; i < length; i++) {
			for (int j = 0; j < 5; j++)if (grid[i][j])res++;
		}
		cout << res << endl;
	}
}


Measured memory_bytes: 3136
import os, sys, re, math

lines = sys.stdin.readlines()

N = int(lines[0])

possible = False
possible |= (N % 4 == 0)
possible |= (N % 7 == 0)
if not possible:
    for i in range(1, 101):
        r = (N - 4 * i)
        possible |= (r >= 0 and r % 7 == 0)
        if possible:
            break

print ('Yes' if possible else 'No')


Measured memory_bytes: 3188
A,B,K = map(int,input().split())
ans =list()

for i in range(A,A+K):
	if i <= B:
		ans.append(i)

for i in range(B-K+1,B+1):
	if A <= i:
		ans.append(i)
#リストをset化して、重複を取り除く
ans=list(set(ans))
ans.sort()	#昇順にソート

for i in ans:
	print(i)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

int N, K;
vector<int> ans;

signed main()
{
	cin >> N >> K;

	int sum = (N - 1) * (N - 2) / 2;

	if (sum < K)
	{
		cout << -1 << endl;
	}
	else
	{
		for (int i = 2; i <= N; i++)
		{
			ans.push_back(i);
			ans.push_back(1);
		}

		for (int i = 2; i <= N; i++)
		{
			for (int j = i + 1; j <= N; j++)
			{
				if (sum == K)
				{
					goto END;
				}
				sum--;
				ans.push_back(i);
				ans.push_back(j);
			}
		}
		
END:
		cout << (ans.size() / 2) << endl;
		for (int i = 0; i < ans.size() / 2; i++)
		{
			cout << ans[i * 2] << " " << ans[i * 2 + 1] << endl;
		}
	}
}











Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;

struct Node{
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k){
	Node *y = NIL;
	Node *x = root;
	Node *z;

	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while(x != NIL){
		y = x;
		if(z->key < x->key)
			x = x->left;
		else
			x = x->right;
	}
	z->parent = y;
	if(y == NIL)
		root = z;
	else{
		if(z->key < y->key){
		y->left = z;
	}
	else
		y->right = z;
	}
}
void inorder(Node *u){
	if(u == NIL)
		return;
	inorder(u->left);
	printf(" %d", u->key);
	inorder(u->right);
}

void preorder(Node *u){
	if(u == NIL)
		return;
	printf(" %d", u->key);
	preorder(u->left);
	preorder(u->right);
}

int main(){
	int n, i, x;
	string com;

	scanf("%d", &n);

	for(i = 0; i < n; i++){
		cin >> com;
		if(com == "insert"){
			scanf("%d", &x);
			insert(x);
		}
		else if(com == "print"){
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}
	return 0;
}


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

using namespace std;

int n,k,t,l;
double a,p,ans;

int main()
{
	scanf("%d%lf%lf",&n,&a,&p);
	a-=p;
	t=2*n;
	l=n;
	for(int i=1; i<=n; i++)
	{
		ans+=(double)(a*t+p*t*(t+1)/2)/t;
		a=a+a/l+3*p/(2*l);
		p=p+2*p/l;
		l--;
		t-=2;
	}
	printf("%.9lf",ans);
	return 0;
}

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

public class AtCoderA
{
    static void Main()
    {
        int n;
        long w;
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            n = int.Parse(words[0]);
            w = long.Parse(words[1]);
        }

        Tuple<long, long>[] obj = new Tuple<long, long>[n];
        for (int i = 0; i < n; i++)
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            obj[i] = Tuple.Create(long.Parse(words[0]), long.Parse(words[1]));
        }

        const int MAX_N = 110;
        const int MAX_V = 100100;

        // dp[ i ][ sum_v ] := i-1 番目までの品物から価値が sum_v 以上を達成するように選んだときの、重さの総和の最小値
        long[,] dp = new long[MAX_N, MAX_V];
        for (int i = 0; i < MAX_N; i++)
        {
            for (int j = 0; j < MAX_V; j++)
            {
                dp[i, j] = int.MaxValue;
            }
        }

        dp[0, 0] = 0;

        for (int i = 0; i < n; i++)
        {
            long weight = obj[i].Item1;
            long value = obj[i].Item2;
            for (int j = 0; j < MAX_V; j++)
            {
                dp[i + 1, j] = dp[i, j];
                if (j - value >= 0)
                {
                    dp[i + 1, j] = Math.Min(dp[i + 1, j], dp[i, j - value] + weight);
                }
            }
        }

        long answer = 0;
        for (int i = 0; i < MAX_V; i++)
        {
            if (dp[n, i] <= w)
            {
                answer = i;
            }
        }

        Console.WriteLine(answer);
    }
}

Measured memory_bytes: 96992
#include <iostream>
#include <string>
#include <math.h>
#include <stdio.h>
#include <ctype.h>

using namespace std;

int main () {
    int b[10];
    

    int x;
    cin>>x;
    
    while(cin>>b[0]>>b[1]>>b[2]>>b[3]>>b[4]>>b[5]>>b[6]>>b[7]>>b[8]>>b[9]){
        int flag=0;
        int l=0,r=0;
        for(int i=0; i<10; i++){
            if(l<b[i]&&r<b[i]){
                if(l<r){
                    r=b[i];
                }else{
                    l=b[i];
                }
            }else if(l>b[i]&&r<b[i]){
                r=b[i];
            }else if(l<b[i]&&r>b[i]){
                l=b[i];
            }else{
                flag++;;
                break;
            }
        }
        
        if(flag==1){
            cout<<"NO"<<endl;
        }else{
            cout<<"YES"<<endl;
        }

    }
    return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);

	int N = sc.nextInt();
	int n = (String.valueOf(N)).length();

	int count = 0;
	int x = 10;
	int i;
	for (i = 1; i < n; i++, x *= 10) {
	    if ((i % 2) == 1) 
		count += x - (x / 10);
	}
	if ((i % 2) == 1)
	    count += N - (x / 10) + 1;

	System.out.println(count);
    }
}

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

int dp[102][100005];

#undef int
int main()
{
#define int long long int
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int n, W;
	cin>>n>>W;
	vector<int> w(n), v(n);
	for(int i = 0;i<n;i++)
		cin>>w[i]>>v[i];

	for(int i = 1;i<=W;i++)
		dp[0][i] = (w[0] <= i)?v[0]:0ll;

	for(int curi = 1;curi<n;curi++)
		for(int curw = 0;curw<=W;curw++)
		{
			dp[curi][curw] = max(dp[curi][curw], dp[curi-1][curw]);
			dp[curi][curw] = max(dp[curi][curw], dp[curi][curw-1]);
			if(curw >= w[curi] && dp[curi-1][curw-w[curi]] != -1)
				dp[curi][curw] = max(dp[curi][curw], dp[curi-1][curw-w[curi]]+v[curi]);
		}
	// for(int i = 0;i<n;i++)
	// 	for(int j = 0;j<=W;j++)
	// 		cout<<dp[i][j]<<" \n"[j==W];
	cout<<dp[n-1][W]<<endl;
	
	return 0;
}

Measured memory_bytes: 78336
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
using vb = vector<bool> ;
using pll = pair<ll, ll> ;

#define IOS ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'
#define all(x) x.begin(), x.end()
#define sz(x) ((long long)x.size())
#define arr array

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e10;

ll fast(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        y >>= 1;
    }
    return res;
}

ll inv(ll n){
    return fast(n,mod-2);
}

void pre(){

}


void solve(){  

    int n;
    cin >> n;
    vector<pair<int,int>> arr;

    for(int i=1;i<=n;i++){
        long double x;
        cin >> x;
        long long y = (long long)(x*1e9+0.5);
        int c2=0,c5=0;
        while(y%2==0){
            c2++;
            y /= 2;
        }
        while(y%5==0){
            c5++;
            y /= 5;
        }
        arr.push_back({c2,c5});
    }
    map<pair<int,int>,int> MAP;
    long long ans=0;
    for(auto it : arr){
        for(auto x : MAP){
            if(it.ff + x.ff.ff >= 18 and it.ss + x.ff.ss >= 18)
                ans += x.ss;
        }
        MAP[it]++;
    }
    cout << ans;

}   

int32_t main(){
    #ifndef ONLINE_JUDGE
    freopen("input00.txt","r",stdin);
    #endif
    IOS;
    pre();
    ll T = 1;   
    //cin>>T;
    ll tt = 1;
    while(T--){  
        //cout << "Case #" << tt << ": "; 
        tt++;
        solve();
    }
    return 0;
}

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

#define LL long long

int arr[100009];

int main(){
	

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n,k;
	cin>>n>>k;
	int idx=0;

	for(int i=0;i<n;i++){cin>>arr[i];}

	int ans=0,i=n;
	while(i>1){
		i-=(k-1);ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 640
#include<stdio.h>
 
static const int MAX = 500;

static const int INFTY = (1<<21);
  
  int sum2;

int  printer(int d){

  sum2 = sum2 + d;
  
return sum2;
}
 

int main(){
  int n;
  int j;
  int i;
  int e;
  int sum1;
  int M[MAX][MAX];
  int d[MAX];
  int isA[MAX];
  int u;
   
  scanf("%d", &n);
   
  for ( i = 0; i< n; i++ )
{
    for ( j = 0; j < n; j++ ){
      scanf("%d", &e);
      M[i][j] = (e==-1?INFTY:e);
    }   
    d[i]=INFTY;
    isA[i]=0;
   }
   
  d[0]=0;
 
  while(1){
    int u;
int v=INFTY;
     
    for(i=0;i<n;i++){
      if(isA[i]==1){
continue;
      }      
if(v>d[i])
{
    v=d[i];
    u=i;
      }
    }
 
    if(v==INFTY)break;
    isA[u]=1;
    for(j=0;j<n;j++)
{
      if(isA[j]==1)continue;
      if(d[j]>=M[u][j])
{
    d[j]=M[u][j];
      }
    }
  } 
  sum1 = 0;  for ( u = 0; u < n; u++ )
{
    printer(d[u]);
  }
  sum1 = sum2;
  printf("%d\n", sum1);
   
  return 0;
}

Measured memory_bytes: 804
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

const int mod = 1e9 + 7;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            int k = 1;
            int v = 1;
            while ((i / v) % 2 == (j / v) % 2) {
                k++;
                v <<= 1;
            }
            cout << k << " \n"[j == n];
        }
    }
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll i,j,k,m,ans,K;
    ll fr[26]={0};
    string s;
    cin>>s;
    cin>>K;
    ll n=s.length();
    for(i=0;i<n;i++)
    {
    	fr[s[i]-97]++;
	}
	for(i=0;i<26;i++)
	{
		if(fr[i]==n)
		{
			cout<<(n*K)/2;
			return 0;
		}
	}
	ll ctr=0,f=0,b=0;
	i=0;
	while(s[i]==s[0])
	{
		i++;
		f++;
	}
	j=i;
	i=n-1;
	while(s[i]==s[n-1])
	{
		i--;
		b++;
	}
	k=i;
	ans=0;
	if(s[0]==s[n-1])
	{
		ans=((f+b)/2)*(K-1);
		ans+=(f/2)+(b/2);
	}
	else
	{
		ans=(f/2+b/2)*K;
	}
	while(j<=k)
	{
		ctr=0;
		i=j;
		while(s[j]==s[i])
		{
			i++;
			ctr++;
		}
		ans+=(ctr/2)*K;
		j=i;
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace __gnu_pbds;
using namespace std;
/*
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
*/
#define ull unsigned long long int
#define ll long long int
#define MAX 1000000007
//1e9+7
#define pll pair<ll,ll>
#define pii pair<int,int>
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FO ifstream fin("a.in");ofstream fout("a.out");
#define TEST int testcase;cin>>testcase;while(testcase--)
#define all(x) (x).begin(),(x).end()
#define mset0(x) memset((x), 0, sizeof((x)));
#define mset1(x) memset((x), -1, sizeof((x)));
#define endl "\n"
typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;

void solve(){
    int A,B,C,D,E,F;
    cin>>A>>B>>C>>D>>E>>F;
    int mom=A*100,son=0;
    for(int a=0;a<=30;a++){
        for(int b=0;b<=30;b++){
            for(int c=0;c<=100;c++){
                for(int d=0;d<=100;d++){
                    if(a*A*100+b*B*100+c*C+d*D>F) continue;

                    int water=a*A*100+b*B*100;
                    int sugar=c*C+d*D;
                    if(100*sugar>E*water) continue;
                    //cout<<sugar<<" "<<water<<endl;
                    if((sugar*mom)>son*(sugar+water)){
                        son=sugar;
                        mom=sugar+water;
                    }

                }
            }
        }
    }
    cout<<mom<<" "<<son;

    return;
}
int main(){
    IO
    //TEST
    solve();
    return(0);
}


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

signed main() {
  int N, K;
  cin >> N >> K;
  
  int H;
  int ans = 0;
  for( int i = 0; i < N; i++ ){
    cin >> H;
    if( H >= K ) ans++;
  }
  
  cout << ans << endl;
  
  
  
  
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

const ll MOD = 1000000007LL;
const double PI = 3.14159265358979323846;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

// for loop
#define REP(i, n) for ((i) = 0;(i) < (ll)(n);(i)++)

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

bool is_cyclic_impl(ll node, const vector<vector<ll>>& edges, vector<int>& status, vector<ll>& result) {
	if (status[node] == 1) return true;
	if (status[node] == 0) {
		status[node] = 1;
		for (ll i = 0; i < edges[node].size(); ++i) {
			if (is_cyclic_impl(edges[node][i], edges, status, result)) return true;
		}
		status[node] = 2;
		result.emplace_back(node);
	}

	return false;
}

bool is_cyclic(const vector<vector<ll>>& edges, vector<int>& status, vector<ll>& result) {
	for (ll i = 0; i < edges.size(); ++i) {
		if (status[i] == 0 && is_cyclic_impl(i, edges, status, result)) return true;
	}
	reverse(result.begin(), result.end());
	return false;
}

int solve() {
	ll N;
	cin >> N;

	N = N % 10LL;

	if (N == 3LL) {
		cout << "bon" << endl;
		return 0;
	}

	if ((N == 0LL) || (N == 1LL) || (N == 6LL) || (N == 8LL)) {
		cout << "pon" << endl;
		return 0;
	}

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

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

	solve();

	return 0;
}


Measured memory_bytes: 3644
#include <stdio.h>

typedef struct {
	int key, id;
} data;

void merge_sort(data x[], int n)
{
	static data y[200001] = {};
	if (n <= 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p].key < x[q].key)? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int main()
{
	int i, N, x[200001], y[200001];
	data d[200001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%d %d", &(x[i]), &(y[i]));
		d[i-1].key = x[i];
		d[i-1].id = i;
	}
	merge_sort(d, N);
	
	int j, k, ans[200001], t = 1, b = 1;
	for (i = 0, k = 0; i < N; i++) {
		if (N + 1 - y[d[i].id] > b) b = N + 1 - y[d[i].id];
		else if (b - t == i - k) {
			for (j = k; j <= i; j++) ans[d[j].id] = b - t + 1;
			k = i + 1;
			t = i + 2;
			b = i + 2;
		}
	}
	for (i = 1; i <= N; i++) printf("%d\n", ans[i]);
	fflush(stdout);
	return 0;
}

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

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
#define mset(a, b) memset(a, b, sizeof(a))
#define DBG(x) cout << "[" << #x << "]: " << x << endl
using ll = long long;
using pii = pair<int, int>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template<class Ty> Ty randint(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); }
template<class num> inline void rd(num& x) {
	char c; while(isspace(c = getchar()));
	bool neg = false;
	if(!isdigit(c)) neg = (c == '-'), x = 0;
	else x = c - '0';
	while(isdigit(c = getchar())) x = (x << 3) + (x << 1) + c - '0';
	x = neg ? -x : x; }
template <class... Args> inline void rd(Args&... args) { (rd(args), ...); }
template <class... Args> inline void rf(Args&... args) { (cin >> ... >> args); }
template <class... Args> inline void pr(Args&&... args) { (cout << ... << args); }

const int MAXN = 2e5 + 5, INF = 0x3f3f3f3f;

ll a[MAXN];

int main() {
	const ll M = 1000000000000000000ll;

	int n; rd(n);
	for (int i = 1; i <= n; i++) rd(a[i]);
	sort(a+1, a+n+1);

	if (a[1] == 0) {
		puts("0");
		return 0;
	}

	ll ans = 1;
	for (int i = 1; i <= n; i++) {
		if (ans <= M / a[i]) {
			ans *= a[i];
		} else {
			ans = LLONG_MAX;
			break;
		}
	}
	if (ans > M) puts("-1");
	else printf("%lld\n", ans);
}

Measured memory_bytes: 4552
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define bit(k) (1LL<<(k))
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9+7;
const double PI = acos(-1.0);

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

/*------------------------------------/
for library*/

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N;
    cin>>N;
    vector<ll> A(N);
    bool f = true;
    rep(i,N){
        cin>>A[i];
        if(A[i]%2 == 0){
            if(A[i]%3 == 0 || A[i]%5 == 0)continue;
            else f = false;
        }
    }
    if(f){
        cout<<"APPROVED"<<endl;
    }
    else{
        cout<<"DENIED"<<endl;
    }
}

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

using namespace std;

typedef long long ll;
#define pb push_back
#define dbg(x) cerr << #x << " " << x << "\n"

struct Bracket {
    int lowest;
    int toadd;
};

vector <Bracket> bad, good;

bool cmp (Bracket a, Bracket b) {
    int low1 = min (a.lowest, a.toadd + b.lowest);
    int low2 = min (b.lowest, b.toadd + a.lowest);
    return low1 > low2;
}

int main() {
    ios::sync_with_stdio (false);
    cin.tie (0); cout.tie (0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        int t = 0, p = 0;
        for (char ch : s) {
            if (ch == ')')
                p--;
            else
                p++;
            t = min (t, p);
        }
        good.pb ({t, p});
    }
    sort (good.begin (), good.end (), cmp);
    int cur = 0;
    for (Bracket x : good) {
        if (cur + x.lowest < 0) {
            cout << "No\n";
            return 0;
        }
        cur += x.toadd;
    }
    if (cur == 0)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}


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

typedef long long ll;

constexpr int MAX_N = 2001;

int n;
ll c[MAX_N], memo[MAX_N][MAX_N];

ll dfs(int a, int b);

void solve();

int main(){
	std::cin >> n;

	for(int i = 0; i < n; ++i)
		std::cin >> c[i];
	
	solve();

	return 0;
}

void solve(){
	ll ans = 0;

	for(int i = 0; i < n; ++i)
		ans = std::max(dfs(i, i) + c[i], ans);

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

ll dfs(int a, int b){
	if(memo[a][b] > 0)
		return memo[a][b];

	int diff;

	if(a > b)
		diff = n - a + b + 1;
	else 
		diff = b - a + 1;

	if(diff == n)
		return memo[a][b] = 0;

	if(diff % 2)
		return memo[a][b] = (c[(a + n - 1) % n] > c[(b + 1) % n] ? dfs((a + n - 1) % n, b) : dfs(a, (b + 1) % n));
	else
		return memo[a][b] = std::max(dfs((a + n - 1) % n, b) + c[(a + n - 1) % n], dfs(a, (b + 1) % n) + c[(b + 1) % n]);
}

Measured memory_bytes: 34456
/* In The Name of Anton*/

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

#define rep(i,n) for(int i=0;i<n;i++)
#define repa(i,a,n) for(int i=a;i<=n;i++)
#define repb(i,a,n) for(int i=a;i>=n;i--)
#define trav(a,x) for(auto a=x.begin();a!=x.end();a++)
#define all(x) x.begin(),x.end()
#define fst first
#define snd second
#define pb push_back
#define mp make_pair
typedef long double ld;
typedef pair <int,int> pii;
typedef vector <int> vi;
typedef long long ll;

void pre(){

}

void solve(){
  int n; cin>>n;
  ll a[n];
  rep(i,n) cin>>a[i];
  ll ma=a[0];

  ll ans=0;

  for(int i=1;i<n;i++){
    ll temp=ma-a[i];
    if(temp>0){
      ans+=temp;
      a[i]=a[i]+temp;
    }

    ma=max(ma,a[i]);
  }

  cout<<ans<<"\n";
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);
  pre();
  int t; t=1;
  rep(i,t) solve();
  return 0;
}


Measured memory_bytes: 5148
N,K = map(int,input().rstrip().split(" "))
S = list(input())

l = []
ans = 0
q = "1"
n = 0

for i in range(len(S)):
    if q != S[i]:
        l.append(n)
        n = 1
    else:
        n += 1
    q = S[i]
l.append(n)
if S[-1] == "0":
    l.append(0)

maxlen = K * 2 + 1

if maxlen >= len(l):
    print(N)
else:
    su = 0
    for i in range(maxlen):
        su += l[i]
    ans = su
    for i in range(0,len(l) - maxlen,2):
        su -= l[i] + l[i + 1]
        su += l[maxlen + i] + l[maxlen + i + 1]
        ans = max(ans,su)
    print(ans)

Measured memory_bytes: 78152
//To compile : type "$     g++ test.cpp -std=c++14 -I .    "
#include <atcoder/convolution>
#include <atcoder/modint>
#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
using namespace atcoder;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<60);

int main() {
	cin>>N>>M;
	vec a(N), b(M);
    rep(i, N) scanf("%lld", &a[i]);
    rep(i, M) scanf("%lld", &b[i]);
	vec c = convolution(a, b);
	rep(i, N + M - 1) printf("%lld%c", c[i], " \n"[i == N + M - 2]);
}


Measured memory_bytes: 27288
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <algorithm>
#include <cassert>
#include <string>
#include <climits>
#include <numeric>

using namespace std;
using ll = long long;

int main()
{
	int N, K;
	cin >> N >> K;
	vector<ll> h(N);
	for (int i = 0; i < N; i++)
		cin >> h[i];
	sort(h.begin(), h.end());

	ll ans = LLONG_MAX;
	for (int i = 0; i < N-K+1; i++) {
		ll h_min = h[i];
		ll h_max = h[i+K-1];
		ans = min(ans, h_max - h_min);
	}

	cout << ans << endl;
}



Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    private int findLongestPath(int[][] edges, int n) {
      List<Integer>[] adjList = new List[n + 1];
      int[] dist = new int[n + 1];
      boolean[] visited = new boolean[n + 1];
      for (int i = 1; i <= n; i++) {
        adjList[i] = new ArrayList<>();
      }
      for (int[] e: edges) {
        adjList[e[0]].add(e[1]);
      }
      for (int i = 1; i <= n; i++) {
        if (!visited[i]) {
          dfs(i, adjList, dist, visited);
        }
      }
      int result = 0;
      for (int i = 1; i <= n; i++) {
        if (dist[i] > result) {
          result = dist[i];
        }
      }
      return result;
    }
    private void dfs(int i, List<Integer>[] adjList, int[] dist, boolean[] visited) {
      visited[i] = true;
      for (int u: adjList[i]) {
        if (!visited[u]) {
          dfs(u, adjList, dist, visited);
        }
        dist[i] = Math.max(dist[i], 1 + dist[u]);
      }
    }
    public static void main(String[] args)  {
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String[] split = br.readLine().split(" ");
            int n = Integer.parseInt(split[0]);
            int m = Integer.parseInt(split[1]);
            int[][] edges = new int[m][2];
            for (int i = 0; i < m; i++) {
              split = br.readLine().split(" ");
              edges[i][0] = Integer.parseInt(split[0]);
              edges[i][1] = Integer.parseInt(split[1]);
            }
            Main app = new Main();
            int result = app.findLongestPath(edges, n);
            System.out.println(result);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 57044
#include<bits/stdc++.h>
using namespace std;
#define N 100005
#define int long long
int n,m,s,e,b,Ne[N<<1],E[N<<1],ans=1,mo=1e9+7,HEAD[N],F[N],SZ[N],TO[N];
void ADD(int s,int e) {
	E[++b]=e,Ne[b]=HEAD[s],HEAD[s]=b;
}
void DFS(int i,int f) {
	F[i]=f;
//	printf("%lld	 %lld\n",i,(m-SZ[f]-(f>0)-(F[f]>0)));
	(ans*=(m-SZ[f]-(f>0)-(F[f]>0)))%=mo;
	for(int z=HEAD[i]; z; z=Ne[z]) {
//		printf("")
		if(E[z]!=f) {
			DFS(E[z],i);
			SZ[i]++;
		}
	}
}
signed main() {
	scanf("%lld %lld",&n,&m);
	for(int i=1; i<n; i++) {
		scanf("%lld %lld",&s,&e);
		ADD(s,e),ADD(e,s);
		TO[s]++,TO[e]++;
	}
	DFS(1,0);
//	for(int i=1; i<=n; i++) {
//		if(TO[i]==1) {
//			DFS(i,0);
//			break;
//		}
//	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 8832