akhauriyash/Code-Regression huggingface dataset:
use std::cmp;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let s = sc.chars();
    let n = s.len();
    let mut min = n;
    for i in 1..n {
        if s[i] != s[i - 1] {
            let t = i;
            let s = n - t;
            min = cmp::min(min, cmp::max(s, t));
        }
    }

    println!("{}", min);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
import sys
from collections import Counter
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


def inpl():
    return list(map(int, input().split()))


def main():
    N = int(input())
    A = inpl()
    Q = int(input())
    BC = [inpl() for _ in range(Q)]
    cA = Counter(A)

    sum_p = sum(k * v for k, v in cA.items())

    for b, c in BC:
        if b not in cA:
            print(sum_p)
            continue
        t_value = cA.pop(b)
        sum_p -= t_value * b
        if c in cA:
            cA[c] += t_value
        else:
            cA[c] = t_value
        sum_p += t_value * c
        print(sum_p)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 37376
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,a,b) for (int i = (a); i < (b); i++ )
typedef pair<int,int> P;
typedef long long ll;
const int INF = 100000000;

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

    ll H[N];

    for (int i = N-1; i>=0; i--) {
        cin >> H[i];
    }
    string ans = "Yes";
    rep(i,1,N) {
        if (H[i]<=H[i-1]) {
            continue;
        }
        else if (H[i]==H[i-1]+1) {
            H[i]--;
        }
        else {
            ans = "No";
            break;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 1024
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int cnt[1000010], n, q;

int main(){
	int mx = -inf, mxi;
	cin >> n >> q;
	set<pi> s;
	rep(i, q){
		int a, v;
		cin >> a >> v;
		s.erase(mp(-cnt[a], a));
		cnt[a] += v;
		s.insert(mp(-cnt[a], a));
		
		cout << s.begin()->second << " " << -s.begin()->first << endl;
	}
	return 0;
}

Measured memory_bytes: 9556
def main

a,b,c = gets.split(" ").map(&:to_i)
 
x = c - a - b
 
if x > 0
 
	y = x*x - 4*a*b
 
	if y > 0
		puts "Yes"
	else
		puts "No"
	end
else
puts "No"
end
end

main

Measured memory_bytes: 1788
#include <stdio.h>
#define MAX 10000
#define NIL -1

struct Node { int p, l, r; };
struct Node T[MAX];
int n;

void preParse(int u) {
  if ( u == NIL ) return;
  printf(" %d", u);
  preParse(T[u].l);
  preParse(T[u].r);
}

void inParse(int u) {
  if ( u == NIL ) return;
  inParse(T[u].l);
  printf(" %d", u);
  inParse(T[u].r);
}

void postParse(int u) {
  if (u == NIL ) return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d", u);
}

int main() {
  int i, v, l, r, root;

  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) {
    T[i].p = NIL;
  }

  for ( i = 0; i < n; i++) {
    scanf("%d %d %d", &v, &l, &r);
    T[v].l = l;
    T[v].r = r;
    if ( l != NIL ) T[l].p = v;
    if ( r != NIL ) T[r].p = v;
  }

  for ( i = 0; i < n; i++ ) if ( T[i].p == NIL ) root = i;

  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}



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

typedef long long ll;

using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
//  --------------------------------------

	int N, K, Q, A[100010] = {};
	cin >> N >> K >> Q;

	for (int i = 0; i < Q; i++)
	{
		int Ai; cin >> Ai;
		A[Ai-1] += 1;
	}
	
	for (int i = 0; i < N; i++)
	{
		if (A[i] > Q-K)
		{
			cout << "Yes\n";
		}
		else
		{
			cout << "No\n";
		}
		
	}

}

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

using namespace std;

int main(){

	string str, cha, code1[50], code2[50];
	int i, j, n, m, flag;

	while(1){
		str = "";
		cin >> n;
		if(!n){break;}
		for(i=0;i<n;i++){
			cin >> code1[i] >> code2[i];
		}
		cin >> m;

		for(i=0;i<m;i++){
			cin >> cha;
			flag = 0;
			for(j=0;j<n;j++){
				if(cha == code1[j]){
					str += code2[j];
					flag = 1;
				}
				else if(j==n-1 && !flag){
					str += cha;
				}
			}
		}

		cout << str << endl;
	}

	return 0;
}

Measured memory_bytes: 1336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define pf push_front
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	vector<vector<int>> a(3, vector<int>(3));
	forn(i, 3) forn(j, 3) cin >> a[i][j];
	int n;
	cin >> n;
	vector<int> b(n);
	vector<vector<bool>> u(3, vector<bool>(3));
	forn(i, n){
	   	cin >> b[i];
		forn(j, 3) forn(k, 3)
			if(a[j][k] == b[i])
				u[j][k] = true;
	}
	bool ok = false;
	forn(i, 3) {
		if(u[i][0] && u[i][1] && u[i][2]) {
			ok = true;
			break;
		}
	}
	forn(i, 3) {
		if(u[0][i] && u[1][i] && u[2][i]) {
			ok = true;
			break;
		}
	}
	if(u[0][0]&&u[1][1]&&u[2][2])
		ok = true;
	if(u[0][2]&&u[1][1]&&u[2][0])
		ok = true;
	if(ok) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 3536
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_167
{
    class C
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[] nmx = ReadInts();
            int n = nmx[0];
            int m = nmx[1];
            int x = nmx[2];
            int[] cs = new int[n];
            int[,] array = new int[n,m];
            for(int i = 0; i < n; i++)
            {
                int[] input = ReadInts();
                cs[i] = input[0];
                for(int j = 0; j < m; j++)
                {
                    array[i, j] = input[j + 1];
                }
            }

            int all = 1 << n;
            int res = int.MaxValue;
            for(int i = 0; i < all; i++)
            {
                int[] vals = new int[m];
                int tmp = 0;
                for(int j=0;j<n;j++)
                {
                    if ((i & (1 << j)) == 0)
                    {
                        continue;
                    }

                    tmp += cs[j];
                    for(int k = 0; k < m; k++)
                    {
                        vals[k] += array[j, k];
                    }
                }

                bool ok = true;
                for(int j = 0; j < m; j++)
                {
                    if (vals[j] < x)
                    {
                        ok = false;
                        break;
                    }
                }

                if (ok)
                {
                    res = Min(res, tmp);
                }
            }

            if (res == int.MaxValue)
            {
                WriteLine(-1);
            }
            else
            {
                WriteLine(res);
            }
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 27612
#include <algorithm>
#include <cassert>
#include <set>
#include <iostream>
#include <vector>

using namespace std;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define per(i, a, b) for (auto i = (b) - 1; i >= (a); --i)
#define trav(x, v) for (auto &x : v)

#define sz(x) int((x).size())
#define eb(x...) emplace_back(x)
#define ff first
#define ss second

using ll = int64_t;
const ll inf = 2e18;

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

struct Line {
	mutable ll k, m, p;
	bool operator<(const Line& o) const { return k < o.k; }
	bool operator<(ll x) const { return p < x; }
};
struct LineContainer : multiset<Line, less<>> {
	ll div(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }
	bool isect(iterator x, iterator y) {
		if (y == end()) { x->p = inf; return false; }
		if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
		else x->p = div(y->m - x->m, x->k - y->k);
		return x->p >= y->p;
	}
	void add(ll k, ll m) {
		auto z = insert({k, -m, 0}), y = z++, x = y;
		while (isect(y, z)) z = erase(z);
		if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
		while ((y = x) != begin() && y->p <= (--x)->p)
			isect(x, erase(y));
	}
	ll query(ll x) {
		assert(!empty());
		auto l = *lower_bound(x);
		return l.k * x + l.m;
	}
};

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n; ll c; cin >> n >> c;
	ll h[n]; rep(i, 0, n) cin >> h[i];
	LineContainer L; L.add(2 * h[0],h[0] * h[0]);
	ll t = 0;
	rep(j, 1, n) {
		t = c + h[j] * h[j] - L.query(h[j]);
		L.add(2 * h[j], t + h[j] * h[j]);
	}
	cout << t;
}

Measured memory_bytes: 14336
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main(void)
{
    int n;
    char s[100];
    char s1[100];
    char s2[100];
    int res,res1,res2;

    scanf("%s",s);
    n=strlen(s);
    // printf("%d\n",n);

    for (int i=0;i<=(n-1)/2;i++){
        if (i==(n-1)/2)
            s1[i]='\0';
        else
            s1[i]=s[i];
    }
    // printf("%s\n",s1);
    int s1_n=strlen(s1);
    for (int i=0;i<s1_n;i++){
        if (s1[i]==s1[s1_n-i-1])
            res1=1;
        else
            res1=0;    
    }
    // printf("res1=%d\n",res1);

    for (int i=(n+3)/2-1;i<=n;i++){
        // if (i==n)
        //     s2[i-((n+3)/2-1)]='\n';
        // else
            s2[i-((n+3)/2-1)]=s[i];
    }
    // printf("%s\n",s2);
    int s2_n=strlen(s2);
    for (int i=0;i<s2_n;i++){
        if (s2[i]==s2[s2_n-i-1])
            res2=1;
        else
            res2=0;    
    }
    // printf("res2=%d\n",res2);

    if (strcmp(s1,s2)==0)
        res=1;
    else
        res=0;
    // printf("res=%d\n",res);

    if (res==1 && res1==1 && res2==1)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;

}

Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

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

    List<int[]> keys = new ArrayList<>();
    for (long i = 0; i < M ; i++) {
      int cost = sc.nextInt();
      int b = sc.nextInt();
      int key = 0;
      for (int j = 0; j < b; j++) {
        int box = sc.nextInt() -1;
        key |= (1<<box);
      }
      int[] pair = {key, cost};
      keys.add(pair);
    }

    int[] dp = new int[1<<N];
    int MAX = 1001001001;
    Arrays.fill(dp,MAX);
    dp[0] = 0;//cost
    for (int i = 0; i < (1<<N) ; i++) {
      if( dp[i] >= MAX) continue;
      for (int[] pair: keys) {
        int cost = pair[1];
        int key = pair[0];
        int newState = i | key;
        int newCost = dp[i] + cost;
        if(dp[newState] > newCost){
          dp[newState] = newCost;
        }
      }
    }
    if(dp[(1<<N)-1] >= MAX){
      System.out.println(-1);
    }else{
      System.out.println(dp[(1<<N)-1] );
    }

  }
}

Measured memory_bytes: 30456
n,w=map(int,input().split())
dp=[0 for i in range(w+1)]
dp1=dp.copy()
for i in range(1,n+1):

	
    
	a,b=map(int,input().split())
	
	for j in range(1,w+1):
		dp1[j]=dp[j]
		if(a<=j):
			dp1[j]=max(dp1[j],dp[j-a]+b)
	
	dp=dp1.copy()
print(dp[w])





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

void greedyTakahashi(long long &A, long long &B, long long K);

int main()
{
    long long A, B, K;
    cin >> A >> B >> K;
    greedyTakahashi(A, B, K);
    cout << A << ' ' << B << endl;
}

void greedyTakahashi(long long &A, long long &B, long long K)
{
    if (A >= K)
    {
        A -= K;
        return;
    }
    
    K -= A;
  	A = 0;
    B = B > K ? B - K : 0;
}

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

using namespace std;

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

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define YES puts("YES\n")
#define Yes puts("Yes\n")
#define NO  puts("NO\n")
#define No  puts("No\n")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }




signed main() {

	int N;
	cin >> N;
	/*
	vector<int> a(N);
	rep(i, N) a[i] = i + 1;

	int ans = 0;
	do {
		int t = 0;
		rep(i, N) t += (i + 1) % a[i];
		ans = max(ans, t);

	} while (next_permutation(a.begin(), a.end()));
	*/
	int ans = 0;
	for (int i = 0; i < N-1; i++) ans += i + 1;

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


Measured memory_bytes: 256
n, m = map(int, input().split())
s = input()

g = [[] for _ in range(n)]

for _ in range(m):
    a, b = map(int, input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

count = [[0, 0] for _ in range(n)]
bad = []

for i in range(n):
    for v in g[i]:
        if s[v] == 'A':
            count[i][0] += 1
        else:
            count[i][1] += 1
    if count[i][0]*count[i][1] == 0:
        bad.append(i)


visited = [False]*n
while bad:
    v = bad.pop()
    if visited[v]:
        continue
    visited[v] = True
    for w in g[v]:
        if not visited[w]:
            if s[v] == 'A':
                count[w][0] -= 1
            else:
                count[w][1] -= 1
            if count[w][0]*count[w][1] == 0:
                bad.append(w)

for i in range(n):
    if count[i][0]*count[i][1] > 0:
        print('Yes')
        exit()

print('No')


Measured memory_bytes: 94492
/*	MASTER HAS FAILED MORE TIMES
	THAN BEGINNER HAS EVER TRIED
*/

#include <bits/stdc++.h>

using namespace std;

#define endl             '\n'
#define all(a)           a.begin(), a.end()
#define mem(a, n)        memset(a, n, sizeof(a))
#define Unique(n)        (n).erase(unique(all(n)), (n).end())
#define NumofDigits(n)   ((long long)log10(n)+1)
#define repeat(i, a, n)  for(int i=a; i<n; i++)
#define isPowerOfTwo(n)  (n && !(n & (n - 1)))

typedef long long ll;
typedef long double ld;

int sieve(int n);
unsigned long long pow(long long base, long long power);
long long gcd(long long a, long long b)
{
    return a%b ? gcd(b, a%b) : b;
}
long long lcm(long long a, long long b)
{
    return a*b/gcd(a, b);
}

void quicken()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
void file()
{
#ifdef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif /*ONLINE_JUDGE*/
}

int main()
{
    quicken();

    int a, b; cin >> a >> b;
    repeat(i, 1, 100000001){
        ld c = (ld)i * 0.08, d = (ld)i * 0.1;
        if((int)c == a && (int)d == b)
            return cout << i, 0;
    }
    cout << -1;

    return 0;
}

unsigned long long pow(long long base, long long power)  /// mod?
{
    if(power==0)
        return 1;
    if(power==1)
        return base;

    unsigned long long ans = pow(base, power/2); /// mod?
    ans *= ans; /// ((ans%mod)*(ans%mod))%mod;

    if(power&1)
        return ans*base; /// ((ans%mod)*(base%mod))%mod;
    return ans;
}

int sieve(int n)
{
    int c = 0;
    vector<bool> isPrime(n+1, true);
    isPrime[0] = isPrime[1] = 0;

    for(long long i=2; i*i<=n; i++)
        if(isPrime[i])
            for(long long j=i*2; j<=n; j+=i)
                isPrime[j] = 0;
    repeat(i, 0, n+1)
    if(isPrime[i])
        c++;
    return c; /// primeCount [1:n]
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int a[1000006];
int b[1003][1003];
int n, m, k;
int x, y, z;
int as(int x) {
    return max(x, -x);
}
int main() {
    scanf("%d", &n);
    int res1 = 0;
    int res2;
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
        res1 = max(res1, a[i]);
    }
    int i = 1;
    while (a[i] == res1) {
        ++i;
    }
    res2 = a[i];
    int tmp = res1 / 2;
    for ( ; i <= n; ++i) {
        if (res1 & 1) {
            if (min(as(res2 - tmp), as(res2 - tmp)) > min(as(a[i] - tmp), as(a[i] - tmp - 1))) {
                res2 = a[i];
            }
        } else {
            if (as(res2 - tmp) > as(a[i] - tmp)) {
                res2 = a[i];
            }
        }
    }
    printf("%d %d", res1, res2);
    return 0;
}

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

int main() {
    char b;
    cin >> b;
    switch (b) {
        case 'A':
            cout << 'T' << endl;
            break;
        case 'C':
            cout << 'G' << endl;
            break;
        case 'G':
            cout << 'C' << endl;
            break;
        case 'T':
            cout << 'A' << endl;
            break;
    }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	int x, y;
	cin >> x >> y;
	if (x <= 8 && y <= 8) {
		cout << "Yay!" << endl;
	}
	else {
		cout << ":(" <<endl;
	}

	return 0;
}



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

using namespace std;
using namespace std::chrono;

#define rep(i,a,b) for(int i = a;i<(b);++i)
#define trav(a,v) for(auto& a : v)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;

const ll big = 1000000007ll;
const ll big2 = 1000000009ll;
ll n,m,k,q,h,T;
ll x;

ll sum(ll i){
    ll i2 = i;
    ll ans = 0;
    while(i2 > 0){
        ans += i2%10;
        i2 /= 10;
    }
    return ans;
}

ll L(ll i){
    ll i2 = i;
    ll ans = 0;
    while(i2 > 0){
        ans++;
        i2 /= 10;
    }
    return ans;
}


ll dijk(ll start){
    ll dist[100001] = {0};
    bool mark[100001] = {0};
    dist[start] = start;
    priority_queue<pair<ll,ll> > pq;
    pq.push({-start,start});
    while(!pq.empty()){
        ll a = pq.top().second;
        ll w = -pq.top().first;
        pq.pop();
        if(!mark[a]){
            mark[a] = 1;
            for(ll c1 = 0; c1 < 10; c1++){
                ll b = (10*a+c1)%k;
                ll w2 = w+c1;
                if(dist[b] == 0 || w2 < dist[b]){
                    dist[b] = w2;
                    pq.push({-w2,b});
                }
            }
        }
    }
    return dist[0];
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,d;

    cin >> k;
    while(k%2 == 0)k/=2;
    while(k%5 == 0)k/=5;
    ll ans = big;
    for(ll c1 = 1; c1 < 9; c1++){
        ans = min(ans,dijk(c1));
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 8772
//
//  ROIGold.cpp
//  Main calisma
//
//  Created by Rakhman on 05/02/2019.
//  Copyright © 2019 Rakhman. All rights reserved.
//
 
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>
 
#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define no_answer return cout << 0, 0;
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)
 
const int MXN = 1e7 + 200;
const long long MNN = 2e3 + 520;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const int OO = 1e9 + 500;
 
typedef long long llong;
typedef unsigned long long ullong;
 
using namespace std;

llong n;
vector<int> g[MXN];

void add(llong& a, llong b){
    a += b;
    //if(a < 0) a += MOD;
    while(a >= MOD) a -= MOD;
}

pair<llong, llong> dfs(int x, int p){
    llong all_white = 1, some_black = 1;
    for(int i = 0; i < g[x].size(); i++){
        int to = g[x][i];
        if(to == p) continue;
        pair<llong, llong> sinok = dfs(to, x);
        all_white = (all_white * sinok.F) % MOD;
        some_black = (some_black * (sinok.F + sinok.S) % MOD) % MOD;
    }
    return {some_black, all_white};
}

int main () {
    ios;
    cin >> n;
    for(int i = 1; i < n; i++){
        int a, b;
        cin >> a >> b;
        g[a].pb(b);
        g[b].pb(a);
    }
    pair<llong, llong> ans = dfs(1, 0);
    cout << (ans.F + ans.S) % MOD;
}


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

#define i64 long long
#define u64 unsigned long long
#define i32 int
#define u32 unsigned int

#define pii pair<int, int>
#define pll pair<long long, long long>

#define ld long double
#define defmod 1000000007

#define mati64(a,b) vector<vector<i64>>(a, vector<i64>(b, 0));
using namespace std;


int main(){
	cin.sync_with_stdio(0);
	cin.tie(0);
	
	string s; cin >> s;
	set<char> lol;
	int n = s.length();
	for(int i = 0; i < n; ++i)
		lol.insert(s[i]);
	bool c1 = false, c2 = false;
	if((lol.count('N') && lol.count('S')) || (lol.count('N') == 0 && lol.count('S') == 0)){
		c1 = true;
	}
	if((lol.count('E') && lol.count('W')) || (lol.count('E') == 0 && lol.count('W') == 0)){
		c2 = true;
	}
	if(c1 && c2)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	scanf("%d", &n);
	int x[501];
	map<int, int> xmp;
	for(int i=1; i<=n; i++){
		scanf("%d", &x[i]);
		xmp[x[i]]=i;
	}
	deque<int> a1, a2;
	vector<int> a;
	for(auto itr=xmp.begin(); itr!=xmp.end(); itr++){
		int x=itr->first;
		int i=itr->second;
		for(int j=0; j<i-1; j++){
			a1.push_back(i);
		}
		for(int j=0; j<n-i; j++){
			a2.push_back(i);
		}
	}
	for(int j=0; j<n*(n-1)/2; j++){
		a1.push_back(a2.front());
		a2.pop_front();
	}
	for(int i=1; i<=n*n; i++){
		auto itr=xmp.find(i);
		if(itr==xmp.end()){
			a.push_back(a1.front());
			a1.pop_front();
		}else{
			a.push_back(itr->second);
		}
	}
	for(int i=1; i<=n; i++){
		int count=0;
		for(int j=0; j<n*n; j++){
			if(a[j]==i){
				count++;
				if(count==i && j+1!=x[i]){
					printf("%s\n", "No");
					return 0;
				}
			}
		}
	}
	printf("%s\n", "Yes");
	for(int i=0; i<n*n; i++){
		printf("%d ", a[i]);
	}
	printf("\n");

	return 0;
}

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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N), counter(N,0);
  for(int i=0; i<N; i++){
    cin >> A.at(i);
    counter.at(A.at(i)-1)++;
  }
  sort(counter.begin(),counter.end());
  int num_ball = 0;
  for(int i=N-1; i>N-1-K; i--){
    num_ball += counter.at(i);
  }
  cout << N - num_ball;
  return 0;
}

Measured memory_bytes: 4832
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			String s = sc.next();
			int max = 0;

			for (int i = 1; i < n; i++) {
				String head = s.substring(0, i);
				String tail = s.substring(i, s.length());
				int count = 0;

				for (char c = 'a'; c <= 'z'; c++) {
					if (-1 < head.indexOf(c) && -1 < tail.indexOf(c)) {
						count++;
					}
				}
				if (max < count) {
					max = count;
				}
			}
			System.out.println(max);
		}
	}
}


Measured memory_bytes: 24276
mlist = list([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])
b = int(input())
print(mlist[b-1])

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

int main(){
	int a,b;
	cin>>a>>b;
	int i=1;
	while(i<1005){
		if(i*8/100==a&&i*10/100==b){
			break;
		}
		i++;
	}
	if(i>1000){
		i=-1;
	}		
	
	cout<<i<<endl;
	return 0;
}

Measured memory_bytes: 384
def add(s,d):
     sum=0
     for i in d[1:]:
          sum+=s[i] 
     return sum

def check(m):
    for i in range(m):
        if add(s, d[i]) % 2 == p[i]:
            pass
        else :
            return -1
    return 1
        
        
d = []
s=[]
inc=0

n, m = (int(x) for x in input().split())
for i in range(m):
    i = [int(i) for i in input().split()] 
    d.append(i)
p = [int(i) for i in input().split()]

r = 2 ** n

for i in range(r):
    x = str(bin(i).split('b')[1]).zfill(n + 1)
    s=list(x)
    s= [int(s) for s in s]
    if check(m) == 1:
            inc +=1
    
print(inc)

Measured memory_bytes: 3064
class UnionFindTree:  # UnionFind木を作る
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    def find(self, x):  # 根を検索する
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):  # 木を併合する
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same_check(self, x, y):  # 同じ木に属するかチェックする
        return self.find(x) == self.find(y)

N, M = map(int, input().split())

tree = UnionFindTree(N)

for i in range(1, M+1):
    x, y, w = map(int, input().split())
    tree.union(x, y)

root_list = []

for i in range(1, N+1):
    root_list.append(tree.find(i))

root_list = list(set(root_list))

print(len(root_list))


Measured memory_bytes: 17952
N = gets.to_i
s = []
s << gets.chomp.chars
s << gets.chomp.chars

t = Array.new(N, nil)

N.times do |i|
  if s[0][i] == s[1][i]
    t[i] = 'T'
  end
end

N.times do |i|
  if t[i].nil?
    t[i] = 'Y'
  end
end

t = t.join.gsub(/Y+/) { |str| 'Y' * (str.size / 2) }

cnt = 0

t.chars.each_with_index do |c, i|
  if c == 'T'
    if i.zero?
      cnt = 3
    else
      if t[i - 1] == 'T'
        if i == 1
          cnt = 6
        else
          cnt *= 2
        end
      else
        cnt *= 1
      end
    end
  else
    if i.zero?
      cnt = 6
    else
      if t[i - 1] == 'T'
        if i == 1
          cnt = 6
        else
          cnt *= 2
        end
      else
        cnt *= 3
      end
    end
  end
end

puts cnt % 1_000_000_007


Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  int l,r;
  int min;
  int tmp_r,tmp_l;
  tmp_r=0;
  tmp_l=0;
  l=0;
  r=0;
  int lucky=0;
  if(s[0]=='L')tmp_l++;
  else tmp_r++;
  if(s[0]=='R'&&s[1]=='R')lucky++;
  for(int i=1;i<n;i++){
    if(s[i]=='L'){
      if(tmp_l!=0)tmp_l++;
      else{
	tmp_r=0;
	r++;
	tmp_l++;
      }
    }
    else if(s[i]=='R'){
    if(tmp_r!=0)tmp_r++;
    else{
      tmp_l=0;
      l++;
      tmp_r++;
      }
    }
    if(s[i]=='L'){
      if(s[i-1]=='L')lucky++;
    }
    if(s[i]=='R'){
      if(i!=n-1){
	if(s[i+1]=='R')lucky++;
      }
    }
  }
  if(s[n-1]=='L')l++;
  else r++;
  if(l>r)min=r;
  else min=l;
  int ans=lucky;
  if(k>=min)ans=n-1;
  if(k==min-1){
    if(s[0]==s[n-1])ans=n-3;
    else ans=n-2;
  }
  if(k<min-1)ans=lucky+k*2;
  cout<<ans<<endl;
  return 0;
  }


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

int main()
{
  string a, b, c;
  float num, f;
  cin >> a >> b;
  c = a + b;
  num = sqrt(atoi(c.c_str()));
  f = floor(num);
  if (num == f) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;

template<int mod>
struct ModInt {
    int x;
 
    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
 
    ModInt &operator+=(const ModInt &p) {
        if((x += p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator-=(const ModInt &p) {
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator*=(const ModInt &p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }
 
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
 
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
 
    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }
 
    ModInt pow(int e){
        long long a = 1, p = x;
        while(e > 0) {
            if(e%2 == 0) {p = (p*p) % mod; e /= 2;}
            else {a = (a*p) % mod; e--;}
        }
        return ModInt(a);
    }
 
    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

using modint = ModInt<mod>;
modint f[d5];

void makef() {
    f[0] = 1;
    for (int i = 1; i < d5; i++) f[i] = f[i - 1] * i;
}
 
modint nCr(int n, int r){
    if(n < r) return 0;
    return f[n] / (f[r] * f[n-r]);
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h,w;
    cin>>h>>w;
    string a[1001];
    for(int i=0;i<h;i++)cin>>a[i];
    modint dp[1010][1010];
    //dp[i][j]:(i,j)の行き方の総数
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++)dp[i][j]=0;
    }
    dp[0][0]=1;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(a[i][j]=='#')dp[i][j]=0;
            else{
                if(i!=0)dp[i][j]+=dp[i-1][j];
                if(j!=0)dp[i][j]+=dp[i][j-1];
            }
        }
    }
    cout<<dp[h-1][w-1]<<endl;
}

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

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

using namespace std;

int main() {
  int n;
  while(scanf("%d",&n) != EOF) {
    vector<bool> isp(n+1, true);
    isp[0] = isp[1] = false;
    for (int i = 2; i*i <= n; ++i)
      if (isp[i])
        for (int j = i*i; j <= n; j += i)
          isp[j] = false;
    int cnt = 0;
    for (int i = 1; i <= n; ++i)
      if (isp[i] && isp[n-i+1])
        ++cnt;
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 3144
#include<stdio.h>
#define NILL -1

typedef struct
{
  int parent;
  int l;
  int r;
  //int id;
}T;

T tree[30];

void PreOrder(int i)
{
  if(i == NILL) return;
  printf(" %d",i);
  //if(i == NILL) return;
  PreOrder(tree[i].l);
  PreOrder(tree[i].r);
}

void InOrder(int i)
{
  if(i == NILL) return;
  InOrder(tree[i].l);
  printf(" %d",i);
  InOrder(tree[i].r);
}

void PostOrder(int i)
{
  if(i == NILL) return;
  PostOrder(tree[i].l);
  PostOrder(tree[i].r);
  printf(" %d",i);
}

int main()
{
  int i;//節点番号
  int n;
  int root = 0;

  scanf("%d",&n);
  
  for(i=0;i < n;i++) tree[i].parent = NILL;

  int v;
  for(i=0;i < n;i++){
    scanf("%d",&v);
    scanf("%d%d",&tree[v].l, &tree[v].r);
    if(tree[v].l != NILL) tree[tree[v].l].parent = v;
    if(tree[v].r != NILL) tree[tree[v].r].parent = v;
  }
  for(i = 0;i < n;i++){
    if(tree[i].parent == NILL) root = i;
  }

  printf("Preorder\n");
  PreOrder(root);
  printf("\n");
  
  printf("Inorder\n");
  InOrder(root);
  printf("\n");

  printf("Postorder\n");
  PostOrder(root);
  printf("\n");
  
  return 0;
}


Measured memory_bytes: 2760
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define loop1(n, i) for(int i=1;i<=n;i++)
#define rloop(n, i) for(int i=n;i;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;

const long long mod1 = 999999937LL, mod2 = 1000000007LL, base = 9973;

int main() {
    int n; cin >> n;
    string S; cin >> S;
    V<ll> hash1(n), hash2(n);

    loop (n, i) {
        hash1[i] = S[i];
        hash2[i] = S[i];
    }

    int ans = 0;
    loop1 (n, i) {
        unordered_set<ll> set1, set2;
        loop (n - i + 1, j) {
            if (j - i >= 0) {
                set1.insert(hash1[j - i]);
                set2.insert(hash2[j - i]);
            }
            if (set1.find(hash1[j]) != set1.end() &&
                set2.find(hash2[j]) != set2.end()) {
                ans = i;
            }
        }
        loop (n - i, j) {
            hash1[j] = (hash1[j] * base + S[j + i]) % mod1;
            hash2[j] = (hash2[j] * base + S[j + i]) % mod2;
        }
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, m;
	int arr[50][50], brr[50][50];
	cin >> n >> m;
	for(int i = 0; i < n; i++) {
		cin >> arr[i][0] >> arr[i][1];
	}
	for(int i = 0; i < m; i++) {
		cin >> brr[i][0] >> brr[i][1];
	}

	int min = INT_MAX;
	int num = 0;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) {
			int keep = abs(arr[i][0] - brr[j][0]) + abs(arr[i][1] - brr[j][1]);
			if(keep < min) {
				min = keep;
				num = j;
			}
		}
		cout << num + 1 << endl;
		min = INT_MAX;
		num = 0;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; n>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'
template <class T> bool updmax(T& a, T b) { if (b > a) { a = b; return true;} return false;}
template <class T> bool updmin(T& a, T b) { if (b < a) { a = b; return true;} return false;}
template <class T> T permutation(ll n, ll k) { T f(1); for (ll i=0; i<k; ++i, --n) f *= n; return f; }
template <class T> T factorial(ll n) { return permutation<T>(n,n); }
template <class T> T binomial(ll n, ll k) { return permutation<T>(n,k) /= factorial<T>(k); }

template <ll Mod>
class modint {
    public:
    ll n=0;
    modint(){}
    modint(ll n):n(n){ clamp(); }
    modint& operator = (modint const& a) = default;
    modint& operator = (int a) { n = a; clamp(); return *this; }
    modint operator - () { modint t = *this; t.n = -t.n; t.clamp(); return t; }
    modint& operator *= (modint const& a) { n *= a.n; clamp(); return *this; }
    modint& operator *= (ll a) { n *= a; clamp(); return *this; }
    modint& operator /= (modint const& a) { *this *= a.inv(); return *this; }
    modint& operator += (modint const& a) { n += a.n; if (n >= Mod) n -= Mod; return *this; }
    modint& operator -= (modint const& a) { n -= a.n; if (n < 0) n += Mod; return *this; }
    modint& operator %= (modint const& a) { n %= a.n; clamp(); return *this; }
    friend modint operator * (modint a, modint b) { modint t(a); t.n *= b.n; t.clamp(); return t; }
    friend modint operator + (modint a, modint b) { modint t(a); t.n += b.n; t.clamp(); return t; }
    friend modint operator - (modint a, modint b) { modint t(a); t.n -= b.n; t.clamp(); return t; }
    friend ostream& operator << (ostream& os, modint const& a) { os << a.n; return os; }
    friend bool operator == (modint const& a, int b) { return a.n == b; }
    void clamp() { n %= Mod; if (n < 0) n += Mod; }
    modint inv() const { return this->pow(Mod-2); }
    ll get() { return n; }
    modint pow(ll p) const {
        ll a=1, e=n;
        while (p > 0) {
            if (p&1) { a *= e; a %= Mod; }
            e *= e; e %= Mod; p >>= 1;
        }
        return modint(a);
    }
};

const ll Mod = (ll)1e9+7;
using mint = modint<Mod>;
int main() {
    fastio;
    ll N,a,b;
    cin >> N >> a >> b;
    auto m = mint(2).pow(N);
    m -= binomial<mint>(N,a);
    m -= binomial<mint>(N,b);
    m -= 1;
    cout << m.get() << endl;
}


Measured memory_bytes: 3616
import java.util.Scanner;

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

	/* 入力 */
	String s = scan.next();

	/* 英小文字配列 */
	int[] e = new int[26];

	int flag = 1;
	for(int i = 0; i < s.length(); i++){
	    e[s.charAt(i)-97]++;
	    if(e[s.charAt(i)-97] == 2){
		flag = -1;
		break;
	    }
	}

	if(flag == 1){
	    System.out.println("yes");
	}else{
	    System.out.println("no");
	}
    }
}


Measured memory_bytes: 23252
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {
    int N,L;
    private void solve() {
        N = nextInt();
        L = nextInt();
        int sum = 0;
        for(int i = 1;i <= N;i++) {
            sum += L + i - 1;
        }

        int ans = Integer.MAX_VALUE;
        int minDiff = Integer.MAX_VALUE;
        for(int i = 1;i <= N;i++) {
            int diff = Math.abs(sum - (sum - (L + i -1)));

            if (minDiff > diff) {
                minDiff = diff;
                ans = sum - (L + i - 1);
            }
        }
        out.println(ans);
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

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

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

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


Measured memory_bytes: 22356
#include <iostream>
#include <string>
using namespace std;
char max_string(string s, int N);
char min_string(string s, int N);
int main()
{
    string s,t;
    cin >> s >> t;
    int N = s.size();
    int M = t.size();
    char a = min_string(s,N);
    char b = max_string(t,M);
    if(a<b) cout << "Yes" << endl;
    else if(N<M)
    {
    	int cnt = 0;
        for(int i=0; i<M; i++)
        {
        	for(int j=0; j<N; j++)
        	{
        		if(s[i]==t[j])
        		{
        			cnt++;
        			break;
        		}
        	} 
        }
        if(cnt==N) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else cout << "No" << endl;
	return 0;
}

char max_string(string s, int N)
{
	char x = 'a';
	for(int i=0; i<N; i++)
	{
		if(x<s[i]) x = s[i];
	}
	return x;
}

char min_string(string s, int N)
{
	char x = 'z';
	for(int i=0; i<N; i++)
	{
		if(x>s[i]) x = s[i];
	}
	return x;
}

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

ll N, A[100010], S[200010];

// start-point (1-indexed), length
bool d(ll init, ll len) {
    // [lb, ub)
    ll lb = init, ub = N+init, idx = init;
    rep(i,0,3) {
        ll target = S[idx] + len;
        idx = lower_bound(S, S+2*N+2, target) - S;
        if(idx > ub) return false;
    }
    return true;
}

int main() {
    cin >> N;
    rep(i,0,N) cin >> A[i];

    // 1 ... N
    rep(i,0,N) S[i+1] = S[i] + A[i];
    // N+1 ... 2N
    rep(i,0,N) S[i+1+N] = S[i+N] + A[i];
    S[2*N+1] = 1LL << 62;

    ll ans = 0;
    repq(i,1,N) {
        ll ub = (ll)1e15, lb = 0;
        while(ub - lb > 1) {
            ll mid = (ub + lb) / 2;
            if(d(i, mid)) lb = mid;
            else ub = mid;
        }
        ans = max(ans, lb);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5444
sx, sy, tx, ty = map(int, input().split())

ans = 'R'*abs(tx-sx) + 'U'*abs(ty-sy) + 'L'*abs(tx-sx) + 'D'*abs(ty-sy)
ans += 'D'*1 + 'R'*abs(tx-sx+1) + 'U'*abs(ty-sy+1) + 'L' * 1 + 'U' * 1 + 'L' * abs(tx-sx+1) + 'D'*abs(ty-sy+1) + 'R'*1

print(ans)


Measured memory_bytes: 3060
from collections import defaultdict
N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))
dic = defaultdict(int)
for d in D:
  dic[d] += 1
for t in T:
  if dic[t] > 0:
    dic[t] -= 1
  else:
    print("NO")
    exit()
print("YES")

Measured memory_bytes: 41700
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define mp make_pair
#define INF 1e9

void init(){
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}

int tel(vector<ll> &a,ll k,int temp){
    if(k==0){
        return a[temp];
    }
    int ans=a[tel(a, k-1,temp)];
    return ans ;
}

int main(void){
    init();
    ll n,k;
    cin>>n>>k;
    vector<ll>a(n+1);
    vector<ll>label(n+1);
    rep(i,n){
        cin>>a[i+1];
    }
    int temp=1,m1=0;
    while(1){
        if(label[temp]==1)break;
        label[temp] = 1;
        int next=a[temp];
        temp=next;
        m1++;
    }
    int temp2=1,m2=0;
    while(1){
        if(temp2==temp)break;
        int next=a[temp2];
        temp2=next;
        m2++;
    }

    if(k<=m2){
        cout << tel(a, k - 1, 1) << endl;
    }else{
        k = m1 + (k - m2) % (m1-m2);
        cout << tel(a, k - 1, 1) << endl;
    }
}


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

using namespace std;

typedef long long ll;
#define fore(i, s, e) for(ll i = s; i < e; i++)

const int N = 2e5;
ll n, w, h[N][2], dp[100][N];

ll calc(int i, int w) {
    if(i == n) return 0;
    ll &r = dp[i][w];
    if(r != -1) return r;
    ll res = -1e18;
    if(w >= h[i][0]) res = max(h[i][1] + calc(i + 1, w - h[i][0]), calc(i + 1, w));
    if(w < h[i][0]) res = calc(i + 1, w);
    return r = res;
}

int main() {
    cin >> n >> w;
    fore(i, 0, n) cin >> h[i][0] >> h[i][1];
    memset(dp, -1, sizeof dp);
    cout << calc(0, w) << endl;
    return 0;
}

Measured memory_bytes: 157952
#include<bits/stdc++.h>
#define GPA 4
#define ROLLMAN endl

using namespace std;
typedef int OTAKU;

OTAKU main(){
  
  OTAKU roll[ GPA ], man[ GPA ];

  for(OTAKU i = 0; i < 4; i++)cin>>roll[i];
  for(OTAKU i = 0; i < 2; i++)cin>>man[i];
  
  sort(roll,roll+4);
  sort(man,man+2);
  
  OTAKU Happy_Birthday=0;
  
  for(OTAKU i = 3; i > 0; i--) Happy_Birthday += roll[i];
  Happy_Birthday += man[1];
  
  cout << Happy_Birthday << ROLLMAN;
  return GPA-4;
}

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


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.flush();
	ll ans=0;
	ll n;
	cin>>n;
	
	ll x[10000],i,sum=0;
	for(i=0;i<n;i++)
	{
		cin>>x[i];
		sum+=x[i];
		}
	if(sum%n!=0)
	{
		
	ll ans1=0;
	ll ans2=0;
	ll av=sum/n;
	ll p1=av;
	ll p2=p1+1;
	for(i=0;i<n;i++)
	{
		ans1+=((p1-x[i])*(p1-x[i]));
		ans2+=((p2-x[i])*(p2-x[i]));
	}
	ans=min(ans1,ans2);
	}
	else{
		for(i=0;i<n;i++)
	{
		ans+=(((n*x[i])-sum)*((n*x[i])-sum));
		}
	ans=ans/(n*n);
}
	cout<<ans<<endl;
	
	
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
#define mp make_pair
using namespace std;
vector<ll> invs,invsum;
ll inve(ll x){
	ll pw = mod - 2;
	ll res = 1;
	vector<ll> dbl;
	dbl.pb(x);
	for(int i=1;i<=30;i++){
		dbl.pb( (dbl[i-1]*dbl[i-1])%mod );
	}
	for(int i=0;i<=30;i++){
		if(pw%2==1){
			res *= dbl[i];
			res %= mod;
		}
		pw = pw/2;
	}
	return res;
}
ll fact(ll x){
	ll res=1;
	for(int i=1;i<=x;i++){
		res *= i;
		res %= mod;
	}
	return res;
}
ll calc(ll pos, ll num){
	return (invsum[pos]+invsum[num-pos+1]-1)%mod;
}
int main(){
	ll n;
	cin>>n;
	vector<ll> a;
	ll fn = fact(n);
	invs.pb(0);
	invsum.pb(0);
	for(int i=1;i<=n;i++){
		invs.pb(inve(i));
		invsum.pb( (invsum[i-1]+invs[i])%mod );
	}
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		a.pb(x);
	}
	ll ans = 0;
	for(int i=0;i<n;i++){
		ll tmp = a[i] * calc(i+1,n);
		ans += tmp;
		ans %= mod;
	}
	ans *= fn;
	ans %= mod;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3308
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		int a = sc.nextInt();
		int b = sc.nextInt();
		String u = sc.next();

		if (u.equals(s)) {
			a = a - 1;
		} else if (u.equals(t)) {
			b = b - 1;
		}
		System.out.println(a + " " + b);
	}
}

Measured memory_bytes: 23380