akhauriyash/Code-Regression huggingface dataset:
K=int(input())
L1=[1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836, 194157, 207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 
8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813, 10493367, 10611772, 10813692]
print(L1[K-1])

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

int main(){
    using namespace std;
    size_t n, k;
    cin >> n >> k;
    vector<size_t> w(n);
    for(auto& i : w)cin >> i;
    
    size_t lower = *max_element(w.begin(), w.end()) - 1, upper = 10000000000000;
    while(lower + 1 < upper){
        auto mid = (lower + upper) / 2;
        size_t tmp = 0, a = 0;
        for(const auto i : w){
            if(tmp + i > mid && !(tmp = 0))++a;
            tmp += i;
        }
        (a >= k ? lower : upper) = mid;
    }
    cout << upper << endl;
}


Measured memory_bytes: 3596
# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
using namespace std;
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) ((x)&1)
#define sqr(x) ((x)*(x))
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define rep(i,a,b) for (int i=(a); i<=(b); i+=2*((a)<(b))-1)
#define rep_it(it,x) for (__typeof((x).begin()) it=(x).begin(); it!=(x).end(); it++)
#define ____ puts("\n_______________\n\n") 
#define debug(x) ____; cout<< #x << " => " << (x) << endl
#define debug_pair(x) cout<<"\n{ "<<(x).fir<<" , "<<(x).sec<<" }\n"
#define debug_arr(x,n) ____; cout<<#x<<":\n"; rep(i,0,n) cout<<#x<<"["<<(i)<<"] => "<<x[i]<<endl
#define debug_set(x) ____; cout<<#x<<": \n"; rep_it(it,x) cout<<(*it)<<" "; cout<<endl
#define debug_map(x) ____; cout<<#x<<": \n"; rep_it(it,x) debug_pair(*it)
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
const int oo = /*2 * 1000 * 1000 * 1000*/0x3f3f3f3f;
const int _cnt = 1000 * 1000 + 7;
const int _p = 1000 * 1000 * 1000 + 7;
const double PI=acos(-1);
const double eps=1e-9;
int o(int x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b)*b; }

void file_put() {
    freopen("filename.in", "r", stdin);
    freopen("filename.out", "w", stdout);
}

int n,k,x,y=0,t=0;

int main() {
    //file_put(); 
    
    scanf("%d%d",&n,&k);
    for (int i=1; i<=n; i++) {
    	scanf("%d",&x);
    	y=gcd(y,x);
    	t=max(t,x);
	}
	if ((k>t) || (k%y!=0)) printf("IMPOSSIBLE\n"); else printf("POSSIBLE\n");
    
    return 0;
}

Measured memory_bytes: 256
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val N, M, K = in.nextInt
  val As = List.fill(N)(in.nextLong)
  val Bs = List.fill(M)(in.nextLong)

  def takeRead(unread: List[Long], time: Long, cnt: Int, read: List[Long]): (List[Long], Long, Int) = unread match {
    case Nil => (read, time, cnt)
    case x :: xs =>
      if (time + x > K) (read, time, cnt)
      else takeRead(xs, time + x, cnt + 1, x :: read)
  }

  def dropRead(unread: List[Long], time: Long, cnt: Int): (List[Long], Long, Int) = unread match {
    case Nil => (unread, time, cnt)
    case x :: xs =>
      if (time + x > K) (unread, time, cnt)
      else dropRead(xs, time + x, cnt + 1)
  }


  def readBs(readAs: List[Long], unreadBs: List[Long], time: Long, cnt: Int, cntMax: Int): Int = readAs match {
    case Nil => cntMax
    case x :: xs =>
      val (newUnreadBs, newTime, newCnt) = dropRead(unreadBs, time - x, cnt - 1)
      readBs(xs, newUnreadBs, newTime, newCnt, cntMax max newCnt)
  }

  val (as, time, cnt) = takeRead(As, 0L, 0, Nil)
  println(readBs(0L :: as, Bs, time, cnt + 1, cnt))
}

Measured memory_bytes: 94444
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

M, D = list(map(int, sys.stdin.readline().split()))


def ok(m, d):
    return len(str(d)) == 2 and int(str(d)[0]) >= 2 and int(str(d)[1]) >= 2 and int(str(d)[0]) * int(str(d)[1]) == m


ans = 0
for m in range(1, M + 1):
    for d in range(1, D + 1):
        ans += ok(m, d)
print(ans)


Measured memory_bytes: 13652
#include<iostream>
#include<cstdio>
#include<cstring>
#include<climits>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
#define MAXN 50000
int D[MAXN+5],n,k;
int tot[10],ans;
int main()
{
	ans=100000;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=k;i++)
	{
		scanf("%d",&D[i]);
		tot[D[i]]++;
	}
	for(int p=1;p<=100000;p++)
	{
		bool flag=1;int tmp=p;
		while(tmp>0)
		{
			if(tot[tmp%10])flag=0;
			tmp/=10;
		}
		if(flag&&p>=n)ans=min(ans,p);
	}
	printf("%d",ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始

int main(){
  ll a,b,x;
  cin>>a>>b>>x;
  ll cnt = b/x-a/x;
  if(a%x==0) cnt++;
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 256
N,*A = $<.read.split.map(&:to_i)
B = [0]*(N+1)
A.each{|a|
	B[a] += 1
}
C = B.inject(0){|c,b|
	c + b*(b-1)/2
}
A.each{|a|
	b = B[a]
	p C+1-b
}


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

using namespace std;

int main() 
{
    long long int a[100]={0},n,i,len,l=0,p=0,ans=1,N=3;
    
    vector<long long int>v;
    
    string s1,s2;
    
    cin>>n>>s1>>s2;
    
    len=s1.length();
    
    for(i=0;i<len;i++)
    {
        if(s1[i]==s2[i])
        {
            a[p]=1;
        }
        else
        {
            a[p]=0;
            i++;
        }
        p++;
    }
    
/*    for(i=0;i<p;i++)
    {
        cout<<a[i]<<" ";
    }
    cout<<endl;
*/    
    
    for(i=0;i<p;i++)
    {
        if(a[i]==0)
        {
            if((N-l)==3)
            {
                ans*=3;
                ans%=1000000007;
                ans*=2;
                ans%=1000000007;
            }
            else if((N-l)==2)
            {
                ans*=1;
                ans%=1000000007;
                ans*=2;
                ans%=1000000007;
            }
            else if((N-l)==1)
            {
                ans*=1;
                ans%=1000000007;
                ans*=3;
                ans%=1000000007;
            }
            
            l=2;
        }
        else
        {
            if((N-l)==3)
            {
                ans*=3;
                ans%=1000000007;
            }
            else if((N-l)==2)
            {
                ans*=2;
                ans%=1000000007;
            }
            else if((N-l)==1)
            {
                ans*=1;
                ans%=1000000007;
            }
            
            l=1;
        }
    }
    
    cout<<ans;
    
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
 
int main()
{
    string W;
    cin >> W;
 
    for(int i=0; i<W.size(); i++){
        W[i] = tolower(W[i]);
    }
 
    int cnt = 0;
 
    while(true){
        string T;
        cin >> T;
 
        if(T=="END_OF_TEXT")
            break;
 
        for(int i=0; i<T.size(); i++){
            T[i] = tolower(T[i]);
        }
 
        if(T==W){
            cnt++;
        }
    }
 
    cout << cnt << endl;
 
    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {    
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if(s == "abc") cout << "Yes" << endl;
    else cout << "No" << endl;
}

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


using namespace std;
typedef long long ll;
const int md = 998244353;
ll fast_pow(ll x,ll y)
{
	ll ans=1,now=x;
	while(y)
	{
		if(y&1) ans=(ans*now)%md;
		now=(now*now)%md;
		y>>=1;
	}
	return ans;
}

int main() {
  int N;
  cin >> N;
  vector<int> a(N,0), sum(N,0);
  for(int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  for(int i = 0; i < N; i++) {
    if(i == 0) {
      sum.at(i) = a.at(i);
      continue; 
    }
    sum.at(i) = sum.at(i-1) + a.at(i);
  }
  vector<vector<ll>> dp(N, vector<ll>(sum.at(N-1)+1,0));
  vector<vector<ll>> dp2(N, vector<ll>(sum.at(N-1)+1,0));
  for(int i = 0; i < N; i++) {
    for(int j = 0; j<sum.at(i)+1; j++ ) { 
      if(i == 0 && j == a.at(0)) {
        dp.at(0).at(0) = 2; 
        dp2.at(0).at(0) = 1;
        dp.at(0).at(j) = 1; 
        dp2.at(0).at(j) = 1;
        continue; 
      } 
      if(i == 0)continue; 
      if(j < a.at(i)) { 
        dp.at(i).at(j) = 2*dp.at(i-1).at(j)%md;
        dp2.at(i).at(j) = dp2.at(i-1).at(j)%md;
      }else{ 
        dp.at(i).at(j) = (2*dp.at(i-1).at(j) + dp.at(i-1).at(j-a.at(i)))%md;
        dp2.at(i).at(j) = (dp2.at(i-1).at(j) + dp2.at(i-1).at(j-a.at(i)))%md;
      } 
    }   
  }
  ll comp = 0; 
  for(int i= (sum.at(N-1)+1) /2 ; i<sum.at(N-1)+1 ;i++) { 
    comp += dp.at(N-1).at(i); 
    comp = comp%md; 
  } 
  /*for(int i = 0; i < N ;i++) {
    for(int j = 0; j < sum.at(N-1) +1; j++) {
      cout << dp2.at(i).at(j) << ' ';
    }
    cout << endl;
  }*/
  comp *= 3;
  comp %= md;
  int suuu = sum.at(N-1)/2;
  //cout << comp << endl; 
  if(sum.at(N-1)%2 == 0) comp = comp - 3*dp2.at(N-1).at(suuu);
  ll all = fast_pow(3,N);
  ll ans = (all - comp +md) % md;
  cout << ans << endl;
}

Measured memory_bytes: 422336
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    long long N;
    cin >> N;
    string sn = to_string(N);
    
    int a = 0;
    for ( int i = 0; i < sn.length(); i++ ) {
        a += sn[i]-'0';
    }
    
    cout << ( N%a == 0 ? "Yes" : "No" ) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    string s;
    cin >> s;
    vector<bool> dp(s.size()+1);
    vector<string> t = {"dream", "dreamer", "erase", "eraser"};
    dp[0] = true;   
    for(int i = 0; i < s.size(); i++){
        if (dp[i]){
            for(string tt: t){
                if (s.substr(i, tt.size()) == tt) dp[i+tt.size()] = true;
            }
        }
    }
    if (dp[s.size()]) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3776
import java.util.Scanner;

public class Main {

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

			if (1 < Math.abs(n - m)) {
				System.out.println("0");
				return;
			}

			long sortN = 1;
			for(int i = n; i > 0; i--) {
				sortN *= i;
				sortN %= 1000000007;
			}
			long sortM = 1;
			for(int i = m; i > 0; i--) {
				sortM *= i;
				sortM %= 1000000007;
			}
			long result = sortN * sortM;
			if (Math.abs(n - m) == 0) {
				result *= 2;
			}
			System.out.println(result % 1000000007);
		}
	}
}


Measured memory_bytes: 21844
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int h = Integer.parseInt(sc.next());
    int w = Integer.parseInt(sc.next());
    int a = Integer.parseInt(sc.next());
    int b = Integer.parseInt(sc.next());
    //int c[][] = new int[h][w];
    String s1 = "";
    String s2 = "";
    
    for(int j=0; j<w; j++){
      if (j<a) {
        s1 = s1 + "0";
        s2 = s2 + "1";
      } else {
        s1 = s1 + "1";
        s2 = s2 + "0";
      }
    }
    
    for(int i=0; i<h; i++){
        if(i<b) {
          System.out.print(s1);
        } else if (i>=b) {
          System.out.print(s2);
        }
        System.out.print("\n");
    }
    
//    for(int i=0; i<h; i++){
//      for(int j=0; j<w; j++){
//        System.out.print(c[i][j]);
//      }
//      System.out.print("\n");
//    }
    
  }
}


Measured memory_bytes: 33328
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
typedef long double ldouble;

typedef vector<llong> vecllong;
typedef vector<vecllong> vvecllong;

const llong MOD = 1e9 + 7;
const llong INF = 1e17;

#define FOR(i, n) for (llong i = 0; i < n; i++)
#define FORS(i, a, b) for (llong i = a; i < b; i++)
#define FORR(i, n) for (llong i = n; i > 0; i++)

struct cordinate {
    llong h, w, dist;
};

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

    llong H, W;
    cin >> H >> W;

    vector<vector<bool>> map(H + 2, vector<bool>(W + 2, false));
    llong streatCount = 0;

    FORS(h, 1, H + 1) {
        string line;
        cin >> line;
        FORS(w, 1, W + 1) {
            if(line[w - 1] == '.') {
                map[h][w] = true;
                streatCount++;
            }
        }
    }


    queue<cordinate> que;
    que.push({1, 1, 1});
    vector<vector<bool>> confilm(H + 2, vector<bool>(W + 2, false));

    while(!que.empty()) {
        cordinate now = que.front();
        que.pop();

        if(now.h == H and now.w == W) {
            cout << streatCount - now.dist << endl;
            return 0;
        }

        if(confilm[now.h][now.w]) continue;
        confilm[now.h][now.w] = true;

        if(map[now.h - 1][now.w]) que.push({now.h - 1, now.w, now.dist + 1});
        if(map[now.h + 1][now.w]) que.push({now.h + 1, now.w, now.dist + 1});
        if(map[now.h][now.w - 1]) que.push({now.h, now.w - 1, now.dist + 1});
        if(map[now.h][now.w + 1]) que.push({now.h, now.w + 1, now.dist + 1});
    }

    cout << "-1" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int cards[4][13] = {//カードの枚数分の要素をもつ配列
		{0,0,0,0,0,0,0,0,0,0,0,0,0},//スペード
		{0,0,0,0,0,0,0,0,0,0,0,0,0},//ハート
		{0,0,0,0,0,0,0,0,0,0,0,0,0},//クラブ
		{0,0,0,0,0,0,0,0,0,0,0,0,0} //ダイヤ
	}; 
	char mark;	//絵柄を表す文字
	int rank;	//カードのランク
	int n;		//現在持っているカードの枚数
	
	scanf("%d",&n);//持っているカードの枚数を入力
	
	for(int i = 0;i < n;i++){
		scanf(" %c%d", &mark,&rank);/*持っているカードを入力
										（先頭に半角スペースを入れ、スペースや改行をパス）*/
		switch(mark){
			case 'S'://スペードのとき
				cards[0][rank - 1] = 1;//持っているカードのフラグを１にする
				break;
			case 'H'://ハートのとき
				cards[1][rank - 1] = 1;//持っているカードのフラグを１にする
				break;
			case 'C'://クラブのとき
				cards[2][rank - 1] = 1;//持っているカードのフラグを１にする
				break;
			case 'D'://ダイヤのとき
				cards[3][rank - 1] = 1;//持っているカードのフラグを１にする
				break;
		}
	}
	
	for(int j = 0;j < 4;j++){//絵柄の数だけループ
		for(int k = 0;k < 13;k++){//絵柄毎のランクの数だけループ
			if(cards[j][k] == 0){//フラグが０の場合
				switch(j){
					case 0:
						printf("S %d\n",k + 1);//スペード
						break;
					case 1:
						printf("H %d\n",k + 1);//ハート
						break;
					case 2:
						printf("C %d\n",k + 1);//クラブ
						break;
					case 3:
						printf("D %d\n",k + 1);//ダイヤ
						break;
				}
			}
		}
	}
	
	return 0;
}



Measured memory_bytes: 2104
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

string s,s1,s2;
int dp[55][55];
int main(){
s1 = "AKIHABARA";
s2 = "KIHBR";
	cin >> s;	
	memset(dp,0,sizeof(dp));
	for(int i = 1;i <= s.length();i++){
		for(int j = 1;j <= s1.length();j++){
			dp[i][j] = max(dp[i][j - 1],dp[i - 1][j]);
			if(s[i - 1] == s1[j - 1]){
				dp[i][j] = max(dp[i][j],dp[i - 1][j - 1] + 1);
			}
		}
	}
	if(dp[s.length()][s1.length()] != s.length())	{
		printf("NO\n");
		return 0;
	}
	memset(dp,0,sizeof(dp));
	for(int i = 1;i <= s.length();i++){
		for(int j = 1;j <= s2.length();j++){
			dp[i][j] = max(dp[i][j - 1],dp[i - 1][j]);
			if(s[i - 1] == s2[j - 1]){
				dp[i][j] = max(dp[i][j],dp[i - 1][j - 1] + 1);
			}
		}
	}
	if(dp[s.length()][s2.length()] != s2.length()){
		printf("NO\n");
		return 0;
	}
	printf("YES\n");	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define ll long long
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define fi first
#define se second
#define pr(x) cerr<<#x<<"="<<(x)<<endl
#define pri(x,lo) {cerr<<#x<<"={";for (int ol=0;ol<=lo;ol++)cerr<<x[ol]<<",";cerr<<"}"<<endl;}
#define inf 100000000
#define N 1000
ll n,o,i,last,ans;
void bac() {printf("-1\n");exit(0);}
int main()
{
	scanf("%lld",&n);
	for (i=1;i<=n;i++)
	{
		scanf("%lld",&o);
		if (o>=i) bac();
		if (o-last>1) bac();
		if (o<=last) ans+=last;
		last=o;
	}
	ans+=last;
	cout<<ans;
}

Measured memory_bytes: 384
from operator import itemgetter
n = int(input())
a = []
for _ in range(n):
        a.append(list(map(int, input().split())))
a.sort(key=itemgetter(1))
sumA = 0
for i in range(n):
        sumA += a[i][0]
        if sumA > a[i][1]:
                print("No")
                exit()
print("Yes")

Measured memory_bytes: 53720
#include <iostream>
using namespace std;
int main()
{
    int n, m;
    cin >> n;
    if (n < 105) {
        m = 0;
    } else if (n < 135) {
        m = 1;
    } else if (n < 165) {
        m = 2;
    } else if (n < 189) {
        m = 3;
    } else if (n < 195) {
        m = 4;
    } else {
        m = 5;
    }   
    cout << m << endl;
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1e17 - 10;
const double PI = acos(-1);
typedef pair<LL, LL> Pll;
LL h = 0, w, n = 0, m, s, ans =0, dp[1003][1003][3] = {}, a[10000] = {}, sum = 0;
int flag = 0;
string str;
int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		int aa;
		cin >> aa;
		if (a[aa] == 0)
			h++;
		a[aa]++;
	}
	sort(a, a + n + 1);
	int now = 0;
	while (true) {
		if (h <= m)
			break;
		for (int i = now; i <= n; i++) {
			if (a[i] != 0) {
				ans += a[i];
				a[i] = 0;
				h--;
				break;
			}
			now++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int main() {
    string S, T;
    cin >> S >> T;
    bool can = false;
    for (int i = 0; i < S.size(); ++i) {
        char c = S.back();
        S.pop_back();
        S = c + S;
        if (S == T) can = true;
    }
    cout << (can ? "Yes" : "No") << endl;
}


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

int main(){
  int n;
  while(true){
    cin>>n;
    if(n==0){
      break;
    }
    int m[n],e[n],j[n],me[n],total[n];
    for(int i=0;i<n;i++){
      cin>>m[i]>>e[i]>>j[i];
      me[i]=m[i]+e[i];
      total[i]=m[i]+e[i]+j[i];
    }
    for(int k=0;k<n;k++){
      if(m[k]==100||e[k]==100||j[k]==100||me[k]>=180||total[k]>=240){
	cout<<"A"<<endl;
      }else if(total[k]>=210){
	cout<<"B"<<endl;
      }else if(total[k]>=150&&m[k]>=80){
	cout<<"B"<<endl;
      }else if(total[k]>=150&&e[k]>=80){
	cout<<"B"<<endl;
      }else{
	cout<<"C"<<endl;
      }
    }
  }

    return 0;
}

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

using namespace std;

int main() {
  vector<pair<int, int>> vec;

  int p, s;
  char dummy;
  while (cin >> p >> dummy >> s) {
    if (p == 0)
      break;
    vec.push_back(make_pair(p, s));
  }

  sort(vec.begin(), vec.end(), [](pair<int, int> &a, pair<int, int> &b) {
    return a.second > b.second;
  });

  int q;
  while (cin >> q) {
    int rank = 0;
    int last = 50;
    for (auto &v : vec) {
      if (v.second < last) {
        last = v.second;
        ++rank;
      }
      if (v.first == q) {
        cout << rank << endl;
        break;
      }
    }
  }
}


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

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

#define INF 1 << 30
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

int n;
int a[200010];

int main(){
  cin >> n;
  REP(i,n) cin >> a[i];
  ll cnt = 0;
  if(a[0]!=0){
    cout << -1 << endl;
    return 0;
  }
  FOR(i,1,n){
    if(a[i-1] +1<a[i]){
      cout << -1 <<endl;
      return 0;
    }
    if(a[i-1] +1 == a[i]){
      cnt++;
    }else if(a[i-1] >= a[i]){
      cnt += a[i];
    }
  }
  cout << cnt << endl;
}


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

int main() {
    int n;
    cin >> n;
    int num[26];
    fill(num, num+26, 1001001001);
    for(int i=0; i<n; ++i) {
        string S;
        cin >> S;
        int numS[26] = {0};
        for(int j=0; j<S.size(); ++j) {
            numS[S[j] - 'a'] += 1;
        }
        for(int j=0; j<26; ++j) {
            num[j] = min(num[j], numS[j]);
        }
    }
    for(char i='a'; i<='z'; ++i) {
        for(int j=0; j<num[i-'a']; ++j) {
            cout << i;
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;
#define MOD 1000000007
#define INF 1000000
#define MAX_N 100010



int main()
{
  int N,K;cin>>N>>K;
  vector<int> h(N+1);
  for (int i=1;i<=N;i++)
    cin>>h[i];
  //dp[i]=i番目にいるときに最小のコスト
  vector<int> dp(N+1);
  dp[1]=0;
  for (int i=2;i<=N;i++)
  {
    dp[i]=dp[i-1]+abs(h[i-1]-h[i]);
    for (int j=1;j<=K;j++)
    {
      if (i-j>=1)
      {
        dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i])); 
      }
    }
  }
  cout<<dp[N]<<endl;
}

Measured memory_bytes: 1024
N, C = map(int, input().split())
channels = [[] for _ in range(C)]
for _ in range(N):
    a, b, c = map(int, input().split())
    channels[c-1].append((a, b))
for c in range(C):
    channels[c].sort()
recorders = [0]*(10**5+2)
for c in channels:
    if c:
        recorders[c[0][0]] += 1; recorders[c[0][1] + 1] -= 1;
        for i in range(1, len(c)):
            if c[i][0] == c[i-1][1]:
                recorders[c[i][0] + 1] += 1; recorders[c[i][1] + 1] -= 1;
            else:
                recorders[c[i][0]] += 1; recorders[c[i][1] + 1] -= 1;
for i in range(1, len(recorders)):
    recorders[i] += recorders[i-1]
print(max(recorders))

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

int main(){
    int h, w;
    cin >> h >> w;
    int c[10][10];
    for (int i = 0; i < 10; ++i) {
        for (int j = 0; j < 10; ++j) {
            cin >> c[i][j];
        }
    }
    int a[210][210];
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> a[i][j];
        }
    }

    for (int k = 0; k < 10; ++k) {
        for (int i = 0; i < 10; ++i) {
            for (int j = 0; j < 10; ++j) {
                c[i][j] = min(c[i][j], c[i][k]+c[k][j]);
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if(a[i][j] == -1) continue;
            else ans += c[a[i][j]][1];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
n = int(input())
a = list(map(int,input().split()))

a.sort()

if a[0] == 0:
    ans = True
    for i in range(n):
        if a[i] != ((i+1)//2)*2:
            ans = False
            break
    if ans:
        print(2**(n//2) % (10**9+7))
    else:
        print(0)
else:
    ans = True
    for i in range(n):
        if a[i] != (i//2)*2+1:
            ans = False
            break
    if ans:
        print(2**(n//2) % (10**9+7))
    else:
        print(0)


Measured memory_bytes: 52204
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words

getIntList = readIntList <$> BS.getLine

main = do
  [d, n] <- getIntList
  if n < 100
    then print $ 100 ^ d * n
    else print $ 100 ^ d * (n + 1)


Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<ll,pll> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
//const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

ll mod;

ll Pow(ll n,ll p){
	ll r=1;
	for(;p>0;p>>=1){
		if(p&1) r=(r*n)%mod;
		n=(n*n)%mod;
	}
	return r;
}

vvl mul(vvl A,vvl B){
	vvl C(A.size(),vl(B[0].size()));
	for(int i=0;i<A.size();i++) for(int k=0;k<B.size();k++) for(int j=0;j<B[0].size();j++) (C[i][j]+=A[i][k]*B[k][j])%=mod;
	return C;
}

vvl pow(vvl A,ll n){
	vvl B(A.size(),vl(A.size()));
	for(int i=0;i<A.size();i++) B[i][i]=1;
	while(n>0){
		if(n&1) B=mul(B,A);
		A=mul(A,A);
		n>>=1;
	}
	return B;
}

ll n,a,d;

ll f(ll x){
	return a+d*x;
}

int main(){
	cin>>n>>a>>d>>mod;
	ll t=1,res=0,tmp=1;
	for(int i=0;i<17;i++) t*=10;
	for(int i=17;i>=0;i--){
		ll l=-1,r=n;
		while(r-l>1){
			ll m=(l+r)/2;
			if(f(m)>=t) r=m;
			else l=m;
		}
		ll A=f(r);
		l=-1,r=n;
		while(r-l>1){
			ll m=(l+r)/2;
			if(f(m)>=t*10) r=m;
			else l=m;
		}
		ll B=f(r);
		if(A<B){
			ll N=(B-A)/d;
			vvl a(3,vl(3));
			a[0][0]=t*10%mod;
			a[0][1]=a[1][1]=a[1][2]=a[2][2]=1;
			a=pow(a,N);
			ll sum=(A%mod*a[0][1]%mod+d%mod*a[0][2]%mod)%mod;
			(res+=sum*tmp)%=mod;
			(tmp*=Pow(Pow(10,N),i+1))%=mod;
		}
		t/=10;
	}
	cout<<res<<endl;
}

Measured memory_bytes: 256
//84104971101048411497 - Can you guess what does this mean?
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define maxN 500005
#define oo 2000000007
#define sz(a) (int)a.size()
 
const double PI = acos(-1.0);
 
double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}
 
template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}
 
template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}
 
string getBA(int n) {
    string ans;
    fto(i, 0, n-1) ans += (i&1) ? 'B' : 'A';
    reverse(ans.begin(), ans.end());
    return ans;
}
 
string s;
int n, k;
 
int main () {
    cin >> n >> k;
    cin >> s;
 
    int cur = 0;
    string ans;
    fto(i, 0, n-1) {
        if ((s[i] == 'A')^(i&1)) {
            --k;
            if (k == 0) {
                ans += 'B';
                fto(j, i+1, n-1) {
                    ans += ((s[j] == 'A')^(i&1)) ? 'A' : 'B';
                }
                ans += getBA(i);
                break;
            }
        }
        --k;
        if (k == 0) {
            fto(j, i+1, n-1) {
                ans += ((s[j] == 'A')^(i&1)) ? 'B' : 'A';
            }
            ans += getBA(i+1);
            break;
        }
    }
 
    if (k > 0) {
        ans += (n%2 == 1 && k%2 == 0) ? 'A' : 'B';
        ans += getBA(n-1);
    }
    cout << ans;
 
    return 0;
}
 

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

int main() {
  int n;
  cin >> n;
  long long dp[2] = {0};
  long long x, acc_l;
  cin >> acc_l;
  for (int i = 2; i <= n; ++i) {
    cin >> x;
    if (i&1) {
      dp[1] = max(dp[1] + x, dp[0]);
      acc_l += x;
    } else {
      dp[0] = max(acc_l, dp[0] + x);
    }
  }
  cout << dp[(n&1)] << endl;
}

Measured memory_bytes: 3620
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>
#define _USE_CMATH_DEFINES

const long INF = (1l << 30);
const long LINF = (1l << 60); //1.15*10^18

long n;
std::vector<long> edge[200005];
long longest[200005];
std::set<long> color[2];
long p[200005];

void tree_coloring(long vis, long par, long dep){
    color[dep%2].insert(vis);\
    for(int i = 0; i < edge[vis].size(); i++){
        long nx = edge[vis][i];
        if(nx == par){
            continue;
        }
        tree_coloring(nx, vis, dep+1);
    }
}

int main(){
    scanf("%ld", &n);
    for(int i = 0; i < n-1; i++){
        long a, b;
        scanf("%ld%ld", &a, &b);
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    tree_coloring(1, 0, 0);
    if(color[0].size() > color[1].size()){
        color[0].swap(color[1]);
    }
    if(color[0].size() <= n/3){
        long pos[2] = {3, 1};
        for(auto it : color[0]){
            p[it] = pos[0];
            pos[0] += 3;
        }
        for(auto it : color[1]){
            p[it] = pos[1];
            pos[1]++;
            if(pos[1] < pos[0] && pos[1] % 3 == 0){
                pos[1]++;
            }
        }
    }else{
        long pos[3] = {1, 2, 3};
        for(int i = 0; i < 2; i++){
            for(auto it : color[i]){
                if(pos[i] <= n){
                    p[it] = pos[i];
                    pos[i] += 3;
                }else{
                    p[it] = pos[2];
                    pos[2] += 3;
                }
            }
        }
    }
    for(int i = 1; i <= n; i++){
        printf("%ld ", p[i]);
    }
    printf("\n");
}


Measured memory_bytes: 27264
#include<bits/stdc++.h>//'三玖是天！ '.
using namespace std;
int main()
{
	string s,ss;
	cin>>s;
	ss=s;
	reverse(s.begin(),s.end());
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='b')s[i]='d';
		else if(s[i]=='d')s[i]='b';
		else if(s[i]=='p')s[i]='q';
		else s[i]='p';
	}
	if(ss==s)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    vl x(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
    }
    ll ret = 0;
    for (int i = 1; i < n; ++i) {
        ret += min(a * (x[i] - x[i - 1]), b);
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 1024
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
 * File:   main.c
 * Author: kundaikwangwari
 *
 * Created on July 23, 2019, 8:15 PM
 */

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#define NIL -1
#define White 0
#define Grey 1
#define Black 2
#define size 105

/*
 * 
 */
int Timetrack,n,head,tail,Que[size];
int table[size][size], Distance[size];

void insert(int val){
    
    Que[tail++]=val;
}

int Retrieve(){
    return Que[head++];
}


void BreathFirstSearch(int val, int *Color){
   
    for(int i = 0; i < n + 1; i++){
        Distance[i] = INT_MAX;
        Color[i] = White;
        }
    Distance[val] = 0;
    Color[val] = Grey;
    insert(val);
 
    while(head!=tail){
  int node =Retrieve();

    //printf("going intp node %d, color %d\n",V,Color[V]);
    
    for(int u = 1; u < n + 1; u++){
        if(table[node][u] == NIL)continue;
        if(Color[u] == White){
    
    Distance[u] = Distance[node]+1;
    insert(u);
    Color[u] = Black;
            }
        }
    }
    }

int main(int argc, char** argv) {

    int V,k,edge;
    scanf("%d",&n);
    
    int Color[n+1];
    for(int i = 1; i < n + 1; i++){
        for(int a = 1; a < n + 1; a++)table[i][a] = NIL;
}
    
    for(int i = 0; i < n ; i++){
        
        scanf("%d%d",&V,&k);
        //printf("V %d edges %d\n",V,edge);
        for(int a = 0; a < k; a++){
            scanf("%d",&edge);
            table[V][edge] = 1;
            //printf("table(%d)(%d) has value %d \n",V,edge,table[V][edge]);
        }
    }
    
    
        BreathFirstSearch(1,Color);
        for(int i = 1; i < n + 1; i++){
            if(Distance[i] != INT_MAX)printf("%d %d\n",i,Distance[i]);
            else printf("%d -1\n",i);
        }
    
    return (0);
}




Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int mul(long long a, long long b){
	return a * b % mod;
}
int gcd(int a, int b){
	while(b){
		a %= b;
		swap(a, b);
	}
	return a;
}
int main(){
	int n, res = 1; cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++)
		cin >> a[i];
	sort(a.begin(), a.end());
	for(int i = 0; i < n; i++)
		res = mul(res, gcd(a[i], i));
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 640
<>;
for(`factor`){
	$x=1;$y=1;
	s/( \d+)\1*\b/$x*=$&**($a=$&=~y! !!%3);$y*=$&<1e5&&$&**(-$a%3)/ge;
	++$h{$x};
	$t{$x}=$y
}
$%=!!$h{1};
delete$h{1};
for(keys%h){
	$%+=$h{$_}>$h{$t{$_}}?$h{$_}:$h{$t{$_}};
	$h{$_}=$h{$t{$_}}=0
}
print$%,$/


Measured memory_bytes: 46684
#include <cstdio>
const int MAXN = 55;
int D[MAXN];
int N;

int solve() {
    int sum = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < i; ++j) {
            sum += D[i] * D[j];
        }
    }
    return sum;
}

int main() {
    scanf("%d", &N);
    for (int i = 0; i < N; ++i) {
        scanf("%d", &D[i]);
    }
    printf("%d\n", solve());
    return 0;
}

Measured memory_bytes: 128
a, b, c = gets.chomp.split.map(&:to_i).sort
ans = c - b
a += ans
b += ans
d = c - a
if d == 1
  ans += 2
elsif d == 2
  ans += 1
else
  x, y = d.divmod(2)
  if y == 0
    ans += x
  else
    ans += x + 2
  end
end
puts ans

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



int main(int argc, char const *argv[])
{

#if !ONLINE_JUDGE

	freopen("in1.txt", "r", stdin);
	freopen("out1.txt", "w" , stdout);

#endif



	long a, b;
	cin >> a >> b;

	cout << (a + b) % 24 << endl;




	return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define ll long long
#define sz size
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define fst first
#define scd second
#define pb push_back
#define ne '\n'
#define ne1 endl
#define MOD(x)  x%int(1e9+7)
//::== dana_paani
//====================================================================================================================================//
 
using namespace std;
 
void solve()
{
} 


int main()
{
//   int t;
//   cin>>t;
//   while(t--)
long long a;
long double b,c;
cin>>a>>b;
c=(long double)a * (long double)b;
cout<<(long long)c<<endl;

return 0;
}

Measured memory_bytes: 3756
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
double dat[100][100];
int dp[6][1010];//動的計画法
int prime[10000001];
char str[1010][1010];
vector<pair<int,int> > pc[100001];
int ABS(int a){return max(a,-a);}
int main(){
	long long n,a,b,ans;
	cin>>n>>a>>b;
	long long x[n+1];
	for(int i=0;i<n;i++) cin>>x[i];
	ans=0;
	for(int i=1;i<n;i++){
		ans+=min((x[i]-x[i-1])*a,b);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5120
using System;
using System.Linq;

/*
 全探索
 nが小さいから使える
 同じ計算を複数回しているので、動的計画法を使った方が良い
 */

public class ALDS1_5_A
{
    public static void Main(string[] args)
    {
        //var exStdIn = new System.IO.StreamReader( "input.txt" );
        //System.Console.SetIn( exStdIn );

        int n = int.Parse(Console.ReadLine());
        int[] aArray = Console.ReadLine().Split(' ').Select(str => int.Parse(str)).ToArray();
        int q = int.Parse(Console.ReadLine());
        int[] mArray = Console.ReadLine().Split(' ').Select(str => int.Parse(str)).ToArray();

        Solve(n, aArray, q, mArray);
    }

    private static void Solve(int n, int[] aArray, int q, int[] mArray)
    {
        foreach (var m in mArray)
        {
            // 0:未評価 1:true 2:false
            int[,] dp = new int[21, 2001];
            Console.WriteLine(Solve(n, aArray, 0, m, dp) ? "yes" : "no");
        }
    }

    private static bool Solve(int n, int[] aArray, int i, int m, int[,] dp)
    {
        if (dp[i, m] > 0)
        {
            return dp[i, m] == 1;
        }
        if (m == 0)
        {
            dp[i, m] = 1;
            return true;
        }
        if (i == n)
        {
            dp[i, m] = 2;
            return false;
        }
        if (Solve(n, aArray, i + 1, m, dp))
        {
            dp[i, m] = 1;
            return true;
        }
        if (m - aArray[i] < 0)
        {
            dp[i, m] = 2;
            return false;
        }
        if (Solve(n, aArray, i + 1, m - aArray[i], dp))
        {
            dp[i, m] = 1;
            return true;
        }
        dp[i, m] = 2;
        return false;
    }
}



Measured memory_bytes: 34500
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int a[100005],b[100005],ped[100005];
int main() {
	int n,i,j;
	scanf("%d",&n);
	for(i=1; i<=n; i++) {
		scanf("%d",&a[i]);
	}
	for(i=1; i<=n; i++)	b[i] = 0;
	for(i=1; i<=n; i++)	ped[i] = 0;
	b[1] = 1;
	ped[1] = 1;
	int Li = 1;
	bool ans = true;
	int count = 0;
	while(b[2]!=1) {
		count++;
		b[Li] = 0;
		b[a[Li]] = 1;
		Li = a[Li];
		if(ped[Li] == 1 && b[2] !=1) {
			ans = false;
			break;
		}
		ped[Li] = 1;
	}
	if(ans) {
		printf("%d",count);
	} else {
		printf("-1");
	}
	return 0;
}

Measured memory_bytes: 1408
let n = read_int ()
let f m = let cs = Array.make 8 0 in let rec f n =
  if n = 0 then cs.(3) + cs.(5) + cs.(7) = 3 else (cs.(n mod 10) <- 1; f (n / 10)) in m <= n && f m
let rec g m = let h m k = g (10 * m + k) + if f @@ 10 * m + k then 1 else 0 in if m > n then 0 else h m 3 + h m 5 + h m 7
let _ = g 0 |> Printf.printf "%d\n"

Measured memory_bytes: 2560
ret = [0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(ret[K])


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

#define int long long

const int MOD = 1e9 + 7;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, P;
    cin >> N >> P;
    vector<int> A(N);
    REP(i, N){
        cin >> A[i];
    }
    vector<int> dp(N + 1);
    vector<int> dp1(N + 1);
    dp[0] = 1;
    dp1[0] = 0;
    REP(i, N){
        if(A[i] % 2 == 0){
            dp[i + 1] = 2 * dp[i];
            dp1[i + 1] = 2 * dp1[i];
        }else{
            dp[i + 1] = dp[i] + dp1[i];
            dp1[i + 1] = dp1[i] + dp[i];
        }
    }
    if(P == 0){
        cout << dp[N] << endl;
    }else{
        cout << dp1[N] << endl;
    }
    return 0;
}

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

const int SZ = 1e5 + 1;

vector<vector<int>> fg(SZ);
vector<vector<int>> bg(SZ);

vector<int> parent(SZ, -1);

int root(int x) {
    return parent[x] == -1 ? x : root(parent[x]);
}

void merge(int a, int b) {
    int x = root(a);
    int y = root(b);
    if (x == y) return;
    if (x < y) {
        parent[y] = x;
    } else {
        parent[x] = y;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    int N, M, K;
    cin >> N >> M >> K;
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        fg[a].push_back(b);
        fg[b].push_back(a);
        merge(a, b);
    }
    for (int i = 0; i < K; ++i) {
        int c, d;
        cin >> c >> d;
        bg[c].push_back(d);
        bg[d].push_back(c);
    }
           
    vector<int> cnt(N + 1, 0);
    for (int i = 1; i <= N; ++i) {
        cnt[root(i)]++;
    }

    for (int i = 1; i <= N; ++i) {
        int p1 = root(i);
        int ans = cnt[p1] - fg[i].size() - 1; // My immediate frens and myself from island
        for (int b : bg[i]) {
            int p2 = root(b);
            if (p1 == p2) ans--;
        }
        cout << ans << " ";
    }
}


Measured memory_bytes: 12664
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

#define bit(n,k) ((n>>k)&1) //*n no k bit me 1 or 0*/


int main(){
  int n,m,x;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  rep(i,n){
    cin >> c[i];
    rep(j,m){
      cin >> a[i][j];
    }
  }

  int ans = inf;
  rep(i,1<<n){
    vector<int> t(m,0);
    int cur= 0;
    rep(j,n)if(bit(i,j)){
      cur += c[j];
      rep(k,m){
        t[k] += a[j][k];
      }
    }

    bool flag = true;
    rep(k,m){
      if(t[k]<x){ flag = false;}
    }
    if(flag){
      ans = min(ans, cur);
    }
  }
  if(ans==inf) ans = -1;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3628
/*
数据不清空，爆零两行泪。
多测不读完，爆零两行泪。
边界不特判，爆零两行泪。
贪心不证明，爆零两行泪。
D P 顺序错，爆零两行泪。
大小少等号，爆零两行泪。
变量不统一，爆零两行泪。
越界不判断，爆零两行泪。
调试不注释，爆零两行泪。
溢出不 l l，爆零两行泪。
*/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int N=500000;
int n;
char a[N+5];
int lcP[N+1],Lcs[N+1];
int z[N+1];
void z_init(){
	z[1]=n;
	int zl=0,zr=0;
	for(int i=2;i<=n;i++)
		if(zr<i){
			z[i]=0;
			while(i+z[i]<=n&&a[1+z[i]]==a[i+z[i]])z[i]++;
			if(z[i])zl=i,zr=i+z[i]-1;
		}
		else if(i+z[i-zl+1]<=zr)z[i]=z[i-zl+1];
		else{
			z[i]=zr-i+1;
			while(i+z[i]<=n&&a[1+z[i]]==a[i+z[i]])z[i]++;
			zl=i;zr=i+z[i]-1;
		}
}
vector<int> dsr[N+1];
int main(){
	cin>>a+1;
	n=strlen(a+1);
	bool ok=true;
	for(int i=1;i<n;i++)ok&=a[i]==a[i+1];
	if(ok)return cout<<n<<"\n1",0;
	z_init();
	for(int i=1;i<=n;i++)lcP[i]=z[i];
	reverse(a+1,a+n+1);
	z_init();
	for(int i=1;i<=n;i++)Lcs[i]=z[n-i+1];
	ok=true;
	for(int i=1;i<n;i++)if(n%i==0&&lcP[i+1]==n-i)ok=false;
	if(ok)return puts("1\n1"),0;
	puts("2");
	for(int i=1;i<n;i++)for(int j=2*i;j<=n;j+=i)dsr[j].pb(i);
	int ans=0;
	for(int i=1;i<n;i++){
		ok=true;
		for(int j=0;j<dsr[i].size();j++)if(lcP[dsr[i][j]+1]>=i-dsr[i][j])ok=false;
		for(int j=0;j<dsr[n-i].size();j++)if(Lcs[n-dsr[n-i][j]]>=n-i-dsr[n-i][j])ok=false;
		ans+=ok;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 62208