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

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

    string s;
    cin >> s;
    ll n = s.size();
    string ans = "";
    for (ll i = 0; i < n; i++){
        if (s[i] == '0'){
            ans.push_back('0');
        }
        else if (s[i] == '1'){
            ans.push_back('1');
        }
        else{
            if (ans != ""){
                ans.pop_back();
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3600
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H,W,K;
    cin >> H >> W >> K;
    set<P> se;
    for(int i=0; i<K; i++){
        int a,b;
        cin >> a >> b;
        se.emplace(a,b);        
    }
    vector<int> sum(10,0);
    set<P> used;
    auto suzu = [&](int y,int x){
        int cnt = 0;
        for(int i=0; i<3; i++){
            for(int j=0; j<3; j++){
                if(se.count(P(y+i,x+j))) cnt++;                
            }
        }
        return cnt;
    };
    for(auto s:se){
        int y,x;
        tie(y,x) = s;
        for(int i=-2; i<=2; i++){
            for(int j=-2; j<=2; j++){
                int ny = y+i;
                int nx = x+j;
                if(ny<=0 || nx<=0 || ny+2>H || nx+2>W) continue;
                if(used.count(P(ny,nx))) continue;
                sum[suzu(ny,nx)]++;
                used.emplace(ny,nx);
            }
        }
    }
    int s = 0;
    for(int i=1; i<10; i++){
        s += sum[i];
    }
    cout << (ll)(H-2)*(W-2) - s << "\n";
    for(int i=1; i<10; i++){
        cout << sum[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 125488
#include <bits/stdc++.h> 
#include <time.h>
#define F(i,a,b) for(int i=a;i<=(b);++i)
#define dF(i,a,b) for(int i=a;i>=(b);--i)
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define maxnkp make_pair
#define fi first
#define se second
#define eps 1e-10
using namespace std;
typedef long long ll;
const int mods = 1e9+7;
const int maxn = 1e6+10;
const int N = 1e5+10;
const int E = 2e5+10;  
int n,k;

int main(){
	cin>>n>>k;
	if(k>=n){
		printf("unsafe\n");
	} 
	else printf("safe\n");
	
}

Measured memory_bytes: 3636
/*  
    |\_/|
    |* *|
    \_+_/
*/
#include<bits/stdc++.h>

#define endl '\n'

using namespace std;

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/

  int R,G;
  
  cin>>R>>G;

  cout<<(G*2)-R<<endl;
  return 0;

}




Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto A = RD;
	auto B = RD;

	writeln(A <= 8 && B <= 8 ? "Yay!" : ":(");
	stdout.flush();
	debug readln();
}


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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define what_is(x) cerr << #x << " is " << x << endl;

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n;
	scanf("%d", &n);
	vi a(n);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	int ans = *max_element(all(a)) - *min_element(all(a));
	cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Threading;

namespace ConsoleApp19
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string r = string.Concat(s.Reverse());
            int count = 0;

            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] != r[i])
                {
                    count++;
                } 
            }
            Console.WriteLine(count/2);
        }
    }
}


Measured memory_bytes: 26668
use std::fs;
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

const MOD: usize = 1000000007;
fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let n: usize = parse!(it);
    let mut dp = vec![0; n + 1];
    dp[0] = 1;
    let mut dp1 = vec![0; 200010];
    let mut c = vec![0];
    for _ in 0..n {
        c.push(parse!(it));
    }
    for i in 1..(n + 1) {
        dp[i] = dp1[c[i]];
        if c[i] != c[i - 1] {
            dp[i] += dp[i - 1];
            dp[i] %= MOD;
            dp1[c[i]] = dp[i];
        }
    }
    println!("{}", dp[dp.len() - 1] % MOD);
}

fn test() {
    let mut f = fs::File::open("foo.txt").unwrap();
    let mut s = String::new();
    f.read_to_string(&mut s).unwrap();
    solve(&s);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_main() {
        test();
    }
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 14588
import java.util.Scanner;

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

		Scanner scanner = new Scanner(System.in);

		int day = scanner.nextInt();

		switch (day) {
		case 25:
			System.out.println("Christmas");
			break;
		case 24:
			System.out.println("Christmas Eve");
			break;
		case 23:
			System.out.println("Christmas Eve Eve");
			break;
		case 22:
			System.out.println("Christmas Eve Eve Eve");
			break;
		}
	}

}


Measured memory_bytes: 21716
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::io::Read;
use std::io::{stdout, BufWriter, Write};
use std::cmp::min;

use std::collections::HashMap;
 
fn main() {
    let mut buf = String::new();
    
    let out = stdout();
    let mut out = BufWriter::new(out.lock());
 
    std::io::stdin().read_to_string(&mut buf).unwrap();
 
    let mut iter = buf.split_whitespace();
 
    let s: String = iter.next().unwrap().parse().unwrap();

    let ans = if s == "ABC" {
        "ARC"
    } else {
        "ABC"
    };
    println!("{}",ans);
    
}

Measured memory_bytes: 2120
while True:
    can_n, pass_min, pass_max = [int(i) for i in input().split()]
    if can_n == pass_min == pass_max == 0:
    	break
    	
    score_lst = []
    for _ in range(can_n):
    	score_lst.append(int(input()))
    
    gap_lst = []
    for i in range(pass_min, pass_max + 1):
    	gap_lst.append(score_lst[i - 1] - score_lst[i])
    
    gap_max = max(gap_lst)	
    for i in range(len(gap_lst) - 1, -1, -1):
    	if gap_lst[i] == gap_max:
    		print(i + pass_min)
    		break


Measured memory_bytes: 5620
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

long long int gcd(long long int x, long long int y)
{
	if (y == 0) { return x; }
	return gcd(y, x % y);
}

int main(void)
{
	long long int n, d[110], ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++) { cin >> d[i]; }
	for (int i = 0; i <  n - 1; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			ans += d[i] * d[j];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define F first
#define S second
//#define biGinf 9e+18
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define inpv(v) for(auto &x:v) cin>>x
#define otpv(v) for(auto &x:v) cout<<x<<nwl
#define otpv2(v) for(auto &x:v) cout<<x<<" "
#define CASES int tt;cin>>tt; while(tt--)
#define for0(i,n) for(int i=0; i<n; i++)
#define for1(i,n) for(int i=1; i<=n; i++)
#define sz(v) (int)(v).size()
#define vec(x) vector < x >
using vi = vector < int >;
using vvi = vector < vi >;
using pii = pair < int , int >;
using vpii = vector < pii >;
using int64 = long long;
//const int64 biGinf = 9e+18;
//const string yo = "YES", no = "NO";
const int inf = 2e9 + 7;
const char nwl = '\n';


string fun(int64 n) {
	string s = "";
	int64 d = n;
	while (d) {
		int c = d % 26;
		if (!c) c = 26;
		s = (char)(96 + c) + s;
		//cout << c << " " << (char)('a' - 1 + c) << nwl;
		d /= 26;
		//k *= 26;
	}
	return s;
}


int main() {
// #ifndef ONLINE_JUDGE
// 	if (fopen("input.txt", "r")) {
// 		freopen("input.txt", "r", stdin);
// 		freopen("output.txt", "w", stdout);
// 	}
// #endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//ur code
	int64 n;
	cin >> n;
	string s = "";
	int64 d = n;
	int64 k = 26;
	// int64 a = 1, b = 0;
	// while (b + pow(26, a) < n) {
	// 	b += (int64)pow(26, a);
	// 	a++;
	// }
	// d -= b;
	// a--;
	// cout << b << " " << a << nwl;
	while (d > 0 ) {
		int c = d % 26;
		d /= 26;
		if (!c) {
			c = 26;
			d--;

		}
		s = (char)(96 + c) + s;
		//cout << c << " " << (char)('a' - 1 + c) << nwl;

	}
	cout << s;
	return 0;
}

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

int main()
{
	int a = 0;
	for (int i = 0; i < 4; i++)
	{
		int j;
		cin >> j;
		a += j;

	}
	cout << a / 60 << endl << a % 60 << endl;

}

Measured memory_bytes: 1164
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FAST         ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll           long long
#define ld           long double
#define pb           push_back
#define mp           make_pair
#define pii          pair<int,int>
#define mii          map<int,int>
#define vi           vector<int>
#define vll          vector<long long>
#define all(a)       (a).begin(),(a).end()
#define clz(a)       __builtin_clz(a) // count leading zeroes
#define ctz(a)       __builtin_ctz(a) // count trailing zeroes
#define popc(a)      __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define lul          1000000007
#define rep(i,a,b)   for(int i=a;i<b;i++)
#define rfor(i,a,b)  for(int i=a; i>=b; i--)
#define SIZE         1000005
#define F            first
#define S            second
#define mod          998244353
 
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " = " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " = " << arg1<<" |";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define endl         '\n'
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k)
// find_by_order(k)
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;

void solve()
{
    int n,k; cin>>n>>k;
    string s; cin>>s;
    int ans = n-1, cur=0;
    rep(i,0,n-1)
    {
        cur+=(s[i] == s[i+1]);
    }
    ans = min(ans,cur+2*k);
    cout<<ans; 
}
int main()
{   
    FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1; //cin>>t;
    while(t--){
       solve();
    }
    return 0;
}

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

using namespace std;

int main() {
    int N, T;
    cin >> N >> T;
    vector<long long int> A(N);
    vector<long long int> dif(N, 0);
    long long int tmp_min;
    for(int n=0; n<N; n++) {
        cin >> A[n];
        
        if(n==0) {
            tmp_min = A[n];
            continue;
        } else {
            if(tmp_min>A[n]) {
                tmp_min = A[n];
            } else {
                dif[n] = A[n]-tmp_min;
            }
        }
    }
    
    sort(dif.begin(), dif.end());
    
    int ans=dif.end()-lower_bound(dif.begin(), dif.end(), dif[dif.size()-1]);
    cout << ans << endl;


    return 0;
    
}

Measured memory_bytes: 1792
h,*s=open(0)
h,w,k,*m=map(int,h.split())
b=512
while b:
 b-=1;r=t=j=0;d=[0]*h
 while w-j:
  i=c=0
  while h-i:
   d[c]+=s[i][j]>'0';f=d[c]>k
   if(t<j)&f:r+=1;t=j;d=[0]*h;break
   r+=h*w*f;c+=b>>i&1;i+=1
  else:j+=1;v=c
 m+=r+v,
print(min(m))

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

typedef long long ll;
// i番目まで見たときの、j個使って重さの総和がk以下のときの価値の最大値が入る。
// 実際の重さの総和は、(j * sub + k)   ←これとWを比較してdpテーブルを埋める。
ll dp[105][105][310];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll n, W;
    cin >> n >> W;
    vector<ll> w(n), v(n);
    ll sub;
    for(int i = 0; i < n; ++i){
        cin >> w[i] >> v[i];
        if(i == 0){
            if(W < w[0]){
                cout << 0 << endl;
                return 0;
            }
            sub = w[0];
        }
        w[i] -= sub;
    }
    
    // dpテーブルを埋める
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < i + 1; ++j){     // (i+1)番目を見ているときの取れる個数の最大値は(i+1)個
            if(j == 0){
                if(sub + w[i] <= W){
                    dp[i + 1][j + 1][w[i]] = max(dp[i + 1][j + 1][w[i]], dp[i][j][0] + v[i]);
                }
            }
            else{
                for(int k = 0; k <= n * 3; ++k){
                    // (i+1)番目を使わない場合
                    dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j][k]);
                    
                    // (i+1)番目を使う場合
                    if((j + 1) * sub + k + w[i] <= W){
                        dp[i + 1][j + 1][k + w[i]] = max(dp[i + 1][j + 1][k + w[i]], dp[i][j][k] + v[i]);
                    }
                }
            }
        }
    }

    ll res = 0;
    for(int i = 0; i <= n; ++i){
        for(int j = 0; j <= n * 3; ++j){
            if(i * sub + j <= W){
                res = max(res, dp[n][i][j]);
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 24960
import java.util.*;

public class Main
{
  public static void main(String[] args)
  {
	Scanner in = new Scanner(System.in);
    char[] s = in.next().toCharArray();
    char[] t = in.next().toCharArray();
    int sl = s.length, tl = t.length;
    int[][] dp = new int[sl+1][tl+1];
    for (int i = 1; i < sl+1; i++)
        for (int j = 1; j < tl+1; j++)
        {
            if (s[i-1] == t[j-1])
                dp[i][j] = 1+dp[i-1][j-1];
            else
                dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]);
        }
    int r = sl, c = tl;
    String lcs = "";
    while (r > 0 && c > 0)
    {
      if (s[r-1] == t[c-1])
      {
        lcs += s[r-1]+"";
        r--;
        c--;
      }
      else if (dp[r][c] == dp[r-1][c])
        r--;
      else
        c--;
    }
    
    for (int i = lcs.length()-1; i >= 0; i--)
      System.out.print(lcs.charAt(i));
    in.close();
  }
}

Measured memory_bytes: 98016
#include <bits/stdc++.h>
using namespace std;
int main(){
  int R;
  cin >> R;
  if(R < 1200 ){
    cout << "ABC" << endl;
  }else if(R < 2800){
    cout << "ARC" << endl;
  }else {
    cout << "AGC" << endl;
  }

}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef pair <int,int> pii;
const int N = 809;
const int Tx[] = {-1, 0, 1, 0};
const int Ty[] = {0, 1, 0, -1};

char ar[N][N];
bool vis[N][N];
int h[N][N];
int H, W, k;

bool ck(int x, int y)
{
	return (x >= 1 && y >= 1 && x <= H && y <= W && ar[x][y] == '.' && h[x][y] <= k && vis[x][y] == false);
}
int getans(int x, int y)
{
	int res = min(min(H - x, x - 1), min(W - y, y - 1));
	if(res % k == 0)
		return res/k;
	else
		return res/k + 1;
}

queue <pii> q;

int bfs(int x, int y)
{
	int res = H*W;
	q.push({x, y});
	vis[x][y] = true;
	while(q.size() > 0)
	{
		int a = q.front().fi,
			b = q.front().se;

		vis[a][b] = true;
		res = min(res, getans(a, b) + 1);
		
		q.pop();
		for(int i=0;i<4;i++)
		{
			int na = a + Tx[i],
				nb = b + Ty[i];
			h[na][nb] = h[a][b] + 1;
			if(ck(na, nb) == true)
			{
				q.push({na, nb});
				h[na][nb] = h[a][b] + 1;
				vis[na][nb] = true;
			}
		}
	}

	return res;
}
int main()
{
	// freopen("in10.txt","r",stdin);
	int x = 1, y = 1;
	cin >> H >> W >> k;
	for(int i=1;i<=H;i++)
	{
		for(int j=1;j<=W;j++)
		{
			cin >> ar[i][j];
			if(ar[i][j] == 'S')
				x = i,
				y = j;
		}
	}

	// cout << x << ' ' << y << '\n';
	cout << bfs(x, y);


}

Measured memory_bytes: 4096
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};
string res(string s){
	REP(i, s.length() / 2) {
		swap(s[i], s[s.length() - 1 - i]);
	}
	return s;
}
int main() {
	int n;
	cin >> n;
	while (n--) {
		string s;
		cin >> s;
		set<string> ss;
		REP(i,s.length()-1) {
			string s1 = s.substr(0,i+1);
			string s2 = s.substr(i + 1,s.length()-1-i);
			ss.insert(s1+s2);
			ss.insert(res(s1) + s2);
			ss.insert(s1 + res(s2));
			ss.insert(res(s1) + res(s2));
			ss.insert(s2 + s1);
			ss.insert(res(s2) + s1);
			ss.insert(s2 + res(s1));
			ss.insert(res(s2) + res(s1));
		}
		cout<<ss.size() << endl;
	}
}

Measured memory_bytes: 3192
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

typedef long long LL;

const int inf = 1 << 26;

string a, b;
char c[100005];

int main(){
	int p = 0;
	cin >> a >> b;
	for ( int i = 0; i < a.size(); i ++ ) {
		c[p] = a[i];
		p += 2;
	} 
	p = 1;
	for ( int i = 0; i < b.size(); i ++ ) {
		c[p] = b[i];
		p += 2;
	}
	cout << c << endl;

	return 0;
}
/*
aattccooddeerrbreeggiunlnaerrccoonntteesstt
aattccooddeerrbreeggiunlnaerrccoonntteesstt
*/


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

int max(int a,int b){
  if(a>b) return a;
  else return b;
}
int absolute(int a,int b){
  if(a-b<0) return -(a-b);
  else return a-b;
}
int main(){
  int X,A,B;
  cin >> X >> A >> B;
  
  if(B-A <= 0) cout << "delicious" << endl;
  else if(B-A <= X) cout << "safe" << endl;
  else if(X < B-A) cout << "dangerous" << endl;
}

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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    ll n,k,x;
    cin >> n >> k;
    vector<ll>A(n+1);
    for(ll i=0;i<n;i++){
        cin >> x;
        A[x]++;
    }
    sort(A.rbegin(),A.rend());
    ll ret = n;
    for(ll i=0;i<k;i++){
        ret-=A[i];
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<valarray>
#include<cmath>
using namespace std;
int n;
valarray<double> data;
int inp(){
  cin>>n;
  if(!n)return 0;
  data=valarray<double>(n);
  for(int i=0;i<n;i++)
    cin>>data[i];
  return n;
}
double avg;
double app(double x){return (x-avg)*(x-avg);}
void proc(){
  avg=data.sum()/n;
  double result=sqrt(data.apply(app).sum()/n);
  printf("%lf\n",result);
}
int main(){
  while(inp())proc();
  return 0;
}

Measured memory_bytes: 1268
//int a = s - '0'; 文字から数字
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//過半数：N/2.0で判定
//優先度付きキュー
//priority_queue<
//ll,
//vector<ll>
//> q;
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
#define PI 3.14159265358979323846264338327950L
using namespace std;

//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

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

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

ll RS(ll N, ll P, ll M) {
	if (P == 0) return 1;
	if (P % 2 == 0) {
		ll t = RS(N, P / 2, M);
		return t * t % M;
	}
	return N * RS(N, P - 1, M);
}

vector<int> IntegerToVector(int bit, int N) {
    vector<int> S;
    for (int i = 0; i < N; ++i) {
        if (bit & (1 << i)) {
            S.push_back(i);
        }
    }
    return S;
}

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

	if( A >= 13) cout << B << endl;
	else if(A >= 6) cout << B/2 << endl;
	else cout << 0 << endl;
}	

Measured memory_bytes: 10884
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include<algorithm>

using namespace std;

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

	priority_queue<int,vector<int>> pq;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		pq.push(a);
	}
	
	priority_queue<pair<int,int>> cb;
	for (int i = 0; i < m; i++) {
		int b, c;
		cin >> b >> c;
		
		cb.push(make_pair(c,b));
	}
	
	long long sum = 0;
	int cnt=0;
	int a_max = pq.top();
	pq.pop();
	
	long long c_max = cb.top().first;
	long long b = cb.top().second;
	cb.pop();
	while (cnt < n) {
		if (a_max >= c_max) {
			sum += a_max;
			a_max = pq.top();
			pq.pop();
			cnt++;
		}
		else {
			
			if (b + cnt <= n) {
				sum += c_max * b;
				
				cnt += b;
				
				
			}
			else {
				sum += c_max * (n - cnt);
				cnt = n;
				
			}

			if (!cb.empty()) {
				c_max = cb.top().first;
				b = cb.top().second;
				cb.pop();
			}
			else {
				c_max = 0;
				b = 0;
			}
		}

	}

	cout << sum << endl;
}

Measured memory_bytes: 1784
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate, gcd など
#include <cassert>    // assert
#include <stdexcept>
#include <bitset>
using namespace std;

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
// typedef int128_t ll;
// typedef cpp_int ll;

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

// #define NDEBUG 1
// debug用出力 https://trap.jp/post/998/
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << H << " ";
    debug_out(T...);
}
#ifdef NDEBUG
#define debug(...)
#else
#define debug(...) debug_out(__VA_ARGS__)
#endif

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

// constexpr inline ll mod = 1'000'000'007;

int a,b,n;
vector<int> ps,qs;
vector<int> perms;

int main()
{
    // 入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(10); // 浮動小数の表示の精度

    // 16:12
    cin>>n;
    rep(i,n){
        int p; cin>>p;
        ps.push_back(p);
        perms.push_back(i+1);
    }
    rep(i, n)
    {
        int q;
        cin >> q;
        qs.push_back(q);
    }
    int i = 0;
    do
    {
        if (ps == perms)
        {
            a = i;
        }
        if (qs == perms)
        {
            b = i;
        }
        i++;
    } while (next_permutation(perms.begin(), perms.end()));
    
    cout<<abs(a - b)<<endl;

    return 0;
}


Measured memory_bytes: 3580
from collections import defaultdict
import queue
N = int(input())
edge = defaultdict(list)
for i in range(N-1):
    a,b = map(int,input().split())
    edge[a].append(b)
    edge[b].append(a)

def bfs(s):
    dist = defaultdict(lambda:float('inf'))
    dist[s] = 0
    que = queue.Queue()
    que.put(s)
    while que.qsize():
        s = que.get()
        for t in edge[s]:
            if dist[t] > dist[s] + 1:
                dist[t] = dist[s] + 1
                que.put(t)
    return dist

fdist = bfs(1)
sdist = bfs(N)
f = 0
for i in range(1,N+1):
    if fdist[i] <= sdist[i]:
        f += 1
s = N-f
if f > s:
    print('Fennec')
else:
    print('Snuke')


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

int N;
long long a[3010], dp[3010][3010];

long long f(int x, int y) {
	if (x>y) return 0;
	if (dp[x][y] != -1) return dp[x][y];
	dp[x][y] = max(a[x] - f(x+1, y),
	               a[y] - f(x, y-1));
	return dp[x][y];
}

int main () {
	cin >> N;
	for(int i=1; i<=N; i++)
		cin >> a[i];
	memset(dp, -1, sizeof(dp));
	cout << f(1, N) << endl;
}


Measured memory_bytes: 71296
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



// [l,r]が回文にできるとき d = r-l+1 として
// dが奇数かつ奇数個のアルファベットが1個 or dが偶数かつ奇数個のアルファベットが0個
// やっぱdが偶数なら奇数個のアルファベットが奇数個あることはないからただ「奇数個のアルファベットが1個以下」とだけ言える
// 2進数でアルファベットの偶奇を表現したものの累積和をとれば区間が回文にできるかはO(1)でわかる

int n, x, dp[200200], dp2[1<<26];
string s;

signed main() {
	cin >> s;
	n = s.size();
	reps(i,1,1<<26) dp2[i] = inf;
	rep(i,n) {
		x ^= 1<<(s[i]-'a');
		int t = dp2[x];
		rep(k,26) chmin(t, dp2[x^(1<<k)]);
		chmin(dp2[x], t+1);
		dp[i] = t+1;
	}
	cout << dp[n-1] << endl;
}


Measured memory_bytes: 263504
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back

struct SegTree{
    int n;
    vector<int> dat;
    //初期化
    SegTree(int _n){
        n=1;
        while(n<_n) n*=2;
        dat=vector<int>(2*n-1,0);
    }

    //k番目(0-indexed)の値をaに変更
    void update(int k, int a){
        k+=n-1;
        dat[k]=a;
        //更新
        while(k>0){
            k=(k-1)/2;
            dat[k]= dat[2*k+1]+dat[2*k+2];
        }
    }

    int find(int x){
        int now = 0;
        while(now<n-1){
            if(dat[2*now+1] < x){
                x -= dat[2*now+1];
                now = 2*now + 2;
            }
            else{
                now = 2*now + 1;
            }
        }
        return now - (n-1);
    }
};

int main(){
    int q,lim;
    while(scanf(" %d %d", &q, &lim),q){
        SegTree st(q);
        int idx = 0, num = 0;
        unordered_map<int,int> id2idx;
        vector<int> a;

        auto DEL = [&](int p){
            st.update(p,0);
            --num;
        };

        rep(i,q){
            int t,x;
            scanf(" %d %d", &t, &x);

            if(t==0){
                id2idx[x] = idx;
                st.update(idx,1);
                a.pb(x);
                ++idx;
                ++num;

                if(num == lim+1) DEL(st.find(1));
            }
            else if(t==1) DEL(st.find(x));
            else if(t==2) printf("%d\n",a[st.find(x)]);
            else DEL(id2idx[x]);
        }
        printf("end\n");
    }
    return 0;
}



Measured memory_bytes: 25296
nums = list(map(int, input().split()))
N, K = nums[0], nums[1]
S = input()
before = S[0]
a = 0
for i in range(N-1):
    if S[i+1] != before:
        a += 1
    before = S[i+1]
b = max(0, a - 2 * K) + 1
print(N - b)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define pa pair<int,int>
const int N=2e5+10;
const int mod=998244353;
using namespace std;


struct point{ int x,y;}p[N];
inline ll cross(point a,point b,point c){return 1LL*(b.x-a.x)*(c.y-a.y)-1LL*(b.y-a.y)*(c.x-a.x); }
 
int main()
{     
     int n; scanf("%d",&n);
     for(int i=0;i<n;i++)  scanf("%d%d",&p[i].x,&p[i].y);
     int ff=1;
     for(int i=0;i<n;i++)
     {
       int j=(i+1)%n,k=(i+2)%n;
       if(cross(p[i],p[j],p[k])<0)  {ff=0; break;}
     }
     if(ff)puts("1");else puts("0");
return 0;
}
/*

*/


Measured memory_bytes: 3168
#include <bits/stdc++.h>
 
using namespace std;
using pii = tuple<int,int,int>;
 
map<int,int> first_met;
 
int main() {
    //freopen("103.in", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
 
    int n, q;
    cin >> n >> q;
 
    vector<int> arr(n);
    int t;
    for (int i = 0; i < n; i++) {
        cin >> t;
        if (first_met.count(t) == 0) {
            first_met[t] = first_met.size();
        }
        arr[i] = first_met[t];
    }
 
    vector<pii> queries(q);
    int a, b;
    for (int i = 0; i < q; i++) {
        cin >> a >> b;
        queries[i] = {a-1, b, i};
    }
 
    int k = sqrt(n);
    sort(queries.begin(), queries.end(), [&](const pii& q1, const pii& q2) {
        int a1k = get<0>(q1) / k;
        int a2k = get<0>(q2) / k;
        if (a1k < a2k) {
            return true;
        }
        if (a2k < a1k) {
            return false;
        }
        return get<1>(q1) < get<1>(q2);
    });
 
    vector<int> met(first_met.size());
    vector<int> res(q);
    int l = 0, r = 0, cur = 1;
    met[arr[0]]++;
    for (auto& [start, end, indx] : queries) {
        while (l < start) {
            met[arr[l]]--;
            if (met[arr[l]] == 0) {
                cur--;
            }
            l++;
        }
        while (l > start) {
            l--;
            met[arr[l]]++;
            if (met[arr[l]] == 1) {
                cur++;
            }
        }
        while (r >= end) {
            met[arr[r]]--;
            if (met[arr[r]] == 0) {
                cur--;
            }
            r--;
        }
        while (r < end - 1) {
            r++;
            met[arr[r]]++;
            if (met[arr[r]] == 1) {
                cur++;
            }
        }
        res[indx] = cur;
    }
 
    for (auto& r : res) {
        cout << r << "\n";
    }
}

Measured memory_bytes: 38960
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct BoolName : numpunct<char> {
  string t, f;
  BoolName (string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const {return t;}
  string do_falsename() const {return f;}
};

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

int main() {
  int n;
  cin >> n;
  if (n == 0) {
    cout << 0 << endl;
    return 0;
  }
  string r;
  for (int i = 1; n; i *= -1, n /= 2) {
    r = to_string(abs(n) % 2) + r;
    n -= abs(n) % 2 * i;
  }
  cout << r << endl;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static long findMin(int n, int[] a) {
        long[] dp = new long[n];
        dp[0]=0;
        dp[1]=Math.abs(a[1]-a[0]);
        for(int i=2;i<n;++i) {
            dp[i]=Math.min(dp[i-2]+Math.abs(a[i]-a[i-2]),dp[i-1]+Math.abs(a[i]-a[i-1]));
        }
        return dp[n-1];
    }
    public static void main(String[] args) {
        InputStreamReader r=new InputStreamReader(System.in);
        String input=null;
        BufferedReader reader = new BufferedReader(r);
        try {
            input = reader.readLine();
            int n= Integer.parseInt(input);
            int[] a= new int[n];
            String nums = reader.readLine();
            String [] nums1 = nums.split(" ");
            for(int i=0;i<nums1.length;++i) {
                a[i]=Integer.parseInt(nums1[i]);
            }
            System.out.println(findMin(n,a));
        } catch(IOException e) {

        }

    }
}


Measured memory_bytes: 35668
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;
typedef pair<long long ,long long> ii; 	

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin >> s;
	if (s == "MON"){
		cout << 6 << endl;
	} else if (s == "TUE"){
		cout << 5 << endl;
	} else if (s == "WED"){
		cout << 4 << endl;
	} else if (s == "THU"){
		cout << 3 << endl;
	} else if (s == "FRI"){
		cout << 2 << endl;
	} else if (s == "SAT"){
		cout << 1 << endl;
	} else {
		cout << 7 << endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
const ll mo=998244353;
ll ans=0;
ll dp[301][90001]={};
ll dp2[301][90001]={};

int main()
{
ll n;
cin >> n;
ll table[n]={};
rep(i,n) {
    cin >> table[i];
}
ll sum=0;
rep(i,n){
    sum+=table[i];
}
bool a=1;
if(sum%2==1)a=0;
sum=(sum-1)/2;
dp[0][0]=1;
dp2[0][0]=1;
ll maxa=1;
rep(i,n){rep(j,maxa){
    dp[i+1][j]+=2*dp[i][j];
    dp[i+1][j]=dp[i+1][j]%mo;
    dp2[i+1][j]+=dp2[i][j];
    dp2[i+1][j]=dp2[i+1][j]%mo;
    dp[i+1][j+table[i]]+=dp[i][j]; 
    dp[i+1][j+table[i]]=dp[i+1][j+table[i]]%mo;
    dp2[i+1][j+table[i]]+=dp2[i][j]; 
    dp2[i+1][j+table[i]]=dp2[i+1][j+table[i]]%mo;
}
maxa=maxa+table[i];
}
for(int i=sum+1;i<maxa;i++){
    ans+=3*dp[n][i];
    ans=ans%mo;
}
/* for (int i = 0; i < 10; ++i) {
    cout << dp[n][i] << " ";
}cout  << endl; */

if(a){
    ans=ans-dp2[n][sum+1]*6/2;
}


ll jyo=1;
rep(i,n){
    jyo=3*jyo;
    jyo=jyo%mo;
}
ans=jyo+mo-ans;
ans=ans%mo;

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








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

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF (long long)(1e18)
#define MOD (int)(1e9+7)

#define yn(f) (f?"Yes":"No")
#define YN(f) (f?"YES":"NO")

#define MAX 110000

template<class RandomAccessIterator>
void comb_sort(RandomAccessIterator first, RandomAccessIterator second){
	long long N = second-first, h = N*10/13;
	bool flag = true;
	while(flag){
		flag = false;
		for(int j = N-1; j-h >= 0; j--){
			if(*(first+j) < *(first+j-h)){
				swap(*(first+j),*(first+j-h));
				flag = 1;
			}
		}
		if(h>1)flag = true,h = h*10/13;
		else h = 1;
	}
}

int h[MAX];
signed main(){
	cout<<fixed<<setprecision(7);
	int N, K, ans = INF;
	
	cin>>N>>K;
	
	for(int i = 0; i < N; i++){
		cin>>h[i];
	}
	
	comb_sort(h, h+N);
	
	for(int i = 0; i + K - 1< N; i++){
		ans = min(ans, h[i+K-1]-h[i]);
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int r, c, n;
int x[100100][2];
int y[100100][2];

int rim_num(int a, int b) {
    if (a == 0) return b;
    if (b == c) return c+1+a;
    if (a == r) return c+r+2+(c-b);
    return 2*c+r+3+(r-a);
}

bool rim(int a, int b) {
    return (a == 0 || a == r) || (b == 0 || b == c);
}

bool solve() {
    vector<P> vec;
    for (int i = 0; i < n; i++) {
        if (rim(x[i][0], y[i][0]) && rim(x[i][1], y[i][1])) {
            for (int j = 0; j < 2; j++) {
                vec.push_back(P(rim_num(x[i][j], y[i][j]), i));
            }
        }
    }
    sort(ALL(vec));

    stack<int> st;
    for (int i = 0; i < vec.size(); i++) {
        int v = vec[i].second;
        if (st.empty() || st.top() != v) {
            st.push(v);
        } else {
            st.pop();
        }
    }
    return st.empty();
}

void input() {
    cin >> r >> c >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 2; j++) {
            cin >> x[i][j] >> y[i][j];
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << (solve()?"YES":"NO") << endl;
}


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

using namespace std;


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

	int m, d, i, j, k, ans, d1, d10;
	cin >> m >> d;
	ans = 0;
	for (i = 1; i <= m; i++) {
		for (j = 1; j <= d; j++) {
			d10 = j / 10;
			d1 = j % 10;

			if ((d1 >= 2) && (d10 >= 2) && (d1 * d10 == i)) {
				ans++;
				//cout << i << " " << j << "\n";
			}
		}
	}
	cout << ans << "\n";
	return 0;
}



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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) { 
        os << v[i]; 
        if (i != (int)v.size() - 1) 
            os << " "; 
    } 
    return os; 
} 

ll nCrModp(ll n, ll r, ll p)
{
    ll C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}

int main()
{
    ll A,B;
    cin >> A >> B;
    if (A >= 10 || B >= 10) {
        print(-1);
    } else {
        print(A*B);
    }
    return 0;
}

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

const int MAX_N = 100010;
int par[MAX_N];
int rnk[MAX_N];

void init(int n) {
    rep(i,n) {
        par[i] = i;
        rnk[i] = 0;
    }
}

int 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 (rnk[x] < rnk[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (rnk[x] == rnk[y]) rnk[x]++;
    }
}

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

int main() {
    int N, M, ans = 0;
    cin >> N >> M;
    vector<int> a(M), b(M);
    rep(i, M) cin >> a[i] >> b[i];
    rep(i, M) {
        init(N);
        rep(j, M) {
            if (i == j) continue;
            unite(a[j] - 1, b[j] - 1);
        }
        rep(i, N) {
            if (!same(0, i)) {
                ans++;
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#define pb push_back
#define mod 1000000007
using namespace std;
typedef long long int ll;

int main(void){
  string s;
  cin>>s;
  s.insert(4," ");
  cout<<s<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
     long long int a,b,k,m,n;
     cin>>a>>b>>k;
     if (a>=k)
     {
         m=a-k;
         n=b;
         cout<<m<<" "<<n<<endl;
     }
else if(a+b<=k)
     {
         m=0;
         n=0;
         cout<<m<<" "<<n<<endl;
     }

     else if(a<=k && a+b>=k)
      {m=k-a;
     n=b-m;
         m=0;
            cout<<m<<" "<<n<<endl;

     }


     return 0;
}


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

int main() {
  int long long A,B,K;
  cin >> A >> B >> K;
  
  if(K>=A){
    B-=(K-A);
    if(B<0){
      B=0;
    }
    cout << 0 << " " << B << endl;
  }
  else{
    cout << A-K << " " << B << endl;
  }
}

Measured memory_bytes: 256