akhauriyash/Code-Regression huggingface dataset:
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions
void dijkstra(vl& d, vvi& es, int s, map<pii,int>& cost) {
    int N = es.size();
    d = vl(N, LINF);

    d[s] = 0;

    priority_queue<pll, vector<pll>, greater<pll>> pq;

    pq.push(pll(d[s], s));
    vb vis(N, false);

    while (!pq.empty()) {
        // get the smallest(nearest) element
        pll p = pq.top(); pq.pop();

        int i = p.second;
        vis[i] = true;

        for (int t : es[i]) {
            if (vis[t]) continue;

            if (p.first + 1 < d[t]) {
                //d[t] = p.first + 1;
                d[t] = p.first + cost[pii(i, t)];
                pq.push(pll(d[t], t));
            }
        }
    }
}
#endif


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

    int N; cin >> N;
    vi A(N - 1), B(N - 1), C(N - 1);
    REP(i,N-1){
        cin >> A[i] >> B[i] >> C[i];
        A[i]--; B[i]--;
    }
    int Q, K; cin >> Q >> K;
    K--;
    vi X(Q), Y(Q); 
    REP(i,Q){
        cin >> X[i] >> Y[i];
        X[i]--; Y[i]--;
    }

    vvi es(N);
    map<pii, int> cost;
    REP(i,N-1) {
        es[A[i]].push_back(B[i]);
        cost[pii(A[i], B[i])] = C[i];
        es[B[i]].push_back(A[i]);
        cost[pii(B[i], A[i])] = C[i];
    }

    vl dist;
    dijkstra(dist, es, K, cost);

    REP(i,Q) {
        ll ans = dist[X[i]] + dist[Y[i]];
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 23764
def is_contain_cycle(g, v):
    visited = set()
    for i in range(v):
        if i in visited:
            continue
        #route = Stack([None])
        route = [None]
        dfs_stack = [(i, None)]
        while dfs_stack:
            u, prev = dfs_stack.pop()
            while route[-1] != prev:
                route.pop()
            if u in route:
                return True
            if u in visited:
                continue
            visited |= {u}
            dfs_stack.extend((v, u) for v in g[u])
            route.append(u)
    return False

from sys import stdin
from collections import defaultdict


readline = stdin.readline

v, e = map(int, readline().split())
g = defaultdict(set)
for i in range(e):
    s, t = map(int, readline().split())
    g[s] |= {t}
print(1 if is_contain_cycle(g, v) else 0)

Measured memory_bytes: 6736
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>

using namespace std;

template <typename T> void read(T& x)
{
	x = 0; char c = getchar(); bool f = 0;
	while(!isdigit(c) && c!='-') c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(isdigit(c)) x = x*10+c-'0', c = getchar();
	if(f) x = -x;
}

int n, m, c;
int a[100], b[100];

int main()
{
	int ans = 0;
	cin >> n >> m >> c;
	for(int i=1; i<=m; i++) cin >> b[i];
	for(int i=1; i<=n; i++)
	{
		int tot = c;
		for(int j=1; j<=m; j++) cin >> a[j], tot += a[j] * b[j];
		if(tot > 0) ans++;
	}
	cout << 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;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	vector<ll> v(n+2, 0);
	rep(i,n) cin >> v[i+1];
	ll ans = 0;
	for(int l = 0; l <= min(k,n); l++){
		for(int r = 0; r <= min(k-l,n-l); r++){
			priority_queue<ll> pq;
			ll score = 0;
			for(int i = 0; i <= l; i++){
				score += v[i];
				pq.push(-v[i]);
			}
			for(int i = 0; i <= r; i++){
				score += v[n+1-i];
				pq.push(-v[n+1-i]);
			}
			int rest = k - l - r;
			for(int i = 0; i < rest; i++){
				ll p = pq.top();
				pq.pop();
				if(p > 0) score += p;
				else break;
			}
			chmax(ans, score);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import math
ns = list(map(int, input().split()))
f = ns[0]
b = ns[1]
result = 0

for i in range(f):
  n = list(map(int, input().split()))
  t = n[0] ** 2 + n[1] ** 2
  d = math.sqrt(t)
  if d <= b:
    result += 1
print(result)
  

Measured memory_bytes: 9068
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
inline char tc(void){
	static char fl[10000],*A=fl,*B=fl;
	return A==B&&(B=(A=fl)+fread(fl,1,10000,stdin),A==B)?EOF:*A++;
}
inline int read(void){
	int a=0;static char c;
	while((c=tc())<'0'||c>'9');
	while(c>='0'&&c<='9')a=a*10+c-'0',c=tc();
	return a;
}
struct Y{
	int a,b,p;
	bool operator <(const Y&a)const{
		return p>a.p;
	}
}k[100005];
int x,y,z,n,sum;
long long ans=-1e18,ans1,ans2,c;
char b[100005];
priority_queue<int,vector<int>,greater<int> >sum2;
priority_queue<pair<int,int>,vector<pair<int,int> >,less<pair<int,int> > >sum1;
int main(void){
	register int i,wjnsb;
	x=read(),y=read(),z=read(),n=x+y+z;
	for(i=1;i<=n;++i){
		k[i].a=read(),k[i].b=read(),wjnsb=read(),k[i].a-=wjnsb,k[i].b-=wjnsb,
		k[i].p=k[i].a-k[i].b,c+=wjnsb;
	}
	sort(k+1,k+n+1);
	for(i=1;i<=x;++i)
		sum2.push(k[i].a),ans1+=k[i].a;
	for(i=x+1;i<=n;++i)
		sum1.push(make_pair(k[i].b,i));
	for(i=1;i<=y;++i)
		b[sum1.top().second]=1,ans2+=sum1.top().first,sum1.pop();
	n-=y;
	ans=max(ans1+ans2,ans);
	for(i=x+1;i<=n;++i){
		sum2.push(k[i].a),ans1+=k[i].a,ans1-=sum2.top(),sum2.pop();
		if(b[i]==1){
			ans2-=k[i].b;
			while(b[sum1.top().second])
				sum1.pop();
			b[sum1.top().second]=1,ans2+=sum1.top().first,sum1.pop();
		}
		b[i]=1,ans=max(ans1+ans2,ans);
	}
	printf("%lld",ans+c);
	return 0;
}

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

int main() {
    int n, m, x, y; cin >> n >> m >> x >> y;
    int X[n], Y[m];
    rep(i, n) cin >> X[i];
    rep(i, m) cin >> Y[i];
    sort(X, X+n);
    sort(Y, Y+m);
    if (Y[0] - X[n-1] > 0) {
        for (int i=X[n-1]+1; i<=Y[0]; ++i) {
            if (i>x && i<=y) {
                puts("No War");
                return 0;
            }
        }
    }
    puts("War");
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <utility>
#include <string>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ul;

const int iinf = 1 << 29;
const long long linf = 1l << 61;

struct line
{
	double x1, y1, x2, y2;
};

int t[110];
int v[110];
line l[300];
int N;

int main(int argc, char* argv[])
{
	scanf("%d", &N);
	for(int i = 0; i < N; i++) scanf("%d", &t[i]);
	for(int i = 0; i < N; i++) scanf("%d", &v[i]);

	double ans = 0;

	int v1 = 0;
	int T = accumulate(t, t + N, 0);
	for(int x = 1; x <= 2 * T; x++)
	{
		int v2 = iinf;
		int t1 = 0;
		for(int i = 0; i < N; i++)
		{
			int t2 = t1 + t[i];
			if(x < 2 * t1)
			{
				v2 = min(v2, -x + 2 * (t1 + v[i]));
			}
			else if(x > 2 * t2)
			{
				v2 = min(v2, x + 2 * (-t2 + v[i]));
			}
			else
			{
				v2 = min(v2, 2 * v[i]);
			}
			t1 = t2;
		}
		v2 = min(v2, x);
		v2 = min(v2, -x + 2 * t1);

		ans += 1.0 / 8.0 * (v1 + v2);

		v1 = v2;
	}
	printf("%f", ans);

	return 0;
}


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

int main(){
    int A,B;
    cin>>A>>B;
    if(A==1)A=14;
    if(B==1)B=14;
    if(A>B)cout<<"Alice"<<endl;
    if(B>A)cout<<"Bob"<<endl;
    if(A==B)cout<<"Draw"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long 
using namespace std;
int main(){
  string s;
  cin >>s;
  int bl=0;
  int wh=0;
  rep(i,s.size()){
    if(s[i]=='0'){
      wh++;
    }else{
      bl++;
    }
  }
    cout <<2*min(bl,wh)<<endl;
}

Measured memory_bytes: 512
n,m,q=map(int,input().split())
t=[[0]*(1+n) for _ in range(1+n)]
for i in range(m):
    l,r=map(int,input().split())
    t[l][r]+=1
for i in range(n):
    for j in range(n):
        t[i+1][j+1]+=t[i+1][j]+t[i][j+1]-t[i][j]

for i in range(q):
    p,q=map(int,input().split())
    p-=1
    print(t[q][q]-t[q][p]-t[p][q]+t[p][p])


Measured memory_bytes: 13292
def main():
    temp=input()
    temp=list(map(int,list(temp.split(" "))))    
    a=int(temp[0])
    b=int(temp[1])
    count=0
    for i in range(a,b+1):                    
        if str(i)==str(i)[::-1]:
            count+=1
    print(count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (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")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: chars
    }
    let a = (n.len() - 1) * 9 + (n[0] as u8 - '0' as u8) as usize;
    if n.iter().skip(1).all(|&c| c == '9') {
        println!("{}", a);
    } else {
        println!("{}", a - 1);
    }
}


Measured memory_bytes: 4352
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

int main(){
	
	while(true){
		int H, W;
		cin >> H >> W;
		if(H == 0 && W == 0){
			break;
		}
		int a[20][20];
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				cin >> a[i][j];
			}
		}
		int ans = 0;
		for(int sy = 0; sy < H; sy++){
			for(int gy = sy + 2; gy < H; gy++){
				for(int sx = 0; sx < W; sx++){
					for(int gx = sx + 2; gx < W; gx++){
						int mini = 1000;
						int maxi = 0;
						int sum = 0;
						for(int i = sy; i <= gy; i++){
							for(int j = sx; j <= gx; j++){
								if(i == sy || i == gy || j == sx || j == gx){
									mini = min(mini, a[i][j]);
								}else{
									sum += a[i][j];
									maxi = max(maxi, a[i][j]);
								}
							}
						}
						if(mini - maxi > 0){
							ans = max(ans, mini * (gx - sx - 1) * (gy - sy - 1) - sum);
						}
					}
				}
			}
		}
		cout << ans << endl;
	}
	
	return 0;
	
}



Measured memory_bytes: 3100
A,B,C,D,E,F = map(int, input().split())
 
import functools
import sys
sys.setrecursionlimit(10**5)
 
@functools.lru_cache(maxsize=None)
def calc_strength(sugar, water):
    if water == 0: return -1
    return sugar * 100 / (sugar + water)
 
@functools.lru_cache(maxsize=None)
def f(strength, sugar, water):
    cand = [(strength, sugar + water, sugar)]
    for x in ((C, 0), (D, 0), (0, 100*A), (0, 100*B)):
        s, w = sugar + x[0], water + x[1]
        if s + w <= F and s * 100 <= w * E:
            cand.extend([f(calc_strength(s, w), s, w)])
    return max(cand)

e=f(-1, 0, 0)
print(*f(-1, 0, 0)[1:])

Measured memory_bytes: 7988
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
  public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}



int main(){
    string S;
    cin >> S;
    for (int i = 0; i < 3; i++)
    {
        if(S[i] == S[i+1]){
            cout << "Bad" << endl;
            return 0;
        }   
    }
    
    cout << "Good" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include<math.h>
#include<bitset>
#include<string>
#include<iostream>
#include<vector>
#include<string.h>
#include<algorithm>
using namespace std;


int main()
{
    string s,t;
    int cnt=0;
    cin>>s>>t;
    for(int i=0;i<3;i++){
        if(s[i]==t[i])cnt++;
    }
    cout<<cnt<<endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

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

Measured memory_bytes: 384
// AtCoDeerくんとボール色塗り
#include <iostream>
using namespace std;
typedef long long INT;
int main(){
    INT n,k;
    cin>>n>>k;
    INT ans=k;
    k--;
    for(INT i=1;i<n;i++){
        ans*=k;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
let () = Scanf.scanf "%d %d\n" @@ fun n x ->
  let ls = Array.init n @@ fun _ -> Scanf.scanf " %d" Fun.id in
  let (now, cnt) = Array.fold_left (fun (now', cnt') l ->
    now' + l, cnt' + if now' <= x then 1 else 0) (0, 0) ls in
  Printf.printf "%d\n" @@ cnt + if now <= x then 1 else 0

Measured memory_bytes: 3836
import java.util.*;
import java.util.Map.Entry;

import javax.swing.text.Segment;
import javax.xml.ws.WebEndpoint;

import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main //implements Runnable
{
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};
	
    public static void main(String[] args)   throws Exception, IOException{        
        long mod=1000000007;
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int n=sc.nextInt();
        int d[]=sc.nextIntArray(n);
        int e[]=new int[n+1];
        long r=1,z=0;
        
        for (int i = 0; i < d.length; i++) {
        	e[d[i]]++;
        	if(d[i]==0) {
        		z++;
        		continue;
        	}
        	if(e[d[i]-1]<=0)ret("0");
			r*=e[d[i]-1];r%=mod;
			e[d[i]-1]--;
		}
        
        if(z==1)r*=3;
        else if(z>3)r=0;
        else r*=6;
        r%=mod;

        out.println(r);
     	out.flush();
    }


    static void ret(String ans) {
    	System.out.println(ans);
    	System.exit(0);
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}

//
//class P {
//	int x, y, d;
//	P(int  x, int y, int d) {
//	  this.x=x;
//	  this.y=y;
//	  this.d=d;
//	}
//}

class P implements Comparable<P>{
    int a,b;
    P(int a, int b) {
    	this.b=b;
    	this.a=a;
    }

    public int compareTo(P p){
        return -p.a+a;//as
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) throws IOException{
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public char[] getCharSet() throws IOException{
        return this.nextString().toCharArray();
    }    
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 37136
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll Mod=998244353;
int n,a[300010],b[300010],len,v[300010],q[600010],s[300010];
ll ans;
bool used[300010];
void add(int x,int y)
{
	s[v[x]]+=y;
}
int main()
{
	scanf("%d",&n);
	for (int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	int t=0;
	for (int i=1;i<n;i++)
	{
		if (a[i]==1 && a[i-1]!=1)
		{
			t=i;
		}
	}
	for (int i=0;i<n;i++)
	{
		b[i]=a[(t+i)%n];
	}
	for (int i=0;i<n;i++)
	{
		a[i]=b[i];
		//cerr<<a[i]<<" ";
	}
	//cerr<<endl;
	len=0;
	while (len<n && a[len]==1)
	{
		len++;
	}
	if (!len)
	{
		puts("0");
		return 0;
	}
	if (len==n)
	{
		ans=1;
		for (int i=2;i<=n;i++)
		{
			ans=ans*i%Mod;
		}
		cout<<ans<<endl;
		return 0;
	}
	used[1]=true;
	for (int i=1;i<n;i++)
	{
		if (a[i]==a[i-1])
		{
			continue;
		}
		if (used[a[i]])
		{
			puts("0");
			return 0;
		}
		int j=i;
		while (j<n && a[j]==a[i])
		{
			j++;
		}
		if (j-i>len)
		{
			puts("0");
			return 0;
		}
		used[a[i]]=true;
		i=j-1;
	}
	ans=1;
	int l=1,r=0;
	for (int i=1;i<len;i++)
	{
		while (l<=r && a[q[r]]<=a[i])
		{
			r--;
		}
		q[++r]=i;
	}
	v[0]=1;
	for (int i=1;i<n;i++)
	{
		while (l<=r && a[q[r]]<=a[(i+len-1)%n])
		{
			r--;
		}
		q[++r]=(i+len-1)%n;
		v[i]=a[q[l]];
		if (q[l]==i)
		{
			l++;
		}
	}
	l=0,r=-1;
	for (int i=len;i<n;i++)
	{
		if (a[i]==a[i-1])
		{
			continue;
		}
		int j=i;
		while (j<n && a[j]==a[i])
		{
			j++;
		}
		while (r<i)
		{
			r++;
			add(r,1);
		}
		while (l<j-len)
		{
			add(l,-1);
			l++;
		}
		ans=ans*s[a[i]]%Mod;
		//cerr<<l<<" "<<r<<" "<<s[a[i]]<<endl;
		i=j-1;
	}
	memset(s,0,sizeof(s));
	for (int i=0;i<n;i++)
	{
		s[v[i]]++;
		//cerr<<v[i]<<" ";
	}
	//cerr<<endl;
	for (int i=1;i<=n;i++)
	{
		s[i]+=s[i-1];
	}
	for (int i=2;i<=n;i++)
	{
		if (used[i])
		{
			continue;
		}
		if (s[i]<i-1)
		{
			ans=0;
		}
		ans=ans*(s[i]-i+1)%Mod;
	}
	cout<<ans<<endl;
	return 0;
}
//弹破庄周梦，两翅驾东风，三百座名园、一采一个空。
//——王和卿《醉中天·咏大蝴蝶》

Measured memory_bytes: 7552
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		sc.close();
		int[] list = new int[] {a,b,c};
		Arrays.sort(list);
		int cnt = 0;
		int sbn = list[2] - list[1];
		if(sbn % 2 == 0) {
			cnt += sbn/2;
		} else {
			list[0] ++;
			sbn --;
			cnt += sbn/2 + 1;
		}
		sbn = list[2] - list[0];
		if(sbn % 2 == 0) {
			cnt += sbn/2;
		} else {
			sbn--;
			cnt += sbn/2 + 2;
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 22612
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n, m, k;
	cin>>n>>m>>k;
	for(int i=0; i<=n; i++){
		for(int j=0; j<=m; j++){
			if(i*j+(n-i)*(m-j)==k){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  string S;
  cin>>S;
  int ans = 0;
  for(int i=0;i<S.size();++i) {
    if(i%2==0) {
      if(S[i]=='p') ans--;
    }
    else {
      if(S[i]=='g') ans++;
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3736
#include<iostream>
#include<string.h>
using namespace std;

int main() {
  string s;
  cin >> s;
  string ans = "Yes";

  for(int i = 0; i < s.size(); i++) {
    if( i % 2 == 0 ) {
      //奇数
      if(s[i] == 'L') ans = "No";
    } else {
      //偶数
      if(s[i] == 'R') ans = "No";
    }
  }

  cout << ans << endl;
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int a, b, c, x, ans = 0;
  cin >> a >> b >> c >> x;
  for (int i = 0; i <= a; i++)
    for (int j = 0; j <= b; j++)
      for (int k = 0; k <= c; k++)
        if (x == i * 500 + j * 100 + k * 50) ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n, a, b = gets.split.map(&:to_i)
if (b - a).even?
  puts (b - a) / 2
else
  # direct
  d = [b - 1, n - a].min
  
  # indirect
  # go nearest edge
  s_1 = [a - 1, n - b].min
  # wait until even (just 1 time)
  s_2 = 1
  # behave as even
  s_3 = (b - a - 1) / 2
  s = s_1 + s_2 + s_3
  puts [d, s].min
end


Measured memory_bytes: 1788
T="357"
N=int(input())
sts = {""}
for _ in range(len(str(N))):
    sts = sts | {s+t for t in T for s in sts}
    #if int(sts[-1])>N:break
#print(sts)
sts = [s for s in sts if '3' in s and '5' in s and '7' in s]
#print(sts)
sts = [int(s) for s in sts if int(s)<=N]
#print(sts)
print(len(sts))

Measured memory_bytes: 10712
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string str;
  cin >> str;
  int count = 0;
  for (int i = 0; i < str.size(); i++) {
    if (str.at(i) == '+') {
      count++;
    }
  }
    for ( int i = 0; i < str.size(); i++) {
      if ( str.at(i) == '-') {
        count--;
  }
    }
  cout << count << endl;
}

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

using namespace std;

const int N = 1e2+7;

long long n, a, b;

int main()
{
    cin >> n >> a >> b;
    if ((b-a)%2 == 0) {
        cout << (b-a)/2 << endl;
    } else {
        long long res = 0;
        if (a-1 <= n-b) {
            b -= a-1;
            res += a-1;
            a = 1;
            --b;
            ++res;
            res += (b-a)/2;
        } else {
            a += n-b;
            res += n-b;
            b = n;
            ++a;
            ++res;
            res += (b-a)/2;
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

    int X = scanner.nextInt();
    int A = scanner.nextInt();
    if (X < A) {
      System.out.println(0);
    } else {
      System.out.println(10);
    }
  }
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
int x;
inline bool isprime(int x){
    if(x<2)return false;
    if(x==2)return true;
    if(!(x&1))return false;
    for(int i=2;i*i<=x;i++)if(!(x%i))return false;
    return true;
}
int main(){
    scanf("%d",&x);
    for(;;x++){
        if(isprime(x)){
            printf("%d\n",x);
            exit(0);
        }
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdin = new Scanner(System.in);
		int a=stdin.nextInt();
		int b=stdin.nextInt();
		int max=-99999999;
		if(a+b>=a-b){
			max=a+b;
		}else{
			max=a-b;
		}
		
		if(a*b>=max){
			max=a*b;
		}
		System.out.println(max);
		

	}

}

Measured memory_bytes: 23636
#include"bits/stdc++.h"
#include"math.h"
using namespace std;

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
 

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

#define REP(i,m,n) for(ll i = m; i < (ll)(n);++i)
#define rep(i,n) REP(i,0,n)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
 
using vi=vc<int>;

const ll mod=1e9+7;
const ll INF = 1e18;

int main(){
  ll n,k;
  cin >> n >>k;
  ll ans=0,x=0;
  for(ll i=1;i<=n;i++){
     if(i%k==k/2)x++;}
  if(k%2==1){
    ans=pow(n/k,3);
  }
  else{
    ans+=pow(n/k,3);
    ans+=pow(x,3);
  }
  cout << ans << endl;}

    

Measured memory_bytes: 256
#include<stdio.h>
int length(char s[]){
    int i=0;
    while(s[i])
        i++;
    return i-1;
}
int main(void){
    char a[10],b[10],c[10];
    int al,bl;
    scanf("%s %s %s",a,b,c);
    al=length(a);
    bl=length(b);
    if((a[al]==b[0]) && (b[bl]==c[0])){
        printf("YES\n");
    }
    else{
        printf("NO\n");
    }
    return 0;
}

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

typedef long long ll;

using std::pair;
using std::vector;
using std::string;

#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)

const int N = 200000;
const int mo = 1e9 + 7;

int fpm(int x, int y) {
    int res = 1;
    for(; y > 0; y >>= 1) {
        if(y & 1) 
            res = (ll) res * x % mo;
        x = (ll) x * x % mo;
    }
    return res;
}

int n, s = 1;
int a[N + 5], d[N + 5];
int lim[N + 5], cnt[N + 5];

namespace BIT {
    int c[N + 5];

    void clear() {
        memset(c, 0, sizeof c);
    }
    void modify(int x, int y) {
        for( ; x <= N; x += x & -x) {
            c[x] = (c[x] + y) % mo;
        }
    }
    int query(int x) {
        int res = 0;
        for( ; x > 0; x -= x & -x) {
            res = (res + c[x]) % mo;
        }
        return res;
    }
    inline int query(int x, int y) {
        return query(y) - query(x - 1);
    }
}

int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) scanf("%d", a + i), ++ cnt[a[i]];
    for(int i=n-1; i >= 1; --i) cnt[i] = cnt[i] + cnt[i + 1] - 1;

    d[0] = 1;
    for(int i = 1; i <= n; ++i) {
        s = (ll) s * cnt[i] % mo;
        if(cnt[i] <= 0) return !puts("0");

        if(cnt[i] > 1) {
            lim[i] = lim[i-1];
            d[i] = (ll) d[i-1] * (cnt[i] - 1) % mo * fpm(cnt[i], mo - 2) % mo;
        } else {
            lim[i] = i;
            d[i] = d[i-1];
        }
    }
    
    int ans = 0;
    for(int i = 1; i <= n; ++i) {
        ans = (ans + (ll) d[a[i]] * s % mo * BIT::query(lim[a[i]], a[i])) % mo;
        BIT::modify(a[i], fpm(d[a[i]], mo - 2));
    }

    BIT::clear();
    for(int i = 1; i <= n; ++i) {
        ans = (ans + (ll) 2 * s * (i - 1 - BIT::query(a[i]))) % mo;
        BIT::modify(a[i], 1);
    }

    BIT::clear();
    for(int i = n; i >= 1; --i) {
        ans = (ans - (ll) d[a[i]] * s % mo * BIT::query(lim[a[i]], a[i] - 1)) % mo;
        BIT::modify(a[i], fpm(d[a[i]], mo - 2));
    }

    ans = (ll) (ans + mo) * ((mo + 1) >> 1) % mo;
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n, a;
    cin >> n;
    multiset<ll> ms;
    for(int i=0;i<n;i++){
    	cin >> a;
    	ms.insert(a);
    }
    ll ma = *(--ms.end());

    if(ma == 1){
    	cout << ((ms.count(ma) == 2)? "Possible": "Impossible") << endl;
    	return 0;
    }

    ll mi = (ma + 1) / 2;
    for(ll i = mi + 1;i <= ma;i++){
    	if(ms.count(i) < 2){
    		cout << "Impossible" << endl;
    		return 0;
    	}
    	ms.erase(i);
    }

    if(ma & 1){
    	if(ms.size() == 2 && ms.count(mi) == 2){
    		cout << "Possible" << endl;
    	}else{
    		cout << "Impossible" << endl;
    	}
    }else{
    	if(ms.size() == 1 && ms.count(mi) == 1){
    		cout << "Possible" << endl;
    	}else{
    		cout << "Impossible" << endl;
    	}
    }
    return 0;
}


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

int main(void)
{

    int N,K;

    cin >> N >> K;

	int x;

	if(N%K==0)	x=0;
	else x=1;
	
		
	printf("%d",x);
	
return 0;
}



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

int main() {
  int N, M;
  cin >> N >> M;
  
  ll x_s[N], y_s[N], x_c[M], y_c[M];
  
  for (int i = 0; i < N; i++) {
    cin >> x_s[i] >> y_s[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> x_c[i] >> y_c[i];
  }
  
  for (int i = 0; i < N; i++) {
    ll dist = 10000000000;
    int c = 0;
    for (int j = 0; j < M; j++) {
      if (abs(x_s[i] - x_c[j]) + abs(y_s[i] - y_c[j]) < dist) {
        c = j + 1;
        dist = abs(x_s[i] - x_c[j]) + abs(y_s[i] - y_c[j]);
      }
    }  
    cout << c << endl;
  }
  
  
}

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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  long long N;
  cin >> N;
  vector<long long> A(N);
  for(int i = 0; i < N; i++) cin >> A[i];
  long long max = 0;
  long long ans = 0;
  for(int i = 0; i < N; i++){
    if(A[i] >= max){
      max = A[i];
    } else{
      ans += max - A[i];
    }
  }
  cout << ans <<endl;
}


Measured memory_bytes: 4784
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  int c=(a+b)/2;
  if(c*2==a+b){
    cout<<c<<endl;
  }
  else{
    cout<<c+1<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
/*
 * WelcomeToAtCoder.cpp
 *
 *  Created on: 2020/02/19
 *      Author: black
 */
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_set>
using namespace std;

int main(){
	int N;
	unordered_set<string>strList;
	string tmp;
	cin >> N;

	int count = 0;
	for (int i=0; i<N; ++i){
		cin >> tmp;
		if (strList.find(tmp) == strList.end()){
			strList.insert(tmp);
			count++;
		}
	}

	cout << count << endl;

	return 0;
}


Measured memory_bytes: 13852
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,n)  for(ll i=0;i<n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef pair<int,int> pii;
int main()
{
	IOS;
	//int t; cin>>t;
	//ll M=pow(10,9)+7;
	int t=1;
	while(t)
	{
		ll n,k; cin>>n>>k;
		ll a[n]; f(i,n) cin>>a[i];
		vector<string> v;
		for(ll i=k;i<n;i++)
		{
			//ans=ans/a[i-k];
			if(a[i]>a[i-k])
			{
				v.push_back("Yes");
			}
			else
			{
				v.push_back("No");
			}
		}
		for(ll i=0;i<v.size();i++)
		{
			cout<<v[i]<<"\n";
		}
		t--;
	}
	return 0;
}

Measured memory_bytes: 13180
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, L, R, H, W;

long long int ans = LLONG_MAX;
vector<vector<long long int>>edge;
int place[10] = {};

void Search(vector<int>v, int num,long long int sum,int last) {
	//cout << num << " " << last << " " << sum << endl;
	for (int i = 0; i < K; i++) {
		if (v[i]) {
			continue;
		}
		v[i] = 1;
		Search(v, num + 1, sum + edge[last][place[i]], place[i]);
		v[i] = 0;
	}
	if (num==K) {
		ans = min(ans, sum);
	}
	return;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> N >> M >> K;
	for (int i = 0; i < K; i++) {
		cin >> place[i];
	}
	edge.resize(N + 1, vector<long long int>(N + 1, INT_MAX));
	for (int i = 0; i < M; i++) {
		cin >> L >> R >> H;
		edge[L][R] = H;
		edge[R][L] = H;
	}
	for (int i = 1; i <= N; i++) {
		edge[i][i] = 0;
	}
	for (int k = 1; k <= N; k++) {
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N; j++) {
				edge[i][j] = min(edge[i][j], edge[i][k] + edge[k][j]);
			}
		}
	}
	vector<int>box(K, 0);
	for (int i = 0; i < K; i++) {
		box[i] = 1;
		Search(box, 1, 0, place[i]);
		box[i] = 0;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

LL modinv(LL a) {
    LL b = MOD, u = 1, v = 0;
    while (b) {
        LL t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}

LL moddev(LL a, LL b){
	return a * modinv(b) % MOD;
}

void Main()
{
    double l;cin>>l;
    double ll=l/3.0;

    cout << ll*ll*ll <<endl;  




	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){ 
    string s,t;
    cin>>s;
    cin>>t;

    int ans=0;
    for(int i=0;i<3;i++){
        if(s[i]==t[2-i])ans++;
    }

    if(ans==3)cout<<"YES";
    else cout<<"NO";
 
    return 0;
}

Measured memory_bytes: 256
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

D1 = D2 = D3 = Dc = 0
for xi, yi in zip(x, y):
    D1 += abs(xi-yi)
    D2 += abs(xi-yi)**2
    D3 += abs(xi-yi)**3
    Dc = max(Dc, abs(xi-yi))

D2 = D2**(1/2)
D3 = D3**(1/3)

print("{:.8f}".format(D1))
print("{:.8f}".format(D2))
print("{:.8f}".format(D3))
print("{:.8f}".format(Dc))



Measured memory_bytes: 5640
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(s...)  fprintf(stderr, s)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }


int N, A[100111];

int main() {
    scanf("%d", &N);
    REP (i, N) scanf("%d", A+i);

    LL ans = 0;
    REP (i, N) {
	ans += A[i] / 2;
	A[i] %= 2;
	if (i + 1 < N) {
	    int g = min(A[i], A[i+1]);
	    ans += g;
	    A[i]-=g; A[i+1]-=g;
	}
    }

    printf("%lld\n", ans);



    return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int dp[100001],h[100001];
int main(){
  int N;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> h[i];
  }
  dp[0]=0;dp[1]=abs(h[1]-h[0]);
  for(int i=2;i<N;i++){
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
  }
  //for(int i=0;i<N;i++)
  cout << dp[N-1] << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x) \
  int x;     \
  cin >> x;  \
  while (x--)

int32_t main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n,k;
  cin>>n>>k;
  vector<int> v(n);
  for(int &i:v)
    cin>>i;
  int cur = 1;
  
  for(int i = k;i<n;i++) {
    if(v[i-k]<v[i])
      cout<<"Yes\n";
    else cout<<"No\n";
  }
  return 0;
}

Measured memory_bytes: 4776
#include <iostream> // c++の標準入出力
#include <stdio.h> // c言語の標準入出力
#include <string>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
	int a, b, c, d, e;
	scanf("%d", &a);
	scanf("%d", &b);
	c = a + b;
	d = c % 2;
	e = c / 2;
		if (d==0) { printf("%d", e); }
		else { printf("%s", "IMPOSSIBLE"); }
}

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

// varibable settings
#define int long long
const int INF=1e18;
const int MOD=1e9+7;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define ceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

signed main() {
  int a,b,k;cin>>a>>b>>k;
  int d = min(a,k);
  a -= d;
  k -= d;
  dump(a, k);
  b -= min(b,k);
  cout << a << " " << b << endl;
  return 0;
}


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

int main() {
	int n;cin>>n;
  	ll temp,mygcd,a;cin>>temp;
  	for(int i=2;i<=n;i++){
      	cin>>a;
    	mygcd=__gcd(temp,a);
      	temp=temp/mygcd*a;
    }
  	cout<<temp<<endl;
}

Measured memory_bytes: 256
s=input()
n=len(s)
mod=10**9+7
dp=[[0 for i in range(13)] for i in range(n)]
if s[0]=="?":
  for i in range(10):
    dp[0][i]=1
else:
  dp[0][int(s[0])]=1
for i in range(1,n):
  if s[i]=="?":
    for j in range(13):
      for k in range(10):
        dp[i][(10*j+k)%13]+=dp[i-1][j]
  else:
    for j in range(13):
      dp[i][(10*j+int(s[i]))%13]+=dp[i-1][j]
  for j in range(13):
    dp[i][j]%=mod
print(dp[n-1][5])


Measured memory_bytes: 66012
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
N = int(input())
s = [int(input()) for i in range(N)]

Alist = A1+A2+A3
A = [0]*len(Alist)

for i in range(len(Alist)):
    if s.count(Alist[i])>0:
        A[i]=1

if A[0]+A[1]+A[2]>2 or A[3]+A[4]+A[5]>2 or A[6]+A[7]+A[8]>2 or A[0]+A[3]+A[6]>2 or A[1]+A[4]+A[7]>2 or A[2]+A[5]+A[8]>2 or A[0]+A[4]+A[8]>2 or A[2]+A[4]+A[6]>2:
    print("Yes")
else:
    print("No")


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

using namespace std;

int main(void) {
    int w[10], k[10], W = 0, K = 0;
    for (int i = 0; i < 10; i++)
        cin >> w[i];
    for (int i = 0; i < 10; i++)
        cin >> k[i];
    sort(w, w + 10, greater<int>());
    sort(k, k + 10, greater<int>());
    
    for (int i = 0; i < 3; i++) {
        W += w[i];
        K += k[i];
    }
    cout << W << " " << K << endl;

    return 0;
}


Measured memory_bytes: 3120
#include<stdio.h>
#define MAX 500000
#define INF 1e9

int Left[MAX/2+2];
int Right[MAX/2+2];
int cnt = 0;

void merge(int A[], int l, int mid, int r)
{
  int i,k;
  
  int n1 = mid - l;
  int n2 = r - mid;

  for(i=0;i < n1;i++) Left[i] = A[l+i];
  for(i=0;i < n2;i++) Right[i] = A[mid+i];
  Left[n1] = Right[n2] = INF;

  int ii=0,jj=0;
  for(k = l;k < r;k++){
    if(Left[ii] <= Right[jj]) A[k] = Left[ii++];
    else A[k] = Right[jj++];
    cnt++;
  }
}

void mergesort(int A[], int left, int right)
{
  if( left+1 < right ){
    int mid = (right + left)/2;
    mergesort(A, left, mid);
    mergesort(A, mid, right);
    merge(A, left, mid, right);
  }
}
int main()
{
  int i;
  int A[MAX+1];
  int n;

  scanf("%d",&n);
  for(i = 0;i < n;i++) scanf("%d",&A[i]);

  mergesort(A, 0, n); //left = 0, right = n

  for(i = 0;i < n;i++){
    if(i) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");

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



Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  string ans="kogakubu10gokan";
  Int n,q;
  cin>>n>>q;
  for(Int i=0;i<n;i++){
    Int y;
    string s;
    cin>>y>>s;
    if(y<=q) ans=s;
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3172
days_summer_vacation, amount_homework = map(int, input().split())
a = map(int, input().split())
schedule_hw = list(a)

need_days_hw = 0

for i in schedule_hw:
    need_days_hw += i


if days_summer_vacation > need_days_hw:
    print(days_summer_vacation - need_days_hw)
elif days_summer_vacation == need_days_hw:
    print(0)
else:
    print(-1)

Measured memory_bytes: 9876
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;

int main() {
  int p, q, r;
  cin >> p >> q >> r;
  int ans = min({p + q, p + r, q + r});
  cout << ans << endl;
}

Measured memory_bytes: 256
package main
import (
    "fmt"
    "math"
)

var zero = make(map[int]int)
var one  = make(map[int]int)

func main(){
    var N, K int
    var s string
    fmt.Scan(&N, &K, &s)
    fmt.Println(search(s, K))
}

func search(s string, K int) float64{
    padding(s, K)
    ans, count := 0.0, 0
    memoLength := int(math.Max(float64(len(one)), float64(len(zero))))
    for i:=0;i<= memoLength;i++{
        if s[0] == 49 && i == 0{
            count += one[K] + zero[K]
        }
        if i == 0{
            for j:=0; j<K && i+j<memoLength;j++{
                count += zero[i+j] + one[i+j]
            }
        }else if s[0] == 48{
            count += zero [i+K-1] + one[i+K-1] - zero[i-1] - one[i-2]
        } else {
            count += zero [i+K] + one[i+K] - zero[i] - one[i-1]
        }
        
        ans = math.Max(ans, float64(count))
    } 
    return ans
}

func padding(s string, K int){
    for i, now:= 0, 0; now < len(s);i++{
        for now < len(s) && s[now] == 48{
            zero[i]++
            now ++
        }
        for now < len(s) && s[now] == 49{
            one[i]++
            now ++
        }
    }
}


Measured memory_bytes: 5504
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def trial_division(n):
    factor=[]
    sqrt=int(n**.5)+1 # sqrt=ceil(sqrt(n))
    for d in range(2,sqrt):
        while(n%d==0):
            n//=d
            factor.append(d)
    if n==1: return factor
    else: return factor+[n]
def resolve():
    from fractions import gcd
    a,b=map(int,input().split())
    g=gcd(a,b)
    print(len(set(trial_division(g)))+1)
resolve()

Measured memory_bytes: 64876
K, N = map(int, input().split())
A = list(map(int, input().split()))
box = []
for i in range(0, N - 1):
    data = abs(A[i] - A[i + 1])
    box.append(data)
box.append(A[0] - A[-1] + K)
m = max(box)
print(K - m)

Measured memory_bytes: 26420
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
ll dp[110][100010];
int main() {
    // O(NW)
    int N,W;
    scanf("%d%d", &N, &W);
    int w[N],v[N];
    rep(i, N) cin >> w[i] >> v[i];
    rep(i, N) rep(j, W+1){
        if(w[i] > j) dp[i+1][j] = dp[i][j];
        else dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]+v[i]);
    }
    cout << dp[N][W] << endl;
    return 0;
}

Measured memory_bytes: 79360