akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = 0;
		if(a >= b) {
			c = a;
		}else {
			c = b;
		}
		int k = 0;
		
		for(int i = 0; i < c; i++) {
			if(Math.abs(a - i) == Math.abs(b - i)){
				k = i;
			}
		}
		if(k == 0) {
			System.out.println("IMPOSSIBLE");
		}else {
			System.out.println(k);
		}
	}
}

Measured memory_bytes: 24020
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
int main(){
	int ans=0;char s;
	rep(i,3){
		cin>>s;
		ans+=(s=='0'?0:1);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,i,s=0,f[1000005];
int main(){
	cin>>n;
    f[n]=n;
    f[n-1]=n*n%1000000007;
    for(i=n-2;i>0;i--){
    s=(s+f[i+3])%1000000007;
    f[i]=f[i+1];
    f[i]=(f[i]+((n-1)*(n-1)%1000000007))%1000000007;
    f[i]=(f[i]+s)%1000000007;
    f[i]=(f[i]+i+1)%1000000007;
    }
    cout<<f[1]<<endl;
}

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

using namespace std;
using ll = long long;
using ld = long double;
using Vec = vector<int>;

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main() {
 
ll x,k,d;
bool a=true;
cin>>x>>k>>d;

ll lim=d*k;  //到達限界

if(lim/d!=k || lim/k!=d ||lim%k!=0 ||lim%d!=0){
   a=false;
}

if(lim<abs(x) && a==true){
    cout<<abs(x)-lim<<endl;
}
else{
  ll t=abs(x)/d;//t=>k 到達する場合　の回数
  ll far=abs(x)-t*d; //ｔ回あとの距離
  ll amari=k-t; //残り試行回数
  int p=amari%2;

  
  if(p==0){
      cout<<far<<endl;
  }
  if(p==1){
      cout<<abs(d-far)<<endl;
  }


}

}

Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
using namespace std;
typedef long long ll;



int main() {
	ll n; cin >> n;
	if (n == 0) {
		cout << 0 << endl;
		return 0;
	}
	ll cur = 0, b = 2;
	string s;
	for (int i = 0; i < 32; i++) {
		if ((n%b + b)%b != (cur%b + b)%b) {
			s += '1';
			cur += (i & 1 ? -1 : 1)*(1 << i);
		}
		else if (cur != n) s += '0';
		b *= 2;
	}
	reverse(s.begin(), s.end());
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
vector<ll> v1[100005];
ll a[100005],vis[100005],t;
ll dfs(ll i)
{
    vis[i]=1;
    for(auto k:v1[i])
    {
        if(vis[k]==0) { t=dfs(k); a[i]=max(a[i],t+1); }
        else a[i]=max(a[i],a[k]+1);
    }
    return a[i];
}
int main()
{
    ll N,M,i,x,y,ans=0;
    cin>>N>>M;
    for(i=0;i<M;i++)
    { cin>>x>>y; v1[x].push_back(y);  }
    for(i=1;i<=N;i++)
    {  ans=max(ans,dfs(i));  }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 8576
#include <iostream>
#include <math.h>
#include <cstdio>

using namespace std;

int main() {
    while(1) {
        int n;
        cin >> n;
        if (n == 0) break;
        int S[n];
        for (int i = 0; i < n; i++) cin >> S[i];
        double m = 0;
        for (int i = 0; i < n; i++) m += S[i];
        m /= n;
        double a = 0;
        for (int i = 0; i < n; i++) a += (S[i] - m) * (S[i] - m);
        a /= n;
        a = sqrt(a);
        printf("%.5lf\n", a);
        // cout << a << endl; 
    }
    return 0;
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#define MAX_N 100001
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define FOR(i, a, b) for(ll i=a; i<b; i++)
#define REP(i, n) for(ll i=0; i<n; i++)
#define REV(i, n) for(ll i=n-1; i>=0; i--)
#define ALL(v) v.begin(), v.end()
#define pb push_back
const ll INF = 9e18;
ll n, m;

signed main(){
	cin >> n >> m;
	ll ret = 0;
	// FOR(i, 1, m/n + 1){
	for(ll i=1; i*i<=m; i++){
		if(m - i * (n - 1) > 0){
			if((m - i * (n - 1)) % i == 0) ret = max(ret, i);
		}
		if(m - (m/i) * (n - 1) > 0){
			if((m - (m/i) * (n - 1)) % (m/i) == 0) ret = max(ret, (m/i));
		}
	}
	cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;


public class Main {
	public static void main(String[] args) throws IOException{
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int sum = sc.nextInt();
			if(n == 0 && sum == 0){break;}
			
			int ret = 0;
			int s = 0;
			for(int i = 0; i < (1<<10);i++){
				s = 0;
				if(numofbits5(i) != n){
					continue;
				}
				for(int j =0;j < 10;j++){
					if(((1 << j) & i) != 0){s += j;}
				}
				if(sum == s){ret++;}
			}
			
			System.out.println(ret);
		}
	}
	
	static int numofbits5(int bits) {
		  bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
		  bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
		  bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
		  bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
		  return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
	}
}

Measured memory_bytes: 12000
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

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

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

fn main() {
    input! {
        n: usize,
        c: isize,
        sushi: [(isize, isize); n]
    };

    let mut fwd_max:Vec<isize> = vec![0;n+1];
    let mut fwd_v:Vec<isize> = vec![0;n+1];
    let mut fwd_va:isize = 0;
    for i in 0..n {
        fwd_va += sushi[i].1;
        let fwd_vi = fwd_va - sushi[i].0;
        fwd_v[i+1] = fwd_vi - sushi[i].0;
        fwd_max[i+1] = std::cmp::max(fwd_max[i], fwd_vi);
    }

    let mut rev_max:Vec<isize> = vec![0;n+1];
    let mut rev_v:Vec<isize> = vec![0;n+1];
    let mut rev_va:isize = 0;
    for i in 0..n {
        let ii = n-1-i;
        rev_va += sushi[ii].1;
        let rev_vi = rev_va - (c - sushi[ii].0);
        rev_v[i+1] = rev_vi - (c - sushi[ii].0);
        rev_max[i+1] = std::cmp::max(rev_max[i], rev_vi);
    }

    let fmax = (0..n+1).map(|i| {
        rev_v[i] + fwd_max[n-i]
    }).max().unwrap();
    let rmax = (0..n+1).map(|i| {
        fwd_v[i] + rev_max[n-i]
    }).max().unwrap();

    println!("{}", std::cmp::max(fmax,rmax));
}


Measured memory_bytes: 10492
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
using namespace std;
int main() {
  int n,m,a,b,ans=0;
  cin >> n >> m;
  priority_queue<int> que;
  vector<int> v[100005];
  for(int i=0; i<n; i++) {
    cin >> a >> b;
    v[a].push_back(b);
  }
  for(int i=1; i<=m; i++) {
    for(auto p:v[i]) {
      que.push(p);
    }
    if(que.size()) {
      ans+=que.top();
      que.pop();
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }
    vector<ll> rui(n + 1, 0);
    unordered_map<ll, ll> mp;
    mp[0]++;
    for(int i = 0; i < n; i++) {
        rui[i + 1] = rui[i] + a[i];
        if(i < k - 1) {
            mp[rui[i + 1] % k]++;
        }
    }
    ll ans = 0;
    for(auto e : mp) {
        ans += e.second * (e.second - 1) / 2;
    }
    for(int m = k - 1; m < n; m++) {
        mp[rui[m - k + 1] % k]--;
        ans += mp[rui[m + 1] % k];
        mp[rui[m + 1] % k]++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 11592
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b;
  string s;
  bool flag = true;
  cin >> a >> b >> s;
  if(s.size() != a + b + 1) flag = false;
  REP(i,a) if(!isdigit(s[i])) flag = false;
  if(s[a] != '-') flag = false;
  FOR(j,a+1,s.size()) if(!isdigit(s[j])) flag = false;
  YesorNo(flag);
  return 0;
}
//templete by private_yusuke

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

using namespace std;

const int N = 1000007;

int a[N];

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

    int n, m; cin >> n >> m;

    int tot = 0;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        tot += a[i];
    }

    int ans = 0;
    for(int i = 0; i < n; ++i) {
        if(a[i] >= tot/(4.0 * m)) ans++;
    }
    cout << (ans >= m? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		Stack<Integer> A=new Stack<>(),B=new Stack<>();
		
		int n=in.nextInt();
		for(int i=0;i<n;i++) {
			A.clear(); B.clear();
			int C[]=new int[10];
			for(int j=0;j<10;j++)C[j]=Integer.parseInt(in.next());
			A.push(C[0]);
			
			int j=1;
			for(;j<10;j++) {
				if(C[j]<A.peek()) {
					if(B.isEmpty() || C[j]>B.peek())B.push(C[j]);
					else{
						System.out.println("NO");
						break;
					}
				}
				else {
					if(B.isEmpty() || C[j]-A.peek()<=C[j]-B.peek() || C[j]<B.peek())A.push(C[j]);
					else B.push(C[j]);
				}
			}
			
			if(j==10)System.out.println("YES");
			
//			System.out.println(A);
//			System.out.println(B);
		}
	}

}



Measured memory_bytes: 26004
#084_B
a,b=map(int,input().split())
s=input()
flg=True
for i in range(a+b+1):
    if i==a:
        if s[i]!='-':
            flg=False
    else:
        if s[i] not in '0123456789':
            flg=False

print('Yes' if flg else 'No')

Measured memory_bytes: 3060
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define MAX 300000
typedef long long ll;
typedef pair<ll,int> P;

int N,M,s[10][10],k[10],p[10],pass[10],ans=0;

bool check(){
  int x;
  for(int i=0;i<M;i++){
    for(int j=0;j<k[i];j++){
      if(pass[s[i][j]]) x++;
    }
    if(x%2!=p[i]) return false;
    x=0;
  }
  return true;
}

void makepass(int x){
  if(x==N){
    if(check()) ans++;
  }
  else{
    pass[x]=1;
    makepass(x+1);
    pass[x]=0;
    makepass(x+1);
  }
}

int main(){
  cin>>N>>M;
  for(int i=0;i<M;i++){
    cin>>k[i];
    for(int j=0;j<k[i];j++){
      cin>>s[i][j];
      s[i][j]--;
    }
  }
  for(int i=0;i<M;i++) cin>>p[i];
  makepass(0);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 N, K;
  std::cin >> N >> K;
  std::cout << N - K + 1 << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
#include <ctype.h> // isdigit
#include <cassert>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(u) begin(u),end(u)
#define PB push_back
#define LE(n,m) ((n) < (m) + EPS * (abs(n) + abs(m)))
#define GE(n,m) ((n) + EPS * (abs(n) + abs(m)) > (m))
#define LT(n,m) ((n) + EPS * (abs(n) + abs(m)) < (m))
#define GT(n,m) ((n) > (m) + EPS * (abs(n) + abs(m)))
#define EQ(n,m) (abs((n)-(m)) < EPS * (abs(n) + abs(m)))

typedef long long int ll;
const int INF = (1<<30) - 1;
const double EPS = 1e-9;
const int MOD = 1000000007;

//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.precision(16);
    //cout.setf(ios::fixed);
    
    int N; cin >> N;
    
    vector<int> inputs(N);
    for(auto &v: inputs)
        cin >> v;
    
    vector<int> exists(10000, false);
    for(int l=1; l<=4; l++){
        for(int i=0; i<N+1-l; i++){
            int v = 0;
            for(int j=0; j<l; j++)
                v = v*10 + inputs[i+j];
            exists[v] = true;
        }
    }
    
    for(int i=0; i<10000; i++){
        if(!exists[i]){
            cout << i << endl;
            return 0;
        }
    }
    
    return 0;
}

Measured memory_bytes: 3232
require 'bigdecimal'

gets.to_i.times{
	x1, y1, x2, y2, x3, y3, x4, y4 = gets.split.map{ |s| BigDecimal(s) }

	if (y2 - y1)/(x2 - x1) == (y4 - y3)/(x4 - x3) then
		puts "YES"
	else
		puts "NO"
	end
}

Measured memory_bytes: 6280
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.IntStream;

public class Main {

	private static final int MAX_BINARY = 0xFFFF_FFFF;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			// パスの一覧
			@SuppressWarnings("unchecked")
			Set<Integer>[] paths = new Set[n];
			IntStream.range(0, n).forEach(i -> paths[i] = new HashSet<>());
			IntStream.range(0, m).forEach(i -> {
				int a = scanner.nextInt() - 1;
				int b = scanner.nextInt() - 1;
				paths[a].add(b);
				paths[b].add(a);
			});
			System.out.println(getResult(0, paths, (MAX_BINARY << n) ^ MAX_BINARY, new HashMap<>()));
		}
	}

	/**
	 * @param startNode アクセス始点
	 * @param paths
	 * @param status    グラフのアクセス済ステータス（nビット目が1＝まだアクセスしていない）
	 * @param map
	 * @return アクセスのパスの数
	 */
	private static int getResult(int startNode, Set<Integer>[] paths, int status, Map<List<Integer>, Integer> map) {
		// 現在のノードが最後のノードの場合
		if (0 == (status & (~(1 << startNode)))) {
			return 1;
		}
		List<Integer> key = Arrays.asList(startNode, status);
		Integer result = map.get(key);
		if (null == result) {
			result = 0;
			// 現在のノードをアクセス済にする
			status &= ~(1 << startNode);
			for (Integer nextNode : paths[startNode]) {
				if ((status & (1 << nextNode)) > 0) {
					result += getResult(nextNode, paths, status, map);
				}
			}
			map.put(key, result);
		}
		return result;
	}
}


Measured memory_bytes: 28244
n=int(input())
ans=0
l=[list(map(int,input().split())) for i in range(3)]
for i in range(1,n+1):
    ans+=l[1][l[0][i-1]-1]
    if i!=n and l[0][i]==l[0][i-1]+1:
        ans+=l[2][l[0][i-1]-1]
print(ans)

Measured memory_bytes: 9108
import math


def solve(a: int, b: int, x: int) -> float:
  if 2*x <= a**2 * b:
    return math.degrees(math.atan(a * b**2 / (2*x)))
  else:
    return math.degrees(math.atan( (2*b - 2*x/a**2) / a))


a, b, x = [int(c) for c in input().split()]
solve(a, b, x)

print(solve(a, b, x))


Measured memory_bytes: 3188
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7; //924844033 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, p, q, last, first, cnt, sum, ans, dp[40000],a[200000],b[200000];
string str, ss;
bool f;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Edge { LL to, cost; };
struct edge { LL from, to, cost; };
vector<LL>vec;
vector<edge>ed;
vector<Pll>v;
map<LL,LL>ma;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main() {
	cin >> n >> m;
	h = m;
	for (int i = 2; i <= sqrt(h); i++) {
		cnt = 0;
		while (m%i==0) {
			m /= i;
			cnt++;
		}
		v.push_back(Pll(i, cnt));
	}
	v.push_back(Pll(m, 1));
	ans = 1;
	rep(i, v.size()) {
		while (v[i].sec >= n) {
			ans *= v[i].first;
			v[i].sec -= n;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 18792
n = int(input())
a = list(map(int, input().split()))
ans = 'Yes'
for i in range(n-1, 1, -1):
    if a[i] < a[i-1]:
        a[i-1] -= 1
        if a[i] < a[i-1]:
            ans = 'No'
            break
print(ans)



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

int main(){
    int H, N; cin >> H >> N;
    for(int i=0; i<N; i++){
        int A; cin >> A;
        H -= A;
    }
    if(H>0) cout << "No" << endl;
    else cout << "Yes" << endl;
}


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


int H, N;
vector<int> A;


void input() {
    cin >> H >> N;
    A = vector<int>(N);
    rep(i, N) cin >> A[i];
}


int main() {
    input();
    ll s = 0;
    rep(i, N) s += A[i];
    if (s < H) cout << "No" << endl;
    else cout << "Yes" << endl;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
class Test
{
    public static void Main()
    {

        var n = int.Parse(Console.ReadLine());

        var arr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();

        int max = 0;
        int count = 0;
        for(int i=1;i<n;i++)
        {
            if(arr[i]<=arr[i-1])
            {
                count++;
            }
            else
            {
                max = Math.Max(count, max);
                count = 0;
            }
        }
        if (max < count)
            max = count;
        Console.Write(max);
    }
}



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

using ll = long long;
using namespace std;
constexpr ll inf = 1e15;
constexpr ll mod = 1e9+7;

ll dp[2][2001] = {0};
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int N, Z, W;
    cin>>N>>Z>>W;
    vector<int> A(N);
    for (int n = 0; n < N; n++) cin>>A[n];

    for (int i = 0; i < 2; i++)
        for (int k = 0; k <= 2000; k++)
            dp[i][k] = inf;

    function<ll(bool, int, int)> game = [&](bool turn, int X, int Y) {
        if (X == N || Y == N) return dp[turn][max(X,Y)] = abs((X == 0 ? Z : A[X-1]) - (Y == 0 ? W : A[Y-1]));
        if (dp[turn][max(X,Y)] != inf) return dp[turn][max(X,Y)];

        ll ans;
        if (!turn) {
            ans = 0;
            for (int x = max(X,Y)+1; x <= N; x++) ans = max(ans, game(!turn, x, Y));
        } else {
            ans = inf;
            for (int y = max(X,Y)+1; y <= N; y++) ans = min(ans, game(!turn, X, y));
        }
        return dp[turn][max(X,Y)] = ans;
    };

    cout<<game(false, 0, 0)<<endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>

using lint = int64_t;
using std::vector;

int n, cnt, p1, d, d1;
lint sum;
int f[10000010], divisor[10000010];
bool is_prime[10000010], used[10000010];
vector<int>primes;
int main() {
	scanf("%lld", &n);
	f[1] = 1;
	for (int i = 2; i <= n; ++i) {
		if (!used[i]) {
			is_prime[i] = true;
			primes.push_back(i);
			for (int j = 2, end = n / i; j <= end; ++j) {
				int k = i * j;
				used[k] = true;
				is_prime[k] = false;
				divisor[k] = i;
			}
		}
	}
	for (int i = 2; i <= n; ++i) {
		if (is_prime[i]) f[i] = 2;
		else {
			p1 = divisor[i];
			d = i / p1;
			if (p1 == d) {
				f[i] = f[d] + 1;
			}
			else {
				cnt = 0, d1 = d;
				while (d1 % p1 == 0) {
					cnt++;
					d1 /= p1;
				}
				f[i] = f[d] / (cnt + 1) * (cnt + 2);
			}
		}
		sum += (lint)i * f[i];
	}
	printf("%lld\n", sum + 1);
}

Measured memory_bytes: 103784
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstdlib>
#include <cmath>
#include<stdio.h>
#include<queue>
#include<stack>
#include<set>
#define int long long
#define MAX 1000000000000000000LL
int inf=100000000000007;
using namespace std;
typedef pair<int,int> P;
string alph="abcdefghijklmnopqrstuvwxyz";
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main(){
    int n;cin>>n;
    int key[100005]={};
    int a;
    for(int i=0; i<n; i++){
        cin>>a;
        key[a]++;
        key[a+1]++;
        key[a-1]++;
    }
    int maxl=-1;
    for(int i=1; i<100000;i++){
        maxl=max(maxl,key[i]);
    }
    cout<<maxl<<endl;
}


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

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

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, 0, n) {
    cin >> a[i];
    a[i]--;
  }

  vector<int> idx(n);
  rep(i, 0, n) {
    idx[a[i]] = i;
  }
  set<int> s;
  ll ans = 0;
  for (int x = n - 1; x >= 0; --x) {
    int i = idx[x];
    ll c = 0;
    { // calc c
      s.insert(i);
      vector<int> l(2, -1);
      vector<int> r(2, n);
      { // calc l
        auto it = s.find(i);
        rep(j, 0, 2) {
          if (it == s.begin()) break;
          --it;
          l[j] = *it;
        }
      }

      { // calc r
        auto it = s.find(i);
        rep(j, 0, 2) {
          ++it; // 先に++をする
          if (it == s.end()) break;
          r[j] = *it;
        }
      }

      vector<int> ls(2);
      ls[0] = i - l[0]; ls[1] = l[0] - l[1];

      vector<int> rs(2);
      rs[0] = r[0] - i; rs[1] = r[1] - r[0];
      c += (ll)ls[0]*rs[1] + (ll)ls[1]*rs[0];
    }

    ans += c*(x+1);
  }

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


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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    vector<int> cnt(26,0);
    for(int i = 0; i < s.size(); i++) {
        cnt[s[i]-'a']++;
    }
    if(s.size()==26) {
        int idx=25;
        while(idx>0 && s[idx-1]>s[idx]) idx--;
        if(idx==0) {
            cout << "-1" << "\n";
            return 0;
        }

        char e='z'+1;
        for(int i = idx; i < s.size(); i++) if(s[idx-1]<s[i]) e=min(e,s[i]);
        for(int i = 0; i < idx-1; i++) cout << s[i];
        cout << e << "\n";
    }
    else{
        cout << s;
        int idx=0;
        while(cnt[idx]!=0) idx++;
        cout << char('a'+idx) << "\n";
    }

    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}

using namespace std;
// now

struct UnionFind {
    vector<int> d;
    UnionFind(int n=0) : d(n,-1){}
    int Find (int x){//根の番号を探す
        if(d[x] < 0) return x;
        return d[x] = Find(d[x]);
    }
    bool unite (int x, int y){
        x = Find(x); y = Find(y);
        if(x == y ) return false;
        if(d[x] < d[y]){
            swap(x,y);
        }
        d[x] += d[y];
        d[y] = x;
        return true;
    } 

    bool same(int x, int y){
        return Find(x) == Find(y);
    }
    int size(int x) {
        return (-d[Find(x)]);
    }
};


ll nCr (ll n, ll r){
    ll ans = 1;
    for(ll i = n ; i > n-r ; i --){
        ans *= i;
    }
    for(ll i = 1 ; i<= r; i ++){
        ans /= i;
    }
    return ans ;
}

int nPr (int n,int r){
    int ans = 1;
    for(int i = n ; i > n-r ; i --){
        ans *= i;
    }
    return ans ;
}
int ke (int n){
    n--;
    if(n == 1 )return 0;
    int ans = 1;
    while (0 < n){
        ans *= n;
        n--;
    }
    return ans ;

}

void go(ll n , ll k){
    ll mi = INF;
    REP(i,3){
        mi = min(mi, abs(n-k));
        n = abs(n-k);
    }

    cout << mi <<endl;
    
    return  ;


}
int main(){
    int64_t n,k;
    cin  >> n >>k;

    int64_t su = n/k;
    
    if(n < k){
        int64_t mi = n;
    REP(i,3){
        mi = min(mi, abs(n-k));
        n = abs(n-k);
    }

    cout << mi <<endl;
    
    return 0 ;

    
    } else{
        n -= su*k;
        while(true){
            int64_t l = n;
            int64_t r = abs(l - k);
            if(l <= r){
                n = l;
                int64_t mi = n;
                REP(i,3){
                    mi = min(mi, abs(n-k));
                    n = abs(n-k);
                }
                cout << mi <<endl;
                return 0 ;
            }
            n = r;     
        }
    }

    return 0;
}





Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

int main() {
  ios::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<pair<char, char>> tds(q);
  FOR(td, tds) {
    string a, b;
    cin >> a >> b;
    td.first = a[0];
    td.second = b[0];
  }
  int l = -1;
  int r = n;
  while (l + 1 < r) {
    int m = (l + r) / 2;
    int x = m;
    FOR(td, tds) {
      char tx = s[x];
      char t = td.first;
      char d = td.second;
      if (tx == t) {
        if (d == 'L') {
          x--;
        } else {
          x++;
        }
      }
      if (x < 0 || x >= n) {
        break;
      }
    }
    if (x < 0) {
      l = m;
    } else {
      r = m;
    }
  }
  int ld = l;
  l = -1;
  r = n;
  while (l + 1 < r) {
    int m = (l + r) / 2;
    int x = m;
    FOR(td, tds) {
      char tx = s[x];
      char t = td.first;
      char d = td.second;
      if (tx == t) {
        if (d == 'L') {
          x--;
        } else {
          x++;
        }
      }
      if (x < 0 || x >= n) {
        break;
      }
    }
    if (x >= n) {
      r = m;
    } else {
      l = m;
    }
  }
  int rd = r;
  cout << rd - ld - 1 << endl;

  return 0;
}


Measured memory_bytes: 976
#include <iostream>

using namespace std;

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

	int topping_count = 0;
	for (int i = 0; i < S.length(); i++) {
		if (S.at(i) == 'o') {
			topping_count++;
		}
	}

	cout << 700 + 100 * topping_count << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <numeric>
#include <algorithm>
using namespace std;
int main(){
    while(true){
        int cnt=0;
        string s;
        cin>>s;
        if(s=="0"){
            return 0;
        }
        for(int i=0;i<s.size();++i){
            cnt+=s[i]-'0';
        }
        cout<<cnt<<endl;
    }
}



Measured memory_bytes: 3140
#include <bits/stdc++.h>
#define REP(i, x, n) for (int i  =  x; i < (int)(n); ++i)
#define REPR(i,  n) for (int i  =  n - 1; i >= 0; --i)
using namespace std;
#define int long long int
//------------ATCODER TEMPLATE-------------

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

  int ans = 0;
  REP(i, 1, N) {
    int An; cin >> An;
    if (A > An) {
      ans += A - An;
    } else {
      A = An;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
    int a,b,num;
    cin >> a >> b;
    rep(i,to_string(b).size())a *= 10;
    num = sqrt(a+b);
    //cout << a << b << endl;
    if(int(num*num) == a+b){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
using namespace std;

void swp(int &a,int &b){
	int tmp=a;
	a=b;
	b=tmp;
}

void quicksort(int a[],int lower,int upper){
	int bound=a[lower],l=lower,u=upper;
	do{
		while(a[l]<bound)l++;
		while(a[u]>bound)u--;
		if(l<=u){
			swp(a[l],a[u]);
			l++;
			u--;
		}
	}while(l<u);
	if(lower<u)quicksort(a,lower,u);
	if(l<upper)quicksort(a,l,upper);
}

int main(){
	int p[100000],num;
	cin>>num;
	for(int i=0;i<num;i++){
		cin>>p[i];
	}
	quicksort(p,0,num-1);
	cout<<p[num/2]-p[num/2-1]<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <utility>
#include <climits>
#include <iomanip>
using namespace std;
#define MAXSIZE 100005
#define MAXL 100
#define MOD_CONST 1000000007
typedef long long int lli;

int main(){
    int n, k;
    cin >> n >> k;
    const int max_num = (n - 1) * (n - 2) / 2;
    if(k > max_num){
        const int wa_num = -1;
        cout << wa_num << endl;
        return 0;
    }

    vector<int> row(n, 0);
    vector<vector<int>> mat(n, row);
    for(int i = 0; i < n; ++i){
        mat[i][i] = -1;
        if(i < n - 1){
            mat[i][n - 1] = 1;
            mat[n - 1][i] = 1;
        }
    }

    // cout << endl;
    // for(int i = 0; i < n; ++i){
    //     for(int j = 0; j < n; ++j){
    //         printf("%2d", mat[i][j]);
    //         cout << ((j == n - 1)? '\n' : ' ');
    //     }
    // }

    int pair_dist2_num = (n - 1) * (n - 2) / 2;
    int edge_num = n - 1;
    int write_row = 0, write_col = write_row + 1;
    while (pair_dist2_num > k){
        mat[write_row][write_col] = 1;
        mat[write_col][write_row] = 1;

        // cout << endl;
        // for(int i = 0; i < n; ++i){
        //     for(int j = 0; j < n; ++j){
        //         printf("%2d", mat[i][j]);
        //         cout << ((j == n - 1)? '\n' : ' ');
        //     }
        // }

        pair_dist2_num--;
        edge_num++;
        // cout << "pair_dist2_num = " << pair_dist2_num << endl;

        if(write_col == n - 2){
            write_row++;
            write_col = write_row + 1;
        }else{
            write_col++;
        }
    }

    cout << edge_num << endl;
    for(int i = 0; i < n - 1; ++i){
        for(int j = i + 1; j < n; ++j){
            if(mat[i][j] == 1){
                cout << (i + 1) << " " << (j + 1) << endl;
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 384
# For sys.std*, sys.argv etc...
import sys

# For cases when input tokens are spread unevenly over many lines.
# This provides methods for reading tokens of various types.
class BufferedTokenizer:
    pass

def read_ints():
    return [int(token) for token in input().split()]

def read_tokens():
    return input().split()

def main():
    print("Yes" if len(set(read_ints())) == 2 else "No")

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<stdio.h>

int main(){
	int arrey[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int K=0;

	//puts("番号を入力");
	scanf("%d",&K);

	if((K<=0)||(K>32)){
		goto END;
	}
	for(int i=0;i<32;i++){
		if(i==(K-1)){
			printf("%d",arrey[i]);
		}

	}

	END:
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define reps(i,n) for (int i=1;i<=(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rreps(i,n) for (int i=(n);i>0;i--)
#define all(v) (v).begin(),(v).end()
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>
template<class T> inline bool chmin(T &a, T b) {if (a>b) {a = b; return 1;} return 0;};
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a = b; return 1;} return 0;};
typedef long long int ll;
const long long INF = 1LL << 60;

void func1(int N, int K, int P[], ll C[]){
  bool checked[N] = {};
  vector<vector<ll>> group;
  rep(i,N){
    if (checked[i]) continue;

    int cur = i;
    vector<ll> tmp;
    while (!checked[cur]){
      checked[cur] = true;
      tmp.push_back(C[cur]);
      cur = P[cur];
    }
    group.push_back(tmp);
  }

  ll ans = -INF;
  for (auto vec : group){
    ll M = vec.size();
    ll acum[2*M+1]={};
    rep(i,2*M) acum[i+1] = acum[i] + vec[i%M];

    vector<ll> acum_max(M, -INF); // 連続するj(0<=j<=M-1)項の和の最大値
    rep(i,M) rep(j,M) chmax(acum_max[j], acum[i+j]-acum[i]);

    for (int r=0;r<M;r++){  // 始めのr項（余り）で最大化
      if (r>K) continue;
      ll q = (K-r)/M;
      if (r==0 && q==0) continue;

      if (acum[M]>0) chmax(ans, acum_max[r] + acum[M]*q);
      else if (r>0) chmax(ans, acum_max[r]);
    }

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

void func2(int N, int K, int P[], ll C[]){
  ll ans = -INF;
  
  rep(i,N){
    ll tmp = -INF, score = 0;
    int s = i;
    rep(j,K){
      s = P[s];
      score += C[s];
      chmax(tmp, score);
    }
    chmax(ans, tmp);
  }
  cout << ans << endl;
  return;
}

int main(){
  int N, K; cin >> N >> K;
  int P[N]; 
  rep(i,N) {
    int p; cin >> p;
    P[i] = p-1;
  }
  ll C[N]; rep(i,N) cin >> C[i];
  func1(N, K, P, C);
  // func2(N, K, P, C);
  

  // cout << fixed << setprecision(10);
  
  return 0;
}

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



int main(){
    ll N;
    cin >> N;
    vector<ll> a(N ,0);
    ll ans = 0;
    for(int i = 0; i < N ; i++){
        cin >> a[i];
        ans ^= a[i];
    }
    if(ans == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}


Measured memory_bytes: 1024
#include <iostream>

int main()
{
	int x, ans;
	for (int i = 0; i < 5; i++)
	{
		std::cin >> x;
		if (x == 0)
		{
			ans = i+1;
		}
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
#define INF 1 << 29

using namespace std;

int n, m, s, g1, g2;
int cost[101][101];

int main(){

  while(scanf("%d%d%d%d%d", &n, &m, &s, &g1, &g2) && n){
    s--;g1--;g2--;
    rep(i, n) rep(j, n) cost[i][j] = INF;
    rep(i, n) cost[i][i] = 0;
    int a, b, c;
    rep(i, m){
      scanf("%d%d%d", &a, &b, &c);
      a--;b--;
      cost[a][b] = c;
    }

    rep(i, n) rep(j, n) rep(k, n)
      cost[j][k] = min(cost[j][k], cost[j][i] + cost[i][k]);

    /*    rep(i, n){
      rep(j, n) printf("%d ", cost[i][j]);
      puts("");
      } */ 
 
    int res = INF;
    rep(i, n){
      res = min(res, cost[s][i] + cost[i][g1] + cost[i][g2]);
      //      printf("%d + %d + %d\n", cost[s][i], cost[i][g1], cost[i][g2]);
    }
    printf("%d\n", res);
  }
  return 0;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
#define getbit(n, i) (((n) & (1LL << (i))) != 0) 
#define setbit0(n, i) ((n) & (~(1LL << (i)))) 
#define setbit1(n, i) ((n) | (1LL << (i))) 
#define togglebit(n, i) ((n) ^ (1LL << (i))) 
#define lastone(n) ((n) & (-(n))) 
char gap = 32;
template<typename T> 
ostream& operator<<(ostream &os, const vector<T> &v) { 
    os << '{'; 
    for (const auto &x : v) os << gap << x;
        return os << '}'; 
}
template<typename A, typename B> 
ostream& operator<<(ostream &os, const pair<A, B> &p) {
        return os << '(' << p.first << gap << p.second << ')';
}

template <class T>
void read(T &x) {
    char c;
    for (c = getchar(); c < '0' || c > '9'; c = getchar())
        ;
    for (x = 0; c <= '9' && c >= '0'; c = getchar()) x = x * 10 + (c & 15);
}
#define ll long long 
#define lll __int128_t
#define pb push_back
#define mp make_pair
typedef pair < int,int> ii;
typedef vector<ii> vii;
typedef vector<ll>vl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll hashPrime = 1610612741;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll i, j, k, l, n, m;
    cin >> n >> k;
    vector<ll> data(n + 1);
    for (i = 1; i <= n;i++){
        cin >> data[i];
    }
    vector<ll> working,aro;
    vector<ll> ischecked(n + 1, 0), move(n + 1, 0);
    working.pb(1);
    ischecked[1] = 1;
    ll present = 1;
    ll last = -1;
    move[0] = 1;
    ll bal = 1;
    for (i = 1; i <= n;i++){
        ll kola = data[bal];
        ///pos[kola] = i;
        if(ischecked[kola]==1){
            last = kola;
            break;
        }
        ischecked[kola] = 1;
        move[i] = kola;
        bal = kola;
        ///present = kola;
        ///working.pb(kola);
    }
    ll sz;
    for (j = 0; j <= n;j++){
        if(move[j]==last){
            sz = i - j;
            present = j;
            //present = i-j;
            break;
        }
    }
    if (k <= present)
    {
            cout << move[k] << "\n";
    }
    else{
        ///cout << present << " " << sz << "\n";
        ll temp = (k - present) % sz;
        cout << move[temp+present] << "\n";
    }
        return 0;
}

Measured memory_bytes: 7936
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

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

// dp[i][j] := 数 j を i 分割する総数
vector<vector<ll>> dp(1010, vector<ll>(1010, 0));
void part_init(){
    dp[0][0] = 1;
    for(int i=1; i<=1005; i++){
        for(int j=0; j<=1005; j++){
            if(0 <= j - i){
                (dp[i][j] = dp[i-1][j] + dp[i][j-i]) %= MOD;
            }
            else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }
}

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

    int n, k; cin>>n>>k;

    part_init();

    cout << dp[k][n] << endl;


    return 0;
}


Measured memory_bytes: 11236
using System;

namespace ABC105C
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            ulong res = 0;

            if (N > 0)
            {
                // plus
                int num = N;
                int scale = 0;

                while (num > 1)
                {
                    if (num % 2 == 1)
                    {
                        res = TranslatePlus(res, scale);
                    }

                    num /= 2;
                    scale++;
                }
                res = TranslatePlus(res, scale);
            }
            else if (N < 0)
            {
                // minus
                int num = -N;
                int scale = 0;

                while (num > 1)
                {
                    if (num % 2 == 1)
                    {
                        res = TranslateMinus(res, scale);
                    }

                    num /= 2;
                    scale++;
                }
                res = TranslateMinus(res, scale);
            }
            else
            {
                // zero
                Console.WriteLine(0);
                return;
            }

            bool headFlag = false;
            ulong comp = 0x8000000000000000;
            for (int i = 63; i >= 0; i--)
            {
                if (!headFlag && (comp & res) != 0)
                {
                    headFlag = true;
                }

                if (headFlag)
                {
                    Console.Write((comp & res) != 0 ? '1' : '0');
                }
                comp >>= 1;
            }
            Console.WriteLine();
        }

        static ulong TranslatePlus(ulong src, int scale)
        {
            ulong diff = 0x1;
            ulong comp = (ulong)1 << scale;

            if (scale % 2 == 0)
            {
                if ((comp & src) != 0)
                {
                    diff |= 0x6;
                }

            }
            else
            {
                if ((comp & src) == 0)
                {
                    diff |= 0x2;
                }
            }

            src ^= (diff << scale);

            return src;
        }

        static ulong TranslateMinus(ulong src, int scale)
        {
            ulong diff = 0x1;
            ulong comp = (ulong)1 << scale;

            if (scale % 2 == 0)
            {
                if ((comp & src) == 0)
                {
                    diff |= 0x2;
                }

            }
            else
            {
                if ((comp & src) != 0)
                {
                    diff |= 0x6;
                }
            }

            src ^= (diff << scale);

            return src;
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
const int MAXn = 1e5 + 10, MAXlg = 32;
int  n, ar[MAXn], have[MAXn], cnt;
long long hp;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> ar[i];
	
	for (int i = 0; i < n; i++)
		hp ^= ar[i];
	
	for (int i = 0; i < n; i++)
		have[__builtin_ctz(ar[i])]++;
	
	for (int i = MAXlg; i >= 0; i--) {
		if ((hp>>i) & 1) {
			if (!have[i])
				return cout << -1,0;
			hp ^= (1<<(i+1)) - 1;
			cnt++;
		}
		
	}
	cout << cnt;
}

Measured memory_bytes: 640
D,N = map(int,input().split())

if D == 0:
    if N == 100:
        print(101)
    else:
        print(N)
elif D == 1:
    if N == 100:
        print(10100)
    else:
        print(N*100)
elif D == 2:
    if N == 100:
        print(1010000)
    else:
        print(N * 10000)

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

int main(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	cout << (abs(a-c)<=d||(abs(a-b)<=d&&abs(b-c)<=d)?"Yes":"No") << endl;
	return 0;
}

Measured memory_bytes: 256