akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/

ll d[100005];

int main() {
    cin >> n >> m;
    vp v(n), vd(n);
    REP(i, n) {
        cin >> v[i].first >> v[i].second;
    }

    ll now = 0;
    vp va, vb;
    vi ga(n), gb(n), vaa, vbb;
    REP(i, n) {
        cnt = v[i].first - now;
        ans += v[i].second;
        ans -= cnt;
        va.push_back({ ans,v[i].first });
        now = v[i].first;
    }
    cnt = 0;
    ans = 0;
    now = m;
    RREP(i, n) {
        cnt = now - v[i].first;
        ans += v[i].second;
        ans -= cnt;
        vb.push_back({ ans,m-v[i].first });
        now = v[i].first;
    }

    ga[0] = va[0].first - va[0].second;
    FOR(i, 1, n) {
        ga[i] = max(ga[i - 1], va[i].first - va[i].second);
    }
    gb[0] = vb[0].first - vb[0].second;
    FOR(i, 1, n) {
        gb[i] = max(gb[i - 1], vb[i].first - vb[i].second);
    }
    ans = 0;
    REP(i, n) {
        chmax(gb[i], ans);
        chmax(ga[i], ans);
    }


    REP(i,n-1) {
        //cout << vb[i].first << " + " << ga[n - 2 - i] << "  = " << vb[i].first + ga[n - 2 - i] << endl;
        vbb.push_back(vb[i].first + ga[n - 2 - i]);
    }
    //cout << vb.back().first << endl;
    vbb.push_back(vb.back().first);

    

    REP(i, n - 1) {
        //cout << va[i].first << " + " << gb[n - i - 2] << "  = " << va[i].first + gb[n - i - 2] << endl;
        vaa.push_back(va[i].first + gb[n - i - 2]);
    }
    //cout << va.back().first << endl;
    vaa.push_back(va.back().first);


    sort(ALL(vaa));
    sort(ALL(vbb));
    cout << max(ans,max(vaa.back(), vbb.back())) << endl;
}

Measured memory_bytes: 10736
def cls(i):
    if i < 60:
        return i // 10
    else:
        return 6

def answer(n,d):
    tbl = [ 0 for i in range(7) ]
    for i in range(n):
        c = cls(d[i])
        tbl[c] += 1
    return tbl

while True:
    n = int(input())
    if n == 0:
        break
    d = [int(input()) for i in range(n)]
    o = answer(n,d)
    for i in range(7):
        print(o[i])

Measured memory_bytes: 15540
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int64_t N,M;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N>>M;
	if (N < M) { std::swap(N, M); }
	if (M == 1) {
		if (N == 1) { out << 1 << endl; }
		else {
			out << N - 2 << endl;
		}
	}
	else {
		out << (N - 2)*(M - 2) << endl;
	}
	

	return 0;
}
#endif


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

template <typename T, typename K> struct P {
	T a; K b;
};
typedef struct {
	vector <int> to;
	bool is_visited = false;
} node;
typedef struct {
	int to;
	int cost;
	P <int, int> change;
} edge;
int main( void ){
	int N; cin >> N;
	N--;
	vector <vector <int> > input( N, vector <int>( 3 ));
	rep( i, 0, N ){
		rep( j, 0, 3 ){
			cin >> input[ i ][ j ];
		}
	}
	rep( index, 0, N ){
		int sum = input[ index ][ 1 ] + input[ index ][ 0 ];
		rep( i, index + 1, N ){
			if (sum < input[i][1]){
				sum = input[i][1];
			}
			else if (sum%input[i][2]!= 0){
				sum += input[i][2] - (sum %input[i][2]);
			}
			sum += input[i][0];
		}
		cout << sum << endl;
		// break;
	}
	cout << "0\n";
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 256
h,n = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
INF = 10 ** 18
dp = [10 ** 18] * (h+1)
dp[0] = 0
for i in range(h):
  for a,b in ab:
    c = min(h,i+a)
    dp[c] = min(dp[c],dp[i]+b)
ans = dp[h]
print(ans)

Measured memory_bytes: 42076
#include <stdio.h>
#define R_MAX 10
#define POW_R_WITH_2 0x400
#define C_MAX 10000

int crackers[R_MAX][C_MAX];
int row,column;

int progress[R_MAX];

int incf(void){
	int digit = row;
	while(digit--){
		progress[digit] ^= 1;
		if(progress[digit]){
			return 0;
		}
	}
	return 1;
}

int solve(void){
	int i,j;
	int answer = 0;
	memset(progress, 0, sizeof(int) * row);
	for(;;){
		int maybe_answer = 0;
		for(j = 0; j < column; j++){
			int longitu_crks = 0;
			for(i = 0; i < row; i++){
				longitu_crks += (crackers[i][j] ^ progress[i]);
			}
			if(longitu_crks > row / 2)
				maybe_answer += longitu_crks;
			else
				maybe_answer += (row - longitu_crks);
		}
		if(answer < maybe_answer){
			answer = maybe_answer;
		}
		if(incf())
			break;
	}
	return printf("%d\n", answer);
}

int main(void){
	while(scanf("%d%d", &row, &column), (column || row)){
		int in_row,in_column;
		for(in_row = 0; in_row < row; in_row++){
			for(in_column = 0; in_column < column; in_column++){
				scanf("%d", &crackers[in_row][in_column]);
			}
		}
		solve();
	}
	return 0;
}

Measured memory_bytes: 996
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int a, b;
    cin >> a >> b;
    string x = "", y = "";
    for (int i = 0; i < a; ++i)
        x += (char) ('0' + b);
    for (int i = 0; i < b; ++i)
        y += (char) ('0' + a);
    cout << min(x, y);
    return 0;
}


Measured memory_bytes: 256
//
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

int main(){

    ll N;
    cin >> N;
    if(N == 1){
        cout << 1 << endl;
        cout << 0 << endl;
    }
    else if(N == 2){
        cout << 2 << endl;
        cout << 0 << endl;
        cout << 11 << endl;
    }
    else{
        cout << N - 1 << endl;
        rep(i, N - 1){
            cout << 1;
            rep(j, i)cout << 0;
            cout << 1 << endl;
        }
        
    }

    return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2　//1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

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

    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]){
      cout << "Yes\n";
    } else {
      cout << "No\n";
    }
    return 0;
} 


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define set_bits(a) __builtin_popcount(a)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define M 998244353
#define fi first
#define se second
#define endl '\n'
#define INF 1e18
#define PI 3.14159265358979323846
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


int main()
{
     ll n,i,j;
     cin>>n;
     ll sum=0;
     unordered_map<ll,ll>mp;
     ll arr[n];
     for(i=0;i<n;i++)
     {
         cin>>arr[i];
         sum+=arr[i];
         mp[arr[i]]++;
     }

     ll q;
     cin>>q;
     while(q--)
     {
         ll a,b;
         cin>>a>>b;

         if(mp.find(a)!=mp.end())
         {
             ll x = mp[a];
             ll p = a*x;
             sum-=p;

             sum = sum + x*b;
             cout<<sum<<endl;

             mp[b] += mp[a];
             mp.erase(a);
         }
         else
         {
             cout<<sum<<endl;
         }

     }
}


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

using namespace std;

typedef long long ll;

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const double EPS = 1e-9;
const ll INF = 1e17;

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

	ll n, m;
	cin >> n >> m;

	ll l = -1, r = max(n, m) + 1;

	while (r - l > 1) {
		ll mid = (l + r) / 2;

		if (m - max(0LL, mid - n) * 2 - mid * 2 >= 0) {
			l = mid;
		} else {
			r = mid;
		}
	}

	cout << l << "\n";

	return 0;
}


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int ac = 0;
  int wa = 0;
  int re = 0;
  int tle = 0;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    ac += (s == "AC");
    wa += (s == "WA");
    re += (s == "RE");
    tle += (s == "TLE");
  }
  cout << "AC x " << ac << '\n';
  cout << "WA x " << wa << '\n';
  cout << "TLE x " << tle << '\n';
  cout << "RE x " << re << '\n';
}


Measured memory_bytes: 3632
N, K = map(int, input().split())
p = list(map(int, input().split()))
tmp = []
before = (sum(p[:K]) + K) / 2
tmp.append(before)
for i in range(1, N-K+1):
    cur = before - (p[i-1] + 1) / 2 + (p[i+K-1] + 1) / 2
    tmp.append(cur)
    before = cur
print(max(tmp))

Measured memory_bytes: 25060
S = int(input())

def solve() :
    ret = 0
    lst = [0]
    pre, cur = 0, len(lst)
    for _ in range(10) :
        for i in range(pre, cur) :
            for j in [3, 5, 7] :
                s = lst[i]*10+j
                if s > S :
                    return ret
                lst.append(s)
                s = str(s)
                if '3' in s and '5' in s and '7' in s :
                    ret += 1
        pre, cur = cur, len(lst)

print(solve())

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

ll H, W, x, y;

void solve() {
  double s = (double)H * (double)W / 2.0;
  cout << fixed << setprecision(10) << s << ' ';
  if (2 * x == H && 2 * y == W) {
    cout << 1 << '\n';
  } else {
    cout << 0 << '\n';
  }
}

int main() {
  cin >> H >> W >> x >> y;
  solve();
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using E = System.Linq.Enumerable;
class Program
{

    static void Main(string[] args)
    {
        Solve();
    }
    static long ans;
    static long[] map = new long[13];
    static void Solve()
    {
        //var NM = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        var N = long.Parse(Console.ReadLine());
        var D = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        ans = D.Min();
        for (int i = 0; i < N; i++)
        {
            map[D[i]]++;
        }
        ans = Math.Min(ans, Cul(0, new List<long>()));
        Console.WriteLine(ans);
    }

    static long Cul(int depth,List<long> nums)
    {
        if(depth == 13)
        {
            long tmp = long.MaxValue;
            for (int i = 0; i < nums.Count; i++)
            {
                for (int j = i+1; j < nums.Count; j++)
                {
                    var diff = Math.Abs(nums[i] - nums[j]);
                    diff = Math.Min(24 - diff, diff);
                    tmp = Math.Min(tmp, diff);
                }
            }
            return tmp;
        }
        else
        {
            var next1 = new List<long>(nums);
            var next2 = new List<long>(nums);
            if(map[depth] == 0)
            {
                return Cul(depth + 1, next1);
            }
            else if (map[depth] == 1)
            {
                next1.Add(depth);
                next2.Add(24 - depth);
                return Math.Max(Cul(depth + 1, next1), Cul(depth + 1, next2));
            }
            else if (map[depth] == 2){
                next1.Add(depth);
                next1.Add(24 - depth);
                return Cul(depth + 1, next1);
            }
            else
            {
                return 0;
            }
        }
    }

}



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

class Main{
    public static void main(String[] args){
        FastScanner fsc=new FastScanner();
        int n=fsc.nextInt();
        int k=fsc.nextInt();
        fsc.close();
        int ans=k;
        for(int i=0;i<n-1;i++){
            ans*=(k-1);
        }
        System.out.println(ans);
    }
    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte(){
            if(ptr<buflen) return true;
            else{
                ptr = 0;
                try{
                    buflen = in.read(buffer);
                }
                catch(IOException e){
                    e.printStackTrace();
                }
                if(buflen<=0) return false;
            }
        return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }
                else if(b == -1 || !isPrintableChar(b)) return minus ? -n : n;
                else throw new NumberFormatException();
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
        public void close(){
            try{in.close();}
            catch(IOException e){e.printStackTrace();}
        }
    }
}


Measured memory_bytes: 21204
let (p1, p2, p3) = (257, 251, 1000000007)

let pow x n =
  let rec doit i acc =
    if i = n then acc
    else doit (i + 1) (acc*x mod p3) in
  doit 0 1

let solve a (h, w) b (r, c) =
  let make_hash v (y, x) =
    let h1 = Array.make_matrix y x 0 in
    let c1 = pow p1 c in
    let rec duduwa i =
      if i < y then begin
        let rec calc_z j acc =
          if j = c then acc
          else calc_z (j + 1) ((acc*p1 + Char.code v.(i).(j)) mod p3) in
        let rec aux j z =
          if j = x - c then h1.(i).(j) <- z
          else begin
            h1.(i).(j) <- z;
            let new_z = (z*p1 - (Char.code v.(i).(j))*c1 + Char.code v.(i).(j+c)) mod p3 in
            aux (j + 1) (if new_z < 0 then new_z + p3 else new_z)
          end in
        aux 0 (calc_z 0 0);
        duduwa (i + 1)
      end in
    duduwa 0;
    let h2 = Array.make_matrix y x 0 in
    let c2 = pow p2 r in
    let rec doit j =
      if j < x then begin
        let rec calc_z i acc =
          if i = r then acc
          else calc_z (i + 1) ((acc*p2 + h1.(i).(j)) mod p3) in
        let rec aux i z =
          if i = y - r then h2.(i).(j) <- z
          else begin
            h2.(i).(j) <- z;
            let new_z = (z*p2 - h1.(i).(j)*c2 + h1.(i+r).(j)) mod p3 in
            aux (i + 1) (if new_z < 0 then new_z + p3 else new_z)
          end in
        aux 0 (calc_z 0 0);
        doit (j + 1)
      end in
    doit 0;
    h2 in
  let s = make_hash a (h, w) in
  let t = make_hash b (r, c) in
  let rec doit = function
    | (i, _) when i > h - r -> ()
    | (i, j) when j > w - c -> doit (i + 1, 0)
    | (i, j) ->
      if s.(i).(j) = t.(0).(0) then Printf.printf "%d %d\n" i j;
      doit (i, j + 1) in
  doit (0, 0)

let split str delim =
  let open String in
  let rec doit s acc =
    match
      try Some (rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i -> doit (sub s 0 i) (sub s (i + 1) (length s - i - 1) :: acc) in
  doit str []

let str_to_list str =
  let rec doit i acc =
    if i < 0 then acc
    else doit (i - 1) (String.get str i :: acc) in
  doit (String.length str - 1) []

let input_array y x =
  let a = Array.make_matrix y x '\000' in
  let rec doit i =
    if i = y then a
    else begin
      let rec aux j = function
        | [] -> ()
        | c :: cs -> a.(i).(j) <- c; aux (j + 1) cs in
      aux 0 (str_to_list (read_line ()));
      doit (i + 1)
    end in
  doit 0

let () =
  match List.map int_of_string (split (read_line ()) ' ') with
  | [h; w] ->
    begin
      let a = input_array h w in
      match List.map int_of_string (split (read_line ()) ' ') with
      | [r; c] when h < r || w < c -> ()
      | [r; c] ->
        let b = input_array r c in
        solve a (h, w) b (r, c)
      | _ -> exit 1
    end
  | _ -> exit 1

Measured memory_bytes: 46268
#include <bits/stdc++.h>
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define int long long int
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
 
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
 
typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int n, m;
vector<int> graph[100000];
int maxPath[100000];

void dfs(int u) {
	maxPath[u] = 0;
	for (auto v : graph[u]) {
		if (maxPath[v] == -1)
			dfs(v);
		maxPath[u] = max(maxPath[u], 1 + maxPath[v]);
	}
}

void solve() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
    	int x, y;
    	cin >> x >> y;
    	graph[x-1].pb(y-1);
    }
    for (int i = 0; i < n; i++)
    	maxPath[i] = -1;
    for (int i = 0; i < n; i++) {
    	if (maxPath[i] == -1)
    		dfs(i);
    }
    int res = 0;
    for (int i = 0; i < n; i++)
    	res = max(res, maxPath[i]);
    cout << res;
}
 
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
  
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  char a, b;
  cin >> a >> b;
  cout << ((a > b) ? string(a - '0', b) : string(b - '0', a));
  return 0;
}


Measured memory_bytes: 3636
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include <map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
#include <complex>
using namespace std;
#define eps 0.000001
#define LONG_INF 10000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define seg_size 65536*4
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	cout << h * w - (h / a) * (w / b) * a* b << endl;
	return 0;
}


Measured memory_bytes: 3072
n = gets.to_i
a, b = 2.times.map { gets.split.map(&:to_i) }

answer = (0...n).reduce(0) do |s, i|
  x = [a[i], b[i]].min
  y = [a[i + 1], b[i] - x].min
  a[i + 1] -= [b[i] - x, a[i + 1]].min
  s += x + y
end

puts answer

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

count = 0
for i in range(A+1):
    if i * 500 > X:
        continue
    for j in range(B+1):
        if i * 500 + j * 100 > X:
            continue
        for k in range(C+1):
            if i * 500 + j * 100 + k * 50 > X:
                break
            elif i * 500 + j * 100 + k * 50 == X:
                count += 1

print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
using namespace std;

int main() {
    int b,r,g,c,s,t;
    while (cin>>b>>r>>g>>c>>s>>t,(b||r||g||c||s||t)) {
        int res = 100;

        res -= b * 3;
        res += b * 15;
        res += b * 5 * 13;
        t -= b * 6;

        res -= r * 3;
        res += r * 15;
        res += r * 3 * 13;
        t -= r * 4;

        res -= g * 3;
        res += g * 7;
        t -= g;

        res -= c * 3;
        res += c * 2;
        t -= c;

        res -= s * 3;
        t -= s * 2;

        res -= t * 3;

        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    H,W=map(int,input().split())
    s=[['.']*(W+2) for _ in range(H+2)]
    for i in range(1,H+1):
        s[i][1:W+1]=list(input())
    dy=[1,0,-1,0]
    dx=[0,1,0,-1]
    for i in range(1,H+1):
        for j in range(1,W+1):
            if s[i][j]=='#':
                for k in range(4):
                    if s[i+dy[k]][j+dx[k]]=='#':
                        break
                else:
                    print('No')
                    exit()
    print('Yes')

if __name__ == '__main__':
    main()


Measured memory_bytes: 39280
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i=0;i<n;++i) {
        cin >> a[i];
    }
    sort(a.rbegin(), a.rend());

    ll ans = a[0];
    int m = n-2;
    for(int i=1;i<n&&m;++i) {
        ans += a[i] * min(m, 2);
        m -= min(m, 2);
    }
    cout << ans << endl;
}


Measured memory_bytes: 4780
#define _USE_MATH_DEFINES
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <numeric>
#include <array>
#include <float.h>
#include <memory>
#include <functional>
#include <iomanip>
#include <random>
#include <map>
#include <string.h>
#include <set>

using namespace std;

using ULL = decltype(0ull);
constexpr auto DIV = 1000000007ull;
constexpr auto MAX = numeric_limits<ULL>::max();

int main() {
  ULL N, K;
  cin >> N >> K;
  array<bool, 10> checker;
  checker.fill(false);
  for (int i = 0; i < K; ++i) {
    int val;
    cin >> val;
    checker[val] = true;
  }
  ULL result = N;
  string str;
  array<bool, 10> arr;
  bool flag = true;
  while(true) {
    flag = true;
    for (auto val = result, i = 0ull; val != 0; val /= 10) {
      if (checker[val % 10]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      break;
    }
    else {
      ++result;
    }

  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int k,a,b,c,ans=0;
int main()
{
	scanf("%d",&k);
	for(a=1;a<=k;a++)
	{
		for(b=1;b<=k;b++)
		{
			for(c=1;c<=k;c++)
				ans+=__gcd(__gcd(a,b),c);
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 3824
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

import fractions

dicts={}

K=one_int()

def reg(a,b):
    key = str(a)+","+str(b)
    if key not in dicts:
        dicts[key] = fractions.gcd(a,b)
        dicts[str(b)+","+str(a)] = dicts[key]
    temp = dicts[key]
    return temp

sums = 0
count=0
for a in range(1,K+1):
    for b in range(1,K+1):
        temp1 = reg(a,b)
        for c in range(1,K+1):
            temp = reg(temp1,c)
            sums += temp

print(sums)

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

int main() {
    ll t,n,k,a1=0,a2=0,a3=0,a4=0,a5=0;
    cin>>t>>n>>k;
    for(int i=t;i<=n;i++)
        if(i%k==0)
            a1++;
    cout<<a1<<endl;
    return 0;
}


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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

struct Point {
	int x, y, s;
	Point(int x_, int y_, int s_) : x(x_), y(y_), s(s_) {}
};

int dx[2][6] = {
		{1, 1, 1, 0, -1, 0}, 
		{0, 1, 0, -1, -1, -1}
	},
	dy[6] = {-1, 0, 1, 1, 0, -1},
	W, H, S, T;

bool vis[110][110], grid[110][110];

vector< Point > search(int sx, int sy) {
	memset(vis, 0, sizeof(vis));
	
	queue< Point > que;
	que.push(Point(sx, sy, 0));
	vis[sy][sx] = 1;
	
	vector< Point > res;
	int mns = int(1e9);
	
	while (!que.empty()) {
		Point p = que.front(); que.pop();
		
		if (mns < p.s) break;
		
		if (grid[p.y][p.x]) {
			mns = p.s;
			res.push_back(p);
			continue;
		}
		
		for_(d,0,6) {
			int nx = p.x + dx[p.y % 2][d], ny = p.y + dy[d];
			if (nx <= 0 || W < nx || ny <= 0 || H < ny) continue;
			if (vis[ny][nx]) continue;
			vis[ny][nx] = 1;
			que.push(Point(nx, ny, p.s + 1));
		}
	}
	
	return res;
}

int main() {	
	while (cin >> W >> H, W) {
		memset(grid, 0, sizeof(grid));
		
		cin >> S;		
		for_(i,0,S) {
			int x, y;
			cin >> x >> y;
			grid[y][x] = 1;
		}
		
		int ans = 0;
		
		cin >> T;
		for_(i,0,T) {
			int x, y;
			cin >> x >> y;
			grid[y][x] = 1;
			
			int cnt = 0;
			for_(yy,1,H+1) for_(xx,1,W+1) {
				vector< Point > vp = search(xx, yy);
				if (vp.size() > 1) continue;				
				if (vp[0].x == x && vp[0].y == y) ++cnt;
			}
			
			grid[y][x] = 0;
			ans = max(ans, cnt);
		}
		
		cout << ans << endl;
	}
}

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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n;
    ll m,v,p;
    cin >> n >> m >> v >> p;
    vector<ll> a(n);
    for (int i = 0;i < n;++i) scanf("%lld",&a[i]);
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    int l = 0,r = n;
    // p_ary(a,0,n);
    while (r-l > 1) {
        int mid = (l+r)/2;
        ll sum = 0;
        int cnt = 0;
        vector<ll> u;
        for (int i = 0;i < n;++i) {
            if (mid == i) sum += m;
            else if (a[i] > a[mid]+m) {
                sum += m;
                cnt++;
            } else if (a[i] <= a[mid]) {
                sum += m;
            } else {
                sum += m+a[mid]-a[i];
                u.push_back(a[i]-a[mid]);
            }
        }
        // cout << a[mid] << endl;
        // cout << l << " " << mid << " " << r << " " << sum << " " << cnt << endl;
        // p_ary(u,0,u.size());
        bool ok = false;
        if (sum >= m*v && cnt < p) ok = true;
        else {
            sort(u.begin(),u.end());
            reverse(u.begin(),u.end());
            int k = u.size();
            for (int i = 0;i < k;++i) {
                sum += u[i];
                cnt++;
                if (sum >= m*v) break;
            }
            if (sum >= m*v && cnt < p) ok = true;
        }
        (ok ? l : r) = mid;
    }
    cout << r << endl;
}

Measured memory_bytes: 2884
#include <bits/stdc++.h>
using namespace std;
int n,dp[100001],biao[50],cnt;
int main() {
    scanf("%d",&n);
    biao[++cnt] = 1;
    int tmp = 6;
    while (tmp <= n) biao[++cnt] = tmp,tmp *= 6;
    tmp = 9;
    while (tmp <= n) biao[++cnt] = tmp,tmp *= 9;
    memset(dp,0x7f,sizeof(dp));
    dp[0] = 0;
    for (int i = 1;i <= n;i++)
        for (int j = 1;j <= cnt;j++) if (i-biao[j] >= 0) dp[i] = min(dp[i],dp[i-biao[j]]+1);
    printf("%d",dp[n]);
    return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
#define MAX_N 100010

ll N;
vector<ll> ans;

signed main()
{
    cin >> N;

    ll cur = 0;
    for(int i = 1; i <= N; ++i) {
        cur += i;
        ans.push_back(i);
        if(cur >= N) { break; }
    }
    ll sub = cur - N;
    for(auto& a : ans) {
        if(sub == a) { continue; }
        printf("%lld\n", a);
    }

    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
int main(){

  int A,B,C;
  scanf("%d%d%d",&A,&B,&C);

  if(B<A && B==C)printf("YES\n");
  else  if(A<B && A==C)printf("YES\n");
  else  if(B<C && B==A)printf("YES\n");
  else printf("NO\n");

  return 0;
}


Measured memory_bytes: 128
# ABC 143 D - Triangles
# https://atcoder.jp/contests/abc143/tasks/abc143_d

n = gets.chomp.to_i
l = gets.chomp.split(/ /).map(&:to_i).sort.reverse

# puts sticks.inspect
# puts ""

count = 0
0.upto(n - 3) do |i|
  a = l[i]
  (i + 1).upto(n - 2) do |j|
    b = l[j]
    c_candidates = l[(j + 1)..(n - 1)]
    t = a - b
    # puts "--------"
    # puts c_candidates.inspect
    # puts "a: #{a}, b: #{b}, a - b: #{t}"
    c_over_index = c_candidates.bsearch_index { |c| c <= t }
    if c_over_index.nil?
      count += (n - 1) - j
    else
      count += c_over_index
    end
  end
end

puts count


Measured memory_bytes: 1916
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main() {
  // input
    long n,k;cin >> n >> k;

  // compute
    vector<int> a(n + 1);
    vector<int> p(n + 1);
    vector<int> ts(18);
    long sum = 0;
    long div = 0;
    double ans;
    for(long i = 1; i < n + 1; i++) a[i] = (k + (i-1)) / i;

    //2 square
    ts[0] = 1;
    for(int i = 1; i < 18; i++) ts[i] = 2 * ts[i - 1];   

    for(int i = 1; i < n + 1; i++) {
        if( k <= i){
          p[i] = 0;
          continue;
        }           
        for(int j = 0; j < 18; j++){     	
            if(ts[j] < a[i] && a[i] <= ts[j + 1]){
                p[i] = j + 1;
            }
        }
    }
  
    //debug
    //debug for(int i = 1; i < n + 1; i++) cout << p[i] << endl;

    for(int i = 1; i < n + 1; i++) sum += ts[17 - p[i]]; 
    div = ts[17] * n;
  
    //debug
    //debug for(int i = 1; i < 18; i++) cout << i << " " << ts[i] << endl;
  	//debug cout << sum << " " << div << endl;

    ans = (double)sum / (double)div;

  // output  
    cout << fixed << setprecision(12);
    cout << ans << endl;
}


Measured memory_bytes: 3908
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,h[20],max=0,ans=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>h[i];
		if(h[i]>=max)
		{
			ans++;
			max=h[i];
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <climits>
using namespace std;
int mp[200002];
void solve()
{
	int a,b;
	string u,s,t;
	cin>>s>>t>>a>>b>>u;
	if(u==s)a--;
	else if(u==t) b--;
	cout<<a<<' '<<b<<'\n';

}

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

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

using namespace std;

class data{
public:
	int num,score;
	data(int nn,int sc){
		num=nn;
		score=sc;
	}
	bool operator<(const data& da)const{
		if(da.score==score)return da.num>num;
		return da.score<score;
	}
};

int m;
int num[10000];
int score[10000][11][2],pts[11],sp,st[11];
vector<data> d;

int main(void){
	while(1){
		scanf("%d",&m);
		if(m==0)break;
		d.clear();
		for(int i=0;i<m;i++){
			scanf("%d",&num[i]);
			sp=0;
			for(int j=0;j<10;j++){
				scanf("%d",&score[i][j][0]);
				if(sp==1){
					pts[j-1]+=score[i][j][0];
					sp=0;
				}
				if(j>0 && st[j-1]>0){
					pts[j-1]+=score[i][j][0];
					st[j-1]--;
				}
				if(j>1 && st[j-2]>0){
					pts[j-2]+=score[i][j][0];
					st[j-2]--;
				}
				if(score[i][j][0]==10){
					if(j==9){
						scanf("%d %d",&score[i][j][1],&score[i][j][2]);
						pts[9]=score[i][j][0]+score[i][j][1]+score[i][j][2];
						if(j>0 && st[j-1]>0){
							pts[j-1]+=score[i][j][1];
							st[j-1]--;
						}
						if(j>1 && st[j-2]>0){
							pts[j-2]+=score[i][j][1];
							st[j-2]--;
						}
					}else{
						st[j]=2;
						pts[j]=10;
					}
				}else{
					scanf("%d",&score[i][j][1]);
					if(score[i][j][0]+score[i][j][1]==10){
						if(j==9){
							scanf("%d",&score[i][j][2]);
							pts[9]=10+score[i][j][2];
						}else{
							pts[j]=10;
							sp=1;
						}
					}else pts[j]=score[i][j][0]+score[i][j][1];
					if(j>0 && st[j-1]>0){
						pts[j-1]+=score[i][j][1];
						st[j-1]--;
					}
					if(j>1 && st[j-2]>0){
						pts[j-2]+=score[i][j][1];
						st[j-2]--;
					}
				}
			}
			int sc=0;
			for(int j=0;j<10;j++){
				sc+=pts[j];
			}
			d.push_back(data(num[i],sc));
		}
		sort(d.begin(),d.end());
		for(int i=0;i<m;i++){
			printf("%d %d\n",d[i].num,d[i].score);
		}
	}
}

Measured memory_bytes: 1048
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define msi map<string,int>
#define mii map<int,int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define po pop_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
//	#ifndef ONLINE_JUDGE
 //   	freopen("input.txt", "r", stdin);
 //   	freopen("output.txt", "w", stdout);
//	#endif
	int n;
	cin>>n;
	int x[n];
	int v[n];
	int w;
	cin>>w;
	rep(i,n){
		cin>>x[i]>>v[i];
	}
	vector<ll> dp(w+1,0);
	rep(i,n){
		for(int j=w;j>=x[i];j--){
			dp[j] = max(dp[j],dp[j-x[i]]+v[i]);
		}
	}
	cout<<dp[w]<<"\n";
	return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long ll;
typedef vector<ll> vll;
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; }

int main() {
	ll n,m,x;cin >> n >> m;
	vll a(m), b(m);
	vector<vll> c(m);
	rep(i, m) {
		cin >> a[i] >> b[i];
        //push_backよりemplace_backの方が速いらしい。改宗します。
		rep(j, b[i]) {cin >> x; c[i].emplace_back(x);}
	}
	vll dp(1<<n, M);
	dp[0] = 0;
	rep(i, m) {
		ll now = 0;
		//get 'OR' of all c[i][j]
		rep(j, b[i]) now |= 1<<(c[i][j]-1);
		//cout << bitset<10>(now)<< endl;
		rep(bit, 1 << n) chmin(dp[bit | now], dp[bit]+a[i]);
	}
	if (dp[(1 << n) - 1] == M) dp[(1 << n) - 1] = -1;
	cout << dp[(1 << n) - 1] << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
#define itn int
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   itn a,b,c;
   cin >> a >> b >> c;
   if(a+b+c>=22){
      cout << "bust";
   }else{
      cout << "win";
   }
   return 0;
} 

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

using namespace std;

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

        int price,sum = 0;
        int max = 0;
        for(int i = 0; i < N; i++){
                cin >> price;
                sum += price;
                if(price >= max) swap(price,max);
        }
        sum -= max/2;
        cout << sum;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
using namespace std;

int main() {
    int N,L;
    cin >> N >> L;
    if(L >= 1){
        cout << N * L - N + ((N + 1) * N)/2 - L << endl;
    }
    else if(L+N-1 <= 0){
        cout << N * L - N + ((N + 1) * N)/2 - (L + N - 1) << endl;
    }
    else{
        cout << N * L - N + ((N + 1) * N)/2 << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<int, P > PP;
int n,ans[100];
PP t[500];
PP u[500];
int ts,te,us,ue;
int state[17];
 
void t_in(PP x){
  t[te]=x;
  te++;
}
void u_in(PP x){
  u[ue]=x;
  ue++;
}
PP t_out(){
  ts++;
  return t[ts-1];
}
PP u_out(){
  us++;
  return u[us-1];
}
 
 
int u_check(){
  int a = u[us].second.second;
  int b = (a%5==1?5:2);
  int cnt=0;
  for(int i=0;i<17;i++){
    if(state[i]==-1){
      cnt++;
      if(cnt==b){
    return 1;
      }
    }else{
      cnt=0;
    }
  }
  return 0;
}
 
int u_ins(){
  int a = u[us].second.second;
  int b = (a%5==1?5:2);
  int cnt=0;
  for(int i=0;i<17;i++){
    if(state[i]==-1){
      cnt++;
      if(cnt==b){
    for(int j=i;j>i-b;j--){
      state[j]=a;
    }
    break;
      }
    }else{
      cnt=0;
    }
  }
 
   
  u_out();
  return a;
}
int u_check2(PP x){
  int a = x.second.second;
  int b = (a%5==1?5:2);
  int cnt=0;
  for(int i=0;i<17;i++){
    if(state[i]==-1){
      cnt++;
      if(cnt==b){
    return 1;
      }
    }else{
      cnt=0;
    }
  }
  return 0;
}
void u_ins2(PP x){
  int a = x.second.second;
  int b = (a%5==1?5:2);
  int cnt=0;
  for(int i=0;i<17;i++){
    if(state[i]==-1){
      cnt++;
      if(cnt==b){
    for(int j=i;j>i-b;j--){
      state[j]=a;
    }
    break;
      }
    }else{
      cnt=0;
    }
  }
}
 
int main(){
  ts=us=te=ue=0;
 
  for(int i=0;i<100;i++)ans[i]=0;
  for(int i=0;i<17;i++)state[i]=-1;
 
  for(int i=0;i<100;i++){
    t_in(PP(5*i,P(1,i)));
  }
 
  sort(t+ts,t+te);
 
  PP x,y;
  int flg,z,flg2;
  while(!(ts==te)){
 
    /*
    for(int i=0;i<17;i++)printf("%3d ",state[i]);
    cout<<endl;
 
    for(int i=us;i<ue;i++)printf("%3d ",u[i].second.second);
    cout<<endl;
    */
     
    sort(t+ts,t+te);
    y=x;
    x=t_out();
 
    //cout<<x.first<<' '<<x.second.first<<' '<<x.second.second<<endl;
    for(int i=us;i<ue;i++)ans[u[i].second.second]+=(x.first-y.first);
 
    

    if(x.second.first==0){
      for(int i=0;i<17;i++)if(state[i]==x.second.second)state[i]=-1;
      if(ts!=te&&t[ts].first==x.first&&t[ts].second.first==0)flg2=0;
      else flg2=1;
      while(flg2){
    if(us==ue)break;
    flg=u_check();
    if(flg==0)break;
    z=u_ins();
     
    t_in(PP(x.first+(17*(z%2)+3*(z%3)+19),P(0,z)));
      }
             
    }else if(x.second.first==1){
      flg=u_check2(x);
 
      if(flg==0||us!=ue){
    u_in(x);
      }else{
    u_ins2(x);
 
    z=x.second.second;
    t_in(PP(x.first+(17*(z%2)+3*(z%3)+19),P(0,z)));
      }
    }//if
  }
 
   
  //cout<<te<<endl;
  while(cin>>n){
    cout<<ans[n]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1180
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApplication1
{

    class Program
    {

        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');

            int n = int.Parse(str[0]);
            int m = int.Parse(str[1]);

            bool[,] data = new bool[n + 1, n + 1];
            var anser = new int[n + 1];

            int a;
            int b;           

            for(int i = 1; i < m + 1; i++)
            {
                str = Console.ReadLine().Split(' ');

                a = int.Parse(str[0]);
                b = int.Parse(str[1]);

                anser[a]++;
                anser[b]++;

            }


            for(int i= 1; i <= n; i++)
            {
                Console.WriteLine(anser[i]);
            }


        }

    }

}
    


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
const int N=15;
const int M=15;
int n, m, x, c[N], a[N][M], vis[N], s[M], ans=INT_MAX;
bool check(){
	bool f=true;
	for(int i=1;i<=m;i++)
		if(s[i]<x)
		{
			f=false;
			break;
		}
	return f;
}
void add_one(int x){
	for(int i=1;i<=m;i++)
		s[i]+=a[x][i];
}
void del_one(int x){
	for(int i=1;i<=m;i++)
		s[i]-=a[x][i];
}
void dfs(int k, int csum){
	if(check()){
		ans=min(ans,csum);
		return;
	}
	for(int i=k+1;i<=n;i++){
		if(!vis[i]){
			vis[i]=true;
			add_one(i);
			dfs(i,c[i]+csum);
			vis[i]=false;
			del_one(i);
		}
	}	
}
int main(){
	cin>>n>>m>>x;
	for(int i=1;i<=n;i++){
		cin>>c[i];
		for(int j=1;j<=m;j++)
			cin>>a[i][j];
	}
	
	for(int i=1;i<=n;i++){
		vis[i]=true; 
		add_one(i);
		dfs(i, c[i]);
		vis[i]=false;
		del_one(i);
	}
	if(ans!=INT_MAX) printf("%d",ans);
	else printf("-1");
	return 0;
}


Measured memory_bytes: 3764
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a,b ,c;
    while(cin >> a >> b >> c)
    {

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


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

int main() {
	int n;

	std::cin >> n;

	std::vector<long long> a(n), t(n), min_mountain(n);

	for (int i = 0; i < n; i++) {
		std::cin >> t[i];
	}

	for (int i = 0; i < n; i++) {
		std::cin >> a[i];
	}

	if (t.back() != a.front()) {
		std::cout << 0 << std::endl;
		return 0;
	}

	std::vector<bool> change_pos(n, false);
	change_pos[0] = change_pos[n - 1] = true;

	for (int i = 0; i < n; i++) {
		min_mountain[i] = std::min(a[i], t[i]);
		if (i != 0 && a[i] < t[i] && t[i - 1] < t[i] && a[i] != t[i]) {
			std::cout << 0 << std::endl;
			return 0;
		}
		if (i != n - 1 && a[i] > t[i] && a[i + 1] < a[i] && a[i] != t[i]) {
			std::cout << 0 << std::endl;
			return 0;
		}
		if (i != 0 && t[i - 1] < t[i]) change_pos[i] = true;
		if (i != n - 1 && a[i + 1] < a[i]) change_pos[i] = true;
	}

	long long ans = 1;
	for (int i = 0; i < n; i++) {
		if (change_pos[i]) continue;
		ans *= min_mountain[i];
		ans %= 1000000007;
	}
	
	std::cout << ans << std::endl;
	return 0;

}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define vi vector<int>
#define vvi vector<vi>
#define P pair<int, int>
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  FOR(i, 1, n) { ans += (n - 1) / i; }
  cout << ans << endl;
}

Measured memory_bytes: 3608