akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdlib.h>
#include<stdio.h>
#include<vector>
#include<utility>
#include<queue>
#include<stdbool.h>
using namespace std;
#define N (1000000000+7)
typedef long long ll;
typedef pair<int, int> P;

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


int main(void) {
	int n, m;
	cin >> n >> m;
	vector<ll>x(m), d(m - 1);
	for (int i = 0;i < m;i++)cin >> x[i];
	if (n >= m) {
		cout << 0 << endl;
		return 0;
	}
	sort(x.begin(), x.end());
	for (int i = 0;i < m - 1;i++)d[i] = x[i + 1] - x[i];
	sort(d.begin(), d.end());
	ll ans = 0;
	for (ll i = 0;i < m - n;i++)ans += d[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main()
{
    int a,b,k,c=0;
    scanf("%d %d",&a,&b);
if((a+b)%2==0)
    {
    k=(a+b)/2;
    printf("%d",k);
    }
else
    {
    printf("IMPOSSIBLE");
    }
return 0;
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = (int)1e9;
const long long mod = 998244353LL;
const double pi = acos(-1.0);

int main() {
	int a, b;
	while (cin >> a >> b) {
		Cout(a + b);
	}
}


Measured memory_bytes: 3044
S = input()

D_dict = {}
D_dict['SUN'] = 7
D_dict['MON'] = 6
D_dict['TUE'] = 5
D_dict['WED'] = 4
D_dict['THU'] = 3
D_dict['FRI'] = 2
D_dict['SAT'] = 1

print(D_dict[S])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
 
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------
 
int N;
int A[101],B[101],C[101];
 
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>A[i];
	int ret=0;
	FOR(i,N) {
		cin>>B[i];
		ret+=B[i];
	}
	FOR(i,N-1) cin>>C[i];
	FOR(i,N-1) if(A[i]+1==A[i+1]) ret+=C[A[i]-1];
	cout<<ret<<endl;
}
 
 
int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<String[]> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            String[] str = new String[3];

            str[0] = sc.next();
            str[1] = sc.next();
            str[2] = String.valueOf(i);
            list.add(str);
        }

        Collections.sort(list, new Comparator<String[]>() {
            @Override
            public int compare(String[] o1, String[] o2) {
                if (o1[0].compareTo(o2[0]) != 0) {
                    return o1[0].compareTo(o2[0]);
                } else {
                    return Integer.parseInt(o2[1]) - Integer.parseInt(o1[1]);
                }
            }
        });


        for (String[] strs : list) {
            System.out.println(Integer.parseInt(strs[2]) + 1);
        }
    }
}



Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <list>

int main()
{
    std::string input;
    while(std::cin >> input, input != "-"){
    	int n;
        std::cin >> n;
        for (int a = 0; a < n; ++a) {
            int h;
            std::cin >> h;

            input = input.substr(h,input.length()-h)+ input.substr(0,h);
        }

        std::cout << input << std::endl;
    }
    
    return 0;
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
signed main(){
  int a,b;
  cin>>a>>b;
  vector<int> c(b);
  int d[b+1][a+1];
 rep(i,b){
  cin>>c[i];
    rep(j,c[i])
      cin>>d[i][j];
  }
  vector<bool> e(a+1,1);
 rep(i,b){
    rep(j,c[i]){
      int s=d[i][j];
      e[s]=0;
      }
  }
  int k=0;
  rep1(i,a){
  if(e[i])
    k++;
  }
  cout<<k;
}

Measured memory_bytes: 3684
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	vector<vector<int>> x(N), y(N);
	for (int i = 0; i < N; i++) {
		int a;
		cin >> A[i];
		x[i].resize(A[i]);
		y[i].resize(A[i]);
		for (int j = 0; j < A[i]; j++) {
			int x1, y1;
			cin >> x[i][j] >> y[i][j];	
		}
	}
	int max = 0;
	for (int i = 0; i < (1 << N); i++) {
		int tmp = 0;
		bool flag = true;
		for (int j = 0; j < N; j++) {
			if (((i >> j) & 1) == 0)continue;
			for (int k = 0; k < A[j]; k++) {
				if (((i >> (x[j][k] - 1)) & 1) != y[j][k])flag = false;
			}
			if (flag) tmp++;
			
		}
		if (flag) {
			if (tmp > max) {
				max = tmp;
			}
		}
	}
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 256
x, y = [int(i) for i in input().split()]

def kai(x, p):
    a = 1
    for i in range(1, x + 1):
        a *= i
        a %= p
    return a

def comb(a, b, p):
    if a < 0 or b < 0:
        return 0
    elif a < b:
        return 0
    c = 1
    c *= kai(a, p)
    c *= pow(kai(b, p), p - 2, p)
    c *= pow(kai(a - b, p), p - 2, p)
    return c % p

if (x + y) % 3 != 0:
    print(0)
    exit()

z = (x + y) // 3
p = 10 ** 9 + 7
print(comb(x + y - 2 * z, x - z, p))


Measured memory_bytes: 38640
# -*- coding: utf-8 -*-

N = int(input())
S = input()

Ss = {}
for s in S:
    if s in Ss:
        Ss[s] += 1
    else:
        Ss[s] = 1

ans = 1
for v in Ss.values():
    ans *= (v + 1)

print((ans - 1) % int(1e9 + 7))


Measured memory_bytes: 3188
#include <algorithm>
#include <functional>
#include <iostream>
#include <iterator>
int main(int argc, char *argv[]) {
  int K, N;
  std::cin >> N >> K;
  int l[51];
  for (int i = 0; i < N; ++i)
    std::cin >> l[i];

  std::sort(l, l + N, std::greater<int>());
  int sum = 0;
  for (int i = 0; i < K; ++i) 
    sum += l[i];
  std::cout << sum << std::endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int A,B,T,i=1,sum=0;
 	scanf("%d",&A);
  	scanf("%d",&B);
  	scanf("%d",&T);

  	while((float)i*A<(float)T +0.5){
      sum=sum+B;
      i++;
    }
  	printf("%d\n",sum);
  	return 0;
}


Measured memory_bytes: 128
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val N = next().replace(" ", "").toInt()
    println(if (N % 4 == 0) "YES" else "NO")
}

Measured memory_bytes: 37872
#include <stdio.h>
int main(void){
    int a;
    scanf("%d", &a);
    if(a%10 == 3){
        printf("bon");
    }else if(a%10 == 0 || a%10 == 1 || a%10 == 6 || a%10 == 8){
        printf("pon");
    }else{
        printf("hon");
    }
    
    

}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if (a==b && b!=c){
        printf("2\n");
    }
    else if (a==c && b!=c){
        printf("2\n");
    }
    else if (b==c && a!=b){
        printf("2\n");
    }
    else if (a==b && b==c){
        printf("1\n");
    }
    else{
        printf("3\n");
    }
}

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

using namespace std;

typedef unsigned long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 18) + 1;
	
	char buf[L], *S , *T, c;
	 
	char getchar() {
		if(S == T) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}
	
	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	char B[25], *outs=B+20, *outr=B+20;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;
		
		if(!a)*--outs = '0';
		else 
			while(a)
				*--outs = (a % 10) + 48, a /= 10;
		
		if(x)
			*--outs = x;
		
		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inp_ll;

const int MAXN = 111;

int n, m;
char s[MAXN][MAXN];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};

int main()
{
	
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++ i)
		scanf("%s", s[i]+1);
	for (int i = 1; i <= n; ++ i)
		for (int j = 1; j <= m; ++ j)
		{
			if (s[i][j] == '.') continue;
			int flag = 0;
			for (int k = 0; k < 4; ++ k)
			{
				int tx = i+dx[k];
				int ty = j+dy[k];
				if (s[tx][ty] == '#') flag = 1;
			}
			if (!flag)
			{
				puts("No");
				return 0;
			}
		}
	puts("Yes");
	
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
//<DEFINE>
void Fast() {
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
}
void File() {
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#ifdef _WIN64
#define __builtin_popcountll __popcnt64
#else
inline int __builtin_popcountll(__int64 a) {
	return __builtin_popcount((unsigned int)a) + __builtin_popcount(a >> 32);
}
#endif
#endif
using ll = long long;
using ull = unsigned long long;
#define mod 1000000007
ll gcd(ll a, ll b) {
	return!b ? a : gcd(b, a % b);
}
#define fix(n) cout << fixed << setprecision(n);
#define all(a) a.begin(), a.end()
#define skip continue
#define pi  acos(-1)
#define endl "\n"
//#define ceil(x,y) ((x+y-1)/y)
//sin(x*pi/180)
//be careful from the multiplication while using this define 
//alot of memset may cause TLE
#define TC int t$$t$;cin>>t$$t$;while(t$$t$--)
//</DEFINE>
int dx[] = { 0,0,-1,1,1,1,-1,-1 };
int dy[] = { 1,-1,0,0,1,-1,1,-1 };
int send, tend;
string s, t;
int res[3000][3000];
//<FUNCTIONS>	
int solve(int sidx = 0, int tidx = 0) {
	if (sidx == send || tidx == tend)return 0;
	int& mx = res[sidx][tidx];
	if (~mx)return mx;
	if (s[sidx] == t[tidx])return mx = solve(sidx + 1, tidx + 1) + 1;
	return mx = max(solve(sidx + 1, tidx), solve(sidx, tidx + 1));
}
string build(int sidx = 0, int tidx = 0) {
	if (sidx == send || tidx == tend)return "";
	if (s[sidx] == t[tidx])return s[sidx] + build(sidx + 1, tidx + 1);
	if (solve(sidx + 1, tidx) == res[sidx][tidx])return build(sidx + 1, tidx);
	else return build(sidx, tidx + 1);
}
//</FUNCTIONS>	
int main() {
	Fast();
	cin >> s >> t;
	send = s.size(), tend = t.size();
	memset(res, -1, sizeof(res));
	solve();
	cout << build() << endl;
}

Measured memory_bytes: 39260
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define repr(i, n, m) for (int i = (int)(n) - 1; i >= (int)(m); i--)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7

int main() {
    double a, b, h, m;
    cin >> a >> b >> h >> m;

    double theta = abs(11 * m - 60 * h) * M_PI / 360;
    double ans = sqrt(a * a + b * b - 2 * a * b * cos(theta));
    cout << fixed << setprecision(15) << ans << endl;
}


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

#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using int32 = int;
using int64 = long long;

const int   mod   = 1e9 + 7;
const int32 inf   = 1001001001;
const int64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup;

template <typename T = int64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solver() {
    int N = input(), M = input();
    vector< pair< int, int > > v(M);
    cin >> v;

    whole(sort, v);

    int ans = 0;
    int cut = inf;
    for (auto p : v) {
        int a = p.first, b = p.second;

        if (~cut && cut <= a) {
            ans++;
            cut = b;
        } else {
            chmin(cut, b);
        }
    }
    ans++;

    cout << ans << endl;
}

signed main(int argc, char *argv[]) {
  solver();
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100

int N, M;
vector<int> Ons[MAX_N]; // 電球 i の ON になっているスイッチの数
vector<int> P;

signed main()
{
    cin >> N >> M;
    REP(i, M) {
        int k;
        cin >> k;
        REP(j, k) {
            int s;
            cin >> s;
            s--;
            Ons[i].push_back(s);
        }
    }
    P.resize(M);
    REP(i, M) {
        cin >> P[i];
    }

    int ans = 0;
    for(int pat = 0; pat < (1 << N); ++pat) {
        bool isAll = true;
        REP(i, M) {
            int sum = 0;    // 電球 i について on になっているスイッチの数
            for(auto& on : Ons[i]) {
                if( (pat >> on) & 1) {
                    sum++;
                }
            }
            if( sum % 2 != P[i]) {
                isAll = false;
                break;
            }
        }
        if(isAll) { ans++; }
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, k, n) for (int i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int>> pipii;
typedef priority_queue<pii, vector<pii>, greater<pii>> minpq;
typedef priority_queue<pii> maxpq;
//const double PI = acos(-1);
const int mod =1000000007;

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

template <typename T, typename V>
void __print(const pair<T, V> &x)
{
	cerr << '{';
	__print(x.first);
	cerr << ',';
	__print(x.second);
	cerr << '}';
}
template <typename T>
void __print(const T &x)
{
	int f = 0;
	cerr << '{';
	for (auto &i : x)
		cerr << (f++ ? "," : ""), __print(i);
	cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v)
{
	__print(t);
	if (sizeof...(v))
		cerr << ", ";
	_print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)               \
	cerr << "[" << #x << "] = ["; \
	_print(x)
#else
#define debug(x...)
#endif
// ----------------------DEBUG TEMPLATE--------------------------



void lcs(string a,string b){

	int x = a.length();
	int y = b.length();
	int dp[x+1][y+1];
	for(int i =0;i <=x;i++){
		dp[i][0]=0;
	}
	for(int i =0;i <=y;i++){
		dp[0][i]=0;
	}
	for(int i =1;i <=x;i++){
		for(int j =1;j <=y;j++){
			if(a[i-1]==b[j-1]){
				dp[i][j] = dp[i-1][j-1]+1;
			}
			else{
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	string res="";
	int i = x;int j = y;
	while(i>0 && j>0){
		if(a[i-1]==b[j-1]){
			res+=a[i-1];
			i--;
			j--;
		}
		else{
			if(dp[i-1][j] > dp[i][j-1]){
				i--;
			}
			else{
				j--;
			}
		}
	}
	reverse(all(res));
	cout<<res<<endl;



}




int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	string a,b;
	cin>>a>>b;
	lcs(a,b);

}
	

Measured memory_bytes: 74016
#define _USE_MATH_DEFINES

typedef long long ll;

#include <iostream>
#include <math.h>
#include <climits>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <map> 
#include <set>
#include <string>
using namespace std;

/* sample input

*/


int main()
{
	string str;
	cin >> str;
	int length = str.length();

	char ch[200];

	for (int i = 0; i < length; i++){
		ch[i] = str[i];
	}


	int answer=0;
	for (int i = length / 2-1; i >= 1; i--){
		int flug = 0;
		for (int j = 0; j < i; j++){
			if (ch[j] != ch[j + i]){
				flug = 1;
				break;
			}
		}
		if (!flug){
			answer = i;
			break;
		}
	}

	cout << answer*2;

	return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for(ll i = n-1; i >= 0LL; i--)
#define FOR(i, n, m) for(ll i = n; i < (ll)(m); i++)
#define PRINT(x) cout << x << endl
#define ALL(v) v.begin(), v.end()
#define INF (ll)1e18
#define INFD 1e18
#define PI 3.14159265358979
#define MOD 1000000007
// #define MOD 998244353
#define VL vector<ll>

vector<ll> dx = {-1, 1, 0,  0, -1, -1,  1, 1};
vector<ll> dy = { 0, 0, 1, -1, -1,  1, -1, 1};

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



template< typename T >
struct edge {
	int src, to;
	T cost;

	edge(int to, T cost) : src(-1), to(to), cost(cost) {}

	edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

	edge &operator=(const int &x) {
		to = x;
		return *this;
	}

	operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
/*
WeightedGraph<ll> g(V);
g[a].emplace_back(b, c);
*/
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;


template< typename T >
void dijkstra(WeightedGraph< T > &g, vector< T > &dist, vector< T > &prev, vector< T > &num, int s) {
	T N = g.size();
	dist.resize(N, INF);
	prev.resize(N, -1); // 初期化
	num.resize(N, 0);
	using Pi = pair< T, int >;
	priority_queue< Pi, vector< Pi >, greater< Pi > > que;
	dist[s] = 0;
	que.emplace(dist[s], s);
	while(!que.empty()) {
	T cost;
	int idx;
	tie(cost, idx) = que.top();
	que.pop();
	if(dist[idx] < cost) continue;
	for(auto &e : g[idx]) {
		auto next_cost = cost + e.cost;
		if(dist[e.to] < next_cost) continue;
		if (dist[e.to] == next_cost) {
			num[e.to] += num[idx];
			num[e.to] %= MOD;
			continue;
		}
		dist[e.to] = next_cost;
		prev[e.to] = idx; // 頂点 v を通って e.to にたどり着いた
		num[e.to] = num[idx];
		que.emplace(dist[e.to], e.to);
	}
	}
	return;
}

/* get_path(prev, t)
	入力：dijkstra で得た prev, ゴール t
	出力： t への最短路のパス
*/
template< typename T >
vector<T> get_path(const vector<T> &prev, T t) {
	vector<T> path;
	for (T cur = t; cur != -1; cur = prev[cur]) {
		path.push_back(cur);
	}
	reverse(path.begin(), path.end()); // 逆順なのでひっくり返す
	return path;
}

int main()
{
	ll N, u, v;
	cin >> N >> u >> v;
	u--; v--;
	if (N == 2) {
		PRINT(0);
		return 0;
	}
	WeightedGraph<ll> G(N);
	REP(i, N-1) {
		ll a, b;
		cin >> a >> b;
		a--; b--;
		G[a].emplace_back(b,1);
		G[b].emplace_back(a,1);
	}
	vector<ll> dist1, prev1, num1;
	dijkstra(G,dist1,prev1,num1,u);
	vector<ll> dist2, prev2, num2;
	dijkstra(G,dist2,prev2,num2,v);
	// REP(i, N) cout << dist1[i] << " ";
	// cout << endl;
	// REP(i, N) cout << dist2[i] << " ";
	// cout << endl;
	ll ma = 0;
	REP(i, N) {
		if (dist1[i] < dist2[i]) {
			ma = max(ma, dist2[i]);
		}
	}
	PRINT(ma-1);
	return 0;
}


Measured memory_bytes: 12868
while True:
    n = input()
    if n == "-":
        break
    
    h = int(input())
    count = 0
    for i in range(h):
        count += int(input())
        
    for i in range(len(n)):
        print("%s" %(n[((count%len(n))+i)%len(n)]), end="")
    print()


Measured memory_bytes: 5620
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

bool is_prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n%i == 0) return false;
	}
	return n != 1;  // 1の場合は例外
}

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

	int cnt=0;
	for (int i = 2; i <= 55555; i++) {
		if (is_prime(i)) {
			if (i % 10 == 1) {
				cout << i <<" ";
				cnt++;
			}
		}
		if(cnt==N) break;
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
using namespace std;

int find_L(string s, int offset)
{
    int len = s.length();
    for (int i = offset; i < len; i++) {
        if (s[i] == 'L')
            return i;
    }
    return -1;
}

void update_R(vector<int> &a, string s)
{
    int len = s.length();
    int pos = 0;
    while (pos < len) {
        if (s[pos] == 'L') {
            pos++;
            continue;
        }
        int l = find_L(s, pos);
        if ((l - pos) % 2 == 0) {
            a[l] += (l - pos) / 2;
            a[l-1] += (l - pos) / 2;
        } else {
            a[l] += (l - pos) / 2;
            a[l-1] += (l - pos) / 2 + 1;
        }
        pos = l + 1;
    }
}

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

    int len = s.length();
    vector<int> a(len);
    vector<int> b(len);
    for (int i = 0; i < len; i++) {
        a[i] = 0;
        b[i] = 0;
    }

    update_R(a, s);

    reverse(s.begin(), s.end());
    for (int i = 0; i < len; i++)
        s[i] = (s[i] == 'L') ? 'R' : 'L';

    update_R(b, s);

    for (int i = 0; i < len; i++) {
        a[i] += b[len - i - 1];
    }

    for (int i: a)
        cout << i << " ";

    cout << endl;
}

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

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

int H, W;
bool s[52][52] = {0}; // true: black, false: white

bool check(int y, int x) {
  return (s[y-1][x] || s[y+1][x] || s[y][x-1] || s[y][x+1]);
}

int main() {
  scanf("%d%d", &H, &W);
  char buf[51];
  FOR(y,1,H+1) {
    scanf("%s", buf);
    FOR(x,1,W+1) if (buf[x-1] == '#') s[y][x] = true;
  }

  FOR(y,1,H+1) FOR(x,1,W+1) {
    if (s[y][x] && !check(y,x)) {
      printf("No\n");
      return 0;
    }
  }

  printf("Yes\n");
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,no-stack-protector,fast-math")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 2e5 + 5, M = 2 * N + 5;

char s[N];
int cnt[26];

int main(){
    scanf("%s", s);
    int n = strlen(s);
    for(int i = 0 ; i < n ; ++i)
        ++cnt[s[i] - 'a'];
    for(int i = 0 ; i < 26 ; ++i)
        if(cnt[i] & 1)
            exit((puts("No"), 0));
    puts("Yes");
}

Measured memory_bytes: 256
#!/usr/bin/ruby
n,*a=`dd`.split.map &:to_i
a[c=0]=r=1
(1...n).each{|i|
	if a[i]>=2+d=a[i-1]
		a[i]=2+d
	else
		a[i]=d
		r*=i+2-c+=1
	end
}
p (1..n-c).reduce(r){|s,i|s*i%(10**9+7)}

Measured memory_bytes: 83120
#include<bits/stdc++.h>
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define INF 1e10
using namespace std;
const int maxn = 1e7+10;
int n,m,a[maxn],b[maxn];
map<int,int >T;
int32_t main(){
    IOS;
    cin>>n;
    int nn=sqrt(n);
    int ans=0;
    fu(i,1,nn)
    {
        if(i*i+i*2>n)continue;
        if(n/i*i==n)
        {
            ans+=n/i-1;
        }
    }
    cout<<ans;

    return 0;
}


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

using namespace std;

int main()
{
	int k;
	string s;
	cin>>k;
	cin>>s;
	for (int i=0; i<min(k, (int)s.size()); i++) cout<<s[i];
	if (k < s.size()) cout<<"..."<<endl;
	return 0;
}

Measured memory_bytes: 3628
import sys
input = sys.stdin.readline
import itertools
import bisect

def main():
    N = int(input())
    L = [int(x) for x in input().split()]
    ans = 0
    L_sorted = sorted(L)
    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            a = L_sorted[i]
            b = L_sorted[j]
            l = bisect.bisect_left(L_sorted, max(a - b, b - a), lo=j + 1)
            r = bisect.bisect_left(L_sorted, a + b, lo=j + 1)
            ans += r - l

    print(ans)



    

if __name__ == '__main__':
    main()



Measured memory_bytes: 44892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 505;
const int mod = 1e9 + 7;
int d[maxn][maxn];
int n, m, q, l, r;
int main() {
    cin >> n >> m >> q;
    while(m--) cin >> l >> r, d[l][r]++;
    for(r = 0; r <= 500; ++r) {
        for(l = 500; l >= 0; --l) {
            if(r == 0) d[l][r] += d[l+1][r];
            else d[l][r] += d[l+1][r]+d[l][r-1]-d[l+1][r-1];
        }
    }
    while(q--) cin >> l >> r, cout << d[l][r] << endl;
    return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF LLONG_MAX/10
#define rep(i,n) for(int i=0;i<n;i++)
#define krep(i,k,n,m) for(int i=k;i<n;i+=m)
#define erep(i,k,n) for(int i=k;i<n;i++)
#define mod 1000000007
//最大公約数
int gcd(int s,int b){
    if(b==0)return s;
    return gcd(b,s%b);
}
signed main(){
    int n;
    cin>>n;
    int a[n];
    rep(i,n){
        cin>>a[i];
    }
    sort(a,a+n);
    int ans=0,kai=1;
    rep(i,n-1){
        if(a[i]==a[i+1]){
            ans++;
        }
    }
    rep(i,n-1){
        if(a[i]!=a[i+1]){
            kai++;
        }
    }
    if(ans%2==0){
        cout<<kai<<endl;
    }
    else{
        cout<<kai-1<<endl;
    }
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
long long int fie[101][21];
int main(){
    long long int N,a;
    cin>>N;
    cin>>a;
    fie[0][a]=1;
    for(int i=1;i<N-1;i++){
        cin>>a;
        for(int j=0;j<=20;j++){
            if(0<=j-a)fie[i][j]+=fie[i-1][j-a];
            if(j+a<=20)fie[i][j]+=fie[i-1][j+a];
        }
    }
    cin>>a;
    cout<<fie[N-2][a]<<endl;
    return 0;
}

Measured memory_bytes: 1172
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset

using namespace std;

int main() {

	int a[51],sum,n,flag=0,m,count=0;

	cin >> n ;


	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] != i + 1)count++;
	}

	if(count==2||count==0)cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

#define MAXLEVEL 30

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

	long long n, i, j, k, ans, ca, cb, x;
	cin >> n;
	vector<long long> a(n), b(n), aa(n), bb(n);
	vector<long long>::iterator p1, p2, p3, p4;
	for (i = 0; i < n; i++) cin >> a[i];
	for (i = 0; i < n; i++) cin >> b[i];
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	ans = 0;
	for (i = 0; i < MAXLEVEL - 1; i++) {
		x = 1 << i;
		ca = 0;
		for (j = 0; j < n; j++) aa[j] = a[j] % (2 * x);
		for (j = 0; j < n; j++) bb[j] = b[j] % (2 * x);
		sort(bb.begin(), bb.end());
		for (j = 0; j < n; j++) {
			p1 = lower_bound(bb.begin(), bb.end(), x - aa[j]);
			p2 = lower_bound(bb.begin(), bb.end(), 2 * x - aa[j]);
			p3 = lower_bound(bb.begin(), bb.end(), 3 * x - aa[j]);
			p4 = lower_bound(bb.begin(), bb.end(), 4 * x - aa[j]);
			ca += (p2 - p1) + (p4 - p3);
		}
		if (ca % 2 == 1) ans += x;
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 6528
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


ll getTwo(ll x){
  ll ans = 0;
  while(x % 2 == 0)
  {
    ans ++;
    x /=2;
  }
  return ans;
}

bool compare(pl x, pl y){
  if(x.second > y.second) return true;
  if(x.second == y.second && x.first > y.first) return true;
  return false;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll n,k;
    cin >> n >> k;
    ll a[n];
    vpl v;
    map<ll,ll> dic;
    rp(i,n) {
      cin >> a[i];
      dic[a[i]]++;
    }

    for (auto it = dic.begin(); it != dic.end(); it++) {
      v.pb(mp(it->f,it->s));
    }
    sort(all(v),compare);
    ll counter = 0;
    ll ans = 0;
    for (auto it = v.begin(); it != v.end(); it++) {
      counter ++;
      if(counter > k)
        ans += it->second;
    }
    cout << ans << endl;

    return 0;

}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

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

    LL ans = 0;
    for(int i = 1; i <= n; i++)
        if(i % 3 && i % 5)
            ans += i;

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include<cmath>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;

int main(){
    int M,D;
    cin >> M >> D;
    
    int ans = 0;
    for(int i = 1;i <= M;i++){
        for(int j = 10;j <= D;j++){
            if(j%10 >= 2){
                if(j/10 >= 2){
                    if((j%10)*(j/10) == i){
                        ans++;
                    }
                }
            }
        }
    }
    cout << ans << endl;
}


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

int main(void) {
    int n;
    cin >> n;
    int a[n+1];
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    int searching = 1;
    bool not_succeed = true;
    for (int i = 1; i <= n; i++) {
        if (a[searching] == 2) {
            not_succeed = false;
            cout << i << endl;
            break;
        } else {
            searching = a[searching];
        }
    }

    if (not_succeed) {
        cout << -1 << endl;
    }
}

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

int main() {
    long long a, b, n;
    cin >> a >> b >> n;
    if (n >= b) {
        n = b - 1;
    }
    cout << ((a * n) / b - a * (n / b)) << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
using namespace std;


int main()
{
	int n;
	cin >> n;
	vector<double>x(n);
	vector<string>u(n);
	for (int i = 0; i < n; i++)cin >> x[i] >> u[i];
	for (int i = 0; i < n; i++) {
		if (u[i] == "BTC") {
			x[i] *= 380000.0;
		}
	}
	cout << fixed << setprecision(8) << accumulate(x.begin(), x.end(), 0.0) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    string s;
    cin >> s;
    cout << (s.size() >= 4 && s.substr(0, 4) == "YAKI" ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto s = readln.chomp.dup, ns = s.length;
  auto t = readln.chomp, nt = t.length;

 loop: foreach_reverse (i; 0..ns-nt+1) {
    foreach (j; 0..nt)
      if (s[i+j] != '?' && s[i+j] != t[j]) continue loop;

    s[i..i+nt][] = t[];
    writeln(s.replace("?", "a"));
    return;
  }
  writeln("UNRESTORABLE");
}


Measured memory_bytes: 256
from sys import stdin
n = int(stdin.readline())
a = [int(stdin.readline()) for _ in xrange(n)]
b = [a[0::2], a[1::2]]
ans = t = 0
a.sort()
d = dict()
for x in a:
    d[x] = t
    t = 1 - t
for i, l in enumerate(b):
    for x in l:
        ans += d[x] ^ i
print ans / 2


Measured memory_bytes: 16052
#include<stdio.h>
#include<algorithm>
#include<functional>
int n,k;
int c,g;
int hon[11][2001];
int i,j;
using namespace std;
int main(void){
	scanf("%d %d",&n,&k);
	for(i=1;i<=10;i++){
		for(j=0;j<=n;j++){
			hon[i][j]=0;
		}
	}
	int cnt[11];
	for(i=1;i<=10;i++){
		cnt[i]=0;
	}
	for(i=0;i<n;i++){
		scanf("%d %d",&c,&g);
		hon[g][cnt[g]]=c;
		cnt[g]++;
	}
	int temp[2001];
	for(i=1;i<=10;i++){
		for(j=0;j<=cnt[i];j++){
			temp[j]=0;
			temp[j]=hon[i][j];
		}
		sort(temp,temp+cnt[i],greater<int>());
		for(j=0;j<=n;j++){
			hon[i][j]=temp[j];
		}
	}
	for(i=1;i<=10;i++){
		for(j=0;j<=cnt[i];j++){
			if(hon[i][j]!=0){
				if(j==0){
					hon[i][j]=hon[i][j];
				}
				else {
					hon[i][j]=hon[i][j]+hon[i][j-1];
					hon[i][j]+=j+1*j;
				}
			}
		}
	}
	int hon1[11][2001];
	for(i=1;i<=10;i++){
		for(j=0;j<=k;j++){
			if(hon[i][j]!=0){
				hon1[i][j+1]=hon[i][j];
			}
			else {
				break;
			}
		}
	}
	int dp[11][2001];
	for(i=0;i<=10;i++){
		for(j=0;j<=k;j++){
			if(j==0){
				dp[i][j]=0;
			}
			else {
				dp[i][j]=-1;
			}
		}
	}
	int m;
	for(i=0;i<10;i++){
		for(j=0;j<=k;j++){
			if(dp[i][j]!=-1){
				for(m=1;m<=k;m++){
					if(dp[i+1][j+m]<hon1[i+1][m]+dp[i][j] && j+m<=k && hon1[i+1][m]!=0){
						dp[i+1][j+m]=hon1[i+1][m]+dp[i][j];
					}
					if(hon1[i+1][m]==0){
						break;
					}
				}
			}
		}
		for(j=0;j<=2000;j++){
			if(dp[i+1][j]<dp[i][j]){
				dp[i+1][j]=dp[i][j];
			}
		}
	}
	int max=0;
	for(i=0;i<=k;i++){
		if(max<dp[10][i]){
			max=dp[10][i];
		}
	}
	/*for(i=0;i<=3;i++){
		for(j=0;j<=10;j++){
			printf("%d ",dp[i][j]);
		}
		printf("\n");
	}*/
	printf("%d\n",max);
	return 0;
}

Measured memory_bytes: 1276
#include<iostream>
#include<cmath>
#include <limits>
using namespace std;
int main()
{   int N,k;
    cin>>N>>k;
    int height[N],dp[N];
    for(int i=0;i<N;i++)
     { 
        cin>>height[i];
     }
    dp[0]=0;
    dp[1]=abs(long(height[1]-height[0]));
    for(int x=2;x<N;x++)
    { int upper=min(x,k),min=2147483647;
      for(int i=1;i<=upper;i++)
       {  int value;
          value=dp[x-i]+abs(long(height[x]-height[x-i]));
           if(value<min)
            { min=value;}

       }
       dp[x]=min;
    }
   cout<<dp[N-1];
   system("pause");
    return 0;
}

Measured memory_bytes: 1272
n = int(input())
a,b,c=0,0,0
for i in range(n):
    t,x,y = map(int, input().split())
    sa = t-a
    if sa<abs(x-b)+abs(y-c):
        print("No")
        exit()
    else:
        tw = sa-abs(x-b)-abs(y-c)
        if tw%2!=0:
            print("No")
            exit()
    a,b,c=t,x,y
print("Yes")


Measured memory_bytes: 3060
K = int(input())

l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(l[K-1])

Measured memory_bytes: 3316
import itertools

N = int(input())
P = [int(x) for x in input().split()]
Q = [int(x) for x in input().split()]

a = 0
b = 0
j = 0
for i in itertools.permutations([int(x+1) for x in range(N)]):
    j += 1
    if(list(i) == P) :
        a = j
    if(list(i) == Q) :
        b = j

print(abs(a-b))

Measured memory_bytes: 9028
#include<iostream>
#include<vector>
#include<algorithm>
struct Data{
  int w;
  int d;
  Data(int ww,int dd):w(ww),d(dd){}
  Data(){}
  int getArea(){ return d*w;}
};

bool operator<(Data d1,Data d2){
  return (d1.getArea() < d2.getArea());
}

using namespace std;

int main(){
  int n,w,d;
  while(cin>>n>>w>>d,n+w+d){
    vector<Data> v;
    v.reserve(n+1);
    v.push_back(Data(w,d));
    for(int i=0;i<n;i++){
      int p,s;
      cin>>p>>s;
      p--;
      Data data=v[p];
      for(int j=p;j<i;j++){
	//	swap(v[j],v[j+1]);
	v[j]=v[j+1];
      }
      s = s%(data.d+data.w);
      Data ddd;
      if(s < data.w){
	ddd = Data(data.w-s,data.d);
	data.w = s;
      }else if(data.w < s && s < data.d+data.w){
	ddd = Data(data.w,s-data.w);
	data.d = data.w+data.d-s;
      }else if(data.w+data.d < s && s < 2*data.w+data.d){
	ddd = Data(s-data.w-data.d,data.d);
	data.w = 2*data.w+data.d-s;
      }else{
	ddd = Data(data.w,s-2*data.w-data.d);
	data.d = 2*data.d+2*data.w-s;
      }
      if(data.w*data.d > ddd.w*ddd.d) swap(data,ddd);
      v[i]=data;
      v.push_back(ddd);
    } 
    sort(v.begin(),v.end());
    for(int i=0;i<n;i++){
      cout<<v[i].getArea()<<' ';
    }
    cout<<v[n].getArea()<<endl;
  }
  return 0;
}

Measured memory_bytes: 1200
#include <iostream>
using namespace std;
int main() {
 long long n, fl[10][10], ans = 0; cin >> n;
 for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) fl[i][j] = 0;
 for (int i = 1; i <= n; i++) {
   	int x = i;
   	while (x>=10) x/=10;
   	fl[x][i%10]++;
 }
 for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) ans += fl[i][j]*fl[j][i];
 cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    vector<int> a(n+1);
    int i;
    for(i=1; i<=n; i++) {
        scanf("%d", &a[i]);
    }

    vector<vector<int> > z(n+1);
    for(i=1; i<=n; i++) {
        int k=i+i;
        while(k<=n) {
            z[k].push_back(i);
            k+=i;
        }
    }

    vector<int> ans;
    for(i=n; i>=1; i--) {
        if(a[i]) {
            ans.push_back(i);

            int k;
            for(k=0; k<(int)z[i].size(); k++) {
                a[z[i][k]]=1-a[z[i][k]];
            }
        }
    }

    reverse(ans.begin(), ans.end());
    printf("%d\n", ans.size());
    for(i=0; i<(int)ans.size(); i++) {
        printf("%d\n", ans[i]);
    }


    return 0;
}



Measured memory_bytes: 23544
L = int(input().strip())
for _ in range(0,L):
    gx,gy = map(int,input().strip().split(" "))
    heiankyo = [[0 for j in range(0,gx+1)] for i in range(0,gy+1)]
    heiankyo[0][0] = 1
    P = int(input())
    matatabi = []
    for p in range(P):
        x1,y1,x2,y2 = map(int,input().strip().split(" "))
        l = [[y1,x1],[y2,x2]]    
        l.sort()
        matatabi.append(l)
    for i in range(1,gy+1):
        if not [[i-1,0],[i,0]] in matatabi:
            heiankyo[i][0] = heiankyo[i-1][0]
    for j in range(1,gx+1):
        if not [[0,j-1],[0,j]] in matatabi:
            heiankyo[0][j] = heiankyo[0][j-1]
    for i in range(1,gy+1):
        for j in range(1,gx+1):
            if not [[i-1,j],[i,j]] in matatabi:
                heiankyo[i][j] = heiankyo[i][j] + heiankyo[i-1][j]
            if not [[i,j-1],[i,j]] in matatabi:
                heiankyo[i][j] = heiankyo[i][j] + heiankyo[i][j-1]
    if heiankyo[gy][gx] == 0:
        print("Miserable Hokusai!")
    else:
        print(heiankyo[gy][gx])


Measured memory_bytes: 5620
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <limits>
#include <set>
#include <iomanip>
 
int main()
{
    int a{}, b{}, c{};
    std::cin >> a >> b >> c;

    if (((a == b) && (b != c)) || ((b == c) && (a != b)) || ((a == c) && (a != b))) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
public class Main {
	 public static void main(String[] args) {
		    java.util.Scanner scanner = new java.util.Scanner(System.in);
		    String n = scanner.next();
		    if (n.contains("9")) {
		    	System.out.println("Yes");
		    } else {
		    	System.out.println("No");
		    }
		 }


}


Measured memory_bytes: 21844
X,Y,Z,K = map(int, input().split())

A = sorted(list(map(int, input().split()))[:K])
B = sorted(list(map(int, input().split()))[:K])
C = sorted(list(map(int, input().split()))[:K])

ab = sorted(list(a+b for a in A for b in B), reverse = True)[:K]
abc = sorted(list(ab+c for ab in ab for c in C), reverse = True)[:K]

for i in abc : 
    print(i)

Measured memory_bytes: 186000
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits>

int main(){
    long N;
    std::cin >> N;
    long h[100];
    for(long i=0; i<N; i++){
        std::cin >> h[i];
    }
    long count=0;
    while(1){
        long l=0;
        long r=N;

        for(long i=0; i<N; i++){
            if(h[i]!=0){
                l=i;
                break;
            }
        }

        for(long j=l+1; j<N; j++){
            if(h[j]==0){
                r=j;
                break;
            }
        }

        long counts=0;
        for(long i=0; i<N; i++){
            if(h[i]==0){
                counts++;
            }
        }
        if(counts==N){
            break;
        }
        for(long i=l; i<r; i++){
            h[i]-=1;
        }
        count++;
    }
    std::cout << count << std::endl;
    return 0;
}

Measured memory_bytes: 3604