akhauriyash/Code-Regression huggingface dataset:
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

struct UnionFind{
    v: Vec<usize>
}

impl UnionFind{
    fn new(n: usize) -> UnionFind{
        let mut v: Vec<usize> = Vec::new();
        for i in 0..n{
         v.push(i);
        }
        UnionFind{v:v}
    }

    fn find(&mut self, i: usize) -> usize{
        if self.v[i] == i{
            i
        }else{
            let ni = self.v[i];
            self.v[i] = self.find(ni);
            self.v[i]
        }
    }

    fn union(&mut self, i: usize, j: usize){
        let root_i = self.find(i);
        let root_j = self.find(j);
        self.v[root_i] = root_j;
    }

}

struct CombMod{
    fac: Vec<u64>,
    inv: Vec<u64>,
    finv: Vec<u64>,
    mmod: u64,
}

impl CombMod{
    pub fn new(max: u64, m: u64) -> CombMod{
        let max: usize = max as usize;
        let mut fac: Vec<u64> = vec![0;max+1];
        let mut finv: Vec<u64> = vec![0;max+1];
        let mut inv: Vec<u64> = vec![0;max+1];

        fac[0] = 1;
        fac[1] = 1;
        finv[0] = 1;
        finv[1] = 1;
        inv[1] = 1;

        for i in 2..max+1{
            fac[i] = fac[i-1] * i as u64 % m;
            inv[i] = m - inv[m as usize %i] * (m/(i as u64)) % m;
            finv[i] = finv[i-1] * inv[i] % m;
        }

        CombMod{
            fac: fac,
            finv: finv,
            inv: inv,
            mmod: m,
        }
    }

    fn get(&self, n: u64, m: u64) -> u64{
        assert!(n >= m && n != 0 && m != 0);
        self.fac[n as usize] * self.finv[m as usize] % self.mmod
            * self.finv[(n-m) as usize] % self.mmod
    }
}

fn is_prime(x: usize) -> bool{
    if x == 2{
        return true;
    }
    for div in 2..(x as f64).sqrt().ceil() as usize+1{
        if x%div == 0{
            return false;
        }
    }

    return true;
}

fn main(){
    let x = read_as_vec::<usize>()[0];

    for i in x..200000{
        if is_prime(i){
            println!("{}", i);
            return;
        }
    }
}


Measured memory_bytes: 4352
#include<stdio.h>

int main(void)
{
    int a;
    int b;
    scanf("%d",&a);
    scanf("%d",&b);
    if(b % 2 != 0){
        printf("No");
        return 0;
    }
    int b4 = (b+3)/4;
    int b2 = b / 2;
    if(a <= b2 && a >= b4)
    {
        printf("Yes");
        return 0;
    }
    printf("No");
    return 0;
}

Measured memory_bytes: 1692
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define N 200001
#define ll long long
#define int ll 
#define pi pair<int , int>
#define pip pair<pair ,int>
#define mp make_pair 
#define f first
#define s second
#define mod 998244353
ll Mod(ll x, ll y, int p) 
{ll res = 1; x = x % p;
while (y > 0) 
{if(y & 1) res = (res*x) % p; 
y = y>>1;x = (x*x) % p; 
}return res; 
}
int* getlps(string pattern){
 int len = pattern.length();
 int * lps = new int[len];
 lps[0] = 0;
 int i = 1 , j = 0;
 while(i < len){
  if(pattern[i] == pattern[j]){
	  lps[i] = j+1;
   i++;
   j++;
  }
  else{
		if(j != 0){
		 j = lps[j-1];
		}
		else{
		 lps[i] = 0;
		 i++;
		}
  }
 }
 return lps;
}
class Triplet{
 public:
 int x ;
 int y ;
 int gcd;
};
Triplet extendedEuclid(int a , int b){
 if(b == 0){Triplet ans; ans.gcd = a;ans.x = 1;ans.y = 0;return ans;}
 Triplet smallAns = extendedEuclid(b , a%b);
 Triplet ans;
 ans.gcd = smallAns.gcd;
 ans.x = smallAns.y;
 ans.y = smallAns.x - (a/b)*smallAns.y;
 return ans;
}
int mmInverse(int a , int m){
 Triplet ans = extendedEuclid(a , m);
 return ans.x;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// dp[i] represents whoesever turns it is , if there are i-stones does he win (true , otherwise false).
int n , k;
cin>>n>>k;
int arr[n];
for(int i =0 ; i < n;i++){
   cin>>arr[i];
}
bool dp[k+1];
memset(dp , false , sizeof(dp));
for(int i = 0 ; i <= k ; i++){
     // i stones , 
     for(int j = 0 ; j < n ; j++){
			if(i-arr[j] >= 0 && !dp[i-arr[j]]){
			  dp[i] = true;
			}
	 }
}
if(dp[k]){
 cout<<"First"<<endl;
}
else
cout<<"Second"<<endl;
}



Measured memory_bytes: 384
//#pragma comment(linker,"/STACK:16777216") /*16Mb*/
#pragma comment(linker,"/STACK:33554432") /*32Mb*/

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <cmath>
#include <list>
#include <iomanip>
#include <set>
#include <map>
#include <sstream>
using namespace std;

typedef  long long LL;
typedef  unsigned long long ULL;
typedef  long double LD;
typedef  pair<int, int> PII;
typedef vector<int> VI;
#define For(i,a,b) for(int (i)=(a);i<(b);++(i))
#define FoR(i,a,b) for(int (i)=(a)-1;(i)>=(b);--(i)) 
#define MP make_pair
#define MOD 1000000007
#define INF 1000000000
#define PB push_back
#define y0 kihrbdb
#define y1 ugvrrtgtrg
#define eps 1e-5
#define X first
#define Y second

int n;
LL arr[100010];

bool canAbs(int ind)
{
	LL sz = arr[ind];
	int i = 0;
	while (i < n)
	{
		if (i == ind)
		{
			i++;
			continue;
		}
		if (arr[i] > 2 * sz) return 0;
		sz += arr[i];
		i++;
	}
	return 1;
}

int bp(int l, int r)
{
	if (l == r)
	{
		if (canAbs(l)) return l;
		return l + 1;
	}
	int mid = (l + r) / 2;
	bool canDoIt = canAbs(mid);
	if (canDoIt) return bp(l, mid);
	return bp(mid + 1, r);
}

int main()
{
	///freopen("distance4.in", "r", stdin);
	///freopen("distance4", "w", stdout);
	//cout.setf(ios::fixed, ios::floatfield);
	//cout.precision(4);

	cin >> n;
	For(i, 0, n) cin >> arr[i];
	sort(arr, arr + n);

	int ans = n - bp(0, n - 1);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func scanInts(n int) []int {
	sl := make([]int, n)
	for i := range sl {
		sl[i] = scanInt()
	}
	return sl
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n, k := scanInt(), scanInt()
	ps := scanInts(n)

	sort.Ints(ps)
	var sum int
	for i := 0; i < k; i++ {
		sum += ps[i]
	}

	fmt.Println(sum)
}


Measured memory_bytes: 1780
#include<bits/stdc++.h>
#define lp(i, x, n) for (int i = x; i < (int)n; ++i)
using namespace std;
typedef long long ll;
ll k;
int main(){
    string str;
    cin >> str >> k;

    for(int i =0; i < (int)str.size(); i++){
        if(str[i] == '1' && k == (i + 1)){
            cout << '1' << endl;
            return 0;
        }
        if(str[i] != '1'){
            cout << str[i] << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader();
        int A, B, C;
        {int[] a = r.ii(); A = a[0]; B = a[1]; C = a[2];}
        boolean flag = false;
        for(int i = 1; i <= B; i++){
            if(A*i%B == C){
                flag = true;
                break;
            }
        }
        println(flag ? "YES" : "NO");
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long(ss[j]);            
            return ll;
        }
    }
}

Measured memory_bytes: 21204
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<string>

using namespace std;

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long

const lint MOD = 1e9 + 7;

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

int main(){
    lint n; cin >> n;
    vector<lint> c;
    rep(i, n){
        lint x; cin >> x; c.push_back(x);
    }
    sort(all(c));

    if(n == 1){
        cout << (c[0] * 2) % MOD << endl; return 0;
    }

    lint c_min = modpow(2, n-1);
    lint d = modpow(2, n-2);

    lint res = 0;
    repr(i, n){
        res += (c_min * c[i]) % MOD;
        res %= MOD;
        c_min += d; c_min %= MOD;
    }
    res = (res * modpow(2, n)) % MOD; 
    cout << res << endl;
}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pii;
typedef pair<ll,ll> pli;
const ll maxn=1e5+100;
vector<pii>edge[2][maxn];
bool inque[maxn];
ll dis[2][maxn];
ull cnt[2][maxn];
struct node{
    ll x,y,w;
}p[maxn];
void add(ll x,ll y,ll w,vector<pii> *edge){
    edge[x].push_back({y,w});
}
ll n,m;
void dij(ll st,vector<pii> *edge,ll dis[],ull cnt[]){
    priority_queue<pli,vector<pli>,greater<pli>>q;
    memset(inque,0,sizeof(inque));
    dis[st]=0;
    q.push({0,st});
    cnt[st]=1;
    while(q.size()){
        auto it=q.top();
        q.pop();
        ll u=it.second;
        ll val=it.first;
        if(inque[u])  continue;
        inque[u]=1;
        for(auto itt:edge[u]){
            ll v=itt.first,w=itt.second;
            if(inque[v]) continue;
            if(dis[v]>val+w){
                dis[v]=val+w;
                cnt[v]=cnt[u];
                q.push({val+w,v});
            }
            else if(dis[v]==val+w){
                cnt[v]+=cnt[u];
            }
        }
    }
}

ll vis[maxn];
int main(){
    memset(dis,0x3f,sizeof(dis));
    scanf("%lld%lld",&n,&m);
    for(ll i=1;i<=m;i++){
        ll x,y,w;
        scanf("%lld%lld%lld",&x,&y,&w);
        add(x,y,w,edge[0]);
        add(y,x,w,edge[1]);
        p[i]={x,y,w};
    }
    dij(1,edge[0],dis[0],cnt[0]);
    dij(2,edge[1],dis[1],cnt[1]);
    for(ll i=1;i<=n;i++) edge[0][i].clear(),edge[1][i].clear();
    for(ll i=1;i<=m;i++){
        ll x=p[i].x,y=p[i].y,w=p[i].w;
        if(dis[0][y]+dis[1][x]+w<dis[0][2]){
            printf("HAPPY\n");
        }
        else if(dis[0][y]+dis[1][x]+w==dis[0][2]){
            printf("SOSO\n");
        }
        else{
            if(dis[0][x]+dis[1][y]+w==dis[0][2]){
                if(cnt[0][x]*cnt[1][y]==cnt[0][2]) printf("SAD\n");
                else printf("SOSO\n");
            }
            else{
                printf("SOSO\n");
            }
        }
    }
}




Measured memory_bytes: 19680
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double x = 0, y = 0;
        int d = 90;
        while (true) {
            String[] lines = sc.next().split(",");
            int n = Integer.parseInt(lines[0]);
            int m = Integer.parseInt(lines[1]);
            if (n == 0 && m == 0)
                break;

            x += n*Math.cos(Math.toRadians(d));
            y += n*Math.sin(Math.toRadians(d));
            d -= m;

        }
        System.out.println((int)x);
        System.out.println((int)y);
    }
}


Measured memory_bytes: 26072
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>
#include <functional>

using namespace std;
#define ALL(x)			(x).begin(),(x).end()
#define REP(i, n)		for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)	for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF				(int)2e9
#define MOD				(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)		(((((x))+((n)-1))/n))	
#define CeilN(x, n)		(((((x))+((n)-1))/n)*n)	
#define FloorN(x, n)	((x)-(x)%(n))			
#define IsOdd(x)		(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)		(!IsOdd((x)))						
#define M_PI			3.14159265358979323846
typedef long long			ll;
typedef unsigned long long	ull;
typedef pair<ll, ll>		P;
typedef vector<ll>			VLL;
typedef vector<VLL>			VVLL;
typedef vector<VVLL>		VVVLL;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main()
{
	int K, X;
	cin >> K >> X;
	
	if (K * 500 < X) {
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
	}
 
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#define ll long long
using namespace std;

ll compute(ll b, ll n){
	if(n<b){
		return n;
	}else{
		return  compute(b, n/b) + n%b;
	}
}

int main(){
	ll n, s;
	ll b = 2;
	ll ans = -1;
	cin >> n;
	cin >> s;
	if(n == s){
		cout << n+1 << endl;
		return 0;
	}
	while(b*b <= n){
		if(compute(b, n) == s){
			cout << b << endl;
			return 0;
		} 
		b++;
	}
	// そうじゃないときは|n-s|の最大公約数で|n-s|をわったものにプラス１がB
	ll ab = abs(n-s);
	ll sq = sqrt(ab);

	bool flag = false;
	b = 1000000000005;
	for (ll p = 1; p < sqrt(n); ++p)
	{
		if(ab % p == 0 ){
			// ll q = ab / p;
			if(ab/p + 1 >= sqrt(n) ) {
				if(compute(ab/p+1, n) == s){
					b = min(ab/p + 1, b);
			        flag = true;
				}
			}
			// if(ab/q + 1 >= n){
			// 	if(compute(ab/q+1, n) == s){
			// 		b = min(ab/q + 1, b);
			//         flag = true;
			// 	}
			// }
			// cout << b << endl;

		}
	}
	if(flag){
		cout << b << endl;
		return 0;
	}

	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
 
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
 
struct S002 {
  int n;
  S002& operator > (long& x) {
    n = x;
    return *this;
  }
  S002& operator > (long&& x) {
    n = x;
    return *this;
  }
  S002& operator >= (long& x) {
    if( scanf("%ld", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (double& x) {
    if( scanf("%lf", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (std::string& s) {
    if( not (std::cin >> s) ) exit(0);
    return *this;
  }
  template<typename a>
  S002& operator >= (std::vector<a>& v) {
    v.resize(n);
    for(long i = 0; i < n; ++i) {
      *this >= v[i];
    }
    return *this;
  }
  template<typename a, std::size_t s>
  S002& operator >= (std::array<a, s>& x) {
    for(long i = 0; i < (long)s; ++i) {
      *this >= x[i];
    }
    return *this;
  }
};

struct Solver {
  std::string ss;
  Solver() {
    S002 reader;
    reader >= ss;
  }
  void solve() {
    long res = (long)ss.size();
    std::stack<char> s;
    for(char c : ss) {
      if( c == 'S' ) {
        s.push('S');
      }
      if( c == 'T' ) {
        if( s.empty() ) continue;
        s.pop();
        res -= 2;
      }
    }
    printf("%ld\n", res);
  }
};
 
int main() {
  loop std::unique_ptr<Solver>(new Solver())->solve();
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) find(Range(c), x) != c.end()
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, x) T x; cin >> x
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cout(x) cout << (x) << "\n"
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"

using namespace std;
using ll = long long;

int main(void){
    Cinss(int, 3, 3, a);
    
    For(i, 101) For(j, 101) For(k, 101){
        if( (a[0][0] - i == a[0][1] - j && a[0][1] - j == a[0][2] - k) &&
            (a[1][0] - i == a[1][1] - j && a[1][1] - j == a[1][2] - k) &&
            (a[2][0] - i == a[2][1] - j && a[2][1] - j == a[2][2] - k)){
                Cout("Yes");
                return 0;
            }
    }
    Cout("No");
}


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> l(m);
    vector<int> r(m);
    for(int i = 0; i < m; i++){
        cin >> l.at(i) >> r.at(i);
    }
    sort(l.begin(), l.end());
    reverse(l.begin(), l.end());
    sort(r.begin(), r.end());
    if(r.at(0) >= l.at(0)){
    cout << r.at(0) - l.at(0) + 1 << endl;
    } else {
        cout << 0 << endl;
    }
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int INF = (int) 1e9 + 1e6;
const ll LINF = (ll) 1e18 + 1e9;
const ld EPS = (ld) 1e-7;
const ll MOD = (ll) 998244353;

#define sz(x) (int) (x).size()
#define mp(x, y) make_pair(x, y)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lb(s, t, x) (int) (lower_bound(s, t, x) - s)
#define ub(s, t, x) (int) (upper_bound(s, t, x) - s)
#define rep(i, f, t) for (auto i = f; i < t; ++(i))
#define per(i, f, t) for (auto i = (f); i >= (t); --(i))

ll power(ll x, ll y, ll mod = MOD) {
    if (y == 0) {
        return 1;
    }
    if (y & 1) {
        return power(x, y - 1, mod) * x % mod;
    } else {
        ll tmp = power(x, y / 2, mod);
        return tmp * tmp % mod;
    }
}

template<typename A, typename B> bool mini(A &x, const B &y) {
    if (y < x) {
        x = y;
        return true;
    }
    return false;
}

template<typename A, typename B> bool maxi(A &x, const B &y) {
    if (y > x) {
        x = y;
        return true;
    }
    return false;
}

void add(ll &x, ll y) {
    x += y;
    if (x >= MOD) x -= MOD;
    if (x < 0) x += MOD;
}

void run();

#define TASK ""

int main() {
#ifdef LOCAL
    if (strlen(TASK) > 0) {
        cerr << "Reminder: you are using file i/o, filename: " TASK "!" << endl << endl;
    }
#endif
#ifndef LOCAL
    if (strlen(TASK)) {
        freopen(TASK ".in", "r", stdin);
        freopen(TASK ".out", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#endif
    cout << fixed << setprecision(12);
    run();
    return 0;
}

// == SOLUTION == //

const int N = 105;

int n;
int a[N], b[N], c[N], d[N];
vector<int> g[N];
int match[N];
bool used[N];

bool dfs(int v) {
    if (used[v]) return 0;
    used[v] = 1;
    for (int u : g[v]) {
        if (match[u] == -1 || dfs(match[u])) {
            match[u] = v;
            return 1;
        }
    }
    return 0;
}

void run() {
    cin >> n;
    rep(i, 0, n) {
        cin >> a[i] >> b[i];
    }
    rep(i, 0, n) {
        cin >> c[i] >> d[i];
    }
    rep(i, 0, n) {
        rep(j, 0, n) {
            if (a[i] < c[j] && b[i] < d[j]) {
                g[i].pb(j);
            }
        }
    }
    fill(match, match + N, -1);
    int ans = 0;
    rep(i, 0, n) {
        memset(used, 0, sizeof used);
        if (dfs(i)) {
            ans++;
        }
    }
    cout << ans << "\n";
}


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

public class Main {
	static FastReader in = new FastReader();

	public static void main(String[] args) {
		solve();
	}

	
	static int n, k;
	static int[] arr;
	
	static void solve() {
		n = in.nextInt();
		k = in.nextInt();
		arr = new int[n];
		for(int i = 0; i < n; i++) arr[i] = in.nextInt();
		
		int min = 1, max = (int) 1e9 + 100;
		
		while(min != max)
		{
			int mid = (min + max) / 2;
			if(possible(mid, arr, k)) max = mid;
			else min = mid + 1;
		}
		
		System.out.println(min);
		
	}
	
	static boolean possible(int ans, int[] a, int k)
	{
		for(int i : a) k -= (i + ans - 1) / ans - 1;
		return k >= 0;
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}





Measured memory_bytes: 55300
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n; cin >> n;
  ll a[5]; rep(i, 5) cin >> a[i];
  ll mn = longinf;
  int mni = 0;
  rep(i, 5) if(a[i] <= mn) {
    mn = a[i];
    mni = i;
  }
  cout << 4+(n+a[mni]-1)/a[mni] << "\n";
  return 0;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

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

   int l, r, d;
   cin >> l >> r >> d;
   int ans = r / d - (l - 1) / d;
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 3648
// unolight {{{
#include <bits/stdc++.h>
#include <unistd.h>
#define SZ(x) ((int)(x).size())
#define ALL(c) begin(c),end(c)
#define REP(i,n) for ( int i=0; i<(int)(n); i++ )
#define REP1(i,a,b) for ( int i=(int)(a); i<=(int)(b); i++ )
#define FOR(it,c) for ( auto it=(c).begin(); it!=(c).end(); it++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long LL;

void RI() {}

template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}

template<typename T>
void _dump( const char* s, T&& head ) { cerr<<s<<"="<<head<<endl; }

template<typename T, typename... Args>
void _dump( const char* s, T&& head, Args&&... tail ) {
    int c=0;
    while ( *s!=',' || c!=0 ) {
        if ( *s=='(' || *s=='[' || *s=='{' ) c++;
        if ( *s==')' || *s==']' || *s=='}' ) c--;
        cerr<<*s++;
    }
    cerr<<"="<<head<<", ";
    _dump(s+1,tail...);
}

#define dump(...) _dump(#__VA_ARGS__, __VA_ARGS__);

template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.first<<","<<p.second<<")"; }

template<typename Iter>
ostream& _out( ostream &s, Iter b, Iter e ) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
template<typename A, typename B>
ostream& operator <<( ostream &s, const map<A,B> &c ) { return _out(s,ALL(c)); }
// }}}

const int MAX_N = 100005;
int n, x, y;
vector<int> adj[MAX_N];
int dist1[MAX_N], dist2[MAX_N]; // takahashi, aoki

void input() {
    RI(n, x, y);
    x--; y--;
    REP(i, n-1) {
        int a, b;
        RI(a,b);
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
}

void dfs(int u, int e, int d, int dist[MAX_N]) {
    dist[u] = d;
    for(int v:adj[u]) {
        if(v == e) continue;
        dfs(v, u, d+1, dist);
    }
}

void solve() {
    dfs(x, -1, 0, dist1);
    dfs(y, -1, 0, dist2);
    int ans = 0;
    REP(i, n) {
        // cout << i << ' ' << dist1[i] << ' ' << dist2[i] << endl;
        if(dist1[i] < dist2[i]) {
            ans = max(ans, dist2[i]);
        }
    }
    printf("%d\n", ans-1);
}

int main( int argc, char *argv[] ) {
    input();
    solve();
    return 0;
}

Measured memory_bytes: 11648
using System;
using System.Collections.Generic;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("H H");
            //H
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("D H");
            //D
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("D D");
            //H
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        string[] wkArr = InputList[0].Split(' ');

        string a = wkArr[0];
        string b = wkArr[1];

        if (a == "D" && b == "D") Console.WriteLine("H");
        if (a == "D" && b == "H") Console.WriteLine("D");
        if (a == "H" && b == "D") Console.WriteLine("D");
        if (a == "H" && b == "H") Console.WriteLine("H");
    }
}


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

int main() {
  int N;
  cin >> N;
  int sum = 0;
  
  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    sum += (r - l) + 1;
  }
  
  cout << sum << endl;
}

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

d = set()
for aa in a[0], a[1]:
    for i in range(1, int(aa ** 0.5) + 1):
        if aa % i == 0:
            d.add(i)
            d.add(aa // i)  # i == aa//iのときは重複する
# aの2要素の約数全列挙

# print(d)

g = 1
for dd in d:
    cnt = 0
    for aa in a:
        if aa % dd == 0:
            cnt += 1
    if cnt >= N - 1:
        # N-1個以上の要素を割るなら、求める最大公約数足り得る
        g = max(g, dd)
print(g)


# def is_p(x):
#     if x <= 1: return False
#     for i in range(2, int(x ** 1 / 2) + 1):
#         if x % i == 0:
#             return False
#     else:
#         return True
#
#
# b = (i for i in range(100) if is_p(i))
# t = 1
# for i, bb in enumerate(b, 1):
#     t *= bb
#     t, i
#     if t > 10 ** 9:
#         bb
#         break
# (2, 1)
# (6, 2)
# (30, 3)
# (210, 4)
# (2310, 5)
# (30030, 6)
# (510510, 7)
# (9699690, 8)
# (223092870, 9)
# (6469693230, 10)
# 29
# 小さい方から9個の素数の積で、10**9以内の最大数となる

# 数列で最小の値が素数9個の積で、
# 次に小さい値も重複しない素数9個の積の場合でも、
# 全約数は、
# 2 * 2 ** 9個なので、
# 10**5個の要素に対する全探索が間に合う

Measured memory_bytes: 14076
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define repds(i, n) for (int i = (n); i > 0; --i)
#define loop(i, x, n) for (int i = (x); i < (n); ++i)
#define loops(i, x, n) for (int i = (x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (x); i > (n); --i)
#define loopds(i, x, n) for (int i = (x); i >= (n); --i)
#define itrep(i, a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i, a) for (auto i = rbegin(a); i != rend(a); ++i)
#define each(i, x) for (auto &&i : x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(a) ((int)a.size())
#define pow2(n) (n * n)
#define int ll
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
using p_queue = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-8;
ll mod = static_cast<ll>(1e9 + 7);
template <class T, class... Args>
constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); }
template <class T, class... Args>
constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); }
template <class F>
class FixPoint : private F {
public:
    explicit constexpr FixPoint(F &&f) : F(std::forward<F>(f)) {}
    template <class... Args>
    constexpr decltype(auto) operator()(Args &&... args) const { return F::operator()(*this, std::forward<Args>(args)...); }
};
template <class F>
constexpr decltype(auto) funcs(F &&f) { return FixPoint<F>{std::forward<F>(f)}; }
template <class T>
std::vector<T> vecs(int n, T &&val) { return std::vector<T>(std::forward<int>(n), std::forward<T>(val)); }
template <class... Args>
decltype(auto) vecs(int n, Args &&... args) { return std::vector<decltype(vecs(std::forward<Args>(args)...))>(std::forward<int>(n), vecs(std::forward<Args>(args)...)); }
template <class V, class T>
void fill(V &x, const T &val) { x = val; }
template <class V, class T>
void fill(vector<V> &vec, const T &val) {
    for (auto &&v : vec)
        fill(v, val);
}

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    int cnt = 0, res = 1000;
    rep(i, n - 1) {
        if (a[i] < a[i + 1]) {
            cnt += res / a[i];
            res %= a[i];
        }
        if (a[i] > a[i + 1]) {
            res += a[i] * cnt;
            cnt = 0;
        }
    }
    cout << res + a[n - 1] * cnt << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3656
#include <stdio.h>
 
int main(int argc, char *argv[])
{
    char line[256];
    int a, b;
 
    if (!fgets(line, sizeof(line), stdin)) {
        fprintf(stderr, "error input val\n");
        return -1;
    }
 
    if (sscanf(line, "%d %d", &a, &b) != 2) {
        fprintf(stderr, "error input format\n");
        return -1;
    }
 
    printf("%d %d %f", a/b, a%b, (double)a/(double)b);
 
    return 0;
}

Measured memory_bytes: 644
///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 h,w,d,q;
int a[303][303];
vector<vector<int> >dp;
int vx[90012];
int vy[90012];
 main()

{
    fast
    cin>>h>>w>>d;
    dp.resize(d+1);
    f(i,1,h)
    {
        f(j,1,w)
        {
            cin>>a[i][j];
            vx[a[i][j]]=i;
            vy[a[i][j]]=j;
        }
    }
    for(int i=1;i<=d;i++)
    {
        int sum=0;
        dp[i].pb(sum);
        for(int j=i+d;j<=h*w;j=j+d)
        {
            int cx=vx[j];
            int cy=vy[j];
            int px=vx[j-d];
            int py=vy[j-d];
            int cost=abs(px-cx)+abs(py-cy);
            sum+=cost;
            dp[i].pb(sum);
        }
    }
    int q;
    cin>>q;
    while(q--)
    {
        int lft,rgt;
        cin>>lft>>rgt;
        if(lft==rgt)
        {
            cout<<"0"<<endl;
            continue;
        }
        int id=lft%d;
        if(id==0)id=d;
        int dan,bam;
        bam=(lft-1)/d;
        dan=(rgt-1)/d;
        int ses=dp[id][dan];
        ses-=dp[id][bam];
        cout<<ses<<endl;
    }
    return 0;
}


Measured memory_bytes: 7552
#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace std;
#define endl '\n'
#define FAST ios::sync_with_stdio(0);cin.tie(0);
#define _ <<' '<<
using ll = long long int;


signed main(){
	FAST
	ll A,B,K;
	cin >> A >> B >> K;
	ll tmp = 0;
	if(K>=A){
		tmp = K-A;
		A = 0;
	}else A-=K;

	B-=tmp;
	if(B<0) B = 0;
	cout << A _ B<< endl;
}

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

using namespace std;

int main() {
    int n;
    string s;

    cin >> n >> s;

    char ch = 'A';
    int cnt = 0;

    for(int i=0; i<s.length(); i++) {
        if (ch != s.at(i)) {
            cnt++;
        }
        ch = s.at(i);
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(s) cout << s << endl;
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
   string s; cin>>s;
   s[3] = '8';
   cout << s << endl;
}


Measured memory_bytes: 256
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)                  cerr<<#x<<": "<<x<<endl
#define trace2(x, y)              cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)              cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)          cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)     cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll a,b,c;
    cin >> a >> b >> c;
    if(b-a == c-b) cout << "YES";
    else cout << "NO";
    return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */

Measured memory_bytes: 256
using System;

class Class01
{
    public static void Main(string[] args)
    {
        double debt = 100000;
        int n = int.Parse(Console.ReadLine());

        for (int i = 0; i < n; i++)
        {
            debt = Math.Ceiling(debt * 1.05 / 1000) * 1000;
        }
        Console.WriteLine(debt);
    }

}

Measured memory_bytes: 9208
var
	n,m,i:Longint;
	ans,o:int64;
begin
	read(n,m);
	ans:=1;
	o:=1000000007;
	for i:=1 to n do ans:=ans*i mod o;
	for i:=1 to m do ans:=ans*i mod o;
	if n=m then ans:=ans*2 mod o else if(m<n-1)or(n+1<m)then ans:=0;
	write(ans);
end.


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

int n;
vector<string> w;
template <class T>
void readVector(int n, vector<T> &v){
    for(int i=0; i<n; ++i){
        T t;
        cin >> t;
        v.push_back(t);
    }
}
bool f = true;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n;
	readVector(n, w);
	for(int i=1; i<n; ++i)
		if(w[i-1][w[i-1].size()-1] != w[i][0])
			f = false;
	sort(w.begin(), w.end());
	for(int i=1; i<n; ++i)
		if(w[i] == w[i-1])
			f = false;
	if(f) cout << "Yes\n";
	else cout << "No\n";
}

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

int main() {
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    if(A+B>C+D)cout << "Left" << endl;
    else if(A+B<C+D)
    {
        cout << "Right" << endl;
    }
    else cout <<"Balanced"<< endl;
    
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.TreeMap;
import java.util.StringTokenizer;
import java.util.Map;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            long[] a = in.nextLongArray(n);

            Map<Long, Integer> map = new TreeMap<>();
            map.put(0L, 1);
            long sum = 0;
            for (int i = 0; i < n; i++) {
                sum += a[i];
                map.merge(sum, 1, Integer::sum);
            }

            long ans = 0;
            for (long x : map.values()) {
                ans += x * (x - 1) / 2;
            }

            out.println(ans);
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public long nextLong() {
            return Long.parseLong(nextString());
        }

        public long[] nextLongArray(int n) {
            long[] res = new long[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextLong();
            }
            return res;
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

using ll = long long;

vector<int> t[100000];
pair<int, int> e[100000];
map<pair<int, int>, int> color;
int maxc = 0;

void dfs(int u, int v, int c) {
    if (c > 0) {
        maxc = max(maxc, c);
        color[make_pair(min(u, v), max(u, v))] = c;
    }
    int cc = 1;
    for (auto w : t[u]) {
        if (w == v)
            continue;
        if (cc == c)
            cc++;
        dfs(w, u, cc++);
    }
}

int main() {
    int n, a, b;
    cin >> n;
    for (int i = 0; i < n - 1; ++i) {
        cin >> a >> b;
        a--; b--;
        e[i] = make_pair(min(a, b), max(a, b));
        t[a].push_back(b);
        t[b].push_back(a);
    }
    dfs(0, 0, 0);
    cout << maxc << endl;
    for (int i = 0; i < n - 1; ++i) {
        cout << color[e[i]] << endl;
    }

    return 0;
}

Measured memory_bytes: 14976
N = int(input())
c = list(input())
count = 0
i = 0
j = N-1
while i < j:
    while c[i] == "R" and i <= N-2:
        i += 1
    while c[j] == "W" and j >= 1:
        j -= 1
    if i < j:
        count += 1
    i += 1
    j -= 1
    if i >= j or i >= N or j <= 0:
        break
print(count)

Measured memory_bytes: 77200
n,m = map(int,input().split())
xyz = [list(map(int,input().split()))for i in range(n)]
ans = 0
for i in range(2**3):
    res = []
    for j in range(n):
        sm = sum(xyz[j])
        for k in range(3):
            if (i>>k)%2:sm -= 2*xyz[j][k]
          
        res.append((sm,j))
    res.sort(reverse = True)
    point = 0

    for j in range(m):
        point += res[j][0]
        
    ans = max(ans,point)
print(ans)
        
        
        
        
        
        
    

Measured memory_bytes: 3316
import java.util.*;
import java.util.stream.*;
class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int N;
        N = input.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++){
            A[i] = input.nextInt();
        }
        int count;
        count = bubbleSort(A,N);
        for (int i = 0; i < N; i++){
            if (i == N-1){
                System.out.println(A[i]);
            } else {
                System.out.printf("%d ",A[i]);
            }
        }
        System.out.println(count);
    }
    public static int bubbleSort(int[] A, int N){
        boolean flag = true;
        int tmp,count;
        count = 0;
        while (flag){
            flag = false;
            for (int i = N-1; i > 0; i--){
                if (A[i] < A[i-1]){
                    tmp = A[i];
                    A[i] = A[i-1];
                    A[i-1] = tmp;
                    flag = true;
                    count += 1;
                }
            }
        }
        return count;
    }
}


Measured memory_bytes: 26560
#pragma GCC optimze("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define md 998244353
#define trace(...)
#define ll long long int
#define ld long double
#define fi first
#define se second
#define fr(i,a,b) for(ll i=a;i<=b;i++)
#define frr(i,b,a) for(ll i=b;i>=a;i--)
#define mem(a) memset(a, 0, sizeof(a))
#define vpi std::vector<pair<int,int>>
#define pii pair<int,int>
#define pb push_back
#define sall(v) sort(v.begin(),v.end())
#define all(v) (v.begin(),v.end())
#define minf -10000000
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
    uniform_int_distribution<int> uid(0,lim-1);
    return uid(rang);
}
ll power(ll x, ll y,ll p) { 
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or equal to p 
    while (y > 0) {  
        if (y & 1) // If y is odd, multiply x with result
            res = (res*x) % p;  
        y = y>>1; // y = y/2 // y must be even now
        x = (x*x) % p;   
    } 
    return res; 
}
ll power(ll x, ll y) { 
    ll res = 1;      // Initialize result 
    while (y > 0) {    
        if (y & 1)// If y is odd, multiply x with result 
            res = (res*x) ;  
        y = y>>1; // y = y/2 // y must be even now 
        x = (x*x);   
    } 
    return res; 
}
 
ll max3(ll a,ll b,ll c){
    return max(a,max(b,c));
}
ll min3(ll a,ll b,ll c){
    return min(a,min(b,c));
}
bool isPrime(ll n) { // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
}

void solve() {
    int n,k;cin>>n>>k;
    int arr[n];fr(i,0,n-1)cin>>arr[i];
    int dp[n];fr(i,0,n-1)dp[i]=1e9;
    dp[0]=0;
    fr(i,1,n-1){
        fr(j,max(i-k,0ll),i-1){
            dp[i]=min(dp[i],dp[j]+abs(arr[i]-arr[j]));
        }
    }
    cout<<dp[n-1]<<endl;
    return ;
}

int main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout<<fixed<<setprecision(8);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    int t;
    // cin>>t;
    t=1;
    while(t--){
        solve();
    }
    #ifndef ONLINE_JUDGE
    cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
    #endif
    return 0;
}


Measured memory_bytes: 4316