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

using ll = long long;

vector<ll> seg;

template<typename T>
void max_self(T& a, T b)
{
  a = max(a, b);
}

void calculate(int root)
{
  seg[root] = max(seg[root * 2], seg[root * 2 + 1]);
}

long long maxi(int l, int r, int x, int y, int root = 1)
{
  // full overlap
  if(x <= l and r <= y)
    return seg[root];
  
  // no overlap
  if(y < l or r < x)
    return 0;
  
  ll ans = 0;
  int mid = (l + r) / 2;
  max_self(ans, maxi(l, mid, x, y, root * 2));
  max_self(ans, maxi(mid + 1, r, x, y, root * 2 + 1));
  return ans; 
}

void update(int l, int r, int x, ll val, int root = 1)
{
  if(l == r)
  {
    seg[root] = val;
    return;
  }
  int mid = (l + r) / 2;
  if(x <= mid)
    update(l, mid, x, val, root * 2);
  else
    update(mid + 1, r, x, val, root * 2 + 1);
  calculate(root);  
}


int main()
{
  int n;
  scanf("%d", &n);
  seg.resize(4*n);
  vector<int> h(n), a(n);
  for(int i = 0; i < n; i++)
  {
    scanf("%d", &h[i]);
  }
  for(int i = 0; i < n; i++)
  {
    scanf("%d", &a[i]);
  }
  vector<long long> dp(n + 1);
  // the max total value so far if the last flower taken has height i
  
  for(int i = 0; i < n; i++)
  {
    ll best = maxi(1, n, 1, h[i]);
    dp[h[i]] = best + a[i];
    update(1, n, h[i] + 1, dp[h[i]]);
      
    // basically in below loop what we are doing is
    // find the max in range [0, h[i]] and assigning
    // it to dp[h[i]] means finding the maximum in a 
    // range -> use segment tree
    //  for(int j = 0; j < h[i]; j++)
    //  {
      //  max_self(dp[h[i]], dp[j] + a[i]);
    //  }
    //  for(int j = 0; j <= 3 * n; j++)
    //  printf("%lld ", seg[j]);
    //  printf("\n");
  }
  long long sol = 0;
  for(int i = 0; i <= n; i++)
  {
    max_self(sol, dp[i]);
  }
  printf("%lld", sol);
  
  
  return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define inf 1000000005
#define all(a) (a).begin(), (a).end()
#define ms(a,x) memset(a, x, sizeof(a))
#define mod 1000000007
#define sz(a) ((int)(a).size())

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcount(s);}
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define eps 1e-9
typedef pair<int, int> II;
template<class T> T gcd(T a, T b){ T r; while (b != 0) { r = a % b; a = b; b = r; } return a;}
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define PI 2 * acos(0)

#define maxn 600006

int n;

int main(){
	srand(1412);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
    ll a, b;
    cin >> n;
    ll Min = inf;
    ll res = 0;
    Rep(i, n){
    	cin >> a >> b;
    	if(a > b) Min = min(Min, b);
    	res += b;
    }
    if(Min < inf) cout << res - Min << endl;
    else cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 256
import heapq
N = int(input())
src = list(map(int,input().split()))

lsum = sum(src[:N])
lmem = [lsum]
lq = src[:N][:]
heapq.heapify(lq)
for a in src[N:2*N]:
    if a <= lq[0]:
        lmem.append(lmem[-1])
    else:
        lsum += a - heapq.heappop(lq)
        heapq.heappush(lq, a)
        lmem.append(lsum)

rq = [-a for a in src[-N:]]
rsum = sum(rq)
rmem = [rsum]
heapq.heapify(rq)
for a in reversed(src[N:2*N]):
    if -a <= rq[0]:
        rmem.append(rmem[-1])
    else:
        rsum += -a - heapq.heappop(rq)
        heapq.heappush(rq, -a)
        rmem.append(rsum)

ans = -float('inf')
for l,r in zip(lmem, rmem[::-1]):
    ans = max(ans, l+r)
print(ans)

Measured memory_bytes: 37212
#include <iostream>
#include <cstring>

using namespace std;

int main(){
	int n;
	string s;
	cin >> n;
	cin >> s;
	
	int hlf = n/2 + 1;
	int count = hlf;
	char red = 82;
	for(int i = 0;i < n ; i++){
	    char k = s[i];
		if(red == k){
			count--;
		}
		if(count == 0){ break;}
	}
	if( count == 0){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}

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

#define ROW_MAX 100
#define COL_MAX 100

int main() {
  int n, m;
  int a[ROW_MAX][COL_MAX];
  int b[COL_MAX];

  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      cin >> a[i][j];

  for (int j = 0; j < m; j++)
    cin >> b[j];

  for (int i = 0; i < n; i++) {
    int res_sum = 0;
    for (int j = 0; j < m; j++) {
      res_sum += a[i][j] * b[j];
    }
    cout << res_sum << endl;
  }

  return 0;
}



Measured memory_bytes: 3108
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX=1000;
static const int VMAX=10000;
int n,A[MAX],s;
int B[MAX],T[VMAX+1];
int solve(){
 int ans=0;
 bool V[MAX];
 for(int i=0;i<n;i++){
  B[i]=A[i];
  V[i]=false;
 }
 sort(B,B+n);
 for(int i=0;i<n;i++)T[B[i]]=i;
 for(int i=0;i<n;i++){
  if(V[i])continue;
  int cur=i;
  int S=0;
  int m=VMAX;
  int an=0;
  while(1){
   V[cur]=true;
   an++;
   int v=A[cur];
   m=min(m,v);
   S+=v;
   cur=T[v];
   if(V[cur])break;
  }
  ans+=min(S+(an-2)*m,m+S+(an+1)*s);
 }
 return ans;
}
int main(){
 cin>>n;
 s=VMAX;
 for(int i=0;i<n;i++){
  cin>>A[i];
  s=min(s,A[i]);
 }
 int ans=solve();
 cout<<ans<<endl;
 return 0;
}


Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

bool vis[100005];
vector<vii> adjlist;
int dp[100005];

void dfs(int i){
	vis[i] = true;
	for(int j=0;j<adjlist[i].size();j++){
		ii v = adjlist[i][j];
		if(!vis[v.first]){
			dfs(v.first);
		}
		dp[i] = max(dp[i],1+dp[v.first]);
	}
}

main(){
	int n,m;
	cin>>n>>m;
	adjlist.assign(n+1,vii());
	int x,y;
	while(m--){
		cin>>x>>y;
		adjlist[x].push_back(ii(y,1));
	}
	int ans = 0;
	memset(vis,false,sizeof(vis));
	for(int i=1;i<=n;i++){
		if(!vis[i]) dfs(i);
	}	
	cout<<*max_element(dp+1,dp+n+1);
}

Measured memory_bytes: 11764
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main(){
    let input : Vec<i64> = read_vec();
    let unit : i64 = input[1] + input[2];
    let remainder : i64 = input[0] % unit;
    let count : i64 = input[0] / unit;
    if remainder == 0 {
        println!("{}", input[1] * count);
    }
    else {
        if remainder >= input[1] {
            println!("{}", input[1] * (count + 1));
        }
        else {
            println!("{}", input[1] * count + remainder);
        }
    }
}

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

int main() {
  int N, M;
  
  map<string, int> U;
  
  cin >> N;
  for (int i = 0; i < N; ++i) {
    string si;
    cin >> si;
    U[si] += 1;
  }
  cin >> M;
  for (int i = 0; i < M; ++i) {
    string si;
    cin >> si;
    U[si] -= 1;
  }

  vector<int> V;
  V.push_back(0);
  for (const auto& x : U) {
    V.push_back(x.second); 
  }
  sort(V.begin(), V.end(), greater<int>());
  cout << V.at(0) << endl;
}

Measured memory_bytes: 3632
from collections import defaultdict
s = input()
t = input()
sd = defaultdict(set)
td = defaultdict(set)
for i in range(len(s)):
    sd[s[i]].add(t[i])
    td[t[i]].add(s[i])
if [1 for i in sd.values() if len(i)!=1] or [1 for i in td.values() if len(i)!=1]:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 4016
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int x = sc.nextInt();
		int sum = 0;
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			sum += d / a + 1;
			if (d < a * (d / a) + 1) {
				sum--;
			}
		}
		System.out.println(sum + x);
	}
}

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

vector<ll> totals;
vector<ll> patties;

ll saiki(ll N, ll X)
{
    //レベル0なら1を返す
    if(N == 0)
    {
        return 1;
    }
    if(X == totals.at(N))
    {
        //左端
        return patties.at(N);
    }else if(X > totals.at(N - 1) + 2){
        //左のレベルN - 1のどこか
        ll nextX = X - totals.at(N - 1) - 2;
        return patties.at(N - 1) + saiki(N - 1, nextX) + 1;
    }else if(X == totals.at(N - 1) + 2){
        //真ん中
        return patties.at(N - 1) + 1;
    }else if(X > 1){
        //右のレベルN - 1 のどこか
        return saiki(N - 1, X - 1);
    }else if(X == 1){
        //右端
        return 0;        
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, X;
    cin >> N >> X;
    totals = vector<ll>(N + 1);//レベルNのバーガー全体の層数
    patties = vector<ll>(N + 1);//レベルNのパティの数
    totals.at(0) = 1;
    patties.at(0) = 1;
    for (int i = 1; i <= N; i++)
    {
        totals.at(i) = totals.at(i - 1) * 2 + 3;
        patties.at(i) = patties.at(i - 1) * 2 + 1;
    }
    cout << saiki(N, X) << endl;
    return 0;
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	long long int len=0;
	long long int maxx=INT_MIN;
	string s;
	cin>>s;
	for(long long int i=0;i<s.size();i++){
		if(s[i]=='R'){
			len++;
			maxx=max(maxx,len);
		}
		else if(i==2){
			maxx=max(maxx,len);
		}
		else{
			len=0;
		}
	}
	cout<<maxx;
   	return 0;
}

Measured memory_bytes: 3648
using System;
using System.Linq;

namespace DOWANGO006
{
    class A
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] s = new string[N];
            int[] t = new int[N];
            for (int i = 0; i < N; i++)
            {
                string[] input = Console.ReadLine().Split().ToArray();
                s[i] = input[0];
                t[i] = int.Parse(input[1]);
            }
            string X = Console.ReadLine();
            int sum = 0;
            int total = t.Sum();
            for (int i = 0; i < N; i++)
            {
                sum += t[i];
                if (s[i] == X) break;
            }
            Console.WriteLine(total - sum);
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,l,r) for(int i=l;i<r;i++)
using ll = long long;
const int inf=2e9+10;
const ll MOD=1e9+7;
const ll INF=9e18+10;
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};

int n;
void bfs(int ans[],vector<int> adj[],int i){
	int dis[n];
	for(int j=0;j<n;j++)dis[j]=inf;
	queue<int> q;
	q.push(i);
	dis[i]=0;
	while(!q.empty()){
		int u=q.front();q.pop();
		rep(j,adj[u].size()){
			int v=adj[u][j];
			if(dis[v]!=inf)continue;
			dis[v]=dis[u]+1;
			q.push(v);
		}
	}
	for(int j=i;j<n;j++){
		ans[dis[j]]++;
	}


	return;
}
//iとi~n-1の点間の最短距離を求める(重複を避けるため)
//そしてきちんとansに記録

void solve(int ans[],vector<int> adj[]){
	for(int i=0;i<n;i++){
		bfs(ans,adj,i);
	}
}

int main(){
	int x,y;
	cin>>n>>x>>y;
	vector<int> adj[n];
	for(int i=1;i<n;i++){
		adj[i].emplace_back(i-1);
		adj[i-1].emplace_back(i);
	}
	--x;--y;
	adj[x].push_back(y);
	adj[y].push_back(x);
	int ans[n];//最短期よりが1-n-1になるものの数
	for(int i=1;i<n;i++)ans[i]=0;

	solve(ans,adj);
	for(int i=1;i<n;i++){
		cout<<ans[i]<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 3740
n,k=map(int,input().split())
d=set(map(str,input().split()))
i=n
a=[]
for j in range(len(str(n))):
	a.append(str(n)[j])
a=set(a)
while i<10**5+1:
	if len(a&d)==0:
		print(i)
		exit()
	else:
		i+=1
		a=[]
		for j in range(len(str(i))):
			a.append(str(i)[j])
		a=set(a)


Measured memory_bytes: 3064
int main(void){
	int num;
	scanf("%d", &num);

	char str1[num];
	char str2[num];
	scanf("%s %s", str1, str2);

	for(int i=0; i<num; i++){
		printf("%c%c", str1[i], str2[i]);
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 1668
import java.util.Scanner;

class Main{

	static int ans = Integer.MAX_VALUE;
	static	boolean[] flag ;
	static	int[][] dp ;
	static	int count = 0;
	static 	int[] r ;

	public static void main(String[] args) {



		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int M = scanner.nextInt();
		int R = scanner.nextInt();

		r = new int[R];
		for(int i= 0;i <  R;i++){
			r[i] = scanner.nextInt();

		}

		flag = new boolean[R];

		int[] A = new int [M+1];
		int[] B = new int [M+1];
		int[] C = new int [M+1];

		dp =  new int[201][201];
		
		for(int i = 1; i < N+1;i++){
			for(int j = 1;j < N+1;j++){
				if(i != j){
					dp[i][j] = Integer.MAX_VALUE/2;
				}
			}
		}

		for(int i =1 ;i < M+1;i++){
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			int c = scanner.nextInt();

			dp[a][b] = c;
			dp[b][a] = c;

		}


		for(int k = 1;k < N+1;k++){
			for(int i = 1;i < N+1;i++){
				for(int j = 1;j < N+1;j++){
					dp[i][j] = Math.min(dp[i][j], dp[i][k] + dp[k][j]);
				}
			}
		}

	

		dps(r,0,0,0);

		System.out.println(ans);

	}

	static void dps(int[] r,int p,int sum ,int count){


		if(count == r.length){
			ans = Math.min(sum, ans);
			return ;
		}

		for(int i = 0;i < r.length;i++){


			if(!flag[i]){
				flag[i] = true;
				if(p == 0){
					dps(r, r[i], 0, count+1);	
				}else{
					dps(r, r[i], sum+dp[p][r[i]], count+1);	
				}
				flag[i] = false;

			}
		}

	}
}

class Pair implements Comparable{
	int from;
	int middle;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}






Measured memory_bytes: 47408
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    static class BBiteEating
    {
        static void Main(string[] args)
        {
            var nl = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
            int n = nl[0];
            int l = nl[1];

            bool includeZero = false;
            int tastes = 0;
            for (int i = 0; i < n; i++)
            {
                if (l + i == 0)
                {
                    includeZero = true;
                }
                tastes += l + i;
            }

            if (includeZero)
            {
                Console.WriteLine(tastes);
                Console.ReadLine();
                return;
            }

            if (Math.Abs(l) < Math.Abs(l + n - 1))
            {
                Console.WriteLine(tastes - l);
                Console.ReadLine();
                return;
            }

            Console.WriteLine(tastes - (l + n - 1));
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char b;
  cin >> b;
  if(b == 'A'){
    cout << 'T' << endl;
  }
  if(b == 'C'){
    cout << 'G' << endl;
  }
  if(b == 'G'){
    cout << 'C' << endl;
  }
  if(b == 'T'){
    cout << 'A' << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
int n,f[maxn],dep[maxn];
vector<int>g[maxn];
void dfs(int u,int fa){
	for(int i=0;i<g[u].size();i++)
		if(g[u][i]!=fa)
			dep[g[u][i]]=dep[u]+1,dfs(g[u][i],u);
}
int main(){
	f[0]=1;
	f[1]=0;
	scanf("%d",&n);
	for(int i=2;i<=n;i++)
		if(f[i-1]&&f[i-2])
			f[i]=0;
		else f[i]=1;
		int x,y;
	for(int i=2;i<=n;i++){
		scanf("%d%d",&x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	dfs(1,0);
	int t=1;
	for(int i=2;i<=n;i++)
		if(dep[i]>dep[t])
			t=i;
	for(int i=1;i<=n;i++)
		dep[i]=0;
	dfs(t,0);
	t=0;
	for(int i=1;i<=n;i++)
		t=max(t,dep[i]);
	if(f[t])
		puts("First");
	else puts("Second");
}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const  ll INF = 1e18;
const  ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i,n,init) for(ll i=init;i<(n);i++)
#define repd(i,n,init) for(ll i=(n);i>=init;i--)
#define repm(i,m) for(auto i=m.begin();i!=m.end();i++)

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

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const long long inf = 1e17;

struct data {
	int id[2];
	long long c[2];
	void merge(const data &x, const data &y) {
		if(x.c[0] < y.c[0]) {
			id[0] = x.id[0];
			c[0] = x.c[0];
		} else {
			id[0] = y.id[0];
			c[0] = y.c[0];
		}
		id[1] = id[0];
		c[1] = inf;
		for(int i = 0; i < 2; i++) {
			if(id[0] != x.id[i] && c[1] >= x.c[i]) {
				id[1] = x.id[i];
				c[1] = x.c[i];
			} 
		}	
		for(int i = 0; i < 2; i++) {
			if(id[0] != y.id[i] && c[1] >= y.c[i]) {
				id[1] = y.id[i];
				c[1] = y.c[i];
			} 
		}
	}
};

struct info {
	long long val;
	int i, j;
	info() {}
	info(long long val, int i, int j) : val(val), i(i), j(j) {}
	bool operator < (const info &x) const {
		return val < x.val;
	}
};

data p[200010 * 4];
data q[200010 * 4];
info ans[200010 * 4];

int n;
long long D;
int a[200010];

void build(int c = 1, int b = 1, int e = n) {
	if(b == e) {
		p[c].id[0] = p[c].id[1] = b;
		p[c].c[0] = D*b + a[b];
		p[c].c[1] = inf;

		q[c].id[0] = q[c].id[1] = b;
		q[c].c[0] = -D*b + a[b];
		q[c].c[1] = inf;

		ans[c] = info(inf, b, b);
		return ;
	}
	int m = (b + e) >> 1;
	int l = c << 1;
	int r = l + 1;
	build(l, b, m);
	build(r, m+1, e);
	p[c].merge(p[l], p[r]);
	q[c].merge(q[l], q[r]);
	ans[c] = min(ans[l], ans[r]);
	for(int i = 0; i < 2; i++) {
		for(int j = 0; j < 2; j++) {
			if(p[r].id[i] != q[l].id[j]) {
				ans[c] = min(ans[c], info(p[r].c[i] + q[l].c[j], q[l].id[j], p[r].id[i]));
				break;
			}
		}
	}
}
void update(int x, int val, int c = 1, int b = 1, int e = n) {
	if(b == e) {
		p[c].id[0] = p[c].id[1] = val;
		p[c].c[0] = D*b + a[b];
		p[c].c[1] = inf;

		q[c].id[0] = q[c].id[1] = val;
		q[c].c[0] = -D*b + a[b];
		q[c].c[1] = inf;
		return ;
	}
	int m = (b + e) >> 1;
	int l = c << 1;
	int r = l + 1;
	if(x <= m) {
		update(x, val, l, b, m);
	} else {
		update(x, val, r, m+1, e);
	}
	p[c].merge(p[l], p[r]);
	q[c].merge(q[l], q[r]);
	ans[c] = min(ans[l], ans[r]);
	for(int i = 0; i < 2; i++) {
		for(int j = 0; j < 2; j++) {
			if(p[r].id[i] != q[l].id[j]) {
				ans[c] = min(ans[c], info(p[r].c[i] + q[l].c[j], q[l].id[j], p[r].id[i]));
				break;
			}
		}
	}
}

int par[200010];
vector <int> v[200010];
int root(int x) {
	if(par[x] == x) return x;
	return par[x] = root(par[x]);
}
void join(int p, int q) {
	p = root(p);
	q = root(q);
	if(v[p].size() > v[q].size()) swap(p, q);
	for(auto i : v[p]) {
		v[q].emplace_back(i);
		update(i, q);
	}
	par[p] = q; 
	v[p].clear();
} 

int main(int argc, char const *argv[])
{
	scanf("%d %lld", &n, &D);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		par[i] = i;
		v[i].emplace_back(i);
	}
	build();

	long long res = 0;
	for(int i = 1; i < n; i++) {
		int x = ans[1].i;
		int y = ans[1].j;
		res += ans[1].val;
		join(x, y);
	}

	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 59384
#include <bits/stdc++.h>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod = 1e9 + 7;

ll H,W, A[100000], B[100000];
int a, b;
ll res;
vector<lP> p;

int main(){
	cin >> H >> W;
	a = H; b = W;
	for (int i = 0; i != H; ++i) {
		cin >> A[i];
		p.push_back(mkp(A[i], i));
	}
	for (int i = 0; i != W; ++i) {
		cin >> B[i];
		p.push_back(mkp(B[i], i + H));
	}
	sort(p.begin(), p.end());
	for (int i = 0; i != H+W; ++i) {
		if (p[i].second < H) {
			--a;
			res += p[i].first*b;
		}
		else {
			--b;
			res += p[i].first*a;
		}
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 8024
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=1e5+19;

ll A[N],B[N],tmp;
int n;

int main(){
	n=IN();
	For(i,1,n+1){
		A[i]=IN(),B[i]=IN();
	}
	for (int i=n;i;i--){
		A[i]+=tmp;
		if (A[i]%B[i]!=0) tmp+=B[i]-A[i]%B[i];
	}
	cout<<tmp<<endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
int main(void){
    long int  max, min, n, i;
    long int sum = 0;
    scanf("%d\n", &n);
    int num[n];
    for(i = 0; i < n; i++){
        scanf("%d", &num[i]);
        sum = sum + num[i];
    }

    max = num[0];
    for(i = 0; i < n; i++){
        if(num[i] > max)
            max = num[i];
    }
    
    min = num[0];
    for(i = 0; i < n; i++){
        if(num[i] < min)
            min = num[i];
    }
    
    printf("%ld %ld %ld\n", min, max, sum);
    return (0);
}


Measured memory_bytes: 2104
//
//  main.cpp
//  ABC154C
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(int argc, const char * argv[]) {
    int N;
    cin>>N;
    vector<int>A(N);
    for (int i=0; i<N; i++) {
        cin>>A.at(i);
    }
    sort(A.begin(),A.end());
    int tmp=0;
    for (int i=0; i<N-1; i++) {
        tmp=A.at(i);
        if (tmp==A.at(i+1)) {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}


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


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int F[110][10];
    int P[110][11];
    rep(i, N) {
        rep(j, 10) {
            cin >> F[i][j];
        }
    }
    rep(i, N) {
        rep(j, 11) {
            cin >> P[i][j];
        }
    }
    int all = (1 << 10);
    int ans = -INF;
    rep(i, all) {
        if (i == 0) continue;
        int tmp = 0;
        rep(j, N) {
            int bit = i;
            int cnt = 0;
            rep(k, 10) {
                if (bit % 2 && F[j][k])
                    cnt++;
                bit /= 2;
            }
            tmp += P[j][cnt];
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;


    return 0;
}


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

class Program
{
    static void Main(string[] args)
    {
        string s = Console.ReadLine();
        char[] array = s.ToCharArray();
        for(int i = 0; i < array.Length; i++)
        {
            array[i] = 'x';
        }
        s = new string(array);
        Console.WriteLine(s);
    }

}


Measured memory_bytes: 11092
#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<queue>

using namespace std;

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

int main()
{
	string s;
	cin>>s;
	
	bool ok = false;
	rep(i,s.size()-1)if(s[i]=='A' && s[i+1]=='C')ok=true;
	
	if(ok)puts("Yes");
	else puts("No");
	
}

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

#define mem(a,b) memset(a, b, sizeof a)

int a[100005][4];
int dp[100005][4];
int n;
int solve(int day, int col)
{
	if (day == n)
		return 0;

	if (dp[day][col] != -1)
		return dp[day][col];

	int mx = 0;
	if (col == 0) {
		mx = max(mx, a[day][1] + solve(day + 1, 1));
		mx = max(mx, a[day][2] + solve(day + 1, 2));
		mx = max(mx, a[day][3] + solve(day + 1, 3));
	}
	else if (col == 1) {
		mx = max(mx, a[day][2] + solve(day + 1, 2));
		mx = max(mx, a[day][3] + solve(day + 1, 3));
	}
	else if (col == 2) {
		mx = max(mx, a[day][1] + solve(day + 1, 1));
		mx = max(mx, a[day][3] + solve(day + 1, 3));
	}
	else {
		mx = max(mx, a[day][1] + solve(day + 1, 1));
		mx = max(mx, a[day][2] + solve(day + 1, 2));
	}

	dp[day][col] = mx;
	return mx;
}
int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	//FUCK RATINGS
	//Once a CHARAS, always a CHARAS


	//int t; cin>>t;
	//while(t--){
	//}
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= 3; j++) {
			cin >> a[i][j];
		}
	}
	mem(dp, -1);
	cout << solve(0, 0);


	return 0;
}

Measured memory_bytes: 17712
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    ll ans = 0;
    ll dp[3][200000] ={};
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];
	dp[0][0] = a[0];	dp[0][1] = 0;		dp[0][2] = a[0]+a[2];
	dp[1][0] = 0; 		dp[1][1] = a[1]; 	dp[1][2] = 0;
	dp[2][0] = 0;		dp[2][1] = 0; 		dp[2][2] = a[2];
	for(int i = 3; i <= n-1; i++){
		if(i % 2 == 1){
			dp[0][i] = 0;
			dp[1][i] = max(dp[1][i-2]+a[i], dp[0][i-3]+a[i]);
			dp[2][i] = 0;
		} 
		else
		{
			dp[0][i] = dp[0][i-2] + a[i];
			dp[1][i] = 0;
			dp[2][i] = max(dp[0][i-4]+a[i],  max(dp[1][i-3]+a[i], dp[2][i-2]+a[i]));
		}
	}
	if(n%2==0) cout << max(dp[0][n-2], dp[1][n-1]) << endl;
	else cout << max(dp[0][n-3], max(dp[1][n-2], dp[2][n-1])) << endl;
}

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

using namespace std;

typedef long long int ll;
typedef vector<ll> V;
typedef vector<V> VV;

int main() {
  // Happy hacking!
  ll n, k;
  string s;

  cin >> n >> k;
  cin >> s;

  s[k-1] = s[k-1] + ('a' - 'A');

  cout << s << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] n = new int[N];
        for(int i = 0; i < N; i++){
          n[i] = sc.nextInt();
        }
      
        int kisuu = 1;
        for(int i = 0; i < N; i++){
          int temp = 0;
          if((n[i]-1)%2 != 0){
            temp++;
          }
          if(n[i]%2 != 0){
            temp++;
          }
          if((n[i]+1)%2 != 0){
            temp++;
          }
          kisuu *= temp;
          
        }
      
       System.out.println((int)Math.pow(3,N)-kisuu);
	}
}

Measured memory_bytes: 35720
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
    int a[5];
    int min = 200;
    int min_index = 200;
    for(int i=0; i<5; i++){
        cin >> a[i];
        if(min > a[i]%10 && a[i]%10 != 0){
            min = a[i]%10;
            min_index = i;
        }
    }

    int ans = 0;
    for(int i=0; i<5; i++){
        if(i == min_index) continue;
        if(a[i]%10==0){
            ans += a[i];
        }else{
            ans += a[i] + 10 - a[i]%10;
        }
    }
    ans += a[min_index];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
class Main{
	/**
	*??°?????????????????????
	*/
	public static void main(String[] args) throws IOException{ //try????????\????????????
		BufferedReader br =
				new BufferedReader(new InputStreamReader(System.in)); //?¨??????\???
		String str = br.readLine();
		int count = 1;   //???????????°
		while(!str.equals("0")){   //????????\?????????????????????
				System.out.println("Case " + count + ": " + str);  //"Case ????????\?????°???"?????¢?????§??????
				count++;    
				str = br.readLine();
		}
	}
}
		

Measured memory_bytes: 31836
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
//#include <boost/multiprecision/cpp_int.hpp>



using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const double EPS = 1e-10;
long long const MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}


int main(void) {
    Int N; cin >> N;
    if (N == 1) cout << 0 << endl;
    else cout << (N*(N-1))/2 << endl; 
}


Measured memory_bytes: 888
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll k, a, b;
	cin >> k >> a >> b;
	if(a >= b-2){
		cout << k+1 << endl;
		return 0;
	}
	ll ans = a;
	k -= a-1;
	ll cnt = k/2;
	ans += cnt * (b - a);
	k %= 2;
	ans += k;
	cout << ans << endl;
	return 0;
}


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

#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
using namespace std;
typedef long long ll;

char b;

int main() {
	cin >> b;
	if (b == 'A')b = 'T';
	else if (b == 'T')b = 'A';
	else if (b == 'C')b = 'G';
	else b = 'C';
	cout << b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653
#define INF 100000000000000

int main(){
    double a, b, h, m; cin >> a >> b >> h >> m;
    double pi = 3.141592653589793238;
    double x = (30*h-11*m/2)*pi/180;
    double ansp = a*a+b*b-2*a*b*cos(x);
    cout << setprecision(10) <<sqrt(ansp) << endl;
}

Measured memory_bytes: 4228
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int N,K,S;cin>>N>>K>>S;
	int A[N];
    if(S<inf){
      rep(i,0,K) A[i]=S;
      rep(i,K,N) A[i]=inf;
    }else{
      rep(i,0,K) A[i]=inf;
      rep(i,K,N) A[i]=1;
    }
	print(A,N);
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s; cin >> s;
  deque<char> q;
  int n = s.size();
  rep(i, n) {
    if(s[i] == 'T' && !q.empty() && q.back() == 'S') {
      q.pop_back();
    } else {
      q.push_back(s[i]);
    }
  }
  cout << q.size() << endk;
  return 0;
}


Measured memory_bytes: 3792
#include<iostream>
#include<stdio.h>
using namespace std;
 
int main(){
int w,n,a,b,tmp;
char dummy;                //w:縦線 n:横線　それぞれの本数
 
cin >> w >> n;
 
int line[w];
for(int i=0;i<w;i++){
        line[i] = i + 1;
        }
 
 
 
while(cin >> a >>dummy >> b){
        tmp = line[a-1];
        line[a-1] = line[b-1];
        line[b-1] = tmp;
        }
 
for(int j=0;j<w;j++){
        cout << line[j] << endl;
        }
 
 
 
 
return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <stdio.h>
# include <string.h>
#include <string>
using namespace std;
typedef long long ll;
int main(void){
    char str [222];
    scanf ("%s", str ) ;
    int n= strlen (str );
    for(int i = n - 2; i; i-=2){
        int sp = i;
        if(sp % 2 == 0){
            if(strncmp(str, str+i/2, i/2) == 0){
                printf ("%d\n" ,i) ;
                return 0;
            }
        }
    }
    return 0;
}


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

int main() {
    string S;
    cin >> S;

    string ans = "AC";

    if (S[0]!='A'){
        ans = "WA";
    }

    int cnt = 0;
    for (int i = 2; i <= S.size()-1; i++){
        if (S[i]=='C'){
            cnt++;
        }
    }
    
    if (cnt!=1){
        ans = "WA";
    }

    for (int i = 1; i <= S.size(); i++){
        if (S[i]!='C'){
            if (isupper(S[i])){
                ans = "WA";
            }
        }
    }

    if (S[S.size()-1]=='C'){
        ans = "WA";
    }

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

Measured memory_bytes: 256
/*

*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/hash_policy.hpp>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
//#define int long long 
#define LL long long 
#define ull unsigned long long 
#define rg register 
#define pt(x) printf("%d ", x);
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 22)], *p1 = buf, *p2 = buf;
//char obuf[1<<24], *O = obuf;
//void print(int x) {if(x > 9) print(x / 10); *O++ = x % 10 + '0';}
//#define OS  *O++ = ' ';
using namespace std;
//using namespace __gnu_pbds;
const int MAXN = 501, INF = 1e9 + 10, mod = 1e9 + 7;
const double eps = 1e-9;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int N, M;
int a[MAXN][MAXN];
int xx[6] = {0, -1, +1, 0, 0};
int yy[6] = {0, 0, 0, -1, +1};
int ans[MAXN * MAXN][7], cnt = 0;
void add(int i, int j, int wx, int wy) {
	ans[++cnt][0] = i;
	ans[cnt][1] = j;
	ans[cnt][2] = wx;
	ans[cnt][3] = wy;	
}
main() {
	N = read(); M = read();
	for(int i = 1; i <= N; i++)
		for(int j = 1; j <= M; j++)
			a[i][j] = read();
	for(int i = 1; i < N; i++) {
		for(int j = 1; j <= M; j++) {
			if(a[i][j] & 1) {
				int wx = i + 1, wy = j;
				a[i][j]--; a[wx][wy]++;
				add(i, j, wx, wy);
			}
		}
	}
	for(int i = 1; i < M; i++) {
		if(a[N][i] & 1) {
			a[N][i]--; a[N][i + 1]++;
			add(N, i, N, i + 1);
		}
	}
	printf("%d\n", cnt);
	for(int i = 1; i <= cnt; i++) 
		printf("%d %d %d %d\n", ans[i][0], ans[i][1], ans[i][2], ans[i][3]);
    return 0;
}
/*
2 2 1
1 1
2 1 1
*/

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

int main()
{
    vector<string> s;
    string temp;
    int n, l;
    cin >> n >> l;

    while (n--)
    {
        cin >> temp;
        s.push_back(temp);
    }
    sort(s.begin(), s.end());
    for (auto x : s)
    {
        cout << x;
    }
    cout << endl;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0

for i in range(N):
    mons = a[i]
    hero = b[i]
    if hero <= mons:
        ans += hero
    else:
        ans += mons
        hero -= mons
        mons_next = a[i+1]
        if hero >= mons_next:
            ans += mons_next
            a[i+1] = 0
        else:
            ans += hero
            a[i+1] = mons_next - hero

print(ans)


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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define ws(x) cerr << #x << " is " << x << endl
#define pb push_back
#define ats(x) cout << x << "\n"
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef pair <int, int> pii;
typedef vector<pii> vii;
typedef tuple<int, int, int> tiii;

const int INF = INT_MAX;

int n, m;

vi adj[100001];
int dist[100001];
int prevv[100001];
bool used[100001];

void bfs(int x){
    for (int i = 1; i <= n; i++){
        dist[i] = INF;
        prevv[i] = -1;
    }
    dist[x] = 0;
    queue <int> q;
    q.push(x);
    while (!q.empty()){
        int a = q.front();
        q.pop();
        for (int b:adj[a]){
            if (dist[b] == INF){
                dist[b] = dist[a] + 1;
                prevv[b] = a;
                q.push(b);
            }
        }
    }
}


int main()
{
    FAST_IO;
    cin >> n >> m;
    for (int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        adj[b].pb(a);
        adj[a].pb(b);
    }
    for (int i = 1; i <= n; i++){
            dist[i] = INF;
            used[i] = false;
    }
    bfs(1);
    bool all = true;
    for (int i = 1; i <= n; i++){
        if (dist[i] == INF) all = false;
    }
    if (all){
        ats("Yes");
        for (int i = 2; i <= n; i++){
            ats(prevv[i]);
        }
    } else {
        ats("No");
    }
    return 0;
}



Measured memory_bytes: 11016
#include<stdio.h>
int main()
{ int N,M;
 int i,j;
 int count=0;
 scanf("%d%d",&N,&M);
 for(i=1;i<N;i++)
 { 
   for(j=i;j<N;j++)
  { 
     count++;
  }
 } 
  for(i=1;i<M;i++)
 { 
    for(j=i;j<M;j++)
  { 
    count++;
  }
 } 
 printf("%d",count);
 return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll n,m;

int main(){
    cin >> n >> m;
    vector<vector<ll> > v(m,vector<ll>());
    rep(i,m){
        ll k;
        cin >> k;
        rep(j,k){
            ll s;
            cin >> s;
            s--;
            v[i].push_back(s);
        }
    }
    vector<ll> p(m);
    rep(i,m)cin >> p[i];
    ll ans = 0;
    rep(i,(1LL << n)){
        // cout << "!!!" << endl;
        ll cnt = 0;
        rep(j,m){
            ll c = 0;
            rep(k,v[j].size()){
                if(i & (1LL << v[j][k]))c++;
            }
            if(c%2 == p[j])cnt++;
        }
        if(cnt == m)ans++;
    }
    cout << ans << endl;
}

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

int cmpnum(const void * n1, const void * n2)
{
	if (*(int *)n1 > *(int *)n2)
	{
		return 1;
	}
	else if (*(int *)n1 < *(int *)n2)
	{
		return -1;
	}
	else
	{
		return 0;
	}
}

int main(void){

  int n;
  scanf("%d", &n);
  n /= 2;
  int odd[n];
  int even[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &odd[i]);
    scanf("%d", &even[i]);
  }

  qsort(odd, n, sizeof(int), cmpnum);
  int max_odd_count = 1;
  int max_odd_number;
  int count = 1;
  for (int i = 1; i < n; i++) {
    if (odd[i] == odd[i-1]) {
      count++;
      if (count > max_odd_count) {
        max_odd_count = count;
        max_odd_number = i;
      }
    } else {
      count = 1;
    }
  }
  int second_odd_count = 1;
  int second_odd_number;
  count = 1;
  for (int i = 1; i < n; i++) {
    if (odd[i] == odd[i-1]) {
      count++;
      if (i != max_odd_number && count > second_odd_count) {
        second_odd_count = count;
        second_odd_number = i;
      }
    } else {
      count = 1;
    }
  }
  if (max_odd_count == n) {
    second_odd_count = 0;
  }

  qsort(even, n, sizeof(int), cmpnum);
  int max_even_count = 1;
  int max_even_number = 0;
  count = 1;
  for (int i = 1; i < n; i++) {
    if (even[i] == even[i-1]) {
      count++;
      if (count > max_even_count) {
        max_even_count = count;
        max_even_number = i;
      }
    } else {
      count = 1;
    }
  }
  int second_even_count = 1;
  int second_even_number;
  count = 1;
  for (int i = 1; i < n; i++) {
    if (even[i] == even[i-1]) {
      count++;
      if (i != max_even_number && count > second_even_count) {
        second_even_count = count;
        second_even_number = i;
      }
    } else {
      count = 1;
    }
  }
  if (max_even_count == n) {
    second_even_count = 0;
  }

  int answer;
  int case2;
  if (odd[max_odd_number] != even[max_even_number]) {
    answer = n*2-max_odd_count-max_even_count;
  } else {
    answer = n*2-max_odd_count-second_even_count;
    case2 = n*2-second_odd_count-max_even_count;
    if (case2 < answer) {
      answer = case2;
    }
  }
  printf("%d\n", answer);

  return 0;
}

Measured memory_bytes: 792
#include<bits/stdc++.h>
using namespace std;
int main(){
    long int l,r;
    cin >> l >> r;
    long int min=10000000;
    for(long int i=l;i<r&&i<l+2019;i++){
        for(long int j=i+1;j<=r&&j<l+2019;j++){
            long int now=(i*j)%2019;
            if(min>now)min=now;
        }
    }
    cout << min;
}

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

int main(){
  string s;
  cin>>s;
  for(bool cat=true;cat;){
    cat=false;
    for(int i=0;i<s.size();i++){
      if(s.substr(i,3)=="mew") s.erase(i,3);
      else if(s.substr(i,4)=="mcew"||s.substr(i,4)=="mecw") s.erase(i,4);
      else if(s.substr(i,5)=="mcecw") s.erase(i,5);
      else continue;
      s.insert(i,"c"); cat=true;
    }
  }
  cout<<((s=="c")?"Cat":"Rabbit")<<endl;
}


Measured memory_bytes: 1224
n,*bb = map(int, open(0).read().split())

ans = []

while bb:
    imp = True
    for i,v in zip(range(len(bb),0,-1),bb[::-1]):
#         print(i,v)
        if i==v:
            ans.append(v)
            del bb[i-1]
            imp = False
            break
    if imp:
        ans = [-1]
        break

for a in ans[::-1]:
    print(a)

Measured memory_bytes: 64120
N = int(input())
s = list(input())

def judge() :
    # 最初の2個を決めれば良い
    for comb in (('S', 'S'), ('S', 'W'), ('W', 'S'), ('W', 'W')) :
        t = [None] * N
        t[0], t[1] = comb
            
        for i in range(1, N - 1) :
            if (s[i] == 'o') == (t[i] == 'S') :
                t[i + 1] = t[i - 1]
            else :
                t[i + 1] = 'S' if t[i - 1] == 'W' else 'W' 
        
        con1 = ((s[0] == 'o') == (t[0] == 'S')) == (t[N-1] == t[1])
        con2 = ((s[N - 1] == 'o') == (t[N - 1] == 'S')) == (t[N-2] == t[0])
        if con1 and con2 :
            return ''.join(t)
        
    return -1

print(judge())

Measured memory_bytes: 50160
from itertools import accumulate
n, *AB = map(int, open(0).read().split())
A, B = AB[:n], AB[n:]
P = []
N = []
for a, b in zip(A, B):
    if b-a > 0:
        P.append(b-a)
    elif b-a < 0:
        N.append(a-b)
N.sort(reverse=1)
s = sum(P)
if s == 0:
    print(0)
else:
    for i, x in enumerate(accumulate(N), 1):
        if x >= s:
            print(len(P) + i)
            break
    else:
        print(-1)

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

int main() {
  int n, x;
  cin >> n;
  for (int i = n; i; i /= 10) {
    x += i % 10;
  }
  if (n % x == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <functional>
#include <math.h>
#include <string.h>

using std::endl;

#define ll long long int
#define LEP(a, n) for(int a = 0; a < n; ++a)
#define INF 1145141919810
#define OUT std::cout
#define IN std::cin
#define itn int
#define fro for
#define sdt std

int X, A, B;

int main()
{
	IN >> X >> A >> B;

	X -= A;
	X -= (X / B) * B;

	printf("%d\n", X);



	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long INF=1LL<<60;
//set<int>::iterator it;

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	
	int n,i,d,s=0;
	cin>>n;
	d=n;
	while(d>0){
		s+=d%10;
		d/=10;
	}
//	cout<<s<<endl;
	if(n%s==0)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
    int n,a,b;
    scanf("%d%d%d",&n,&a,&b);
    int res=0;
    for(int i=1;i<=n;i++)
    {
        int k=i,num=0;
        while(k>0)
        {
            num+=k%10;
            k/=10;
        }
        if(a<=num&&num<=b)
        res+=i;
    }
    printf("%d\n",res);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
double goa(double xh,double yh,double xc,double yc){
double X=xc-xh;double Y=yc-yh;double a;
a=sqrt((xc-xh)*(xc-xh)+(yc-yh)*(yc-yh));
return a;
}
double mense(double a,double b,double c){
double z;double S;
z=(a+b+c)*0.5;
S=sqrt(z*(z-a)*(z-b)*(z-c));
return S;
}

int main(){
double x,y,xh,yh,xc,yc,a=0,b=0,c=0,d=0,S=0,s=0;
//cin>>xh>>yh;
//cin>>xc>>yc;
scanf("%lf,%lf",&xh,&yh);
scanf("%lf,%lf",&xc,&yc);
scanf("%lf,%lf",&x,&y);

//cin>>x>>y;
a=goa(xh,yh,xc,yc);
b=goa(xc,yc,x,y);
c=goa(xh,yh,x,y);
S+=mense(a,b,c);
//cout<<a<<" "<<b<<" "<<c<<endl;
xc=x;yc=y;
while(scanf("%lf,%lf",&x,&y)!=EOF){
	a=goa(xh,yh,xc,yc);
b=goa(xc,yc,x,y);
c=goa(xh,yh,x,y);
S+=mense(a,b,c);
xc=x;yc=y;
	
	/*
goa(xh,yh,x,y,a);
goa(xc,yc,x,y,b);
goa(xh,yh,x,y,c);
S+=mense(a,b,c);
xc=x;yc=y;
*/
}
printf("%lf\n",S);
return 0;
}

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

using namespace std;

int main(){
    int n;
    int dansuu = 1;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n ; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    for(int j =0; j < n;j++){
        if(a[j] < a[j+1]){
            dansuu = dansuu + 1;
        }
    }
    cout << dansuu << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)
#define INF 1<<29;

int main()
{
    int n,m;
    cin >> n >> m;
    vector<int> x(m);
    rep(i,m) cin >> x[i];

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

    vector<int> len(m-1);
    i64 sum_len = 0;
    rep(i,m-1)
    {
        len[i] = x[i+1]-x[i];
        sum_len += len[i];
    }

    sort(len.begin(),len.end(),greater<int>());

    rep(i,min(n-1,m-1))
    {
        sum_len -= len[i];
    }

    cout << sum_len << endl;
    return 0;
}

Measured memory_bytes: 1024