akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

const ll MOD = 998244353;

ll DP[3001][3001];

// A の部分集合 T、Tの部分集合 U で数える
int main() {
  int N, S;
  cin >> N >> S;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];

  DP[0][0] = 1;
  REP(i, N) REP(j, S + 1) {
    // Ai が T に選ばれない場合
    DP[i + 1][j] += DP[i][j];
    // Ai が T には選ばれているが U には選ばれていない場合
    DP[i + 1][j] += DP[i][j];
    DP[i + 1][j] %= MOD;
    // Ai が選ばれた場合
    if (A[i] + j <= S) DP[i + 1][j + A[i]] += DP[i][j];
    DP[i + 1][j] %= MOD;
  }
  cout << DP[N][S] << endl;
}

Measured memory_bytes: 73944
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,string>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;

int main(){
    ll N;
    cin >> N;   
    vector<ll> d(N,0);
    ll sum=0;
    ll minus=0;
    for(ll i=0;i<N;i++){
        cin>>d[i];
        sum+=d[i];
        minus+=d[i]*d[i]
    ;}
    cout<<(sum*sum-minus)/2<<endl;

return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#define int long long
#define ll getchar();getchar();return 0;
using namespace std;
int a[114], b[114];
signed main() {
	int n, m, x, y;
	cin >> n >> m >> x >> y;
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int j = 0; j < m; j++)cin >> b[j];
	sort(a, a + n);
	sort(b, b + m);
	if (a[n - 1] >= b[0])puts("War");
	else {
		if (b[0] <= x)puts("War");
		else if (a[n - 1] >= y)puts("War");
		else puts("No War");
	}
	ll
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<ll, II> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 110;
const int MAXK = 510;

int n, m;
vector<int> a[MAXN];
bool visit[MAXN];

void dfs(int u) {
    visit[u] = true;
    FOR(i,0,SZ(a[u])-1) {
        int v = a[u][i];
        if (!visit[v]) dfs(v);
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> m;
    FOR(i,1,m) {
        int u, v, c;
        cin >> u >> v >> c;
        a[u].emplace_back(v);
        a[v].emplace_back(u);
    }
    int cnt = 0;
    FOR(i,1,n)
        if (!visit[i]) {
            cnt++;
            dfs(i);
        }
    cout << cnt;
    return 0;
}

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

int add(int *,int,int);
int solve(int *,int,int);
int n;
int main(){
  int i,q,A[2000],key;


  scanf("%d",&n);

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


  scanf(" %d",&q);

  for(i=0;i<q;i++){
    scanf(" %d",&key);
    if(solve(A,0,key)==1){
      printf("yes\n");
    }
    else{
      printf("no\n");
    }

  }
  return 0;
}


int solve(int *A,int i,int  key){
  int res;
  if(key == 0){
    return 1;
  }
 if(i >= n){
   return 0;
 }
 res = solve(A,i + 1, key) || solve(A,i + 1, key - A[i]);
 return res;
}




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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define fi first
#define se second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;
template <class T> using vec = vector<T>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i) continue;
    ret.push_back(i);
    if (i * i != n) ret.push_back(n / i);
  }

  sort(begin(ret), end(ret), greater<ll>());
  return ret;
}

int main(int argc, char* argv[]) {
  ll n, k;
  cin >> n >> k;
  vec<ll> a(n);
  scan(a);

  ll total = accumulate(all(a), 0LL);
  auto v = divisor(total);

  vec<ll> m(n), neg(n + 1, 0), pos(n + 1, 0);
  for (ll d : v) {
    rep(i, 0, n) m[i] = a[i] % d;
    sort(all(m));

    rep(i, 0, n) {
      neg[i + 1] = neg[i] + m[i];
      pos[i + 1] = pos[i] + (d - m[i]) * bool(m[i]);
    }

    rep(i, 1, n) {
      ll neg_cnt = neg[i] - neg[0];
      ll pos_cnt = pos[n] - pos[i];
      if (neg_cnt != pos_cnt || pos_cnt > k) continue;
      cout << d << endl;
      return 0;
    }
  }
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N,L;
int abs(int x)
{
	if(x<0)return -x;
	return x;
}
bool cmp(int l,int r)
{
	return abs(l)<abs(r);
}
int main()
{
	scanf("%d%d",&N,&L);
	int a[205];
	for(int i=1;i<=N;i++)a[i]=L+i-1;
	sort(a+1,a+N+1,cmp);
	int sum=0;
	for(int i=2;i<=N;i++)sum+=a[i];
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 256
using System;

class ITP1
{
    static void Main()
    {
        string str = Console.ReadLine();
        str += str;
        string str2 = Console.ReadLine();
        char[] ch = str.ToCharArray();
        char[] ch2 = str2.ToCharArray();
        int cnt = 0;
        for (int i = 0; i < ch.Length/2; i++)
        {
            cnt = 0;
            if (ch2[0] == ch[i])
            {
                for (int j = 0; j < ch2.Length; j++)
                {
                    if (ch2[0 + j] == ch[i + j])
                    {
                        cnt++;
                    }
                }
                if (cnt == ch2.Length)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }
        }
            Console.WriteLine("No");
    }
}

Measured memory_bytes: 5276
#include <stdio.h>

int main() {
  char str[51];
  int num, l;
  int i;
  scanf("%d %d", &num, &l);
  scanf("%s", str);
  str[l - 1] = str[l - 1] - 'A' + 'a';

  printf("%s\n", str);

  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<cstdio>
#include<numeric>

using namespace std;
/*
int find(int x, vector<int> &p) {
if (p[x] == x)return x;
return p[x] = find(p[x], p);
}

void uni(int x, int y, vector<int> &p) {
x = find(x, p);
y = find(y, p);
p[x] = y;
}

int same(int x, int y, vector<int> p) {
if (find(x, p) == find(y, p))return 1;
return 0;
}
*/

struct res {
	int num;
	string S;
	long long P;
};

int main() {
	long long N, K, cnt = 0, tmp, ans = 0;
	cin >> N;
	vector<res> r(N);

	for (int i = 0; i < N; i++) {
		r[i].num = i;
		cin >> r[i].S >> r[i].P;
	}
	
	sort(r.begin(), r.end(), [](res a, res b) {return a.S != b.S ? a.S < b.S : a.P > b.P; });

	for (int i = 0; i < N; i++) {
		cout << r[i].num + 1 << endl;
	}

	char qq;
	cin >> qq;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int n, s, i, j, sum, max, min, count;

	for (i = 0; i < 20; i++){
		scanf("%d", &n);
		if (n == 0) break;
		else if (3 <= n && n <= 100){
			max = 0; min = 1000; sum = 0; count = 0;
			for (j = 0; j < n; j++){
				scanf("%d", &s);
				if (s >= 0 && s <= 1000){
					if (s > max) max = s;
					if (s < min) min = s;
					sum = sum + s;
				}
				else{
					count++;
				}
			}
			sum = sum - max - min;
			printf("%d\n", sum / (n - 2 ));
		}
	}
	return 0;
}

Measured memory_bytes: 600
import sys
from heapq import heappush, heappop

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *UVW = map(int, read().split())
    G = [[] for _ in range(N)]
    for u, v, w in zip(*[iter(UVW)] * 3):
        G[u - 1].append((v - 1, w))
        G[v - 1].append((u - 1, w))

    dist = [INF] * N
    dist[0] = 0
    hq = [(0, 0)]

    while hq:
        d, v = heappop(hq)
        if d > dist[v]:
            continue
        for nv, cost in G[v]:
            if dist[nv] > dist[v] + cost:
                dist[nv] = dist[v] + cost
                heappush(hq, (dist[nv], nv))

    ans = [0] * N
    for i in range(N):
        ans[i] = 0 if dist[i] % 2 == 0 else 1

    print(*ans, sep='\n')
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 58808
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    int x,y;
    while(scanf("%d %d",&x,&y)!=EOF){
        out(x+y);
    }
}



Measured memory_bytes: 3180
from collections import defaultdict
import sys
sys.setrecursionlimit(20000000)
connection = defaultdict(lambda: [])

n = int(input())

ab = []
for i in range(n-1):
    a, b = map(int, input().split())
    connection[a].append(b)
    connection[b].append(a)
    ab.append((a, b))

c = list(map(int, input().split()))
c.sort()

ans = [0] * (n+1)
def dfs(num):
    ans[num] = c.pop()
    for next_num in connection[num]:
        if ans[next_num] == 0 :
            dfs(next_num)

dfs(1)

score = 0
for a, b in ab:
    score += min(ans[a], ans[b])

print(score)
print(" ".join(map(str, ans[1:])))


Measured memory_bytes: 14752
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
int N;
int K;
int A[200000];
int main(){
  int i;
  rd(N);
  rd(K);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  for(i=(K);i<(N);i++){
    if(A[i] > A[i-K]){
      wt_L("Yes");
      wt_L('\n');
    }
    else{
      wt_L("No");
      wt_L('\n');
    }
  }
  return 0;
}
// cLay varsion 20200509-1

// --- original code ---
// int N, K, A[2d5];
// {
//   rd(N,K,A(N));
//   rep(i,K,N) wt(if[A[i] > A[i-K], "Yes", "No"]);
// }


Measured memory_bytes: 6044
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<ll,ll>;

ll ketasu(ll a){
   ll num=1;
   while(a/10){
       num++;
       a/=10;
   }
   return num;
}

ll gcd(ll a,ll b){return b ? gcd(b,a%b) :a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

ll kosuu(ll a){
    ll sum=0;
    for(ll i=1;i*i<=a;i++){
        if(a%i==0){
            if(a!=1&&i*i!=a){
            sum+=2;
            }else{
             sum++;   
            }
        }
    }
    return sum;
}

ll n;



    vector<pair<ll,ll>>p;
void fs(ll a){
    for(ll i=2;i*i<=n;i++){
        ll cnt=0;
        while(n%i==0){
            n/=i;
            cnt++;
        }
        p.emplace_back(i,cnt);
    }
    return;
}


ll di[]={1,0,-1,0};
ll dj[]={0,-1,0,1};
int main(){
   int n;
   cin>>n;
    long long int a[n],ans=0,i;
    int mod=1000000007;
    long long int sum=0;
 
    for( i = 0 ; i < n ; i++ ){
            cin>>a[i];
        sum = sum + a[i];
    }
    for( i = 0 ; i < n ; i++ ){
        sum = sum - a[i];
        if(sum<0)sum+=mod;
 
        ans+=(a[i]%mod * (sum%mod))%mod;
        ans%=mod;
    }
    cout<<ans%mod;
 
    return 0;
}
 




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

int main(void) {
	int i,j;
	scanf("%d",&i);
	scanf("%d",&j);
	if(i>j)printf("a > b\n");
	if(i<j)printf("a < b\n");
	if(i==j)printf("a == b\n");
	return EXIT_SUCCESS;
}

Measured memory_bytes: 580
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Gosu_Hiroo
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define tr(container, it) \
        for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define intv(x, a, b)((x)>=a && (x)<=b)
#define  rep(i, _begin, _end) for (__typeof(_end) end = _end, begin = _begin,  i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define  _for(i, end) for (__typeof(end) i = 0, _len = (end); i < (_len); i += 1)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define readint ({int t;cin >> t;t;})
const double PI = 2 * acos(.0);
const int INF = 0x3f3f3f3f;
const ll LLINF = 1000000000000000005LL;;
const ll MOD = (ll) (1e9) + 7;

void _mod(ll &x) { x = mod(x, MOD); }

//const ll MOD = (ll) 998244353 ;
const double EPS = 1e-10;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *) array, (T *) (array + N), val);
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> V) {
    for (auto v : V)os << v << " ";
    return os;
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> V) {
    for (auto v : V)os << v << " ";
    return os;
}

//#define int ll

class CSequence {
public:
    int N;
    ll crt1 = 0, res1 = 0, crt2 = 0, res2 = 0;
    ll A[101010];
    void solve(std::istream &cin, std::ostream &cout) {
        cin >> N;
        _for(i,N)cin >> A[i];
        _for(i, N) {
            ll t = A[i];
            crt1 += t;
            if (i & 1) {
                if (crt1 <= 0)res1 += 1 - crt1, crt1 = 1;
            } else {
                if (crt1 >= 0)res1 += crt1 + 1, crt1 = -1;
            }
        }

        _for(i, N) {
            ll t = A[i];
            crt2 += t;
            if (!(i & 1)) {
                if (crt2 <= 0)res2 += 1 - crt2,crt2 = 1;
            } else {
                if (crt2 >= 0)res2 += crt2 + 1,crt2 = -1;
            }
        }
        cout << min(res1, res2) << endl;


    }
};


#undef int
int main() {


	CSequence solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	in.tie(0); ios::sync_with_stdio(0); out<<fixed<<setprecision(20);
	solver.solve(in, out);
	return 0;
}


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


int main(){

int n , k , x , s;
cin>>n>>k;
for(int i=1;i<=n;i++){
    cin>>x;
    if( x == 1 )s=i;
}

int ans = 1+  (n-k + k-2) / (k-1);
cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
ans = 0

like_list = []

n.times do
  like_list << gets.split.map(&:to_i)
end

duplicate = {}


# [[1,2,3], [4,3,5]]
# [1,2,3] = n | (n.size = 3-1 = 2)
#   n[1] = 2..3.each do |i|
#     duplicateにiのキーがあれば += 1する
#     なければ1を入れよう
# [4,3,5]



like_list.size.times do |n|
  # first = 0 like_list[0]
  # 回すのは１〜size-1まで
  1.upto(like_list[n].size-1) do |i|
    like_list[n][i]
    if duplicate[like_list[n][i]]
      duplicate[like_list[n][i]] += 1
    else
      duplicate[like_list[n][i]] = 1
    end
  end
end

duplicate.each do |_, v|
  if v == like_list.size
    ans += 1
  end
end

puts ans


Measured memory_bytes: 3836
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
 
using namespace std;
 
int main(void)
{
  int n;
  cin >> n;
  vector<pair<int,int>> vp;
  REP(i,n) {
    int x; cin >> x;
    vp.emplace_back(x,i);
  }
  sort(vp.begin(),vp.end());
  int streak=0;
  int prev=-1;
  int mst=0;
  REP(i,n) {
    if(vp[i].second < prev) streak = 0;
    ++streak;
    prev = vp[i].second;
    mst = max(streak,mst);
  }
  cout << n-mst << endl;
  return 0;
}


Measured memory_bytes: 2420
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

// -------------------------------------------------------------------------------------



int main() {
  int n;
  cin >> n;
  vector<int> x(n), sort_x(n);
  rep(i, n) {
    cin >> x[i];
    sort_x[i] = x[i];
  }
  sort(all(sort_x));

  rep(i, n) {
    int p = lower_bound(all(sort_x), x[i]) - sort_x.begin();
    if(p < n/2) {
      cout << sort_x[n/2] << endl;
    } else {
      cout << sort_x[n/2-1] << endl;
    }
  }

  return 0;
}

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

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

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

    if (a==0) cout << 1 ;
    else if (b==0) cout << 2;
    else if (c==0) cout << 3;
    else if (d==0) cout << 4;
    else cout << 5;

    cout << "\n";    

    return 0;
}

Measured memory_bytes: 3540
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long ll;

int num[11];

bool ok(int a); 

int main(){
    int n,k;
    cin >> n >> k;
    int b;
    //嫌いな数字にのみ＋１
    for(int i=0; i<k; i++){
        cin >> b, num[b]++;
    }
    for(int j=n;;j++){
        if(ok(j)){
            cout << j << "\n";
            return 0;
        }
    }
    return 0;


}

bool ok(int a){
    while(a>0){
        //各桁の値を取得し、嫌いな数値かどうか判定。
        //嫌いならfalseを返す
        if(num[a%10])
            return false;
        a/=10;
    }
    return true;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int P=1e9+7,N=1e5+10;
int n,m,a[N],b[N],g[N],w,dp[N],p,c[N];
pair<int,int> f[N];ll ans=1;
inline void upd(int &x,int y){((x+=y)>=P)&&(x-=P);}
int sum(int i){ll ans=0;for(;i;i-=i&(-i)) ans+=c[i];return ans%P;}
void add(int i,int x){for(;i<=w;i+=i&(-i)) upd(c[i],x);}
int main(){
    scanf("%d%d",&n,&m);int t=1;
    rep(i,1,n) scanf("%d",a+i);
    rep(i,1,m) scanf("%d",b+i);
    rep(i,1,n) if(a[i]>b[1]&&a[i]<b[m]){
        while(a[i]>b[t+1]) ++t;
        f[++p]=mp(a[i]-b[t],b[t+1]-a[i]);
        g[p]=b[t+1]-a[i];
    }sort(g+1,g+p+1);w=unique(g+1,g+p+1)-g-1;
    rep(i,1,p) f[i].se=lower_bound(g+1,g+w+1,f[i].se)-g;
    sort(f+1,f+p+1,[](pair<int,int> x,pair<int,int> y){return x.fi==y.fi?x.se>y.se:x.fi<y.fi;});p=unique(f+1,f+p+1)-f-1;
    rep(i,1,p){
        dp[i]=sum(f[i].se-1);upd(dp[i],1);ans+=dp[i];
        add(f[i].se,dp[i]);
    }
    printf("%lld\n",ans%P);
    return 0;
}

Measured memory_bytes: 2688
#include <stdio.h>

int main() {
	int sum = 0;

	char s[3];
	scanf("%s", s);

	for(int i = 0; i < 3; ++i) {
		switch(s[i]) {
			case 'a':
				sum += 1;
				break;
			case 'b':
				sum += 10;
				break;
			case 'c':
				sum += 100;
				break;
		}
	}

	if (sum == 111) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}

	return 0;
}

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

int main(void){
    ll n, x;
    cin >> n >> x;

    ll a[n];
    rep(i, n){
        cin >> a[i];
    }

    ll count = 0;
    rep(i, n - 1){
        if(a[i] + a[i+1] > x){
            if(a[i] + a[i+1] - x < a[i+1]){
                count += a[i] + a[i+1] - x;
                a[i+1] = x - a[i];
            }else{
                count += a[i+1] + a[i] - x;
                a[i+1] = 0;
                a[i] = x;
            }
        }
    }

    cout << count << endl;
    return 0;
}


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

typedef pair<int,int> P;

int cnt = 1;
vector<P> vec;

signed main(){
	int n;
	string s;
	cin >> s;
	n = s.length();
	bool flag = true;
	if(s[n - 1] == '1' || s[0] == '0') flag = false;
	for(int i = 0;i <= n - 2;i++){
		if(s[i] != s[n - i - 2]) flag = false;
	}
	if(!flag){
		cout << -1 << endl;
		return 0;
	}
	int pv = 0,prev1 = 0;
	flag = false;
	for(int i = n / 2 - 1;i >= 0;i--){
		if(s[i] == '1'){
			if(!flag){
				for(int j = 0;j < n - (i + 1);j++) vec.push_back(P(0,cnt++));
				flag = true;
			}else{
				for(int j = 0;j < prev1 - i;j++) vec.push_back(P(pv,cnt++));
			}
			prev1 = i;
			pv = cnt - 1;
		}
	}
	for(P p : vec) cout << p.first + 1 << " " << p.second + 1 << endl;
}

Measured memory_bytes: 3056
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n;
main(){
	cin>>n;
	vector<int>v(n);
	r(i,n)cin>>v[i];;
	v.erase(unique(v.begin(),v.end()),v.end());
	r(i,v.size())cout<<v[i]<<(i==v.size()-1?'\n':' ');
}


Measured memory_bytes: 3104
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#if __cplusplus >= 201103L
#include <chrono>
using namespace std::chrono;
#endif
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#ifdef LOCAL
#define prln(x) (cout << #x << ' ' << x << endl)
#define pr(x) (cout << #x << ' ' << x << ' ' )
#define prv(x) (cout << x << ' ')
#else
#define prln(x) 
#define pr(x)
#define prv(x)
#endif
#define clr(x) memset((x), 0, sizeof((x)))
#define clr1(x) memset((x), -1, sizeof((x)))
#define endl "\n"
#define pi acos(-1)
#define rep(i, st, ed) for (int i = (st); i <= (ed); ++i)
#define rep0(i, st, ed) for (int i = (st); i < (ed); ++i)
#define per0(i, st, ed) for (int i = (st); i > ed; --i)
#define per(i, st, ed) for (int i = (st); i >= ed; --i)
#define chmin(a, b) (a = a > b ? b : a)
#define chmax(a, b) (a = a < b ? b : a)
template<class T> void _sf(T &x) {cin >> x;}
void _sf(int &x) {scanf("%d", &x);}
void _sf(ll &x) {scanf("%lld", &x);}
void _sf(double &x) {scanf("%lf", &x);}
void _sf(char &x) {scanf(" %c", &x);}
void _sf(char *x) {scanf("%s", x);}
void sf() {}
template <class T, class...U> void sf(T & head, U&... tail) { _sf(head); sf(tail...);}
template<class T> void _out(const T &x) { cout << x; }
void _out(const int &x) { printf("%d", x); }
void _out(const ll &x) { printf("%lld", x); }
void _out(const double &x) { printf("%.16f", x); }
void _out(const char &x) { putchar(x); }
void _out(const char *x) { printf("%s", x); }
template<class T,class U> void _out(const pair<T,U> &x) {_out(x.F); putchar(' '); _out(x.S);}
template<class T> void _out(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _out(*i++)) if (i != x.cbegin()) putchar(' '); }
void out() {}
template<class T, class... U> void out(const T &head, const U &... tail) { _out(head); putchar(sizeof...(tail) ? ' ' : '\n'); out(tail...); }
const int mod = 998244353;
const int INF = 0x3f3f3f3f;

int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}

const int maxn = 3030;

int dp[maxn];
int a[maxn];

int main(){
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    int n, k;
    sf(n, k);
    rep(i, 0, n - 1) {
        a[i] = read();
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = k - a[i]; j >= 0; --j) {
            (dp[j + a[i]] += dp[j]) %= mod;
        }
        (dp[a[i]] += i + 1) %= mod;
        (ans += dp[k]) %= mod;
    }
    out(ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
  int n, a, b, prod;
  std::cin >> n >> a >> b;

  prod = n*a;

  if (prod < b) {
    std::cout << prod;
  } else {
    std::cout << b;
  }
  std::cout << std::endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		int n = scan.nextInt();

		int[] x = new int[n];

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

		int ans = Integer.MAX_VALUE;
		for(int i = 1; i <= 100; i++) {
			int temp =0;
			for ( int j = 0; j < n; j++) {
				temp += (int)Math.pow((x[j] - i), 2);
			}
			if(temp < ans)
				ans = temp;
		}
		System.out.println(ans);
	}
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	ll x, y;
	cin >> x >> y;
	int cnt = 1;
	while(2*x <= y){
		x *= 2;	
		cnt++;
	}
	cout << cnt << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int>t(n);
	for (int i = 0; i < n; i++) cin >> t[i];
	int m;
	cin >> m;
	vector<int>p(m), x(m);
	for (int i = 0; i < m; i++)cin >> p[i] >> x[i];

	for (int i = 0; i < m; i++) {
		cout << accumulate(t.begin(), t.end(), 0) - t[p[i]-1] + x[i] << endl;
	}
}

Measured memory_bytes: 888
import numpy as np
I=lambda:map(int,input().split())
R,G,B,N=I()
r=0
rG = N-np.array(range(N//G+1))*G
for i in range(N//R+1):
    rB=rG-i*R
    r+=np.sum((rB>=0)&(rB%B==0))
print(r)

Measured memory_bytes: 12740
// dile a la jardinera que traigo flores
// corner cases // int vs ll // cin vs scanf
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define sz(x) int(x.size())
#define fill(x,v) memset(x,v,sizeof(x))
#define FER(i,a,b) for(int i = int(a); i < int(b); ++i)
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define N 64
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int n;
ll k,a[N][N],ans[N][N];

void sum(ll &a, ll b){ a += b; if(a >= MOD) a -= MOD; }

void traceMat(ll x[N][N]){
	cout << "Matrix : " << endl;
	FER(i,0,n){
		FER(j,0,n) cout << x[i][j] << " ";
		cout << endl;
	}
}

void Init(ll x[N][N]){
	FER(i,0,n) FER(j,0,n) x[i][j] = (i == j);
}

void Cpy(ll a[N][N], ll b[N][N]){
	FER(i,0,n) FER(j,0,n) b[i][j] = a[i][j];
}

void Mult(ll a[N][N], ll b[N][N], ll c[N][N]){
	FER(i,0,n) FER(j,0,n) c[i][j] = 0;
	FER(i,0,n) FER(j,0,n) FER(k,0,n)
		sum(c[i][j],(a[i][k]*b[k][j])%MOD);
}

void Binpow(ll a[N][N], ll p, ll ans[N][N]){
	Init(ans);
	ll aux[N][N];
	while(p){
		if(p&1) Mult(ans,a,aux), Cpy(aux,ans);
		p >>= 1; Mult(a,a,aux), Cpy(aux,a);
	}
}

int main(){

	fastio;
	cin >> n >> k;
	FER(i,0,n) FER(j,0,n) cin >> a[i][j];
	Binpow(a,k,ans);
	ll x = 0;
	FER(i,0,n) FER(j,0,n) sum(x,ans[i][j]);
	cout << x << endl;

	return 0;
}


Measured memory_bytes: 512
A = []
b = []
n, m = map(int,input().split())
for i in range(n):
    A.append(list(map(int,input().split())))
for i in range(m):
    b.append(int(input()))

for i in range(n):
    c = 0
    for s in range(m):
        c += A[i][s] * b[s]
    print(c)

Measured memory_bytes: 7956
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

int main()
{
  int n;
  int h[100005];
  
  scanf("%d", &n);
  
  for (int i = 1; i <= n; i++)
    scanf("%d", &h[i]);
  
  int dp[100005];
  dp[1] = 0;
  dp[2] = abs(h[1]-h[2]);
  for (int i = 1; i <= n-2; i++)
    dp[i+2] = min(dp[i]+abs(h[i]-h[i+2]), dp[i+1]+abs(h[i+1]-h[i+2]));
  
  printf("%d\n", dp[n]);
  
  return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int arr[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n;
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>arr[i];
    int ans=0;
    for(int i=1; i<=n; i++)
    {
        if(i!=arr[i])
            continue;
        ans++;
        if(i+1<=n)
        {
            if(i+1==arr[i+1])
                i++;

        }
       // cout<<i<<" "<<ans<<endl;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4040
import scala.annotation.tailrec
object Main extends App {
  import scala.io.StdIn._
  solve
  @tailrec def solve: Unit = {
    val n = readLine.trim.toInt
    if (n == 0) return
    val squares = Array.tabulate(n){_ ⇒ Square(0, 0)}
    for (i ← 1 until n){
      val Array(a, b) = readLine.trim.split(' ').map(_.toInt)
      squares(i) = squares(a).neighbor(b)
    }
    println(
      s"${squares.map{_.x}.max - squares.map{_.x}.min + 1} ${squares.map{_.y}.max - squares.map{_.y}.min + 1}"
    )
    solve
  }
  implicit class ScopeFunc[T](private val value: T) {
    def let[A](func:(T) ⇒ A): A = func(value)
    def apply(func:(T)⇒Unit): T = {
      func(value)
      value
    }
  }
  case class Square(x:Int, y: Int){
    def neighbor(direction:Int): Square = direction match{
      case 0 ⇒ Square(x - 1, y)
      case 1 ⇒ Square(x, y - 1)
      case 2 ⇒ Square(x + 1, y)
      case 3 ⇒ Square(x, y + 1)
      case _ ⇒ throw new Exception
    }
  }
}


Measured memory_bytes: 52104
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int x;
	cin >> x;
	
	if( x >= 30 ) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}


Measured memory_bytes: 3628
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
using namespace std;
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
int dx[4]={0,0,-1,1},dy[4]={1,-1,0,0};


int main(int argc, char const *argv[]) {
  int y,m,d;
  char s,t;
  std::cin >> y >> s >> m >> t >> d;
  std::cout << (m<=4 ? "Heisei" : "TBD") << '\n';
  return 0;
}


Measured memory_bytes: 256
n = int(input())

ans = n
for i in range(0, n+1):
    count = 0
    j = n - i
    while i > 0:
        count += i % 6
        i //= 6
    
    while j > 0:
        count += j % 9
        j //= 9
        
    ans = min(ans, count)

print(ans)

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

int main(){
	int n,a,i,b;

	cin >> n;

	for(i=9;i>0;i--){
		a=n/i;
		b=n%i;
		if((a<10)&&(b==0)){
			cout << "Yes" << endl;
			break;
		}

		if(i==1){
			cout << "No" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] a = new int[n];
        PriorityQueue<Integer> queue = new PriorityQueue<Integer>(Collections.reverseOrder());
        for(int i=0;i<n;i++){
            a[i] = Integer.parseInt(sc.next());
            queue.add(a[i]);
        }
        sc.close();
        int price = 0;
        while(!queue.isEmpty() && m > 0){
            price = queue.poll();
            price/=2;
            if(price!=0){
                queue.add(price);
            }
            m--;
        }
        long res = 0;
        while(!queue.isEmpty()){
            res+=queue.poll();
        }

        System.out.println(res);
    }
    
}

Measured memory_bytes: 46888
program sample
    implicit none
    integer(8) :: i,j,k,m,n,ans
    integer(8)::a,b,c,d
    integer(8),allocatable::x(:),y(:),z(:)
  
    read(*,*) n,m
    allocate(x(n),y(m),z(m))
    read(*,*)x
    do i=1,m
        read(*,*)y(i),z(i)
    end do

    call msort(x)
    if(m>1)then
        call m2sort(z,y)
    end if
    a=n
    b=m
    c=n
    ans=0
    d=0
    do j=1,n
        if(x(a)>=z(b))then
            ans=ans+x(a)
            c=c-1
            a=a-1
            if(c==0)then
                exit
            endif
        elseif(c<=y(b))then
                ans=ans+z(b)*c
                exit
        elseif(b==1)then
                ans=ans+z(b)*y(b)
                c=c-y(b)
                b=b-1
                
                    do i=1,c
                        ans=ans+x(a)
                        a=a-1
                    end do
                    exit
        else
            ans=ans+z(b)*y(b)
                c=c-y(b)
                b=b-1      
            
        endif
    end do
    write(*,*)ans      
    stop
    contains
    recursive subroutine msort(x)
    implicit none
    integer(8), intent(inout) :: x(:)
 
    integer(8) :: n, mid, i, j, k
    integer(8), allocatable :: tmp(:)
    
    n = size(x)
    
    if(n == 1) then
      return
    end if
 
    !
    ! 前半と後半に分けてソート
    ! 1~midとmid+1~nをそれぞれソート済みにする
    !
    mid = n / 2
    call msort(x(:mid))
    call msort(x(mid+1:))
 
    !
    ! tmpという配列にxを一時的に保管
    ! マージソートは外部ソート
    !
    allocate(tmp(n))
    tmp = x
 
    ! tmpの後半部分を左右反転
    do k = n, mid+1, -1
      tmp(k) = x(mid + n - k + 1)
    end do
 
    ! iは前半のリストのうちまだ見ていないものの最小値
    ! jは後半のリストのうちまだ見ていないものの最小値
    ! kは見た回数の合計
    i = 1
    j = n
 
    do k = 1, n
      !
      ! 一番左と一番右のうち小さい方をxに入れていく
      ! ここが等号つき不等号なので、安定ソートとなる
      !
      if(tmp(i) <= tmp(j)) then
        x(k) = tmp(i)
        i = i + 1
      else
        x(k) = tmp(j)
        j = j - 1
      end if
    end do
    
    deallocate(tmp)
    return
  end subroutine msort

  recursive subroutine m2sort(x,y)
    implicit none
    integer(8), intent(inout) :: x(:),y(:)
 
    integer(8) :: n, mid, i, j, k
    integer(8), allocatable :: tmp(:),tmp2(:)
    
    n = size(x)
    
    if(n == 1) then
      return
    end if
 
    mid = n / 2
    call m2sort(x(:mid),y(:mid))
    call m2sort(x(mid+1:),y(mid+1:))
 
    !
    ! tmpという配列にxを一時的に保管
    ! マージソートは外部ソート
    !
    allocate(tmp(n),tmp2(n))
    tmp(:) = x(:)
    tmp2(:)=y(:)
    ! tmpの後半部分を左右反転
    do k = n, mid+1, -1
      tmp(k) = x(mid + n - k + 1)
      tmp2(k) = y(mid + n - k + 1)
    end do
 
    ! iは前半のリストのうちまだ見ていないものの最小値
    ! jは後半のリストのうちまだ見ていないものの最小値
    ! kは見た回数の合計
    i = 1
    j = n
 
    do k = 1, n
      !
      ! 一番左と一番右のうち小さい方をxに入れていく
      ! ここが等号つき不等号なので、安定ソートとなる
      !
      if(tmp(i) <= tmp(j)) then
        x(k) = tmp(i)
        y(k)=tmp2(i)
        i = i + 1
      else
        x(k) = tmp(j)
        y(k)=tmp2(j)
        j = j - 1
      end if
    end do
    
    deallocate(tmp,tmp2)
    return
  end subroutine m2sort
end program sample
  



Measured memory_bytes: 6656
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

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

    int n;
    cin >> n;
    vector<int> l(n), r(n);
    REP(i, n) cin >> l[i] >> r[i];

    int ans = 0;
    REP(i, n) ans += r[i] - l[i] + 1;
    cout << ans << endl;
}


Measured memory_bytes: 256
N,T = map(int,input().split())
A = list(map(int,input().split()))
cnt = 0
cur = 0
for i in range(1,N):
    b = A[i]
    a = A[i-1]
    if b-a<T:
        cur += b-a
    else:
        cnt += cur+T
        cur = 0
cnt += cur+T
print(cnt)

Measured memory_bytes: 85328
#include<stdio.h>
int main(void){
int x,y;
scanf("%d %d",&x,&y);
   for(;;){
     if(x<y){
               printf("%d %d\n",x,y);
            }else{
               printf("%d %d\n",y,x);
            }
              scanf("%d %d\n",&x,&y);
         if(x == 0 && y == 0)break;
   }
return 0;
}



Measured memory_bytes: 2044
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 100000 + 10;
int power(int a, int b){
    int res = 1;
    while(b > 0){
        if(b & 1){
            res = 1LL * res * a % mod;    
        }
        a = 1LL * a * a % mod;
        b >>= 1;
    }
    return res;
}
int main() {
    int a, f[10] = {0};
    for(int i = 0; i < 4; i++){
        scanf("%d", &a);
        f[a] = 1;
    }
    if(f[1] && f[9] && f[7] && f[4]){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
#include <string>
#include <cmath>
#include <stack>
using namespace std;
typedef long long int ll;
const ll  MOD = 1000000007;
typedef pair<ll,ll> P;

ll N;
ll a[100100];
vector<P> v;
vector<int> vv;
ll ans[100100];
int main(){
  cin >> N;
  for(ll i=1;i<=N;i++){
    cin >> a[i];
  }
  ll tmp_max=0;
  for(ll i=1;i<=N;i++){
    if(a[i] > tmp_max){
      v.push_back(make_pair(a[i],i));
      tmp_max = a[i];
    }
    else{
      vv.push_back(a[i]);
    }
  }
  ll diff=0;
  ll l = v.size();
  for(int i=0;i<v.size();i++){
    //cout << v[i].first << " " << v[i].second << endl;
    ans[v[i].second] += (v[i].first - diff) *(l-i); 
    diff = v[i].first;
  }
  sort(vv.begin(),vv.end());
  for(int i=0;i<vv.size();i++){
   // cout << " " << vv[i] << endl;
  }
  l = vv.size();
  ll pos = 0;
  diff = 0;
  for(int i=0;i<l;i++){
    if(v[pos].first >= vv[i]){
      ans[v[pos].second] += vv[i] - diff;
    }
    else{
      ans[v[pos].second] += (v[pos].first - diff) * (l-i);
      diff = v[pos].first;
      pos++;
      i--;
    }

  }
  for(int i=1;i<=N;i++){
    cout << ans[i] <<endl;
  }

}


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

int main(){
    int n; cin >> n;
    vector<int> d(n);
    rep(i,n) cin >> d[i];
    vector<int> num(100,0);
    rep(i,n){
        num[d[i]]++;
    }
    int ans = 0;
    for(int i = 1; i <= 100; i++){
        if(num[i]) ans++;
    }
    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	int N, M; cin >> N >> M;

	int k = 1;
	for (int i = 0;i < M;i++){
		k *= 2;
	}

	cout << ((N-M)*100+M*1900)*k << endl;

	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;


int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n, l; cin >> n >> l;
	vector<string> arr(n);
	for (int i = 0; i < n; ++i) cin >> arr[i];

	sort(arr.begin(), arr.end());

	string res = "";
	for (int i = 0; i < n; ++i) res += arr[i];
	cout << res << "\n";

	
	return 0;
}

Measured memory_bytes: 256
let (n,k) = cin.pair
var sset = Set<Int>()
let array: [Int] = Array((1...k).map { _ -> [Int] in 
    _ = cin.int
    return cin.array
}.joined())

print(
    (1...n).filter { !array.contains($0) }.count
)

// MARK: #### 以下、ライブラリ ####

import Foundation
#if os(Linux)
    import Glibc
#else
    import Darwin.C
#endif

enum cin {
    // 123
    static var int: Int { Int(readLine()!)! }
    // 12 23
    static var pair: (Int, Int) { let line = readLine()!.components(separatedBy: " "); return (Int(line[0])!, Int(line[1])!) }
    // 12 23 34
    static var triple: (Int, Int, Int) { let line = readLine()!.components(separatedBy: " "); return (Int(line[0])!, Int(line[1])!, Int(line[2])!) }
    // AtCoder
    static var str: String { readLine()! }
    // At Coder
    static var arrayStr: [String] { str.components(separatedBy: " ") }
    // 1 2 3 4
    static var array: [Int] { str.components(separatedBy: " ").map { Int($0)! } }
    // 1
    // 2
    // 3
    static func v_array(count: Int) -> [Int] { (0..<count).map { _ in int } }
}

extension Int {
    // 123 -> [1, 2, 3]
    var digits: [Int] { Array(String(self)).map { Int(String($0))! } }
}

extension Array where Element == Int {
    // [2, 1, 3, 2] -> 8
    var sum: Int { self.reduce(0, +) }
    // [2, 1, 3, 2] -> [1, 2, 2, 3]
    var orderBy: [Int] { sorted() }
    // [2, 1, 3, 2] -> [3, 2, 2, 1]
    var orderByDesc: [Int] { sorted(by: { $0 > $1 }) }
    // [2, 1, 3, 2] -> [2, 1, 3]
    var distinct: [Int] { Array(Set(self)) }
}

precedencegroup PowerPrecedence { higherThan: MultiplicationPrecedence }
infix operator ^^ : PowerPrecedence
func ^^ (radix: Int, power: Int) -> Int {
    return Int(pow(Double(radix), Double(power)))
}

extension String {
    // e.g. cin.line.regex(match: "^(dream|dreamer|erase|eraser)*$")
    func regex(match pattern: String) -> Bool {
        let regex = try! NSRegularExpression(pattern: pattern)
        return regex.firstMatch(in: self, range: NSRange(location: 0, length: self.count)) != nil
    }
    // "ABC"[1] -> "B"
    subscript(i: Int) -> Character {
        get {
            self[index(at: i)]
        }
        set(char) {
            var characters = Array(self)
            characters[i] = char
            self = String(characters)
        }
    }
    func index(at offset: Int) -> String.Index { index(startIndex, offsetBy: offset) }
    // "ABC".swapAt(0, 1) -> "BAC"
    mutating func swapAt(_ index1: Int, _ index2: Int) {
        var characters = Array(self)
        characters.swapAt(index1, index2)
        self = String(characters)
    }
}


Measured memory_bytes: 14244