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

int main() {
	int n,k;cin>>n>>k;
  	int mysum=0;
  	for (int i=0;i<n;i++){
    	int a;cin>>a;
      	mysum+=min(k-a,a-0)*2;
    }
  	cout<<mysum<<endl;
}
  	


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

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

Measured memory_bytes: 1024
#include<stdio.h>
#define MAX 102
#define WHITE -1
#define BLACK -2
#define GRAY -3

int n,time=0;
int M[MAX][MAX];
int d[MAX],f[MAX],color[MAX];

void visit(int u){
  int v;
  color[u] = GRAY;
  d[u] = ++time;
  for( v  = 0 ; v < n ; v++ ){
    if( color[v] == WHITE && M[u][v] == 1)
      visit(v);
  }
  color[u] = BLACK;
  f[u] = ++time;
}

void dfs(){
  int u;
  for( u = 0 ; u < n ; u++ )
    {
      color[u] = WHITE;
      d[u] = 0;
      f[u] = 0;
    }
  time = 0;
  for( u = 0 ; u < n ; u++ ){
    if( color[u] == WHITE )
      visit(u);
  }
}

int main(){
  int i,j,x,num1,num2;
  
  scanf("%d",&n);

  for( i = 0 ; i < n ; i++ ){
    for( j = 0 ; j < n ; j++ )
      M[i][j] = 0;
  }
    

  for( i = 0 ; i < n ; i++ ){
    scanf("%d%d",&num1,&x);
    for( j = 0 ; j < x ; j++ ){
      scanf("%d",&num2);
      M[num1-1][num2-1] = 1;
    }
  }
  
  dfs();

  for( i = 0 ; i < n ; i++ )
    printf("%d %d %d\n",i+1,d[i],f[i]);
  
  return 0;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
#define ll long long
#define maxn 2005
#define inf 1000000007
using namespace std;


inline ll read(){
	ll u=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){u=u*10+c-'0';c=getchar();}
	return u*f;
}

int G[maxn],L[maxn],n,R[maxn],a[maxn],b[maxn],ans=inf,q[maxn];
char c[maxn];
bool cmp(int x,int y){return R[x]<R[y];}
int main(){
	scanf("%s",c+1);n=strlen(c+1);
	for(int i=1;i<=n;i++)a[i]=c[i]-'0',L[i]=R[i]=inf;
	scanf("%s",c+1);
	for(int i=1;i<=n;i++)b[i]=c[i]-'0';
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(b[j])L[i]=min(L[i],(i-j+n)%n),R[i]=min(R[i],(j-i+n)%n);
	int sa=0,sb=0;
	for(int i=1;i<=n;i++)sa|=a[i],sb|=b[i];
	if(!sb){
		if(!sa)puts("0");
		else puts("-1");
		return 0;
	}
	for(int i=1;i<=n;i++){
		int k=i,j,r=0;
		for(j=1;j<=n;j++){
			if(a[k]!=b[j])q[++r]=k;
			k%=n;k++;
		}
		sort(q+1,q+r+1,cmp);
		G[r+1]=0;
		for(k=r;k;k--)G[k]=max(G[k+1],L[q[k]]);
		for(k=0;k<=r;k++){
			ans=min(ans,(R[q[k]]+max((i-j+n)%n,G[k+1]))*2-(i-j+n)%n+r);
			ans=min(ans,(G[k+1]+max((j-i+n)%n,R[q[k]]))*2-(j-i+n)%n+r);
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

int main(){
    vector<int> vec(3);
    for (int i = 0; i < vec.size(); i++){
        cin >> vec[i];
    }
    sort(vec.begin(), vec.end());
    
    cout << vec[0] << " " << vec[1] << " " << vec[2] << endl;
}


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

int main(){
  int n, d, sum=0;
  long long int x, y;
  cin >> n >> d;
  
  for(int i=0; i < n; i++){
    cin >> x >> y;
    if(sqrt(x*x + y*y) <= d) sum++;
  }
  
  cout << sum << endl;
}


Measured memory_bytes: 3676
#include <stdio.h>

int	main(void)
{
  char	str[500];
  int	i;
  int	j;
  int	len;

  scanf("%s", str);
  len = 0;
  while (str[len] != '\0')
    len++;
  i = 0;
  while (i < len - 1)
  {
    j = i + 1;
    while (j < len)
    {
      if (str[i] == str[j])
      {
        printf("no");
        return (0);
      }
      j++;
    }
    i++;
  }
  printf("yes");
  return (0);
}

Measured memory_bytes: 2152
#include <iostream>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define DESCEND greater<int>()  // sort 降順 大きい順
#define UNIQUE(vec) (vec).erase(unique(ALL((vec))), (vec).end());  // 必ずsortを行なってから
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;

const int MOD = 1000000007;  // 1 000 000 007


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

    // input
    string str, alpha;
    cin >> str;
    for (char i = 'a'; i <= 'z'; ++i) {
        alpha += i;
    }
    
    // calculation
    size_t s_len = str.length();
    bool flag = false;
    char res = 'a';
    REP(i, alpha.length()) {
        char ch = alpha[i];
        if ((int)str.find(ch) == -1) {
            res = ch;
            flag = true;
            break;
        }
    }
    
    if (flag) {
        cout << res << "\n";
    } else {
        cout << "None" << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 512
n, m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
cd = [list(map(int,input().split())) for _ in range(m)]

for i in range(n):
    dis = []
    for j in range(m):
        dis.append(abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1]))
    ans = dis.index(min(dis))
    print(ans+1)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <limits>
//#include <stack>
//#include <tuple>

using namespace std;

const double Inf = numeric_limits<double>::infinity();

int main(int argc, char** argv){
    int A, B, T;
    cin >> A >> B >> T;
    int t = 1;
    int sum = 0;
    while (1){
        if (t > T) break;
        if (t%A == 0) sum += B;
        t++;
    }
    cout << sum << "\n";

    return 0;
}


Measured memory_bytes: 256
from math import sqrt
M = 10**5+10
p = [1]*(M+1)
p[0] = p[1] = 0
for x in range(2, int(sqrt(M))+1):
    if p[x]:
        for y in range(x*x, M+1, x):
            p[y] = 0

t = 0
a = []
for i in range(M):
    if i % 2 != 0:
        if p[i] == 1 and p[(i+1)//2] == 1:
            t += 1
    a.append(t)

q = int(input())
for _ in range(q):
    l,r = map(int,input().split())
    print(a[r] - a[l-1])

Measured memory_bytes: 5144
#include<bits/stdc++.h>
using namespace std;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
int n,m,k,x1,yyy,x2,y2;
string s[1010101];
int main()
{
	cin>>n>>m>>k>>x1>>yyy>>x2>>y2;
	x1--;
	yyy--;
	x2--;
	y2--;
	for(int i=0;i<n;i++)
	{
		cin>>s[i];
	}
	vector<vector<int> >dt(n,vector<int>(m,1e9+1e7));
	queue<pair<int,int> >q;
	dt[x1][yyy]=0;
	q.push(make_pair(x1,yyy));
	while(!q.empty())
	{
		int x=q.front().first,y=q.front().second;
		q.pop();
		int nw=dt[x][y]+1;
		for(int d=0;d<4;d++)
		{
			int xx=x,yy=y;
			for(int i=0;i<k;i++)
			{
				xx+=dx[d];
				yy+=dy[d];
				if(xx<0 || yy<0 || xx>=n || yy>=m || s[xx][yy]=='@' || dt[xx][yy]<nw)
				{
					break;
				}
				if(dt[xx][yy]==nw)
				{
					continue;
				}
				dt[xx][yy]=nw;
				q.push(make_pair(xx,yy));
			}
		}
	}
	if(dt[x2][y2]<1e9+1e7)
	{
		cout<<dt[x2][y2]<<endl;
	}
	else
	{
		cout<<-1<<endl;
	}
	return 0;
}

Measured memory_bytes: 43604
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)

	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	aa := make([]int64, n)
	var sum1, sum2 int64
	sum1 = 0
	sum2 = 0
	for i := 0; i < n; i++ {
		aa[i] = getNextInt64(scanner)
		sum1 += aa[i]
	}

	mm := make([]int64, n)
	for i := 0; i < n*2; i += 2 {
		mm[(i+2)%n] = mm[i%n] + (aa[(i+1)%n]-aa[i%n])*2
	}

	for i := 0; i < n; i++ {
		sum2 += mm[i]
	}

	for i := 0; i < n; i++ {
		fmt.Fprint(writer, mm[i]+(sum1-sum2)/int64(n))
		if i == n-1 {
			fmt.Fprintln(writer, "")
			continue
		}
		fmt.Fprint(writer, " ")
	}

	writer.Flush()
}


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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadArrayInt();
            var A = input[0];
            var B = input[1];
            var C = input[2];
            var ans = 0;
            if (C <= A)
            {
                ans += C + B;
            }
            else
            {
                ans += A;
                C -= A;
                if (C <= B)
                {
                    ans += C + B;
                }
                else
                {
                    ans += 2 * B + 1;
                }
            }

            Console.WriteLine(ans);
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
int main(){
  int n;cin>>n;
  vector<int> v(n);for(int i=0;i<n;i++)cin>>v[i];
  vector<int> ans;
  for(int i=0;i<n;i++){
    int c=0;
    for(int j=v.size()-1;j>=0;j--){
      if(v[j]==j+1){
        c=1;
        ans.push_back(j+1);
        v.erase(v.begin()+j);
        break;
      }
    }
    if(c==0){
      cout<<-1<<endl;
      return 0;
    }
  }
  for(int i=ans.size()-1;i>=0;i--)cout<<ans[i]<<endl;
}
  

Measured memory_bytes: 256
def solve(L, R):
    if R - L >= 2019:
        return 0

    L %= 2019
    R %= 2019
    if R < L:
        return 0
    
    ans = 2019
    for i in range(L, R + 1):
        for j in range(i + 1, R + 1):
            ans = min(ans, (i * j) % 2019)
    return ans

if __name__ == "__main__":
    L, R = map(int, input().split(" "))
    print(solve(L, R))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    cout << a[n/2]-a[n/2-1]<<endl;
    return 0;
}




Measured memory_bytes: 640
#include <iostream>
#include <queue>
#include <cstring>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef pair<int, int> P;

struct C{
	int arr;	// Ô
	int num;	// l;
	int eat;	// HÔ
};

P seki[17];	// ÀÁ½O[vid ÞÈ·éÔ

int res[100];
C cust[100];

void init_val ()
{
	rep (i, 17 ){
		seki[i].first = -1, seki[i].second = -1;
	} // end rep
	memset (res, 0, sizeof (res ) );
}

int is_sit (int n )
{
	int need = cust[n].num;
	int si = -1;
	rep (i, 17 ){
		if (seki[i].first == -1 ){
			int seat = 0;
			for (int j = i; seki[j].first == -1 && j < 17; j++ ){
				seat++;
			} // end for
			if (seat >= need ){
				return i;
			} // end if
		} // end if
	} // end rep
	
	return -1;
}

void sit_down (int id, int si, int t )
{
	int need = cust[id].num;
	int endt = t + cust[id].eat;
	for (int i = si, j = 0; j < need; i++, j++ ){
		seki[i].first = id;
		seki[i].second = endt;
	} // end fpr
}

int is_depr (int t )
{
	int res = -1;
	rep (i, 17 ){
		if (seki[i].second != -1 && seki[i].second <= t ){
			res = seki[i].first;
			return res;
		} // end if
	} // end rep
	
	return -1;
}
void depr_cust (int id )
{
	rep (i, 17 ){
		if (seki[i].first == id ){
			seki[i].first = -1, seki[i].second = -1;
		} // end if
	} // end rep
}

int main()
{
	rep (i, 100 ){
		cust[i].arr = 5*i;
		cust[i].num = (i % 5 == 1 ? 5 : 2 );
		cust[i].eat =  17*(i%2)+3*(i%3)+19;
	} // end rep

	init_val ();
	queue<P> que;	// sñ·éO[vid, sñðJnµ½Ô

	int id = 0;	
	rep (t, 1000 ){
		int di, si;
		while ((di = is_depr (t ) ) != -1 ){	// ÞÈ·é¨qª¢é©
			depr_cust (di );					// ÞÈ
		} // end if
		while (!que.empty() ){					// sñÉÀñÅ¢é©
			P w = que.front();
			int wi = w.first;
			int wt = w.second;
			if ((si = is_sit(wi ) ) != -1 ){	// ÈÉÀêé
				res[wi] = t - wt;
				sit_down (wi, si, t );
				que.pop();
			}else{
				break;
			} // end if
		} // end if
		if (t == cust[id].arr ){	// ¨qª½
			if (que.empty() && ((si = is_sit(id ) ) != -1 ) ){	// ÈÉÀêé
 				sit_down (id, si, t );	// ÈÉÀé			
			}else{							// ÈÉÀêÈ¢
				que.push (P (id, t ) );	// sñÉÁ¦é
			} // end if
			id++;
		} // end if
	} // end rep

	int n;
	while (cin >> n ){
		cout << res[n] << endl;
	} // end while
		
	return 0;
}

Measured memory_bytes: 0
#if 0

#endif

#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void p(A a){cout << (a) << endl;}
template<class A,class B>void p(A a,B b){cout << a << " "  ;p(b);}
template<class A,class B,class C>void p(A a,B b,C c){cout << a << " " ;p(b,c);}
template<class A,class B,class C,class D>void p(A a,B b,C c,D d){cout << a << " " ;p(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for copy
// for(int i=0;i<N;++i) {

int main(void) {
  int h,a;cin>>h>>a;
  int r = h/a;
  if(h%a==0) p(r);
  else p(r+1);
  return 0;
}



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

int main(void){
  string str;
  int alphabet[26]={0},cnt=0;
  cin >> str;
  for(int i=0;i<str.size();i++)
    alphabet[str[i]-'a']++;
  for(int i=0;i<26;i++)
    cnt+=alphabet[i]%2;
  cout << cnt/2 << endl;
}

Measured memory_bytes: 3228
def main():
  
  n,*l=(map(int,open(0).read().split()))
  m=sorted(list(l))
  a,b=m[-1],m[-2]
  s=""
  for x in l:
    if x!=a:
      s+=str(a)+"\n"
    else:
      s+=str(b)+"\n"
  print(s)
  
if __name__=="__main__":
  main()

Measured memory_bytes: 25156
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	string x; cin >> x;
	int s = 0;
	int res = x.size();
	int cnt = 0;
	for (char a : x)
	{
		if (a == 'S')++cnt;
		else if (cnt != 0)
		{
			res -= 2;
			--cnt;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 640
from collections import Counter 
N = int(input())
A = list(map(int, input().split()))
c_A = Counter(A)
all =sum( [i*(i-1)//2 for i in c_A.values()] )

for i in range(N):
    ans =all -( c_A[A[i]] -1)
    print(ans)

Measured memory_bytes: 26780
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N,M;
    cin>>N>>M;
    int L,R;
    cin>>L>>R;
    int l,r;
    while(cin>>l>>r)
    {
        if(L<l)L=l;
        if(R>r)R=r;
        
    }
    
    if(R-L+1>=1)cout<<R-L+1<<endl;
    else cout<<0<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>

//using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

using ll =  long long;

constexpr int inf = 1e9 + 7;
//constexpr int inf = INT_MAX;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
template<typename T> void chadd(T& a, T b) { a = a + b; }

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}
}


int main() {

	int n;
	std::cin >> n;
	std::vector<std::pair<ll, ll>> xl(n);
	rep(i, n) std::cin >> xl[i].first >> xl[i].second;

	std::sort(allof(xl));

	// 各ロボットのスタートと終わり
	std::vector<std::pair<ll, ll>> se;
	rep(i, n) {
		se.push_back(std::make_pair(xl[i].first + xl[i].second, xl[i].first - xl[i].second));
	}

	std::sort(allof(se));

	// 貪欲

	int ans = 0;

	ll t = -1e9 - 7;
	// 終了時刻を早いものにする
	rep(i, n) {
		if (t <= se[i].second) {
			++ans;
			t = se[i].first;	
		}
	}

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 3956
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		if(n<1000){
          System.out.println("ABC");
        }else{
          System.out.println("ABD");
        }
	}
}


Measured memory_bytes: 35716
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>

using namespace std;

int isprime[100005];
int cnt[100005];

int prime(){
  isprime[0] = 1;
  isprime[1] = 1;
  for(int i=2;i<100005;i++){
    if(isprime[i] == 0){
      for(int j=i+i;j<100005;j+=i){
        isprime[j] = 1;
      }
    }
  }
  return 0;
}

int cntpri(){
  for(int i=0;i<100005;i++){
    if(!isprime[i] && !isprime[(i+1)/2]) cnt[i] = 1;
  }
  for(int i=1;i<100005;i++)cnt[i] += cnt[i-1];
  return 0;
}


int main(){
  prime();
  cntpri();

  int q;cin>>q;
  for(int i=0;i<q;i++){
    int r,l;cin>>r>>l;
    cout<<(cnt[l]-cnt[r-1])<<endl;
  }

  return 0;
}

Measured memory_bytes: 1408
n, t = map(int, input().split())
lst = []
for i in range(n):
    lsti = list(map(int, input().split()))
    lst.append(lsti)

lst.sort(key=lambda x: x[0])
a, b = [], []
for i in range(n):
    lsti = lst[i]
    a.append(lsti[0])
    b.append(lsti[1])

# DPテーブルの作成
dp = [[-1 for i in range(t)] for j in range(n+1)]
for i in range(t):
    dp[0][i] = 0

# DPテーブルの更新
for i in range(n):
    for j in range(t):
        if j >= a[i]:
            dp[i+1][j] = max(dp[i][j-a[i]]+b[i], dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]

# 答え(最大となる合計価値)
kouho = []
for i in range(n):
    kouho.append(dp[i][t-1]+b[i])
kouho.append(dp[n][t-1])
print(max(kouho))

Measured memory_bytes: 124248
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define init(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p1=1000000007;
int n;
int main() {
    
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int T=1;
    // cin>>T;
    while(T--) {
        ll n,k;cin>>n>>k;
        double a[n];
        rep(i,n){
            cin>>a[i];
            a[i]=(a[i]+1)/2;
        }
        double sum=0;double ma=0;
        rep(i,k)sum+=a[i];
        ma=sum;
        for(int i=k;i<n;i++){
            sum=sum+a[i]-a[i-k];
            ma=max(sum,ma);
        }
        cout<<fixed<<setprecision(6);
        cout<<ma;
    }   
    return 0;   
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;
const ll limit = 1e6+2;
long long a[limit];
long long n,m,d,temp,op;
float tp,t,mp=2;

int main()
{
    cin>>t;t*=2;
    tp=6.28318530717958623200/mp*t;
    printf("%0.20f",tp);
}


Measured memory_bytes: 3236
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int stack[205], top = 0;

void push(int x) {
	stack[top ++] = x;
}

int pop() {
	top --;
	return stack[top];
}

bool isOperator(char symbol) {
 	return symbol == '+' || symbol == '-' || symbol == '*';
}

int operate(int a, int b, char symbol) {
	if (symbol == '+') {
		return a + b;
	} else if (symbol == '-') {
		return a - b;
	} else if (symbol == '*') {
		return a * b;
	} else {
		return -999999999;
	}
}

int main() {
	char str[15];
	while (scanf("%s", str) != EOF) {
		if (isOperator(str[0])) {
			int a = pop();
			int b = pop();
			int result = operate(b, a, str[0]);
			push(result);
		} else {
			int number = atoi(str);
			push(number);
		}
	}

	top --;
	cout << stack[top] << endl;

	return 0;
}


Measured memory_bytes: 3204
def diff_a(c)
  "z".ord + 1 - c.ord
end

s = gets.chomp
k = gets.to_i
n = s.size
s.each_char.with_index do |c, i|
  next if c == "a" && i != n - 1
  d = diff_a(c)
  if i == n - 1
    s[i] = (97 + ((c.ord - 97) + k) % 26).chr
  elsif k >= d
    k -= d
    s[i] = "a"
  else
    next
  end
end
puts s


Measured memory_bytes: 4220
from sys import stdin

s = [x for x in stdin.readline().rstrip()]

odd = []
even = []

for i in range(len(s)):
    if (i + 1) % 2 == 0:
        even.append(s[i])
    else:
        odd.append(s[i])

if ("L" not in odd) and ("R" not in even):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include <stdio.h>
#include <string.h>
const int N=1e5+10;
const int INF=1e9+10;
int val[N*4],flag[N*4];
int min(int a,int b){return a>b?b:a;}
void add(int now,int l,int r,int L,int R,int n){
    if(L<=l&&r<=R){
        val[now]+=n;
        flag[now]+=n;
    }
    else if(!(L>r||l>R)){
        int mid=(l+r)>>1;
        if(flag[now]!=0){
            flag[now*2+1]+=flag[now];
            flag[now*2+2]+=flag[now];
            val[now*2+2]+=flag[now];
            val[now*2+1]+=flag[now];
            flag[now]=0;
        }
        add(now*2+1,l,mid,L,R,n);
        add(now*2+2,mid+1,r,L,R,n);
        val[now]=min(val[now*2+1],val[now*2+2]);
    }
    return ;
}
int query(int now,int l,int r,int L,int R){
    int ans=INF;
    if(L<=l&&r<=R)ans=val[now];
    else if(!(L>r||l>R)){
        int mid=(l+r)>>1;
        if(flag[now]!=0){
            flag[now*2+1]+=flag[now];
            flag[now*2+2]+=flag[now];
            val[now*2+2]+=flag[now];
            val[now*2+1]+=flag[now];
            flag[now]=0;
        }
        ans=min(query(now*2+1,l,mid,L,R),query(now*2+2,mid+1,r,L,R));
    }
    return ans;
}
int main(){
    int n,q,k,l,r;
    scanf("%d%d",&n,&q);
    memset(val,0,sizeof(val));
    memset(flag,0,sizeof(flag));
    while(q--){
        scanf("%d%d%d",&k,&l,&r);
        if(k==0){
            scanf("%d",&k);
            add(0,0,n,l,r,k);
        }
        else printf("%d\n",query(0,0,n,l,r));
    }
    
}


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

using namespace std;

const int N = 1e5 + 10;

int n, a[N];
int cnt[N];

int main() {
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;
        cnt[t]++;
    }
    int ans = 1;
    for (int X = 0; X <= N; X++) {
        int res = 0;
        for (int i = -1; i <= 1; i++) {
            if (X + i >= 0 && X + i <= N) {
                res += cnt[X + i];
            }
        }
        ans = max(ans, res);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 640
def show_list(a):
    for x in a:
        print x,
    print

def selection_sort(a,n):
    count=0
    for i in xrange(n):
        minj = i
        for j in xrange(i,n):
            if a[j]<a[minj]:
                minj = j
        if minj!=i:  
            tmp = a[i]
            a[i]=a[minj]
            a[minj]=tmp
            count+=1
    show_list(a)
    print count


def main():
    n = input()
    a = map(int,raw_input().split())
    selection_sort(a,n)


if __name__ == '__main__':
    main()

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

int main(){
    cout << fixed << setprecision(12);

    while (true)
    {
        int n;
        double s[1000];
        double sum = 0;

        cin >> n;

        if(n == 0) break;

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

        for(int i = 0; i < n; i++){
            sum += s[i];
        }

        double ave = sum / n;

        double ans = 0;

        for(int i = 0; i < n; i++){
            ans += pow(s[i] - ave, 2);
        }

        ans = sqrt(ans / n);

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


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

int main(){
  int n,k,num=0;
  cin >> n >> k;
  vector<int> vec(n);
  for(int i=0;i<n;i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  for(int i=0;i<k;i++){
    num += vec.at(i);
  }
  cout << num << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
int
main (void)
{
  int d, i, result;
  while (scanf ("%d", &d) != EOF)
    {
      result=0;
      for (i = 0; i < 600; i += d)
	result += d * i * i;
      printf ("%d\n", result);
    }
  return 0;
}

Measured memory_bytes: 596
N = int(input())

MOD = int(1e9) + 7

dp = [[0] * 4 for _ in range(N + 1)]
dp[0][0] = 1
for i in range(1, N + 1):
    # 0も9もない
    dp[i][0] = dp[i - 1][0] * 8 % MOD
    # 0だけある
    dp[i][1] = (dp[i - 1][0] + dp[i - 1][1] * 9) % MOD
    # 9だけある
    dp[i][2] = (dp[i - 1][0] + dp[i - 1][2] * 9) % MOD
    # 0も9もある
    dp[i][3] = (dp[i - 1][1] + dp[i - 1][2] + dp[i - 1][3] * 10) % MOD

print(dp[N][3])

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

int main()
{
    int k;
    cin >> k;
    char s[105];
    cin >> s;

    if (strlen(s) <= k) cout << s << endl;
    else if (strlen(s) > k) {
        for (int i=0; i<k; ++i) {
            cout << s[i];
        }
        cout << "..." << endl;
    }
    return 0;
}


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

const int P = 1e9 + 7, N = 2e5 + 10;

struct BIT {
    int c[N];
    int n;
    void init(int sz = 0) {
        n = sz;
        for (int i = 0; i <= n; ++i) c[i] = 0;
    }
    void upd(int x, int v) {
        while (x <= n) {
            c[x] += v;
            if (c[x] >= P) c[x] -= P;
            x += x & -x;
        }
    }
    int qry(int x) {
        int ans = 0;
        while (x) {
            ans += c[x];
            if (ans >= P) ans -= P;
            x -= x & -x;
        }
        return ans;
    }
} bt;

int n, m, a[N], b[N];

struct point {
    int x, y;
    bool operator < (const point &o) const {
        return x < o.x || (x == o.x && y > o.y);
    }
    bool operator == (const point &o) const {
        return x == o.x && (y == o.y);
    }
} p[N];

int yval[N], tn;
void push(int x) {
    yval[++tn] = x;
}
void init() {
    sort(yval + 1, yval + tn + 1);
    tn = unique(yval + 1, yval + tn + 1) - yval - 1;
}
int idx(int v) {
    return lower_bound(yval + 1, yval + tn + 1, v) - yval;
}

int dp[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= m; ++i) cin >> b[i];
    int tot = 0;
    for (int i = 1; i <= n; ++i) {
        if (a[i] <= b[1] || a[i] >= b[m]) continue;
        int r = lower_bound(b + 1, b + m + 1, a[i]) - b;
        if (a[i] == b[r]) continue;
        int l = r - 1;
        p[++tot] = {a[i] - b[l], b[r] - a[i]};
        push(p[tot].y);
    }
    init();
    for (int i = 1; i <= tot; ++i) p[i].y = idx(p[i].y);
    sort(p + 1, p + tot + 1);
    tot = unique(p + 1, p + tot + 1) - p - 1;
    bt.init(tn + 5);
    for (int i = 1; i <= tot; ++i) {
        dp[i] = (bt.qry(p[i].y - 1) + 1) % P;
        bt.upd(p[i].y, dp[i]);
    }
    int ans = 1;
    for (int i = 1; i <= tot; ++i) {
        ans += dp[i];
        if (ans >= P) ans -= P;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 6052
program abc029a
    implicit none
    integer(8):: ind_sum,i,n,wcnt
    character(200000):: s

    read*, s(:)
    n = len_trim(s)
    
    ind_sum=0
    wcnt=0
    do i=1,n
        if (s(i:i) == 'W')then
            wcnt=wcnt+1
            ind_sum = ind_sum + i - wcnt
        end if
    end do
    print*, ind_sum
end program abc029a

Measured memory_bytes: 1084
N,M=map(int,input().split())
par=[-1]*N

def find(x):
    if par[x]<0:
        return x
    else:
        par[x]=find(par[x])
        return par[x]
def union(x,y):
    p,q=find(x),find(y)
    if p==q:
        return
    if p>q:
        p,q=q,p
    par[p]+=par[q]
    par[q]=p   

for _ in range(M):
    X,Y,_=map(int,input().split())
    X,Y=X-1,Y-1
    union(X,Y)
ans=0
for i in range(N):
    if par[i]<0:
        ans+=1
print(ans)


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

int main() {
  int X, Y, Z;
  cin >> X >> Y >> Z;
  int tmp;

  tmp = X;
  X = Y;
  Y = tmp;

  tmp = X;
  X = Z;
  Z = tmp;

  cout << X << " " << Y << " " << Z << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int p = sc.nextInt();
    int q = sc.nextInt();
    int r = sc.nextInt();
    System.out.println(Math.min(p+q, Math.min(q+r, r+p)));
  }
}


Measured memory_bytes: 35308
import sys, math, re
from functools import lru_cache
from collections import defaultdict
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    S = input()
    l = [0]
    for i in range(N):
        if S[i] == '(':
            l.append(l[-1]+1)
        else:
            l.append(l[-1]-1)

    m = min(l)

    if m < 0:
        l = list(map(lambda x: x-m, l))

    print('('*l[0] + S + ')'*l[-1])

if __name__ == '__main__':
    main()

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

using namespace std;

#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i)

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int Q, H, S, D, N;
    cin >> Q >> H >> S >> D >> N;

    vector<llong> L05, L1, L2;
    L05.push_back(H);
    L05.push_back(Q * 2);
    llong min_L05 = *min_element(L05.begin(), L05.end());

    L1.push_back(S);
    L1.push_back(min_L05 * 2);
    llong min_L1 = *min_element(L1.begin(), L1.end());

    L2.push_back(D);
    L2.push_back(min_L1 * 2);
    L2.push_back(min_L05 * 4);
    llong min_L2 = *min_element(L2.begin(), L2.end());
    
    //cout << Q << " " << min_L05 << " " << min_L1 << " " << min_L2 << endl;
    llong ans = 0;
    ans = (N / 2) * min_L2 + (N % 2) * min_L1;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	int n=5;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		if(a[i]==0)
		{
			cout<<i+1;
			return 0;
		}
	}
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) > (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define R cin>>
#define i64 unsigned long long
#define repr(i, n) REPR(i, n, 0)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define in(a) insert(a)
#define P(p) cout<<(p)<<endl;
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SORT(a) sort((a).begin(), (a).end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long int> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll mod = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;
template<typename T> void co(T e){cout << e << "\n";}
template<typename T> void co(const vector<T>& v){for(const auto& e : v)
    { cout << e << " "; } cout << "\n";}
ll gcd(ll a, ll b) {
    if (a < b)swap(a, b);
    if (b == 0) return a;
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}
ll lcm(ll a, ll b) {
    ll g = gcd(a, b);
    return a * b / g;
}
bool prime(ll n) {
    for (ll i = 2; i <= sqrt(n); i++) {
        if (n%i == 0)return false;
    }
    return n != 1;
}


int pow(int x, int y, int mod){
    int ret=1;
    for(;y;y>>=1,x=1ll*x*x%mod){
        if(y&1) ret=1ll*ret*x%mod;
    }
    return ret;
}
void kill()
{
    cout << "No" << endl;
    exit(0);
}

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





int main(){
    sonic();
    int n, A=0, B=0, AB=0, ans=0;
    R n;
    rep(i, n) {
        string s;
        R s;
        int l = s.length();
        if ((s[l - 1] == 'A') && (s[0] == 'B'))AB += 1;
        else {
            if (s[l - 1] == 'A')A += 1;
            else if (s[0] == 'B')B += 1;
        }
        rep(j, l - 1)if(s[j] == 'A' && s[j + 1] == 'B')ans += 1;
    }
        if(AB==0)ans+=min(A,B);
        else{
            ans+=AB-1;
            if(A){
                A-=1;
                ans+=1;
            }
            if(B){
                B-=1;
                ans+=1;
            }
            ans+=min(A,B);
        }
        co(ans);
}


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

using namespace std;

int main(){
  int n;

  while(cin>>n){
    int ans_ma;
    int ma_n = n + 1;
    int c_ma = 0;

    if(ma_n % 2 == 0){
      ++ma_n;
    }
    for(int i = ma_n;;i = i + 2){
      int q = sqrt(i);

      c_ma = 1;
      for(int j = 3;j <= q;j = j + 2){
        if(i % j == 0){
          c_ma = 0;
          break;
        }
      }
      if(c_ma == 1){
        ans_ma = i;
        break;
      }
    }

    int ans_mi;
    int mi_n = n - 1;
    int c_mi = 0;

    if(mi_n == 2){
      ans_mi = 2;
    }
    else{
      if(mi_n % 2 == 0){
        --mi_n;
      }
      for(int i = mi_n;i >= 3;i = i - 2){
        int q = sqrt(i);
        
        c_mi = 1;
        for(int j = 3;j <= q;j = j + 2){
          if(i % j == 0){
            c_mi = 0;
            break;
          }
        }
        if(c_mi == 1){
          ans_mi = i;
          break;
        }
      }
    }
    cout<<ans_mi<<" "<<ans_ma<<endl;
  }
  return 0;
}



Measured memory_bytes: 2976
#include <iostream> 
#include <sstream> 
#include <iomanip> 
#include <algorithm> 
#include <cmath> 
#include <string> 
#include <vector> 
#include <list> 
#include <queue> 
#include <stack> 
#include <set> 
#include <map> 
#include <bitset> 
#include <numeric> 
#include <climits> 
#include <cfloat> 
using namespace std;

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

int h, w;
int gy, gx;

bool check(bitset<49> bs, int y0, int x0)
{
    if(y0 != gy || x0 != gx){
        for(int y=0; y<h; ++y){
            for(int x=0; x<w; ++x){
                if(!bs[y*w+x] || (y == gy && x == gx))
                    continue;
                int tmp = 0;
                for(int i=0; i<4; ++i){
                    int y2 = y + dy[i];
                    int x2 = x + dx[i];
                    if(y2 < 0 || y2 >= h || x2 < 0 || x2 >= w)
                        continue;
                    if(bs[y2*w+x2] || (y2 == y0 && x2 == x0))
                        ++ tmp;
                }
                if(tmp < 2)
                    return false;
            }
        }
    }

    int i = 0;
    while(!bs[i])
        ++ i;

    queue<pair<int, int> > q;
    q.push(make_pair(i/w, i%w));
    bs[i] = false;
    while(!q.empty()){
        int y = q.front().first;
        int x = q.front().second;
        q.pop();
        for(int i=0; i<4; ++i){
            int y2 = y + dy[i];
            int x2 = x + dx[i];
            if(y2 < 0 || y2 >= h || x2 < 0 || x2 >= w)
                continue;
            if(!bs[y2*w+x2])
                continue;
            q.push(make_pair(y2, x2));
            bs[y2*w+x2] = false;
        }
    }

    return bs.none();
}

vector<vector<set<unsigned long long> > > memo;

bool solve(int y, int x, bitset<49>& bs)
{
    if(y == gy && x == gx && !bs[y*w+x])
        return bs.none();

    unsigned long long index = (bs >> 32).to_ulong();
    index <<= 32;
    index |= ((bs << 17) >> 17).to_ulong();
    if(memo[y][x].find(index) != memo[y][x].end())
        return false;
    memo[y][x].insert(index);

    if(!check(bs, y, x))
        return false;

    for(int i=0; i<4; ++i){
        int y2 = y + dy[i];
        int x2 = x + dx[i];
        if(y2 < 0 || y2 >= h || x2 < 0 || x2 >= w)
            continue;
        int j = y2 * w + x2;
        if(!bs[j])
            continue;

        bs[j] = false;
        if(solve(y2, x2, bs))
            return true;
        bs[j] = true;
    }

    return false;
}

int main()
{
    for(;;){
        cin >> w >> h;
        if(w == 0)
            return 0;

        bitset<49> bs;
        for(int i=0; i<h; ++i){
            for(int j=0; j<w; ++j){
                int a;
                cin >> a;
                if(a == 0){
                    bs[i*w+j] = true;
                    gy = i;
                    gx = j;
                }
            }
        }

        if(bs.none()){
            cout << "No" << endl;
            continue;
        }

        memo.assign(h, vector<set<unsigned long long> >(w, set<unsigned long long>()));
        if(solve(gy, gx, bs))
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>

#define MAX_DATA_NUM      100

static void Exchange_Void(int *pSortBuff, int insert, int key );

int main(void)
{
    int data_num;			/* Data Num */
	int cd;					/* Count Data */
	int key = 0;			/* Compare Num */
//	int pSortBuff[MAX_DATA_NUM];
	int *pSortBuff;
	int insert;
	int loop;
   
    pSortBuff = (int *)malloc(sizeof(int) * MAX_DATA_NUM);
    /* get "Data Num" */
    scanf("%d", &data_num);
     
    /* get Name & time */
    while((scanf("%d", &(pSortBuff[cd])) != EOF) && cd < MAX_DATA_NUM)
    {
        cd++;
    }
    
	
    /* get Data Num equal process num */
    if( data_num == cd )
    {
         while(key < data_num)
        {
        	if(key>0)
        	{
        		insert = -1;
	        	for(loop=key-1; loop>=0; loop--)
	        	{
	        		if(pSortBuff[loop] > pSortBuff[key])
	        		{
	        			insert = loop;
	        		}
	        	}
        		if(insert != -1)
        		{
        			Exchange_Void(pSortBuff, insert, key);
        		}
        	}
        	// print
			for(loop=0; loop<data_num-1; loop++)
			{
				printf("%d ", pSortBuff[loop]);
			}
        	printf("%d\n", pSortBuff[data_num-1]);
			key++;
        }
    }
    else
    {
        /* error input */
    }
	free(pSortBuff);
    return 0;
}

static void Exchange_Void(int *pSortBuff, int insert, int key )
{
	int swap;
	int loop;
	
	swap = pSortBuff[key];
	
	for(loop=key; loop>insert; loop--)
	{
		pSortBuff[loop] = pSortBuff[loop-1];
	}
	pSortBuff[insert] = swap;
}

Measured memory_bytes: 1864
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

//D日目時点のスコアを計算
int score(int D, int c[], int s[][26], int t[]){
    int pen_day[26]={1};
    for(int i=0; i<26; i++){
        pen_day[i]=1;
    }
    int score=0;
    
    for(int i=0; i<D; i++){
        int type=t[i]-1;
        pen_day[type]=0;
        //満足度増加
        score+=s[i][type];
        //満足度低下
        for(int j=0; j<26; j++){
            int dec=c[j]*pen_day[j];
            score-=dec;
        }
        //日数追加
        for(int j=0; j<26; j++){
            pen_day[j]++;
        }        
    }
    return score;
}

//penの変異
int hen_pen(int st, int end, int c[], int s[][26], int t[], int type1, int type2){
    int sum=0;
    int de_type1=0;
    int de_type2=0;
    int last1=0, last2=0;

    for(int i=st; i<=end; i++){
        if(t[i]==type1){
            de_type1++;
            last1=i;
        }
        if(t[i]==type2){
            de_type2++;
            last2=i;
        }
    }

    sum+=c[type1]*de_type1;
    sum+=c[type2]*de_type2;
    sum+=(end-last1)*c[type1];
    sum-=(last2-st)*c[type2];

    return sum;
}

void Greedy(int D, int c[], int s[][26]){
    int t[D], max_type=0, max_score=0;

    for(int i=0; i<D; i++){
        max_score=0;
        for(int j=0; j<26; j++){
            t[i]=j+1;
            int S=score(i+1, c, s, t);
            if(max_score < S){
                max_score = S;
                max_type=j+1;
            }
        }
        t[i]=max_type;
    }

    //局所探索
    int new=0;
    int roop_num=0;
    int MAX=max_score;
    while(1){
        int a=rand()%D;
        int b=rand()%D;

        if(a>b){
            int tmp=a;
            a=b;
            b=tmp;
        }

        if(hen_pen(a, b, c, s, t, t[a], t[b]) < 0){
            //a,bを入れ替え
            int tmp;
            tmp=t[a];
            t[a]=t[b];
            t[b]=tmp;
        }
/*
        //a,bを入れ替え
        int tmp;
        tmp=t[a];
        t[a]=t[b];
        t[b]=tmp;

        //scoreを計算
        int now_score=score(fmax(a,b), c, s, t);
        if(MAX<now_score) MAX=now_score;
        else{
            tmp=t[a];
            t[a]=t[b];
            t[b]=tmp;  
        }
        */
        new++;
        roop_num++;
        if(roop_num==D*10000) break;
    }

    for(int i=0; i<D; i++){
        printf("%d\n", t[i]);
    }
}

int main(void){
    int D, c[26], s[365][26], t[365];

    //入力
    scanf("%d", &D);
    for(int i=0; i<26; i++){
        scanf("%d", &c[i]);
    }
    for(int i=0; i<D; i++){
        for(int j=0; j<26; j++){
            scanf("%d", &s[i][j]);
        }
    }
    /*
    for(int i=0; i<D; i++){
        scanf("%d", &t[i]);
    }
    */

   /*ここから処理*/
   /*
    int num=1;
    for(int i=0; i<D; i++){
        printf("%d\n", num);
        num++;
        if(num>26) num=1;
    }
    */

   Greedy(D, c, s);


    return 0;
}

Measured memory_bytes: 1744
// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#define _USE_MATH_DEFINES
#include<math.h>

//#include<cmath>

#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>



//#include "Ants.h"
using namespace std;
typedef long long ll;
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<n;i++)
#define show(s) cout<<s<<endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define LINF (1000000000000000000ll)

//typedef pair < int, int> P;
ll gcd(ll a, ll b) {//最大公約数を求める///最大公倍数a*b/gcd(a,b)
	if (b == 0) return a;
	return gcd(b, a % b);
}

ll lcd(ll a, ll b) {//最小公倍数を求める　b=0のときaを返す
	if (b == 0) return a;
	return (a / gcd(a, b)) * b;
}
vector<int> calc(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p;
}
int N;
map <string,int> m;
int main()
{
	cin >> N;
	int big = 0;
	rep(i, N) {
		string s;
		cin >> s;
		chmax(big, ++m[s]);
	}
	
	map<string, int>::iterator itr;
	for (itr = m.begin(); itr != m.end(); itr++) {
		pair<string, int>p = *itr;
		if(p.second==big)
		cout << p.first << endl;
	}

	
}

Measured memory_bytes: 25216
import qualified Data.IntMap as M
import qualified Data.ByteString.Char8 as B
import Data.Maybe
 
main = B.getContents >>= print . solve . tail . map readB . B.words

readB = fst . fromJust . B.readInt
 
solve = calc . count
 
count as = M.fromListWith (+) $ zip as (repeat 1)
 
calc = M.foldrWithKey op 0
 
op k v s
  | k <= v = s + v - k
  | otherwise = s + v


Measured memory_bytes: 16764
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>

#define ll long long int
#define mod 1000000007

using namespace std;


int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cnt = 1;
    for(int i = 0; i < n - 1; i++){
        if(s[i] != s[i + 1])
            cnt++;
    }
    cout << cnt;
}









Measured memory_bytes: 3696
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
using pii = pair<int, int>;
using ll = long long;
using vint = vector<int>;

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

vint solve(string S, int C) {
    int cnt = 0;
    vint ret;
    rep(i, S.size()){
        char c = S[i];
        cnt = max(0, cnt-1);
        if (cnt) continue;
        if (c == 'o') {
            ret.emplace_back(i);
            cnt = C+1;
        }
    }

    return ret;
}

int main() {
    int N, K, C;
    cin >> N >> K >> C;
    string S;
    cin >> S;

    vint asc = solve(S, C);
    if (asc.size() > K) {
        return 0;
    }

    reverse(S.begin(), S.end());
    vint desc = solve(S, C);
    rep(i, desc.size()) {
        desc[i] = N-1 - desc[i];
    }
    sort(desc.begin(), desc.end());
    rep(i, asc.size()) {
        if (asc[i] == desc[i]) {
            cout << asc[i]+1 << endl;
        }
    }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define int long long int
mt19937 rng(std::chrono::duration_cast<std::chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int N=100005;
#define M 1000000007
#define double long double
#define BINF 10000000000000000
#define init(arr,val) memset(arr,val,sizeof(arr))
#define MAXN 15000001
#define deb(x) cout << #x << " " << x << "\n";
const int LG = 22;

multiset<int>s[N];\

#undef int 
int main() {
#define int long long int
ios_base::sync_with_stdio(false); 
cin.tie(0); 
cout.tie(0);
 

    int n;
    cin >> n;
    if(n & 1 or n < 2){
        cout << 0;
        return 0;
    }

    int p = 0, ans = 0;

    for(int i = 26; i >= 1; i--){
        int x = pow(5, i);
        int y = n / (2 * x);
        y -= p;
        ans += i * y;
        p += y;
    }

    cout << ans << endl;


return 0;
}




Measured memory_bytes: 4992