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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

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

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

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> v(n, 0);
  for (int i = 0; i < n; i++)
  {
    cin >> v[i];
  }

  sort(all(v));
  int a = v[k-1] - v[0];
  for (int i = 0; i+k-1 < n; i++)
  {
    a = min(a, v[k-1+i] - v[i]);
  }
  cout << a << endl;
}


Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
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; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int kurai(int a,int b){
  int m=pow(10,b),n=pow(10,b-1);
  return (a%m)/n;
}
int ketawa(int a){
  int k=0;
  rep(i,keta(a)){
  k+=kurai(a,i+1);
  }
  return k;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
int mid(int a,int b,int c){
  vector<int> k(3);
  k[0]=a;k[1]=b;k[2]=c;
  sort(all(k));
  return k[1];
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
 if(!b)return 1; if(b&1)return modpow(a,b-1,m)*a%m;
 int memo = modpow(a,b>>1,m);
 return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  int a;
  cin>>a;
  out(a+a*a+a*a*a);
}

Measured memory_bytes: 3820
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    char[] s = sc.next().toCharArray();
    int tmp = 0;
    int ans = 0;
    for (char ss : s) {
      if (ss == 'R') {
        tmp++;
      } else {
        tmp = 0;
      }
      ans = Math.max(tmp, ans);
    }
    System.out.println(ans);
    sc.close();
  }
}


Measured memory_bytes: 35584
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#define ll long long
#define N 300010
#define mod 1000000007
using namespace std;
int nxt[8][2]={{2,1},{4,3},{6,5},{3,3},{7,1},{2,1},{2,2},{4,4}};
ll f[N][8];
char str[N];
int main()
{
	scanf("%s",str);
	int n=strlen(str);
	f[0][0]=1;
	for(int i=0;i<n;i++)
		for(int j=0;j<=7;j++)
		{
			if(str[i]=='1' || str[i]=='?') (f[i+1][nxt[j][1]]+=f[i][j])%=mod;
			if(str[i]=='0' || str[i]=='?') (f[i+1][nxt[j][0]]+=f[i][j])%=mod;
        }
    printf("%lld\n",(f[n][1]+f[n][3])%mod);
	return 0;
}


Measured memory_bytes: 19328
package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var llist [9923456]int
var llistIdx int

func main() {
	scanInit()

	k := nextInt()

	for i := 1; i < 10; i++ {
		push(i)
	}

	// BFS
	llistIdx = 0
	for queue.Len() > 0 {
		now := pop()
		llist[llistIdx] = now
		llistIdx++

		if keta(now) < 10 {
			base := now % 10

			if base != 0 {
				push(now*10 + base - 1)
			}

			push(now*10 + base)

			if base != 9 {
				push(now*10 + base + 1)
			}
		}
	}

	anslist := llist[:llistIdx]

	fmt.Println(anslist[k-1])

}

var queue = list.New()

func push(a int) {
	queue.PushBack(a)
}
func pop() int {
	e := queue.Front()
	queue.Remove(e)
	return e.Value.(int) // 明示的キャストが必要
}

// 正数の桁数を返す
func keta(n int) int {
	keta := 0
	if n == 0 {
		return 1
	}
	for n > 0 {
		keta++
		n /= 10
	}
	return keta
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 12744
#include <bits/stdc++.h>
using namespace std;
int main() {
    while (true) {
        int h, w; cin >> h >> w;
        if (h == 0 && w == 0) break;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++)
                if ((i ^ j) & 1) cout << '.';
                else cout << '#';
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define R register
#define ll long long
#define mp make_pair
#define pii pair<int, int>
using namespace std;

template <class T>
inline void read(T &x) {
    x = 0;
    char ch = getchar(), w = 0;
    while (!isdigit(ch)) w = ch == '-', ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    x = w ? -x : x;
    return;
}

int main() {
    int n;
    read(n);
    for (R int i = 1; i <= 9; ++i)
        if (n % i == 0 && n / i <= 9)
            return printf("Yes\n"), 0;
    printf("No\n");
    return 0;
}

Measured memory_bytes: 256
let readCharArray _ = stdin.ReadLine().ToCharArray()

let x = readCharArray ()
let y = readCharArray ()

(if x.Length = y.Length then Array.zip x y else Array.zip x (Array.append y [| ' ' |]))
|> Array.collect (fun (x, y) -> [| x; y |])
|> System.String
|> fun x -> x.Trim()
|> printfn "%s"


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

using namespace std;

int main()
{
    int n, k;
    cin>>n>>k;
    int tall[n];
    for (int i=0;i<n;i++)
        cin>>tall[i];
    sort(tall, tall+n);
    cout<<n-(lower_bound(tall, tall+n, k)-tall);
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t N, K;
  cin >> N >> K;
  int64_t a = K;
  int num = 1;
  while (true) {
    if (N < a) {
      break;
    }
    a *= K;
    num++;
  }
  cout << num << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
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; }
using namespace std;

string s, t;
int dp[3010][3010];

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

    int n = s.length(), m = t.length();
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (s[i-1] == t[j-1]) {
                dp[i][j] = dp[i-1][j-1] + 1;
            } else {
                dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
            }
        }
    }

    // 復元
    string a = "";
    int i = n, j = m;
    while (i > 0 && j > 0) {
        if (s[i-1] == t[j-1]) {
            a += s[i-1];
            i--; j--;
        } else {
            if (dp[i-1][j] > dp[i][j-1]) i--;
            else j--;
        }
    }
    reverse(a.begin(), a.end());
    cout << a << endl;
}


Measured memory_bytes: 35584
#include <bits/stdc++.h>
#include <iterator>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <math.h>
#define vi vector<int>
#define vvi vector<vector<int> > 
#define vl vector<long long>
#define vpi vector<pair<int,int> >
#define ll long long 
#define all(x) x.begin(),x.end()
#define vpl vector<pair<long long,long long> > 
#define F first
#define S second
#define mp make_pair
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pci pair<char,int>
#define un unsigned
# define M_PI           3.14159265358979323846  /* pi */
// #define mod 998244353
#define mod 1000000007
#define MAXN  1000001
using namespace std; 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)


int n,m,x;
int a[12][12];
int c[12];

void read()
{
    cin>>n>>m>>x;
    for(int i = 0 ; i < n ; i++)
    {
        cin>>c[i];
        for(int j = 0 ; j < m ; j++)
        cin>>a[i][j];    
    }
}

void solve()
{
    read();
    int all = pow(2,n);
    ll ans = pow(10,9);
    for(int mask = 0 ; mask < all ; mask++)
    {
        int flag =0;
        vi level(m,0);
        ll temp = 0;
        for(int i = 0 ; i < n ; i++)
        {
            if(mask>>(i)&1)
            {
                temp += c[i];
                for(int j = 0 ; j < m ; j++)
                level[j] += a[i][j];
            }
        }
        for(int j = 0 ; j < m ; j++)
        {
            if(level[j] < x)
            {
                flag = 1;
                break;
            }
        }
        if(flag == 0)
        {
            ans = min(ans,temp);
        }
    }
    if(ans == pow(10,9))
    {
        cout<<-1<<endl;
        return;    
    }
    cout<<ans<<endl;
}


int main()
{
    fast;
    int t;
    // cin>>t;
    t = 1;
    while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 4052
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
LL dp[101][100001];
LL *val,*wgt;
LL knapsack(LL n, LL w) {
    if(n==0 || w==0) return 0;
    if(dp[n][w] == -1) {
        if(wgt[n-1]>w) {
            dp[n][w] = knapsack(n-1,w);
        } else {
            dp[n][w] = max(val[n-1]+knapsack(n-1,w-wgt[n-1]),
                           knapsack(n-1,w));
        }
        return dp[n][w];
    } else {
        return dp[n][w];
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    LL n,w;
    cin >> n >> w;
    val = new LL[n];
    wgt = new LL[n];
    for(int i=0; i<n; i++) cin >> wgt[i] >> val[i];
    memset(dp,-1,sizeof(dp));
    cout << knapsack(n,w) << "\n";
}


Measured memory_bytes: 79232
from math import sqrt

n = int(input())
if n == 1:
    print(0)
    exit()

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

f = factorization(n)
ans = 0
for p in f:
    ans += (-1 + int(sqrt(1 + 8 * p[1]))) // 2
print(ans)


Measured memory_bytes: 63584
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll M{100000};
ll N,A[M],B[M],C[M],ans;
int main(){
    cin>>N;
    for(ll i{};i<N;++i)cin>>A[i];
    for(ll i{};i<N;++i)cin>>B[i];
    for(ll i{};i<N;++i)cin>>C[i];
    sort(A,A+N),sort(B,B+N),sort(C,C+N);
    for(auto& b:B)
        ans+=distance(A,lower_bound(A,A+N,b))*distance(upper_bound(C,C+N,b),C+N);
    cout<<ans<<endl;
}

Measured memory_bytes: 2560
n = int(input())

ans = 0


def gen_pat(cur):
    global ans

    if int(cur) > n:
        return

    if len(set(cur)) == 4:  # 0 7 5 3 が含まれる。
        ans += 1

    gen_pat(cur + "3")
    gen_pat(cur + "5")
    gen_pat(cur + "7")


gen_pat("0")
print(ans)


Measured memory_bytes: 9172
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N,K=get_i
p=get_i.sort
puts p[0..K-1].inject(:+)

Measured memory_bytes: 14280
#include <bits/stdc++.h>
using namespace std;
 
#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main() {
    int N, A, B;
    string S;
    cin >> N >> A >> B >> S;

    int cnt1 = 0, cnt2 = 0;
    REP(i, N) {
        if(S[i] == 'a' && cnt1 + cnt2 < A + B) {
            cnt1++;
            cout << "Yes" << endl;
        } else if (S[i] == 'b' && cnt1 + cnt2 < A + B && cnt2 < B) {
            cnt2++;
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}


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

using namespace std;

const int N = 200'009;

vector<int> c[N];
vector<int> r[N];
int pc[N];
int pr[N];

int main() {
  int rows, cols, n;
  scanf("%d %d %d", &rows, &cols, &n);
  for (int i = 0; i < cols; ++i) {
    c[i].clear();
  }
  for (int i = 0; i < rows; ++i) {
    r[i].clear();
  }
  for (int i = 0; i < n; ++i) {
    int cr, cc;
    scanf("%d %d", &cr, &cc);
    --cr;
    --cc;
    c[cc].push_back(cr);
    r[cr].push_back(cc);
  }
  for (int i = 0; i < cols; ++i) {
    c[i].push_back(rows);
    sort(c[i].begin(), c[i].end());
    pc[i] = 0;
  }
  for (int i = 0; i < rows; ++i) {
    r[i].push_back(cols);
    sort(r[i].begin(), r[i].end());
    pr[i] = 0;
  }
  int ans = 1'000'000'000;
  int sr = 0, sc = 0;
  while (true) {
    while (sr >= c[sc][pc[sc]]) {
      ++pc[sc];
    }
    ans = min(ans, c[sc][pc[sc]] - 1);
    if (sr + 1 == c[sc][pc[sc]]) {
      break;
    }
    ++sr;
    while (sc >= r[sr][pr[sr]]) {
      ++pr[sr];
    }
    if (sc + 1 < r[sr][pr[sr]]) {
      ++sc;
    }
  }
  printf("%d\n", ans + 1);
}


Measured memory_bytes: 23808
(* Vicfred
 * https://atcoder.jp/contests/abc142/tasks/abc142_c
 * implementation, simulation
 * *)
Scanf.scanf "%d\n" @@ fun n ->
    let a = Array.init n (fun i -> Scanf.scanf "%d " (fun a -> i+1,a)) in
    Array.sort (fun (a,b) (x,y) -> compare b y) a;
    Array.iter (fun (x, _) -> Printf.printf "%d " x) a;
    Printf.printf "\n"



Measured memory_bytes: 9416
#include<iostream>
#include<string>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
using namespace std;
int main()
{
    string s;
    cin >> s;
    for (int i=0;i<3;i++)
        if (s[i]=='1') cout << '9'; else cout << '1';
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
void OUT(int x){if(x<0)putchar('-'),x=-x;if(x>=10)OUT(x/10);putchar(x%10+48);}
int main(void)
{
  int N,i,j,x;long long K;
  i=scanf("%d %lld",&N,&K);
  int A[N]={0},here[N]={},town[N]={0};
  for(i=0;i<N;i++)here[i]=-scanf("%d",&A[i]);
  for(i=0,j=0;;i=A[i]-1,j++)if(here[i]<0)here[i]=j,town[j]=i;else{x=here[i];break;}
  if(K>=j)K=(K-x)%(x-j)+x;
  return OUT(town[K]+1),0;
}

Measured memory_bytes: 4004
#include <iostream>
#include <math.h>
using namespace std;

int main(){
	int A,B,C,D;
	cin >> A >> B >> C >> D;
	int attack_takahashi,attack_aoki;
	attack_takahashi = C/B;
	attack_aoki = A/D;
	if( fmod(C,B)!=0 ) attack_takahashi++;
	if( fmod(A,D)!=0 ) attack_aoki++;
	if( attack_aoki < attack_takahashi ) cout << "No" << endl;
	else cout<< "Yes" << endl;
	return 0;
}



Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
bool R1[5021][5021];
bool R2[5021][5021];
int main() {
  ll N,K;
  cin >> N >> K;
  ll a[N];
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  ll ans = 0;
  R1[0][0] = true;
  if (a[0] <= K) R1[0][a[0]] = true;
  for (ll i = 1; i < N; i++) {
    for (ll j = 0; j <= K; j++) {
      R1[i][j] = R1[i-1][j];
      if (0 <= j-a[i] && j-a[i] <= K) {
        if (R1[i-1][j-a[i]]) {
          R1[i][j] = true;
        }
      }
    }
  }
  R2[N-1][0] = true;
  if (a[N-1] <= K) R2[N-1][a[N-1]] = true;
  for (ll i = N-2; i >= 0; i--) {
    for (ll j = 0; j <= K; j++) {
      R2[i][j] = R2[i+1][j];
      if (0 <= j-a[i] && j-a[i] <= K) {
        if (R2[i+1][j-a[i]]) {
          R2[i][j] = true;
        }
      }
    }
  }
  // R1[i][j]はi番目までにjぴったりが作れるか R2[i][j]は逆順
  // i = 0,N-1の時は例外処理
  for (ll i = 1; i < N-1; i++) {
    if (a[i] >= K) {
      continue;
    }
    ll Can[K - a[i] + 1];
    for (ll j = 0; j < K - a[i] + 1; j++) {
      Can[j] = 0;
    }
    for (ll j = 0; j < a[i]; j++) {
      if (R1[i-1][j]) {
        Can[0]++;
      }
    }
    for (ll j = 1; j < K - a[i] + 1; j++) {
      Can[j] = Can[j-1];
      if (R1[i-1][j+a[i]-1]) Can[j]++;
      if (R1[i-1][j-1]) Can[j]--;
    }
    bool need = false;
    for (ll j = 0; j < K - a[i] + 1; j++) {
      if (Can[j] != 0 && R2[i+1][K-a[i]-j]) {
        need = true;
      }
    }
    if (!need) {
      ans++;
    }
  }

  if (a[0] < K) {
    bool need = false;
    for (ll i = K-a[0]; i < K; i++) {
      if (R2[1][i]) {
        need = true;
      }
    }
    if (!need) {
      ans++;
    }
  }
  if (a[N-1] < K) {
    bool need = false;
    for (ll i = K-a[N-1]; i < K; i++) {
      if (R1[N-2][i]) {
        need = true;
      }
    }
    if (!need) {
      ans++;
    }
  }
  if (N == 3) {
    ans--;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 52608
while 0<n=gets.to_i
r=[0]*(n/2)
a=(1..n-1).map{|i|i**2%n}.uniq.sort
a.each{|i|a.each{|j|i>j||break;d=i-j;r[d>n/2?n-d-1:d-1]+=2}}
puts r
end

Measured memory_bytes: 6512
#include <iostream>
#include <vector>
#include <string>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

const int mod = 1000000000+7;

int count_bit(int n){
    int ret = 0;
    rep(i, 30){
        if(n & (1 << i))    ret++;
    }
    return ret;
}

int main(){
    int n;  cin >> n;
    vector<vector<int> >c(n, vector<int>(n));
    rep(i, n)   rep(j, n)   cin >> c[i][j];
    vector<vector<int> >dp(n+1, vector<int>(1 << n));
    dp[0][0] = 1;
    rep(i, n)   for(int j = 0; j < (1 << n); j++)   if(i == count_bit(j)){
        rep(w, n)   if(j != j | (1 << w))  if(c[i][w]){
            dp[i+1][j | (1 << w)] += dp[i][j];
            dp[i+1][j | (1 << w)] %= mod;
        }
    }
    cout << dp[n][(1 << n) - 1] << endl;
}


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

int main(){
    int n,k;
    cin >> n >> k;
    
    vector<int> a(n),b;
    rp(i,n){
        cin >> a.at(i);
    }
    sort(a.begin(),a.end());
    int d=0,i=0;//dは要素の種類数
    
    while(i<n){
        int cnt=1;//cntは重複した要素の個数
        while(i<n-1&&a.at(i)==a.at(i+1)){
            i++;
            cnt++;
        }
        b.push_back(cnt);//重複した要素数を格納
        d++;//要素の種類数をカウント
        i++;
    }
    if(d<=k){
        cout << 0 << endl;
    }else{
        sort(b.begin(),b.end());
        int ans=0;
        rp(j,d-k){
            ans += b.at(j);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
int n,a[300001],b[300001];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",a+i);
		if(a[i]>=i||a[i]-a[i-1]>1){puts("-1");return 0;}
	}
	long long ans=0;
	for(int i=n,prev=0;i;i--,prev=max(0,prev-1))
		if(prev!=a[i])
		{
			if(!a[i]){puts("-1");return 0;}
			ans+=a[i];prev=a[i];
		}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;
public class Main
{
	public static void main(String aeg[])
	{
		Scanner in= new Scanner(System.in);
		while(in.hasNext())
		{
			int W=in.nextInt();
			int B=in.nextInt();
			int H=in.nextInt();
			if((W|B|H)==0)
				return;
			double f1=Math.sqrt((W*W+B*B));
			double f2=Math.sqrt((B*B+H*H));
			double f3=Math.sqrt((H*H+W*W));
			int n=in.nextInt();
			for(int i=0;i<n;i++)
			{
				int r=2*in.nextInt();
				if(r>f1||r>f2||r>f3)
					System.out.println("OK");
				else
					System.out.println("NA");
			}
		}
	}
}

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

#define all(x) (x).begin(),(x).end()
#define init() \
  ios::sync_with_stdio(false); \
  cin.tie(0)

using namespace std;

using ll = long long;
using ull = unsigned long long;

template<typename M, typename N>
constexpr common_type_t<M, N> gcd(M a, N b) {
  return a == 0 ? b
    : b == 0 ? a
    : gcd(b, a % b);
}

template <typename M, typename N>
constexpr common_type_t<M, N> lcm(M a, N b) {
  return a * b / gcd(a, b);
}

int main() {
  init();

  int x,y,z,p;
  cin >> x;
  cin >> y;
  cin >> z;
  cin >> p;

  int res = 0;
  for(int i=0;i<=x;i++){
    for(int j=0;j<=y;j++){
      for(int k=0;k<=z;k++){
        if (i * 500 + j * 100 + 50 * k == p) {
          res++;
        }
      }
    }
  }

  cout << res << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main() {
	int n, count;
	while(1) {
		scanf("%d", &n);
		if(n == 0) break;
		for(count = 0; n != 1; ++ count) {
			if(n % 2 == 0) n /= 2;
			else n = 3 * n + 1;
		}
		printf("%d\n", count);
	}
	return 0;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    string s, t;
    cin >> s;
    cin >> t;
    int n_s = s.size();
    int n_t = t.size();

    map<char, set<int>> mp;
    for (int i = 0; i < n_s; i++) {
        mp[s[i]].insert(i);
    }

    ll now = -1;
    ll cycle = 0;
    for (int i = 0; i < n_t; i++) {
        if (!mp.count(t[i])) {
            cout << -1 << endl;
            return 0;
        }
        auto it = mp[t[i]].upper_bound(now);
        if (it == mp[t[i]].end()) {
            now = *mp[t[i]].begin();
            cycle++;
            continue;
        } else {
            now = *it;
        }
    }

    cout << n_s * cycle + now + 1 << endl;
    return 0;
}

Measured memory_bytes: 8540
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

ll cnt[10000001];

int main() {
    ll N;
    cin >> N;
    ll ans = 0;
    FOR(i, 1, N + 1) {
        ll Y = N / i;
        ans += (Y + 1) * Y / 2 * i;
    }
    cout << ans << endl;
    return 0;
}

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

public class hello
{
    public static void Main()
    {
        while (true)
        {
            var players = new Queue<int>();
            string[] line = Console.ReadLine().Trim().Split(' ');
            var m = int.Parse(line[0]);
            var n = int.Parse(line[1]);
            if (m == 0 && n == 0) break;
            foreach (var x in Enumerable.Range(1, m))
                players.Enqueue(x);
            for (int i = 1; i < n + 1; i++)
            {
                var s = Console.ReadLine().Trim();
                if (players.Count != 1)
                {
                    var pp = players.Dequeue();
                    if (s == FizzBuzzGet(i)) players.Enqueue(pp);
                }
            }
            var displist = new List<int>();
            while (players.Count() > 0)
            {
                displist.Add(players.Dequeue());
            }
            displist.Sort();
            for (int i = 0; i < displist.Count(); i++)
            {
                Console.Write(displist[i]);
                if (i == displist.Count() - 1) Console.WriteLine();
                else Console.Write(" ");
            }
        }
    }
    public static string FizzBuzzGet(int n)
    {
        if (n % 15 == 0)
        {
            return "FizzBuzz";
        }
        else if (n % 5 == 0)
        {
            return "Buzz";
        }
        else if (n % 3 == 0)
        {
            return "Fizz";
        }
        else
        {
            return n.ToString();
        }
    }
}

Measured memory_bytes: 10756
#include <iostream>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
 
using namespace std;
 
int main(){
	
	int n,sum=0,ans=0;
	cin>>n;
	char s[n],t[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>s[i];
	}
	for (int i = 0; i < n; ++i)
	{
		cin>>t[i];
	}

	for (int i = 1; i <= n; ++i)
	{
		sum=0;
		char s1[i];
		
		for (int j = 0; j <i ; ++j)
		{
			s1[j]= s[n+j-i];
			
		}

		


		char t1[i];
		for (int j = 0; j <i ; ++j)
		{
			t1[j]= t[j];
		}

		for (int j = 0; j < i; ++j)
		{
			if (s1[j]==t1[j])
			{
				sum=sum+1;
			}

		}
		if (sum==i)
		{
			ans=i;
		}

	}

	cout<<2*n-ans<<endl;


return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<map>
#include<utility>
using namespace std;
#define TxT for(int i = 0; i < 3; i++)for(int j = 0; j < 3; j++)

typedef struct tep{
	int e[3][3];
	int c;
	bool operator  < (const tep& r) const{
		TxT if(e[i][j] > r.e[i][j]) return true;
		return false;
	}
	// bool operator  == (const tep& r) const{
		// TxT if(e[i][j] != r.e[i][j]) return false;
		// return true;
	// }
} EP;

map<int,bool> z;
EP e;
int dxy[] = {1,-1,0,0};

int hogefuga(EP hoge){
	int ten = 1, re = 0;
	TxT re += ten*hoge.e[i][j],ten*=10;
	return re;
}

int fugafuga(EP hoge){
	int count = 1, count2 = 0;
	TxT{ if(hoge.e[i][j] != (count++)%9) count2++;}
	return count2;
}

void print(EP hoge){	
	cout<<hoge.c<<" +++++ "<<endl;;
	cout<<hogefuga(hoge)<<endl;
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < 3; j++) cout<<hoge.e[i][j]<<" ";
		cout<<endl;
	}
	cout<<endl;
	string hogehogehoge;
	cin>>hogehogehoge;
}

bool hogehoge(EP hoge){
	int count = 1;
	TxT{ if(hoge.e[i][j] != (count++)%9) return false;}
	return true;
}

void fuga(queue<EP> &Q, EP hoge){
	int x, y, mi = 10, t, ti;
	
	TxT if(hoge.e[i][j] == 0)y = i, x = j;
	
	for(int i = 0; i < 4; i++){
		int ny = y + dxy[i], nx = x + dxy[3-i];
		if(ny < 0 || ny >= 3 || nx < 0 || nx >= 3) continue;
		EP fuga = hoge;
		swap(fuga.e[y][x],fuga.e[ny][nx]);
		
		if(z[hogefuga(fuga)]) continue;
		else z[hogefuga(fuga)] = true;
		fuga.c = hoge.c+1;
		Q.push(fuga);
		
		// if((t = fugafuga(fuga)) < mi){
			// mi = t, ti = i;
		// }
		
		
		// fuga.c = hoge.c+1;
		// Q.push(fuga);
	}
	// if(mi != 10){
		// int ny = y + dxy[ti], nx = x + dxy[3-ti];
		// EP fuga = hoge;
		// swap(fuga.e[y][x],fuga.e[ny][nx]);
		// fuga.c = hoge.c+1;
		// Q.push(fuga);
		// z[hogefuga(fuga)] = true;
	// }
}

int solve(){
	queue<EP> Q;
	
	e.c = 0;
	
	Q.push(e);
	
	while(!Q.empty()){
		EP hoge = Q.front(); Q.pop();//print(hoge);
		fuga(Q,hoge);
		if(hogehoge(hoge)) return hoge.c;
	}
}

int main(){
	
	TxT cin>>e.e[i][j];
	
	//z[hogefuga(e)] = true;
	
	cout<<solve()<<endl;
	
	return 0;
}


Measured memory_bytes: 12048
#include<bits/stdc++.h>
using namespace std;                                                            
#define pb push_back                                                            
#define mp make_pair                                                                                                                                
#define sqr(a) ((a) * (a))                                                      
#define io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);   
#define co() cout.precision(10);                                                
#define F for(li i=0;i<n;i++)
#define fo(i,a,n) for(i=a;i<n;i++)
#define ne cout<<"\n"; 
#define test int t;cin>>t;while(t--)
//#define oj #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif

typedef long long li;
typedef long double ld;

const li mod = 1000000007;

int main() 
{
    io();
    li h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    li x=k/60;
    li y=k%60;
    if(h1<=h2)
    {
        li a=(h1*60)+m1;
        li b=(h2*60)+m2;
        //cout<<a<<" "<<b<<" ";
        li ans=(b-a)-k;
        cout<<ans;
    }
    else
    {
        li a=(h1*60)+m1;
        li b=(h2*60)+m2;
        li ans=((24*60)-(b-a))-k;
        cout<<ans;
    }
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
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; }

int main(void){
  int n; cin >> n;
  double a[n],b[n];
  rep(i,n) cin >> a[i] >> b[i];
  sort(a,a+n);
  sort(b,b+n);
  double am,bm;
  if(n %2 == 1){
    am = a[n/2];
    bm = b[n/2];
    cout << ll(bm - am) + 1 << endl;
  }
  else{
    am = (a[n/2]+a[n/2-1])/2;
    bm = (b[n/2]+b[n/2-1])/2;
    cout << fixed << setprecision(12);
    cout << ll((bm - am)*2) + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 6840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
const ll INF=1e14;

int main(){
  int N;cin>>N;
  vll A;
  for (int i=0;i<N;++i){
    ll a;cin>>a;A.push_back(a);
  }
  vll cum(N+1);cum[0]=0;
  for (int i=0;i<N;++i){
    cum[i+1]=cum[i]+A[i];
  }

  ll ans=INF;

  for (int mid=2;mid<N-1;++mid){
    int n=lower_bound(cum.begin(), cum.end(), cum[mid]/2)-cum.begin();
    int m=lower_bound(cum.begin(), cum.end(), (cum[N]+cum[mid])/2)-cum.begin();
    ll P=cum[n], Q=cum[mid]-cum[n], R=cum[m]-cum[mid], S=cum[N]-cum[m];
    if(P-Q>cum[mid]-2*cum[n-1]){P=cum[n-1]; Q=cum[mid]-cum[n-1];}
    if(R-S>cum[N]-2*cum[m-1]+cum[mid]){R=cum[m-1]-cum[mid]; S=cum[N]-cum[m-1];}
    ll ma=max(max(P, Q), max(R,S)), mi=min(min(P,Q), min(R, S));
    if(n>0){
      ll P_=cum[n-1], Q_=cum[mid]-cum[n-1];
    }
    ans=min(ma-mi, ans);
  }

  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3824
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			while(sc.hasNext()) {
				int N=sc.nextInt();
				if(N==0) break;
				int[] dx= {-1, 0, 1, 0};
				int[] dy= {0, -1, 0, 1};
				int[] x=new int[N];
				int[] y=new int[N];
				x[0]=0;
				y[0]=0;
				int xmin=0, xmax=0, ymin=0, ymax=0;
				for(int i=1; i<N; i++) {
					int n=sc.nextInt();
					int d=sc.nextInt();
					x[i]=x[n]+dx[d];
					y[i]=y[n]+dy[d];
					xmin=Math.min(x[i], xmin);
					xmax=Math.max(x[i], xmax);
					ymin=Math.min(y[i], ymin);
					ymax=Math.max(y[i], ymax);
					
				}
				System.out.printf("%d %d\n", xmax-xmin+1, ymax-ymin+1);
				
				
			}


		}
	}
}


Measured memory_bytes: 43524
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

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

    vector<int64_t> Ans(100000,0);
    rep(x,1,101){
        rep(y,1,101){
            rep(z,1,101){
                int64_t v=x*x+y*y+z*z+x*y+y*z+z*x;
                if(v<Ans.size()) Ans.at(v)++;
            }
        }
    }
    rep(i,1,N+1) cout<<Ans.at(i)<<endl;
}

Measured memory_bytes: 3992
#include <stdio.h>
#include <string.h>
char str[1005];
char nstr[1005];
char cmd[10];

int main() {
#ifdef TEST
    freopen("input", "r", stdin);
#endif

    scanf("%s", &str);
    int n;
    scanf("%d", &n);
    int l, r;
    for (int i = 0; i < n; ++i) {
        scanf("%s %d %d", cmd, &l, &r);
        if(cmd[2] == 'p') {
            scanf("%s", nstr);
            int pos = 0;
            for (int j = l; j <= r; ++j) {
                str[j] = nstr[pos++];
            }
        } else if (cmd[2] == 'v') {
            int mid = (l + r) / 2;
            for (int j = l; j <= mid; ++j) {
                char tmp = str[j];
                str[j] = str[r - (j - l)];
                str[r - (j - l)] = tmp;
            }
        } else {
            for (int j = l; j <= r; ++j) {
                printf("%c", str[j]);
            }
            printf("\n");
        }
    }
    return 0;
}



Measured memory_bytes: 2132
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const long long MOD = 1000000007;


const int MAX = int(1e6)*2+5;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

template< typename T >
T mod_pow(T x, T n, const T &p) {
  T ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}


void solve(long long K, std::string S){
    ll N = S.size();
    ll ans =mod_pow(26ll,K+N,MOD);
    
    COMinit();
    for(ll i=0;i<N;i++){
        ll minus =COM(K+N,i)*mod_pow(25ll,K+N-i,MOD);
        minus %= MOD;
        ans = ans + MOD -minus;
        ans %=MOD;
    }
    cout << ans << endl;

}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long K;
    scanf("%lld",&K);
    std::string S;
    std::cin >> S;
    solve(K, S);
    return 0;
}


Measured memory_bytes: 52352
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
#include<set>
#include<map>
using namespace std;
using ll = long long;
static const double pi = 3.141592653589793;
int main(){
  double a,b,h,m;
  cin >> a >> b >> h >> m;
  double arg_a, arg_b;
  arg_a = 30*(h+m/60);
  arg_b = 6 * m;
  double arg = abs(arg_a - arg_b) * pi / 180;
  double ans = sqrt(a*a + b*b - 2*a*b*cosl(arg));
  printf("%.15lf", ans);
}

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

using namespace std;

template <class T> inline bool chmin(T &a, T b) { /* {{{ */
  if (a > b) {
    a = b;
    return true;
  }
  return false;
} /* }}} */

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  for (auto &h : H) cin >> h;
  sort(H.begin(), H.end());
  int ans = 1e9 + 5;
  for (int i = 0; i <= N - K; i++) {
    chmin(ans, H[i + K - 1] - H[i]);
  }
  cout << ans << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 640
n=int(input())
s=input()*2
for a in[['S','S'],['S','W'],['W','S'],['W','W']]:
    for i in range(1,n+1):
        f=a[i]+s[i]
        if f=='So'or'Wx'==f:
            a+=[a[i-1]]
        else:
            a+=[a[i-1].translate({83:87,87:83})]
    if a[:2]==a[n:]:
        print(''.join(a[:n]))
        break
else:
    print(-1)

Measured memory_bytes: 60892
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  if(1 == N) {
    cout << "Hello World" << endl;
    return 0;
  }
  if(2 == N) {
    int A, B;
    cin >> A >> B;
    cout << (A + B) << endl;
    return 0;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";

int N, A;
vector<int> x(51);
vector<vector<ll>> dp(51, vector<ll>(50*50*2+1, 0));

int main() {

    cin >> N >> A;
    for (int i = 1; i <= N; i++) {
        int temp;
        cin >> temp;
        x[i] = temp - A;
    }

    dp[0][A*N] = 1;
    for (int i = 1; i < N+1; i++) {
        for (int s = 0; s <= 2*A*N; s++) {
            if (s - x[i] >= 0 && s - x[i]<= 2*A*N) {
                dp[i][s] = dp[i - 1][s] + dp[i - 1][s - x[i]];
            } else {
                dp[i][s] = dp[i - 1][s];
            }
        }
    }


    cout << (dp[N][A*N] - 1) << "\n";

    return 0;
}

Measured memory_bytes: 2304
import java.awt.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        Point[] red = new Point[n];
        Point[] blue = new Point[n];

        for (int i = 0; i < n; i++) {
            red[i] = new Point(sc.nextInt(), sc.nextInt());
        }
        for (int i = 0; i < n; i++) {
            blue[i] = new Point(sc.nextInt(), sc.nextInt());
        }
        Arrays.sort(blue, Comparator.comparingInt(p -> p.x));
        Arrays.sort(red, Comparator.comparingInt(p -> p.x));
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int index = - 1;
            Point kouho = null;
            for (int j = 0; j < n; j++) {
                if (red[j] == null) {
                    continue;
                }
                if (red[j].x >= blue[i].x) {
                    break;
                }
                if (red[j].x < blue[i].x && red[j].y < blue[i].y) {
                    if (kouho == null || kouho.y < red[j].y) {
                        kouho = red[j];
                        index = j;
                    }
                }
            }
            if (kouho == null) {
                continue;
            }
            red[index] = null;
            ans++;
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 27988
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  vector<pint> a;
  int ans = 0;
  REP(i,5) {
    int c; cin>>c;
    if(c % 10 == 0) ans	+= c;
    else a.push_back(make_pair(c % 10, c));
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  int size = a.size();
  if(size > 0) {
    REP(i,size-1) {
      ans += a[i].second;
      if(ans % 10	> 0) ans = ans / 10 * 10 + 10;
    }
    ans += a[size-1].second;
  }
  cout << ans << endl;

  return 0;
}


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

// input
int n;
int W;
int weight[110], value[110];

// dp table
int dp[110][10010];

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

	for (int i = 0; i < n; i++) {
		cin >> value[i] >> weight[i];
	}

	for (int w = 0; w <= W; w++) dp[0][w] = 0;

	for (int i = 0; i < n; i++) {
		for (int w = 0; w <= W; w++) {
			if (w >= weight[i]) dp[i+1][w] = max(dp[i][w-weight[i]] + value[i], dp[i][w]);
			else dp[i+1][w] = dp[i][w];
		}
	}

	cout << dp[n][W] << endl;
}



Measured memory_bytes: 7060
/*Stay true to yourself, yet always be open to learn. Work hard, and never give up on your dreams, 
even when nobody else believes they can come true but you. These are not cliches but real tools you 
need no matter what you do in life to stay focused on your path.
*/

 /*Pppppppp    UU      UU     CCCCCCCC    CCCCCCCC     HH     HH     UU      UU
   pp    pp    UU      UU     CC          CC           HH     HH     UU      UU
   pp    pp    UU      UU     CC          CC           HHHHHHHHH     UU      UU
   pppppppp    UU      UU     CC          CC           HHHHHHHHH     UU      UU
   pp          UU      UU     CC          CC           HH     HH     UU      UU
   pp          UUUUUUUUUU     CCCCCCCC    CCCCCCCC     HH     HH     UUUUUUUUUU
   */

#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n ;
    cin >> n;
    int a[n];
    int max =0,maxi=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(max<a[i])
        {
         max = a[i];
         maxi=i;
        }
    }
    sort(a,a+n);
    for(int i=0;i<n;i++)
    {
        if(i!=maxi)
        cout<<max<<endl;
        else
        cout<<a[n-2]<<endl;
    }
    return 0;
}

Measured memory_bytes: 2432
N =int( input())
S = input()

## empty list ##
out = []

for i in S:
  ## make code num ##
  num = ord(i)
  num = num + N
  if num > 90:
    num = num - 26
  ## make list ##
  out.append(chr(num))

## output ##
out = "".join(out)
print(out)
  

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;
 
int main(){
    int N;
    cin >> N;

    vector<ll> C;
    for(int i=0;i<N;i++){
        int c;
        cin >> c;
        c--;
        if(C.empty() || C.back() != c){
            C.push_back(c);
        }
    }

    N = C.size();

    ll prev = 1;
    vector<ll> c_sum(200000, 0);
    for(int i=N-1;i>=0;i--){
        prev = (prev + c_sum[C[i]]) % MOD;
        c_sum[C[i]] = prev;
    }
    cout << prev << endl;

    return 0;
}


Measured memory_bytes: 3440
#include<iostream> 
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<sstream>
using namespace std;

#define sf scanf
#define pf printf
#define pfn printf("\n");
#define pfk printf(" ");
#define pf0 printf("0");
#define pf1 printf("1");
#define ll long long
#define ull unsigned long long
#define sfd(n) scanf("%d",&n);
#define sfdd(n,m) scanf("%d%d",&n,&m);
#define sfld(n) scanf("%lld",&n);
#define sfldd(n,m) scanf("%lld%lld",&n,&m);
#define sflf(n) scanf("%lf",&n);
#define sflff(n,m) scanf("%lf%lf",&n,&m);
#define sfc(n) scanf("%c",n);
#define sfcc(n,m) scanf("%c%c",n,m);
#define sfs(n) scanf("%s",n);
#define sfss(n,m) scanf("%s%s",n,m);
#define pfd(n) printf("%d",n);
#define pfld(n) printf("%lld",n);
#define pflf(n) printf("%lf",n);
#define pfc(n) printf("%c",n);
#define pfs(n) printf("%s",n);

#define csh(a,n) memset(a,n,sizeof(a));
int main(){
	int arr[4];
	cin>>arr[0]>>arr[1]>>arr[2];
	sort(arr,arr+3);
	if(arr[0]==arr[1]&&arr[1]!=arr[2]){
		cout<<"Yes"<<endl;	
	} 
	else if(arr[1]==arr[2]&&arr[1]!=arr[0]){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string A,B;
  cin>>A>>B;
  bool C=false;
  for(int i=0;i<A.size();i++){
    if(A.at(i)!=B.at(i)){
      C=true;
      cout<<"No"<<endl;
      break;
    }
  }
  if(C==false){
    cout<<"Yes"<<endl;
  }
}

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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define w(x)  int x; cin>>x; while(x--)
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"
#define watch4(x,y,z,q) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<" and "<<(#q)<<" is "<<(q)<<"\n"
#define MOD 1000000007
#define INF 1000000007;
#define F first
#define S second
#define pb(x) push_back(x);


#define ll  long long
#define all(c) (c).begin(),(c).end()
#define endl "\n"

typedef vector<int> vl;
typedef vector< vl > vvl;
typedef pair< int, int> pll;
typedef map< int, int> mll;


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif





void c_p_c()
{
#ifndef ONLINE_JUDGE
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
void parray(int a[],int n){
    for(int i=0;i<n;i++){
    cout<<a[i]<<" ";
    }
    cout<<endl;
}

int main() {
    int i,n,m,k,sum=0;
    c_p_c();
  	cin>>n;
  	cin>>k;
  	int a[n];
  	fo(i,n) cin>>a[i];
  	for (int i = 0; i < n; ++i)
  	{
  		/* code */
  		sum+=min(a[i],k-a[i])*2;
  	}
  	cout<<sum<<endl;




 	return 0;

   }

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    string s;
    cin >> s;
    bool flag = true;
    if(s[0] != 'A')flag = false;
    bool c = false;
    repi(i,1,s.length()){
        if(s[i] == 'C'){
            if((i >= 2)&&(i <= s.length() - 2)){
                if(c)flag = false;
                else c = true;
            }
            else flag = false;
        }
        else if(s[i] < 'a')flag = false;
    }
    if(!c)flag = false;
    fp(flag,"AC","WA");
    return 0;
}

Measured memory_bytes: 256