akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  string s;
  cin >> s;
  ll n = SZ(s);
  reverse(ALL(s));

  vector<ll> f(n + 1, 0);
  ll m = 2019;
  ll cur = 1;
  f[0] = 0;

  REP(i, n) {
    ll x = s[i] - '0';
    f[i + 1] = (f[i] + x * cur) % m;
    (cur *= 10) %= m;
  }
  vector<ll> cnt(m, 0);
  REP(i, n + 1) { cnt[f[i]]++; }

  ll ans = 0;
  REP(i, m) { ans += cnt[i] * (cnt[i] - 1) / 2; }
  cout << ans << endl;
}

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

#define ll long long
#define MOD 1000000007
#define MAX 1000000



int main(){
    int x,n;
    cin>>x>>n;
    vector<int> in(102,0);
    int p;
    for(int i=0;i<n;i++){
        cin>>p;
        in.at(p)++;
    }

    int dis=99999;
    int ans;
    for(int i=0;i<=101;i++){
        if(in.at(i)==1)continue;
        if(dis>abs(x-i)){
            dis = abs(x-i);
            ans = i;
        }
    }

    cout<<ans<<endl;
}


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

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

int q;

signed main() {
  cin >> q;
  while (q--) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ans = 0;
    for (int yi = a; yi <= c; yi++) {
      for (int xi = b; xi <=d; xi++) {
        if (yi % 2 == 1 and xi % 2 == 0) {
        } else {
          ans++;
        }
      }
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3076
#include<iostream>
using namespace std;
int main() {
	int n,t=0,t2=0;
	cin>>n;
	int a[n],s[n];
	for(int cnt=0; cnt<n; cnt++) {
		cin>>a[cnt];
		t+=a[cnt];
		if(cnt%2==1)t2+=a[cnt]*2;
	}
	s[0]=t-t2;
	cout<<s[0]<<' ';
	for(int cnt=1; cnt<n; cnt++) {
		s[cnt]=a[cnt-1]*2-s[cnt-1];
		cout<<s[cnt]<<' ';
	}
}

Measured memory_bytes: 2048
from collections import defaultdict

S = input()
n = len(S)

mod = 2019
d = defaultdict(int)
d[0] = 1
num = 0
for i in reversed(range(n)):
    num += int(S[i]) * pow(10, n - i - 1, mod)
    num %= mod
    d[num] += 1

ans = 0
for v in d.values():
    ans += v * (v - 1) // 2
print(ans)


Measured memory_bytes: 74616
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define CHECKPOINT printf("CHECKPOINT\n");
typedef struct list
{
  int key;
  struct list *prev;
  struct list *next;
} *listPointer;
listPointer nil;//head list
listPointer make1list(void);//just make 1 list
void insertkey(int);//insert with key integer
void insertlist(listPointer);//insert listPointer and reconnect
void deletekey(int);//delete key integer
void deleteFirst(void);//delete first one
void deleteLast(void);//delete last one
void deletelist(listPointer);//delete listPointer and reconnect
listPointer findlist(int);//find key integer
void printlist(void);//print linked list

int main(void)
{
  int i;//counter
  int n;//the number of operations
  int data;//new key
  char op[15];//operation
  nil=make1list();
  nil->prev=nil;
  nil->next=nil;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%s%d",op,&data);
      if(strcmp(op,"insert")==0) insertkey(data);
      if(strcmp(op,"delete")==0) deletekey(data);
      if(strcmp(op,"deleteFirst")==0) deleteFirst();
      if(strcmp(op,"deleteLast")==0) deleteLast();
    }
  printlist();
  return 0;
}
listPointer make1list(void)
{
  listPointer p=malloc(sizeof(struct list));
  return p;
}
void insertkey(int data)
{
  listPointer p=make1list();
  p->key=data;
  insertlist(p);
}
void insertlist(listPointer p)
{
  p->next=nil->next;
  nil->next->prev=p;
  nil->next=p;
  p->prev=nil;
}
void deletelist(listPointer p)
{
  if(p!=nil)
    {
      p->prev->next=p->next;
      p->next->prev=p->prev;
      free(p);
    }
}
void deleteFirst(void)
{
  deletelist(nil->next);
}
void deleteLast(void)
{
  deletelist(nil->prev);
}
void deletekey(int data)
{
  listPointer p=findlist(data);
  deletelist(p);
}
listPointer findlist(int data)
{
  listPointer p;
  for(p=nil->next;p!=nil;p=p->next)
    {
      if(p->key==data) break;
    }
  return p;
}
void printlist(void)
{
  int flag=0;
  listPointer p;
  for(p=nil;p->next!=nil;p=p->next)
    {
      if(flag) printf(" ");
      else flag=1;
      printf("%d",p->next->key);
    }
  printf("\n");
}



Measured memory_bytes: 32980
#include<iostream>

using namespace std ;

int main()
{
	int len ,n ,ans = 0 ;
	cin >> len  ;
	int arry_[ len ] ;

	for( int i = 0 ; i < len ; i++ )
		cin >> arry_[ i ] ;

	cin >> len ;

	for( int i = 0 ; i < len ; i++ )
	{
		cin >> n ;
		for( int j = 0 ; j < sizeof arry_ / sizeof( int ) ; j++ )
		{
			if( n == arry_[ j ] )
			{
				ans++ ;
				break ;
			}
		}
	}

	cout << ans << endl ;

	return 0 ;
}

Measured memory_bytes: 3092
# RL
# 0, 11
# 1, 11
# 2, 11
# 3. 11
# 4, 11 1回で収束して以降は同じ

# RRL
# 0, 111
# 1, 021
# 2, 012
# 3. 021
# 4, 012 1回で収束して以降は振動する


# RRLL
# 0, 1111
# 1, 0220
# 2, 0220
# 3, 0220
# 4, 0220 1回で収束して以降は振動(差分0だけど)

# RRRLL
# 0, 11111
# 1, 01220
# 2, 00320
# 3, 00230
# 4, 0033000 2回で収束して以降は振動

# RRLLL
# 0, 11111
# 1, 02210
# 2, 02300
# 3, 03200
# 4, 02300 2回で収束して以降は振動

# RRRLLL
# 0, 111111
# 1, 012210
# 2, 003300
# 3, 003300
# 4, 0033000 2回で収束して以降は振動

# RRRRRR...RLLL....L の時、max(len(R), len(L)) - 1回で 0, 0, 0,len(R), len(L), 0, 0, 0, に収束してそう

# RR|LLL
# ab|cde

#  a|be
#  c|d

#  b|a
#  d|e
#   |c
# 以降振動

# 境界から距離が奇数のRは左、偶数は右, RRLLL ->   01100
# 境界から距離が奇数のLは右、偶数は左, RRLLL -> + 01200
#                                               = 02300
import math
s = input()
rrr = [0] * len(s)
lll = [0] * len(s)
ct = 0
for i in range(len(s)):
    if s[i] == 'R':
        ct += 1
    elif ct != 0:
        rrr[i-1] = math.ceil(ct/2)
        rrr[i] = math.floor(ct/2)
        ct = 0
s = s[::-1]
for i in range(len(s)):
    if s[i] == 'L':
        ct += 1
    elif ct != 0:
        lll[i-1] = math.ceil(ct/2)
        lll[i] = math.floor(ct/2)
        ct = 0
lll = lll[::-1]
#print(s[::-1])
#print(rrr)
#print(lll)
print(' '.join(map(str, [r+l for (r,l) in zip(rrr, lll)])))

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

int main() {
	int N;
	cin >> N;
	vector<int> A(N), B(N);
	for (int i = 0; i < N; i++) cin >> A[i] >> B[i];
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());

	if (N % 2 == 0) {
		int Amin = A[N / 2 - 1] + A[N / 2];
		int Bmax = B[N / 2 - 1] + B[N / 2];
		cout << Bmax - Amin + 1 << endl;
	}
	else {
		int Amin = A[(N - 1) / 2];
		int Bmax = B[(N - 1) / 2];
		cout << Bmax - Amin + 1 << endl;
	}

}


Measured memory_bytes: 4792
#include<bits/stdc++.h>
using namespace std;
int main()
{
	map<long long,long long> mp;
	long long n;
	cin>>n;
	vector<long long> vi;
	for(long long i=0;i<n;i++)
	{
		long long a;
		cin>>a;
		vi.push_back(a);
		mp[a]++;
	}
	long long sum = 0;
	for(map<long long,long long>::iterator it = mp.begin();it!=mp.end();it++)
	{
		long long k = it->second;
		sum+=(k*(k-1))/2;
	}
	for(long long i=0;i<n;i++)
	{
		long long m = sum;
		long long u = mp[vi[i]];
		long long no = u-1;
		cout<<m-no<<endl;
	}
	return 0;
}

Measured memory_bytes: 11120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);i++)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;i--)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> void chmin(T& t, const U& u){if(t>u)t=u;}
template<typename T,typename U> void chmax(T& t, const U& u){if(t<u)t=u;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T mpow(T a, T n) {
   T res = 1;
   for(;n;n>>=1) {
	  if (n & 1) res = res * a;
	  a = a * a;
   }
   return res;
}

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



signed main(){
	int n,cnt=1;cin>>n;
	vector<bool> v(1000100,false);
	while(1){
		if(v[n]){
			cout<<cnt<<endl;
			return 0;
		}

		v[n]=true;
		if(n%2==0){
			n/=2;
		}else{
			n=3*n+1;
		}
		cnt++;
	}
}

Measured memory_bytes: 384
import itertools
import math
n = int(input())
p = input().split()
q = input().split()

p_mojiretu = ""
q_mojiretu = ""

for x in p:
    p_mojiretu += x
for x in q:
    q_mojiretu += x


cnt = 1
index_a = 0
index_b = 0

for i in itertools.permutations(range(1, n+1)):
    s = "".join(str(x) for x in i)
    if s == p_mojiretu:
        index_a = cnt
    if s == q_mojiretu:
        index_b = cnt
    cnt += 1
print(abs(index_a - index_b))


Measured memory_bytes: 3064
n = int(input())
e = tuple(tuple(map(int, input().split())) for _ in range(n))

dp = [[0] * 3 for _ in range(n + 1)]

for i in range(1, n + 1):
    for j in range(3):
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + e[i - 1][0]
        dp[i][1] = max(dp[i - 1][2], dp[i - 1][0]) + e[i - 1][1]
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + e[i - 1][2]

print(max(dp[n]))


Measured memory_bytes: 40176
#include<stdio.h>
#include<stdlib.h>
int main()
{
	int n;
	scanf("%d",&n);
	int *a = NULL,*b=NULL;
	b = (int *)malloc(sizeof(int)*n);
	a = (int *)malloc(sizeof(int)*n);
	int i,x,y;
	x = y = n / 2;
	for (i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
		if (n % 2 == 1)
		{
			if (i % 2 == 0)  b[x--] = a[i];
			else b[++y] = a[i];
		}
		else
		{
			if (i % 2 == 0)  b[x++] = a[i];
			else b[--y] = a[i];
		}
	}
	for (i = 0; i < n; i++)
		printf("%d ", b[i]);
	free(a);
	free(b);
	return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
int main(){
  int i,j,a[100],n,minj,count=0;
  cin>>n;
  for(i=0;i<n;i++){
    cin>>a[i];
  }
  
  for(i=0;i<n;i++){
    minj=i;
    for(j=i;j<n;j++)if(a[j]<a[minj])minj=j;
    if(i!=minj){
      swap(a[i],a[minj]);
      count++;
    }
  }
  
  for(i=0;i<n;i++){
    if(i==n-1)cout<<a[i];
    else cout<<a[i]<<" ";
  }
  cout<<endl;
  cout<<count<<endl;
  return 0;
}

    




Measured memory_bytes: 3088
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <string>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define MAX_N 100000
int par[MAX_N];
int rnk[MAX_N];
struct point { int index; int X; int Y; };
struct edge { point st; point fin; };
vector <point> p;
vector <edge> e;
void init(int 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 par[x] = find(par[x]);
	}
}
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y) return;
	if (rnk[x] < rnk[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rnk[x] == rnk[y]) rnk[x]++;
	}
}
bool same(int x, int y) {
	return find(x) == find(y);
}
int norm(edge E) {
	return min({abs(E.st.X-E.fin.X),abs(E.st.Y-E.fin.Y)});
}
bool lessX(const point& p1, const point& p2) { return (p1).X < (p2).X; };
bool lessY(const point& p1, const point& p2) { return (p1).Y < (p2).Y; };
int main(void) {
	int N;
	cin >> N;
	int x, y;
	for (int i = 0; i < N; i++) {
		cin >> x >> y;
		p.push_back({ i,x,y });
	}
	sort(p.begin(), p.end(), lessX);
	int k = 0;
	for (int i = 1; i < N; i++) {
		e.push_back( {p[i - 1], p[i] });
		k++;
	}
	sort(p.begin(), p.end(), lessY);
	for (int i = 1; i < N; i++) {
		e.push_back({ p[i - 1],p[i] });
		k++;
	}
	sort(e.begin(), e.end(), [](edge e1, edge e2) {return norm(e1) < norm(e2); });
	int ans = 0;
	init(N);
	for (int i = 0; i < 2 * N - 2; i++) {
		if (!(same(e[i].st.index, e[i].fin.index))) {
			unite(e[i].st.index, e[i].fin.index);
			ans += norm(e[i]);
		}
	}
	cout << ans << endl;
	return 0;
}

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

#define ll long long
#define MOD 1000000007




int main(){
    int k,s;
    cin>>k>>s;

    ll co=0;
    int z;
    for(int i=0;i<=k;i++){
        for(int j=0;j<=k;j++){
            z = s-(i+j);
            if(z<=k&&z>=0)co++;
        }
    }

    cout<<co<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <functional>
#include <map>
#include <set>
#include <stack>
#include <deque>

//#define INF 1000000000;
#define MOD 1000000007;
#define LIMIT 1000000000000000000;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
typedef pair<int, int> P;

char cap(const string& s) {
    return s[0] + ('A' - 'a');
}

int main()
{
    string a, b, c; cin >> a >> b >> c;
    cout << cap(a) << cap(b) << cap(c) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define numrep(i,n) for(int i=1;i<=n;i++)
#define bitrep(n) for(int bit=0;bit<(1<<n);bit++)
#define ll int64_t
#define all(v) v.begin(), v.end()

const int MOD = 1000000007;

int main() {
  int X,N;
  cin >> X >> N;
  vector<int> p(N);
  rep(i,N) cin >> p[i];//input

  int sub=1000,ans=X;

    for(int i=-100;i<=110;i++){
      bool e=false;
      rep(j,N) if(p[j]==i) e=true;
      if(e==true) continue;

      if(abs(X-i)<sub){
        sub=abs(X-i);
        ans=i;
      }
          
    }

  cout << ans <<endl;
  

return 0;

}

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

const int INF = 0x3f3f3f3f;

int c[13], a[13][13], b[13];

int main()
{
    int n, m, x;
    cin >> n >> m >> x;
    rep(i, n) {
        cin >> c[i];
        rep(j, m) cin >> a[i][j];
    }
    int ans = INF;
    rep(_, (1<<n)) {
        memset(b, 0, sizeof b);
        rep(i, n) if((1<<i) & _) rep(j, m) b[j] += a[i][j];
        bool flag = true;
        rep(i, m) if(b[i] < x) flag = false;
        if(flag) {
            int sum = 0;
            rep(i, n) if((1<<i) & _) sum += c[i];
            ans = min(ans, sum);
        }
    }
    if(ans == INF) ans = -1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    priority_queue <int> maxpq;
    cin >> n >> k;
    REP(i, n){
        int l;
        cin >> l;
        maxpq.push(l);
    }
    int sum = 0;
    REP(i, k){
        sum += maxpq.top();
        maxpq.pop();
    }
    cout << sum << "\n";


    return 0;
}


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

int main()
{
    int n,m,ans=0;
    while(cin >> n >> m)
    {
        ans = 0;
        int p[m],d[m-1];
        for (int ctr = 0;ctr<m;ctr++)
        {
            cin >>p[ctr];
        }
        if (n>=m)
        {
            cout << 0 <<endl;
        }
        else
        {
            sort(&p[0],&p[m]);
            ans = p[m-1]-p[0];
            for (int ctr = 0;ctr<m-1;ctr++)
            {
                d[ctr]=p[ctr+1]-p[ctr];

            }
            sort(&d[0],&d[m-1]);
            for(int ctr = 0;ctr<n-1;ctr++)
            {
                ans-=d[m-2-ctr];

            }
            cout << ans << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int N,K,X,Y,sum;
	cin>>N>>K>>X>>Y;
	if(N<=K)
	{
		sum=N*X;
		
	}
	if(N>K)
	{
		sum=K*X+(N-K)*Y;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
from heapq import heappush, heappop

def main():
  n, m = map(int, input().split())
  edges = [[] for _ in range(n)]
  for _ in range(m):
    x, y, t = map(int, input().split())
    x -= 1
    y -= 1
    edges[x].append((y, t))
    edges[y].append((x, t))
  
  v0 = int(input())
  a, b, c = map(int, input().split())
  v_next = {}
  v = v0
  while True:
    if v not in v_next:
      v_next[v] = (v * a + b) % c
      v = (v * a + b) % c
    else:break

  dic = {}
  dic[(v0, 0)] = 0
  que = []
  heappush(que, (0, 0, v0))
  while que:
    score, node, v = heappop(que)
    new_v = v_next[v]
    for to, t in edges[node]:
      new_score = score + v * t
      if (new_v, to) not in dic or dic[(new_v, to)] > new_score:
        dic[(new_v, to)] = new_score
        heappush(que, (new_score, to, new_v))
  
  dic2 = {}
  que = []
  for v in range(c):
    if (v, n - 1) in dic:
      dic2[(v, n - 1)] = dic[(v, n - 1)]
      heappush(que, (dic[(v, n - 1)], n - 1, v))
  
  while que:
    score, node, v = heappop(que)
    if node == 0:
      print(score)
      break
    new_v = v_next[v]
    for to, t in edges[node]:
      new_score = score + v * t
      if (new_v, to) not in dic2 or dic2[(new_v, to)] > new_score:
        dic2[(new_v, to)] = new_score
        heappush(que, (new_score, to, new_v))
main() 


Measured memory_bytes: 20308
#include <stdio.h>
#include <math.h>
const double eps=1e-9;
double ABS(double n){return n>=0?n:-n;}
bool same(double a,double b){return ABS(a-b)<eps;}
struct point{
	double x;
	double y;
	point(){}
	point(double a,double b){x=a;y=b;}
	point operator +(const point &a){return point(x+a.x,y+a.y);}
	point operator -(const point &a){return point(x-a.x,y-a.y);}
	point operator *(const double &a){return point(x*a,y*a);}
	point operator /(const double &a){return point(x/a,y/a);}
	void operator =(const point &a){x=a.x;y=a.y;}
	void operator +=(const point &a){x+=a.x;y+=a.y;}
	void operator -=(const point &a){x-=a.x;y-=a.y;}
	void operator *=(const double &a){x*=a;y*=a;}
	void operator /=(const double &a){x/=a;y/=a;}
	bool operator <(const point &a){return x<a.x||(same(x,a.x)&&y<a.y);}
	bool operator ==(const point &a){return same(x,a.x)&&same(y,a.y);}
	double length(){return sqrt(x*x+y*y);}
	void in(){scanf("%lf%lf",&x,&y);}
	void out(){printf("%.20lf %.20lf\n",x,y);}
};
struct segment{
	point a;
	point b;
	segment(){}
	segment(point x,point y){a=x;b=y;}
};
struct line{
	double A;
	double B;
	double C;
	line(){}
	line(double a,double b,double c){A=a;B=b;C=c;}
	line(point a,point b){
		A=a.y-b.y;
		B=b.x-a.x;
		C=A*a.x+B*a.y;
	}
	line(double a,double b,point p){
		A=a;
		B=b;
		C=A*p.x+B*p.y;
	}
	line(segment s){
		A=s.a.y-s.b.y;
		B=s.b.x-s.a.x;
		C=A*s.a.x+B*s.a.y;
	}
};
double dist(point a,point b){return (a-b).length();}
double dot(point a,point b){return a.x*b.x+a.y*b.y;}
double cross(point a,point b){return a.x*b.y-b.x*a.y;}
//angle only returns positive value
double angle(point a,point b){return acos(dot(a,b)/(a.length()*b.length()));}
double area(point a,point b,point c){return ABS(cross(b-a,c-a));}
double distancetoline(point a,line b){return (b.A*a.x+b.B*a.y-b.C)/sqrt(b.A*b.A+b.B*b.B);}
bool parallel(line a,line b){return same(a.A*b.B,b.A*a.B);}
point intersect(line a,line b){
	double x,y,det;
	x=(a.C*b.B-b.C*a.B);
	y=(a.A*b.C-b.A*a.C);
	det=(a.A*b.B-b.A*a.B);
	return point(x,y)/det;
}
/*
bool intersect(segment a,segment b){}
point intersect(segment a,segment b){}
*/
point projection(point a,line b){return intersect(line(b.B,-b.A,a),b);}
point reflection(point a,line b){return projection(a,b)*2-a;}
bool online(point p,line l){return ABS(l.A*p.x+l.B*p.y-l.C)<eps;}
bool between(point a,point b,point c){
	if((a.x-b.x<=eps&&b.x-c.x<=eps)||(eps>=b.x-a.x&&eps>=c.x-b.x))
	if((a.y-b.y<=eps&&b.y-c.y<=eps)||(eps>=b.y-a.y&&eps>=c.y-b.y))
	return true;
	return false;
}
int main(){
	point from,to,p;
	int q;
	line l;
	from.in();
	to.in();
	l=line(from,to);
	scanf("%d",&q);
	while(q--){
		p.in();
		if(online(p,l)){
			if(between(from,p,to))printf("ON_SEGMENT\n");
			else if(between(from,to,p))printf("ONLINE_FRONT\n");
			else if(between(p,from,to))printf("ONLINE_BACK\n");
			else printf("wronged!!\n");
		}
		else{
			if(cross(to-from,p-from)>=-eps)printf("COUNTER_CLOCKWISE\n");
			else if(cross(to-from,p-from)<=eps)printf("CLOCKWISE\n");
			else printf("wronged!!\n");
		}
	}
}



Measured memory_bytes: 2740
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Gput(a, b) G[a].push_back(b)
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    if (k <= a)
    {
        putout(k);
        return 0;
    }
    if (k>a&&k<=a+b){
        putout(a);
        return 0;
    }
    if(k>a+b){
        putout(2*a+b-k);
    }
        return 0;
}


Measured memory_bytes: 3624
# coding: utf-8

def _main():
    text = input()
    A, B, K = [int(i) for i in text.split(' ')]

    diviser_list = []
    num = 1
    min_num = min(A, B)

    while num <= min_num:
        if A%num == 0 and B%num == 0:
            diviser_list.append(num)

        num += 1

    print(diviser_list[-K])

if __name__ == '__main__':
    _main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define INF 1000000000
#define MAX_V 1000
#define MAX_E 2000
using namespace std;

struct edge { int from, to, cost; };
int V, E, r;
int d[MAX_V];

edge es[MAX_E];

bool Bellman_Ford(int start) {
	fill(d, d + V, INF);
	d[start] = 0;
	bool update;
	for (int i = 0; i < V; i++) {
		update = false;
		for (int j = 0; j < E; j++) {
			edge e = es[j];
			if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}
		if (!update) return false;
	}
	return true;
}

int main()
{
	int r;
	cin >> V >> E >> r;
	for (int i = 0; i < E; i++)
		cin >> es[i].from >> es[i].to >> es[i].cost;

	if (!Bellman_Ford(r)) {
		for (int i = 0; i < V; i++) {
			if (d[i] == INF)
				cout << "INF" << endl;
			else
				cout << d[i] << endl;
		}
	}
	else {
		cout << "NEGATIVE CYCLE" << endl;
	}
	return 0;
}

Measured memory_bytes: 3116
N,P=map(int,input().split())

def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0:
        cnt+=1
        temp //= i
      arr.append([i, cnt])

  if temp!=1:
    arr.append([temp, 1])

  if arr==[]:
    arr.append([n, 1])

  return arr

A=factorization(P) 
x=len(A)
ans=1
for i in range(x):
  x=(A[i][1]//N)
  if x>0:
    ans*=A[i][0]**x
print(ans)

Measured memory_bytes: 3188
#include <iostream>
    #include <string>
    #include <set>  
    #include <algorithm>
    #include <vector>
    #include <cmath>
    #include <queue>
    #include <deque>
    #include <cstring>
    #include <cstdio>
    #include <map>
    #include <numeric>
    #include <cassert>
    #include <iomanip>
    #include <sstream>
using namespace std;
const int MAXN=1e5+5;
int n,cnt[2];
vector<int> g[MAXN],mid;
set<int> bw[2];
bool vis1[MAXN],vis[MAXN],col[MAXN];
bool dfs1(int x,int cc)
{
	vis1[x]=1;
	if(x==n-1)
		cc=1;
	col[x]=cc;
	bool f=0,F=0;
	for(int i=0;i<g[x].size();i++)
		if(!vis1[g[x][i]])
		{
			f=dfs1(g[x][i],cc);
			F|=f;
			if(f&&!cc&&x)
			{
				mid.push_back(x);
				vis[x]=1;
			}
		}
	return cc||F;
}
void dfs(int x)
{
	col[x]=1;
	for(int i=0;i<g[x].size();i++)
	{
		if(col[g[x][i]]||vis[g[x][i]])continue;
			dfs(g[x][i]);
	}
}
int main()
{
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int x,y;
		cin>>x>>y;
		x--,y--;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	col[0]=0;
	col[n-1]=1;
	dfs1(0,0);
	/*for(int i=0;i<mid.size();i++)
		cout<<mid[i]+1<<" ";*/
	for(int i=0;i<mid.size()/2;i++)
	{
		col[mid[i]]=1;
		dfs(mid[i]);
	}
	/*for(int i=0;i<n;i++)
		cout<<col[i]<<" ";*/
	for(int i=0;i<n;i++)
		cnt[col[i]]++;
		cout<<(cnt[0]<=cnt[1]?"Snuke":"Fennec")<<endl;
	return 0;
}

Measured memory_bytes: 12924
#include <iostream>
#include <algorithm>
using namespace std;
using uint = unsigned;
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    uint a,b,k;
    cin >> a >> b >> k;
    const uint m = min(a,b);
    uint ans = 0;
    uint cnt = 0;
    for(uint i = m; i > 0; i--) {
        if (a % i == 0 && b % i == 0) {
            ans = i;
            cnt++;
        }
        if (cnt == k) {
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


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



int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n), b(n), minus(n);
  rep(i, n) cin >> a[i];

  rep(i, k) {
    bool all_n = true;
    rep(j, n) if (a[j] < n) all_n = false;
    if (all_n) break;

    int tot = 0;
    rep(j, n) {b[j] = 1; minus[j] = 0;}
    rep(j, n) {
      b[j] += tot;
      tot -= minus[j];
      if (j + a[j] < n - 1) {
        minus[a[j] + j]++;
      }
      if (a[j] > 0) tot++;
      //cout << "l to r " << tot << endl;
      //rep(l, n) cout << minus[l] << " "; cout << endl;
      //rep(l, n) cout << b[l] << " "; cout << endl; cout << endl;
    }

    tot = 0;
    rep(j, n) minus[j] = 0;
    for (int j=n-1; j>=0; j--) {
      b[j] += tot;
      tot -= minus[j];
      if (j - a[j] >= 0) {
        minus[j - a[j]]++;
      }
      if (a[j] > 0) tot++;
      //cout << "r to l " << tot << endl;
      //rep(l, n) cout << minus[l] << " "; cout << endl;
      //rep(l, n) cout << b[l] << " "; cout << endl; cout << endl;
    }

    rep(j, n) a[j] = b[j];
  }

  rep(i, n) cout << a[i] << endl;

  return 0;
}

/*
*/


Measured memory_bytes: 5616
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p){os<<"("<<p.first<<","<< p.second<<")";return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v){os<<"{";REP(i,(int)v.size()){if(i)os<<",";os<<v[i];}os<<"}";return os;}
template <typename T, size_t S> void printArray(const T (&array)[S]){for(auto val : array)std::cout << val << ", ";std::cout << "\n";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
//const int dx[4] = {1, 0, -1, 0};
//const int dy[4] = {0, 1, 0, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve(){
    string s;
    cin >> s;
    int res = 0;
    REP(i, s.size()){
        if(s[i] == '+') res++;
        else res--;
    }
    cout << res << endl;
}

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

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())
c = 0
for i in range(A+1):
  for j in range(B+1):
    for k in range(C+1):
      if (500 * i + 100 * j + 50 * k) == X:
        c += 1
      else:
        continue
print(c)

Measured memory_bytes: 9176
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

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

  int next=0;
  int ans=0;
  while(1){
    ++ans;
    next=a.at(next);
    if(next==1) break;
    if(ans>N){
      ans=-1;
      break;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3756
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <locale>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int solve(int n) {
    int ans = 0;
    for (int sentou = 1; sentou < 1000; sentou++) {
        for (int kousuu = 2; kousuu < 1000; kousuu++) {
            if (kousuu * (2 * sentou + kousuu - 1) / 2 == n) {
                ans++;
                // cout << sentou << " " << kousuu << endl;
            }
        }
    }
    return ans;
}

int main(int argc, char const *argv[]) {
    cin.tie(0);

    int n;
    vector<int> ans;
    while (1) {
        cin >> n;
        if (n == 0) break;
        ans.push_back(solve(n));
    }
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 3016
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        a: u64, b: u64, k: u64
    };

    let sub = a.min(k);
    let a = a - sub;
    let rest_k = k - sub;
    let sub = b.min(rest_k);
    let b = b - sub;
    println!("{} {}", a, b);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 2276
#include<cstdio>
#include<cstring>
using namespace std;
char s[200100];
int cnt[30]; long long ans;
int main(){
	scanf("%s",s);
	int len=strlen(s);
	long long ans=1LL*len*(len+1)/2;
	for (int i=0; i<len; i++) cnt[s[i]-'a']++;
	for (int i=0; i<26; i++) ans-=1LL*cnt[i]*(cnt[i]+1)/2;
	printf("%lld\n",ans+1);
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void) {
    int building1[3][10] = {{},{},{}};
    int building2[3][10] = {{},{},{}};
    int building3[3][10] = {{},{},{}};
    int building4[3][10] = {{},{},{}};

    int n, b, f, r, v;
    
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        scanf("%d %d %d %d", &b, &f, &r, &v);

        if (b == 1) building1[f - 1][r - 1] += v;
        else if (b == 2) building2[f - 1][r - 1] += v;
        else if (b == 3) building3[f - 1][r - 1] += v;
        else building4[f - 1][r - 1] += v;
    }

    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 10; k++) {
                if (i == 0) printf(" %d", building1[j][k]);
                else if (i == 1) printf(" %d", building2[j][k]);
                else if (i == 2) printf(" %d", building3[j][k]);
                else printf(" %d", building4[j][k]);
            }
            printf("\n");
        }
        if (i < 3)printf("####################\n");
    }

    return 0;
}


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

#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define vvi vector<vi>
#define vb vector<bool>
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define INF int(1e9)

using namespace std;

int main () {
    ios_base::sync_with_stdio(false);

    int n, m;

    cin >> n >> m;
    int sum = 0;
    vi arr(n);

    for(int i=0; i<arr.size(); i++) cin >> arr[i], sum+=arr[i];


    double val = 1/(4.0*m);

    int count = 0;

    for(int i=0; i<arr.size(); i++){
        double v = (double)arr[i]/sum;
        if(v>=val)
            count++;
    }

    if(count>=m)
        cout << "Yes" <<endl;
    else cout << "No" << endl;

    return 0;
}

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

int n, col[205];
int a[205][205];
int dis[205][205];
char s[205];
queue<int> Q;

void check() {
	col[1] = 1;
	Q.push(1);
	while (!Q.empty()) {
		int x = Q.front(); Q.pop();
		for (int i = 1; i <= n; ++i) {
			if (!a[x][i]) continue;
			if (!col[i]) {
				col[i] = 3 - col[x];
				Q.push(i);
			}
			else {
				if (col[i] == col[x]) {
					puts("-1");
					exit(0);
				}
			}
		}
	}
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%s", s + 1);
		for (int j = 1; j <= n; ++j) {
			a[i][j] = (s[j] - '0');
		}
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			if (i == j) dis[i][j] = 0;
			else dis[i][j] = a[i][j] ? 1 : n + 1;
		}
	}
	for (int k = 1; k <= n; ++k) {
		for (int i = 1; i <= n; ++i) {
			for (int j = 1; j <= n; ++j) {
				dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
			}
		}
	}
	int u = 1, v = 1;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			if (dis[i][j] > dis[u][v]) {
				u = i;
				v = j;
			}
		}
	}
	int ans = dis[u][v];
	check();
	cout << ans + 1 << endl;
	return 0;
}


Measured memory_bytes: 640
program aaa
implicit none
 
integer :: one, two, three, four
integer, dimension(26) :: h = [2,3,5,7,11,13,17,19,23,29,31,37,&
41,43,47,53,59,61,67,71,73,79,83,89,97,101]
integer :: a, b, c
character(4) :: s
 
read*, s
 
one=h(iachar(s(1:1))-64)
two=h(iachar(s(2:2))-64)
three=h(iachar(s(3:3))-64)
four=h(iachar(s(4:4))-64)
 
a=(one*two)-(three*four)
b=(one*three)-(two*four)
c=(one*four)-(two*three)
 
if(a==b.and.a==c) then
write(*,'(a2)') 'No'
return
end if

if(a==0.or.b==0.or.c==0) then
write(*,'(a3)') 'Yes'
else
write(*,'(a2)') 'No'
end if
 
end program

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (int i = f; i < t; i++)
#define pr(i, f, t) for (int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()

int main()
{
    ll k;
    cin >> k;
    vl run;
    rp(i, 0, 10) run.push_back(i);

    ll co = 9;
    ll kk = 1;

    while (co <= k)
    {
        ll s = run.size();

        rp(i, 0, s)
        {
            ll up = run[i];

            ll co2 = 1;

            while (up >= 10)
            {
                co2++;
                up /= 10;
            }

            if (co2 != kk && up <= 1)
            {
                run.push_back(1 * pow(10, kk) + run[i]);
                co++;
            }
            if (co2 == kk)
            {
                if (up > 0)
                {
                    run.push_back(up * pow(10, kk) + run[i]);
                    co++;
                }
                if (up - 1 > 0)
                {
                    run.push_back((up - 1) * pow(10, kk) + run[i]);
                    co++;
                }
                if (up + 1 < 10)
                {
                    run.push_back((up + 1) * pow(10, kk) + run[i]);
                    co++;
                }
            }
        }
        kk++;
    }
    sort(be(run));
    cout << run[k] << endl;
    // ca(200, run);
}

Measured memory_bytes: 2420
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int a[] = new int[n];
    int total = 0;
    for(int i = 0;i<n;i++){
      a[i] = sc.nextInt();
      total += a[i];
    }
    int count = 0;
    for(int i = 0;i<n;i++){
      if(a[i] * 4 * m >= total){
        count++;
      }
    }
    if(count >= m){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 23252
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int L, N, M;
	static int[][] data;
	public static void main(String[] args) {
		while(read()){
			solve();
		}
	}
	static boolean read(){
		L = sc.nextInt();
		if(L == 0)
			return false;
		data = new int[13][13];
		for(int i = 1; i <= 12; i++){
			M = sc.nextInt(); N = sc.nextInt();
			data[0][i] = M; data[1][i] = N;
		}
		return true;
	}
	static int solve(){
		int wedge = 0;
		for(int i = 1; i <= 12; i++){
			wedge += data[0][i] - data[1][i];
			if(wedge >= L){
				System.out.println(i);
				return 0;
			}
		}
		System.out.println("NA");
		return 0;
	}

}

Measured memory_bytes: 12000
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
#![macro_use]

use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::mem::*;
use std::num::*;
use std::ops::*;
use std::slice::*;
use std::*;

const MOD: isize = 1000000007;
fn main() {
    let (N, M) = {
        let v = read_vec::<usize>();
        (v[0], v[1])
    };
    let f = |x: usize| {
        if x > 0 {
            x * (x - 1) / 2
        } else {
            0
        }
    };
    println!("{}", f(N) + f(M));
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace() // iter
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  int i;
  int ans = 0;
  for(i = 0; i < n; i++)
  {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  for(i = 0; i < n; i++)
  {
    if(i%2==0)
    {
      ans += a.at(i);
    }
    else
    {
      ans -= a.at(i);
    }
  }
  cout << ans << endl;
}

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


int main(){
	string S, T;
	cin >> S >> T;
	int N, M;
	N = S.size();
	M = T.size();
	int ok = 2;
	if(N > M) ok = 0;
	else if (N < M) ok = 1;
	else{
		rep(i,N){
			int a, b;
			a = S[i] - '0';
			b = T[i] - '0';
			if(a > b) {
				ok = 0;
				break;
			}
			else if(a < b){
			    ok = 1;
				break;
			}
		}
	}
	if(ok == 0) cout << "GREATER" << endl;
	else if(ok == 1) cout << "LESS" << endl;
	else cout << "EQUAL" << endl;
}













Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define randome_generate srand(std::chrono::high_resolution_clock::now().time_since_epoch().count())
using namespace std;
int n,p;
long long m,v,a[100100];
bool ok(int mid){
	int kk=n-p;
	long long s=0LL;
	for(int i=n;kk;i--){
		if(i==mid)
			continue;
		if(a[mid]-a[i]>m)
			return false;
		s+=(max(a[mid]-a[i],0LL));
		kk--;
	}
	return (s<=1LL*m*v);
}
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m>>v>>p;
	v=n-v;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		a[i]=1e9-a[i];
	}
	sort(a+1,a+n+1);
	int l=1,r=n,mid;
	while(l<r){
		mid=(l+r+1)>>1;
		if(ok(mid))
			l=mid;
		else
			r=mid-1;
	}
	cout<<l<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const ll max_co = 3234600000;
int mod =1000000007;
int main(){
   ll n ;
   cin>>n;
   cout<<(n*(n-1))/2<<endl;
}


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

int main()
{
	int64_t n, q;
	cin >> n >> q;
	vector<int64_t> as(n - 1), bs(n - 1);
	for (int64_t i = 0; i < n - 1; i++)
	{
		cin >> as[i] >> bs[i];
		as[i]--;
		bs[i]--;
	}

	vector<vector<int64_t>> g(n);
	for (int64_t i = 0; i < n - 1; i++)
	{
		g[as[i]].emplace_back(bs[i]);
		g[bs[i]].emplace_back(as[i]);
	}

	vector<int64_t> add(n, 0);

	for (int64_t i = 0; i < q; i++)
	{
		int64_t p, x;
		cin >> p >> x;
		p--;
		add[p] += x;
	}

	vector<int64_t> ans(n, 0);

	auto solve = [&](auto &f, int64_t now = 0, int64_t par = -1, int64_t ap = 0) -> void {
		ap += add[now];

		ans[now] += ap;

		for (int64_t next : g[now])
		{
			if (next == par)
			{
				continue;
			}
			f(f, next, now, ap);
		}
	};

	solve(solve);

	for (auto &x : ans)
	{
		cout << x << ' ';
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 26496
import sys
# input = sys.stdin.buffer.readline
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)

S = input()
n = len(S)

def kaibun(s):
    n = len(s)
    for i in range(n//2):
        if s[i] != s[-1-i]:
            return False
    return True

if kaibun(S) and kaibun(S[:n//2]) and kaibun(S[n//2+1:]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define endl "\n"
#define fo for(int i=0;i<n;i++)
#define clear cin.clear();cin.ignore(numeric_limits<streamsize>::max(), '\n');
#define loopSolve int t; cin>>t; while(t--){solve();}
//INT_MAX         2,147,483,647                       <10^10
//U_INT_MAX       4,294,967,295                       <10^10
//LONG_LONG_MAX   9,223,372,036,854,775,807           <10^18
//U_LONG_LONG_MAX 18,446,744,073,709,551,615          <10^18
//ll power(int a, int b){
//    return (ll)(pow(a,b)+0.5);
//}

vector<int> gV(int n){
    vector<int> v(n);
    int input;
    fo { cin>>v[i];  }
    return v;
}

int* gA(int n){
    int* arr = new int[n];
    fo cin>>arr[i];
    return arr;
}


void solve(){
    int N;
    cin>>N;
    map<string,int> mp;
    string s;
    for(int i=0;i<N;i++){
        cin>>s;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;
}


int main() {
	ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);

    solve();
    //loopSolve;

	return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); 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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll h, w;
  cin >> h >> w;
  rep(i, h+2) {
    rep(j, w+2) {
      if (i==0 || i==h+1) {
        cout << '#';
      } else {
        if (j==0 || j==w+1) {
          cout << '#';
        } else {
          char a;
          cin >> a;
          cout << a;
        }
      }
    }
    cout << endl;
  }
}

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




int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << min(a,b) + min(c,d) << endl;

    return 0;
}





Measured memory_bytes: 256