akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define fi first
#define se second
#define inf 1000000007

ll N;
ll a[3010];

int main() {
    cin >> N;
    rep(i,N) cin >> a[i];
    ll ans = 0;
    rep(i,N) ans += a[i]-1;
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;

void testcase() {
	int x;
	cin >> x;
	if (x >= 30)
	 cout << "Yes";
	else
		cout << "No";	
}

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	
    int tt = 1;
    // cin >> tt;
    while(tt--) {
        testcase();
    }
    return 0;
}

Measured memory_bytes: 3640
#include<stdio.h>
int main()
{
    int N,i,j;
	int sum=0;
	scanf("%d",&N);
    for(i=0;i<=25;i++)
	{
		for(j=0;j<=14;j++)
		{
            if(i*4+j*7==N)
			{
				sum=1;
			}
		}
	}
	if(sum==1)
	{
		printf("Yes\n");
	}
	if(sum==0)
	{
		printf("No\n");
	}
	return 0;
}

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

class RollingHash {
public:
    vector<long long> hs[2], pw[2];
    const long long base = 9973;
    const long long mod[2] = {1000000007LL, 999999937LL};
    int len = 0;
    RollingHash(const string &s) {
        len = s.size();
        for(int i = 0; i < 2; ++i) {
            hs[i].assign(len + 1, 0);
            pw[i].assign(len + 1, 1);
            for (int j = 0; j < len; ++j) {
                pw[i][j + 1] = pw[i][j] * base % mod[i];
                hs[i][j + 1] = (hs[i][j] * base + s[j]) % mod[i];
            }
        }
    }
    void connect(const string &s) {
        int n = s.size();
        for(int i = 0; i < 2; ++i) {
            hs[i].resize(len + n + 1);
            pw[i].resize(len + n + 1);
            for (int j = len; j < len + n; ++j) {
                pw[i][j + 1] = pw[i][j] * base % mod[i];
                hs[i][j + 1] = (hs[i][j] * base + s[j - len]) % mod[i];
            }
        }
        len += n;
    }
    pair<long long, long long> hash(const int l, const int r) {
        long long t1 = ((hs[0][r] - hs[0][l] * pw[0][r - l]) % mod[0] + mod[0]) % mod[0];
        long long t2 = ((hs[1][r] - hs[1][l] * pw[1][r - l]) % mod[1] + mod[1]) % mod[1];
        return make_pair(t1, t2);
    }
};

int main() {
    int N; cin >> N;
    string S; cin >> S;
    RollingHash rh(S);
    int l = 0, r = N / 2 +1;
    while(r - l > 1) {
        int mid = (l + r) / 2;
        map<pair<long long, long long>, int> ma;
        bool ok = false;
        rep(i, 0, N - mid + 1) {
            auto h = rh.hash(i, i + mid);
            if(ma[h]) {
                if(i + 1 - ma[h] >= mid) ok = true;
            }
            else ma[h] = i + 1;
        }
        if(ok) l = mid;
        else r = mid;
    }
    cout << l << endl;
    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main(){
    cin>>N>>K;
    vec h(N);
    rep(i,N) cin>>h[i];
    sort(ALL(h));
    ll ans = 0;
    rep(i,N - K) ans += h[i];
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
# 上からm番目がx
# x以上のヒトがm人以上、x+1以上のヒトがm-1人以下
# x以上のヒトがm人以上となる最大のx
from bisect import bisect_left
from itertools import accumulate
import sys

input = sys.stdin.buffer.readline


n, m = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
ok = 0
ng = 3 * (10 ** 5)

B = [0] + A[::-1]
C = list(accumulate(B))

while ng - ok > 1:
    mid = (ok + ng) // 2
    cnt = 0
    for i in range(n):
        gendo = mid - A[i]
        position = bisect_left(A, gendo)
        if position == n:
            continue
        kosuu = n - position
        cnt += kosuu
    if cnt >= m:
        ok = mid
    else:
        ng = mid
ans = 0
cnt = m
for i in range(n):
    gendo = ok - A[i]
    position = bisect_left(A, gendo)
    if position == n:
        continue
    kosuu = n - position
    ans += C[kosuu] + kosuu * A[i]
    cnt -= kosuu
ans += cnt * ok
print(ans)


Measured memory_bytes: 54496
class dice:

    def __init__(self, numlist):
        self._men = {"T": numlist[0],
                     "B": numlist[5],
                     "N": numlist[4],
                     "S": numlist[1],
                     "W": numlist[3],
                     "E": numlist[2]}

    def roll(self, direction):
        t = dict(self._men)

        if direction == "N":
            self._men["T"] = t["S"]
            self._men["B"] = t["N"]
            self._men["N"] = t["T"]
            self._men["S"] = t["B"]
        elif direction == "S":
            self._men["T"] = t["N"]
            self._men["B"] = t["S"]
            self._men["S"] = t["T"]
            self._men["N"] = t["B"]
        elif direction == "W":
            self._men["T"] = t["E"]
            self._men["B"] = t["W"]
            self._men["W"] = t["T"]
            self._men["E"] = t["B"]
        elif direction == "E":
            self._men["T"] = t["W"]
            self._men["B"] = t["E"]
            self._men["W"] = t["B"]
            self._men["E"] = t["T"]


    def clock(self):
        t = dict(self._men)
        self._men["E"] = t["N"]
        self._men["N"] = t["W"]
        self._men["W"] = t["S"]
        self._men["S"] = t["E"]


    def simpleequal(self, d2):
        if self._men == d2._men:
            return True
        else:
            return False


    def equal(self, d2):
        for _ in range(4):
            d2.roll("N")

            for _ in range(4):
                d2.clock()
                if self.simpleequal(d2):
                    return True

        d2.roll("E")
        for _ in range(4):
            d2.clock()
            if self.simpleequal(d2):
                return True


        d2.roll("E")
        d2.roll("E")
        for _ in range(4):
            d2.clock()
            if self.simpleequal(d2):
                return True



    def gettop(self):
        return self._men["T"]

def decode():
    numlist1 = [int(x) for x in input().split()]
    numlist2 = [int(x) for x in input().split()]

    return numlist1, numlist2


if __name__ == '__main__':

    numlist1, numlist2 = decode()
    d1 = dice(numlist1)
    d2 = dice(numlist2)

    if d1.equal(d2):
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 5624
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
    int N, K; cin >> N >> K;
    vector<int> H(N);
    rep(i, N) {
        int h; cin >> h;
        H[i] = h;
    }
    sort(H.begin(), H.end(), greater<int>());
    long long ans = 0;
    if(K >= N) {
        ans = 0;
    } else {
        for (int k = K; k < N; ++k) {
            ans += H[k];
        }
    }
    cout << ans << endl;
    return 0;
}


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

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

    int n; cin>>n;
    int p=ceil((-1+sqrt(1+n*8))/2);
    for (int i = p; i; i--){
        if(i<=n){
            cout<<i<<'\n';
            n-=i;
        }
    }
}

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

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

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  // 端っこ: 1 それ以外: 2
  // 偶数: + 奇数 -
  int N; cin >> N;
  vector<ll> A(N);
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }

  vector<ll> cof(N,2);

  cof[0] = 1;
  cof[N-1] = 1;

  for(int i = 0; i < N; i++){
    if(i%2 == 1){
      cof[i] *= -1;
    }
  }
  sort(cof.begin(), cof.end());
  sort(A.begin(), A.end());

  ll max_val = 0;
  ll ans = 0;
  for(int i = 0; i < N; i++){
    ans += cof[i] * A[i];
  }
  max_val = ans;

  vector<ll> cof2(N,2);

  cof2[0] = 1;
  cof2[N-1] = 1;

  for(int i = 0; i < N; i++){
    if(i%2 == 0){
      cof2[i] *= -1;
    }
  }
  sort(cof2.begin(), cof2.end());
  ans = 0;
  for(int i = 0; i < N; i++){
    ans += cof2[i] * A[i];
  }

  max_val = max(max_val, ans);

  cout << max_val << endl;

}


Measured memory_bytes: 5616
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    String t = sc.next();
    int ans = n;

    for (int i = 0; i < n; i++) {
      if (s.substring(i, n).equals(t.substring(0, n - i))) {
        break;
      } else {
        ans++;
      }
    }

    System.out.println(ans);

  }
}

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

typedef long long ll;

int main()
{
	int n;
	std::cin >> n;
	std::vector<int> a(n + 1);
	std::vector<int> b(n);
	for (int i = 0; i <= n; ++i)
	{
		std::cin >> a[i];
	}
	for (int i = 0; i < n; ++i)
	{
		std::cin >> b[i];
	}
	ll count = 0;
	for (int i = 0; i < n; ++i)
	{
		int temp = std::min(a[i], b[i]);
		a[i] -= temp;
		b[i] -= temp;
		count += temp;
		temp = std::min(a[i + 1], b[i]);
		a[i + 1] -= temp;
		b[i] -= temp;
		count += temp;
	}
	std::cout << count << '\n';
	return 0;
}

Measured memory_bytes: 4044
N, C = map(int, input().split())

channels = [[] for _ in range(C)]
maxT = 0

for _ in range(N) :
    s, t, c = map(int, input().split())
    maxT = max(maxT, t)
    channels[c - 1].append((s, t))

maxT = maxT * 2 + 10
tvSum = [0 for _ in range(maxT)]

for tv in channels :
    imos = [0 for _ in range(maxT)]
    for (s, t) in tv :
        imos[s * 2 - 1] += 1
        imos[t * 2] -= 1
    for i in range(1, maxT) :
        imos[i] += imos[i - 1]
    for i in range(maxT) :
        if imos[i] > 0 :
            tvSum[i] += 1

print(max(tvSum))


Measured memory_bytes: 117700
import itertools

n = int(input())
num_list = list(map(int, input().split()))

combi = list(itertools.combinations(num_list, 3))

new_list = []
for a in combi:
  if not((a[0] == a[1] or a[1] == a[2] or a[0] == a[2]) or sum(a)-max(a) <= max(a)):
    new_list.append(a)
print(len(new_list))



Measured memory_bytes: 21612
#include <iostream>

#include <algorithm>
#include <queue>
#include <string>
#include <tuple>

#include <cstring>

using std::cin;
using std::cout;
using std::endl;

using std::get;
using std::make_tuple;
using std::max;
using std::queue;
using std::string;
using std::tuple;

using std::memcpy;

using i3 = tuple<int, int, int>;

static int const dydx[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
static int H, W;
static char mat[1000][1000];

static int
solve()
{
  queue<i3> q;
  for (int y = 0; y < H; y++)
  {
    for (int x = 0; x < W; x++)
    {
      if (mat[y][x] == '#')
      {
        q.push(make_tuple(y, x, 0));
      }
    }
  }
  int ret = 0;
  while (!q.empty())
  {
    int y = get<0>(q.front());
    int x = get<1>(q.front());
    int d = get<2>(q.front());
    q.pop();
    for (int i = 0; i < 4; i++)
    {
      int yy = y + dydx[i][0];
      int xx = x + dydx[i][1];
      if (0 <= yy && yy < H && 0 <= xx && xx < W && mat[yy][xx] == '.')
      {
        mat[yy][xx] = '#';
        q.push(make_tuple(yy, xx, d + 1));
        ret = max(ret, d + 1);
      }
    }
  }
  return ret;
}

int
main()
{
  cin >> H >> W;
  string s;
  for (int y = 0; y < H; y++)
  {
    cin >> s;
    memcpy(mat[y], s.data(), W);
  }
  cout << solve() << endl;
  return 0;
}


Measured memory_bytes: 13328
import java.util.*;
  
class Main{
   public static void main(String[] args){
   	
	int[] len = new int[3];
   	 Scanner input = new Scanner(System.in);
   	
   	for(int i=0; i<len.length;i++){	
    len[i] = input.nextInt();
   	}
   	
   	Arrays.sort(len);
   	System.out.println(len[0]+" "+len[1]+" "+len[2]);
   }
}

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

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
const int INF = 1e9;

using namespace std;
int calc[45];

int fib(int n){
    if(calc[n] != 0)
        return calc[n];
    for(int i = 2; i <= n; i++)
        calc[i] = calc[i-2] + calc[i-1];
    return calc[n];
}

int main() {
    int n;
    cin >> n;
    REP(i, 45) calc[i] = 0;
    calc[0] = 1;
    calc[1] = 1;
    cout << fib(n) << endl;
    return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>

void swap(int *x, int *y)
{
    int tmp;

    tmp = *x;
    *x = *y;
    *y = tmp;
}

int main(void)
{
    int x;
    int y;

    while ( 1 ) {
        scanf("%d %d", &x, &y);
        if ( (x == 0) && (y == 0) ) {
            break;
        }
        if ( x > y ) {
            swap(&x, &y);
        }
        printf("%d %d\n", x, y);
    }

    return 0;
}


Measured memory_bytes: 2060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  int A, B, K; cin >> A >> B >> K;
  set<int> st;
  
  repi(i,A,min(A+K-1,B)) {
    printf("%d\n", i);
  }
  repi(i,max(B-K+1,A+K),B) {
    printf("%d\n", i);
  }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;


namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            int N = int.Parse(ReadLine());
            Dictionary<int, string> dic = new Dictionary<int, string>();
            Dictionary<int, int> ls = new Dictionary<int, int>();
            for (int i = 0; i < N; i++)
            {
                var s = ReadLine().Split(' ');
                int P = int.Parse(s[1]);
                string S = s[0];
                dic.Add(P, S);
                ls.Add(P,i);
            }
            var SortedDic = dic.OrderBy(x => x.Value).ThenByDescending(x => x.Key);


            foreach (var item in SortedDic)
            {
                WriteLine(ls[item.Key]+1);
            }
        }
    }
}


Measured memory_bytes: 13536
program main
  
  implicit none
  integer :: n
  integer, allocatable :: h(:), g(:)
  integer :: i,j,k,ans
  
  read(*,*) n
  allocate( h(n) )
  allocate( g(n-1) )
  read(*,*) h
  
  g = 0 
  do i = 1, n-1
    if( h(i) >= h(i+1) ) then
    else
      g(i) = 1
    end if
  end do

  j = 0
  ans = 0

  do i = 1, n-1
    if( g(i) == 0 ) then
      j = j + 1
    else
      if( j >= ans ) then
        ans = j
      end if
      j = 0
    end if
  end do
  if( j >= ans ) then
    ans = j
  end if

  print*, ans

  !ans = 0 
  !do i = 1, n-1
  !  k = 0
  !  do j = i, n-1
  !    if( h(j) >= h(j+1) ) then
  !      k = k + 1
  !    else
  !      exit
  !    end if
  !  end do
  !  if( k > ans ) then
  !    ans = k
  !  end if
  !end do
  !print*, ans
end program main


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

map<string, int> myMap;

int getAppearedNum(string str) {
  map<string, int>::iterator itr = myMap.find(str);
  if(itr == myMap.end()) {
    myMap[str] = 0;
  }
  else {
    myMap[str] += 1;
  }
  return myMap[str];
}

int main(void) {
  string target;
  string maxLengthWord;
  int maxLength = 0;
  int nowWordLength;

  int mode = 0;
  string modeWord;
  int nowAppearedNum;

  while(cin >> target) {
    nowWordLength = target.length();
    if(maxLength < nowWordLength) {
      maxLength = nowWordLength;
      maxLengthWord = target;
    }
    
    nowAppearedNum = getAppearedNum(target);
    if(nowAppearedNum > mode) {
      mode = nowAppearedNum;
      modeWord = target;
    }
  }

  cout << modeWord << " " << maxLengthWord << endl;


  return 0;
}

Measured memory_bytes: 1196
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

//=====I/O=====

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//=====main=====

func main() {
	sc.Split(bufio.ScanWords)

	n := int64(scanInt())

	if n%2 == 1 || n == 0 {
		fmt.Println(0)
	} else {
		ans := int64(0)
		b := int64(10)
		for n/b > 0 {
			ans += n/b
			b*=5
		}
		fmt.Println(ans)
	}
}


Measured memory_bytes: 640
N=int(input())
def prime_factorization(n):
    r={}
    for i in range(2,int(n**.5)+1):
        num=0
        while(True):
            x,y=divmod(n,i)
            if y!=0:
                break
            n=x
            num+=1
        if num>0:
            r[i]=num
    if n>1:
        r[n]=1
    return r
D={}
for i in range(N):
    d=prime_factorization(i+1)
    for k in d.keys():
        if k in D:
            D[k]+=d[k]
        else:
            D[k]=d[k]
c=[0]*5
for v in D.values():
    if v>73:
        c[0]+=1
    if v>23:
        c[1]+=1
    if v>13:
        c[2]+=1
    if v>3:
        c[3]+=1
    if v>1:
        c[4]+=1
print(c[0]+c[1]*max(0,c[4]-1)+c[2]*max(0,c[3]-1)+c[3]*max(0,c[3]-1)*max(0,c[4]-2)//2)

Measured memory_bytes: 3188
#include<iostream>
using namespace std;
struct State{int x[12][12];};
int H,W,n,b[20],p[20];State S,ans;
int area(State V,int q){
	int mx=100000,my=100000,nx=-1,ny=-1;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(V.x[i][j]!=q)continue;
			mx=min(mx,i);my=min(my,j);nx=max(nx,i);ny=max(ny,j);
		}
	}
	for(int i=mx;i<=nx;i++){
		for(int j=my;j<=ny;j++){
			if(V.x[i][j]!=q && V.x[i][j]!=0)return 99999999;
		}
	}
	return (nx-mx+1)*(ny-my+1);
}
int solve(State T,int r1,int r2){
	if(r2==W){r1++;r2=0;}
	if(r1==H){
		for(int i=1;i<=n;i++){
			if(area(T,i)!=p[i])return 0;
		}
		ans=T;return 1;
	}
	if(T.x[r1][r2]>=1){return solve(T,r1,r2+1);}
	else{
		int ret=0;
		for(int i=1;i<=n;i++){
			State U=T;U.x[r1][r2]=i;
			if(area(U,i)>p[i])continue;
			ret+=solve(U,r1,r2+1);
		}
		return ret;
	}
}
int main(){
	while(true){
		cin>>W>>H>>n;if(n==0)break;
		for(int i=0;i<n;i++){cin>>b[i];cin>>p[b[i]];}
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++)cin>>S.x[i][j];
		}
		int ret=solve(S,0,0);
		if(ret==1){
			for(int i=0;i<H;i++){
				for(int j=0;j<W;j++){
					if(j)cout<<' ';cout<<ans.x[i][j];
				}
				cout<<endl;
			}
		}
		else cout<<"NA"<<endl;
	}
	return 0;
}

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

using namespace std;

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

	long long n, m;
	cin >> n >> m;
	cout << (n * (n-1))/2  + (m * (m-1))/2 << '\n';

	return 0;
}

Measured memory_bytes: 256
n,k = map(int, input().split())
a = [0] + list(map(int, input().split()))

before=k
roop=1
cnt={}
nxt=1
mp = [1]
for i in range(1, k+1):
    if nxt not in cnt:
        cnt[nxt] = i
        nxt = a[nxt]
    else:
        roop = i - cnt[nxt]
        before = cnt[nxt]-1
        break
    mp.append(nxt)
print(mp[before + (k-before)%roop])

Measured memory_bytes: 32360
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <complex>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

int main() {
  int n, k;
  while (cin >> n >> k) {
    int ans = 0;
    for (int i = 0; i < n; i++) {
      int a;
      cin >> a;
      if (a >= k) {
        ans++;
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <array>
#include <stack>
#include <queue>
#include <chrono>
#include <numeric>

#pragma warning(disable:4996)
#define REP(i,n) for(int i = 0 ; i < n ; ++i)
typedef long long Int;

using namespace std;

int balls[10];
int ar[10];

bool solve()
{
	int a(0);
	int b(0);

	REP(i, 10){
		if (ar[i]){
			if (a > balls[i])
				return false;
			a = balls[i];
		}
		else{
			if (b > balls[i])
				return false;
			b = balls[i];
		}
	}
	return true;
}

int main()
{
	cin.tie(0); ios::sync_with_stdio(false);
	//fstream fs("input.txt");
	////////////ここから開始///////////
	int n(0);
	cin >> n;
	while (n--){
		bool f = false;
		REP(i, 10){
			cin >> balls[i];
			ar[i] = 0;
		}
		for (int i = 0; i < 1 << 10; ++i){
			REP(j, 10)
				ar[9 - j] = i >> j & 1;

			f |= solve();
		}
		string ans = f ? "YES" : "NO";
		cout << ans << endl;
	}
	
	return 0;
}

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

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;

#define MAX_N 1000000

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	while (1) {
		ll h, w; cin >> h >> w;
		if (h == 0 && w == 0) break;
		rep(i, h) {
			rep(j, w) {
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
}


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

int main(){
  int M,N;
  int sum = 0;
  int count = 0;
  
  cin >> N >> M;
  vector<int> vec(N);

  for(int i=0;i<N;++i){
    cin >> vec.at(i);
    sum += vec.at(i);
  }

  for(int i=0;i<N;++i){
    if(vec.at(i) >= double(1.0 *sum / (4 * M))){
      count += 1;
    }
  }

  if(count >= M){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define ll long long 
# define skorost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 

using namespace std ;
 
ll z , o , ans ;

ll N = 1e9 + 7 ;

int main(){ skorost ;

	string s ;

	cin >> s ;

	if( s[s.size()-1] == '3' ){

		cout << "bon" << endl ;

		return 0 ;

	}

	if( s[s.size()-1] == '0' || s[s.size()-1] == '1' || s[s.size()-1] == '6' || s[s.size()-1] == '8' ){

		cout << "pon" << endl ;

		return 0 ;

	}

	if( s[s.size()-1] == '2' || s[s.size()-1] == '4' || s[s.size()-1] == '5' || s[s.size()-1] == '9' || s[s.size()-1] == '7'){

		cout << "hon" << endl ;

		return 0 ;

	}

}

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

using namespace std;
typedef long long ll;

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

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


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

int main(){
  int x,a,b;
  cin>>x>>a>>b;
  if(b-a>x)cout<<"dangerous"<<endl;
  else{
    if(a>=b)cout<<"delicious"<<endl;
    else cout<<"safe"<<endl;
  }
  return 0;
}
  



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define rep(i, o) for (ll i = 0; i < (o);i++)
#define rep_s(i, o) for (int i = 1; i <= (o);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
#define NUM 1e5

typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }


template<class T>
bool chmax(T &a, const T &b) { if (a < b) { return b; } return a; }

template<class T>
bool chmin(T &a, const T &b) { if (a > b) { a = b; return a; } return a; }

int main() {
    ull k; cin >> k;
    ll ans = 0; ull n = 0; 
    rep(i, k) {
        n = (i == 0) ? i*10 + 7 : n*10 + 7;
        n = n%k;
        if (n == 0) { ans = i+1; break; }
    }
    cout << ((ans == 0) ? -1 : ans) << endl;
    return 0;
}

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

#define int long long
#define fi first
#define se second
#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 rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

string s;

signed main() {
    cin >> s;
    rep(i,s.size()) {
        cout << s[i];
        if (i == 3) cout << " ";
    }
    cout << endl;
}












Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;

int main(){
  int A,B;
  cin>>A>>B;

  if(A<=5) cout<<0<<endl;
  else if(A<=12) cout<<B/2<<endl;
  else cout<<B<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
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++)
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};



int main(void) {
  int n;
  cin >> n;
  vpii a(n);
  rep(i,n) {
    int p;
    cin >> p;
    a[i] = make_pair(p,i);
  }
  sort(a.begin(),a.end());
  vi b(n);
  rep(i,n){
    b[i] = a[n-1].first;
    if(a[n-1].second == i) b[i] = a[n-2].first;
  }
  rep(i,n) cout << b[i] << endl;
    
  
    
}


Measured memory_bytes: 3968
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect

def s():
    return input()
def n():
    return int(input())
def d():
    return float(input())

def ls():
    return input().split()
def ln():
    return map(int, input().split())
def ld():
    return map(float, input().split())

def fs():
    return [input() for i in range(input())]
def fn():
    return [int(input()) for i in range(input())]
def fd():
    return [float(input()) for i in range(input())]

A,B = ln()
on = 0
for i in range(1,4):
    tmp = A*B*i
    if tmp % 2 == 1:
        on = 1
if on == 1:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 5708
def p(u):
 if u+1:print(s,u,end=s);p(T[u]);p(T[u+N])
def i(u):
 if u+1:i(T[u]);print(s,u,end=s);i(T[u+N])
def o(u):
 if u+1:o(T[u]);o(T[u+N]);print(s,u,end=s)
s=''
N=int(input())
T=[0,0]*N
for _ in[0]*N:
 a,b,c=map(int,input().split())
 T[a],T[a+N]=b,c
r=(set(range(N))-set(T)).pop()
print('Preorder')
p(r)
print('\nInorder')
i(r)
print('\nPostorder')
o(r)
print()


Measured memory_bytes: 5632
N = int(input())
abc = [[int(_) for _ in input().split()] for _ in range(N)]
dp = [[0]*(3) for _ in range(N)]
for i in range(3):
    dp[0][i] = abc[0][i]

for i in range(1, N):
    dp[i][0] = max(dp[i-1][1]+abc[i][0], dp[i-1][2]+abc[i][0])
    dp[i][1] = max(dp[i-1][0]+abc[i][1], dp[i-1][2]+abc[i][1])
    dp[i][2] = max(dp[i-1][0]+abc[i][2], dp[i-1][1]+abc[i][2])

print(max(dp[N-1][0], dp[N-1][1], dp[N-1][2]))

Measured memory_bytes: 74712
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int mx, n;
	while(cin >> mx, mx){
		cin >> n;
		vi d(n + 2), v(n + 2);
		bool ans = 1;
		rep(i, n) cin >> d[i + 1];
		function<void(int, vi&)> rec = [&](int c, vi &v){
			v[c] = 1;
			if(c == n + 1) return;
			for(int i = 1; i <= mx && c + i < n + 2; i++){
				int to = c + i + d[c + i];
				to = max(0, min(to, n + 1));
				if(!v[to]) rec(to, v);
			}
		};
		rec(0, v);
		
		rep(i, n + 1) if(v[i]){
			vi vv(n + 2);
			rec(i, vv);
			if(!vv[n + 1]){ ans = 0; break; }
		}
		cout << (ans ? "OK" : "NG") << endl;
	}
	return 0;
}


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

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    vector<int> c(m);
    for (int i=0; i<m; i++)
        scanf(" %d", &c[i]);
    vector<int> dp(n+1, INT_MAX);
    dp[0] = 0;
    for (int i=0; i<=n; i++)
        for (int j=0; j<m; j++)
            if (i - c[j] >= 0)
                dp[i] = min(dp[i-c[j]]+1, dp[i]);
    printf("%d\n", dp[n]);
    return 0;
}

Measured memory_bytes: 3260
class Queue:
    queue_list = []
    start = 0
    def enqueue(self, a):
        self.queue_list.append(a)
    def dequeue(self):
        assert self.start != len(self.queue_list), "オーバーフローが発生しました。"
        self.start += 1
        return self.queue_list[self.start - 1]
    def isEmpty(self):
        return self.start == len(self.queue_list)

n, q = list(map(lambda x: int(x), input().strip().split()))

queue = Queue()

for i in range(n):
    queue.enqueue(input().strip().split())


sum_time = 0
while not queue.isEmpty():
    name, time = queue.dequeue()
    if int(time) <= q:
        sum_time += int(time)
        print(name + ' ' + str(sum_time))
    else:
        queue.enqueue([name, str(int(time) - q)])
        sum_time += q


Measured memory_bytes: 36640
#include <stdio.h>
#include <string.h>

int main(){
  int Adj[101][101],n,v,i,j,u,k;
  memset(Adj, 0, 101*101*sizeof(int));
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      Adj[u][v]=1;
    }
  }
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      if(j!=1)printf(" ");
      printf("%d",Adj[i][j]);
    }
    printf("\n");
  }
  
  return 0;
}



Measured memory_bytes: 2740
#include <bits/stdc++.h>
using namespace std;
int dp[100001];
int mincost(int arr[], int n)
{
	if (n == 1)
		return 0;
	if (n < 1)
		return 10000000;

	if (dp[n] != -1)
		return dp[n];

	int a = abs(arr[n] - arr[n - 1]) + mincost(arr, n - 1);
	int b = abs(arr[n] - arr[n - 2]) + mincost(arr, n - 2);
	return dp[n] = min(a , b );
}

int mincostBU(int arr[], int n)
{
	int t[n + 1];

	t[1] = 0;
	t[2] = abs(arr[2] - arr[1]);
	for (int i = 3; i <= n; i++)
	{
		int a = t[i - 1] + abs(arr[i] - arr[i - 1]);
		int b = t[i - 2] + abs(arr[i] - arr[i - 2]);

		t[i] = min(a, b);
	}
	return t[n];
}

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

	int arr[n + 1];

	for (int i = 1; i < n + 1; i++)
		cin >> arr[i];
	memset(dp, -1, sizeof(dp));
	cout << mincostBU(arr, n);
}

Measured memory_bytes: 1408
s=input()
if s=='SUN':
    print('7')
elif s=='MON':
    print('6')
elif s=='TUE':
    print('5')
elif s=='WED':
    print('4')
elif s=='THU':
    print('3')
elif s=='FRI':
    print('2')
else:
    print('1')

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int,pii> tii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

const int nmax=300010;
set<pii> LIS[nmax];
vector<tii> ary;

void ins(int pos,pii p){
	auto it=LIS[pos].lower_bound(p);
	auto it2=it;it2--;
	if(it2->second<=p.second) return;
	while(p.second<=it->second) LIS[pos].erase(it++);
	LIS[pos].insert(p);
}

bool mini(int pos,pii p){
	auto it=LIS[pos].lower_bound(p);
	while(it->second<p.second){
		if(it->first<p.first) return true;
		it--;
	}
	return false;
}


inline int rng(int &a,int &b){
	const int C = ~(1<<31), M = (1<<16)-1;
	a=36969*(a & M)+(a >> 16);
	b=18000*(b & M)+(b >> 16);
	return (C&((a<<16)+b))%1000000;
}

int main(void){
	int n,m,A,B;
	while(cin >> n >> m >> A >> B){
		if(n==0&&m==0) break;
		rep(i,nmax){
			LIS[i].clear();
			LIS[i].insert(mp(inf,-1));
			LIS[i].insert(mp(-1,inf));
		}
		ary.clear();
		rep(i,n){
			int x,y,z;
			cin >> x >> y >> z;
			ary.pb(mp(-z,mp(y,x)));
		}
		rep(i,m){
			int x=rng(A,B),y=rng(A,B),z=rng(A,B);
			ary.pb(mp(-z,mp(y,x)));
		}
		sort(ary.rbegin(),ary.rend());
		int ans=0;
		rep(i,n+m){
			int l=-1,r=ans;
			while(r-l>1){
				int mid=(l+r)/2;
				if(mini(mid,ary[i].second))
					l=mid;
				else
					r=mid;
			}
			ans=max(ans,r+1);ins(r,ary[i].second);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 54992
#include<bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
using namespace std;
int main(){
    int n,k,ans=1;
	cin>>n>>k;
	while(n>0){
		ans+=min(ans,k);
		n--;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int i,j,n;
  char ch;
  while(1){
    scanf("%c",&ch);
    if(ch>='a' && ch<='z'){
      ch=ch-32;
    }
    else  if(ch>='A' && ch<='Z'){
      ch=ch+32;
    }
    printf("%c",ch);
    if(ch=='\n'){
      break;
	}	
  }	  
  return (0);
}

Measured memory_bytes: 524
countac=0
countwa=0
counttle=0
countre=0
for _ in range(0, int(input())):
    n = input()
    if n=="AC":
        countac += 1
    elif n=="WA":
        countwa += 1
    elif n=="TLE":
        counttle += 1
    elif n=="RE":
        countre += 1
print("AC x ", countac)
print("WA x ", countwa)
print("TLE x ", counttle)
print("RE x ", countre)


Measured memory_bytes: 9212
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> p;
const int inf=(1<<30);
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)

int main(){
	string s;
	cin>>s;
	ll ans=0;
	rep(i,0,s.length()){
		if(s[i]=='2')ans++;
		else continue;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

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

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n;
	cin >> n;
	int dig = 0, cur = 0;
	while(1) {
		dig++;
		if(26 * cur + 26 >= n) {
			n -= cur;
			break;
		}
		cur = 26 * cur + 26;
	}
	int p[dig];
	p[0] = 1;
	for(int i = 1; i < dig; i++) {
		p[i] = 26 * p[i - 1];
	}
	string ans = "";
	for(int i = 0; i < dig; i++) {
		for(char c = 'a'; c <= 'z'; c++) {
			n -= p[dig - i - 1];
			if(n <= 0) {
				n += p[dig - i - 1];
				ans += c;
				break;
			}
		}
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<stdlib.h>
#define ll long long

#define rep(i,l,r)for(ll i=(l);i<(r);i++)

ll d[110][110];
int main(){
	int h,w,n;
	scanf("%d%d%d",&h,&w,&n);
	ll s=0;
	rep(i,1,n+1){
		int t;
		scanf("%d",&t);
		while(t--){
			d[s/w][s%w]=i;
			s++;
		}
	}
	rep(i,0,h)rep(j,0,w){
		if(i%2==0)printf("%d%c",d[i][j],j==w-1?'\n':' ');
		else printf("%d%c",d[i][w-1-j],j==w-1?'\n':' ');
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,u;
	scanf("%d%d%d",&u,&n,&m);
	if(n>m)
	{
		while(n>m)
		{
			n--;
			if(n==m)
			{
				printf("Borys");
				return 0;
			}
			m++;
			if(n==m)
			{
				printf("Alice");
				return 0;
			}
		}
	}
	if(n<m)
	{
		while(n<m)
		{
			n++;
			if(n==m)
			{
				printf("Borys");
				return 0;
			}
			m--;
			if(n==m)
			{
				printf("Alice");
				return 0;
			}
		}
	}
	return 0;
} 

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    long X;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        X = sc.nextLong();
    }
    
    //解答処理
    private long solve() {
        long happy = 0;
         while (X >= 500) {
        	 happy += 1000;
        	 X -= 500;
         }
         while (X >= 5) {
        	 happy += 5;
        	 X -= 5;
         }
        
        return happy;
    }
    
    //出力
    public void show(long answer) {
        System.out.println(answer);
    }

}


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

using namespace std;




int main () {
//    freopen("1.txt", "r", stdin);
//    freopen("2.txt", "w", stdout);

    int n;
    cin >> n;

    vector <long long> a(3 * n);
    for (int i = 0; i < 3 * n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    long long ans = 0;
    for (int i = 0, j = 3 * n - 2; i < n; i++, j -= 2) {
        ans += a[j];
    }
    cout << ans << endl;
    

    return 0;
}


Measured memory_bytes: 2560
S = int(input())
t = [0]*4
frag = True
for i in range(4):
    t[i] = S % 10
    S = int(S/10)

for i in range(3):
    if t[i] == t[i+1]:
        frag = False

if frag:
    print("Good")
else:
    print("Bad")

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void push(int*, int, int*);
int pop(int*, int*);

int main(){
  int i, x;
  int a, b;
  char s[100];
  int  stk[200];
  int top = 0;

  while( scanf("%s", s) != EOF ){

    if( s[0] == '+' || s[0] == '-' || s[0] == '*'){
      b = pop(stk, &top);
      a = pop(stk, &top);
    }
    if ( s[0] == '+' ){
      x = a + b;
    } else if ( s[0] == '-' ){
      x = a - b;
    } else if ( s[0] == '*' ){
      x = a * b;
    } else {
      x = atoi(s);
    }
    push( stk, x, &top);
  }

  printf("%d\n" ,pop(stk,&top));
  return 0;
}

void push(int* s_p, int x, int* t_p){
  *t_p = *t_p +1;
  s_p[(*t_p)] = x;
  return;
}

int pop(int* s_p, int* t_p){
  *t_p = *t_p -1;
  return s_p[((*t_p)+1)];
}

Measured memory_bytes: 980
#include <stdio.h>

#define MAPX 25
#define MAPY 25

char data[MAPY][MAPX];
int h,w;

int search(int num, int nowx, int nowy){
	num = 1;
	data[nowy][nowx] = '#';
	if(nowx>0)if(data[nowy][nowx-1]=='.')num += search(num, nowx-1, nowy);
	if(nowy>0)if(data[nowy-1][nowx]=='.')num += search(num, nowx, nowy-1);
	if(nowx<w-1)if(data[nowy][nowx+1]=='.')num += search(num, nowx+1, nowy);
	if(nowy<h-1)if(data[nowy+1][nowx]=='.')num += search(num, nowx, nowy+1);
	return num;
}

void solve(){
	int i,t;
	int sx,sy;
	for(i = 0;i < h;i++){
		scanf("%s", &data[i][0]);
	}
	for(i = 0;i < h;i++){
		for(t = 0;t < w;t++){
			if(data[i][t]=='@'){
				sx = t;
				sy = i;
			}
		}
	}
	printf("%d\n", search(0,  sx, sy));
}

int main(){
	while(1){
		scanf("%d %d ", &w, &h);
		if(h == 0 && w == 0)break;
		solve(h,w);
	}
	return 0;
}

Measured memory_bytes: 640
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.Tuple (swap)
import Data.List (sortBy)
import Data.Function (on)
import qualified Data.IntSet as IS

main :: IO ()
main = do
  [n, k] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    initialize :: [(Int, Int)] -> Q
    initialize = go k . (Q IS.empty 0 0 [])
      where
        go :: Int -> Q -> Q
        go 0 q = q
        go c (Q us dp tp ds ((d, t) : dts))
            | IS.member t us = go c' (Q us dp' tp ds' dts)
            | otherwise      = go c' (Q us' dp' tp' ds dts)
          where
            c' = pred c :: Int
            us' = IS.insert t us :: IS.IntSet
            dp' = dp + d :: Int
            tp' = succ tp :: Int
            ds' = d : ds :: [Int]
    maxSP ::  Q -> Int
    maxSP (Q us0 dp0 tp0 ds0 cs0) = go (Q us0 dp0 tp0 ds0 cs0) sp0
      where
        sp0 = dp0 + tp0 ^ 2 :: Int
        go :: Q -> Int -> Int
        go (Q us dp tp ds@(d' : ds') ((d, t) : cs')) sp
            | IS.member t us = go (Q us dp tp ds cs') sp
            | otherwise      = go (Q us' dp' tp' ds' cs') sp'
          where
            us' = IS.insert t us :: IS.IntSet
            dp' = dp - d' + d :: Int
            tp' = succ tp :: Int
            sp' = max sp (dp' + tp' ^ 2) :: Int
        go _ sp = sp
  tds <- sequence . replicate n $ unsafeListToPair . map unsafeTextToInt . T.words <$> T.getLine :: IO [(Int, Int)]
  let
    dts = sortBy (flip compare `on` fst) . map swap $ tds :: [(Int, Int)]
  print . maxSP . initialize $ dts

data Q = Q !IS.IntSet !Int !Int ![Int] ![(Int, Int)]

unsafeListToPair :: [a] -> (a, a)
unsafeListToPair [x, y] = (x, y)

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;

using namespace std;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout<<setprecision(10);
  int a,b,k;
  cin>>a>>b>>k;
  int cnt=0;
  for(int i=100;i>0;i--)
  {
    if(a%i==0 && b%i==0){cnt++;}
    if(cnt==k){cout<<i<<endl;break;}
  }



  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (long long i = l; i < r; i++)
using namespace std;
typedef pair<int, int> P;

struct edge {
    int to, cost;
};
class dijkstra {
    int V;
    int d[100002];
    priority_queue<P, vector<P>, greater<P>> que;
    void update(int s, vector<edge> G[]) {
        fill(d, d + V + 1, 100000000000ll);
        d[s] = 0;
        que.push(make_pair(0, s));
        while (!que.empty()) {
            P p = que.top();
            que.pop();
            int v = p.second;
            if (d[v] < p.first) continue;
            rep(i, G[v].size()) {
                edge e = G[v][i];
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    que.push(make_pair(d[e.to], e.to));
                }
            }
        }
    }

public:
    dijkstra(int v, int s, vector<edge> G[]) {
        V = v;
        update(s, G);
    }
    int find(int e) {
        return d[e];
    }
};
int gcd(int a, int b) {
    if (a % b == 0)
        return b;
    else
        return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
bool prime(int a) {
    if (a == 1) return false;
    for (int i = 2; i * i <= a; i++) {
        if (a % i == 0) return false;
    }
    return true;
}
class Union_Find {
private:
    vector<int> t, s;

public:
    Union_Find(int max_length) {
        rep(i, max_length + 1) {
            t.push_back(i);
            s.push_back(1);
        }
    }
    void Union(int x, int y) {
        if (same(x, y)) return;
        int tx = Find(x), ty = Find(y);
        if (s[tx] < s[ty]) {
            s[ty] += s[tx];
            t[tx] = ty;
        }
        else if (s[tx] > s[ty]) {
            s[tx] += s[ty];
            t[ty] = tx;
        }
        else if (tx > ty) {
            t[tx] = ty;
            s[ty] += s[tx];
        }
        else {
            t[ty] = tx;
            s[tx] += s[ty];
        }
    }
    int Find(int n) {
        if (t[n] == n)
            return n;
        else
            return t[n] = Find(t[n]);
    }
    bool same(int x, int y) {
        return Find(x) == Find(y);
    }
    int get_Size(int a) {
        return s[a];
    }
};
signed main() {
    string s;
    cin>>s;
    int cnt=0,ans=0;
    if(s[s.size()-1]=='C'&&s[s.size()-2]=='B')cnt=1;
    for(int i=s.size()-3;i>=0;i--){
        if(s[i+1]=='C'&&s[i]=='B')cnt++;
        if(s[i+1]=='C'&&s[i]=='A')cnt=0;
        if(s[i+1]=='C'&&s[i]=='C')cnt=0;
        if(s[i+1]=='B'&&s[i]=='B')cnt=0;
        if(s[i+1]=='A'&&s[i]=='B')cnt=0;
        if(s[i]=='A'&&cnt){
            ans+=cnt;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640