akhauriyash/Code-Regression huggingface dataset:
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FAST         ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll           long long
#define ld           long double
#define pb           push_back
#define mp           make_pair
#define pii          pair<int,int>
#define mii          map<int,int>
#define vi           vector<int>
#define vll          vector<long long>
#define all(a)       (a).begin(),(a).end()
#define clz(a)       __builtin_clz(a) // count leading zeroes
#define ctz(a)       __builtin_ctz(a) // count trailing zeroes
#define popc(a)      __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define lul          1000000007
#define rep(i,a,b)   for(int i=a;i<b;i++)
#define rfor(i,a,b)  for(int i=a; i>=b; i--)
#define SIZE         1000005
#define F            first
#define S            second
#define mod          998244353

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " = " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " = " << arg1<<" |";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define endl         '\n'
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k)
// find_by_order(k)
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;

void solve()
{
     string ans = "AKIHABARA";
     unordered_map<string,int> ma;
     ma[ans]=1;
     queue<string> q;
     q.push(ans);
     while(!q.empty())
     {
        string t = q.front();
        q.pop();
        for(int i=0; i<(int)t.size(); i++)
        {
            if(t[i] == 'A')
            {
                string temp = t.substr(0,i)+t.substr(i+1,(int)t.size()-i-1);
                if(ma.count(temp) == 0)
                {
                    ma[temp]=1;
                    q.push(temp);
                }
            }
        }
     }
     string s; cin>>s;
     if(ma.count(s)) cout<<"YES";
     else cout<<"NO"; 
}
int main()
{   
    FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1;
    while(t--){
       solve();
    }
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>

using namespace std;

#define N_MAX 200000
#define MOD 1000000007

typedef long long int lli;


void solv()
{
	int N; scanf("%d", &N);
	int a[N_MAX];
	for (int i = 0; i < N; i++){
		scanf("%d", a + i);
	}

	int cur = 1, ret = 0;
	for (int i = 0; i < N; i++){
		if (cur == a[i]){
			cur++;
		}
		else{
			ret++;
		}
	}

	if (N == ret){
		ret = -1;
	}
	printf("%d", ret);
	return;
}

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	solv();

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define f first
#define s second
#define int long long
int a[114514];
set<int>st;
signed main(){
	ic(n)
	int sum=0;
	rep(0,i,n)cin>>a[i];
	rep(0,i,n){
		if(st.find(a[i])!=st.end()){
			sum++;
		}
		st.insert(a[i]);
	}		
	c(n-sum)
}	
	


Measured memory_bytes: 8540
# 2019は10と互いに素なので、
# N%2019と(N*(10**正整数))%2019は一致する
# pppppxxxxxxxを2019で割った余りとxxxxxxxを2019で割った余りが一致すれば、
# pppppは2019で割り切れることが言える

S = input()
from collections import defaultdict
amari = defaultdict(int)
cur = 0 # 今の数値
keta = 1 # 今の桁数
for i in range(len(S)-1,-1,-1):
  cur += int(S[i]) * keta
  cur %= 2019
  keta *= 10
  keta %= 2019
  amari[cur] += 1

ans = 0
if 0 in amari:
  ans += amari[0]
for n in amari.values():
  ans += (n * (n-1)) // 2
  
print(ans)

Measured memory_bytes: 9596
import math
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
count = 0

for i in range(N):
    r1 = X[i]
    for j in range(N-1, -1, -1):
        if i == j:
            break
        r2 = X[j]
        ls = [(r1[j] - r2[j])**2 for j in range(D)]
        res = math.sqrt(sum(ls))
        if res % 1 == 0:
            count += 1

print(count)

Measured memory_bytes: 3064
#include<iostream>
int main(){
	int n,a[10000];
	int na = -1000001,nb = 1000001;
	long long sum = 0;
	std::cin>>n;
	for(int i = 0; i < n; ++i){
		std::cin>>a[i];
		if(na < a[i])
			na = a[i];
		if(nb > a[i])
			nb = a[i];
		sum += a[i];
	}
	std::cout<<nb<<" "<<na<<" "<<sum<<std::endl;
	return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
int n;
int a[200000];
int twoTimes[100001];
ll fuct_i[200001];
ll fact[200001];
#define MOD 1000000007

// Extended Euclidean algorithm
int xGCD(int a, int b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }

    ll x1, y1, gcd = xGCD(b, a % b, x1, y1);
    x = y1;
    y = x1 - (long long)(a / b) * y1;
    return gcd;
}


// multiply a and b modulo MOD
int modmult(int a, int b) {
    return ((long long)a * b) % MOD;
}

// inverse of a modulo MOD
int inverse(int a) {
    ll x, y;
    xGCD(a, MOD, x, y);
    return x % MOD;
}

// binomial coefficient nCk modulo MOD
int bc(int n, int k)
{
    if(k > n)
        return 0;
    return modmult(modmult(fact[n], inverse(fact[k])), inverse(fact[n - k]));
}

long long int p(long long int n, int e) {
	if (e == 0)
		return 1;
	else if (e % 2 == 0)
		return p((n * n) % MOD, e / 2);
	else
		return (n * p(n, e - 1)) % MOD;
}

long long int nCr(int n, int r) { return r > n ? 0 : fact[n] * fuct_i[r] % MOD * fuct_i[n - r] % MOD; }
int main()
{
    scanf("%d" , &n);
    int firstPos , secondPos;
    for(int i = 0; i < n + 1; i++)
    {
        scanf("%d" , &a[i]);
        if(!twoTimes[a[i]])
            twoTimes[a[i]] = i + 1;
        else
        {
            firstPos = twoTimes[a[i]] - 1;
            secondPos = i;
        }
    }
    //cout << "eeee" << endl;
    //secondPos = n - secondPos;
    fact[0] = 1;
    for(int i = 1; i <= 200000; i++)
    {
        fact[i] = (fact[i - 1] * i) % MOD;
    }
    fuct_i[n + 1] = p(fact[n + 1], MOD - 2);	// フェルマーの小定理
	for (int i = n; i >= 0; i--)
        fuct_i[i] = fuct_i[i + 1] * (i + 1) % MOD;
    ll res = 0;
    int d = secondPos - firstPos;
    //printf("%d %d\n" , firstPos , secondPos);
    printf("%d\n" , n);
    for(int i = 2; i <= n + 1; i++)
    {
        res = (nCr(n + 1, i) - nCr(n - d , i - 1) + MOD) % MOD;
        printf("%d\n" , (int)res);
    }
    return 0;
}


Measured memory_bytes: 5248
from collections import deque

n = int(input())
a = deque(map(int, input().split()))
b = deque()

if n % 2 == 1:
    for i in range(n):
        if i % 2 == 0:
            b.appendleft(a.popleft())
        else:
            b.append(a.popleft())
else:
    for i in range(n):
        if i % 2 == 0:
            b.append(a.popleft())
        else:
            b.appendleft(a.popleft())

print(*b)

Measured memory_bytes: 25540
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
const int ININF = 1000000;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
int main() {
    int H, W, D;
    cin >> H >> W >> D;
    vector<pair<int, int>> xy(H * W + 1);
    rep(i, 0, H) {
        rep(j, 0, W) {
            int a;
            cin >> a;
            xy[a] = make_pair(i, j);
        }
    }
    vector<int> dp(H * W + 1);
    rep(i, 1, H * W + 1) {
        if(i <= D) {
            dp[i] = 0;
        } else {
            dp[i] = dp[i - D] + abs(xy[i].first - xy[i - D].first) +
                    abs(xy[i].second - xy[i - D].second);
        }
    }
    int Q;
    cin >> Q;
    rep(i, 0, Q) {
        int l, r;
        cin >> l >> r;
        cout << dp[r] - dp[l] << endl;
    }
}


Measured memory_bytes: 2176
N = int(input())
A = sorted(list(map(int, input().split())))

ans_n = A.pop()
target = ans_n / 2

ans_r = - 1
high_score = 0
for r in A:
    min_r = min(ans_n - r, r)
    if min_r >= high_score:
        high_score = r
        ans_r = r

print(ans_n, ans_r)


Measured memory_bytes: 14060
#include <stdio.h>

int main(){
  int n,k,count=0;
  int data[10000000];
  scanf("%d %d",&n,&k);
  
  for(int i=0;i<n;i++){
    scanf("%d",&data[i]);
  }
  for(int i=0;i<n;i++){
    if(data[i]>=k){
      count++;
    }
  }
  printf("%d",count);
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
constexpr int INF = 1000000000;

int dp[2][2][60][60][120];

int pt(const vector<int> &a, const vector<int> &b, int p, int i, int j, int h) {
  int sum = 0;
  bool addp = true;
  bool addo = true;
  REP(k,h) {
    if((k%2) == 0) {
      if (p) {
        if (a[i-1-k/2] == -1) addp = false;
      } else {
        if (b[j-1-k/2] == -1) addp = false;
      }
      if (addo) {
        if (p) {
          sum -= max(0, a[i-1-k/2]);
        } else {
          sum -= max(0, b[j-1-k/2]);
        }
      }
    } else {
      if (p) {
        if (b[j-1-k/2] == -1) addo = false;
      } else {
        if (a[i-1-k/2] == -1) addo = false;
      }
      if (addp) {
        if (p) {
          sum += max(0, b[j-1-k/2]);
        } else {
          sum += max(0, a[i-1-k/2]);
        }
      }
    }
  }
  return sum;
}

int solve(int p, int q, int i, int j, int h, const vector<int> &a, const vector<int> &b) {
  if (dp[p][q][i][j][h] != -INF) {
    return dp[p][q][i][j][h];
  }
  int pass, play = -INF+1;
  if (h) {
    pass = -solve(1-p, 0, i, j, 0, a, b) + pt(a, b, p, i, j, h);
  } else if (q == 0) {
    pass = -solve(1-p, 1, i, j, 0, a, b);
  } else {
    pass = 0;
  }
  if (p) {
    if (j < b.size()) {
      play = -solve(1-p, 0, i, j+1, h+1, a, b);
    }
  } else {
    if (i < a.size()) {
      play = -solve(1-p, 0, i+1, j, h+1, a, b);
    }
  }
  dp[p][q][i][j][h] = max(pass, play);
  return dp[p][q][i][j][h];
}

int main() {
  int n,m;
  cin>>n>>m;
  vector<int> a(n);
  REP(i,n) cin>>a[i];
  vector<int> b(m);
  REP(i,m) cin>>b[i];
  REP(p,2)REP(q,2)REP(i,n+1)REP(j,m+1)REP(h,n+m+1) dp[p][q][i][j][h] = -INF;
  int res = solve(0, 0, 0, 0, 0, a, b);
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 8784
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

public class Main {

  public static void main(String[] args) throws IOException {

    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
    Deque<Integer> trainStack = new ArrayDeque<>();

    while (input.ready()) {
      int num = Integer.parseInt(input.readLine());
      if (num == 0) {
        System.out.println(trainStack.poll());
      } else {
        trainStack.push(num);
      }
    }
  }
}

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

using namespace std;

int main() {
	string a, b, c;
	cin >> a >> b >> c;

	if (a[a.size() - 1] == b[0] && 
		b[b.size() - 1] == c[0])
		cout << "YES";
	else cout << "NO";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
long long int n,k,i,j;
long long int s=0;
  cin>>n>>k;
 long long int a[n];
  for(i=0;i<n;i++)
    cin>>a[i];
  if(k>=n)
    cout<<"0";
  else{
  sort(a,a+n);
  for(j=0;j<n-k;j++)
  	s=s+a[j];
  cout<<s;
  }
  return 0;
}

Measured memory_bytes: 1792
A = int(input())
B = int(input())
C = int(input())
X = int(input())

count = 0
for a in range(A + 1):
  for b in range(B + 1):
    for c in range(C + 1):
      if 500 * a + 100 * b + 50 * c == X:
        count += 1


print(count)

Measured memory_bytes: 3060
MOD = 10**9 + 7 

N = gets.to_i
S = gets.chomp

h = Hash.new

S.chars do |c|
  h[c].nil? ? h[c] = 1 : h[c] += 1
end

ans = 1
h.each do |k, v|
  # p [k, v]
  ans *= (v+1) 
  ans %= MOD
end

p ans-=1


Measured memory_bytes: 1916
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

ll N, D, A;
vector<pair<ll,ll>> XH;

bool isok(ll x, ll key){
  // code here
  if(XH[x].first <= key) return true;
  else return false;
}
ll binsch(ll key){
  // set value
  ll ng = N; ll ok = 0;
  while(abs(ok-ng)>1){
    ll mid = (ok+ng)/2;
    if(isok(mid, key)) ok = mid;
    else ng = mid;
  }
  return ok;
}

int main(){
  cin >> N >> D >> A;
  XH.resize(N);
  rep(i,N) cin >> XH[i].first >> XH[i].second;
  sort(all(XH));
  rep(i,N){
    XH[i].second = (XH[i].second+A-1)/A;
  }
  vector<ll> counter(N+1,0);
  ll ans = 0;
  rep(i,N){
    if(i!=0) counter[i] += counter[i-1];
    if(counter[i]<XH[i].second){
      ll add = XH[i].second-counter[i];
      ans += add;
      counter[i] += add;
      counter[min(N, binsch(XH[i].first+2*D)+1)] -= add;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4992
def main():
    n = int(input())
    x=[]
    for i in range(n):
        x.append(list((map(int,input().split()))))
    
    for i in range(1,n):
        for j in range(3):
            x[i][j]+=max(x[i-1][(j+1)%3],x[i-1][(j+2)%3]);
    
    print(max(x[n-1]))
if __name__ == "__main__":
    main()


Measured memory_bytes: 30260
#include<iostream>
using namespace std;
#define MAX 10000

int p(int i)
{
    return i/2;
}

int l(int i)
{
    return 2*i;
}

int r(int i)
{
    return 2*i+1;
}

int main()
{
    int H , i, A[MAX+1];
    cin >> H;
    for(i=1;i<=H;i++)
    {
        cin >> A[i];
    }
    for(i=1;i<=H;i++)
    {
        cout << "node " << i << ": key = "<<A[i]<<", ";
        if(p(i)>=1) cout << "parent key = " << A[p(i)] <<", ";
        if(l(i)<=H) cout << "left key = " << A[l(i)] << ", ";
        if(r(i)<=H) cout << "right key = " << A[r(i)] << ", ";
        cout << endl;
    }
}



Measured memory_bytes: 3108
#include <iostream>

 

using namespace std;

 

int main() 
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a <= b && b <= c)
        cout << a << " " << b << " " << c << endl;
    else if(a <= c && c <= b)
        cout << a << " " << c << " " << b << endl;
    else if(b <= a && a <= c)
        cout << b << " " << a << " " << c << endl;
    else if(b <= c && c <= a)
        cout << b << " " << c << " " << a << endl;
    else if(c <= a && a <= b)
        cout << c << " " << a << " " << b << endl;
    else if(c <= b && b <= a)
        cout << c << " " << b << " " << a << endl;
}


Measured memory_bytes: 3076
function main(input){
  input=input.trim();
  if(input=="A"){
    console.log("T");
  }else if(input=="C"){
    console.log("G");
  }else if(input=="G"){
    console.log("C");
  }else{
    console.log("A");
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
#define ll long long int
using namespace std;

ll check(ll n,vector<ll> v[],vector<ll> &dp,ll s)
{
    if(dp[s]!=-1)
        return dp[s];
    ll p=0;
    for(ll i=0;i<v[s].size();i++)
    {
        ll k=check(n,v,dp,v[s][i])+1;
        p=max(p,k);
    }
    dp[s]=p;
    return p;
}

int main()
{
    ll n,m;
    cin>>n>>m;
    vector<ll> v[n+1];
    for(ll i=0;i<m;i++)
    {
        ll x,y;
        cin>>x>>y;
        v[x].push_back(y);
    }
    vector<ll> dp(n+1,-1);
    for(ll i=1;i<=n;i++)
    {
        if(dp[i]==-1)
        {
            ll p=check(n,v,dp,i);
        }
    }
    ll ans=dp[1];
    for(ll i=2;i<=n;i++)
    {
        ans=max(ans,dp[i]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 9856
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int s = sc.nextInt();
	int e = sc.nextInt();
	int cnt = 0;
	for(int i = s; i<=e; i++) {
	    int rev = getRev(i);
	    if(i==rev) {
		cnt++;
	    }
	}
	System.out.println(cnt);
    }
    public static int getRev(int i) {
	int ic = 0;
	while(i>0) {
	    ic = ic*10+i%10;
	    i /= 10;
	}
	return ic;
    }
}

Measured memory_bytes: 21844
#include <cstdio>
#include <iostream>
using namespace std;
int N, K, idx;

int main()
{
    scanf("%d %d", &N, &K);
    for(int i = 0; i < N; i++)
    {
        int num;
        scanf("%d", &num);
    }
    int div, temp;
    div = (N - 1) / (K - 1);
    temp = (N - 1) % (K - 1);
    if(temp != 0)
    {
        temp = 1;
    }
    printf("%d", div + temp);
}

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

int selection_sort(vector<int> &A, int N) {
  int counter = 0;
  // i=0 の時
  //   i>=1 の要素について、i=0 の値より小さい値が複数存在する場合、その値の中で最も小さい値の要素番号をピックアップする。
  //   i=0 の値と i=minj の値を交換する。
  //   これで i=0 には、最も小さい値がセットされていることになる。
  //   つまり、i=0 はソート済みの部分列となる。
  for (int i = 0; i < N; i++) {
    int minj = i;
    for (int j = i; j < N; j++) {
      if (A.at(j) < A.at(minj)) {
        minj = j;
      }
    }

    // i=x の時、対象の要素が i>x より最も小さい値の場合、i=minj となる。
    // この場合は交換する必要がないので swap しない。
    if (minj != i) {
      swap(A.at(i), A.at(minj));
      counter++;
    }
  }

  return counter;
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  int counter = selection_sort(A, N);

  for (int i = 0; i < N; i++) {
    cout << A.at(i);
    if (i < N-1) {
      cout << " ";
    }
  }
  cout << endl;

  cout << counter << endl;
  return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;


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

  ll N;
  cin >>N;

  vector<ll> vec(N);

  for (ll i = 0; i < N; i++) {
    cin >>vec.at(i);
  }

  ll sum = 0;
  for (ll i = 0; i < N; i++) {
    sum+=vec.at(i);
  }
  ll ave;
  ave = sum / N;

  ll ans = 0;
  ll ans2 = 0;
  for (ll i = 0; i < N; i++)
  {
    ans += (vec.at(i) - ave) * (vec.at(i) - ave);
    ans2 += (vec.at(i) - (ave+1)) * (vec.at(i) - (ave+1));
  }
  cout << min(ans, ans2) << endl;
}

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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    int ans = max(
        10 * A + B + C,
        A + 10 * B + C
    );
    ans = max(ans, A + B + 10 * C);
    cout << ans << endl;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define LL long long

class UnionFind{
private:
  std::vector<int> par;
  std::vector<int> rnk;
public:
  UnionFind(int n):par(n),rnk(n){
    for(int i=0;i<n;i++){
      par[i]=i;
      rnk[i]=0;
    }
  }
  
  int find(int x){
    if(par[x] == x)
      return x;
    else
      return find(par[x]);
  }

  void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)
      return;
      
    if(rnk[x] < rnk[y])swap(x,y);
    par[y] = x;
    if(rnk[x]==rnk[y]) rnk[x]++;
  }

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



int n,m,k;
int a[100002],b[100002],c[100002],d[100002],ret[100000],top[100000];

int main(){
  cin>>n>>m>>k;
  UnionFind uf(n);
  REP(i,n)ret[i]=0;
  REP(i,m){
    cin>>a[i]>>b[i];
    a[i]--;
    b[i]--;
    ret[a[i]]--;
    ret[b[i]]--;
    uf.unite(a[i],b[i]);
  }
  REP(i,k){
    cin>>c[i]>>d[i];
    c[i]--;
    d[i]--;
  }
  REP(i,n)top[i]=0;

  

  REP(i,k){
    if(uf.same(c[i],d[i])){
      ret[c[i]]--;
      ret[d[i]]--;
    }
  }
  REP(i,n){
    top[uf.find(i)]++;
  }


  cout << ret[0]+top[uf.find(0)]-1;
  FOR(i,1,n)cout<<" "<<ret[i]+top[uf.find(i)]-1;
  cout<<endl;
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<ll> strong(3*N);
  for (ll &e : strong) {
    cin >> e;
  }
  
  sort(strong.begin(),strong.end());
  
  ll pow = 0;
  for (int i = N; i < 3*N; i += 2) {
    pow += strong[i];
  }
  
  cout << pow << endl;
}

Measured memory_bytes: 2560
program number_of_digits
  implicit none
  integer(8), parameter :: md = 1000000007_8, u = 100000000_8
  integer(8) :: s, ans = 0_8, tmp = 1_8, i, k
  integer(8) :: l = 1_8, r = 1_8, dl = 1_8, dr = 1_8, nxtl = 10_8, nxtr = 10_8
  read(*,*) s
  do while (l < u)
    do while (tmp < s)
      r = r+1_8
      if (r == nxtr) then
        dr = dr+1_8
        nxtr = nxtr*10_8
      end if
      tmp = tmp+dr
    end do
    if (tmp == s) ans = ans+1_8
    tmp = tmp-dl
    l = l+1_8
    if (l == nxtl) then
      dl = dl+1_8
      nxtl = nxtl*10_8
    end if
  end do
  do i = 1_8, s
    k = s/i
    if (k <= 8) exit
    if (mod(s,i) == 0_8) then
      ans = modulo(ans+9_8*pow(10_8,int(k-1_8))-i+1_8,md)
    else
      ans = mod(ans+1_8,md)
    end if
  end do
  write(*,'(i0)') ans
contains
  function pow(a,b) result(r)
    integer(8), intent(in) :: a
    integer, intent(in) :: b
    integer(8) :: r, p
    integer :: k
    r = 1_8
    p = a
    k = b
    do while (k > 0)
      if (btest(k,0)) r = mod(r*p,md)
      p = mod(p*p,md)
      k = rshift(k,1)
    end do
  end
end program number_of_digits

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
#define LL long long
#define MAXN 100000
#define MAXK 60
int n,len;LL L;
char s[MAXN+5];
int tr[MAXN+5][2],nd,pnt[MAXK+5];
int lowpos(LL x){
	int cnt=0;
    for(;!(x&1);cnt++,x>>=1);
    return cnt;
}
void Insert(){
	int p=0;
	for(int i=1;i<=len;i++){
		if(!tr[p][s[i]-'0'])tr[p][s[i]-'0']=++nd;
		p=tr[p][s[i]-'0'];
	}
}
void dfs(int x,int dep){
    for(int k=0;k<=1;k++)
	if(tr[x][k]==0) {if(L-dep>0)pnt[lowpos(L-dep)]^=1;}
	else dfs(tr[x][k],dep+1);
}
int main()
{
	scanf("%d%lld",&n,&L);
	for(int i=1;i<=n;i++){
		scanf("%s",s+1);
		len=strlen(s+1);
		Insert();
	}
	dfs(0,0);
	for(int i=0;i<=MAXK;i++)if(pnt[i]){printf("Alice\n");return 0;}
	printf("Bob\n");
}

Measured memory_bytes: 5760
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
int a[26];
int main()
{
	int num,gen;
	scanf("%d%d",&num,&gen);
	for(int i=0;i<num;i++)
	{
		string s;
		cin>>s;
		a[s[0]-'A']++;
	}
	int ans=0;
	for(;;)
	{
		sort(a,a+26);
		reverse(a,a+26);
		if(a[gen-1]==0)
		{
			printf("%d\n",ans);
			break;
		}
		for(int i=0;i<gen;i++)a[i]--;
		ans++;
	}
}

Measured memory_bytes: 256
#n = int(input())
#s = input()
#n, k= map(int,input().split())
#da = list(map(int,input().split()))

da = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]
for k in range(3):
    for i in range(3):
        for j in range(n):
            if(da[k][i] == b[j]):
                da[k][i] = 0
                break
ju = False
for i in range(3):
    if(da[i][0] == 0 and da[i][1] == 0 and da[i][2] == 0):
        ju = True
    if(da[1][i] == 0 and da[2][i] == 0 and da[0][i] == 0):
        ju = True
if da[0][0] == 0 and da[1][1] == 0 and da[2][2] == 0:
    ju = True
if da[0][2] == 0 and da[1][1] == 0 and da[2][0] == 0:
    ju = True

if ju:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <string> 
#include <cstring> 
using namespace std;
int main()
{
	int n;
	int head,dis,sum=0;
	char str[110],board[100];
	cin>>n;
	cin>>board;
	for(int i=0;i<=n-1;i++){
		cin>>str;
	  for(head=0;head<=strlen(str)-1;head++){
		 	for(dis=0;head+(strlen(board)-1)*dis<strlen(str);dis++){
		 	  	    for(int k=0;k<=strlen(board)-1;k++){
		 	  	    if(str[head+dis*k]!=board[k]) {goto p1;}
		 	  	 }
		 	  	 sum++;
		 	  	 goto p2;
		 	  	 p1:;
		 	  }	 	 
	  }
	  p2:;	
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
using i64 = int64_t;
using namespace std;
int main() {
    int N, M;
    cin >> N >> M;
    vector< set< int > > node(N);
    vector< int > used(N, 0);
    for(int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        node[a].insert(b);
        node[b].insert(a);
    }
    list< int > ans;
    int l = 0, r = *node[0].begin();
    bool flag = true;
    ans.push_front(l);
    ans.push_back(r);
    used[l] = used[r] = 1;
    while(flag) {
        flag = false;
        for(auto x : node[ans.front()]) {
            if(!used[x]) {
                ans.push_front(x);
                flag = true;
                break;
            }
        }
        used[ans.front()] = 1;
    }
    flag = true;
    while(flag) {
        flag = false;
        for(auto x : node[ans.back()]) {
            if(!used[x]) {
                ans.push_back(x);
                flag = true;
                break;
            }
        }
        used[ans.back()] = 1;
    }
    cout << ans.size() << endl;
    int j = 0;
    for(auto x : ans) {
        cout << (j ? " " : "") << x + 1;
        j++;
    }
    return 0;
}

Measured memory_bytes: 18432
#include <bits/stdc++.h>
using namespace std;
using ll = long long; 
using vpii = vector<pair<int, int>>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
ll inf = 1e10;

ll gcd(ll a, ll b){
  return (b != 0) ? gcd(b, a%b) : a;
}

ll f(ll a, ll b){
  return (a/gcd(a,b))*b;
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> t(n);
  rep(i, n) cin >> t[i];
  ll now = 1;
  rep(i, n){
    now = f(now, t[i]);
  }
  cout << now << "\n";
}  

Measured memory_bytes: 256
import math


tax_8, tax_10 = map(int, input().split())

min_8 = math.ceil(tax_8 * 100 / 8)
limit_8 = math.ceil((tax_8 + 1) * 100 / 8)

min_10 = tax_10 * 100 // 10
limit_10 = (tax_10 + 1) * 100 // 10

target = max(min_8, min_10)

if target < limit_8 and target < limit_10:
    print(target)
else:
    print(-1)


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

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

	for(int n, m; cin >> n >> m, n;) {
		vector<int> cnt(11, 0);
		for(int i = 0; i < n; ++i) {
			int d, p;
			cin >> d >> p;
			cnt[p] += d;
		}

		int ans = 0;
		for(int i = 10; i > 0; --i) {
			if(m >= cnt[i]) {
				m -= cnt[i];
			}
			else {
				ans += i * (cnt[i] - m);
				m = 0;
			}
		}

		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1200
#include <iostream>

int main() {
    long int A, B, K, a_A, a_B;
    std::cin >> A >> B >> K;

    if (A > 0) {
        A -= K;
        if (A < 0) {
            B += A;
            A = 0;
            if (B < 0) {
                B = 0;
            }
        }
    } else {
        B -= K;
        if (B < 0) {
            B = 0;
        }
    }

    printf("%ld %ld", A, B);
}

Measured memory_bytes: 256
import std.stdio; // readln
import std.array; // split
import std.conv; // to
import std.typecons;
import std.range;
import std.algorithm;

void main(){
	string[] s = split(readln());
	int n = to!int(s[0]);
	long k = to!long(s[1]);

	alias Tuple!(long,long) pair;
	pair[] p = new pair[](n);
	for(int i = 0; i < n; i++){
		s = split(readln());
		long a = to!long(s[0]);
		long b = to!long(s[1]);
		p[i] = pair(a,b);
	}

	sort(p);

	long cur = 0;
	for(int i = 0; i < n; i++){
		cur += p[i][1];
		if(cur >= k){
			writeln(p[i][0]);
			return;
		}
	}
}


Measured memory_bytes: 4732
import java.util.*;



import java.io.*;
public class Main {


	public static void main(String[] args) {
	FastScanner sc=new FastScanner();
    String s=sc.next(),t=sc.next();
    int n=s.length(),m=t.length();
    int dp[][]=new int[s.length()+1][t.length()+1];
    for(int i=0;i<=n;i++) {
    	for(int j=0;j<=m;j++) {
    		if(i==0||j==0)
    			dp[i][j]=0;
    		else {
				if(s.charAt(i-1)==t.charAt(j-1))
					dp[i][j]=dp[i-1][j-1]+1;
				else dp[i][j]=Math.max(dp[i-1][j],dp[i][j-1]);
    			
			}
    	}
    }
    int idx=dp[n][m];
    int  t1=idx;
   // System.out.println(t1);
    char lcs[]=new char[idx+1];
    lcs[idx]=' ';
    int  i=n;
    
    int j=m;
    while(i>0&&j>0){
        if(s.charAt(i-1)==t.charAt(j-1)){
             lcs[idx-1]=s.charAt(i-1);
            i--;
            j--;
            idx--;
           
            
        }
        else if(dp[i-1][j]>dp[i][j-1])
        i--;
        else
        j--;
    }
    for(int k=0;k<=t1;k++){
        System.out.print(lcs[k]);
    }
    System.out.println();


	}
	static class FastScanner{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		int [] readArray(int n) {
			int a[]=new int[n];
			for(int i=0;i<n;i++) a[i]=nextInt();
			return a;
		}
		
		
	}
	

}



Measured memory_bytes: 85096
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)();
typedef long long ll;
 
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}
 
const ll big=998244353;
int exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x)%big;
    ll t=exp(x,y/2);
    return (t*t)%big;
}
 
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(0);
    /*--------------------------------*/
    
    int n;cin >> n;
    vector<int> a(n);
    rep(i,n){cin >> a[i];a[i]-=i+1;}
    sort(a.begin(),a.end());
    int k;
    if(n%2==1)k=a[n/2];
    else k=(a[n/2]+a[n/2-1])/2;
    ll ans=0;
    rep(i,n)ans+=abs(a[i]-k);
    ll ans2=0;
    if(n%2==0){
        k++;
        rep(i,n)ans2+=abs(a[i]-k);
        ans=min(ans,ans2);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
import math
import sys
N,M=map(int,input().split())
A=list(map(int,input().split()))
S=sum(A)
cnt=0
for i in range(N):
    #print(A[i], 1 / 4 / M * S)
    if A[i] >= 1/4/M*S:
        #print(A[i],1/4/M*S)
        cnt+=1
if cnt>=M:
    print("Yes")
else:
    print("No")
#print(cnt)



Measured memory_bytes: 38384
n=int(input())
l=[]
from bisect import bisect_left
for i in range(n):
    a=int(input())
    if l==[]:
        l.append(a)
    else:
        if l[-1]<a:
            l.append(a)
        else:
            l[bisect_left(l,a)]=a

print(len(l))


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

int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int n, a, b;
  cin >> n >> a >> b;
  vector<int> x(n + 1), f(n + 1);
  for (int i = 1; i <= n; i++) cin >> x.at(i);
  long long ans = 0;
  for (int i = 2; i <= n; i++) {
    ans += min(1ll * a * (x.at(i) - x.at(i - 1)), 1ll * b);
  }
  cout << ans << '\n';
}

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

int main(){
double n;
  cin >> n;
  double a = n/1.08;
  double c = ceil(a);
  double f = floor(a);
  if(floor(c*1.08)==n)cout << (int)(c) << endl;
  else if(floor(f*1.08)==n)cout << (int)(f) << endl;
  else cout << ":(" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define fi first
#define se second
#define mp make_pair
int main() {

ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll r,d,x,y=0;
cin>>r>>d>>x;
y=x;
for(ll i=1;i<=10;i++)
{
y=r*x-d;
cout<<y<<endl;
x=y;
}
	return 0;
}


Measured memory_bytes: 256
import bisect
n = int(input())
d_li = list(map(int,input().split()))
m = int(input())
t_li = list(map(int,input().split()))

import collections
d_cnt = collections.Counter(d_li)
t_cnt = collections.Counter(t_li)
#print(d_cnt,t_cnt)

for t in t_cnt.items():
    #print(d_cnt,d_cnt[t[0]],t[1])
    if d_cnt[t[0]] < t[1]:
        print('NO')
        exit()
print('YES')

Measured memory_bytes: 56800
#include<iostream>
#include<string>
using namespace std;
int main(){
    string let;
    string sub;
    int m,h;
    string a;
    while(1){
        cin >> let;
        if(let == "-")break;
        cin >> m;
        for(int i=0; i<m;i++){
            cin >> h;
            a = let.substr(h);
            let.erase(h);
            let = a + let;
        }cout<<let<<endl;
    }
    return 0;
}


Measured memory_bytes: 3212
#include<stdio.h>
int main()
{
    int n;
    scanf("%d", &n);
    if (n <= 1000)
        n = 1000 - n;

    else if (n <= 2000)
        n = 2000 - n;

    else if (n <= 3000)
        n = 3000 - n;

    else if (n <= 4000)
        n = 4000 - n;

    else if (n <= 5000)
        n = 5000 - n;

    else if (n <= 6000)
        n = 6000 - n;

    else if (n <= 7000)
        n = 7000 - n;

    else if (n <= 8000)
        n = 8000 - n;

    else if (n <= 9000)
        n = 9000 - n;

    else if (n <= 10000)
        n = 10000 - n;

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

    return 0;
}


Measured memory_bytes: 1716
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <bitset>
#include <queue>
#include <cstring>
#include <set>
#include <map>

#define rep(i, l, r) for(int i=l; i<=r; i++)
#define dow(i, l, r) for(int i=l; i>=r; i--)
#define clr(x, c) memset(x, c, sizeof(x))
#define travel(x) for(edge *p=fir[x]; p; p=p->n)
#define all(x) (x).begin,(x).end
#define pb push_back
#define fi first
#define se second
#define l(x) Left[x]
#define r(x) Right[x]
#define lowbit(x) (x&-x)
#define pi acos(-1)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

inline int read()
{
    int x=0; bool f=0; char ch=getchar();
    while (ch<'0' || '9'<ch) f|=ch=='-', ch=getchar();
    while ('0'<=ch && ch<='9') x=x*10+ch-'0', ch=getchar();
    return f?-x:x;
}

int k[100009];

int main()
{
	int n=read(), A=read(), B=read();
	rep(i, 1, n) k[i]=read();
	int l=1, r=1000000000, mid;
	while (l<r)
	{
		mid=(l+r)>>1; ll g=0;
		rep(i, 1, n) if (k[i]>1LL*mid*B) g+=(k[i]-1LL*mid*B-1)/(A-B)+1;
		if (g<=mid) r=mid; else l=mid+1;
	}
	printf("%d\n", l);
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	int a,b,c;
	cin>>a>>b>>c;
	if(c>=a&&c<=b)cout<<"Yes"<<endl;
	else if(c<=a&&c>=b)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;


	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
int read();
int M(int x) { return x >= mod ? x - mod : x; }
void Add(int &x, int y) { (x += y) >= mod ? x -= mod : x; }
int fsp(long long bs, int p) {
    int rt = 1;
    while (p) {
        if (p & 1) rt = bs * rt % mod;
        bs = bs * bs % mod, p >>= 1;
    }
    return rt;
}

int n, K, m, res;
int a[30004];
int fac[30004], caf[30004], lim = 30000;

void init() {
    res = n - m + 1;
    for (int i = 1; i <= n - m; ++i) res = 1ll * res * K % mod;
    fac[0] = 1;
    for (int i = 1; i <= lim; ++i) fac[i] = 1ll * fac[i - 1] * i % mod;
    caf[lim] = fsp(fac[lim], mod - 2);
    for (int i = lim; i >= 1; --i) caf[i - 1] = 1ll * caf[i] * i % mod;
}

int p[30004];
bool check1() {
    for (int r = 1, l = 1; r <= m; ++r) {
        l = max(l, p[a[r]] + 1), p[a[r]] = r;
        if (r - l + 1 >= K) return 1;
    }
    return 0;
}

int llen, rlen;
bool check2() {
    for (int i = 1; i <= K; ++i) p[i] = 0;
    for (int i = 1; i <= m; p[a[i]] = 1, ++i)
        if (p[a[i]]) {
            llen = i - 1;
            break;
        }
    for (int i = 1; i <= K; ++i) p[i] = 0;
    for (int i = m; i >= 1; p[a[i]] = 1, --i)
        if (p[a[i]]) {
            rlen = m - i;
            break;
        }
    return llen;
}

int x[30004], y[30004];
int f[30004][502];
void work(int *g, int st) {
    g[0] = f[0][st] = 1;
    for (int i = 1, tmp; i <= n; ++i) {
        tmp = f[i - 1][K - 1];
        for (int j = K - 1; j >= 1; --j) {
            f[i][j] = M(tmp + 1ll * (K - j + 1) * f[i - 1][j - 1] % mod);
            Add(tmp, f[i - 1][j - 1]), Add(g[i], f[i][j]);
        }
    }
    f[0][st] = 0;
}

int g[30004][502];
int solve() {
    for (int i = 1, tmp; i <= n; ++i) {
        tmp = g[i - 1][K - 1];
        for (int j = K - 1; j >= 1; --j) {
            g[i][j] = M(tmp + 1ll * (K - j + 1) * g[i - 1][j - 1] % mod);
            Add(tmp, g[i - 1][j - 1]), j >= m ? Add(g[i][j], f[i][j]) : void();
        }
    }
    int rt = 0;
    for (int i = 1; i < K; ++i) Add(rt, g[n][i]);
    return rt;
}

int main() {
    n = read(), K = read(), m = read(), init();
    for (int i = 1; i <= m; ++i) a[i] = read();
    if (check1()) return printf("%d\n", res), 0;
    if (check2()) {
        work(x, llen), work(y, rlen);
        for (int i = 0; i <= n - m; ++i)
            Add(res, mod - 1ll * x[i] * y[n - m - i] % mod);
        return printf("%d\n", res), 0;
    }
    work(x, 0), Add(res, mod - 1ll * solve() * fac[K - m] % mod * caf[K] % mod);
    printf("%d\n", res);
    return 0;
}
int read() {
    int x = 0, f = 1;
    char c = getchar();
    while (!isdigit(c)) f = (c == '-') ? -1 : f, c = getchar();
    while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
    return x * f;
}

Measured memory_bytes: 100992
import java.util.*;

public class Main {
  public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
	  int N = Integer.parseInt(sc.next());
	  int L = Integer.parseInt(sc.next());
	  
	  int[] appleValue = new int[N];
	  int sum = 0;
	  int a = 0;
	  int min = 9999;
	  for(int i = 0; i < N; i++) {
		  int value = L + i;
		  appleValue[i] = value;
		  sum += appleValue[i];
		  
		  if(min > Math.abs(value)) {
			  min = Math.abs(value);
			  a = value;
		  }
	  }
	  System.out.println(sum - a);
	  	  
	  
  }
}


Measured memory_bytes: 21844
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var (
	BufferSize = 100
)

func readLine(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func scanStr(sc *bufio.Scanner) string {
	if !sc.Scan() {
		panic(nil)
	}
	return sc.Text()
}

func scanInt(sc *bufio.Scanner) int {
	if !sc.Scan() {
		panic(nil)
	}
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, BufferSize)
	sc.Split(bufio.ScanWords)

	k := scanInt(sc)
	x := scanInt(sc)

	for i := -(k - 1); i < k; i++ {
		if i != k-1 {
			fmt.Printf("%d ", x+i)
		} else {
			fmt.Printf("%d", x+i)
		}
	}
}


Measured memory_bytes: 640
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
    String s = sc.next();
    if (s.length() <= a){
      System.out.println(s);
    } else {
      String t = s.substring(0,a);
      System.out.println(t + "...");
    }
  }
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N, L;
    cin >> N >> L;
    vector<string> S(N);
    REP(i,0,N) cin >> S[i];

    ASC(S);
    string T;
    REP(i,0,N) T += S[i];
    PR(T);

    return 0;
}

/*



*/

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

int main(){
  int n;
  cin >> n;
  vector<int> leaf(n+1);
  for(int i=0; i<n+1; ++i) cin >> leaf[i];
  vector<ll> rui(n+1);
  rui[n] = leaf[n];
  for(int i=n-1; i>=0; --i){
    rui[i] = rui[i+1] + (ll)leaf[i];
  }
  int tnpoint;
  ll maxroot=1;
  for(int i=0; i<n+1; ++i){
    if(maxroot >= rui[i]){
      tnpoint = i;
      break;
    }
    maxroot -= leaf[i];
    maxroot *= 2;
    if(i==n || maxroot<0){
      cout << -1 << endl;
      return 0;
    }
  }
  ll ans=0;
  ll notl = 1;
  for(int i=0; i<tnpoint; ++i){
    ans += notl;
    notl -= leaf[i];
    notl *= 2;
  }
  for(int i=tnpoint; i<n+1; ++i){
    ans += rui[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 4580
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <map>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){
  int N,H,W;
  cin>>N>>H>>W;
  cout<< (N-H+1)*(N-W+1);
return 0;
}


Measured memory_bytes: 256
N,K = map(int, input().split())
A = list(map(int, input().split()))
dp = [0 for i in range(N)]
dp[0] = 0
if N > K:
    for i in range(1,N):
        if i <= K:
            dp[i] = abs(A[i] - A[0])
        else:
            L = []
            for j in range(1,K+1):
                L.append(abs(A[i]-A[i-j]) + dp[i-j])
            dp[i] = min(L)
    print(dp[N-1])
else:
    print(abs(A[N-1]-A[0]))

Measured memory_bytes: 56544
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

constexpr auto N=10;

int main()
{
  vector<pair<int,int>> const inc[] = {
    { {0,-1}, {-1,0}, {0,0}, {1,0}, {0,1} },
    { {-1,-1}, {0,-1}, {1,-1}, {-1,0}, {0,0}, {1,0}, {-1, 1}, {0,1}, {1,1} },
    { {0,-2}, {-1,-1}, {0,-1}, {1,-1}, {-2,0}, {-1,0}, {0,0}, {1,0}, {2,0}, {-1, 1}, {0,1}, {1,1}, {0,2} }
  };

  unsigned int p[N][N]={};
  int x, y, s;
  while( scanf( "%d,%d,%d", &x, &y, &s ) != EOF ) {
    for( auto const i : inc[s-1] ) {
      auto const px = x + i.first, py = y + i.second;
      if ( px >= 0 && px < N && py >= 0 && py < N )
        ++p[px][py];
    }
  }

  cout
    << count( &p[0][0], &p[0][0]+N*N, 0 ) << endl
    << *max_element( &p[0][0], &p[0][0]+N*N ) << endl;
}

Measured memory_bytes: 1204
#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 N;
  cin >> N;
  int x = N%10;
  if(x == 2 || x == 4 || x == 5 || x == 7 || x == 9)
    cout << "hon" << endl;
  else if(x == 0 || x == 1 || x == 6 || x == 8)
    cout << "pon" << endl;
  else
    cout << "bon" << endl;
  return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
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;}
const long long INFLL = 1LL<<60;
const int INF = 1<<28;
const long long MOD =1000000000+7;

int main()
{
	string s;

	cin >>s;
	int a=0;
	int b=s.size()-1;
	while(s[a]!='A'){
		a++;
	}
	while(s[b]!='Z'){
		b--;
	}
	cout <<b-a+1<<endl;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <iostream>
#include <math.h>
#include <map>
#include <set>
using namespace std;
int main ()
{
	char s[101];
	scanf("%s",&s);
	for(int i=0;i<strlen(s);i++)
	{
		printf("x");
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  int A,B;

  cin >>  A >> B;

  int ans=-1;

//10%税で100円(Bの最大値)の税がかかるのは限界でも1009円
  for(int i=1;i<=1009;i++){
    int a=i*2/25,b=i/10;
    if(a==A&&b==B){
      ans=i; break;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int A;
int B;
string s;
string output = "Yes";
int main()
{
    cin >> A >> B >> s;
    for (int i = 0; i < A; ++i) if (!('0' <= s[i] && s[i] <= '9'))output = "No";
    if (s[A]!='-')output = "No";
    for (int i = A+1; i <= A+B; ++i) if (!('0' <= s[i] && s[i] <= '9'))output = "No";
    cout << output << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
const int mod = 1000000007;
int N, M;
int main() {
	cin >> N >> M;
	vector<int> x(N), y(M), nx;
	for (int i = 0; i < N; ++i) cin >> x[i];
	for (int i = 0; i < M; ++i) cin >> y[i];
	sort(y.begin(), y.end());
	for (int i = 0; i < N; ++i) {
		if (!(x[i] < y[0] || x[i] > y[M - 1])) {
			nx.push_back(x[i]);
		}
	}
	x = nx;
	N = x.size();
	vector<int> px(N), py(N);
	for (int i = 0; i < N; ++i) {
		int ptr = lower_bound(y.begin(), y.end(), x[i]) - y.begin();
		py[i] = y[ptr] - x[i];
		px[i] = x[i] - y[ptr - 1];
	}
	vector<int> sy = py, p(N);
	sort(sy.begin(), sy.end());
	sy.erase(unique(sy.begin(), sy.end()), sy.end());
	for (int i = 0; i < N; ++i) {
		py[i] = lower_bound(sy.begin(), sy.end(), py[i]) - sy.begin();
		p[i] = i;
	}
	int W = sy.size();
	sort(p.begin(), p.end(), [&](int i, int j) { return px[i] != px[j] ? px[i] < px[j] : py[i] > py[j]; });
	vector<int> bit(W + 2);
	for (int i = 1; i <= W + 1; i += i & (-i)) bit[i] = 1;
	for (int i = 0; i < N; ++i) {
		if (i >= 1 && px[p[i]] == px[p[i - 1]] && py[p[i]] == py[p[i - 1]]) continue;
		int cy = py[p[i]];
		int sum = 0;
		for (int k = cy + 1; k >= 1; k -= k & (-k)) {
			sum += bit[k];
			if (sum >= mod) sum -= mod;
		}
		for (int k = cy + 2; k <= W + 1; k += k & (-k)) {
			bit[k] += sum;
			if (bit[k] >= mod) bit[k] -= mod;
		}
	}
	int ans = 0;
	for (int i = W + 1; i >= 1; i -= i & (-i)) {
		ans += bit[i];
		if (ans >= mod) ans -= mod;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3196