akhauriyash/Code-Regression huggingface dataset:
require 'pp'

n, h = gets.chomp!.split(" ").map(&:to_i)
a_n = Array.new(n)
b_n = Array.new(n)
n.times do |i|
    a, b = gets.chomp!.split(" ").map(&:to_i)
    a_n[i] = a
    b_n[i] = b
end

# 通常攻撃の最大値以下の通常攻撃と投げ技は価値がない
# 投げ技は最後の攻撃で投げればよいので，
# (通常攻撃の最大値, 通常攻撃の最大値より大きい投げ技1, 通常攻撃の最大値より大きい投げ技2, ...)
# 大きい順に適用すればよい

basic_max = a_n.max
nage = b_n.sort!.select{|x| x > basic_max }

count = 0
while h > 0 && nage.empty?.!
    h -= nage.pop
    count += 1
end

if h > 0
    count += h / basic_max
    if h % basic_max != 0
        count += 1
    end
end

puts count


Measured memory_bytes: 4712
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
	#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N,T;
    cin >> N >> T;
    vector<ll> A(N), B(N), C(N+1);
    rep(i,N){
        cin >> A[i] >> B[i];
    }
    vector<vector<ll>> dp(N+1, vector<ll>(T+1)), dp2(N+1, vector<ll>(T+1));
    rep(i,N){
        rep(j,T){
            if(j+A[i] <= T){
                cmax(dp[i+1][j+A[i]], dp[i][j] + B[i]);
            }
            cmax(dp[i+1][j+1], dp[i][j+1]);
            cmax(dp[i+1][j+1], dp[i+1][j]);
        }
    }
    for(ll i=N;i>0;i--){
        rep(j,T){
            if(j+A[i-1] <= T){
                cmax(dp2[i-1][j+A[i-1]], dp2[i][j] + B[i-1]);
            }
            cmax(dp2[i-1][j+1], dp2[i][j+1]);
            cmax(dp2[i-1][j+1], dp2[i-1][j]);
        }
    }
    ll ans = 0;
    REP(i,0,N){
        rep(j,T){
            cmax(ans, dp[i][j] + B[i] + dp2[i+1][T-1-j]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 144136
#define _CRT_SECURE_NO_WARNINGS

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

typedef unsigned int uint;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mii;
typedef pair<int, ii> edge;


#define sc(x)  scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mem(arr,val) memset(arr,val,sizeof arr)
#define sz(v) (int)v.size()
#define rsz(v) v.resize
#define clr(v) v.clear()
#define rev(v) reverse(all(v))
#define lop(i,end) for(int i=0; i<end; i++)
#define rlop(i,start) for(int i=start-1; i>=0; i--)
#define loop(i,start,end) for(int i=start; i<end; i++)
#define rloop(i,start,end) for(int i=start-1; i>=end; i--)
#define PB push_back
#define pb pop_back
#define mP make_pair
#define f first
#define s second

const ll OO = (ll)(4e18) + 9;
const int MOD = (int)(1e9) + 7;
const int oo = 2147483647;
const double EPS = 1e-8;
const double PI = acos(-1.0);

//enum dir { D, R, U, L , dr, ur, dl, ul };
int dx[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
int dy[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

string abc = "abcdefghijklmnopqrstuvwxyz";
string vowels = "aeiouy"; //and sometimes "aeiouy"

template<typename X, typename Y> bool ckmin(X& a, Y b) { return a > b ? a = b, true : false; }
template<typename X, typename Y> bool ckmax(X& a, Y b) { return a < b ? a = b, true : false; }
bool cklex(string &a, string b) {
	if (b == "") return false;
	if (a == "") return a = b, true;
	if (sz(a) < sz(b)) return false;
	if (sz(b) < sz(a)) return a = b, true;
	if (a < b) return false;
	return a = b, true;
}

int dcmp(ld d1, ld d2) { return fabs(d1 - d2) <= EPS ? 0 : d1 > d2 ? 1 : -1; } //Compare Double Numbers
ll gcd(ll x, ll y) { return !y ? x : gcd(y, x%y); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
int conv_2_1(int r, int c, int nCol) { return (nCol*r) + c + 1; } //convert index from 2D array to 1D array. (Zero-indexed)
ii conv_1_2(int n, int nCol) { return{ n / nCol, n % nCol }; } //convert index from 1D array to 2D array (row, col). (Zero-indexed)
template<typename T> void inter(T X) { cout << X << endl; fflush(stdout); }


void _solveE_() {
	ull n, x, m;
	cin >> n >> x >> m;
	map<ull, int> mp;
	ull ans = 0;
	int i = 0;
	vector<ull> v;
	while (i < n and x) {
		if (mp[x]++) {
			int idx = 0;
			lop(j, sz(v)) if (v[j] == x) {
				idx = j;
				break;
			}
			ull szz = sz(v) - idx;
			ull div = (n - (ull)i) / szz;
			ull rem = (n - (ull)i) % szz;
			loop(j, idx, sz(v)) {
				if (j - idx < rem) ans += v[j];
				ans += div * v[j];
			}
			break;
		}
		v.push_back(x);
		ans += x;
		x = ((x%m)*(x%m)) % m;
		i++;
	}
	cout << ans << endl;
}

void _solveD_() {

}

void _solveC_() {

}

void _solveB_() {

}

void _solveA_() {

}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int t = 1, tt = 0;
	//cin >> t;
	while (tt++ != t) {
		_solveE_();
	}


	return 0;
}


Measured memory_bytes: 6724
#include <iostream>
#include <string>
#include<math.h>
#include<map>
#include<vector>
#include <tuple>
#include <algorithm>
using namespace std;
int main() {
  long long int N;
  cin >> N;
  long long int A[N];
  long long int B[N];
  vector<pair<int,int> > vec;
  for(int i = 0; i < N; i++){
    int a, b;
    cin >> a >> b;
    vec.emplace_back(b, a);
  }
  sort(vec.begin(), vec.end());
  long long int sum = 0;
  for(auto v:vec){
    sum += v.second;
    if(sum > v.first){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N, M;
	cin >> N >> M;
	vector<ll> A(N), B(M);
	REP(i, N) cin >> A[i];
	REP(i, M) cin >> B[i];

	sort(A.begin(), A.end());
	sort(B.begin(), B.end());

	bool dabli_flag = false;
	REP(i, N-1) if(A[i]==A[i+1]) dabli_flag = true;
	REP(i, M-1) if(B[i]==B[i+1]) dabli_flag = true;
	if(dabli_flag){
		cout << 0 << endl;
		return 0;
	}

	ll res = 1;
	for(ll x=N*M;x>=1;x--){
		ll x_in_A = upper_bound(A.begin(), A.end(), x) - lower_bound(A.begin(), A.end(), x);
		ll x_in_B = upper_bound(B.begin(), B.end(), x) - lower_bound(B.begin(), B.end(), x);
		ll x_yori_A = A.end() - upper_bound(A.begin(), A.end(), x);
		ll x_yori_B = B.end() - upper_bound(B.begin(), B.end(), x);

		if(x_in_A==1&&x_in_B==1){
			res *= 1;
		}else if(x_in_A==1){
			res *= x_yori_B;
			res %= mod;
		}else if(x_in_B==1){
			res *= x_yori_A;
			res %= mod;
		}else{
			ll tmp = x_yori_A*x_yori_B - N*M + x;
			if(tmp<=0) res *= 0;
			else res *= tmp;
			res %= mod;
		}
	}
	cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
h,w,K = map(int,input().split())
cum = [[0 for _ in range(w+1)]]
for _ in range(h):
  tmp = input()
  add = [0]
  for j in range(w):
    add.append(add[-1]+int(tmp[j]))
  cum.append(add)
for i in range(h):
  for j in range(w):
    cum[i+1][j+1] += cum[i][j+1]
time = [0 for _ in range(h-1)]
def nex(time):
  for d in range(h-1):
    if time[d] == 0:
      time[d] = 1
      return time
    else:
      time[d] = 0
  else:
    return 'over'
can = []
while time != 'over':
  tmp = [0]
  for d in range(h-1):
    if time[d] == 1:
      tmp.append(d+1)
  tmp.append(h)
  #print(tmp,time)
  l = len(tmp) - 1
  ans = l - 1
  now = 0
  att = 1
  for j in range(1,w+1):
    cand = []
    for k in range(l):
      cand.append(cum[tmp[k+1]][j] - cum[tmp[k+1]][now] - cum[tmp[k]][j] + cum[tmp[k]][now])
    #print(cand,now,tmp)
    if max(cand) > K:
      now = j - 1
      ans += 1
      cane = []
      for k in range(l):
        cane.append(cum[tmp[k+1]][j] - cum[tmp[k+1]][now] - cum[tmp[k]][j] + cum[tmp[k]][now])
        #if tmp == [0,1,3]:
          #print(cane,j)
        if max(cane) > K:
          ans += 1
          now = j
    #print(l-1,ans,time)
  else:
    can.append(ans)
  time = nex(time)
  #print(tmp,l-1,ans)
print(min(can))

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    int ans = m;
    rep(i,n-m+1){
        int cnt = 0;
        rep(j,m){
            if(s[i+j] != t[j]) ++cnt;
        }
        chmin(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <numeric>
#include <bitset>
using namespace std;
#define lint long long
#define ll long long
#define pq priority_queue
const long long INF = 10000000;
#define pii pair<long long,long long>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
/****************temporary declaration & definitions*******************/
const int MAX_H = 50, MAX_W = 50;
char maze[MAX_H][MAX_W + 1];
int H, W;
int sx, sy;
int gx, gy;

int d[MAX_H][MAX_W];

int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
/**************************define functions****************************/
int bfs() {
	queue<pii> que;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			d[i][j] = INF;
		}
	}
	que.push(pii(sx, sy));
	d[sx][sy] = 0;

	while (que.size()) {
		pii p = que.front(); que.pop();
		int x = p.first, y = p.second;
		if (p.first == gx && p.second == gy) break;
		for (int i = 0; i < 4; i++) {
			int nx = x + dx[i], ny = y + dy[i];

			if (0 <= nx && nx < H && 0 <= y && ny < W&& maze[nx][ny] != '#'&& d[nx][ny] == INF) {
				que.push(pii(nx, ny));
				d[nx][ny] = d[p.first][p.second] + 1;
			}
		}
	}
	return d[gx][gy];
}
/****************************main function*****************************/
int main(void) {
	cin >> H >> W;
	sx = 0, sy = 0, gx = H - 1, gy = W - 1;
	int black = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> maze[i][j];
			if (maze[i][j] == '#') black++;
		}
	}
	int goal = bfs();
	if (goal == INF){ cout << -1 << endl; return 0; }
	else { cout << (H*W) - black - goal - 1 << endl; return 0; }
	
}

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

int main()
{
  string s;
  int n;
  cin >> s >> n;
  for (int i = 0; i < n; i++)
  {
    string op;
    int a, b;
    cin >> op >> a >> b;
    if (op == "print")
    {
      cout << s.substr(a, b - a + 1) << endl;
    }
    else if (op == "reverse")
    {
      string left, mid, right;
      left = s.substr(0, a);
      mid = s.substr(a, b - a + 1);
      right = s.substr(b + 1, s.size() - b - 1);
      reverse(mid.begin(), mid.end());
      s = left + mid + right;
    }
    else if (op == "replace")
    {
      string r;
      cin >> r;
      string left, right;
      left = s.substr(0, a);
      right = s.substr(b + 1, s.size() - b - 1);
      s = left + r + right;
    }
  }
}


Measured memory_bytes: 3228
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
//		executeA();
		executeB();
	}

	private static void executeA() {

		Scanner sc = new Scanner(System.in);

		String s1 = sc.nextLine();
		String[] s1Array = s1.split(" ");

		try {
			int n = Integer.parseInt(s1Array[0]);
			int m = Integer.parseInt(s1Array[1]);

			int count = (n*(n-1) + m*(m-1))/2;
			PrintWriter pw = new PrintWriter(System.out);
			pw.println(count);
			pw.flush();
			pw.close();
		} catch (NumberFormatException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
	}

	private static void executeB() {
		Scanner in = new Scanner(System.in);
		String s1 = in.nextLine();

		int result = 1;
		int len = s1.length();
		int halflen = (len-1)/2;

		for(int i=0;i<halflen;i++) {
			if(s1.charAt(i) != s1.charAt(len-1-i)){
				result = -1;
				break;
			}
		}

		if( result == 1) {
			for(int i=0;i<halflen/2;i++) {
				if(s1.charAt(i) != s1.charAt(halflen-1-i)){
					result = -1;
					break;
				}
				if(s1.charAt(halflen+1+i) != s1.charAt(len-1-i)){
					result = -1;
					break;
				}
			}
		}

		PrintWriter pw = new PrintWriter(System.out);
		pw.println( result == 1 ? "Yes" : "No" );
		pw.flush();
		pw.close();
	}

}


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

int main() {
    
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i,n) cin >> v[i];

    cout << accumulate(v.begin(), v.end(), 0) - n << endl;

    return 0;
}
    

Measured memory_bytes: 3636
//https://atcoder.jp/contests/abc152/tasks/abc152_b
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
int main() {
    string a,b; cin>>a>>b;
    ll ai = std::stoi(a);
    ll bi = std::stoi(b);     
    vector<string> ans;

    string tmp;
    REP(i,ai){
        tmp += b;
    }
    ans.push_back(tmp);
    tmp="";
    REP(i,bi){
        tmp += a;
    }
    ans.push_back(tmp);

    sort(ans.begin(),ans.end());
    cout<<ans[0]<<endl;
    return 0;
}

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

int main(){

    ll a,b,c,d;
    cin >> a >> b >> c >> d;

    ll tmp,r,x;
    ll m1, m2;
    m1 = c;
    m2 = d;
    x = c*d;
    if(c<d){
        tmp = c;
        c = d;
        d = tmp;
    }
    r = c % d;
    while(r!=0){
    c = d;
    d = r;
    r = c % d;
    }

    ll lcm = x/d;

    ll m1count,m2count,lcmcount;

    ll bmod,emod;
    bmod = a%m1;
    emod = b%m1;
    
    if(bmod== 0){
        m1count = (b/m1)-(a/m1)+1;
    }else{
        m1count = (b/m1)-(a/m1);
    }


    bmod = a%m2;
    emod = b%m2;
    if(bmod== 0){
        m2count = (b/m2)-(a/m2)+1;
    }else{
        m2count = (b/m2)-(a/m2);
    }

    bmod = a%lcm;
    emod = b%lcm;
    if(bmod== 0){
        lcmcount = (b/lcm)-(a/lcm)+1;
    }else{
        lcmcount = (b/lcm)-(a/lcm);
    }

    ll answer = (b-a)+1-(m1count+m2count-lcmcount);

    cout << answer << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  cin>>s;
  int ans=0;
  for(int i=0;i<3;i++){
    if(s.at(i)=='1'){
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
def md(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors[:1]+divisors[2:]

N = int(input())
A = [int(i) for i in input().split()]
ans = []

for i in range(N)[::-1]:
  a = A[i]
  if a % 2:
    ans.append(i+1)
  D = md(i+1)
  
  for d in D:
    A[d-1] += a
    
print(len(ans))
print(*ans)

Measured memory_bytes: 69212
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<i64> as(N);
  i64 all = 0;
  F0R(i, N) {
    cin >> as[i];
    all ^= as[i];
  }
  //cout << bitset<64>(all) << newl;
  all = ~all;
  F0R(i, N) {
    as[i] &= all;
  }
  sort(rrng(as));
  int rank = 0;
  RF0(i, 63) {
    if (rank >= as.size()) break;
    if (!(as[rank] >> i)) continue;

    F0R(j, as.size()) {
      if (rank == j) continue;
      if (!((as[j] >> i) & 1)) continue;
      as[j] ^= as[rank];
    }

    rank++;
    sort(rrng(as));
  }

  i64 all2 = 0;
  F0R(i, as.size()) {
    all2 ^= as[i];
    //cout << bitset<64>(as[i]) << newl;
  }

  all = ~all;
  i64 result = all2 + all2 + all;
  cout << result;
}
#endif


Measured memory_bytes: 1024
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  int n;
  scanf("%d",&n);
  vector<int> vc(n);
  for(int i = 0 ; i < n ; i++ ) scanf("%d",&vc[i]);
  int ans = 0,q,a;
  scanf("%d",&q);
  sort(vc.begin(),vc.end());
  while(q--){
    cin >> a;
    if(binary_search(vc.begin(),vc.end(),a)) ans++;
  }
  printf("%d\n",ans);
}


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

int main(){
	long long n;
	cin >> n;
	
	vector<string> s(n);
	rep(i, n) cin >> s.at(i);
	sort(s.begin(), s.end());
    s.erase(unique(s.begin(), s.end()), s.end());
	
	cout << s.size() << endl;
  
 // rep(i, n) cout << s.at(i) << endl;
}

Measured memory_bytes: 9580
using System;
using System.Linq;
 
namespace AtcoderProj
{
    class AtcoderClass
    {
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(input[0] - input[1] * 2 < 0 ? 0 :input[0] - input[1] * 2);
        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  //vector<int> x(N);
  int ans = 0;
  for (int i = 0; i < N;i++){
    int x;
    cin >> x;
    ans += (min(x - 0, K - x))*2;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n=int(input())
d={}
ans=0
for i in range(n):
    a=int(input())
    try:
        if d[a]%2==0:
            ans+=1
            d[a]+=1
        else:
            ans-=1
            d[a]+=1
    except:
        d[a]=1
        ans+=1
print(ans)


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

int main(void){
	int n;

	scanf("%d",&n);
	if(n%10==7){
		printf("Yes");
	}else{
		n=n/10;
		if(n%10==7){
			printf("Yes");
		}else{
			n=n/10;
			if(n==7){
				printf("Yes");
			}else{
				printf("No");
			}
		}

	}
	return 0;
}


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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod (int)(1e9 +7);

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef string ss;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}

vll binary_convert(ll n){
    vll s;
    ll size = 0;

    while(n / (ll)(pow(2,size)) > 0)size++;
    rep(i,size + 1){
        s.pb(n / (ll)(pow(2,i)));
        n %= (ll)(pow(2,i));
    }

    return s;
}

int main()
{
    vll a(3);
    ll max = 0,axn;
    rep(i,3){
        cin >> a[i];
        if(max < a[i]){
            max = a[i];
            axn =  i;
        }
    }

    ll ans = 0;
    rep(i,3){
        if(i != axn)ans += a[i];
    }

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

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        String b = sc.next();

        if(b.equals("A")){
            System.out.println("T");
        }
        else if(b.equals("T")){
            System.out.println("A");
        }
        else if(b.equals("C")){
            System.out.println("G");
        }
        else if(b.equals("G")){
            System.out.println("C");
        }
    }
}

Measured memory_bytes: 22996
n = int(input())
strli = [input() for i in range(n)]

seen = []
before = ''
flag = True

for i in strli:
    if before != '':
        if before[-1] != i[0]:
            flag = False
    if i in seen:
        flag = False
    if not flag:
        break
    before = i
    seen.append(i)

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


Measured memory_bytes: 3064
n,*a=map(int,open(0).read().split())
mod=998244353
b=[0]*n
for i in a:
    b[i]+=1
ans=0
if a[0]==0 and 1==b[0]:
    ans=1
for i,j in zip(b,b[1:]):
    ans=ans*i**j%mod
print(ans)

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

/* Name of the class has to be "Main" only if the class is public. */
public class Main {
    public static void main(String[] args) throws java.lang.Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k=sc.nextInt();
        int h[] = new int[n];
        int min=0;
        for (int i = 0; i < n; i++)
        {
            h[i]=sc.nextInt();
        }
        int a[]=new int[n];
        a[0]=0;
        a[1]=Math.abs(h[1]-h[0]);
        for(int i=2;i<n;i++)
        {
            min=Integer.MAX_VALUE;
            for(int j=1;j<=k ;j++)
            {if(i-j<0)
                break;
            min=Math.min(min,a[i-j]+Math.abs(h[i-j]-h[i]));
           }
            a[i]=min;
            //System.out.println(a[i]);
        }
        System.out.println(a[n-1]);
    }
}

Measured memory_bytes: 53224
#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define repid(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin,(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define int intl
#define itn intl
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool flag){
    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;
}
void fp(bool flag, string s, string t){
    if(flag)cout << s << endl;
    else cout << t << endl;
}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl digit10(intl a){
    if(!a)return 1;
    intl b = 0;
    while(a){
        a /= 10;
        b++;
    }
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    string a,b,c;
    cin >> a >> b >> c;
    bool f = true;
    if(a[a.length() - 1] != b[0])f = false;
    if(b[b.length() - 1] != c[0])f = false;
    fp(f,"YES","NO");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    #define   nl   <<'\n'
    #define   pi   acos(-1.0);
    #define   ll   long long
    #define   pb   push_back
    #define   eb   emplace_back
    #define   tc   int t; cin>>t; while(t--)
    #define   fio  ios_base::sync_with_stdio(0); cin.tie(0)

    ll a[2001];

    int main()
    {
        fio;
        int n;
        cin>>n;
        a[1]=a[2]=0,a[3]=a[4]=a[5]=1;
        if(n<6)
        {
            cout<<a[n] nl;
            return 0;
        }
        for(int i=6; i<=n; i++)
        {
            a[i]=a[i-1]+a[i-3];
            a[i]%=1000000007;
        }
        cout<<a[n] nl;
    }  

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int a, b, c, counter, counter1;
int main(){
	while(cin>>a>>b){
		c=a+b;
		counter=0;
		while(c>0){
			counter++;
			c=c/10;
		}
		cout<<counter<<endl;
	}
	
	
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
#define  B   begin()
#define  E   end()
const int N=2e5+3;
//string s,p;
//vector<int>v;
//map<int,int>mp;

int main()
{
    ft
    int t,i,j,n,m,l,r;
    string s;
    cin>>s;
    if(s[0]=='R' && s[1]=='R' && s[2]=='R')
    {
        cout<<"3\n";
    }
    else if((s[0]==s[1] && s[0]=='R') || (s[1]==s[2] && s[1]=='R'))
    {
        cout<<"2\n";
    }
    else if(s[0]=='R' || s[1]=='R' || s[2]=='R')
    {
        cout<<"1\n";
    }
    else
    {
        cout<<"0\n";
    }
    return 0;
}



Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define INF (1<<21)
const int maxn=100000+10;
int n;
int a[maxn];
int L[maxn];
void solve()
{
   L[0]=a[0];
   int len=1;
   for(int i=1;i<n;i++)
   {
       if(L[len-1]<a[i])
       {
           L[len++]=a[i];
       }
       else
       {
            *lower_bound(L,L+len,a[i])=a[i];
       }

   }
   printf("%d\n",len);


}
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&a[i]);

    solve();

    return 0;
}

Measured memory_bytes: 3888
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a[4];
    rep(i,4)cin>>a[i];
    sort(a,a+4);
    cout<<abs(a[0]+a[3]-a[1]-a[2])<<endl;
    return 0;
}


Measured memory_bytes: 3216
#include <iostream>

using namespace std;

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

	int h, a, ans;
	
	cin >> h >> a;

	ans = h / a;

	if (h % a == 0) cout << ans;
	else cout << ans + 1;

	return 0;
}

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

int main(){
  double a,b,x,r;
  cin>>a>>b>>x;
  r=(x<=a*a*b/2.0)? atan((a*b*b)/(2.0*x)): atan((2*(a*a*b-x))/(a*a*a));
  cout<<fixed<<setprecision(10)<<r*180.0/M_PI<<endl;
}

Measured memory_bytes: 4068
"""素因数分解"""
def prime_decomposition(n):
    i = 2
    tank = []
    while i * i <= n:
        while n%i == 0:
            n /= i
            tank.append(i)
        i += 1
    if n > 1:
        tank.append(int(n))
    return tank

from collections import Counter

n = int(input())
if n==1:
    print(0)
    exit()

lst = prime_decomposition(n)
c = Counter(lst)
ans = 0

for k,v in c.items():
    j = 1
    while True:
        if j*(j+1)//2 <=v:
            j += 1
        else:
            break
    ans += j-1
print(ans)

Measured memory_bytes: 66000
import math
s = input().split(" ")
a = round(float(s[0]),8)
b = round(float(s[1]),8)
c = round(float(s[2]),8)
d = round(math.sqrt(a**2 + b**2 - 2*a*b*(round(math.cos(math.radians(c)),8))),8)
L = a + b + d
S = round(b * a * (round(math.sin(math.radians(c)),8)) / 2, 8)
h = round(S * 2 / a, 8)
print(S)
print(L)
print(h)

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

struct Node{
  int key, priority;
  struct Node *right, *left;
};

struct Node *root, *NIL;

struct Node *rightRotate(struct Node *t){
  struct Node *s = t->left;
  t->left = s->right;
  s->right = t;
  return s; // root of the subtree
}

struct Node *leftRotate(struct Node *t){
  struct Node *s = t->right;
  t->right = s->left;
  s->left = t;
  return s; // root of the subtree
}

struct Node *find(struct Node *u, int k){
  while(u != NIL && k != u->key){
    if(k < u->key)  u = u->left;
    else  u = u->right;
  }
  return u;
}


struct Node *insert(struct Node *t, int key, int priority){           // 再帰的に探索
  struct Node *z;
  if(t == NIL){
    z = malloc(sizeof(struct Node));
    z->key = key;
    z->priority = priority;
    z->left = NIL;
    z->right=NIL;
    return z;
  }

  if(key < t->key){                               // 左の子へ移動
    t->left = insert(t->left, key, priority);   // 左の子へのポインタを更新
    if(t->priority < t->left->priority)          // 左の子の方が優先度が高い場合右回転
      t = rightRotate(t);
  }
  else{                                         // 右の子へ移動
    t->right = insert(t->right, key, priority); // 右の子へのポインタを更新
    if(t->priority < t->right->priority)         // 右の子の方が優先度が高い場合左回転
      t = leftRotate(t);
    }

    return t;
}

struct Node *_delete(struct Node*, int);

struct Node *delete(struct Node *t, int key){
  if(t == NIL)
    return NIL;
  if(key < t->key)                                // 削除対象を検索
    t->left = delete(t->left, key);
  else if(key > t->key)
    t->right = delete(t->right, key);
  else
    return _delete(t, key);
  return t;
}

struct Node *_delete(struct Node *t, int key){ // 削除対象の節点の場合
    if(t->left == NIL && t->right == NIL)           // 葉の場合
      return NIL;
    else if(t->left == NIL)                        // 右の子のみを持つ場合左回転
      t = leftRotate(t);
    else if(t->right == NIL)                       // 左の子のみを持つ場合右回転
      t = rightRotate(t);
    else{                                         // 左の子と右の子を両方持つ場合
      if(t->left->priority > t->right->priority)    // 優先度が高い方を持ち上げる
        t = rightRotate(t);
      else
        t = leftRotate(t);
    }
    return delete(t, key);
}

void inorder(struct Node *u){
  if(u == NIL)  return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(struct Node *u){
  if(u == NIL)  return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(void){
  int n, i, x, y;
  char s[20];

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%s", s);
    if(s[0] == 'i'){
      scanf("%d %d", &x, &y);
      root = insert(root, x, y);
      x++;
    }
    else if(s[0] == 'f'){
      scanf("%d", &y);
      struct Node *t = find(root, y);
      if(t != NIL)  printf("yes\n");
      else  printf("no\n");
    }
    else if(s[0] == 'd'){
      scanf("%d", &y);
      root = delete(root, y);
    }
    else if(strcmp(s ,"print")==0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}



Measured memory_bytes: 7992
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (i=a;i<n;i++)
#define per(i,a,n) for (i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define PI acos(-1)
#define SIZE 2000001
#define ONLINE_JUDGE
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
auto clk=clock(); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;

vector<ll> set_count;

ll overlap(int j,int k){
	ll ans=0,i;
	for(i=2*j;i<k+1;i+=j)
		if(i%j==0)
			ans+=set_count[i];
	return ans;
}

int main(){
	/*srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(20);
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);*/
	
	//
	ll n,k,ans=0,i;
	cin>>n>>k;
	set_count.resize(k+2);
	rep(i,1,k+1) set_count[i]=powmod(k/i,n);
	per(i,1,k+1) set_count[i]=(set_count[i]-overlap(i,k))%mod;
	rep(i,1,k+1) ans=(ans%mod+((i%mod)*(set_count[i]%mod))%mod)%mod;
	cout<<ans;
	//

	/*#ifdef ONLINE_JUDGE
	cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<" sec"<<endl;
	#endif*/
	return 0;
}

Measured memory_bytes: 4032
import java.util.*;

public class Main{
  public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        if(X >= 400 && X <= 599) {
        	System.out.println("8");
        }else if(X >= 600 && X <= 799) {
        	System.out.println("7");
        }else if(X >= 800 && X <= 999) {
        	System.out.println("6");
        }else if(X >= 1000 && X <= 1199) {
        	System.out.println("5");
        }else if(X >= 1200 && X <= 1399) {
        	System.out.println("4");
        }else if(X >= 1400 && X <= 1599) {
        	System.out.println("3");
        }else if(X >= 1600 && X <= 1799) {
        	System.out.println("2");
        }else if(X >= 1800 && X <= 1999) {
        	System.out.println("1");
        }
	}
}

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

int main() {
	int d;
	cin >> d;
	vector<int> c(30);
	vector<int> co(d+5);
	vector<int> ans(d + 5);
	int ans_c = 0;

	rep(i,26) {
		cin >> c[i];
	}

	vector<int> last(26);

	rep(i, 26) {
		last[i]=0;
	}

	vector<int> t(d + 5);
	int s[370][30];

	rep(j, d) {
		rep(i, 26) {
			cin >> s[j][i];
		}
	}

	int count = 0;
	
	rep(j, d) {

		int max=s[j][0];
		int max_d=0;

		rep(i, 26) {
			if (max <= s[j][i]) {
				max = s[j][i];
				max_d = i;
			}
		}

		last[max_d] = j+1;
		count += max;

		rep(i, 26) {
			count -= c[i] * (j+1-last[i]);
		}

		co[j] = max_d;
	}

	ans_c += count;
	count = 0;
//	cout << ans_c << endl;

	rep(k, 1000) {
		count = 0;
		rep(j, d) {
			ans[j] = co[j];
		}

		rep(i,((1000-k)/100)+1) {
			ans[(rand() % d)] = rand()%26;
		}
		rep(i, 26) {
			last[i] = 0;
		}

		rep(j, d) {

			rep(i, 26) {
				if (ans[j] + 1 == i) {
					count += s[j][i];
				}
				else {
					count -= c[i] * (j + 1 - last[i]);
				}
			}
		}
	//	cout << count << endl;

		if (ans_c <= count) {
			ans_c = count;
			rep(j, d) {
				co[j] = ans[j];
			}

			rep(j, d) {
				cout << co[j] + 1 << endl;
			}
		}

	}


	rep(j, d) {
		cout << co[j]+1<<endl;
	}

	return 0;
}

Measured memory_bytes: 3672
import bisect


def main():
    N = int(input())
    A = list(map(int, input().split(' ')))
    B = list(map(int, input().split(' ')))
    C = list(map(int, input().split(' ')))
    A.sort()
    B.sort()
    C.sort()
    ans = 0
    for i in range(N):
        ans += bisect.bisect_left(A, B[i]) * (N - bisect.bisect_right(C, B[i]))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 22720
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる





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

  cout << 48-a << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#include <numeric>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[8]={ 0, 1, 0,-1, 1, 1,-1,-1}; // x軸方向への変位
ll dy[8]={ 1, 0,-1, 0, 1,-1, 1,-1}; // y軸方向への変位


int main(void){
    ll n;
    cin >> n;
    map<p, ll> I{};
    vector<p> vp;
    for(ll i = 0; i < n; i++){
        ll a, b;
        cin >> a >> b;
        vp.push_back(p(a, b));
    }
    for(ll i = 0; i < n; i++){
        for(ll j = 0; j < n; j++){
            if(i==j) continue;
            ll x = vp[j].first-vp[i].first;
            ll y = vp[j].second-vp[i].second;
            I[p(x, y)]++;
        }
    }
    ll MAX = 0;
    for(auto x : I) {
        MAX = max(MAX, x.second);
        //cout << x.second << endl;
    }
    cout << n-MAX << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define fi first
#define se second
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5, M = 1e6 + 5;
const ll LINF = 1e18 + 5;
constexpr int mod = 998244353, two = (mod+1)/2;
int n, a[N], c[M], f[M];
int mu[M], prime[M];
bool vis[M];
void init(int n)
{
	mu[1] = 1; 
	for(int i=2; i<=n; i++)
	{
		if(!vis[i])
		{
			prime[++prime[0]] = i;
			mu[i] = -1; 
		}
		for(int j=1; j<=prime[0]&&1ll*i*prime[j]<=n; j++)
		{
			vis[i*prime[j]] = 1;
			if(i%prime[j]==0) break;
			else mu[i*prime[j]] = -mu[i]; 
		}
	}
}
int main()
{
	scanf("%d", &n);	
	for(int i=1; i<=n; i++) scanf("%d", a+i), c[a[i]]++;
	const int up = *max_element(a+1, a+n+1);
	init(up);
	for(int i=1; i<=up; i++)
		for(int j=1; j<=up/i; j++)
			f[i] = (f[i] + 1ll*j*c[i*j]%mod)%mod;
	int ans = 0;
	for(int d=1; d<=up; d++)
		for(int k=1; k<=up/d; k++)
			ans = (ans + 1ll*d*mu[k]%mod*k%mod*k%mod*f[d*k]%mod*f[d*k]%mod)%mod;
	for(int i=1; i<=n; i++) ans = (ans - a[i] + mod)%mod;
	ans = 1ll*ans*two%mod;
	if(ans<0) ans += mod;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 14848
#include <stdio.h>

int main(void){
    int a,b,c;
    
    scanf("%d %d %d",&a,&b,&c);
    
    if(a==b)
        printf("%d\n",c);
    else if(b==c)
        printf("%d\n",a);
    else
        printf("%d\n",b);
}


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

int main(void){
    string S;
    int Q, rev;
    cin >> S >> Q;
    rev = 0;
    int q;
    int f;
    char c;
    string pre = "";
    
    
    for(int i = 0; i < Q; i++){
        cin >> q;
        if( q == 1 ){
            rev++;
        }
        else{
            cin >> f;
            if( (rev + f) % 2 == 1 ){
                cin >> c;
                pre = pre + c;
            }
            else{
                cin >> c;
                S = S + c;
            }
        }
    }
    reverse(pre.begin(), pre.end());
    S = pre + S;
    if(rev % 2 == 1){
        reverse(S.begin(), S.end());
    }
    cout << S;
    
    
}

Measured memory_bytes: 1708
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int64_t H;
  cin >> H;
  int64_t A=0;
  int64_t B=1;
  int64_t C=1;
  if(H==1)
  {
    A=1;
  }
  
  while(A<1)
  {
    
    if(H==1)
  {
    break;
  }
    H=H/2;
    B=B+C*2;
    C=C*2;
  }
  cout << B << endl;
}

Measured memory_bytes: 3640
N = int(input())

def divisors(n):
    ret = set()
    m = 1
    while m*m <= n:
        if n%m==0:
            ret.add(m)
            ret.add(n//m)
        m += 1
    return ret

a = divisors(N)
b = divisors(N-1)

ans = len(b)-1
for k in a:
    if k==1: continue
    n = N
    while n%k==0:
        n //= k
    if n%k == 1:
        ans += 1

print(ans)

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

int main() {
    int k; cin >> k;
    queue<long long> nums;
    for (int i=1; i<=9; ++i) nums.push(i);
    for (int i=0; i<k-1; ++i) {
        long long num = nums.front();
        nums.pop();
        if (num%10 != 0) nums.push(num*10+num%10-1);
        nums.push(num*10+num%10);
        if (num%10 != 9) nums.push(num*10+num%10+1);
    }
    cout << nums.front() << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(){
    
    int a,b,c,counter=0;
    
    scanf("%d %d %d",&a,&b,&c);
    
    for(;a<=b;a++){
        if(c%a==0)
            counter++;
    }
    
    printf("%d\n",counter);
    
    return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

#define M 1000000007

//// mod power
ll mod_pow(ll x,ll n,ll mod){
	ll res=1;
	while(n>0){
		if(n&1)res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}

int n,c;
int a[444],b[444];
ll dp[444][444];
ll sum[444][444];

int main(){
	cin.sync_with_stdio(false);
	cin>>n>>c;
	rep(i,n)cin>>a[i];
	rep(i,n)cin>>b[i];
	memset(sum,0,sizeof(sum));
	rep(i,c+1)rep(j,404){
		sum[i][j+1]=(sum[i][j]+mod_pow(j+1,i,M))%M;
	}
	dp[0][0]=1;
	rep(i,n)rep(j,c+1){
		dp[i+1][j]=0;
		rep(k,j+1){
			dp[i+1][j]=(dp[i+1][j]+(dp[i][j-k]*(M+sum[k][b[i]]-sum[k][a[i]-1])%M)%M)%M;
		}
	}
	cout<<dp[n][c]%M<<endl;
	return 0;
}


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

using namespace std;

int main()
{
	int n;
	while(cin >> n && n)
	{
		while(n--)
		{
			int a,b,c;
			cin >> a >> b >> c;
			int ava=(a+b+c)/3;

			if( a==100 || b==100 || c==100 || (a+b)/2>=90 || ava>=80 )cout<<"A"<<endl;
			else if(ava>=70 || ( ava>=50 && (a>=80||b>=80)))cout<<"B"<<endl;	
			else cout << "C" << endl;
		}
	}	
}

Measured memory_bytes: 1156
#include <iomanip>
#include <utility>
#include <algorithm>
#include <type_traits>
#include <set>
#include <string>
#include <iostream>
#include <fstream>
#include <cassert>
#include <memory>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <queue>
#include <vector>
#include <array>
#include <chrono>
#include <random>
#include <forward_list>
#include <iomanip>
#include <functional>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <sstream>
#include <numeric>

using namespace std;
#define MFOR(i,end) for(size_t i = 0, end_i = (end); i < end_i; ++ i)

int main()
{
	int H, W;
	char map[100][100];//y,x
	cin >> H >> W;
	for (size_t i = 0; i < H; ++i)
	{
		cin >> map[i];
	}
	bool impossible = false;
	for (size_t x = 0; x < W; ++x) {
		for (size_t y = 0; y < H; ++y) {

			if (map[y][x] == '#')
			{
				for (size_t y2 = 0; y2 < H; ++y2) {
					impossible |= std::any_of(map[y2], map[y2] + x, [](char c) {return c == '#'; });
				}
				for (size_t y2 = 0; y2 < y; ++y2) {
					impossible |= std::any_of(map[y2], map[y2] + W, [](char c) {return c == '#'; });
				}
				map[y][x] = '.';
			}

		}
	}
	if (impossible) {
		cout << "Impossible" << std::endl;
	}
	else {
		cout << "Possible" << std::endl;
	}
}

Measured memory_bytes: 888
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<string>
#include<string.h>
using namespace std;
int n,A,B;
int m[415][415];
int v[415][415];
int a[45], b[45], c[45];
int main(){
	while (~scanf("%d%d%d", &n, &A,&B)){
		for (int i = 0; i < n; i++){
			scanf("%d%d%d", &a[i], &b[i], &c[i]);
		}
		memset(m, -1, sizeof(m));
		m[0][0] = 0;
		for (int k = 0; k < n; k++){
			for (int i = 390; i >= 0; i--){
				for (int j = 390; j >= 0; j--){
					if (m[i][j] != -1){
						if (m[i + a[k]][j + b[k]] == -1){ m[i + a[k]][j + b[k]] = c[k]+m[i][j]; }
						else{ m[i + a[k]][j + b[k]] = min(m[i + a[k]][j + b[k]], c[k]+m[i][j]); }
					}
				}
			}
		}
		int ans = 0x3f3f3f;
		for (int i = 1; i*A <= 400 && i*B <= 400; i++){
			if (m[i*A][i*B] != -1){
				ans = min(ans, m[i*A][i*B]);
			}
		}
		if (ans == 0x3f3f3f){ printf("-1\n"); }
		else{ printf("%d\n", ans); }
	}
	return 0;
}

Measured memory_bytes: 896
N = int(input().strip())

e = [0] * (N + 1)
for i in range(2, N + 1):
  cur = i
  for j in range(2, i + 1):
    while cur % j == 0:
      e[j] += 1  # jで割れるなら個数を+1
      cur //= j  # jで割っとく

def num(m):
  return len(list(filter(lambda x: x>=m-1, e)))

print(num(75) + num(25)*(num(3)-1) + num(15)*(num(5)-1) + num(5)*(num(5)-1) * (num(3)-2)//2)

Measured memory_bytes: 3064
def function(A, B, K):
    i = 1
    lista = []
    while i <= min(A, B):
        if A%i == 0 and B%i == 0:
            lista.append(i)
        i+=1
    lista.sort()
    return lista[-K]

line = input()
A, B, K = [int(n) for n in line.split()]
print(function(A, B, K))

Measured memory_bytes: 3060
import sys
import numpy as np

h, w = map(int, input().split())
s = np.array([list(input()) for i in range(h)])

bomb = np.array(np.where(s == '#')).T
n = np.zeros(s.shape, dtype=np.int64)
for k in bomb:
    i, j = k
    n[max(0,i-1), max(0,j-1)] += 1
    try: n[i+2, max(0,j-1)] -= 1
    except IndexError: pass
    try: n[max(0,i-1), j+2] -= 1
    except IndexError: pass
    try: n[i+2, j+2] += 1
    except IndexError: pass
n = np.cumsum(np.cumsum(n,axis=0), axis=1)
ans = np.where(s == '#' , '#', n)
for row in ans:
    print(*row, sep='')

Measured memory_bytes: 12916
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 1);
		String str;
		try {
			str = br.readLine();
			System.out.println("ABC" + str);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}


Measured memory_bytes: 22868