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

#define ll long long
#define endl '\n'

using namespace std;

int main (){
	//freopen("input.txt", "r", stdin);

	int n;
	cin>>n;
	bool flag = 0;

	while(n){
		int r = n%10;
		if(r == 7){
			flag = 1;
			break;
		}
		n = n/10;
	}

	if(flag) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>

using namespace std;
int main(){
  int A,B;
  cin>>A>>B;
  int a=0;
  for(int i=0;i<2;i++){
      if(A>=B){
          a+=A;
          A=A-1;
      }else{
          a+=B;
          B=B-1;
      }
  }
  cout<<a<<endl;
    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>  
using namespace std;  int main() {   ios::sync_with_stdio(false);   cin.tie(0);   int n;   cin >> n;   vector<int> a(n);  for (int i = 0; i < n; i++) {   cin >> a[i];  }  sort(a.begin(), a.end());  int ans = 0;  vector<int> v;  v.push_back(a[0] + a[1]);  for (int i = 2; i < n; i++) {   for (int k : v) {    ans += (a[i] < k);   }   for (int j = 0; j < i; j++) {    v.push_back(a[i] + a[j]);   }  }  cout << ans << '\n';   return 0; }


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

int roundUp(int numer,int denom){
    int n = numer/denom;
    if(numer%denom!=0)n++;
    return n;
}
int main(int argc, const char * argv[]) {
    int N;
    cin >> N;
    int T[N],A[N];
    for(int i=0;i<N;i++){
        cin >> T[i] >> A[i];
    }
    
    long long ans = 0;
    long long t=T[0],a=A[0];
    

    for(int i=1;i<N;i++){
//        int hi = T[i]/t; int hu = A[i]/a;
//        int multiVal = min(hi,hu);
        long long nVal = max((t%T[i]==0) ? t/T[i] : t/T[i]+1, (a%A[i]==0) ? a/A[i] : a/A[i]+1);
        t = nVal*T[i];
        a = nVal*A[i];
    }
    ans = t+a;
    
    cout << ans << endl;
    return 0;
}


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

int main(){
 int N; 
 int a;
 int x = 0, y = 0, z=0;
  
 cin >> N;

 for(int i = 0; i < N ; i++){
   cin >> a;
   
   if( a % 4 == 0){
     x++;
   }
   else if( a % 2 == 0){
     y++;
   }
   else if( a % 4 != 0){
     z++;
   }

 }
 
 if( y > 0) z++;
  
 if( x >= z -1 ) cout << "Yes" << endl;
 else cout << "No" << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main  ()
{
    int n;cin>>n;int a[n + 5];
    int pos = 1;
    vector<int>v;
    for(int i = 0; i<n; i++)
    {
        cin>>a[i];
        if(pos == a[i])
        {
            v.push_back(pos);
            pos++;
        }
    }
    if(!(int)v.size())cout<<-1<<endl;
    else cout<<n - (int)v.size()<<endl;
    return 0;
}


Measured memory_bytes: 1912
def digits(n):
    if n < 10: return 1
    c = 0
    while n > 0:
        c += 1
        n = n // 10

    return c

n = int(input())
for i in range(n):
    u = int(input())
    v = int(input())
    s = u + v
    if (digits(u) > 80 or digits(v) > 80 or digits(s) > 80):
        print("overflow")
    else:
        print(s)

Measured memory_bytes: 6720
n = int(input())
alis = list(map(int,input().split()))
blis = list(map(int,input().split()))
clis = list(map(int,input().split()))

sum = 0
for i in range(n):
    sum += blis[alis[i]-1]
    if i != 0:
        if alis[i] == alis[i-1] +1:
            sum += clis[alis[i-1]-1]
print(sum)


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

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    int dx = tx - sx, dy = ty - sy;

    cout << string(dy, 'U') << string(dx, 'R');
    cout << string(dy, 'D') << string(dx, 'L');
    cout << 'L' << string(dy + 1, 'U') << string(dx + 1, 'R') << 'D';
    cout << 'R' << string(dy + 1, 'D') << string(dx + 1, 'L') << 'U';
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define NewNode (ListNode *)malloc(sizeof(ListNode))
#define Mem(a,b) memset(a,b,sizeof(a))
const int N = 3e5 + 5;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-10;
const unsigned long long mod = 998244353;
const int II = 3.1415926535;
typedef long long ll;
typedef unsigned long long ull;
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int a,b,c,d,i;
    cin >> a >> b >> c >> d;
    for(i = 0;;i++)
    {
        if(i % 2 == 0) c -= b;
        else a -= d;
        if(a <= 0 || c <= 0) break;
    }
    i % 2 == 0 ? cout << "Yes" << endl : cout << "No" << endl;
}


Measured memory_bytes: 3640
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <cinttypes>
#include <string.h>
#include <bits/stdc++.h>

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define pi pair<int,int>
#define fi first
#define se second

#define FOR(var, to)          for (register s64 var = 0; var < (s64)to; var++)
#define FROMTO(var, from, to) for (register s64 var = from; var <= (s64)to; var++)

#define INIT(var) FOR(i,countof(var)) var[i] = 0
#define INPUT(var) FOR(i,countof(var)) var[i] = ri()

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)

#define MOD 1000000007
#define INF (1 << 30)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

using namespace std;

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

static inline s64 rs64() {
  s64 a;
  scanf("%" SCNd64, &a);
  return a;
}

static inline void wi(int a) {
  printf("%d", a);
}

static inline void wu64(u64 a) {
  printf("%" PRIu64, a);
}

static inline void ws64(s64 a) {
  printf("%" PRId64, a);
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

int main() {
    int a = ri();
    int b = ri();
    int c = ri();
    int k = ri();
    int m = max(max(a,b),c);
    int mm = a+b+c-m;
    FOR(i,k) m*=2;
    cout << m+mm << endl;
 return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
    	long X, Y;
    	
        void solve(InputReader in, PrintWriter out) {
        	X = in.nextLong();
        	Y = in.nextLong();
        	
        	if (Math.abs(X - Y) < 2) out.println("Brown");
        	else out.println("Alice");
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int size) {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        long[] nextLongArray(int size) {
            long[] arr = new long[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }
    }
}


Measured memory_bytes: 22484
import sys
input=sys.stdin.readline
n,m,l=map(int,input().split())
INF=10**10
graph=[[INF for i in range(n)] for j in range(n)]
fuel=[[INF for i in range(n)] for j in range(n)]
for i in range(n):
    graph[i][i]=0
for i in range(m):
    a,b,c=map(int,input().split())
    a-=1;b-=1
    if c>l:continue
    graph[a][b],graph[b][a]=c,c
for i in range(n):
  for j in range(n):
    for k in range(n):
      graph[j][k]=min(graph[j][k],graph[j][i]+graph[i][k])
for i in range(n):
    for j in range(n):
        if graph[i][j]<=l:
            fuel[i][j]=1
for i in range(n):
  for j in range(n):
    for k in range(n):
      fuel[j][k]=min(fuel[j][k],fuel[j][i]+fuel[i][k])
q=int(input())
for i in range(q):
    s,t=map(int,input().split())
    s-=1;t-=1
    if fuel[s][t]==INF:print(-1)
    else:print(fuel[s][t]-1)


Measured memory_bytes: 56796
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,i,m,c=0;
cin>>n;
int a[n];
for(i=0;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n);
m=a[0];
for(i=1;i<n;i++)
{
if(m==a[i])
{
c=1;
break;	
}	
else
m=a[i];	
	
}
if(c==0)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;


}


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

int main(){
    int n;
    string s;
    cin >> n >> s;
    ll r_count = 0, g_count = 0, b_count = 0;
    for (int i = 0; i < n; ++i){
        if(s.at(i) == 'R') r_count++;
        else if(s.at(i) == 'G') g_count++;
        else if(s.at(i) == 'B') b_count++;
    }

    ll out_count = 0;   // (Si != Sj != Sk)を満たしつつ(j-i != k-j)を満たさないもの
    for(int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (i - j < 0 || i + j > n - 1) break;
            else if (s.at(i - j) != s.at(i) && s.at(i) != s.at(i + j) &&
                     s.at(i - j) != s.at(i + j)) {    // Si = s.at(i-j), Sj = s.at(i), Sk = s.at(i+j)
                out_count++;
            }
        }
    }
    ll ans = (r_count * g_count * b_count) - out_count; // (Si != Sj != Sk)を満たす → (nCr_count * nCg_count * nCb_count)

    cout << ans <<endl;

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    vector<int> ans;
    stack<int> stk;
    int v;
    while(cin>>v){
        if(v==0){
            ans.pb(stk.top());
            stk.pop();
        }else{
            stk.push(v);
        }
    }
    rep(i,ans.size()){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3140
n = int(input())
s = sorted([input() for x in range(n)], key=lambda x: len(x))
head = s[0]
tail = list(map(list, s[1:]))
result = []
for h in head:
    for t in tail:
        if h not in t:
            break
    else:
        result.append(h)
        for t in tail:
            t.remove(h)
print("".join(sorted(result)))


Measured memory_bytes: 3316
#include<stdio.h>
int main()
{
  int K;
  scanf("%d", &K);
  
  if(K%2==0)
  {
    printf("%d", K*K/4);
  }
  
  else
  {
    printf("%d", ((K-1)/2)*((K+1)/2));
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <cstring>

#define pb push_back
#define mp make_pair

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef long long ll;

int main() {
  int n, d;

  cin >> n >> d;

  double m[11][11];
  memset(m, 0, sizeof m);

  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < d; ++j) {
      double k;
      cin >> k;

      m[i][j] = k;
    }
  }

  int count = 0;
  for (int i = 1; i < n; ++i) {
    for (int j = i+1; j <= n; ++j) {
      double sum = 0;
      for (int dim = 0; dim < d; ++dim) {
        sum += (m[i][dim]-m[j][dim])*(m[i][dim]-m[j][dim]);
      }
      int r = (int)sqrt(sum);
      if (r*r == (int)sum) {
        count++;
      }
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
	int n,m;
	cin >> n >> m;
	cout << pow(2, m) * (1900 * m + 100 * (n - m)) << endl;
}

Measured memory_bytes: 256
#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 main() {
    int a, b, c;
    cin >> a >> b >> c;
    set<int> st;
    st.insert(a);
    st.insert(b);
    st.insert(c);
    if (st.size() == 2) {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}

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

#include <bits/stdc++.h>

using namespace std;

class B81 {
public:
    void solve(std::istream &in, std::ostream &out) {
        int n;
        in >> n;
        bool res = false;
        for (int i = 1; i < 10; i++) {
            for (int j = 1; j < 10; j++) {
                if (i * j == n) {
                    res = true;
                }
            }
        }
        out << (res ? "Yes" : "No") << "\n";
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    B81 solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


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

int main(){
	while(1){
		string s;
		int m;
		
		cin >> s;
		if(s == "-") break;
		cin >> m;
		for(int i=0; i<m; ++i){
			int a;
			cin >> a;
			
			string add = s.substr(0,a);
			s = s+add;
			s = s.substr(a, s.size());
		}
		
		cout << s << endl;
	}
	return 0;
}



Measured memory_bytes: 3164
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <sstream>
#include <queue>
using namespace std;
using ll = long long;

class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};

void dfs(int idx, vector<int>& depth, vector<int>& as) {
  if (depth[idx] >= 0) return;
  dfs(as[idx], depth, as);
  depth[idx] = depth[as[idx]] + 1;
}

int main() {
  int N, K;
  while (scanf("%d%d", &N, &K) != EOF) {
    vector<int> as(N);
    vector<vector<int>> children(N);
    for (int i : range(N)) {
      scanf("%d", &as[i]);
      as[i]--;

      if (i > 0) children[as[i]].push_back(i);
    }

    int res = 0;
    if (as[0] != 0) {
      res++;
    }

    vector<int> depth(N, -1);
    depth[0] = 0;
    for (int idx : range(N)) dfs(idx, depth, as);

    priority_queue<pair<int, int>> q; // <depth, idx>
    for (int i : range(N)) {
      if (depth[i] > K) q.push({depth[i], i});
    }

    vector<char> removed(N);
    while (!q.empty()) {
      int idx = q.top().second;
      q.pop();
      if (removed[idx]) continue;

      for (int iter : range(K - 1)) {
        idx = as[idx];
      }

      queue<int> q2;
      q2.push(idx);
      while (!q2.empty()) {
        int now = q2.front();
        q2.pop();
        if (removed[now]) continue;
        removed[now] = 1;
        for (int ch : children[now]) {
          q2.push(ch);
        }
      }

      res++;
    }

    printf("%d\n", res);
  }
}


Measured memory_bytes: 10744
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
const int oo = 1e6;
bool sortbysec(const pair<int, int>& a,
	const pair<int, int>& b)
{
	return (a.second < b.second);
}
int main() {
	string a, b, c;
	cin >> a >> b >> c;
	char trans = 'A' - 'a';
	
	cout << char(a[0] + trans) << char(b[0] + trans) << char(c[0] + trans);

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct edge
{
	int v,nxt;
}e[5000];
int head[2005],tot=0,n,k,ans,tmp;
void add(int a,int b)
{
	tot++;
	e[tot].v=b;
	e[tot].nxt=head[a];
	head[a]=tot;
}
void dfs(int x,int fa,int dep)
{
	if (dep>k/2) tmp++;
	for (int i=head[x];i!=-1;i=e[i].nxt) if (e[i].v!=fa) dfs(e[i].v,x,dep+1);
}
int main()
{
	memset(head,-1,sizeof(head));
	scanf("%d%d",&n,&k);
	for (int i=1;i<n;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		add(a,b);
		add(b,a);
	}
	if (k&1)
	{
		ans=n+1;
		for (int i=1;i<=tot;i+=2)
		{
			tmp=0;
			dfs(e[i].v,e[i+1].v,0);
			dfs(e[i+1].v,e[i].v,0);
			ans=min(ans,tmp);
		}
	}
	else
	{
		ans=n+1;
		for (int i=1;i<=n;i++)
		{
			tmp=0;
			dfs(i,0,0);
			ans=min(ans,tmp);
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 256
#include<stdio.h>

int selectionSort(int *, int);

main(){

  int n,i,num[100],c;

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++)
    scanf("%d",&num[i]);

  c = selectionSort(num, n);

  for(i = 0 ; i < n ; i++){
    printf("%d",num[i]);
    if(i!=n-1) printf(" ");
  }

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

  return 0;
}

int selectionSort(int *num, int n){

  int i,minj,j,tmp,count=0,flag;

  for(i = 0 ; i <= n-1 ; i++){
    flag = 0;
    minj = i;
    for(j = i ; j <= n-1 ; j++){
      if(num[j] < num[minj]){ 
	minj = j;
	flag = 1;
      }
    }
    tmp = num[i];
    num[i] = num[minj];
    num[minj] = tmp;
    
    if(flag==1) count++;
  }

  return count;

}

Measured memory_bytes: 604
#include<stdio.h>

int main(void){
    int a,n,i,min=1000000,max=-1000000;
    long int sum=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a);
        sum+=a;
        if(min>a)
            min=a;
        if(max<a)
            max=a;
    }
    printf("%d %d %ld\n",min,max,sum);
    return 0;
}


Measured memory_bytes: 2148
from bisect import bisect_right
import sys

readline = sys.stdin.readline
n, m = map(int, readline().split())
ken = [list() for _ in range(n)]
PY = []
for _ in range(m):
    p, y = map(int, readline().split())
    PY.append((p, y))
    ken[p-1].append(y)
for i in range(n):
    ken[i].sort()

for p, y in PY:
    print(str(p).zfill(6) + str(bisect_right(ken[p-1],y)).zfill(6)) 


Measured memory_bytes: 29564
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
using namespace std;
#define INF 0x3f3f3f3f
//#define INF 1100000000000000000LL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=1050;
//int arr[SIZE]={};
//ここまでテンプレ
int main(){
	vector<pint> vec;
	int W,H;
	cin>>W>>H;
	for(int i=0;i<W;i++){
		int p;
		cin>>p;
		vec.pb(mp(p,0));
	}
	for(int i=0;i<H;i++){
		int	q;
		cin>>q;
		vec.pb(mp(q,1));
	}
	sort(vec.begin(),vec.end());
	ll a=W+1,b=H+1;
	ll ans=0;
	for(pint now:vec){
		if(!now.second && b>0){
			ans+=b*now.first;
			a--;
		}
		else if(now.second && a>0){
			ans+=a*now.first;
			b--;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3444
import java.util.*;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int N = sc.nextInt();
    int[] num = new int[N];
    int count = 0;
    
    for(int i=0; i<N; i++){
        num[i] = sc.nextInt();
        H -= num[i];
    }
    //if(str.charAt(0) == str.charAt(1)){
    //}
    if(H<=0){
        System.out.println("Yes");
    }else{
        System.out.println("No");
    }
  }
}

Measured memory_bytes: 48292
#include"bits/stdc++.h"


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(int x = (l);x<=(u);x++)
#define RREP(x,l,u) for(int x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 5010;
const int mod = 1e9+7;
const int MAX = 1000000010;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int n,m;

ll A[maxn];

ll Ans[maxn][maxn],V[maxn][210];

int Q[maxn],bot;

int l[maxn],r[maxn];

void Work(){
	REP(j,1,m){
		bot=0;Q[0]=0;
		REP(i,1,n){
			while(bot&&V[Q[bot]][j]<V[i][j])bot--;
			l[i]=Q[bot];
			Q[++bot]=i;
		}
		bot=0;Q[0]=n+1;
		RREP(i,n,1){
			while(bot&&V[Q[bot]][j]<=V[i][j])bot--;
			r[i]=Q[bot];
			Q[++bot]=i;
		}
		REP(i,1,n){
			l[i]++;r[i]--;
			Ans[l[i]][i]+=V[i][j];Ans[l[i]][r[i]+1]-=V[i][j];
			Ans[i+1][i]-=V[i][j];Ans[i+1][r[i]+1]+=V[i][j];
		}
	}
	REP(i,1,n)REP(j,1,n)Ans[i][j]=Ans[i][j]+Ans[i-1][j]+Ans[i][j-1]-Ans[i-1][j-1];
	ll ans=0;
	REP(i,1,n)REP(j,i,n)ans=max(ans,Ans[i][j]-A[j]+A[i]);
	cout<<ans<<endl;
}

void Init(){
	read(n,m);
	REP(i,2,n)read(A[i]),A[i]+=A[i-1];
	REP(i,1,n)REP(j,1,m)read(V[i][j]);
}

int main(){
	Init();
	Work();
	return 0;
}


Measured memory_bytes: 204288
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.string;

immutable long MOD = 10^^9 + 7;

void main() {
    auto N = readln.chomp.to!long;
    auto S = readln.chomp;

    auto cnt = new long[](26);

    foreach (i; 0..N) {
        cnt[S[i] - 'a'] += 1;
    }

    long ans = 0;
    foreach (i; 0..N) {
        long tmp = 1;
        foreach (j; 0..26) if (cnt[j] && j != S[i] - 'a') tmp = tmp * (cnt[j] + 1) % MOD;
        ans += tmp;
        ans %= MOD;
        cnt[S[i] - 'a'] -= 1;
    }

    ans = (ans + MOD) % MOD;
    ans.writeln;
}

long powmod(long a, long x, long m) {
    long ret = 1;
    while (x) {
        if (x % 2) ret = ret * a % m;
        a = a * a % m;
        x /= 2;
    }
    return ret;
}


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

int main(){
	int n;
	scanf("%d",&n);
	int k[n];
	int p[n];
	for(int i=0;i<n;i++){
	scanf("%d%d",&k[i],&p[i]);
	if(k[i]%p[i]!=0){
	printf("%d\n",k[i]%p[i]);
	}else{
	printf("%d\n",p[i]);
	}
	}
	
}

Measured memory_bytes: 1192
N = int(input())
S = str(N)
K = len(S)

if K == 6:
  print(9+900+90000)
elif K == 5:
  print(9+900 + (N-10000+1))
elif K == 4:
  print(9+900)
elif K == 3:
  print(9 + (N-100+1))
elif K == 2:
  print(9)
else:
  print(N)

Measured memory_bytes: 3060
import sys
from collections import defaultdict, deque

def main():
    input = sys.stdin.readline
    N = int(input())
    d = defaultdict(list)
    for _ in range(N-1):
        u, v, w = map(int, input().split())
        d[u-1].append((v-1, w))
        d[v-1].append((u-1, w))

    dist = [0] * N
    q = deque()
    q.append((0, 0))
    visited = set()

    while len(q) > 0:
        q_ = deque()
        while len(q) > 0:
            node1, cost1 = q.popleft()

            dist[node1] = cost1
            visited.add(node1)

            for node2, cost2 in d[node1]:
                if node2 in visited:
                    continue

                q_.append((node2, cost1 + cost2))

        q = q_

    for d in dist:
        print(d % 2)


if __name__ == '__main__':
    main()

Measured memory_bytes: 112132
#include<bits/stdc++.h>
using namespace std;
int main(){
  long a,b,c;
  cin >> a >> b >> c;
  double ab = sqrt(a*b);
  if((c-a-b)*(c-a-b)>4*a*b && c-a-b>0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
n = int(input())
ls = [[] for i in range(n)]
for i in range(n):
    s = list(map(int,input().split()))
    for j in range(s[1]):
        ls[i].append(s[j+2])
ls2 = [[0 for i in range(n)] for i in range(n)]
for i in range(len(ls)):
    for j in range(len(ls[i])):
        ls2[i][ls[i][j]-1] += 1
    print(*ls2[i])


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

template <class T>
void chmin(T &a, T b) {if (a > b) a = b;}

int main(int argc, char **argv)
{
	ll N; cin >> N;
	vector<ll> TARGET(N); for (ll i = 0; i < 3; ++i) cin >> TARGET[i];
	vector<ll> L(N); for (ll i = 0; i < N; ++i) cin >> L[i];

	vector<ll> bits(3);

	ll res{1ll<<60};
	for (bits[0] = 1; bits[0] < (1 << N); ++bits[0])
	{
		for (bits[1] = 1; bits[1] < (1 << N); ++bits[1])
		{
			if (bits[0] & bits[1]) continue;
			for (bits[2] = 1; bits[2] < (1 << N); ++bits[2])
			{
				if (bits[1] & bits[2] || bits[0] & bits[2]) continue;

				vector<ll> sum_l(3, 0);
				ll num_l{0};
				for (ll l = 0; l < N; ++l)
				{
					for (ll i = 0; i < 3; ++i)
					{
						if (bits[i] & (1 << l))
						{
							sum_l[i] += L[l];
							++num_l;
						}
					}
				}

				ll tmp = (num_l - 3) * 10;
				for (ll i = 0; i < 3; ++i)
					tmp += abs(TARGET[i] - sum_l[i]);
				
				chmin(res, tmp);
				
			}
		}
	}
	std::cout << res << std::endl;
	
}


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

int main() {
  string s;
  cin >> s;
  set<char> c;
  for(auto i:s) {
    c.insert(i);
  }
  if(c.size()==2) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    string S;
    cin >> S;
    int ans = 0;
    for(int i = 0; i < 4; i++)
        if(S[i] == '+')
            ans++;
        else
            ans--;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,itit )  for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define mp make_pair
#define pb push_back
#define all(s) s.begin(),s.end()
#define present(c,x) ((c).find(x) != (c).end())
const double EPS = 1e-8;
const int mod = 1e9+7;
const int N = 1e6+10;
const ll INF = 1e18;

//#define DEBUG
ll power(ll x,ll y){
  ll t=1;
  while(y>0){
    if(y%2) y-=1,t=t*x%mod;
    else y/=2,x=x*x%mod;
  }
  return t;
}
#ifdef DEBUG
#define dprintf(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#else
#define dprintf(fmt,...)
#endif

char s[5000];
int c[5000];
ll dp[3005][3005],nck[3005][3005];
int u[N];
ll solve(vector<pii> z){
  REP(i,z.size()+1) REP(j,3005) dp[i][j]=0;
  dp[0][c[z[0].Y]-c[z[0].X-1]]=1;
  ll ans=0;
  REP(i,z.size()) REP(j,3005) if(dp[i][j]){
    if(i+1==z.size()){
      ans+=nck[z[i].Y-z[i].X+1][j]*dp[i][j]%mod;
    }else{
      int ex=c[z[i+1].Y]-c[z[i].Y],zo=z[i].Y-z[i].X+1-j;
      REP(k,min(j,z[i+1].X-z[i].X)+1) if(z[i+1].X-z[i].X-k<=zo){
        dp[i+1][ex+j-k]+=nck[z[i+1].X-z[i].X][k]*dp[i][j]%mod;
        dp[i+1][ex+j-k]%=mod;
      }
    }
  }
  return ans%mod;
}
int main(){
  nck[0][0]=1;
  REPP(i,1,3005){
    nck[i][0]=1;
    REPP(j,1,i+1) nck[i][j]=(nck[i-1][j]+nck[i-1][j-1])%mod;
  }
  int n,m; scanf("%d%d%s",&n,&m,s);
  vector<pii> a,nw;
  ll ans=1;
  REP(i,n) c[i+1]=c[i]+(s[i]=='1');
  REP(i,m){
    pii x;
    scanf("%d%d",&x.X,&x.Y);
    a.pb(x);
  }
  sort(all(a));
  a.resize(unique(all(a))-a.begin());
  m=a.size();
  REP(i,m) REP(j,m) if(i!=j){
    if(a[i].X<=a[j].X&&a[j].Y<=a[i].Y) u[j]=1;
  }
  REP(i,m) if(!u[i]) nw.pb(a[i]);
  a=nw;
  int tl=0;
  while(tl<a.size()){
    vector<pii> cur; cur.pb(a[tl++]);
    while(tl<a.size()&&a[tl].X<=cur.back().Y) cur.pb(a[tl++]);
    ans=ans*solve(cur)%mod;
  }
  printf("%lld\n",ans);
  return 0;
}

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


int main(){
    int64_t N,a;
    bitset<30> sum,ans;
    cin >> N;
    vector<bitset<30>> bit(0);
    for(int64_t i = 0; i < N; i++){
        cin >> a;
        bitset<30> a_bit(a);
        bit.push_back(a_bit);
        sum = sum ^ a_bit;
    }
    for(int64_t i = 0; i < N; i++){
        ans = bit.at(i) ^ sum;
        if(i != N-1){
            cout << (int64_t)(ans.to_ulong()) << ' ';
        }else{
            cout << (int64_t)(ans.to_ulong()) << endl;
        }
    }
}

Measured memory_bytes: 5344
#include <iostream>
using namespace std;
int main(){
    int H,W;
    int i=0;
    while(1){
        cin>>H>>W;
        if(H==0&&W==0){
            break;
        }
        for(int n=1;n<=H;n++){
            for(int i=1;i<=W;i++){
                if(n==1){
                    cout<<"#";
                }
                 else if(n==H){
                    cout<<"#";
                }
                else{
                    if(i==1){
                        cout<<"#";
                    }
                    else if(i==W){
                        cout<<"#";
                    }
                    else{
                        cout<<".";
                    }
                }
            }
            cout<<endl;
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3064
n=int(input())
a=[int(j) for j in input().split()]
import collections
c=collections.Counter(a)
l=c.most_common()
ll=[]
for i,j in l:
    ll.append(i)
if sum(ll)==0:
    print("Yes")
    exit()
if 0 in ll:
    if len(l)==2:
        for i,j in l:
            if i==0:
                z=j
            else:
                t=j
        if 2*z==t:
            print("Yes")
            exit()
        else:
            print("No")
            exit()
    else:
        print("No")
        exit()

p=l[0][1]
q=[]
if len(l)==3:
    for i,j in l:
        if j==p:
            q.append(i)
        else:
            print("No")
            exit()
else:
    print("No")
    exit()
if q[0]^q[1]==q[2] and q[0]^q[2]==q[1] and q[2]^q[1]==q[0]:
    print("Yes")
else:
    print("No")







Measured memory_bytes: 16164
import sys
from collections import Counter
from collections import deque
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))
n=int(input())
a=mp()
l=[0]*(10**5+10)
for x in a:
    l[x]+=1
    l[x-1]+=1
    l[x+1]+=1
print(max(l))

Measured memory_bytes: 10996
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
using namespace std;
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;}
template <class T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007;
const ll MAX = 510000;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
    int a,b,c,k;
    vector<int> v(3);
    rep(i,3) {
        cin >> v[i];
    }
    cin >> k;
    sort(all(v));
    int sum = 0;
    sum = v[0] +v[1];
    sum += v[2]*pow(2,k);
    cout << sum << "\n";

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <sstream>

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)
#define rrep(i, a) RREP(i, a, 0)
#define RREP(i, a, b) for(int i = a; i >= b; --i)
#define repll(i, a) REPLL(i, 0, a)
#define REPLL(i, a, b) for(ll i = a; i < b; ++i)
#define rrepll(i, a) RREPLL(i, a, 0)
#define RREPLL(i, a, b) for(ll i = a; i >= b; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<int, P> PP;
const double PI = 3.14159265358979323846;
const double esp = 1e-9;
const int infi = (int)1e+9 + 10;
const ll infll = (ll)1e+18 + 10;

int n;
std::set<std::string> s;

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

	rep(i, n){
		char p[20], q[20];
		scanf("%s %s", &p, &q);
		if (p[0] == 'i')s.insert(q);
		else printf("%s\n", (s.find(q) != s.end() ? "yes" : "no"));
	}

	return 0;
}

Measured memory_bytes: 27056
// D - Various Sushi

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

pair<int, int> sushi[100000];

int main() {
	int N, K;
	cin >> N >> K;

	for (int i=0; i<N; i++) {
		int t, d;
		cin >> t >> d;
		sushi[i] = make_pair(d, t);
	}

	sort(sushi, sushi+N, greater<pair<int, int>>());

	ll score = 0;
	ll x = 0;
	stack<int> A;
	queue<int> B;
	unordered_map<int, int> cnt;

	for (int i=0; i<N; i++) {
		int t = sushi[i].second;
		int d = sushi[i].first;
		cnt[t]++;

		if (i < K) {
			score += d;
			if (cnt[t] == 1) x++;
			else A.push(d);
		} else {
			if (cnt[t] == 1) B.push(d);
		}
	}

	//cout << score << endl; // **** debug ****

	score += x * x;
	ll max_score = score;
	while(1) {
		//cout << max_score << endl; // **** debug ****
		if (A.empty() || B.empty()) break;

		score -= A.top();
		//cout << " - " << A.top() << endl; // **** debug ****
		A.pop();

		score += B.front();
		//cout << " + " << B.front() << endl; // **** debug ****
		B.pop();

		score -= x * x;
		//cout << " - " << x * x << endl; // **** debug ****
		x++;
		score += x * x;
		//cout << " + " << x * x << endl; // **** debug ****

		max_score = max(max_score, score);
	}

	cout << max_score << endl;

	return 0;
}

Measured memory_bytes: 8328
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

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


	int L;
	cin >> L;

	double are = 1.0 * L / 3;

	double kotae = are * are * are;

	cout << fixed << setprecision(12) << kotae;


	Would you please return 0;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main()
{
//    freopen("f.in","r",stdin);
//    freopen("f.out","w",stdout);
    int n,i,x,nr=0;
    scanf("%d",&n);
    for(i=1;i<=n;++i)
    {
        scanf("%d",&x);
        while(x%2==0)
        {
            nr++;
            x/=2;
        }
    }
    printf("%d\n",nr);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<map>
#include<set>
#define IOS ios::sync_with_stdio(false); cin.tie(0);
using namespace std;
typedef pair<string,int> PII;
typedef long long ll;
int a,b,c; 
int main(){
	IOS;
	cin>>a>>b>>c;
	if(a+b+c>=22) cout<<"bust"<<endl;
	else cout<<"win"<<endl;
	return 0;
}

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

template <class Abel>
struct WeightedUnionFind
{
  vector<int> par;
  vector<int> rank;
  vector<Abel> diff_weight;

  WeightedUnionFind(int n = 1, Abel SUM_UNITY = 0)
  {
    init(n, SUM_UNITY);
  }

  void init(int n = 1, Abel SUM_UNITY = 0)
  {
    par.resize(n);
    rank.resize(n);
    diff_weight.resize(n);
    for (int i = 0; i < n; ++i)
      par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
  }

  int root(int x)
  {
    if (par[x] == x)
    {
      return x;
    }
    else
    {
      int r = root(par[x]);
      diff_weight[x] += diff_weight[par[x]];
      return par[x] = r;
    }
  }

  Abel weight(int x)
  {
    root(x);
    return diff_weight[x];
  }

  bool issame(int x, int y)
  {
    return root(x) == root(y);
  }

  bool merge(int x, int y, Abel w)
  {
    w += weight(x);
    w -= weight(y);
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    if (rank[x] < rank[y])
      swap(x, y), w = -w;
    if (rank[x] == rank[y])
      ++rank[x];
    par[y] = x;
    diff_weight[y] = w;
    return true;
  }

  Abel diff(int x, int y)
  {
    return weight(y) - weight(x);
  }
};

int main()
{
  int N, M;
  cin >> N >> M;
  WeightedUnionFind<int> uf(N);
  for (int i = 0; i < M; i++)
  {
    int l, r, d;
    cin >> l >> r >> d;
    l--, r--;
    if (uf.issame(l, r))
    {
      int diff = uf.diff(l, r);
      if (diff != d)
      {
        cout << "No" << endl;
        return 0;
      }
    }
    else
    {
      uf.merge(l, r, d);
    }
  }
  cout << "Yes" << endl;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;



ll ans=0;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, m; cin>>n>>m;
	vll k(m);
	vll p(m);
	vector<vll> s(m);
	ll ans=0;

	rep(i, m){
		cin >> k[i];
		rep(j, k[i]){
			ll _s; cin>>_s;
			s[i].pb(_s-1);
		}
	}
	rep(i, m){
		cin >> p[i];
	}

	rep(i, (int)pow(2, n)){
		ll on=0;
		rep(j, m){
			ll cnt=0;
			for(auto e : s[j]){
				ll mask = 1 << e;
				if (i & mask) cnt++;
			}
			if (cnt % 2 == p[j]) on++;
		}
		if (on == m) ans++;
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

int main(){
	int n;
	scanf("%d", &n);
	vector<int> a(n);
	vector<int> a2(n);
	for(int i = 0; i < n; i++){
		int t;
		scanf("%d", &t);
		a[i] = a2[i] = t;
	}
	sort(a2.begin(), a2.end());
	map<int, int> m;
	for(int i = 0; i < n; i++){
		m[a2[i]] = i;
	}
	int ans = 0;
	for(int i = 0; i < n; i++){
		if(i % 2 != m[a[i]] % 2)
			ans++;
	}
	printf("%d\n", ans / 2);
	return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define ifaxb(a, x, b) if (a < x && x < b)  // 比較は昇順
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define all(x) x.begin(), x.end()
#define pi 3.1415926536
#define ff first
#define ss second
#define pq priority_queue
#define ipair pair<int, int>
#define spair pair<string, string>
#define lpair pair<LL, LL>
#define MP make_pair
#define INF 2147483647
#define _INF -2147483647
#define MM multimap
#define PB push_back
#define MAXN 100004
using namespace std;
typedef long long ll;

int main() {
    int n, k;
    string s;
    cin >> n >> k >> s;
    if (s[k - 1] == 'A') s[k - 1] = 'a';
    if (s[k - 1] == 'B') s[k - 1] = 'b';
    if (s[k - 1] == 'C') s[k - 1] = 'c';
    cout << s << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<climits>
#include<map>
#define ll long long
using namespace std;

int main() {
	string s;
	cin >> s;
	vector<char>x(s.size());
	for (ll i = 0; i < s.size();i++) {
		if (s[i] == '0') {
			x[i]='0';
		}
		else if (s[i] == '1') {
			x[i] = '1';
		}
		else {
			if (i > 0) {
				for (ll j = i-1; j >=0; j--) {
					if (x[j] != ' ') {
						x[j] = ' ';
						x[i] = ' ';
						break;
					}
				}
			}

			x[i] = ' ';
		}
	}
	for (ll i = 00; i < s.size(); i++) {
		if (x[i] != ' ') {
			cout << x[i];
		}
	}
	cout << endl;
}





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

int main() {
  int N,M;
  cin>>N>>M;
  vector <pair<ll,ll>> shops(N);
  for (int i(0);i<N;i++) cin>>shops[i].first>>shops[i].second;
  sort(shops.begin(),shops.end());
  ll sum(0),cnts(0);
  for (int i(0);i<N;i++){
    ll price=shops[i].first;
    ll cnt=shops[i].second;
    if (cnts+cnt<M){
      sum+=price*cnt;
      cnts+=cnt;
    }
    else {
      sum+=(M-cnts)*price;
      cout << sum <<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 1792
import collections

N = int(input())
A = list(map(int,input().split()))
a = collections.Counter(A)
v = a.values()
l_v = list(v)

#合計
s = 0
for i in range(len(l_v)):
    n = l_v[i]-1
    s += n*(n+1)//2
#カウント
for i in range(N):
    print(s-(a[A[i]]-1))


Measured memory_bytes: 25900
#include <bits/stdc++.h>
#define m 1000000007

using namespace std;

typedef long long int ll;

int gcd(int a, int b) { 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
}
 
int main(){
 
	int k;
	scanf("%d", &k);
	ll s = 0;
	for(int i = 1; i <= k; i++)
		for(int j = 1; j <= k; j++)
			for(int l = 1; l <= k; l++)
				s += gcd(gcd(i, j), l);
	printf("%lld", s);
	return 0;
}
 

Measured memory_bytes: 3828
n, m = map(int, input().split())
cnt = [[] for _ in range(n + 1)]
for i in range(m):
    p, y = map(int, input().split())
    cnt[p].append((y, i))
buf = [None] * m
for p, l in enumerate(cnt):
    if not l:
        continue
    l.sort()
    for j, (y, i) in enumerate(l):
        buf[i] = '{:06d}{:06d}'.format(p, j + 1)
print('\n'.join(buf))

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

int Vacation(vector<vector<int>>A,int n)
{
    vector<vector<int>>dp(n,vector<int>(3));
    int ans=INT_MIN;
    for(int i=0;i<n;i++)
    {
        
        for(int j=0;j<3;j++)
        {
            dp[i][j]=A[i][j];
            if(i-1>=0)
            {
                
                if(j==0)dp[i][j]+=max(dp[i-1][1],dp[i-1][2]);
                else if(j==1)dp[i][j]+=max(dp[i-1][0],dp[i-1][2]);
                else dp[i][j]+=max(dp[i-1][0],dp[i-1][1]);
               
            }// cout<<dp[i][j]<<" ";
        }//cout<<endl;
    }
    return max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
   
}

int main() {
	int n;
	cin>>n;
	vector<vector<int>> A(n,vector<int>(3));
	
	for(int i=0;i<n;i++)
	{
	    for(int j=0;j<3;j++)
	    {
	        cin>>A[i][j];
	    }
	}
	cout<<Vacation(A,n);
	return 0;
}

Measured memory_bytes: 16640
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  Scanner sc;

  int ex(int src, int ratio) {
    return (src * (100 + ratio))/100;
  }

  void run() {
    for (; ; ) {
      int h = ni();
      if(h==0) {
        break;
      }

      int[][] f = new int[h][5];
      for(int i = 0; i < h; ++i) {
        for(int j = 0; j < 5; ++j) {
          f[i][j] = ni();
        }
      }

      int score = 0;
      for(;;) {
        int cnt = 0;

        for(int i = 0; i < h; ++i) {
          for(int j = 0; j < 3; ++j) {
            int v = f[i][j];
            boolean flag = true;
            for(int k = 0; k < 3; ++k) {
              flag &= f[i][j + k] == v;
            }
            if(flag) {
              for(int k = j; k < 5; ++k) {
                if(f[i][k] != v) {
                  break;
                }
                cnt += v;
                for(int l = i; l > 0; --l) {
                  f[l][k] = f[l-1][k];
                }
                f[0][k] = 0;
              }
              break;
            }
          }
        }
        if(cnt == 0) {
          break;
        }
        score += cnt;
      }

      System.out.println(score);
    }
  }

  Main() {
    sc = new Scanner(System.in);
  }

  int ni() {
    return sc.nextInt();
  }

  public static void main(String[] args) {
    new Main().run();
  }

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
}

Measured memory_bytes: 48736
//temprates
#include <iostream>
#include <tuple>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

using ll = long long;
using namespace std;

#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define LFOR(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define FORR(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define LFORR(i,a,b) for(ll i = (int)(a); i >= (ll)(b); i--)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define LREP(i,n) LFOR(i,0,(ll)(n)-1)
#define REPR(i,n) FORR(i,(int)(n)-1,0)
#define LREPR(i,n) LFORR(i,(ll)(n)-1,0)

#define SIZ(v) int(v.size())
const int INF = 1e8;
const ll LINF = 1e15;
const int MOD = 1e9+7;

struct Work{
  ll a;
  ll b;
};
bool operator<(Work w1, Work w2){
  return w1.b < w2.b;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  vector<Work> tasks;
  bool ans=true;
  cin >> n; REP(i,n){
    ll a,b;
    cin>> a >> b;
    tasks.push_back(Work{a,b});
  }
  sort(tasks.begin(),tasks.end());
  ll t=0;
  for(int i=0;i<n;i++){
    if(t+tasks[i].a<=tasks[i].b){
      t += tasks[i].a;
    }
    else{ans=false;break;}
  }

  cout << ((ans)?"Yes":"No") << endl;

}


Measured memory_bytes: 6384