akhauriyash/Code-Regression huggingface dataset:
from math import factorial as f
p = int(1e9+7)
X, Y = map(int, input().split())
n = (2 * X - Y) // 3
m = (2 * Y - X) // 3
if(n < 0 or m < 0 or (X + Y) % 3 > 0):
  print(0)
else:
  fac = [0] * (n+m+1)
  inv = [0] * (n+m+1)
  finv = [0] * (n+m+1)

  fac[0] = fac[1] = 1
  inv[1] = 1
  finv[0] = finv[1] = 1
  
  for i in range(2,n+m+1):
    fac[i] = fac[i-1] * i % p
    inv[i] = p - inv[p%i] * (p // i) % p
    finv[i] = finv[i-1] * inv[i] % p

  print(fac[n+m] * finv[n] * finv[m] % p)

Measured memory_bytes: 82072
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<long long> x(N), y(N);
    for(int i=0; i<N; i++) {
        cin >> x[i] >> y[i];
        if(x[i] > y[i]) swap(x[i], y[i]);
    }

    long long xmax = *max_element(x.begin(), x.end());
    long long xmin = *min_element(x.begin(), x.end());
    long long ymax = *max_element(y.begin(), y.end());
    long long ymin = *min_element(y.begin(), y.end());

    long long ans = (xmax - xmin) * (ymax - ymin);

    long long dif1 = ymax - xmin;

    vector<pair<long long, long long>> xy(N);
    for(int i=0; i<N; i++) xy[i] = pair<long long, long long>(x[i], y[i]);
    sort(xy.begin(), xy.end());

    multiset<long long> ms;
    for(int i=0; i<N; i++) ms.insert(xy[i].first);

    long long dif2 = *ms.rbegin() - *ms.begin();
    for(int i=0; i<N; i++){
        auto itr = ms.find(xy[i].first);
        ms.erase(itr);
        ms.insert(xy[i].second);
        dif2 = min(dif2, *ms.rbegin() - *ms.begin());
    }
    ans = min(ans, dif1 * dif2);

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

Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
#define int long long
main(){
  int n;
  while(cin>>n,n){
    int a[n],b[n-1],s=0;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n-1;i++)cin>>b[i];
    for(int i=0;i<n;i++)s+=a[i];
    sort(b,b+n-1);
    int sum=s*n,t=n-1;
    for(int i=0;i<n-1;i++){
      s+=b[n-2-i];
      sum=max(sum,s*t--);
    }
    cout<<sum<<endl;
  }
}

Measured memory_bytes: 4152
#include <algorithm>
#include <iostream>
#include <math.h>
#define ll long long int
#define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n)

using namespace std;

int main() {
    int n;
    cin >> n;
    int digit = 0, num = n;
    while (num > 0) {
        digit++;
        num /= 10;
    }
    if (digit == 6)
        cout << 90909 << endl;
    else if (digit == 5)
        cout << 9 + 900 + (n - 9999) << endl;
    else if (digit == 4)
        cout << 909 << endl;
    else if (digit == 3)
        cout << 9 + (n - 99) << endl;
    else if (digit == 2)
        cout << 9 << endl;
    else
        cout << n << endl;
    return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())

x=list(map(int,input().split()))

if n>=m:
    print(0)
    exit(0)

if n==1:
    print(max(x) - min(x))
    exit(0)

x= sorted(x)

dist =[0]*(m-1)
for i in range(m-1):
    dist[i] = x[i+1]-x[i]

dist = sorted(dist,reverse=True)

total=max(x)-min(x)
for j in range(n-1):
    total -=dist[j]


print(total)

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

int main(){
  int N,X;  cin >> N >> X;
  int x = 0;
  int ans;
  for(int i=0;i<N;i++){
    int L;  cin >> L;
    x += L;
    if(x > X){
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << N+1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int dp[101010];
bool ng[101010];

signed main() {
  INIT;

  VAR(int,n,m);
  REP(i,m){
    VAR(int, a);
    ng[a] = true;
  }

  dp[0] = 1;

  REP(i,n+1){
    if (i>0 && !ng[i-1]) (dp[i] += dp[i-1]) %= MOD;
    if (i>1 && !ng[i-2]) (dp[i] += dp[i-2]) %= MOD;
    //debug(dp[i]);
  }
  OUT(dp[n])BR;
  
  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <stdio.h>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>

using namespace std;

#define x first
#define y second
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define all(x) x.begin(),x.end()
#define SZ(x) int(x.size())
#define rep(i, a, b) for(int i = a; i < b; i++)
#define per(i, a, b) for(int i = b-1; i >= a; i--)
#define DBG(x) cerr << (#x) << "=" << x << "\n";
#define ll long long
#define inf 1000000007
#define mod 998244353 //1000000007
#define N 400005

template<typename U, typename V> void Min(U &a, const V & b){if(a > b)a = b;}
template<typename U, typename V> void Max(U &a, const V & b){if(a < b)a = b;}
template<typename U, typename V> void add(U &a, const V & b){a = (a + b) % mod;} 
template<typename U> U gcd(U a, U b){
	if(a == 0)return b;
    if(b == 0)return a;
	if(a >= b)return gcd(a-b, b);
	else return gcd(a, b - a);
} 
int pow(int a, int b){
    int ans = 1;
    while(b){
        if(b & 1)ans = 1LL * ans * a % mod;
        a = 1LL * a * a % mod;
        b >>= 1;
    }
    return ans;
}

int main(){
    int T, m, n, i, j, k, K;
    int a, b;
    scanf("%d%d%d%d", &n, &m, &a, &b);
    rep(i, 0, n-b){
        rep(j, 0, a)putchar('1');
        rep(j, a, m)putchar('0');
        puts("");
    }
    rep(i, n-b, n){
        rep(j, 0, a)putchar('0');
        rep(j, a, m)putchar('1');
        puts("");
    }
}


Measured memory_bytes: 1280
import java.util.Scanner;

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

		Scanner scan = new Scanner(System.in);
		String num = scan.nextLine();
		String[] numbers = num.split(" ");
		double S = Integer.parseInt(numbers[0]);
		double W = Integer.parseInt(numbers[1]);

		if(S>W) {
			System.out.println("safe");
		}else {
			System.out.println("unsafe");
		}

	}
}


Measured memory_bytes: 35756
s=input()
n=int(input())
ans=0
tmp=1
for i in range(len(s)-1):
  if s[i]==s[i+1]:
    tmp+=1
  else:
    ans+=tmp//2
    tmp=1
if tmp!=0:
  ans+=tmp//2
ans*=n
if len(s)!=1 and s[0]==s[-1]:
  top=0
  bottom=0
  for i in range(len(s)):
    if s[:i].count(s[0])==i:
      top=i
    if s[-i:].count(s[-1])==i:
      bottom=i
  if top!=len(s)-1:
    ans-=(top//2+bottom//2-(top+bottom)//2)*(n-1)
  elif len(s)%2==1:
    ans+=n//2
if len(s)==1:
  print(n//2)
else:
  print(ans)

Measured memory_bytes: 9176
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
using ll = long long;

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

    if (A == B) {
        cout << C << endl;
    } else if(B == C) {
        cout << A << endl;
    } else if(C == A) {
        cout << B << endl;
    }

    return 0;
}


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

int main() {
	
	int n, k;
	
	cin>>n>>k;
	
	bool arr[10];
	
	memset(arr, 0, sizeof arr);
	
	for(int i=0; i<k; i++){
		
		int d;
		cin>>d;
		arr[d]=1;
	}
	
	int flag=1;
	for( int num=n; num<=100000; num++)
	{
		flag=1;
		string s= to_string(num);
		for(char c: s){
				if(arr[c-'0']) flag=0; 
			}
		if(flag==1) {
			cout<<num<<endl;
			return 0;
		}
	}
	return 0;
}


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

int main()
{
    int n,m,i,max=0,j,cnt=0;
    char s[100][10],t[100][10],x[200][10];
   
   scanf("%d",&n);
   
    for(i=0; i<n; i++)
        scanf("%s",s[i]);
   
    scanf("%d",&m);
   
    for(i=0; i<m; i++)
        scanf("%s",t[i]);
   
    for(i=0; i<n; i++)
    {
        cnt=0;
        for(j=0; j<n; j++)
        {
            if(strcmp(s[i],s[j])==0)
                cnt++;
        }
        for(j=0; j<m; j++)
        {
            if(strcmp(s[i],t[j])==0)
                cnt--;
        }
        if(max<cnt)
            max=cnt;
    }
    printf("%d\n",max);
}


Measured memory_bytes: 128
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  int n;
  int ct=0;
  string s,t;
  cin>>s>>n;
  for(i=0;i<n;i++){
    cin>>t;
    t+=t;
    if(t.find(s)!=string::npos)
      ct++;
  }
  cout<<ct<<endl;
  return 0;
}

Measured memory_bytes: 0
/* 挿入ソート */
#include <stdio.h>
#define MAX_N 100

void insertionSort(int ary[], int n) {
  /* nは配列aryの大きさ */
  int i;
  for (i = 1; i < n; i++) {
    int key = ary[i];
    int j = i-1;
    while (j >= 0 && ary[j] > key) {
      ary[j+1] = ary[j];
      j--;
    }
    ary[j+1] = key;

    /* 各計算ステップの途中結果を表示 */
    printf("%d", ary[0]);
    for (j = 1; j < n; j++) {
      printf(" %d", ary[j]);
    }
    putchar('\n');
  }
}

int main(void) {
  int i, N;
  int array[MAX_N];

  scanf("%d", &N);
  for (i = 0; i < N; i++) {
    scanf("%d", &array[i]);
  }

  /* 最初の状態を出力 */
  printf("%d", array[0]);
  for (i = 1; i < N; i++) {
    printf(" %d", array[i]);
  }
  putchar('\n');
  
  insertionSort(array, N);

  return 0;
}

Measured memory_bytes: 604
package main

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

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

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

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

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

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	l := getNextInt(scanner)

	min := absint(l)
	ans := 0
	reduce := 0
	for i := 0; i < n; i++ {
		ans += l + i
		if min >= absint(l+i) {
			min = absint(l + i)
			reduce = l + i
		}
	}

	fmt.Fprintln(writer, ans-reduce)
	writer.Flush()
}
func absint(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  string S;
  cin >> N >>S;
  string alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";  
  for (int i=0; i<S.size(); i++){
    string a = S.substr(i,1);
    int b = alpha.find(a);//Sから取り出したアルファベットの数値化
    int c = (b+N)%26;//アルファベットの位置
    cout << alpha.substr(c,1);    
  }
  cout << endl;
}

Measured memory_bytes: 256
import java.awt.Point;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Scanner;
  
public class Main {
     
    static int H, W, C;
    static int[][] P;
    
    static int[][] p;
    static boolean[][] check;
    
    static int[] dx = {0, 1, 0, -1};
    static int[] dy = {1, 0, -1, 0};
    
    static int calc(int[] order)
    {
    	for (int y = 0; y < H; y++) {
			for (int x = 0; x < W; x++) {
				p[y][x] = P[y][x];
			}
		}
    	
    	for (int i = 0; i < 6; i++) {
    		int color = p[0][0];
    		
    		for (int y = 0; y < H; y++) {
    			for (int x = 0; x < W; x++) {
    				check[y][x] = false;
    			}
    		}
    		
    		LinkedList<Point> queue = new LinkedList<Point>();
    		queue.offer(new Point(0, 0));
    		while(!queue.isEmpty())
    		{
    			Point poi = queue.poll();
    			if( poi.x < 0 || W <= poi.x || poi.y < 0 || H <= poi.y )  continue;
    			if(check[poi.y][poi.x] == true) continue;
    			
    			check[poi.y][poi.x] = true;
    			for (int j = 0; j < 4; j++) {
					int x = poi.x + dx[j];
					int y = poi.y + dy[j];
					if( x < 0 || W <= x || y < 0 || H <= y )  continue;
					
					if(p[y][x] == color) queue.offer(new Point(x, y));
				}
    		}
    		
    		if(i == 5) break;
    		
    		for (int y = 0; y < H; y++) {
    			for (int x = 0; x < W; x++) {
    				if(check[y][x] == true) p[y][x] = order[i];
    			}
    		}
		}
    	
    	int count = 0;
    	for (int y = 0; y < H; y++) {
			for (int x = 0; x < W; x++) {
				if(check[y][x] == true) count++;
			}
		}
    	
    	return count;
    }
     
    static void start()
    {
    	int max = 0;
    	p = new int[H][W];
    	check = new boolean[H][W];
    	
        for (int i0 = 1; i0 <= 6; i0++) {
        	
        	for (int i1 = 1; i1 <= 6; i1++) {
        		
        		for (int i2 = 1; i2 <= 6; i2++) {
        			
        			for (int i3 = 1; i3 <= 6; i3++) {
        				
        				max = Math.max(max, calc(new int[]{i0, i1, i2, i3, C}));
        			}
        		}
    		}
		}
        
        System.out.println(max);
    }
      
    public static void main(String[] args)
    {
        Scanner sca = new Scanner(System.in);
        
        while(true)
        {
            H = sca.nextInt();
            W = sca.nextInt();
            C = sca.nextInt();
            if(H == 0) break;
             
             P = new int[H][W];
             for (int y = 0; y < H; y++) {
				for (int x = 0; x < W; x++) {
					P[y][x] = sca.nextInt();
				}
			}
            
            start();
        }
         
    }
}

Measured memory_bytes: 285968
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000007;

int main() {

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

	Int n;
	cin >> n;

	vector<vector<Int>> even(100000 + 1, vector<Int>(2, 0));
	vector<vector<Int>> odd(100000 + 1, vector<Int>(2, 0));

	Int temp = 0;
	for (Int i = 0; i < 100001; i++) {
		even[i][1] = temp;
	    odd[i][1] = temp;
		temp++;
	}

	Int temp1 = 0;
	Int flag = 0;
	for (Int i = 0; i < n; i++) {
		cin >> temp;

		if (i == 0)temp1 = temp;
		if (temp1 != temp)flag = 1;


		if (i % 2)odd[temp][0]++;
		else if(i%2==0) even[temp][0]++;
		
	}

	sort(odd.begin(), odd.end());
	sort(even.begin(), even.end());

	Int ans = 0;
	if (flag == 0) {
		cout << n / 2 << endl;
		return 0;
	}

	if (odd[100000][1] != even[100000][1]) {
		ans = n - odd[100000][0] - even[100000][0];
		cout << ans << endl;
		return 0;
	}
	else {
		ans = min(n - odd[99999][0] - even[100000][0], n - odd[100000][0] - even[99999][0]);
		cout << ans << endl;
		return 0;

	}
}

Measured memory_bytes: 11392
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
using namespace std;

template<class T>
void in(vector<T>& V) {
	for (auto itr = V.begin(); itr != V.end(); itr++)cin >> *itr;
	return;
}

template<class T>
void out(vector<T>& V) {
	for (T& itr : V)cout << itr << endl;
	return;
}

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

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

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

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

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

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
vector< T > dijkstra(WeightedGraph< T >& g, int s) {
	const auto INF = numeric_limits< T >::max();
	vector< T > dist(g.size(), INF);

	using Pi = pair< T, int >;
	priority_queue< Pi, vector< Pi >, greater< Pi > > que;
	dist[s] = 0;
	que.emplace(dist[s], s);
	while (!que.empty()) {
		T cost;
		int idx;
		tie(cost, idx) = que.top();
		que.pop();
		if (dist[idx] < cost) continue;
		for (auto& e : g[idx]) {
			auto next_cost = cost + e.cost;
			if (dist[e.to] <= next_cost) continue;
			dist[e.to] = next_cost;
			que.emplace(dist[e.to], e.to);
		}
	}
	return dist;
}

struct circle {
	long double x, y, r;
};
vector<circle> circles;
int N;

int main() {
	circle tc;
	cin >> tc.x >> tc.y;
	tc.r = 0;
	circles.push_back(tc);
	cin >> tc.x >> tc.y;
	tc.r = 0;
	circles.push_back(tc);
	cin >> N;
	for (int n = 0; n < N; n++) {
		circle c;
		cin >> c.x >> c.y >> c.r;
		circles.push_back(c);
	}
	WeightedGraph<long double> edges;
	edges.resize(N + 2);
	for (int s = 0; s < N + 2; s++) {
		for (int t = s + 1; t < N + 2; t++) {
			circle cs = circles[s];
			circle ct = circles[t];
			long double rr = (cs.x - ct.x) * (cs.x - ct.x) + (cs.y - ct.y) * (cs.y - ct.y);
			long double r = sqrt(rr);
			if (r - cs.r - ct.r < 0) {
				edges[s].push_back(edge<long double>(s, t, 0));
				edges[t].push_back(edge<long double>(t, s, 0));
			}
			else {
				r = r - cs.r - ct.r;
				edges[s].push_back(edge<long double>(s, t, r));
				edges[t].push_back(edge<long double>(t, s, r));
			}
		}
	}
	cout << setprecision(12) << dijkstra(edges, 0)[1] << endl;
	return 0;
}

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

using ll = long long;

int main() {
    int n, m; cin >> n >> m;
    vector<vector<int>> g(n);
    vector<int> col(n, -1);
    for(int i = 0; i < m; ++i) {
        int a, b; cin >> a >> b;
        g[a - 1].push_back(b - 1);
        g[b - 1].push_back(a - 1);
    }

    ll odd = 0, even = 0;
    function<bool(int, int)> dfs = [&] (int v, int c) {
        col[v] = c;
        odd += c == 1, even += c == 0;
        for(auto to : g[v]) {
            if(col[to] != -1) {
                if(col[to] == c) return true;
                continue;
            }
            if(dfs(to, !c)) return true;
        }
        return false;
    };
    bool bipartite = false;
    for(int i = 0; i < n; ++i) {
        if(col[i] != -1) continue;
        bipartite |= dfs(i, 0);
    }

    if(bipartite) {
        cout << 1LL * n * (n - 1) / 2 - m << endl;
    } else {
        cout << odd * even - m << endl;
    }
}


Measured memory_bytes: 6656
NUM = 20005

table = [""]*NUM

while True:
    T = str(input())
    if T == '-':
        break

    left = 0
    right = 0
    #長い配列にパターン文字列を転記
    for i in range(len(T)):
        #print(T[right])
        table[left+right] = T[right]
        right += 1

    num_shuffle = int(input())

    for loop in range(num_shuffle):
        pick_num = int(input())
        #先頭からpick_num文字を末尾に転記し、論理削除
        for i in range(pick_num):
            table[right+i] = table[left+i]
        left += pick_num
        right += pick_num

    for i in range(left,right):
        print("%s"%(table[i]),end = "")
    print()


Measured memory_bytes: 5724
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll N = 2000009;
const ll p = 31;
const ll m = 1e9 + 7;
const ll inf= 1e14;
ll mod = 1e9+7;
ll powm(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; }
// ll fact[N];


// ll ncr(ll n,ll r){
//      return (((fact[n]*powm(fact[r],mod-2))%mod)*powm(fact[n-r],mod-2))%mod;
// }
bool comp(string a,string b){
     if(a+b>b+a){
          return false;
     }
     return true;
}
 int main() {   
     ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
     // #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
     // #endif
     ll t = 1;
     // cin>>t;
     while(t--){
          string s;
          ll n,k;cin>>n>>k>>s;
          ll ans = 0;
          for(int i = 1;i<n;i++){
               if(s[i] == 'R' && s[i-1]=='R'){
                    ans++;
               }
          }
          for(int i = n-2;i>=0;i--){
               if(s[i]=='L'&&s[i+1]=='L'){
                    ans++;
               }
          }
          cout<<min(ans + 2*k,n-1);
     }
}            


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
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;}
/*
void chmin(ll a, ll b){if (a>b){a = b; return true;}return false;}
void chmax(ll a, ll b){if (a<b){a = b; return true;}return false;}
*/

const ll MOD = 1000000007;
const ll INF = 9999999999;

int main() {
  string s,t; cin >>s >>t;
  cout <<t <<s <<endl;
}

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

int main() {
	int p, q;

	while(cin >> p >> q) {
		vector<int> v;
		bool flag = true;

		p %= q;
		v.push_back(p);
		while(flag){
			p *= 10;
			cout << p / q;
			p %= q;
			if(p == 0) {
				cout << endl;
				break;
			}
			for(int i = 0; i < v.size(); i++) {
				if(p == v[i]) {
					flag = false;
					cout << endl;
					for(int j = 0; j < i; j++)
						cout << " ";
					for(int j = i; j < v.size(); j++)
						cout << "^";
					cout << endl;
				}
			}
			v.push_back(p);
		}
	}

	return 0;
}

Measured memory_bytes: 1220
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

string s;

bool v(int a)
{
	return 1<=a&&a<=12;
}

int main()
{
	cin>>s;
	int a=atoi(s.substr(0,2).c_str()),b=atoi(s.substr(2,2).c_str());
	if(v(a)&&v(b)) puts("AMBIGUOUS");else
	if(v(a)) puts("MMYY");else
	if(v(b)) puts("YYMM");else
	puts("NA");
	rt0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  int k, s;
  int ans;
  cin >> k;
  cin >> s; 
  ans = 0;
  for (int x = 0; x<=k; x++){
    for (int y = 0; y<=k; y++){
      int z = s - x -y;
      if (z >= 0 and z <= k){
        ans += 1;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i > 0; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> p;

int main() {
	int a,b,c;
	cin >> a >> b >> c;
	if (b / a > c) {
		cout << c;
	}
	else {
		cout << b / a;
	}
	return 0;
}

//Ctrl+Aを使わない

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

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

typedef struct node *Node;
#define NIL NULL

Node root = NIL;

Node treeMinimum(Node x){
  while(x->left!=NIL)x=x->left;
  return x;
}

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

Node treeSuccessor(Node x){
  if(x->right != NIL)return treeMinimum(x->right);
  Node y=x->parent;
  while(y != NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y;
  Node x;
  if(z->left == NIL || z->right==NIL)y=z;
  else y=treeSuccessor(z);
  if(y->left != NIL)x=y->left;
  else x=y->right;
  if(x!=NIL)x->parent=y->parent;
  if(y->parent==NIL)root=x;
  else if(y==y->parent->left)y->parent->left=x;
  else y->parent->right=x;
  if(y!=z)z->key=y->key;
  free(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!=NIL){
    y=x;
    if(z->key < x->key)x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL)root=z;
  else if(z->key < y->key)y->left=z;
  else y->right=z;
}

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

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

void aaaaa(int a){
  int i, count=0;
  for(i=0; i<a; i++){
    count++;
  }
}

int main(){
  int n, i, x, a=2;
  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));
    }
  }

  aaaaa(a);
  return 0;
}



Measured memory_bytes: 20612
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
using namespace std;

typedef long long int ll;

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	string st;
	cin >> st;
	if(n&1)
		cout << "No";
	else{
		string c1 = "" , c2 = "";
		for(ll i=0; i<st.length()/2; i++){
			c1 += st[i];
			c2 += st[st.length()/2 + i];
		}
		if(c1==c2)
			cout << "Yes";
		else
			cout << "No";
	}
	return 0;
}

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

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class FForkInTheRoad {
public:
	void solve(std::istream& in, std::ostream& out) {
        int N, M;
        in >> N >> M;
        vector<int> s(M), t(M);
        REP(i,0,M) in >> s[i] >> t[i];

        vector<vector<int>> st(N+1), ts(N+1);
        REP(i,0,M) {
            st[s[i]].push_back(t[i]);
            ts[t[i]].push_back(s[i]);
        }
        // calculate mean distances from each locations
        vector<double> dp(N+1, 0);
        RREP(current, 1, N) {
            for (const auto next : st[current]) {
                dp[current] += dp[next] + 1;
            }
            dp[current] /= st[current].size();
        }
        // find block candidates
        vector<pair<int,int>> blockCandidates = {{-1, -1}};
        REP(current,1,N) {
            if (st[current].size() == 1) continue;
            double candidate = 0;
            for (const auto next : st[current]) {
                if (dp[candidate] < dp[next]) candidate = next;
            }
            blockCandidates.push_back({current, candidate});
        }
        // calculate mean distances again for all block candidates
        double answer = 1e5;
        for (const auto& block : blockCandidates) {
            vector<double> dp(N+1, 0);
            RREP(current, 1, N) {
                for (const auto next : st[current]) {
                    if (block.first == current && block.second == next) continue;
                    dp[current] += dp[next] + 1;
                }
                if (block.first == current) {
                    dp[current] /= st[current].size() - 1;
                } else {
                    dp[current] /= st[current].size();
                }
            }
            answer = min(answer, dp[1]);
        }
        out << fixed << setprecision(10) << answer << "\n";
	}
};


int main() {
	FForkInTheRoad solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3968
#include <iostream>
#include <string>
#include <cstdio>

using namespace std;

int main(){
  string g;
  int y, m, d;


  while(1){
    cin >> g;
    if( g == "#" ) break;

    scanf("%d %d %d", &y, &m, &d);

    if(y >= 32){
      y -= 30;
      printf("? %d %d %d\n",  y, m, d);
    }
    else if(y == 31 && m >= 5){
      printf("? 1 %d %d\n",  m, d);
    }
    else
      printf("HEISEI %d %d %d\n", y, m, d);
  }
  return 0;
}


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

char s[10][21];
bool used[10][20];
int main() {
	int h, w;
	while (scanf("%d%d", &h, &w), h) {
		rep(i, h)scanf("%s", s[i]);
		map<string, int>mp;
		rep(i, h)rep(j, w) {
			for (int dx = -1; dx <= 1; dx++) {
				for (int dy = -1; dy <= 1; dy++) {
					if (dx == 0 && dy == 0)continue;
					string t;
					memset(used, 0, sizeof(used));
					int x = i, y = j;
					while (!used[x][y]) {
						t += s[x][y]; used[x][y] = 1; x += dx; y += dy;
						x = (x + h) % h; y = (y + w) % w;
						mp[t]++;
					}
				}
			}
		}
		string ans = "0";
		for (auto p : mp) {
			if (p.second > 1 && ans.size() < p.first.size())ans = p.first;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 38032
#include<iostream>
using namespace std;
int main(){
  bool num[1000000] = {false};
  for(int i=2; i<1000; i++){
    if(!num[i]) for(int j=i*i; j<1000000; j+=i) num[j] = true;
  }
  int n;
  while(cin >>n){
    int ans = 0;
    for(int i=2; i<=n; i++) if(!num[i]) ans++;
    cout <<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 2144
#include <algorithm>  // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>     // bitset
#include <cctype>     // isupper, islower, isdigit, toupper, tolower
#include <cstdint>    // int64_t, int*_t
#include <cstdio>     // printf
#include <deque>      // deque
#include <iomanip>    // fixed, setprecision
#include <iostream>   // cout, endl, cin
#include <map>        // map
#include <queue>      // queue, priority_queue
#include <set>        // set
#include <stack>      // stack
#include <string>     // string, to_string, stoi
#include <tuple>      // tuple, make_tuple
#include <unordered_map>  // unordered_map
#include <unordered_set>  // unordered_set
#include <utility>        // pair, make_pair
#include <vector>         // vector
using namespace std;

int main() {
  string s;
  cin >> s;
  int bw = 0, wb = 0;
  for (int i = 0; i < s.length(); i++) {
    if (i % 2 == 0) {
      if (s[i] == '0') bw++;
      if (s[i] == '1') wb++;
    } else {
      if (s[i] == '1') bw++;
      if (s[i] == '0') wb++;
    }
  }
  cout << min(bw, wb) << endl;
}


Measured memory_bytes: 3316
use proconio::input;
use std::cmp::min;

const INF: usize = 1000000;

fn main() {
	input!(n: usize);

	let mut dp = vec![INF; n+1];
	dp[0] = 0;
	for i in 1..=n {
		let mut cnt = dp[i-1] + 1;

		let mut j = 6;
		while j <= i {
			cnt = min(cnt, dp[i-j] + 1);
			j *= 6;
		}

		let mut j = 9;
		while j <= i {
			cnt = min(cnt, dp[i-j] + 1);
			j *= 9;
		}

		dp[i] = cnt;
	}
	println!("{}", dp[n]);
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);


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

  vector<ll> l,r;

  REP(i,n){
    ll x;
    cin >> x;
    if(x<0){
      l.emplace_back(-x);
    }else if(x>0){
      r.emplace_back(x);
    }else{
      k--;
    }
  }
  reverse(ALL(l));
  if(k==0){
    cout << 0 << endl;
    return(0);
  }
  
  if(l.size()==0){
    cout << r[k-1] << endl;
    return(0);
  }
  if(r.size()==0){
    cout << l[k-1] << endl;
    return(0);
  }

  ll ans = INF;
  for(int li = 1; li <= k && li <= l.size(); li++){
    int ri = k-li;
    if(ri > r.size())continue;
    ans=min(ans,l[li-1]*2+r[ri-1]);
  }
  for(int ri = 1; ri <= k && ri <= r.size(); ri++){
    int li = k-ri;
    if(li > l.size())continue;
    ans=min(ans,r[ri-1]*2+l[li-1]);
  }
  cout << ans << endl;
}



Measured memory_bytes: 1656
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[200][3] = {{0}};
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            cin >> a[i][j];
        }
    }
    int ans[200] = {0};
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < n; j++){
            int temp = a[j][i];
            bool flg = 0;
            for(int k = 0; k < n; k++){
                if(temp == a[k][i] && j != k){
                    flg = 0;
                    break;
                }
                else flg = 1;
            }
            if(flg){
                ans[j] += a[j][i];
            }
        }
    }
    for(int i = 0; i < n; i++){
        cout << ans[i] << endl;
    }
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <limits>
#include <string>
#include <vector>

using namespace std;

const long long INF = 1LL << 60;

//各桁の和を出力
long long Sum(long long n) {
  long long m = 0;
  while (n) {
    m += n % 10;
    n /= 10;
  }
  return m;
}

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void Comuse() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

#define comuse Comuse()
// nCk(comuseを使え)
long long combi(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// pCk(comuseを使え)
long long perm(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] % MOD) % MOD;
}

//最小公倍数(aとbの)
long long lcm(long long a, long long b) {
  long long n;
  n = a / __gcd(a, b) * b;
  return n;
}

// auto A = div(n)
vector<long long> div(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) {
        ret.push_back(n / i);
      }
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}

//(aのn乗をmodで割ったあまり)
long long modpow(long long a, long long n, long long mod) {
  long long ans = 1;
  while (n > 0) {
    if (n & 1) {
      ans = ans * a % mod;
    }

    a = a * a % mod;

    n >>= 1;
  }

  return ans;
}

void solve();

const int MAX_N = 131072;
// segment tree
int NN;
int seg[MAX_N * 2 - 1];
void seguse() {
  for (int i = 0; i < 2 * NN - 1; i++) {
    seg[i] = INT_MAX;
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << fixed;
  solve();
}

///////////////////////////////////////////////////////////

vector<vector<int>> bingo(3, vector<int>(3));
int N;
vector<int> number(100);
void solve() {
  for(int i = 0; i < 3; i++){
    cin >> bingo.at(i).at(0) >> bingo.at(i).at(1) >> bingo.at(i).at(2);
  }
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> number.at(i);
    for(int j = 0; j < 3; j++){
      for(int t = 0; t < 3; t++){
        if(bingo.at(j).at(t) == number.at(i)){
          bingo.at(j).at(t) = -1;
        }
      }
    }
  }
  for(int i = 0; i < 3; i++){
    if(bingo.at(i).at(0) == -1 && bingo.at(i).at(1) == -1 && bingo.at(i).at(2) == -1){
      cout << "Yes" <<endl;
      return;
    } else if(bingo.at(0).at(i) == -1 && bingo.at(1).at(i) == -1 && bingo.at(2).at(i) == -1){
      cout << "Yes" <<endl;
      return;
    }
  }
  if(bingo.at(0).at(0) == -1 && bingo.at(1).at(1) == -1 && bingo.at(2).at(2) == -1){
      cout << "Yes" <<endl;
      return;
  }
  if(bingo.at(0).at(2) == -1 && bingo.at(1).at(1) == -1 && bingo.at(2).at(0) == -1){
      cout << "Yes" <<endl;
      return;
  }
  cout << "No" <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;

int main () {
    string s;

    cin >> s;

    if (s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes";
    } else cout << "No";
}
/*
    Good Luck
        -Lucina
*/




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

const int MOD = (int)1e9+7;
const double PI=(acos(-1));

double f(double a,double b,double theta){
	if(theta>PI/2.0)	return 0.0;
	double ans;
	if(a*tan(theta)<=b)	ans=a*a*b - a*a*a*tan(theta)/2.0;
	else	ans=b*b/tan(theta)*a/2.0;
	return ans;
}

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

	double ok=PI/2.0;
	double ng=0.0;
	for(int i=1;i<=100000;i++){
		double mid=(ok+ng)/2.0;
		if(f(a,b,mid)<x)	ok=mid;
		else	ng=mid;
	}
	printf("%.9lf\n",ok/PI*180);

	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;

typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}

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

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll n,ans=0;
    cin >> n;
    vector<vector<ll>> x(n,vector<ll>(n));
    for (ll i=0;i<n;i++)for(ll j=0;j<n;j++)x[i][j]=2;
    for (ll i=0;i<n;i++){
        ll a;
        cin >> a;
        for (ll j=0;j<a;j++){
            ll b,c;
            cin >> b >> c;
            x[i][b-1]=c;
        }
    }
    for (int bit = 0; bit < (1<<n); ++bit){
        vector<ll> S;
        for (ll i = 0; i < n; ++i) {
            if (bit & (1<<i)) {
                S.push_back(i);
            }
        }
        ll xx=S.size();
        bool z[n];
        fill(z,z+n,false);
        for (ll i=0;i<S.size();i++){
            z[S[i]]=true;
        }
        bool flag=false;
        for (ll i=0;i<n;i++){
            if (z[i])continue;
            for (ll j=0;j<n;j++){
                if (x[i][j]==2)continue;
                else if (x[i][j]==1){
                    if (!z[j])continue;
                }
                else if (x[i][j]==0){
                    if (z[j])continue;
                }
                flag=true;
                break;
            }
            if (flag)break;
        }
        if (flag)continue;
        ans=max(ans,n-xx);
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

std::chrono::time_point<std::chrono::steady_clock> start;

void tic() {
    start = std::chrono::steady_clock::now();
}
 
double toc() {
    auto now = std::chrono::steady_clock::now();
    std::chrono::duration<double> duration = now - start;
    return duration.count();
}

int main(){
    tic();

    int D;
    cin >> D;
    vector<int> c(26);
    rep(i,26) cin >> c[i];
    vector<vector<int>> s(D,vector<int>(26));
    rep(j,D) rep(i,26) cin >> s[j][i];

    vector<int> t(D);
    vector<vector<int>> last(26, vector<int>(1,-1));
    Int manzoku = 0;

    rep(j,1) {
        int maxs = 0;
        rep(i,26) maxs = max(maxs, s[j][i]);
        vector<int> v(0); //s[j][i]が最も大きくなるようなiを入れる
        rep(i,26) {
            if (s[j][i] == maxs) {
                v.push_back(i+1);
            }
        }
        if (v.size() == 1) {
            t[j] = v[0];
            last[t[j]-1].push_back(j);
        }
        else { //仮
            t[j] = v[0];
            last[t[j]-1].push_back(j);
        }
    }
    rep1(j,D-1) {
        vector<pair<int,int>> mzkp(26);
        rep(k,26) {
            int mzknow = s[j][k];
            rep(i,26) {
                if (i != k) mzknow -= c[i] * (j - last[i][last[i].size()-1]);
            }
            mzkp[k] = make_pair(mzknow,k);
        }
        sort(mzkp.begin(),mzkp.end());
        t[j] = mzkp[25].second+1;
        last[t[j]-1].push_back(j);
    }


    rep(i,26) last[i].push_back(D);

    vector<int> nums(26,0);
    rep(i,26) nums[i] = last[i].size();

    while (toc() < 1.9) {
        int d, q;
        vector<pair<int,int>> vp(26);
        rep(i,26) vp[i] = make_pair(c[i] - 2+(rand()%8) * nums[i],i);
        sort(vp.begin(),vp.end());
        reverse(vp.begin(),vp.end());
        q = vp[0].second + 1;
        int p;
        for (int j = 25; j>=0; j--) {
            p = vp[j].second;
            if (last[p].size() == 2) continue;
            else {
                break;
            }
        }
        if (last[p].size() <= 2) continue;
        int lpsz = last[p].size() - 2;
        d = last[p][1 + (rand() % lpsz)] + 1;
        manzoku = 0;

        manzoku -= s[d-1][t[d-1]-1];
        manzoku += s[d-1][q-1];

        auto iteold = find(last[t[d-1]-1].begin(), last[t[d-1]-1].end(), d-1);
        int old_last = *(iteold-1);
        manzoku -= c[t[d-1]-1] * (d-1 - old_last) * (*(iteold+1) - (d-1));

        auto itenew = upper_bound(last[q-1].begin(), last[q-1].end(), d-1);
        int new_last = *(itenew-1);
        manzoku += c[q-1] * (d-1 - new_last) * (*itenew - (d-1));

        if (manzoku > 0) {
            //更新したほうがよいならこれをやる
            last[t[d-1]-1].erase(iteold);
            last[q-1].insert(itenew,d-1);
            t[d-1] = q;
            nums[t[d-1]-1]--;
            nums[q-1]++;
        
        }
        //cout << manzoku << endl;
    }

    rep(j,D) cout << t[j] << endl;
}

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


int main(int argc, char** argv) {

    int n;
	cin>>n;
    vector <int> v;
    for (int i =0; i<2*n;i++)
    {int x;
        cin>>x;
        v.push_back(x);}
    sort(v.begin(), v.end());
    int max=0;
    for (int i = 0; i < v.size(); i=i+2)
    {
        max=max+min(v[i], v[i+1]);
    }
cout<<max;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ss second
#define ff first
#define N 200005
#define inf 1000000009
#define ll long long
#define pii pair<int,int>
#define sz(a) int(a.size())
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int n,k,a[N];
int b = 1;
int cep[N],sag[N];

int main(){
	scanf("%d%d",&n,&k);
	for(int i = 1;i <= n;i++) scanf("%d",&a[i]);
	while(b == 1 and k){
		memset(cep,0,sizeof(cep));
		memset(sag,0,sizeof(sag));
		for(int i = 1;i <= n;i++){
			cep[max(0,i-a[i]-1)]--;
			cep[i - 1]++;
			sag[i + 1]++;
			sag[min(n+1,i+a[i]+1)]--;
		}
		b = 0;
		for(int i = n;i >= 1;i--) cep[i] += cep[i+1];
		for(int i = 1;i <= n;i++){
			sag[i] += sag[i-1];
			a[i] = cep[i] + sag[i] + 1;
			if(a[i] != n) b = 1;
		}
		k--;
	}
	for(int i = 1;i <= n;i++)
		printf("%d ",a[i]);
}


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

using ll = long long;

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

	#ifdef ARTHUR_LOCAL
		ifstream cin("input.txt");
	#endif

	int n;
	cin>>n;

	priority_queue<pair<int,int>> pos_PQ,neg_PQ;
	int tot_bal=0;

	for(int i=0; i<n; i++)
	{
		string s;
		cin>>s;

		int min_bal=0;
		int cur_bal=0;

		int m = int(s.size());

		for(int j=0; j<m; j++)
		{
			if(s[j]=='(') cur_bal++;
			else cur_bal--;

			min_bal=min(min_bal,cur_bal);
		}

		tot_bal+=cur_bal;
		if(cur_bal>=0) pos_PQ.push({min_bal,cur_bal});
	
		else
		{
			// diff ... cur_bal

			neg_PQ.push({min_bal-cur_bal,cur_bal});
			// cout << min_bal << " " << cur_bal << endl;
		}
	}

	if(tot_bal!=0)
	{
		cout << "No" << endl;
		return 0;
	}

	// cout << "here" << endl;

	int cur_bal=0;

	while(!pos_PQ.empty())
	{
		int mb=pos_PQ.top().first;
		int cb=pos_PQ.top().second;
		pos_PQ.pop();

		if(cur_bal+mb>=0) cur_bal+=cb;
		else
		{
			cout << "No" << endl;
			return 0;
		}
	}

	cur_bal=0; // I think ...

	while(!neg_PQ.empty())
	{
		int diff = neg_PQ.top().first;
		int cb = neg_PQ.top().second;
		neg_PQ.pop();

		if(diff+cur_bal<0)
		{
			cout << "No" << endl;
			return 0;
		}

		else
		{
			cur_bal -= cb;
		}
	}

	cout << "Yes" << endl;
}

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


void solve() {
  int n;
  scanf("%d", &n);
  int guu, ki;
  guu = n/2;
  ki = n-guu;
  double ans = (double)ki/(double)(guu+ki);
  cout << ans << "\n";
}

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


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define rep(i,l,r)for(int i=(l);i<(r);i++)
#define min(p,q)((p)<(q)?(p):(q))

typedef struct tuple{int x,y,d;}T;
 
int xcmp(const void*p,const void*q){
	T *pp=(T*)p,*qq=(T*)q;
	if(pp->x<qq->x)return-1;
	if(pp->x>qq->x)return 1;
	if(pp->y<qq->y)return-1;
	if(pp->y>qq->y)return 1;
	return 0;
}

int ans=1e9;
T temp[400010];
void solve(int c){
	qsort(temp,c,sizeof(T),xcmp);
	rep(i,1,c)if(temp[i-1].x==temp[i].x&&temp[i-1].d==1&&temp[i].d==-1)ans=min(ans,abs(temp[i-1].y-temp[i].y)*5);
}

T dataaaa[4][200010];
T *data[4];
int main(){
	rep(i,0,4)data[i]=dataaaa[i];
	int n;
	scanf("%d",&n);
	int cnt[4]={};
	rep(i,0,n){
		int x,y;
		char c;
		scanf("%d%d %c",&x,&y,&c);
		T*t;
		if(c=='U')t=data[0]+cnt[0]++;
		if(c=='L')t=data[1]+cnt[1]++;
		if(c=='D')t=data[2]+cnt[2]++;
		if(c=='R')t=data[3]+cnt[3]++;
		t->x=x;
		t->y=y;
	}
	
	rep(d,0,4){
		//正面衝突
		int c=0;
		rep(i,0,cnt[0]){
			temp[c].x=data[0][i].x;
			temp[c].y=data[0][i].y;
			temp[c].d=1;
			c++;
		}
		rep(i,0,cnt[2]){
			temp[c].x=data[2][i].x;
			temp[c].y=data[2][i].y;
			temp[c].d=-1;
			c++;
		}
		solve(c);
		
		//UとLの衝突
		c=0;
		rep(i,0,cnt[0]){//U
			temp[c].x=data[0][i].x-data[0][i].y;
			temp[c].y=data[0][i].x+data[0][i].y;
			temp[c].d=1;
			c++;
		}
		rep(i,0,cnt[1]){//L
			temp[c].x=data[1][i].x-data[1][i].y;
			temp[c].y=data[1][i].x+data[1][i].y;
			temp[c].d=-1;
			c++;
		}
		solve(c);
		
		//rotate
		rep(d,0,4)rep(i,0,cnt[d]){
			T old=data[d][i];
			data[d][i].x=-old.y;
			data[d][i].y= old.x;
		}
		{T* aaa=data[0];data[0]=data[3];data[3]=data[2];data[2]=data[1];data[1]=aaa;}
		{int aaa=cnt[0];cnt[0]=cnt[3];cnt[3]=cnt[2];cnt[2]=cnt[1];cnt[1]=aaa;} 
	}
	
	if(ans==1e9)puts("SAFE");
	else printf("%d",ans);
}

Measured memory_bytes: 9516