akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define SORT(v) sort((v).begin(), (v).end())
#define REV(v) sort((v).begin(), (v).end(), greater<int>())
#define INF 1000000007
typedef long long ll;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int main() {
  int n, m;
  cin >> n >> m;
  int N = 2 * n;
  int a[m];
  rep(i, m) cin >> a[i];
  int c[N];
  rep(i, N) c[i] = i + 1;

  rep(i, m) {
    if(a[i]) { // cut
      int cp[N];
      rep(j, N) cp[j] = c[j];
      int k = a[i];
      rep(j, N - k) {
        c[j] = cp[k + j];
      }
      REP(j, N - k, N) {
        c[j] = cp[j - N + k];
      }
    } else { // rifuru
      int cp[N];
      rep(j, N) cp[j] = c[j];
      rep(j, N) {
        if(j % 2 == 0) {
          c[j] = cp[(j + 1) / 2];
        } else {
          c[j] = cp[n + (j - 1) / 2];
        }
      }
    }
  }

  rep(i, N) cout << c[i] << endl;
  return 0;
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 2e5+10;
ll n,ans,d[20][20],k;
int main () {
    cin >> n;
    for(ll i=1;i<=n;++i) {
        for(k=i;k>=10;k/=10);
        d[k][i%10]++;
    }
    for(int i=1;i<=9;++i) {
        for(int j=1;j<=9;++j) {
            ans+=d[i][j]*d[j][i];
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define int long long
#define MOD 1000000007ll
using namespace __gnu_pbds;
using namespace std;

int n,dp[5010][5010],f[5010][5010],sz[5010],g[5010];
vector<int> v[5010];

inline void add(int &x,int y)
{
	x+=y;
	if(x>=MOD) x-=MOD;
}

inline void dfs(int x,int pr)
{
	dp[x][1]=1;sz[x]=1;
	for(int i=0;i<v[x].size();i++) if(v[x][i]!=pr){
		int u=v[x][i];
		dfs(u,x);
		for(int j=1;j<=sz[x];j++){
			for(int k=0;k<=sz[u];k++){
				add(f[x][j+k],(dp[x][j]*dp[u][k])%MOD);
			}
		}
		sz[x]+=sz[u];
		for(int j=1;j<=sz[x];j++){
			dp[x][j]=f[x][j];
			f[x][j]=0;
		}
	}
	for(int i=1;i<=sz[x];i++) add(dp[x][0],MOD-((dp[x][i]*g[i])%MOD));
}

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<n;i++){
		int x,y;
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	g[0]=1;
	for(int i=2;i<=n;i+=2) g[i]=(g[i-2]*(i-1))%MOD;
	dfs(1,-1);
	cout<<(MOD-dp[1][0])%MOD<<endl;
	return 0;
}

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

/**
 * Created by Ayushi on 19 Jan 2020.
 * Problem:
 * Round:
 */

public class Main {
    public static void main(String[] args) throws IOException {
        StringTokenizer st;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String temp = br.readLine();
        int n = Integer.parseInt(temp);

        temp = br.readLine();
        st = new StringTokenizer(temp, " ");
        int[] a = new int[n];
        int j = 0;
        int min = n+1;
        int ans = 0;
        while (st.hasMoreTokens()) {
            a[j] = Integer.parseInt(st.nextToken());
            if (a[j] < min) {
                min = a[j];
                ans++;
            }
            j++;
        }
        br.close();
        System.out.println(ans);
    }
}


Measured memory_bytes: 47444
#include <stdio.h>

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

    if(a==1) a=14;
    if(b==1) b=14;
    
    if(a>b) printf("Alice");
    else if(a==b) printf("Draw");
    else printf("Bob");
    
}

Measured memory_bytes: 128
n = int(input())
cnt = [0 for i in range(n+1)]
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            ind = (x+y+z)**2-x*y-y*z-z*x
            if ind > 0 and ind < n+1:
                cnt[ind] += 1
for i in range(n):
    print(cnt[i+1])

Measured memory_bytes: 9276
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
        int n = ni();

        long ans = 0;
        int prev = 0;

        for (int i = 0; i < n; i++) {
            int a = ni();
            if (prev == 1 && a > 0) {
                ans++;
                a--;
            }
            ans += a / 2;
            prev = a % 2 == 1 ? 1 : 0;
        }

        out.println(ans);
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 23184
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 1000005
#define MOD 1000000007
#define INF 1000000009
typedef long long int lli;

lli Gcd(lli x, lli y)
{
  if (y == 0) return x;
  return Gcd(y, x % y);
}

int main(void) {
  int n;
  int a[MAX], c[MAX] = {0};
  scanf("%d", &n);
  rep(i, 0, n) {
    scanf("%d", &a[i]);
    c[a[i]]++;
  }
  
  int pairwise = 1;
  rep(i, 2, MAX) {
    int cnt = 0;
    for (int j = i; j < MAX; j += i) {
      cnt += c[j];
    }
    if (cnt > 1) pairwise = 0;
  }
  if (pairwise) {
    printf("pairwise coprime");
    return 0;
  }

  int g = 0;
  rep(i, 0, n) g = Gcd(g, a[i]);
  if (g == 1) {
    printf("setwise coprime");
    return 0;
  }

  printf("not coprime");
  return 0;
}



Measured memory_bytes: 9540
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;

const ll MOD = (ll)(1e9 + 7);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  bool appear[10] = {};
  rep(i, 4)
  {
    int a;
    cin >> a;
    appear[a] = true;
  }
  YES(appear[1] && appear[9] && appear[7] && appear[4]);
  return 0;
}


Measured memory_bytes: 256
var n = 0
var a = 0L
var b = 0L
var h = LongArray(0)

fun main(args: Array<String>) = IO().exec {
    n = int()
    a = long()
    b = long()
    h = LongArray(n){long()}
    var ok = 1e9.toLong()
    var ng = -1L
    while (Math.abs(ok - ng) > 1) {
        val mid = (ok + ng) / 2
        if (isOk(mid)) {
            ok = mid
        } else {
            ng = mid
        }
    }
    println(ok)
}

fun isOk(k: Long): Boolean {
    var aRest = k
    for (i in n) if (h[i] > b * k) {
        aRest -= (h[i] - b * k).ceilDiv(a - b)
        if (aRest < 0) return false
    }
    return true
}

fun Long.ceilDiv(k: Long): Long = (this + k - 1) / k
fun Long.ceilMod(m: Long): Long = this.ceilDiv(m) * m

// region template
operator fun Int.iterator() = 0.until(this).iterator()
class IO {
    val printable = 33..126
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    val out = java.io.PrintWriter(System.out)
    fun hasNextByte(): Boolean = if (ptr < buflen) true else {
        ptr = 0
        buflen = System.`in`.read(buffer)
        buflen > 0
    }

    fun readByte(): Byte = if (hasNextByte()) buffer[ptr++] else -1
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }

    fun string(): String {
        if (!hasNext()) throw java.util.NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }

    fun long(): Long {
        if (!hasNext()) throw java.util.NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun int(): Int {
        val nl = long()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }

    fun double(): Double = string().toDouble()
    fun print(obj: Any) = out.print(obj)
    fun print(i: Int) = out.print(i)
    fun print(l: Long) = out.print(l)
    fun println(obj: Any) = out.println(obj)
    fun println(i: Int) = out.println(i)
    fun println(l: Long) = out.println(l)
    inline fun exec(block: IO.() -> Unit) {
        block()
        out.flush()
    }
}
// endregion

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

vector<vector<vector<ll>>> dp;
vector<int> x;
int N, A;

int main() {
	cin >> N >> A;
	dp = vector<vector<vector<ll>>>(N + 1, vector<vector<ll>>(N + 1, vector<ll>(N*A + 1)));
	x = vector<int>(N + 1, 0);
	for (int i = 1; i <= N; i++) cin >> x[i];

	for (int i = 0; i <= N; i++) for (int j = 0; j <= N; j++) for (int k = 0; k <= N*A; k++) {
		dp[i][j][k] = 0;
	}
	dp[0][0][0] = 1;
	for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) for (int k = 0; k <= N*A; k++) {
		if (k + x[i + 1] <= N*A) {
			dp[i + 1][j + 1][k + x[i + 1]] += dp[i][j][k];
		}
		dp[i + 1][j][k] += dp[i][j][k];
	}

	ll ans = 0;
	for (int n = 1; n <= N; n++) {
		ans += dp[N][n][n*A];
	}
	cout << ans << endl;
}


Measured memory_bytes: 52224
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

string solve() {
  string ans = "";
  string s; int K;
  cin>>s>>K;
  vector<string> data;
  data.push_back("");
  int len = s.size();
  REP(i,len) {
    REP(j,5) {
      if(i+j<=len)
        data.push_back(s.substr(i,j+1));
    }
  }
  sort(data.begin(), data.end());
  //  REP(i,data.size()) {                                                              
    //    cout << i << data[i] << endl;                                                 
  //  }                                                                                 
  for(int i = 1; i < data.size(); i++) {
    if(data[i-1] != data[i]) {
      K--;
      if(K==0) return data[i];
    }
  }
  return "";

}
int main() {
  string ans = solve();
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 1660
from math import gcd


class Eratosthenes(): # エラトステネスの篩
    def __init__(self, N): # 素数リスト生成 O(n*log(log n))
        is_prime = [0, 0] + [1] * (N - 1)
        for i in range(int(N**0.5) + 1):
            if is_prime[i] == 0:
                continue
            for j in range(i * 2, N + 1, i):
                is_prime[j] = 0
        self.prime_list = [i for i, pi in enumerate(is_prime) if pi == 1]


    def factor(self, NUM):  # 高速素因数分解 O(log num)
        PRIME = set()
        for p in self.prime_list:
            if p * p > NUM:
                break
            while NUM % p == 0:
                NUM //= p
                PRIME.add(p)
        if NUM > 1:
            PRIME.add(NUM)
        return PRIME


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

ans = 0
for ai in a:
    ans = gcd(ans, ai)
if ans != 1:
    print('not coprime')
    exit()

era = Eratosthenes(max(a))
num = set()
for ai in a:
    prime = era.factor(ai)
    if len(prime & num) > 0:
        print('setwise coprime')
        break
    num |= prime
else:
    print('pairwise coprime')


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

using namespace std;

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

    int p, q, r;
    cin >> p >> q >> r;
    cout << min(p + q, min(q + r, r + p)) << '\n';

    return 0;
}

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

int main() {
  long long n;
  cin>>n;
  long long ans=0;
  vector<long long>a(3*n);
  for(long long i=0;i<3*n;i++) cin>>a[i];
  sort(a.begin(),a.end());
  for(int i=0;i<n;i++){
    ans+=a[3*n-2-2*i];
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 2560
from collections import deque

he,w,k = map(int,input().split())
sx,sy,gx,gy = map(int,input().split())
l = [list(input()) for i in range(he)]

sx -= 1
sy -= 1
gx -= 1
gy -= 1
q = deque([])
d = [[float("INF")]*w for i in range(he)]
dx = [1,-1,0,0]
dy = [0,0,1,-1]
d[sx][sy] = 0
q.append((0,sx,sy))
while q:
    dis,bx,by = q.popleft()
    if bx == gx and by == gy:
        continue
    for i in range(4):
        for j in range(1,k+1):
            nx = bx+dx[i]*j
            ny = by+dy[i]*j
            if 0 > nx or 0 > ny or nx >= he  or ny >= w:
                break
            if l[nx][ny] == "@":
                break
            if d[nx][ny] <= dis:
                break
            if d[nx][ny] > dis+1:
                d[nx][ny] = dis+1
                q.append((dis+1,nx,ny))

if d[gx][gy] == float("INF"):
    print(-1)
else:
    print(d[gx][gy])


Measured memory_bytes: 176400
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define dump(o) { cerr << #o << " " << o << endl; }
#define dumpc(o) { cerr << #o; for (auto &e : (o)) cerr << " " << e; cerr << endl; }
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

int main() {
	int N, L; cin >> N >> L;
	vector<string> S(N);
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}
	sort(S.begin(), S.end());

	string ans = "";
	for (int i = 0; i < N; i++) {
		cout << S[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
s = gets.chomp.chars

n = s.length
m = (n - 1) / 2
u = (n + 3) / 2

mae = s[0..m - 1]
ushiro = s[u - 1..n - 1]

if mae == mae.reverse && ushiro == ushiro.reverse && s == s.reverse
  puts "Yes"
else
  puts "No"
end


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

#define INF_LL (int64)1e18
//#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

class UnionFind{
private:
    ::std::vector<int_fast32_t> par, edge;
    size_t n;

public:
    UnionFind(){}
    UnionFind(size_t n):n(n){
        par.resize(n, -1);
        edge.resize(n, 0);
    }

    uint_fast32_t find(uint_fast32_t x){
        return par[x] < 0 ? x : par[x] = find(par[x]);
    }

    size_t size(uint_fast32_t x){
        return -par[find(x)];
    }

    bool unite(uint_fast32_t x, uint_fast32_t y){
        x = find(x);
        y = find(y);
        edge[x] += 1;
        if(x == y) return false;
        if(size(x) < size(y)) std::swap(x, y);
        par[x] += par[y];
        edge[x] += edge[y];
        par[y] = x;
        return true;
    }

    bool same(uint_fast32_t x, uint_fast32_t y){
        return find(x) == find(y);
    }

    size_t esize(uint_fast32_t x) {
        return edge[find(x)];
    }
};

int main(void) {
    int64 N, K;
    string S;
    cin >> N >> K; K--;
    cin >> S;
    S[K] = tolower(S[K]);
    cout << S << endl;
}


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

using namespace std;

#define PI 3.14159265358979323846264338327950L

vector<long long> vec;

void PreProcess(long long n) {
	vector<long long> v(n+5, 0);
	vec = v;

	for (long long i = 1; i <= n; i++) {
		for (long long j = 1; j * i <= n; j++) {
	
			vec[j*i]++;
		}
	}

	return;
}

int main(void) {
	long long N, ans = 0;;

	cin >> N;

	PreProcess(N);

	for (long long i = 1; i <= N; i++) {
		ans = ans + i * vec[i];
	}

	cout << ans << endl;


	return 0;
}



Measured memory_bytes: 159464
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <utility>

#define INF 1000000001
#define EPS (1e-7)
#define REP(i,n) for(int i=0;i<n;i++)

using namespace std;

typedef long long unsigned int ll;
typedef pair<ll, ll> P;

int dfs(long s, int n) {
  if (s > n) {
    return 0;
  }

  bool flag = true;
  bool three = false;
  bool five = false;
  bool seven = false;
  long tmp = s;
  while (tmp > 0) {
    if (tmp % 10 == 3) three = true;
    if (tmp % 10 == 5) five = true;
    if (tmp % 10 == 7) seven = true;
    
    if (tmp % 10 != 3 && tmp % 10 != 5 && tmp % 10 != 7) {
      flag = false;
      break;
    }
    tmp /= 10;
  }

  long ret = 0;
  if (three && five && seven && flag) {
    ret = 1;
  }

  vector<long> array{3, 5, 7};

  for(int num : array) {
    ret += dfs(10 * s + num, n);
  }

  return ret;
}

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

  cout << dfs(0, n) << endl;
  
  return 0;

}


Measured memory_bytes: 764
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, m) revi(i, m, 0)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  int D, G;
  ci(D, G);
  ve<int> p(D), c(D);
  rep(i, D){
    ci(p.at(i), c.at(i));
  }
  int a = 100000000;
  rep(bit, 1 << D){
    int b = 0, cnt = 0, f = 0; 
    rep(i, D){
      if(bit >> i & 1){
        b += p.at(i) * (i + 1) * 100 + c.at(i);
        cnt += p.at(i);
      }
      else{
        f = i;
      }
    }
    rep(i, p.at(f) + 1){
      if(b + (f + 1) * 100 * i >= G){
        cnt += i;
        a = min(a, cnt);
        br;
      }
    }
  }
  co(a);
}

Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
import collections
c=collections.Counter(l)
l=[0]+list(c.values())
c=collections.Counter(l)
l=list(c.items())
l.sort()
l.append((n,0))
acc=[0 for i in range(n+2)]
for i,j in l:
    acc[i]+=j
for i in range(1,n+1):
    acc[-i-1]+=acc[-i]
ans=[0 for i in range(n+1)]
t=0
for i,j in zip(l,l[1:]):
    a,b=i
    c,d=j
    t+=a*b
    for i in range(a+1,c+1):
        for j in range(acc[i+1],acc[i]+t//i+1):
            ans[j]=i
for i in ans[1:]:
    print(i)

Measured memory_bytes: 120476
#include<bits/stdc++.h>
using namespace std;
inline long long read() {
	long long t=0;
	char v=getchar();
	while(v<'0'||v>'9')v=getchar();
	while(v>='0'&&v<='9') {
		t=(t<<3)+(t<<1)+v-'0';
		v=getchar();
	}
	return t;
}
int n,a[100002],ans;
int main(){
n=read();
n*=2;
for(register int i=1;i<=n;++i){
	a[i]=read();
}
sort(a+1,a+n+1);
for(register int i=n-1;i>=1;i-=2){
	ans+=a[i];
}
cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int e, a, b, c, d, time = 0;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&d);
	scanf("%d",&e);
	if(a < 0){
		time = time + d + ((a * -1) * c);
		time = time + b * e;
		printf("%d\n", time);
		return 0;
		}
	time = time + (b - a) * e;
	printf("%d\n", time);
	return 0;
}


Measured memory_bytes: 2060
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int> a(6);
  for(int i=0;i<6;i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  int c1=0,c2=0,c3=0,c4=0;
  for(int i=0;i<6;i++){
    if(a.at(i)==1)
      c1++;
    else if(a.at(i)==2)
      c2++;
    else if(a.at(i)==3)
      c3++;
    else
      c4++;
  }
  if(c1==3||c2==3||c3==3||c4==3)
    cout << "NO" << endl;
  else
    cout << "YES" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
char a[3];
char b[3];
scanf("%s",a);
//scanf("%s",a[1]);
//scanf("%s",a[2]);

scanf("%s",b);
//scanf("%s",b[1]);
//scanf("%s",b[2]);

if(a[0]==b[2]&&a[1]==b[1]&&a[2]==b[0]){
puts("YES");}
else{
puts("NO");}



return 0;}

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

template<class T>
T gcd(T a, T b) {
	if (a == 0) return b;
	return gcd(b % a, a);
}

int main() {
	cin.tie(0)->sync_with_stdio(false);

	ll a, b; cin >> a >> b;
	ll n = gcd(a, b);

	int res = 1;
	for (ll i = 2; i * i < n; i++) {
		if (n % i != 0) continue ;
		res++;
		while (n % i == 0)
			n /= i;
	}

	if (n != 1) res++;
	cout << res << '\n';
	return 0;
}


Measured memory_bytes: 3656
// Vivek Rai
// Blazer_007

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define fastio 		ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll          long long
#define int 		ll
#define pb          push_back
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define ppi 		pair<ll,pii>
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define bit(x, y)   (((x)>>(y))&1)
#define bpt(x)      (__builtin_popcount(x))
#define bptl(x)     (__builtin_popcountll(x))
#define loop(i,a,b)  for(int i=a;i<b;i++)
#define rloop(i,a,b) for(int i=a;i>=b;i--)
#define N 2000010

using namespace std;
using namespace __gnu_pbds;

typedef priority_queue<int> maxHeap;
typedef priority_queue<int,vector<int>,greater<int> > minHeap;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
// find_by_order(index) -> value at given index or Kth smallest element in set
// order_of_key(X) -> number of elements strictly less than X
typedef tree<pii , null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> OST;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

istream &operator>>(istream &in, vector<int> &arr)
{
    for(int i = 0 ; i < arr.size() ; i++)
    	cin >> arr[i];
    return in;
}

ostream &operator<<(ostream &os, vector<int> arr)
{
    for(int i = 0 ; i < arr.size() ; i++)
        cout << arr[i] << " ";
    cout << endl;
    return os;
}

void solution(){
    int n;
    cin >> n;
    vector<int> l(n);
    cin >> l;
    sort(all(l));
    int ans = 0;
    for(int i = 0 ; i < n-2 ; i++)
    {
        for(int j = i+1 ; j < n-1 ; j++)
        {
            if (l[i] == l[j])
                continue;
            for(int k = j+1 ; k < n ; k++)
            {
                if (l[j] == l[k])
                    continue;
                if (l[i] + l[j] > l[k])
                    ans++;
            }
        }
    }
    cout << ans << endl;
}

signed main(){
    fastio

    ll t=1;
    // cin>>t;
    loop(i,1,t+1){
    	//cout<<"Case #"<<i<<": ";
    	solution();
    }
}




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

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

    x = stoi(s);
    vector<int> coin_counts = {0, 0, 0};
    const vector<int> coins = {500, 5, 1};

    for(int i = 0; i < 3; ++i)
    {
        coin_counts[i] = x / coins[i];
        x = x % coins[i];
    }

    cout << coin_counts[0] * 1000 + coin_counts[1] * 5 << endl;
    
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
//for(int i = 0; i < n; i++)

int main()
{
	int n;cin>>n;
    vector<int> a(n);
    vector<int> b(n);
    for(int i = 0; i < n; i++) {
        cin>>a[i];
        b[i] = a[i];
    }
    sort(b.begin(), b.end(), greater<int> ());
    for(int i = 0; i < n; i++){
        if(a[i] == b[0]) cout << b[1] << endl;
        else cout << b[0] << endl;
    }
	return 0;
}

Measured memory_bytes: 3200
aa, bb = open(0).read().splitlines()

aa = sorted(aa)

bb = sorted(bb, reverse=True)

import sys
for a, b in zip(aa, bb):
    if a == b:
        continue
    else:
        if a<b:
            print('Yes')
            sys.exit()
        else:
            print('No')
            sys.exit()
        break
if len(aa)<len(bb):
    print('Yes')
else:
    print('No')

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

const int maxn = 2e5+10 ;
pair<long long, long long> a[maxn] ;
bool mark[maxn] ;
long long t = 0 ;
string ans = "Yes" ;
int n ;

int main() {

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

    cin >> n ;
    for(int i = 0; i < n; i++){

        cin >> a[i].second >> a[i].first ;

    }
    sort(a, a+n) ;

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

        if(t + a[i].second > a[i].first){

            ans = "No" ;
            break ;

        }
        t += a[i].second ;

    }

    cout << ans ;

}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

UL D;
UL C[26];
UL S[400][26];

UL T[400];
LL Last[26];
LL Score[400];

int main() {
 scanf("%u", &D);
 rep(i,26) scanf("%u",&C[i]);
 rep(i,D)rep(j,26) scanf("%u",&S[i][j]);
 rep(i,D) {scanf("%u",&T[i]); T[i]--;}
 
 Score[0]=0;
 rep(i,26)Last[i]=-1;
 rep(d,D){
  Score[d+1] = Score[d];
  Last[T[d]]=d;
  rep(i,26){
   Score[d+1] -= C[i] * ((LL)d-Last[i]);
  }
  Score[d+1] += S[d][T[d]];
 }
 
 rep(d,D) printf("%lld\n", Score[d+1]);
 
 return 0;
}



Measured memory_bytes: 3760
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int MAX_N = 100;
int n;
int s[MAX_N];

int main() {
  cin >> n;
  rep(i,n) cin >> s[i];

  int sum = 0;
  int mi = 1e9;
  rep(i,n) {
    sum += s[i];
    if (s[i]%10 != 0) mi = min(mi, s[i]);
  }

  if (sum%10 != 0) {
    cout << sum << endl;
  } else {
    if (mi > 100) cout << 0 << endl;
    else cout << sum - mi << endl;
  }

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class B
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public void Solve()
	{
		int N = GetInt();

		for(int i = 1; i <= N; i++)
		{
			int p = (int)Floor((double)i * 1.08);
			if(p == N)
			{
				WriteLine(i);
				return;
			}
		}
		WriteLine(":(");
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll farland = pow(10,18);


ll A,B,Q;
vector<ll> s;
vector<ll> t;

void input()
{
  cin >> A >> B >> Q;
  s.push_back(-farland);
  for (ll i = 0; i < A; i++)
  {
    ll tmp;
    cin >> tmp;
    s.push_back(tmp);
  }
  s.push_back(farland);
  t.push_back(-farland);
  for (ll i = 0; i < B; i++)
  {
    ll tmp;
    cin >> tmp;
    t.push_back(tmp);
  }
  t.push_back(farland);
}

// returns the shortest length of the way visiting x, a and b
ll dist(ll x, ll a, ll b)
{
  ll tmp = abs(a-x) + abs(b-a);
  tmp = min(tmp,abs(b-x)+abs(a-b));
  return tmp;
}

void ans(ll x)
{
  ll tmp = LLONG_MAX;
  ll tlow = lower_bound(t.begin(),t.end(),x) - t.begin();
  ll slow = lower_bound(s.begin(),s.end(),x) - s.begin();
  for (int i = 0; i < 2; i++)
  {
    for (int j = 0; j < 2; j++)
    {
      tmp = min(tmp,dist(x,t[tlow-i],s[slow-j]));
    }    
  }
  cout << tmp << endl;
}

int main()
{
  input();
  for (ll i = 0; i < Q; i++)
  {
    ll tmp;
    cin >> tmp;
    ans(tmp);
  }
  
  return 0;
}

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)
 
int main(void) {
  int n;cin>>n;
  bool can = false;
  Fr(i, 9) Fr(j, 9) if(n==i*j) can = true;

 
  cout << (can?"Yes":"No")<< endl;

  return 0;
}

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

int main() {
  long int n, a, max = -1000000, min = 1000000, sum = 0;

  cin >> n;
  while (n > 0) {
    cin >> a;
    sum += a;
    if (a > max) max = a;
    if (a < min) min = a;
    n--;
  }

  cout << min << " " << max << " " << sum << endl;

  return 0;
}

Measured memory_bytes: 3100
#include<stdio.h>
#include<stdlib.h>

int main() {
  int i, j, v, *A, n;

  scanf("%d", &n);
  A = (int *)malloc(n*sizeof(int));

  for (i = 0; i < n; i++) {
    scanf("%d", &A[i]);
  }

  for (i = 0; i < n; i++) {
    v = A[i];
    j = i-1;
    while (j >= 0 && A[j] > v) {
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    /*
    for(j = 0; j < n; j++) {
      printf("%d ", A[j]);
    }
    printf("\b\n");
    */

    for(j = 0; j < n-1; j++) {
      printf("%d ", A[j]);
    }
    printf("%d\n",A[j]);
  }
  free(A);

  return 0;
}



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

int main() {
    int K, N; cin >> K >> N;
    vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i];
    vector<int> B(N);
    int maxi = K + A[0] - A[N-1];
    for (int i = 1; i < N; i++) maxi = max(maxi, A[i] - A[i-1]);
    cout << K - maxi << endl;
}


Measured memory_bytes: 1792
#105b
n=int(input())
x = n//4
if n%4==0 or n%7==0:
    print('Yes')
    exit()
else:
    for i in range(x):
        for j in range(x):
            temp=4*i+7*j
            if temp==n:
                print('Yes')
                exit()
print('No')

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
    詰まった時に、別の分野の問題として考え直す（これdpでは？、グラフとしてみればいいのでは？）
    多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

typedef tuple<ll, ll, ll> T;

const int inf = INT_MAX;

struct SegmentTree{
private:
    int n; // セグ木の葉の数, つまり２冪になっており,　全体の要素数は2*n-1
    vector<int> node;

public:
    SegmentTree(vector<int> v){
        int sz = v.size();
        n = 1; while(n < sz) n*= 2;
        node.resize(2*n-1, 0);
        for(int i=0; i<sz; ++i) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; --i) node[i] = node[2*i+1]+node[2*i+2];
    }

    // k番目(0-indexed)をvalに変更
    void add(int k, int val){
        k += n-1;
        node[k] += val;

        while(k>0){
            k = (k-1)/2;
            node[k] = node[2*k+1] + node[2*k+2];
        }
    }

    // [a,b)の最小値を求める
    // kは接点の番号、l、rはその接点が[l, r)に対応していることを表す
    // 外からはgetmin(a, b, 0, 0, n)と呼ぶ
    int getsum(int a, int b, int k=0, int l=0, int r=-1){
        if(r < 0) r = n;
        // [a, b)と[l, r)が交差していなければinfを返す
        if(r <= a || b <= l) return 0;

        // [a,b) ⊃ [l, r)ならば、この接点の値
        if(a <= l && r <= b) return node[k];

        // そうでなければ二つの子の最小値
        int vl = getsum(a, b, k*2+1, l, (l+r)/2);
        int vr = getsum(a, b, k*2+2, (l+r)/2, r);
        return vl+vr;
    }
};

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

    int n, q; cin >> n >> q;
    vector<int> v(n, 0);

    SegmentTree seg(v);

    for(int i=0; i<q; ++i){
        int com, x, y; cin >> com >> x >> y;
        if(com == 0){
            seg.add(x-1, y);
        }
        else{
            cout << seg.getsum(x-1, y) << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 4680
from collections import Counter
from itertools import product

NUM = 0
CNT = 1

n = int(input())
v = tuple(map(int, input().split()))

c_odd = Counter(v[1::2])
c_even = Counter(v[0::2])

odd_12 = c_odd.most_common()[:2]
even_12 = c_even.most_common()[:2]
# [(num, cnt),(num, cnt)]

ans = n
for o, e in product(odd_12 + [(-1, 0)], even_12 + [(-1, 0)]):
    # print(o, e)
    if o[NUM] == e[NUM]:
        continue
    ans = min(ans, n - (o[CNT] + e[CNT]))
print(ans)


Measured memory_bytes: 18660
/*╔═══╗──╔╗╔╗───────────────────╔╗────────╔═══╦═══╗
  ║║─║╠╗╠╗╔╣╚═╦══╦═╗╔╦╗╔═╗╔══╦══╣╚═╦╦══╦══╣║─║║║─╚╝
  ║╔═╗║╚╝║╚╣║║║╚╝║║─╔╦╗║║║║╚╝║╚╝║╚╝║║║═╬══║╔═╗║╚╩═║
  ╚╝─╚╩══╩═╩╝╚╩══╩╝─╚╩╝╚╝╚╩══╩══╩══╩╩══╩══╩╝─╚╩═══╝*/

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

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvll vector<vll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(c) c.begin(),c.end()
#define sz(c) (int)c.size()
#define lb lower_bound
#define ub upper_bound
#define ff first
#define ss second
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define nl cout << endl
#define hello cout << "hello" << endl;
#define sp(x) fixed << setprecision(x)
#define re return

void dbg_out(){cerr << endl;}
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)

const double pi = 3.14159265359;
const ll mod = 1000000007;
const ll modc = 998244353;

ll inline power(ll a, ll b, ll p){
    a %= p;
    ll ans = 1;
    while(b>0){
        if(b & 1)
            ans = (ans*a)%p;
        a = (a*a)%p;
        b >>= 1;
    }
    return ans;
}

ll mod_inv(ll n, ll p){
    return power(n,p-2, p);
}

bool inline isPrime(ll n) {
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
    return true;
}
template<typename... T>
void W(T&&... args)
{
	((cout << sp(9) <<  args << " "), ...);
	nl;
}
template<typename... T>
void R(T&&... args)
{
	((cin >> args), ...);
}
ll ston(string s) 
{
	ll a = 0;
	reverse(s.begin(),s.end());
	ll pow = 1;
	for(int i=0;i<s.size();i++)
	{
		a += pow*(s[i]-'0');
		pow*=10;
	}
	return a;
}
template <class T>
string to_binary(T n) 
{
	string binaryNum;
	int i = 0;
	while (n > 0) {
		binaryNum.pb((n % 2)+'0');
		n = n / 2;
		i++;
	}
	reverse(binaryNum.begin(),binaryNum.end());
	return binaryNum;
}
template<class T>
bool perfectSq(T n)
{
	if(sqrt(n) == floor(sqrt(n)))
		return true;
	else
		false;
}
template<class T>
void wv(T &v)
{
	for(auto x : v)
		cout << x << " " ;
	nl;
}
template<class T>
void rv(T &v)
{
	for(int i=0;i<sz(v);i++)
		cin >> v[i];
}
void solve()
{
	int i,j;ll sum = 0,prod = 1;ll maxl = LONG_MIN,minl = LONG_MAX;int maxi = INT_MIN,mini = INT_MAX;
	int n,m,k;
	R(n,m,k);
	vll fact(n+1);
	fact[0] = 1;
	for(i=1;i<=n;i++)
		fact[i] = (i*fact[i-1])%modc;
	vll pow(n);
	pow[0] = 1;
	for(i=1;i<n;i++)
		pow[i] = (pow[i-1]*(m-1))%modc;
	ll p = modc;
	for(i=0;i<=k;i++)
	{
		sum+=((((((fact[n-1]*mod_inv(fact[i],p))%p)*mod_inv(fact[n-1-i],p))%p)*pow[n-1-i])%p*m)%p;
		sum%= p;
	}
	W(sum);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
	while(t--)
	{
		solve();
	}
}


Measured memory_bytes: 6344
#include "stdio.h"

int main(void){
  int x,y,z;
  scanf("%d %d %d", &x, &y, &z);
  int t;
  if(x > y){
    t = x;
    x = y;
    y = t;
  }
  if(y > z){
    t = y;
    y = z;
    z = t;
  }
  if(x > y){
    t = x;
    x = y;
    y = t;
  }
  printf("%d %d %d\n", x, y, z);
}




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

using namespace std;
#define ll long long
#define N 1000000007
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

int main() {
	int n,a,b;
	cin>>n;
	a=n%100;
	b=n/100;
	bool a1=0,b1=0;
	if(a<13 && a>0) a1=1;
	if(b<13 && b>0) b1=1;
	if(a1 && b1)    cout<<"AMBIGUOUS";
	else if(!a1 && !b1)  cout<<"NA";
	else if(a1) cout<<"YYMM";
	else cout<<"MMYY";
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
from collections import defaultdict, deque
import math
from math import factorial
import fractions
import re

BIGNUM = 10 ** 9 + 7

def main():
    N, x = map(int, input().split())
    As = list(map(int, input().split()))

    As = sorted(As)
    total = 0
    num = 0
    for a in As:
        if total+a <= x:
            total += a
            num += 1
        else:
            break

    if num == N and total != x:
        num -= 1
    print(num)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5312
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b; cin>>a>>b;
  int count=0;
  
  if(a%3==0) count++;
  if(b%3==0) count++;
  if((a+b)%3==0) count++;
  
  if(count>0) cout <<"Possible"<<endl;
  else cout<<"Impossible"<<endl;










}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef vector<int> vec;
//配列の添字ズレに注意
//=に注意

int main(){
  int a; cin>>a;
  //string s; cin>>s;
  cout<< (a%1000==0?0:1000-(a%1000))<<endl;
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{
	int N;
	cin >> N;
	ll ans = 0;
	vecl(A);
	vector<ll> B(N + 1,0);
	fx(N) {
		vecpl(A);
	}
	fx(N) {
		B[N - x -1] =B[N-x]+ A[N - x-1];
		B[N - x - 1] %= MOD;
	}
	
	fx(N) {
		ll sum = B[x+1] *A[x];
		ans += sum % MOD;
		ans %= MOD;
	}
	ce(ans)
    return 0;
}



Measured memory_bytes: 6936
import java.util.*;

public class Main {
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			long h = sc.nextLong();
			long w = sc.nextLong();
			
			if(h % 3 ==0 || w % 3 == 0){
				System.out.println(0);
				continue;
			}
			
			
			long res = Long.MAX_VALUE;
			for(int i  =1; i <= w; i++){
				long a = h / 2 * (w - i);
				long b = (h + 1) / 2 * (w - i);
				long c = h * i;
				
				long max = Math.max(a, Math.max(b, c));
				long min = Math.min(a, Math.min(b, c));
				res = Math.min(res, max - min);
			}
			
			for(int i  =1; i <= h; i++){
				long a = w / 2 * (h - i);
				long b = (w + 1) / 2 * (h - i);
				long c = w * i;
				
				long max = Math.max(a, Math.max(b, c));
				long min = Math.min(a, Math.min(b, c));
				res = Math.min(res, max - min);
			}
			res = Math.min(res, Math.min(w, h));
			
			System.out.println(res);

		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

}


Measured memory_bytes: 23252
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;

 main()

{
    fast
    int n,z,w;
    cin>>n>>z>>w;
    int a[n+2];
    f(i,1,n)
    {
        cin>>a[i];
    }
    int last=a[n];
    int v1=abs(last-w);
    if(n==1)
    {
        cout<<v1<<endl;
        return 0;
    }
    int v2=abs(last-a[n-1]);
    if(v1>v2)
    {
        cout<<v1<<endl;
        return 0;
    }
    cout<<v2<<endl;
    return 0;

}





































Measured memory_bytes: 3628