akhauriyash/Code-Regression huggingface dataset:
using System;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {

            while(true)
            {
                var read = Console.ReadLine();
                var temp_string = read.Split(' ');
                int a = int.Parse(temp_string[0]), b = int.Parse(temp_string[1]);
                
                if(a==0&&b==0)
                {
                    break;
                }

                if (a > b)
                {
                    int temp = a;
                    a = b;
                    b = temp;
                }
                Console.WriteLine(a+" "+b);
            }
        }
    }
}

Measured memory_bytes: 9372
#include <bits/stdc++.h>
#include<algorithm>
#include<math.h>
using namespace std;
 
template <class T> using V = vector<T>;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n,m;
  	ci(n>>m);
  ll ans=1;
  ll A=sqrt(m);
  if(n==1){
    co(m)
  }
  
  
  else{
  FOR(i,1,A){
    ll a=pow(i,n);
    for(int j=0;j<A;j++){
    if(m%a==0){
      ans*=i;
      m/=a;
    }
      else{
        break;
      }
  }
  }
  co(ans)
  }
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>

using namespace std;
#define endl '\n'
#define pb push_back
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1e9 + 7)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define REP(i,n) for(int i = 0;i < (n);i++)
#define FOR(i,a,b) for(int i = (a);i <= (b);i++)
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) > "Yes" : "No" ) << endl


typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vii;

template <class T = int> T in() { T x; cin >> x; return (x); }
template <class T = int> void out(T x) { cout << (x) << endl; }

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

void solve() {

	int a = in(), b = in();

	out((a - 1)*(b - 1));

	return;
}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,k,n) for(ll i= (ll) k;i< (ll) n;i++)
#define all(v) (v).begin(), (v).end()
#define SZ(v) (int)((v).size())
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long long INF = 1e18L + 1;
const int IINF = 1e9 + 1;

using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

#ifdef LOCAL
#define DBG(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int s(int a) {
	int r = 0;
	while (a) {
		r += a % 10;
		a /= 10;
	}
	return r;
}

int main() {
	#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	#endif
	int n;
	cin >> n;
	int wyn = IINF;
	rep (i, 1, n) {
		wyn = min(wyn, s(i) + s(n - i));
		DBG(i, wyn);
	}
	cout << wyn;
}


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

int main(){
	int N;
	long long K;
	cin >> N >> K;
	vector<long long> A(N);
	vector<long long> F(N);
	for(auto &i:A)cin >> i;
	for(auto &i:F)cin >> i;
	
	sort(A.begin(),A.end());
	sort(F.begin(),F.end(),greater<long long>());
	
	long long ok=F[0]*A[N-1],ng=-1;
	
	while(abs(ok-ng)>1){
		long long mid=(ok+ng)/2;
		long long cost=0;
		for(int i=0;i<N;i++)cost+=max(0LL,(A[i]*F[i]-mid+F[i]-1)/F[i]);
		if(cost<=K)ok=mid;
		else ng=mid;
	}
	cout << ok << endl;
	return 0;
}

Measured memory_bytes: 3328
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let _n: usize = read!();
    let s: String = read!();
    let k: usize = read!();
    let s = s.chars().collect_vec();
    let c = s[k - 1];
    let ans: String = s.iter().map(|&cc| if cc != c { '*' } else { c }).collect();
    println!("{}", ans);
}


Measured memory_bytes: 2108
function Main(input) {
  const numbers = input.split(' ').map(n => Number(n));
  const a = numbers[0];
  const b = numbers[1];
  const c = numbers[2];
  console.log(a + b + c - Math.max(...numbers))
  
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
int main()
{
   ll n,m,s;
   cin>>n>>m;
   s=0;
   while(n)
   {
   	n=n/m;
   	s++;
   }
   printf("%lld\n",s);

}

Measured memory_bytes: 256
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()

N=int(input())
A=list(map(int,input().split()))
UV=[list(map(int,input().split())) for i in range(N-1)]
data=[[] for i in range(N)]
for u,v in UV:
    data[u-1].append(v-1)
    data[v-1].append(u-1)



idle_max=10**18

stack=deque([0])
visited={0}

miti_to_0=[-1 for i in range(N)]
miti=[set() for i in range(N)]

while stack:
    a=stack.popleft()
    for p in data[a]:
        if not p in visited:
            visited.add(p)
            miti_to_0[p]=a
            miti[a].add(p)
            stack.append(p)

stack=[0]
visited={0}
dp=[A[0]]
decodelst=[]
dic=defaultdict(int)
dic[0]=1
while stack:
    #print(dp)
    #print(decodelst)
    a=stack.pop()
    if miti[a]:
        p=miti[a].pop()

        if A[p]>dp[-1]:

            decodelst.append([len(dp),A[p],-1])
            dp.append(A[p])
            dic[p]=len(dp)


        else:
            i=bisect_left(dp,A[p])
            decodelst.append([i,A[p],dp[i]])
            dp[i]=A[p]
            dic[p]=len(dp)
        stack.append(p)
    else:
        if miti_to_0[a]==-1:
            break
        i,p,f=decodelst.pop()
        if f==-1:
            dp.pop()
        else:
            dp[i]=f
        stack.append(miti_to_0[a])
for i in range(N):
    print(dic[i])


Measured memory_bytes: 240452
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
const int N = 100030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const int mod =    1e9+7;
int n,m;

double dp[3010][3010];
double a[3030],ans=0;

int main()
{ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>n;
rep(i,1,n+1)
cin>>a[i];
dp[1][0]=1-a[1];
rep(i,2,n+1)
dp[i][0]=dp[i-1][0]*(1-a[i]);
dp[1][1]=a[1];
rep(i,2,n+1)
dp[i][i]=dp[i-1][i-1]*a[i];
rep(i,2,n+1)
{
	rep(j,1,i)
	{
		dp[i][j]=(1-a[i])*dp[i-1][j]+a[i]*dp[i-1][j-1];
	}
}
rep(i,n/2+1,n+1)
ans+=dp[n][i];
cout<<fixed<<setprecision(10)<<ans;
}

Measured memory_bytes: 69248
#include <stdio.h>
#include <iostream>

using namespace std;

int main() {
	int N;
	int K;
	int* x;
	int distance;
	int sum = 0;
	
	x = new int;
	
	cin >> N;
	cin >> K;

	x[N] = {};

	for (int i = 0; i < N; i++) {
		cin >> x[i];
		if (x[i]<=K-x[i]) {
			sum += x[i]*2;
		}
		else {
			sum += (K - x[i]) * 2;
		}
	}

	cout << sum << endl;;

	return 0;
}

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

m = 1000
s = 0

for i in range(n-1):
    if a[i] < a[i+1]:
        s = m // a[i]
        m += (a[i+1]-a[i]) * s

print(m)

#溶けてないよ


Measured memory_bytes: 9184
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<functional>
#include<map>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;
int main(){
    int a, b,c, d;
    cin >> a >> b >> c >> d;
    cout << max(a*b, c*d)<<endl;
    return 0;
}


Measured memory_bytes: 256
def mp():return map(int,input().split())
def lmp():return list(map(int,input().split()))
n,m,k = mp()
mod = 998244353
conb = [1]
pows = [pow(m-1, n-1-k, mod)]
for i in range(1,k+1):
    conb.append(conb[i-1]*(n-i)*pow(i,mod-2,mod) % mod)
    pows.append(pows[i-1]*(m-1) % mod)
pows.reverse()
# print(conb, pows)
ans = 0
for i in range(k+1):
    ans += m * conb[i] * pows[i]
    ans %= mod
print(ans)

# print(conb)
# print(pows)
# exit()
# now_comb = 1
# now_pow = pow(m-1, n-1, mod)
# ans = now_pow*m
# for i in range(1, k+1):
#     u1 = (now_comb * (n-i) * pow(i, mod-2, mod)) % mod
#     u2 = (now_pow * pow(m-1, mod-2, mod)) % mod
#     now_comb = u1
#     now_pow = u2
#     ans += u1*u2*m
#     ans %= mod
# print(ans%mod)


Measured memory_bytes: 96256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int X = sc.nextInt();
        String ans = "Yes";

        if (500 * K < X) {
            ans = "No";
        }

        System.out.println(ans);

        sc.close();
    }    
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC exit(0);
using namespace std;
char c;
int main() {
    DAU
    cin >> c;
    if ('A' <= c && c <= 'Z')
        cout << "A";
    else cout << "a";
    PLEC
}


Measured memory_bytes: 3632
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        if(N % 10 == 3){
            System.out.println("bon");
        }else if(N % 10 == 2 || N % 10 == 4 || N % 10 == 5 || N % 10 == 7 || N % 10 == 9){
            System.out.println("hon");
        }else if(N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8){
            System.out.println("pon");
        }
    }
}


Measured memory_bytes: 35744
D = list(map(int, input().split()))

D.sort()

Ans = (D[2] - D[0]) // 2
Ans += (D[2] - D[1]) // 2

a = D[2] % 2
b = D[0] % 2 + D[1] % 2

if a == 0:
  if b == 1:
    Ans += 2
  elif b == 2:
    Ans += 1
else:
  if b == 0:
    Ans += 1
  elif b == 1:
    Ans += 2

print(Ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
using namespace std;
#define int long long
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF (long long)(1e18)
#define MOD (int)(1e9+7)
#define yn(f) (f?"Yes":"No")
#define YN(f) (f?"YES":"NO")
#define MAX_N 110
#define MAX_V 1
#define max(a,b) (a>b?a:b)
// #define abs(a) (a>0?a:a*-1)

int x[MAX_N], y[MAX_N], h[MAX_N];


signed main(){
	int n, H = 0;
	
	cin>>n;
	
	for(int i = 1; i <= n; i++){
		cin>>x[i]>>y[i]>>h[i];
		if(x[i] == 0 && y[i] == 0){
			H = h[i];
		}
	}
	for(int i = 0; i <= 100; i++){
		for(int j = 0; j <= 100; j++){
			int flag = true, f = false, ff=false;
			int b, ll=1, hh = 0;
			for(int l = 1; l <= n; l++){
				if(h[l]==0){
					// hh  = max(abs(x[ll]-i)+abs(y[ll]-j), hh);
					// f = true;
					continue;
				}
				ll = l;
				// int temp = h[l]-abs(x[l]-i)-abs(y[l]-j);
				int temp  = h[ll]+abs(x[ll]-i)+abs(y[ll]-j);
				if(ff && temp != b){
					flag = false;
					break;
				}
				ff = true;
				b = temp;
			}
			if(flag){
				int hi  = h[ll]+abs(x[ll]-i)+abs(y[ll]-j);
				// if(H&&H!=hi)continue;
				// if(f&&hi > hh)continue;
				for(int l = 1; l <= n; l++){
					if(h[l] != max(hi-abs(x[l]-i)-abs(y[l]-j),0)){
						flag = false;
						break;
					}
				}
				if(flag)cout<<i<<" "<<j<<" "<<hi<<endl;
				else continue;
				// cout<<h[ll]<<" "<<x[ll]<<" "<<y[ll]<<endl;
				return 0;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL N;
	in >> N;

	if (N % 2 == 1) out << 0 << std::endl;
	else
	{
		LL ans = 0, cnt = 1;
		for (LL i = 10; i <= N; i *= 5)
		{
			ans += N / i;
			++cnt;
		}
		out << ans << std::endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>
#define INF 1000000000
using namespace std;
struct po{int node,flg;};
typedef long long ll;
int n,m,s,g;
vector <int> G[100001];
map <int,int> mp[2];

ll bfs(){
  int D[2][100001]={};
  queue <po> Q;
  mp[0].clear(),mp[1].clear();
  mp[0][0]++,mp[1][0]++;
  Q.push(po{s,0}),Q.push(po{g,1});
  while(!Q.empty()){
    po t=Q.front();Q.pop();
    for(int i=0;i<G[t.node].size();i++) {
      if(D[t.flg][G[t.node][i]]!=0)continue;
      Q.push(po{G[t.node][i],t.flg});
      D[t.flg][G[t.node][i]] = D[t.flg][t.node]+1;
      mp[t.flg][D[t.flg][t.node]+1]++;
    }
  }
  mp[0][D[0][s]]--,mp[1][D[1][g]]--;
  int DG = D[0][g];
  ll sum=0;
  map<int,int>::iterator it=mp[0].begin();
  while(it!=mp[0].end()){
    if(mp[1].count(DG-2-it->first))sum += (ll)it->second * mp[1][DG - it->first-2];
    it++;
  }
  return sum;
}

int main() {
  cin >> n >> m >> s >>g;
  for(int i=0;i<m;i++){
    int a,b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  cout << bfs() <<endl;
  return 0;
}

Measured memory_bytes: 9016
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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; }

string S;
int ans,s;

int main(){
    cin>>S;
    rep(i,S.length()){
        if(S[i]=='S')s++;
        else{
            if(s){
                ans++;
                s--;
            }
        }
    }
    out(S.length()-ans*2);
    
    
}


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

int main(){
  int r, g, b;
  cin >> r >> g >> b;
  if((100*r+10*g+b)%4==0){
    cout << "YES";
  }
  else{
    cout << "NO";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int v[110], w[110];
long long dp[110][100010];

long long f(int i, int W) {
  if(i <= 0 || W <= 0) return 0;
  if(dp[i][W]) return dp[i][W];
  dp[i][W] = f(i - 1, W);
  if(w[i - 1] <= W) dp[i][W] = max(dp[i][W], f(i - 1, W - w[i - 1]) + v[i - 1]);
  return dp[i][W];
}

int main() {
  int n, W;
  cin >> n >> W;
  for(int i=0; i<n; ++i) {
    cin >> w[i] >> v[i];
  }
  cout << f(n, W) << endl;
}

Measured memory_bytes: 79360
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main() {
  ll i,o,t,j,l,s,z;
  cin >>i>> o>> t>> j>> l>> s>> z;
  ll ans =o;
  if(i%2+j%2+l%2>1){
    ll tmp = min(1LL, min(i, min(j, l)));
    ans+=3*tmp;
    i-=tmp;j-=tmp;l-=tmp;
  }
  ans+=(i/2)* 2;
  ans+=(j/2)* 2;
  ans+=(l/2)* 2;
  cout << ans << endl;
}


Measured memory_bytes: 256
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let mut ans: usize = 0;
    let mut k: usize = 2;
    while k * k <= n - 1 {
        if (n - 1) % k == 0 {
            ans += 1;
            if k * k < n - 1 {
                ans += 1;
            }
        }
        k += 1;
    }
    if n - 1 >= 2 {
        ans += 1;
    }
    let mut k: usize = 2;
    while k * k <= n {
        if n % k == 0 {
            let mut x = n;
            while x % k == 0 {
                x /= k;
            }
            if x % k == 1 {
                ans += 1;
            }
        }
        k += 1;
    }
    if n >= 2 {
        ans += 1;
    }
    println!("{}", ans);
}


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

using namespace std;

const int NMAX = 50 + 5;

int N, P;
int cnt[2];

int main() {
    cin >> N >> P;
    while (N --) {
        int val;
        cin >> val;
        ++ cnt[val & 1];
    }
    
    long long int ways = 1;
    for (int i = 1; i <= cnt[0]; ++ i)
        ways = 2ll * ways;
    if (cnt[1] == 0) {
        if (P == 1)
            ways = 0;
    }
    else {
        for (int i = 1; i < cnt[1]; ++ i)
            ways = 2LL * ways;
    }
    
    cout << ways << '\n';
    return 0;
}

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

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;
int a[505];
int pre[505];
int suf[505];
int n,k;
int solve(int d)
{
    vector<int>vec;
    f(i,1,n)
    {
        int rem=a[i]%d;
        vec.pb(rem);
    }
    sort(vec.begin(),vec.end());
    int sum=0;
    int sz=vec.size();
    f(i,1,sz)
    {
        sum+=vec[i-1];
        pre[i]=sum;
    }
    sum=0;
    rf(i,sz,1)
    {
        sum+=(d-vec[i-1]);
        suf[i]=sum;
    }
    int ret=inf;
    f(i,1,sz)
    {
        int cost=max(pre[i],suf[i+1]);
        ret=min(ret,cost);
    }
    if(ret<=k)return true;
    return false;
}
 main()

{
    fast
    cin>>n>>k;
    int sum=0;
    f(i,1,n)
    {
        cin>>a[i];
        sum+=a[i];
    }
    vector<int>d;
    for(int i=1;i*i<=sum;i++)
    {
        if(sum%i==0)
        {
            d.pb(i);
            if((sum/i)!=i)
            {
                d.pb(sum/i);
            }
        }
    }
    int ses=inf;
    sort(d.rbegin(),d.rend());
    for(auto x:d)
    {
        if(solve(x)){
        cout<<x<<endl;
        return 0;
        }
    }


}





































Measured memory_bytes: 3716
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {

	int* aji;
	int N = 0;//apple_num
	int L = 0;
	rewind(stdin);
	scanf("%d %d", &N,&L);


	aji= (int*)malloc(N);
	memset(aji, 0, N);
	for (int i = 0; i < N; i++) {
		*(aji+i) = L + (i + 1) - 1;
	}

	int tmp = 0;
	for (int j = N; j > 0; j--) {
		for (int i = 0; i + 1 < j; i++) {
			if ((*(aji + i) * *(aji + i)) > (*(aji + i + 1) * *(aji + i + 1))) {
				tmp = *(aji + i);
				*(aji + i) = *(aji + i + 1);
				*(aji + i + 1) = tmp;
			}
		}
	}

	int sum = 0;
	for (int i = 1; i < N; i++) {
		sum = *(aji + i) + sum;
	}
	printf("\n%d\n", sum);

	rewind(stdin);
	getchar();
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

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

		int[] total = new int[11];
		total[0] = x;
		for(int i = 1; i<=10; i++) {
			total[i] = r * total[i-1] - D;
			System.out.println(total[i]);
		}
	}

}


Measured memory_bytes: 21716
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e8;

signed main() {
	string s;
	cin >> s;
	int cnt = 0;
	rep(i,s.size())if (s[i] == '1')cnt++;
	cout << cnt;
}

Measured memory_bytes: 256
h,w,d = map(int,input().split())
a = [list(map(int,input().split())) for i in range(h)]
r = [None for i in range(h*w+1)]
for i in range(h):
    for j in range(w):
        r[a[i][j]] = (i,j)
#print(r)

c = [0 for i in range(h*w+1)]
for i in range(d+1,h*w+1):
    c[i] = c[i-d] + abs(r[i][0]-r[i-d][0]) + abs(r[i][1]-r[i-d][1])
#print(c)
q = int(input())
for _ in range(q):
    x,y = map(int,input().split())
    print(c[y]-c[x])


Measured memory_bytes: 18028
a, b, c, d, e, f = list(map(int, input().split()))
res = [0, 0]
w = set()
s = set()
for i in range(f//(a*100)+1):
    for j in range(f//(b*100)+1):
        total = a*i*100 + b*j*100
        if a*i*100 + b*j*100 <= f:
            w.add(total)
w.remove(0)

s_max = int(f * (e / 100))
for i in range(0, s_max+1, c):
    for j in range(0, s_max-i+1, d):
        s.add(i+j)

max_nodo = -1
for wtr in w:
    for sgr in s:
        nodo = (sgr * 100) / (wtr + sgr)
        if wtr + sgr <= f and nodo <= (e*100) / (e+100):
            if nodo > max_nodo:
                max_nodo = nodo
                res[0] = wtr+sgr
                res[1] = sgr

print(str(res[0]) + " " + str(res[1]))

Measured memory_bytes: 3188
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        char[][] field = new char[h][];
        int[][] results = new int[h][w];
        for (int i = 0; i < h; i++) {
            field[i] = sc.next().toCharArray();
            Arrays.fill(results[i], Integer.MAX_VALUE);
        }
        PriorityQueue<Path> queue = new PriorityQueue<>();
        int start = 0;
        if (field[0][0] == '#') {
            start = 1;
        }
        queue.add(new Path(start, 0, 0));
        while (queue.size() > 0) {
            Path p = queue.poll();
            if (results[p.row][p.col] <= p.value) {
                continue;
            }
            results[p.row][p.col] = p.value;
            if (p.row < h - 1) {
                int next = 0;
                if (field[p.row][p.col] == '.' && field[p.row + 1][p.col] == '#') {
                    next ++;
                }
                queue.add(new Path(p.value + next, p.row + 1, p.col));
            }
            if (p.col < w - 1) {
                int next = 0;
                if (field[p.row][p.col] == '.' && field[p.row][p.col + 1] == '#') {
                    next ++;
                }
                queue.add(new Path(p.value + next, p.row, p.col + 1));
            }
        }
        System.out.println(results[h - 1][w - 1]);
    }
    
    static class Path implements Comparable<Path> {
        int value;
        int row;
        int col;
        
        public Path(int value, int row, int col) {
            this.value = value;
            this.row = row;
            this.col = col;
        }
        
        public int compareTo(Path another) {
            return value - another.value;
        }
    }
}


Measured memory_bytes: 23748
#include <iostream>
#include <string>

int main(int argc, char* argv[])
{
  char c;
  std::cin >> c;
  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
    std::cout << "vowel" << std::endl;
  } else {
    std::cout << "consonant" << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var A, B, C uint
	fmt.Scanf("%d %d %d", &A, &B, &C)

	if A == B {
		if A != C {
			fmt.Println("Yes")
			return
		}
	}
	if B == C {
		if B != A {
			fmt.Println("Yes")
			return
		}
	}
	if C == A {
		if C != B {
			fmt.Println("Yes")
			return
		}
	}

	fmt.Println("No")
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
using namespace std;

const int MAX = 210000;
const long long int MOD = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];


void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}


long long com(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

 long long int RepeatSquaring(long long int N, long long int P, long long int M){
  long long int res = 1;
    while(P>0){
        if(P & 1) res = res * N % M;
        N = N * N % M;
        P >>= 1;
    }
    return res;
}
 



int main(){
  
   COMinit();
  
   long long int N, M, X;
    cin >> N >> M >> X;
  
  long long int ans = 0;
  for(int i=0;i<=X;i++){

  
  ans +=  (((M*RepeatSquaring(M-1,N-1-i,MOD))%MOD)*com(N-1,i)%MOD);
  ans %= MOD;
  }
  
  cout << ans << endl;
  
}
  
  
  
    

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

// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define whole(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define bit(n) (1LL<<(n))
// functions
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(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << p.first << " " << p.second; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
//  types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
  fast_io(){ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20);}
} fast_io_;


int main(int argc, char const* argv[])
{
  int n, m; cin >> n >> m;
  if(n == m)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(a<b&&b<c)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}



Measured memory_bytes: 2092
n,*L=map(int,open(0).read().split())
G=[[]for _ in range(n)]
db=[-1]*n
dw=[-1]*n
for a,b in zip(*[iter(L)]*2):
	G[a-1]+=[b-1]
	G[b-1]+=[a-1]
q=[(0,0)]
while q:
	cur,d=q.pop(0)
	db[cur]=d
	for nxt in G[cur]:
		if db[nxt]<0:
			q.append((nxt,d+1))
q=[(n-1,0)]
while q:
	cur,d=q.pop(0)
	dw[cur]=d
	for nxt in G[cur]:
		if dw[nxt]<0:
			q.append((nxt,d+1))
b=w=0
for i,j in zip(db,dw):
	if i<=j:b+=1
	else:w+=1
if b<=w:
	print("Snuke")
else:
	print("Fennec")

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

int main(){
  int n;
  cin >> n;
  vector<ll> takahashi(n);
  ll sum = 0;
  for(int i = 0; i < n; i++){
    ll a, b;
    cin >> a >> b;
    takahashi[i] = a+b;
    sum-=b;
  }
  sort(takahashi.begin(), takahashi.end(), greater<long long>());
  for(int i = 0; i < n; i++){
    if(i%2 == 0){  
    sum += takahashi[i];
    }
  }
  cout << sum;
}


Measured memory_bytes: 1024
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var N = input[0];
        var X = input[1];
        var Y = input[2];

        var result = new int[N];
        for (int i = 1; i < N; i++)
        {
            for (int j = i + 1; j <= N; j++)
            {
                result[Math.Min(j - i, Math.Abs(X - i) + Math.Abs(Y - j) + 1)]++;
            }
        }
        for (int i = 1; i < N; i++)
        {
            Console.WriteLine(result[i]);
        }
    }
}


Measured memory_bytes: 13396
#include<stdio.h>
 
int main(){
  int h,w,i,j;
 
  while(1){
    scanf("%d%d",&h,&w);
 
    if(!h&&!w)
      return 0;
 
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
    if((i+j)%2==0)
      printf("#");
    else
      printf(".");
      }
      printf("\n");
    }      
    printf("\n");
  }
}

Measured memory_bytes: 572
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    
    int max,min;
    max=n;
    min=1;
    int gl,gh;
    
    for(int i=0;i<m;i++){
        cin>>gl;
        cin>>gh;
        
        if(gl>min) min=gl;
        if(gh<max) max=gh;
    }
    
    if(max-min>=0) cout<<max-min+1<<endl;
    else cout<<0<<endl;
    
 return 0;   
}

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

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

using namespace std;
typedef int Weight;
struct Edge{
  int src, dest; Weight weight;
  bool operator < (const Edge &rhs) const {return weight > rhs.weight;}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

Edges prim(Graph &g){
  Edges res;
  vector<int> visited(g.size(), 0);
  priority_queue<Edge> q;
  q.push((Edge){-1, 0, 0});
  while (!q.empty()) {
    Edge e = q.top();
    q.pop();
    if (visited[e.dest]) continue;
    if (e.src >= 0) res.push_back(e);
    visited[e.dest] = 1;
    for (Edge i : g[e.dest]) if(visited[i.dest] == 0) q.push(i);
  }
  sort(res.rbegin(), res.rend());
  return res;
}

int main() {
  while(1) {
    int n,m;
    cin>>n>>m;
    if(!n)break;
    Graph g(n);
    REP(i,m) {
      int a,b,c;
      cin>>a>>b>>c;
      g[a].push_back((Edge){a,b,c});
      g[b].push_back((Edge){b,a,c});
    }
    auto es = prim(g);
    int sum = 0;
    for(auto e:es) sum += e.weight;
    cout<<sum<<endl;
  }
  return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  vector<int>city(n);
  rep(i,n)cin>>city[i];
  int l,q;
  cin>>l>>q;
  int nl=n,c=0;
  while(nl>0){c++;nl/=2;}
  vector<vector<int>>db(n,vector<int>(c,n));
  int r=0;
  rep(i,n)
  {
    while(r+1<n&&city[r+1]<=city[i]+l)r++;
    db[i][0]=r;
  }
  rep(i,c-1)
  {
    rep(j,n)
    {
      db[j][i+1]=db[db[j][i]][i];
    }
  }
  rep(i,q)
  {
    int a,b;
    cin>>a>>b;
    a--;b--;
    if(a>b)swap(a,b);
    int cnt=0;
    int ma=lower_bound(all(db[a]),b)-db[a].begin();
    for(int j=ma-1;j>=0;j--)
    {
      if(db[a][j]<b)
      {
        a=db[a][j];
        cnt+=1<<j;
      }
    }
    cout<<cnt+1<<"\n";

  }
  cout<<flush;


  return 0;

}


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

int main() {
  int N;
  cin >> N;

  vector<pair<int, int>> C(N);
  rep(i, N) cin >> C[i].first >> C[i].second;

  vector<int> array;
  rep(i, N) array.push_back(i);

  double dist = 0;
  int count = 0;
  do {
    for (int i = 0; i < N - 1; i++) {
      dist += pow(pow(C[array[i]].first - C[array[i + 1]].first, 2) +
              pow(C[array[i]].second - C[array[i + 1]].second, 2),
          0.5);
    }
    count++;
  } while (next_permutation(array.begin(), array.end()));
  cout << setprecision(10) << dist / (double)count << endl;
}

Measured memory_bytes: 4264
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

#define REP(i,n) for(int i=0;(i)<(n);(i)++)
#define ll long long

int N;
int a[10004];
int ans;

signed main() {
	cin >> N;
	REP(i, N) {
		cin >> a[i];
	}

	for (int i = 0; i < N; i++) {
		for (int k = 29;k >= 0;k--) {
			if (a[i] % (1 << k) == 0) {
				ans += k;
				a[i] /= (1 << k);
			}
		}
	}

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

Measured memory_bytes: 256
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

ll gcd(ll a, ll b){
	while(b){
		a %= b;
		swap(a, b);
	}
	return a;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> as(n); cin >> as;
    int ans = as[0];
    for(int i = 1; i < n ; i++){
        ans = gcd(ans, as[i]);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 640
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var (H, W) = Slice2<long>();
            var ban = new long[H][];
            for (var i = 0; i < H; ++i)
                ban[i] = Sarray();
            var opes = new List<(long fh, long fw, long th, long tw)>();
            for (var h = 0; h < H; ++h)
            {
                var flg = h % 2 == 1;
                for (var w = 0; w < W - 1; ++w)
                {
                    var fw = flg ? W - 1 - w : w;
                    var tw = flg ? W - 1 - (w + 1) : w + 1;
                    if (ban[h][fw] % 2 == 1)
                    {
                        --ban[h][fw];
                        ++ban[h][tw];
                        opes.Add((h, fw, h, tw));
                    }
                }
                var fww = flg ? 0 : W - 1;
                if (ban[h][fww] % 2 == 1 && h < H - 1)
                {
                    --ban[h][fww];
                    ++ban[h + 1][fww];
                    opes.Add((h, fww, h + 1, fww));
                }
            }
            WriteLine(opes.Count);
            foreach (var o in opes)
                WriteLine($"{o.fh + 1} {o.fw + 1} {o.th + 1} {o.tw + 1}");
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 55344
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
int main(){
    cin.tie(0);
    cout.sync_with_stdio(false);
    int N; cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];
    int cnt = 0;
    REP(i, N){
        if(i+1 == A[i]){
            if(i==N-1){
                swap(A[i], A[i-1]);
                cnt++;
            }else {
                swap(A[i], A[i+1]);
                cnt++;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <numeric>
#include <math.h>
#include <climits>
#include <stack>
#include <iomanip>
#include <sstream>

using namespace std;

template <typename T>
inline bool sign(T A) {
    return (A>0)-(A<0);
}
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SREP(i,s,n) for(int i=s; (n-i)*sign(n-s)>0; i+=sign(n-s))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef unsigned long long ull;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

bool _less(pair<int, int> a, pair<int, int> b) {
    return a.second < b.second;
}

template <template<class,class,class...> class C, typename K, typename V, typename... Args>
V map_get(const C<K,V,Args...>& m, K const& key, const V & defval)
{
    typename C<K,V,Args...>::const_iterator it = m.find( key );
    if (it == m.end())
        return defval;
    return it->second;
}

#define MOD (1'000'000'000+7)


int cdp[200001];

int main(void)
{
    ll N;
    cin >> N;
    map<int, int> s;
    REP(i, N) {
        int A;
        cin >> A;
        auto lb = s.lower_bound(A);
        if (lb != s.begin()) {
            if (prev(lb)->second > 1) {
                s[prev(lb)->first]--;
            } else {
                s.erase(prev(lb));
            }
        }
        s[A]++;
    }
    ll cnt = 0;
    for (auto i : s)
    {
        cnt += i.second;
    }
    
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 4864
import Control.Monad
import Data.Functor
import Data.List

readInt :: String -> Int
readInt = read

main :: IO ()
main = do
  lis <- sort <$> map readInt <$> words <$> getLine
  let (x:xs) = take 4 lis
  let (y:ys) = take 4 $ drop 4 lis
  let (z:zs) = drop 8 lis
  putStrLn $ if all (== x) xs && all (== y) ys && all (== z) zs then "yes" else "no"

Measured memory_bytes: 3672
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<map>
using namespace std;


int distanta(pair<int,int> a,pair<int,int> b);

int main()
{
    int R,C;
    cin>>R>>C;
    string harta[1001];
    for(int i=1;i<=R;i++){
        cin>>harta[i];
    }

    queue<pair<int,int>> coada;
    int adaugateUltimaData=0;

    for(int i=1;i<=R;i++){
        for(int j=0;j<C;j++){
            if(harta[i][j]=='#'){
                coada.push({i,j});
                adaugateUltimaData++;
            }
        }
    }

    int ture=0;
    const int dl[]={-1,0,1,0};
    const int dc[]={0,1,0,-1};
    while(!coada.empty()){
        ture++;
        int adaugateAcum=0;
        while(adaugateUltimaData){
            pair<int,int> coords=coada.front();
            coada.pop();
            for(int k=0;k<4;k++){
                int newI=coords.first+dl[k];
                int newJ=coords.second+dc[k];
                if(newI>=1&&newI<=R&&newJ>=0&&newJ<C){
                    if(harta[newI][newJ]!='#'){
                        harta[newI][newJ]='#';
                        coada.push({newI,newJ});
                        adaugateAcum++;
                    }
                }
            }

            adaugateUltimaData--;
        }

        adaugateUltimaData=adaugateAcum;
    }

    cout<<ture-1;



}

int distanta(pair<int,int> a,pair<int,int> b){
    return abs(a.first-b.first)+abs(a.second-b.second);
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using P = pair<int, int>;

int main(){
    int n;
    cin >> n;
    VI begin, end;
    rep(i,n){
        int a;
        cin >> a;
        if(i%2==0){
            end.push_back(a);
        }else{
            begin.push_back(a);
        }
    }

    int bn = begin.size(), en = end.size();
    if(n%2==0){
        rep(i,bn) cout << begin[bn-i-1] << " ";
        rep(i,en) cout << end[i] << " ";
    }else{
        rep(i,en) cout << end[en-i-1] << " ";
        rep(i,bn) cout << begin[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3188
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define srep(i) for(int i = 0; i < s.size(); i++)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout << #x << ": " << x << endl
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 1e9
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int N, W, A, B, K;
int a[100005];
int h[100005];
int weight[105] = {}, value[105] = {};
ll dp[100000005];
int in = 0;
int cnt = 0;

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

ll all_search(int i) {
    ll res = INF;
    if(i + 1 == N) {
        return 0;
    }

    for(int k = 1; k <= K; k++) {
        if(i + k == N) {
            return all_search(i + k - 1) + abs(h[i] - h[i + k - 1]);
        } else {
            res = min(res, all_search(i + k) + abs(h[i] - h[i + k]));
        }
    }
    return res;
}

ll dp_recursive(int i) {
    ll res = INF;
    if(dp[i] >= 0) {
        return dp[i];
    }

    if(i + 1 == N) {
        return 0;
    }

    for(int k = 1; k <= K; k++) {
        if(i + k == N) {
            return dp[i] = dp_recursive(i + k - 1) + abs(h[i] - h[i + k - 1]);
        } else {
            res = min(res, dp_recursive(i + k) + abs(h[i] - h[i + k]));
        }
    }
    return dp[i] = res;
}

ll dp_for(int n, int k) {
    for(int i = 0; i < N; i++)
        dp[i] = INF;
    dp[0] = 0;

    for(int i = 0; i < n; i++) {
        for(int j = 1; j <= k; j++) {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }
    return dp[n - 1];
}

int main() {
    cin >> N >> K;
    rep(i, N) cin >> h[i];
    memset(dp, -1, sizeof(dp));
    cout << dp_for(N, K) << endl;
}


Measured memory_bytes: 781952