akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>

std::vector<std::pair<int, int>> prime_factor(long long n) {
  std::vector<std::pair<int, int>> res;
  for (long long p = 2; p * p <= n; ++p) {
    int exp = 0;
    while (n % p == 0) {
      n /= p;
      ++exp;
    }
    if (exp)
      res.push_back(std::make_pair(p, exp));
  }
  if (n != 1)
    res.push_back(std::make_pair(n, 1));
  return res;
}

int main() {
  int mod = 1000000007;

  int n;
  std::cin >> n;

  std::map<int, int> mp;
  for (int i = 1; i <= n; ++i) {
    auto fs = prime_factor(i);
    for (auto &v : fs) {
      mp[v.first] += v.second;
    }
  }

  long long res = 1;
  for (auto &kv : mp)
    res = res * (kv.second + 1) % mod;
  std::cout << res << std::endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

long long int gcd(long long int x, long long int y)
{
	if (y == 0) { return x; }
	return gcd(y, x % y);
}

int main(void)
{
	vector<int> a;
	int k, n,tmp,ans = 0,max;
	cin >> k >> n;
	for (int i = 0; i < n; i++) { cin >> tmp; a.push_back(tmp); }
	max = k - a[n - 1] + a[0]; ans += max;
	for (int i = 0; i < n - 1; i++)
	{
		ans += a[i + 1] - a[i];
		if (max < a[i + 1] - a[i]) { max = a[i + 1] - a[i]; }
	}
	cout << ans - max << endl;
	return 0;
}


Measured memory_bytes: 1400
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;
ll modpow(ll x, ll n){
	ll r=1;
	while(n){
		if(n&1) r=r*x%MOD;
		x=x*x%MOD;
		n>>=1;
	}
	return r;
}
int main(){
  ll m,n;cin>>m>>n;
  cout<<modpow(m,n)<<endl;
}



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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	ll n, k;
	cin >> n >> k;
	int a[n];
	int c=0, p=0;
	vector<int> pos;
	unordered_map<int,int> seen;
	
	for (int i = 0; i < n; i++)
		cin >> a[i];
		
	while (p < k) {
		pos.push_back(c);
		seen[c] = p++;
		c = a[c]-1;
		if (seen.find(c) != seen.end())
			break;
	}
	if (p == k)
		cout << c+1 << "\n";
	else cout << pos[seen[c]+(k-p)%(p-seen[c])]+1 << endl;
	
	/*for (int x : pos)
		cout << x << " ";
	cout << endl;
	cout << seen[c] << endl;*/
	
	return 0;
}


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author deepanshu
 */
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);
        BYYMMOrMMYY solver = new BYYMMOrMMYY();
        solver.solve(1, in, out);
        out.close();
    }

    static class BYYMMOrMMYY {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String s = in.next();
            int firstpart = Integer.parseInt(s.substring(0, 2));
            int secondpart = Integer.parseInt(s.substring(2));
            if ((firstpart > 12 || firstpart == 00) && (secondpart <= 12 && secondpart >= 1))
                out.println("YYMM");

            else if ((firstpart <= 12 && firstpart >= 1) && (secondpart > 12 || secondpart == 0))
                out.println("MMYY");

            else if ((firstpart <= 12 && firstpart >= 1) && (secondpart <= 12 && secondpart >= 1))
                out.println("AMBIGUOUS");
            else
                out.println("NA");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

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

    }
}



Measured memory_bytes: 20692
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine();
		
		S = S.replaceFirst("a", "").replaceFirst("b", "").replaceFirst("c", "");

		if (S.isEmpty()) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 22996
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] arr = new int[N+1000];
        int[] memo = new int[N+1000];

        for (int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
            memo[i]=-1;
        }

//        int[] dp = new int[N+1000];
//        for (int i = 0; i <dp.length ; i++) {
//            dp[i] = Integer.MAX_VALUE;
//        }
//        dp[1] = 0;
//        for (int i = 1; i <= N ; i++) {
//            dp[i+1] =Math.min(dp[i+1], dp[i] +Math.abs(arr[i-1]-arr[i]));
//            dp[i+2] =Math.min(dp[i+2], dp[i] +Math.abs(arr[i-1]-arr[i+1]));
//        }
//        System.out.println(dp[N]);


        System.out.println(recur(arr,memo,N-1));

    }

    static public int recur(int[] arr,int[] memo, int idx){
        if(memo[idx]!=-1) return memo[idx];
        if(idx <=0){
            return 0;
        }

        int min = Integer.MAX_VALUE;
        if(idx-1>=0)
        min = Math.min(min, recur(arr,memo,idx-1) + Math.abs(arr[idx] - arr[idx-1]));

        if(idx-2>=0)
        min = Math.min(min, recur(arr,memo,idx-2) + Math.abs(arr[idx] - arr[idx-2]));

        memo[idx] =min;
        return min;
    }


}


Measured memory_bytes: 62864
#include "bits/stdc++.h"
using namespace std;

int main(){
    int n;
    int id;
    double height, weight;
    double diff;
    double best;
    int ans;
    while(cin >> n, n){
        best = 1000;
        for(int i=0; i< n; i++){
            cin >> id >> height >> weight;
            diff = abs(22 - weight / pow(height/100, 2));

            if(diff < best){
                best = diff;
                ans = id;
            }
        }
        cout << ans << endl;
    }

}

Measured memory_bytes: 3124
N=int(input())

from collections import defaultdict
cnt=defaultdict(int)
M=0
for a in map(int,input().split()):
    cnt[a]+=1
    M=max(a,M)
ans=0
for i in cnt.keys():
    if cnt[i]>i:
        ans+=cnt[i]-i
    elif cnt[i]<i:
        ans+=cnt[i]
print(ans)

Measured memory_bytes: 23680
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int a[N];
int main()
{
    int n,m;
    cin>>n>>m;
    long long sum=0;
    for(int i=1;i<=m;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    if(sum<n)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
    //cout << "Hello world!" << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n,k;
  cin>>n>>k;
  vector<int> ps(n);
  for(int i=0;i<n;i++) cin>>ps[i];
  sort(ps.begin(),ps.end());

  int ans=0;
  for(int i=0;i<k;i++) ans+=ps[i];
  cout<<ans<<newl;
  return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
#define endl '\n'
#define F first
#define S second
typedef pair<int, int> pii;
typedef long long ll;

const int MAX = 1e5+1;
vector<pii> g[MAX];
bool vis[MAX];
int color[MAX];

void dfs(pii u){
	vis[u.F] = 1;
	for(auto&x: g[u.F]){
		if(!vis[x.F]){
			if(x.S%2==0) color[x.F]=color[u.F];
			else color[x.F]=!color[u.F];
			dfs(x);
		}
	}
}

int main(){
	int n; cin>>n;
	int u, v, w;
	for(int i=0; i<n-1; i++){
		cin>>u>>v>>w;
		u--; v--;
		g[u].push_back({v, w});
		g[v].push_back({u, w});
	}
	dfs({0,0});
	for(int i=0; i<n; i++){
		cout<<color[i]<<endl;
	}
	return 0;   
}


Measured memory_bytes: 11384
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
using namespace std;

typedef long long ll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

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

int main() {
	int n;
	cin >> n;
	vi a(n);
	map<int, int> mp;
	rep(i, n) {
		cin >> a.at(i);
		mp[a.at(i)]++;
	}
	sort(all(a));
	reverse(all(a));
	ll b = 0, c = 0;
	ll ans = 0;
	rep(i, n) {
		if (mp[a.at(i)] >= 2) {
			if (b == 0) {
				b = a.at(i);
			}
			else {
				c = a.at(i);
			}
			mp[a.at(i)] -= 2;
			i--;
		}
		if (b * c > 0) {
			break;
		}
	}
	ans = b * c;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5376
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

ll MOD = ((ll)1e9 + 7);

struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
	}
	
	mod& operator=(const ll & tx) {
		x = tx;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return (x + m2.x) % MOD;
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return (x - m2.x + MOD) % MOD;
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return (x * m2.x) % MOD;
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return mod(((*this).x * (*this).inv().x) % MOD);
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}

/* TEMPLATE ENDS HERE */

#define MAXN (1 << 12)
#define INF (1 << 29)

int mem[MAXN];
int c[MAXN];
int u[MAXN];
int n, m;

int solve(int mask) {
	if (mask == 0) {
		return 0;
	}
	int & ret = mem[mask];
	if (ret <= INF) {
		return ret;
	}
	ret = INF;
	for (int i = 0; i < m; i++) {
		int next = mask & (~u[i]);
		if (next == mask) {
			continue;
		}
		int nextcost = c[i] + solve(next);
		if (nextcost < ret) {
			ret = nextcost;
		}
	}
	return ret;
}

int main() {
	memset(mem, 63, sizeof(mem));
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int t;
		cin >> c[i];
		cin >> t;
		for (int j = 0; j < t; j++) {
			int tt;
			cin >> tt;
			tt--;
			u[i] |= (1 << tt);
		}
	}
	int ret = solve((1 << n) - 1);
	if (ret < INF) {
		cout << ret << endl;
	} else {
		cout << -1 << endl;
	}
	return 0;
}


Measured memory_bytes: 3172
#include<bits/stdc++.h>
int main()
{
int n,m,p,x,i,sum,s;
int a[110];
scanf("%d",&n);
sum=0;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
scanf("%d",&m);
s=sum;
while(m--)
{
scanf("%d%d",&p,&x);
if(x>=a[p-1])
sum+=(x-a[p-1]);
else
sum-=(a[p-1]-x);
printf("%d\n",sum);
sum=s;
}
return 0;
}


Measured memory_bytes: 256
'use strict'

function main(input) {

    input = input.split('\n')[0].split('');
    var plus = 0;
    var minus = 0;
    for (var i = 0; i < input.length; i++) {
        if (input[i] == '+') plus++;
        else minus++;
    }


    console.log(plus - minus)

}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long w,h,x,y;
    cin>>w>>h>>x>>y;
    double ans=((double)w*(double)h)/2;
    if(x*2==w&&y*2==h)
    {
        printf("%.6lf 1",ans);
    }
    else
    {
        printf("%.6lf 0",ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)


int main(){
	int w,h,m[4][100][100];
	// 0:↑ 1:→ 2:↑に曲がった直後 3:→に曲がった直後
	for(;;){
		scanf("%d%d",&w,&h);
		if(w==0 && h==0)break;
		if(h>w)swap(h,w);
		rep(i,w)rep(k,4)m[k][i][0]=m[k][0][i]=0;
		reps(i,1,w-1)m[0][i][0]=m[1][0][i]=1;
		reps(i,1,w-1)reps(j,1,w-1){
			m[0][i][j]=(m[0][i-1][j]+m[2][i-1][j])%1000000;
			m[1][i][j]=(m[1][i][j-1]+m[3][i][j-1])%1000000;
			m[2][i][j]=m[1][i-1][j]%1000000;
			m[3][i][j]=m[0][i][j-1]%1000000;
		}
		int c=0;
		rep(i,4)c=(c+m[i][w-1][h-1])%100000;
		printf("%d\n",c);
	}
	return 0;
}

Measured memory_bytes: 1344
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

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

    int n,alim,blim;cin>>n>>alim>>blim;
    string s;cin>>s;
    int a=0,b=0;
    rep(i,n){
        if(s[i]=='a'){
            if(a+b<alim+blim){
                a++;cout<<"Yes"<<endl;
            }else{
                cout<<"No"<<endl;
            }
        }
        if(s[i]=='b'){
            if(a+b<alim+blim and b<blim){
                b++;cout<<"Yes"<<endl;
            }else{
                cout<<"No"<<endl;
            }
        }
        if(s[i]=='c'){
            cout<<"No"<<endl;
        }
    }

    return 0;
}


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

int main() {
	long long n, k;
	cin >> n >> k;
	if(n == k){
		cout << 1 << endl;
		return 0;
	}
	//vector<long long> a(n);
	bool flag = true;
	int x = 0, y = 0;
	for(int i = 0; i < n; i++){
		int k;
		cin >> k;
		if(k == 1){
			flag = false;
			y--;
		}
		if(flag == true){
			x++;	
		}else{
			y++;
		}
	}
	int ansx, ansy;
	if((x + y) % (k - 1) == 0){
		cout << (x + y) / (k - 1) << endl;
	}else{
		cout << (x + y) / (k - 1) + 1 << endl;
	}
	

	return 0;
}

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>;
 
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(2000005);

long long g(long long r, long long c) {
  return comb(r + c + 2, r + 1).x;
}

int main() {
    long long r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    --r1;
    --c1;

    long long result = g(r2,c2);
    result = (result + g(r1,c1)) % mod;
    result += mod - g(r1,c2);
    if (result >= mod) result -= mod;
    result += mod - g(r2,c1);
    if (result >= mod) result -= mod;

    cout << result << endl;
    return 0;
}


Measured memory_bytes: 31488
#include<iostream>
#include<cmath>
#include <vector>
#include <string.h>
#include <algorithm>
using namespace std;


int main(){
  	string s;
  int k;
	cin>>s;
	if(s.length()!=6) k=0;
  	if(s[2]==s[3] && s[4]==s[5]) k=1;
  else k=0;
  	if(k==0) cout<<"No";
  else cout<<"Yes";
	return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n, m = mi()
    # 1-index
    k = [None]
    for _ in range(m):
        a, _ = mi()
        k.append([a, lmi()])

    d = 2 ** n
    dp = [[0] * d for _ in range(m + 1)]
    for j in range(1, d):
        dp[0][j] = inf
    for j in range(1, d):
        for i in range(1, m + 1):
            cost = k[i][0]
            able_to_open = k[i][1]
            mask = 0b0
            for num in able_to_open:
                mask |= (1 << (num - 1))
            # print(bin(mask))
            mask = ~mask
            # print(bin(mask))
            j_prime = j & mask
            dp[i][j] = min(dp[i-1][j], dp[i-1][j_prime] + cost)
    # print(dp)
    print(dp[m][d-1]) if dp[m][d-1] != inf else print(-1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 171528
C = [[0]*3 for _ in range(3)]
for i in range(3):
  C[i] = list(map(int,input().split()))
  
d = [[0]*3 for _ in range(2)]
for i in range(2):
  for j in range(3):
    d[i][j] = C[i+1][j] - C[i][j]

for i in range(2):
  for j in range(2):
    if d[i][j] != d[i][j+1]:
      print("No")
      exit()

print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int prime(ll a){
  if(a==2){return 1;}
  else if(a%2==0 || a==1){return 0;}
  for(ll i=3;i*i<=a;i+=2){
    if(a%i==0){return 0;}
  }
  return 1;
}
ll gcd(ll a,ll b){
  if(a%b==0){return(b);}
  else{return(gcd(b,a%b));}
}
int main(){
  ll A,B,ans=1;
  cin>>A>>B;
  ll x=gcd(A,B);
  ll memo=x,maxx=0;
  unordered_map<ll,ll> mp;
  for(ll i=1;i*i<=memo;i++){
    while(x%i==0 && x>1 && prime(i)==1){
      x/=i;
      mp[i]++;
      maxx=max(maxx,i);
      if(x==1){break;}
    }
    if(memo%i==0 && prime(memo/i)==1 && x%(memo/i)==0){
      ans=2;
      break;
    }
  }
  for(ll i=1;i<=maxx;i++){
    if(mp[i]>0 && prime(i)==1){ans++;}
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 36624
from math import *
import sys

N = int(input())
all_input_list = [list(map(int, input().split())) for i in range(N)]
x, y, h = sorted(all_input_list, key=lambda x: x[2])[-1]
for cx in range(101):
    for cy in range(101):
        H = h + abs(cx - x) + abs(cy - y)
        for input_list in all_input_list:
            if (input_list[2] != max(H - abs(cx - input_list[0]) - abs(cy - input_list[1]), 0)):
                break
        else:
            print("%s %s %s" % (cx, cy, H))
            sys.exit(0)

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

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

int main() {
    int n;
    cin >> n;
    vector<lint> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    lint m = 0;
    lint sum = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] < m) {
            sum += m - a[i];
        } else {
            chmax(m, a[i]);
        }
    }
    cout << sum << endl;
}

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


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

	int s = 0, g = l + n - 1;
	for (int i = l; i <= g; i++) s += i;

	int ans = s;
	if (g < 0) { ans -= g; }
	else if (l > 0) { ans -= l; }
	else { ans -= 0; }

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#D
import heapq#heapqで優先度付きキューを使うことができる ...ヒープソートを用いた
n, m = map(int, input().split())
a= list(map(lambda x: int(x) * (- 1), input().split()))
heapq.heapify(a)  #優先度つきキューに移動

for i in range(m):
    tmp=heapq.heappop(a) * -1  #最大値の取り出し
    tmp //= 2
    heapq.heappush(a, -1 * tmp) #値の挿入(全体が-1倍になっているので注意)
print(sum(a)*-1)



Measured memory_bytes: 20468
N=int(input())
l=[]
for i in range(N):
    S,P=map(str,input().split())
    b=' '
    if len(S)<10:
        S=S+b*(10-len(S))
    P=(100-int(P))
    l.append([S+str(P).zfill(3),i])
l.sort()

for i in range (N):
    print(l[i][1]+1)

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

int main() {
  string s;
  cin >> s;
  vector<int> count(3);
  for(int i=0;i<s.size();i++) {
    count[s[i]-'a']++;
  }
  sort(count.begin(), count.end());
  if((count[0] == count[1] && count[1] == count[2]) || (count[0] == count[1] && count[1]+1 == count[2]) || (count[0]+1 == count[1] && count[1] == count[2])) cout << "YES" << endl;
  else cout << "NO" << endl; 
}

Measured memory_bytes: 512
#include <stdio.h>
int main(){
  int a;
  int b;
  int c;
  scanf("%d %d %d", &a, &b, &c);
    if(a < b){
      if(b < c)
      printf("Yes\n");
      else
      printf("No\n");
    }
    else {
      printf("No\n");
    }
    return 0;
}
    

Measured memory_bytes: 580
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) throws FileNotFoundException {

//    Scanner cin = new Scanner(new FileReader("input.txt"));
    Scanner cin = new Scanner(System.in);

    int n = cin.nextInt();
    int x = cin.nextInt();

    int len = 0;
    int count = 1;

    int[] bounce = new int[n+1];

    for (int i=1;i<=n;i++) {
      bounce[i] = bounce[i-1] + cin.nextInt();
    }

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

      if (bounce[i]>x) {
        System.out.println(i);
        return;
      }

    }

    System.out.println(i);

  }

}

Measured memory_bytes: 25172
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <iomanip>
#include <bitset>
using namespace std;
int main()
{
    int n;
    char c;
    cin>>n;
    bool flag=false;
    for(int i=0;i<110;i++){
        cin>>c;
        if(c=='Y') flag=true;
    }
    if(flag==true) puts("Four");
    else puts("Three");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int kou,sou=114514,H,W;
int main(){
    cin>>H>>W;
    char HW[H][W];
    for(int i=0;i<H;i++){ for(int o=0;o<W;o++){ scanf(" %c",&HW[i][o]); }}
    for(int i=1;i<H-1;i++){
        for(int j=1;j<H-i;j++){
            kou=0;
            for(int o=0;o<i;  o++){ for(int f=0;f<W;f++){ if(HW[o][f]!='W'){kou++;} } }
            for(int o=i;o<i+j;o++){ for(int f=0;f<W;f++){ if(HW[o][f]!='B'){kou++;} } }
            for(int o=i+j;o<H;o++){ for(int f=0;f<W;f++){ if(HW[o][f]!='R'){kou++;} } }
            sou=min(sou,kou);
        }
    }
    cout<<sou<<endl;
}

Measured memory_bytes: 3148
(h,w,k)=gets.split.map(&:to_i)
a=ARGF.map{|s|s.chomp}
#p a
t=0
(0...2**h).each{|hs|
    (0...2**w).each{|ws|
        t2 =0
          (0...h).select{|hi| (hs>>hi) % 2 == 1}.each{|hi|
              (0...w).select{|wi| (ws>>wi) % 2 == 1}.each{|wi| 
                  t2 += 1 if a[hi][wi] == "#" 
                  }
              }
        t+=1 if t2 == k
        }
}

print t

Measured memory_bytes: 14392
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int main() {
    fastio();

    int m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;

    if (m1 != m2) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import numpy as np
import math
import fractions

class KyoPro:
    @staticmethod
    def ReadNumbers():
        return list(map(int, input().split()))

    @staticmethod
    def MakeStringFromNumbers(a):
        if len(a) == 0:
            return
        s = str(a[0])

        for i in range(1, len(a)):
            s += ' ' + str(a[i])
        
        return s

def main():
    n = int(input())
    a = KyoPro.ReadNumbers()

    a.sort()
    a.reverse()

    count = 0
    ans = 0
    for i in range(3 * n):
        if(i % 2 == 1):
            ans += a[i]
            count += 1
        if(count == n):
            break
    
    print(ans)

    

main()

Measured memory_bytes: 47076
import numpy as np
n,w=map(int,input().split())
 
dp=np.zeros(w+1,np.int64)
for i in range(n):
    w,v = map(int,input().split())
    dp[w:] = np.maximum(dp[w:], dp[:-w] + v)
    
print(np.max(dp))

Measured memory_bytes: 15472
#include<iostream>
#define MAX 20000000
#define ll long long 
using namespace std;

struct Data{
  int D;
  ll P;
};

struct Data D_P[MAX];
struct Data L[MAX/2+2],R[MAX/2+2];

void merge(int n,int left,int mid,int right){
  int n1=mid-left;
  int n2=right-mid;
  for(int i=0;i<n1;i++) L[i]=D_P[left+i];
  for(int i=0;i<n2;i++) R[i]=D_P[mid+i];
  L[n1].P=R[n2].P=MAX;
  int i=0,j=0;
  for(int k=left;k<right;k++){
    if(L[i].P<=R[j].P) D_P[k]=L[i++];
    else D_P[k]=R[j++];
  }
}

void mergeSort(int n,int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(n,left,mid);
    mergeSort(n,mid,right);
    merge(n,left,mid,right);
  }
}

int main(){
  int N;
  ll M,ans;  
  
  while(1){
    ans=0;
    cin>>N>>M;
    if(N+M==0)break;

    for(int i=0;i<N;i++)D_P[i].D=D_P[i].P=0;
    
    for(int i=0;i<N;i++){
      cin>>D_P[i].D>>D_P[i].P;
    }

    mergeSort(N,0,N);

    // for(int i=0;i<N;i++) cout<<D_P[i].D<<" "<<D_P[i].P<<endl;
    
    for(int i=N-1;i>=0;i--){
      if(D_P[i].D<M) M-=D_P[i].D;
      else if(M<=D_P[i].D&&M!=0){
	D_P[i].D-=M;
	M=0;
	ans+=D_P[i].P*D_P[i].D;
      }else if(M==0){
	ans+=D_P[i].P*D_P[i].D;
      }
      //if(M<0)  cout<<<<M<<endl;
    }
    //    cout<<"A"<<endl;
    cout<<ans<<endl;
  }
  
  return 0;
}

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

int main(){
    int r,g,b,n; cin >> r >> g >> b >> n;
    int c = 0;
    for(int i = 0; i <= n/r; i++){
        for(int j = 0; j <= n/g; j++){
            int l = n-(i*r + j*g);
            if(l%b == 0 && l >= 0) c++;
        }
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e9;
const int mod=1e9+7;
const ll maxx=1e18;
ll s;
ll Sqrt(ll x)
{
    ll l=sqrt(x),r=sqrt(x)+1;
    return r*r<=x?r:l;
}
int main()
{
    scanf("%lld",&s);
    if(s==maxx)
    {
        printf("0 0 1000000000 0 0 1000000000");
        return 0;
    }

    if(s<=maxn)
    {
        printf("0 0 1 0 0 %d",s);
        return 0;
    }
    ll x=Sqrt(s);
    x+=1;
    if(x>maxn)
        x=maxn;
    ll t=x;
    x=x*x-s;
    printf("0 0 %lld %lld 1 %lld",t,x,t);
    return 0;
}


Measured memory_bytes: 256
n,m = map(int, raw_input().split())
A = []
B = []

for i in range(n):
        A.append(map(int, raw_input().split()))
for i in range(m):
        B.append(input())

for i in range(n):
        answer = 0
        for j in range(m):
                answer += A[i][j] * B[j]
        print answer

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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

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

  for ( int i = 0; i < 10; i++ ) {
    c = a*c - b;
    cout << c << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
//typedef __int64 LL;
typedef vector<int> ivec;
typedef vector<string> svec;

const int MOD=1000000007;

int a[100010];
int main(){
	int n;
	int a,b;
	bool flag=false;
	cin>>n>>a>>b;
	for(int i=a;i<=b;i++)
	{
		if(i%n==0)
		{
			flag=true;
			break;
		}
	}
	if(flag)cout<<"OK"<<endl;
	else cout<<"NG"<<endl;
	
	return 0;
}

Measured memory_bytes: 3624
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Dynamic;
using System.Linq;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;

namespace atcorder
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            int N = S.Length;
            // Sの1文字目から(N-1)/2までが回文
            // (N+3)/2から最後の文字までが回文
            int a = (N - 1) / 2;
            int b = (N + 3) / 2;
            string s1 = S.Substring(0, a);
            string s2 = S.Substring(b-1);
            
            char[] rev1 = s1.ToArray();
            char[] rev2 = s2.ToArray();
            char[] rev3 = S.ToArray();
            Array.Reverse(rev1);
            Array.Reverse(rev2);
            Array.Reverse(rev3);
            if (S == new string (rev3) && s1 == new string (rev1) && s2 == new string (rev2))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


//文字配列の取得
//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];

//文字列の取得
//string s = Console.ReadLine();

//数字配列の取得
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];

//数字の取得
//int N = int.Parse(Console.ReadLine());

//リスト型(int)の取得
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());

//出力
//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.WriteLine(cnt);



Measured memory_bytes: 26192
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
const Int MAX = 2020;
Int dp[MAX][MAX];
const Int MOD = 1e9+7;
Int ri[MAX][27],le[MAX][27];;
Int n;
string s;
Int dfs(Int l,Int r){
  if(~dp[l][r]) return dp[l][r];
  Int &res=dp[l][r];
  res=1;
  for(Int i=0;i<26;i++){
    if(ri[l][i]<r&&le[r][i]>l){
      res++;
      if(ri[l][i]<le[r][i]) res+=dfs(ri[l][i],le[r][i]);
      res%=MOD;
    }
  }
  return res;
}

signed main(){
  cin>>s;
  s=char('a'+26)+s+char('a'+26);
  n=s.size();
  for(Int i=0;i<n;i++) s[i]-='a';
  memset(dp,-1,sizeof(dp));
  for(Int i=0;i<27;i++) ri[n-1][i]=n,le[0][i]=-1;
  for(Int i=n-2;i>=0;i--){
    for(Int j=0;j<27;j++){
      if(s[i+1]==j) ri[i][j]=i+1;
      else ri[i][j]=ri[i+1][j];
    }
  }
  for(Int i=1;i<n;i++){
    for(Int j=0;j<27;j++){
      if(s[i-1]==j) le[i][j]=i-1;
      else le[i][j]=le[i-1][j];
    }
  }
  cout<<(dfs(0,n-1)+MOD-1)%MOD<<endl;
  return 0;
}



Measured memory_bytes: 35980
char_to_ind = dict()
ind_to_char = dict()
for i, char in enumerate("ABCDEFGHIJKLMNOPQRSTUVWXYZ"):
    char_to_ind[char] = i
    ind_to_char[i] = char


def solve(n, s):
    return "".join([ind_to_char[(char_to_ind[c] + n) % 26] for c in s])


def main():
    n = int(input())
    s = input()
    res = solve(n, s)
    print(res)


def test():
    assert solve(2, "ABCXYZ") == "CDEZAB"
    assert solve(0, "ABCXYZ") == "ABCXYZ"
    assert solve(13, "ABCDEFGHIJKLMNOPQRSTUVWXYZ") == "NOPQRSTUVWXYZABCDEFGHIJKLM"


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 3064
A,B = map(int,input().split())

def solve(x):
    
    if x < 0:
        return 0
    
    if x % 4 == 0:
        return x
    elif x % 4 == 1:
        return 1
    elif x % 4 == 2:
        return x+1
    elif x % 4 == 3:
        return 0
    
print(solve(A-1)^solve(B))

Measured memory_bytes: 3060
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int n;
    vector<pair<string,int>>AA;
    R(n);
    REP(i,n){
        string s;
        int t;
        R(s,t);
        AA.PB({s,t});
    }
    string s;
    R(s);
    bool st=0;
    int an=0;
    REP(i,n){
        if(st)an+=AA[i].S;
        if(AA[i].F==s)st=1;
    }
    W(an);
    return 0;
}


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

int main()
{
    string s;
    cin >> s;
    int ab = s.length();
    int i = 0;
    int j = (ab - 1) / 2 - 1;
    bool num1 = true, num2 = true;
    while (i < j)
    {
        if (s[i] != s[j])
        {
            num1 = false;
        }
        i++;
        j--;
    }
    int k = (ab + 3) / 2 - 1;
    int l = ab - 1;
    while (k < l)
    {
        if (s[k] != s[l])
        {
            num2 = false;
        }
        k++;
        l--;
    }
    int p = 0;
    int q = ab-1;
    bool num3 = true;
    while(p<=q){
        if(s[p] != s[q]){
            num3 = false;
        }
        p++;
        q--;
    }


    if (num1 && num2 && num3)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

using C = complex<double>;
double pi = acos(-1.0);

void FFT(vector<C>& A, bool inv) {
 int N=A.size();
 for(int i=0,j=0; j<N; j++){
  if(i<j) swap(A[i],A[j]);
  for(int k=N>>1; k>(i^=k); k>>=1);
 }
 for(int i=1; i<N; i<<=1){
  rep(j,i){
   C q = C(cos(pi/i*j),sin(pi/i*j)*(inv?1.0:-1.0));
   for(int k=j; k<N; k+=i*2){
    C l=A[k], r=A[k+i]*q;
    A[k]=l+r;
    A[k+i]=l-r;
   }
  }
 }
 if(inv) rep(i,N) A[i]/=N;
}

vector<C> CONV(const vector<C>& A,const vector<C>& B) {
 int Z=1; while(Z<A.size()+B.size()) Z<<=1;
 vector<C> Ax(Z),Bx(Z);
 rep(i,Z) Ax[i]=Bx[i]=0;
 rep(i,A.size()) Ax[i]=A[i];
 rep(i,B.size()) Bx[i]=B[i];
 FFT(Ax,false);
 FFT(Bx,false);
 rep(i,Z) Ax[i]*=Bx[i];
 FFT(Ax,true);
 return move(Ax);
}

const ULL M=200003;
int N;
ULL I[M];
vector<C> A;
vector<C> V;

int main() {
 scanf("%d", &N);
 for (int i=0,j=1; i<M-1; i++,j=j*2%M) I[j]=i;
 A.resize(M-1);

 ULL sq=0;
 rep(i, N) {
  int a; scanf("%d",&a);
  if(a) A[I[a]] += C(1.0,0.0);
  sq += (ULL)a*a%M;
 }
 V = CONV(A,A);

 ULL ans=0;
 for (int i=0,j=1; i<V.size(); i++,j=j*2%M)
  ans += (ULL)(V[i].real()+0.5)*j;
 ans = (ans-sq)/2;

 cout<<ans<<endl;

 return 0;
}


Measured memory_bytes: 24356
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("Ofast")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;
using ull = unsigned long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string & str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int n;
	ll k, x = 0;
	scanf("%d%lld", &n, &k);
	vector<ll> a(n);
	rep(i, n)scanf("%lld", &a[i]);
	vector<int> bit(64);
	rep(i, n) {
		rep(j, 60) {
			if (a[i] & (1LL << j))++bit[j];
		}
	}
	for (int i = 60; i >= 0; --i) {
		if (2 * bit[i] < n and x + (1LL << i) <= k)x += (1LL << i);
	}
	ll ans = 0;
	rep(i, n)ans += a[i] xor x;
	printf("%lld\n", ans);

	Please AC;
}

Measured memory_bytes: 4068
#include <stdio.h>
#include <math.h>
int main(int argc, const char * argv[]) {
    double a,b,C,c,p=3.14159265;
    double S,L,h;
    scanf("%lf %lf %lf",&a,&b,&C);
    c=C/180*p;
    S=0.5*a*b*sin(c);
    L=a+b+sqrt((a*a)+(b*b)-(2*a*b*cos(c)));
    h=2*S/a;
    printf("%f\n",S);
    printf("%f\n",L);
    printf("%f\n",h);
    return 0;
}

Measured memory_bytes: 648
#include<stdio.h>
#include<string.h>

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }

int find(char str[]){
  long long key, i, h;
  key = getKey(str);
  for ( i = 0;; i++){
    h = (h1(key)+i*h2(key))%M;
    if( strcmp(H[h],str) == 0 ) return 1;
    else if ( strlen(H[h]) == 0 ) return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key, i, h;
  key = getKey(str);
  for ( i = 0; ; i++ ){
    h = (h1(key)+i*h2(key))%M;
    if( strcmp(H[h],str) == 0 ) return 1;
    else if ( strlen(H[h]) == 0 ){
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}

main(){
  int i, n, h;
  char str[L], com[9];
  for ( i = 0; i < M; i++ ) H[i][0] = '\0';
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ){
    scanf("%s %s", com, str);

    if ( com[0] == 'i' ){
      if (insert(str)){

      }
    } else {
      if (find(str) ){
	printf("yes\n");
      } else {
	printf("no\n");
      }
    }
  }
  return 0;
}



Measured memory_bytes: 16016