akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int k; cin>>k;
  if(k%2==0 || k%5==0) {
    cout<<"-1\n";return 0;
  }
  int x=7%k, c=1;
  while(x != 0) {
    x = (x*10) +7;
    x %= k;
    c++;
  }
  cout<<c<<"\n";
}

Measured memory_bytes: 3576
///
// File:  c.cpp
// Author: ymiyamoto
//
// Created on Sun Dec 10 21:26:22 2017
//

#include <algorithm>
#include <cstdint>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int32_t main()
{
  int32_t N, K;
  cin >> N >> K;

  map<uint32_t, uint32_t> m;
  for (int32_t i = 0; i < N; i++) {
    uint32_t n;
    cin >> n;
    if (m.count(n) > 0) {
      m[n]++;
    } else {
      m[n] = 1;
    }
  }

  vector<uint32_t> nums;
  for (auto i = m.begin(); i != m.end(); i++) {
    nums.push_back(i->second);
  }

  sort(nums.begin(), nums.end());
  uint32_t total = 0;
  for (int32_t i = 0; i < (int32_t)nums.size() - K; i++) {
    total += nums[i];
  }

  cout << total << endl;
  return 0;
}


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



using ll = long long;
const int INF = 1e9+5;

int main(){
    int n;
    cin>>n;
    vector<int> dp(n+1,INF);
    vector<int> h(n);
    for(int i=0; i<n; i++) cin>>h[i];
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(int i=2; i<n; i++){
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
    }

    cout<<dp[n-1];
}

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

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

using namespace std;

int main()
{
	int n;
	
	while(cin >> n)
	{
		n %= 39;
		
		cout << "3C";

		if(n == 0) cout << 39 << endl;
		else if(n < 10) cout << "0" << n << endl;
		else cout << n << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.*
//import kotlin.math.*
 
private fun readString() = readLine()!! // string line
private fun readInt() = readString().toInt() // single int
private fun readLong() = readString().toLong()
private fun readStrings() = readString().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of ints
 
val INF = 1000000000
 
fun main(args: Array<String>)
{
    var n = readInt()
	var b = readInts().toTypedArray()
	var ret = b[0]+b[n-2]
	
	fun minOf(a: Int, b: Int): Int
	{
		return if (a > b) b else a
	}
	
	for (i in 1..n-2)
	{
		ret += minOf(b[i-1], b[i])
	}
	print(ret)
}


Measured memory_bytes: 37692
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

constexpr int inf = (1 << 30) - 1;

int main() {
  int N;
  std::cin >> N;
  std::vector<std::string> grid(N);
  bool able = false;
  for (auto &s: grid) {
    std::cin >> s;
    if (std::count(s.cbegin(), s.cend(), '#') > 0) {
      able = true;
    }
  }
  if (!able) {
    std::cout << "-1\n";
    return 0;
  }
  int row = inf;
  int column = 0;
  for (int j: range(0, N)) {
    for (int i: range(0, N)) {
      if (grid[i][j] == '.') {
        ++column;
        break;
      }
    }
  }
  for (int i: range(0, N)) {
    int empty = 0;
    for (int j: range(0, N)) {
      if (grid[i][j] == '.') {
        ++empty;
      }
    }
    bool exist = false;
    for (int k: range(0, N)) {
      if (grid[k][i] == '#') {
        exist = true;
        break;
      }
    }
    if (exist) {
      chmin(row, empty);
    }
    else {
      chmin(row, empty + 1);
    }
  }
  std::cout << row + column << '\n';
  return 0;
}


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

int main()
{
  int n;
  cin >> n;
  int a = n%10;
  if(a==3) cout << "bon" << endl;
  else if(a==0 or a==1 or a==6 or a==8) cout << "pon" << endl;
  else	cout << "hon" << endl;
  return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define rep(i, n) for(int i=0; i<n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
typedef long long ll;

#define MAX_N 100000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

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

ll n;
ll h[MAX_N];
ll dp[MAX_N+1]; //足場iまでのコストの総和の最小値

int main() {

  cin >> n;
  rep(i, n) {
    cin >> h[i];
    dp[i] = INF;
  }

  dp[0] = 0;

  rep(i, n-1) {
    dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1]-h[i]));
    if(i<n-2) dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2]-h[i]));
  }

  cout << dp[n-1] << endl;

  return 0;
}


Measured memory_bytes: 1792
<?php
$num_data = trim(fgets(STDIN));

// arr[4][3][10]
$rooms = array_fill(0, 4,
           array_fill(0, 3,
             array_fill(0, 10, 0)));

while ($num_data-- > 0) {
  $input = trim(fgets(STDIN));
  $data  = explode(" ", $input);
  $rooms[$data[0]-1][$data[1]-1][$data[2]-1] += $data[3];
}

$num_bldg = 0;
foreach ($rooms as $bldg) {
  if ($num_bldg > 0) {
    echo "####################" . PHP_EOL;
  }
  $num_bldg++;

  foreach ($bldg as $floor) {
    echo " " . implode(" ", $floor) . PHP_EOL;
  }
}

Measured memory_bytes: 15396
import java.util.Scanner;

/**
 * Gcm
 */
public class Main {

    public static void main(String[] args) {
        new Main().solveGcm();
    }

    void solveGcm(){

        final int INF = 10^9;
        int x,y;

        Scanner sc = new Scanner(System.in);
        x = Integer.parseInt(sc.next());
        y = Integer.parseInt(sc.next());
        sc.close();

        int smaller, mod, dump;

        if(x <= y){
            smaller = x;
            mod = y % x;
        }
        else{
            smaller = y;
            mod = x % y;
        }

        while (mod > 0) {
            dump = smaller;
            smaller = mod;
            mod = dump % smaller;
        }

        System.out.println(smaller);

    }
}


Measured memory_bytes: 26332
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
#define FOR(i, c) \
  \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
const long long mod = 1e9 + 7;
typedef long long ll;  // ll とdoubleは違う
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII;  // VII a(n,vector<int>(m)) n * m
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;  // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>  // chmin(min,a)
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>  // operator << (cout,a);
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp

// Union Find
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3]=2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
const int MAX_N = 1000;
VI G[MAX_N];
VI color(MAX_N); //頂点iの色 (1 or -1)


int main() {
  ll z=0,k,n,m,h,w,ans=0,sum=0,cnt=0,Max=-1e9,Min=1e9+1;
  string u;
  bool ok = false;
  cin >> n >> k;
  VL a(n);
  rep(i,n){
    cin >> a[i];
  }
  sort(ALL(a));
  int i = n-1;
  while(k>0){
    a[i] = 0;
    i--;
    if(i<0)
      break;
    k--;
  }
  rep(i,n) sum += a[i];
  
   cout << sum << endl;
  return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	cin >>n >> k;
	int sum=0;
	for(int i=1;i<=n;i++){
		int t;
		cin >> t;
		if(t>=k)
		sum++;
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;

public class Hello
{

    public static void Main()
    {
        string s = Console.ReadLine();
        int n = int.Parse(s);
        int k = s.ToCharArray().Select(a => int.Parse(a.ToString())).Sum();
        Console.WriteLine((n%k == 0?"Yes":"No"));
    }
}


public class Atcoder
{
    static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static int LCM(int a, int b)
    {
        int c = a * b;
        if (a < b) Swap(ref a, ref b);
        int d = a % b;
        while (d != 0)
        {
            a = b;
            b = d;
            d = a % b;
        }
        return c / b;
    }
    public static string strReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static int intRead()
    {
        return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
    public static string[] SpRead(char c)
    {
        return Console.ReadLine().Split(c);
    }
    public static int[] SpIntRead(char c)
    {
        return Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
    }

}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
  ll n; cin>>n;
  ll ans=1;
  for(ll i=2;i<=n;i++){
      for(ll j=i;j<=n;j+=i)
       ans+=j;
      ans+=i;
  }
  cout<<ans;
}

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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()
#define HOGE cout << "hoge" << endl;
using P = pair<ll,ll>;

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

const int INF = 1e9;

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


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

int main() {
 
  int n;
  string s;
  cin >> n;
  cin >> s;
  string ret = "Yes";
  if((n % 2) != 0)
  {
    ret = "No";
  }
  else
  {
    if( s.substr( 0, (s.size() / 2)) == s.substr((s.size() / 2), (s.size()/2)))
      
       {
         ret = "Yes"; 
       }
    else
    {
      ret = "No";
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string a,b;
  cin>>a>>b;
  
  int cnt=0;
  for(int i=0;i<a.size();i++){
    if(a[i]!=b[i]){
      cnt++;
    }
  }
  cout<<cnt<<endl;
  return(0);
}

Measured memory_bytes: 3848
#include<iostream>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;

#define MAX_N 5500
bool x[MAX_N][MAX_N];
int y[MAX_N][2];
bool z[MAX_N];
int m[MAX_N];
int s[MAX_N];
int t[MAX_N][MAX_N];

queue<int> Q;

int main() {
	memset(x, false, sizeof(x));
	for (int i = 0; i<5500; i++) {
		for (int j = 0; j<5500; j++) {
			m[i] = 1000000000;
			s[i] = 0;
			t[i][j] = 0;
		}
	}
	int N, K, a, b;
	cin >> N >> K;
	for (int i = 1; i <= N; i++) {
		cin >> y[i][0] >> y[i][1];
	}
	for (int i = 1; i <= K; i++) {
		cin >> a >> b;
		x[a][b] = true;
		x[b][a] = true;
		t[a][s[a]] = b;
		t[b][s[b]] = a;
		s[a] += 1;
		s[b] += 1;
	}

	int p;
	int r;
	int u;

	u = N;
	if (K > 6000) {
		u = 20;
	}

	m[1] = 0;

	for (int i = 0; i < u; i++) {
		for (int j = 1; j <= N; j++) {
			if (m[j] < 100000000) {
				while (!Q.empty()) {
					Q.pop();
				}
				Q.push(j);
				memset(z, false, sizeof(z));
				for (int k = 0; k < y[j][1]; k++) {
					r = Q.size();
					for (int l = 0; l < r; l++) {
						p = Q.front();
						for (int o = 0; o < s[p]; o++) {
							if (x[p][t[p][o]] == true && z[t[p][o]] == false) {
								Q.push(t[p][o]);
								z[t[p][o]] = true;
								m[t[p][o]] = min(m[t[p][o]], m[j] + y[j][0]);
							}
						}
						Q.pop();
					}
					if (Q.empty()) {
						goto Exit;
					}
				}
			Exit:;
			}
		}
	}

	cout << m[N] << endl;

	return 0;
}

Measured memory_bytes: 149028
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    int n, t, a;
    cin >> n >> t >> a;
    a *= 1000;
    t *= 1000;
    vector<int> h(n);
    rep(i, n) cin >> h[i];

    int ans = inf;
    int aans = 0;
    rep(i, n) {
        int sa = t - h[i] * 6;
        ans = min(ans, abs(sa - a));
        if(ans == abs(sa - a)) aans = i + 1;
    }

    cout << aans << endl;

    return 0;
}

Measured memory_bytes: 3636
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): pass
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n = I()
A = LI()
acc = [0] + list(accumulate(A))
dp = [[0] * n for _ in range(n)]

def f(l, r):
    if dp[l][r]:
        return dp[l][r]
    if l == r:
        return 0
    m = INF
    for i in range(l, r):
        m = min(m, f(l, i) + f(i + 1, r) + acc[r + 1] - acc[l])
    dp[l][r] = m
    return m

print(f(0, n-1))




Measured memory_bytes: 79984
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int main()
{
	int a,b,x,y;
	while(~scanf("%d%d%d%d",&a,&b,&x,&y))
	{
		int n = x-a,m = y-b;
		for(int i = 0;i < m;i++)
			printf("U");
		for(int i = 0;i < n;i++)
			printf("R");
		for(int i = 0;i < m;i++)
			printf("D");
		for(int i = 0;i < n+1;i++)
			printf("L");
		for(int i = 0;i < m+1;i++)
			printf("U");
		for(int i = 0;i < n+1;i++)
			printf("R");
			printf("D");	
			printf("R");
		for(int i = 0;i < m+1;i++)
			printf("D");
		for(int i = 0;i < n+1;i++)
			printf("L");
		printf("U\n");
	}
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;

const int INF = -1e18;
const int N = 16;
ll cost[1<<N];
ll dp[1<<N];
int n;

int lg2(const int &x) { return 31-__builtin_clz(x); }

ll f(int mask) {
    if (mask == 0) return 0;
    ll &r = dp[mask];
    if (r != -1) return r;
    
    r = -INF;
    for (int sub = mask; sub; sub = (sub-1)&mask) {
        int next = mask&~sub;
        r = max(r, f(next) + cost[sub]);
    }
    return r;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    
    cin >> n;
    int g[n][n];
    forn(i, 0, n) {
        forn(j, 0, n) {
            cin >> g[i][j];
        }
    }
    
    forn(mask, 1, 1<<n) {
        for (int a = mask; a; a &= a-1) {
            int i = lg2(a & -a);
            for (int b = mask; b; b &= b-1) {
                int j = lg2(b & -b);
                cost[mask] += g[i][j];
            }
        }
        cost[mask] /= 2;
    }
    
    int mask = (1<<n)-1;
    memset(dp, -1, sizeof dp);
    ll ans = f(mask);
    
    cout << ans << endl;
}


Measured memory_bytes: 4684
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    k, x = LI()
    min_ = max(-1000000, x - k + 1)
    max_ = min(1000000, x + k - 1)
    print(" ".join([str(i) for i in list(range(min_, max_ + 1))]))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
x, y = map(int, input().split())

if x <= y:
    if x >= 0 or y <= 0:
        cnt = abs(abs(x) - abs(y))
    else:
        cnt = abs(abs(x) - abs(y)) + 1
else:
    if x < 0 or y > 0:
        cnt = abs(abs(x) - abs(y)) + 2
    else:
        cnt = abs(abs(x) - abs(y)) + 1

print(cnt)

Measured memory_bytes: 3188
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <ctime>
#include <iomanip>
#include <numeric>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> p(n), q(n);
	vector<int> perm(n);
	iota(perm.begin(), perm.end(), 1);
	reverse(perm.begin(), perm.end());
	for (int i = 0; i < n; i++)
	{
		cin >> p[i];
	}
	for (int i = 0; i < n; i++)
	{
		cin >> q[i];
	}
	int fakt = 1;
	for (int i = 2; i <= n; i++)
	{
		fakt *= i;
	}
	int a = fakt, b = fakt;
	do
	{
		if (perm == q) b = fakt;
		if (perm == p) a = fakt;
		fakt--;
	} while (prev_permutation(perm.begin(), perm.end()));
	cout << abs(a - b);
}


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

int main(){
	int n; cin>>n;
	int arr[n][3];
	for(int i = 0; i < n; i++) cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
	int dp[n][3];
	dp[0][0] = arr[0][0]; dp[0][1] = arr[0][1]; dp[0][2] = arr[0][2];
	for(int i = 1; i < n; i++){
		dp[i][0] = arr[i][0] + max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] = arr[i][1] + max(dp[i-1][0], dp[i-1][2]);
		dp[i][2] = arr[i][2] + max(dp[i-1][1], dp[i-1][0]);
	}
	cout<<max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]))<<endl;
}


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

int MAX = 100001;
int MOD = 1000000007;
vector<long long> fac(MAX), finv(MAX), inv(MAX);

void COMinit() {
  fac.at(0) = fac.at(1) = 1;
  finv.at(0) = finv.at(1) = 1;
  inv.at(1) = 1;
  for (int i = 2; i < MAX; i++) {
    fac.at(i) = fac.at(i-1) * i % MOD;
    inv.at(i) = MOD - inv.at(MOD % i) * (MOD / i) % MOD;
    finv.at(i) = finv.at(i-1) * inv.at(i) % MOD;
  }
}

long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac.at(n) * (finv.at(k) * finv.at(n-k) % MOD) % MOD;
}

long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}

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

  long long ans = 0;
  COMinit();
  for (int i = N-1; i >= K-1; i--) {
    long long tmp = mod(COM(i, K-1) * A.at(i), MOD);
    ans = mod(ans + tmp, MOD);
  }
  for (int i = 0; i <= N-K; i++) {
    long long tmp = mod(COM(N-1-i, K-1) * A.at(i), MOD);
    ans = mod(ans - tmp, MOD);
  }
  cout << ans << endl;
}

Measured memory_bytes: 2944
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#include<cmath>
#include<queue>
#include<stack>
#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
#define chmax(a,b) {if(a < b) a = b;}
#define chmin(a,b) {if(a > b) a = b;}
using namespace std;
typedef long long ll;
ll gcd(ll, ll);
vector<bool> to_binary(int);
int sum(vector<int>);
int min(vector<int>);
int max(vector<int>);
ll nCr(ll n, ll r);

const ll INF = 1LL << 60;

typedef tuple<ll, ll> mtupl;

bool mycomp(mtupl x, mtupl y) {
	return get<1>(x) < get<1>(y);
}

vector<vector<ll>> memo;

ll get(int x, int y) {
	if (memo[x][y] != -1)
		return memo[x][y];

	if (x == 0) return 1;
	if (y < x) return 0;

	memo[x][y] = get(x, y - 1) + get(x - 1, y - 1);
	return memo[x][y];
}

ll mpow(ll a, ll b) {
	ll ans = 1;
	for (ll i = 0; i < b; i++) {
		ans *= a;
		ans %= 1000000007;
	}
	return ans;
}

ll nCr(ll n, ll r) {
	ll res = 1;
	for (int i = 0; i < r; i++) {
		res *= (n - i);
	}
	for (int i = 1; i <= r; i++) {
		res /= i;
	}
	return res;
}

int vsum(vector<int> v) {
	int res = 0;
	for (auto it = v.begin(); it != v.end(); it++)
		res += *it;
	return res;
}
int vmin(vector<int> v) {
	int min = INT32_MAX;
	for (auto it = v.begin(); it != v.end(); it++)
		min = std::min(min, *it);
	return min;
}
int vmax(vector<int> v) {
	int max = INT32_MIN;
	for (auto it = v.begin(); it != v.end(); it++)
		max = std::max(max, *it);
	return max;
}

ll gcd(ll A, ll B) {
	if (A == 0 || B == 0) return max(A, B);
	int r = A % B;
	while (r != 0) {
		A = B;
		B = r;
		r = A % B;
	}
	return B;
}

ll _gcd(ll A, ll B) {
	return (B == 0) ? A : gcd(A % B, B);
}

vector<bool> to_binary(int x) {
	vector<bool> res;
	while (x != 0) {
		res.push_back(x % 2);
		x /= 2;
	}
	return res;
}

template<int index>
bool comp(tuple<ll, ll, ll, ll> a, tuple<ll, ll, ll, ll> b) {
	return get<index>(a) < get<index>(b);
}

int vector_finder(std::vector<ll> vec, ll number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return index;
	}
	else { // 発見できなかったとき
		return 0;
	}
}


int len(int x) {
	return (int)log10(x) + 1;
}

int same_vec(vector<int> a, vector<int> b) {
	int res = 1, num = a.size();
	for (int i = 0; i < num; i++) {
		if (a[i] != b[i]) {
			res = 0;
			break;
		}
	}
	return res;
}


ll fibs[100] = { 0 };
ll fib(int n) {
	if (fibs[n] == 0) {
		return fibs[n] = fib(n - 1) + fib(n - 2);
	}
	return fibs[n];
}

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

	string S;
	cin >> S;

	if (S == "Sunny")
		cout << "Cloudy" << endl;
	if (S == "Cloudy")
		cout << "Rainy" << endl;
	if (S == "Rainy")
		cout << "Sunny" << endl;




ProgramEndPointLabel:;

	//Program End
#ifndef DEBUG
	system("pause");
#endif // !DEBUG


	return 0;
}




Measured memory_bytes: 504
#include <bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000
int MOD=1000000007;
int n,w;
int dp[101][10001];
signed main() {
cin>>n>>w;
vector<int>value(n);
vector<int>weight(n);
rep(i,n){
  cin>>value[i]>>weight[i];
}
rep(i,101){
  rep(j,10001){
    dp[i][j]=0;
  }
}
rep(i,n){
  rep(j,w+1){
    if(j-weight[i]>=0){
      dp[i+1][j]=max(dp[i][j],dp[i][j-weight[i]]+value[i]);
      dp[i+1][j]=max(dp[i+1][j],dp[i+1][j-weight[i]]+value[i]);
    }

    else dp[i+1][j]=dp[i][j];
  }
}
cout<<dp[n][w]<<endl;
}



Measured memory_bytes: 11012
#include <iostream>
#include <string>
using namespace std;
int main()
{
    int K;
    cin >> K;
    string S;
    cin >> S;
    
    if(S.length()<=K)
    {
        cout << S;
    }
    else
    {
        for(int i=0;i<K;i++)
        {
            cout << S[i];
        }
        cout << "...";
    }
    

    return 0;
}

Measured memory_bytes: 3596
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
using pint = pair<int,int>;
using vec = vector<int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
const int mod = 1000000007;
struct mint {
    int64_t x;
    mint(int64_t x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(int64_t t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    //for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) {return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

ll a[100005][3];
ll dp[100005][3];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    ll n;cin>>n;
    rep(i,n)rep(j,3) cin>>a[i][j];
    
    rep(i,n)rep(l,3)rep(j,3){
        if(l != j) chmax(dp[i+1][j], dp[i][l] +a[i][j]);
    }

    cout<<*max_element(dp[n],dp[n] + 3)<<endl;
    
}

Measured memory_bytes: 8344
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int N;
    int cnt[9] = {};
    cin >> N;
    for(int i = 0;i < N;i++){
        int a;
        cin >> a;
        if(a >= 3200)cnt[8]++;
        else cnt[a/400]++;
    }
    int mini = 0,maxi = 0;
    for(int i = 0;i < 8;i++)mini += (cnt[i] != 0);
    maxi = mini + cnt[8];
    if(mini == 0)mini = 1;

    cout << mini << " " << maxi << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String input = sc.next();
        int len, num, sum;

        while (!input.equals("0")) {
            len = input.length();
            sum = 0;

            for (int i = 0; i < len; i++) {
                num = input.charAt(i) - '0';
                sum += num;
            }

            System.out.println(sum);

            input = sc.next();
        }

        sc.close();
    }
}


Measured memory_bytes: 26300
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int i,j,k;
int n=-1,m,ans=0;
char s[1000005];

int main(){
	j=0;
	scanf("%d",&n);
	while(n!=0){
		scanf("%d",&m);
		scanf("%s",s);
		for(i=0;i<m-n*2;i++){
			if(s[i]=='I'){
				while(j<n){
					if(s[i+1+j*2]=='O'){
						if(s[i+2+j*2]=='I'){
							j++;
						}else{
							i++;break;}
					}else break;
				}
				if(j==n)ans++;
				j=0;
			}
		}
		printf("%d\n",ans);
		ans=0;
		scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 1396
n, m = map(int, input().split())
s_li = [list(map(int, input().split())) for i in range(m)]

if n != 1:
    ans = ['1']
    ans.extend(['0'] * (n - 1))
else:
    ans = ['0']
flag = [0] * n

for s, c in s_li:
    if flag[s - 1] == 0:
        ans[s - 1] = '{}'.format(c)
        flag[s - 1] = 1
    elif flag[s - 1] == 1 and int(ans[s - 1]) == c:
        continue
    else:
        ans = ['-1']
        break

ans = int(('').join(ans))

if n != 1 and (ans // 10**(n - 1)) == 0:
    ans = -1

print(ans)

Measured memory_bytes: 3064
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int l[] = new int[n];
		int ans = 0;
		for(int i = 0;i < n;i++) {
			l[i] = sc.nextInt();
		}
		Arrays.sort(l);
		for(int i = 0;i < n-2;i++) {
			for(int k = i + 1;k < n - 1; k++) {
				for(int m = k+1;m < n ;m++) {
					if(l[m] < l[k] + l[i]) {
						ans++;
					}else {
						break;
					}
				}
			}
		}
		System.out.println(ans);

	}

}


Measured memory_bytes: 25884
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> P;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[100000],dp[100][100];

int main(){
  cin >> s;
  pel(i,s.sz-1,0){
    t = "";
    m = 0;
    rep(j,0,i)t += s[j];
    if(t.sz % 2)continue;
    // cout << t.sz << " " << t << endl;
    rep(j,0,t.sz/2){
      if(t[j] == t[t.sz/2+j])m += 2;
    }
    if(t.sz == m)break;
  }
  print(m);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;

int n;
bool same = false;
bool diff = false;

int main() {
    cin >> n;
    int ans = 0;
    int a = 0, b = 0;
    rep(i,n) {
        string str;
        cin >> str;
        if (str[0] == 'B') b++;
        if (str[str.size()-1] == 'A') a++;
        if (str[0] == 'B' && str[str.size()-1] == 'A') same = true;
        else if (str[0] == 'B') diff = true;
        else if (str[str.size()-1] == 'A') diff = true;
        rep(j,str.size()-1) {
            if (str[j] == 'A' && str[j+1] == 'B') {
                ans++;
            }
        }
    }
    ans += min(a, b);
    if (same && !diff) ans--;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{

    ll a,b,m;
    cin>>a>>b>>m;
    ll arr[a+5]= {0};
    ll brr[b+5]= {0};
    ll mna=INT_MAX;
    ll mnb=INT_MAX;
    for(int i=0; i<a; i++)
    {
        cin>>arr[i];
        mna=min(mna,arr[i]);
    }
    for(int i=0; i<b; i++)
    {
        cin>>brr[i];
        mnb=min(mnb,brr[i]);
    }
    ll sum=mna+mnb;
    ll arek=INT_MAX;
    for(int i=0;i<m;i++)
    {
        ll x,y,c;
        cin>>x>>y>>c;
        ll f=arr[x-1];
        ll ff=brr[y-1];
        ll tot=f+ff-c;
        arek=min(tot,arek);

    }
    cout<<min(arek,sum)<<endl;


}


Measured memory_bytes: 5100
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-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;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	vl v(1,0);
	if(s[0]=='1')v.push_back(0);
	int cnt=0;
	rep(i,n){
		if(i==0)cnt++;
		else{
			if(s[i]!=s[i-1]){
				v.push_back(cnt);
				cnt=1;
			}
			else cnt++;
		}
	}
	v.push_back(cnt);
	if(s.back()=='0')v.push_back(0);
	rep(i,v.size()-1){
		v[i+1]+=v[i];
	}
	ll ans=0;
	rep(i,v.size()){
		if(i%2==0)chmax(ans,v[i]-v[max(0,i-k*2-1)]);
	}
	cout<<ans<<endl;
}


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

bool check(string s) {
	int n = std::atoi(s.c_str());
	if (n == 0) {
		return false;
	}  
	if (n > 12) {
		return false;
	}
	return true;
}

int main() {
	string s;
	cin >> s;

	string f = s.substr(0, 2);
	string b = s.substr(2, 2);

	bool fr = check(f);
	bool br = check(b);

	if (fr && br) {
		cout << "AMBIGUOUS" << endl;
	} else if (fr) {
		cout << "MMYY" << endl;
	} else if (br) {
		cout << "YYMM" << endl;
	} else {
		cout << "NA" << endl;
	}
	
	return 0;
}

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

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

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

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

	operator Type&()
	{
		return val;
	}

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

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

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

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

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

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

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

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

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

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

	ll dividend = 1, divisor = 1;

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

	return dividend / divisor;
}

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

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

    return true;
}

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

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

void Main();

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

	Main();

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

	return 0;
}

using namespace std;

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

void Main()
{
	inll a_, b_, c_;
	ll a  = a_, b = b_, c = c_;
	
	return OUT(max({a,b,c}) * 10 + min({a,b,c}) + (a+b+c-max({a,b,c})-min({a,b,c})));
}


Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>

using namespace std;


int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<int> v1, v2;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'R') {
			v1.push_back(i);
		}
		if (s[i] == 'G') {
			v2.push_back(i);
		}
	}
	long long int res = 0;
	int b = 0;
	vector<int> vb;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'B') {
			b++;
		}
		vb.push_back(b);
	}
	int l1 = v1.size(), l2 = v2.size();
	for (int i = 0; i < l1; i++) {
		for (int j = 0; j < l2; j++) {
			int index1 = min(v1[i], v2[j]), index2 = max(v1[i], v2[j]);
			int index3 = 0;
			// [1, 2, 3]
			res += vb.back() - vb[index2];
			index3 = 2 * index2 - index1;
			if (index3 < s.size() && s[index3] == 'B') {
				res--; 
			}
			// [3, 1, 2]
			res += vb[index1];
			index3 = index1 - (index2 - index1);
			if (index3 >= 0 && s[index3] == 'B') {
				res--;
			}
			// [1, 3, 2]
			res += vb[index2] - vb[index1];
			index3 = (index1 + index2) / 2;
			if ((index2 - index1) % 2 == 0 && s[index3] == 'B') {
				res--;
			}
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 3660
/*
Author: Sagar Gupta
E mail: sagar.june97p@gmail.com
*/

#pragma comment(linker, "/STACK:268435456")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl ("\n")
#define deb(n) cerr << #n << " = " << (n) << '\n'
#define FOR(i, n) for (int(i) = 0; (i) < n; (i)++)
#define PI (3.141592653589)
#define ordered_set tree<int, null_type, std::less<int>, rb_tree_tag, tree_order_statistics_node_update>

#define MOD 1000000007

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed;
    cout.precision(10);
    // Those who cannot acknowledge themselves, will invariably fail

    int n;
    cin >> n;
    int arr[n];
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    int prefix[n], suffix[n];
    prefix[1] = arr[0];
    for (int i = 2; i < n; i++)
    {
        prefix[i] = __gcd(prefix[i - 1], arr[i - 1]);
    }
    suffix[n - 2] = arr[n - 1];
    for (int i = n - 3; i >= 0; i--)
    {
        suffix[i] = __gcd(suffix[i + 1], arr[i + 1]);
    }
    int sol = 0;
    for (int i = 0; i < n; i++)
    {
        if (!i)
        {
            sol = max(sol, suffix[i]);
        }
        else if (i == n - 1)
        {
            sol = max(sol, prefix[i]);
        }
        else
        {
            sol = max(sol, __gcd(prefix[i], suffix[i]));
        }
    }
    cout << sol;
    return 0;
}

Measured memory_bytes: 1408
using System;
using CompLib.Util;

public class Program
{
    private int K;
    private int[] A;

    public void Solve()
    {
        var sc = new Scanner();
        K = sc.NextInt();
        A = sc.IntArray();
        long l = 2;
        long r = 2;
        for (int i = K - 1; i >= 0; i--)
        {
            long t = (l + A[i] - 1) / A[i];
            long nextL = t * A[i];
            long tt = r / A[i];
            long nextR = tt * A[i] + A[i] - 1;
            if (nextR < nextL)
            {
                Console.WriteLine("-1");
                return;
            }

            l = nextL;
            r = nextR;
        }

        Console.WriteLine($"{l} {r}");
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 30300
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N,K=map(int,input().split())
    h=list(map(int,input().split()))+[INF]*K
    dp=[INF]*(2*10**5)
    dp[0]=0
    for i in range(N):
        for k in range(1,K+1):
            dp[i+k]=min(dp[i+k],dp[i]+abs(h[i+k]-h[i]))
    print(dp[N-1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 53984
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using namespace std;
using ll = long long;
const ll MOD = (ll)1e9+7;
//const ll MOD = 998244353;
//const ll MOD = 924844033;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
const double EPS = 1e-5;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

#ifdef DEBUG
#define OUTPUT(x) (output(x), outendl())
#else
#define OUTPUT(x) (void)0
#endif

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
	if(was_output)cout << " ";
	cout << a;
	was_output = true;
}
void outendl(){
	was_output = false;
	cout << endl;
}

int main(){
	int n;
	cin >> n;
	int top = 0;
	rep(i,n){
		int d;
		cin >> d;
		if(top+1==d){
			++top;
		}
	}
	if(top==0){
		cout << -1 << endl;
	}else{
		cout << n - top << endl;
	}
		return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int[] a = new int[n];
    for(int i=0;i<n;i++)a[i] = Integer.parseInt(sc.next());
    long res = 0;
    long val;
    for(int i=0;i<n-1;i++){
      val = a[i]/2;
      a[i]-=2*val;
      res+=val;
      if(a[i]>0 && a[i+1] > 0){
        res++;
        a[i+1]--;
      }
    }
    val = a[n-1]/2;
    System.out.println(res+val);
  }
}

Measured memory_bytes: 48900
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"
long long int powint(long long int a, long long int b) {
	assert(b >= 0);
	if (b == 0)return 1;
	if (b == 1)return a;
	long long int ans = 1;
	long long int aa = powint(a, b / 2);
	ans *= aa*aa;
	if (b % 2)ans *= a;
	return ans;
}

string to_string_keta(const long long int l, const int keta) {
	ostringstream oss;

	oss << std::setw(keta) << std::setfill('0') << l;

	return oss.str();
}

int main() {
	string from; cin >> from;
	
	long long int  st(stoll(from));
	int keta = from.size();
	vector<int>perms(10);
	iota(perms.begin(), perms.end(), 0);
	pair<long long int, long long int>ans(0, 0);
	do {
		string after;
		long long int aft = 0;
		for (int i = 0; i < keta; ++i) {
			aft = aft * 10 + perms[i];
		}
		auto p = make_pair(min(abs(st - aft), powint(10, keta) - abs(st - aft)), -aft);
		ans = max(ans, p);
		
		
	} while (next_permutation(perms.begin(), perms.end()));
	string ast = to_string_keta(-ans.second, keta);
	cout << ast<< endl;
	return 0;
}

Measured memory_bytes: 3220