akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

int a[200010];
int ans[200010];

int main() {
    int n;cin>>n;
    rep(i,n) cin>>a[i+1];
    int m=0;
    for (int i = n;i>=1;i--) {
        int sum = 0;
        int tim = 2;
        while(i*tim<=n) {
            sum+=ans[i*tim];
            tim++;
        }
        if(sum%2 == a[i]%2) {
            ans[i]=0;
        } else {
            ans[i]=1;
            m++;
        }
    }
    cout<<m<<endl;
    rep(i,n) {
        if(ans[i+1]) cout<<i+1<<" ";
        if(i==n-1) cout<<endl;
    }
}

Measured memory_bytes: 5192
a = []
while True:
    b = map(int, raw_input().split())
    if b == [0, 0]:
        break
    a.append(b)
for list in a:
    h, w = list
    k = 0
    l = 0
    x = []
    while k < w:
        x.append('#')
        k = k + 1
    while l < h:
        print ''.join(x)
        l = l + 1
    print 

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

typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int dijkstra(int s, int g, int c, vector<vector<P>> &G){
    vector<vector<int>> dist(110, vector<int>(20, 1e9));
    priority_queue<T, vector<T>, greater<T>> que;
    dist[s][0] = 0;
    que.emplace(0, s, 0);

    while(!que.empty()){
        int ccost, cv, cused;
        tie(ccost, cv, cused) = que.top();
        que.pop();

        if(dist[cv][cused] < ccost) continue;

        for(auto x : G[cv]){
            int nv, ncost;
            tie(nv, ncost) = x;

            if(dist[cv][cused] + ncost < dist[nv][cused]){
                dist[nv][cused] = dist[cv][cused] + ncost;
                que.emplace(dist[nv][cused], nv, cused);
            }

            if(cused < c){
                if(dist[cv][cused] + ncost / 2 < dist[nv][cused+1]){
                    dist[nv][cused+1] = dist[cv][cused] + ncost / 2;
                    que.emplace(dist[nv][cused+1], nv, cused + 1);
                }
            }
        }
    }

    int ans = 1e9;
    for(int i=0; i<=c; i++){
        ans = min(ans, dist[g][i]);
    }

    return ans;
}

int main(){
    while(1){
        int c, n, m, s, d; cin>>c>>n>>m>>s>>d;
        s--, d--;
        if(c == 0) return 0;

        vector<vector<P>> G(n);
        for(int i=0; i<m; i++){
            int a, b, f; cin>>a>>b>>f;
            a--, b--;
            G[a].emplace_back(b, f);
            G[b].emplace_back(a, f);
        }

        cout << dijkstra(s, d, c, G) << endl;
    }
}


Measured memory_bytes: 3172
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

int N;
ll a[101010], b[101010];

int main() {
    cin >> N;
    for (int j = 0; j < N; ++j) { cin >> a[j]; }
    for (int j = 0; j < N; ++j) { cin >> b[j]; }

    ll v = 0;
    for (int j = 0; j < N; ++j) {
        if (a[j] <= b[j]) {
            v += (b[j] - a[j]) / 2;
        } else {
            v -= a[j] - b[j];
        }
    }
    cout << (v >= 0 ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i = (int)(begin); i < (int)(end); i++)
#define rep(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
using ll = long long;
int main(int argc, char const *argv[])
{
    int card[3][3];
    rep(i, 3) {
        rep(j, 3) {
            scanf("%d", &card[i][j]);
        }
    }
    int N;
    std::cin >> N;
    std::set<int> told;
    rep(i, N) {
        int n;
        scanf("%d", &n);
        told.insert(n);
    }
    bool bingo[3][3];
    rep(i, 3) {
        rep(j, 3) {
            if (told.find(card[i][j]) != told.end())
                bingo[i][j] = true;
            else bingo[i][j] = false;
            // std::cout << bingo[i][j];
        }
    }

    // horizontal
    rep(i, 3) {
        bool judge = bingo[i][0] && bingo[i][1] & bingo[i][2];
        if(judge) {
            printf("Yes\n");
            return 0;
        }
    }
    rep(i, 3) {
        bool judge = bingo[0][i] && bingo[1][i] & bingo[2][i];
        if(judge) {
            printf("Yes\n");
            return 0;
        }
    }
    bool judge = bingo[0][0] && bingo[1][1] && bingo[2][2];
    if(judge) {
        printf("Yes\n");
        return 0;
    }
    judge = bingo[2][0] && bingo[1][1] && bingo[0][2];
    if(judge) {
        printf("Yes\n");
        return 0;
    }
    printf("No\n");
    

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
main(){
  string s;
  cin >> s;
  int n;
  cin >> n;
  vector< string >v;
  for(int i = 0; i < s.size() ; i++ )
  {
    string t;
    for(int j = 0 ; j < 5 && j+i<s.size() ; j++)
    {
      t += s[j+i];
      v.push_back( t );
    }
  }
  sort(v.begin(),v.end());
  
  v.erase(unique(v.begin(),v.end()),v.end());
  
  cout << v[n-1] << endl;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
#define mp make_pair
using namespace std;
int main(){
	ll n;
	cin>>n;
	ll k = 0;
	for(ll i=1;i<=1000;i++){
		if( i*(i-1)==2*n){
			k = i;
		}
	}
	if(k == 0){
		cout<<"No"<<endl;
		return 0;
	}
	else{
		cout<<"Yes"<<endl;
		cout<<k<<endl;
		vector<int> a[k];
		ll now = 1;
		for(int i=0;i<k;i++){
			for(int j=0;j<k-1-i;j++){
				a[i].pb(now);
				a[i+j+1].pb(now);
				now++;
			}
		}
		for(int i=0;i<k;i++){
			cout<<k-1<<" ";
			for(int j=0;j<k-1;j++){
				cout<<a[i][j]<<" ";
			}
			cout<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 2304
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cmath>
#include <climits>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;

#define fast_cin() ios_base::sync_with_stdio(false)

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

const int max_N = 1e3 + 10;
const ll mod = 1e9 + 7;
map<int, int> dp[max_N][max_N];
ll cum[max_N][max_N];
ll fact[max_N], finv[max_N];

ll choose(int N, int K);
ll choose_extend(int N, int k, int j);
ll fast_pow(ll a, ll b);

int main()
{
	fact[0] = 1; finv[0] = 1;
	for (int i = 1; i < max_N; ++i) {
		fact[i] = (fact[i - 1] * i) % mod;
		finv[i] = fast_pow(fact[i], mod - 2);
	}

	int N, A, B, C, D;
	cin >> N >> A >> B >> C >> D;
	dp[0][A - 1][0] = 1;
	cum[0][A - 1] = 1;
	for (int i = 0; i <= N; ++i) {
		for (int j = A; j <= B; ++j) {
			dp[i][j][0] += cum[i][j - 1];
			dp[i][j][0] %= mod;
			cum[i][j] = dp[i][j][0];
//			fprintf(stderr, "(%d, %d): ", i, j);
			for (int k = C; k * j <= i && k <= D; ++k) {
				ll temp = (choose(i, k * j) * cum[i - k * j][j - 1]) % mod;
				temp *= choose_extend(k * j, k, j);
				temp %= mod;
//				fprintf(stderr, "%d %lld, ", k, temp);
				dp[i][j][k] += temp;
				dp[i][j][k] %= mod;
				cum[i][j] += dp[i][j][k];
				cum[i][j] %= mod;
			}
			dp[i][j].clear();
//			cerr << endl;
//			fprintf(stderr, "(%d, %d)->(%lld) ", i, j, cum[i][j]);
		}
//		cerr << endl;
	}

	cout << cum[N][B] << endl;
}

ll fast_pow(ll a, ll b)
{
	a %= mod;
	ll ans = 1, res = a;
	while(b) {
		if (b % 2) {
			ans *= res;
			ans %= mod;
		}
		b /= 2;
		res *= res;
		res %= mod;
	}
	return ans;
}

ll choose(int N, int K)
{
	return (fact[N] * ((finv[K] * finv[N - K]) % mod)) % mod;
}

ll choose_extend(int N, int k, int j)
{
	return (fact[N] * ((fast_pow(finv[j], k) * finv[k]) % mod)) % mod;
}


Measured memory_bytes: 56064
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a; i<n; i++)
using namespace std;

const int S = 10010;
int uf[S];
int find(int a) {
    return (a == uf[a]) ? a : find(uf[a]);
}

void unite(int a, int b) {
    uf[find(a)] = uf[find(b)];
}

int main() {
    rep(i,0,S) uf[i] = i;
    int n, q; cin >> n >> q;
    rep(i,0,q) {
        int c, x, y; cin >> c >> x >> y;
        if(c == 0) unite(x, y);
        else if(c == 1) cout << (find(x) == find(y)) << endl;
    }
    return 0;
}

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

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

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

int n, m;
int a[1001][1001], b[1001];

int main(){
	std::cin >> n >> m;
	rep(i, n)rep(j, m)std::cin >> a[i][j];
	rep(i, m)std::cin >> b[i];
	rep(i, n){
		int sum = 0;
		rep(j, m)sum += a[i][j] * b[j];
		std::cout << sum << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1556
fun main(args: Array<String>) {

    val (H, W) = readInts()
    val map = Array(H, {it -> Array(W, {it -> false})})

    var prevRow = Array(W, {it -> false}).toMutableList()
    for (i in 0 until H) {
        readLine()!!.map { it == '#' }.let {
            it.forEachIndexed { index, shouldBlack ->
                if (shouldBlack) {
                    if (prevRow[index]) {
                        map[i - 1][index] = true
                        map[i][index] = true
                    }
                    if (index > 0 && it[index -1]) {
                        map[i][index -1] = true
                        map[i][index] = true
                    }
                }
            }
            if (i > 0 && map[i - 1].filterIndexed { idx, isBlack -> prevRow[idx] != isBlack }.isNotEmpty()) {
                println("No")
                return
            }
            prevRow = it.toMutableList()
        }
    }
    if (map[H  - 1].filterIndexed { idx, isBlack -> prevRow[idx] != isBlack }.isNotEmpty()) {
        println("No")
        return
    }

    println("Yes")
}

fun readInts(): List<Int> = readStrings().map { it.toInt() }
fun readStrings(): List<String> = readLine()!!.split(" ")

Measured memory_bytes: 37996
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

    string s;
    cin >> s;

    int a=0, b=0, c=0;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'a') a++;
        if (s[i] == 'b') b++;
        if (s[i] == 'c') c++;
    }

    if (abs(a-b)<=1 && abs(b-c)<=1 && abs(c-a)<=1) {
        cout << "YES";
    } else {
        cout << "NO";
    }

    return 0;
}

Measured memory_bytes: 512
N, K = map(int, input().split())
A = list(map(int, input().split()))

nums = A[:]

sum_n = sum(nums)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors

divisors = sorted(list(make_divisors(sum_n)), reverse=True)
#print('DIV', divisors)


for d in divisors:
    mod_nums = list(map(lambda x: x%d, nums[:]))
    mod_nums = sorted(mod_nums)
    #print(mod_nums)
    x = 10**10
    for i in range(0, len(mod_nums)+1):
        if sum(mod_nums[:i]) == sum(list(map(lambda x: d-x, mod_nums[i:]))):
            x = sum(mod_nums[:i])
            break
    #print(d, x)
    if x <= K:
        ans = d
        break
            
print(ans)

Measured memory_bytes: 51732
#include<bits/stdc++.h>
using namespace std;
    int main(){
        int A, B;
            cin >> A >> B;
                if(A <= 5){
                    cout << 0 << endl;
                }else if(6 <= A && A <= 12){
                    cout << (B / 2) << endl;
                }else if(13 <= A){
                    cout << B << endl;
                }
    return 0;}

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

using namespace std;

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

int a[200020];

int main() {
    int N;
    cin >> N;
    rep(i, N) {
        cin >> a[i];
        a[i] -= i + 1;
    }
    sort(a, a + N);
    int median = a[(N - 1) / 2];

    long long sum = 0;
    rep(i, N)sum += abs(median - a[i]);
    cout << sum << endl;

}

Measured memory_bytes: 1024
import java.util.*;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		for (int i = 0; i < N; i++) {
			int Ai = sc.nextInt();
		}
		int index = 0;
		while (0 < N) {
			if (index == 0) {
				N -= K;
			} else {
				N -= (K-1);
			}
			index++;
		}
		System.out.println(index);
	}
}

Measured memory_bytes: 59028
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] temp = br.readLine().split(" ");
        int N = Integer.parseInt(temp[0]);
        int A = Integer.parseInt(temp[1]);
        int B = Integer.parseInt(temp[2]);
        
        int tempSum = 0,sumAns = 0;
       
        for(int i = 1 ; i <= N ; i ++){
            int n = i;
            while(n > 0){
                tempSum += n % 10;
                n /= 10;
                
            }     
            if(A <= tempSum && tempSum <= B){
                
                sumAns += i;
                
            }
            tempSum = 0;
        }
        
        
        System.out.println(sumAns);
        
        
    }
}


Measured memory_bytes: 21972
//include <bits/stdc++.h> 全ヘッダーのinclude
#include <iostream>
#include <cmath>

#define INF 1000001

bool cmpmin(long long *,long long );
bool cmpmax(long long *,long long );

//long long h[101][INF];
long long dp[101][INF] = {0}; //結果配列
long long weight[INF];
long long v[INF];

int main(void){
  int n,w,i;
  int sum_w;
  std::cin >> n >> w;
  for(i=0;i<n;i++){
    std::cin >> weight[i] >> v[i];
  }

  for(i=0;i<n;i++){
    for(sum_w=0;sum_w<=w;sum_w++){
      if(sum_w-weight[i]>=0){
        cmpmax(&dp[i+1][sum_w],dp[i][sum_w-weight[i]]+v[i]);
      }
      cmpmax(&dp[i+1][sum_w],dp[i][sum_w]);
    }
  }

  long long res = 0;
  for(sum_w=0;sum_w<=w;sum_w++){
    cmpmax(&res,dp[n][sum_w]);
  }

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

bool cmpmin(long long *a,long long b){
  if(*a>b){
    *a = b;
    return true;
  } else {
    return false;
  }
}

bool cmpmax(long long *a,long long b){
  if(*a<b){
    *a = b;
    return true;
  } else {
    return false;
  }
}


Measured memory_bytes: 291072
#include<iostream>
#include <algorithm>

using namespace std;

int main(){
  int K,N,buffer;
  cin >> K >> N;
  int A[N],B[N];
  for(int i=0;i<N;i++){
    cin >>A[i];
  }

  for(int i=0;i<N;i++){
    if(i==0){
      B[0]=K-A[N-1]+A[0];
      continue;
    }
    B[i]=A[i]-A[i-1];
  }
  sort(B,B+N);
  cout << K-B[N-1];

  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int line[13];
	for (int i = 1; i <= 12; ++i) {
		cin >> line[i];
	}
	sort(line + 1, line + 13);
	bool hantei = true;
	for (int i = 1; i <= 11; i += 2) {
		if (line[i] != line[i + 1]) {
			hantei = false;
			break;
		}
	}
	if (hantei) {
		cout << "yes" << endl;
	}
	else {
		cout << "no" << endl;
	}
	return 0;
}

Measured memory_bytes: 3092
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;
int main(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	int S = a+b+c+d;
	cin >> a >> b >> c >> d;
	int T = a+b+c+d;
	
	if(S>=T) cout << S << endl;
	else cout << T << endl;

	return 0;
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;

#define NIL NULL

void insert(int);
void inorder(Node);
void preorder(Node);
Node treeSearch(Node, int);
Node treeMinimum(Node);
Node treeSuccessor(Node);
void treeDelete(Node);

Node root;

int main(){

  int n, i, x;
  char com[20];

  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
  
    if( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    }

    else if( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } 
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 
    else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }

  }
  
  return 0;
}

void insert(int k){

  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

 
  while(x != NIL){

    y = x;

    if(z->key < x->key){
      x = x->left;
    }

    else{
      x = x->right;
    }
  }

  z->parent = y;

  if(y == NIL){
    root = z;
  }

  else if(z->key < y->key){
    y->left = z;
  }

  else y->right = z;

}

void inorder(Node u){

  if(u != NIL){
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
  }

}

void preorder(Node u){

  if(u != NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }

}

Node treeSearch(Node u, int k){

  if((u == NIL) || (k == u->key)) return u;

  if(k < u->key) return treeSearch(u->left, k);
  else return treeSearch(u->right, k);

}

Node treeMinimum(Node x){

  while(x->left != NIL){
    x = x->left;
  }

  return x;

}

Node treeSuccessor(Node x){

  Node y; 

  if(x->right != NIL) return treeMinimum(x->right);

  y = x->parent;

  while((y != NIL) && (x == y->right)){
    x = y;
    y = y->parent;
  }

  return y;

}

void treeDelete(Node z){

  Node y; // node to be deleted
  Node x; // child of y

  if((z->left == NIL) || (z->right == NIL)) 
    y = z;
  else y = treeSuccessor(z);

  if(y->left != NIL)
    x = y->left;
  else x = y->right;

  if(x != NIL)
    x->parent = y->parent;

  if(y->parent == NIL)
    root = x;
  else if(y == y->parent->left)
    y->parent->left = x;
  else y->parent->right = x;

  if(y != z)
    z->key = y->key;
}

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

int bubble_sort(int n, int A[]){
    int flag = 1;
    int sw = 0;
    while(flag){
        flag = 0; //flag=0?????´???????°????????????????
        for(int i = n-1; i > 0; i--){
            if(A[i] < A[i-1]){
                int temp = A[i];
                A[i] = A[i-1];
                A[i-1] = temp;
                flag = 1;
                sw++;
            }
        }
    }
    return sw;
}


int main(){
    int N; cin >> N;
    int array[N];
    for(int i = 0; i < N; i++) cin >> array[i];
    int count;
    count = bubble_sort(N, array); //??????????????°???????????¨????????????????????\?????????

    for(int i = 0; i < N; i++){
        if(i == N-1) cout << array[i] << endl;
        else cout << array[i] << " " ;
    }
    cout << count << endl;

    return 0;
}

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

int main(){
	int m[5],min,sum=0,check,n[5],ans=0;
	
	for(int i=0;i<5;i++)
		cin>>m[i];
	
	for(int i=0;i<5;i++)
		n[i]=m[i]%10;
	
	if(n[0]==0&&n[1]==0&&n[2]==0&&n[3]==0&&n[4]==0){
		for(int i=0;i<5;i++){
			ans+=m[i];
		}
	}
	else{
	for(int i=0;i<5;i++){
		for(int j=1;j<=9;j++){
			if(m[i]%10==j){
				m[i]+=(10-j);
			}
		}
	}

	if(n[0]!=0)
		min=n[0];
	for(int i=1;i<5;i++){
		if(min>n[i]){
			if(n[i]!=0){
				min=n[i];
				check=i;
			}
		}
	}
	
	for(int i=0;i<5;i++){
		sum+=m[i];
	}
	
	ans=sum-(10-n[check]);
	}
	
	cout<<ans<<endl;
	
	
	
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll = unsigned long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
    ll n = in(), m = in();

    vector<ll>a(n);
    REP(i, n)scanf("%lld", &a[i]);
    sort(ALL(a));

    vector<pair<ll, ll>>bc(m);
    REP(i, m) {
        ll b, c; scanf("%lld%lld", &b, &c);
        bc[i] = make_pair(c, b);
    }
    sort(ALL(bc), greater<pair<ll, ll>>());

    ll inow = 0, ans = 0;
    REP(i, m) {
        ll b = bc[i].second, c = bc[i].first;
        for (ll j = inow; j < min(inow + b, n); ++j) {
            ans += max(a[j], c);
        }
        inow += b;
    }
    for (ll j = inow; j < n; ++j)ans += a[j];

    cout << ans << endl;
}

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

using namespace std;

const int MOD = 1e9 + 7;
const long long INF = 1e18;
const int MaxN = 1e4 + 14;
const int MaxD = 100;

int dp[MaxN][MaxD][2];

void up(int & x, int y)
{
    x += y;
    if(x >= MOD)
        x -= MOD;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    freopen("input.txt", "r", stdin);

    string s;
    cin >> s;

    int D;
    cin >> D;

    for(int i = 0; i < s[0] - '0'; ++i)
        dp[1][i % D][0] += 1;
    dp[1][(s[0] - '0') % D][1] += 1;

    for(int i = 2; i <= s.size(); ++i)
    {
        int curD = s[i - 1] - '0';
        for(int prevSum = 0; prevSum < D; ++prevSum)
            for(int nextD = 0; nextD < 10; ++nextD)
            {
                int nextSum = (prevSum + nextD) % D;

                if(nextD < curD)
                {
                    up(dp[i][nextSum][0], dp[i - 1][prevSum][0]);
                    up(dp[i][nextSum][0], dp[i - 1][prevSum][1]);
                }else
                if(nextD == curD)
                {
                    up(dp[i][nextSum][0], dp[i - 1][prevSum][0]);
                    up(dp[i][nextSum][1], dp[i - 1][prevSum][1]);
                }else
                {
                    up(dp[i][nextSum][0], dp[i - 1][prevSum][0]);

                }
            }
    }

    int ans = MOD - 1;
    up(ans, dp[s.size()][0][0]);
    up(ans, dp[s.size()][0][1]);

    cout << ans << '\n';

    return 0;
}



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

int main(){
    int n[]={1, 0};
    while(n[0]||n[1]){
        cin >> n[0] >> n[1];
        if(n[0]||n[1]) if(n[0]<n[1]) cout << n[0] << " " << n[1] << endl; else cout << n[1] << " " << n[0] << endl;
    }
}


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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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

//グラフ関連
struct Edge {
    ll to, cap, rev;
    Edge(ll _to, ll _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph &G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    while(a >= b and k) {
        b *= 2;
        k--;
    }

    while(b >= c and k) {
        c *= 2;
        k--;
    }
    if(a < b and b < c) {
        cout << "Yes" << en;
    } else {
        cout << "No" << en;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /*
    ll t;
    cin >> t;
    while(t--)*/
    solve();

    return 0;
}


Measured memory_bytes: 3640
/*
author: rootn
*/

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

#define X first
#define Y second
#define pb push_back
#define mp make_pair

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    int n, k;cin >> n >> k;
    string s, ns = "";cin >> s;
    for(int i = 0;i < n;i++)
    {
        if(i != k-1)
        {
            ns += s[i];
        }
        else{
            ns += tolower(s[i]);
        }
    }
    cout << ns << endl;
}


Measured memory_bytes: 256
// dile a la jardinera que traigo flores

#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define sz(x) int(x.size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define FER(i,a,b) for(int i = int(a); i < int(b); ++i)
#define IFR(i,a,b) for(int i = int(a); i >= int(b); i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

const int N=55;
ll tam[N],lel[N];

void pcal(){
	tam[0]=1;
	FER(i,1,51)tam[i]=2*tam[i-1]+3;
	lel[0]=0;
	FER(i,1,51)lel[i]=2*lel[i-1]+2;
}

ll solve(ll n,ll x){
	//trace(n);
	//trace(x);
	if(x==0)return 0;
	if(n==0)return 0;
	if(x==tam[n])return lel[n];
	if(x<=tam[n-1]+1)return 1+solve(n-1,x-1);
	return 1+solve(n-1,tam[n-1])+solve(n-1,x-2-tam[n-1]);
}

int main(){	
	fastio;
	ll n,x;cin>>n>>x;
	if(n==0){
		cout<<1<<endl;
		return 0;
	}
	pcal();
	cout<<x-solve(n,x)<<endl;
	return 0;
}


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

int main()
{
    int w, a, b;
    cin >> w >> a >> b;
    if(max(a, b) - (min(a,b) + w) > 0) cout << abs(max(a, b) - (min(a,b) + w)) << endl;
    else cout << 0 << "\n";
}

Measured memory_bytes: 256
s = int( input() )
mod = 10 ** 9 + 7

fact = [ 1, 1 ]
inv = [ 1, 1 ]
inv_fact = [ 1, 1 ]

for k in range( 2, 2000 ):
    fact.append( fact[ k-1 ] * k % mod )
    inv_k = ( - inv[ mod % k ] * ( mod // k ) % mod ) % mod
    inv.append( inv_k )
    inv_fact.append( inv_fact[ k - 1 ] * inv_k % mod )

# print( inv_fact[:5] )

ans = 0
for k in range( 1, s // 3 + 1 ):
    comp = fact[ s - 2 * k - 1 ] * inv_fact[ s - 3 * k ] % mod
    comp = comp * inv_fact[ k - 1 ] % mod
    ans = ( ans + comp ) % mod

print( ans )

Measured memory_bytes: 9372
#define _CRT_SECURE_NO_WARNINGS
#define M_PI 3.14159265358979
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include<iomanip>
#include<vector>
#include<cmath>
#include <algorithm>

using namespace std;

int main(){
	int n,m[100],i=0;
	while (cin >> n){
		if (n == 0){
			cout << m[i-1] << endl;
			i--;
		}
		else{
			m[i] = n;
			i++;
		}
	}
	return 0;
}

Measured memory_bytes: 1164
#include <stdio.h>

int main() {
    int N, A, B, x, y;
    scanf("%d %d %d", &N, &A, &B);
    x=N*A;
    if(x < B){
        printf("%d", x);
    }else{
        printf("%d", B);
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>

using namespace std;

int main(void)
{
	long long i,j,L,R,r,ans=2018;
	
	cin >> L >> R;

	for(i=L;i<=L+2019;i++)
	{
		for(j=R-2019;j<=R;j++)
		{
			if(i<j)
			{
				r=(i*j)%2019;
			}
			else
			{
				continue;
			}
			if(ans>r)
			{
				ans=r;
			}
		}

	}

	cout << ans << endl;

}


Measured memory_bytes: 256
N = int(input())
l = [int(x) for x in input().split()]

if 0 in l:
    ans = 0
else:
    n = min(N,len(l))
    ans = 1
    for i in l[:n]:
        ans *= i
        if ans > 10**18:
            ans = -1
            break
print(ans)

Measured memory_bytes: 21440
import sys
N,K=map(int, input().split())
p=[]
for i in range (0,N):
  r=list(map(int, input().split() )) 
  p.append(r)
p.sort()
k=0
for i in range(0,N):
  k+=p[i][1]
  if k>=K:
    print(p[i][0])
    sys.exit()

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

#define FOR(i, a, b) for (int i = (a); i < static_cast<int>(b); i++)
#define FORR(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) FOR (i, 0, n)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
template <typename T>
void print(const vector<vector<T>> matrix);
template <typename T>
void print(const vector<T> vec);
template <typename Arg>
void print(const Arg arg);
template <typename Head, typename... Args>
void print(const Head head, const Args... args);
template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;
using ll = long long;

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

    int a, b;
    cin >> a >> b;

    if (a + b == 15)
        print('+');
    else if (a * b == 15)
        print('*');
    else
        print('x');

    return 0;
}

//---------------------------------------------
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    repall (i, vec)
        cout << i << ' ';
    cout << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}


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

public class Main{

	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
		int joi=0,ioi=0;

        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            while ((line = br.readLine()) != null&&line.length()!=0) {
            	joi=0;
            	ioi=0;
            	for(int i=0;i<line.length()-3;i++){
            		if(line.substring(i,i+3).equals("JOI")){
            			joi++;
            		}else if(line.substring(i,i+3).equals("IOI")){
            			ioi++;
            		}
            	}
            	System.out.println(joi);
            	System.out.println(ioi);
            }
         }
	}

}

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

int		main(void)
{
	vector<int> Pillar(3);
	for (int i = 0; i < 3; i++)
		cin >> Pillar.at(i);

	int		tmp = Pillar.at(1) - Pillar.at(0);

	cout << (Pillar.at(2) == Pillar.at(1) + tmp ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int X,i,j;

	scanf("%d",&X);

while(1){
	j=0;
  	for(i=1;i<=X;i++){
      if(X%i==0)
        j++;
    }
  	if(j==2){
 	 printf("%d",X);
  	return 0;
  	}else{
  	X++;
  	}
}

return 0;
} 

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;

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

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

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	int H, W;
	cin >> H >> W;

	vector <string> s;
	for (int ii = 0; ii < H; ++ii){
		string tmp;
		cin >> tmp;
		s.push_back(tmp);
	}

	queue<pair<int,int>> q;
	q.push(make_pair(0,0));	//最初のキューを追加

	vector<vector<int>> dist(H, vector <int>(W, -1));
	dist[0][0] = 0;

	vector <int> p(H*W, -1);

	int nx[4] = {1, -1, 0, 0};
	int ny[4] = {0, 0, 1, -1};
	while (!q.empty()) {	//キューが空になるまで探索
		int ty = q.front().first;
		int tx = q.front().second;
		int tidx = W * ty + tx;
		q.pop();

		for (int ii = 0; ii < 4; ++ii){
			int x = tx + nx[ii];
			int y = ty + ny[ii];
			if (x<0 || x>= W || y<0 || y>= H ){
				continue;
			}
			if (s[y][x] == '#'){
				continue;
			}
			int tmp = dist[ty][tx] + 1;
			int idx = W * y + x;
			if ( (dist[y][x] < 0) || (tmp < dist[y][x])){
				dist[y][x] = tmp;
				p[idx] = tidx;
				q.push(make_pair(y, x));
			}
		}
	}

	vector<vector<bool>> valid(H, vector <bool>(W, true));
	int index = H*W - 1;
	while (true) {
		int x = index % W;
		int y = index / W;
		valid[y][x] = false;
		index = p[index];
		if (index < 0){
			break;
		}
	}

	int ans = 0;
	for (int ii = 0; ii < H; ++ii){
		for (int jj = 0; jj < W; ++jj){
			if ( (s[ii][jj] == '.') && valid[ii][jj] ){
				ans++;
			}
		}
	}

	if (dist[H-1][W-1] < 0){
		cout << -1 << "\n";		
	} else {
		cout << ans << "\n";
	}

	return 0;
}


Measured memory_bytes: 256
<?php

$S = explode(' ', trim(fgets(STDIN)));
$sx = (int)$S[0];
$sy = (int)$S[1];
$tx = (int)$S[2];
$ty = (int)$S[3];

$res = '';
$x = 0 < $tx - $sx ? true : false;
$y = 0 < $ty - $sy ? true : false;

//root1
$res .= str_repeat($y ? 'U':'D',  abs($ty - $sy));
$res .= str_repeat($x ? 'R':'L',  abs($tx - $sx));
$res .= str_repeat($y ? 'D':'U',  abs($ty - $sy));
$res .= str_repeat($x ? 'L':'R',  abs($tx - $sx));

//root2

$res .= $x ? 'L' : 'R' ;
$res .= str_repeat($y ? 'U':'D',  abs($ty - $sy) + 1);
$res .= str_repeat($x ? 'R':'L',  abs($tx - $sx) + 1);
$res .= $y ? 'D' : 'U';
$res .= $x ? 'R' : 'L';
$res .= str_repeat($y ? 'D':'U',  abs($ty - $sy) + 1);
$res .= str_repeat($x ? 'L':'R',  abs($tx - $sx) + 1);
$res .= $y ? 'U' : 'D';

echo $res . "\n";

?>


Measured memory_bytes: 4856
#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define F first
#define S second
#define pb push_back
#define f(i,s,n) for(int i=(int)s;i<=(int)n;++i)
#define Fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N=2e5+5;
int vis[N];
vector<int> adj[N];
int c=0;
void dfs(int child){
	vis[child]=1;
	++c;
	for(auto n:adj[child]){
		if(!vis[n]){
			dfs(n);
		}
	}
}
void solve()
{
	int n,m;cin>>n>>m;
	
	map<pair<int,int> ,int >mp;
	f(i,0,m-1){
		int u,v;cin>>u>>v;
		if(!mp[{u,v}]){
			adj[u].pb(v);
			adj[v].pb(u);
			mp[{u,v}]++;
			mp[{v,u}]++;
		}
	}
	int cc=0;
	int ans=0;
	f(i,1,n){
		if(!vis[i]){
			dfs(i);
			ans=max(ans,c);
			c=0;
		}
	}
	cout<<ans<<'\n';
}
int main()
{	Fast;
	//int t;cin>>t;
	//while(t--)
	solve();
}

Measured memory_bytes: 46512
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

fn main() {
    input! {
        s: chars,
    }

    if s[0] == 'S' {
        println!("Cloudy");
    } else if s[0] == 'C' {
        println!("Rainy");
    } else if s[0] == 'R' {
        println!("Sunny");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip> 
#define pb push_back
#define mp make_pair
#define fi first 
#define se second
#define rep(i, a, b) for (long long i = a; i < b; i++)
#define per(j, a, b) for (long long j = a; j >= b; j--)
using namespace std;
long long const MOD = 1000000007;
int main(){
	long long n, sum = 0, ans = 0;
	cin >> n;
	vector <long long> v(n);
	rep(i,0,n){
		cin >> v[i];
		sum +=v[i];
	}
	rep(i,0,n-1){
		sum -=v[i];
		ans+= ((sum%MOD)*v[i])%MOD;
		ans%=MOD;
	}
	cout << ans << endl;
}



Measured memory_bytes: 4844
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int hei[n+1];
    int arr[n+1];
    int fre[n+1];
    for(int i=0;i<=n;i++)
    {
    arr[i]=1;
    fre[i]=0;
    }
    fre[0]=1;
    hei[0]=0;
    for(int i=1;i<=n;i++)
    cin>>hei[i];
    int a,b,ans=n;
    while(m--)
    {
        cin>>a>>b;
        if(hei[a]<=hei[b])
        {
            if(arr[a]!=0)
            {
            ans--;
            arr[a]--;
            }
        }
        if(hei[b]<=hei[a])
        {
            if(arr[b]!=0)
            {
            arr[b]--;
            ans--;
            }
        }
       
    }
    cout<<ans;
}

Measured memory_bytes: 4796
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n;
    cin>>n;
    set<long long int> s;
    long long int a[n+1];
    for(long long int i=0;i<n;i++)
    {
        cin>>a[i];
        s.insert(a[i]);
    }
    if(s.size()!=n)
      cout<<"NO";
      else
      cout<<"YES";
    
}

Measured memory_bytes: 11136
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  vector<ll>a(n),aa(n);
  rep(i,n)cin>>a[i];
  ll sum,mask;
  sum=0;
  rep(i,n)sum^=a[i];
  mask=(1LL<<61)-1-sum;
  rep(i,n)aa[i]=mask&a[i];
  int id=0;
  for(int i=60;i>-1;i--)
  {
    ll bit=1LL<<i;
    int flag=-1;
    repi(j,id,n)
    {
    //  cout<<aa[j];
      if((bit&aa[j])==bit)
      {
        if(flag==-1)
        {
          if(j!=id)
          {
            swap(aa[id],aa[j]);
          }
          flag=id;
        }
        else
        {
          aa[j]^=aa[flag];
        }
      }
    }
  //  cout<<endl;

    if(flag!=-1)id++;

  }
  ll res=0;
  rep(i,n)
  {
  //  cout<<(bitset<60>)aa[i]<<endl;
    chmax(res,res^aa[i]);
  }
//  cout<<res<<endl;
  cout<<res*2+sum<<endl;
  return 0;

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)

int main(){
  int N, M;
  cin >> N >> M;
  int total = N + M;
  vector<int> vec;

  for (int i = 0; i < N; i++){
    vec.push_back(2 * (i + 1));
  }
  for (int i = 0; i < M; i++){
    vec.push_back(2 * i + 1);
  }

  int count = 0;
  for (int i = 0; i < vec.size(); i++){
    for (int j = i + 1; j < vec.size(); j++){
      if (i == j) continue;
      if ((vec.at(i) + vec.at(j)) % 2 == 0){
        count += 1;
      } 
    }
  }

  cout << count << endl;
}

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

int main () {
  int D;
  cin >> D;
  string C = "Christmas";
  
  if (D == 25) {
    cout << C << " " << endl;
  }
  if (D == 24) {
    cout << C << " " <<"Eve" << endl;
  }
  if (D == 23) {
    cout << C << " " <<"Eve Eve" << endl;
  }
  if (D == 22) {
    cout << C << " " <<"Eve Eve Eve" << endl;
  }
}

Measured memory_bytes: 256
import numpy as np
import sys

n, a, b = map(int, input().split())
x = list(map(int, input().split()))

if n == 2:
    print(min((x[1] - x[0]) * a, b))
    sys.exit()

left = 0
right = n - 1
curr = 0
cnt = 0
reverse = False


while left < right:
    if not reverse:
        if (x[curr + 1] - x[curr]) * a > (x[right] - x[right - 1]) * a + b:
            reverse = True
            cnt += b
            curr = right
            left += 1
        elif (x[curr + 1] - x[curr]) * a <= b:
            left += 1
            cnt += (x[curr + 1] - x[curr]) * a
            curr = left
        else:
            left += 1
            cnt += b
            curr = left
    else:
        if (x[curr] - x[curr - 1]) * a > (x[left + 1] - x[left]) * a + b:
            reverse = False
            cnt += b
            curr = left
            right -= 1
        elif (x[curr] - x[curr - 1]) * a <= b:
            right -= 1
            cnt += (x[curr] - x[curr - 1]) * a
            curr = right
        else:
            right -= 1
            cnt += b
            curr = right

print(cnt)

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

int main(){
  int N, K;
  cin >> N >> K;
  
  vector<int> vec(N);
  for(int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(),vec.end());
  int ans = 0;
  for(int i = 0; i < K; i++){
    ans += vec.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3592
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			String t = sc.nextLine();
			if(t.compareTo("0")==0) break;
			
			int n = Integer.valueOf(t);
			int[] num = new int[n];
			int[] sum = new int[n];
			int[] tmps = new int[n];
			
			for(int k=0;k<n;k++){
				String[] s = sc.nextLine().split(" ");
				int len = s.length;
				int[] a = new int[len];
				for(int i=0;i<len;i++) a[i] = Integer.valueOf(s[i]);
				
				int count = 0;
				for(int i=1;;i++){
					if(a[i]==10){
						a[i] = a[i]+a[i+1]+a[i+2];
					}
					else if(a[i]+a[i+1]==10){
						a[i] = a[i]+a[i+2];
						i++;
					}else{
						i++;
					}
					count++;
					if(count==9) break;
				}
				for(int i=1;i<len;i++) sum[k] += a[i];
				num[k] = a[0];
			}
			tmps = sum.clone();
			Arrays.sort(tmps);
			ArrayList<Integer> list = new ArrayList<Integer>();
			
			for(int i=0;i<n;i++){
				for(int j=0;j<n;j++){
					if(tmps[n-1-i]==sum[j]) list.add(num[j]);
				}
				Collections.sort(list);
				for(int j=0;j<list.size();j++){
					System.out.println(list.get(j) + " " + tmps[n-1-i]);
				}
				i+=list.size()-1;
				list.clear();
			}
			
		}
	}	
}

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

void log(int A[], int n)
{
    for (int i = 0; i < n; ++i) {
        cout << A[i];
        if (i != n - 1) {
            cout << " ";
        }
    }
    cout << endl;
}

void InsertionSort(int A[], int n)
{
    for (int i = 1; i < n; ++i) {
        int tmp = A[i];
        int j = i;
        while (j > 0 && A[j-1] > tmp) {
            A[j] = A[j-1];
            --j;
        }
        A[j] = tmp;
        log(A, n);
    }
}

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

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

    log(A, n);
    InsertionSort(A, n);

    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
int main() {
  string A;
  cin >> A;
  int ans = 0;
  for(int i = 0; i < 4; i++) {
    if(A.at(i) == '+') {
      ans++;
    }
    else {
      ans--;
    }
  }
  cout << ans << endl;
}


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

class UnionFind {
	vector<int>par, sz;
public:
	UnionFind() {}
	UnionFind(int n) {
		par = sz = vector<int>(n);
		for (int i = 0; i < n; i++) {
			par[i] = i;
			sz[i] = 1;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (sz[x] > sz[y]) {
			par[y] = x;
			sz[x] += sz[y];
		}
		else {
			par[x] = y;
			sz[y] += sz[x];
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return sz[find(x)];
	}
};

int cnt[200000];
int main(){
	int n,m,K;cin>>n>>m>>K;
	UnionFind uf(n);
	rep(i,m){
		int a,b;scanf("%d%d",&a,&b);a--;b--;
		cnt[a]--;cnt[b]--;
		uf.unite(a,b);
	}
	rep(i,K){
		int a,b;scanf("%d%d",&a,&b);a--;b--;
		if(uf.same(a,b))cnt[a]--,cnt[b]--;
	}
	rep(i,n)printf("%d ",cnt[i]+uf.size(i)-1);
}

Measured memory_bytes: 2048
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(){
    char s[200010];
    scanf("%s",s);
    int l = strlen(s);
    int i,j,n,p = 2019,c = 0,list[200005],mod[200005];
    long m = 0;
    list[0] = 1;
    mod[0] = (s[l - 1] - '0') % p;
    for(i = 1; i < l; i++){
      list[i] = (list[i - 1] * 10) % p;
      mod[i] = ((s[l - i - 1] - '0') * list[i] + mod[i - 1]) % p;
    }
    for(i = 0; i < p; i++) list[i] = 0;
    for(i = 0; i < l; i++){
      if(mod[i] == 0) m++;
      m += list[mod[i]];
      list[mod[i]]++;
    }
    printf("%ld\n",m);
    return 0;
}

Measured memory_bytes: 3428
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <assert.h>
using namespace std;
typedef long long LL;
const int N=100000+10;
int n,sz[N]; 
pair<LL,LL> d[N];
vector<LL> g[N];
bool cmp(pair<LL,LL> p1,pair<LL,LL> p2){
    return p1.second>p2.second;
}
map<LL,LL> mp;
vector< pair<LL,LL> > res;
int dep[N]; LL sum=0;
void prt(int u,int p){
    for(auto v:g[u]){
        if(v==p)continue;
        res.push_back(make_pair(u,v));
        dep[v]=dep[u]+1; sum+=dep[v];
        prt(v,u);
    }
}
int main() {
    scanf("%d",&n); 
    for(int i=1;i<=n;i++){
        d[i].first=i; 
        scanf("%lld",&d[i].second);
        mp[d[i].second]=i;
        sz[i]=1;
    }
    sort(d+1,d+1+n,cmp);
    for(int i=1;i<n;i++){
        LL tmp=d[i].second;
        LL nex=tmp-(n-2*sz[d[i].first]);
        if(mp[nex]==0||nex>=tmp){
            return !printf("-1\n");
        }
        int u=mp[nex];
        int v=d[i].first;
        g[u].push_back(v); g[v].push_back(u);
        sz[u]+=sz[v];
    }
    prt(d[n].first,d[n].first);
    if(sum != d[n].second) return !printf("-1\n");
    if(res.size()==n-1){
        for(auto p: res) printf("%lld %lld\n", p.first, p.second);
    } else {
        printf("-1\n");
    }
}




Measured memory_bytes: 21108