akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll; 

int A, B, K;

int gcd(int a, int b) {
    int big = max(a, b);
    int small = min(a, b);
    if (small == 0) return big;
    else return gcd(small, big % small);
}

int divK(int x, int k){
    vector<int> div;
    for (int i = x; i >= 1; i--){
        if (x % i == 0) div.push_back(i);
    }
    return div[k-1];
}

int main() {
    cin >> A >> B >> K;
    int num1 = gcd(A, B);
    cout << divK(num1, K) << endl;
    return 0;    
}

Measured memory_bytes: 888
/*
	Behind every successful man 
	there's a lot of unsuccessful years
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define E endl
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int dp[N];
signed main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		int n,k;
		cin >> n >>k;
		fn{
			cin >> ar[i];
		}
		int ans=0;
		sort(ar,ar+n);
		for(int i =0 ;i < n-k;i++)ans+=ar[i];
			cout << ans<<endl;
	
	
	}
	
	cerr << "Time Taken : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
	return 0;
}

Measured memory_bytes: 4352
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <random>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
const double pi = acos(-1);
typedef pair<int, int> P;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)
#define ALL(a) ((a).begin(), (a).end())

bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)
{

    if (a.first == b.first)
        return a.second < b.second;

    return a.first < b.first;
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll A[100010], B[100010];
vector<pair<ll, ll>> vp;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);

    int N;
    cin >> N;
    for (int i = 0; i < N; ++i)
    {
        cin >> A[i] >> B[i];
        vp.push_back({A[i] + B[i], A[i]});
    }

    sort(vp.rbegin(), vp.rend());

    ll sum = 0;
    for (int i = 0; i < N; ++i)
    {
        if (i % 2 == 0)
        {
            sum += vp[i].second;
        }
        else
        {
            sum -= (vp[i].first - vp[i].second);
        }
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#pragma region Macros
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define all(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define ceil(a,b) ((a+b-1)/b)
int gcd(int a, int b) // assuming a,b >= 1
{
    if (a < b)
        swap(a, b);
    if (b == 0)
        return a;
    if (a % b == 0)
        return b;
    return gcd(b, a % b);
}
int lcm(int a, int b) // assuming a,b >= 1
{
    return  a * b / gcd(a, b);
}
using namespace std;
#pragma endregion
signed main() {
    int N,i;
    cin >> N >> i;
    cout << (N - 1) * (i - 1);
}

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

int main(){
    long long H; cin >> H;
    long long i = 0;
    long long ans = 0;

    while(H > 0){
        long long num = pow(2, i);
        ans += num;
        H /= 2;
        ++i;
    }

    cout << ans << endl;


}

Measured memory_bytes: 4072
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t n,cnt=0;
  cin >> n;
  int L[n];
  for(int i=0;i<n;i++)cin >> L[i];
  sort(L,L+n);
  for(int i=0;i<n-2;i++){
    for(int j=i+1;j<n-1;j++){
      for(int k=j+1;k<n;k++){
        if(L[j]<L[i]+L[k] && L[k]<L[i]+L[j])cnt++;
      }
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3580
import java.util.ArrayList;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main {
	private static ArrayList<Point> pointList = new ArrayList<Point>(4);
	private static ArrayList<String> resultList = new ArrayList<String>(1);
	private static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		int numDataSet = sc.nextInt();
		for(int i = 0; i < numDataSet; i++){
				//4ÂÌÀWf[^ðüÍ©çæ¾·é
				setInputsToPointList();
				setResult(areParallel(pointList.get(0), pointList.get(1), pointList.get(2), pointList.get(3)));
				pointList.clear();
		}
		sc.close();
		printResultList();
	}
	
	private static void printResultList(){
		for(int i = 0; i < resultList.size(); i++){
			System.out.println(resultList.get(i));
		}
	}
	
	public static void setInputsToPointList(){
		Point point1 = new Point(sc.nextDouble(), sc.nextDouble());
		pointList.add(point1);
		Point point2 = new Point(sc.nextDouble(), sc.nextDouble());
		pointList.add(point2);
		Point point3 = new Point(sc.nextDouble(), sc.nextDouble());
		pointList.add(point3);
		Point point4 = new Point(sc.nextDouble(), sc.nextDouble());
		pointList.add(point4);
	}
	
	public static void setResult(boolean flag){
		if(flag){
			resultList.add("YES");
		}
		else{
			resultList.add("NO");
		}
	}
	
	private static boolean areParallel(Point a, Point b, Point c, Point d){
		if(getSlope(a, b) == getSlope(c, d)){
			return true;
		}
		else{
			return false;
		}
	}
	
	public static double getSlope(Point a, Point b){
		boolean aHasBiggerXThanB = aHasBiggerXThanB(a, b);
		
		double valiationX;
		if(aHasBiggerXThanB){
			valiationX = a.x - b.x;
		}
		else{
			valiationX = b.x - a.x;
		}
		
		double valiationY;
		if(aHasBiggerXThanB){
			valiationY = a.y - b.y;
		}
		else{
			valiationY = b.y - a.y;
		}
		
		double slope = valiationY / valiationX;
		if(slope == Double.NEGATIVE_INFINITY){
			slope = Double.POSITIVE_INFINITY;
		}
		
		return slope;
	}
	
	private static boolean aHasBiggerXThanB(Point a, Point b){
		boolean aHasBiggerX;
		if(a.x > b.x){
			aHasBiggerX = true;
		}
		else{
			aHasBiggerX = false;
		}
		return aHasBiggerX;
	}
}

class Point {
	double x;
	double y;
	
	Point(double x, double y){
		this.x = x;
		this.y = y;
	}
}

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

multiset<int> S;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        S.insert(x);
    }
    int ans=0;
    while(!S.empty())
    {
        int x=*S.rbegin();
        int y=1;
        S.erase(S.find(x));
        while(y<=x)
            y*=2;
        auto it=S.find(y-x);
        if(it!=S.end()){
            ans++;
            S.erase(it);
        }
    }
    cout<<ans;

}


Measured memory_bytes: 9600
import sys
import collections

N = int(input())
AN = list(map(int,input().split()))

count = collections.Counter(AN)


edge1 = 0
edge2 = 0
for c in sorted(count.keys(),reverse=True):
  if count[c] >= 4:
    if edge1 == 0:
      print(c*c)
      sys.exit()
    else:
      print(edge1*c)
      sys.exit()
  elif count[c] >= 2:
    if edge1 == 0:
      edge1 = c
    else:
      print(edge1*c)
      sys.exit()
else:
  print(0)


Measured memory_bytes: 22192
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <fstream>

#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <tuple>
#include <queue>
#include <functional>
#include <stack>
#include <numeric>
#include <cassert>

using namespace std;

class arcC {
public:
    void solve(istream& in, ostream& out) {
        int n;
        in >> n;
        vector<int> v(26, 1000);
        for (int i = 0; i < n; ++i) {
            string s;
            in >> s;
            for (int j = 0; j <= 25; ++j) {
                v[j] = min(v[j], (int)std::count(s.begin(), s.end(), (char)('a'+j)));
            }
        }
        
        for (int i = 0; i < 26; ++i) {
            for (int j = 0; j < v[i]; ++j) {
                out << (char)('a'+i);
            }
        }
        out << "\n";
    }
};


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

	arcC solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef pair<long, long> P;
vector<int> G[100010];
long d[100010],INF=99999999;
long par[100010],rank[100010]={};


void init(int n){
  for(int i=0;i<n;i++){
    par[i]=i;
    rank[i]=0;
  }
}

long find(int x){
  if(par[x]==x){
    return x;
  }else{
    return par[x]=find(par[x]);
  }
}

void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y) return ;

  if(rank[x]<rank[y]){
    par[x]=y;
  }else{
    par[y]=x;
    if(rank[x]==rank[y]) rank[x]++;
  }
}

bool same(int x,int y){
  return find(x)==find(y);
}

void dijkstra(int s){
fill(d,d+100010,INF);
priority_queue<P, vector<P>, greater<P> > que;
d[s-1]=0;
que.push(P(0,s-1));

while(!que.empty()){
  P p=que.top();
  que.pop();
  int v=p.second;
  if(d[v]<p.first) continue;
  for(int i=0;i<G[v].size();i++){
    if(d[G[v][i]]>d[v]+1){
      d[G[v][i]]=d[v]+1;
      que.push(P(d[G[v][i]],G[v][i]));
    }
  }
}
}

int main(){
  long N,M,s,t,x,y;
  cin>>N>>M>>s>>t;
  init(N);

  for(int i=0;i<M;i++){
    cin>>x>>y;
    G[x-1].push_back(y-1);
    G[y-1].push_back(x-1);
    unite(x-1,y-1);
  }

  dijkstra(s);
  long jdg[N]={},ans=0;
  for(int i=0;i<N;i++){
    if(same(t-1,i)) jdg[d[i]]+=1;
    }
  for(int i=0;i<N;i++){
  //  cout<<"jdg["<<i<<"]="<<jdg[i]<<endl;
  }
  long spath=d[t-1];

  dijkstra(t);

  long jdg2[N]={};
  for(int i=0;i<N;i++){
    if(same(t-1,i)) jdg2[d[i]]+=1;
    }
  for(int i=0;i<N;i++){
  //  cout<<"jdg2["<<i<<"]="<<jdg2[i]<<endl;
  }

  for(int i=0;i<spath-1&&spath-2-i>=0;i++){
    ans+=jdg[i]*jdg2[spath-2-i];
  }
/*
  for(int i=0;i<spath-1;i++){
      if(i+2<=spath){
        ans+=jdg[i];
        cout<<"i+2="<<jdg[i]*jdg2[spath-i-1]<<endl;
      }
      if(spath<2*spath-2-i&&2*spath-2-i<N){
        ans+=jdg[i]*jdg[2*spath-2-i];
        cout<<"spath*2="<<jdg[i]*jdg[2*spath-2-i]<<endl;
      }
  }
  */
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 14088
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIII pair< int, pair<int,int> >
const int MaxN = 3e3+2;
double p[MaxN];
double dp[MaxN][MaxN];
const double eps = 1e-9;
int N;

double rec(int i, int k){

    if(i==N) return k>(N-k);
    auto &ret = dp[i][k];
    if(ret+1.0>eps) return ret;
    return ret = rec(i+1,k+1)*p[i] + rec(i+1,k)*(1-p[i]);
}


void solve(){

    cin>>N;
    memset(dp,-1,sizeof dp);
    for(int i=0; i<N; i++)
        cin>>p[i];

    cout<<fixed<<setprecision(10)<< rec(0,0) <<"\n";
}


int main(){

    //freopen("input.txt","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();

    return 0;
}


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

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

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

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

void solve(ll x) {
	bool solved = false;

	for (int a = -1000; a < 1000; ++a) {
		if (solved) return;

		for (int b = -1000; b < 1000; ++b) {
			if (pow(a, 5) - pow(b, 5) == x) {
				cout << a << " " << b << endl;
				solved = true;
				return;
			}
		}
	}
}

int main() {
	ll x;
	cin >> x;

	solve(x);
}

Measured memory_bytes: 4040
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);

        int a = Integer.parseInt(scan.next());
        int b = Integer.parseInt(scan.next());
        int count = 0;
        if(b%a == 0){
            count =  a+b;
        }else{
            count = b-a;
        }
        PrintWriter out = new PrintWriter(System.out);
        out.println(count);
        out.flush();
        scan.close();
    }
}

Measured memory_bytes: 23124
#include<stdio.h>

int main(){
	
	int N, K, X, Y;
	
	scanf("%d %d %d %d", &N, &K, &X, &Y);
	if(N >= K){
		printf("%d\n", (K * X) + ((N-K) * Y));
	}
	else{
		printf("%d\n", N * X);
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
    int N;
    cin >> N;
    int count = 0;
    for(int a = 1;a<N;++a){
        count += (N%a==0) ? (N/a - 1) : N/a;
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 3632
package main

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

var scanner = bufio.NewScanner(os.Stdin)

const div = 1000000007

func NextStr() string {
	scanner.Scan()
	return scanner.Text()
}

func NextInt() int {
	i, _ := strconv.Atoi(NextStr())
	return i
}

func main() {
	scanner.Split(bufio.ScanWords)
	n := NextInt()
	A := make([]int, n)
	var sum int
	var ans int
	for i := 0; i < n; i++ {
		A[i] = NextInt()
		sum += A[i]
		sum %= div
	}
	for i := 0; i < n; i++ {
		sum -= A[i]
		if sum < 0 {
			sum += div
		}
		ans += A[i] * sum
		ans %= div
	}
	fmt.Println(ans)
}



Measured memory_bytes: 5848
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}

fun powerMod(x: Int, n: Int, mod: Int): Int = when {
    n == 0 -> 1
    n % 2 == 1 -> ((powerMod(x, n - 1, mod).toLong() * x.toLong()) % mod).toInt()
    else -> {
        val tmp = (powerMod(x, n / 2, mod) % mod).toLong()
        ((tmp * tmp) % mod).toInt()
    }
}

class Combination2 {
    companion object {
        fun calc(a: Int, b: Int, mod: Int): Int {
            if (b > a - b) return calc(a, a - b, mod)

            var mul = 1L
            var div = 1L

            for (i in 0 until b) {
                mul *= (a - i)
                mul %= mod
                div *= (i + 1)
                div %= mod
            }

            return ((mul * powerMod(div.toInt(), mod - 2, mod)) % mod).toInt()
        }
    }
}

const val mod = 1_000_000_007

fun main() {
    val (n, a, b) = readIntList()

    val numAll = powerMod(2, n, mod) - 1
    val numA = Combination2.calc(n, a, mod)
    val numB = Combination2.calc(n, b, mod)
    var res = numAll - numA - numB
    while (res < 0) res += mod

    println(res)
}


Measured memory_bytes: 36480
N,K = map(int,input().split())
if K>((N-1)*(N-2))//2:
    print(-1)
else:
    print((N*(N-1))//2-K)
    for i in range(1,N):
        print(i,N)
    cnt = 0
    for i in range(1,N-1):
        for j in range(i+1,N):
            if cnt>=K:
                print(i,j)
            else:
                cnt += 1

Measured memory_bytes: 74396
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U & u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U & u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
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 (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S;
	cin >> S;
	vector<int> C(26);
	REP(i, SZ(S)) {
		C[S[i] - 'A']++;
	}
	int cnt = 0;
	REP(i, 26) {
		if (C[i] == 2)cnt++;
	}
	if (cnt == 2)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <functional>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

int main(){
  int N, M;
  int u, v;
  int S, T;
  cin >> N >> M;
  vector<vector<int>> G(N*3);
  vector<int> d(N*3);
  for(int i=0;i<(int)d.size();i++){
    d[i] = -1;
  }
  for(int i=0;i<M;i++){
    cin >> u >> v;
    u--; v--;
    for(int i=0;i<3;i++){
      G[u*3+i].push_back(v*3+((1+i)%3));
    }
  }
  cin >> S >> T;
  S--; T--; S *= 3; T *= 3;
  queue<int> q;
  q.push(S); d[S] = 0;
  while(!q.empty()){
    int now = q.front(); q.pop();
    for(int i=0;i<(int)G[now].size();i++){
      if(G[now][i] == T) {cout << (d[now]+1)/3 << endl; return 0;}
      if(d[G[now][i]] < 0){
        q.push(G[now][i]);
        d[G[now][i]] = d[now] + 1;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 17792
<?php
//error_reporting(0);
//$N = trim(fgets(STDIN));
//$A =  explode(" ",trim(fgets(STDIN)));
list($x,$a) =  explode(" ",trim(fgets(STDIN)));
//

if ($x < $a) {
  printf("0\n");
}
else {
  printf("10\n");
}


Measured memory_bytes: 4728
#include <bits/stdc++.h>
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define ll long long
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define VAR(v, i) __typeof( i) v=(i)
#define forit(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
 
using namespace std;
 
const int maxn = (int)3e5 + 100;
const int mod = (int)1e9 + 7;
const int P = (int) 1e6 + 7; 
const double pi = acos(-1.0);
 
#define inf mod
 
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;   
typedef vector<ll> vll;               
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;                        


main () {
	int a, b;
	scanf("%d%d", &a, &b);
	if(a % b == 0) puts("-1");
	else printf("%d", a);
}

Measured memory_bytes: 256
#include<stdio.h>
long a[200003],b[200003];
int main()

{
	long n,m,i,j=0,k=0,x,y,c,d,t1=0,t2=0,t;
	scanf("%ld%ld",&n,&m);
	for(i=0;i<m;i++)
	{
		scanf("%d %d",&x,&y);
		if(x==1)
		{
			a[y]=1;
			t1=(y>t2)?y:t1;
		}
		if(y==n)
		{
			b[x]=1;
			t2=(x>t2)?x:t2;
		}
	}
	t=(t1>t2)?t1:t2;
	int flag=0;
	for(i=0;i<=t;i++)
	{
	    if(a[i]&&b[i]) {
		flag=1;break;}
	}
	if(flag==1) printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");
	return 0;
}

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

const lint MOD = 1e9 + 7;
map<lint, lint> memo;

lint f(lint s){
    if(s==0 || s==1) return s + 1;
    if(memo.count(s)) return memo[s];
    return memo[s] = (f(s/2)+f((s-1)/2)+f((s-2)/2)) % MOD;
}

int main(){
    lint n; cin >> n;
    cout << f(n) << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  int N, K; cin >> N >> K;
  int a[N]; rep(i,N) cin >> a[i];
  bool dp[K+1] = {};
  rep(i,K+1) rep(j,N) if (i>=a[j]) dp[i] |= !dp[i-a[j]];
  // debug(dp,dp+(K+1));

  string result = dp[K] ? "First" : "Second";
  cout << result << endl;
  return 0;
}

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

int a,b,n,ta,tb;

int main(){
	while(true){
		a=0; b=0;
		cin >> n;
		if(!n)
			return 0;
		for(int i=0; i<n; i++){
			cin >> ta >> tb;
			if(ta>tb)
				a+=ta+tb;
			else if(ta==tb){
				a+=ta;
				b+=tb;
			}else
				b+=ta+tb;
		}
		cout << a << ' ' << b << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

int main(){
  long long N; cin>>N;
  long long b=0,a=0,ba=0;
  long long ans=0;
  for(long long i=0;i<N;i++){
    string s; cin>>s;
    if(s[0]=='B'&&s[s.size()-1]=='A') ba++;
    else if(s[0]=='B') b++;
    else if(s[s.size()-1]=='A') a++;
    long long num=s.find("AB");
    while(num>=0){
      ans++;
      num=s.find("AB",num+1); 
    }
  }
  if(ba>0){
    ans+=ba-1;
    if(a>0){ans++;a--;}
    if(b>0){ans++;b--;}
    ans+=min(a,b);
  }
  else{
    ans+=min(a,b);
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int (i)=(a);(i)<(int)(b);(i)++)
#define RREP(i,a,b) for(int (i)=(a);(i)>=(int)(b);(i)--)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;

const int Maxn = 200010;
bool link_1[Maxn], link_n[Maxn];

int main(){
    int n, m;
    cin >> n >> m;
    REP(i,0,m){
        int a, b;
        cin >> a >> b;
        if (a == 1) link_1[b] = true;
        else if (b == n) link_n[a] = true;
    }

    bool ans = false;
    REP(i,2,n){
        if (link_1[i] && link_n[i]){
            ans = true;
            break;
        }
    }

    cout << (ans?"POSSIBLE":"IMPOSSIBLE") << endl;
    
    
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	int a, b, x;
	
	scanf("%d %d %d", &a, &b, &x);
	
	if (a <= x){
		if ((a + b) >= x){
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
	}
	else {
		printf("NO\n");
	}
	
	return (0);
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
int H, W;

string S[1010];
typedef pair<int, int> P;
typedef pair<int, P> PP;
int d[1010][1010];

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> H >> W;
    rep(i, H) cin >> S[i];
    priority_queue<PP, vector<PP>, greater<PP>> que;
    rep(i, H) rep(j, W) d[i][j] = INF;
    rep(i, H) {
        rep(j, W) {
            if(S[i][j] == '#') {
                que.push({0, {i, j}});
                d[i][j] = 0;
            }       
        }
    }
    
    while(que.size()) {
        PP p = que.top(); que.pop();
        int x = p.second.first;
        int y = p.second.second;
        int d1 = p.first;
        rep(i, 4) {
            int xx = x + dx[i];
            int yy = y + dy[i];
            if(xx >= H || xx < 0 || yy >= W || yy < 0) continue;
            if(d[xx][yy] != INF) continue;
            d[xx][yy] = d[x][y] + 1;
            que.push({d[xx][yy], {xx, yy}});
        }
        //cout << que.size() << endl;
    }
    int ans = 0;
    rep(i, H) rep(j, W) ans = max(ans, d[i][j]);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 19308
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.Maybe (fromJust)
import Debug.Trace

solve :: Integer -> Integer -> String
solve a b
    | aa > bb = "Alice"
    | aa < bb = "Bob"
    | otherwise = "Draw"
    where
        calc = \x -> (if x == 1 then 14 else x)
        aa = calc a
        bb = calc b

main :: IO ()
main = do
    (a:b:_) <- map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine
    putStrLn $ solve a b

Measured memory_bytes: 380
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

aa = input()
alphabet=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

for nn in alphabet:
  if sorted([aa,nn])[0] == aa and aa != nn:
    print(nn)
    exit()

Measured memory_bytes: 5192
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
int h, r;
int main(){
    cin >> h >> r;
    if(h+r==0) cout << 0 << endl;
    else if(h+r<0) cout << -1 << endl;
    else cout << 1 << endl;
    return 0;
}


Measured memory_bytes: 3112
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.Int (Int64)
import Data.List (unfoldr)
import Control.Monad (forM_)
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as BS
import Data.Array.Unboxed
import Data.Array.ST

main = do
  n <- readLn
  xs <- U.map fromIntegral . U.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  let ys :: U.Vector Int64
      ys = U.scanl (+) 0 xs
  let arr :: UArray (Int,Int) Int64
      arr = runSTUArray $ do
        arr <- newArray ((0,0),(n,n)) 0
        -- arr ! (i,j) : 半開区間 [i,j) にいるやつを全部合体させるために必要な最小のコスト
        -- 1個のスライムから1個のスライムを得るのに合体は必要ないので arr ! (i,i+1) == 0
        forM_ [2..n] $ \d -> do
          forM_ [0..n-d] $ \i -> do
            let j = i + d -- 0 <= i < j <= d
            c1 <- minimum <$> sequence [(+) <$> readArray arr (i,k) <*> readArray arr (k,j) | k <- [i+1..j-1]] -- これまでの合体で払うコストの最小値
            let c2 = ys U.! j - ys U.! i -- 今回の合体の際に払うコスト
            writeArray arr (i,j) $! c1 + c2
        return arr
  print $ arr ! (0,n)


Measured memory_bytes: 3068
K, S = list(map(lambda n: int(n), input().split(" ")))
cnt = 0
# X + Y + Z = S, 0 <= X, Y, Z <= K #
for x in range(K + 1):
  if S - x > 2 * K:
    continue
  for y in range(K + 1):
    if 0 <= S - x - y <= K:
      cnt += 1

print(cnt)


Measured memory_bytes: 9156
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N];
int32_t main(){_

   cin>>n;

   L ans = 0;
   for (int i = 0; i < n; ++i)
   {
      cin>>a[i];
      ans += 1.0 / a[i];
   }

   ans = 1.0 / ans;
   
   cout << fixed << setprecision(15);

   cout<<ans;

   return 0;
}

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

const int MAXLEN = 1234567;

char sum[MAXLEN];
int p[MAXLEN];
int nxt[MAXLEN],prv[MAXLEN];

int main()
{
    int n;
    scanf("%d", &n);
    scanf("%s", sum);
    memset(p,0,sizeof(p));
    nxt[n] = n;
    for(int i = n-1; i >= 0; --i)
    {
        if(sum[i] == '0')
            nxt[i] = i;
        else
            nxt[i] = nxt[i+1];
    }
    
    for(int i = 0; i < n; ++i)
    {
        if(sum[i] == '0')
            prv[i] = i;
        else
            prv[i] = (i==0?-1:prv[i-1]);
    }
    for(int i=0; i<=n;++i)
    {
        if(i>=3 && sum[i-1]=='1' && sum[i-2]=='0' && sum[i-3]=='1')
        {
            int j=prv[i-3];
            p[i]=max(p[i],p[j+1]+(i-j-3));
            if(j!=i-4)
                p[i]=max(p[i],p[j+2]+(i-j-4));
        }
        if(i==n)
            break;
        if(i+3<=n && sum[i]=='1' && sum[i+1]=='0' && sum[i+2]=='1')
        {
            int j=nxt[i+2];
            p[j]=max(p[j],p[i]+(j-i-2));
            if(j!=i+3)
                p[j-1]=max(p[j-1],p[i]+(j-i-3));
        }
        p[i+1]=max(p[i+1],p[i]);
    }
    printf("%d\n",p[n]);
    return 0;
}

Measured memory_bytes: 13056
#include<cstdio>
#include<algorithm>
using namespace std;

const int N=300005,M=100005;
int n,m,cnt[M*4];
struct node
{
	int l,r;
}a[N];
bool operator<(const node&a,const node&b){return a.r-a.l<b.r-b.l;}

void insert(int u,int l,int r,int ql,int qr)
{
	if(l>=ql&&r<=qr){cnt[u]++;return;}
	int mid=l+r>>1;
	if(ql<=mid)insert(u<<1,l,mid,ql,qr);
	if(qr>mid)insert(u<<1|1,mid+1,r,ql,qr);
}

int query(int p)
{
	int ans=0,u=1,l=1,r=m;
	for(;;)
	{
		ans+=cnt[u];
		if(l==r)break;
		int mid=l+r>>1;
		if(p<=mid)u=u<<1,r=mid;
		else u=u<<1|1,l=mid+1;
	}
	return ans;
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d%d",&a[i].l,&a[i].r);
	sort(a+1,a+1+n);
	for(int i=1,j=1;i<=m;i++)
	{
		while(j<=n&&a[j].r-a[j].l<i)insert(1,1,m,a[j].l,a[j].r),j++;
		int ans=0;
		for(int k=i;k<=m;k+=i)ans+=query(k);
		printf("%d\n",ans+n-j+1);
	}
	return 0;
}


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

using ll = long long;
using pr = pair<ll, ll>;
#define rep(n, i) for(ll i = 0; i < n; ++i)

void solve(void){
  ll n, m; cin >> n >> m;
  vector<pr> vec;
  rep(n, i) {
    ll ta, tb;
    cin >> ta >> tb;
    vec.emplace_back(make_pair(ta, tb));
  }

  sort(vec.begin(), vec.end());

  ll res = 0;
  ll cnt = 0;
  rep(n, i) {
    if (m - cnt > vec[i].second) {
      res += (vec[i].first * vec[i].second );
      cnt += vec[i].second;
    } else {
      res += (vec[i].first * (m - cnt));
      break;
    }
  }

  cout << res << endl;
  return;
}

int main(void) {
  solve();
  return 0;
}

Measured memory_bytes: 2420
#!/usr/bin/env python3
#ABC147 D

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


n = I()
a = LI()
b = [0]*60
for i in range(n):
    for j in range(a[i].bit_length()):
        if (a[i] >> j) & 1:
            b[j] += 1
ans = 0
tmp = 0
for i in range(60):
    r = n-b[i]
    ans += b[i]*r*(2**tmp)
    ans %= mod
    tmp += 1
print(ans)

Measured memory_bytes: 123084
#pragma GCC optimize("O3")

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <assert.h>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <random>
#include <cmath>
#include <chrono>
#include <bitset>

#define ld long double
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;

const int INF = 2e18;
const int MOD = 1e9 + 7;
const int MB = 20;

vector<vector<int>> g;
int n, m;

vector<int> now, used, ans, d;

void dfs(int v, int start) {
	if (!ans.empty()) return;
	used[v] = 1;
	now.pb(v);
	bool good = false, bad = d[v] > 1;
	for (int u : g[v]) {
		if (u == start) good = true;
		else if (used[u] == 1) bad = true;
	}
	if (bad) {
		now.pop_back();
		return;
	}
	if (good && ans.empty()) {
		ans = now;
		now.pop_back();
		return;
	}

	vector<int> q;
	for (int u : g[v]) {
		if (!used[u]) {
			d[u]++;
			q.pb(u);
		}
	}

	for (int u : g[v]) {
		if (!used[u]) {
			dfs(u, start);
		}
	}

	for (int u : q) {
		d[u]--;
	}

	used[v] = 2;
	now.pop_back();
}

void solve() {
	cin >> n >> m;
	g.resize(n);
	for (int i = 0; i < m; i++) {
		int from, to;
		cin >> from >> to;
		from--; to--;
		g[from].pb(to);
	}

	for (int i = 0; i < n; i++) sort(all(g[i]));

	used.resize(n);
	d.resize(n);
	for (int i = 0; i < n; i++) {
		fill(all(used), 0);
		dfs(i, i);
		if (!ans.empty()) {
			cout << ans.size() << '\n';
			for (int i : ans) cout << i + 1 << '\n';
			return;
		}
	}
	cout << -1;
}
signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout.precision(12);
	solve();
}

Measured memory_bytes: 512
# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vll vector < ll >
# define pii pair < int , int >
# define mp make_pair
# define db long double
# define pdd pair < db , db >
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n;
    fi>>n;
    auto f = [&](int w)
    {
        vi ans;
        int cnt = n;
        for (int i = w;i;--i)
            if (cnt >= i)
                ans.push_back(i),cnt -= i;
        reverse(ans.begin(),ans.end());
        return mp(ans,cnt);
    };
    int ans = min(n,100000);
    for (int k = 1 << 20;k;k /= 2)
        if (ans >= k && !f(ans - k).y)
            ans -= k;
    vi w = f(ans).x;
    for (auto it : w)
        fo << it << '\n';
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define ll long long int
using namespace std;

const ll mod = 1000000007;

void solve() {
	ll d, t, s; cin >> d >> t >> s;
	if (d <= s * t) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	//cin >> t;
	t = 1;
	for (int i = 1; i <= t; i++) {
		solve();
		cout << "\n";
	}
	return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e  2.718281828459045
#define eps 1.0e18
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define memset(x,y) memset(x,y,sizeof(x))
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
#define ll long long
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	ll n,k;
	cin>>n>>k;
	ll ans=0;
	while(n){
		n/=k;
		ans++;
	}
	cout<<ans;
	return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
    ll n;
    cin >> n;
    ll mi = 1e18;
    for (ll i = 1; i <= sqrt(n); i++) {
        if (n % i == 0) {
            if (mi > i + n / i - 2) {
                mi = i + n / i - 2;
            }
        }
    }
    cout << mi << endl;
}

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

using std::cin;
using std::cout;
using std::cerr;

using std::abs;
using std::min;
using std::max;
using std::swap;

using std::map;
using std::pair;
using std::set;
using std::string;
using std::vector;

using std::sort;
using std::reverse;

using ll = long long;

#define forn(i, n) for (ll i = 0; i < (ll) n; ++i)
#define sz(a) static_cast<int>(a.size())
#define endl '\n'

struct __init {
    __init() {
        cin.tie(nullptr);
        std::iostream::sync_with_stdio(false);
        cout << std::fixed << std::setprecision(10);
        cerr << std::fixed << std::setprecision(5);
        std::mt19937 rand(300);
    }

    ~__init() {
        #ifdef SEREZHKA
            cerr << "Time elapsed: " << static_cast<double>(clock()) / CLOCKS_PER_SEC << endl;
        #endif
    }
} init;

const ll inf = (ll) 1e9 + 7ll;
const int maxn = (int) 3e2 + 17;

int n, k;
string s;
int dp[maxn][maxn][maxn];

bool read() {
    if (!(cin >> s))
        return false;

    cin >> k;
    return true;
}

void solve() {
    n = sz(s);

    forn (i, n)
        forn (j, n)
            forn (kk, n)
                dp[i][j][k] = -inf;

    forn (i, n) {
        dp[i][i][0] = 1;
        dp[i][i][1] = 1;
        
        if (i < n - 1) {
            if (s[i] == s[i + 1]) {
                dp[i][i + 1][0] = 2;
                dp[i][i + 1][1] = 2;
                dp[i][i + 1][2] = 2;
            }
            else {
                dp[i][i + 1][0] = 1;
                dp[i][i + 1][1] = 2;
                dp[i][i + 1][2] = 2;
            }
        }
    }

    for (int len = 3; len <= n; ++len) {
        for (int l = 0; l + len <= n; ++l) {
            int r = l + len - 1;

            for (int kk = 0; kk <= min(k, len); ++kk) {
                dp[l][r][kk] = max(dp[l][r - 1][kk], dp[l + 1][r][kk]);

                if (s[l] == s[r]) {
                    dp[l][r][kk] = max(dp[l][r][kk], dp[l + 1][r - 1][kk] + 2);

                    for (int p = 1; p <= 2 && kk - p >= 0; ++p)
                        dp[l][r][kk] = max(dp[l][r][kk], dp[l + 1][r - 1][kk - p] + 2);
                } else {
                    if (kk >= 1)
                        dp[l][r][kk] = max(dp[l][r][kk], dp[l + 1][r - 1][kk - 1] + 2);

                    if (kk >= 2)
                        dp[l][r][kk] = max(dp[l][r][kk], dp[l + 1][r - 1][kk - 2] + 2);

                    dp[l][r][kk] = max(dp[l][r][kk], dp[l + 1][r - 1][kk]);
                }
            }
        }
    }

    int ans = 0;

    for (int kk = 0; kk <= k; ++kk)
        ans = max(ans, dp[0][n - 1][kk]);

    cout << ans << endl;
}

int main() {
#if SEREZHKA
    freopen("file.in", "r", stdin);
#endif

    while (read())
        solve();

    return 0;
}


Measured memory_bytes: 118912
#include <bits/stdc++.h>
using namespace std;
int xv[]={1,1,1,1,1,2,2,2,3},yv[]={2,1,0,-1,-2,1,0,-1,0};

void solve(int w,int h){
    char in;
    bool l;
    int r,c;
    queue<pair<bool,pair<int,int>>> q;
    pair<int,int> n;
    vector<vector<int>> mp=vector<vector<int>>(h+4,vector<int>(w+6,-1));
    vector<vector<vector<int>>> ma(h+4,vector<vector<int>>(w+6,vector<int>(2,INT_MAX/2)));
    set<pair<int,int>> sset,tset;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>in;
            if(in=='X')mp[i+1][j+2]=-1;
            else if(in=='S'){
                mp[i+1][j+2]=0;
                sset.insert(make_pair(i+1,j+2));
            }
            else if(in=='T'){
                mp[i+1][j+2]=0;
                tset.insert(make_pair(i+1,j+2));
            }
            else{
                mp[i+1][j+2]=in-'0';
            }
        }
    }
    for(pair<int,int> x:sset){
        q.push(make_pair(true,make_pair(x.first,x.second)));
        q.push(make_pair(false,make_pair(x.first,x.second)));
        ma[x.first][x.second][0]=0;
        ma[x.first][x.second][1]=0;
    }
    while(!q.empty()){
        l=q.front().first;n=q.front().second;q.pop();
        for(int i=0;i<9;i++){
            r=n.first+yv[i];
            c=n.second+(l?xv[i]:-1*xv[i]);
            if(mp[r][c]!=-1&&ma[n.first][n.second][!l]+mp[r][c]<ma[r][c][l]){
                ma[r][c][l]=ma[n.first][n.second][!l]+mp[r][c];
                q.push(make_pair(!l,make_pair(r,c)));
            }
        }
    }
    int mini=INT_MAX/2;
    for(pair<int,int> x:tset){
        mini=min(mini,ma[x.first][x.second][0]);
        mini=min(mini,ma[x.first][x.second][1]);
    }
    cout<<(mini!=INT_MAX/2?mini:-1)<<endl;
}

int main(){
    int w,h;
    while(cin>>w>>h,w){
        solve(w,h);
    }
}



Measured memory_bytes: 3244
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
string str;
int side[100001];

bool check(){
	for(int i=1;i<n-1;i++){
		if(side[i]==0){
			if(str[i]=='o'){
				side[i+1]=side[i-1];
			}else{
				side[i+1]=1-side[i-1];
			}
		}else{
			if(str[i]=='x'){
				side[i+1]=side[i-1];
			}else{
				side[i+1]=1-side[i-1];
			}
		}
	}
	if(side[n-1]==0){
		if(str[n-1]=='o'){
			if(side[0]!=side[n-2])return false;
		}else{
			if(side[0]==side[n-2])return false;
		}
	}else{
		if(str[n-1]=='x'){
			if(side[0]!=side[n-2])return false;
		}else{
			if(side[0]==side[n-2])return false;
		}
	}
	if(side[0]==0){
		if(str[0]=='o'){
			if(side[1]!=side[n-1])return false;
		}else{
			if(side[1]==side[n-1])return false;
		}
	}else{
		if(str[0]=='x'){
			if(side[1]!=side[n-1])return false;
		}else{
			if(side[1]==side[n-1])return false;
		}
	}
	return true;
}

int main(void){
	scanf("%d",&n);
	cin >> str;
	for(int i=0;i<2;i++){
		side[0]=i;
		for(int j=0;j<2;j++){
			side[1]=j;
			if(check()){
				for(int k=0;k<n;k++){
					printf("%c",side[k]==0?'S':'W');
				}
				printf("\n");
				return 0;
			}
		}
	}
	printf("-1\n");
	return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long MOD = 1000000007;
const long long INF = 0x3f3f3f3f;
using namespace std;
typedef long long ll;
map<int, int> mp;
using Graph = vector<vector<int>>; 
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a, b, c; cin >> a >> b >> c;
	if (a==b&&b==c&&a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
		cout << -1 << endl;
		return 0;
	}
	else if(a==b&&b==c){
		cout << 0 << endl;
		return 0;
	}
	if (a % 2 != 0 || b % 2 != 0 || c % 2 != 0) {
		cout << 0 << endl;
		return 0;
	}
	int cnt = 1;
	while (true) {
		if (a % 4 != 0 || b % 4 != 0 || c % 4 != 0) {
			cout << cnt << endl;
			return 0;
		}
		else {
			int tmp = a / 2;
			int tmp2 = b / 2;
			int tmp3 = c / 2;
			a = tmp2 + tmp3;
			b = tmp + tmp3;
			c = tmp + tmp2; cnt++;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;


vector<int> adj[100005];
int parent[100005];

int visited[100006];

int32_t main(){
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int x, y;
		cin >> x >> y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	queue<int> q;
	q.push(1);
	parent[1] = -1;
	visited[1] = 1;
	
	while(q.size()){
		auto p = q.front();
		q.pop();
		for(auto x : adj[p]){
			if(visited[x])
				continue;
			q.push(x);
			parent[x] = p;
			visited[x] = 1;
		}
	}
	
	int ok = 1;
	for(int i = 2; i <= n; i++){
		ok &= (parent[i] != 0);
	}
	
	if(!ok){
		cout << "No";
		return 0;
	}
	
	cout << "Yes\n";
	for(int i = 2; i <= n; i++)
		cout << parent[i] << endl;
	
	
	

	return 0;
}



Measured memory_bytes: 13772
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
#include<utility>
#include<vector>
using namespace std;
//--------------------

int main() {

	long res = 0;
	long N, K; cin >> N >> K;
	res = abs(N - (K - 1) - 1);
    if (K == 1) res = 0;
	cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int P[12][12],n,d;
int dis(int a,int b){
	int res=0;
	for(int i=0;i<d;i++) res+=(P[a][i]-P[b][i])*(P[a][i]-P[b][i]);
	return res;
}
int main(){
	ios::sync_with_stdio();
	cin.tie(0);
	cin>>n>>d;
	for(int i=0;i<n;i++){
		for(int j=0;j<d;j++){
			cin>>P[i][j];
		}
	}
	int cnt=0;
	for(int i=0;i<n;i++)
		for(int j=i+1;j<n;j++){
			int dist=dis(i,j),dd=sqrt(dist);
			if(dist==dd*dd) cnt++;
		}
	cout<<cnt<<endl;
}

Measured memory_bytes: 256