akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define fo(i, n) for(int i = 1; i <= n; ++i)
typedef long long ll;

const int N = 500505;
const int mod = 1e9 + 7;

int n, a[N], u, v;
vector<int> g[N];
inline void no() {
    cout << "NO";
    exit(0);
}

inline ll dfs(int v, int p = 0) {
    vector<ll> h;
    for(int to : g[v]) {
        if(to == p) continue;
        h.pb(dfs(to, v));
    }
    if(!h.size()) return a[v];
    ll sum = 0;
    for(ll w : h) sum += w;
    ll min_moves = sum / 2;
    ll max_moves = sum;
    if(a[v] < min_moves || a[v] > max_moves)
        no();
    ll moves_by_two = max_moves - a[v];
    ll all_moves = min(sum - *max_element(h.begin(), h.end()), sum / 2);
    if(moves_by_two > all_moves) no();
    sum -= moves_by_two * 2;
    return sum;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    fo(i, n) cin >> a[i];
    for(int i = 1; i < n; ++i) {
        cin >> u >> v;
        g[u].pb(v); g[v].pb(u);
    }
    if(n == 2) {
        if(a[1] == a[2]) return cout << "YES", 0;
        cout << "NO";
        return 0;
    }
    int root = 1;
    for(int i = 1; i <= n; ++i)
        if(g[i].size() != 1) root = i, i = n + 1;
    if(dfs(root) != 0) return cout << "NO", 0;
    cout << "YES";
    return 0;

}

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

using namespace std;

typedef long long int Int;

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

    for(int i = 0;i < s.size();i++)
	if(s[i] == '9')
	{
	    cout<<"Yes"<<endl;

	    return 0;
	}

    cout<<"No"<<endl;

    return 0;
}


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

int main() {

	string s, t; cin >> s >> t;
	int ans = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != t[i]) ans++;
	}
	cout << ans << endl;
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  int d[N];
  int cnt = 1;
  for(int i=0;i<N;i++) cin >> d[i];
  sort(d,d+N);
  for(int i=1;i<N;i++){
    if(d[i] != d[i-1]) cnt++;
  }
  cout << cnt;
}

Measured memory_bytes: 256
e1 , e2 , e3 , e4 =map(int,input().split())
if e1==e2 and e3==e4:
    print("yes")
elif e2==e3 and e1==e4:
    print("yes")
elif e1==e3 and e2==e4:
    print("yes")
else:
    print("no")


Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n,u,v; cin>>n>>u>>v;
  vector<vector<int>> t(n+1,vector<int>(0));
  for(int i=0; i<n; ++i){
    int a,b; cin>>a>>b;
    t[a].push_back(b),t[b].push_back(a);
  }
  vector<int> ud(n+1,0),vd(n+1,0);
  vector<bool> d(n+1,true);
  queue<pair<int,int>> q;
  q.push({v,0}); d[v]=false;
  while(!q.empty()){
    int x=q.front().first,y=q.front().second; q.pop();
    vd[x]=y;
    for(auto& i:t[x]) if(d[i]==true) q.push({i,y+1}),d[i]=false;
  }
  int res=0;
  d=vector<bool>(n+1,true);
  q.push({u,0}); d[u]=false;
  while(!q.empty()){
    int x=q.front().first,y=q.front().second; q.pop();
    ud[x]=y; if(vd[x]>ud[x]) res=max(vd[x]-1,res);
    for(auto& i:t[x]) if(d[i]==true) q.push({i,y+1}),d[i]=false;
  }
  cout<<res;
  return 0;
}


Measured memory_bytes: 9720
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <stdlib.h>
#define ll long long
#define MOD_P 1000000007
using namespace std;

struct vec {
	int to;
	int cost;
};

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

	if (n > 12) {
		printf("%d", cost);
	} else if (n > 5) {
		printf("%d", cost / 2);
	} else {
		printf("0");
	}
	
	return 0;
}

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

int main() {
    int N, Y;
    cin >> N >> Y;
    int res10000 = -1, res5000 = -1, res1000 = -1;
    for (int a = 0; a <= N; ++a) {  // 10000円の枚数を 0 〜 N で調べる
        for (int b = 0; b + a <= N; ++b) {  // 5000円の枚数を 0 〜 N-a で調べる
            int c = N - a - b;  // 1000円の枚数は決まる
            int total = 10000*a + 5000*b + 1000*c;
            if (total == Y) {  // 答えが見つかったら
                res10000 = a;
                res5000 = b;
                res1000 = c;
            }
        }
    }

    // 答えを出力 (見つかっていなくても -1 -1 -1 になるので OK です)
    cout << res10000 << " " << res5000 << " " << res1000 << endl;
}

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

int main(){
    int n;
    cin>>n;
    vector<int> xs(n);
    map<int,int> mp;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        xs[i]=x;
        mp[x]++;
    }

    int bound=1000010;
    vector<bool> table(bound);
    sort(xs.begin(),xs.end());
    int ans=0;
    for(int i=0;i<xs.size();i++){
        int v=xs[i];
        if(!table[v] && mp[v]==1){
            ans++;
        }
        if(!table[v]){
            for(int j=v;j<bound;j+=v){
                table[j]=true;
            }
        }
    }

    if(n==1){
        cout<<1<<endl;
    }else{
        cout<<ans<<endl;
    }

    return 0;
}

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

int main() {
    int n; cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    int min_i = p[0];
    int ans = 1;
    for(int i = 1; i < n; i++){
        int &p_i = p[i];
        if(min_i >= p_i){
            min_i = p_i;
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <random>
#include <chrono>
#include <string>
#include <cstring>
#include <bitset>
#include <cassert>
#include <queue>
#include <deque>
#include <memory>

//#pragma comment(linker, "/STACK:16777216")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,abm,mmx,avx,avx2,popcnt,tune=native")

using namespace std;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

#define ll long long
#define ull unsigned long long
//#define double long double
//#define int ll
//#define int ull
//#define int short
//#define int unsigned short
//#define int unsigned int
#define mp make_pair
#define F first
#define S second
#define pii pair<int, int>
#define hash hash228
const int SZ = 5e3 + 4;
const double EPS = 1e-3;
const int mod = 1e9 + 7;
const int hashpow = 2;
const int inf = 2e9;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int k;
string s;

inline void read() {
    cin >> k >> s;
}

inline void solve() {
    if (s.size() <= k) {
        cout << s << "\n";
        return;
    }
    while (s.size() > k) {
        s.pop_back();
    }
    cout << s << "...\n";
}

signed main() {

#ifdef __LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

//    int t;
//    cin >> t;
//    for (int i = 0; i < t; ++i) {
        read();
        solve();
//    }

    return 0;
}

Measured memory_bytes: 3604
alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]

n = int(input())

sub = 26
count = 1
while True:
  if n <= sub:
    break
  n -= sub
  sub *= 26
  count += 1

ans = []
n -= 1
for i in range(count):
  ans.append(alphabet[n%26])
  n //= 26
ans.reverse()
print("".join(ans))



Measured memory_bytes: 9184
#include<bits/stdc++.h>
using namespace std;  
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define pii pair<int,int>
#define piii pair<int,pii>
#define mp make_pair
#define pb push_back  
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const double eps = 1e-14;
const double PI = M_PI;  
#define DEB cout<<"!"<<endl
#define SHOW(a,b) cout<<(a)<<" "<<(b)<<endl  
#define DIV 1000000009  
int main(){
	int N;
	cin >> N;
	string s1,s2;
	cin >> s1 >> s2;
	
	for(int i = 0; i < N; i++){
		if(s1.substr(i,N) == s2.substr(0,N - i)){
			cout << 2 * N - ( N - i)  << endl;
			return 0;
		}
	}
	cout << 2 * N << endl;
	return 0;
}

Measured memory_bytes: 256
S = raw_input()

count_map = {}

for s in S:
    if s in count_map :
        v = count_map[s]
        count_map[s] = v + 1
    else:
        count_map[s] = 1

answer = True

if len(count_map) == 2:
    for key in count_map.keys():
        if count_map[key] != 2:
            answer = False
            break
else:
    answer = False

if answer :
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2696
#include <iostream>
#include <cmath>

using namespace std;

int aa(int x, int y, int z) {

	return ((pow(x, 2) + pow(y, 2) == pow(z, 2)) || (pow(x, 2) + pow(z, 2) == pow(y, 2)) || (pow(y, 2) + pow(z, 2) == pow(x, 2)));
}

int main() {

	int a, b[1000], c[1000], d[1000];
	bool e[1000];

	cin >> a;

	for (int i = 1; i <= a; i++)
	{
		cin >> b[i] >> c[i] >> d[i];

		e[i] = aa(b[i], c[i], d[i]);

	}

	for (int i = 1; i <= a; i++)
	{

		cout << ((e[i] != 0) ? "YES" : "NO") << endl;
	}

	return 0;
}

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

int N, X;
vector<int> L;

int main(void) {
	cin >> N >> X;
	L.resize(N + 1, 0);
	for (int i = 1; i <= N; ++i)
		cin >> L[i];

	int cnt = 1;
	int d = 0;
	for (int i = 2; i <= N + 1; ++i) {
		d = d + L[i - 1];
		if (d > X)
			break;
		++cnt;
	}

	cout << cnt << '\n';
	return 0;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    ll n;
    cin>>n;
    string s;


    do {
	--n;
	ll d = n%26;
	char c = 'a' + d;
	s += c;
	n /= 26;
    } while (n>0) ;


    reverse(s.begin(), s.end());

    cout<<s<<endl;    
    return 0;
}


Measured memory_bytes: 3652
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        long[][][] dp = new long[3][N+5][2];
        dp[0][0][0] = 1000;
        dp[0][0][1] = 0;
        dp[1][0][0] = 1000;
        dp[1][0][1] = 0;
        dp[2][0][0] = 1000;
        dp[2][0][1] = 0;
        for (int j = 1; j <= N; j++) {
            int price = A[j-1];
            for (int i = 0; i < 3; i++) {
                long maxValue = 0;
                for (int k = 0; k < 3; k++) {
                    long money  = dp[k][j-1][0];
                    long stock = dp[k][j-1][1];
                    if (i == 0) {
                        long buyNum = money/price;
                        money -= buyNum*price;
                        stock += buyNum;
                    } else if (i == 1) {
                        money += stock*price;
                        stock = 0;
                    } else {
                        // nop
                    }
                    long value = money + stock*price;
                    if (value >= maxValue) {
                        maxValue = value;
                        dp[i][j][0] = money;
                        dp[i][j][1] = stock;
                    }
                }
            }
        }

        System.out.println(Math.max(dp[1][N][0], dp[2][N][0]));
    }
}


Measured memory_bytes: 35676
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		for(int i = 0; i < N; i++){
			int m = sc.nextInt();
			int n = sc.nextInt();

			int limit = m*m + n*n;

			int count = 0;
			for(int j = -1000 ; j <= 1000; j++){
				for(int k = -1000 ; k <= 1000; k++){
					if(j*j + k*k > limit){
						continue;
					}

					int tmp1 = j*m + k*n;
					int tmp2 = j*n - k*m;
					int div = j*j + k*k;
					if(div == 0){
						continue;
					}

					if(tmp1 % div == 0 && tmp2 % div == 0){
//						System.out.println("<"+j+","+k+">");
						count++;
					}
				}
			}

			if(count == 8){
				System.out.println("P");
			}
			else {
				System.out.println("C");
			}
		}
	}

}



Measured memory_bytes: 27268
;; #!/usr/bin/env sbcl --script

(define-alien-routine getchar_unlocked char)

(declaim (optimize (speed 3) (safety 0) (debug 0))
         (inline getchar_unlocked my-read-int))

(deftype int32 () '(signed-byte 32))

(declaim (ftype (function () int32) my-read-int))
(defun my-read-int ()
  (let ((is-negative nil)
        (result 0))
    (declare (type int32 result))
    (loop for cur-char = (getchar_unlocked) then (getchar_unlocked)
       while (and (/= cur-char (char-code #\-))
                  (/= 0)
                  (or (< cur-char 48)
                      (> cur-char 57)))
       finally (if (<= 48 cur-char 57)
                   (setf result (- cur-char 48))
                   (setf is-negative t)))
    (loop for cur-char = (getchar_unlocked) then (getchar_unlocked)
       while (<= 48 cur-char 57)
       do (setf result (+ (* result 10) (- cur-char 48))))
    (when is-negative (setf result (- result)))
    result))

(defun main ()
  (let* ((n (my-read-int))
         (k (my-read-int))
         (a (make-array n :element-type 'int32))
         (dp (make-array n :element-type 'int32 :initial-element (+ (expt 10 9) 100))))
    (dotimes (i n)
      (setf (aref a i) (my-read-int)))
    (setf (aref dp 0) 0)
    (loop for i of-type int32 from 0 below n do
      (loop with from-val of-type int32 = (aref dp i)
         for j of-type int32 from (1+ i) to (+ i k)
         while (< j n)
         for nval of-type int32 = (+ from-val (abs (- (aref a i) (aref a j))))
         if (< nval (aref dp j))
         do
           (setf (aref dp j) nval)))
    (format t "~a~%" (aref dp (- n 1)))))

(main)



Measured memory_bytes: 22756
package main

import "fmt"

func main() {
	var n, t int
	fmt.Scan(&n, &t)
	cs := make([]int, n)
	ts := make([]int, n)
	for i := range cs {
		var a, b int
		fmt.Scan(&a, &b)
		cs[i] = a
		ts[i] = b
	}

	min_cost := 99999
	for i := range cs {
		if ts[i] <= t && cs[i] < min_cost {
			min_cost = cs[i]
		}
	}

	if min_cost == 99999 {
		fmt.Println("TLE")
	} else {
		fmt.Println(min_cost)
	}
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define lint long long
#define inf 100000000000000000
#define mod 1000000007
#define MAX 1000005
#define pb push_back
#define vit vector<int>::iterator
typedef pair<int,int> pii;
map<int,int>M;
vector<int> V[MAX];
lint dp[MAX],A[MAX]={-1,1,-1,3,-1,-1,-1,1,-1,9,-1};
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    lint n,a,sum;
    cin>>n;
    if(n<=10){
        cout<<A[n];
        return 0;
    }
    a=7;
    sum=1;
    while(!dp[a]){
        if(!a){
            cout<<sum;
            return 0;
        }
        dp[a]=1;
        a=(a*10+7)%n;
        sum++;
    }
    cout<<-1;
    return 0;
}


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

int main(){
    int i,acount=0,bcount=0,ccount=0,abcmin=0;
    string s;
    cin >> s;
    for(i=0;i<s.size();i++){
        if(s[i]=='a')acount++;
        if(s[i]=='b')bcount++;
        if(s[i]=='c')ccount++;
    }
    abcmin=min(acount,min(bcount,ccount));
    acount -= abcmin;
    bcount -= abcmin;
    ccount -= abcmin;
    if(acount>=2||bcount>=2||ccount>=2)cout << "NO" << endl;
    else cout << "YES" << endl;
    return 0;
}

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

using namespace std;

int main(void)
{
	int n;
	cin >> n;
	int a;
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> a;
		ans += a - 1;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <limits>
#include <numeric>
#include <functional>
#include <map>
#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
using namespace std;

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

	int N, T, A, temp;
	vector<double> diff;

	cin >> N >> T >> A;

	REP(i, N)
	{
		cin >> temp;
		diff.push_back(abs(A - (T - temp * 0.006)));
	}

	vector<double>::iterator min = min_element(diff.begin(), diff.end());
	size_t minIndex = distance(diff.begin(), min);

	cout << minIndex + 1 << endl;

	return 0;
}

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

int main(){
    int num1,num2,num3;
    int cnt5 = 0;
    int cnt7 = 0;

    cin >> num1 >> num2 >> num3;

    if(num1 % 5 == 0){
        cnt5++;
    }
    else if(num1 % 7 == 0){
        cnt7++;
    }
    if(num2 % 5 == 0){
        cnt5++;
    }
    else if(num2 % 7 == 0){
        cnt7++;
    }
    if(num3 % 5 == 0){
        cnt5++;
    }
    else if(num3 % 7 == 0){
        cnt7++;
    }

    if(cnt5 == 2 && cnt7 == 1){
        cout << "YES\n";
    }
    else{
        cout << "NO\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long
//#define lint long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順



signed main(){
  string s;
  cin >> s;
  if(s=="SUN") cout << 7 << endl;
  if(s=="MON") cout << 6 << endl;
  if(s=="TUE") cout << 5 << endl;
  if(s=="WED") cout << 4 << endl;
  if(s=="THU") cout << 3 << endl;
  if(s=="FRI") cout << 2 << endl;
  if(s=="SAT") cout << 1 << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // ABC061B - Counting Roads

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();   // 2 <= n,m <= 50
        int m = sc.nextInt();

        int[] a = new int[m];   // 1 <= a,b, <= n
        int[] b = new int[m];   // a <> b
        
        for (int i = 0; i < m; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }
        
        int[] cnt = new int[n];
        for (int j = 0; j < m; j++) {
            for (int k = 0; k < n; k++) {
                if (a[j] == k + 1 || b[j] == k + 1) ++cnt[k];
            }
        }
        
        for (int c : cnt) {
            System.out.println(c);
        }
    }

}

Measured memory_bytes: 21844
N, K = map(int, input().split())
umai = {}
mazui = []
for _ in range(N):
    t, d = map(int, input().split())
    if t not in umai:
        umai[t] = d
    else:
        tmp = umai[t]
        if tmp < d:
            umai[t] = d
            mazui.append((t, tmp))
        else:
            mazui.append((t, d))

umai = sorted(umai.items(), key=lambda x: -x[1])
mazui = sorted(mazui, key=lambda x: -x[1])


umai_len = len(umai)
mazui_len = len(mazui)

acc_umai = [0 for _ in range(umai_len)]
acc_umai[0] = umai[0][1]
for i in range(umai_len - 1):
    acc_umai[i + 1] = acc_umai[i] + umai[i + 1][1]

acc_mazui = [0 for _ in range(mazui_len)]
if mazui_len > 0:

    acc_mazui[0] = mazui[0][1]
    for i in range(mazui_len - 1):
        acc_mazui[i + 1] = acc_mazui[i] + mazui[i + 1][1]
acc_mazui.insert(0, 0)

ans = []
for i in range(1, K + 1):
    if umai_len < i or mazui_len < K - i:
        continue
    ans.append(acc_umai[i - 1] + acc_mazui[K - i] + i ** 2)
print(max(ans))


Measured memory_bytes: 27400
def main():
    N = int(input()) - 1
    digit = 1
    while N >= 26 ** digit:
        N -= 26 ** digit
        digit += 1
    buf = []
    a = ord("a")
    for i in range(digit):
        buf.append(chr(a + (N % 26)))
        N //= 26
    ans = "".join(buf[::-1])
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 61956
#include <iostream>
#include <fstream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	string s,t;
	cin >> s >> t;
	int size = s.size();
	s += s;
	vector<vector<int>> alph(26);
	rep(i,s.size())
	{
		alph[s[i]-'a'].push_back(i);
	}
	ll ans = 0;
	ll now = 0;
	rep(i,t.size())
	{
		if(alph[t[i]-'a'].empty())
		{
			cout<<-1<<endl;
			return 0;
		}
		//ans += *upper_bound(ALL(alph[t[i]-'a']),now);
		now = *lower_bound(ALL(alph[t[i]-'a']),now)+1;
		//cout<<now<<endl;
		if(now>=size)
		{
			now-=size;
			ans+=size;
		}
	}
	ans+=now;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1788
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

# n
# a, b = 
# s = input()


N = int(input())
A = [0]*N
for i in range(N):
    A[i] = int(input())


b = [0]*2
for e in A:
    if e > b[0]:
        b[1] = b[0]
        b[0] = e
    elif e > b[1]:
        b[1] = e
        
for e in A:
    if b[0] == e:
        print(b[1])
    else:
        print(b[0])


Measured memory_bytes: 57304
#include<cstdio>
#include<algorithm>
using namespace std;

int N, K;
int h[111111];

int main(){
	scanf("%d %d", &N, &K);
	for(int i = 0; i < N; i++) scanf("%d", &h[i]);
	sort(h, h + N);
	int res = 1000000001;
	for(int i = 0; i < N - K + 1; i++) res = min(res, h[i + K - 1] - h[i]);
	printf("%d\n", res);
	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
	int n,d,x,a[101],i,j,z=0;
	scanf("%d%d%d",&n,&d,&x);
	for(i=0; i<n; i++){
		scanf("%d",&a[i]);
		for(j=0; j<=d/a[i]; j++){
			if(j*a[i]+1<=d){
				z=z+1;
			}
		}
	}
	printf("%d\n",x+z);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
// #define INF 1LL<<60

const int INF = 1e9;

struct edge {
    int to;
    int d;
};

int main() {
    int N, M, r;
    cin >> N >> M >> r;
    vector< vector<edge> > edges(N, vector<edge>());
    REP(i, M) {
        int s, t, d;
        cin >> s >> t >> d;
        edge e = {t, d};
        edges[s].push_back(e);
    }

    vector<int> dist(N, INF);
    queue<int> que;
    que.push(r);
    dist[r] = 0;

    while(!que.empty()) {
        int cur = que.front();
        que.pop();

        for(edge e: edges[cur]) {
            if(dist[e.to] > dist[cur] + e.d) {
                dist[e.to] = dist[cur] + e.d;
                que.push(e.to);
            }
        }
    }

    REP(i, N) {
        if(dist[i] < INF) {
            cout << dist[i] << endl;
        } else {
            cout << "INF" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 12304
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define ld long double
typedef pair<ll,ll> pll;
typedef vector <ll> vi;
#define out(x) return cout<<x,0;
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));

int main(){
    FAST;
    ll  n, ans = 0, k, m, j = 0, t = 1, x = 0, y = 0, c = 0, i, z = 0;
    string s , s1;
    cin >> s;
    s1 = s;
    reverse(all(s1));
    n = s.size();
    for ( i = 0 ; i < n / 2 ; i ++ ){
        if ( s[i] != s1[i] ) c ++;
    }
    cout << c;
    
}

Measured memory_bytes: 256
import java.io.*;

class Main
{
public static void main (String[] args)throws IOException
{

BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));

String str1 = br.readLine();
String str2[] = str1.split(" ");
int a = Integer.parseInt(str2[0]);
int b = Integer.parseInt(str2[1]);
int c = a*b;
int d = 2*(a+b);
System.out.println( c + " " + d);
}
}

Measured memory_bytes: 24240
a=[]
a[0]=gets.to_i
1000000.times{|i|
    if a[i]%2==0
        a[i+1]=a[i]/2
        else
        a[i+1]=a[i]*3+1
        end
    (i+1).times{|k|
        if a[k]==a[i+1]
            puts (i+2)
            exit
            end
    }
}

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

int main() {
    int n; cin >> n;
    double sum = 0.0;
    for (int i=0; i<n; ++i) {
        double x; string s;
        cin >> x >> s;
        if (s == "JPY") sum += x;
        else sum += x * 380000;
    }
    cout << sum << endl;
}

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

using namespace std;

const int MAX = 200001;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void) {
  COMinit();

  long long N, M, K; cin >> N >> M >> K;
  long long D[N][M];
  
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      D[i][j] = (i + j) * (N-i) * (M-j) * (i == 0 || j == 0 ? 1 : 2);
    }
  }

  long long ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      ans += D[i][j] * COM(N*M-2, K-2);
      ans %= MOD;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 6528
from sys import stdin
from collections import deque
input = stdin.readline

N, Q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N - 1)]
px = [list(map(int, input().split())) for _ in range(Q)]

tree = [[] for _ in range(N)]
count = [0] * N
seen = [0] * N

for a, b in ab:
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)

for p, x in px:
    count[p - 1] += x

d = deque([])


def dfs(p):
    d.append(p)
    seen[p] = 1

    while d:
        p = d.pop()

        for np in tree[p]:
            if seen[np] == 0:
                seen[np] = 1
                count[np] += count[p]
                d.append(np)


dfs(0)

for c in count:
    print(c, end=" ")

print()


Measured memory_bytes: 140772
program main;
var n,a,b,i :integer;
    c : boolean;
begin
    c := false;
    readln(n);
    readln(a,b);
    for i := a to b do
        if i mod n = 0
        then c := true;
    if c
    then writeln('OK')
    else writeln('NG');
end.

Measured memory_bytes: 1364
#include<stdio.h>
#include<stdlib.h>
int main(){
        int n,x;
        int i;
        int cnt;
        int min=0;
        int siyou=0;
        scanf("%d %d",&n,&x);
        int m[n];
        for(i=0;i<=n-1;i++){
                scanf("%d",&m[i]);
                siyou+=m[i];
                if(m[i]<m[min])min=i;
        }
 
        cnt=n;
 
        while(x-m[min]>=siyou){
                siyou+=m[min];
                cnt++;
        }
        printf("%d\n",cnt);
 
        return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
void judgement(int a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  if(a){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

int main(){
  ll i,j,H,W,K,bf;
  cin>>H>>W>>K;
  mat v(H,vec(W,0));
  string s;
  rep(i,H){
    cin>>s;
    bf=0;
    rep(j,W){
      if(s[j]=='#'){
        bf=K--;
      }
      v[i][j]=bf;
    }
  }
  rep(i,H){
    if(v[i][W-1]==0)continue;
    brep(j,W){
      if(v[i][j]==0)v[i][j]=v[i][j+1];
    }
  }
  rep1(i,H){
    if(v[i][0]==0)
    rep(j,W){
      v[i][j]=v[i-1][j];
    }
  }
  brep(i,H-1){
    if(v[i][0]==0)
    rep(j,W){
      v[i][j]=v[i+1][j];
    }
  }
  rep(i,H)output(v[i]);
  return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
using namespace std;

int main (void){
    string s;
    cin >> s;
    if (s == "ABC") {
        cout << "ARC" << endl;
    } else {
        cout << "ABC" <<endl;
    }
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

int n;
int a[100010];
int b[100010];

const int inf = 1e9;

bool val(){
	vector<int> vx, vy;
	for(int i=1; i<=n+1; ++i){
		vx.pb(a[i]); vy.pb(b[i]);
	}
	sort(all(vx)); sort(all(vy));
	for(int i=0; i<=n; ++i) if(vx[i] != vy[i]) return 0;
	return 1;
}

int cn;
void comp(){
	vector<int> xp;
	for(int i=1; i<=n+1; ++i) xp.pb(a[i]), xp.pb(b[i]);
	sort(all(xp));
	xp.erase(unique(all(xp)), xp.end());
	cn = xp.size();
	for(int i=1; i<=n+1; ++i){
		a[i] = lower_bound(all(xp), a[i]) - xp.begin();
		b[i] = lower_bound(all(xp), b[i]) - xp.begin();
	}
}

int par[100010];
int r(int x){ return (par[x]==x)?x:(par[x]=r(par[x])); }
void join(int a, int b){ par[r(a)]=r(b); }
bool ex[100010];

bool vis[100010];

int main()
{
	read(n);
	for(int i=1; i<=n; ++i) read(a[i]);
	for(int i=1; i<=n; ++i) read(b[i]);
	int x=0, y=0;
	for(int i=1; i<=n; ++i){
		x^=a[i]; y^=b[i];
	}
	a[n+1]=x; b[n+1]=y;
	comp();
	
	if(!val()){
		puts("-1");
		return 0;
	}
	
	for(int i=0; i<cn; ++i) par[i]=i;
	int df = 0;
	for(int i=1; i<=n; ++i){
		if(a[i] != b[i]){
			ex[a[i]]=1; ex[b[i]]=1;
			join(a[i], b[i]);
			++df;
		}
	}
	
	ex[a[n+1]]=1; ex[b[n+1]]=1;
	int comp = 0;
	for(int i=0; i<cn; ++i){
		if(!ex[i]) continue;
		if(vis[r(i)]) continue;
		++comp; vis[r(i)]=1;
	}
	
	printf("%d\n", df + comp - 1);
	return 0;
}


Measured memory_bytes: 4324
#include <stdio.h>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
    int n,m,sum=0,flag=0;
    scanf("%d %d",&n,&m);
    int *A;
    A = new int[n];
    for(int i=0;i<n;i++){
        scanf("%d",&A[i]);
        sum+=A[i];
    }

    sort(A,A+n,greater<int>());
    
    int border;
    if(sum%(4*m)==0){
        border=sum/(4*m);
    }else{
        border=sum/(4*m)+1;
    }
    for(int i=0;i<m;i++){
        if(A[i]<border){
            flag++;
            printf("No");
            break;
        }
    }
    if(flag==0){
        printf("Yes");
    }

    return 0;
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var s = Console.ReadLine();
        int curMaxLength = 0;
        var hash = new RollingHash(s);
        for (int i = 0; i < s.Length; i++)
            for (int j = i; j < s.Length; j++)
                while (curMaxLength < j - i && j + curMaxLength < n && hash.Slice(i, curMaxLength + 1) == hash.Slice(j, curMaxLength + 1)) curMaxLength++;
        Console.WriteLine(curMaxLength);
    }
}

class RollingHash
{
    const ulong MASK30 = (1UL << 30) - 1;
    const ulong MASK31 = (1UL << 31) - 1;
    const ulong MOD = (1UL << 61) - 1;
    const ulong POSITIVIZER = MOD * ((1UL << 3) - 1);
    static uint Base;
    static ulong[] powMemo = new ulong[5000 + 1];
    static RollingHash()
    {
        Base = (uint)new Random().Next(129, int.MaxValue);
        powMemo[0] = 1;
        for (int i = 1; i < powMemo.Length; i++)
            powMemo[i] = CalcMod(Mul(powMemo[i - 1], Base));
    }

    ulong[] hash;

    public RollingHash(string s)
    {
        hash = new ulong[s.Length + 1];
        for (int i = 0; i < s.Length; i++)
            hash[i + 1] = CalcMod(Mul(hash[i], Base) + s[i]);
    }

    public ulong Slice(int begin, int length)
    {
        return CalcMod(hash[begin + length] + POSITIVIZER - Mul(hash[begin], powMemo[length]));
    }

    private static ulong Mul(ulong l, ulong r)
    {
        var lu = l >> 31;
        var ld = l & MASK31;
        var ru = r >> 31;
        var rd = r & MASK31;
        var middleBit = ld * ru + lu * rd;
        return ((lu * ru) << 1) + ld * rd + ((middleBit & MASK30) << 31) + (middleBit >> 30);
    }

    /*private static ulong Mul(ulong l, uint r)
    {
        var lu = l >> 31;
        var rd = r & MASK31;
        var middleBit = lu * rd;
        return  (l & MASK31) * rd + ((middleBit & MASK30) << 31) + (middleBit >> 30);
    }*/

    private static ulong CalcMod(ulong val)
    {
        val = (val & MOD) + (val >> 61);
        if (val > MOD) val -= MOD;
        return val;
    }
}

Measured memory_bytes: 13264
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));
        br.readLine();
        String[] ips = br.readLine().split(" ");
        int len = ips.length;
        int[] cnta = new int[100005];
        int[] cntb = new int[100005];
        int mxa = 0;
        int mxb = 0;
        int mxa2 = 0;
        int mxb2 = 0;
        int besta = -1;
        int bestb = -1;
        
        for(int i = 0; i < len; i+=2){
            int curr = Integer.parseInt(ips[i]);
            cnta[curr]++;
            if(cnta[curr] > mxa){
                mxa = cnta[curr];
                besta = curr;
            }
        }
        
        for(int i = 1; i < len; i+=2){
            int curr = Integer.parseInt(ips[i]);
            cntb[curr]++;
            if(cntb[curr] > mxb){
                mxb = cntb[curr];
                bestb = curr;
            }
        }
        
        for(int i = 0; i < 100005; ++i){
            int f = cnta[i];
            int f2 = cntb[i];
            if(f <= mxa && i!=besta)
                mxa2 = Math.max(mxa2, f);
            if(f2 <= mxb && i!=bestb)
                mxb2 = Math.max(mxb2, f2);
        }
        
        int res = 0;
        if(besta != bestb){
            System.out.println(len-mxa-mxb);
            return;
        }
        res = Math.min(len-mxa2-mxb, len-mxa-mxb2);
        System.out.println(res);
    }
}

Measured memory_bytes: 37772
/**
 *    author:  FromDihPout
 *    created: 2020-08-06
**/

#include <bits/stdc++.h>
using namespace std;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    int p1 = 0, p2 = n-1;
    while (p1 < p2) {
        while (p1 < p2 && s[p1] != 'W') {
            p1++;
        }
        while (p1 < p2 && s[p2] != 'R') {
            p2--;
        }
        if (p1 < p2) {
            ans++;
            p1++;
            p2--;
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3752
use std::io::*;

const SP: u8 = b' ';
const LF: u8 = b'\n';

struct CharacterInput<'a> {
    locked_stdin: StdinLock<'a>,
    bytes_buffer: Vec<u8>,
}

impl<'a> CharacterInput<'a> {
    fn read(&mut self, delimiter: u8) -> &[u8] {
        self.bytes_buffer.clear();

        let len = self
            .locked_stdin
            .read_until(delimiter, &mut self.bytes_buffer)
            .unwrap();

        let end_index = match self.bytes_buffer.last() {
            Some(byte) => {
                if *byte == delimiter {
                    len - 1
                } else {
                    len
                }
            }
            None => len,
        };

        &self.bytes_buffer[0..end_index]
    }

    fn scan_u(&mut self, delimiter: u8) -> u32 {
        self.read(delimiter)
            .into_iter()
            .fold(0, |accumulator, byte| {
                (byte - b'0') as u32 + accumulator * 10
            })
    }

    fn scan_u_vec(&mut self, n: usize, separator: u8, delimiter: u8) -> Vec<u32> {
        let mut vector = Vec::with_capacity(n as usize);
        for _i in 0..n - 1 {
            vector.push(self.scan_u(separator));
        }
        vector.push(self.scan_u(delimiter));
        vector
    }
}

fn create_cin<'a>(input: StdinLock<'a>, buffer_capacity: usize) -> CharacterInput {
    CharacterInput {
        locked_stdin: input,
        bytes_buffer: Vec::with_capacity(buffer_capacity),
    }
}

fn println<T: std::string::ToString>(s: T) {
    println!("{}", s.to_string());
}

// ------------------------------------------------------------------------

fn main() {
    let cin = stdin();
    let cin = &mut create_cin(cin.lock(), 64);

    let n = cin.scan_u(SP) as usize;
    let k = cin.scan_u(LF) as usize;
    let a = cin.scan_u_vec(n, SP, LF);

    let mut count: usize = 0;
    let k_tri = k * (k + 1) / 2;
    let k_minus_one_tri = (k - 1) * k / 2;

    for i in 0..n {
        let a_1 = a[i];
        let mut former_count = 0;
        if i > 0 {
            for m in 0..i {
                let a_2 = a[m];
                if a_1 > a_2 {
                    former_count += 1;
                }
            }
        }
        let mut latter_count = 0;
        for m in i + 1..n {
            let a_2 = a[m];
            if a_1 > a_2 {
                latter_count += 1;
            }
        }
        // count = (count + former_count * k_minus_one_tri) % 1000000007;
        // count = (count + latter_count * k_tri) % 1000000007;
        count = (0..former_count).fold(count, |acc, _cur| (acc + k_minus_one_tri) % 1000000007);
        count = (0..latter_count).fold(count, |acc, _cur| (acc + k_tri) % 1000000007);
    }

    println(count);
}


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

int main(){
    
    int a[3][3], mark[3][3];
    for(int i = 0; i < 3; i++){
        for(int j = 0;j<3;j++){
            cin >> a[i][j];
        }
    }
    
    int N;
    cin >> N;
    int b[10];
    for(int i = 0; i < N; i++){
        cin >> b[i];
    }
    
    for(int i = 0; i < 3; i++){
        for(int j = 0; j<3; j++){
            mark[i][j] = 0;
            for(int k = 0; k < N; k++){
                if(a[i][j] == b[k]){
                    mark[i][j] = 1;
                }
            }
        }
    }
    
    string ans = "No";
    
    for(int i = 0; i < 3; i++){
        if(mark[0][i] == 1 && mark[1][i] == 1 && mark[2][i] == 1){
            ans = "Yes";
        }else if(mark[i][0] ==1 && mark[i][1] == 1 && mark[i][2] == 1){
            ans = "Yes";
        }
    }
    
    if(mark[0][0] == 1 && mark[1][1] == 1 && mark[2][2] == 1){
        ans = "Yes";
    }else if(mark[0][2] == 1 && mark[1][1] == 1 && mark[2][0] == 1){
        ans = "Yes";
    }
    
    cout << ans << endl;
    return 0;
}

    

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

cnt = 0
i = 1
while i <= n:
    is_broken = False
    string = list(str(i))
    for j, s in enumerate(string):
        if s not in ['3', '5', '7']:
            i = i + 10**(len(string) - j - 1)
            is_broken = True
            break
    if is_broken:
        continue

    c1 = string.count('3') >= 1
    c2 = string.count('5') >= 1
    c3 = string.count('7') >= 1
    if c1 and c2 and c3:
        cnt += 1

    i += 1

print(cnt)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int x2 = sc.nextInt();
		int y2 = sc.nextInt();
		int Xsa = x2-x;
		int Ysa = y2-y;
		StringBuilder R = new StringBuilder();
		for(int i = 0;i < Xsa; i++) {
			R.append("R");
		}
		StringBuilder U = new StringBuilder();
		for(int i = 0;i < Ysa; i++) {
			U.append("U");
		}
		String L = R.toString();
		L = L.replace("R", "L");
		String D = U.toString();
		D = D.replace("U","D");
		StringBuilder ans = new StringBuilder(R);
		ans.append(U).append(L).append(D).append("D").append(R).append("R").append(U).append("U")
		.append("L").append("U").append(L).append("L").append(D).append("D").append("R");
		System.out.println(ans);
	}
}


Measured memory_bytes: 25556
#include <stdio.h>
 
int main(void)
{
	int i=0,x;
	
	scanf("%d",&x);
	while(x!=0)
	{
		printf("Case %d: %d\n",i+1,x);
		i++;
		scanf("%d",&x);
	}
	
	
	
	return 0;
}

Measured memory_bytes: 596
#include <stdio.h>

int main(void) {
	int num_100;
	int num_500;
	int num_1000;
	int in_A,in_B;
	int rest;
	while(1) {
		scanf("%d%d",&in_A,&in_B);
		if(in_A==0 && in_B==0)break;
		rest=in_B-in_A;
		num_1000=rest/1000;
		rest%=1000;
		num_500=rest/500;
		rest%=500;
		num_100=rest/100;
		printf("%d %d %d\n",num_100,num_500,num_1000);
	}
	return 0;
}

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

int main() {
	int N;
	cin >> N;
	int64_t L[2] = {2, 1}; // 1個目の方に偶数を、2個目の方に奇数を入れていくよ
	for (int i = 2;i <= N;i ++) {
		L[i % 2] = L[0] + L[1]; // 漸化式通りの計算を行うよ
	}
	cout << L[N % 2];
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

とりあえず、10^18<=2^60より小さいと保証されているときは64bitの整数型を用いようね
自分はint64_t派だけど別にlong long intで良いと思うよ(C99なんて古いバージョン使ってるなら別)

次。見れば分かるようにリュカ数は漸化式で定義されているね
この形は必ずメモ化再帰や動的計画法を用いることができるよ
つまり、L3、L4と順にfor文とかで回しながら値を求めれば良いの

今回のソースコードのように、n項前までしか参照しない時はn個の要素を持つ配列だけでやりくりすることもできるよ
*/

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define EPS 10e-8

using namespace std;
typedef pair<int, int> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

int N, A[200000], sorted[200000];
int main(int argc, char **argv) {
    cin >> N;
    for(int i = 0; i < N; ++i) {
        cin >> A[i];
        sorted[i] = A[i];
    }

    sort(sorted, sorted + N);

    bool sw = sorted[N - 1] == sorted[N - 2];
    for(int i = 0; i < N; ++i) {
        if(A[i] == sorted[N - 1] && !sw)
            cout << sorted[N - 2] << endl;
        else
            cout << sorted[N - 1] << endl;
    }
    
}

Measured memory_bytes: 3200
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]
group = [i for i in range(n)]
islands = {i: [i] for i in range(n)}
ret = [0] * m + [n * (n - 1) // 2]
for i in range(m - 1, -1, -1):
    a, b = ab[i]
    ga, gb = group[a - 1], group[b - 1]
    if ga == gb:
        ret[i] = ret[i + 1]
    else:
        la, lb = len(islands[ga]), len(islands[gb])
        ret[i] = ret[i + 1] - la * lb
        if la > lb:
            for j in islands[gb]:
                group[j] = ga
                islands[ga].append(j)
        else:
            for j in islands[ga]:
                group[j] = gb
                islands[gb].append(j)
for i in range(1, m + 1):
    print(ret[i])

Measured memory_bytes: 55476
from functools import reduce

from itertools import product
k = int(input())
if k < 10:
    print(k)
else:
    i = 1
    sigma = 9
    while sigma < k:
        L = product([-1, 0, 1], repeat=i)
        # print(L)

        def f(n, v):
            returnlist = []
            for j in range(len(v)+1):
                if j == 0:
                    returnlist.append(n)
                else:
                    x = returnlist[-1]
                    returnlist.append(x + v[j-1])
            return returnlist
        biglist = []
        for v in L:
            for kk in range(1, 10):
                biglist.append(f(kk, v))
        # print(biglist)
        numbers = []
        for lists in biglist:
            if not (- 1 in set(lists) or 10 in set(lists)):
                x = [(10 ** (i - j)) * lists[j] for j in range(i+1)]
                y = reduce(lambda x, y: x + y, x)
                numbers.append(y)
        numbers.sort()
        if sigma + len(numbers) >= k:
            print(numbers[k - sigma - 1])
            sigma += len(numbers)
        else:
            sigma += len(numbers)
            i += 1


Measured memory_bytes: 53120
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll a,b,k;cin>>a>>b>>k;
  rep(i,k){
    if(i%2==0){
      b+=a/2;
      a/=2;
    }
    else {
      a+=b/2;
      b/=2;
    }
  }
  cout<<a<<" "<<b<<endl;
}
      

Measured memory_bytes: 256