akhauriyash/Code-Regression huggingface dataset:
#![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! vmax {
    ($x: expr, $y: expr) => { cmp::max($x, $y) };
    ($x: expr, $($args: expr),*) => { cmp::max($x, vmax!($($args),*)) };
}

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

fn main() {
    let n = parse_word::<usize>();
    let k = parse_word::<usize>();

    // N (> 0) ranges cover (K + (N - 1) * (K - 1)) length.
    // Thus, N = ceil((len - K) / (K - 1)) + 1.
    println!("{}", if n == k { 1 } else { (n - k - 1) / (k - 1) + 2 });
}

#[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();
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    string s;
    cin>>s;
    int cnt=0;
    int n=s.length();
    int max1=0;
    rep(i,n){
        if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T'){
            cnt++;
        }
        else{
            cnt=0;
        }
        max1=max(max1,cnt);
    }
    cout<<max1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;

long long modpow(long long a,long long n,long long p)
{
    if(n==1)
    {
        return a%p;
    }
    if(n%2==1)
    {
        return a*modpow(a,n-1,p)%p;
    }
    long long t = modpow(a,n/2,p);
    return t*t%p;
}
 
//O(K)でnCkを求める
int comb( int N, int K ){
  int X = 1; //分子
  int Y = 1; //分母
  for( int i = N; i > N-K; i-- ){
    X = (X*i)%MOD;
  }
  for( int i = 1; i <= K; i++ ){
    Y = (Y*i)%MOD;
  }
  return X * modpow(Y, MOD-2, MOD)%MOD;   //Aの逆元を取る場合、modpow(A, MOD-2, MOD) https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a 3-4参照
}

int main()
{
    int n,m;
    cin>>n>>m;
    int count;
    count = (n*(n-1)/2+m*(m-1)/2);
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstdlib>

using namespace std;

const int MAXN=200010;
const int MAXM=(1<<26);
char s[MAXN];
int f[MAXN],g[MAXN],minn[MAXM];

int main()
{
	scanf("%s",s+1);
	int n=strlen(s+1);
	for (int i=1;i<=n;i++)
	{
		int c=s[i]-'a';
		g[i]=g[i-1]^(1<<c);
	}
	minn[0]=0;
	for (int i=1;i<(1<<26);i++)
	{
		minn[i]=1e9;
	}
	for (int i=1;i<=n;i++)
	{
		f[i]=1e9;
		for (int j=0;j<26;j++)
		{
			int zt=g[i]^(1<<j);
			f[i]=min(f[i],minn[zt]+1);
		}
		f[i]=min(f[i],minn[g[i]]+1);
		minn[g[i]]=min(minn[g[i]],f[i]);
	}
	cout<<f[n];
	return 0;
}


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

int main(){
  int A,B;
  cin>>A>>B;
  if(A>=13){
    cout<<B<<endl;
  }
  if((6<=A)&&(A<=12)){
    cout<<B/2<<endl;
  }
  if(A<=5){
    cout<<0<<endl;
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++){
    a[i] = i + 1;
  }
  while (1){
    for (int i = 0; i < n; i++){
      cout << a[i];
      if (i < n - 1){
        cout << ' ';
      }
    }
    cout << endl;
    if (!next_permutation(a.begin(), a.end())){
      break;
    }
  }
}


Measured memory_bytes: 3108
#include <iostream>
using namespace std;
#define ll long long
int main() {
  ll a,b,c,k,ans=0;
  cin>>a>>b>>c>>k;
  if(a<k)
  {
    ans+=a;
    k-=a;
  }
  else
  {
    ans+=k;
    k=0;
  }
  if(b<k)
  {
    k-=b;
  }
  else
  {
    k=0;
  }
  if(c<k)
  {
    ans-=c;
    k-=c;
  }
  else
  {
    ans-=k;
    k=0;
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

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

		int count = 0;
		if (s.equals(t)) {
			System.out.println(count);
			return;
		}
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) != t.charAt(i)) {
				count++;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 32220
#include<iostream>
#include<vector>
#include<algorithm>
#include<string.h>
#define int long long
using namespace std;
const int N=502;
const int inf=1e15+2;
int ar[N][N],dp[N][N],sum[N][N],f[N][N],damn[N][N];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k,l,ans=inf,xd=0;
	cin>>n;
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			if(i==j){
				continue;
			}
			cin>>ar[i][j];
			sum[i][j]=sum[i][j-1]+ar[i][j];
			xd+=ar[i][j];
		}
	}
//	cout<<"cac"<<endl;
	for(i=1;i<=n;i++){
		for(j=0;j<=n;j++){
			dp[i][j]=inf;
		}
		dp[0][i]=inf;
		for(j=i;j<=n;j++){
			for(k=1;k<=n;k++){
				damn[i][j]+=sum[k][j]-sum[k][i-1];	
			}
			f[i][j]=f[i][j-1];
			for(k=i;k<j;k++){
				f[i][j]+=ar[k][j];
			}
		}
	}
//	cout<<"cac"<<endl;
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			for(k=j;k<=n;k++){
				damn[j][k]-=sum[i][k]-sum[i][j-1];
			}
		}
		for(j=0;j<i;j++){
			for(k=0;k<=j;k++){
				dp[i][j]=min(dp[i][j],dp[j][k]+damn[k+1][j]+f[j+1][i]);
			}
			if(i==n){
				ans=min(ans,dp[i][j]);
			}
		}
	}
	cout<<ans;
}

Measured memory_bytes: 10112
import sys
MOD = 998244353
def main():
    input = sys.stdin.readline
    N, S = map(int, input().split())
    *A, = map(int, input().split())
    A = [0] + A
    dp = [[0] * 3 for __ in range(S + 5)]
    dp[0][0] = 1
    for i in range(1, N + 1):
        for s in range(S, -1, -1):
            ps = s - A[i]
            dp[s][1] = (dp[s][1] + dp[s][0]) % MOD
            dp[s][2] = (dp[s][2] + dp[s][0]) % MOD
            dp[s][2] = (dp[s][2] + dp[s][1]) % MOD
            if ps >= 0:
                dp[s][1] = (dp[s][1] + dp[ps][0]) % MOD
                dp[s][1] = (dp[s][1] + dp[ps][1]) % MOD
                dp[s][2] = (dp[s][2] + dp[ps][0]) % MOD
                dp[s][2] = (dp[s][2] + dp[ps][1]) % MOD

    print(dp[S][2])

if __name__ == '__main__':
    main()


Measured memory_bytes: 68804
b = input().split(" ")
num = [0 for i in range(int(b[0]))] 
for i in range(int(b[1])):
    a = input().split(" ")
    num[int(a[0])-1] = num[int(a[0])-1]+1
    num[int(a[1])-1] = num[int(a[1])-1]+1

for i in range(int(b[0])):
    print(num[i])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

long long gcd(long long a,long long b) {
  if(b==0) return a;
  else return gcd(b,a%b);
}


int main() {
  
  long long X,Y;
  cin >> X >> Y;

  if(X % Y == 0) {
    cout << -1 << endl;
    return 0;
  }

  long long l = X*Y / gcd(X,Y);

  if(l+X > 1000000000000000000) cout << l-X << endl;
  else cout << l+X << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define pc(x)  __builtin_popcount (x)
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define ld long double
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod 1000000007
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout) 
#define gcd __gcd
#define primeDEN 727999983
#define nx_pe next_permutation(s.begin(),s.end())
#define cl cout<<"\n"

    
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL) ;
    std::ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a[n];ll x=0;
    rep(i,n)cin>>a[i],x^=a[i];
    rep(i,n){
        ll y=x^a[i];
        cout<<y<<" ";
    }



}




Measured memory_bytes: 5208
from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math
from fractions import gcd

_,__,M=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
XYC=[list(map(int,input().split())) for i in range(M)]

value=min(A)+min(B)


for x,y,c in XYC:
    value=min(value,A[x-1]+B[y-1]-c)
print(value)


Measured memory_bytes: 104896
k = int(input()) 
 
lunlun = [i for i in range(1, 10)]
 
p = 0 

def generate_lunlun(p):
    last = p % 10
    if last - 1 >= 0:
        yield p * 10 + last - 1
    yield p * 10 + last
    if last + 1 <= 9:
        yield p * 10 + last + 1 

while len(lunlun) < k:
    for new_lunlun in generate_lunlun(lunlun[p]):
        lunlun.append(new_lunlun)
    p += 1

print(lunlun[k-1])

Measured memory_bytes: 7272
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <cassert>
using namespace std;

typedef unsigned long long lli;

//const lli H = 1000000007LL;
const lli B = 8999;
lli B2;
lli Bn[300005];

int n, m;
string s, q;

lli gcd(lli a, lli b) {
  return b == 0 ? a : gcd(b, a%b);
}

lli b_pow(lli x,lli b){
  return b ? b_pow(x*x,b/2) * ((x&1)?x:1) : 1;
}

lli mypow(lli x, lli n) {
  if(n == 0) return 1ull;
  lli tmp = mypow(x, n/2);
  if(n%2ull) return tmp*tmp*x;
  return tmp*tmp;
}

inline lli conv(char c) {
  return (lli)c;
  return c - 'a' + 1ull;
}

int main() {
//  cout << H*H << endl;
  //assert(gcd(H, B) == 1LL);
  B2 = b_pow(8999,18446744073709551614ull);
  //cout << b_pow(8999,18446744073709551614ull) << endl;
  //cout << mypow(8999,18446744073709551614ull) << endl;
  Bn[0] = 1ull;
  for(int i = 1; i < 300005; ++i) {
    Bn[i] = Bn[i-1] * B;
  }
  while(cin >> n >> m) {
    set<lli> vis;
    cin >> s;
    int L, R;
    L = R = 0;
    lli h = conv(s[0]);
    while(m--) {
      cin >> q;
      if(0) {
      } else if(q == "L++") {
        h = h - Bn[R-L]*conv(s[L]);
        L++;
      } else if(q == "L--") {
        L--;
        h = h + Bn[R-L]*conv(s[L]);
      } else if(q == "R++") {
        R++;
        h = h * B + conv(s[R]);
      } else if(q == "R--") {
        h -= conv(s[R]);
        h *= B2;
        R--;
      }
      //cout << h << ":" << s.substr(L, R-L+1) << endl;
      vis.insert(h);
    }
    cout << vis.size() << endl;
  }
  return 0;
}

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

int main(){
  int H, A;
  cin >> H >> A;
  if(H % A == 0){
    cout << H / A << endl;
    return 0;
  }
  else{
    cout << H / A + 1 << endl;
    return 0;
  }
}


Measured memory_bytes: 256
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define dcml(n) fixed<<setprecision(n)
using namespace std;
int main(void){
    ll N;cin>>N;
    ll A[N+1];
    REP(i,N+1){
        cin>>A[i];
    }
    ll B[N];REP(i,N)cin>>B[i];

    ll ans=0;
    REP(i,N){
        if(A[i]<=B[i]){
            ans+=A[i];
            B[i]-=A[i];
            if(A[i+1]<=B[i]){
                ans+=A[i+1];
                A[i+1]=0;
            }else{
                A[i+1]-=B[i];
                ans+=B[i];
            }
        }else{
            ans+=B[i];
        }
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 1792
// In The Name Of God
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int maxn = 3e3 + 40;
int a, b, c, d, e, f;
pair<int, int> p[maxn][maxn];

bool can(int w) {
    return (w + c <= f || w + d <= f || w + 100 * a <= f || w + 100 * b <= f);
}

double dens(int w, int s) {
	if (w + s == 0)
		return 0;
	return (double)(100 * s) / (double)(w);
}

pair<int, int> solve(int w, int s) {
	if (p[w][s].first != -1)
		return p[w][s];
    pair<int, int> ans = {w + s, s};
    if (!can(w + s)) {
        if (dens(ans.first, ans.second) > dens(e + 100, e)) {
			p[w][s] = {100 * a, 0};
            return {100 * a, 0};
		}
        else {
			p[w][s] = ans;
            return ans;
		}
    }
    else {
        if (w + s + c <= f) {
            pair<int, int> t = solve(w, s + c);
            if (dens(t.first, t.second) > dens(ans.first, ans.second))
                ans = t;
        }
        if (w + s + d <= f) {
            pair<int, int> t = solve(w, s + d);
            if (dens(t.first, t.second) > dens(ans.first, ans.second))
                ans = t;
        }
        if (w + s + 100 * a <= f) {
            pair<int, int> t = solve(w + 100 * a, s);
            if (dens(t.first, t.second) > dens(ans.first, ans.second))
                ans = t;
        }
        if (w + s + 100 * b <= f) {
            pair<int, int> t = solve(w + 100 * b, s);
            if (dens(t.first, t.second) > dens(ans.first, ans.second))
                ans = t;
        }
    }
	if (dens(ans.first, ans.second) > dens(e + 100, e)) {
		p[w][s] = {100 * a, 0};
		return {100 * a, 0};
	}
	p[w][s] = ans;
    return ans;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> a >> b >> c >> d >> e >> f;
	for (int i = 0; i < maxn; i++)
		for (int j = 0; j < maxn; j++)
			p[i][j] = {-1, -1};
    pair<int, int> ans = solve(0, 0);
	if (ans.first == 0)
		ans = {100 * a, 0};
    return cout << ans.first << ' ' << ans.second << endl, 0;
}

Measured memory_bytes: 72576
program main
implicit None
	integer::n,k,p,a,i,j,b
	integer,allocatable::d(:)
	character(len = 5)::c
	
	read *,n,k
	allocate(d(k))
	
	read *,d
	
	do
		p = 0
		write(c,"(i5)")n
		c =adjustl(c)
		a =len_trim(c)
		do i = 1,a
			do j = 1,k
				read(c(i:i),*)b
				if(b == d(j)) p = 1
			enddo
		enddo
		if(p == 1)then
			n = n + 1
			else
			exit
		endif
	enddo
	
	print *,n
	
end program main

Measured memory_bytes: 256
using System;
class c
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int now = 1;
        for (int i = 0; i < n; i++)
        {
            if (a[i] == now) now++;
        }
        Console.WriteLine(now == 1 ? -1 : n - now + 1);
    }
}

Measured memory_bytes: 42964
#include <iostream>

using namespace std;

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

int m, n;
int map[91][91];
int ans;

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

int dfs(int x, int y)
{
    int ret = 1;

    map[y][x] = 0;
    for (int i = 0; i < 4; i++) {
        int nx = x + dx[i];
        int ny = y + dy[i];

        if (canMove(nx, ny) && map[ny][nx] == 1) 
            ret = max(ret, dfs(nx, ny) + 1);
    }
    map[y][x] = 1;

    return ret;
}

int main()
{
    while (cin >> m >> n, m || n) {
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                cin >> map[i][j];
        // for (int i = 0; i < n; i++) {
        //     for (int j = 0; j < m; j++)
        //         cout << map[i][j] << " ";
        //     cout << endl;
        // }
        
        ans = 0;
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                if (map[i][j] == 1)
                    ans = max(dfs(j, i), ans);

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num,init) vector<ll> name((num),(init));
#define op(i) cout<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define mat(name,fnum,snum,init); vector<vector<ll>> name((fnum),vector<ll>((snum),(init)));
#define debugP int debug_point; cin>>debug_point;
template <typename T>
void putv(vector<T>& V){
	// cout << "The elements in the vector are: " << endl;
	for(auto x: V)
		cout << x << " ";
	cout << endl;
}
template <class T>
vector<T> getv(int n){
	vector<T> Vector_temp;
	rep(i,n){
		T input;
		cin >> input;
		Vector_temp.emplace_back(input);
	}
	return Vector_temp;
}
/* <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3*/

int main(){
    int n;
    cin>>n;
    vec(a,n,0);
    vector<int> b(100001,0);
    rep(i,n){
        cin>>a[i];
        b[a[i]]++;
    }
    int ans=-1;
    repf(i,1,100000){
        ans=max(ans,b[i-1]+b[i]+b[i+1]);
    }

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

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
using namespace std;
int n;
vector<int> win[100009];
int getdep(int x){
	vector<int> dps;
	if(win[x].size()==0)return 0;
	for(int i=0;i<win[x].size();i++){
		dps.pb( getdep(win[x][i]) );
	}
	sort(dps.begin(), dps.end() );
	for(int i=0;i<dps.size();i++){
		dps[i] += dps.size() - i;
	}
	sort(dps.begin(),dps.end());
	return dps[dps.size()-1];
}
int main(){
	cin>>n;
	for(int i=2;i<=n;i++){
		int tmp;
		cin>>tmp;
		win[ tmp ].pb(i);
	}
	cout<<getdep(1)<<endl;
	return 0;
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORX(i, a, b, x) for (int i = (a); i <= (b); i+=x)
#define debug(x) cerr << #x << " is= " << x << endl; //use for debugging
#define read(a) int a; cin >> a;
#define reads(s) string s; cin >> s;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 5] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
 
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;}
 
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define mp(a,b) make_pair(a,b)
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long int
#define vi         vector<int>
#define vll        vector<ll>
#define vpii       vector<pair<int,int>>
#define vov        vector<vector<int>> 
#define pr         pair<ll,ll>
#define vpll       vector<pair<ll,ll>>
#define all(v)     v.begin(),v.end()
#define rall(v)    v.rbegin(),v.rend()  //reverse of above;
#define sz(container) int((container).size())
#define cut(x) {cout<<x<<"\n"; return;}
#define setprec(x) cout << fixed << showpoint << setprecision(8)<<x<<endl;
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/__gcd(a,b)
#define time cout << clock() / double(CLOCKS_PER_SEC) << endl;
#define endl "\n"
#define mod 1000000007
using namespace std;
using namespace __gnu_pbds;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; 
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
//*s.find_by_order() ->returns an iterator to the k-th largest element (counting from zero);
//s.order_of_key() ->number of elements strictly smaller then our item;
//st.rbegin()->second; last element in set
//st.erase(prev(st.end())); delete last element in set;
//sort(a+1,a+n+1,[](ll x,ll y){return abs(x)>abs(y);});
//sort(v.begin(), v.end(), greater<int>()); 
const int N=2e5+5;
ll n,k,a[N],ans=0;
void solve()
{
 map<ll,ll>m;
 m[0]++;
 FOR(i,1,n)
 {
  a[i]--;
  a[i]=a[i-1]+a[i];
  a[i]%=k;
 }
 //FOR(i,1,n) cout<<a[i]<<' ';
 cout<<endl;
 FOR(i,1,n)
 {
  if(i-k>=0) m[a[i-k]]--;
  ans+=m[a[i]];
  m[a[i]]++;
 }
 cout<<ans;
}
int main()
{
  fast_io;
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
  cin>>n>>k;
  FOR(i,1,n) cin>>a[i];
  solve();
}

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

using lint = long long;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    lint n;
    cin >> n;
    lint ret = n-1;
    for (lint i = 1; i <= 10001000; ++i)
        if (n % i == 0) {
            lint k = i*i + n;
            ret = min(ret, k/i - 2);
        }
    cout << ret << '\n';
}

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

long long int N, a[114514], i, ans;

int main(){
    scanf("%lld", &N);
    for(; i < N; --a[i], ++i)scanf("%lld", a + i);
    for(i = 0; i < N; ++i){
        if(a[i] == i){
            ++ans;
            swap(a[i], a[i + 1]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
let split str delim =
  let rec doit s acc =
    match
      try Some (String.index s delim)
      with _ -> None
    with
    | None -> s :: acc
    | Some i ->
        let s1 = String.sub s 0 i in
        let s2 = String.sub s (i + 1) (String.length s - String.length s1 - 1) in
        doit s2 (s1 :: acc)
  in
  List.rev (doit str [])

let string_fold_left f init str =
  let n = String.length str in
  let rec doit i acc =
    if i >= n then acc
    else doit (i + 1) (f acc str.[i])
  in
  doit 0 init

let swap (a, b) = (b, a)

let make_dice = function
  | a :: b :: c :: d :: e :: f :: _ -> [(a, f); (b, e); (c, d)]
  | _ -> exit 1

let roll dice cmd =
  match dice with
  | [] | [_] | _::_::[] -> exit 1
  | x :: y :: z :: _ ->
      match cmd with
      | 'N' -> [y; swap x; z]
      | 'S' -> [swap y; x; z]
      | 'E' -> [swap z; y; x]
      | 'W' -> [z; y; swap x]
      | _ -> exit 1

let multi_roll dice cmds =
  string_fold_left (fun acc c -> roll acc c) dice cmds

let rotate_clockwise = function
  | [] | [_] | _::_::[] -> exit 1
  | x :: y :: z :: _ -> [x; z; swap y]

let all_rolled_patterns dice =
  let pin_top d =
    [d; roll d 'N'; roll d 'W'; roll d 'E'; roll d 'S'; multi_roll d "SS"]
  in
  let rotate d =
    let d1 = rotate_clockwise d in
    let d2 = rotate_clockwise d1 in
    let d3 = rotate_clockwise d2 in
    [d; d1; d2; d3]
  in
  List.concat (List.map rotate (pin_top dice))

let () =
  let l = read_line () in
  let d1 = make_dice (List.map int_of_string (split l ' ')) in
  let l = read_line () in
  let d2 = make_dice (List.map int_of_string (split l ' ')) in
  if List.mem d1 (all_rolled_patterns d2) then Printf.printf "Yes\n"
  else Printf.printf "No\n"

Measured memory_bytes: 2160
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}




int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll N , M ; cin >> N >> M ;
  map<ll, vector<ll> > E;
  rep(i,M){
    ll a, b; 
    cin >> a >> b;
    E[a].pb(b);
    E[b].pb(a);
  }
  
  vector<ll> lst;
  rep(i,N){
    lst.pb(i+1);
  }

  ll ans = 0;
  do{
    //開始が必ず1から
    if(lst[0] != 1 )continue;

    

    
    
    bool flag = true;
    rep(i,N-1){
      ll a = lst[i];
      ll b = lst[i+1];
      bool flag1 = false;
      rep(j,E[a].size()){
	if(E[a][j] == b) {flag1 = true; break;}
      }
      
      if(!flag1) {
	flag = false;
	break;
      }
    }
    if(flag) ans ++;
    
  }while(next_permutation(all(lst)));

  cout << ans << endl;
  
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  vector<ll> b(n+1,0);
  rep(i,n) b[i+1] = b[i] + a[i];
  ll ans=0;
  int MOD=1000000007;
  rep(i,n) {
    ll sum=(b[n]-b[i+1])%MOD;
    ans += a[i]*sum;
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 6424
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    ll n;
    cin>>n;
    cout<<n*(n-1)/2<<endl;
    return 0;
}

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

int main()
{   int i, j, n, m, k;
    cin>>n>>m>>k;

    for(i=0; i<=n; i++)
        for(j= 0 ; j<=m ;j++)
            if(n*j+m*i-2*i*j==k) {cout<<"Yes"<<endl;return 0;}

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










Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
using namespace std;

int K,X;
int ans = 0;
 
void solve(){
  if(500*K>=X) ans = 1;
}
 
int main(){
  cin>>K>>X;
 
	solve();

 if(ans==1){
  cout << "Yes";
  return 0;
 }
  cout << "No";
  return 0;
}

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

using namespace std;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple

// #define N 311111
#define A 1111111
#define BLOCK 555 // ~sqrt(N)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;

const int INF = 1e9 +5;
const int nax = 100005;
const long M = 1000000007;

ll dp[nax];
// int in_degree[nax];
// vector<int> edges[nax];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	// cout<<fixed;
	// cout<<setprecision(10);
	int t;
	// cin>>t;
	t = 1;
	while(t--){
		ll n,k;
		cin>>n>>k;
		int arr[n];
		for(int i=0;i<n;i++){
			cin>>arr[i];
		}
		
		for(int val=1;val<=k;val++){
			for(int stones=0;stones<n;stones++){
				if(arr[stones] <= val && dp[val - arr[stones]]==0){
					dp[val] = 1;
				}
			}
		}

		if(dp[k]==1){
			cout<<"First"<<endl;
		}
		else{
			cout<<"Second"<<endl;
		}
	}
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int MAXN=20005 , T=500000000 ;
int n , P[MAXN] , A[MAXN] , B[MAXN] ;
int tag[MAXN] ;

int main(){
	scanf("%d",&n) ;
	for(int i=1;i<=n;++i) scanf("%d",&P[i]) ;
	for(int i=1;i<=n;++i) A[i]=T+i , B[i]=T+(n-i+1) ;
	for(int i=2;i<=n;++i){
		A[P[i]]+=(i-1) ;
		tag[P[i]+1]+=(i-1) ;
	}
	int sum=0 ;
	for(int i=1;i<=n;++i){
		sum+=tag[i] ;
		A[i]+=sum , B[i]-=sum ;
	}
	for(int i=1;i<=n;++i) { printf("%d ",A[i]) ; }
	printf("\n") ;
	for(int i=1;i<=n;++i) { printf("%d ",B[i]) ; }
	return 0 ;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

struct union_find {
  vector<int> par;

  union_find() {}
  union_find(int n) :
    par(n+1, -1)
  {}

  int root(int x) {
    if(par[x] < 0) return x;
    return par[x] = root(par[x]);
  }
  int size(int x) {
    return -par[root(x)];
  }
  bool same(int a, int b) {
    return root(a) == root(b);
  }
  bool marge(int a, int b) {
    a = root(a), b = root(b);
    if(a == b) return false;
    if(par[a] > par[b]) swap(a, b);
    par[a] += par[b];
    par[b] = a;
    return true;
  }
};

int main() {
  llong N, M, K;
  union_find uf;
  vector<lpair> AB, CD;

  cin >> N >> M >> K;
  AB.resize(M);
  CD.resize(K);
  uf = union_find(N);
  for (auto &in: AB) {
    cin >> in.first >> in.second;
    uf.marge(in.first, in.second);
  }
  for (auto &in: CD) {
    cin >> in.first >> in.second;
  }

  vector<llong> ans(N + 1);
  for (int i = 1; i <= N; ++i) {
    ans[i] = uf.size(i) - 1;
    cerr << ans[i] << " ";
  }
  cerr << endl;

  for (auto &ab: AB) {
    --ans[ab.first];
    --ans[ab.second];
  }
  for (auto &cd: CD) {
    if (uf.same(cd.first, cd.second)) {
      --ans[cd.first];
      --ans[cd.second];
    }
  }

  for (int i = 1; i <= N; ++i) {
    cout << ans[i] << " ";
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.20f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;

int main() {
	int n;
	cin >> n;
	ll d;
	cin >> d;
	ll x[n], y[n];
	rep (i, n) cin >> x[i] >> y[i];

	int cnt = 0;
	rep (i, n) {
		if (x[i]*x[i] + y[i]*y[i] <= d * d) cnt++;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 6748
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(int i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    UnionFind uf(n + m);
    rep (i, n) {
        int k; cin >> k;
        rep (j, k) {
            int t; cin >> t; t--;
            uf.unite(i, n + t);
        }
    }
    int gr = uf.find(0);
    rep (i, n) {
        if (uf.find(i) != gr) {
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001001001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

// 数値を受け取り素因数分解の結果を返す
// 計算量はおおよそO(√N)
// 形式：12 -> [[2, 2], [3, 1]]
vector<pair<ll, ll>>
factorization(ll num)
{
    map<ll, ll> mp;

    ll tmp = num;
    for (ll i = 2; i * i <= num; i++)
    {
        while (tmp % i == 0)
        {
            mp[i]++;
            tmp /= i;
        }
    }
    if (tmp != 1)
    {
        mp[tmp]++;
    }
    vector<pair<ll, ll>> ret;
    for (auto m : mp)
    {
        ret.push_back(make_pair(m.first, m.second));
    }
    return ret;
}

int main()
{
    ll n, p;
    cin >> n >> p;
    auto fac = factorization(p);
    ll ans = 1;
    for (auto f : fac)
    {
        ans *= pow(f.first, f.second / n);
    }
    cout << ans << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
};

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
const int dr[]={0,1,0,-1,0};

int main(){
	int n;
	cin >>n;
	int mx=-1, svb=-1;
	rep(i,n){
		int a, b;
		cin >>a >>b;
		if(a > mx){mx=a; svb=b;}
	}
	cout << mx + svb  <<"\n";
}



Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;

#define INF 1e9
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;


int main() {
    string a, b;
    cin >> a >> b;
    if (a.size() > b.size()) goto lasta;
    else if (a.size() < b.size()) goto lastb;
    else {
        rep(i, a.size()) {
            if (a.at(i) < b.at(i)) goto lastb;
            else if (a.at(i) > b.at(i)) goto lasta;
        }
        cout << "EQUAL" << endl;
        return 0;
    }
    lasta:
    cout << "GREATER" << endl;
    return 0;
    lastb:
    cout << "LESS" << endl;
    return 0;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int a,b,t;
    cin>>a>>b>>t;
    cout<<(t/a)*b<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define PII pair < int, int >
#define x first
#define y second
#define pb push_back
  
using namespace std;
ll n, x, y, rs;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    while (n--){
		cin >> x >> y;
		rs += y - x + 1;
	}
	cout << rs;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
template<typename A, size_t N, typename T>void Fill(A (&a)[N], const T &val){fill((T*)a, (T*)(a+N), val);}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 302;
int n, T, H[N];
ll DP[N][N], DP2[N][N];
ll mi[N+1];
V<int> z={0};

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> T;
  FOR(i, 0, n){
    cin >> H[i];
    z.pb(H[i]);
  }
  uniq(z);
  int C = sz(z);
  mi[C] = LINF;
  FOR(i, 0, n) H[i] = lower_bound(all(z), H[i]) - z.begin();
  Fill(DP, LINF);
  FOR(i, 0, C) DP[0][i] = z[i];
  FOR(i, 0, n){
    Fill(DP2, LINF);
    FOR(j, 0, T+1){
      FORR(k, C-1, 0) mi[k] = min(mi[k+1], DP[j][k]);
      ll m = LINF;
      FOR(k, 0, C){
        mins(m, DP[j][k]-z[k]);
        if(k==H[i]) mins(DP2[j][k], min(mi[k], m+z[k]));
        DP2[j+1][k] = min(mi[k], m+z[k]);
      }
    }
    swap(DP, DP2);
  }
  ll ans = LINF;
  FOR(i, 0, T+1)FOR(j, 0, C) mins(ans, DP[i][j]);
  cout << ans << endl;
}

Measured memory_bytes: 1664
#include<stdio.h>
#include<string.h>

int main(){
  char S[100000] = {};
  scanf("%s", &S);

  char prec = S[0];
  int count = 0;
  for(int i=1; i<100000; i++){
    if(S[i]=='\0'){
      break;
    }else if(S[i]!=prec){
      count++;
    }
    prec = S[i];
  }

  printf("%d\n", count);
  return 0;
}


Measured memory_bytes: 1820
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

# define INF 0x3f3f3f3f

template <typename T>
struct Edge {
  int src, dst;
  T weight;
  Edge(int src, int dst, T weight) :
    src(src), dst(dst), weight(weight) { }
};
template <typename T>
bool operator < (const Edge<T> &e, const Edge<T> &f) {
  return e.weight != f.weight ? e.weight > f.weight :
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

template <typename T>
struct Graph {
  int V;    // 頂点数
  vector<Edge<T>> *adj;

  explicit Graph(int V) {
    this->V = V;
    adj = new vector<Edge<T>> [V];
  }
  void add_edge(int src, int dst, T weight) {
    assert(src >= 0 && src < V);
    assert(dst >= 0 && dst < V);
    adj[src].push_back(Edge<T>(src, dst, weight));
  }
  vector<T> shortest_path(int s);
  // vector<vector<T>> shortest_paths();
  // Graph<T> spanning_tree();
};

// 最短経路 (Dijkstra)
template <typename T>
vector<T> Graph<T>::shortest_path(int src) {
  priority_queue<Edge<T>> pq;
  vector<T> dist(V, INF);

  pq.push(Edge<T>(src, src, 0));
  dist[src] = 0;

  while (!pq.empty()) {
    int u = pq.top().dst;
    pq.pop();

    for (const auto& e : adj[u]) {
      if (dist[e.dst] > dist[u] + e.weight) {
        dist[e.dst] = dist[u] + e.weight;
        pq.push(Edge<T>(src, e.dst, dist[e.dst]));
      }
    }
  }
  return dist;
}

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

  ll N;
  cin >> N;

  Graph<int> g(N);

  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    g.add_edge(a - 1, b - 1, 1);
    g.add_edge(b - 1, a - 1, 1);
  }

  vector<int> dist1 = g.shortest_path(0);
  vector<int> dist2 = g.shortest_path(N - 1);

  int cnt1 = 0;
  int cnt2 = 0;
  for (int i = 0; i < N; i++) {
    if (dist1[i] <= dist2[i]) {
      cnt1++;
    } else {
      cnt2++;
    }
  }
  if (cnt1 > cnt2) {
    cout << "Fennec" << endl;
  } else {
    cout << "Snuke" << endl;
  }
  return 0;
}


Measured memory_bytes: 8104
class PriorityQueue
  def initialize(array = [])
    @data = []
    array.each{|a| add(a)}
  end
  
  def add(element)
    @data.push(element)
    bottom_up
  end
  
  def sum()
    return @data.inject(:+)
  end
  
  # @return Integer
  def peek
    @data[0]
  end
 
  # @return Integer
  def poll
    if size == 0
      return nil
    elsif size == 1
      return @data.pop
    else
      max = @data[0]
      @data[0] = @data.pop
      top_down
      return max
    end
  end
  
  # @return Integer
  def size
    @data.size
  end
 
  private
 
  def swap(i, j)
    @data[i], @data[j] = @data[j], @data[i]
  end
 
  
  def bottom_up
    idx = size - 1
    while(has_parent?(idx))
      parent_idx = parent_idx(idx)
      if @data[parent_idx] < @data[idx]
        swap(parent_idx, idx)
        idx = parent_idx
      else
        return
      end
    end
  end
  
  def top_down
    idx = 0
    while (has_child?(idx))
      a = left_child_idx(idx)
      b = right_child_idx(idx)
      if @data[b].nil?
        c = a
      else
        c = @data[a] >= @data[b] ? a : b
      end
      if @data[idx] < @data[c]
        swap(idx, c)
        idx = c
      else
        return
      end
    end
  end
  
 
  # @param Integer
  # @return Integer
  def parent_idx(idx)
    (idx - (idx.even? ? 2 : 1)) / 2
  end
 
  # @param Integer
  # @return Integer
  def left_child_idx(idx)
    (idx * 2) + 1
  end
 
  # @param Integer
  # @return Integer
  def right_child_idx(idx)
    (idx * 2) + 2
  end
 
  # @param Integer
  # @return Boolent
  def has_child?(idx)
    ((idx * 2) + 1) < @data.size
  end
 
  def has_parent?(idx)
    idx > 0
  end
end

n,m=gets.split.map(&:to_i)
a=gets.split.map(&:to_i)
pq=PriorityQueue.new(a)
m.times{x=pq.poll;pq.add(x/2)}
s=0
puts pq.sum


Measured memory_bytes: 11924
#include<iostream>
#include<string>
#include<sstream>
#include<iomanip>
using namespace std;
class BigInt{
  unsigned int i[11];
public:
  BigInt(string str){
    if(str.size()>80){i[0]=1; return;}
    i[0]=0;
    for(int j=80;j>0;j-=8){
      if((int)str.size()>j){
	stringstream ss;
	ss << str.substr(str.size()-j,8);
	ss >> i[11-j/8];
      }else if((int)str.size()+8>j){
	stringstream ss;
	ss << str.substr(0,str.size()+8-j);
	ss >> i[11-j/8];
      }else{
	i[11-j/8]=0;
      }
    }
  }
  BigInt():i{0,0,0,0,0,0,0,0,0,0,0}
  {}
  void print(){
    if(i[0]>0)
      cout << "overflow\n";
    else{
      int j=1;
      for(;j<11;j++)
	if(i[j]>0 || j == 10)
	  break;
      cout << i[j++];
      for(;j<11;j++)
	cout << setfill('0') << setw(8) << right << i[j];
      cout << "\n";
    }
  }
  BigInt operator+(const BigInt& rhs){
    BigInt result = rhs;
    for(int j=10;j>0;j--){
      result.i[j] += i[j];
      if(result.i[j]>=100000000){
	result.i[j]-=100000000;
	result.i[j-1]++;
      }
    }
    result.i[0]+=i[0];
    return result;
  }
};

int main(){
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    string tmp;
    cin>>tmp;
    BigInt b(tmp);
    cin>>tmp;
    BigInt a(tmp);
    (a+b).print();
  }
}

Measured memory_bytes: 1244
w,h,n = map(int, input().split())
xya = []
xl, xr, yu, yt = 0, w, 0, h
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
       if xl < x:
           xl = x 
    elif a == 2:
        if xr > x:
            xr = x
    elif a == 3:
        if yu < y:
            yu = y
    else:
        if yt > y:
            yt = y
print([(xr - xl) * (yt - yu), 0][(xr - xl) <= 0 or (xr - xl) <= 0])

Measured memory_bytes: 3064
n,m=map(int,raw_input().split())
c=map(int,raw_input().split())

dp=[i for i in range(n+1)]

c.remove(1)
c.sort()

for coin in c:
	for x in range(1,n+1):
		if x-coin>=0:
			dp[x]=min(dp[x],dp[x-coin]+1)

print dp[n]


Measured memory_bytes: 7624
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
const int MAX = 100005;
int a[MAX][3];
ll dp[MAX][3];
int main() {
	int n,i,j,k;
	cin>>n;
	for(i=0;i<n;++i) {
		for(j=0;j<3;++j) {
			cin>>a[i][j];
		}
	}
	dp[0][0] = a[0][0];
	dp[0][1] = a[0][1];
	dp[0][2] = a[0][2];
	for(i=1;i<n;++i) {
		for(j=0;j<3;++j) {
			for(k=0;k<3;++k) {
				if(k == j) continue;
				dp[i][j] = max(dp[i][j], dp[i-1][k] + a[i][j]);
			}
		}
	}
	cout<<max({dp[n-1][0], dp[n-1][1], dp[n-1][2]})<<endl;
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  int n;
  cin >> n;
  int now=0;
  set<int> st;
  int x;
  bool ok=false;
  rep(i,n){
    cin >> x;
    if(ok){
      cout << "No" << endl;
      continue;
    }
    if(x<now){
      cout << "No" << endl;
    }else if(x==now){
      if(st.upper_bound(x)==st.end()){
        cout << "Yes" << endl;
        ok=true;
      }else{
        cout << "No" << endl;
      }
    }else{
      auto itr = st.find(x);
      while(itr!=st.end()){
        st.erase(itr);
        x--;
        itr = st.find(x);
      }
      st.insert(x);
      itr = st.find(now+1);
      while(itr!=st.end()){
        now++;
        itr = st.find(now+1);
      }
      cout << "Yes" << endl;
    }
  }

  return 0;
}



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

int n;

#include <vector>
template <typename T>
void print(vector<T> vec)
{
    int n = vec.size();
    for (int i = 0; i < n; i++)
    {
        cout << vec[i] << (i == n - 1 ? "\n" : " ");
    }
}

int main()
{
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    vector<int> r(n);
    r[n - 1] = -1e9;
    for (int i = n - 2; i >= 0; i--)
    {
        r[i] = max(r[i + 1], v[i + 1]);
    }
    int ans = -1e9;
    for (int i = 0; i < n; i++)
    {
        ans = max(ans, r[i] - v[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 4408