akhauriyash/Code-Regression huggingface dataset:
package main

// Next lexicographical permutation algorithm
// https://www.nayuki.io/page/next-lexicographical-permutation-algorithm

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

func stringifyArray(arr []int) string {
	return strings.TrimRight(fmt.Sprintf("%+v", arr)[1:], "]")
}

func swap(a []int, i, j int) {
	t := a[i]
	a[i] = a[j]
	a[j] = t
}

func sortNonIncreasing(a []int, iHead int) {
	n := len(a)
	for i := iHead + 1; i < n; i++ {
		v := a[i]
		j := i - 1
		for j >= iHead && a[j] < v {
			a[j+1] = a[j]
			j--
		}
		a[j+1] = v
	}
}

func sortNonDecreasing(a []int, iHead int) {
	n := len(a)
	for i := iHead + 1; i < n; i++ {
		v := a[i]
		j := i - 1
		for j >= iHead && a[j] > v {
			a[j+1] = a[j]
			j--
		}
		a[j+1] = v
	}
}

func prevPermutation(aOrig []int) (bool, []int) {
	n := len(aOrig)

	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = aOrig[i]
	}

	iHeadIncreasingSuffix := n - 1
	for iHeadIncreasingSuffix > 0 && a[iHeadIncreasingSuffix-1] <= a[iHeadIncreasingSuffix] {
		iHeadIncreasingSuffix--
	}

	if iHeadIncreasingSuffix == 0 {
		return false, []int{}
	}

	iSmallestInSuffix := n - 1
	for a[iHeadIncreasingSuffix-1] <= a[iSmallestInSuffix] {
		iSmallestInSuffix--
	}

	swap(a, iHeadIncreasingSuffix-1, iSmallestInSuffix)
	sortNonIncreasing(a, iHeadIncreasingSuffix)

	return true, a
}

func nextPermutation(aOrig []int) (bool, []int) {
	n := len(aOrig)

	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = aOrig[i]
	}

	iHeadIncreasingSuffix := n - 1
	for iHeadIncreasingSuffix > 0 && a[iHeadIncreasingSuffix-1] >= a[iHeadIncreasingSuffix] {
		iHeadIncreasingSuffix--
	}

	if iHeadIncreasingSuffix == 0 {
		return false, []int{}
	}

	iLargestInSuffix := n - 1
	for a[iLargestInSuffix] <= a[iHeadIncreasingSuffix-1] {
		iLargestInSuffix--
	}

	swap(a, iHeadIncreasingSuffix-1, iLargestInSuffix)
	sortNonDecreasing(a, iHeadIncreasingSuffix)

	return true, a
}

func main() {
	scanner.Split(bufio.ScanWords)

	n := nextInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}

	okPrev, aPrev := prevPermutation(a)
	if okPrev {
		fmt.Println(stringifyArray(aPrev))
	}

	fmt.Println(stringifyArray(a))

	okNext, aNext := nextPermutation(a)
	if okNext {
		fmt.Println(stringifyArray(aNext))
	}
}



Measured memory_bytes: 1156
import sys
from collections import deque, defaultdict
import copy
import bisect
sys.setrecursionlimit(10 ** 9)
import math
import heapq
from itertools import product, permutations,combinations
import fractions

import sys
def input():
	return sys.stdin.readline().strip()

N = int(input())
a = list(map(int, input().split()))

top_list = [0]


for i in range(1, N):

	if a[i] > a[top_list[-1]]:
		top_list.append(i)

num_list = [0]*N
com = []
for i in range(len(top_list)):
	com.append(a[top_list[i]])
com.sort()

for i in range(N - 1, top_list[-1], -1):
	com.append(a[i])
com.sort()

stock = 0
#print(com, top_list, num_list)
for top in range(len(top_list) - 2, -1, -1):
	if top_list[top + 1] - top_list[top] > 10000:
		for i in range(top_list[top + 1] - 1, top_list[top], -1):
			#bisect.insort(com, a[i])
			com.append(a[i])
		com.sort()
	else:
		for i in range(top_list[top + 1] - 1, top_list[top], -1):
			bisect.insort(com, a[i])

	judge = 0
	total = stock*(a[top_list[top + 1]] - a[top_list[top]])
	#print(total, (a[top_list[top + 1]] - a[top_list[top]])*stock,  top)
	while judge == 0:
		x = com.pop()
		if x > a[top_list[top]]:
			total += x - a[top_list[top]]
			stock += 1
		else:
			bisect.insort(com, x)
			judge = 1
	num_list[top_list[top + 1]] = total
	#print(com, top_list, num_list, stock)


num_list[top_list[0]] = sum(a) - sum(num_list)
for i in range(N):
	print(num_list[i])




Measured memory_bytes: 89396
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int mod=(1e9)+7;
int n,k,a[110];
int s[110][100010];
int dp[110][100010];
void F(int &x) {
	if (x<0) x+=mod;
	if (x>=mod) x-=mod;
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n); read(k);
	for (int i=1;i<=n;i++) read(a[i]);
	dp[0][0]=1;
	for (int j=0;j<=k;j++) s[0][j]=1;
	for (int i=1;i<=n;i++)
	for (int j=0;j<=k;j++) {
		int tmp=j-a[i]-1;
		if (tmp<0) dp[i][j]=s[i-1][j];
		else dp[i][j]=s[i-1][j]-s[i-1][tmp]; F(dp[i][j]);
		if (j) s[i][j]=s[i][j-1]+dp[i][j]; else s[i][j]=dp[i][j];
		F(s[i][j]);
	}
	printf("%d\n",dp[n][k]);	
	return 0;
}

Measured memory_bytes: 83840
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

int main(void){
    ll N;
    cin >> N;
    ll ans=0;
    for(ll i=1; i<=N; ++i){
        if(i%3>0 && i%5>0) ans += i;
    }
    cout << ans << endl;
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define rer(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int inf = 1000000000;
const int mod = 1000000007;
const double eps = 1e-9;
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1};

int main() {
	// cin.tie(0); // tie
	// ios::sync_with_stdio(false); // sync
	string s;
	while (cin >> s) {
		int JOI = 0, IOI = 0;
		rep(i, s.size() - 2) {
			string sub = s.substr(i, 3);
			if (sub == "JOI") JOI++;
			else if (sub == "IOI") IOI++;
		}
		cout << JOI << endl;
		cout << IOI << endl;
	}
	return 0;
}

Measured memory_bytes: 1212
n,a,b = map(int,input().split())

total = 0

def sumdigits(i):
    i_sum = 0
    while(i > 0):
        i_sum += i % 10
        i = i // 10
        
    return i_sum

for j in range(1,n+1):
    num = sumdigits(j)
    if(num >= a and num <= b):
        total += j
    
print(total)
    


Measured memory_bytes: 2940
# -*- coding: utf-8 -*-

X, K, D = map(int,input().split())

X_abs = abs(X)
p = X_abs // D

if ( p > K ):
  print( X_abs - D*K )
  
else: # ( -D < ans < D )
  K_p = K-p
  
  if ( K_p % 2 == 0 ):
    print( X_abs - D*p )
    
  else:
    print( - X_abs + D*(p+1) )

Measured memory_bytes: 9076
// 解説を見た　こんなの思い付けない
#include<iostream>
#include<cstring>
using namespace std;

int a[10010], b[10010];

void calc(int x, int y){
    memset(b, 0, sizeof(b));
    x *= 10;
    for(int i = 1; i <= 10009; i++){
        b[i] = x/y;
        x %= y;
        x *= 10;
    }
    int carry = 0;
    for(int i = 10009; i >= 0; i--){
        a[i] += b[i]+carry;
        carry = 0;
        if(a[i] >= 10)   a[i] -= 10, carry++;
    }
}

int main(){
    int n, k, m, r;
    while(cin>>n>>k>>m>>r, n){
        memset(a, 0, sizeof(a));
        calc(1, n);
        if(m == 1){
            for(int i = 1; i <= n-1; i++){
                calc(1, n*i);
            }
        }
        cout << a[0] << ".";
        for(int i = 0; i < r; i++)  cout << a[1+i];
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

int main(){
   string s;
   cin >> s;
   if(s =="Sunny") cout << "Cloudy" <<endl;
   else if(s =="Cloudy") cout << "Rainy" <<endl;
   else cout << "Sunny" <<endl;
   return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
if abs(n-m)>1:
    print(0)
    exit()
mod=10**9+7
from math import factorial
x=factorial(n)
y=factorial(m)
if n==m:
    print(((x%mod)*(y%mod)*2)%mod)
else:
    print(((x%mod)*(y%mod))%mod)

Measured memory_bytes: 4364
#include <cstdio>
#include <algorithm>
#include <iostream>
int a[100001];
int dp[100001];
int main() {
 	int n, m;
    int module = 1000000007;
    long ans = 1;
    dp[0] = dp[1] = 1;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; ++i) {
        scanf("%d", &a[i]);
    }
    if (m == 0) {
        for (int i = 2; i <= n; ++i) {
            dp[i] = (dp[i - 1] + dp[i - 2]) % module;
        }
        printf("%d\n", dp[n]);
        return 0;
    }
    std::sort(a, a + m);
    for (int i = 1; i < m; ++i) {
        if (a[i] - a[i - 1] == 1) {
            printf("0\n");
            return 0;
        }
    }
    a[m] = n + 1;
    int start = 0;
    int current_m = 0;
    int dp_size = 1;
    while (start < n) {
        int range = a[current_m] - start - 1;
        if (dp_size < range) {
            for (int j = dp_size + 1; j <= range; ++j) {
                dp[j] = (dp[j - 1] + dp[j - 2]) % module;
            }
            dp_size = range;
        }
        ans = ans * dp[range] % module;
        start = a[current_m++] + 1;
    }
    printf("%d\n", int(ans));
  	return 0;
}

Measured memory_bytes: 640
n=int(input())
a=list(map(int,input().split()))
su=0
mi=20000000000000000000
for i in range(n):
  su+=a[i]
  
c=0  
for i in range(n):
  c+=a[i]
  left=su-c
  mi=min(mi,max((c-left),(left-c)))

print(mi)


Measured memory_bytes: 26220
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(
			new InputStreamReader(System.in));
		try {
			int n = Integer.parseInt(br.readLine());
			String[] a = br.readLine().split(" ");
			int[] order = new int[n];
			for(int i = 0; i < n; i++) {
				order[Integer.parseInt(a[i]) - 1] = i + 1;
			}
			for(int i = 0; i < n; i++) {
				if(i != 0) {
					System.out.print(" ");
				}
				System.out.print(order[i]);
			}
			br.close();
		} catch(IOException e) {
			e.printStackTrace();
		}
	}
}


Measured memory_bytes: 44584
#include<iostream>
#include<cstdint>
using namespace std;
//実行時間制限TLE
int main(){
  //(A+B)*10^100
  //先頭からN個のボール
  //AAABBBB | AAABBB
  long long int N,A,B;
  //uint64_t N,A,B;
  cin >> N >> A >> B;
  long long int blue_num = N / (A+B);
  long long int reminder = N % (A+B);
  //uint64_t blue_num = N / (A+B);
  //uint64_t reminder = N % (A+B);
  //cout << "blue_num" << blue_num << endl;
  //cout << "reminder" << reminder << endl;
  if(A < reminder){
	//cout << "case 1" << endl;
	cout << blue_num*A+A << endl;
  }
  else{
	//cout << "case 2" << endl;
	cout << blue_num*A+reminder << endl;
  }
  //cout << sizeof(long long int) << endl;
  //cout << sizeof(int64_t) << endl;
  //cout << sizeof(uint64_t) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>


void fib(int);

int F[44];

int main(){
  int n;
  scanf("%d",&n);

  fib(n);

  printf("%d\n",F[n]);

  return 0;

}



void fib(int n){
  int i;
  F[0]=1;
  F[1]=1;
  for(i=2;i<=n;i++){
    F[i]=F[i-2]+F[i-1];
  }
}



Measured memory_bytes: 2108
def gcd_(a,b):
    if a<b:    a,b=b,a
    if b==0:    return a
    return gcd_(b,a%b)

def gcd(l):
    ans=l[0]
    for i in l:
        ans=gcd_(ans,i)
    return ans  
  
N=int(input())
A=list(map(int,input().split()))
print(gcd(A))

Measured memory_bytes: 14224
#include <stdio.h>
#include <algorithm>

int main(){
  char S[4];
  scanf("%s", S);
  
  if (S[0] == S[1] || S[1] == S[2] || S[2] == S[3]){
    printf("Bad\n");
  }
  else{
    printf("Good\n");
  }
}

Measured memory_bytes: 128
// In the name of God

#include <bits/stdc++.h>

using namespace std;

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

	int a, b;
	cin >> a >> b;

	int h, m;
	cin >> h >> m;

	double x = h * 30 + m * 0.5;
	
	double y = m * 6;

	double pi = acos(-1);

	auto in_radians = [&](double degree) {
		return (degree * pi) / 180;
	};

	double ans = a*a + b*b - 2 * a * b * cos(in_radians(x-y));

	ans = sqrt(ans);

	cout << fixed << setprecision(10) << ans;

	return 0;
}


Measured memory_bytes: 4156
#include<cstdio>
int main(){
	int A,B,C,D;
	scanf("%d %d %d %d",&A,&B,&C,&D);
	if((A*B)>=(C*D)) printf("%d",(A*B));
	if((A*B)<(C*D)) printf("%d",(C*D));
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <limits.h>
#include <numeric>
#include <math.h>
#include <bits/stdc++.h>
#define rep(i,c) for (int i=0;i<c;i++)
using namespace std;
typedef long long ll;

    
    

int main(){
    string S,T;
    cin >> S >> T;
    string ans = "No";
    int size = (int)(S.length());
    rep(i,size){
        if(S[i] == T[i]) ans = "Yes";
        else{
            ans = "No";
            break;
        } 
    }

    cout << ans << endl;

}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using System.Text;
 
class DandA {
    static void Main(string[] args) {
        int[] ab = ReadLineIntArray();
        int rtn = 0;
        int n = ab[1] - 1;
        while (n > 0) {
            n -= ab[0] - 1;
            rtn++;
        }
        Console.WriteLine(rtn);
    }
 
    static string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
    static string[] strAry = new string[] {"L", "R", "U", "D"}; 
  
    static private string ReadLineStr() {return Console.ReadLine();}
    static private int ReadLineInt() {return int.Parse(Console.ReadLine());}
    static private long ReadLineLong() {return long.Parse(Console.ReadLine());}
    static private double ReadLineDouble() {return double.Parse(Console.ReadLine());}
    static private string[] ReadLineStrArray() {return Console.ReadLine().Trim().Split();}
    static private int[] ReadLineIntArray() {return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToArray();}
    static private long[] ReadLineLongArray() {return Console.ReadLine().Trim().Split().Select(a => long.Parse(a)).ToArray();}
    static private double[] ReadLineDoubleArray() {return Console.ReadLine().Trim().Split().Select(a => double.Parse(a)).ToArray();}
    static private decimal[] ReadLineDecimalArray() {return Console.ReadLine().Trim().Split().Select(a => decimal.Parse(a)).ToArray();}
    static private string[][] ReadMLineStrArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split()).ToArray();}
    static private int[][] ReadMLineIntArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();}
 
    static private bool IsPrime(int num) {
        if (num < 2) return false;
        if (num == 2) return true;
        else if (num % 2 == 0) return false;
        double sqrtNum = Math.Sqrt(num);
        for (int i = 3; i <= sqrtNum; i += 2) {
            if (num % i == 0) return false;
        }
        return true;
    }
  
    static private string IntToNString(int x, int n) {
        var nstring = "";
        var numbers = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
        int r = 1;
        int q = x;
        while (q > 0) {
            r = q % n;
            nstring += numbers[r];
            q = q / n;
        }
        return string.Join("",nstring.Reverse());
     }
}

Measured memory_bytes: 13396
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n, m;
    cin >> n >> m;
    vector<bool> flg(n, false);
    vector<int> cnt(n, 0);
    rep(i, m) {
        int p;
        string s;
        cin >> p >> s;
        --p;
        if (s == "AC") {
            flg[p] = true;
        }
        else if (!flg[p]) {
            ++cnt[p];
        }
    }
    int ac_num = 0;
    int wa_num = 0;
    rep(i, n) {
        if (flg[i]) {
            ++ac_num;
            wa_num += cnt[i];
        }
    }
    cout << ac_num << " " << wa_num << endl;
    return 0;
}


Measured memory_bytes: 3744
/*
  Compete against Yourself.
  Author - Aryan Choudhary (@aryanc403)
*/

#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"

typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;

clock_t time_p=clock();
void aryanc403()
{
#ifdef ARYANC403
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
#endif
}

#ifdef ARYANC403
#include "/home/priank/codes/PastCodes/header.h"
#else
    #define dbg(args...)
#endif

const lli INF = 0xFFFFFFFFFFFFFFFL;

lli seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

const lli mod = 1000000007L;
const lli maxN = 4000000L;

    lli T,n,i,j,k,in,cnt,l,r,u,v,x,y;
    lli m,sum;
    string s;
    vi a;
    bitset<maxN+5> bt;
    //priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue .

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{

    cin>>n;
    bt[0]=1;
    fo(i,n)
    {
        cin>>in;
        // in=2000;
        sum+=in;
        bt|=bt<<in;
    }

    x=(sum+1)/2;
    while(true)
    {
        if(bt[x])
        {
            cout<<x<<endl;
            return 0;
        }
        x++;
    }

}   aryanc403();
    return 0;
}


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

int main() {
  int N;
  bool flag = false;
  string S;
  cin >> N;
  for (int i = 0; i < N; i ++) {
  	cin >> S;
    if (S == "Y") {
      flag = true;
      break;
    }
  }
  
  if (flag == true) {
    cout << "Four" << endl;
  } else {
    cout << "Three" << endl;
  }
}  

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

const long long MOD=1000000007;
long long N,sum[27]; string s;

int main(){
	cin>>N>>s;
	for(int i=0; i<N; i++){
		sum[s[i]-'a']++;
	}
	long long total=1;
	for(int i=0; i<26; i++){
		total*=(sum[i]+1)%MOD;
		total=total%MOD;
	}
	cout<<total-1<<'\n';
}

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

int main(){
    int a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;
    int noudo = 0;
    int wmax = 0;
    int smax = 0;
    for(int i = 0; i <= 100; i++){
        for(int j = 0; j <= 100; j++){
            for(int k = 0; k <= 100; k++){
                for(int l = 0; l <= 100; l++){
                    int w = a*i*100 + b*j*100;
                    int s = c*k + d*l;
                    if(w == 0) continue;
                    if(e*10000/(100+e) < s*10000/(w + s)) continue;
                    if(w + s > f) continue;
                    if(s*10000/(w+s) >= noudo){
                        noudo = s*10000/(s + w);
                        smax = s;
                        wmax = w + s;
                    }
                }
            }
        }
    }
    cout << wmax << " " << smax << endl;
}

Measured memory_bytes: 3536
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import *

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a, b, c = MAP()

if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt():
	print("Yes")
else:
	print("No")


Measured memory_bytes: 5268
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

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

    int N;
    cin >> N;
    vector<pair<string, int>> S(N);
    REP(i, N) {
        string s;
        int a;
        cin >> s >> a;
        S[i] = {s, a};
    }
    auto P  = S;
    auto id = S;
    vector<bool> bid(N, true);
    RSORT(P);
    SORT(S);
    bool f = false;

    REP(i, N) {
        REP(j, N) {
            f = false;
            if (S[i].first == P[j].first) {
                REP(k, N) {
                    if (P[j].first == id[k].first &&
                        P[j].second == id[k].second && bid[k]) {
                        std::cout << k + 1 << '\n';
                        bid[k] = false;
                        break;
                    }
                }
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
K,N = map(int,input().split())
A = list(map(int,input().split()))
ans = 10**7

for i in range(N-1):
  if i == 0:
    ans = min(ans,K - (A[i+1]-A[i]),A[-1]-A[i])
  else:
    ans = min(ans,K - (A[i+1]-A[i]),K - (A[i]-A[i-1]))

print(ans)

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int N=in();
	
	out(N*N);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
long long int L; 
int N; 
long long int solve(long long int A[200010]){
	long long int Dir[200010] = {}; // 1を出発・iをindexが減る向きにゴールするときの最小値
	Dir[2] = L - A[2] + A[1]; 
	for(int i = 3; i <= N/2+1; i++){
		Dir[i] = Dir[i-1] + L*2 - 3 * (A[i]-A[i-1]) - 2 * (A[i*2-2]-A[i*2-3]) - 4 * (A[i*2-3]-A[i]);
	}
	Dir[N] = L - A[1] - A[N] + 2*A[N-1]; 
	for(int i = N-1; i > N/2+1; i--){
		Dir[i] = Dir[i+1] + L*2 - (A[i+1]-A[i]) - 2 * (A[i*2-N]-A[i*2-N-1]) - 4 * (A[i]-A[i*2-N]);
	}
	long long int ans = 0; 
	for(int i = 2; i <= N; i++){
		ans = max(ans, Dir[i]); 
	}
	return ans;  
}
int main(){
	cin >> L >> N; 
	long long int X[200010] = {}; 
	for(int i = 1; i <= N; i++){
		cin >> X[i];
	}
	long long int Y[200010] = {}; 
	long long int Z[200010] = {}; 
	long long int W[200010] = {}; 
	for(int i = 2; i <= N; i++){
		Y[i] = X[1] + L - X[N+2-i]; 
		Z[i] = X[N] - X[N+1-i];
		W[i] = X[i-1] + L - X[N]; 
	}
	X[N+1] = L+X[1]; Y[N+1] = L+Y[1];
	Z[N+1] = L+Z[1]; W[N+1] = L+W[1];
	long long int a = X[1] + solve(X); 
	long long int b = X[1] + solve(Y); 
	long long int c = L - X[N] + solve(Z); 
	long long int d = L - X[N] + solve(W); 
	cout << max({a,b,c,d}) << endl; 
}

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

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

int main()
{
    int n,ans=0;
    cin>>n;
    vector<double> a(n);
    double sum=0,diff=10000;
    
    for(int i = 0; i < n; i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    sum/=n;
    
    for(int i = 0; i < n; i++)
    {
        if(abs(sum-a[i])<diff)
        {
            ans=i;
            diff=abs(sum-a[i]);
        }
    }
    
    
    cout<<ans<<endl;

    return 0;
}

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

#define SIZE 100005
#define PI acosl(-1) //3.14159265358979323846264338327950L 
#define rep(i, N) for (i = 0; i < N; i++) //制御変数iを用いてN回転
#define array(N, t) (t*)calloc(N, sizeof(t)) //t型N要素の1次元配列を動的確保後0クリア(freeを忘れずに)
#define zero(a); {int iter; rep(iter, sizeof(a)/sizeof((a)[0])) (a)[iter]=0;} //1次元配列aのゼロ初期化?

typedef long long ll; typedef long double ld;
typedef struct node { int data; struct node *next; } Node;

Node *list[SIZE];
int queue[SIZE]; int q_head = 0, q_tail = 0;

void print_log(); //とりあえず文字を出力してどこまで実行できているか確認(for debug)
void printa_int(int *a, int size); //int型の1次元配列aを出力(for debug)
void printl_int(int size); //リンクリストを出力(for debug)
Node* add_node(int i, int data); void free_list(Node* head);
int queue_empty(); int queue_full();
void enqueue(int data); int dequeue();
ll* factorize(ll N); //Nを素因数分解、得られる配列は素因数,指数,素因数,…となっている(添字はintで指定する必要あり?)
void check_factorization(ll *fact); //素因数分解を表示(for debug)

int main() {
    int i, x;
    rep(i, 5) {
        scanf("%d", &x);
        if (x == 0) break;
    }
    printf("%d\n", i + 1);
    return 0;
}

void print_log() {
    printf("=== print log ===\n");
}
void printa_int(int *a, int size) {
    int i;
    printf("[");
    for (i = 0; i < size; i++)
        printf("%d, ", a[i]);
    printf("]\n");
}
void printl_int(int size) {
    int i;
    Node *t;
    rep(i, size) {
        printf("[%d] ", i);
        for (t = list[i]; t; t = t->next) printf("%d, ", t->data);
        printf("\n");
    }
}
Node* add_node(int i, int data) {
    if (!list[i]) {
        list[i] = (Node*)malloc(sizeof(Node*));
        list[i]->data = data;
    } else {
        Node *t;
        t = list[i];
        list[i] = (Node*)malloc(sizeof(Node*));
        list[i]->data = data;
        list[i]->next = t;
    }
    return list[i];
}
void free_list(Node* head) {
    Node *prev = NULL, *t = head;
    while (t) {
        prev = t;
        t = t->next;
        free(prev);
    }
}
int queue_empty() {
    return q_head == q_tail;
}
int queue_full() {
    return (q_head - 1) % SIZE == q_tail % SIZE;
}
void enqueue(int data) {
    if (queue_full()) {
        printf("full!\n");
        return;
    }
    queue[q_tail++] = data;
    q_tail %= SIZE;
}
int dequeue() {
    if (queue_empty()) {
        printf("empty!\n");
        return -444444;
    }
    int data = queue[q_head++];
    q_head %= SIZE;
    return data;
}
ll* factorize(ll N) {
    ll *res = array(((sqrt(N) + 1) * 2), ll);
    ll i, x = N;
    int count = 0;
    for (i = 2; i * i <= N; i++) {
        ll e = 0;
        while (x % i == 0) {
            x /= i;
            e++;
        }
        if (e > 0) {
            res[count * 2] = i;
            res[count * 2 + 1] = e;
            count++;
        }
    }
    if (x > 1) {
        res[count * 2] = x;
        res[count * 2 + 1] = 1;
    }
    return res;
}
void check_factorization(ll *fact) {
    int i = 1;
    printf("%lld^%lld", fact[0], fact[1]);
    while (fact[i * 2] > 0) {
        printf(" * %lld^%lld", fact[i * 2], fact[i * 2 + 1]);
        i++;
    }
    printf("\n");
}

Measured memory_bytes: 2148
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n){
    cin >> a.at(i);
  }
  ll i,j;
  sort(a.begin(),a.end());
  ll ans=0;
  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      ll x=a.at(i)+a.at(j);
      ans+=lower_bound(a.begin(),a.end(),x)-a.begin()-j-1;
    }
  }
  cout << ans;
}

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

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

class Prime {
private:
	void Eratos(lint N) {
		for (lint i = 2; i * i < N; i++) {
			if (Ptb[i]) for (int j = 0; i * (j + 2) < N; j++) Ptb[i *(j + 2)] = 0;
		}
	}
public:
	vector<int> Ptb;
	Prime(lint N) : Ptb(N + 1, 1) { Eratos(N + 1); }

	vector<pair<lint, int>> Pfact(lint num) {
		vector<pair<lint, int>> res;
		for (lint i = 2; i * i <= num; i++) {
			int cnt = 0;
			while (num % i == 0) {
				cnt++;
				num /= i;
			}
			if (cnt) res.emplace_back(i, cnt);
		}
		if (num != 1) res.emplace_back(make_pair(num, 1));
		return res;
	}

	bool isPrime(lint num) {
		if (num < 2) return false;
		else if (num < (int)(Ptb.size())) return (bool)(Ptb[num]);
		else if (num == 2 || num == 3) return true;
		else if (num % 2 == 0 || num % 3 == 0) return false;
		else if (num % 6 != 1 && num % 6 != 5) return false;
		for (lint i = 5; i * i <= num; i += 6) {
			if (num % i == 0) return false;
			if (num % (i + 2) == 0) return false;
		}
		return true;
	}
};

int main() {

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

	int N;
	cin >> N;

	Prime p(55555);

	vector<int> ans;
	int ans_sz = 0;
	for (int i = 2; ans_sz < N; i += 5) {
		if (p.isPrime(i)) {
			ans.emplace_back(i);
			ans_sz = (int)(ans.size());
		}
	}

	for (const auto &e : ans) cout << e << " ";
	cout << "\n";

	return 0;
}

Measured memory_bytes: 1020
// -----------------------------------
// Author     : MatsuTaku
// Country    : Japan
// Created    : 04/11/20 07:29:12
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  static constexpr int INF = 1e9+10;

  int q; cin>>q;
  priority_queue<int> left;
  left.push(-INF);
  priority_queue<int, vector<int>, greater<>> right;
  right.push(INF);
  ll min_v = 0;
  for (int i = 0; i < q; i++) {
    int t; cin>>t;
    if (t == 1) {
      ll a, b; cin>>a>>b;
      min_v += b;
      if (left.top() <= a and a <= right.top()) {
        left.push(a);
        right.push(a);
      } else if (a < left.top()) {
        min_v += left.top()-a;
        left.push(a);
        left.push(a);
        auto t = left.top();
        left.pop();
        right.push(t);
      } else {
        min_v += a-right.top();
        right.push(a);
        right.push(a);
        auto t = right.top();
        right.pop();
        left.push(t);
      }
    } else if (t == 2) {
      cout << left.top() << " " << min_v << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3828
#include <stdio.h>

int main(void)
{
    char s[4],t[4];
    int i,n=0;
    scanf("%s",s);
    scanf("%s",t);
    for(i=0;i<3;i++)
    {
        if(*(s+i)==*(t+i)) n++;
    }
    printf("%d",n);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(){
  int W, H;
  cin >> H >> W;
  string S;
  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      cin >> S;
      if(S == "snuke"){
	cout << char('A'+j) << i+1 << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
S = input()
N = len(S)
def check(s):
  return "".join(reversed(s)) == s
#print(S, S[:(N-1)//2], S[(N+1)//2:])
if check(S) and check(S[:(N-1)//2]) and check(S[(N+1)//2:]):
  print("Yes")
else:
  print("No")


Measured memory_bytes: 2940
using System;

    class Program
    {
        static void Main(string[] args)
        {
            var line = System.Console.ReadLine();
            var data = line.Split(new char[] { ' ' });
            int H = Convert.ToInt32(data[0]);
            int A = Convert.ToInt32(data[1]);
            int count = 0;
            do
            {
                H -= A;
                count++;
            } while (H > 0);

            // map検索終了
            Console.WriteLine(count);
        }
    }

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;
struct Edge{ll from, to, cost;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  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, ll mod){
  return modpow(a, mod-2, mod);
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N;
  cin >> N;
  set<ll> frontB, bottomA, both;
  vector<string> s(N);
  ll ans = 0;
  rep(i, N){
    cin >> s[i];
    ll cnt = 0;
    ll len = s[i].size();
    if(s[i][0]=='B'){
      frontB.insert(i);
      cnt++;
    }
    if(s[i][s[i].size()-1]=='A'){
      bottomA.insert(i);
      cnt++;
    }
    rep(j, len-1){
      ans += (s[i].substr(j, 2)=="AB"?1:0);
    }
    if(cnt==2)both.insert(i);
  }

  if(bottomA.size()==frontB.size() and both.size() == frontB.size()){
    ans += max((ll)bottomA.size()-1, 0LL);
  }else{
    ll tmp  = min(bottomA.size(), frontB.size());
    ans += min(tmp, N-1);
  }
  /*
  if(both.empty()){
    ans += min(bottomA.size(), frontB.size());
  }else if(both.size()==1 and bottomA.size()==1){
    ans += 1;
  }else if(both.size()==1 and frontB.size()==1){
    ans += 1;
  }else{
    ans += min(bottomA.size(), frontB.size());
  }
  */
  cout << ans;
  return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;

vector<int> g[100010];
int dp[100010];
// solve(i) は頂点iから見た時のlongestなパスの長さ

int solve(int x) {
    if (g[x].size() == 0) return 0;
    if (dp[x] != -1) return dp[x];
    int ret = 0;
    for (int i = 0; i < g[x].size(); ++i) {
        int tmp = solve(g[x][i])+1;
        ret = max(ret, tmp);
    }
    dp[x] = ret;
    return ret;
}

int main(int argc, char const *argv[]) {
    int n, m;
    cin >> n >> m;
    REP(i,m) {
        int x, y;
        cin >> x >> y;
        g[x-1].push_back(y-1);
    }
    memset(dp, -1, sizeof(dp));
    int ans = -1;
    REP(i,n) ans = max(ans,solve(i));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8192
#include <iostream>

using namespace std;

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

    int ac = 0;
    int wa = 0;
    int tle = 0;
    int re = 0;
    for (int i = 0; i < n; ++i) {
        string tmp; cin >> tmp;
        if (tmp == "AC") ++ac;
        else if (tmp == "WA") ++wa;
        else if (tmp == "TLE") ++tle;
        else if (tmp == "RE") ++re;
    }

    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;

    return 0;
}

Measured memory_bytes: 3572
import java.util.*;
import java.math.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long k = sc.nextLong();

    long ans = n%k;

    System.out.println(Math.min(ans,k-ans));



  }

}


Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#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 show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << i.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}

long mod = 1000000007;
/* C++の構造体 メンバがpublicなclass */
typedef struct mint
{
    ll x;
    mint(ll x = 0) : x(x % mod) {} //コンストラクタ
    /* 演算子オーバーロード */
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const
    {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const
    {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const
    {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const
    {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const
    {
        return pow(mod - 2);
    }
    mint &operator/=(const mint a)
    {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const
    {
        mint res(*this);
        return res /= a;
    }
} mint_t;

ll intpow(mint_t m, int n)
{
    if (n == 0) return 1;
    mint_t ans(1);
    while (n >= 1)
    {
        if ((n % 2) == 0){
            m *= m.x;
            n /= 2;
        }else {
            ans *= m.x;
            n -= 1;
        }
    }
    return ans.x;
}

template<class X> void factorization(X input, vector<X>& Pnumber){
    for(X i = 2; i*i <= input; i++)
    {
        if (input % i == 0){
            while (input % i == 0){
                input /= i;
                Pnumber.push_back(i);
            }
        }
    }
    if (input != 1) Pnumber.push_back(input);
}

/*
1~K以下の整数からなる長さNの数列
この数列は、K^Nのパターンが存在する。

この数列のK^Nの最大公約数の和
最大公約数がXとなるときのパターン数をf(X)とする。
f(K) = 1 (全てK)
f(K/2) = 2^N - f(K) 

pをmの公倍数かつK以下の数とする。
f(m): (pの数)^N -  f(p)の総和

 */

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

    vector<mint> f(k+1, 0);
    for (int m = k; m >= 1; m--)
    {
        //f(m)を包除原理で求める。
        int pnum = k/m;
        mint tans = pnum;
        tans = tans.pow(n);
        for (int i = 2; i <= pnum; i++)
        {
            tans -= f[m*i];
        }
        f[m] = tans;
    }
    
    mint ans(0);
    for (int i = 1; i <= k; i++)
    {
        //cout << f[i].x << endl;
        mint tans = f[i];
        tans *= i;
        ans += tans;
    }
    
    cout << ans.x << endl;
}


Measured memory_bytes: 4060
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int n;
    cin>>n;
    int ans=0;
    ans+=(n/2)*min(d,min(c*2,min(b*4,a*8)));
    ans+=(n%2)*min(c,min(b*2,a*4));
    cout<<ans<<endl; 
    return 0;
}

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

constexpr Int mod = 998244353;
Int n, ans = 1;
vector<Int> v;
vector<Int> w;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	v.resize(n);
	for(auto &i:v) cin >> i;
	if(v[0] != 0) ans = 0;
	w.resize(n);
	for(auto i:v) ++w[i];
	if(w[0] != 1) ans = 0;
	for(Int i=1; i<n; ++i){
		for(Int j=0; j<w[i]; ++j){
			ans *= w[i-1];
			ans %= mod;
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 1792
a, b, c, x = int(input()), int(input()), int(input()), int(input())
count = 0
for i in range(a + 1):
  p = x - i * 500
  if p < 0 :
    continue
  elif p == 0:
    count += 1
    continue
  for j in range(b + 1):
    q = p - j * 100
    if q < 0 :
      continue
    elif q == 0:
      count += 1
      continue
    for k in range(c + 1):      
      if q - k * 50 == 0 :
        count += 1
      else:
        continue
      
print(count)

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

#define vec                vector<int>
#define vecll              vector<ll>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt((ok ? "YES" : "NO"));}
//----------------------------------------------------------------

int main(void) {
  ll n, a;
  cin >> n >> a;
  arrll(t,n);

  ll ans=0;
  rep(i,n){
    if(i!=n-1){
      ans += min(t[i+1]-t[i], a);
    } else {
      ans += a;
    }
  }
  prt(ans);
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
 

 int main(){
   ll n ; cin>> n ;
   vector<ll> A(3*n) ;
   rep(i,3*n) cin>>A[i] ;
   vector<ll> B(n+1),C(n+1) ;
   priority_queue<ll,vector<ll>,greater<ll>> p ;
   priority_queue<ll> q ;
   ll sum=0 ;
   ll sun=0 ;
   rep(i,2*n){
   p.push(A[i]) ;
   q.push(A[3*n-1-i]) ;
   sum+= A[i] ;
   sun+= A[3*n-1-i] ;
   if(i>=n){
   ll x= p.top() ;
   ll y=q.top() ;
   sum-=x ;
   sun-=y ;
   p.pop() ;
   q.pop() ;
   }
   if(i>=n-1){
     B[i-(n-1)]=sum ;
     C[i-(n-1)]=sun ;
   }
   }
   ll ans=-INF ;
   rep(i,n+1){
   ll now=   B[i]-C[n-i] ;
   chmax(ans,now) ;
   }
   cout<<ans<<endl ;
   return 0 ;
}



Measured memory_bytes: 8920
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();
    int K = sc.nextInt() - 1;

    List<Integer> divisorA = cul(A);
    List<Integer> divisorB = cul(B);

    List<Integer> common = new ArrayList<>();

    for(Integer a : divisorA){
      if(divisorB.contains(a)){
        common.add(a);
      }
    }

    Collections.sort(common, Collections.reverseOrder());

    System.out.println(common.get(K));

  }

  public static List<Integer> cul(int number) {
    List<Integer> divisor = new ArrayList<>();

    for (int i = 1; i <= number ; i++ ) {
      if (number%i == 0) {
        divisor.add(i);
      }
    }

    return divisor;
  }
}


Measured memory_bytes: 21716