akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	Scanner sc = new Scanner(System.in);
	int INF = 1 << 28;
	double EPS = 1e-10;

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

	void run() {
		String a = sc.next();
		int ans = 0;
		for (int i = 0; i < a.length(); i++) {
			String head = a.substring(0, i);
			String tail = a.substring(i, a.length());
			int h, t;
			if (head.equals("")) {
				h = 0;
			} else if (head.equals("-")) {
				continue;
			} else {
				h = Integer.parseInt(head);
			}
			if (tail.equals("")) {
				t = 0;
			} else if (tail.charAt(0) == '0') {
				continue;
			} else {
				t = Integer.parseInt(tail);
			}
			if (t < 0) {
				continue;
			}
			if (h > t)
				continue;
			if ((h + t) % 2 != 0) {
				continue;
			}
			if ((t - h) % 2 != 0) {
				continue;
			}
			ans++;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 17324
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,l,n) for(int i=l; i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  int n; cin>>n;
  vector<int> p(n),q(n);
  REP(i,n) cin>>p[i];
  REP(i,n) cin>>q[i];
  
  vector<int> order(n);
  REP(i,n) order[i]=i+1;

  int cnt=0, a, b;
  do{
    bool chk_p=true, chk_q=true;
    REP(i,n){
      if(order[i]!=p[i]) chk_p=false;
      if(order[i]!=q[i]) chk_q=false;
    }
    cnt++;
    if(chk_p) a=cnt;
    if(chk_q) b=cnt;
  } while (next_permutation(order.begin(), order.end()));
  
  cout << abs(a-b) << endl;
}

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

long long int a[200005], sum;
int main() {
  long long int n;
  cin >> n;
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long int j;
  for (long long int i = 0; i < n-1; i++) {
    j = i + 1;
    if (a[i] > a[j]) {
      sum += (a[i] - a[j]);
      a[j] = a[i];
    }
  }
  cout << sum << endl;
  system("pause");
  return 0;
}


Measured memory_bytes: 5232
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;

int main()
{
    int K,e=0,o=0;

    cin>>K;

    for(int i=1;i<=K;i++){
        if(i%2==1){
            o++;
        }else{
            e++;
        }
    }

    cout << o*e<<endl;

    return 0;
}


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

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> l(n);
	for (int i = 0; i < n; i++) {
		cin >> l[i];
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			for (int k = j + 1; k < n; k++) {
				int triangle[3] = {l[i], l[j], l[k]};
				sort(triangle, triangle + 3);
				bool works = triangle[0] + triangle[1] > triangle[2];
				for (int m = 0; m < 3; m++) {
					for (int p = m + 1; p < 3; p++) {
						if (triangle[p] == triangle[m]) {
							works = false;
						}
					}
				}
				ans += works;
			}
		}
	}
	cout << ans << '\n';
}



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

using namespace std;

typedef long long ll;
const int MAX_N = (1<<18)-1;

vector<ll> x;
vector<ll> dat[MAX_N];

void init(int k, int l, int r)
{
    if (r - l == 1) {
        dat[k].push_back(x[l]);
    } else {
        int lch = k * 2 + 1, rch = k * 2 + 2;
        init(lch, l, (l + r) / 2);
        init(rch, (l + r) / 2, r);
        dat[k].resize(r - l);

        merge(dat[lch].begin(), dat[lch].end(),
              dat[rch].begin(), dat[rch].end(),
              dat[k].begin());
    }
}

int query(int i, int j, ll x, int k, int l, int r)
{
    if (j <= l || r <= i) {
        return 0;
    } else if (i <= l && r <= j) {
        return upper_bound(dat[k].begin(), dat[k].end(), x) - dat[k].begin();
    } else {
        int lc = query(i, j, x, k * 2 + 1, l, (l + r) / 2);
        int rc = query(i, j, x, k * 2 + 2, (l + r) / 2, r);
        return lc + rc;
    }
}

int main()
{
    ll D, Q, l, r, e;
    cin >> D;
    x.resize(D);
    for (int i = 0; i < D; i++) {
        cin >> x[i];
    }    
    
    init(0, 0, D);
    
    cin >> Q;
    while (Q--) {
        cin >> l >> r >> e;
        l--; r--;
        ll a = min(x[l], x[r]) - e, b = max(x[l], x[r]) + e;
        
        cout << query(l, r, a-1, 0, 0, D) + (r - l + 1) - query(l, r+1, b, 0, 0, D) << endl;
    }
    return 0;
}

Measured memory_bytes: 27176
A, B, C, K = map(int, input().split())

if K < A:#KがAより小さければ最大値はK
    max = K
else:
    if K < A+B:#KがA+Bより小さければ最大値はA
        max = A
    else:
        if K < A+B+C:#KがA+B+Cより小さければ最大値はA-(K-A-B)
            max = A + B*0 + (K-A-B)*-1
        else:
            max = A + B*0 + C*(-1)

print(max)


Measured memory_bytes: 9180
import fractions

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

N = int(input())
T = []
for i in range(N):
	T.append(int(input()))

ans = T[0]
for i in range(N - 1):
	ans = (ans * T[i + 1])//fractions.gcd(ans, T[i + 1])
print(ans)

Measured memory_bytes: 64364
IDENTIFICATION DIVISION.
       PROGRAM-ID. ABC044-B.
       DATA DIVISION.
       FILE SECTION.
       WORKING-STORAGE SECTION.
       77 W PIC X(100).
       77 I PIC 9(3).
       77 CN PIC 9(2).
       01 WCC.
        03 CC OCCURS 26 PIC 9(3) VALUE ZERO.
       77 NFLG PIC 9(1) VALUE ZERO.

       PROCEDURE DIVISION.
       MAIN-PROCEDURE.
            ACCEPT W FROM SYSIN.
            PERFORM VARYING I FROM 1 BY 1
             UNTIL FUNCTION STORED-CHAR-LENGTH (W) < I
               COMPUTE CN = FUNCTION ORD (W(I:1))
                               - FUNCTION ORD ("`")
               ADD 1 TO CC(CN)
            END-PERFORM.
            PERFORM VARYING I FROM 1 BY 1 UNTIL 26 < I
               IF FUNCTION REM (CC(I),2) = 1 THEN
                   MOVE 1 TO NFLG
                   EXIT PERFORM
               END-IF
            END-PERFORM.
            IF NFLG = 1 THEN
               DISPLAY "No"
            ELSE
               DISPLAY "Yes"
            END-IF
            STOP RUN.
       END PROGRAM ABC044-B.


Measured memory_bytes: 384
N, K = $stdin.gets.split.map {|i| i.to_i }
A = $stdin.gets.split.map {|i| i.to_i }
passed = [-1] * N
pos = 1
count = nil
1.upto(K) do |c|
  if passed[pos - 1] > 0
    count = c
    break
  end
  passed[pos - 1] = c
  pos = A[pos - 1]
  #$stderr.puts "* #{c} / #{pos}"
end
#$stderr.puts passed.to_s
if count
  loop_start = passed[pos - 1]
  loop_count = count - loop_start
  rest = (K - loop_start) % loop_count + 1
  #$stderr.puts "* ls = #{loop_start} / lc = #{loop_count} / rest = #{rest}"
  1.upto(rest) do
    pos = A[pos - 1]
    #$stderr.puts "** #{pos}"
  end
end
puts pos


Measured memory_bytes: 28912
#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, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
#define MOD 1000000007
#define INF 1000000000000000007
#define MAXN 100005

// it's swapnil07 ;)


signed main(){
    fast
    #ifdef SWAPNIL07
        freopen("/home/swapnil/Desktop/c++/input.txt","r",stdin);
        freopen("/home/swapnil/Desktop/c++/output.txt","w",stdout);
    #endif
    int m, k; cin>>m>>k;
    int maxv = pow(2, m)-1;
    if(k==0){
        For(i, 0, maxv+1){
            cout<<i<<" "<<i<<" ";
        }
        return 0;
    }
    if(k>maxv){
        cout<<-1;
        return 0;
    }
    int xv = 0;
    For(i, 0, maxv+1){
        if(i!=k){
            xv = xv^i;
        }
    }
    if(xv!=k){
        cout<<-1;
        return 0;
    }
    cout<<k<<" ";
    For(i, 0, maxv+1){
        if(i!=k){
            cout<<i<<" ";
        }
    }
    cout<<k<<" ";
    for(int i=maxv; i>=0; i--){
        if(i!=k){
            cout<<i<<" ";
        }
    }
    return 0;
}

Measured memory_bytes: 1792
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
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;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

ll memo[100010];
int a[100010];
int n, m;

ll calc(int x) {
	if (a[x] == 1) return 0;
	if (x > n) return 0;
	if (x == n) return 1;
	ll& res = memo[x];
	if (~res) return res;
	res = 0;
	res += calc(x + 1);
	res %= INF;
	res += calc(x + 2);
	res %= INF;
	return res;
}

void solv() {
	
	int a, p;
	cin >> a >> p;
	cout << ((a * 3) + p) / 2 << endl;
}

int main() {
	//COMinit();
	solv();

	return 0;
}
 

Measured memory_bytes: 256
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

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

fn main() {
    input! {
        a: usize, b: usize, c: usize
    }

    println!("{}", std::cmp::min(b / a, c));
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

int N;

struct Info{
	double x,y,z,r;
};

struct Data{
	Data(int arg_to,double arg_cost){
		to = arg_to;
		cost = arg_cost;
	}
	int to;
	double cost;
};

double calc(Info left,Info right){
	return sqrt((left.x-right.x)*(left.x-right.x)+(left.y-right.y)*(left.y-right.y)+(left.z-right.z)*(left.z-right.z));
}

int main(){

	Info info[100];
	vector<Data> V[100];
	vector<int> Group;
	bool check[100];
	double ans,dist,tmp_min;
	int count,min_index,index;

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		for(int i = 0; i < N; i++){
			V[i].clear();
			check[i] = false;
		}
		Group.clear();

		for(int i = 0; i < N; i++){
			scanf("%lf %lf %lf %lf",&info[i].x,&info[i].y,&info[i].z,&info[i].r);
		}

		for(int i = 0; i < N-1; i++){
			for(int k = i+1; k < N; k++){
				dist = calc(info[i],info[k]);
				if(dist <= info[i].r+info[k].r){
					V[i].push_back(Data(k,0.0));
					V[k].push_back(Data(i,0.0));
				}else{
					dist -= (info[i].r+info[k].r);
					V[i].push_back(Data(k,dist));
					V[k].push_back(Data(i,dist));
				}
			}
		}

		ans = 0.0;

		count = 1;

		Group.push_back(0);
		check[0] = true;

		while(count < N){

			tmp_min = DBL_MAX;

			for(int i = 0; i < Group.size(); i++){
				index = Group[i];
				for(int k = 0; k < V[index].size(); k++){
					if(check[V[index][k].to] == false && tmp_min > V[index][k].cost){
						min_index = V[index][k].to;
						tmp_min = V[index][k].cost;
					}
				}
			}

			ans += tmp_min;
			check[min_index] = true;
			Group.push_back(min_index);
			count++;
		}

		printf("%.3lf\n",ans);
	}

	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
int main(){
    int n,m;cin>>n>>m;
    int a[100010];
    fill(a,a+100010,0);
    rep(i,0,m){
        int l,r;cin>>l>>r;
        a[l]++;
        a[r+1]--;
    }
    int ans=0;
    int now=0;
    rep(i,1,100001){
        now+=a[i];
        if(now==m)ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
	int n,k; cin>>n>>k;
	for(int i=-1000000;i<=1000000;i++){
		if(abs(k-i)<n){
			cout<<i;
			if(abs(k-i-1)<n){
				cout<<" ";
			}
		}
	}
	cout<<endl;
	
}


Measured memory_bytes: 256
S = input()
Sa = S.replace("?", "a")
T = input()
nt = len(T)
ans = list()
for i in range(len(S) - nt + 1):
    X = S[i: i + nt]
    for x, t in zip(X, T):
        if x == "?":
            continue
        if x != t:
            break
    else:
        ans.append(Sa[:i] + T + Sa[i + nt:])
ans.sort()
print(ans[0] if ans else "UNRESTORABLE")


Measured memory_bytes: 9060
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int M = scan.nextInt();
			int X= scan.nextInt();
			int [][]A = new int[N][M];
			int []C = new int[N];
			int []x = new int [M];
			long goukei=0;
			long min = Long.MAX_VALUE;
			
			for(int i = 0;i<N;i++) {
				C[i] = scan.nextInt();
				for(int j = 0;j<M;j++) {
					A[i][j] = scan.nextInt();
				}
			}
			
			
			for(int i = 0;i<(int)Math.pow(2, N);i++) {
				int okcount = 0;
				goukei=0;
				Arrays.fill(x, 0);
				
				
				for(int j = 0;j<N;j++) {
					
					if((1&i>>j)==1) {
						goukei+=C[j];
						for(int z = 0;z<M;z++) {
							x[z]+=A[j][z];
						}
					}
					
					
				}
				/*
				for(int j = 0;j<M;j++) {
					System.out.print(x[j]);
					System.out.print(" ");
				}
				System.out.println();
				*/
				for(int j = 0;j<M;j++) {
					if(x[j]>=X) {
						okcount++;
					}
				}
				
				if(okcount==M&&min>goukei) {
					min=goukei;
				}
				
				
			}
			
			
			
			if(min==Long.MAX_VALUE) {
				System.out.println(-1);
			}else {
				System.out.println(min);
			}
			
			
		}
		
		
	}
		

}


Measured memory_bytes: 37188
fun main (args : Array<String>) {
	val (n, a, b) = readLine()!!.split(" ")
	val N : Int = n.toInt()
	val A : Int = a.toInt()
	val B : Int = b.toInt()
	return if ( (N * A) <= B) {
		println("${N * A}")
	} else {
		println("${B}")
	}
}

Measured memory_bytes: 38004
using System;
using System.Collections.Generic;
using System.Linq;

namespace B_ABC131
{
    class MainClass
    {

        static int[] s;

        public static void Main(string[] args)
        {
            s = Array.ConvertAll(Console.ReadLine().Split().ToArray(), int.Parse);
            int tmp = s[1];
            int ans = s[1];
            if (s[0] + s[1] > 0 && s[1] < 0)
            {
                for (int i = 0; i < s[0] - 1; i++)
                {
                    tmp = tmp + 1;
                    ans += tmp;
                }

            }
            else if (s[0] + s[1] <= 0)
            {
                for (int i = 0; i < s[0] - 2; i++)
                {
                    tmp = tmp + 1;
                    ans += tmp;

                }

            }
            else
            {
                ans = s[1] + 1;
                tmp = s[1] + 1;
                for (int i = 0; i < s[0] - 2; i++)
                {
                    tmp = tmp + 1;
                    ans += tmp;
                }
            }
            Console.WriteLine(ans);
        }
    }
}


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

using namespace std;



int main(){
    int64_t n, k;
    cin >> n >> k;
    int64_t res = 0;
    while(k--){
        int64_t a;
        cin >> a;
        res += a;
        if(res >= n){
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
n=int(input())
s=list(input())
b=[chr(i) for i in range(65, 65+26)]
#print(b)
a= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
for i in range(len(s)):
    for j in range(len(b)):
        if s[i]==b[j]:
            s[i]=b[(j+n)%26]
            break
print(''.join(s))

    
    

Measured memory_bytes: 40688
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		Long n = sc.nextLong();
		Long a = sc.nextLong();
		Long b = sc.nextLong();
		Long count =n/(a+b)*a;
		if(n%(a+b)>a) {
			count = count +a;
		} else {
			count = count+n%(a+b);
		}
		System.out.println(count);

	}
}


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

using namespace std;

int main() {
		int N;
		cin >> N;
		vector<int> x(N, 0);
		vector<int> y(N, 0);
		vector<int> h(N, 0);
		for (int i = 0; i < N; i++) {
				cin >> x[i] >> y[i] >> h[i];
		}

		for (int posY = 0; posY <= 100; posY++) {
				for (int posX = 0; posX <= 100; posX++) {
						int needH = -1; // -2:search is fail, -1:searching
						for (int i = 0; i < N; i++) {
								if (h[i] > 0) {
										int t = h[i] + abs(x[i] - posX) + abs(y[i] - posY);
										if (needH == -1) {
												needH = t;
										} else {
												if (needH != t) {
														needH = -2;
														break;
												}
										}
								}
						}

						if (needH == -2) continue;

						for (int i = 0; i < N; i++) {
								if (h[i] == 0) {
										int dist = abs(x[i] - posX) + abs(y[i] - posY);
										if (needH > dist) {
												needH = -2;
												break;
										}
								}
						}

						if (needH == -2) continue;

						cout << posX << " " << posY << " " << needH << endl;
						return 0;
				}
		}
		return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*
3 2 0 = 2 //121 212
3 2 1 = 6 // 2*(2+1)
3 2 2 = 8 // 2^3

2通りとれるばしょ
4 2 1だとして
1121
ペアは3か所。そのうち1か所まで
2 * 

DP

DP[K]
DP[0] = M;
1回目のループ
DP[0] = DP[0] * (M-1)
DP[1] = DP[0];
DP(NK)になってまう

3 3 0
3 * 2 * 2
=12
3 3 1 = 3^2 3^(N-K)
3 3 2 = 3^1
330+
112
113
221
223
331
332
122
133
211
233
311
322
=9通り
3*3

3 3 2
=3通り

1=0+1
2=0+1+2

3 3 0 = 12
3 3 1 = 12 + 9同じペアをくっつけてカウント？
3 3 2 = 12 + 9 + 3

4 4 0 = 4*3*3*3
4 4 1 = 4 * 3 * 3 * 3C1 = (N-1)CK
4 4 2 = 4 * 3 * 2C2？
1122 1133
1112 1113とか
3通りある。3C2か
1123
1223
1233
1112
1222
1122
1111

4 4 0 = 4*3*3*3* 3C0//1234
4 4 1 = 4*3*3* 3C1//1123 1223 1233
4 4 2 = 4*3 * 3C2//1122 1112 1222
4 4 3 = 4 * 3C3 //1111
M * (M-1)^(N-1-K)*(N-1)CK

3 2 0 = 2 //121 212
2 * 1 * 1 * 2C0
*/

const int MAX = 510000;
const int MOD = 998244353;

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

ll 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(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  COMinit();
  
  ll N, M, K; cin >> N >> M >> K;
  ll ans = 0;
  vector<ll> Z(N+10, 1);
  rep(i, N){
    Z[i+1] = Z[i] * (M-1);
    Z[i+1] %= MOD;
  }
  for(ll k=K; k>=0; k--){
//cout << "k;"<<k<<" ans:"<<ans<<endl;
//M * (M-1)^(N-1-K)*(N-1)CK
    ll tmp = M * Z[N-1-k];
    tmp %= MOD;
    tmp *= COM(N-1, k);
    tmp %= MOD;
    ans += tmp;
    ans %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 16668
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    string s;
    cin >> s;
    REP(i,0,s.size()) if (s[i] == ',') s[i] = ' ';
    cout << s << endl;
}

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

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    ix = 0
    cnt = 0
    while(ix < N):
        nix = ix
        minx = 0
        while(nix+1 < N and A[nix] <= A[nix+1]):
            minx += 1
            nix += 1
        nix = ix
        maxx = 0
        while(nix+1 < N and A[nix] >= A[nix+1]):
            maxx += 1
            nix += 1
        ix = ix + max(minx, maxx) + 1
        
        cnt += 1

    print(cnt)

    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 15140
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ld eps = (ld)1 / 1e6;
ll inf = LLONG_MAX, mod1 = 1e9 + 7, mod2 = 998244353;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ll p[16], ans[16], dp[14400000], mn[16], nb[16], st[16], dist[16][16][2];
pll c[16];

int main()
{
    fast_io;
    int n, i, j, t;
    ll s, m, nw;
    vector<ll> v;
    cin >> n;
    for (i = 1, st[0] = 1; i <= n; i++) cin >> c[i].first >> c[i].second >> p[i], st[i] = st[i - 1] * 3, ans[i] = inf;
    for (i = 1; i <= n; i++) mn[i] = p[i] * min(abs(c[i].first), abs(c[i].second)), dp[0] += mn[i];
    ans[0] = dp[0];
    for (i = 1; i <= n; i++)
        for (j = 1; j <= n; j++)
            for (t = 0; t <= 1; t++)
                dist[i][j][t] = p[i] * abs(t ? c[i].second - c[j].second : c[i].first - c[j].first);
    for (i = 1; i < st[n]; i++)
    {
        dp[i] = inf;
        t = i, nw = 0;
        v.clear();
        for (j = 1; t > 0 && j <= n; j++, t /= 3)
        {
            nb[j] = t % 3;
            if (nb[j]) nw++, v.pb(j), dp[i] = min(dp[i], dp[i - nb[j] * st[j - 1]]);
        }
        for (j = 1, s = 0; j <= n; j++)
        {
            m = mn[j];
            for (auto f: v) m = min(m, dist[j][f][nb[f] - 1]);
            s += m;
        }
        dp[i] = min(dp[i], s);
        ans[nw] = min(ans[nw], dp[i]);
    }
    for (i = 0; i <= n; i++) cout << ans[i] << '\n';
    return 0;
}

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

int main() {
	for(int n; cin >> n;) {
		vector<int> ans;

		for(int bit = 1; bit <= n; bit <<= 1) {
			if(bit & n) ans.emplace_back(bit);
		}

		for(unsigned i = 0; i < ans.size(); ++i) {
			cout << ans[i] << (i + 1 == ans.size() ? "\n" : " ");
		}
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1200
#include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;

const int INF = 1001001001;

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/

int main() {
    vector<int> dish(5);
    rep(i, 5) cin >> dish[i];
    int ans = 0;

    vector<int> hasu(0);
    rep(i, 5) {
        ans += (dish[i] / 10) * 10;
        if (dish[i] % 10 != 0)
            hasu.emplace_back(dish[i] % 10);
    }

    int mini = 10;
    rep(i, hasu.size()) {
        mini = min(mini, hasu[i]);
    }
    if (mini != 10) {
        ans += mini + (hasu.size() - 1) * 10;
    }

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


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

long long gcd(long long a, long long b){
    if(a < b) swap(a, b);
    long long r;
    while(a%b != 0){
        r = a%b;
        a = b;
        b = r;
    }
    return b;
}

int main(){
    long long n, i, r1, r2, tem;
    cin >> n;
    long long a[n];
    for(i=0; i<n; i++){
        cin >> a[i];
    }
    r1 = a[0];
    tem = gcd(a[0],a[1]);
    for(i=2; i<n; i++){
        if(tem > gcd(a[i],r1)){
            r1 = tem; 
        }else{
            r1 = gcd(a[i],r1);
        }
        tem = gcd(tem, a[i]);
    }
    tem = 0;
    r2 = a[1];
    tem = gcd(a[0],a[1]);
    for(i=2; i<n; i++){
        if(tem > gcd(a[i],r2)){
            r2 = tem; 
        }else{
            r2 = gcd(a[i],r2);
        }
        tem = gcd(tem, a[i]);
    }
    cout << max(r1,r2);
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

const ll MXN=100005;
vector<edge> G[MXN];
vector<bool> B(MXN,false);
vl ans(MXN);

void bfs(ll x,ll d){
  B[x]=true;
  ans[x]=d;
  ll k=G[x].size();
  rep(i,k){
    if(B[G[x][i].to]==false){
      bfs(G[x][i].to,G[x][i].cost+d);
    }
  }
}

  
int main() {
  ll N;
  cin >> N;
  rep(i,N-1){
    ll a,b,c;
    cin >> a >> b >> c;
    a--;b--;
    G[a].push_back({b,c});
    G[b].push_back({a,c});
  }
  ll Q,K;
  cin >> Q >> K;
  K--;
  bfs(K,0);
  rep(i,Q){
    ll x,y;
    cin >> x >> y;
    x--;y--;
    cout << ans[x]+ans[y] << "\n";
  }
}

Measured memory_bytes: 15296
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (int i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
const int INF = 1e9;
const int MOD = 1e9 + 7;
int main() {
    string S;
    cin >> S;
    string key = "keyence";
    int len = S.size();
    rep(i, len) {
        loop(k, i, len) {
            string str = "";
            rep(j, len) {
                if (j < i || k < j) {
                    str.push_back(S[j]);
                }
            }
            if (str == key || S == key) {
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
N = input()
W = [int(i) for i in input().split()]

left = 0
right = sum(W)

min_diff = abs(left-right)

for pos in range(len(W)):
    left+=W[pos]
    right-=W[pos]
    diff_tmp = abs(right-left)
    if(diff_tmp<=min_diff):
        min_diff = diff_tmp

print(min_diff)



Measured memory_bytes: 38256
#include<bits/stdc++.h>
#define INF 2147483647
#define SYOU(x) setprecision(x)
using namespace std;
long long i[10000][10000];
long long u[1111111];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,d=0,e=1,f=0;
  string s;
  cin >>u[0]>>u[1]>>u[2];
  sort(u,u+3);
  if(u[0]+u[1]==u[2]) cout <<"Yes\n";
  else cout <<"No\n";
  return (0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 2000000000
#define INFL 2000000000000000000
typedef long long int ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1LL<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1LL<<(i))))
#define setbit1(n,i) ((n)|(1LL<<(i)))
#define togglebit(n,i) ((n)^(1LL<<(i)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define fi first
#define se second
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("%d%d",&a,&b)
#define PI (acos(-1))
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod (1000000007LL)
#define asz 500005
int main()
{
    fastread;
    int T=1;
//    cin>>T;
    for(int qq=1;qq<=T;qq++)
    {
        int n,k;
        cin>>n>>k;
        cout<<(n%k)<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    string s,t = "CODEFESTIVAL2016";
    cin >> s;
    int ans = 0;
    for(int i=0; i<16; i++){
        if(s[i] != t[i]){
            ans += 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

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

        int max = 0;
        int currentPoint = 0;
        for (int i = 0; i < n; i++) {

            if (s.charAt(i) == 'D') {
                currentPoint--;
            } else {
                currentPoint++;
            }

            max = Math.max(max, currentPoint);
        }

        System.out.println(max);
    }
}


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

int main() {
  long N;
  cin >> N;
  long ans;
  
  for(long i = 1; i < sqrt(N) + 1; i++) {
    if(N % i == 0) ans = (N / i - 1) + i - 1;
  }
  
  cout << ans << endl;
    
}

Measured memory_bytes: 256
def Fib(n, memo={}):
    if n < 2:
        return 1
    elif n in memo:
        return memo[n]
    else:
        memo[n] = Fib(n - 1, memo) + Fib(n - 2, memo)
        return memo[n]


def resolve():
    N, M = [int(i) for i in input().split()]
    aa = []
    for _ in range(M):
        aa.append(int(input()))
    fib_l = list(Fib(i) for i in range(N + 1))

    ans = 1
    now = 0
    for a in aa:
        if now == a:
            ans = 0
            break
        tmp = a - now - 1
        ans = ans * fib_l[tmp]
        now = a + 1
    else:
        ans = ans * fib_l[N - now]
    print(ans % (10**9 + 7))


resolve()


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

int main() {
    int N;
    string S;
    cin >> N >> S;
    
    char prev = '/';
    int ans = 0;

    for (int i = 0; i < N; ++i)
    {
        if (prev != S[i]) ++ans;
        prev = S[i];
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

typedef long long ll;
const int maxn = 1e5+500;
double a[150];
int main()
{
	int n;
	cin>>n;
	double sum=0;
	for(int i=0;i<n;i++){
		double x;
		cin>>x;
		sum+=(1.0/x);
	}
	//cout<<1.0/sum<<endl;
	printf("%lf",(1.0/sum));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d,e;

  cin >> a;
  cin >> b;

  c = a * b;
  d = a + b;
  e = a - b;

  if (c >= d){
    if(c >= e){
      cout << c;
    }else {
      cout << e;
    }
  }else if(d >= e){
      cout << d;
    }else{
      cout <<e;
    }
}

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

template<typename ...> static inline int gc(void) { return getchar(); }
static inline long long read(){
    long long int k=gc(),x=0;
    for(;k<48||k>57;k=gc());
    for(;k>47&&k<58;k=gc())x=x*10+k-48;
    return x;
}

typedef priority_queue<long long> P;
long long d[300001], m, i, M, N, O, a[300000];
P q, l;

int main(){
    N = read();
    M = N << 1;
    O = N * 3;
    for(; i < O; ++i){
        a[i] = read();
    }
    for(i = 0; i < M; ++i){
        q.push(-a[i]);
        m += a[i];
        if(N <= i){
            m += q.top();
            q.pop();
        }
        d[i + 1] = m;
    }
    m = 0;
    for(i = O; --i >= N;){
        l.push(a[i]);
        m += a[i];
        if(i < M){
            m -= l.top();
            l.pop();
        }
        d[i] -= m;
    }
    cout << *max_element(d + N, d + M + 1) << endl;
}


Measured memory_bytes: 7156
/**
 * author: moririn_cocoa       
**/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

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

Measured memory_bytes: 3564
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
	
	string str;
	
	while(cin>>str, !cin.eof()){
		
		int n=str.size();
		string res = "";
		
		for(int i=0; i<n; ++i){
			
			if(str[i]!='@'){
				res+=str[i];
			}
			else{
				
				int p = str[i+1]-'0';
				
				for(int j=0; j<p; ++j){
					res += str[i+2];
				}
				
				i+=2;
			}
		}
		
		cout << res << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define LL long long
using namespace std;
static const LL INF = 1LL<<61LL;
typedef pair<int,int> PII;

int N,M;
int P[10010];
PII C[550];
int V[10010];
int mem[10010][550];

int cal(int n,int kin){
    int res=0;
    if(mem[n][kin]!=-1){
        return mem[n][kin];
    }
    if(n==N||kin>M)return 0;
    if(V[n]>0||n==0){
        if(N-n>=C[kin].second)res=max(cal(n+C[kin].second,kin+1)+V[n+C[kin].second]-V[n]-C[kin].first,max(cal(n,kin+1),res));
        else return mem[n][kin]=res=max(V[N]-V[n]-C[kin].first,res);
    }
    return mem[n][kin]=res;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N>>M;
    memset(mem,-1,sizeof(mem));
    FOR(i,1,N)cin>>P[i];
    FOR(i,1,M)cin>>C[i].second>>C[i].first;
    C[0].first=-INF;
    sort(P,P+N+1,greater<LL>());
    sort(C,C+M+1);
    FOR(i,1,N){
        V[i]=V[i-1]+P[i-1];
    }
    cout<<cal(0,1)<<endl;
    return 0;
}

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

int main()
{
	int n, k, ans = 0;
	cin>>n>>k;
	vector<int>v1(n);
	for(int i=0;i<k;i++){
		int d;
		cin>>d;
		vector<int>v2(d);
		for(int j=0;j<d;j++){
			cin>>v2[j];
			v1[v2[j]-1]++;
		}
	}
	for(int i=0;i<n;i++){
		if(v1[i] == 0) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3632
S = input()
d = ['A','T','G','C']
l = len(S)
acgt = []
a = ''
for i in range(l):
    if S[i] in d:
        a = a + S[i]
        if i == l-1:
            acgt.append(a)
    else:
        acgt.append(a)
        a = ''

max = 0
for a in acgt:
    if len(a) > max:
        max = len(a)
print(max)

Measured memory_bytes: 3064
import itertools

n=int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

a = list(itertools.permutations([i+1 for i in range(n)], n))
ans = 0
for i in range(len(a)):
    if a[i]==p:
        ans+=i+1
    if a[i]==q:
        ans-=i+1
print(abs(ans))

Measured memory_bytes: 8052
a,b,c,d=map(int,input().split())
import fractions
import math
nc=b//c-(a-1)//c
nd=b//d-(a-1)//d
min=c*d//fractions.gcd(c,d)
ncd=b//min-(a-1)//min
print(b-a+1-(nc+nd-ncd))

Measured memory_bytes: 5048
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

struct query {
  int L, R, id;
} q[500020];

const int BLOCK = 1000;

bool cmp(query a, query b) {
  if (a.L / BLOCK != b.L / BLOCK)
    return a.L / BLOCK < b.L / BLOCK;
  else
    return a.R < b.R;
}

int a[500020], cnt[500020], ans[500020];

int main() {
  int n, m;
  scanf("%d", &n);
  scanf("%d", &m);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &q[i].L, &q[i].R);
    q[i].id = i;
  }
  sort(q, q + m, cmp);
  int L = 0, R = 0, cur = 0;
  for (int i = 0; i < m; i++) {
    int left = q[i].L, right = q[i].R, id = q[i].id;
    while (L < left) {
      cur -= --cnt[a[L++]] == 0;
    }
    while (L > left) {
      cur += ++cnt[a[--L]] == 1;
    }
    while (R < right) {
      cur += ++cnt[a[++R]] == 1;
    }
    while (R > right) {
      cur -= --cnt[a[R--]] == 0;
    }
    ans[id] = cur;
  }
  for (int i = 0; i < m; i++)
    printf("%d\n", ans[i]);
  return 0;
}

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)

using namespace std;


int main() {
    ll n;
    cin >> n;
    vector<ll> a(n+2, 0);
    rep(i, n)   cin >> a[i+1];

    ll sum = 0;
    vector<ll> memo(n+1, 0);
    rep(src, n+1) memo[src] = abs(a[src]-a[src+1]);
    rep(src, n+1) sum += memo[src];

    rep(src, n){
        cout << sum-memo[src]-memo[src+1] + abs(a[src]-a[src+2]) << endl;
    }



    return 0;
}


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

vector<int> A;

void show(vector<int> A) {
	for (int i = 0; i < A.size(); i++) {
		if (i == A.size()-1)
			cout << A[i];
		else
			cout << A[i] << ' ';
	}
	cout << endl;
}

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	show(A);
	
	for (int i = 1; i < N; i++) {
		int v = A[i];
		int j = i - 1;
		while (j >= 0 && A[j] > v) {
			A[j+1] = A[j];
			j--;
		}
		A[j+1] = v;
		show(A);
	}
}


Measured memory_bytes: 3164
#include <stdio.h>

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

    if(input_a < input_b) {
        printf("a < b\n");
    }
    else if(input_a > input_b) {
        printf("a > b\n");
    }
    else{
        printf("a == b\n");
    }

}


Measured memory_bytes: 2148
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
#define w1 first
#define w2 second
#define ls (x<<1)
#define rs (x<<1|1)
#define pb push_back
#define mid ((l+r)>>1)
#define SZ(x) ((x).size())
#define All(x) (x).begin(),(x).end()
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)])
template<class T>void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=1ll*x*x%p)if(k&1)res=1ll*res*x%p;return res;}
const int maxn=2e5+5,inf=1e9+10,mod=1e9+7;
int totmin,totrest,X,Y,n;
int mini[maxn],ban[maxn],rest[maxn],c[maxn],w[maxn],mini2[maxn],mini3[maxn],mini4[maxn];
int fac[maxn],ifac[maxn];
int main(){
	read(n);
	fac[0]=1;rep(i,1,n)fac[i]=1ll*fac[i-1]*i%mod;
	rep(i,0,n)ifac[i]=power(fac[i],mod-2,mod);
	rep(i,1,n)mini[i]=inf;
	totmin=inf;
	read(X);read(Y);
	rep(i,1,n)read(c[i]),read(w[i]),mini[c[i]]=min(mini[c[i]],w[i]),totmin=min(totmin,w[i]);
	mini2[1]=inf;rep(i,2,n)mini2[i]=min(mini2[i-1],mini[i-1]);
	mini3[n]=inf;per(i,n-1,1)mini3[i]=min(mini3[i+1],mini[i+1]);
	rep(i,1,n)mini4[i]=min(mini2[i],mini3[i]);
	int cnt=n;
	rep(i,1,n)if(mini[i]+totmin>Y)ban[i]=1,cnt--;
	if(cnt<=1)return puts("1"),0;
	rep(i,1,n)if(!ban[c[i]]&&((w[i]+mini[c[i]]<=X)||(w[i]+mini4[c[i]]<=Y)))rest[c[i]]++,totrest++;
	int ans=fac[totrest];
	rep(i,1,n)ans=1ll*ans*ifac[rest[i]]%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 8064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;

class Program
{
    static bool Solve(int H, int W, char[][] A)
    {
        int h = 0;
        int w = 0;
        while (true)
        {
            A[h][w] = '.';
            if (h == H - 1 && w == W - 1) { break; }
            else if (h + 1 < H && A[h + 1][w] == '#') { ++h; }
            else if (w + 1 < W && A[h][w + 1] == '#') { ++w; }
            else { return false; }
        }
        return A.All(row => row.All(c => c == '.'));
    }
    static void Main(string[] args)
    {
        int[] values = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        int H = values[0];
        int W = values[1];
        char[][] A = new char[H][];
        for (int i = 0; i < H; ++i)
        {
            A[i] = Console.ReadLine().ToCharArray();
        }
        Console.WriteLine(Solve(H, W, A) ? "Possible" : "Impossible");
    }
}


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

using namespace std;

typedef long long ll;

int main() {
    int x, y, z, k;
    cin >> x >> y >> z >> k;
    ll a[x], b[y], c[z];
    for (int i = 0; i < x; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < y; i++) {
        cin >> b[i];
    }
    for (int i = 0; i < z; i++) {
        cin >> c[i];
    }

    ll ab[x*y];
    for (int i = 0; i < x * y; i++) {
        ab[i] = a[i/y] + b[i%y];
    }
    sort(ab, ab+x*y);
    reverse(ab, ab+x*y);

    int xy = min(x * y, k);

    ll abc[xy*z];
    for (int i = 0; i < xy * z; i++) {
        abc[i] = ab[i/z] + c[i%z];
    }
    sort(abc, abc+xy*z);
    reverse(abc, abc+xy*z);

    for (int i = 0; i < k; i++) {
        cout << abc[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 31488
package main

import (
  "fmt"
)

func main() {
  var a, b, c, d int 
  fmt.Scan(&a, &b, &c, &d)
  for {
    c -= b
    if c <= 0 {
      fmt.Println("Yes")
      return
    }
    a -= d
    if a <= 0 {
      fmt.Println("No")
      return
    }
  }

}

Measured memory_bytes: 1752
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll Pow(ll n,ll p){
	ll r=1;
	for(;p>0;p>>=1){
		if(p&1) r=(r*n)%mod;
		n=(n*n)%mod;
	}
	return r;
}

const int M=2000005;
ll F[M];

void Init(){
	F[0]=1;
	for(int i=1;i<M;i++) F[i]=F[i-1]*i%mod;
}

ll Div(ll n,ll m){
	return n*Pow(m,mod-2)%mod;
}

ll nCk(ll n,ll k){
	return Div(F[n],F[n-k]*F[k]%mod);
}

ll nPk(ll n,ll k){
	return nCk(n,k)*F[k]%mod;
}

int n;
vi a;

int main(){
	cin>>n;
	a=vi(n);
	int x=0,t=0;
	while(1){
		x=(10*x+7)%n;
		t++;
		if(x==0) break;
		if(a[x]){
			t=-1;
			break;
		}
		a[x]++;
	}
	cout<<t<<endl;
}

Measured memory_bytes: 7172
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		HashMap<Integer, Boolean> m = new HashMap<Integer, Boolean>();
		int N;
		// GET INPUT
		N = sc.nextInt();
		for(int i=0; i<N; i++) {
			int A = sc.nextInt();
			if(m.containsKey(A)) {
				if(m.get(A)) {
					m.put(A, false);
				} else {
					m.put(A, true);
				}
			} else {
				m.put(A, true);
			}
		}
		
		
		
		// GET INPUT END
		
		sc.close();
		
		int ans = 0;
		for(Map.Entry<Integer, Boolean> entry : m.entrySet()) {
			if(entry.getValue()) {
				ans++;
			}
		}
		System.out.println(ans);
		
		


	}

}

Measured memory_bytes: 61440