akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.NoSuchElementException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BDigits solver = new BDigits();
        solver.solve(1, in, out);
        out.close();
    }

    static class BDigits {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long n = in.nextLong();
            long k = in.nextLong();
            out.println(convert(n, k));
        }

        long convert(long x, long n) {
            long y = 0;
            long i = 0;
            long z;
            while (x > 0) {
                z = x % n;
//            y += z * Math.pow(10, i);
                x = x / n;
                i++;
            }
            return i;

        }

    }

    static class Scanner {
        private final InputStream in;
        private final byte[] buffer;
        private int ptr;
        private int buflen;

        public Scanner(InputStream in) {
            this.in = in;
            this.buffer = new byte[1024];
            this.ptr = 0;
            this.buflen = 0;
        }

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

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

        private boolean isPrintableChar(byte c) {
            return '!' <= c && c <= '~';
        }

        private void skipUnprintable() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
                ptr++;
            }
        }

        public boolean hasNext() {
            skipUnprintable();
            return hasNextByte();
        }

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

    }
}



Measured memory_bytes: 21716
N=int(input())
S=["" for j in range(N)]
for i in range(N):
    S[i]=input()

ans=0
for i in range(0,N):
    flag=True
    for j in range(0,N):
        for k in range(0,N):
            flag=flag&(S[(k+i)%N][j]==S[(j+i)%N][k])
    ans+=N*int(flag)

print(ans)

Measured memory_bytes: 43688
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int n, m, c;
	int[][] a;
	P[] ps;
	int[][] w;
	int[] dx={0, 0, -1, 1};
	int[] dy={-1, 1, 0, 0};

	void run(){
		for(;;){
			m=sc.nextInt();
			n=sc.nextInt();
			if((m|n)==0){
				break;
			}
			ps=new P[11];
			c=1;
			a=new int[n][m];
			for(int j=0; j<n; j++){
				String s=sc.next();
				for(int i=0; i<m; i++){
					switch(s.charAt(i)){
					case '.':
						a[j][i]=-1;
						break;
					case 'x':
						a[j][i]=-2;
						break;
					case 'o':
						a[j][i]=0;
						ps[0]=new P(i, j);
						break;
					case '*':
						a[j][i]=c;
						ps[c]=new P(i, j);
						c++;
						break;
					}
				}
			}
			solve();
		}
	}

	void solve(){
		w=new int[c][c];
		for(int i=0; i<c; i++){
			bfs(i);
		}
		for(int j=0; j<c; j++){
			debug(w[j]);
			for(int i=0; i<c; i++){
				if(w[j][i]==-1){
					println("-1");
					return;
				}
			}
		}
		int[][] dp=new int[1<<c][c];
		for(int i=0; i<1<<c; i++){
			fill(dp[i], INF);
		}
		dp[1][0]=0;
		for(int s=1; s<1<<c; s++){
			for(int v=0; v<c; v++){
				for(int u=0; u<c; u++){
					// v->u
					if((s>>u&1)==0&&(s>>v&1)==1){
						dp[s|(1<<u)][u]=min(dp[s|(1<<u)][u], dp[s][v]+w[v][u]);
					}
				}
			}
			debug(s, dp[s]);
		}
		int min=INF;
		for(int i=1; i<c; i++){
			min=min(min, dp[(1<<c)-1][i]);
		}
		debug(min);
		println(""+min);
	}

	void bfs(int s){
		LinkedList<P> que=new LinkedList<Main.P>();
		int[][] d=new int[n][m];
		for(int j=0; j<n; j++){
			fill(d[j], -1);
		}
		d[ps[s].y][ps[s].x]=0;
		que.offer(ps[s]);
		for(; !que.isEmpty();){
			P p=que.poll();
			for(int i=0; i<4; i++){
				P q=new P(p.x+dx[i], p.y+dy[i]);
				if(q.x<0||q.x>=m||q.y<0||q.y>=n){
					continue;
				}
				if(a[q.y][q.x]!=-2&&d[q.y][q.x]==-1){
					d[q.y][q.x]=d[p.y][p.x]+1;
					que.offer(q);
				}
			}
		}
		for(int i=0; i<c; i++){
			w[s][i]=w[i][s]=d[ps[i].y][ps[i].x];
		}
	}

	class P{
		int x, y;

		P(int x, int y){
			this.x=x;
			this.y=y;
		}
	}

	void debug(Object... os){
		// System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    int N;
    cin >> N;
    int i = 0, j = 0;
    while(N >= pow(6, i + 1)) i++;
    while(N >= pow(9, j + 1)) j++;
    vector<int> dp(100010, INF);
    dp.at(N) = 0;
    for (int a = N; a >= 0; a--){
        for (int b = 0; b <= i; b++){
            if (a >= pow(6, b)){
                dp.at(a - pow(6, b)) = min(dp.at(a) + 1, dp.at(a - pow(6, b)));
                //cout << "B " << a << " " << pow(6, b) << endl;
            }
        }
        for (int c= 0; c <= i; c++){
            if (a >= pow(9, c)){
                dp.at(a - pow(9, c)) = min(dp.at(a) + 1, dp.at(a - pow(9, c)));
                //cout << "C " << a << " " << pow(9, b) << endl;
            }
        }
    }
    cout << dp.at(0) << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
    int n, m, k;
    cin >> n >> m >> k;
    vector<ll> a(n + 1), b(m + 1);
    for (int i = 0; i < n; i++) {
        cin >> a[i + 1];
        a[i + 1] += a[i];
    }
    for (int j = 0; j < m; j++) {
        cin >> b[j + 1];
        b[j + 1] += b[j];
    }
    
    ll ans = 0;
    for (ll i = 0, j = m; i <= n; i++) {
        if (a[i] > k) break;
        while (a[i] + b[j] > k) j--;
        ans = max(ans, i + j);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 6428
#include <stdio.h>

int main(void){
    int n,t=0,i,sign=0;
    char mozi[3];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%s",mozi);
        if(mozi[0] == 'A')
            t++;
        else
            t--;
        if(t == -1)
            sign=1;
    }
    if(sign == 1 ||  t != 0)
        printf("NO\n");
    else
        printf("YES\n");
    return 0;
}

Measured memory_bytes: 580
n, k = map(int, input().split())
s = input()

pre=s[0]
tmp=0
ans=0
check=0
for i in range(1, n):
    if s[i] != pre:
        check+=1
        pre=s[i]
        if check%2==1 and tmp < k:
            tmp+=1
            ans+=1
        if check%2==0 and tmp < k+1:
            ans+=1
            if tmp == k:
                tmp+=1
    else:
        ans+=1

print(ans)

Measured memory_bytes: 3316
#include <algorithm>
#include <queue>
#include <cstdio>
typedef long long LL ;
using namespace std ;
int main()
{
    char X[10];
    char Y[10];
    while(scanf("%s %s",X,Y)!=EOF)
    {
        int x,y;
        x=X[0]-'A';
        y=Y[0]-'A';
        if(x>y)
            printf(">\n");
        else if(x<y)
            printf("<\n");
        else
            printf("=\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
    int a, b;
 
    scanf("%d%d", &a, &b);
    if (a < b) printf("a < b\n");
    else if (a > b) printf("a > b\n");
    else printf("a == b\n");
    return 0;
}


Measured memory_bytes: 2036
//"I'll live the focused life, because it's the best kind there is" - Winifred Gallagher
#include<bits/stdc++.h>
using namespace std;
#define debug(a) cout << #a << ": " << a << endl

bool check(string s, vector<pair<int, char>> asset){
	for(auto tmp: asset){
		int id = tmp.first;
		char ch = tmp.second;
		if(s[id] != ch){
			return false;
		}
	}
	return true;
}
int main(){
	cin.tie(0);	ios::sync_with_stdio(false);
	vector<pair<int, char>> asset;
	int m, n; cin>>n>>m;
	while(m--){
		int s; char c; cin>>s>>c;
		s--;
		asset.push_back(make_pair(s, c));
	}
	for(int mask = 0; mask < pow(10, n); mask++){
		string s = to_string(mask);
		if(int(s.size()) == n && check(s, asset)){
			cout<<s<<endl;
			return 0;
		}
	}
	cout<<"-1\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int N, A, B;
      cin >> N >> A;
     B=N%500;
      if (B > A) {
        cout << "No" << endl;
      }
      else{
        cout << "Yes" <<endl;
      }
    }

Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<string>

using namespace std;

int main() {
  set<string> dic;
  string word;
  int n;
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> word;
    if(word == "insert"){
      cin >> word;
      dic.insert(word);
    }
    else {
      cin >> word;
      if(dic.count(word)) cout << "yes" <<endl;
      else cout << "no" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 32628
#include <bits/stdc++.h>
/*    #include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;       */
using namespace std;

#define ll long long
#define ull unsigned long long
#define f(a, b) for (ll i = a; i < b; i++)
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define pl pair<ll, ll>
#define vll vector<ll>
#define pll vector<pair<ll, ll>>
#define ld long double
#define fr(a, b) for (ll j = a; j >= b; j--)
#define fi(a, b) for (ll j = a; j < b; j++)
#define fii(a, b) for (ll k = a; k < b; k++)
#define print(x) cerr << #x << " is " << x << endl;
//      typedef tree<ll ,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int main()
{
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "rt", stdin);
//     freopen("output.txt", "wt", stdout);
// #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n, d;
    cin >> n >> d;
    ll k = 2 * d + 1;
    ll ans = n / k;
    if (n % k != 0)
        ans++;
    cout << ans;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Ho{
  static void Main(){
    var aho = Console.ReadLine().Split();
    var K = int.Parse(aho[0]);
    var N = int.Parse(aho[1]);
    var baka = Console.ReadLine().Split();
    var a = new List <int>();
    foreach(var ba in baka){
      a.Add(int.Parse(ba));
    }
    int saidai = a.Max();
    int saisyou = a.Min();
    int saigo = K-saidai+saisyou;
    int atumari = 0;
    var deka = 0;
    atumari += saigo;
    for(var i = 0;i<a.Count-1;i++){
      atumari += a[i+1]-a[i];
      if((a[i+1]-a[i]) > deka){
        deka = a[i+1]-a[i];
      }
    } 
    if(deka > saigo){
		Console.WriteLine(K-deka);
    }
    else{
      Console.WriteLine(K-saigo);
    }
  }
}
 

Measured memory_bytes: 34268
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  string S;
  cin >> S;
  const int INF = 1 << 25;
  vector<int> steps(N + 1, INF);
  vector<int> nex(N + 1, -1);
  steps[N] = 0;
  int t = N;
  for (; t > 0;) {
    if (S[t] == '1') continue;
    int c = max(t - M, 0);
    int mint = t;
    for (int k = t - 1; k >= c; --k) {
      if (S[k] == '1') continue;
      steps[k] = steps[t] + 1;
      nex[k] = t;
      mint = k;
    }
    if (mint == t && t != 0) {
      cout << -1 << endl;
      return 0;
    }
    t = mint;
  }

  int x = 0;
  while (true) {
    int y = nex[x];
    if (y == -1) break;
    if (x != 0) cout << " ";
    cout << (y - x);
    x = y;
  }
  cout << endl;
}


Measured memory_bytes: 4260
#include <bits/stdc++.h>
const int INF=1e9;
const int MOD=1e9+7;
//const int MOD=998244353;
const long long LINF=1e18;
using namespace std;
#define int long long
#define fin {cout<<"Bad"<<endl;return 0;}
//template

//main
signed main(){
  int a,b,c,d;cin>>a>>b>>c>>d;
  int ans=b-a+1;
  int k=(b/c);
  int q=((a-1)/c);
  ans-=(k-q);
  swap(c,d);
  k=(b/c);
  q=((a-1)/c);
  ans-=(k-q);
  c*=d/__gcd(c,d);
  k=(b/c);
  q=((a-1)/c);
  ans+=(k-q);
  cout<<ans<<endl;
}


Measured memory_bytes: 256
N, M, X = map(int, input().split())

C = []
A = []
for _ in range(N):
    c, *x = map(int, input().split( ))
    C.append(c)
    A.append(x)

inf = 10 ** 9 + 7
ans = inf
for bit in range(1 << N):
    tmp = [0] * M
    val = 0
    for i in range(N):
        if not (bit >> i & 1):
            continue

        val += C[i]
        for j in range(M):
            tmp[j] += A[i][j]
            
    # Check
    if all(v >= X for v in tmp):
        ans = min(ans, val)

print(ans if ans < inf else -1)


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

template<class Abel> struct UnionFind {
    vector<long long> par;
    vector<long long> rank;
    vector<Abel> diff_weight;

    UnionFind(long long n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(long long n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (long long i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    long long root(long long x) {
        if (par[x] == x) {
            return x;
        }
        else {
            long long r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(long long x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(long long x, long long y) {
        return root(x) == root(y);
    }

    bool merge(long long x, long long y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(long long x, long long y) {
        return weight(y) - weight(x);
    }
};

int main() {
    long long n,i;
    cin >> n;
    UnionFind<long long> uf(n);
    for (long long i = 0; i < n-1; ++i) {
        long long l, r, d;
        cin >> l >> r >> d;
        --l, --r;
        if (uf.issame(l, r)) {
        
            
        }
        else {
            uf.merge(l, r, d);
        }
    }
    for(i=0; i<n-1; i++){
    	cout << abs(uf.diff(0, i))%2<< endl;
    }
    cout << abs(uf.diff(0,n-1))%2;
}


Measured memory_bytes: 2816
using System;

namespace Program
{
	class test
    {
    	static void Main()
        {
          	string[] cs = new string[]{"A","C","G","T"};
        	string s = Console.ReadLine();
          	if(s == cs[0]) {
          		Console.WriteLine(cs[3]);
            }
            if(s == cs[1]) {
          		Console.WriteLine(cs[2]);
            }
            if(s == cs[2]) {
          		Console.WriteLine(cs[1]);
            }
            if(s == cs[3]) {
          		Console.WriteLine(cs[0]);
            }
        }
    }
}

Measured memory_bytes: 13140
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
int main()
{
	char s[55] = {0};
	scanf("%s",s);
	int l;
	l = strlen(s);
	s[l-8] = '\0';
	printf("%s\n",s);
	return 0;
}

Measured memory_bytes: 256
N, T = map(int, input().split())
t = list(map(int, input().split()))

ans = 0
for i in range(1, N):
    if t[i] - t[i - 1] > T:
        ans += T
    else:
        ans += t[i] - t[i - 1]
print(ans+T)       
        

Measured memory_bytes: 26708
#include<bits/stdc++.h>
using namespace std;
// include <ext/pb_ds/assoc_container.hpp>
// include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
// typedef tree <ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define vi vector<ll>
#define vvi vector<vi>
#define P_Q priority_queue<ll>
#define p_q priority_queue<ll,vi,greater<ll>>
#define pb push_back
#define popb pop_back
#define ub upper_bound
#define lb lower_bound
#define loop(i,x,y,z) for(int i=x; i<=y; i+=z)
#define loopR(i,x,y,z) for(int i=x; i>=y; i-=z)
#define all(x) begin(x), end(x)
#define allR(x) rbegin(x), rend(x)
#define sum(x) accumulate(all(x),0LL)
#define minE(x) *min_element(all(x))
#define maxE(x) *max_element(all(x))
#define watch(x) cout<<(#x)<<" is "<<x<<'\n'
#define display(v,c) for(auto x:v) cout<<x<<c;
#define setbits(x) __builtin_popcount(x)
#define ctoi(x) (int)((x)-'a')
#define endl "\n"

double dist(pii &a, pii &b){
	int dx = abs(a.first - b.first);
	int dy = abs(a.second - b.second);
	return sqrt(dx*dx + dy*dy);
}

int main(){
	IOS
	// do magic here
	int n,x,y;
	cin>>n;
	vector<pii> points;
	loop(i,0,n-1,1){
		cin>>x>>y;
		points.pb({x,y});
	}
	sort(all(points));
	ll fact=0;
	double d=0;
	do{
		fact++;
		loop(i,1,n-1,1) d+=dist(points[i],points[i-1]);
	}while(next_permutation(all(points)));
	double ans=d/fact;
	printf("%.6f",ans);
	return 0;
}


Measured memory_bytes: 256
fn main(){
    let mut n:i32 = getline().trim().parse().unwrap();
    if (n % 2 != 0) {
        n *= 2;
    }
    println!("{}", n);
}

fn getline() -> String{
    let mut r = String::new();
    std::io::stdin().read_line(&mut r).ok();
    return r;
}


Measured memory_bytes: 4352
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	char s[4003];
	scanf("%s", s);
	long long int cnt[3][4003];
	int i, j;
	cnt[0][n] = cnt[1][n] = cnt[2][n] = 0;
	for (i = n - 1; i >= 0; i--)
	{
		cnt[0][i] = cnt[0][i + 1];
		cnt[1][i] = cnt[1][i + 1];
		cnt[2][i] = cnt[2][i + 1];
		if (s[i] == 'R')
			cnt[0][i]++;
		else if (s[i] == 'G')
			cnt[1][i]++;
		else
			cnt[2][i]++;
	}
	long long int ans = 0;
	int p;
	for (i = 0; i < n; i++)
	{
		for (j = i + 1; j < n; j++)
		{
			if (s[i] != s[j])
			{
				if (s[i] != 'R' && s[j] != 'R')
					p = 0;
				else if (s[i] != 'G' && s[j] != 'G')
					p = 1;
				else
					p = 2;
				ans += cnt[p][j + 1];
				if (2 * j - i < n)
				{
					if (p == 0 && s[2 * j - i] == 'R')
						ans--;
					if (p == 1 && s[2 * j - i] == 'G')
						ans--;
					if (p == 2 && s[2 * j - i] == 'B')
						ans--;
				}
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1772
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll MOD = 1e9 + 7 ;
const ll dx[4] = { -1,1,0,0 };
const ll dy[4] = { 0,0,-1,1 };
const ll MAX =  3e3 + 10 ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
long long gcd(long long  a, long long  b) { return (b == 0 ? a : gcd(b, a % b)); }
ll n , m , x ,y, k , Q , ans ; string s,t;
bool dp[101010];
int a[101];


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);  cout.tie(0);
 //   freopen("test.in","r",stdin);

    cin>>n>>k;

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

    for(int i = 1 ; i <= k ; ++i)
        for(int j = 0 ; j < n ; ++j)
            if(i - a[j] >=0 && !dp[i - a[j]]){
            dp[i] = true;
            break;
            }

    cout<<(dp[k] ? "First\n":"Second\n");

    return 0;
}


Measured memory_bytes: 384
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 C = sc.nextInt();
    int D = sc.nextInt();
    System.out.println(Math.min(A,B) + Math.min(C,D)); 
  }
}

Measured memory_bytes: 22484
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  ll n,k;
  cin >> n >> k;
  
  map<ll,ll> mp;
  
  rep(i,n){
    ll a,b;
    cin >> a >> b;
    mp[a] += b;
  }
  
  ll ans;
  ll count = 0LL; 
  for(auto m:mp){
    //printf("%d,%d\n",m.first,m.second);
    count += m.second;
    if(count >= k){
      ans = m.first;
      break;
    }
  }
  
  cout << ans;
  
  return 0;
}

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

using ll = long long;
template<class T>
using V = vector<T>;

#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for(int i=m; i<n; i++)

int main(){
    int N;
    cin >> N;
    V<int> A(N);
    rep(i, N) cin >> A.at(i);
    int max = 1;
    ll sum = 0;
    rep(i, N){
        if(A.at(i) < max) sum += max - A.at(i);
        else max = A.at(i);
    }
    cout << sum << endl;
}

Measured memory_bytes: 4048
#include<stdio.h>
#include<math.h>

int main(){

  int i, j, cnt = 0, n, flag, num;

  scanf("%d",&n);

  for(i = 0; i < n; i++)
    {
      flag = 0;
      scanf("%d",&num);
      for(j = 2; j * j <= num; j++)
	{
	  if(num % j == 0)
	    {
	      flag = 1;
	      break;
	    }
	}
      if(flag != 1)cnt++;
    }
  printf("%d\n",cnt);
  return 0;
}



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

long double solve()
{
	int N, K;
	scanf("%d%d", &N, &K);
	long double ret{};
	for (int i{1}; i <= N; i++)
	{
		long double prob{1.0 / N};
		for (int j{i}; j < K; j *= 2)
			prob /= 2;
		ret += prob;
	}
	return ret;
}

int main()
{
	printf("%.10Lf\n", solve());
	return 0;
}

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

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

using namespace std;

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

ll bit[131072];
ll sum(int i){
	ll res = 0;
	for(; i; i -= i & -i) res += bit[i];
	return res;
}
void add(int i, int x){
	for(; i < 131072; i += i & -i) bit[i] += x;
}

const int B = 500;
int n, p[100000];
ll ans[200000];

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	cin >> n;
	rep(i, n) cin >> p[i];
	int q; cin >> q;
	
	vector<pair<pi, pi>> v; //l/B, r, l
	rep(i, q){
		int l, r; cin >> l >> r; l--;
		v.pb(mp(mp(l / B, r), mp(l, i)));
	}
	int cnt = 0;
	sort(all(v));
	int L = 0, R = 0; ll res = 0;
	for(auto &i: v){
		int r = i.first.second, l = i.second.first;
		while(R < r) { assert(L <= R); res += R - L - sum(p[R]);         add(p[R++], 1); }
		while(L > l) { assert(L <= R); res += sum(p[--L]);               add(p[L], 1); }
		while(L < l) { assert(L < R); res -= sum(p[L]) - 1;             add(p[L++], -1); }
		while(R > r) { assert(L < R); res -= R - L; res += sum(p[--R]); add(p[R], -1); }
		ans[i.second.second] = res;
	}
	rep(i, q) printf("%lld\n", ans[i]);
	
	return 0;
}

Measured memory_bytes: 8972
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define MP(a,b) make_pair(a,b)
typedef long long LL;
typedef pair<int, int> PI;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
const LL MOD = 1000000007LL;
int main() {
	string S;
	cin >> S;
	LL ans = 0;
	for (int bit = 0; bit < (1 << (S.size() - 1)); bit++) {
		LL num = S[0] - '0', sum = 0;
		for (int i = 0; i < S.size() - 1; i++) {
			if (bit&(1 << i)) sum += num, num = S[i + 1] - '0';
			else num = num * 10 + (S[i + 1] - '0');
		}
		sum += num;
		ans += sum;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        for (int i = 1; i < 10; i++)
        {
            for (int n = 1; n < 10; n++)
            {
                Console.WriteLine(i.ToString() + "x" + n.ToString() + "=" + (i*n).ToString());
            }
        }        
    }
}

Measured memory_bytes: 5512
#include<stdio.h>
int gcd(int, int);
int main(){

  int x,y,i,a=0;
  scanf("%d %d",&x,&y);
 a= gcd(x,y);

 printf("%d\n",a);
  return 0;
}
int gcd(int x,int y){
  int a,b,c,r;
  if(x<y){a=x;
  b=y;
  x=b;
  y=a;
  }

  while(y>0){
    r=x%y;
    x=y;
    y=r;
  }
  if(y!=0) return gcd(x,y);
  else  return x;
}



Measured memory_bytes: 2128
n,d=list(map(int, input().split()))
x=[]
y=[]
z=0
for i in range (n):
    a1,b1=[int(i) for i in input().split()]
    x.append(a1)
    y.append(b1)
for j in range (n):
    if x[j]**2+y[j]**2<=d**2:
        z+=1
print(z)


Measured memory_bytes: 24828
/*Bismillahir Rahmanir Rahim*/


#include<bits/stdc++.h>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#define ll long long int
#define dd double
using namespace std;

int main()
{
 long long a,b,x,y;
 cin>>a>>b;
  x=a%b;
  y=abs(x-b);
 if(x<y)
 cout<<x<<endl;
 else
 {
    cout<<y<<endl;
 }
 
 
}

Measured memory_bytes: 3640
n, a, b=map(int, input().split())
sum1=0
for i in range(n):
    num=str(i+1)
    sum2=0
    for j in range(len(num)):
        sum2+=int(num[j])
    if sum2>=a and sum2<=b:
        sum1+=i+1
print(sum1)


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

int main() {
  ll n;
  cin >> n;
  n = n - 1;
  vector<ll> a(12);
  rep(i,12){
    ll k = 1;
    rep(j,i+1){
      k = k * 26;
    }
    a[i] = k;
  }
  
  ll sum = 0;
  ll h = 0;
  while(sum <= n){
    sum += a[h];
    h++;
  }
  ll b = n - sum + a[h-1];
  
  ll c = 1;
  rep(i,h){
    c = c * 26;
  }
  c = c / 26;
 
  
  vector<ll> m(h);
  rep(i,h){
    m[i] = b / c;
    if(c == 1){
      break;
    }
    b = b % c;
    c = c / 26;
  }
    
  rep(i,h){
    cout << (char)(m[i] + 97);
  }
  return 0;
}

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

int main() {
  int k, a, b;
  cin >> k >> a >> b;
  for (int i = a; i <= b; i ++) {
    if (i % k == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
}


Measured memory_bytes: 3636
use std::io::*;
use std::str::*;

fn read<T: FromStr>(s: &mut StdinLock) -> T {
    let s = s.by_ref().bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}


fn main() {
    let s = stdin();
    let mut s = s.lock();
    let s = &mut s;

	let d = read::<f64>(s);
	let t = read::<f64>(s);
	let spd = read::<f64>(s);
	
	if d / spd > t {
		println!("No");
	} else {
		println!("Yes");
	}

}


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

int solve(int a, int b)
{
	if (a == b) return 0;
	if (a % 2) return solve(a + 1, b) + 1;
	if (b % 2) return solve(a, b - 1) + 1;
	return solve(a/2, b/2);
}

int main()
{
	int ncase;
	cin >> ncase;
	for (int cn = 0; cn < ncase; ++cn)
	{
		int a, b;
		cin >> a >> b;
		cout << solve(a, b) << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <iostream>

using namespace std;

int main()
{
  long long n, m, v, p;
  cin >> n >> m >> v >> p;
  
  long long a[100000];
  for (long long i = 0; i < n; i++)
    cin >> a[i];
  
  sort(a, a+n, greater<int>());
  
  long long cnt = p, sum = a[p-1];
  for (long long i = p; i < n; i++) {
    if (a[p-1] > a[i] + m) break;
    if (sum + max(0LL,(v-p-n+i+1))*m > (a[i]+m)*(i-p+1)) break;
    cnt++;
    sum += a[i];
  }
  
  cout << cnt << endl;
  
  return 0;
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second

typedef pair<lint, lint> P;
const lint MOD = 1e9+7;
const lint INF = MOD * MOD;
const int MAX = 100005;

int n;
vector<int> to[MAX];
bool seen[MAX];
int dist[MAX], dist2[MAX];

void dfs(int s){
    seen[s] = true;
    for(int& t : to[s]){
        if(seen[t]) continue;
        dist[t] = dist[s] + 1;
        dfs(t);
    }
}
void dfs2(int s){
    seen[s] = true;
    for(int& t : to[s]){
        if(seen[t]) continue;
        dist2[t] = dist2[s] + 1;
        dfs2(t);
    }
}

int main(){
    cin >> n;
    rep(i, n - 1){
        int a, b; cin >> a >> b; a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    dfs(0);
    memset(seen, false, sizeof(seen));
    dfs2(n-1);

    int p = 0, q = 0;
    rep(i, n){
        if(dist[i] <= dist2[i]) p++;
        else q++;
    }
    cout << ((p > q)?"Fennec":"Snuke") << endl;
}

Measured memory_bytes: 9728
n=int(input())
b=list(map(int,input().split()))
ans=[]
while len(b)>0:
    c=0
    for i in range(len(b))[::-1]:
        if b[i]==i+1:
            b.pop(i)
            ans=[i]+ans
            c=1
            break
    if c==0:
        print(-1)
        quit()
for i in ans:
    print(i+1)

Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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














int main(){
    ll n, x;
    cin >> n >> x;
    vector<pair<ll, pair<ll, pair<ll, ll>>>> v(n);
    REP(i, n){
        ll b, l, u;
        cin >> b >> l >> u;
        v[i] = {b * l + (x - b) * u, {b, {l, u}}};
    }
    sort(v.begin(), v.end(), greater<pair<ll, pair<ll, pair<ll, ll>>>>());
    ll lo = -1, up = x * n + 1;
    auto f = [&](ll k){
        ll q = k / x, r = k - q * x;
        if(r == 0){
            ll a_sum = 0, t_sum = 0;
            REP(i, n){
                ll b = v[i].second.first, l = v[i].second.second.first, u = v[i].second.second.second;
                if(i < q){
                    a_sum += b * u;
                    t_sum += x * u;
                }
                else{
                    a_sum += b * l;
                }
            }
            return a_sum <= t_sum;
        }
        else{
            ll a_sum = 0, sum = 0;
            REP(i, n){
                ll b = v[i].second.first, l = v[i].second.second.first, u = v[i].second.second.second;
                if(i < q + 1){
                    a_sum += b * u;
                }
                else{
                    a_sum += b * l;
                }
            }
            REP(i, q + 1){
                ll b = v[i].second.first, l = v[i].second.second.first, u = v[i].second.second.second;
                sum += x * u;
            }
            REP(i, n){
                ll b = v[i].second.first, l = v[i].second.second.first, u = v[i].second.second.second;
                if(i < q + 1){
                    ll t_sum = sum - x * u + r * ((r > b)? u : l);
                    if(a_sum - b * u + b * ((r > b)? u : l) <= t_sum) return true;
                }
                else{
                    ll t_sum = sum - x * v[q].second.second.second + r * ((r > b)? u : l);
                    if(a_sum - v[q].second.first * (v[q].second.second.second - v[q].second.second.first) + b * ((r > b)? (u - l) : 0) <= t_sum) return true;
                }
            }
            return false;
        }
    };
    while(up - lo > 1){
        ll k = (lo + up) / 2;
        (f(k)? up : lo) = k;
    }
    cout << up << endl;
}

Measured memory_bytes: 3328
module Main where

solve m as
	| (<=) m $ length $ filter (>= ((sum as) / (4 * (fromIntegral m)))) as = "Yes"
	| otherwise = "No"

main = do
	line1 <- getLine
	line2 <- getLine
	let m = read . last . words $ line1
	let as = map (read) . words $ line2
	putStrLn $ solve m as





Measured memory_bytes: 1020
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int[][] field = new int[H][W];
        for(int i = 0; i < H; i++) {
            String line = sc.next();
            for(int j = 0; j < line.length(); j++) {
                char c = line.charAt(j);
                field[i][j] = c - '0';
            }
        }
        int[][] dp = new int[H][W];
        for(int i = 0; i < H; i++) {
            for(int j = 0; j < W; j++) {
                dp[i][j] = 100000000;
            }
        }
        dp[0][0] = 0;
        for(int i = 0; i < H; i++) {
            for(int j = 0; j < W; j++) {
                if(i < H - 1) dp[i + 1][j] = Math.min(dp[i + 1][j], dp[i][j] + field[i + 1][j]);
                if(j < W - 1) dp[i][j + 1] = Math.min(dp[i][j + 1], dp[i][j] + field[i][j + 1]);
            }
        }
        System.out.println(dp[H - 1][W - 1]);
    }
}

Measured memory_bytes: 17372
#include<stdio.h>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<math.h>
#include<algorithm>
using namespace std;

#define INF 987654321
#define ll long long

int N;

int f(int A, int K)
{
	if (A < K) return 0;
	if (A % K == 0) return A / K;

	int x = (A%K - 1) / (A / K + 1) + 1; //A%K-1에서 1을 빼면 A%K==0인 경우만 예외로 뺄 수 있다.
	return f(A - x * (A / K + 1), K); //O(sqrt(A)) Optimization
}

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

	int res = 0, one = 0, zero = 0;
	for (int i = 0; i < N; i++)
	{
		int A, K;
		scanf("%d %d", &A, &K);
		int val = f(A, K);
		res ^= val;
		if (val == 0) zero++;
		else if (val == 1) one++;
	}
	
	if (one + zero == N)
	{
		if (one % 2 == 1) printf("Takahashi");
		else printf("Aoki");
	}
	else
	{
		if (res == 0) printf("Aoki");
		else printf("Takahashi");
	}

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, s, e) for (ll i = s; i < e; i++)
#define Forr(i, s, e) for (ll i = s; i > e; i--)
#define pb push_back
#define ll long long
#define int ll
#define mp make_pair
#define infi 1e12
const ll mod = 1e9 + 7;
vector<ll> lol;
ll n;
ll dfs(vector<vector<ll>> &v, ll node, ll p)
{
    ll count = 0;
    for (auto itr : v[node])
    {
        if (itr != p)
        {
            count += dfs(v, itr, node);
        }
    }
    if (p != -1)
    {
        ll x = (count + 1) * (n - count - 1);
        lol.pb(x);
    }
    return count + 1;
}
signed main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout << fixed << setprecision(8);
    string s;
    cin >> s;
    ll sum = 0;
    For(i, 0, s.size())
    {
        sum += s[i] - '0';
    }
    if (sum % 9 == 0)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}

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

int max(int a,int b)
{
  int temp;
  if(a+b > a*b)
    temp = a+b;
  else
    temp = a*b;
  if(temp > a-b)
    return temp;
  else 
    return a-b;
}

int main()
{
  int a,b;
  cin>>a>>b;
  cout<<max(a,b);
  return 0;
  
}

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

typedef long long ll;
ll n, l, r, a[100005];
int main()
{
	ll i;
	cin >> n;
	for (i =0; i <n; i++) {
		scanf ("%lld", &a[i]);
	}
	l = r = 2;
	for (i = n - 1; i >= 0; i--) {
		l = ((l + a[i] - 1) / a[i]) * a[i];
		r = (r / a[i]) * a[i] + a[i] - 1;
		if (l > r) {
			cout << -1;
			return 0;
		}
	}
	cout << l << " " << r;
    return 0;
}


Measured memory_bytes: 1024
//By TheOneYouWant
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i=0;i<e;++i)
#define forsn(i,s,e) for(int i=s;i<e;++i)
#define rforn(i,s) for(int i=s;i>=0;--i)
#define rforsn(i,s,e) for(int i=s;i>=e;--i)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define ln '\n'
#define getcurrtime() cerr<<"Time = "<<((double)clock()/CLOCKS_PER_SEC)<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)
#define dbg(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cerr<<endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << "\t"; err(++it, args...);
}
template<typename T1,typename T2>
ostream& operator <<(ostream& c,pair<T1,T2> &v){
	c<<"("<<v.fi<<","<<v.se<<")"; return c;
}
template <template <class...> class TT, class ...T>
ostream& operator<<(ostream& out,TT<T...>& c){
    out<<"{ ";
    forstl(x,c) out<<x<<" ";
    out<<"}"; return out;
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM=2e5+5,MOD=1e9+7;
const ld EPS = 1e-9;

int read(){
    int xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=(xx<<3)+(xx<<1)+ch-'0';ch=getchar();}
    return xx*ff;
}

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

int main(){
	fastio;

	int n = read();
	int t[n], a[n];
	forn(i,n) t[i] = read();
	forn(i,n) a[i] = read();

	ll maxval[n] = {0};
	ll actval[n] = {0};
	
	forn(i,n){
		maxval[i] = MOD;
		actval[i] = -1;
	}

	ll curmax = -1;
	forn(i,n){
		if(t[i] > curmax){
			curmax = t[i];
			actval[i] = curmax;
		}
		maxval[i] = min(maxval[i], curmax);
	}

	bool pos = 1;
	curmax = -1;
	rforn(i,n-1){
		if(a[i] > curmax){
			curmax = a[i];
			if(actval[i] != -1 && actval[i] != curmax) pos = 0;
			actval[i] = a[i];
		}
		if(actval[i] > a[i]) pos = 0;
		maxval[i] = min(maxval[i], curmax);
	}

	ll ans = 1;

	if(!pos){
		cout<<0<<ln;
		return 0;
	}

	forn(i,n){
		if(actval[i] != -1) continue;
		ans *= maxval[i];
		ans %= MOD;
	}
	cout<<ans<<ln;


	return 0;
}

Measured memory_bytes: 6036
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back
const ll MOD = 998244353; 

// 繰り返し2乗法
ll power(ll a, ll n)
{
        ll ret = 1;
        // kの下の桁から処理。右シフトで処理し終わった桁を追い出す
        // ゼロになるまでやる
        for (; n > 0; n >>= 1, a = a * a % MOD)
        {
                if (n % 2 == 1)
                {
                        ret = ret * a % MOD; // 再帰でも書ける
                }
        }
        return ret;
}

const int MAX = 510000;

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;
    }
}

// 二項係数計算, COM(n,k)でコンビネーションの計算結果が出てくる
// MODで割ってくれてる
long long COM(int n, int k){
    if (n < k) return 1;
    if (n < 0 || k < 0) return 1;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
  ll N, M, K;
  ll ans = 0, cnt = 0;
  cin >> N >> M >> K;
  COMinit();

  rep(i, K+1){
    if(i > 0){
      ans = ans + COM(N-1, i)*M%MOD*power(M-1, N-i-1)%MOD;
      ans %= MOD;
    } else { // あってる
      ans = ans + M*power(M-1, N-i-1)%MOD;
    }
    ans %= MOD;
  }
  print(ans);

}


Measured memory_bytes: 15552
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let nmd: Vec<f64> = read_vec();
    let n = nmd[0];
    let m = nmd[1];
    let d = nmd[2];
    let mut ans = (n - d) * (m - 1.0) / n / n;
    if d != 0.0 {
        ans *= 2.0;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
import java.math.BigInteger;
import java.util.Scanner;

public class Main
{

  public static void main(String[] args)
  {
    try (Scanner scanner = new Scanner(System.in))
    {
      while (scanner.hasNextLine())
      {
        String[] tmp = scanner.nextLine().split(" ");
        int n = Integer.valueOf(tmp[0]);
        int m = Integer.valueOf(tmp[1]);
        int r = Integer.valueOf(tmp[2]);

        System.out.println(solver(n, m, r));
      }
    }
  }

  private static BigInteger solver(int n, int m, int r)
  {
    if (n * m > r)
    {
      return new BigInteger("0");
    }

    if (n * m == r)
    {
      return new BigInteger("1");
    }

    return hcombination(n, r-(n*m));
  }

  private static BigInteger hcombination(int n, int r)
  {
    BigInteger fact_a = fact(n+r-1);
    BigInteger fact_b = fact(r);
    BigInteger fact_c = fact(n-1);

    return fact_a.divide(fact_b.multiply(fact_c));
  }

  private static BigInteger fact(int n)
  {
    BigInteger ans = new BigInteger("1");

    for (int i = n; i > 1; i--)
    {
      ans = ans.multiply(new BigInteger(String.valueOf(i)));
    }
    return ans;
  }

}



Measured memory_bytes: 285360
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
int main(){
  int n, ans=0;
    cin >> n;
    if(n%2)
      ans = n/2*(n/2+1);
    else ans = n*n/4;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<string.h>
using namespace std;

int h[1500*1000+1];
int w[1500*1000+1];
int inh[1500],inw[1500];

int main() {
int N,M,in;
  while(scanf("%d %d",&N, &M), N|M) {
    for(int i=0; i<N; ++i)
      scanf("%d", &inh[i]);
    for(int i=0; i<M; ++i)
      scanf("%d", &inw[i]);

    memset(h, 0, sizeof(h));
    memset(w, 0, sizeof(w));

    for(int i=0; i<N; ++i) {
      int sum = 0;
      for(int j=i; j<N; ++j) {
	sum += inh[j];
	h[sum]++;
      }
    }

    for(int i=0; i<M; ++i) {
      int sum = 0;
      for(int j=i; j<M; ++j) {
	sum += inw[j];
	w[sum]++;
      }
    }

    int count = 0;
    for(int i=1; i<=1500*1000; ++i)
      count += h[i]*w[i];

    printf("%d\n",count);

  }
}

Measured memory_bytes: 12000
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;
#define MP make_pair
#define PB push_back
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

struct compare {
    bool operator()(const PII& value, const int& key) {
        return (value.first < key);
    }
    bool operator()(const int& key, const PII& value) {
        return (key < value.first);
    }
};
string zeropad(int i, int n) {
    int I = i;
    int count = 0;
    while (I > 0) {
        I /= 10;
        ++count;
    }
    string res = "";
    REP(k, n - count) {
        res += "0";
    }
    res += to_string(i);
    return res;
}
int main(void){
    // Your code here!
    int N, M;
    cin >> N >> M;
    vector<vector<int> > PY;
    REP(i, N + 1) {
        vector<int> y;
        PY.PB(y);
    }
    vector<PII> Y;
    REP(i, M) {
        int p, y;
        cin >> p >> y;
        PY[p].PB(y);
        Y.PB(MP(y, i));
    }
    sort(Y.begin(), Y.end());
    string ID[M];
    REP(i, N + 1) {
        sort(PY[i].begin(), PY[i].end());
        int id = 1;
        for(vector<int>::iterator it = PY[i].begin(); it != PY[i].end(); ++it) {
            int index = (*lower_bound(Y.begin(), Y.end(), *it, compare())).second;
            ID[index] = zeropad(i, 6) + zeropad(id, 6);
            ++id;
        }
    }
    REP(i, M) {
        cout << ID[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 13168
//https://qiita.com/tanakh/
#[allow(unused_macros)]
macro_rules! input {
	(source = $s:expr, $($r:tt)*) => {
		let mut iter = $s.split_whitespace();
		let mut next = || { iter.next().unwrap() }; 
		input_inner!{next, $($r)*}
	};
	($($r:tt)*) => {

		let stdin = std::io::stdin();
		let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); 
		let mut next = move || -> String{
			bytes
				.by_ref()
				.map(|r|r.unwrap() as char) 
				.skip_while(|c|c.is_whitespace()) 
				.take_while(|c|!c.is_whitespace()) 
				.collect()
			};
	input_inner!{next, $($r)*} 
	};
}

#[allow(unused_macros)]
macro_rules! input_inner { 
	($next:expr) => {}; 
	($next:expr, ) => {};

	($next:expr, $var:ident : $t:tt $($r:tt)*) => { 
		let $var = read_value!($next, $t); 
		input_inner!{$next $($r)*}
	}; 
}
#[allow(unused_macros)]
macro_rules! read_value { 
	($next:expr, ( $($t:tt),* )) => {
		( $(read_value!($next, $t)),* ) 
	};
	
	($next:expr, [ $t:tt ; $len:expr ]) => {
		(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
	};

	($next:expr, chars) => {
		read_value!($next, String).chars().collect::<Vec<char>>()
	};
	
	($next:expr, bytes) => {
		read_value!($next, String).into_bytes()
	};
	
	($next:expr, usize1) => { 
		read_value!($next, usize) - 1
	};

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

fn main(){
    input!{
        n : usize,
        l :[i64; n],
    }
    let mut count : i64 = 0;
    let mut max : i64 = 0;
    for i in 0..n {
        count = count + l[i];
        if max < l[i]{
            max = l[i];
        }
    }
    let mut ans : i64  = 0;
    ans = count - max;
    //println!("{}",ans);
    if max < ans {
        println!("{}","Yes");
    } else {
        println!("{}","No");
    }
}

Measured memory_bytes: 4352