akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

public class Main {


	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		FastScanner fs = new FastScanner();
		int X = fs.nextInt();
		double y = 0;
		for(int B = -100; ; B++) {
			y = X + Math.pow(B, 5);
			for(int A = -100;; A++ ) {
				if(Math.pow(A, 5) == y) {
					System.out.println(A + " " + B);
					return;
				}
				if(Math.pow(A, 5) > y) {
					break;
				}
			}
		}




	}




}


Measured memory_bytes: 25284
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//const int mod = 1e9+7;
string s,t;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int main()
{
    quickread();
    cin >> s >> t;
    if(t.substr(0, s.size()) == s) {
        cout << "Yes" <<endl;
    } else cout << "No" << endl;
    return 0;
}


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

using namespace std;

const int MOD = 1000000007;

int fac[2000001], ifac[2000001], inv[2000001];

int main()
{
  int K, L;
  char s[1000001];
  
  scanf("%d", &K);
  scanf("%s", s);
  L = strlen(s);
  
  fac[0] = ifac[0] = 1;
  fac[1] = ifac[1] = 1;
  inv[1] = 1;
  for (int i = 2; i <= K + L; i++) {
    fac[i] = (long long)fac[i - 1] * i % MOD;
    inv[i] = MOD - (long long)inv[MOD % i] * (MOD / i) % MOD;
    ifac[i] = (long long)ifac[i - 1] * inv[i] % MOD;
  }

  int pow = 1;
  int ans = 0;
  for (int i = 0; i <= K; i++) {
    ans = ((long long)ans + (((long long)pow * fac[K + L]) % MOD) * (((long long)ifac[i] * ifac[K + L - i]) % MOD)) % MOD;
    pow = (long long)pow * 25 % MOD;
  }
  
  printf("%d\n", ans);
  
  return 0;
}

Measured memory_bytes: 28096
#include<stdio.h>

int main(void)
{
    long k,a,b;
    long ans = 1;
    scanf("%ld%ld%ld",&k,&a,&b);

    if(k < a || b - a < 3)
    {
        printf("%ld",ans+k);
        return 0;
    }

    ans = a;
    k -= a - 1;
    ans += k % 2;
    k /= 2;
    ans += (b - a) * k;
    
    printf("%ld",ans);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <chrono>
#include <numeric>
#include <random>

using namespace std;


int main() {
  int h,w;
  cin >> h >> w;
  string s[9];
  int hoge=0;
  for (int i = 0; i < h; i++) {
    cin >> s[i];
    s[i]+=".";
    for (int j = 0; j < w; j++) {
      if(s[i][j]=='#')hoge++;
    }
  }
  for (int i = 0; i < w; i++) {
    s[h]+=".";
  }
  int x=0,y=0;
  int count=0;
  do{
    if(s[x][y+1]=='#' && s[x+1][y]=='#'){
      break;
    }else if(s[x][y+1]=='#' ){
      y++;
      count++;
    }else if(s[x+1][y]=='#'){
      x++;
      count++;
    }else {
      break;
    }
  }while(1);
  if(x==(h-1) && y==(w-1) && count == (hoge-1)){
    cout << "Possible"<<endl;
  }else{
    cout << "Impossible"<<endl;
  }
  return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(a) (a).begin(),(a).end()
 
using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
 
const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

//union find
struct UnionFind {
    vector<ll> parent;
    vector<ll> usize;
 
    UnionFind(int n) : parent(n), usize(n, 1LL){
        rep(i, n)parent[i]=i;
    }
    
    int root(int x){
        if(parent[x] == x) return x;
        else return parent[x] = root(parent[x]);
    }
    
    bool issame(int x, int y){
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x);
        y = root(y);
 
        if(x == y)return false;
 
        if(parent[x] > parent[y]) swap(x, y);

        usize[x] += usize[y];
        parent[y] = x;
 
        return true;
    }
    
    int size(int x) {
        return usize[root(x)];
    }
};

struct leaf{
    ll s, t;
    ll cost;
};

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

    vector<ll> x(n), y(n);
    rep(i, n)cin >> x[i] >> y[i];

    vector<ll> ord_x(n), ord_y(n);
    iota(ALL(ord_x), 0);
    iota(ALL(ord_y), 0);
    sort(ALL(ord_x), [&](ll a, ll b){
        return x[a] < x[b];
    });
    sort(ALL(ord_y), [&](ll a, ll b){
        return y[a] < y[b];
    });

    vector<leaf> g;
    rep(i, n-1){
        g.push_back(leaf{ord_x[i], ord_x[i+1], abs(x[ord_x[i]] - x[ord_x[i+1]])});
        g.push_back(leaf{ord_y[i], ord_y[i+1], abs(y[ord_y[i]] - y[ord_y[i+1]])});
    }

    vector<ll> ord(g.size());
    iota(ALL(ord), 0);

    sort(ALL(ord), [&](ll a, ll b){
        return g[a].cost < g[b].cost;
    });

    UnionFind uf(n);

    ll ans = 0;
    rep(i, g.size()){
        if(!uf.issame(g[ord[i]].s, g[ord[i]].t)){
            ans += g[ord[i]].cost;
            uf.merge(g[ord[i]].s, g[ord[i]].t);
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 12652
/*input
4
1 2 3 5
*/
fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
        return a;
    }
    return gcd(b, a % b);
}

fn lcm(a: u64, b: u64) -> u64 {
    return a * b / gcd(a, b);
}

fn main() {
    let mut s = format!("");
    std::io::stdin().read_line(&mut s).expect("");
    s = format!("");
    std::io::stdin().read_line(&mut s).expect("");
    let v: Vec<u64> = s
        .trim()
        .split_whitespace()
        .map(|x| x.parse().expect(""))
        .collect();
    let mut least_lcm: u64 = v[0];
    for i in 1..v.len() {
        least_lcm = lcm(least_lcm, v[i]);
        //println!("{:?}", least_lcm);
    }
    println!("{}", least_lcm);
}



Measured memory_bytes: 5040
N = int(input())
evids = []
for _ in range(N):
    a = int(input())
    evids.append([list(map(int, input().split())) for _ in range(a)])

ans = 0
for pattern in range(2 ** N):
    p = pattern
    numHonest = 0
    correct = True
    for i in range(N):
        if p & 1:
            numHonest += 1
            for evid in evids[i]:
                if (pattern >> (evid[0]-1)) & 1 != evid[1]:
                    correct = False
                    break
        #else:
        #    for evid in evids[i]:
        #        if (pattern >> (evid[0]-1)) & 1 == evid[1]:
        #            correct = False
        #            break
        if not correct:
            break
        p >>= 1
    if correct:
        ans = ans if ans > numHonest else numHonest
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

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

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();

		int doku = 0;
		// 毒入クッキーを食べられる枚数
		if (C <= A+B+1) {
			doku = C;
		} else {
			doku = A+B+1;
		}

		System.out.println(B+doku);

	}
}

Measured memory_bytes: 22740
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N, K; cin >> N >> K;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    vector<bool> ng(1 << N);
    for(int bit=0; bit<(1<<N); bit++) {
        int sum = 0;
        for(int i=0; i<N; i++) {
            if(bit >> i & 1) sum += A[i];
        }
        if(sum == K) {
            ng[bit] = true;
        }
    }

    for(int bit=0; bit<(1<<N); bit++) {
        if(ng[bit] == false) continue;
        for(int i=0; i<N; i++) {
            ng[bit | (1 << i)] = true;
        }
    }

    int ans = INF;
    for(int bit=0; bit<(1<<N); bit++) {
        if(ng[bit]) continue;
        int c = __builtin_popcount(bit);
        ans = min(ans, N - c);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3228
#include<stdio.h>

int main()
{
  int r,c,i,j,k,sum;
  sum=0;
  while(1){
    scanf("%d %d",&r,&c);
    if(1<=r && c<=100) break;
  }
  int input[r+1][c+1];

  for(i=0;i<r;i++){
    for(j=0;j<c;j++){
      state :
      scanf("%d",&input[i][j]);
      if(0>input[i][j] || input[i][j]>100) goto state;
    }
  }

  for(i=0;i<r;i++){
    for(j=0;j<c;j++) sum+=input[i][j];
    input[i][c]=sum;
    sum=0;
  }

  for(i=0;i<c;i++){
    for(j=0;j<r;j++) sum+=input[j][i];
    input[r][i]=sum;
    sum=0;
  }

  for(i=0;i<r;i++){
    for(j=0;j<c;j++){
      sum+=input[i][j];
    }
  }
  input[r][c]=sum;

  for(i=0;i<=r;i++){
    for(j=0;j<=c;j++){
      printf("%d",input[i][j]);
      if(j!=c) printf(" ");
    }
    printf("\n");
  }

  return 0;

}

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

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define rep(i,n) for(int i=0; i<(int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

ll d;
ll ans = 0;
vector<ll> ex10(19);

void dfs(int i, int l, ll res, ll now) {
  if (l-i <= i) {
    if (res==0) {
      debug(l, i, now);
      if (l-i == i) now *= 10;
      ans += now;
    }
    return;
  }
  ll p = ex10[l-i]-ex10[i];
  auto k = res/p;
  dfs(i+1, l, res-(p*k), now*max(0LL, 10-abs(k)));
  (res >= 0) ? k++ : k--;
  dfs(i+1, l, res-(p*k), now*max(0LL, 10-abs(k)));
}

void check(int l) {
  ll p = ex10[l] - ex10[0];
  auto k=d/p;
  dfs(1, l, d-(p*k), max(0LL, 9-k));
  k++;
  dfs(1, l, d-(p*k), max(0LL, 9-k));
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  ex10[0] = 1;
  for(int i=1; i<=18; i++) {
    ex10[i] = ex10[i-1]*10;
  }

  cin >> d;
  for(int i=1; i<18; i++) {
    check(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
typedef long long int ll;
#define x first
#define y second
#define codec ios_base::sync_with_stdio(false);cin.tie(NULL);
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef pair<int, int> pi;
int main()
{
  codec;
  string a,b;
  cin>>a>>b;
  int sum=0;
  rep(i,0,a.length()-b.length()+1)
  {
      int k=0;
      for(int j=0;j<b.length();j++)
      {
          if(a[i+j]==b[j])
          {
              k++;
          }
          
      }
      sum=max(k,sum);
      if(sum==b.length())
        goto label;
  }
  label:
  cout<<b.length()-sum;
  
}

Measured memory_bytes: 3616
#include <iostream>
#include <string.h>
#include <bits/stdc++.h>
#include<algorithm> 
using namespace std;
// main() is where program execution begins.



int main() {
    int A=0,B=0;
    string s;
    cin>>s;  
   
   for (int i = 0; i < s.size(); ++i)
   {
     if (s[i] == '0')
     {
       A++;
     }
     else{
      B++;
     }
   }

   cout << (2*min(A,B));

   return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>                                               //scanf,printf
#include <algorithm>                                            //max,min
#include <string>                                               //string
#include <cstring>                                              //strlen,strcat
#include <cctype>                                               //isalpha,tolower
#include <cmath>                                                //sqrt,sin
#include <stack>                                                //top,push
#include <queue>                                                //front,push
#include <vector>                                               //push_back,sort
#include <set>                                                  //insert,begin
#include <map>                                                  //insert,find
#include <list>                                                 //push_front,begin
#include <stdio.h>
using namespace std;
#define MAX 1000

int main(){
  int n,a;
  cin>>n>>a;
  string s="No";
  
  for(int i=0; ; i++){
    if(500*i>n) break;
    if(n<=500*i+a) s="Yes";
  }
  
  cout<<s<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
struct item
{
    int wt;
    int val;
};
int solve(vector< struct item>v,int n,int w)
{
    vector<vector<ll>>dp(n+1,vector<ll>(100005,w+1));
    for(int i=0;i<=n;i++)
    {
        dp[i][0]=0;
    }
    dp[1][v[1].val]=v[1].wt;
    for(int i=2;i<=n;i++)
    {
        for(int j=1;j<100005;j++)
        {
            dp[i][j]=dp[i-1][j];
            if(j>=v[i].val)
            {
                dp[i][j]=min(dp[i][j],v[i].wt+dp[i-1][j-(v[i].val)]);
            }
        }
    }
   
    int i;
    for(i=100004;i>0;i--)
    {
        if(dp[n][i]<=w)
        break;
    }
    return i;

}
int  main()
{
    int n;
    int w;
    cin>>n>>w;
    vector<item>v(n+1);
    for(int i=1;i<=n;i++)
    {
        cin>>v[i].wt>>v[i].val;
    }
   cout<< solve(v,n,w);

}

Measured memory_bytes: 83188
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int c[1<<10][1<<10];
int cumsum[1<<10][1<<10];
int N, M;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, m;
    cin >> n >> m;
    N = (1<<n)-1;
    M = (1<<m)-1;
    int k = min(n, m);
    int l = max(n, m);
    vector<string> v[10];
    v[0].push_back("00");
    v[0].push_back("01");
    for(int i = 1; i < l; i++){
        for(int j = 0; j < v[i-1].size(); j++){
            string tmp0, tmp1;
            for(int s = 0; s < v[i-1][j].size(); s++){
                if(v[i-1][j][s] == '0'){
                    tmp0 += "00";
                    tmp1 += "01";
                }else{
                    tmp0 += "11";
                    tmp1 += "10";
                }
            }
            v[i].push_back(tmp0);
            v[i].push_back(tmp1);
        }
    }
    if(n > m){
        // n = l
        for(int i = 0; i <= N; i++){
            for(int j = 0; j <= M; j++){
                cumsum[i][j] = (v[l-1][i][j]-'0');
            }
        }
    }else{
        // m == l
        for(int i = 0; i <= N; i++){
            for(int j = 0; j <= M; j++){
                cumsum[i][j] = (v[l-1][j][i]-'0');
            }
        }
    }
    // for(int i = 0; i <= N; i++){
    //     for(int j = 0; j <= M; j++){
    //         cout << cumsum[i][j];
    //     }
    //     cout << endl;
    // }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < M; j++){
            c[i][j] = (cumsum[i+1][j+1]+cumsum[i][j+1]+cumsum[i+1][j]+cumsum[i][j])%2;
            cout << c[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 11008
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60

const int MAX_V = 400 + 1;
ll d[MAX_V][MAX_V]; // 重み付き隣接行列
					 // ワーシャルフロイドではこれを更新していく
					 // 最初、辺がない場合はINFで初期化
					 // d[i][j] : iからjまでの最短距離
int V, E; // V : 頂点数(Vertex)
		  // E : 辺数(Edge)
int L;

void input() {
	cin >> V >> E >> L;

	for (int i = 0; i < E; i++) {
		int start, end;
		cin >> start >> end;
		cin >> d[start][end];
		// 無効グラフなら
		d[end][start] = d[start][end];
	}
}

void warshall_floyd() {
	// 初期化
	for (int i = 1; i <= V; i++) {
		for (int j = 1; j <= V; j++) {
			if (i != j && d[i][j] == 0) d[i][j] = LLINF; // この初期化を忘れてはいけない
													   // i == jのときは d[i][i] = 0
		}
	}

	for (int k = 1; k <= V; k++) {
		for (int i = 1; i <= V; i++) {
			for (int j = 1; j <= V; j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}

ll newd[309][309];
int A[100009], B[100009];

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

	input();
	int Q; cin >> Q;
	for (int i = 0; i < Q; i++) cin >> A[i] >> B[i];
	warshall_floyd();
	//cout << "ok1" << endl;

	for (int i = 1; i <= V; i++) {
		for (int j = i + 1; j <= V; j++) {
			if (d[i][j] <= L) newd[i][j] = 1LL;
			else newd[i][j] = 0LL;
			newd[j][i] = newd[i][j];
		}
	}
	//cout << "ok2" << endl;

	for (int i = 1; i <= V; i++) {
		for (int j = i+1; j <= V; j++) {
			d[i][j] = newd[i][j];
			d[j][i] = newd[j][i];
		}
	}
	warshall_floyd();
	//cout << "ok2" << endl;

	for (int i = 0; i < Q; i++) {
		if (d[A[i]][B[i]] < LLINF)cout << d[A[i]][B[i]]-1 << endl;
		else cout << -1 << endl;
	}


	return 0;
}

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

using namespace std;

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

	int in1, in2, in3, ans1, ans2, ans3, old1, old2, old3;
	old1 = old2 = old3 = 0;

	while (n--) {
		cin >> in1 >> in2 >> in3;
		ans1 = in1 + max(old3, old2);
		ans2 = in2 + max(old1, old3);
		ans3 = in3 + max(old2, old1);

		old1 = ans1; old2 = ans2; old3 = ans3;
	}
	cout << max (ans1 , max(ans2, ans3)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define ll long long
  #define int long long
  #define double long double
  #define max(a,b) (a>b?a:b)
  #define min(a,b) (a<b?a:b)
  #define mp make_pair
  #define pb push_back
  #define inf INT_MAX
  #define f first
  #define s second
  #define all(v) v.begin(), v.end()
  #define mod INT_MAX 
  int32_t main()
  { 
    /*#ifndef ONLINE_JUDGE
       freopen("in.txt","r",stdin);
       freopen("out.txt","w",stdout);
    #endif*/
    
    IOS
    int x;
    cin>>x;
    cout<<((x-1)*(x))/2;
    return 0;
  }
    

Measured memory_bytes: 256
N = int(input())
src = [input() for i in range(N)]
for s in src:
    st = set([s])
    for n in range(1,len(s)):
        s1,s2 = s[:n], s[n:]
        r1,r2 = s1[::-1], s2[::-1]
        st.add(s1 + r2)
        st.add(r1 + s2)
        st.add(r1 + r2)
        st.add(s2 + s1)
        st.add(s2 + r1)
        st.add(r2 + s1)
        st.add(r2 + r1)
    print(len(st))

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

int main(){
  while(true){
    int K;
    cin >> K;
    if(K ==0)break;
    int num = K *(K-1) /2;
    int c[num];
    int sum=0;
    for(int i=0 ; i<num ; i++){
      cin >> c[i];
      sum += c[i];
    }
    cout << sum/(K-1) << endl;
  }
  return 0;
}

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

typedef long long int   ll;
#define f(i,st,en)    for(int i=st;i<en;i++)
#define s(n)            scanf("%d",&n)
#define sc(n)           scanf("%c",&n)
#define sl(n)           scanf("%lld",&n)
#define sf(n)           scanf("%lf",&n)

using namespace std;

int main(){
    int x,y,z;
    cin>>x>>y>>z;

    swap(x,y);
    swap(x,z);

    cout<<x<<" "<<y<<" "<<z<<endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Consumer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");
		int h = Integer.parseInt(str[0]);
		int w = Integer.parseInt(str[1]);

		boolean flag[][] = new boolean[h][w];

		for (int i = 0; i < h; i++) {
			str = br.readLine().split("");
			for (int j = 0; j < w; j++) {
				if (str[j].equals("#")) {
					flag[i][j] = true;
				}
			}
		}

		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (flag[i][j]) {
					if (i == 0) {
						if (j == 0) {
							if (!flag[i][j + 1] && !flag[i + 1][j]) {
								System.out.println("No");
								return;
							}
						} else if (j == w - 1) {
							if (!flag[i][j - 1] && !flag[i + 1][j]) {
								System.out.println("No");
								return;
							}
						} else {
							if (!flag[i][j + 1] && !flag[i][j - 1] && !flag[i + 1][j]) {
								System.out.println("No");
								return;
							}
						}
					} else if (i == h - 1) {
						if (j == 0) {
							if (!flag[i][j + 1] && !flag[i - 1][j]) {
								System.out.println("No");
								return;
							}
						} else if (j == w - 1) {
							if (!flag[i][j - 1] && !flag[i - 1][j]) {
								System.out.println("No");
								return;
							}
						} else {
							if (!flag[i][j + 1] && !flag[i][j - 1] && !flag[i - 1][j]) {
								System.out.println("No");
								return;
							}
						}
					} else {
						if (j == 0) {
							if (!flag[i][j + 1] && !flag[i + 1][j] && !flag[i - 1][j]) {
								System.out.println("No");
								return;
							}
						} else if (j == w - 1) {
							if (!flag[i][j - 1] && !flag[i + 1][j] && !flag[i - 1][j]) {
								System.out.println("No");
								return;
							}
						} else {
							if (!flag[i][j + 1] && !flag[i][j - 1] && !flag[i + 1][j] && !flag[i - 1][j]) {
								System.out.println("No");
								return;
							}
						}
					}
				}
			}
		}

		System.out.println("Yes");
	}
}


Measured memory_bytes: 23380
#include <stdio.h>
int main(void){
    // Your code here!
    char s[10];
    int y,m,d,i;
    scanf("%s",s);
    for(i=0;i<10;i++){
        s[i]=s[i]-'0';
    }
    
    y=s[0]*1000+s[1]*100+s[2]*10+s[3];
    m=s[5]*10+s[6];
    d=s[8]*10+s[9];

    if(y<2019) {
        printf("Heisei\n");
        return 0;
    }
    if(y==2019){
        if(m<4){
            printf("Heisei\n");
            return 0;
        }
        if((m==4)&&(d<=30)){
            printf("Heisei\n");
            return 0;
        }
    }
    printf("TBD\n");
    return 0;    
    
    
}


Measured memory_bytes: 128
N = int(input())
A = list(map(int, input().strip().split()))
day=0
money=1000
stock=0
is_up=True
while day<N :
    if is_up :
        past_day=day
        while A[day]<=A[day+1]:
            day+=1
            if day==N-1:
                break
        stock=int(money/A[past_day])
        money+=stock*(A[day]-A[past_day])
        day+=1
        if day==N-1:
            break
        is_up=False
    else :
        while A[day]>=A[day+1] :
            day+=1
            if day==N-1:
                day+=1
                break
        is_up=True


print("{}".format(money))





Measured memory_bytes: 9216
#include<iostream>//入出力
#include<string>//文字列

using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int a[200000];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;cin>>n;
    REP(i,n)cin>>a[i];
    int b=0;REP(i,n)b^=a[i];
    string ans="";
    REP(i,n){ans+=to_string(a[i]^b);ans+=" ";}
    cout<<ans<<endl; 
}

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

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

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

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
#define MAX_W 50
#define MAX_H 50

ll H, W;
string S[MAX_W];

signed main()
{
    cin >> H >> W;
    REP(i, H) {
        cin >> S[i];
    }
    REP(i, H) {
        REP(j, W) {
            if(S[i][j] == '.') { continue; }
            if(i > 0 &&  S[i-1][j] == '#') { continue; }
            if(i < H-1 && S[i+1][j] == '#') { continue; }
            if(j > 0 &&  S[i][j-1] == '#') { continue; }
            if(j < W-1 && S[i][j+1] == '#') { continue; }
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n,minn=99999999;
    cin>>n;
    for(int i=0;i<n;i++){
        int tmp=0,m;
        cin>>m;
        while(!(m%2)){
            tmp++;
            m>>=1;
        }
        minn=min(tmp,minn);
    }
    cout<<minn<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
      std::cin.tie(NULL);
  char letter;
  std::cin >>letter;
  if(letter >= 65 && letter <= 90)
    std::cout << "A" << '\n';
  else if(letter >= 97 && letter <= 122)
    std::cout << "a" << '\n';

return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    ll x,y;
    ll ans=0;
    cin >> x >> y;
    ll a = abs(y) - abs(x);
    if(a>0){
        if(x<0){
            ans++;
            x*= -1;
        }
        x += a;
        ans += a;
        if(x != y) ans++;

    }
    else if(a<0){
        if(x>0){
            ans++;
            x*= -1;
        }
        x -= a;
        ans += -a;
         if(x != y) ans++;
    }
    else{
         if(x != y) ans++;
    }
    cout << ans << endl;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll K, T;
    cin >> K >> T;
    ll maxi = 0;
    rep(i, T) {
        ll temp;
        cin >> temp;
        maxi = max(maxi, temp);
    }
    cout << max(0LL, maxi - 1LL - (K - maxi)) << endl;
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define REPR(i,n) for(int i=n-1; i>=(int)(0); i--)
#define FOR(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define FORR(i,a,b) for(int i=(int)(b)-1; i>=(int)(a); i--)
#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()
//**関数リスト**//
int ctoi(char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second < secondElof.second;
}
ll nod(ll F) {
	ll keta = 1;
	while (F / 10 > 0) {
		keta++;
		F /= 10;
	}
	return keta;
}
ll gcd(ll x, ll y) {
	ll r;
	if (x < y) {
		swap(x, y);
	}
	while (y > 0) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
ll isPrime(ll x) {
	ll i;
	if (x < 2) {
		return 0;
	}
	else if (x == 2) {
		return 1;
	}
	else if (x % 2 == 0) {
		return 0;
	}
	else {
		for (i = 3; i * i <= x; i += 2) {
			if (x % 1 == 0) {
				return 0;
			}
		}
		return 1;
	}
}
void eratos(vl isPrime) {
	//(注)isPrimeのサイズはN+1にする！実際にはmain内に配置して使用
	ll i, j;
	REP(i, isPrime.size()) {
		isPrime[i] = 1;
	}
	isPrime[0] = 0; isPrime[1] = 0;
	for (i = 2; i * i <= isPrime.size() - 1; i++) {
		if (isPrime[i] == 1) {
			j = i * 2;
			while (j <= isPrime.size() - 1) {
				isPrime[j] = 0;
				j = j + i;
			}
		}
	}
}
ll modinv(ll a, ll m) {
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
void bitSearch(ll n) {
	//実際にはコピーして中身を改変して使う
	ll i;
	REP(i, pow(2, n)) {
		ll p = i;
		REP(i, n) {
			cout << p % 2;
			p /= 2;
		}
		cout << endl;
	}
}

void bfs(ll now) {
	//中身は毎回書き換えて使用
	queue<ll> Q;
	Q.push(now);
	ll u;
	while (!Q.empty()) {
		u = Q.front();
		Q.pop();
		//ll v=;
		//Q.push(v);
	}
}
//**定義場所**//
ll i, j, k, l, m, n;
ll N, M, K, H, W;
ll MOD = 1000000007;
ll ans = 0;
//***********//

int main() {
	ll A, B, C;
	cin >> A >> B >> C;
	cout << C - min(C, A - B);
}

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

int main(){
    int a,b,c,d,e,f;
    while( cin >> a >> b >> c >> d >> e >> f){
        double mom = a*e - b*d;
        double x = (e*c - b*f)/mom;
        double y = (-c*d + a*f)/mom;
        cout << fixed;
        cout << setprecision(3);
        if (x==0){
            x = 0;
        }
        if (y==0){
            y = 0;
        }
        cout << x << " "<< y << endl;
    }
    //double x = 0.51235;
    //cout << fixed;
    //cout << setprecision(2);
    //cout << x << endl;
}



Measured memory_bytes: 3196
#include <stdio.h>

int main(void) {
	int taro[100] = {0}, hanako[100] = {0};
	int i, j, n, m, min, tarotrade, hanakotrade;
	int taroall, hanakoall;
	
	scanf("%d%d",&n,&m);
	
	while( m + n ) {
		taroall=0;
		hanakoall=0;
		min = 201;
		for(i = 0; i < n; i++ ) {
			scanf("%d",&taro[i]);
			//printf("%d",taro[i]);
			taroall += taro[i];
		}
		for(i = 0; i < m; i++ ) {
			scanf("%d",&hanako[i]);
			//printf("%d",hanako[i]);
			hanakoall += hanako[i];
		}
		
		//printf("%d",taroall);
		//printf("%d",hanakoall);
		
		for(i = 0; i < n; i++ ) {
			for(j = 0; j < m; j++ ) {
				if( (taroall - taro[i] + hanako[j]) == (hanakoall - hanako[j] + taro[i]) ) {
					//printf("%d",taro[i] + hanako[j]);
					if(min > taro[i] + hanako[j] ){
						tarotrade = taro[i];
						hanakotrade = hanako[j];
						min = taro[i] + hanako[j];
						//puts("1");
					}
				}
			}
		}
		if(min == 201) {
			puts("-1");
		} else {
			printf("%d %d\n",tarotrade,hanakotrade);
		}
		scanf("%d%d",&n,&m);
	}
	return(0);
}

Measured memory_bytes: 612
import java.util.Scanner;

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

    int a, b, c;
    a = sc.nextInt();
    b = sc.nextInt();
    c = sc.nextInt();

      if(a<b && b<c){

      System.out.println( "Yes" );

      }else{

      System.out.println( "No" );

      }

    } 
}


Measured memory_bytes: 26184
//コンパイラ最適化用
#pragma GCC optimize("Ofast")

//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

// clang++ main.cc -std=c++11 -stdlib=libc++

signed main(){
/*
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++)
    cin >> a[i];
*/
  string S, T;
  cin >> S >> T;
  int res = 0;
  for (int i = 0; i < S.size(); i++)
    if (S[i] != T[i]) res++;
  cout << res << endl;

  return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e15;
using Graph = vector<vector<int>>;

signed main() {
  char S;
  cin >> S;
  if( S >= 'A' && S <= 'Z') cout << "A" << endl;
  else cout << "a" << endl;
}


Measured memory_bytes: 3616
import java.util.*;
class Main {
    int[] arr;
    private int cost(int i, int j) {
    	return Math.abs(arr[i] - arr[j]);
	}

	private void run() {
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        arr = new int[N];
        for (int i = 0; i < N; i++) arr[i] = sc.nextInt();
        int[] dp = new int[N];
        dp[N-1] = 0;
        dp[N-2] = cost(N-2, N-1);
        for (int i = N - 3; i >= 0; i--) {
        	dp[i] = Math.min(dp[i+1]+ cost(i, i + 1), dp[i+2]+cost(i, i+2));
        }
		System.out.println(dp[0]);
    }
  
	public static void main(String[] args) {
    	Main m = new Main();
      	m.run();
	}
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll,pair<ll,ll>> pii;
typedef pair<ll,ll> pi;
typedef vector<ll> vl;

#define matrix vector<vector<ll>>
#define llmax LLONG_MAX
#define llmin LLONG_MIN
#define rep(i,n) for(ll (i)=0;(i)<n;++(i))
#define crep(i,m,n) for(ll (i)=m;(i)<n;++(i))
#define zero(a) memset((a),0,sizeof((a)))
#define minus(a) memset((a),-1,sizeof((a)));
#define sq(a) ((a)*(a))
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define ff first
#define ss second

ll global=0;

// return nCr value
long long C(int n, int r) {
	if(r>n) return 0;
    if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
    long long ans = 1;
    int i;
    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }
    return ans;
}

// return whether number is prime or not
vector<ll> sieve(ll n){
    vector<ll> is_prime(n+1, true);
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= n; i++) {
        if (is_prime[i] && (long long)i * i <= n) {
            for (int j = i * i; j <= n; j += i)
                is_prime[j] = false;
        }
    }
    return is_prime;
}


void test_case();
int main(){
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    ll t=1;
    // cin >> t;
    for(ll T=0;T<t;T++){
        test_case();
    }
    //**************************************************************************//
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

void test_case(){
    ll n;cin>>n;
    std::vector<ll> dp(n+1,0), v(n);
    rep(i,n)cin>>v[i];
    dp[0] = 0;
    dp[1] = 0;
    dp[2] = abs(v[1]-v[0]);
    for(ll i=3;i<=n;++i){
        dp[i] = min(dp[i-1]+abs(v[i-1]-v[i-2]), dp[i-2]+abs(v[i-1]-v[i-3]));
    }
    cout<<dp[n];
}


Measured memory_bytes: 4784
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
using namespace std;

int main() {
    int n;
    while (cin >> n, n) {
        map<char, int> mp;
        bool f = false;
        for (int i = 0; i < n; i++) {
            char c;
            cin >> c;
            if (f) continue;
            mp[c]++;
            priority_queue<pii> p;
            for (int i = 0; i < 26; i++) {
                p.push(pii(mp['A' + i], i));
            }
            pii fi = p.top();
            p.pop();
            pii se = p.top();
            p.pop();
            if (fi.first > n - i - 1 + se.first) {
                cout << (char)(fi.second + 'A') << " " << i + 1 << endl;
                f = true;
            }
        }
        if (!f) cout << "TIE" << endl;
    }
    return 0;
}


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

int main(){
    long W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    
    if(r <= x && x <= W-r){
        if(r <= y && y <= H-r){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define maxN 100002
using namespace std;

int n, v[maxN];

int a, b;

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++ i)
        scanf("%d", &v[i]);
    sort(v + 1, v + n + 1);
    for (int i = n; (!a || !b) && i >= 1; -- i)
        if (v[i] == v[i - 1])
    {
        if (!a)
            {
                a = v[i];
                -- i;
            }
        else
        if (!b)
           b = v[i];
    }
    printf("%lld\n", 1LL * a * b);
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long LL;
typedef unsigned long long ULL;
const LL LINF = 0x3f3f3f3f3f3f3f3f; 
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int mod = 1e9+7;
const ULL P = 131;
const int N = 2e5+7;

LL a[N];

int main()
{
	int n,t;
	cin>>n;
	LL ans=1000;
	for(int k=1;k<=n;k++) cin>>a[k];
	int i=1,j=2;

	while(j<=n){
		while(a[j]>=a[j-1]&&j<=n) j++;
		if(j>n) {
			j--;
			ans = (ans/a[i])*a[j] + ans%a[i];
			break;
		}
		j--;
		ans = (ans/a[i])*a[j] + ans%a[i];
	    j++,i = j,j++;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define f1(n) for(int i=0;i<n;++i)
#define f2(n) for(int i=1;i<=n;++i)
#define lson(x) x<<1
#define rson(x) x<<1|1
#define mp make_pair
using namespace std;
typedef long long ll;
typedef long double llf;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
const int maxn = 3e5 + 5;
const int mod = 0x3f3f3f3f;
const ll Mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const ll Inf = (ll)1e15;
ll a[maxn], b[maxn], c[maxn];
pll p[maxn];
int cnt = 0;

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

	int x, y, A, B, C;
	cin >> x >> y >> A >> B >> C;
	for (int i = 0; i < A; ++i) {
		cin >> a[i];
		p[cnt++] = mp(a[i], 0);
	}
	for (int i = 0; i < B; ++i) {
		cin >> b[i];
		p[cnt++] = mp(b[i], 1);
	}
	for (int i = 0; i < C; ++i) {
		cin >> c[i];
		p[cnt++] = mp(c[i], 2);
	}
	
	sort(p, p + cnt);

	int num[3] = { 0 };
	ll tot = 0, res = 0;
	for (int i = cnt - 1; i >= 0; --i) {
		int op = p[i].second;
		int k = 0;
		if (op == 0) {
			if (num[op] != x) {
				num[op]++;
				tot++;
				res += p[i].first;
			}
		}
		else if (op == 1) {
			if (num[op] != y) {
				num[op]++;
				tot++;
				res += p[i].first;
			}
		}
		else {
			tot++;
			res += p[i].first;
		}

		if (tot == x + y)break;
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 10496
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FScanner sc = new FScanner();
		int N = sc.nextInt();
		int K = sc.nextInt();
		String S = sc.next();
		List<String[]> list = getRunLength(S);
		long happy = 0;
		for (int i = 0; i < list.size(); i++) {
			happy += Integer.parseInt(list.get(i)[1]) - 1;
		}
		long ret = Math.min(happy + K * 2, N - 1);
		System.out.println(ret);
	}

	public static List<String[]> getRunLength(String str) {
		List<String[]> list = new ArrayList<String[]>();
		char back = 'm';
		for (int i = 0; i < str.length(); i++) {
			if (back != str.charAt(i)) {
				String[] hairetu = new String[2];
				hairetu[0] = String.valueOf(str.charAt(i));
				hairetu[1] = "1";
				list.add(hairetu);
				back = str.charAt(i);
			} else {
				String[] hairetu = list.get(list.size() - 1);
				hairetu[1] = String.valueOf(Integer.parseInt(hairetu[1]) + 1);
				list.set(list.size() - 1, hairetu);
			}
		}
		return list;
	}

}

class FScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 30676
N,M=map(int,input().split())
cakes=[None]*N
for i in range(N):
  x,y,z=map(int,input().split())
  cakes[i]=[x,y,z]
  
# x,y,zをそれぞれマイナスに伸ばすかプラスに伸ばすか、2*3通りをすべて試す。
ans=0
for i in range(2**3):
  plus_or_minus=[1]*3
  for j in range(3):
    if (i>>j)&1:
      plus_or_minus[j]=1
    else:
      plus_or_minus[j]=-1
  # 買った個数に対して、プラスマイナスへの伸びが最も大きい買い方を保持
  dp=[None for j in range(M+1)]
  dp[0]=[0,0,0]
  
  for c in range(len(cakes)):
    for j in range(c+1,-1,-1):
      if j<len(dp)-1 and dp[j]!=None:
        if dp[j+1]==None:
          dp[j+1]=[None]*3
          dp[j+1][0]=dp[j][0]+cakes[c][0]
          dp[j+1][1]=dp[j][1]+cakes[c][1]
          dp[j+1][2]=dp[j][2]+cakes[c][2]
        else:
          diff=0
          for k in range(3):
            diff+=((dp[j][k]+cakes[c][k])*plus_or_minus[k])-(dp[j+1][k]*plus_or_minus[k])
          if diff>0:
            dp[j+1][0]=dp[j][0]+cakes[c][0]
            dp[j+1][1]=dp[j][1]+cakes[c][1]
            dp[j+1][2]=dp[j][2]+cakes[c][2]
  if abs(dp[-1][0])+abs(dp[-1][1])+abs(dp[-1][2])>ans:
    ans=abs(dp[-1][0])+abs(dp[-1][1])+abs(dp[-1][2])

print(ans)

Measured memory_bytes: 51292
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
typedef pair<int,int> P;

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

template<class T>
bool umax(T &a, const T &b){
    if (a<b) {
        a=b; return 1;
    }
    return 0;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b<a) {
        a=b; return 1;
    }
    return 0;
}

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
// v.front() = -BOUND;
// v.back() = BOUND;
int N, M, Q, L[200009], R[200009], X[509][509], C[509][509];

int main() {
    cin >> N >> M >> Q;
    for (int i = 1; i <= M; i++) {
        cin >> L[i] >> R[i]; X[L[i]][R[i]]++;
    }
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) C[i][j] = C[i][j - 1] + X[i][j];
    }
    for (int i = 1; i <= Q; i++) {
        int p, q; cin >> p >> q;
        int sum = 0;
        for (int j = p; j <= q; j++) sum += C[j][q] - C[j][p - 1];
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 4480