akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int64_t A, B; cin >> A >> B;
	int64_t m; cin >> m;
	int64_t a[A]; rep(i,A) cin >> a[i];
	int64_t b[B]; rep(i,B) cin >> b[i];
	int64_t ans = LINF;
	while(m--) {
		int x, y; cin >> x >> y;
		int c; cin >> c;
		--x, --y;
		ans = min(ans, a[x] + b[y] - c);
	}
	sort(a, a + A);
	sort(b, b + B);
	ans = min(ans, a[0] + b[0]);
	cout << ans << '\n';
	return 0;
}

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

using namespace std;
using ll = long long;
int n,a[222222],k,l=1,r,ans;
bool check(int x){
    for(ll i=1,ret=0; i<=n; i++){
        ret += (a[i]-1)/x;
        if(ret > k) return false;
    } return true;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);
    cin>>n>>k;
    for(int i=1; i<=n; i++){
        cin>>a[i];
        r = max(r,a[i]);
    }
    while(l <= r){
        int mid = l+r>>1;
        check(mid) ? r=mid-1,ans=mid: l = mid + 1;
    }
    cout<<ans<<'\n';
}


Measured memory_bytes: 4392
#include <iostream>

using namespace std;

int main()
{
  char arr[19];
  cin>>arr;
 
 for(int i=0;i<5;i++){
    cout<<arr[i];
 }
 cout<<" ";
 for(int i=6;i<13;i++){
    cout<<arr[i];
 }
 cout<<" ";
  for(int i=14;i<19;i++){
    cout<<arr[i];
 }




    return 0;
}

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

using namespace std;

int main(){
	int n;
	int state = 0,res = 0;
	string s;
	cin >> n;
	cin >> s;
	for(int i=0;i<n-2;++i){
		if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')res++;
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int,int>;


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main() {
    long long x; cin >> x;
    cout << x/11*2+(x%11+5)/6 << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<lint, lint>;

int main() {
  lint N, v[3];
  cin >> N >> v[0] >> v[1] >> v[2];

  vector<P> query(N);
  for(lint i=0; i<N; i++) {
    string s;
    cin >> s;

    if(s == "AB") query[i] = {0,1};
    if(s == "AC") query[i] = {0,2};
    if(s == "BC") query[i] = {1,2};
  }
  query.emplace_back(0,1);

  vector<char> ans;
  auto add = [&](lint from, lint to) {
    ans.push_back('A' + to);
    v[to]++;
    v[from]--;
  };

  for(lint i=0; i<N; i++) {
    lint x = query[i].first, y = query[i].second;
    lint X = v[x], Y = v[y];
    if(!X && !Y) {
      cout << "No" << endl;
      return 0;
    } else if(!X) {
      add(y,x);
    } else if(!Y){
      add(x,y);
    } else {
      if(x == query[i+1].first || x == query[i+1].second) {
        add(y,x);
      } else {
        add(x,y);
      }
    }
  }

  cout << "Yes" << endl;
  for(auto e : ans) cout << e << endl;
}

Measured memory_bytes: 6408
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int c = sc.nextInt();
		int[][] d = new int[c + 1][c + 1];
		int[][] grid = new int[3][c + 1];
		for(int i = 1; i < c + 1; i++) {
			for(int j = 1; j < c + 1; j++) {
				d[i][j] = sc.nextInt();
			}
		}
		for(int i = 0; i < 3; i++) {
			for(int j = 0; j < c + 1; j++) {
				grid[i][j] = 0;
			}
		}
		for(int i = 1; i < n + 1; i++) {
			for(int j = 1; j < n + 1; j++) {
				int tmp = sc.nextInt();
				grid[(i + j) % 3][tmp]++;
			}
		}
		int ans = Integer.MAX_VALUE;
		for(int i = 1; i < c + 1; i++) {
			for(int j = 1; j < c + 1; j++) {
				if(i != j) {
					for(int k = 1; k < c + 1; k++) {
						if(i != k && j != k) {
							int dif = 0;
							for(int l = 1; l < c + 1; l++) {
								dif += d[l][i] * grid[0][l];
								dif += d[l][j] * grid[1][l];
								dif += d[l][k] * grid[2][l];
							}
							ans = Math.min(ans, dif);
						}
					}
				}
			}
		}
		System.out.println(ans);

	}

}


Measured memory_bytes: 81340
import java.io.BufferedReader

fun main() = abc171a()

@OptIn(ExperimentalStdlibApi::class)
fun abc171a() = SimpleIO_abc171a().exec {
    val a = readLine().toInt()

    val answer = a + a * a + a * a * a

    println(answer)
}

// region kokokara template dayo (^o^)
@Suppress("unused", "HasPlatformType")
private class SimpleIO_abc171a {
    private val br: BufferedReader = System.`in`.bufferedReader()
    private val sb: StringBuilder = StringBuilder()
    fun readLine() = br.readLine()!!
    fun println() = sb.appendln()
    fun print(any: Any) = sb.append(any)
    fun println(any: Any) = sb.appendln(any)
    fun <T> print(any: Iterable<T>, separator: String) = sb.append(any.joinToString(separator))
    fun <T> println(any: Iterable<T>, separator: String) = sb.appendln(any.joinToString(separator))
    fun exec(action: SimpleIO_abc171a.() -> Unit) = run {
        Thread(null, { action() }, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()
    }.run { kotlin.io.println(sb) }
}
// endregion kokomade template dayo (^o^)


Measured memory_bytes: 35848
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

double helon(double a, double b, double c){
    double ret = 0.0;
    double s = (a+b+c)/2;
    ret = sqrt(s*abs(a-s)*abs(b-s)*abs(c-s));
    return ret;
}

int main(){
    int a, l, x;
    while(cin>>a>>l>>x){
        double s = helon(a, l, l)+2*helon(l, (l+x)/2.0, (l+x)/2.0);//*max({helon(l, (l+x)/2.0, (l+x)/2.0), helon(x, l, l)});
        printf("%.15lf\n", s);
    }
}

Measured memory_bytes: 3068
#include <iostream>
#include<algorithm>
#include<string>

using namespace std;

int main(){
        string s,t;
        cin>>s>>t;

        for(int i=0; i<t.size()-1; i++){
                if(t.find(t[i],i+1)!=string::npos){
                        if(s[i]!=s[t.find(t[i],i+1)]){
                                cout<<"No"<<endl;
                                return 0;
                        }
                }else if((s.find(s[i],i+1)!=string::npos)){
                        if(t[i]!=t[s.find(s[i],i+1)]){
                                cout<<"No"<<endl;
                                return 0;
                        }
                }
        }
        cout<<"Yes"<<endl;
        return 0;
}

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

int main(){
  int N; cin >>N;
  int temp;
  int r = N;
  REP(i,N+1){
    int count = 0;
    temp = i;
    while(temp>0){ count += temp%6; temp /=6;}
    temp = N-i;
    while(temp>0){ count += temp%9; temp /=9;}
    if(r>count) r= count;
  }
  printf("%d\n",r);
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

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

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];

    if (n % 2 == 0) {
        repr(i, n, 0) cout << a[i--] << " ";
        repl(i, 0, n) {
            cout << a[i] << ((i == n - 1) ? "\n" : " ");
            i++;
        }
    } else {
        repr(i, n, 0) cout << a[i--] << " ";
        repl(i, 1, n) {
            cout << a[i] << ((i == n - 2) ? "\n" : " ");
            i++;
        }
    }
    return 0;
}

Measured memory_bytes: 2944
n = int(input())
s = str(input())
m = 0
for i in range(1,n):
  count = 0
  for j in "abcdefghijklmnopqrstuvwxyz":
    if j in s[0:i] and j in s[i:n]:
      count += 1
  if count > m:
    m = count
print(m)

Measured memory_bytes: 2940
import java.util.Scanner;

class Main{
      public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
    	int a;
    	String op;
    	int b;
    	for(;;){
    	  a = scan.nextInt();
          op = scan.next();
          b = scan.nextInt();
        	
	  if(op.equals("+")){
	    	System.out.println(a+b);
	  }else if(op.equals("-")){
	    	System.out.println(a-b);
	  }else if(op.equals("*")){
	    	System.out.println(a*b);
	  }else if(op.equals("/")){
	   	System.out.println(a/b);
	  }else{
	    	break;
	  }
    	}
     }
}

Measured memory_bytes: 26160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
  ll H,W;
  cin >> H >> W;
  ll ans=0;
  if(H==1 || W==1){
    cout << 1 << endl;
    return 0;
  }
  if(H%2==0){
    ans=H*W/2;
  }
  else{
    ans=(H-1)*W/2+(W+1)/2;
  }
  cout << ans << endl;
}

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

int main() {

	int n; cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.rbegin(), a.rend());
	ll ans = a[0];
	ll index = 1;
	n--;
	n--;
	bool next = false;
	while (n--) {
		ans += a[index];
		if (next) {
			index++;
			next = false;
		}
		else {
			next = true;
		}
	}
	cout << ans << endl;
    return 0;
}

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

int main()
{
    int a, b, c, d, e, k;
    cin>>a>>b>>c>>d>>e>>k;
    
    if((e-a)<=k){
        cout<<"Yay!";
    }
    else{
        cout<<":(";
    }

    return 0;
}

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

#define ll long long int
#define pb push_back

int main()
{
    string s1,s2;
    cin >> s1>>s2;
  int flag=0;
    for(int i=0;i<s1.length();i++)
    {
      if(s1[i]!=s2[i])
      {
        flag=1;
        break;
      }
    }
   
  if(flag)
    cout<< "No" <<'\n';
  else
    cout <<"Yes"<<'\n';
}

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

int calc(int x, int y, int z){
    return x*x + y*y + z*z + x*y + y*z + z*x;
}


int main() {
    
    int N;
    cin >> N;
    vector<int> ans(10500,0);

    for(int x = 1; x < 150; x++){
        for(int y = 1; y < 150; y++){
            for(int z = 1; z < 150; z++){
                int v = calc(x, y, z);
                if(v < 10500){
                    ans[v-1]++;
                }
            }
        }
    }

    for(int i = 0; i < N; i++){
        cout << ans[i] << endl;
    }

   
    // int N;
    // cin >> N;
    // vector<vector<int>> vec;

    // for(int x = 1; x < 42; x++){
    //     for(int y = 1; y < 42; y++){
    //         for(int z = 1; z < 42; z++){
    //             vector<int> xyz;
    //             xyz.push_back(x);
    //             xyz.push_back(y);
    //             xyz.push_back(z);
    //             vec.push_back(xyz);
    //         }
    //     }
    // }

    // for(int n = 1; n <=N; n++ ){
    //     bool find = false;
    //     int x = -1, y = -1, z = -1;
    //     for(auto v:vec){
    //         if(calc(v[0], v[1], v[2]) == n){
    //             find = true;
    //             x = v[0];
    //             y = v[1];
    //             z = v[2];
    //             break;
    //         }
    //     }
    //     int ans = 0; 
    //     if(find){
    //         ans = f(x,y,z);
    //     }
    //     cout<< ans << endl;
    // }

    return 0;
}

Measured memory_bytes: 3688
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;

int N;

void dfs(string S) {
	if (S.size() == N) {
		cout << S << endl;
		return;
	}
	char c = 'a';
	REP(i, S.size()) {
		chmax(c, S[i]);
	}
	for (char i = 'a'; i <= c + 1; i++) {
		dfs(S + i);
	}
}


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

	cin >> N;
	
	dfs("a");

	return 0;
}



Measured memory_bytes: 1536
import Control.Monad
main = do
 [n,m]<-map read . words <$> getLine
 asbs <- replicateM m $ map (read::String-> Int) .words <$> getLine
 let edges = asbs ++ (map reverse asbs)
 putStr $ show $ length (f [[1]] edges (n - 1))
 
next v es = [b| [a,b]<-es , a == v]
g p es = [v:p|v<- next (p!!0) es, not $ v `elem` p]
f::[[Int]]->[[Int]]->Int->[[Int]]
f ps es 0 = ps 
f ps es n = f (concat (map (flip g es) ps)) es (n-1)


Measured memory_bytes: 1020
#include<stdio.h>
int s[9][9]={0};
int visit[9]={0},n;
int path(int c){
	visit[c]=1;
	int d=1,cnt=0;
	for(int i=1;i<=n;i++){
		if(visit[i]==0){d=0;}
	}
	if(d){visit[c]=0;return 1;}
	for(int i=2;i<=n;i++){
		if(s[c][i]==1&&visit[i]==0){
			cnt+=path(i);
		}
	}
	visit[c]=0;
	return cnt;
}
int main(void){
	int m,a,b;
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d %d",&a,&b);
		s[a][b]=s[b][a]=1;
	}
	printf("%d",path(1));
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>

int main()
{
    double x,m,j;
    scanf("%lf %lf",&x,&m);
    j=log10(x)/log10(m)+1;
    printf("%d\n",(int)j);

    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
    long long int n, i, j, ans=0, bstart=0, aend=0, min=0, aa=-1, bb=-1, ba=0;
    scanf("%lld", &n);
    char s[n][15];
    for(i=0; i<n; i++){
        memset(s[i], '\0', 15);
        scanf("%s", s[i]);
    }

    for(i=0; i<n; i++){
        for(j=0; s[i][j]!='\0'; j++){
            if(s[i][j] == 'A' && s[i][j+1] == 'B') ans++;
            if(j == 0 && s[i][j] == 'B'){
                bstart++;
                bb = i;
            }
            if(s[i][j] == 'A' && s[i][j+1] == '\0'){
                aend++;
                aa = i;
            }
        }
        if(aa == i && bb == i) ba++;
    }
    min = bstart;
    if(min>aend) min = aend;
    if(ba == aend && ba == bstart && ba != 0) ans--;

    printf("%lld", ans+min);
}

Measured memory_bytes: 256
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a = LISTS()
    if a[1] =='+':
        print(int(a[0])+int(a[2]))
    else:
        print(int(a[0])-int(a[2]))
if __name__ == '__main__':
    do()

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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#else
#define TEST(n) ((void)0)
#endif

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	string s;
	int R;
	long long ans = 0;
	cin >> s;
	R = s.size() - (s.back() == 'B');
	for (int i = s.size() - 2; i >= 0; i--) {
		if (s[i] == 'B') {
			if (s[i + 1] == 'W') {
				ans += --R - i;
				s[i] = 'W';
			}
			else {
				R = i;
			}
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 720
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long ans=0;
		for(int i=1; i<=n; i++){
			if(i%3!=0 && i%5!=0){
				ans+=i;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 35772
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

N,M = map(int,input().split())

A = [[] for i in range(N)]

for i in range(N):
    A[i] = list(map(int,input().split()))

B = [[0]*1 for i in range(M)]

for i in range(M):
    B[i] = int(input())


for row in range(N):
    tmp = 0
    for col in range(M):
        tmp += A[row][col]*B[col]
    print("%d"%(tmp))



Measured memory_bytes: 6036
#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
#define int long long
using namespace std;
signed main() {
	string S;
	cin >> S;
	int A = 0;
	if (S.at(0) == 'o') {
		A++;
	}
	if (S.at(1) == 'o') {
		A++;
	}
	if (S.at(2) == 'o') {
		A++;
	}
	cout << 700 + A * 100 << endl;


}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
typedef pair<int,int> P;
typedef vector<int> vi;

ll gcd(ll a,ll b){
    ll v0=a,v1=b,v2=a%b;
    while(v2!=0){
        v0=v1;
        v1=v2;
        v2=v0%v1;
    }
    return v1;
}

ll lcm(ll a,ll b){
    return (a*b/gcd(a,b));
}

int main(){
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<int> a;
    int keta;
    int ff=0;
    if(n<=9) cout << n <<endl;
    else{
        while(n){
        a.push_back(n%10);
        n/=10;
        keta++;
    }

    rep(i,a.size()-1){
        if(a[i]==9) ff++;
    }
    int ans=9*(keta-1);
    if(ff==keta-1) ans+=a.back();
    else ans+=a.back()-1;
    cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=200005;
string s;
int q,t,f;
char c;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>s;
	cin>>q;
	int cnt=0;
	while(q--) {
		cin>>t;
		if(t==1) cnt++;
		else if(t==2) {
			cin>>f>>c;
			if(f==1) {
				if(cnt%2) {
					s.push_back(c);
				} else {
					s.insert(s.begin(),c);
				}
			} else if(f==2) {
				if(cnt%2) {
					s.insert(s.begin(),c);
				} else {
					s.push_back(c);
				}
			}
		}
	}
	if(cnt%2){
		reverse(s.begin(),s.end());
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 912
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define see(x) cout<< #x <<" = "<< x <<' ';
#define seen(x) cout<< #x <<" = "<< x <<'\n';
#define UWU cout<<'\n';
deque<ll> Q;
vector<ll> g[200005];
map<ll,ll> mp,sign;
void ThangPhanB(ll x){
    mp[x] = 1;
    Q.push_back(x);
    while(!Q.empty()){
        int k = Q.front();
        Q.pop_front();
        for(auto i : g[k]){
            if(mp[i] == 0){
                mp[i] = 1;
                sign[i] = k;
                Q.push_back(i);
            }
        }
    }
}

int main(){
//ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n,m,x,y;cin>>n>>m;

    for(int i = 0 ; i < m ; ++i){
        cin>>x>>y;
        g[x].pb(y);
        g[y].pb(x);
    }
    ThangPhanB(1);
    int cnt = 0;
    for(int i = 2 ; i <= n ; ++i){
        if(mp[i] == 1) cnt++;
    }
    if(cnt != n - 1) cout<<"No";
    else{
        cout<<"Yes";UWU;
        for(int i = 2 ; i <= n ; ++i){
        cout<<sign[i];UWU;
    }
    }

}


Measured memory_bytes: 26964
#include<bits/stdc++.h>
using namespace std ;
int H , W ;
int board[550][550] ;

void dfs (int x , int y ){
  board[x][y] = 0 ;
  for(int i = -1 ; i < 2 ; i++ )
    for(int j = -1 ; j < 2 ; j++ ){
      int nx = x + i , ny = y + j ;
      if( nx >= 0 && ny >= 0 && nx < H && ny < W &&board[nx][ny] == 1) dfs(nx,ny);
    }
}

int main () {
  while(1){
    int ans = 0 ;
    cin >> W >> H ;
    if(H==0&&W==0) break ;
    for(int i = 0 ; i < H ; i++ ){
      for(int j = 0 ; j < W ; j++ ){
        cin >> board[i][j] ;
      }
    }
    for(int i = 0 ; i < H ; i++ ){
      for(int j = 0 ; j < W ; j++ ){
        if(board[i][j]==1){
          dfs(i,j) ;
          ans ++ ;
        }
      }
    }
    cout << ans << endl ;
  }
}


Measured memory_bytes: 3344
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll n,ans,a,b=1000000002,c[100005],d[100005],mx;
P x[100005];
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
		cin>>x[i].F>>x[i].S;
		x[i].S++;
		mx=max(mx,x[i].S-x[i].F);
		if(b>x[i].S)b=x[i].S,a=x[i].F;
		if(b==x[i].S)a=min(a,x[i].F);
	}
    sort(x,x+n);
    c[n-1]=x[n-1].F;
    d[n-1]=x[n-1].S;
    for(int i=n-2;i>=0;i--){
		c[i]=max(c[i+1],x[i].F);
		d[i]=min(d[i+1],x[i].S);
	}
	for(int i=0;i<n;i++){
		a=max(a,x[i].F);
		if(a==x[i].F)ans=max(ans,max(b-a,0LL)+max(d[i+1]-c[i+1],0LL));
	}
	ans=max(ans,max(b-a,0LL)+mx);
	cout<<ans<<endl;
}


Measured memory_bytes: 3328
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>


#define NODE_NUM 100
#define MAX_VALUE 10000000

int cost[NODE_NUM][NODE_NUM];

void WarshallFloyd(){
    int i,j,k;
    
    for (k=0;k < NODE_NUM; k++) {
        for (i=0; i < NODE_NUM; i++) {
            for (j=0; j < NODE_NUM; j++) {
                if (cost[i][j] > cost[i][k] + cost[k][j]) {
                    cost[i][j] = cost[i][k] + cost[k][j];
                }
            }
        }
    }
}


int main( ){
    
    int n, i, j, u, v, k, c;
    scanf("%d", &n);
    
    
    for (i = 0; i < NODE_NUM; i++) {
        for (j =0 ; j < NODE_NUM; j++) {
            cost[i][j] = i == j ? 0 : MAX_VALUE;
        }
    }
    
    for (i = 0; i < n; i++) {
        scanf("%d %d", &u, &k);
        for (j =0 ; j < k; j++) {
            scanf("%d %d", &v, &c);
            cost[u][v] = c;
        }
    }
    
    WarshallFloyd();
    
    for (i=0; i<n; i++) {
        printf("%d %d\n", i, cost[0][i]);
    }
    
    return 0;
}

Measured memory_bytes: 636
#include<stdio.h>
#include<math.h>
 
int main(){
 
  int n,i,j,x,judge,count = 0;
  int a[10000] = {0};
 
   scanf("%d",&n);
 
  for(i = 0; i < n; i++){
 
     scanf("%d",&a[i]);

   }

   for(i = 0; i < n; i++){

    x = sqrt(a[i]);
    
    judge = 0;

    for(j = 2; j <= x; j++){

      if(a[i] % j == 0){

       judge = 1;

 }

      if(judge == 1){

       break;

       }

  }
   
       if(judge == 0){
       
       count++;
 
   }

}

 
    
     printf("%d\n",count);
 
    
       return 0;

}

Measured memory_bytes: 1840
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)

vector<vi> G;
vi Used;

void DFS(int v) {
    for (int u : G[v]) {
        if (Used[u]) continue;
        Used[u] = 1;
        DFS(u);
    }
}

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    G = vector<vi>(N);
    for (int m = 0; m < M; ++m) {
        int x, y, z;
        cin >> x >> y >> z;
        --x; --y;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    
    Used = vector<int>(N, 0);
    int Ans = 0;
    for (int n = 0; n < N; ++n) {
        if (Used[n]) continue;
        DFS(n);
        ++Ans;
    }
    cout << Ans << endl;

    return 0;
}


Measured memory_bytes: 9216
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.bitmanip;


bool ok(ref long[] A, ref long[] B, long n) {
    long s = n * (n+1) / 2;
    if (A.sum % s != 0)
        return false;
    long m = A.sum / s;
    long x = 0;

    //writeln(x, " ", m);
    foreach (i; 0..n) {
        //writeln(m, " ", B[i], " ", m - B[i]);
        if ((m + B[i]) % n != 0)
            return false;
       long d = (m + B[i]) / n;
       if (d < 0) return false;
       x += d;
    }

    return x == m;
}

void main() {
    auto N = readln.chomp.to!long;
    auto A = readln.split.map!(to!long).array;
    auto B = new long[](N);
    foreach (i; 0..N) {
        B[i] = A[i] - A[(i+1)%N];
    }

    writeln(ok(A, B, N) ? "YES" : "NO");
}


Measured memory_bytes: 4660
n = gets.to_i
tmp = n.to_s.size
1.upto(n ** 0.5) do |a|
  b = n.to_f / a.to_f
  if b.to_s[-1] == "0"
    d = a.to_i.to_s.size > b.to_i.to_s.size ? a.to_i.to_s.size : b.to_i.to_s.size
    tmp = d if tmp > d
  end
end
puts tmp

Measured memory_bytes: 1788
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
#include <chrono>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using mint = ModInt< MOD >;

int n, x;
int s[200];
mint dp[100001];

int main() {
    cin >> n >> x;
    rep(i,n) cin >> s[i];
    sort(s, s+n, greater<int>());
    dp[x] = 1;
    rep(i,n) {
        for (int j = 0; j <= x; j++) {
            if (j >= s[i]) {
                dp[j%s[i]] += dp[j];
                dp[j] = dp[j]*(n-1-i);
            } else {
                dp[j] = dp[j]*(n-i);
            }
        }
    }
    mint ans = 0;
    rep(i,x+1) ans += dp[i]*i;
    cout << ans << endl;
}


Measured memory_bytes: 640
s = input()
n = len(s)
def rec(op_index, part_s):
    if op_index == n - 1:
        return sum(map(int, part_s.split('+')))
    part_s1 = '{}{}'.format(part_s, s[op_index+1])
    part_s2 = '{}+{}'.format(part_s, s[op_index+1])
    return rec(op_index+1, part_s1) + rec(op_index+1, part_s2)
 
print(rec(0, s[0]))

Measured memory_bytes: 9184
# 区間ではなく各要素を独立に考える典型のやつ

# ある値について条件を満たすようにしたいとき
# その値より大きいものだけ探せば良い
# 具体的には自分より大きい値を1つだけ含むような区間が条件を満たす

# 愚直にやると各値について, その左右を近い方から順に見ていかなければならず間に合わない
# 自分より大きい値だけ知りたいので, 要素の大きい順に見ていくことで計算量が減る

# 普通にやったのが下のコードでAC+TLE(恐らく合ってる)

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    p = list(map(int, input().split()))

    # 1-indexed
    # f[i]:要素iのインデックス
    f = [0]*(n+1)
    for i in range(n):
        f[p[i]] = i+1

    # 各要素よりも大きい値のインデックスを参照するための配列
    l = [0] + [i for i in range(n+1)]
    r = [i + 1 for i in range(n+1)] + [n+1]

    res = 0

    for i in range(1,n+1):
        # x:要素iのインデックス
        x = f[i]
        
        # iは1から見ていくので, 選んだ時点でiより大きい数のインデックスが分かる
        l1,r1 = l[x],r[x]
        l2,r2 = l[l1],r[r1]

        res += ((l1-l2)*(r1-x) + (x-l1)*(r2-r1))*i

        # 要素iのインデックスをこれ以降参照することはないので消す
        l[r1],r[l1] = l1,r1

    print(res)

if __name__ == '__main__':
    main()

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

vector<bool> visit(10);
int N;
double ans, road;
vector<vector<double>> path(10, vector<double>(10,0));

int factorial(int N){
	if(N==1) return 1;
	int out = N * factorial(N-1);
	return out;
}

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
// ここに処理を記述

	cin >> N;

	vector<int> v;
	vector<P> A;
	int x,y;
	for(int i=0; i<N; i++){
		v.push_back(i+1);
		cin >> x >> y;
		A.push_back(make_pair(x,y));
	}

	REP(i,N-1){
		FOR(j,i+1,N){
			path[i+1][j+1] = (A[i].first - A[j].first)*(A[i].first - A[j].first) + (A[i].second - A[j].second)*(A[i].second - A[j].second);
			path[i+1][j+1] = sqrt(path[i+1][j+1]);
			path[j+1][i+1] = path[i+1][j+1]; 
		}
	}

	road = 0;

	do{
		REP(i,N-1){
			road += path[v[i]][v[i+1]];
		}
	}while(next_permutation(v.begin(),v.end()));

	ans = road / (double)factorial(N);

	cout << setprecision(12);
	cout << ans << "\n";

return 0;
}

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

int main(){
  vector<char> d(3);
  for (int i=0; i<3; i++){
    cin >> d[i];
  }
  sort(d.begin(), d.end());
  if (d[0]=='a'&&d[1]=='b'&&d[2]=='c') cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int n,ar[10050],ans;

int main(void) {
cin>>n;
for(int i=0;i<n;i++) cin>>ar[i];
for(int i=0,j=0;i<=n;i++) 
if(ar[i] != ar[j])
{
ans+=(i-j)/2;
j=i;
}
cout<<ans<<endl;

}


Measured memory_bytes: 256
def calculate(N, arr, S):
    result = []
    tmp = 0
    for i in range(len(arr)):
        if i % 2 == 1:
            tmp += arr[i] * 2

    x0 = S - tmp

    result.append(x0)

    for i in range(1, N):
        result.append(arr[i - 1] * 2 - result[i - 1])

    return result


def calculate2(i, arr):
    # 取偶数项
    return sum(arr[::2]) * 2


def calculateTotaAmount(arr):
    return sum(arr)


def printArr(arr):
    result = ""
    for i in range(len(arr)):
        result += str(arr[i]) + " "

    return result



N = int(input())

S = input().split(" ")
aArr = [int(s) for s in S]

result = calculate(N, aArr, calculateTotaAmount(aArr))
print(" ".join([str(s) for s in result]))


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

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

int dfs(int y, int x, vector<string> &g){
  if(g[y][x] == '#')return 0;
  g[y][x] = '#';

  int res = 1;
  for(int i=0;i<4;i++){
    int ny = y + dy[i], nx = x + dx[i];
    if(ny<0 || nx<0 || ny>=(int)g.size() || nx>=(int)g[0].size())continue;
    res += dfs(ny,nx,g);
  }
  return res;
}

int main(){
  int w,h;
  while(cin >> w >> h){
    if(w==0 && h==0)break;

    vector<string> g(h);
    int y=0,x=0;
    for(int i=0;i<h;i++){
      cin >> g[i];
      for(int j=0;j<w;j++){
	if(g[i][j] == '@')y = i, x = j;
      }
    }

    cout << dfs(y,x,g) << endl;
  }
}

Measured memory_bytes: 1248
#include<stdio.h>

int gcd(int,int);

int main() {

  int x,y;

  scanf("%d %d",&x,&y);
  printf("%d\n",gcd(x,y));

  return 0;

}

int gcd(int a,int b) {

  if(a>=b) {

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

  } else {

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

  }

}


Measured memory_bytes: 2144
X, K, D = map(int, input().split())

need_jump = abs(X) // D
# print(need_jump)

if need_jump >= K:
    print(abs(X) - D * K)
    exit()

# まだ残っていて、奇数ならもう1回飛んだ値、偶数ならその値が答え
cand1 = abs(X) - D * need_jump
# cand2 = abs(cand1 - D)
# print(min(cand1, cand2))

if (K - need_jump) % 2 == 1:
    ans = abs(cand1 - D)
else:
    ans = cand1
print(ans)


Measured memory_bytes: 9144
import math 
n,m = map(int,input().split())
nm_abs = abs(n-m)
n_lad = math.factorial(n)
m_lad = math.factorial(m)
if nm_abs >= 2:
  print(0)
elif nm_abs == 1:
  print((n_lad * m_lad) % (10**9+7))
else:
  print((n_lad * m_lad*2) % (10**9+7))


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

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	int H, W, D;
    vector<vector<int>> A;
    vector<pair<int,int>> c;
    vector<vector<int>> sum;
    int Q;
    
    cin>>H>>W>>D;
	
    A.resize(H, vector<int>(W));
    sum.resize(D, vector<int>((H * W + D - 1)/ D + 10));
    c.resize(H * W);
	
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin>>A[i][j];
            
            A[i][j]--;
            
            c[A[i][j]] = {i, j};
        }
    }
    
    for(int i = 0; i < D; i++){
        for(int j = i; j < W * H; j += D){
            if(j != i) {
                sum[i][j/D] += sum[i][j/D-1] + abs(c[j].first - c[j-D].first) + abs(c[j].second - c[j-D].second);
            }
        }
    }
    
    cin>>Q;
    
    for(int i = 0; i < Q; i++){
        int L, R;
        
        cin>>L>>R;
        
        L--, R--;
        
        cout<<sum[L%D][R/D] - sum[L%D][L/D]<<endl;
        
    }
    
	return 0;
}

Measured memory_bytes: 15796
n = int(input())
A = [0]*n
B = [0]*n
for i in range(n):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b

A.sort()
B.sort()

if n%2 == 1:
    ans = B[n//2]-A[n//2]+1
else:
    ans = B[n//2-1]+B[n//2]-(A[n//2-1]+A[n//2])+1
print(ans)


Measured memory_bytes: 25424
import java.util.*

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val list = ArrayList<Pair<Int, Int>>()
    repeat(n) {
        val (x, y) = readLine()!!.split(" ").map { it.toInt() }
        list.add(x to y)
    }

    var r = 0.0
    for (a in 0 until n) {
        for (b in 0 until n) {
            if (a == b) continue
            val m = (list[a].first - list[b].first) * (list[a].first - list[b].first) +
                    (list[a].second - list[b].second) * (list[a].second - list[b].second)
            r += Math.sqrt(m.toDouble())
        }
    }
    println(r/n)
}

Measured memory_bytes: 37744
var
	S:String;
	N,K,C,i,now:Longint;
	R:Array[1..200000]of Longint;
begin
	readln(N,K,C);
	readln(S);
	now:=K;i:=N;
	while i>=1 do begin
		if S[i]='o'then begin
			R[i]:=now;
			dec(now);
			dec(i,C);
		end;
		dec(i);
	end;
	now:=0;i:=1;
	while i<=N do begin
		if S[i]='o'then begin
			inc(now);
			if R[i]=now then writeln(i);
			inc(i,C);
		end;
		inc(i);
	end;
end.


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

vector<vector<ll>> a(200010);
ll c[200010];
bool ch[200010];
void dep(ll now,ll v,ll nowc){
	c[now]=nowc;
	if(now!=0&&a[now].size()==1){
		return;
	}
	for(int i=0;i<a[now].size();i++){
		ll next=a[now][i];
        if(next==v){
          continue;
        }
		dep(next,now,nowc+c[next]);
	}
}
int main() {
	ll n,q;
	cin>>n>>q;
	for(int i=0;i<n-1;i++){
		ll x,y;
		cin>>x>>y;
		x--;y--;
		a[x].push_back(y);
		a[y].push_back(x);
	}
	for(int i=0;i<q;i++){
		ll x,y;
		cin>>x>>y;
		x--;
		c[x]+=y;
	}
	dep(0,-1,c[0]);
	for(int i=0;i<n;i++){
		cout <<c[i]<< " ";
	}
	return 0;
}

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

using namespace std;

#define INF INT_MAX
#define F first
#define S second

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

int main(){
  int n;
  int cnt[4]={};
  string judge[4]={"AC","WA","TLE","RE"};
  
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    for(int j=0;j<4;j++){
      if(judge[j]==s) cnt[j]++;
    }			  
  }
  for(int i=0;i<4;i++){
    cout<<judge[i]<<" x "<<cnt[i]<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 3688
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


template <typename T>
bool chmax(T & a, const T & b) {
	if (a < b) {
		a = b; 
		return true;
	}
	return false;
}
template <typename T>
bool chmin(T & a, const T & b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}


#define ARRAY_MAX 100005
const int INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

int dx4[4] = { 1,0,0,-1 };
int dy4[4] = { 0,1,-1,0 };
int dx2[2] = { 1,0 };
int dy2[2] = { 0,1 };

/******************************************************************************************/

vector<int> G[2005];

int dist[2005][2005];

vector<int> bfs(int n, int st) {

	vector<int> d(n+10, INF);
	queue<int> que;
	que.push(st);
	d[st] = 0;
	
	while (!que.empty()) {

		int now = que.front();
		que.pop();
		if (d[now] == INF)continue;

		for (auto nxt : G[now]) {

			if (d[nxt] > d[now] + 1) {
				d[nxt] = d[now] + 1;
				que.push(nxt);
			}
		}
	}

	return d;
}


int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);

	ll x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	vector<ll> p(a), q(b), r(c);

	for (int i = 0; i < a; i++)
	{
		cin >> p[i];
	}

	for (int i = 0; i < b; i++)
	{
		cin >> q[i];
	}

	for (int i = 0; i < c; i++)
	{
		cin >> r[i];
	}

	sort(p.rbegin(), p.rend());
	sort(q.rbegin(), q.rend());
	sort(r.rbegin(), r.rend());

	priority_queue<ll,vector<ll>,greater<ll> > R, G;


	for (int i = 0; i < x; i++)
	{
		R.push(p[i]);
	}

	for (int i = 0; i < y; i++)
	{
		G.push(q[i]);
	}
	
	for (int i = 0; i < c; i++)
	{
		ll Rmin = R.top();
		ll Gmin = G.top();

		if (Rmin > Gmin) {

			if (Gmin < r[i]) {
				G.pop();
				G.push(r[i]);
			}

		}
		else
		{
			if (Rmin < r[i]) {
				R.pop();
				R.push(r[i]);
			}
		}
	}

	ll ans = 0;
	while (!R.empty()) {
		ans += R.top();
		R.pop();
	}

	while (!G.empty()) {
		ans += G.top();
		G.pop();
	}

	cout << ans << endl;






	return 0;
}



Measured memory_bytes: 4980
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

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

using namespace std;

vector<string> v;
string s;
string t;

int dp[3005][3005];

int main()
{
    cin >> s;
    cin >> t;
    
    int slen = s.length();
    int tlen = t.length();
    
    for (int i = 1;i <= slen;i++){
        for (int j = 1;j <= tlen;j++){
            if (s[i-1] == t[j-1]){
                dp[i][j] = 1+dp[i-1][j-1];
            }
            else {
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    
    int len = dp[slen][tlen];
    string ans(len,'A');
    int l = len;
    int i = slen;
    int j = tlen;
    
    while (l > 0){
        if (s[i-1] == t[j-1]){
            l--;
            ans[l] = s[i-1];
            i--;
            j--;
        }
        else if (dp[i][j] == dp[i][j-1]){
            j--;
        }
        else {
            i--;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 35456
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

s64 dp[5000][5001];
s64 dst[5000][5001];

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

    s64 n, k;
    cin >> n >> k;

    vs64 p(n), c(n);
    rep (i, n)
    {
        cin >> p[i];
        --p[i];
    }
    rep (i, n)
    {
        cin >> c[i];
    }

    // vector< vs64 > dp(n, vs64(n + 1));
    // vector< vs32 > dst(n, vs32(n + 1));
    rep (i, n) dp[i][0] = 0;
    rep (i, n) dst[i][0] = i;

    rep (j, n)
    {
        rep (i, n)
        {
            dst[i][j + 1] = p[dst[i][j]];
        }
    }

    rep (j, n)
    {
        rep (i, n)
        {
            dp[i][j + 1] = dp[i][j] + c[dst[i][j + 1]];
        }
    }

    s64 ans = -1e18;
    rep (i, n)
    {
        s64 loop;
        for (loop = 1; loop <= n; ++loop)
        {
            if (dst[i][loop] == i)
            {
                break;
            }
        }

        s64 sum;
        if (k > n && loop <= k && dp[i][loop] >= 0)
        {
            s64 tk = k % loop;
            sum = dp[i][loop] * (k / loop);
            s64 temp = 0;
            rep (j, tk + 1)
            {
                temp = max(temp, dp[i][j]);
            }
            rep (j, loop + 1)
            {
                temp = max(temp, dp[i][j] - dp[i][loop]);
            }
            sum += temp;
        }
        else
        {
            sum = -1e18;
            rep (j, MIN(n, k))
            {
                sum = max(sum, dp[i][j + 1]);
            }
        }
        ans = max(ans, sum);
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 394400
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>

ll n,cnt,ans,a[ohara],b[ohara],c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
P p[ohara];

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n>>k;
    rep(i,n){
        cin>>a[i]>>b[i];
        p[i]=m_p(a[i],b[i]);
    }
    sort(p,p+n);
    ll now=0;
    rep(i,n){
        now+=p[i].se;
        if(now>=k){
            Cout(p[i].fi);
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 7936
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(1);

  int N, K;

  std::cin >> N >> K;

  long long C = 0;

  for (int i = 0; i < K; i ++) {
    if ((i + i) % K)
      continue;

    long long c = N / K;

    if (i)
      c += i <= N % K;

    C += c * c * c;
  }

  std::cout << C << std::endl;
  
  return 0;
}


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

int main()
{
    string s;
    cin>>s;
    if(s=="SUN")
    {
        cout<<7;
    }
    else if(s=="MON")
    {
        cout<<6;
    }
    else if(s=="TUE")
    {
        cout<<5;
    }
    else if(s=="WED")
    {
        cout<<4;
    }
    else if(s=="THU")
    {
        cout<<3;
    }
    else if(s=="FRI")
    {
        cout<<2;
    }
    else if(s=="SAT")
    {
        cout<<1;
    }


    return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  int N;
  cin >> N;
  int ans = 1;
  while (ans <= N) {
    if (ans*2 <= N) {
      ans *= 2;
    } else {
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3568