akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int queue[1005][300000] = {0};
int head[300000] = {0};
int tail[300000] = {0};

void enqueue(int t, int x){
  queue[t][tail[t]] = x;
  tail[t]++;
}

int front(int t){
  return queue[t][head[t]];
}

void dequeue(int t){
  head[t] = head[t] + 1;
}

int main(){
  int n, q, i, s, t, u;

  scanf("%d %d", &n, &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &s);
    if (s == 0) {
      scanf("%d %d", &t, &u);
      enqueue(t, u);
    }
    else if (s == 1) {
      scanf("%d", &t);
      if (head[t] != tail[t]) {
        printf("%d\n", front(t));
      }
    }
    else if (s == 2) {
      scanf("%d", &t);
      if (head[t] != tail[t]) {
        dequeue(t);
      }
    }
  }

  return 0;
}



Measured memory_bytes: 6132
-module('Main').
-export([main/1]).

rec([]) -> 0;
rec([A | Rest]) -> A - rec(Rest).

solve() ->
    [N] = input("~d"),
    A = input(lists:flatten(["~d" || _ <- lists:seq(1, N)])),
    ASorted = lists:reverse(lists:sort(A)), % 逆順ソート
    io:format("~B~n", [rec(ASorted)]),
    ok.

main(_) ->
    solve(),
    halt().

input(Pat) ->
    {ok, L} = io:fread("", Pat),
    L.


Measured memory_bytes: 21812
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<set>
#include<map>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const int INF = 2000000000;

    ll N,M;
    ll A,B,C;

    ll S[100010];

    ll ans=0;

int main(){
    ios_base::sync_with_stdio(false);
    cin>>N;
    string s=to_string(N);
    for(auto x:s){
        A+=x-'0';
    }
    cout<<(N%A==0?"Yes":"No")<<endl;
    //cout<<A<<endl<<B;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#include<vector>
#define maxn 100005
using namespace std;
string q1, q2;
int cnt;

int main() {
	cin >> q1 >> q2;
	for(int i = 0; i < 3; i ++) {
		if(q1[i] == q2[i]) cnt ++;
	}
	printf("%d\n", cnt);
}

Measured memory_bytes: 256
s1 = gets.to_s.split("")
s2 = gets.to_s.split("")

dp = Array.new(s1.size){Array.new(s2.size, 0)}
for i in 0..s1.size-1 do
    dp[i][0] = i
end
for i in 0..s2.size-1 do
    dp[0][i] = i
end
for i in 0..s1.size-2 do
    for j in 0..s2.size-2 do
        if s1[i] == s2[j] then
            dp[i+1][j+1] = dp[i][j]
        else
            dp[i+1][j+1] = [dp[i][j],dp[i+1][j],dp[i][j+1]].min + 1
        end
    end
end
puts dp[s1.size - 1][s2.size - 1]

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

int top;
int S[10000];

void push(int x){
    top++;
    S[top] = x;
}

int pop(){
    top--;
    return S[top+1]; 
}


int main(){
    int a,b;
    string s;
    top = 0;
    
    while(cin>>s){
        if(s == "+"){
            a = pop();
            b = pop();
            push(a + b);
        }else if (s == "-"){
            b = pop();
            a = pop();
            push(a-b);
        }else if (s == "*"){
            b = pop();
            a = pop();
            push(a*b);
        }else{
            push(stoi(s));
        }
    }
    cout << pop() << endl;
}


Measured memory_bytes: 3176
#include <iostream>

using namespace std;

int main() {
    unsigned long long n, k;
    cin >> n >> k;
    unsigned long long variation = k;
    for (unsigned long long i = 0; i < n - 1; ++i) {
        variation *= (k - 1);
    }
    cout << variation << endl;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
def popcount(i):
    assert 0 <= i < 0x100000000
    i = i - ((i >> 1) & 0x55555555)
    i = (i & 0x33333333) + ((i >> 2) & 0x33333333)
    return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24

N = int(input())

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

dp = [0]*(2**N)

for s in range(1, 2**N):
    ppc = popcount(s)
    if ppc <= 1:
        continue
    res = sum(A[i][j] for i in range(N) for j in range(N) if 2**i&s and 2**j&s)//2
    t = s&(s-1)
    for _ in range(2**ppc - 2):
        res = max(res, dp[t] + dp[s^t])
        t = (t-1)&s
    dp[s] = res
print(dp[-1])

Measured memory_bytes: 50560
# -*- coding: utf-8 -*-
"""
Basic Operations - Count
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_3_C&lang=jp

"""
n = int(input())
A = input().split()
for _ in range(int(input())):
    b, e, k = input().split()
    print(A[int(b):int(e)].count(k))
    


Measured memory_bytes: 5644
N = int(input())
P = [int(input()) for _ in range(N)]

L = [1]*(N+1)
for i in range(N):
    if P[i] < N and L[P[i]+1] == 1:
        L[P[i]+1] = L[P[i]]+1
    if L[P[i]] == 1:
        L[P[i]] = 0

ans = N-max(L)
print(ans)

Measured memory_bytes: 18888
#include<iostream>
#include<algorithm>
#include<iomanip>

using namespace std;

int main() {
	int N;
	double A[50];
	cin >> N;
	for (int i = 0; i < N; i++)cin >> A[i];
	sort(A, A + N);
	double ans = (A[0] + A[1]) / 2.0;
	for (int i = 2; i < N; i++) {
		ans = (ans + A[i]) / 2.0;
	}
	cout << setprecision(10) << ans << endl;
	return 0;
}

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

using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)


signed main(){

	int N, a[200001], b[200002] = { 0 };
	cin >> N;
	for (int i = 0; i < N; i++){
		cin >> a[i];
		b[i+1] = b[i] + a[i];
	}

	// [0,p),[p,q),[q,r)[r,N)
	//  P     Q       R      S
	int p, q, r;
	int P, Q, R, S;
	p = 1;
	r = 3;
	int minimum = INF;
	for (q = 2; q <= N - 2; q++){
		int minimum1 = INF, minimum2=INF;
		while (P = b[p] - b[0], Q = b[q] - b[p], abs(P - Q) < minimum1){
			minimum1 = abs(P - Q);
			p++;
		}
		p--;

		while (R = b[r] - b[q], S = b[N] - b[r], abs(S - R) < minimum2){
			minimum2 = abs(S - R);
			r++;
		}
		r--;

		P = b[p] - b[0], Q = b[q] - b[p];
		R = b[r] - b[q], S = b[N] - b[r];
		minimum = min(minimum, max(max(P, Q), max(R, S)) - min(min(P, Q), min(R, S)));
	}

	cout << minimum << endl;

	return 0;
}


Measured memory_bytes: 3328
n = gets.chomp.to_i
str = gets.chomp

max = 0
(n-1).times do |i|
  a = str[0..i]
  b = str[i+1..-1]
  # strを取り出して分割する
  tmp_type = []
  # アルファベットの種類のための箱を作る
  a.length.times do |j|
    if b && b.include?(a[j])
      tmp_type << a[j]
    end
  end
  tmp_type.uniq!
  max = [max,tmp_type.length].max
end
puts max


Measured memory_bytes: 1788
def dfs(root):
  isVisited = [False] * n
  queue = [(0, root)]
  # print('queue is', queue)
  longest = (-1, -1)

  while queue:
    total_weight, node = queue.pop()
    if isVisited[node]:
      continue
    isVisited[node] = True
    longest = max(longest, (total_weight, node))
    # print("longest is", longest)
    for w, t in edges[node]:
      if not isVisited[t]:
        queue.append((total_weight + w, t))

  return longest

n = int(input())

edges =[[] for i in range(n)]

for i in range(n-1):
  s,t,w = map(int, input().split())
  edges[s].append((w, t))
  edges[t].append((w, s))

_, ln = dfs(0)
# print("ln", ln)
ld, _ = dfs(ln)
# print("ld", ld)
print(ld)



Measured memory_bytes: 38184
from collections import deque

H,W = map(int,input().split())
sy,sx = map(int,input().split())
gy,gx = map(int,input().split())

S = [None]*W
S = [list(input()) for i in range(H)]

dx = [1,-1,0,0]
dy = [0,0,1,-1]

wx = [-2,-2,-2,-2,-2,-1,-1,-1,-1,-1,0,0,0,0,0,1,1,1,1,1,2,2,2,2,2]
wy = [-2,-1,0,1,2,-2,-1,0,1,2,-2,-1,0,1,2,-2,-1,0,1,2,-2,-1,0,1,2]

def distance(i,j):
    not_visited = [[-1]*W for i in range(H)]
    not_visited[i][j] = 0
    stack = deque()
    stack.append((i,j))

    stack2 = deque()
    stack2.append((i,j))

    while stack2 != deque([]):

        while stack != deque([]):
            y,x = stack.popleft()
            for i in range(4):
                if 0<= x+dx[i] <W and 0<= y+dy[i] <H and S[y+dy[i]][x+dx[i]] != "#" and not_visited[y+dy[i]][x+dx[i]] == -1:
                    not_visited[y+dy[i]][x+dx[i]] =  not_visited[y][x]
                    stack.append((y+dy[i],x+dx[i]))
                    stack2.append((y+dy[i],x+dx[i]))

        y,x = stack2.popleft()
        for i in range(25):
            if 0<= x+wx[i] <W and 0<= y+wy[i] <H and S[y+wy[i]][x+wx[i]] != "#" and not_visited[y+wy[i]][x+wx[i]] == -1:
                not_visited[y+wy[i]][x+wx[i]] =  not_visited[y][x] + 1
                stack.append((y+wy[i],x+wx[i]))
                stack2.append((y+wy[i],x+wx[i]))
        
        """
        for i in range(H):
            print(not_visited[i])
        print()
        """
    return not_visited[gy-1][gx-1]
    
print(distance(sy-1,sx-1))

Measured memory_bytes: 140460
#include <string>
#include <vector>
#include <iostream>

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

using namespace std;

char s[128];

char t[128];
bool tr[128];
vector<string> Ans;

void dfs(int i){
	if(!s[i]){
		t[i]='\0';
		Ans.push_back(t);
		return;
	}

	t[i]=s[i];
	if(!tr[t[i]]) dfs(i+1);

	if(s[i]!='z'){
		t[i]=s[i]+1;
		if(tr[t[i]]){
			tr[t[i]]=false;
			dfs(i+1);
			tr[t[i]]=true;
		}
	}
}

int main(){
	while(cin>>s,s[0]!='#'){
		Ans.clear();
		for(char c='b';c<='z';c++) tr[c]=true;

		dfs(0);

		cout<<Ans.size()<<endl;
		if(Ans.size()<=10){
			rep(i,Ans.size()) cout<<Ans[i]<<endl;
		}
		else{
			rep(i,5) cout<<Ans[i]<<endl;
			rep(i,5) cout<<Ans[Ans.size()-5+i]<<endl;
		}
	}

	return 0;
}

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

int main(){
    int K;
    cin >> K;
    string S;
    cin >> S;
    if(S.size() > K) {
        for (int i = 0; i < K; i++) {
            cout << S.at(i);
        }
        cout << '.' << '.' << '.' << endl;
    } else {
        cout << S << endl;
    }
}


Measured memory_bytes: 3632
import std.algorithm;
import std.range;
import std.stdio;
import std.math;
import std.array;
import std.string;
import std.conv;

/// 数列の読み込み
auto readNums(T = int)() {
	return readln().chomp.split.map!(to!T).array;
}

void main() {
	auto nums = readNums();
	auto a = nums[0];
	auto b = nums[1];
	auto c = nums[2];
	writefln("%s", min(b / a, c));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int mod=998244353;
#define Rint register int
#define C(n,m) (n<m?0:1ll*fac[n]*invfac[n-m]%mod*invfac[m]%mod)
using namespace std;
int T,n,m,p,k;
int ksm(int a,int k){
	int ans=1;
	for(;k;k>>=1,a=1ll*a*a%mod) if(k&1) ans=1ll*ans*a%mod;
	return ans;
}
int a[410],b[410],suma=0,sumb=0,C[410][410],f[410][410]; 
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]),suma+=a[i],sumb+=b[i];
	for(int i=0;i<=sumb;i++){
		C[i][0]=1;
		for(int j=1;j<=i;j++) C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
	}
	f[0][0]=1;
	int inv=ksm(suma,mod-2);
	for(int i=1;i<=n;i++) for(int j=suma;j>=a[i];j--) for(int k=sumb;k>=0;k--){
		for(int l=0,pow_t=1,tmp=1ll*a[i]*inv%mod;l<=min(b[i]-1,k);l++){
			f[j][k]=(f[j][k]-1ll*f[j-a[i]][k-l]*C[k][l]%mod*pow_t%mod+mod)%mod;
			pow_t=1ll*pow_t*tmp%mod;
		}
	}
	int ans=0;
	for(int j=0;j<=suma;j++) for(int k=0;k<=sumb;k++) ans=(ans+1ll*f[j][k]*ksm(1ll*suma*ksm(j,mod-2)%mod,k+1))%mod;
	printf("%d\n",(mod-ans)%mod);
}

Measured memory_bytes: 4984
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int main(){
  ll n,t,s;
  cin >> n >> t >> s;
  vector<ll> a(n), b(n);
  rep(i,n)cin >> a[i] >> b[i];

  vector<ll> dp(t+1,0);

  rep(i,n){
    for(int j=t;j>=0;j--){
      if(j+b[i]<=t && !(j<s && s<j+b[i])){
	dp[j+b[i]] = max(dp[j+b[i]], dp[j] + a[i]);
      }
    }
  }
  cout << *max_element(dp.begin(),dp.end()) << endl;
}

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


int main() {
  string S, T;
  cin >> S;
  cin >> T;

  bool isSubsequent = true;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] != T[i]) isSubsequent = false;
  }
  if (isSubsequent) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 3560
#include <iostream>                                             
#include <cmath>                                                
using namespace std;                                            
                                                                
int main(void) {                                                
  int x;                                                        
  cin >> x;                                                     
  int X_Cubic = pow(x,3);                                       
  cout << X_Cubic << endl;                                      
  return 0;                                                     
}                           

Measured memory_bytes: 3264
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		char[] s = in.next().toCharArray();
		int cnt = 0;
		char prev = '#';
		for ( int i = 0; i < n; i++ ) {
			if( prev != s[i]) {
				prev = s[i];
				cnt++;
			}
		}
		System.out.println(cnt);
		in.close();
	}
}

Measured memory_bytes: 26068
// input! macro is published in the following URLs.
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
// https://github.com/tanakh/competitive-rs.git
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        a: i64,
        b: i64,
    }
    let ans = (a..b + 1)
        .filter(|i| {
            let r = i
                .to_string()
                .chars()
                .rev()
                .collect::<String>()
                .parse::<i64>()
                .unwrap();
            *i == r
        })
        .count();
    println!("{}", ans);
}


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

using namespace std;
using ll = long long;
const ll mod = 1000000007;


int main()
{
    int a, b;
    cin >> a >> b;
    if((a > 0) != (b > 0) || a == 0 || b == 0){
        cout << "Zero" << endl;
        return 0;
    }

    if(a > 0 && b > 0){
        cout << "Positive" << endl;
        return 0;
    }

    cout << ((b - a) % 2 == 0 ? "Negative" : "Positive") << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#define rep(i,n) for (int i= 0;i<(n);++i)
using namespace std;
typedef long long ll;
const int MAX = 2e5;
int n;
ll k; 
int a[MAX]; 
bool visited[MAX];
int main() {
    ll ans = 0;
    cin >> n >> k;
    rep(i, n) {
        cin >> a[i];
        a[i]--;
    }
    int pos = 0;
    visited[pos] = true;
    int cnt = 0;
    rep(i, n) {
        cnt++;
        pos = a[pos];
        if (visited[pos]) break;
    }
    int loop_start = pos;
    if (cnt >= k) {
        pos = 0;
        rep(i, k) {
            pos = a[pos];
        }
        ans = pos;
    } else {
        pos = 0;
        rep(i, n) {
            if (pos == loop_start) break;
            pos = a[pos];
            cnt--;
            k--;
        }
        int loop_size = cnt;
        pos = loop_start;
        rep(i, k%loop_size) {
            pos = a[pos];
        }
        ans = pos;
    }
    ans++;
    cout << ans << endl;
}

Measured memory_bytes: 4384
#include <iostream>
using namespace std;
int n;
int A[100010];

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> A[i];
    int sta = 0, ans = 1;
    for (int i = 0; i < n - 1; i++) {
        if (A[i] < A[i+1]) { 
            if (sta == 0) sta = 1;
            else if (sta == 2) { sta = 0; ans++; }
        }
        else if (A[i] > A[i+1]) {
            if (sta == 0) sta = 2;
            else if (sta == 1) { sta = 0; ans++; }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define inf             LLONG_MAX
ll isPrime(int n) 
{ 
	// Corner cases 
	if (n <= 1) 
		return 1; 
	if (n <= 3) 
		return 2; 

	// This is checked so that we can skip 
	// middle five numbers in below loop 
	if (n % 2 == 0 || n % 3 == 0) 
		return 1; 

	for (int i = 5; i * i <= n; i = i + 6) 
		if (n % i == 0 || n % (i + 2) == 0) 
			return 1; 

	return 2; 
} 

ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i,res%=1000000007; 
    return res; } 
 
 int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b); 
} 
  
 
ll findlcm(ll arr[], int n) 
{ 
   
    ll ans = arr[0]; 
  
    
    for (int i = 1; i < n; i++) 
        ans = (((arr[i] * ans)) / 
                (gcd(arr[i], ans))); 
  
    return ans; 
} 
bool sortbysec(const pair<pair<string,int>,int> &a, 
              const pair<pair<string,int>,int> &b) 
{ 
	if(a.first.first==b.first.first)
		return a.first.second > b.first.second;
    return (a.first.first < b.first.first); 
} 
bool checkValidity(ll a, ll b, ll c) 
{ 
    // check condition 
    if (a + b <= c || a + c <= b || b + c <= a) 
        return false; 
    else
        return true; 
} 
int main() 
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
         string s;
         cin>>s;
         ll k=0,ans=0;
         if(s[0]=='R' && s[1]=='R' && s[2]=='R')
         {
             cout<<"3";
             exit(0);
         }
         if(s[0]=='R' && s[1]=='R')
         {
              cout<<"2";
             exit(0);
         }
         if(s[2]=='R' && s[1]=='R')
         {
              cout<<"2";
             exit(0);
         }
         if(s[0]!='R' && s[1]!='R' && s[2]!='R')
         {
              cout<<"0";
             exit(0);
         }
         cout<<"1";
         
    } 
    return 0;
}


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

#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair

#define forn(i,s,n) for(i=s;i<n;i++)
#define all(c)  c.begin(),c.end()
#define boost ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(0);srand(time(NULL));
#define tc(t) ll t;cin >> t; while(t--)
/* cout << fixed << setprecision(12) << ans << endl;*/
#define pii pair<long long,long long>
#define vii vector<pii>
#define vvi vector<vector <long long> >

#define ff first
#define ss second

#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vector<int> , greater<int> >

#define deb1(x) cout<<#x<<" : "<<x<<endl;
#define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
#define deba(a,n) for(ll i=0;i<n;++i) {  cout<<a[i]<<" "; };cout<<"\n"

#define MOD 1000000007
#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN


int main()
{
 boost;
 ll n,k;
 cin >> n >> k;
 vector<ll> h(n);
 ll i;
 forn(i,0,n)
 cin >> h[i];
 
vector<ll> dp(n,0);
dp[0]=0;

dp[1]=abs(h[1]-h[0]);

 forn(i,2,n)
 {  
     dp[i]=dp[i-1]+abs( h[i-1] - h[i] );
     for(ll j=2;j<=k;j++)
	 {
	  if(i-j >= 0)
	  { dp[i]=min( dp[i-j] + abs(h[i-j]-h[i]) , dp[i] );
	  }	
	 }
 
 	
 	
 }
  
 cout << dp[n-1] << endl;

}






Measured memory_bytes: 1792
x,n = map(int,input().split())

if n == 0:
    print(x)
else:
    p = list(map(int,input().split()))

    p.sort()
    trgt = x
    roop_flg = True
    a = 1
    while roop_flg:
        if trgt not in p:
            break
        else:
            if a > 0:
                trgt = trgt -a
                a = -(a+1)

            else:
                trgt = trgt -a
                a = -(a-1)


    print(trgt)

Measured memory_bytes: 61952
#include <iostream>

using namespace std;

const string st = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int num = 52;

int main()
{
    int n;

    while (cin >> n, n) {
        string s;
        int k[105];
        int idx = 0;

        for (int i = 0; i < n; i++)
            cin >> k[i];
        cin >> s;

         for (int i = 0; i < s.size(); i++) {
             int tmp;
             if ('a' <= s[i] && s[i] <= 'z') 
                 tmp = (s[i] - 'a' - k[idx] + num) % num;
             else if ('A' <= s[i] && s[i] <= 'Z') 
                 tmp = (s[i] - 'A' - k[idx] + 26 + num) % num;

             cout << st[tmp];
             idx = (idx + 1) % n;
         }
         cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1212
n,m=map(int, input().split())
x=list(map(int, input().split()))
x.sort()
tmp=[0]*(m-1)
for i in range(m-1):
    tmp[i]=x[i+1]-x[i]#隣り合う座標の距離
tmp.sort()
if n>=m:
    print(0)
else:
    print(sum(tmp[0:m-n]))
    #隣り合う距離が小さいものを（座標数ー駒数）分選ぶ
    #つまり、移動しないと辿り着けない座標を取ってくる。

Measured memory_bytes: 13960
#include<bits/stdc++.h>
using namespace std;
string s[100000],m;
int main()
{
	long long n,a[3];
	cin>>n>>a[0]>>a[1]>>a[2];
	for(int t=0;t<n;t++)
	{
		cin>>s[t];
	}
	for(int t=0;t<n;t++)
	{
		if(a[s[t][0]-'A']<a[s[t][1]-'A'])
		{
			m+=s[t][0];
			a[s[t][0]-'A']++;
			a[s[t][1]-'A']--;
		}
		else if(a[s[t][0]-'A']==a[s[t][1]-'A'])
		{
			if(t!=n-1)
			{
		    	if(s[t][0]-'A'==s[t+1][0]-'A'||s[t][0]-'A'==s[t+1][1]-'A')
		    	{
		    		m+=s[t][0];
		    		a[s[t][0]-'A']++;
		    		a[s[t][1]-'A']--;
		    	}
		    	else
		    	{
		    		m+=s[t][1];
		    		a[s[t][1]-'A']++;
		    		a[s[t][0]-'A']--;
		    	}
		    }
		    else
		    {
		    	m+=s[t][0];
		    	a[s[t][0]-'A']++;
		    	a[s[t][1]-'A']--;
			}
	    }
		else
		{
			m+=s[t][1];
			a[s[t][1]-'A']++;
			a[s[t][0]-'A']--;
		}
		if(a[0]<0||a[1]<0||a[2]<0)
		{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	for(int t=0;t<n;t++)
	{
		cout<<m[t]<<endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair <ll, ll> pii;
#define x first
#define y second
#define mp make_pair

const int MAXN = (ll)1e5;
pii a[MAXN + 5];
int n;
const ll inf = (ll)1e15;

bool cmp(pii x, pii y){
	return x.y < y.y;
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 0 ; i < n ; ++i){
	cin >> a[i].x >> a[i].y;
	ll l = a[i].x - a[i].y;
	ll r = a[i].x + a[i].y;
	a[i].x = l;
	a[i].y = r;
}
sort(a, a + n, cmp);
int sol = 0;
ll zadnji = -inf;
for(int i = 0 ; i < n ; ++i){
	if(a[i].x >= zadnji){
		sol++;
		zadnji = a[i].y;
	}
}
cout << sol << endl;

return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
const char newl = '\n';
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
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; }
const long long INF = 1LL<<60;

int main(){
    int n,p,m = 0;cin >> n >> p;
    rep(i,n){
        int a;cin >> a;
        if(a&1) m++;
    }
    if(m==0) cout << (p==0?(1LL<<(n-m)):0);
    else cout << (1LL<<n-1);
    return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>

int main()
{
    int h1, m1, h2, m2, k, hours = 0, minutes = 0, ans = 0;
    scanf("%d %d %d %d %d", &h1, &m1, &h2, &m2, &k);

    hours = h2-h1;
    minutes = m2-m1;
    minutes += (hours*60);
    ans = minutes-k;

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

}


Measured memory_bytes: 1700
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int N;
    int V[25],C[25];
    cin>>N;
    for(int i=0;i<N;i++)cin>>V[i];
    for(int i=0;i<N;i++)cin>>C[i];

    int sub[25];
    for(int i=0;i<N;i++)sub[i]=V[i]-C[i];
    sort(sub,sub+N);
    reverse(sub,sub+N);
    int ans=0;
    for(int i=0;i<N;i++){
        if(sub[i]>0)ans+=sub[i];
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <bitset>
#include <map>

using namespace std;

int main(){

    int N;
    long long count = 0;
    cin >> N;
    vector<int> A(N+1), B(N);
    for (int i = 0; i < N+1; i++){
        cin >> A[i];
    }
    for (int i = 0; i < N; i++){
        cin >> B[i];
    }

    for (int i = N-1; i >= 0; i--){
        if (B[i] - A[i+1] >= 0){
            count += A[i+1];
            B[i] -= A[i+1];
            if (B[i] - A[i] >= 0){
                count += A[i];
                A[i] = 0;
            } else {
                count += B[i];
                A[i] -= B[i];
            }
        } else {
            count += B[i];
        }
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  ll N,M,K;
  cin >> N >> M >> K;
  vector<ll> A(N);
  vector<ll> Asum(N);
  ll suma = 0;
  REP(i, N){
    cin >> A[i];
    suma+=A[i];
    Asum.at(i)=suma;
  }
  vector<ll> B(M);
  vector<ll> Bsum(M);
  ll sumb = 0;
  REP(i, M){
    cin >> B[i];
    sumb+=B[i];
    Bsum.at(i)=sumb;
  }
  
  ll MAX = 0;
  REP(i,N){
    auto itr = upper_bound(ALL(Bsum),K-Asum.at(i));
    if(K-Asum.at(i)<0){
      break;
    }
    ll x = i+distance(Bsum.begin(),itr)+1;
    MAX = max(MAX,x);
  }    
  auto itr = upper_bound(ALL(Bsum),K);
  ll y = distance(Bsum.begin(),itr);
  MAX = max(MAX,y);


  cout << MAX << endl;
}

Measured memory_bytes: 9580
#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 big=1e18;
const double PI=2*asin(1);

int N;
int c[500005];
int bit[500005];
map<int, int> amap;

void add(int x) {
  x++;
  int tmp = x;
  while(tmp<=N) {
    bit[tmp]++;
    tmp += tmp & -tmp;
  }
  if(amap[c[x-1]]!=-1) {
    int bef = amap[c[x-1]];
    while(bef<=N) {
      bit[bef]--;
      bef += bef & -bef;
    }
  }
  amap[c[x-1]] = x;
}

int sum(int x) {
  x++;
  if(x==0) return 0;
  int ans = 0;
  while(x>0) {
    ans += bit[x];
    x -= x & -x;
  }
  return ans;
}

int main() {
  int Q;
  cin>>N>>Q;
  for(int i=1;i<=N;++i) {
    amap[i] = -1;
  }
  for(int i=0;i<N;++i) cin>>c[i];
  vector<tuple<int, int, int> > arr(Q);
  int l, r;
  for(int i=0;i<Q;++i) {
    cin>>l>>r;
    l--;
    r--;
    arr[i] = make_tuple(r, l, i);
  }
  sort(arr.begin(), arr.end());
  int ans[Q];
  int index = 0;
  int R, L, I;
  for(int i=0;i<Q;++i) {
    R = get<0>(arr[i]);
    L = get<1>(arr[i]);
    I = get<2>(arr[i]);
    for(int j=index;j<=R;++j) {
      add(j);
    }
    index = R+1;
    ans[I] = sum(R) - sum(L-1);
  }
  for(int i=0;i<Q;++i) cout<<ans[i]<<endl;
}



Measured memory_bytes: 38956
#include <stdio.h>

#define N 2000000
#define M 10000

void CountingSort(int *, int *, int);
int n;
int main() {
  int A[N],B[N],i;

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

  CountingSort(A,B,10000);

  for (i=1;i<=n;i++){

    if(i==1) printf("%d", B[i]);
    else printf(" %d", B[i]);
  }
  printf("\n");

  return 0;
}

void CountingSort(int *A, int *B, int k){
  int C[M],i,j;

  for (i=0;i<=k;i++){
    C[i] = 0;
  }

  for (j=1;j<=n;j++){
    C[A[j]]++;
  }

  for (i=1;i<=k;i++){
    C[i] = C[i] + C[i-1];
  }

  for (j=n;j>0;j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
}


Measured memory_bytes: 17360
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに作成したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), a = scanner.nextInt(), b = scanner.nextInt();
			// m_C_nの配列を計算
			long[][] c = calcC(n);
			long[] v = new long[n];
			// 入力数字のそれぞれの個数を計算するマップ
			Map<Long, Integer> map = new HashMap<>();
			IntStream.range(0, n).forEach(i -> {
				v[i] = scanner.nextLong();
				map.put(v[i], map.getOrDefault(v[i], 0) + 1);
			});
			Arrays.sort(v);
			System.out.println(IntStream.rangeClosed(1, a).mapToLong(i -> v[n - i]).average().getAsDouble());
			if (v[n - 1] == v[n - a]) {
				Integer count = map.get(v[n - 1]);
				int max = Math.min(count, b);
				System.out.println(IntStream.rangeClosed(a, max).mapToLong(i -> c[count][i]).sum());
			} else {
				long[] keys = map.keySet().stream().sorted((l1, l2) -> l2.compareTo(l1)).mapToLong(Long::longValue)
						.toArray();
				// map.get(i) はソートされたvにiが現れるまでの数字の個数（iより大きい数字の個数）
				Map<Long, Integer> countMap = new HashMap<>();
				int count = 0;
				countMap.put(keys[0], count);
				for (int i = 1; i < keys.length; i++) {
					countMap.put(keys[i], count += map.get(keys[i - 1]));
				}
				System.out.println(c[map.get(v[n - a])][a - countMap.get(v[n - a])]);
			}
		}
	}

	/**
	 * パスカルの三角形を使ってm_C_nを計算
	 * 
	 * @param n 整数の最大値
	 * @return m_C_n の配列，c[m][n]はm_C_n
	 */
	private static long[][] calcC(int n) {
		long[][] c = new long[n + 1][n + 1];
		c[0][0] = 1;
		IntStream.rangeClosed(1, n).forEach(i -> IntStream.rangeClosed(0, i).forEach(j -> {
			// c[i][j] = c[i-1][j-1]+c[i-1][j]
			if ((i > 0) && (j > 0)) {
				c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
			} else {
				c[i][j] = 1;
			}
		}));
		return c;
	}
}


Measured memory_bytes: 36952
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
using namespace std;
typedef long long ll;
int main(){
  int n,m;
  cin >> n >> m;
  vector<int> num(n);
  ll all = 0;
  for(int i = 0;i < n;i++)cin >> num[i],all += num[i];
  sort(num.begin(),num.end());
  if(num[n - m] * 4 * m >= all)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=55;
const int MAXM=7;
const int MAXMASK=(1<<5);
double f[MAXM*MAXN+5][MAXMASK];
int L[MAXM],n,bin[25],p[MAXM],C;
int main()
{
	bin[1]=1;for(int i=2;i<=20;i++)bin[i]=bin[i-1]<<1;
	n=read();C=read();
	for(int i=1;i<=n;i++)L[i]=read();sort(L+1,L+1+n);
	--n;for(int i=1;i<=n;i++)p[i]=i;double ans=0;
	int t=0;
	do
	{
		memset(f,0,sizeof(f));f[L[n+1]*(n+1)][0]=1;
		for(int i=0;i<(n+1)*C;i++)
			for(int j=i;j<=(n+1)*C;j++)
				for(int k=0;k<bin[n+1];k++)if(f[j][k])
					if(i%(n+1)&&!(k&bin[p[i%(n+1)]]))
						f[min((n+1)*C,max(j,i+L[p[i%(n+1)]]*(n+1)))][k|bin[p[i%(n+1)]]]+=f[j][k];
		ans+=f[(n+1)*C][bin[n+1]-1];++t;
	}while(next_permutation(p+1,p+1+n));double CC=(double)C;
	printf("%.15lf\n",ans/pow(CC,n)/t);
	return 0;
}


Measured memory_bytes: 256
<?php
$s = str_split(trim(fgets(STDIN)));
$count = count($s);

$ans = 0;
for ($mask = 0; $mask < (1 << $count -1); $mask++) {
    $tmp = 0;
    for ($i = 0; $i < $count; $i++) {
        $tmp += $s[$i];
         if(($mask >> $i) & 1) {
             $ans += $tmp;
             $tmp = 0;
         } else {
             $tmp *= 10;
         }
    }
    $ans += $tmp/10;
}

echo $ans;


Measured memory_bytes: 4728
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long long dp[70][4];
int main(){
	long long a;scanf("%lld",&a);
	dp[0][0]=1;
	for(int i=0;i<60;i++){
		int p=0;
		if(a&(1LL<<(59-i)))p=1;
		for(int j=0;j<4;j++){
			if(!dp[i][j])continue;
			for(int k=0;k<3;k++){
				int to=j;
				if(to==0){
					if(p==0&&k)continue;
					if(p==1&&k==2)continue;
					if(p==1&&k==0)to=1;
				}else if(to==1){
					if(p==0&&k==2)to=0;
					else if(p==1&&k<2)to=2;
					else if(p==0&&k<1)to=2;
				}
				dp[i+1][to]=(dp[i+1][to]+dp[i][j])%mod;
			}
		}
	}
	long long ret=0;
	for(int i=0;i<4;i++)ret=(ret+dp[60][i])%mod;
	printf("%lld\n",ret);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  
  cin >> N;
 
  for (int i = 0; i < N; i++) {
    string str;
    
    cin >> str;
    if (str == "Y") {
      cout << "Four" << endl;
      return 0;
    }
  }
  cout << "Three" << endl;
    
 
}

Measured memory_bytes: 256
module Main where

import           Data.Array
import           Data.List

main :: IO ()
main = do
  x <- readLn
  let cs = combsWithRep [1 .. x] 3
  let g  = dp x
  print $ sum [ f a b c * g a b c | [a, b, c] <- cs ]
 where
  f a b c | a == b && b == c = 1
          | a == b || b == c = 3
          | otherwise        = 6
  dp x = g
   where
    g a b c = a `gcd'` b `gcd'` c
    gcd' a 0 = a
    gcd' a b = dp' ! (b, a `mod` b)
    dp' =
      listArray ((0, 0), (x, x)) [ gcd' a b | a <- [0 .. x], b <- [0 .. x] ]

-- https://rosettacode.org/wiki/Combinations_with_repetitions#Dynamic_Programming
combsWithRep :: [a] -> Int -> [[a]]
combsWithRep xs k = combsBySize xs !! k
 where
  combsBySize = foldr f ([[]] : repeat [])
  f x = scanl1 $ (++) . map (x :)


Measured memory_bytes: 16020
#include<iostream>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<algorithm>

using namespace std;

// int main(){
//     char c;
//     int a,b;
//     scanf("%d %c %d",&a,&c,&b);
//     if(c=='+') printf("%d\n",a+b);
//     if(c=='-') printf("%d\n",a-b);
//     return 0;
// }


    int N;
    int nn[1000];
    int m;
    int p1,x1;
void solve(int p,int s,int *m){
    int sum=0;
    for(int i=1;i<=N;i++){
        if(i==p) sum+=s;
        else sum+=m[i];
    }
    cout<<sum<<endl;
}


int main(){
    cin>>N;
    for(int i=1;i<=N;i++ ) cin>>nn[i];
    cin>>m;
    while(m--){
        cin>>p1>>x1;
        solve(p1,x1,nn);
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define re register
#define ll long long
inline int gi()
{
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=510;
int b[N],pos[N],B[N],n;
vector<int>G;
int main()
{
	n=gi();
	for(int i=1;i<=n;i++)b[i]=gi();
	for(int i=1;i<=n;i++)pos[i]=i;
	for(int i=n;i;--i)
	{
		int mx=0,wh=0;
		for(int j=1;j<=n;j++)
			if(!B[j] && pos[j]==b[j])
				if(b[j]>mx && b[j]<=i){mx=b[j];wh=j;}
		if(!wh){puts("-1");return 0;}
		G.push_back(mx);B[wh]=1;
		for(int j=wh+1;j<=n;j++)
			pos[j]--;
	}
	for(int i=G.size()-1;~i;--i)
		printf("%d\n",G[i]);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define M 200006
#define ll long long int
using namespace std;
int arr[M],n,last=1,circle=0;
ll m;
struct node{
	int s,t;
}p[M];
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;++i)
	{
		cin>>arr[i];
	}
	p[1].s=1;
	p[1].t=0;
	for(int t=1;t<=n;++t)
	{
		p[arr[last]].s+=1;
		if(t==m){cout<<arr[last];return 0;}
		if(p[arr[last]].s==2){
			circle=t-p[arr[last]].t;
			m-=p[arr[last]].t;
			break;
		}
		p[arr[last]].t=t;
		last=arr[last];
	}
	m%=circle;
	if(m==0){cout<<arr[last];return 0;}
	last=arr[last];
	for(int i=1;i<=m;++i)
	{
		last=arr[last];
	}
	cout<<last;
}

Measured memory_bytes: 5984
/**Bismillahir Rahmanir Rahim.**/
/*
         Md.Fagun Molla
         18ICTCSE006
         BSMRSTU(SHIICT)
*/
#include <bits/stdc++.h>
using namespace std;
 
 
#define  gcd(a,b)         __gcd(a,b)
#define  lcm(a,b)         (a*b)/gcd(a,b)
#define  ll               long long
#define  vi               std::vector<int>
#define  pb               push_back
#define  MAX              100007
#define  End              return 0;
#define                   pi acos(-1)
 
 
int main () {
    ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
    ll a,b;
    cin>>a>>b;
    ll c;
  	if(a==1||b==1) cout<<1<<endl;
    else if(b%2==0 && a%2==0) cout<<(a*b)/2<<endl;
    else if(a%2==0 && b%2!=0) cout<<(b/2+1)*a/2+(b/2)*(a/2)<<endl;
    else if(a%2!=0 && b%2==0) cout<<(b/2)*a<<endl;
    else cout<<(b/2+1)*(a/2+1)+(b/2)*(a/2)<<endl;
}
/* pray for me
Do before die
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repr(i,a,n) for(int i=a;i>n;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int a, b, x;
  cin >> a >> b >> x;
  if (x >= a && x <= a+b) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
using namespace std;

int n;
int a[10000];

signed main() {
	int i;
	
	cin >> n;
	for (i = 0; i < n; i++) cin >> a[i];
	
	int ans = 0;
	for (i = 0; i < n; i++) {
		while (a[i] % 2 == 0) {
			a[i] /= 2;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;//入力を取得する(Scanner)

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

											 int a[] = new int[N]; //nyuryokuyou
											 for(int i = 0 ; i < N ; i++ ){
															 a[i] = sc.nextInt();
											 }
											 int b[] = new int[N];
											 for(int i = 0 ; i < N ; i++){
															 b[a[i]-1] = i + 1;
											 }
											 for(int i = 0 ; i <N; i ++){
															 System.out.print(b[i]+" ");
											 }
											 System.out.println();
               }
		}



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

public class Main{
	
	static long mod=(long)1e9+7;
	
	public static void main(String[] args) throws IOException {
		Writer out=new Writer(System.out);
		Reader in=new Reader(System.in);
		int ts=1;
		
		outer: while(ts-->0) {	
			String s=in.next();
			String c=in.next();
			int count=0;
			for(int i=0; i<s.length(); i++) {
				if(s.charAt(i)!=c.charAt(i)) count++;
			}
			out.println(count);
		}
		out.close();		
		
	}

	static boolean tri(int a, int b, int c) {
		if(c<a+b && c>abs(a-b)) return true;
		return false;
	}
	
	
/*********************************** UTILITY CODE BELOW **************************************/	
		
	static int abs(int a) {
		return a>0 ? a : -a;
	}
	
	static int max(int a, int b) {
		return a>b ? a : b;
	}
	
	static int pow(int n, int m) {
		if(m==0) return 1;
		int temp=pow(n,m/2);
		long res=(((long)temp*temp)%mod);
		if(m%2==0) return (int)res;
		return (int)((res*n)%mod);
	}
	
	static class Pair{
		int u, v;
		
		Pair(int u, int v){this.u=u; this.v=v;}
		
		static void sort(Pair [] coll) {		
			List<Pair> al=new ArrayList<>(Arrays.asList(coll));
			Collections.sort(al,new Comparator<Pair>() {
				public int compare(Pair p1, Pair p2) {
					return p1.u-p2.u;
				}	
			});
			for(int i=0; i<al.size(); i++) {
				coll[i]=al.get(i);
			}
		}
		
	}
	
	static void sort(int[] a) {
		ArrayList<Integer> list=new ArrayList<>();
		for (int i:a) list.add(i);
		Collections.sort(list);
		for (int i=0; i<a.length; i++) a[i]=list.get(i);
	}
	
	static int [] array(int n, int value) {	
		int a[]=new int[n];
		for(int i=0; i<n; i++) a[i]=value;
		return a;
	}
	
	static class Reader{
		
		BufferedReader br;
		StringTokenizer to;
		
		Reader(InputStream stream){
			br=new BufferedReader(new InputStreamReader(stream));
			to=new StringTokenizer("");
		}
		
		String next() {
			while(!to.hasMoreTokens()) {
				try {
					to=new StringTokenizer(br.readLine());	
				}catch(IOException e) {}
				
			}
			return to.nextToken();
			
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		int [] readArray(int n) {
			int a[]=new int[n];
			for(int i=0; i<n ;i++) a[i]=nextInt();
			return a;
		}
		long [] readLongArray(int n) {
			long a[]=new long[n];
			for(int i=0; i<n ;i++) a[i]=nextLong();
			return a;
		}
		
	}
	
	static class Writer extends PrintWriter{
		Writer(OutputStream stream){
			super(stream);
		}
		void println(int [] array) {
			for(int i=0; i<array.length; i++) {
				print(array[i]+" ");
			}
			println();
		}
		void println(long [] array) {
			for(int i=0; i<array.length; i++) {
				print(array[i]+" ");
			}
			println();
		}
	}
	
}

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

#define int long long 
#define ld long double
#define pii pair<int, int>
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cerr << #x << ": " << x << '\n'
#define fast_io() ios::sync_with_stdio(false); cin.tie(0);

signed main() {
    fast_io();
    int n;
    cin >> n;
    vector<int> a(n);
    vector<vector<int>> here(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++){
        if(a[i] > (i == 0 ? 0 : a[i - 1] + 1)){
            cout << -1;
            return 0;
        }
        here[i - a[i]].pb(a[i] - i);
    }
    map<int, int> mp;
    int cnt = 0, ans = 0;
    for(int i = 0; i < n; i++){
        for(auto x : here[i]){
            mp[x]++;
            if(mp[x] == 1) cnt++;
        }
        ans += cnt - min(1LL, mp[-i]);
        mp[a[i] - i]--;
        if(mp[a[i] - i] == 0) cnt--;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 28264
#include<stdio.h>
int main()
{
    int a,b,c,d,e,f,i,n;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d%d%d",&a,&b,&c);
        d=a*a;
        e=b*b;
        f=c*c;
        if(d==(e+f)||e==(d+f)||f==(d+e))
        printf("YES\n");
        else
        printf("NO\n");
    }
    return 0;
}

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

using ll = long long;
using ull = unsigned long long;

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

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    int N,C;
    cin>>N>>C;
    vector<vector<pair<int,int>>> prg(C);
    vector<int> timeline(1e5+10,0);
    REP(i,N) {
        int s,t,c;
        cin>>s>>t>>c;
        prg[c-1].push_back(make_pair(s,t));
    }
    REP(i,C) {
        sort(ALL(prg[i]));
        stack<pair<int,int>> st;
        REP(j,prg[i].size()) {
            if (st.size() == 0) st.push(prg[i][j]);
            else {
                pair<int,int> temp = st.top();
                if (temp.se == prg[i][j].fi) {
                    st.pop();
                    st.push(make_pair(temp.fi,prg[i][j].se));
                }
                else {
                    st.push(prg[i][j]);
                }
            }
        }
        while(st.size()) {
            pair<int,int> temp = st.top();
            st.pop();
            timeline[temp.fi-1] += 1;
            timeline[temp.se] -= 1;
        }    
    }

    for (int i=1;i<1e5+5;i++) {
        timeline[i] = timeline[i-1] + timeline[i];
    }

    sort(ALL(timeline),greater<int>());
    cout<<timeline[0]<<endl;
    return 0;
}

Measured memory_bytes: 1920