akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <limits>
#include <map>
#include <bitset>
#include <iomanip>

#define rep(i,n) for(int (i) = 0; (i)<(n); (i)++)
#define FOR(i,s,e) for(int (i) = (s); (i)<(e); (i)++)
#define vecall(itr,vec) for(auto (itr) = (vec).begin(); (itr) != (vec).end(); (itr)++)
#define vecshow(vec) for(auto itr = (vec).begin(); itr != (vec).end(); itr++)cout << *itr << " ";

using namespace std;
using p = pair<int, int>;
using ll = long long;

int gcd(int a, int b) {
	int l = max(a, b);
	int s = min(a, b);
	while (l * s != 0) {
		int tmp = s;
		s = l % s;
		l = tmp;
	}

	return l;
}

vector<vector<int>> path;

int main() {
	int x, n;
	cin >> x >> n;
	if (n == 0) {
		cout << x << endl;
		return 0;
	}
	vector<int> p(n);
	rep(i, n)cin >> p[i];

	sort(p.begin(), p.end());
	//vecshow(p);

	int idx = 0;
	int min = 101;
	int min_i = 0;
	for (int i = p[0] - 1; i <= p[n - 1] + 1; i++) {
		if (p[idx] == i) {
			if(idx != n - 1)idx++;
			continue;
		}
		int tmp = abs(x - i);
		if (tmp < min) {
			min_i = i;
			min = tmp;
		}
	}

	cout << min_i << endl;

	return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <string.h>

int main(){
  int l, i, r;
  char n[1024];
  while(scanf("%s", n) && n[0] != '0'){
    l = strlen(n);
    for(r = i = 0; i < l; i++) r += n[i];
    printf("%d\n", r - l * '0');
  }
  return 0;
}



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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    int n; cin >> n;

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

    if (n % 2 == 0) {
        //偶数
        for (int i = n-1; i >= 0; i -= 2) {
            cout << a[i] << ' ';
        }

        for (int i = 0; i <= n-2; i += 2) {
            if (i != n-2) {
                cout << a[i] << ' ';
            } else {
                cout << a[i];
            }
        }
    } else {
        //奇数
        for (int i = n-1; i >= 0; i -= 2) {
            cout << a[i] << ' ';
        }

        for (int i = 1; i <= n-2; i += 2) {
            if (i != n-2) {
                cout << a[i] << ' ';
            } else {
                cout << a[i];
            }
        }
    }
}

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

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


vector<llong> get_divisors(llong n) {
    vector<llong> res;
    for(llong i = 1; i * i <= n; ++i)
        if(n % i == 0) {
            res.push_back(i);
            if(i != n / i) res.push_back(n / i);
        }
    return res;
}

llong N;
int main(int argc, char **argv) {
    cin >> N;
    vector<llong> divisors = get_divisors(N);

    llong res = __INT64_MAX__;
    for(int i = 0; i < divisors.size(); ++i) {
        res = min(res, divisors[i] + (N / divisors[i]) - 2);
    }

    cout << res << endl;
}

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

int h[20];
int main() {
	int n, w;
	while (scanf("%d%d", &n, &w), n) {
		memset(h, 0, sizeof(h));
		rep(i, n) {
			int v; scanf("%d", &v);
			h[v / w]++;
		}
		int j = 0;
		rep(i, 20) {
			if (h[i])j = i + 1;
		}
		double dark = 1, d = 1. / (j - 1), sum = 0;
		double k = (double)*max_element(h, h + 20);
		for (int i = 0; i < j; i++) {
			sum += dark*h[i] / k;
			dark -= d;
		}
		printf("%.8lf\n", sum + 0.01);
	}
}

Measured memory_bytes: 3208
d = int(input())
c = list(map(int,input().split()))
s = []
day = [0 for i in range(26)]
for i in range(d):
    s.append(list(map(int,input().split())))
ans = 0
num = 1
for i in s:
    max_index = -1
    large = 0
    for j in range(26):
        if large < i[j]:
            large = i[j]
            if not max_index == -1:
                ans -= c[max_index]*(num-day[max_index])
            max_index = j
        else:
            ans -= c[j]*(num-day[j])
    day[max_index] = num
    ans += large
    print(max_index+1)
    num += 1

Measured memory_bytes: 9208
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s,t; cin>>s>>t;
    vector<string> l;
    for(int i=0; i<s.length(); ++i)
    {
            int j = 0;
            int k = i;
            int old = i;
            while((s[k] == t[j] || s[k] == '?') && (k < s.length() && j<t.length()))
            {
                k++;
                j++;
            }
            if(j == t.length())
            {
                string m = s;
                int ii = 0;
                for(int i=old; ii<t.length(); ++i)
                {
                    m[i] = t[ii];
                    ii++;
                }
                for(int i=0; i<m.length(); ++i)
                {
                    if(m[i] == '?')
                        m[i] = 'a';
                }
                l.emplace_back(m);
            }
    }
    if(l.size() == 0)
        cout<<"UNRESTORABLE"<<endl;
    else
    {
        cout<<*min_element(l.begin(),l.end())<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
N, Q = map(int, input().split())
S = input()
s = S[:2]
ans = 'AC'
lst = [0]
count = 0
for i in range(N-1):
    s = S[i] + S[i + 1]
    count += (s == ans)
    lst.append(count)

for _ in range(Q):
    a, b = map(int, input().split())
    print(lst[b - 1] - lst[a - 1])


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

int a[3],b[3],c[3][3];
int main(){
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < 3; j++){
			cin >> c[i][j];
		}
	}

	a[0] = 0;
	b[0] = c[0][0] - a[0];
	b[1] = c[0][1] - a[0];
	b[2] = c[0][2] - a[0];
	a[1] = c[1][0] - b[0];
	a[2] = c[2][0] - b[0];

	for(int i = 0; i < 3; i++){
		for(int j = 0; j < 3; j++){
			if(c[i][j] != a[i] + b[j]){
				cout << "No" << endl;
				return 0;
			}
		}
	}

	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100000;

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

int main() {
	int n;
	cin >> n;
	int a[N];
	rep(i, n) cin >> a[i];
	ll ans = a[0];
	rep(i, n-1) ans = gcd(ans, a[i+1]);
	cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

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

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

std::vector<i64> a;
std::vector<std::vector<i64>> dp;
i64 solve(i64 L, i64 R) {
	if(dp[L][R]) return dp[L][R];
	if(L >= R) return 0LL;
	if(L + 1 == R) return a[L];
	
	i64 A = 0, B = 0, ret = 1LL << 60;
	for(int i = L; i < R; i++) A += a[i];
	for(int i = L; i < R - 1; i++) {
		B += a[i]; A -= a[i];
		
		ret = std::min(ret, solve(L, i + 1) + solve(i + 1, R) + (A + B));
	}
	return dp[L][R] = ret;
}

int main() {
	int n; scanf("%d", &n); a.resize(n);
	for(int i = 0; i < n; i++) scanf("%lld", &a[i]);
	
	dp = make_v<i64>(n + 1, n + 1);
	solve(0, n);
	
	for(auto v: a) dp[0][n] -= v;
	printf("%lld\n", dp[0][n]);
	return 0;
}
 


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ll = long long;
constexpr i64 INF = 1010000000000000017LL;
constexpr i64 MOD = 1000000007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x; 
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x; 
        return true;
    }
    return false;
}
template<typename Val>
bool bitcheck(Val bit, size_t idx) {
    return bit & (1 << idx);
}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr); ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH) cout << unitbuf;
    }
} PROCON_INIT;

void solve() {
    int n; cin >> n;
    int a, w, t, r;
    a = 0;
    w = 0;
    t = 0;
    r = 0;
    FOR(i, 0, n) {
        string str; cin >> str;

        if (str == "AC") ++a;
        else if (str == "WA") ++w;
        else if (str == "TLE") ++t;
        else ++r;
    }

    cout << "AC x " << a << endl;
    cout << "WA x " << w << endl;
    cout << "TLE x " << t << endl;
    cout << "RE x " << r << endl;
}

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

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define prArr(Arr,n) for(int _=0;_<n;_++)   cout<<(Arr)[_]<<" ";
using namespace std;
const long long INF=(long long)0x3f3f3f3f3f3f3f3f;
const int MOD=(int)1e9+7;

int main()
{
    /*ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);*/
    //freopen("output.txt","w+",stdout);
    //freopen("input.txt","r+",stdin);
    int n,tmp,ans=0;
    cin>>n;
    while(n--&&cin>>tmp)
        while((tmp&1)==0)
            ans++,tmp>>=1;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3616
S = input()
Q = int(input())

dir_changed = False
hd, ta = [], []

for _ in range(Q):
  A = list(input().split())
  if A == ["1"]:
    dir_changed = not dir_changed
    hd, ta = ta, hd
    continue
  F, C = int(A[1]), A[2]
  #if dir_changed:
  #  F = 3-F
  if F == 1:
    hd.append(C)
  else:
    ta.append(C)
    
if dir_changed:
  S = S[::-1]
print("".join(hd[::-1]) + S + "".join(ta))

Measured memory_bytes: 6216
#include<stdio.h>
#include<string.h>
int main(void){
    int n;
    char s[10001];
    scanf("%d%s",&n,s);
    for(int i=0;strlen(s)>i;++i){
        s[i]+=n;
        if(s[i]>90)
        s[i]-=26;
    }
    for(int i=0;strlen(s)>i;++i)
    printf("%c",s[i]);
    return 0;
}

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

int calc_digit_sum(int n) {
  int sum = 0;
  while ( n ) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  int N;
  cin >> N;
  int sum = calc_digit_sum(N);
  cout << ( N % sum ? "No" : "Yes") << endl;
}

Measured memory_bytes: 256
N=int(input())
def function(a,b):
    return max(len(str(a)), len(str(b)))
mini=len(str(N))
lim=len(str(int(N**(0.5))))
for i in range(2,int(N**(0.5)+1)):
    if mini==lim:
        break
    if N%i==0:
        if mini>function(i,N//i):
            mini=function(i,N//i)
print(mini)


Measured memory_bytes: 3188
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
idx_B = M-1
m = sum(B)
an = M
ans = 0
for a in [0] + A:
    m += a
    while idx_B >= 0 and m > K:
        m -= B[idx_B]
        idx_B -= 1
        an -= 1
    if m > K:
        break
    if an > ans:
        ans = an
    an += 1
print(ans)


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




typedef long long int ll;
int main()
{
    ll n,k,a[100005],b[100005];
    cin>>n>>k;
    for(ll i=1; i<=n; i++)
    {
        cin>>a[i];
        b[i] = INT_MAX;
    }
    b[1] = 0;
    for(ll i=1; i<n; i++)
    {
        for(ll j=1; j<=k; j++)
            if(i+j-1<n)
                b[i+j] = min(b[i+j],b[i]+abs(a[i]-a[i+j]));
    }
    cout<<b[n]<<endl;



}



Measured memory_bytes: 1792
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 1e6+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    ll g = 0;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    rep(i,0,n)g = gcd(g, a[i]);
    if(g != 1){
        cout << "not coprime" << endl;
        return 0;
    }
    vector<ll> used(n_max);
    rep(i,0,n){
        for(int j = 2; j * j <= a[i]; j++){
            if(a[i] % j != 0)continue;
            if(used[j]){
                cout << "setwise coprime" <<endl;
                return 0;
            }
            while(a[i] % j == 0)a[i] /= j;
            used[j] = 1;
        }
        debug(a[i]);
        if(a[i] != 1 && used[a[i]]){
            cout << "setwise coprime" << endl;
            return 0;
        }
        used[a[i]] = 1;
    }

    cout << "pairwise coprime" << endl;
}

Measured memory_bytes: 18684
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

#define NUM_MAX 500000
#define INF (int64_t)(1e+10)
static int64_t ans[NUM_MAX];
static int aidx = 0;
void traverse(int64_t num) {
    int i;
    if(num >= INF) return;
    ans[aidx++] = num;
    for(i = 0; i <= 9; i++) {
        int64_t new = num*10+i;
        if(labs(num%10-i) <= 1) {
            traverse(new);
        }
    }
    return;
}

int asc(const void *a1, const void *a2) {
    int64_t aa1 = *(int64_t*)a1;
    int64_t aa2 = *(int64_t*)a2;
    return (aa1>aa2)*2-1;
}

int main(void) {
    int k = get_int();
    int i;
    for(i = 1; i <= 9; i++) {
        traverse(i);
    }
    qsort(ans, aidx, sizeof(int64_t), asc);
    printf("%lld\n", ans[k-1]);
    return 0;
}


Measured memory_bytes: 4156
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    long[] arrayA = new long[N + 1];
    long result = 0;
    for (int i = 0; i < N + 1; i++) {
      arrayA[i] = scan.nextLong();
    }
    for (int i = 0; i < N; i++) {
      long tmp = scan.nextLong();

      if (tmp >= arrayA[i]) {
        result += arrayA[i];
        tmp -= arrayA[i];
      } else {
        result += tmp;
        continue;
      }
      if (tmp >= arrayA[i + 1]) {
        result += arrayA[i + 1];
        arrayA[i + 1] = 0;
      } else {
        result += tmp;
        arrayA[i + 1] -= tmp;
      }

    }

    System.out.println(result);
  }

}


Measured memory_bytes: 87136
/* include file*/
#include <functional>
#include <vector>
using namespace std;

template <class Monoid>
struct Segment
{
    using Func = function<Monoid(Monoid,Monoid )>;

    vector<Monoid> node;
    Monoid ide;
    int n = 1;

    Func bin_f;
    Func update_f;

    Segment(const vector<Monoid> &init, Monoid ide_, Func f_,Func u_f) : bin_f(f_),ide(ide_),update_f(u_f)
    {
        int sz = init.size();
        while (n < sz)
            n *= 2;
        node.assign(n * 2 - 1, ide);
        for (int i = 0; i < sz; i++)
            node[i + n - 1] = init[i];
        for (int i = n - 2; i >= 0; i--)
            node[i] = bin_f(node[i * 2 + 1], node[i * 2 + 2]);
    }

    void update(int i, Monoid x)
    {
        i += n - 1;
        node[i] = update_f(node[i],x);
        while (i)
        {
            i = (i - 1) / 2;
            node[i] = bin_f(node[i * 2 + 1], node[i * 2 + 2]);
        }
    }

    Monoid get_inter(int a, int b, int k = 0, int l = 0, int r = -1)
    {
        if (r < 0)
            r = n;
        if (a <= l && r <= b)
            return node[k];
        if (r <= a || b <= l)
            return ide;

        Monoid lm = get_inter(a, b, k * 2 + 1, l, (l + r) / 2);
        Monoid rm = get_inter(a, b, k * 2 + 2, (l + r) / 2, r);
        return bin_f(lm, rm);
    }
};

// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2730414#1

#include <iostream>

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

    typedef long long i64;

    Segment<i64> seg(vector<i64>(n + 1, (1LL << 31) - 1), (1LL << 31) - 1,
                     [](i64 a,i64 b) {
                         return min(a,b);
                     },
                     [](i64 a,i64 b){
                         return b;
                     });
   for(int i = 0;i < q;i++)
   {
       int query;
       cin >> query;
       if(query == 0)
       {
           int x,y;
           cin >> x >> y;
           seg.update(x,y);
       }
       else
       {
           int x,y;
           cin >> x >> y;
           cout << seg.get_inter(x,y + 1) << endl;
       }
   } 
}


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

#define x first
#define y second

const int64_t inf = 4e18 + 11;

signed main () {
    int n, k;
    cin >> n >> k;
    vector < pair < int, int > > p(n);
    vector < int > f(n), s(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i].x >> p[i].y;
        f[i] = p[i].x;
        s[i] = p[i].y;
    }
    int64_t ans = inf;
    for (int i = 0; i < n - 1; ++i) {
        for (int j = 0; j < n - 1; ++j) {
            for (int v = i + 1; v < n; ++v) {
                for (int c = j + 1; c < n; ++c) {
                    int cnt = 0;
                    int l = min(f[i], f[v]), r = max(f[i], f[v]);
                    int d = min(s[j], s[c]), u = max(s[j], s[c]);
                    for (int w = 0; w < n; ++w) {
                        if (p[w].x >= l && p[w].x <= r && p[w].y >= d && p[w].y <= u)
                            ++cnt;
                    }
                    if (cnt >= k)
                        ans = min(ans, int64_t(r - l) * int64_t(u - d));
                }
            }
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
def walk_and_teleport(N: int, A: int, B: int, X: list)->int:
    pos = X[0]
    cost = 0

    for x in X[1:]:
        cost += min(A * (x - pos), B)
        pos = x

    return cost


if __name__ == "__main__":
    N, A, B = map(int, input().split())
    X = [int(s) for s in input().split()]
    ans = walk_and_teleport(N, A, B, X)
    print(ans)


Measured memory_bytes: 14480
// AOJ 2768 Scanner
// 2018.4.18 bal4u

#include <stdio.h>

// バッファを経ずstdinから数値を得る
//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

int  T[52];
char dp[52][1002][1002];

int main()
{
	int N, s, i, j, k, ans;

	N = in();
	s = 0; for (i = 0; i < N; i++) s += T[i] = in();

    dp[0][0][0] = 1;
	for (i = 0; i < N; i++) for (j = 0; j < 1000; j++) for (k = 0; k < 1000; k++) {
		if (!dp[i][j][k]) continue;
		if (j+T[i] < 1000) dp[i+1][j+T[i]][k] = 1;
        if (k+T[i] < 1000) dp[i+1][j][k+T[i]] = 1;
		dp[i+1][j][k] = 1;
    }

	ans = 0x10101010;
    for (i = 0; i < 1000; i++) for (j = 0; j < 1000; j++) {
		if (dp[N][i][j]) {
			k = i; if (k < j) k = j;
			if (k < s-i-j) k = s-i-j;
			if (k < ans) ans = k;
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 34168
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<iomanip>
#include<queue>
#include<numeric>
typedef long long LL;

using namespace std;

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}


int main(void) {
	int n, h, w;
	cin >> n >> h >> w;
	cout << (n - h + 1)*(n - w + 1);
	return 0;
}

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

int main()
{
	int d, n, m, temp;
	while (cin >> d){
		if (!d) return 0;
        scanf("%d%d", &n, &m);
        int sum = 0;
        vector<int> shop;
        shop.push_back(0);
        shop.push_back(d);
		for (int i = 1; i < n; ++i){
			scanf("%d", &temp);
			shop.push_back(temp);
		}
		sort(shop.begin(), shop.end());
		while (m--){
			scanf("%d", &temp);
			vector<int>::iterator maxi = upper_bound(shop.begin(), shop.end(), temp);
			sum += min(*maxi - temp, temp - *(maxi - 1));
		}
		printf("%d\n", sum);
	}
}


Measured memory_bytes: 3584
a, b = input().split()
a = int(a)
b0, b12 = b.split(".")
b1 = b12[0]
b2 = b12[1]
b0 = int(b0)
b1 = int(b1)
b2 = int(b2)

ans0 = a * b0
ans1 = str(a * b1)
ans2 = str(a * b2)
if len(ans1) > 1:
    ans1i = int(ans1[:-1])
else:
    ans1i = 0
if len(ans2) > 2:
    ans2i = int(ans2[:-2])
else:
    ans2i = 0

ans1f=int(ans1)%10
ans2f=int(ans2)%100

if ans1f*10+ans2f>=100:
    ans12i=1
else:
    ans12i=0

# print(int(str(a*b1)[:-1]))
# print(int(str(a*b2)[:-2]))

print(ans0 + ans1i + ans2i+ans12i)

Measured memory_bytes: 61972
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <tuple>
using namespace std;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
typedef long long ll;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

ll sum[5010][5010];
bool used[5010];
ll sizet[5010];

int main ()
{
    ll N,K;
    cin >> N >> K;
    vector<ll> P(N),C(N);
    REP(i,N) cin >> P[i];
    REP(i,N) cin >> C[i];
    REP(i,N) P[i]--;

    REP(i,N){
        ll sumt = 0;
        ll idx = i;
        fill(used, used + 5010, false);
        REP(j,N + 1) {
            idx = P[idx];
            if (used[idx]) {
                sizet[i] = j;
                break;
            }
            used[idx] = true;
            sumt += C[idx];
            sum[i][j + 1] = sumt;
        }
    }

    ll ans = -3e18;
    REP(i,N) {
        ll anst = 0;
        ll Kt = K;
        if (Kt > sizet[i]) {
            ll t = Kt / sizet[i];
            Kt -= t * sizet[i];
            if (Kt == 0) {
                t--;
                Kt = sizet[i];
            }
            if (sum[i][sizet[i]] >= 0) {
                anst += t * sum[i][sizet[i]];
                ans = max(ans, anst);
            }
            REP(j,sizet[i]) {
                ans = max(ans, sum[i][j + 1]);
            }
        }
        REP(j,Kt) {
            ll anstt = anst + sum[i][j + 1];
            if (ans < anstt) {
                ans = anstt;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


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

public class Main {

	public static void main(String[] args) {
		//		new Main().solveA();
		//		new Main().solveB();
		new Main().solveC();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;
		String line = "";

		try {
			scanner = new Scanner(System.in);
			line = scanner.next();

			System.out.println(line.replaceAll("2017", "2018"));

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int n = 0;

		try {
			scanner = new Scanner(System.in);
			n = scanner.nextInt();
			int[] wk = new int[n];

			for (int i = 0; i < n; i++) {
				wk[i] = scanner.nextInt();
			}

			Arrays.sort(wk);

			int res = 0;
			for (int i = 0; i < wk.length; i++) {
				if (i == 0) {
					res++;
				} else if (wk[i] != wk[i - 1]) {
					res++;
				}

			}

			System.out.println(res);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveC() {
		Scanner scanner = null;
		int n = 0;
		int y = 0;

		try {
			scanner = new Scanner(System.in);
			n = scanner.nextInt();
			y = scanner.nextInt();

			for (int i = n; i >= 0; i--) {
				if (i * 10000 > y) {
					continue;
				}
				for (int j = 0; j <= n - i; j++) {
					int k = n - i - j;
					if (n == i + j + k && i * 10000 + j * 5000 + k * 1000 == y) {
						System.out.println(i + " " + j + " " + k);
						return;
					}
				}
			}

			System.out.println(-1 + " " + -1 + " " + -1);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int lineAB = 0;
		int lineBC = 0;
		int lineCA = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

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

class Procon {
    static void Main (string[] agrs) {
        int H = Int ();
        int W = Int ();

        bool[, ] A = new bool[H + 1, W + 1];

        for (int i = 1; i <= H; i++) {
            var tmp = String ();
            for (int j = 1; j <= W; j++) {
                if (tmp[j - 1] == '.') {
                    A[i, j] = false;
                } else {
                    A[i, j] = true;
                }
            }
        }

        int[, ] DP = new int[H + 1, W + 1];

        DP[0, 1] = 1;
        for (int i = 1; i <= H; i++) {
            for (int j = 1; j <= W; j++) {
                if (A[i, j] == false) {
                    DP[i, j] = (DP[i - 1, j] + DP[i, j - 1]) % M;
                }
            }
        }

        Console.WriteLine (DP[H, W]);
    }

    static string String () => Scanner.nextString ();
    static int Int () => int.Parse (Scanner.nextString ());
    static long Long () => long.Parse (Scanner.nextString ());
    static double Double () => double.Parse (Scanner.nextString ());
    static char[] Chars () => String ().ToCharArray ();
    static string[] Strings () => Console.ReadLine ().Split (' ');
    static int[] Ints () => Strings ().Select (v => int.Parse (v)).ToArray ();
    static long[] Longs () => Strings ().Select (v => long.Parse (v)).ToArray ();
    static double[] Doubles () => Strings ().Select (v => double.Parse (v)).ToArray ();
    const int M = 1000000007;
}

class PriorityQueue<T> where T : IComparable<T> {
    public T[] heap;
    public int size;
    public int sign;
    public PriorityQueue (int N, bool descend = false) {
        heap = new T[N];
        sign = 1;
        if (descend) sign = -1;
    }
    public int Compare (T x, T y) {
        return x.CompareTo (y) * sign;
    }
    public void Push (T x) {
        int i = size++;
        while (i > 0) {
            int p = (i - 1) / 2;
            if (Compare (x, heap[p]) >= 0) {
                break;
            }
            heap[i] = heap[p];
            i = p;
        }
        heap[i] = x;
    }
    public T Pop () {
        T ret = heap[0];
        T x = heap[--size];
        int i = 0;
        while (i * 2 + 1 < size) {
            int a = i * 2 + 1;
            int b = i * 2 + 2;
            if (b < size && Compare (heap[a], heap[b]) > 0) {
                a = b;
            }
            if (Compare (heap[a], x) >= 0) {
                break;
            }
            heap[i] = heap[a];
            i = a;
        }
        heap[i] = x;
        return ret;
    }
    public int Count () {
        return size;
    }
}

class Scanner {
    static string[] s = new string[0];
    static int i = 0;
    static int max_i = 0;
    static public string nextString () {
        if (i >= s.Length) {
            s = Console.ReadLine ().Split (' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0) {
                return "";
            }
            return s[i++];
        }
        return s[i++];
    }
}

Measured memory_bytes: 19928
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int n;
    scan(n);
    auto a = readln.split.to!(int[]);
    int ans = a[0];
    foreach (i ; 1 .. n) {
        ans += max(0, a[i] - a[i-1]);
    }
    writeln(ans);
}





void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <iostream>
#include <map>
using namespace std;

int main(void){
    int a,b;
    cin >> a >> b;
    if(a==1)a+=13;
    if(b==1)b+=13;
    if(a==b){
        cout << "Draw" << endl;
        return 0;
    }
    string str=a>b?"Alice":"Bob";
    cout << str << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>
#include <cmath>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e6 * 2 + 10, INF = 1e9 * 1e9 + 10;



int main()
{
    fastInp;

    string s, t;
    cin >> s >> t;

    ll dif = INF;
    for (int i = t.size() - 1; i < s.size(); i++) {
        ll cur = 0;
        for (int j = 0; j < t.size(); j++) {
            if (s[i - j] != t[t.size() - 1 - j]) cur++;
        }
        
        dif = min(dif, cur);
    }

    cout << dif;
    
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
 
int main() {
  string S; cin >> S;
  string T;
  int Q; cin >> Q;
  while (Q--) {
    int type; cin >> type;
    if (type == 1) {
      swap(S, T);
    } else {
      int f; char c; cin >> f >> c;
      if (f == 1) {
        T.push_back(c);
      } else {
        S.push_back(c);
      }
    }
  }
  reverse(range(T));
  cout << T + S << endl;
}

Measured memory_bytes: 1248
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int dp[100001];
	dp[0]=0;
	fill(dp+1,dp+100001,100000);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=i;j*=6)
			dp[i]=min(dp[i],dp[i-j]+1);
		for(int j=1;j<=i;j*=9)
			dp[i]=min(dp[i],dp[i-j]+1);
	}
	cout<<dp[n]<<endl;
}


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

using namespace std;

const int a[40] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main() {
	int k; cin >> k;
	cout << a[k - 1] << endl;
	return 0;
}

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

int k;

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

Measured memory_bytes: 1792
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

bool comp(const vector<int>& i, const vector<int>& j) {
    return i[0] > j[0];
}

int main() {
    int N, Q;
    cin >> N >> Q;

    int S[N], T[N], X[N];
    for (int i = 0; i < N; i++) {
        scanf("%d %d %d", &S[i], &T[i], &X[i]);
    }
    int D[Q];
    for (int i = 0; i < Q; i++) {
        scanf("%d", &D[i]);
    }

    vector< vector<int> > eventList;

    for (int i = 0; i < N; i++) {
        vector<int> tempEvent(3);
        tempEvent[0] = S[i] - X[i];
        tempEvent[1] = 1;
        tempEvent[2] = X[i];
        eventList.push_back(tempEvent);
        vector<int> tempEvent2(3);
        tempEvent2[0] = T[i] - X[i];
        tempEvent2[1] = -1;
        tempEvent2[2] = X[i];
        eventList.push_back(tempEvent2);
    }

    sort(eventList.begin(), eventList.end(), comp);

    multiset<int> now_construction;

    for (int i = 0; i < Q; i++) {
        while (eventList.size() > 0 && eventList[eventList.size() - 1][0] <= D[i]) {
            if (eventList[eventList.size() - 1][1] > 0) {
                now_construction.insert(eventList[eventList.size() - 1][2]);
            }
            else {
                multiset<int>::iterator it = now_construction.find(eventList[eventList.size() - 1][2]);
                if (it != now_construction.end()) now_construction.erase(it);
            }
            eventList.pop_back();
        }
        cout << (now_construction.size() > 0 ? *now_construction.begin() : -1) << endl;
    }

    return 0;
}

Measured memory_bytes: 35880
def gcd(x, y):
    if x < y:
        x, y = y, x
        # x,y = y,x はswap(値の交換)を表す

    while y > 0:
        r = x % y
        x = y
        y = r
    return x


x, y = map(int, input().split())
print(gcd(x, y))


# ユークリッドの互除法により最大公約数: GreatestCommonDivisorを求める

# 以下のようなアルゴリズムはn回の割り算を行う必要があるため、大きな数に対しては時間内に出力を得ることはできない
# gcd(x, y)
#     n = min(x, y)
#     for d = n downto 1
#         if x と y がともに d で割り切れる
#             return d

# ユークリッドの互除法による最大公約数の判定
# gcd(x, y)
#     if x < y
#         swap(x, y)
#     while y > 0
#         r = x % y
#         x = y
#         y = r

#     return x

# ユークリッドの互除法
# a = bq + r
# 74 = 54*1+20
# 54 = 20*2+14
# 20 = 14*1+6
# 14 = 6*2+2
# 6 = 2*3+0


# 一行に複数入力
# >> > a, b = map(int, input().split())  # 標準入力を行う
# 33 66
# >> > print(a)
# 33
# >> > print(b)
# 66



Measured memory_bytes: 5596
N = int(input())
import math

ans = []
l = int(math.log2(N))
for i in range(1,l+1):
  if round(N**(1/i))**i==N:
    ans.append(round(N**(1/i)))

for i in range(2,round((N-1)**0.5)+1):
  if (N-1)%i == 0:
    ans.append(i)
    if (N-1)//i != i:
      ans.append((N-1)//i)
if N>2:
  ans.append(N-1)

for i in range(2,round(N**0.5)+1):
  if N%i == 0:
    n = N
    while n%i==0:
      n//=i
    if n != 1 and n%i==1:
      ans.append(i)

print(len(ans))

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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)

typedef long long ll;
using namespace std;
 
int main (){
  int n;
  cin >> n;

  int t[n];
  rep(i,0,n){
    cin >> t[i];
  }
  int m;
  cin >> m;
  int p[m],x[m];
  rep(i,0,m){
    cin >> p[i] >> x[i];
  }

  rep(i,0,m){
    int a = p[i]-1;
    int b = t[a];
    t[a] = x[i];
    int ans = 0;
    rep(j,0,n){
      ans += t[j];
    }
    pout(ans);
    t[a] = b;
  }
  return 0;
}

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

int main() {
	int a,b,an=0,d=0,m=0;
	cin>>a>>b;
	an=a+b;
	d=a*b;
	m=a-b;
	if(an>=d&&an>=m)
	cout<<an;
	else if(d>=an&&d>=m)
	cout<<d;
	else if(m>=d&&m>=an)
	cout<<m;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner num = new Scanner(System.in);
        while(true) {
            int n = num.nextInt();
            int m = num.nextInt();
            if (n == 0 && m == 0) break;
            for(int i = 1; i <= n; i++){
                for(int j = 1; j <= m; j++){
                    System.out.print("#");
                }
                System.out.printf("\n");
            }
            System.out.printf("\n");
        }
    }
}


Measured memory_bytes: 37764
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

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

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

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

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

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

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

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

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

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

fn main() {
    input!{
        a: String,
        b: String,
    }
    let num: f64 = format!("{}{}", &a, &b).parse().unwrap();
    if num.sqrt() as u64 * num.sqrt() as u64 == num as u64 {
        println!("Yes")
    } else {
        println!("No")
    }
}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;

int main() {
	
	int n,h,w;
	cin >> n >> h >> w;
	
	int res = 0;
	
	while(n--){
	    int a, b;
	    cin >> a >> b;
	    
	    res += a/h > b/w ? b/w : a/h;
	}
	
	cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    fio;
    int n,k,x,y;
    cin>>n>>k>>x>>y;
    if(n<=k)
    {
       cout<<n*x<<endl;
    }
    else
    {
       cout<<k*x + (n-k)*y<<endl;
    }
    return 0;
}



Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main(){
    int K,A,B;
    cin >> K >> A >> B;
    if(A <= B && A < K) {
        cout << -1 << endl;
    }
    else if(A <= B) {
        cout << 1 << endl;
    }
    else {
        if(A >= K) {
            cout << 1 << endl;
        }
        else {
            K-=A;
            cout << 1+2*((K+A-B-1)/(A-B)) << endl;
        }
    }
}


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

int cumulative_sum[501][501];

int main() {
    int n, m ,q;

    cin >> n >> m >> q;

    for(int i=0; i<m; i++){
        int l,r;
        cin >> l >> r;
        cumulative_sum[l][r] += 1;
    }

    /*
    for(int i=0; i<n+1; i++){
        for(int j=0; j<n+1; j++){
            cout << cumulative_sum[i][j] << " ";
        }
        cout << endl;
    }
    //*/

    for(int h=1; h<n+1; h++){
        for(int w=1; w<n+1; w++){
            cumulative_sum[h][w] += cumulative_sum[h][w-1];
        }
    }
/*
    for(int h=1; h<n+1; h++){
        for(int w=1; w<n+1; w++){
            cumulative_sum[h][w] += cumulative_sum[h-1][w];
        }
    }
//*/


    while(q--) {
        int ans = 0;
        int l,r;
        cin >> l >> r;
        for (int i = l; i<=r; i++){
            ans += cumulative_sum[i][r] - cumulative_sum[i][l-1];
        }
        cout << ans << endl;
    }

    /*
    for(int i=0; i<n+1; i++){
        for(int j=0; j<n+1; j++){
            cout << cumulative_sum[i][j] << " ";
        }
        cout << endl;
    }
    //*/


    return 0;
}

Measured memory_bytes: 1920
import java.util.*;

public class Main {
  public static void main(String[] args) {
    @SuppressWarnings("resource")
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int cnt = 0;

    for (int i = 0; i < n; i++) {
      cnt = isPrime(sc.nextInt()) ? cnt + 1 : cnt;
    }
    System.out.println(cnt);
  }

  static boolean isPrime(int x) {
    if (x == 2)
      return true;
    if (x < 2 || x % 2 == 0)
      return false;

    // 合成数xはp<=sqrt x を満たす素因子pを持つ
    int sqrt = (int) Math.sqrt((double) x);
    for (int i = 3; i <= sqrt; i = i + 2) {
      if (x % i == 0)
        return false;
    }
    return true;
  }
}



Measured memory_bytes: 41624
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define int long long
using namespace std;
const int MAX_N=100,MAX_W=100000;
int N,W;
vector<int> w,v;
int dp[MAX_N+1][MAX_W+1];

signed main(){
    cin>>N>>W;
    w.resize(N);v.resize(N);
    REP(i,N) cin>>w[i]>>v[i];
    for(int i=N-1;i>=0;--i){
        REP(j,W){
            if(j+w[i]<=W) dp[i][j]=max(dp[i+1][j+w[i]]+v[i],dp[i+1][j]);
            else dp[i][j]=dp[i+1][j];
        }
    }
    cout<<dp[0][0]<<endl;
}

Measured memory_bytes: 78336
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
vector<ll>vec;
int main() 
{
    ll a,b,n;
    ll x;
    cin>>a>>b>>n;
    if(n>=b)
    x=b-1;
    else
    x=n;
    ll ans=(a*x/b)-(a*(x/b));
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
//cout << fixed << setprecision(20) << *** << endl;
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;
int main()
{
	string s;
	ll base=0,ANS=0;
	cin>>s;
	rep(i,s.size()){
		if(s[i]=='W'){
			ANS=ANS+(i-base);
			base++;
		}
	}
	cout<<ANS<<endl;
}

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

int N, M, Q;
  vector<int> a,b,c,d;
  int ans;

void DFS(vector<int> A){
  //深さ優先探索
  //終了条件
  if(A.size()==N+1){
    int nowscore =0;
    for(int i=0;i<Q;i++){
      if(A[b[i]]-A[a[i]]==c[i]){
        nowscore +=d[i];
      }
    }
    ans = max(ans, nowscore);
    return;
  }
  A.push_back(A.back());
  while(A.back()<=M){
    DFS(A);
    A.back()++;
  }
    
}

int main(){
  cin >> N >> M >> Q;
  a=b=c=d=vector<int>(Q);
  for(int i=0;i<Q;i++){
    cin >> a[i] >> b[i] >> c[i] >> d[i];    
  }
  DFS(vector<int>(1,1));
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3188
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.Unboxed            as AU
import qualified Data.Array.ST                 as ST
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.Int
import qualified Data.IntMap                   as IM
import           Data.List
import qualified Data.Map                      as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Set                      as S
import           Data.Time
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
readInts n = replicateM n readInt
readString = map BS.unpack . BS.words <$> BS.getLine
readStrings n = replicateM n $ BS.unpack <$> BS.getLine
toPair [x, y] = (x, y)

main = do
  [n] <- readInt
  print $ ceiling $ fromIntegral n / 2



Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;
#define fori(i, a, b) for(int i = (int) a; i <= (int) b; ++i)
#define rofi(i, b, a) for(int i = (int) b; i >= (int) a; --i)
#define foreach(tt, a) for(auto &tt: a)
#define all(a) begin(a), end(a)
#define csz(a) (int) a.size()
#define pb push_back
#define epb emplace_back
#define mp make_pair
#define load(a, v) fill(begin(a), end(a), v)
#define load_mem(a, v) memset(a, v, sizeof(a));
#define iostream_optimize() ios::sync_with_stdio(false); cin.tie(0);
using ll = long long;
const ll MOD = 1e9+7, LINF = 1e16+1;
const int INF = 1e9+1;
const double EPS = 1e-10;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const ll P1 = 31, P2 = 37, M1 = 1e9+7, M2 = 1e9+9;

// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/* <<<<<<<<<<<<<<<<<<<<<<<<<<<< END TEMPLATE >>>>>>>>>>>>>>>>>>>>>>>>>>> */
const int N = 1e5+1;

int n, k, a[N];
int main() {
	iostream_optimize();
	cin >> n >> k;
	int pos;
	fori(i, 1, n) {
		cin >> a[i];
		if(a[i] == k) pos = i;
	}
	int ans = INF;
	fori(i, max(pos - k + 1, 1), min(pos + k - 1, n)) {
		ans = min((n - i + k - 2) / (k - 1) + (i - 1 + k - 2) / (k - 1), ans);
	}
	cout << ans;
}
// 1 2 3 4 5 6

Measured memory_bytes: 640
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for i in range(D)]
A = [0 for i in range(26)]
ans = 0
for i in range(D):
  t = int(input())
  A[t-1] = i+1
  c = 0
  for j in range(26):
    c += C[j] * (i+1-A[j])
  ans += S[i][t-1]-c
  print(ans)
  

Measured memory_bytes: 9316