akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        if(a<=b){
            System.out.println("unsafe");
        }
        else{
            System.out.println("safe");
        }

    }
}


Measured memory_bytes: 35592
MOD = 1000000007
n, k = gets.split.map(&:to_i)
edges = []
(n - 1).times { edges << gets.split.map(&:to_i) }
graph = Array.new(n + 1) { Array.new }
edges.each do |from, to|
  graph[from] << to
  graph[to] << from
end
ans = [k]
colors = k - 1
#[from, to]
queue = [[1, 1]]
until queue.empty?
  from, current = queue.shift
  rest = colors
  graph[current].each do |to|
    next if from == to
    ans << rest
    rest -= 1
    queue << [current, to]
  end
  colors = k - 2
end
puts ans.inject(1) { |res, num| res * num % MOD }


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

int main(){
    int a,b,d,r;
    double f;
    cin >> a >> b;
    
    d = a / b;
    
    r = a % b;

    f = ((double) a) / ((double) b);
    
    cout << d << " " << r << " " << fixed << setprecision(5) << f <<endl;
    
    return 0;
}


Measured memory_bytes: 3276
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()


int main() {
    int n;
    cin>>n;
    ll ans=0;
    for(int i=1;i<=n;i++){
        if(i%3==0 || i%5==0) continue;
        ans+=i;
    }

    cout<<ans<<endl;
}



Measured memory_bytes: 3600
#include <stdio.h>

int main(void)
{
	int n;
	
	while (scanf("%d", &n) && n){
		int i;
		int sum;
		
		sum = 0;
		for (i = 0; i < n / 4; i++){
			int a;
			scanf("%d", &a);
			sum += a;
		}
		
		printf("%d\n", sum);
	}
	
	return (0);
}

Measured memory_bytes: 596
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		HashMap<Long, Integer> set = new HashMap<>();
		int n = sc.nextInt();
		for (int i = 0; i < n; ++i) {
			long d = sc.nextLong();
			if (set.containsKey(d)) {
				set.put(d, set.get(d) + 1);
			} else {
				set.put(d, 1);
			}
		}

		int m = sc.nextInt();
		boolean f = true;
		for (int i = 0; i < m; ++i) {
			long t = sc.nextLong();
			if (set.containsKey(t)) {
				if (set.get(t) > 1) {
					set.put(t, set.get(t) - 1);
				} else {
					set.remove(t);
				}
			} else {
				f = false;
			}
		}
		if (f) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


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

int main()
{
  	string s;
	cin >> s;
  
  //vector<int> data(s.length());

  int ret = 0;
for(size_t i=0; i<s.length(); ++i) {
    int temp = s[i]-'0';
  	ret += temp;
}
  if(ret % 9 == 0){
    cout << "Yes";
  }
  else {
    cout << "No";
  }
  
    return 0;
}

Measured memory_bytes: 3696
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;

long long int combination2(long long int n){
	return n*(n-1)/2;	
}

int main()
{
	map<int,int> numMapB;
	int N;
	cin>>N;
	int *a = new int[N];
	for(int i = 0; i < N; i++){
		cin>>a[i];
		if( numMapB.count(a[i]) == 0){
			numMapB.insert(make_pair(a[i],1));
		}else{
			numMapB[a[i]]= numMapB[a[i]] + 1;
		}
	}
	long long int sum = 0;
	for(auto itr = numMapB.begin(); itr != numMapB.end();itr++){
		//cout<< itr->first<<":"<<itr->second<<endl;
		sum += combination2(itr->second);
	}
	for(int i = 0;i < N;i++){
		cout<< sum - combination2(numMapB[a[i]]) + combination2(numMapB[a[i]] - 1)<<endl;
	}
	return 0;
}



Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (ll i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (ll i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--)
#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define CHMAX(a,b) a = max(a,b)
#define CHMIN(a,b) a = min(a,b)
#define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl;
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define e1 first
#define e2 second
#define newline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;
const double pi = 3.141592653589793;
const VI dx = {1, 0, -1, 0};
const VI dy = {0, 1, 0, -1};

int k;

string ans()
{
    deque<string> q;
    REP(i,9) {
        string tmp = "";
        tmp += (char)('1' + i);
        q.push_back(tmp);
    }

    REP(i,k-1) {
        string x = q.front();
        q.pop_front();
        if (x[x.size()-1] != '0')
            q.push_back(x + (char)(x[x.size()-1] - 1));

        q.push_back(x + (char)(x[x.size()-1]));

        if (x[x.size()-1] != '9')
            q.push_back(x + (char)(x[x.size()-1] + 1));
    }

    return q.front();
}

int main()
{
    cin>>k;
    cout<<ans()<<endl;

    return 0;
}


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

int main(){
  int N; cin>>N;
  vector<int> h(N);
  for(int i=0;i<N;i++)
    cin>>h[i];
  vector<int> dp(N);
  dp[1] = abs(h[0] - h[1]);
  for(int i=2;i<N;i++){
    int cost = dp[i-2] + abs(h[i] - h[i-2]);
    int costt = dp[i-1] + abs(h[i] - h[i-1]);
    dp[i] = min(cost,costt);
  }
  cout<<dp[N-1]<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
	int n,p[4][13];
	for (int a= 0;a < 4;a++){
		for (int b = 0; b < 13;b++){
			p[a][b] = 1;
		}
	}
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		char mark;
		int number;
		cin >> mark >> number;
		number--;
		if (mark == 'S')
		{
			p[0][number] = 0;
		}
		else if (mark == 'H')
		{
			p[1][number] = 0;
		}
		else if (mark == 'C')
		{
			p[2][number] = 0;
		}
		else if (mark == 'D')
		{
			p[3][number] = 0;
	    }

		
	}

	for (int i = 0; i < 4; i++)
	{
		for (int j = 0; j < 13; j++)
		{
			if (p[i][j] == 1)
			{
				if (i == 0)cout << "S " << j+1 << endl;
				if (i == 1)cout << "H " << j+1 << endl;
				if (i == 2)cout << "C " << j + 1 << endl;
				if (i == 3)cout << "D " << j + 1 << endl;
			}
		}

	}
	return 0;
}

Measured memory_bytes: 3044
S = input()
T = input()

i = 0
j = 0

sdict = {}
tdict = {}

slist = []
tlist = []

for s in S:
    if s in sdict:
        slist.append(sdict[s])
    else:
        sdict[s] = i
        slist.append(i)
        i += 1


for t in T:
    if t in tdict:
        tlist.append(tdict[t])
    else:
        tdict[t] = j
        tlist.append(j)
        j += 1

if slist == tlist:
    print("Yes")
else:
    print("No")
    


Measured memory_bytes: 6832
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int K = sc.nextInt();
    	int[] hi = new int[N];
    	for (int i = 0; i < N; i++) {
    		hi[i] = sc.nextInt();
    	}
    	Arrays.sort(hi);
    	int count = 0;
    	int min = 0;
    	for (int i = 1; i < K; i++) {
    		count += hi[i] - hi[i-1];
    	}
    	min = count;
    	for (int i = K; i < N; i++) {
    		count += (hi[i] - hi[i-1]) - (hi[i-(K-1)] -hi[i-K]);
    		if (count < min) {
    			min = count;
    		}
    	}
    	System.out.println(min);
    }
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int n;
    cin >> n;

    vector<int> v(n);
    rep(i, n){
        cin >> v[i];
    }

    int ans = INF;
    for (int i = -100; i <= 100; ++i) {
        int sum = 0;
        rep(j, n){
            sum += (v[j] - i) * (v[j] - i);
        }

        ans = min(ans, sum);
    }

    cout << ans << endl;


    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cwchar>
#include <cwctype>
#include <exception>
#include <locale>
#include <numeric>
#include <new>
#include <stdexcept>
#include <limits>
#include <valarray>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <utility>
#include <bitset>
#include <algorithm>
#include <functional>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 1e9 + 7;

int n, p[200005];
int pos[200005];

int main()
{
	scanf("%d", &n);
	rep1(i, n) scanf("%d", &p[i]);
	rep1(i, n) pos[p[i]] = i;
	int tot = 0, ans = 0;
	rep1(i, n + 1)
	if(pos[i] > pos[i - 1]) tot ++;
	else {
		ans = max(ans, tot);
		tot = 1;
	}
	printf("%d\n", n - ans);
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    cout << s << (s.back() == 's' ? "es" : "s") << '\n';
}


Measured memory_bytes: 3604
h,w=map(int,input().split())
d=[0]*26
for i in range(h):
    b=list(input())
    for j in range(w):
        d[ord(b[j])-ord("a")]+=1
s=0
t=0
r=0
for i in range(26):
    if d[i]%4==0:
        s+=d[i]//4
    elif d[i]%2==0:
        s+=d[i]//4
        t+=(d[i]%4)//2
    else:
        s+=d[i]//4
        t+=(d[i]%4)//2
        r+=1
if h%2==0 and w%2==0:
    if t==0 and r==0:
        print("Yes")
    else:
        print("No")
elif h%2==1 and w%2==1:
    if r==1 and(w+h-2-2*t)>=0 and (w+h-2-2*t)%4==0:
        print("Yes")
    else:
        print("No")
else:
    q=(w if h%2==1 else h)
    if q-2*t>=0  and (q-2*t)%4==0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

int main(){
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    set<int> w, s;
    rep2(i, 0, F){
        rep2(j, 0, F){
            if(i-j*A >= 0 && (i-j*A)%B == 0) w.insert(i);
            if(i-j*C >= 0 && (i-j*C)%D == 0) s.insert(i); 
        }
    }
    int ans1 = 1, ans2 = 0;
    for(int u: w) for(int v: s){
        if(100*u+v <= F && v <= u*E){
            if(ans1*v >= ans2*(100*u+v)) ans1 = 100*u+v, ans2 = v;
        }
    }
    cout << ans1 << ' ' << ans2 << endl;
}

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

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int n = sc.nextInt();
        int[] d = new int[n];
        int[] cnt = new int[n];

        for (int i = 0; i < n; i++) {
            d[i] = sc.nextInt();
            if (i == 0 && d[i] != 0) {
                System.out.println(0);
                return;
            }
            cnt[d[i]]++;
        }

        if (cnt[0] != 1) {
            System.out.println(0);
            return;
        }

        int maxIndex = 0;
        for (int i = n-1; i > 0; i--) {
            if (cnt[i] > 0) {
                maxIndex = i;
                break;
            }
        }

        long ans = 1;
        for (int i = 1; i <= maxIndex; i++) {
            ans = ans * exp(cnt[i-1], cnt[i]) % 998244353;
        }

        System.out.println(ans % 998244353);
    }


    // aのb乗を計算する(998244353で割った値を返す)
    static long exp(int a, int b) {
        long tmp = a;
        for (int i = 2; i <= b; i++) {
            tmp = tmp * a % 998244353;
        }

        return tmp % 998244353;
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

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

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

Measured memory_bytes: 35848
import java.util.Scanner;

public class Main
{
	public static void main(String arg[])
	{
		Scanner sc = new Scanner(System.in);
		int n=9;
		while(n-->0)
		{
		String  cla = sc.next();
		int be = sc.nextInt();
		int af = sc.nextInt();
		int sum =be +af;
		System.out.print(cla+" ");
		System.out.print(sum+" ");
		System.out.println(be*200+af*300);
		}	
	}
}

Measured memory_bytes: 12000
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
#include <cstdio>
#include <complex>
#include <cstring>

using namespace std;

void solve()
{
    int n;
    vector<int> a, b;
    cin >> n;
    for(int i = 0; i < n; ++ i) {
        int x;
        cin >> x;
        a.push_back(x);
    }
    for(int i = 0; i < n; ++ i) {
        int x;
        cin >> x;
        b.push_back(x);
    }
    long long sum = 0;
    for(int i = 0; i < n; ++ i) {
        if (a[i] > b[i]) {
            sum -= a[i] - b[i];
        } else {
            sum += (b[i] - a[i]) / 2;
        }
    }
    if (sum >= 0)
        cout << "Yes" << endl;
    else cout << "No" << endl;
}

int main()
{
    solve();
    return 0;
}


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

using namespace std;

long long n,aa[169],a[169],inf=1e18;

int main()
{
	long long rr,i,j,sm,z=-inf;
	
	srand(time(NULL));
	scanf("%lld",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%lld",aa+i);
	}
	for(rr=0;rr<100000;rr++)
	{
		for(i=1;i<=n;i++)
		{
			a[i]=aa[i];
		}
		for(i=n;i;i--)
		{
			sm=0;
			for(j=i;j<=n;j+=i)
			{
				sm+=a[j];
			}
			if(sm<=0^rand()%10==0)
			{
				for(j=i;j<=n;j+=i)
				{
					a[j]=0;
				}
			}
		}
		sm=0;
		for(i=1;i<=n;i++)
		{
			sm+=a[i];
		}
		z=max(z,sm);
	}
	printf("%lld\n",z);
}

Measured memory_bytes: 3768
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <tuple>
#include <numeric>
#include <cstdio>
#include <cmath>
#include <cstdlib>
using namespace std;
using ll = long long;
const int INF = 1000000009;
const ll LINF = 1e18;

int main() {
  int n; cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans += (n-1) / i;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3168
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

for i in range(1,K+1):
    x=combinations_count(K-1,i-1)
    if N-K+1>=i:
        y=combinations_count(N-K+1,i)
        print((x*y)%1000000007)
    else:
        print(0)
        




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


using namespace std;

int n, k;
int h[200010];

bool compare(const int &a, const int &b) {
	return a > b;
}

int main()
{
	scanf("%d%d", &n, &k);
	
	for (int i = 0 ; i < n ; i++)
		scanf("%d", &(h[i]));
		
	sort(h, h + n, compare);
	
	long long ans = 0;
	for (int i = k ; i < n ; i++) {
		ans = ans + h[i];
	}
	
	printf("%lld\n", ans);
	
	return 0;
}



Measured memory_bytes: 896
n = int(input())

m = 100000
a = [6]
b = [9]

while True:
    d = a[-1] * a[0]
    if d > m:
        break
    a.append(a[-1] * a[0])

while True:
    d = b[-1] * b[0]
    if d > m:
        break
    b.append(d)

c = a + b
c.sort()
c.reverse()
dp = {}

def solve(n, i):
    if i == len(c):
        return n
    if (i, n) in dp:
        return dp[(i, n)]
    if n < c[i]:
        dp[(i, n)] = solve(n, i+1)
        return solve(n, i+1)

    temp = []
    l = 9 if c[i] % 9 == 0 else 6
    l = min(l, n//c[i]+1)
    for j in range(l):
        temp.append(solve(n-j*c[i], i+1)+j)
    dp[(i, n)] = min(temp)
    return dp[(i, n)]

print(solve(n, 0))

Measured memory_bytes: 8660
L,R = map(int,input().split())

if R-L > 2019:
  print(0)
  exit()
  
res = 100000
for i in range(L,R):
  ii = i%2019
  for j in range(i+1,R+1):
    j %= 2019
    res = min(res,ii*j%2019)
  
print(res)

Measured memory_bytes: 9004
<?php

fscanf(STDIN, '%s', $S);
if (substr_count($S, 'a') === 1 && substr_count($S, 'b') === 1 && substr_count($S, 'c') === 1) {
    echo 'Yes';
} else {
    echo 'No';
}

echo PHP_EOL;


Measured memory_bytes: 16128
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 1000;
char tab[MAXN][MAXN];



struct pr_Q
{
	int x , y , t;
	bool operator < (const pr_Q & autre) const
	{
		return t > autre.t;
	}
};
bool vu[MAXN][MAXN];
int nbLignes , nbColonnes;

bool dedans(int x , int y)
{
	if (x < 0 || x >= nbLignes || y < 0 || y >= nbColonnes )
	{
		return false;
	}
	return true;
}

int D[4][2] = {{1 , 0} , {-1 , 0} , {0 , 1} , {0 , -1}};
int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> nbLignes >> nbColonnes;
	int xD , yD , xF , yF;
	cin >> xD >> yD >> xF >> yF;
	xD--; yD--; xF--; yF--;
	for (int i = 0 ; i < nbLignes ; i++)
	{
		for (int j = 0 ; j < nbColonnes ; j++)
		{
			cin >> tab[i][j];
		}
	}
	priority_queue<pr_Q> Q;
	if (tab[xD][yD] == '#')
	{
		cout<<-1<<endl;
		exit(0);
	}
	Q.push({xD , yD , 0});
	while (!Q.empty())
	{
		auto actu = Q.top(); Q.pop();
		if (vu[actu.x][actu.y]) continue;
		vu[actu.x][actu.y] = true;
		if (actu.x == xF && actu.y == yF)
		{
			cout<<actu.t<<endl;
			exit(0);
		}
		for (int i = 0 ; i < 4 ; i++)
		{
			int nx = actu.x + D[i][0];
			int ny = actu.y + D[i][1];
			if (dedans(nx , ny) && !vu[nx][ny] && tab[nx][ny] == '.')
			{
				Q.push({nx , ny , actu.t});
			}
		}
		for (int i = -2 ; i <= 2 ; i++)
		{
			for (int j = -2 ; j <= 2 ; j++)
			{
				int nx = actu.x + i;
				int ny = actu.y + j;
				if (dedans(nx , ny) && !vu[nx][ny] && tab[nx][ny] == '.')
				{
					Q.push({nx , ny , actu.t + 1});
				}
			}
		}
	}
	cout<<-1<<endl;
}

Measured memory_bytes: 8036
def check(A):
    for i in range(3):
        if A[i][0] == A[i][1] == A[i][2] == -1:
            return True
        if A[0][i] == A[1][i] == A[2][i] == -1:
            return True
    if A[0][0] == A[1][1] == A[2][2]:
        return True
    if A[2][0] == A[1][1] == A[0][2]:
        return True
    return False


def resolve():
    A = [list(map(int, input().split())) for i in range(3)]
    N = int(input())
    for _ in range(N):
        n = int(input())
        for i in range(3):
            for j in range(3):
                if A[i][j] == n:
                    A[i][j] = -1
    print("Yes" if check(A) else "No")


if __name__ == "__main__":
    resolve()


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> table(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> table.at(i).at(j);
    }
  }

  vector<bool> A(H, true);
  int a = 0;
  for (int i = 0; i < H; i++) {
    int x = 0;
    for (int j = 0; j < W; j++) {
      if (table.at(i).at(j) == '#') x++;
    }
    if (x == 0) {
      A.at(i) = false;
      a++;
    }
  }

  vector<bool> B(W,true);
  int b = 0;
  for (int i = 0; i < W; i++) {
    int x = 0;
    for (int j = 0; j < H; j++) {
      if (table.at(j).at(i) == '#') x++;
    }
    if (x == 0) {
      B.at(i) = false;
      b++;
    }
  }

  int c = 0;
  vector<vector<char>> ans(H);
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (A.at(i) && B.at(j)) {
        ans.at(c).push_back(table.at(i).at(j));
      }
    }
    if (ans.at(c).size() != 0) c++;
  }

  for (int i = 0; i < H - a; i++) {
    for (int j = 0; j < W - b; j++) {
      cout << ans.at(i).at(j);
    }
    cout << endl;
  }
}


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

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        String s = sc.next();

        if (s.equals("abc")
                || s.equals("acb")
                || s.equals("bac")
                || s.equals("bca")
                || s.equals("cab")
                || s.equals("cba")) {
            out.println("Yes");
        } else {
            out.println("No");
        }
        
        out.flush();
    }
}

// https://qiita.com/p_shiki37/items/a0f6aac33bf60f5f65e4
class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

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

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

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

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

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

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

Measured memory_bytes: 22612
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner stdin = new Scanner(System.in);
    int i = 1;
    while (true) {
      int x = stdin.nextInt();
      if (x == 0) {
        break;
      }
      System.out.printf("Case %d: %d%n", i++, x);
    }
  }

}

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

const ll MOD = 1e9+7;

int main(){
  
  ll N; cin >> N;
  
  vector<ll> A(N);
  
  for(ll i = 0; i < N; i++){ cin >> A[i];}
  
  ll ans = 0;
  
  for(ll i = 60; i >= 0; i--){ 
    
    ll x = 0;
    
   for(ll j = 0; j < N; j++){ 
     if( (A[j] >> i) & 1LL){ x++;}
   }
    
    ll tmp = (1LL << i);
    tmp %= MOD;
    ll res = x*(N-x);
    res %= MOD;
    tmp *= res;
    tmp %= MOD;
    ans += tmp;
    ans %= MOD;
  }

  cout << (ans+MOD)%MOD << endl;
  
  return 0;
}
    

Measured memory_bytes: 2560
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define forn(i, n) for (int i = 0; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()


using namespace std;
const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
    freopen("a.in","r",stdin);
    #endif
    ll n,m;
    cin>>n>>m;
    cout<<n*(n-1)/2+m*(m-1)/2;




}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
  private static void solve(int n, int[][] students) {
    int[][] hands = new int[n][n];
    for (int i = 0; i < n; i++) {
      int min = Integer.MAX_VALUE;
      List<Integer> indices = new ArrayList<>();
      for (int j = 0; j < n; j++) {
        if (students[i][j] < min) {
          min = students[i][j];
          indices.clear();
          indices.add(j);
        } else if (students[i][j] == min) {
          indices.add(j);
        }
      }
      for (int index : indices) hands[i][index]++;
    }
    for (int j = 0; j < n; j++) {
      int max = 0;
      List<Integer> indices = new ArrayList<>();
      for (int i = 0; i < n; i++) {
        if (students[i][j] > max) {
          max = students[i][j];
          indices.clear();
          indices.add(i);
        } else if (students[i][j] == max) {
          indices.add(i);
        }
      }
      for (int index : indices) hands[index][j]++;
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (hands[i][j] == 2) {
          System.out.println(students[i][j]);
          return;
        }
      }
    }
    System.out.println(0);
  }
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    while (true) {
      int n = Integer.parseInt(sc.nextLine());
      if (n == 0) break;
      int[][] students = new int[n][n];
      for (int i = 0; i < n; i++) {
        String[] cols = sc.nextLine().split(" ");
        for (int j = 0; j < n; j++) {
          students[i][j] = Integer.parseInt(cols[j]);
        }
      }
      solve(n, students);
    }
    sc.close();
  }
}



Measured memory_bytes: 25988
import collections
def main():
    n = int(input())
    A=[int(i) for i in input().split()]
    dd = collections.defaultdict(int)
    k = sum(A)
    res = []
    q = int(input())
    for i in A:
        dd[i]+=1
    for i in range(q):
        b,c=map(int, input().split())
        k = k - (b*dd[b])
        k = k + ((c)*(dd[b]))
        dd[c]=dd[c]+dd[b]
        dd[b]=0

        res.append(k)
    for i in res:
        print(i)


if __name__ == '__main__':
    main()


Measured memory_bytes: 26992
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A[] = {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 N;
  cin >> N;
  cout << A[N-1] << endl;
}


Measured memory_bytes: 256
A = []
while True:
    a, op, b = input().split()
    if op == '+':
        c = int(a) + int(b)
    elif op == '-':
        c = int(a) - int(b)
    elif op == '*':
        c = int(a) * int(b)
    elif op == '/':
        c = int(a) // int(b)
    elif op == '?':
        break
    A.append(c)
for i in range(len(A)):
    print(A[i])


Measured memory_bytes: 5596
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;

int main(){
	long long int a,b,ans=0;
	cin>>a>>b;
	ans=a+b+1;
	ans=ans/2;
	cout<<ans<<endl;
	
	return 0;
	
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<numeric>
#include<sstream>
#include<cmath>
using namespace std;
long long int mod = 1e9+7;

int main(){
  int n; string s; cin >> n >> s;

  int cnt = 1e9;
  vector<int> w(n+1, 0);
  vector<int> b(n+1, 0);
  for(int i=1; i<=n; i++) {
    w[i] = w[i-1];
    b[i] = b[i-1];
    if(s[i-1] == '.') w[i]++;
    if(s[i-1] == '#') b[i]++;
  }

  for(int i=0; i<n; i++) {
    int cw = b[i];
    int cb = w[n]-w[i+1];
    cerr << cw << " " << cb << endl;
    cnt = min(cnt, cw+cb);
  }
  cout << cnt << endl;

  return 0;
}


// EOF


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

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

using ll = long long;

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

int main() {
  ll A, B, N;
  cin >> A >> B >> N;
  ll ans;
  if(B-1<=N) {
    ans = (A*(B-1))/B;
  }
  else {
    ans = (A*N)/B;
  }
  cout<< ans << endl;
}

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

string S;
int N;

bool check(int num) {
  char tmp = S[N - num];
  for (int i = N - num; i < num; i++) {
    if (S[i] != tmp) {
      return false;
    }
  }
  return true;
}

void solve() {
  int min = (N + 1) / 2;
  int max = N + 1;
  while (min < max - 1) {
    int mid = (min + max) / 2;
    if (check(mid)) {
      min = mid;
    } else {
      max = mid;
    }
  }
  cout << min << endl;
}

int main() {
  cin >> S;
  N = S.length();

  solve();
  return 0;
}


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

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item = U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}

fn gcd(n: usize, m: usize) -> usize {
    match (n, m) {
        (n, 0) => n,
        (n, m) => gcd(m, n%m),
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let K: usize = sc.get();
    if N <= K {
        println!("{}", min(N, K - N));
    } else {
        if N % K == 0 {
            println!("0");
        } else {
            println!("{}", min(N%K, K - (N%K)));
        }
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
bool isPrime(int x)
{
	for(int i=2; i<x; ++i)
		if(x%i==0) return false;
	return true;
}
int main()
{
	int N; scanf("%d", &N);
	int tp = 0;
	for(int i=6;tp < N;i += 5)
	{
		if(isPrime(i))
		{
			printf("%d ", i);
			++tp;
		}
	}
	return 0;
}

Measured memory_bytes: 384
N=int(input())
t=[0]*N
x=[0]*N
y=[0]*N
for i in range(N):
    t[i],x[i],y[i]=(int(z) for z in input().split())

for i in range(N): #i番目の目的に到達まで
    if i ==0:
        t0,x0,y0=0,0,0
        t1,x1,y1=t[0],x[0],y[0]
    else:
        t0,x0,y0=t[i-1],x[i-1],y[i-1]
        t1,x1,y1=t[i],x[i],y[i]
    dt=t1-t0
    dx=x1-x0
    dy=y1-y0
    if (dx+dy)%2==0 and (dt%2)==0 and (dx+dy)<=dt:
        # print("dx,dy,dt=",dx,dy,dt)
        continue
    elif (dx+dy)%2==1 and (dt%2)==1 and (dx+dy)<=dt:
        # print("dx,dy,dt=",dx,dy,dt)
        continue
    else:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 11636
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define rd(x) cin >> x;
#define rda(a,n) for(int i=1;i<=n;i++) cin >> a[i];
#define wr(x) cout << x << ' ';
#define wrl(x) cout << x << '\n';
#define wra(a,n) for(int i=1;i<=n;i++) cout << a[i] << ' '; cout << '\n';
#define lg length()
#define pb(x) push_back(x)
ifstream in("file.in");
ofstream out("file.out");
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
struct comp{
    bool operator()(long long a, long long b){
        return a>b;
    }
};

long long n,t,a,b,p,s[100005];

int main(){
    ios_base :: sync_with_stdio(0);
    cin >> n >> a >> b;
    for(int i=1;i<=n;i++){
        cin >> s[i];
    }
    long long l=0,r=1e9;
    while(l!=r){
        long long mid=(l+r)/2;
        t=0;
        for(int i=1;i<=n;i++){
            t+=max(0ll,(s[i]-b*mid)/(a-b));
            if((s[i]>b*mid) && (s[i]-b*mid)%(a-b)) t++;
        }
        if(mid<t) l=mid+1;
        else r=mid;
    }
    cout << l;
}


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

struct Color{double L,a,b;};
double dist(Color A,Color B)
{
  return (A.L-B.L)*(A.L-B.L)+(A.a-B.a)*(A.a-B.a)+(A.b-B.b)*(A.b-B.b);
}

int numofbits(long bits)
{
  bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
  bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
  bits = ((bits >> 4) + bits) & 0x0f0f0f0f;
  bits += bits >> 8;
  return (bits + (bits >> 16)) & 0xff;
}


int main()
{
  int N,M;
  double ans;
  vector<Color>color;
  cin>>N>>M;
  for(int i=0;i<N;i++){
    Color c;
    cin>>c.L>>c.a>>c.b;
    color.push_back(c);
  }
  if(M==1){
    ans=0.0;
    printf("%.20f\n",ans);
    return 0;
  }
  for(int i=0;i<(1<<N);i++){
    if(numofbits(i)!=M)continue;
    vector<Color>used;
    for(int j=0;j<N;j++)if( i&(1<<j) )used.push_back(color[j]);
    double sum=0.0;
    for(int j=0;j<M;j++)for(int k=j+1;k<M;k++)sum+=dist(used[j],used[k]);
    ans=max(ans,sum);
  }
  printf("%.20f\n",ans);
}

Measured memory_bytes: 932
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  if (b < a) swap(a, b);
  if (a == b) cout << 2*b;
  else cout << 2*b-1 << endl;
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <stdlib.h>
#include <stdio.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl;
#define peintD(a) cout << setprecision(10) << ans << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<int>& a,int n);

int n,m;
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


signed main(){
    cin >> n >> m;
    vec(a,m+1);
    input(a,m);
    a[m] = -1;
    int piv = 0;
    vec(b,n+1);
    REP(i,n+1){
        b[i] = 1;
    }
    if(a[piv] == 1){
        piv++;
        b[1] = 0;
    }
    FOR(i,2,n+1){
        if(a[piv] == i){
            piv++;
            b[i] = 0;
        }
        else{
            b[i] = b[i-1] + b[i-2];
            b[i] %= max_int;
        }
    }
    print(b[n]);


    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<int>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define mod 1000000007
#define rep(i,n) for(int i=0;(i)<(n);i++)
typedef long long ll;
using namespace std;
ll fact(ll n){
    if(n<=1) return 1;
    else return ((n%mod)*fact(n-1))%mod;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll modinv(ll a) {
    return modpow(a, mod - 2);
}
int main(void){
    ll n; cin >> n;
    ll x[100000];
    rep(i,n) cin >> x[i];
    ll p[100000]; p[0] = fact(n-1);
    ll ans = 0;
    rep(i,n-2){
        p[i+1] = (p[i] + p[0]*modinv(i+2))%mod;
        ans = (ans + ((x[i+1]-x[i]) * p[i])%mod)%mod;
    }
    ans = (ans + ((x[n-1]-x[n-2]) * p[n-2])%mod)%mod;
    cout << ans << endl;
}



Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;




int main() {
	lli Q, H, S, D, N;
	cin >> Q >> H >> S >> D;
	cin >> N;
	Q *= 4;
	H *= 2;
	lli use = S;
	if (Q <= H && Q <= S) {
		use = Q;
	}
	else if (H <= Q && H <= S) {
		use = H;
	}
	else if(S<=Q&&S<=H){
		use = S;
	}

	if (use * 2 <= D) {
		cout << N * use << endl;
	}
	else {
		cout << (N / 2) * D + (N % 2) * use << endl;
	}
	return 0;
}


Measured memory_bytes: 256
S= input()
alpha = [chr(i) for i in range(ord('a'), ord('z')+1)]
used = [0] * 26
for i in range(len(S)):
    for j in range(26):
        if S[i] == alpha[j]:
            used[j] = 1
            break
if 0 not in used:
    if S == 'zyxwvutsrqponmlkjihgfedcba':
        print(-1)
    else:
        remvid = []
        for x in range(25,0,-1):
            remvid.append(alpha.index(S[x]))
            if max(remvid) > alpha.index(S[x-1]):
                remvid.sort()
                tmp = 0
                while remvid[tmp] < alpha.index(S[x-1]):
                    tmp += 1
                print(S[:x-1]+alpha[remvid[tmp]])
                break
            else:
                continue
else:
    for x in range(26):
        if used[x] == 0:
            print(S+alpha[x])
            break

Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 100000
 
int main(){
    string str;
    int cnt[3];
   
    cin >> str;
 
    int ans = 0, size = str.size();
    const char JOI[3] = {'J','O','I'};
 
    for(int i = 0 ; i < size ; i++){
	if(str[i] == 'J'){
	    memset(cnt,0,sizeof(cnt));
	    for(int j = 0 ; j < 3 ; j++){
		while(i != size && JOI[j] == str[i]){
		    cnt[j]++; i++;
		}
	    } 
	    i--;
	    if(cnt[0] < cnt[1]) continue;
	    if(cnt[1] > cnt[2]) continue;
	    ans = max(ans, *min_element(cnt, cnt + 3));  
	}
 
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3980
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int main(){cout<<fixed<<setprecision(10);
		   string s;
           cin>>s;
           int n=s.size();
           int cnt=0;
           rep(i,0,n){
             cnt+=s[i]-'0';
             cnt%=9;
           }
           Yes(cnt==0);
}

Measured memory_bytes: 3704
#include <iostream>
using namespace std;
int n;
int a[100010];
main() {
    cin>>n;
    for(int i=0;i<n;++i)cin>>a[i+1];
    int ans=0,p=0;
    for(p=1;ans<n&&p!=2;p=a[p],++ans);
    cout<<(p!=2?-1:ans)<<endl;
}

Measured memory_bytes: 4032