akhauriyash/Code-Regression huggingface dataset:
// NK
#include <bits/stdc++.h>
using namespace std;
#define ii pair<int,int>
#define ll long long
#define vi vector<int>
#define vii vector<ii>
#define vll vector<ll>
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define psf push_front
#define pof pop_front
#define mkp make_pair
#define mkt make_tuple
#define all(x) x.begin(), x.end()

int main(){
	ios::sync_with_stdio(false), cin.tie(nullptr);
	ll n,w; cin>>n>>w;
	ll dp[n+1][w+1]={};
	pair<ll, ll> ar[n];
	for (int i=0; i<n; i++){
		cin>>ar[i].first>>ar[i].second; //w, val
	}
	for (ll i=1; i<=n; i++){
		for (ll j=1; j<=w; j++){
			if (j-ar[i-1].first >= 0){
				dp[i][j]=max(dp[i-1][j-ar[i-1].first] + ar[i-1].second, dp[i-1][j]);
			}else{
				dp[i][j]=dp[i-1][j];
			}
		}
	}
	ll ans=dp[n][w];
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

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

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

	ll kotae = 0;
	if (N == 1 || M == 1) {
		kotae = abs(max(N, M) - 2);
	}
	else {
		kotae = 1ll * (N - 2)*(M - 2);
	}
	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val m = sc.nextInt()
  val ab = (1..m).map { Pair(sc.nextInt(), sc.nextInt()) }

  val map = mutableMapOf<Int, MutableList<Int>>()
  for (abi in ab) {
    val a = abi.first
    val b = abi.second
    val tmp = map.getOrElse(a) { mutableListOf<Int>() }

    tmp.add(b)
    map.put(a, tmp)
  }

  val list = map.get(1)!!

  val list2 = mutableListOf<Int>()
  for (li in list) {
    if (!map.containsKey(li)) continue
    val tmp = map.get(li)!!
    list2.addAll(tmp)
  }


  var ok = false
  for (li in list2) {
    if (li == n) ok = true
  }


  if (ok) {
    println("POSSIBLE")
    return
  }
  println("IMPOSSIBLE")

}

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

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

vector<ll> A;
// vectorのリサイズ
// A.resize(N);

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

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

  ll a, b;
  cin >> a >> b;
  if ((abs(b-a)%2)) {
    cout << "IMPOSSIBLE" << endl;
  } else {
    cout << min(a, b) + abs(b-a)/2<< endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String args[]){
	  Scanner sc = new Scanner(System.in);
      int count = sc.nextInt();
      double a[] = new double[count];
      double sum = 0;
      for(int i = 0; i < count; i++){
        a[i] = sc.nextInt();
        sum += 1/a[i];
      }
      System.out.println(1/sum);
	}
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int N; cin >> N;
    vector<int>v(N);
    for(auto & e : v) cin >> e;
    sort(v.begin(),v.end());
    vector<pii>ans;
    int bound = N - 1;
    for(int i = 0; i < N; ++i){
        if(v[i] >= 0){
            bound = i; break;
        }
    }
    if(bound == 0) bound = 1;
    // bound is minimum unsigned integer
    for(int i = N - 2; i >= bound; --i){
        if(bound - 1 >= 0){
            ans.emplace_back(v[bound - 1] , v[i]);
            v[bound - 1] -= v[i];
        }
    }
    for(int i= 0; i < bound; ++i){
        ans.emplace_back(v.back(),v[i]);
        v.back() -= v[i];
    }
    cout << v.back() << endl;
    for(auto p : ans)
        cout << p.first << " " << p.second << endl;
}


Measured memory_bytes: 4336
n = int(input())
h = list(map(int, input().split()))
dp = [float("Inf")] * (n + 1)

dp[0] = 0
for i in range(1, n):
  dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i - 1]))
  if i > 1:
    dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i - 2]))

print(dp[n - 1])

Measured memory_bytes: 13928
#ifdef _WIN32
#include "stdc++.h"
#else
#include <bits/stdc++.h>
#endif

// 継承可能な型
template <class Type>
struct IN : Type
{
	IN()
	{
		std::cin >> *this;
	}
};

// 継承不可能な型
template <class Type>
struct IN_
{
	Type val;

	IN_()
	{
		std::cin >> val;
	}

	operator Type&()
	{
		return val;
	}

	IN_<Type>& operator=(const Type& _value)
	{
		val = _value;
		return *this;
	}
};

template <class Char, class Type>
std::basic_ostream<Char>& operator <<(std::basic_ostream<Char>& os, const IN_<Type>& value)
{
	return os << value.val;
}

template <class Char, class Type>
std::basic_istream<Char>& operator >>(std::basic_istream<Char>& is, IN_<Type>& value)
{
	return is >> value.val;
}

template <class Type>
void OUT(const Type& value)
{
	std::cout << value << std::endl;
}

template <class Type, class ... Args>
void OUT(const Type& value, const Args& ... args)
{
	std::cout << value << ' ';
	OUT(args...);
}

void YESNO(const bool cond)
{
	OUT(cond ? "YES" : "NO");
}
void YesNo(const bool cond)
{
	OUT(cond ? "Yes" : "No");
}

using ll = long long;
using inll = IN_<ll>;
using vll = std::vector<ll>;
using setll = std::set<ll>;
using msetll = std::multiset<ll>;
using instr = IN<std::string>;

// 階乗を計算 O(N) (N=10^7 で O(10^7))
ll factorial(ll n)
{
	for (ll i = n - 1; i > 1; --i)
		n *= i;
	return n;
}

// nCrを計算 O(N) (N=10^7 で O(10^7))
ll ncr(const ll n, ll r)
{
	if (r * 2 > n) r = n - r;

	ll dividend = 1, divisor  = 1;

	for (ll i = 1; i <= r; ++i) {
		dividend *= n - i + 1;
		divisor *= i;
	}

	return dividend / divisor;
}

// 素数判定 O(sqrt(N)) (N=10^7 で O(10^3))
bool isprime(const ll num)
{
    if (num < 2) return false;
    if (num == 2) return true;
    if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (ll i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0) return false;
    }

    return true;
}

// 各桁の和を計算 O(logN) (N=10^7 で O(7))
ll digsum(ll n)
{
	ll sum = 0;
	while(n != 0){
		sum += n % 10;
		n /= 10;
	}
	return sum;
}

#define FOR(i, m, n) for (ll (i) = (m); (i) < (n); ++(i))
#define REP(i, n) for (ll (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for (ll (i) = (n); (i) >= 0; --(i))
#define ITRREP(it, v) for (auto (it) = (v).begin(); (it) != (v).end(); ++(it))
#define ITRREPR(it, v) for (auto (it) = (v).rbegin(); (it) != (v).rend(); ++(it))
#define DIVUP(a, b) (((a) + (b) - 1) / (b))

void Main();

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

	Main();

#ifdef _DEBUG
	system("pause");
#endif

	return 0;
}

using namespace std;

//////////////////////////////

void Main()
{
	inll a, b, c;

	ll mi = min({(ll)a, (ll)b, (ll)c}), ma = max({(ll)a, (ll)b, (ll)c}), me = (a+b+c-mi-ma);
	
	return OUT(ma - me + me - mi);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main(){
	int a,b,c;cin>>a>>b>>c;
	cout<<max(0,c+b-a)<<endl;
}

Measured memory_bytes: 256
input_n = input()
n = str(input_n)

tmp = 0
result = 0

list_n = list(n)

for i in range(3):
    if list_n[i] == 'R':
        tmp += 1
    if list_n[i] == 'S':
        if tmp > result:
            result = tmp
            tmp = 0

if tmp > result:
    result = tmp
    tmp = 0

print(str(result))


Measured memory_bytes: 9052
using System;
class Program
{
	static void Main(string[] args)
	{
		for (int i = 1; i <= 9; i++)
		{
			for (int j = 1; j <= 9; j++)
			{
				int answer = i * j;

				System.Console.WriteLine(i.ToString() + "x" + j.ToString() + "=" + answer.ToString());
			}
		}
	}
}

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

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

int MOD=1e9+7;
ll INF=1e18;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};

int main(){
    int n, t; cin>>n>>t;
    int a[n+10];
    for(int i=0; i<n; i++) cin>>a[i];

    int MIN=MOD, gap_max=0;
    for(int i=0; i<n; i++){
        MIN=min(MIN, a[i]);
        gap_max=max(gap_max, a[i]-MIN);
    }
    
    MIN=MOD;
    int ans=0;
    for(int i=0; i<n; i++){
        MIN=min(MIN, a[i]);

        if(a[i]-MIN == gap_max){
            ans++;
            MIN=MOD;
        }
    }
    cout << ans << endl;
}

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

int main() {
  int n, i;
  cin >> n;
  ll ans = 1;
  for (i = 1; i <= n; i++) {
    ans = (ans * i) % mod;
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

   
    public static void main(String[] args) {
       Scanner scanner = new Scanner(System.in);
       int A = scanner.nextInt();
       int B = scanner.nextInt();
       int T = scanner.nextInt();
      
        System.out.println((T/A) * B);
    }
    
}


Measured memory_bytes: 23508
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
    const int MAX =200002;
const int MOD = 1000000007;


     signed main(){
   int a,b,c,k;
   cin>>a>>b>>c>>k;
   while(k!=0&&b<=a){
       b*=2;
       k--;
   }
   while(k!=0&&c<=b){
       c*=2;
       k--;
   }
   if(a<b&&b<c)cout<<"Yes"<<endl;
   else cout<<"No"<<endl;

  
  

     }


 


 






    





      

        


Measured memory_bytes: 3672
#include <stdio.h>
#define MAX 100000

int A[MAX],n;

int partition(int p, int r);

int main(){
  int i,q;

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

  q = partition(0, n-1);

  for(i=0;i<n;i++){
    if(i) printf(" ");
    if(i == q) printf("[");
    printf("%d",A[i]);
    if(i==q) printf("]");
  }
  printf("\n");
  
  return 0;
}

int partition(int p,int r){
  int x, i, j, t;
  x = A[r];
  i = p-1;
  for(j = p; j < r; j++){
    if(A[j] <= x){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }
  t = A[i+1];
  A[i+1] = A[r];
  A[r] = t;
  
  return i + 1;
}



Measured memory_bytes: 2172
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;
typedef tuple<int, int, int> TI;

int main()
{
    int N,K;
    cin >> N >> K;
    int input[N];
    rep0(i,N){
        cin >> input[i];
    }
    int res = 1;
    N-=K;
    res += (N+K-2)/(K-1);
    cout << res << endl;
}


Measured memory_bytes: 3988
n = int(input())
a, b, c = input(), input(), input()
ans = 0
for i in range(n):
  if not a[i]==b[i]==c[i]:
    if (a[i]==b[i] and b[i]!=c[i]) or (b[i]==c[i] and c[i]!=a[i]) or (c[i]==a[i] and a[i]!=b[i]):
      ans += 1
    else:
      ans += 2
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <numeric>

using namespace std;

const int MOD = 998244353;

int main(){
    string S; cin >> S;
    int K; cin >> K;
    vector<int> seg;
    int cnt = 0;
    for(int i=S.size()-1;i>=0;i--){
        if(S[i] == '0'){
            seg.push_back(cnt);
            cnt = 0;
        } else {
            cnt++;
        }
    }
    K = min(K, accumulate(seg.begin(), seg.end(), 0));
    vector dp = vector(seg.size()+1, vector(K+1, vector(K+1, 0LL)));
    dp[0][0][0] = 1;
    int upper = 0;
    for(int i=0;i<seg.size();i++){
        for(int hold=0;hold<=upper;hold++){
            for(int op=0;op<=upper;op++){
                for(int j=0;j<=hold;j++){
                    dp[i+1][hold-j][op] = (dp[i+1][hold-j][op] + dp[i][hold][op]) % MOD;
                }
                for(int j=1;j<=min(seg[i], K-max(hold,op));j++){
                    dp[i+1][hold+j][op+j] = (dp[i+1][hold+j][op+j] + dp[i][hold][op]) % MOD;
                }
            }
        }
        upper = min(upper + seg[i], K);
    }
    long long res = 0;
    for(int i=0;i<=K;i++){
        for(int j=0;j<=K;j++){
            res = (res + dp.back()[i][j]) % MOD;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 30244
# include <iostream>
# include <cmath>
# include <vector>

typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int q; cin >> q;
    int l[q], r[q];
    const int MAX = 100001;
    int isPrime[MAX];
    fill(isPrime, isPrime+MAX, 0);
    for (int i = 0; i < q; i++) cin >> l[i] >> r[i];
    for (int n = 2; n < MAX; n++) {
        bool flag = true;
        for (int i = 2; i <= (int)pow(n, 0.5); i++) {
            if (n%i == 0) {
                flag = false;
                break;
            }
        }
        if (flag) isPrime[n] = 1;
    }
    int acum[MAX];
    int cur = 0;
    for (int i = 3; i < MAX; i+=2) {
        if (isPrime[i] && isPrime[(i+1)/2]) cur++;
        acum[i] = cur;
    }
    for (int i = 0; i < q; i++) {
        if (l[i] < 2) {
            cout << acum[r[i]] << endl;
        } else {
            cout << acum[r[i]] - acum[l[i] - 2] << endl;
        }
    }
    return 0;
}


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

long long n,x=-2,z;
vector<int> v;

int main(void){
    cin >> n;

    if (n == 0) {
        cout << "0\n";
        return 0;
    }

    while(n) {
        if (abs(n%x) == abs(x/2)) {
            if (x<0) n -= abs(n%x);
            else n += abs(n%x);
            v.insert(v.begin(),1);
        }else v.insert(v.begin(),0);
        z++;
        x *=-2;
    }

    for (x=0 ; x<z ; x++) cout << v[x];
    cout << "\n";


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct Node{
  int key;
  int id,parent,left,right;
};


Node A[20000000];
int H;

void heap(int H){
  for(int i=1;i<=H;i++){
    if(i==1){
      A[i].left=A[2*i].key;
      A[i].right=A[2*i+1].key;
    }
    else {
      A[i].parent=A[i/2].key;
      A[i].left=A[2*i].key;
      A[i].right=A[2*i+1].key;
    }
  }
}
void maxheap(int i){
  int l=0,r=0;
  int lag;
  int tmp;
  l=2*i;
  r=2*i+1;
  if(l<=H && A[l].key>A[i].key){
    lag=l;
  }
  else {
    lag=i;
  }
  if(r<=H&&A[r].key>A[lag].key){
    lag=r;
  }
  if(lag!=i){
    tmp=A[i].key;
    A[i].key=A[lag].key;
    A[lag].key=tmp;
    maxheap(lag);
  }
}
void changeccc(int i,int k){
  int tmp=0;
  if(k<A[i].key){
    return;
  }
  A[i].key=k;
  while(i>1&&A[i/2].key<A[i].key){
    tmp=A[i].key;
    A[i].key=A[i/2].key;
    A[i/2].key=tmp;
    i=i/2;
  }
}

void insert(int k){
  H++;
  A[H].key=-INT_MAX;
  changeccc(H,k);
}

int heaphigh(){
  int maxx;
  if(H<1)return -INT_MAX;
  maxx=A[1].key;
  A[1].key=A[H--].key;
  maxheap(1);
  return maxx;
}
int main(){
  char c[9];
  int k;
  while(1){
    cin>>c;
    if(strcmp(c,"end")==0)break;
    if(strcmp(c,"insert")==0){
      cin>>k;
      insert(k);
    }
    else {
      cout<<heaphigh()<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 22608
#include<iostream>
#include<string>
#include<vector>
#include<string.h>
#include<queue>
using namespace std;

typedef pair<int,int> COR;

int H,W,C;
vector<string> M;
int INF= 100000;

int cost[10][10];
bool come[1000][1000];

int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};


void solve(){

	for(int i=0;i<10;i++)
		for(int j=0;j<10;j++)
			cost[i][j]=INF;

	M.clear();
	vector<pair<int,int> > V;
	
	for(int i=0;i<H;i++){
		string h;
		cin>>h;
		for(int j=0;j<h.size();j++)
			if(isdigit(h[j]) || h[j]=='S')
				V.push_back(make_pair(i,j));
			
		M.push_back(h);
	}

	int now;
	for(int i=0;i<V.size();i++){
		if(isdigit(M[V[i].first][V[i].second]))
			now=M[V[i].first][V[i].second]-'0';

		if(M[V[i].first][V[i].second]=='S')
			now=0;

		memset(come,false,sizeof(come));
		queue<pair<COR,int> > Q;
		Q.push(make_pair(V[i],0));
		int count=0;
		while(!Q.empty() && count<C+1){
			pair<COR,int> p=Q.front();
			Q.pop();
			int y=p.first.first,x=p.first.second,c=p.second;
			if(y<0 || x<0 || y>=H || x>=W ||come[y][x] || M[y][x]=='X')
				continue;
			come[y][x]=true;
			if(M[y][x]=='0'+now+1){
				cost[now][now+1]=c;
				break;
			}

			for(int r=0;r<4;r++)
				Q.push(make_pair(make_pair(y+dy[r],x+dx[r]),c+1));
		}
	}

	int res=0;

	for(int i=0;i<V.size()-1;i++)
		res+=cost[i][i+1];
	cout<<res<<endl;
}

int main()
{
	while(cin>>H>>W>>C){
		solve();
	}
	return 0;
}

Measured memory_bytes: 2872
/*
    Take me to church
    I'll worship like a dog at the shrine of your lies
    I'll tell you my sins and you can sharpen your knife
    Offer me that deathless death
    Good God, let me give you my life
*/
#include<bits/stdc++.h>
using namespace std;
const int N = 5005, M = 202, LG = 14;
int n, m, B[M][N], Log[N];
long long A[N], dp[N][N];
pair < int , int > MX[LG][N];
inline int GetMax(int l, int r)
{
    int lg = Log[r - l + 1];
    return (max(MX[lg][l], MX[lg][r - (1 << lg) + 1]).second);
}
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 2; i <= n; i ++)
        scanf("%d", &A[i]), A[i] += A[i - 1];
    for (int i = 1; i <= n; i ++)
        for (int j = 1; j <= m; j ++)
            scanf("%d", &B[j][i]);
    for (int i = 2; i < N; i ++)
        Log[i] = Log[i >> 1] + 1;
    for (int j = 1; j <= m; j ++)
    {
        for (int i = 1; i <= n; i ++)
            MX[0][i] = {B[j][i], i};
        for (int h = 1; h < LG; h ++)
            for (int i = 1; i + (1 << h) - 1 <= n; i ++)
                MX[h][i] = max(MX[h - 1][i], MX[h - 1][i + (1 << h - 1)]);
        queue < pair < int , int > > qu;
        qu.push({1, n});
        while (qu.size())
        {
            int l = qu.front().first;
            int r = qu.front().second;
            qu.pop();
            if (r < l) continue;
            int i = GetMax(l, r);
            dp[l][i] += B[j][i];
            dp[l][r + 1] -= B[j][i];
            dp[i + 1][i] -= B[j][i];
            dp[i + 1][r + 1] += B[j][i];
            qu.push({l, i - 1});
            qu.push({i + 1, r});
        }
    }
    for (int i = 1; i <= n; i ++)
        for (int j = 1; j <= n; j ++)
            dp[i][j] += dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
    long long Mx = 0;
    for (int i = 1; i <= n; i ++)
        for (int j = i; j <= n; j ++)
            Mx = max(Mx, dp[i][j] - A[j] + A[i]);
    return !printf("%lld\n", Mx);
}

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

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

    vector<int> vecLen(n);
    for(int i=0; i<n; i++)
        cin >> vecLen.at(i);

    sort(vecLen.begin(), vecLen.end());
    
    int res = 0;
    for(int i=0; i<n-2; i++){
        for(int j=i+1; j<n-1; j++){
            for(int k=j+1; k<n; k++){
                if(vecLen[i] + vecLen[j] <= vecLen[k])
                    break;

                res++;
            }
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(void){
    int N;
    int B[100];
    
    cin >> N;
    for (int i = 0; i < N-1; i++) cin >> B[i];
    
    int value = 0;
    for (int i = 0; i < N-1; i++) {
        if (i == 0)
            value += B[i];
        else
            value += min(B[i], B[i-1]);
    }
    value += B[N-2];
    
    cout << value << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
   double xA,yA,xB,yB,xC,yC,xD,yD;
   while(cin >> xA >> yA >> xB >> yB >> xC >> yC >> xD >> yD){
      if(-0.0000000001 < (yA-yB)*(yC-yD) + (xC-xD)*(xA-xB) &&
     (yA-yB)*(yC-yD) + (xC-xD)*(xA-xB) < 0.0000000001)
     cout << "YES" << endl;
      else cout << "NO" << endl;
   }
   return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

static const ll s = 1000001;
static const ll MOD = 1e9 + 7;
ll f[s] = {};
ll POW(ll e, ll n) {
	//cout << e << " " << n << endl;
	if (n == 0) return 1;
	if (n == 1) return e;

	ll t = POW(e, n / 2) % MOD;

	if (n & 1)return ((t * t) % MOD)* e % MOD;
	else return t * t % MOD;
}

void fact() {
	f[0] = 1;
	rep(i, 1, s) f[i] = i * f[i - 1] % MOD;
}
ll nCr(ll n, ll r) {
	return ((f[n] * POW(f[r], MOD - 2) % MOD) * POW(f[n - r], MOD - 2) % MOD) % MOD;
}

map<ll, ll> mp;
int main()
{
	fact();
	ll h, w, a, b; cin >> h >> w >> a >> b;

	ll ans = 0;
	rep(B, b, w) {
		ans = (ans + nCr(h - a - 1 + B, B) * nCr(a - 1 + w - 1 - B, w - 1 - B) % MOD) % MOD;
	}
	cout << ans << endl;

	return 0;
}

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

int main()
{
  int h,n;
  cin>>h>>n;
  int a[n];
  for(int i=0;i<n;i++)
  {
      cin>>a[i];
  }
  int ans=0;
  for(int i=0;i<n;i++)
  {
      ans+=a[i];
  }
  if(h>ans)   cout<<"No"<<endl;
  else     cout<<"Yes"<<endl;


    return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
using namespace std;
using LL = long long;
LL N, M, S, A[50];
inline LL ceil(LL d, LL n) {return (d+n-1)/n;}
inline bool ok(LL x) {
  if(M < S-x) return false;
  LL s = 0;
  for(auto i=0; i<N; ++i) s += ceil(A[i]+x+1-N, N+1);
  return s <= x;
}
int main() {
  scanf("%lld", &N);
  M=N*(N-1);
  for(auto i=0; i<N; ++i) scanf("%lld", A+i), S+=A[i];
  LL l = -1, h = 1e18;
  while(l+1 < h) {
    LL m = (l+h)>>1;
    if(ok(m)) h = m;
    else      l = m;
  }
  for(auto x=max(0ll,h-M); x<=h; ++x) if(ok(x)) {
    printf("%lld\n",x);
    break;
  }
}

Measured memory_bytes: 504
#include <iostream>

using namespace std;

int main(){
    int N, Y;
    cin >> N >> Y;
    int x, y, z;
    for(x = 0; x <= N; x++){
        for(y = 0; y <= N; y++){
            z = N - x - y;
            if(z >= 0 && Y == 10000 * x + 5000 * y + 1000 * z){
                cout << x << " " << y << " " << z << endl;

                return 0;
            }
        }
    }

    cout << -1 << " " << -1 << " " << -1 << endl;


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    int N;
    string S;
    bool ans=true;
    cin >> N>>S;
    if(N%2!=0){
        ans = false;
    }
    else{
        REP(i,N/2){
            if(S[i]!=S[N/2+i]){
                ans =false;
                break;
            }
        }
    }
    if(ans){
        cout <<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
n = int(input())
p = list(map(float,input().split()))
dp = [[0 for j in range(i+1)] for i in range(n+1)]
dp[0][0] = 1
ans = 0
for i in range(1,n+1):
    for j in range(i+1):
        if i-1 >= j and j >= 1:
            dp[i][j] = p[i-1]*dp[i-1][j-1] + (1-p[i-1])*dp[i-1][j]
        elif i-1>=j:
            dp[i][j] = (1-p[i-1])*dp[i-1][j]
        elif j>=1:
            dp[i][j] = p[i-1]*dp[i-1][j-1]

        if i <= 2*j and i == n:
            ans += dp[i][j]


print(ans)

Measured memory_bytes: 150792
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		for(int i = 0; i<=s.length(); i++){
			if(i==4){
				System.out.print(" ");
			}else if(i<4){
				System.out.print(s.charAt(i));
			}else{
				System.out.print(s.charAt(i-1));
			}
		}
		System.out.println();
 	}
}

Measured memory_bytes: 10056
#include<iostream>
#include<queue>
using namespace std;
int main(){
    int N,A,B,C;
    cin>>N>>A>>B>>C;
    priority_queue<int>que;
    while(N--){
        int v;
        cin>>v;
        que.push(v);
    }
    int best=C,prise=A;
    while(que.size()){
        int v=que.top();que.pop();
        double bfr=1.0*best/prise,aft=1.0*(best+v)/(prise+B);
        if(bfr<aft){
            best+=v;prise+=B;
        }
        else break;
    }
    cout<<best/prise<<endl;

}

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

public class Main {

    //https://atcoder.jp/contests/dp/tasks/dp_a

    private static final int INF = 1000000005;
    private static int[] dp = null;

    public static void main( String[] args ) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

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

        dp = new int[n + 1];
        Arrays.fill(dp, -1);

        //Time  : 422 ms
       /* int value = dfs(arr, n, 0);
        System.out.println(value);*/

        /*int val = solveTopDown(n - 1, arr);
        System.out.println(val);*/

        int val = solveBottomUp(arr);
        System.out.println(val);
    }

    private static int dfs( int[] arr, int n, int temp ) {

       /* if (dp[temp] != -1)
            return dp[temp];*/

        if (temp == n) //if no element in an array then
            return 0;

        if (temp == n - 1) //if no element in an array then
            return arr[n - 1];

        if (temp == n - 2) //if only element in array then difference of two will be the cost.
            return Math.abs(arr[temp] - arr[temp - 1]);

        for (int i = temp; i < n; i++) {

            if (i + 2 < n) {

                dp[i] = Math.min(Math.abs(arr[i] - arr[i + 1]) + dfs(arr, n, i + 1)
                        , Math.abs(arr[i] - arr[i + 2]) + dfs(arr, n, i + 2));
            }
        }

        return dp[n];
    }

    //help from : vengal
    private static int solveTopDown( int i, int[] arr ) {
        if (dp[i] != -1) {
            return dp[i];
        }

        if (i == 0) { //if one element left
            dp[i] = 0;
            return dp[i];
        } else if (i == 1) { //if two left
            dp[i] = Math.abs(arr[i] - arr[i - 1]);
            return dp[i];
        }

        dp[i] = Math.min(Math.abs(arr[i] - arr[i - 1]) + solveTopDown(i - 1, arr)
                , Math.abs(arr[i] - arr[i - 2]) + solveTopDown(i - 2, arr));

        return dp[i];
    }

    private static int solveBottomUp( int[] arr ) {

        //INF : bcz we are comparing Math.min(dp[j] here..
        Arrays.fill(dp, INF);

        //this indicate to reach first stone cost is zero..
        dp[0] = 0;

        for (int i = 0; i < arr.length; i++) {

            //from each stone : frog can jump to i + 1 or i + 2 stone.
            for (int j = i + 1; j <= i + 2; j++) {

                if (j < arr.length) {
                    dp[j] = Math.min(dp[j]
                            , dp[i] + Math.abs(arr[i] - arr[j]));
                }
            }
        }

        return dp[arr.length - 1];
    }
}

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

int main() {
    int n;
    string s;
    cin >> n;
    rep(i, n) {
        cin >> s;
        if(s == "Y") {
            cout << "Four" << endl;
            break;
        }
        else if(i == n - 1) {
            cout << "Three" << endl;
        }
    }
}


Measured memory_bytes: 3592
import java.io.{BufferedReader, InputStreamReader}
import java.util.Arrays.binarySearch
import java.util

object Main extends App {
  val in = new BufferedReader(new InputStreamReader(System.in))
  val n = in.readLine.toInt
  val a, b, c = in.readLine.split(" ").map(_.toLong)

  util.Arrays.sort(a)
  util.Arrays.sort(b)
  util.Arrays.sort(c)
  
  val ans = {
      var posA = 0
      var posC = 0

      def findA(tar:Long):Int = {
        val pa = binarySearch(a, posA, n, tar - 1)
        posA = if(pa > -1) pa else ~pa
        while(posA < n && a(posA) < tar) posA += 1
        posA
      }
      def findC(tar:Long):Int = {
        val pc = binarySearch(c, posC, n, tar - 1)
        posC = if(pc > -1) pc else ~pc
        while(posC < n && c(posC) <= tar) posC += 1
        posC
      }

      b./:(0L)((acc,e) => {
        val ac = findA(e)
        val cc = n - findC(e)

        acc +  ac.toLong * cc.toLong
      })
    }

  println(ans)
}

Measured memory_bytes: 80248
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	s := getString()

	cnt := 0
	b := []byte{}
	p := ""
	for i := 0; i < len(s); i++ {
		b = append(b, s[i])
		if string(b) == p {
			continue
		}
		p = string(b)
		b = []byte{}
		cnt++
	}
	out(cnt)
}


Measured memory_bytes: 4072
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
typedef long long ll;

using ipair = pair<int, int>;

ll INF = 1e16+7;

bool operator>(const ipair a,const ipair b){return a.first > b.first;}


int main(){
  int L, R;
  cin >> L >> R;

  R = min(R, L+5000);

  vector<int> nums;
  for(int i=L; i<=R; i++){
    nums.push_back(i%2019);
  }

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

  int ans = 5000;
  for(int i=0; i<nums.size(); i++){
    for(int j=i+1; j<nums.size(); j++){
      ans = min(ans, (nums[i]*nums[j])%2019);
    }
  }


  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
(* O(n) *)
let n = Scanf.scanf " %d" @@ (+) 0
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ (+) 0
let ps = Array.make 2 0
let _ =
  Array.iter (fun a -> ps.(a mod 2) <- ps.(a mod 2) + 1) a_s;
  if ps.(1) >= 2 then (ps.(0) <- ps.(0) + 1; ps.(1) <- ps.(1) mod 2);
  if ps.(0) >= 1 then ps.(0) <- 1;
  print_endline @@ if ps.(0) + ps.(1) = 1 then "YES" else "NO"

Measured memory_bytes: 5120
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

//a^b % MOD
long long mod_pow(ll a,ll b){
	long long ret = 1;
	long long c = a;
	for(int i = 0;i <= 60;i++){
		if(b & (1LL << i))ret = (ret * c) % MOD;
		c = (c * c) % MOD;
	}
	return ret;
}

//ａをbで割る
long long mod_div(long long a,long long b){
	long long tmp = MOD - 2,c = b,ret = 1;
	while(tmp > 0){
		if(tmp & 1){
			ret *= c;ret %= MOD;
		}
		c *= c;c %= MOD;tmp >>= 1;
	}
	return a*ret%MOD;
}

#define MAX_K 333333
vector<long long> fact(MAX_K);
long long combination(long long n, long long r){
    if(n < r || n < 0 || r < 0)
        return 0;
	if(fact[0] != 1){
		fact[0] = 1;
		for(long long i = 1;i < MAX_K;i++)fact[i] = (fact[i-1] * i) % MOD;
	}
    long long ret = fact[n];
	long long tmp = (fact[r] * fact[n-r]) % MOD;
    return mod_div(ret,tmp);
}

void mod_add(ll &a, ll b){
	a += b;
	a %= MOD;
}

ll mp[222222];

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

	ll n, k;cin >> k >> n;
	ll ans = 0;
	for(ll i = n;i >= 1;i--){
		ll tmp = 0;
		ll cou = 0;
		for(int j = i;j <= n;j += i){
			mod_add(tmp, mp[j]);
			cou++;
		}
		mp[i] = mod_pow(cou, k);
		mod_add(mp[i], MOD - tmp);
		mod_add(ans, i * mp[i] % MOD);
	}

	cout << ans << endl;

	return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> pll;

struct SieveOfEratosthenes {
    vector<bool> is_prime;
    vector<ll> primes;

    SieveOfEratosthenes(ll V) {
        is_prime = vector<bool>(V + 1, true);
        primes = vector<ll>();
        for (ll i = 2; i <= V; i ++) {
            if (is_prime[i]) {
                primes.push_back(i);
                for (ll j = i * i; j <= V; j += i) {
                    is_prime[j] = false;
                }
            }
        }
    }

    vector<pll> factorize(ll x) {
        if (x <= 1) {
            throw invalid_argument("x shoule be > 1");
        }
        auto result = vector<pll>();
        for (auto p : primes) {
            ll exp = 0;
            while (x % p == 0) {
                exp++;
                x = x / p;
            }
            if (exp > 0) {
                result.push_back(pll(p, exp));
            }
            if (p * p > x) {
                break;
            }
        }
        if (x > 1) {
            result.push_back(pll(x, 1));
        }
        return result;
    }
};

ll gcd(ll a, ll b) {
    // gcd(x, 0) = x
    // gcd(a, b) = gcd(b, r)
    while (b != 0) {
        ll r = a % b;
        a = b;
        b = r;
    }
    return a;
}

string solve() {
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    if (all_of(A.begin(), A.end(), [&](const ll x) { return x == 1; })) {
        return "pairwise coprime";
    }


    ll gcd_all = A[0];
    for (int i = 1; i < N; i++) {
        gcd_all = gcd(gcd_all, A[i]);
    }

    if (gcd_all != 1) {
        return "not coprime";
    }
    
    auto sieve = SieveOfEratosthenes(*max_element(A.begin(), A.end()));
    auto used_primes = unordered_set<ll>();

    for (auto x : A) {
        if (x == 1) {
            continue;
        }
        auto factors = sieve.factorize(x);
        for (auto [p, e] : factors) {
            if (used_primes.find(p) != used_primes.end()) {
                return "setwise coprime";
            }
            used_primes.insert(p);
        }
    }

    return "pairwise coprime";
}

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

    cout << solve() << endl;

    return 0;
}

Measured memory_bytes: 12184
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

const int MAX_N = 100000;
int n;
string s;
char ans[MAX_N];

char inv(char c) {
    if (c == 'S')
        return 'W';
    else if (c == 'W')
        return 'S';
    else
        assert(false);
}

bool sheep(int i) {
    return (s[i] == 'o' && ans[(i - 1 + n) % n] == ans[(i + 1 + n) % n])
        || (s[i] == 'x' && ans[(i - 1 + n) % n] != ans[(i + 1 + n) % n]);
}

bool wolf(int i) {
    return (s[i] == 'x' && ans[(i - 1 + n) % n] == ans[(i + 1 + n) % n])
        || (s[i] == 'o' && ans[(i - 1 + n) % n] != ans[(i + 1 + n) % n]);
}

bool check() {
    bool ok = true;
    forn(i, n) {
        ok &= ans[i] == 'S' ? sheep(i) : wolf(i);
    }

    return ok;
}

int main() {
    fastio();

    cin >> n >> s;

    forn(i0, 2) {
        ans[0] = !i0 ? 'S' : 'W';
        forn(in_1, 2) {
            ans[n - 1] = !in_1 ? 'S' : 'W';
            for (int i = 0; i < n - 2; i++) {
                char c = ans[(i - 1 + n) % n];
                if (ans[i] == 'S') {
                    ans[i + 1] = s[i] == 'o' ? c : inv(c);
                } else {
                    ans[i + 1] = s[i] == 'o' ? inv(c) : c;
                }
            }

            if (check()) {
                forn(i, n) {
                    cout << ans[i];
                }
                cout << endl;

                return 0;
            }
        }
    }

    cout << -1 << endl;

    return 0;
}

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

using namespace std;

int main(){
    int N,avl,ans=0,anss=0;
    cin >> N;
    vector<int> a(N);
    cin >> avl;
    a[0] = avl;
    for(int i=1;i<N;i++){
        cin >> a[i];
        avl += a[i];
    }
    avl /= N;
    for(int i=0;i<N;i++){
        ans += abs(a[i]-avl) * abs(a[i]-avl);
    }
    for(int i=0;i<N;i++){
        anss += abs(a[i]-avl-1) * abs(a[i]-avl-1);
    }
    cout << min(ans,anss);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = a, i##_len = (b); i < i##_len; ++i)

int main()
{
    int K, X;
    cin >> K >> X;
    if(500*K >= X) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<string>
#include<vector>
#include<algorithm>
#include<sstream>
#include<map>
#include<iostream>
using namespace std;
int N;
int to_int(string s){
  int res;
  stringstream ss;
  ss<<s;
  ss>>res;
  return res;
}

string int_to_string(int n){
  stringstream ss;
  ss<<n;
  string res;
  ss>>res;
  for(int i=res.size();i<N;i++){
    res='0'+res;
  }
  return res;
}
int main(){
  string s;
  
  while(cin>>s>>N,N!=0){
    s = int_to_string(to_int(s));
    map<string,int> list;
    int c=0;
    while(list.count(s)==0){
      list[s]=c;
      sort(s.rbegin(),s.rend());
      int max_s = to_int(s);
      int min_s = to_int(string(s.rbegin(),s.rend()));
      s = int_to_string(max_s-min_s);
      c++;
    }
    cout<<list[s]<<" "<<to_int(s)<<" "<<c-list[s]<<endl;
  }
}

Measured memory_bytes: 1240
function main(input) {
  input=input.trim();
  const x = parseInt(input.split("\n")[0], 10);
  const a = parseInt(input.split("\n")[1], 10);
  const b = parseInt(input.split("\n")[2], 10);
  console.log((x-a)%b);

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



Measured memory_bytes: 21064
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int[] A = new int[N - 1];
            int[] B = new int[N - 1];
            for (int i = 0; i < N - 1; i++) {
                A[i] = sc.nextInt() - 1;
                B[i] = sc.nextInt() - 1;
            }

            List<Integer>[] edges = new List[N];
            for (int i = 0; i < N; i++) {
                edges[i] = new ArrayList<>();
            }
            for (int i = 0; i < N - 1; i++) {
                edges[A[i]].add(B[i]);
                edges[B[i]].add(A[i]);
            }

            int K = Arrays.stream(edges).mapToInt(e -> e.size()).max().getAsInt();

            Map<Integer, Integer>[] colorMap = new Map[N];
            for (int i = 0; i < N; i++) {
                colorMap[i] = new HashMap<>();
            }

            dfs(0, -1, -1, colorMap, edges);

            StringBuilder ans = new StringBuilder();
            ans.append(K).append("\n");
            for (int i = 0; i < N - 1; i++) {
                Integer c = null;
                if (colorMap[A[i]] != null) {
                    c = colorMap[A[i]].get(B[i]);
                }

                if (c == null) {
                    c = colorMap[B[i]].get(A[i]);
                }

                ans.append(c).append("\n");
            }

            System.out.print(ans.toString());
        }
    }

    public static void dfs(int v, int pv, int pc, Map<Integer, Integer>[] colorMap, List<Integer>[] edges) {
        int c = 1;
        for (int nv : edges[v]) {
            if (nv == pv) {
                continue;
            }

            if (c == pc) {
                c++;
            }

            colorMap[v].put(nv, c);

            dfs(nv, v, c, colorMap, edges);

            c++;
        }
    }

}


Measured memory_bytes: 89344
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

int a[200000], rui[200000];
map<int, int> mp;
signed main(){
	int n, m;
	scanf("%lld%lld", &n, &m);
	rrep(i,n)scanf("%lld", &a[i]);
	rrep(i,n)rui[i] += rui[i-1]+a[i];
	rrep(i,n)mp[rui[i]%m]++;
	int ans = 0;
	for(auto it = mp.begin();it != mp.end();it++){
		int tmp = it->se;
		if(it->fi == 0)ans += tmp*(tmp+1)/2;
		else ans += (tmp-1)*tmp/2;
	}
	printf("%lld\n", ans);
	return 0;
}






Measured memory_bytes: 5760
/*input
8 5
3 6 2 8 7 6 5 9
*/
#include<bits/stdc++.h>
using namespace std;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int fast_ex(int a,int n,int m){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= fast_ex(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

int n,K;
int a[51],dp[51][51][2501];
//dp[i][j][k] = no of ways to select j cards from first i with sum = k

void solve(){
	 cin >> n >> K;
	 RE(i,n)cin >> a[i];
	 dp[0][0][0] = 1;
	 RE(i,n){
	 	dp[i][0][0] =1;
	 	RE(j,i){
           REP(k,2501){
           	  dp[i][j][k] = dp[i-1][j][k]+(k>=a[i])*dp[i-1][j-1][k-a[i]];
           }
	 	}
	 }
	 int ans = 0;
	 RE(i,n){
       ans += (dp[n][i][i*K]);
	 }
     cout << ans;
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;//cin >> t;
  WL(t)solve();
  return 0;
}

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

def isit(N):

    A = make_divisors(N)
    A.pop(0)

    #print(A)

    num = len(A)
    i=num-1

    for n in reversed(A):
        mul = False
        for m in A:
            if n%m == 0 and n!=m:
                mul = True
                break
        if mul == True:
            A.pop(i)
    #        print(A.pop(i))
    #        print(A)
        i -= 1
    #print(A)

    if len(A) == 1:
        return True
    else:
        return False

A =  make_divisors(N)
A.pop(0)

num = 0

for m in A:
    if isit(m) == True:
        if N%m == 0:
            N = N//m
            #print(m)
            num += 1
        if N<m:
            break

print(num)

Measured memory_bytes: 9500
// lcm、__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで
#include <bits/stdc++.h>
#define ll long long
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll i,j,k,l,m,n,maxi=0,f=0,mini=1e10,sum=0;
    string str;
    cin>>n;
    //sum=n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    //rep(i,n) cout<<a[i];
    ll d=round(accumulate(a.begin(),a.end(),0.0)/n);
    //cout<<accumulate(a.begin(),a.end(),0);
    rep(i,n) sum+=pow(abs(a[i]-d),2);

    cout<<sum;

    return 0;
}

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

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			int N = Integer.parseInt(str);
			str = br.readLine();
			int A = Integer.parseInt(str);
 
			System.out.println(N*N-A);
		}catch (Exception e) {
			System.exit(0);
		}
	
	}
 
}

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




void solve(){
	
  int n , m;
  cin >> n >> m ;
  for(int i = 0 ; i <=n ;i++)
  {
   	if(i*2+(n-i)*4 == m)
    {
     cout << "Yes";
      return ;
    }
  }
  cout << "No";
	
	
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  //f();
  //int t;cin>>t;while(t--)
  solve();
  return 0;
}


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

int weishu(int x)
{
	int num = 0;
	while(x > 0){
		num++;
		x /= 10;
	}
	return num;
}
int main()
{
	int n, x = 0;
	cin >> n;
	for(int i = 1; i <= n; i++){
		if(weishu(i)  % 2 == 1){
			x++;
		}
	}
	printf("%d\n", x);
	return 0;
}

Measured memory_bytes: 256