akhauriyash/Code-Regression huggingface dataset:
import Control.Applicative
import Control.Monad
import Data.List
import Data.Array
import Data.Char

main = do
  [a, b] <- map (read::String -> Int) . words <$> getLine
  print $ count a b

count::Int -> Int -> Int
count a b
  | a > b = 0
  | otherwise = if isParindrome b then 1 + count a (b - 1) else count a (b - 1)

isParindrome::Int -> Bool
isParindrome x = let one = x `mod` 10
                     ten = (x `div` 10) `mod` 10
                     thousand = (x `div` 1000) `mod` 10
                     tenThousand = (x `div` 10000)
                 in one == tenThousand && ten == thousand

Measured memory_bytes: 508
#include <bits/stdc++.h>
#define repeat(i, n) for(int (i) = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main() {
	ll L, R;
	cin >> L >> R;
	
	R = min(R, L+4038);
	ll result = 2018;
	for(ll i = L; i <= R; i++) {
		for(ll  j = i+1; j <= R; j++) {
			ll x = i * j % 2019;
			result = min(result, x);
		}
	}

	cout << result << endl;
	return 0;
}


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

slime_list = []
slime_list.append(S[0])
pre_color = S[0] # 左隣のスライムの色
for i in range(1,N):
    if pre_color != S[i]:
        slime_list.append(S[i])
        pre_color = S[i]

print(len(slime_list))




Measured memory_bytes: 3956
#include <stdio.h>

int main(){
  char s[1001];
  int i,N,W,E,S;
  scanf("%s",s);
  i=0;N=0;W=0;E=0;S=0;
  while(s[i]!=NULL){
	if(s[i]=='N')N=1;
    if(s[i]=='W')W=-1;
    if(s[i]=='E')E=1;
    if(s[i]=='S')S=-1;
    i++;
  }
  if((N+S)==0 && (W+E)==0)printf("Yes\n");
  else printf("No\n");
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
import sys

def main():
	a, b, c = map(int, input().split(" "))
	
	i = 1
	tmp = []
	while True:
		ans = (i * a) % b
		if ans == c:
			print("YES")
			sys.exit()
		i += 1
		
		if ans in tmp:
			print("NO")
			sys.exit()
		tmp.append(ans)
	
if __name__ == "__main__":
	main()
	

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

today = [int(x) for x in input().split()]

for i in range(nDays - 1):
    tomorrow = [int(x) for x in input().split()]
    tomorrow[0] += max(today[1], today[2])
    tomorrow[1] += max(today[0], today[2])
    tomorrow[2] += max(today[0], today[1])
    today = tomorrow

print(max(today))

Measured memory_bytes: 74632
# import collections

n, m = map(int, input().split())

students = [tuple(map(int, input().split())) for _ in range(n)]
checkpoint = [tuple(map(int, input().split())) for _ in range(m)]

# students.sort()
# checkpoint.sort()

# i, j = 0, 0

# goal = []
# while True:
#     if students[i](0) < checkpoint[j](0):
        
for v_s in students:
    print(min(range(1, m + 1), key=lambda i: abs(checkpoint[i - 1][0] - v_s[0]) + abs(checkpoint[i - 1][1] - v_s[1])))


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

int main()
{
    int n, f, s;
    cin>>n;
    f=n/100;
    s=n%100;
    if(f>0 && f<13 && s>0 && s<13) cout<<"AMBIGUOUS"<<endl;
    else if(f>0 && f<13) cout<<"MMYY"<<endl;
    else if(s>0 && s<13) cout<<"YYMM"<<endl;
    else cout<<"NA"<<endl;

    return 0;
}


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

struct node{
    struct node *right;
    struct node *left;
    struct node *parent;
    int key;
};

typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){
    while(u!=NULL&&k!=u->key){
        if(k<u->key)
            u=u->left;
        else
            u=u->right;
    }

    return u;
}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
    Node y; // node to be deleted
    Node x; // child of y



}

void insert(int k){
    Node y = NIL;
    Node x = root;
    Node z;

    z = malloc(sizeof(struct node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while(x!=NULL){
        y=x;
        if(z->key<x->key)
            x=x->left;
        else
            x=x->right;
    }

    z->parent=y;

    if(y==NULL)
        root=z;
    else if(z->key<y->key)
        y->left=z;
    else
        y->right=z;

}

void inorder(Node u){
    if(u!=NULL){
        inorder(u->left);
        printf(" %d",u->key);
        inorder(u->right);
    }

}
void preorder(Node u){
    if(u!=NULL){
        printf(" %d",u->key);
        preorder(u->left);
        preorder(u->right);
    }
}


int main(){
    int n, i, x;
    char com[20];
    scanf("%d", &n);

    for ( i = 0; i < n; i++ ){
        scanf("%s", com);
        if ( com[0] == 'f' ){
            scanf("%d", &x);
            Node t = treeSearch(root, x);
            if ( t != NIL ) printf("yes\n");
            else printf("no\n");
        }
        else if ( com[0] == 'i' ){
            scanf("%d", &x);
            insert(x);
        }
        else if ( com[0] == 'p' ){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
        else if ( com[0] == 'd' ){
            scanf("%d", &x);
            treeDelete(treeSearch(root, x));
        }
    }

    return 0;
}



Measured memory_bytes: 20472
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define swap(p,q) r=(p);(p)=(q);(q)=r
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007
#define MODANOTHER 998244353
#define PI acos(-1)

using namespace std;



int main(void)
{
	//変数の宣言
	int n,m,p;
	int a[310][310];
	int kyogi[310];

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	int ans=0;
	int count=0;
	ll int temp,temp1,temp2;
	int max,min;
	int len;
	int sum=0;
	int ok,ng;



	//データの読み込み


	scanf("%d %d",&n,&m);
//	scanf_s("%d %d",&n,&m);

	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%d",&a[i][j]);
//			scanf_s("%d",&a[i][j]);
			a[i][j]--;
		}
	}


	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

	ans=INFINT;

	for(k=0;k<m;k++){
		for(i=0;i<m;i++){
			kyogi[i]=0;
		}
		for(i=0;i<n;i++){
			kyogi[a[i][0]]++;
		}
		temp=0;
		for(i=0;i<m;i++){
			if(temp<kyogi[i]){
				temp=kyogi[i];
				temp2=i;
			}
		}

		ans=min(ans,temp);

		for(i=0;i<n;i++){
			flag=0;
			for(j=0;j<m-1;j++){
				if(flag==0&&a[i][j]==temp2){
					flag=1;
				}
				if(flag==1){
					a[i][j]=a[i][j+1];
				}
			}
		}
	}


	//	printf("計算部分終了\n");

	//出力


	printf("%d",ans);


	//	printf("結果の出力終了\n");


	return 0;
}



Measured memory_bytes: 640
package main
import (
  "fmt"
  "sort"
)

func main() {
  var n int
  fmt.Scan(&n)
  a := aArray(n)
  b := make([]int, 0)
  for _, v := range a {
    b = append(b, v)
  }
  sort.Sort(sort.IntSlice(b))
  size := len(b)
  max := b[size-1]
  big := b[size-2]
  ind := index(max, a)
  if max == big {
    for i := 0; i < n; i++{
      fmt.Println(max)
    }
    }else{
    for i := 0; i < n; i++{
        if i == ind {
          fmt.Println(big)
        }else{
          fmt.Println(max)
        }
      }
    }
}

func aArray(n int) []int{
  var d int
  a := make([]int, 0)
  for i := 0; i < n; i++ {
    fmt.Scan(&d)
   	a = append(a, d)
  	}
  return a
}
  

func index(m int, a []int) int {
  var ind int
  for i, v := range a {
    if ind == 0 {
      switch {
    	case v == m :
      		ind = i
      }
    }
  }
  return ind
}

Measured memory_bytes: 11008
/**
 *      purpose : ABC 85 D
 *      author  : kyomukyomupurin
 *      created : 2018-11-08 20:06:21
**/
 
#include <bits/stdc++.h>
using namespace std;
#define int64 long long
#define print(x) cout << (x) << '\n'
 
inline int divide(int x, int y){
    if (x % y == 0) return x / y;
    else return x / y + 1;
}
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N, H; scanf("%d %d", &N, &H);
  	int a = 0;
	int b[N] = {};
    for (int i = 0; i < N; ++i) {
      	int ta, tb; scanf("%d %d", &ta, &tb);
    	a = max(a, ta); b[i] = tb;
    }
 
    sort(b, b + N);
    auto it = lower_bound(b, b + N, a);     // a の max(x) より大きい b は投げる
 
    int temp = 0; int cnt = 0;
 
    for (int i = N - 1; i >= (int) (it - b); --i){
        temp += b[i]; ++cnt;
        if (temp >= H){
            print(cnt); return 0;
        }
    }
    print(cnt + divide((H - temp), a));
    
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define gcd __gcd
#define pcount __builtin_popcount
#define pcountll __builtin_popcountll
#define nxtperm next_permutation
//primitive roots: 998244353 - 3; 7340033 - 5
//#pragma 03
//#pragma GCC target ("sse4.2")

const ll mod = 1000000007;		const double PI = acos(-1.);
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef complex<double> cd;

struct custom_hash
{
    static uint64_t splitmix64(uint64_t x)
	{
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const
	{
        static const uint64_t kawaii = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + kawaii);
    }
};

const int maxn = 1e5 + 100; 
int h[maxn], dp[maxn]; 
signed main()
{
//	freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);
// 	fast_cin();
	int n, k;
	cin >> n >> k;
	for(int i=1;i<=n;i++) cin >> h[i]; 
	dp[1] = 0; 
	for(int i=2;i<=n;i++)
	{
		dp[i] = 1e9; 
		for(int j=(max(1, i-k));j<i;j++) 
		{
			dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j])); 
		}
	}
	cout << dp[n];  
}

/*
	Test input:
*/


Measured memory_bytes: 1024
#各桁の和を計算する関数
def findSumOfDigits(n):
  sum = 0
  while( n > 0):
    sum += int(n) % 10
    n = int(n) / 10
  return int(sum)

N,A,B = [int(i) for i in input().rstrip().split()]

total = 0
for i in range(1,N+1):
  sum = findSumOfDigits(i)
  if sum >= A and sum <= B:
    total += i

print(total)


Measured memory_bytes: 3060
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}
const int dm = 1400000;
char dn[dm], * di = dn;
const int MAX = 20000;
class unko {
public:
	char C[MAX * 6 + 10];
	int K[MAX + 10];
	constexpr unko() : C(), K() {
		auto di = C + 1;
		C[0] = '0';
		K[0] = 0;
		K[1] = 1;
		rep1(i, MAX) {
			int X = i;
			int keta = 0;
			char c[10] = {};
			while (X) {
				*(c + keta) = '0' + X % 10;
				X /= 10;
				keta++;
			}
			for (int j = keta - 1; j >= 0; j--)* di++ = (*(c + j));
			K[i + 1] = K[i] + keta;
		}
	}
};
constexpr unko f;
inline void putint(ll X) {
	if (X > 20000) {
		int ue = X / 10;
		for (int i = f.K[ue]; i < f.K[ue + 1]; i++)* di++ = f.C[i];
		*di++ = '0' + (X - ue * 10);
	}
	else for (int i = f.K[X]; i < f.K[X + 1]; i++)* di++ = f.C[i];
	*di++ = '\n';
}

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


	int N = getint(), K = getint();

	int A[200001];
	rep(i, N) A[i] = getint();
	ll owa = ll(N) * N;

	rep(p, K) {
		int B[200001] = {};
		rep(i, N) {
			B[max(0, i - A[i])]++;
			B[min(N, i + A[i] + 1)]--;
		}
		ll kei = B[0];
		A[0] = B[0];
		rep1(i, N - 1) {
			kei +=(A[i] = A[i - 1] + B[i]);
		}
		if (kei == owa) break;
	}

	rep(i, N) putint(A[i]);
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 6792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long ans = 0;
		if(0 < x % 11 && x % 11 <= 6) ans = x / 11 * 2 + 1;
		else if(x % 11 > 6) ans = x / 11 * 2 + 2;
		else if(x % 11 == 0) ans = x / 11 * 2;
		System.out.println(ans);
	}
}


Measured memory_bytes: 23892
#include<cstdio>
#include<algorithm>
#include<cmath>
#define ll __int128
using namespace std;
inline void in(ll &x){x=0;char c;bool f=0;while((c=getchar())>'9'||c<'0')if(c=='-')f=!f;x=c-48;while((c=getchar())<='9'&&c>='0')x=x*10+c-48;if(f)x=-x;}
inline void out(ll x){if(x<0)putchar('-');if(x>9)out(x/10);putchar(x%10+48);}
inline void outn(ll x){out(x);printf("\n");}
int log(ll x){ll p=2,s=0;while(p<=x){s++;p<<=1;}return s;}
int main(){
	ll x,y;
	in(x);in(y);
	outn(log(y/x)+1);
}


Measured memory_bytes: 128
import itertools


N=int(input())
P=tuple(map(int,input().split()))
Q=tuple(map(int,input().split()))

l=[i for i in range(1,N+1)]
p =list(itertools.permutations(l, N))
P_n=p.index(P)
Q_n=p.index(Q)
print(abs(P_n-Q_n))

Measured memory_bytes: 8180
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string.h>
#include <vector>
#include <cmath>
#include <iostream>
using namespace std;
typedef unsigned long long ui64;
typedef long long i64;
void Acrostic() {
	string S;
	cin >> S;
	int w;
	cin >> w;
	int si = S.size();
	int tw = 0;
	string s = "";
	while (tw < si)
	{
		s += S[tw];
		tw += w;
	}
	cout << s;
}
int main() {

	Acrostic();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;
vector<pair<int,int>> G[100];
vector<int> v,gr[50];
int ed[1100];
long long beki[60];
void dfs(int s, int p,int ind,int to){
	if(s==to){
		gr[ind] = v;
	}
	for(auto e:G[s]){
		if(e.first==p) continue;
		v.push_back(e.second);
		dfs(e.first,s,ind,to);
		v.pop_back();
	}
}

int main(){
	int i,j,k,n,m;
	cin >> n;
	for(i=0;i<n - 1;i++){
		int a,b; cin >> a >> b; a--; b--;
		G[a].push_back({b,i}); G[b].push_back({a,i});
	}
	cin >> m;
	for(i=0;i<m;i++){
		int a,b; cin >> a >> b; a--; b--;
		dfs(a,-1,i,b);
	}
	long long x = 1;
	for(i=0;i<n;i++){
		beki[i] = x;
		x *= 2;
	}
	long long ans = 0;
	for(i=0;i<(1<<m);i++){
		for(j=0;j<n - 1;j++){
			ed[j] = 0;
		}
		int cnt = 0,cnt1 = 0;
		for(j=0;j<m;j++){
			if((1<<j) & i){
				cnt1++;
				for(int k:gr[j]){
					ed[k] = 1;
				}
			}
		}
		for(j=0;j<n - 1;j++){
			cnt += ed[j];
		}
		if(cnt1&1) ans -= beki[n - 1 - cnt];
		else ans += beki[n - 1 - cnt];
	}
	cout << ans << endl;
}
	

Measured memory_bytes: 256
#include <chrono>
#include <iostream>

using namespace std;
using namespace std::chrono;

int main() {
  auto start = high_resolution_clock::now();

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int x, t;
  cin >> x >> t;
  cout << max(0, x - t) << endl;

  cerr << "Total execution time : " << duration_cast<milliseconds>(high_resolution_clock::now() - start).count() << " ms" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define inf 1001001001001000
#define mod 1000000007
#define pi 3.1415926535
using namespace std;
ll dp[101][4][2];
int main(void){
    string n;
    cin>>n;
    ll K;
    cin>>K;
    dp[0][0][1] = 1;
    rep(i,n.size()) rep(j,4) rep(k,2){
        rep(l,10){
            ll ni=i+1,nj=j,nk=k;
            if(l != 0) nj++;
            if(nj > K) continue;
            if(k == 1){
                if(l<n[i]-'0') nk = 0;
                if(l>n[i]-'0') continue;
            }
            dp[ni][nj][nk] += dp[i][j][k];
        }
    }
    ll ans = dp[n.size()][K][0]+dp[n.size()][K][1];
    cout<<ans<<endl;
}


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

int main() {
	vector< vector<int> > count(10, vector<int>(10, 0));
	int n; cin >> n;
	
	for(int i = 1; i <= n; i++){
		string i_str = to_string(i);
		int length = i_str.size();
		
		count[i_str[0] - '0'][i_str[length - 1] - '0']++;
	}
	
	long long ans = 0;
	for(int i = 0; i < 10; i++) 
		for(int j = 0; j < 10; j++)
			ans += count[i][j] * count[j][i];
	
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    int x1, x2, x3, x4, y1, y2 ,y3, y4;
    cin >> x1 >> y1 >> x2 >> y2;

    x3 = x2 - (y2 - y1);
    y3 = y2 + (x2 - x1);
    x4 = x3 - (x2 - x1);
    y4 = y3 - (y2 - y1);

    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}


Measured memory_bytes: 256
n = int(input())
ids = []
dists = []
weights = []
for _ in range(n):
  s, d, v = map(int, input().split())
  ids.append(s)
  dists.append(d)
  weights.append(v * 20)

dic = {}
INF = 10 ** 20
def score(rest, pos, total_weight, order):
  if rest == 0:
    return 0, []
  if (rest, pos) in dic:
    return dic[(rest, pos)]

  mask = 1
  ret = (INF, [])
  for i in range(n):
    if rest & mask:
      temp = score(rest & ~mask, i, total_weight + weights[i], order)
      ret = min(ret, (temp[0] + abs(dists[pos] - dists[i]) / 2000 * (total_weight), [i] + temp[1]))
    mask <<= 1
  dic[(rest, pos)] = ret
  return ret

rest = 2 ** n - 1
print(*[ids[i] for i in min([score(rest, i, 70, []) for i in range(n)])[1]])


Measured memory_bytes: 89948
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;

int main(){
	int n,m;cin>>n>>m;int a[m],b[m];vector<int> s(n);
	for(int i=0;i<m;i++) cin>>a[i]>>b[i];
	for(int i=0;i<n;i++) s[i]=i+1;
	int ans=0;
	do{
		//for(int i=0;i<n;i++) cout<<s[i];
		//cout<<endl;
		bool cnt=0;
		for(int j=0;j<n-1;j++){
			bool ans_j=0;
			for(int i=0;i<m;i++){
				if((s[j]==a[i]&&s[j+1]==b[i])||(s[j]==b[i]&&s[j+1]==a[i])){
					ans_j=1;
				}
			}
			if(!ans_j){
				cnt=0;
				break;
			}
			else cnt=1;
		}
		if(cnt) {
			//for(int i=0;i<n;i++) cout<<s[i];
			//cout<<endl;
			ans++;
		}
	}while(next_permutation(s.begin()+1,s.end()));

	cout<<ans<<endl;
}

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

#define ll long long
#define ull unsigned long long 
#define endl '\n'
const int MOD = 1e9+7;

int main(){
    int n;
    cin >> n;
    map<int, int> mp;
    for(int i=0; i<n; ++i){
        int x;
        cin >> x;
        mp[x]++;
    }

    ll ans=1;
    int cnt=0;

    for(auto it=mp.rbegin(); it!=mp.rend(); ++it){
        while(it->second >= 2 && cnt<2){
            ans *= it->first;
            it->second -= 2;
            cnt++;
        }
        if(cnt>2)
            break;
    }
    if(cnt < 2)
        cout << 0;
    else 
        cout << ans;
}


Measured memory_bytes: 8276
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;
using ll = long long;


int main()
{
    int n;
    cin >> n;
    vector<int> prime;
    vector<char> c(50000000);
    

    for(int i = 2; i < 50000000; i++) {
        if(c[i])continue;
        prime.push_back(i);
        for(int j = i; j < 50000000; j += i) {
            c[j] = 1;
        }
    }


    cout << *lower_bound(prime.begin(), prime.end(), n) << endl;
}

Measured memory_bytes: 67560
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)

int main() {
	string s; cin >> s;
	bool valid = false;
	if (s.size() >= 3) {
		rep(i, 0, s.size()) {
			if (s[i] == s[i + 1])
			{
				if (i != s.size() - 1) {
					cout << i + 1 << " " << i + 3 << endl;
				}
				else {
					cout << i << " " << i + 2 << endl;
				}
				return 0;
			}
		}
		rep(i, 0, s.size() - 1) {
			if (s[i] == s[i + 2] && s[i] != s[i + 1]) {
				cout << i + 1 << " " << i + 3 << endl;
				return 0;
			}
		}
	}
	else {
		if (s[0] == s[1])
		{
			cout << 1 << " " << 2 << endl;
			return 0;
		}
	}

	cout << -1 << " " << -1 << endl;

	return 0;
}

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

using namespace std;

const int N = 105, K = 1e5 + 5;
int n, k, dp[K], a[N];

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

	cin>>n>>k;
	for(int i=1;i<=n;++i)cin>>a[i];
	sort(a + 1, a + n + 1);
	
	for(int i=a[1];i<=k;++i){
		bool check = false;
		for(int j=1;j<=n;++j)if(i - a[j] >= 0 && dp[i - a[j]] == 0)
			check = true;
		if(check)dp[i] = 1;
	}
	if(dp[k])cout<<"First\n";
	else cout<<"Second\n";

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(){
    int d; cin >> d;
    cout << "Christmas";
    if(d == 25)cout << endl;
    if(d == 24)cout << " Eve" << endl;
    if(d == 23)cout << " Eve Eve" << endl;
    if(d == 22)cout << " Eve Eve Eve" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll          long long int
#define uu          first
#define vv          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define INF         1e9
#define fastRead    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;

const int MAX = 1e6 + 6;
const int MOD = 2019;


int cnt[30000];


ll bigMod(ll a , ll b) {

    ll p ;
    if( b == 0) return 1;
    p = ( bigMod(a , b/2) % MOD );
    p = ( p * p) % MOD;
    if( b & 1 ) p = ( p * a) % MOD;
    return p;
}

int main()
{
    fastRead;
    string str;
    cin>>str;
    cnt[0] = 1;
    int rem = 0;
    ll ans = 0;
    int zero = 0;
    for(int i = str.size() - 1 ; i >= 0 ; i-- ) {
        
        int id = str[i]-'0';
        
        rem = (bigMod(10 , zero++) * id + rem)%MOD;
        
        ans += cnt[rem];
        cnt[rem]++;
        
//        cout<<rem<<'\n';
    }
    cout<<ans<<'\n';
    return 0;
    
    
}

Measured memory_bytes: 3784
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

string s;

ll solve() {
	vector<ll> fact(80080,0);
	ll tmp=1;
	REP(i,80080) {
		fact[i]=tmp;
		tmp*=10;
		tmp%=11;
	}
	vector<ll> cnt(11,0);
	cnt[0]=1;
	ll ans=0;
	tmp=0;
	for(ll i=(ll)s.size()-1; i>=0; i--) {
		tmp+=fact[(ll)s.size()-1-i]*(s[i]-'0');
		tmp%=11;
		if(s[i]!='0') ans+=cnt[tmp];
		cnt[tmp]++;
	}
	return ans;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	while(1) {
		cin>>s;
		if(s=="0") break;
		cout<<solve()<<endl;
	}
}



Measured memory_bytes: 3980
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
struct UnionFind { vector<int> par,cnt;
    UnionFind(int NV){par.clear();cnt.resize(NV, 1);rep(i, 0, NV) par.push_back(i); } 
    int operator[](int x) { return par[x] == x ? x : par[x] = operator[](par[x]); }
    void operator()(int x, int y) { x = operator[](x); y = operator[](y);
        if (x != y) par[x] = y, cnt[y] += cnt[x]; }};
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/




int N, A[101010], B[101010];
//---------------------------------------------------------------------------------------------------
bool chk() {
    map<int, int> cnt;
    rep(i, 0, N + 1) cnt[A[i]]++;
    rep(i, 0, N + 1) { if (cnt[B[i]] == 0) return false; cnt[B[i]]--; }
    return true;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> A[i];
    rep(i, 0, N) cin >> B[i];

    A[N] = 0;
    rep(i, 0, N) A[N] ^= A[i];

    B[N] = 0;
    rep(i, 0, N) B[N] ^= B[i];

    if (!chk()) { printf("-1\n"); return; }

    int e = 0, c = 0, d = 0;

    if (A[N] != B[N]) {
        e++;
        rep(i, 0, N) if (A[i] != B[i] && B[i] == A[N]) {
            swap(A[i], A[N]);
            break;
        }
    }

    vector<int> dic;
    rep(i, 0, N) if (A[i] != B[i]) {
        c++;
        dic.push_back(A[i]);
    }
    sort(dic.begin(), dic.end());
    dic.erase(unique(dic.begin(), dic.end()), dic.end());

    UnionFind uf(dic.size());
    rep(i, 0, N + 1) if (A[i] != B[i]) {
        int a = lower_bound(dic.begin(), dic.end(), A[i]) - dic.begin();
        int b = lower_bound(dic.begin(), dic.end(), B[i]) - dic.begin();
        uf(a, b);
    }

    rep(i, 0, dic.size()) if (uf[i] == i) c++;

    rep(i, 0, N) if (A[i] != B[i] && B[i] == A[N]) {
        d = -1;
        break;
    }

    int ans = e + c + d;
    cout << ans << endl;
}

Measured memory_bytes: 5760
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const ll INFll = 1ll << 60;

int main() {
  int a, b;
  cin >> a >> b;

  if ((a + b) % 2 == 0) {
    cout << (a + b) / 2 << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

void solve(){
    int x;
    cin>>x;
    cout<<10-x/200<<'\n';
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t{1};
    //cin>>t;
    fr(i,t) solve();
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
const int mod=1e9+7;
#define pb push_back
#define pii pair<ll,ll>
#define pi pair<int ,int> 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i,a,n) for(int i=a;i>=n;i-- )

int main()

{  
    ll n;
    cin>>n;
    vector<int>A(n);ll sum=0;
    REP(i,0,n){cin>>A[i];sum+=A[i];}
    sort(A.begin(),A.end());
    //sum=A[0]+A[n-1];
    int check=0;
    //cout<<sum<<" ";
    if((sum%n)>(n/2)){check=1;}
    sum=(sum)/n;
   // cout<<sum<<" ";
    if(check==1){sum++;}
    ll ans=0;
    REP(i,0,n)
    {
        ll temp=pow(sum-A[i],2);
        ans+=temp;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#define N 100000
using namespace std;

int main(){
  int m,a,b;
  bool isprime[N];
  vector<int> prime;
  for(int i=0;i<N;i++) isprime[i]=true;
  isprime[0]=isprime[1]=false;
  for(int i=0;i<N/2;i++){
    if(!isprime[i]) continue;
    for(int j=i*2;j<N;j+=i)
      isprime[j]=false;
  }
  for(int i=0;i<N;i++)
    if(isprime[i]) prime.push_back(i);
  while(1){
    cin>>m>>a>>b;
    if(!m&&!a&&!b) break;
    int maxa=0,maxb=0;
    double a_b=1.0*a/b;
    for(int i=0;prime[i]<prime.size();i++){
      for(int j=0;prime[j]<prime.size();j++){
	double cal=1.0*prime[i]/prime[j],cal2=prime[i]*prime[j];
	if(cal2>m) break;
	if(a_b<=cal&&cal<=1&&cal2<=m){
	  if(maxa*maxb<cal2){
	    maxa=prime[i];
	    maxb=prime[j];
	    if(maxa>maxb) swap(maxa,maxb);
	  }
	}
      }
    }
    cout<<maxa<<' '<<maxb<<endl;
  }
  return 0;
}

Measured memory_bytes: 1420
/*
      Ashraful Islam Paran
      27-August-2020
      10:12:49
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(n) for (int i = 0; i < n; i++)
#define fo(i, x, n) for (int i = x; i < n; i++)
#define fb(i, x, n) for (int i = n - 1; i <= 0; i--)
#define w(t) int t; cin >> t; while (t--)



typedef unsigned long long ull;
typedef vector<long long> vi;
#define ull unsigned long long
#define msi map<string, long long>
#define mii map<long long, long long>
const int MX = 2e5 + 5;
const int INF = 1e18;
#define pb push_back
#define endl "\n"
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define all(x) x.begin(), x.end()
#define ff first
#define ss second


int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    // online submission
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int a,b;cin>>a>>b;
    int mn=min(a,b);
    int mx=max(a,b);
    while(mx--)
    {
        cout<<mn;
    }
    cout<<endl;
    
    
    
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
    return 0;
}

Measured memory_bytes: 3776
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        long a, b = 0;
        long n = Long.parseLong(br.readLine());
        int digits, mindigits = 11;
        
        for (a = 1; a <= Math.sqrt(n); a++) {
            if (n % a == 0) {
                b = n / a;
                digits = String.valueOf(Math.max(a, b)).length();
                if (digits  < mindigits) mindigits = digits;
            }
        }
        
        System.out.println(mindigits);
    }
}


Measured memory_bytes: 21332
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Numerics;
using System.IO;
using System.Runtime.InteropServices;
using static System.Math;
using static io;
public class CompetitiveProgramming
{
  public void Solve()
  {
    var N = Int1;
    var A = Strs;
    bubble(A, N);
    selection(A, N);
  }

  public void bubble(string[] A, int N)
  {
    var s = A.ToArray();
    var t = A.ToArray();
    bool flg = true;
    while (flg)
    {
      flg = false;
      for (int j = N - 1; j > 0; --j)
      {
        if ((int)(t[j - 1][1]) > (int)(t[j][1]))
        {
          var x = t[j - 1];
          t[j - 1] = t[j];
          t[j] = x;
          flg = true;
        }
      }
    }
    Write(string.Join(" ", t));
    Write(isStable(s, t) ? "Stable" : "Not stable");
  }
  public void selection(string[] A, int N)
  {
    var s = A.ToArray();
    var t = A.ToArray();
    for (int i = 0; i < N; ++i)
    {
      int min = i;
      for (int j = i + 1; j < N; ++j)
      {
        if (t[min][1] > t[j][1])
        {
          min = j;
        }
      }
      var x = t[min];
      t[min] = t[i];
      t[i] = x;

    }
    Write(string.Join(" ", t));
    Write(isStable(s, t) ? "Stable" : "Not stable");
  }
  public bool isStable(string[] A, string[] B)
  {
    for (int i = 0; i < A.Length; ++i)
    {
      for (int j = i + 1; j < A.Length; ++j)
      {
        for (int k = 0; k < A.Length; ++k)
        {
          for (int l = k + 1; l < A.Length; ++l)
          {
            if (A[i][1] == A[j][1] && A[i] == B[l] && A[j] == B[k])
            {
              return false;
            }
          }
        }
      }
    }
    return true;
  }
}

class BIT
{

}



class Program
{
  static void Main(string[] args)
  {
    var CompetitiveProgramming = new CompetitiveProgramming();
    CompetitiveProgramming.Solve();
  }
}
public static class io
{
  public static string Str => Console.ReadLine();
  public static string[] Strs => Str.Split(' ');
  public static long[] Longs => Strs.Select(long.Parse).ToArray();
  public static int[] Ints => Strs.Select(int.Parse).ToArray();
  public static char[] Chars => Str.ToArray();
  public static double[] Doubles => Strs.Select(double.Parse).ToArray();
  public static long Long1 => Longs[0];
  public static int Int1 => Ints[0];
  public static char Char1 => Chars[0];
  public static double Double1 => Doubles[0];
  public static long[] VerticalRead(int N) { long[] A = new long[N]; for (int i = 0; i < N; ++i) A[i] = Long1; return A; }
  public static void Write(string a) => Console.WriteLine(a);
  public static void Write(params object[] i) => Write(string.Join(" ", i));
  public static void Write<T>(IEnumerable<T> a) => Write(string.Join(" ", a));
  public static void Verticalwrite<T>(IEnumerable<T> a) { foreach (var z in a) Write(z); }
  public static void YN(bool i) { if (i) Write("Yes"); else Write("No"); }
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int n;
  string s;
  cin >> n >> s;
  int l = 0, r = 0;
  rep(i, 0, s.length()) {
    if(s[i] == 'E') r++;
    else l++;
  }
  int ans = 1145141919;
  int kl = 0;
  rep(i, 0, s.length()) {
    if(s[i] == 'E') r--;
    ans = min(ans, kl + r);
    if(s[i] != 'E') kl++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 720
n = gets.to_i
a = gets.split.map(&:to_i)
t = a.tally
size = t.size

if size == 1
  puts t[0] ? :Yes : :No
elsif size == 2
  puts t[0] == n / 3.0 ? :Yes : :No
elsif size == 3
  puts t.keys.inject(:^) == 0 && t.values.uniq.size == 1 ? :Yes : :No
else
  puts :No
end

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

int main(void) {
  int R;
  cin >> R;

  if(R<1200) {
    cout << "ABC" << endl;
  } else {
    if(R<2800) {
      cout << "ARC" << endl;
    } else {
      cout << "AGC" << endl;
    }
  }
}

Measured memory_bytes: 256
//TO CHANGE THE WORLD
#include <bits/stdc++.h>

using namespace std;

#define L first
#define R second
#define pb push_back
#define mp make_pair
#define int ll
typedef long long ll;

const int maxn=1000+10, mod=1e9+7;

int h, w, horiz, vert, a, b, k;
bool grid[maxn][maxn], gr[maxn][maxn];
struct mat
{
    ll a[5][5];
    int n;
    mat(int _n, int v=0)
    {
	n=_n;
	memset(a,0,sizeof a);
	for(int i=0; i<n; i++) a[i][i]=v;
    }
};
mat operator *(mat a, mat b)
{
    int n=a.n;
    mat ret(n);
    for(int i=0; i<n; i++)
	for(int j=0; j<n; j++)
	    for(int k=0; k<n; k++)
		ret.a[i][j]=(ret.a[i][j]+(a.a[i][k]*b.a[k][j])%mod)%mod;
    return ret;
}
mat operator ^(mat a, int n)
{
    mat ret(a.n, 1);
    if(!n) return ret;
    ret=a^(n/2);
    if(n%2) return ret*ret*a;
    return ret*ret;

}
int pw(int base, int n)
{
    if(!n) return 1;
    int ret=pw(base,n/2);
    if(n%2) return ((ret*ret)%mod)*base%mod;
    return ret*ret%mod;
}
void sp()
{
    swap(horiz, vert);
    memcpy(gr,grid, sizeof grid);
    for(int i=0; i<h; i++)
	for(int j=0; j<w; j++) 
	    grid[j][i]=gr[i][j];
    swap(h,w);
}
main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin>>h>>w>>k;
    for(int i=0; i<h; i++) for(int j=0; j<w; j++) {char ch;cin>>ch;grid[i][j]=ch=='#';a+=grid[i][j];}
    for(int i=0; i<h; i++) if(grid[i][0]==grid[i][w-1] && grid[i][0]) horiz++;
    for(int i=0; i<w; i++) if(grid[0][i]==grid[h-1][i] && grid[0][i]) vert++;
    if(vert && horiz) return cout<<1<<endl, 0;
    if(!vert && !horiz) return cout<<pw(a,k-1)<<endl, 0;
    if(vert) sp();
    for(int i=0; i<h; i++)
	for(int j=0; j<w-1; j++) 
	    if(grid[i][j]==grid[i][j+1] && grid[i][j]) b++;
    mat m(2);
    //cout<<a<<" "<<b<<" "<<horiz<<endl;
    m.a[0][0]=a;m.a[0][1]=mod-b;
    m.a[1][0]=0;m.a[1][1]=horiz;
    m=m^(k-1);
    cout<<(m.a[0][0]+m.a[0][1]+mod)%mod<<endl;
}

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

int main() {
 int n,a,b;
  string member;
  cin >> n >> a >> b >> member;
  
  int passNum = 0;
  int passAbroad = 0;
 
  for(int i = 0; i < n; i++) {
    char current = member.at(i);
 	if(current == 'a' && passNum < (a+b)) {
      cout << "Yes" << endl;
      passNum++;
    } else if(current == 'b' && passNum < (a+b)
              && passAbroad < b){
      cout << "Yes" << endl;
      passNum++;
      passAbroad++;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <set>
#include <utility>
#include <vector>
#include <algorithm>
#define llint long long
#define inf 1e18

using namespace std;
typedef pair<llint, llint> P;

struct BIT{
	int size;
	vector<llint> bit;
	BIT(){size = 0;}
	BIT(int s){
		size = s;
		bit.resize(size+1);
		init();
	}
	void init(){
		for(int i = 1; i <= size; i++) bit[i] = 0;
	}
	llint query(int i){
		llint ret = 0;
		while(i > 0){
			ret += bit[i];
			i -= i&(-i);
		}
		return ret;
	}
	void add(int i, llint x){
		while(i <= size){
			bit[i] += x;
			i += i&(-i);
		}
	}
};


llint n, k;
llint a[100005];
P s[100005];
BIT bit(100005);

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> a[i], a[i] -= k;
	s[0] = P(0, 1);
	for(int i = 1; i <= n; i++) s[i] = P(s[i-1].first+a[i], i+1);
	sort(s, s+n+1);
	
	llint ans = 0;
	for(int i = 0; i <= n; i++){
		ans += bit.query(s[i].second);
		bit.add(s[i].second, 1);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 6004
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
 
signed main() {
    IOS;
    #ifdef LOCAL
        freopen("input.txt","r", stdin);
        freopen("output.txt","w",stdout);
    #endif
    string s;   cin >> s;
    int k;  cin >> k;
    int l = s.length(), c = 1, p = 0, i = 0; 
    if(s[0] != s[l-1]){
        for(int i = 1; i < l; i++){
            if(s[i] == s[i-1])  c++;
            else    p += (c/2), c = 1;
        }
        p += (c/2);
        cout << p*k;
        return 0;
    }
    for(i = 1; i < l && s[i] == s[i-1]; i++);
    int ans = i/2;
    for(; i < l; i++){
        if(s[i] == s[i-1])
            c++;
        else
            p += c/2, c = 1;
    }
    ans += p*k + c/2;
    if(s[0] == s[l-1])  c++;
    for(int i = 1; i < l && s[i] == s[i-1]; i++)
        c++;
    if(c > l)
        cout << (l*k)/2LL;
    else{
        ans += (c/2LL)*(k-1);
        cout << ans;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
inline void add(long long &x, long long y) {
	x += y;
	if(x >= mod) x -= mod;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int h, w, k;
	cin >> h >> w >> k;
	vector<vector<long long>> dp(h + 1, vector<long long>(w));
	dp[0][0] = 1;
	for(int i = 1; i <= h; i++) {
		for(int j = 0; j < (1 << (w - 1)); j++) {
			bool valid = true;
			bitset<7> b(j);
			for(int l = 0; l < 6; l++) {
				if(b[l] && b[l + 1]) valid = false;
			}
			if(!valid) continue;
			vector<int> c(w);
			for(int l = 0; l < w; l++) {
				c[l] = l;
			}
			for(int l = 0; l < w - 1; l++) {
				if((j >> l) & 1) swap(c[l], c[l + 1]);
			}
			for(int l = 0; l < w; l++) {
				add(dp[i][c[l]], dp[i - 1][l]);
			}
		}
	}
	cout << dp[h][k - 1] << endl;
	return 0;	
}


Measured memory_bytes: 256
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define REP_AB(i, a, b) for (ll i = ll(a); i <= ll(b); ++i)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
// true / false
#define BIN_SEARCH(v, a) binary_search(ALL(v), a)
// index
#define BIN_LEFT(v, a) (lower_bound(ALL(v), a) - v.begin())
#define BIN_RIGHT(v, a) (upper_bound(ALL(v), a) - v.begin())
#define BIN_INSERT(v, a) (v.insert(v.begin() + BIN_LEFT(v, a), a))
#define DEL(v, i) v.erase(v.begin() + i)
#define INSERT(v, i, a) v.insert(v.begin() + i, a)
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;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
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; }
// template end

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

    ll n, W;
    in >> n >> W;
    ll dp[n+1][W+1] = {};
    ll w[n+1] = {};
    ll v[n+1] = {};

    REP(i, n){
        in >> w[i+1] >> v[i+1];
    }

    REP_AB(i, 1, n){
        REP_AB(j, 0, W){
            dp[i][j] = dp[i-1][j];
            if(j - 1 < 0) continue;
            dp[i][j] = max(dp[i][j], dp[i][j-1]);
            if(j-w[i] < 0) continue;
            dp[i][j] = max(dp[i][j], dp[i-1][j-w[i]] + v[i]);
        }
    }
    out << dp[n][W] << endl;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	int n,k;
	cin>>n>>k;
	int a[n],b[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i++)
		b[i] = n*10000;
	b[0] = 0;
	for(int i = 1;i<n;i++)
	{
		for(int j = i-1;j >= i-k && j>=0 ;j--)
			b[i] = min(b[i],b[j]+abs(a[i]-a[j]));
	}
	cout<<b[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 4404
#include <iostream>
#include <vector>

using namespace std;

int maxHappines(vector<vector<int> >& activites){
  int n = activites.size();
  int res = 0;
  vector<vector<int> > dp(n, vector<int>(3, 0));

  dp[0][0] = activites[0][0];
  dp[0][1] = activites[0][1];
  dp[0][2] = activites[0][2];

  for(int i = 1; i < n; i++){
    dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + activites[i][0];
    dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + activites[i][1];
    dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + activites[i][2];
  }
  res = max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));
  return res;
}

int main(){

  int n;
  cin >> n;
  vector<vector<int> > activites(n, vector<int>(3));
  for(int i = 0; i < n; i++){
  	for(int j = 0; j < 3; j++){
      cin >> activites[i][j];
    }
  }

  cout << maxHappines(activites) << endl;
  return 0;
}


Measured memory_bytes: 11136
#include<stdio.h>

int main(void)
{
  int a,b,c;
  int e = 0;

  scanf("%d %d %d",&a,&b,&c);

  for(int i=a; i<=b; i++){
    if(c % i == 0)
     e++;
    
  }
  printf("%d\n",e);

  return 0;
}

    
  
    



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

int main() {
	int n, m;
	while(cin >> n, n) {
		cin.ignore();
		int conv[256] = {};
		for(int i = 0; i < n; i++) {
			char c, d;
			cin >> c; cin.ignore();
			cin >> d; cin.ignore();
			conv[c] = d;
		}
		cin >> m; cin.ignore();
		for(int i = 0; i < m; i++) {
			char c;
			cin >> c; cin.ignore();
			if(conv[c])
				cout << (char)conv[c];
			else
				cout << c;
		}
		cout << endl;
	}
}

Measured memory_bytes: 1152
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<cstring>
#include<complex>
#include<cmath>
#include<algorithm>
#include<list>
#include<functional>
#define mp make_pair
#define X first
#define Y second
#define INF 987654321
#define PI 3.14159265358979323846264
#define MOD 1000000007LL
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef vector<iii> Viii;
typedef complex<double> base;
ll POW(ll a, ll b) { if (b == 0)return 1; if (b == 1)return a; if (b & 1)return (a*POW(a, b - 1)) % MOD; ll t = POW(a, b / 2); return (t*t) % MOD; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return gcd(a, b); return a*b / gcd(a, b); }
int dx[] = { 0,-1,1,0 }, dy[] = { 1,0,0,-1 };//동북남서
int ddx[] = { 0,0,1,1,1,-1,-1,-1 }, ddy[] = { 1,-1,1,0,-1,1,0,-1 };

int n;
int a[2][100];
int d[2][100];
int go(int i, int j)
{
	if (i > 1 || j >= n)return -INF;
	if (i == 1 && j == n - 1)return a[i][j];
	int &ret = d[i][j];
	if (ret != -1)return ret;
	ret = a[i][j];
	ret = max(ret + go(i + 1, j), ret + go(i, j + 1));
	return ret;
}
int main() {
	MEM_1(d);
	scanf("%d", &n);
	fup(i, 0, 1, 1)
		fup(j, 0, n - 1, 1)scanf("%d", &a[i][j]);
	printf("%d", go(0, 0));
}

Measured memory_bytes: 256
"use strict";

function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    let tmp = input[0].split(" ");
    let x = parseInt(tmp[0], 10);
    let n = parseInt(tmp[1], 10);
    let p = input[1].split(" ").map(str => parseInt(str, 10)); //p[0], ... , p[n-1]

    p.sort(compareFunc);    //配列nを昇順に並べる

    let nearX = x;
    let i = 0;

    while (1) {
        nearX = x - i;
        if (!p.includes(nearX)) {
            console.log('%d', nearX);
            return;
        }
        nearX = x + i;
        if (!p.includes(nearX)) {
            console.log('%d', nearX);
            return;
        }
        i++;
    }

}

function compareFunc(a, b) {
    return a - b;
}


Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29636