akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define null NULL
#define mp make_pair
#define pb(a) push_back(a)
#define sz(a) ((int)(a).size())
#define all(a) a.begin() , a.end()
#define fi first
#define se second
#define relaxMin(a , b) (a) = min((a),(b))
#define relaxMax(a , b) (a) = max((a),(b))
#define SQR(a) ((a)*(a))
#define PI 3.14159265358979323846
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

const int MAX = 710;

int n, m;
int g[MAX][MAX];

int col[MAX];
int cnt[2];

bool bad = false;

void Dfs(int vr, int c){
  ++cnt[c];
  col[vr] = c;

  c ^= 1;

  for(int i = 0;i < n;++i)
    if(g[vr][i]){
      if(col[i] == -1) Dfs(i, c);
      if(col[i] != c) bad = true;
    }
}

int Edj(int h){
  return h * (h - 1) / 2;
}

int main(){
  scanf("%d%d", &n, &m);

  for(int i = 0;i < n;++i)
    for(int j = 0;j < n;++j)
      if(i != j) g[i][j] = 1;

  for(int i = 0;i < m;++i){
    int a, b;
    scanf("%d%d", &a, &b);
    --a, --b;
    g[a][b] = g[b][a] = 0;
  }

  memset(col, -1, sizeof col);
  vector<pii> nal;
  for(int i = 0;i < n;++i)
    if(col[i] == -1){
      cnt[0] = cnt[1] = 0;
      Dfs(i, 0);
      nal.pb(mp(cnt[0], cnt[1]));
    }

  if(bad){
    printf("-1\n");
    exit(0);
  }

  vector<char> can(n + 1, false);
  can[0] = true;
  for(int i = 0;i < sz(nal);++i){
    vector<char> ncan(n + 1, false);
    for(int j = n;j >= 0;--j)
      if((j - nal[i].fi >= 0 && can[j - nal[i].fi]) ||
         (j - nal[i].se >= 0 && can[j - nal[i].se]))
        ncan[j] = true;
    can.swap(ncan);
  }

  int best = SQR(n);
  for(int i = 0;i <= n;++i)
    if(can[i])
      relaxMin(best, Edj(i) + Edj(n - i));

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

  return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  vector<int> v(3);
  cin >> v[0] >> v[1] >> v[2];
  sort(v.begin(), v.end());

  int add = 0;

  int c = 1;
  int is_max = v[2] & 1;
  if ((v[1] & 1) == is_max)
    c++;
  if ((v[0] & 1) == is_max)
    c++;

  if (c == 1)
    add = 1;
  else if (c == 2)
    add = 2;

  int maxmin = v[2] - v[0];
  int maxmed = v[2] - v[1];
  cout << maxmin / 2 + maxmed / 2 + add << endl;
}


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

int N;
//vector<int> d;
//vector<int> num;

int main(){
  int d[110];
  int num[110] = {};

  cin >> N;


  for(int i = 0; i < N; i++){
    cin >> d[i];
    num[d[i]]++;
  }

  int cnt = 0;

  for(int i = 0; i <= 100; i++){
    if(num[i]) cnt++;
    
  }

  cout << cnt << endl;

  }

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

int n;
vector<int> a;

int main(){
	int bu, len = 1;
	
	cin >> n;
	cin >> bu;
	for( int i = 1; i < n; i++ ){
		int u;
		cin >> u;
		if( bu == u ){
			a.push_back(len);
			len = 1;
		} else {
			len++;
		}
		bu = u;
	}
	a.push_back(len);
	
	int ans = 0;
	for( int i = 0; i < a.size(); i++ ){
		int k = 0;
		for( int j = i; j < a.size() && j < i + 3; j++ ){
			k += a[j];
		}
		ans = max(ans, k);
	}
	cout << ans << endl;
	return 0;
}

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

int main(void){
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    if(A >= K){
        cout << K << endl;
    }else if(A+B >= K){
        cout << A << endl;
    }else{
        cout << A-(K-A-B) << endl;
    }
    return 0;
}

Measured memory_bytes: 3620
import java.util.Scanner;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int a[] = new int[9];
    for(int i = 0; i < 9; i++){
      a[i] = sc.nextInt();
    }
    int n = sc.nextInt();
    for(int i = 0; i < n; i++){
      int b = sc.nextInt();
      for(int j = 0; j < 9; j++){
        if(a[j] == b){
          a[j] = -1;
        }
      }
    }
    for(int i = 0; i < 3; i++){
      if(a[i*3+0]==-1&&a[i*3+1]==-1&&a[i*3+2]==-1){
        System.out.println("Yes");
        return;
      } else if(a[i+0*3]==-1&&a[i+1*3]==-1&&a[i+2*3]==-1){
        System.out.println("Yes");
        return;
      }
    }
    if(a[0]==-1&&a[4]==-1&&a[8]==-1){
      System.out.println("Yes");
      return;
    } else if(a[2]==-1&&a[4]==-1&&a[6]==-1){
      System.out.println("Yes");
      return;
    }
    System.out.println("No");
  }
}

Measured memory_bytes: 21972
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#define WOULD
#define YOU
#define PLEASE
#define ACCEPT
#define MY
#define SUBMISSION
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100;
const long long MOD = 1000000007;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

int main() {
    int A,B,C;cin >> A >> B >> C;
    int maxi = max({A,B,C});
    int X = 0,Y = 0;
    if(A == maxi){
        X = maxi-B;
        Y = maxi-C; 
    }
    if(B == maxi){
        X = maxi-A;
        Y = maxi-C; 
    }
    if(C == maxi){
        X = maxi-A;
        Y = maxi-B; 
    }
    int count = 0;
    while(true){
        if(X >= 1 && Y >= 1){
            X-=1;
            Y-=1;
            count++;
            continue;
        }
        if(X >= 2){
            X-=2;
            count++;
        }
        if(Y >= 2){
            Y-=2;
            count++;
        }
        if(X == 1 && Y == 0){
            count+=2;
            break;
        }
        if(X == 0 && Y == 1){
            count+=2;
            break;
        }
        if(X == 0 && Y == 0) break;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#define NODE_SIZE 25
#define NIL -1

using namespace std;

typedef struct tNode_
{
    int parent;
    int left;
    int right;
    int sibling;
    int degree;
    int depth;
    int height;
}tNode;

int setValue(tNode node[], int p, int d){
    int l = 0, r = 0;
    node[p].depth = d;
    if(node[p].left != NIL){ l = setValue(node, node[p].left, d+1); }
    if(node[p].right != NIL){ r = setValue(node, node[p].right, d+1); }
    node[p].height = max(l, r);
    return node[p].height + 1;
}

string Type(tNode node[], int id){
    string type;

    if(node[id].parent == NIL){
        type = "root";
    }
    else if(node[id].left == NIL && node[id].right == NIL){
        type = "leaf";
    }
    else{
        type = "internal node";
    }

    return type;
}

int main(){
    tNode node[NODE_SIZE];
    int n, id, l, r;

    cin >> n;
    for(int i = 0; i < n; i++){
        node[i].parent = NIL;
        node[i].sibling = NIL;
        node[i].degree = 0;
    }
    for(int i = 0; i < n; i++){
        cin >> id >> l >> r;
        node[id].left = l;
        node[id].right = r;
        if(l != NIL){ 
            node[l].parent = id;
            node[l].sibling = r;
            node[id].degree++;
        }
        if(r != NIL){
            node[r].parent = id;
            node[r].sibling = l;
            node[id].degree++;
        }
    }

    int root = 0;
    while(node[root].parent != NIL){
        root = node[root].parent;
    }

    setValue(node, root, 0);

    for(int i = 0; i < n; i++){
        cout << "node " << i;
        cout << ": parent = " << node[i].parent;
        cout << ", sibling = " << node[i].sibling;
        cout << ", degree = " << node[i].degree;
        cout << ", depth = " << node[i].depth;
        cout << ", height = " << node[i].height;
        cout << ", " << Type(node, i) << endl;
    }

    return 0;
}


Measured memory_bytes: 3176
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.A
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var S = ReadText();
            switch (S)
            {
                case "RRR": return 3;
                case "RRS": return 2;
                case "RSR": return 1;
                case "SRR": return 2;
                case "RSS": return 1;
                case "SRS": return 1;
                case "SSR": return 1;
                case "SSS": return 0;
            }
            return 0;
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 25960
import java.util.*;
public class Main
{
  public static void main(String args[])
  {
    Scanner in=new Scanner(System.in);
    HashSet<Integer> set=new HashSet<>();
    int n=in.nextInt();
    int arr[]=new int[n];
    for(int i=0;i<n;i++)
    {
      arr[i]=in.nextInt();
      set.add(arr[i]);
    }
    if(set.size()==n)
    {
      System.out.println("YES");
    }
    else
    {
      System.out.println("NO");
    }
  }
}
      

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

int main(void) {
	int P, Q, R;
	cin >> P >> Q >> R;

	int sum = P + Q + R;
	int max_v = max(max(P, Q), R);
	int ans = sum - max_v;

	cout << ans << '\n';
	return 0;
}


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

using namespace std;

typedef long long ll;

const ll MAX = 100001;
const ll INF = (1LL<<50);
struct Spell{
  string name,tar;
  ll MP,Dam;
  Spell(){}
  Spell(string n, ll m, string t, ll d):name(n),MP(m),tar(t),Dam(d){}
};

ll dp[2][MAX];
vector<ll> Enemy;
vector<Spell> V[2];
ll N;

void init(){
  fill(dp[0],dp[0]+2*MAX,INF);

  //for(ll i = 0; i < 2; i++) for(ll j = 0; j < MAX; j++) dp[i][j] = INF;
  V[0].clear();
  V[1].clear();
  Enemy.clear();
}

void input(){

  while(N--){
    ll in;
    cin >> in;
    Enemy.push_back(in);
  }

  ll m;
  cin >> m;
  while(m--){
    Spell s;
    cin >> s.name >> s.MP >> s.tar >> s.Dam;
    if(s.tar == "All") V[0].push_back(s);
    else V[1].push_back(s);
  }

}


void make(){

  dp[0][0] = dp[1][0] = 0;

  for(ll x = 0; x < 2; x++){
    for(ll i = 0; i < MAX; i++){
      if(dp[x][i] == INF) continue;
      for(ll j = 0; j < V[x].size(); j++){
        ll nex = min(i+V[x][j].Dam,100000LL);
        ll cos = dp[x][i]+V[x][j].MP;
        dp[x][nex] = min(dp[x][nex],cos);
      }
    }
  }
  
  ll mincos[2];
  mincos[0] = dp[0][MAX-1];
  mincos[1] = dp[1][MAX-1];
  
  for(ll i = MAX-1; i >= 0; i--){
    mincos[0] = min(mincos[0],dp[0][i]);
    mincos[1] = min(mincos[1],dp[1][i]);
    dp[0][i] = min(dp[0][i],mincos[0]);
    dp[1][i] = min(dp[1][i],mincos[1]);
  }
}

void solve(){

  ll ans = INF;

  for(ll i = 0; i < MAX; i++){

    ll cos = dp[0][i];
    for(ll j = 0; j < Enemy.size(); j++){
      ll need = max(Enemy[j]-i,0LL);
      cos+=dp[1][need];

      //    cout << "cos " << dp[1][need] << endl;
    }
    ans = min(ans,cos);
  }
  cout << ans << endl;
}


int main(){

  while(cin >> N && N){
    init();
    input();
    make();
    solve();
  }
  return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  while(1) {
    int h, w; cin >> h >> w;
    if(h == 0 && w == 0) break;
    vi suh(h+1), suw(w+1);
    int su = 0;
    REP(i, h) {
      int tmp;cin>>tmp;
      su += tmp;
      suh[i+1] = su;
    }
    su = 0;
    REP(i, w) {
      int tmp;cin>>tmp;
      su += tmp;
      suw[i+1] = su;
    }
    
    map<int, int> mah, maw;
    REP(lh, h+1) {
      FOR(rh, lh+1, h+1) {
        mah[suh[rh] - suh[lh]]++;
      }
    }
    REP(lw, w+1) {
      FOR(rw, lw+1, w+1) {
        maw[suw[rw] - suw[lw]]++;
      }
    }

    int ans = 0;
    for(auto i=mah.begin();i!=mah.end();i++) {
      ans += i->second * maw[i->first];
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 34296
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cassert>
#include <bitset>
#include <cmath>
#include <iomanip>

using namespace std;

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////
const int MOD = 1000000007;

int N;
int64 K;

using Matrix = vector<vector<int>>;

Matrix Empty() {
    return Matrix(N, vector<int>(N, 0));
}

Matrix A;

void matmul (const Matrix& A, const Matrix& B, Matrix& C) {
    C = Empty();
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            for (int k = 0; k < N; k++) {
                C[i][j] = ((int64)A[i][k] * B[k][j] + C[i][j]) % MOD;
            }
        }
    }
}

Matrix FastPow(Matrix X, int64 p) {
    if (p == 1) {
        return A;
    }
    auto R = FastPow(X, p >> 1);
    Matrix R2 = Empty();
    matmul(R, R, R2);
    if (p & 1) {
        R = R2;
        matmul(R, A, R2);
    }
    return R2;
}

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

    cin >> N >> K;

    A = Empty();

    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
            cin >> A[i][j];

    auto R = FastPow(A, K);

    // for (int i = 0; i < N; i++) {
    //     for (int j = 0; j < N; j++) {
    //         if (R[i][j]) {
    //             cerr << i << " -> " << j << " : " << R[i][j] << "\n";
    //         }
    //     }
    // }

    int res = 0;
    for (auto row : R)
        for (auto v : row)
            res = (res + v) % MOD;
    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
#define size 100000
int main() {
	int n, m;
	cin >> n >> m;
	vector<int> inns(n);
	for(int i = 0; i < n - 1; i++) {
		int si;
		cin >> si;
		inns[i] = si;
	}
	vector<int> mvs(m);
	for(int i = 0; i < m; i++) {
		int ai;
		cin >> ai;
		mvs[i] = ai;
	}
	int pos = 0;
	int inn = 0;
	int sum = 0;
	for(int i = 0; i < m; i++) {
		int nextInn = inn + mvs[i];
		int dist = 0;
		int maxInn = max(inn, nextInn);
		for(int j = min(inn, nextInn); j < maxInn; j++) {
			dist += inns[j];
		}
		sum = (sum + dist) % size;
		inn = nextInn;
	}
	cout << sum << endl;
	
}

Measured memory_bytes: 1652
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main() {


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

	int N, x = 0, y = 0;

	bool end = false;


	cin >> N;

	vector<int>A(N);

	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	
	while (end == false) {
		for (int i = 0; i < N; i++) {
			if (A[i] % 2 != 0) {
				end = true;
				break;
			}
			A[i] /= 2;

		}
		if(end==false)
			x++;

	}

	cout << x;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if (a <= b + c) {
			sb.append(b+c - a);
		} else {
			sb.append(0);
		}
		System.out.println(sb);
	}
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int
const int MAX = 510000;


using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    double w, h, x, y;
    cin >> w >> h >> x >> y;
    cout << (double)(w * h) / 2.0 << " ";
    if(x == (double)w / 2.0 && y == (double)h / 2.0)cout << "1" << endl;
    else cout << "0" << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(int (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(int (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define INF 1000000007
#define LINF 1000000000000000007
typedef long long ll;
using namespace std;

int main(){
  ll H,W,count4=0,count2=0,count1=0;
  bool ans = 0;
  cin >> H >> W;
  vector<char> v(H*W);
  FOR(i,0,H*W){
    cin >> v[i];
  }
  sort(ALL(v));
  for(char c = 'a';c <= 'z';c++){
    int n = upper_bound(ALL(v),c)-lower_bound(ALL(v),c);
    while(n){
      if(n > 3){
        count4++;
        n -= 4;
      }
      else if(n > 1){
        count2++;
        n -= 2;
      }
      else{
        count1++;
        n -= 1;
      }
    }
  }
  if(W%2)swap(H,W);
  if(H%2 && W%2){
    if(count1 == 1 && count2 <= H/2+W/2){
      ans = 1;
    }
  }
  else if(H%2 == W%2){
    if(!count2 && !count1){
      ans = 1;
    }
  }
  else{
    if(!count1 && count2 <= W/2){
      ans = 1;
    }
  }
  cout << (ans ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
n = int(input())
l = list(map(int,input().split()))
k = 0
m = 0
for _ in range(100):
    for i in range(len(l)) :
        if l[i] % 2 != 0  :
            m = 10
            break
        else:
            l[i] = l[i]/2
    if m != 0 :
        break
    k += 1
print(k)


Measured memory_bytes: 2940
/*
lakshaygpt28
Lakshay Gupta
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
using vll = vector < ll >;

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;


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

#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 1e5 + 10;

int main() {
    fast_io();
    ll n, d;
    cin >> n >> d;
    if (n % (2 * d + 1) == 0) {
        cout << n / (2 * d + 1) << "\n";
    } else {
        cout << (n + 2 * d + 1) / (2 * d + 1) << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn runlength<A: Copy + PartialEq>(xs: &Vec<A>) -> Vec<usize> {
    let m = xs.len();
    if m == 0 { return vec![]; }
    let mut count = 1;
    let mut result = vec![];
    for i in 0..m {
        if i > 0 {
            if xs[i - 1] == xs[i] {
                count += 1;
            } else {
                count = 1;
            }
        }
        if i == m - 1 || xs[i] != xs[i + 1] {
            result.push(count);
        }
    }
    result
}
fn main() {
    let mut sc = Scanner::new();
    let s: Vec<char> = sc.cin::<String>().chars().collect();
    let k: usize = sc.cin();
    let g = runlength(&s);

    if g.len() == 1 {
        put!(k * s.len() / 2);
    } else if s[0] != s[s.len() - 1] {
        put!(g.iter().map(|&x| x / 2).sum::<usize>() * k);
    } else {
        let m = g.len();
        put!(g[0] / 2 + g[m - 1] / 2
            + k * (1..m-1).map(|i| g[i] / 2).sum::<usize>()
            + (k - 1) * ((g[0] + g[m - 1]) / 2));
    }
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 4352
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define break break
#define continue continue
#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define LLPair pair<ll, ll>
#define vint vector<int>
#define vll vector<ll>
typedef long long ll;

using namespace std;


int main(void){
	int n; cin>> n;
	vint a(n); rep(i, n) cin >> a[i];
	int now = 1;
	int ans = 0;
	rep(i, n){
		if(a[i] != now) ans++;
		else now++;
	}
	if(now == 1) ans = -1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
import Control.Applicative
import Data.List

searchedge1 []=(0,[])
searchedge1 [x]=(0,[])
searchedge1 (x:y:xs)
    |x==y = (x,xs)
    |otherwise = searchedge1 (y:xs)

searchedge2 []=0
searchedge2 [x]=0
searchedge2 (x:y:xs)
    |x==y = x
    |otherwise = searchedge2 (y:xs)

solver xs =(\(x,y)->(x*y)) $(\(y,ys)->(y,searchedge2 ys))$ searchedge1 xs
 
main :: IO ()
main = do
    getLine
    xs <- map read . words <$> getLine
    putStrLn $ show $ solver $ reverse (sort  xs)

Measured memory_bytes: 40060
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		char[] str = sc.next().toCharArray();
		for(int i=0;i<5;i++) {
			System.out.print(str[i]);
		}
		System.out.print(" ");
		for(int i=6;i<13;i++) {
			System.out.print(str[i]);
		}
		System.out.print(" ");
		for(int i=14;i<19;i++) {
			System.out.print(str[i]);
		}
	}
}


Measured memory_bytes: 22100
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        final long A = Long.parseLong(sc.next());
        final long B = Long.parseLong(sc.next());
        final int K = Integer.parseInt(sc.next());
        Set<Long> set = new TreeSet<>();
        
        int cnt = 0;
        for (long i = A; i <= B; i++) {
            cnt++;
            if (cnt > K) {
                break;
            } else {
                set.add(i);
            }
        }
        
        cnt = 0;
        for (long i = B; i >= A; i--) {
            cnt++;
            if (cnt > K) {
                break;
            } else {
                set.add(i);
            }
        }
        
        set.forEach(i -> out.println(i));
        
        out.flush();
    }
}

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

const int R = 5, A = 441, B = 21;
const int mod = A * (1 << B) + 1;
const int MN = 200010;

int exp(int x, int n) {
    int ret = 1;
    while(n) {
        if(n & 1) ret = 1LL * ret * x % mod;
        x = 1LL * x * x % mod;
        n >>= 1;
    }
    return ret;
}
int inv(int x) {
    return exp(x, mod - 2);
}
int fact[MN], invf[MN];
int comb(int n, int k) {
    return 1LL * fact[n] * invf[k] % mod * invf[n - k] % mod;
}

void ntt(vector<int> &a, bool invert) {
    int n = a.size();
    for(int i = 1, j = 0; i < n; i++) {
        int bit = n >> 1;
        for(;j >= bit; bit >>= 1) j -= bit;
        j += bit;
        if(i < j) swap(a[i], a[j]);
    }
    for(int len = 2; len <= n; len <<= 1) {
        int wlen = exp(invert? inv(R) : R, A * (1 << B) / len);
        for(int i = 0; i < n; i += len) {
            int w = 1;
            for(int j = 0; j < len / 2; j++) {
                int u = a[i + j], v = 1LL * a[i + j + len / 2] * w % mod;
                a[i + j] = (u + v) % mod;
                a[i + j + len / 2] = (u + mod - v) % mod;
                w = 1LL * w * wlen % mod;
            }
        }
    }
    if(invert) {
        int x = inv(n);
        for(int i = 0; i < n; i++) a[i] = 1LL * a[i] * x % mod;
    }
}
void multiply(vector<int> &a, vector<int> &b) {
    int n = 1;
    while(n < max(a.size(), b.size())) n <<= 1;
    n <<= 1;
    a.resize(n); ntt(a, false);
    b.resize(n); ntt(b, false);
    for(int i = 0; i < n; i++) a[i] = 1LL * a[i] * b[i] % mod;
    ntt(a, true);
}

int N;
vector<int> adj[MN];
int sz[MN], cnt[MN];
vector<int> X, Y;

void dfs(int u, int p) {
    sz[u] = 1;
    for(int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i];
        if(v == p) continue;
        dfs(v, u);
        sz[u] += sz[v];
        cnt[ sz[v] ]++;
    }
    cnt[ N - sz[u] ]++;
}

int main() {
    fact[0] = 1;
    for(int i = 1; i < MN; i++) {
        fact[i] = 1LL * fact[i - 1] * i % mod;
    }
    for(int i = 0; i < MN; i++) {
        invf[i] = inv(fact[i]);
    }

    scanf("%d", &N);

    for(int i = 0; i < N - 1; i++) {
        int a, b; scanf("%d %d", &a, &b);
        a--; b--;

        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    dfs(0, -1);

    for(int i = 0; i < N; i++) {
        X.push_back(1LL * cnt[i] * fact[i] % mod);
    }
    for(int i = 0; i < N; i++) {
        Y.push_back(invf[i]);
    }
    reverse(Y.begin(), Y.end());
    multiply(X, Y);

    for(int i = 1; i <= N; i++) {
        int ans = 1LL * comb(N, i) * N % mod;
        ans += mod - 1LL * X[N - 1 + i] * invf[i] % mod;
        ans %= mod;
        printf("%d\n", ans);
    }
}


Measured memory_bytes: 33752
#include "bits/stdc++.h"
using namespace std;
 
int main(){
	int n;
	cin>>n;
	vector<int> a(n);
	vector<int> b(n);
	vector<int> c(n);
	
	for(long long int i=0;i<n;i++){
		cin>>a[i];
	}
	for(long long int i=0;i<n;i++){
		cin>>b[i];
	}
	for(long long int i=0;i<n;i++){
		cin>>c[i];
	}
	
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	sort(c.begin(),c.end());
	
	long long int ans=0;
	
	long long int up=0;
	
	long long int j=0;
	long long int k=0;
	
	for(long long int i=0;i<n;i++){
		while(a[j]<b[i]&&j<n){
			j++;
		}
		while(b[i]>=c[k]&&k<n){
			k++;
		}
		//cout<<j<<" "<<(n-k)<<endl;
		ans+=j*(n-k);
	}
	
	cout<<ans<<endl;
	
	return 0;
}

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

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

    vector<int> a(N-1), ans(N, 0);

    for(int i=0; i<N-1; i++){
	cin >> a[i];
	ans[a[i]-1]++;
    }
    for(auto i: ans){
	cout << i << endl;
    }

} 




Measured memory_bytes: 4844
#n,m=map(int,input().split())
#a=list(map(int,input()))
#s=input()
def main(n,xy):
  d=[x+y for x,y in xy]
  d.sort()
  ans=d[-1]-d[0]
  maxx=max([x for x,y in xy])
  dr=[(maxx-x)+y for x,y in xy]
  dr.sort()
  ans=max(ans,dr[-1]-dr[0])
  return ans
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
print(main(n,xy))


Measured memory_bytes: 119412
def dfs(g,root,ds):
    q = [root]
    ds[root] = 0
    while q:
        v = q.pop()
        for c in g[v]:
            if ds[c] == -1:
                ds[c] = ds[v] + 1
                q.append(c)
        



# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
 
#n = int(input())
n,u,v = [int(i) for i in readline().split()]
u -= 1
v -= 1
 
g = [[] for _ in range(n)]
for i in range(n-1):
    a,b = [int(i) for i in readline().split()]
    g[a-1].append(b-1)
    g[b-1].append(a-1)
 
ds = [-1]*n
dg = [-1]*n

dfs(g,u,ds)
dfs(g,v,dg)

#print(ds,dg)

ans = 0
for i,j in zip(ds,dg):
    if i < j: ans = max(j-1,ans)
    
print(ans)







Measured memory_bytes: 29104
import java.util.*;
import java.io.*;

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };
	static final int INF = Integer.MAX_VALUE / 3;
	static final long LINF = Long.MAX_VALUE / 3;

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int n = fs.nextInt();
		int a[] = fs.nextIntArray(n);
		Arrays.sort(a);
		boolean ok = true;
		int min = a[0];
		while(ok) {
			int nmin = INF;
			for(int i=0;i<n;i++) {
				if(a[i]==min)continue;
				a[i] %= min;
				if(a[i]!=0) nmin = Math.min(nmin, a[i]);
			}
			Arrays.sort(a);
			
			if(nmin==INF)ok=false;
			else min = nmin;
		}
		System.out.println(min);
	}

	//MOD culculations
	static long plus(long x, long y) {
		long res = (x + y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long sub(long x, long y) {
		long res = (x - y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long mul(long x, long y) {
		long res = (x * y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long div(long x, long y) {
		long res = x * pow(y, mod - 2) % mod;
		return res < 0 ? res + mod : res;
	}

	static long pow(long x, long y) {
		if (y < 0)
			return 0;
		if (y == 0)
			return 1;
		if (y % 2 == 1)
			return (x * pow(x, y - 1)) % mod;
		long root = pow(x, y / 2);
		return root * root % mod;
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}


Measured memory_bytes: 36996
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans=max({a*c,a*d,b*c,b*d});
    cout<<ans<<endl;
    
    


    return 0;

}

Measured memory_bytes: 3504
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[] k = new int[M]; // 電球iはk個のスイッチとつながる
		int[][] s = new int[M][N];
		for (int i = 0; i < M; i++) {
			k[i] = sc.nextInt();
			for (int j = 0; j < k[i]; j++) {
				s[i][sc.nextInt() - 1] = 1;
			}
		}
		int[] p = new int[M];
		for (int i = 0; i < M; i++) {
			p[i] = sc.nextInt();
		}
		sc.close();

		// bit全探索
		int ans = 0;
		for (int i = 0; i < (Math.pow(2, N)); i++) {
			int[] sw = new int[N];
			boolean isOk = true;
			for (int j = 0; j < N; j++) { // スイッチの点灯
				if ((1 & i >> j) == 1) {
					sw[j] = 1;
				}
			}
			for (int m = 0; m < M; m++) { // 各電球
				int cnt = 0;
				for (int n = 0; n < N; n++) { // 各スイッチ
					if (s[m][n] == 1 && sw[n] == 1)
						cnt++;
				}
				if (cnt % 2 != p[m]) {
					isOk = false;
				}
			}
			if (isOk) {
				ans++;
			}
		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 23124
N = input()
s = input()
hoge = []
charlist = list(s)
result = 1
Alist = ["q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m"]
for i in Alist:
    hoge.append(charlist.count(i))
for j in hoge:
    result = result * (j + 1)
print((result -1) % (10 ** 9 + 7))


Measured memory_bytes: 3956
n,m = map(int,input().split())
py = []
li = [1] * (10**5 + 10)

for i in range(m):
    p,y = map(int,input().split())
    py.append((p,y,i))

py.sort(key = lambda x: x[1])

ans = []

for p,y,i in py:
    ans_tmp = '0' * (6 - len(str(p))) + str(p) + '0' * (6 - len(str(li[p]))) + str(li[p])
    li[p] += 1
    ans.append([ans_tmp, i])

ans.sort(key = lambda x: x[1])
for i in range(m):
    print(ans[i][0])


Measured memory_bytes: 39776
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int [][] cell = new int[r+1][c+1];
		int sum1 = 0;
		for(int i=0; i<r; i++) {
			for(int j=0; j<c; j++) {
				cell[i][j] = sc.nextInt();
			}
		}
		for(int i=0; i<r; i++) {
			for(int j=0; j<c; j++) {
				System.out.printf("%d ", cell[i][j]);
				sum1 += cell[i][j];
			}
			System.out.printf("%d\n", sum1);
			sum1 = 0;
		}
		int sum2 = 0;
		for(int i=0; i<c; i++) {
			for(int j=0; j<r; j++) {
				sum1 += cell[j][i];
			}
			sum2 += sum1;
			System.out.printf("%d ", sum1);
			sum1 = 0;
		}
		System.out.printf("%d\n",sum2);
	}
}



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

template<typename T>
class Dijk{
    private:
        ll n;
        vector<vector<pair<ll, T>>> v;
        function<bool(pair<ll, T>, pair<ll, T>)> comp;
    public:
        T INF;
        
        Dijk(const vector<vector<pair<ll, T>>> &v, T INF, function<bool(pair<ll, T>, pair<ll, T>)> comp){
            this->n = v.size();
            this->v = v;
            this->INF = INF;
            this->comp = comp;
        }
        
        vector<T> dijk(ll start){
            vector<T> d(n, INF);
            d[start] = 0;
            priority_queue<pair<ll, T>, vector<pair<ll, T>>, function<bool(pair<ll, T>, pair<ll, T>)>> q(comp);
            q.push(pair<ll, T>(start, 0));
            while(q.size()){
                pair<ll, T> now = q.top();
                q.pop();
                if(d[now.first] < now.second){
                    continue;
                }
                for(auto next : v[now.first]){
                    if(d[next.first] == INF || d[now.first] + next.second < d[next.first]){
                        d[next.first] = d[now.first] + next.second;
                        q.push(pair<ll, T>(next.first, d[now.first] + next.second));
                    }
                }
            }
            return d;
        }
};

struct Circle{
    ld x, y, r;
};

vector<vector<pair<ll, ld>>> v(1002);
ll N;

ld dist(pair<ld, ld> x, pair<ld, ld> y){
    return sqrt(pow(x.first - y.first, 2) + pow(x.second - y.second, 2));
}

ld dist(Circle a, Circle b){
    return dist(pair<ld, ld>(a.x, a.y), pair<ld, ld>(b.x, b.y));
}

int main(){
    pair<ld, ld> start, goal;
    cin >> start.first >> start.second >> goal.first >> goal.second;
    cin >> N;
    vector<Circle> C;
    C.push_back(Circle{start.first, start.second, 0});
    C.push_back(Circle{goal.first, goal.second, 0});
    for(ll i = 0; i < N; i++){
        ld x, y, r;
        cin >> x >> y >> r;
        C.push_back(Circle{x, y, r});
    }
    for(ll i = 0; i < C.size(); i++) for(ll j = 0; j < C.size(); j++) v[i].push_back(pair<ll, ld>(j, max<ld>(0, dist(C[i], C[j]) - C[i].r - C[j].r)));
    Dijk<ld> D(v, 5e15, [&](pair<ll, ld> a, pair<ll, ld> b){return a.second > b.second;});
    printf("%.1333Lf\n", D.dijk(0)[1]);
    return 0;
}


Measured memory_bytes: 73196
n, k = map(int, input().split())
lr = []
for _ in range(k):
    lr.append(tuple(map(int, input().split())))
mod = 998244353

dp = [0]*n
dp[0] = 1

acc = [0]*n
acc[0] = 1

for i in range(1, n):
    for l, r in lr:
        if 0 <= i-r and i-l < i:
            dp[i] += acc[i-l]-acc[i-r-1]
        elif i-r < 0 and i-l < i:
            dp[i] += acc[i-l]
        elif i-r < 0 and i <= i-l:
            dp[i] += acc[i-1]
        elif 0 < i-r and i <= i-l:
            dp[i] += acc[i-1]-acc[i-r-1]
    acc[i] = acc[i-1]+dp[i]%mod

print(dp[-1]%mod)

Measured memory_bytes: 76724
#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {
  int R, G, B, N;
  cin >> R >> G >> B >> N;

  int ret = 0;
  for (int i = 0; i <= N / R; ++i) {
    int rest = N - i * R;
    if (rest < 0)
      continue;
    for (int j = 0; j <= rest / G; ++j) {
      int rest2 =  rest - j * G;
      if (rest2 < 0)
        break;
      if (rest2 % B == 0)
        ++ret;
    }
  }

  cout << ret << endl;

  return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

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

    string s1, s2;
    while (cin >> s1, s1 != ".")
    {
        cin >> s2;
        vector<string> v1, v2;
        string tmp = "";
        int cnt = 0;
        int len = s1.length();
        for (int i = 0; i < len; i++)
        {
            if (s1[i] == '"')
            {
                if (cnt == 0)
                {
                    v1.push_back(tmp);
                    tmp = "";
                    tmp += '"';
                    cnt++;
                }
                else
                {
                    tmp += '"';
                    v1.push_back(tmp);
                    tmp = "";
                    cnt = 0;
                }
                continue;
            }
            tmp += s1[i];
        }
        v1.push_back(tmp);

        tmp = "";
        cnt = 0;
        len = s2.length();
        for (int i = 0; i < len; i++)
        {
            if (s2[i] == '"')
            {
                if (cnt == 0)
                {
                    v2.push_back(tmp);
                    tmp = "";
                    tmp += '"';
                    cnt++;
                }
                else
                {
                    tmp += '"';
                    v2.push_back(tmp);
                    tmp = "";
                    cnt = 0;
                }
                continue;
            }
            tmp += s2[i];
        }
        v2.push_back(tmp);

        if (v1.size() != v2.size())
        {
            cout << "DIFFERENT" << endl;
            continue;
        }
        cnt = 0;
        int sz = v1.size();
        for (int i = 0; i < sz; i++)
        {
            if (v1[i] == v2[i])
                continue;
            if (v1[i][0] == '"' && v2[i][0] == '"')
            {
                cnt++;
            }
            else
            {
                cnt = 100;
            }
        }
        if (cnt == 0)
            cout << "IDENTICAL" << endl;
        else if (cnt == 1)
            cout << "CLOSE" << endl;
        else
            cout << "DIFFERENT" << endl;
    }
}



Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
  
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int N, K; cin >> N >> K;
    vector<pair<ll, ll>> dt(N);
    for(int i=0; i<N; i++) cin >> dt[i].second >> dt[i].first;
    sort(dt.begin(), dt.end(), greater<pair<ll,ll>>());

    ll ans = 0;
    map<ll, ll> mp; // map<type, cnt>
    ll size = 0;

    for(int i=0; i<K; i++){
        ans += dt[i].first;
        mp[dt[i].second]++;
    }

    size = mp.size();
    ans += size*size;
    ll tmp = ans;

    int del = K-1, add = K;
    while(del>=0 && add<N){
        while(mp[dt[del].second]==1 && del>=0) del--;
        if(del<0) break;
        mp[dt[del].second]--;
        
        while(mp[dt[add].second]!=0 && add<N) add++;
        if(add>=N) break;
        mp[dt[add].second]++;

        tmp = tmp-dt[del].first+dt[add].first-size*size+(size+1)*(size+1);
        ans = max(ans, tmp);
        size++;

        del--;
        add++;
    }

    cout << ans << endl;

}

Measured memory_bytes: 5760
#include <stdio.h>
 
int N;
int parent[100001];
int sibling[100001];
int degree[100001];
 
int calcDepth(int i) {
  if(parent[i] == -1) return 0;
  return calcDepth(parent[i]) + 1;
}
 
int calcHeight(int i) {
  int j, h;
  h = 0;
  for(j = 0; j < N; ++j) {
    if(parent[j] == i) {
      int tmp = calcHeight(j) + 1;
      if(tmp > h) h = tmp;
    }
  }
  return h;
}
 
int main() {
  int i,j;
  scanf("%d", &N);
  for(i = 0; i < N; ++i) {
    parent[i] = -1;
    sibling[i] = -1;
    degree[i] = 0;
  }
  for(i = 0; i < N; ++i) {
    int id, left, right;
    scanf("%d %d %d", &id, &left, &right);
    if(left != -1) {
      parent[left] = id;
      sibling[left] = right;
      ++degree[id];
    }
    if(right != -1) {
      parent[right] = id;
      sibling[right] = left;
      ++degree[id];
    }
  }
 
  for(i = 0; i < N; ++i) {
    int depth = calcDepth(i);
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",
           i, parent[i], sibling[i], degree[i], depth, calcHeight(i));
    if(depth == 0) {
      printf("root\n");
    } else if(degree[i] == 0) {
      printf("leaf\n");
    } else {
      printf("internal node\n");
    }
  }
  return 0;
}


Measured memory_bytes: 2768
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX;
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;



int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	
	
	int i,n,d=0;
	cin>>n;
	int a[n+2];
	a[0]=a[n+1]=0;
	for(i=1;i<n+1;i++)cin>>a[i];
	for(i=0;i<n+1;i++){
		d+=abs(a[i]-a[i+1]);
//		cout<<a[i]<<" "<<a[i+1]<<" "<<d<<endl;
	}
//	cout<<d<<endl;
	for(i=1;i<n+1;i++){
		cout<<d-abs(a[i-1]-a[i])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1])<<endl;
	}
	
	
	
	
	
	
	
	
//////////////////////////////////////////////////////
	return 0;
}








Measured memory_bytes: 1664
n, t = map(int, input().split())
ct = [list(map(int, input().split())) for _ in range(n)]

m = 0

for l in ct:
    if l[1] > t:
        continue
    
    if m == 0 or l[0] < m:
        m = l[0]

if m == 0:
    print("TLE")
    exit(0)

print(m)


Measured memory_bytes: 3060
import Foundation
let main: () = {
    let N = nextInt()
    var A = listOfInt(-1)
    var ans = Array(N) { 0 }
    A.forEach { ans[$0] += 1 }
    print(ans.joinToString("\n"))
}()
@inlinable func next() -> String { readLine()! }
@inlinable func nextInt() -> Int { Int(next())! }
@inlinable func nextDouble() -> Double { Double(next())! }
@inlinable func listOfString() -> [String] { next().split(separator: " ").map(String.init) }
@inlinable func listOfInt(_ offset: Int = 0) -> [Int] { listOfString().map { Int($0)! + offset } }
extension Array {
    init(_ size: Int, _ initValue: (() -> Element)) {
        self = [Element]()
        for _ in 0 ..< size {
            let value = initValue()
            self.append(value)
        }
    }
}
extension Array where Element == Int {
    @inlinable func joinToString(_ sepatator: String = " ") -> String { self.map { String($0) }.joined(separator: sepatator) }
}


Measured memory_bytes: 23584
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FOR(i) for(cin>>i;i>0;i--)
#define elif else if
#define pb push_back
#define ll long long
#define mp make_pair
#define all(x) x.begin(),x.end()
#define re(x) {cout<<x<<endl;return 0;}
//#define x first
//#define y second

using namespace std;
int n,m;
int main()
{
	cin>>n>>m;
	cout<<n*(n-1)/2+m*(m-1)/2<<endl; 
	return 0;}

Measured memory_bytes: 256