akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define REPE(i, a, b) for (int i = (a); i <= int(b); ++i)
#define SZ(x) ((int)(x).size())
#define ALL(x) x.begin(), x.end()
#define PB push_back
#define EB emplace_back
using LL = long long;
using PII = pair<int, int>;
#define F first
#define S second

int d[110][110];
array<int, 3> e[10010];

int n, m;
const int inf = 1e9;

int main() {
  scanf("%d%d", &n, &m);
  REPE(i, 1, n) REPE(j, 1, n)
    d[i][j] = i == j ? 0 : inf;
  REP(i, m) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    e[i] = {u, v, w};
    d[u][v] = d[v][u] = w;
  }
  REPE(k, 1, n) REPE(i, 1, n) REPE(j, 1, n)
    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  int ans = 0;
  REP(i, m) {
    ans += d[e[i][0]][e[i][1]] != e[i][2];
  }
  printf("%d\n", ans);
  return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;
struct Node {
    int key;
    Node *right, *left, *parent;
};
Node *root, *NIL;
Node *find(Node *u, int k) {
    while (u != NIL&&k != u->key) {
        if (k < u->key)u = u->left;
        else u = u->right;
    }
    return u;
}
void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;
    z = (Node *)malloc(sizeof(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;
    }
    return;
}
void inorder(Node *u) {
    if (u == NIL)return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
    return;
}
void preorder(Node *u) {
    if (u == NIL)return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
    return;
}
int main() {
    int n, i, x;
    string com;
    cin >> n;
    for (i = 0; i < n; i++) {
        cin >> com;
        if (com[0] == 'f') {
            cin >> x;
            Node *t = find(root, x);
            if (t != NIL)puts("yes");
            else puts("no");
        }
        else if (com == "insert") {
            cin >> x;
            insert(x);
        }
        else if (com == "print") {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 22032
[a,b,c,d] = [int(x) for x in input().split()]

alice = [False] * 101
bob = [False] * 101

for i in range(a,b):
    alice[i] = True

for i in range(c,d):
    bob[i] = True

ans = sum([x and y for x, y in zip(alice, bob)])
print(ans)

Measured memory_bytes: 3068
#include<iostream> 
#include<string> 
#include<vector> 
#include<algorithm> 
#include<cmath>
#include<set>
#include<utility>

using namespace std;


int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if ((c - b) % 2 == 0)
	{
		cout << "Alice" << endl;
	}
	else
	{
		cout << "Borys" << endl;
	}

}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var a, b, n int
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &n, &a, &b)

	ans := (b-a)*(n-2) + 1
	if ans < 1 {
		fmt.Println(0)
	} else {
		fmt.Println(ans)
	}
}


Measured memory_bytes: 1840
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
x = []
y = []
c = []

while True:
  try:
    tmp1,tmp2,tmp3 = map(int,input().split())
    x.append(tmp1)
    y.append(tmp2)
    c.append(tmp3)
  except:
    break
    
not_use = min(a) + min(b)

ansList = [not_use]
for i in range(M):
  tmp = a[x[i]-1] + b[y[i]-1] - c[i]
  ansList.append(tmp)
ans = min(ansList)
print(ans)


Measured memory_bytes: 27848
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pw(x) (1ll << (x))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(l);i<(r);++i)
#define per(i,l,r) for(int i=(r)-1;i>=(l);--i)
#define dd(x) cout << #x << " = " << (x) << ", "
#define de(x) cout << #x << " = " << (x) << "\n"
#define endl "\n"

//-----
const int N = 1e3 + 7;
int cnt[N];
vi v[N];
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int n; string s;
	cin >> n >> s;
	rep(i, 0, sz(s)) v[s[i] - 'a'].pb(i);
	rep(i, 0, 26) if (!v[i].empty()) 
		rep(j, v[i][0], v[i].back()) cnt[j]++;
	cout << *max_element(cnt, cnt + sz(s));

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,c=1;
    cin>>t;
    vector<string>s(t);
    for(int i=0;i<t;i++)
    {
        cin>>s[i];
    }
    sort(s.begin(),s.end());
    for(int i=0;i<t-1;i++)
    {
        if(s[i]!=s[i+1])
            c++;
    }
    cout<<c<<endl;


}


Measured memory_bytes: 9520
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pf push_front
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;
const int MAX = 1e5+5;
int N, a[MAX];
ll pd[MAX];

ll solve() {
	pd[2] = abs(a[2] - a[1]);
	REP(i, 3, N) {
		pd[i] = pd[i-1]+abs(a[i]-a[i-1]);
		pd[i] = min(pd[i], pd[i-2]+abs(a[i]-a[i-2]));
	}
	return pd[N];
}

int main(int argc, char ** argv) {
	scanf("%d", &N);
	REP(i, 1, N) scanf("%d", &a[i]);
	printf("%I64d\n", solve());
	return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define fs first
#define sc second
#define mp make_pair
using namespace std;
typedef double D;
typedef pair<D,int> pii;

int main(){
  int h,w;
  string f[999];
  cin.tie(0);
  std::ios::sync_with_stdio(0);
  cin >> h >> w;

  vector<pii> v;
  rep(i,h){
    cin >> f[i];
    rep(j,w){
      if( i==0?f[i][j]=='#':f[i][j]!=f[i-1][j] ){
	v.push_back(mp((D)(h-i)/j,-1));
	v.push_back(mp((D)(h-i)/(j+1),1));
      }
      if( j==w-1?f[i][j]=='#':f[i][j]!=f[i][j+1] ){
	v.push_back(mp((D)(h-i)/(j+1),-1));
	v.push_back(mp((D)(h-i-1)/(j+1),1));
      }
    }
  }

  int res = 0, tmp = 0;
  sort(v.begin(),v.end());
  rep(i,v.size())res = max(res,tmp += v[i].sc);
  cout << (res+3)/2 << endl;
}

Measured memory_bytes: 19280
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
// #define int ll
using namespace std;
const int INF (1 << 30);
const ll LLINF (1LL << 55LL);
const int MOD = 1000000007;
const int MAX = 510000;
const double pi=3.14159265358979;

ll fac[MAX], finv[MAX], inv[MAX];
ll POW[MAX];

ll extgcd(ll a, ll b, ll& x, ll& y){
    ll d=a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }
    else{
        x=1;y=0;
    }
    return d;
}

void POWinit(){
    POW[0]=0;
    POW[1]=1;
    for(ll i=2;i<MAX;i++){
        POW[i]=POW[i-1]*i;
        POW[i]%=MOD;
    }
}


// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll mod_inverse(ll a,ll mod){
    ll x,y;
    extgcd(a,mod,x,y);
    return (mod+x%mod)%mod;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k,ans[1010]={},res=0;
    cin>>n>>k;
    COMinit();
    POWinit();
    ans[1]=1;
    rep2(i,2,k+1){
        ans[i]=1;
        rep(j,n){
            ans[i]*=i;
            ans[i]%=MOD;
        }
        rep2(j,1,i){
            ans[i]-=COM(i,j)*ans[j]%MOD;
            ans[i]%=MOD;
            if(ans[i]<0) ans[i]+=MOD;
        }
    }
    // cout<<ans[k]<<endl;
    rep2(i,1,k+1){
        res+=ans[i] * mod_inverse(POW[i],MOD) %MOD;
        res%=MOD;
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 19116
#include <bits/stdc++.h>
using namespace std;
    int dr[4] = { -1, 0, 1, 0 };
    int dc[4] = { 0, 1, 0, -1 };
    int cost[100][100];
    char x[25][25];
    int n, m;
    void BFS(int r, int c) {
    	queue<pair<int, int> > q;
    	q.push(make_pair(r, c));
    	memset(cost, -1, sizeof(cost));
    	cost[r][c] = 0;
    	while (!q.empty()) {
    		r = q.front().first;
    		c = q.front().second;
    		q.pop();
    		for (int i = 0; i < 4; ++i) {
    			int nr = r + dr[i];
    			int nc = c + dc[i];
    			if (nr >=n || nc >= m || nc < 0 || nr < 0 || cost[nr][nc] != -1 || x[nr][nc]=='#')
    				continue;
    			cost[nr][nc] = cost[r][c] + 1;
    			q.push(make_pair(nr, nc));
    		}
    	}
    }
int main(){
    cin>>n>>m;
    for(int i=0;i<n;i++){ 
        for(int j=0;j<m;j++){ 
            cin>>x[i][j];
        } 
    } 
    int ans=-1;
    for(int i=0;i<n;i++){ 
        for(int j=0;j<m;j++){ 
            if(x[i][j]=='.'){
                BFS(i,j);
                
               for(int k=0;k<n;k++){ 
                  for(int w=0;w<m;w++){
                         if(x[k][w]=='.'&&cost[k][w]!=-1){ 
                             ans=max(ans,cost[k][w]);
                             //cout<<i<<" "<<j<<" "<<k<<" "<<w<<" "<<cost[k][w]<<endl; 
                         }
                  } } } } } 
            
            cout<<ans<<'\n';
    
    
    
    
    
    
    
    
    
    
    return 0;
}


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

#define ll long long
#define endl "\n"
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define f first
#define s second
#define vecll vector<ll>
#define pairll pair<ll,ll>
#define vecpairll vector<pair<ll,ll>>
#define mapllll map<ll,ll>
#define mapstrll map<string,ll>
#define mapllvecll map<ll,vecll>
#define setll set<ll>
#define fio ios_base::sync_with_stdio (false); cin.tie (NULL); cout.tie(NULL);

using namespace std;

ll const N=1e5+5;
ll const inf=1e18+5;
ll const MOD=1e9+7;

ll t,n,m,x,y,z,w,k;

int main()
{
    fio

    ll tmp[3][3];
    tmp[0][1] = 2;
    tmp[1][0] = 2;
    tmp[0][2] = 1;
    tmp[2][0] = 1;
    tmp[1][2] = 0;
    tmp[2][1] = 0;

    string str;
    cin>>n>>str;

    ll a[n];
    for(ll i=0;i<n;i++)
    {
        if(str[i] == 'R')       a[i] = 0;
        else if(str[i] == 'G')  a[i] = 1;
        else                    a[i] = 2;
    }

    ll cnts[3][n];
    memset(cnts,0,sizeof cnts);

    for(ll i=0;i<n;i++)
        cnts[a[i]][i]++;

    for(ll i=1;i<n;i++)
    {
        cnts[0][i] += cnts[0][i-1];
        cnts[1][i] += cnts[1][i-1];
        cnts[2][i] += cnts[2][i-1];
    }

    ll ans = 0;
    for(ll i=1;i<(n-1);i++)
    {
        for(ll j=i+1;j<n;j++)
        {
            if(a[i] == a[j])    continue;
            ll v = tmp[a[i]][a[j]];

            ans += cnts[v][i];

            ll ind = i-(j-i);
            if(ind>=0 && a[ind] == v)   ans--;
        }
    }

    cout<<ans;
    return 0;
}



Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  bool odd=false;
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(a[i]%2==1){
      odd=true;
    }
  }
  if(odd){
    cout << "first" << endl;
  }
  else{
    cout << "second" << endl;
  }
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;

namespace College
{
    class Program
    {
        static string Join(int[] input)
        {
            string result = "";
            foreach(int i in input)
                result += (" " + i.ToString());
            return result;
        }

        static void Main(string[] args)
        {
            List<List<int[]>> college = new List<List<int[]>>();

            for(int i = 0; i < 4; i++)
            {
                college.Add(new List<int[]>());
                for(int j = 0; j < 3; j++)
                {
                  college[i].Add(new int[10]);
                  for(int k = 0; k < 10; k++)
                      college[i][j][k] = 0;
                }          
            }

            int limit = int.Parse(Console.ReadLine());

            for(int i = 0; i < limit; i++)
            {
                int[] _c = Console.ReadLine().Split(' ').Select(e => int.Parse(e)).ToArray();
                college[_c[0] - 1][_c[1] - 1][_c[2] - 1] = college[_c[0] - 1][_c[1] - 1][_c[2] - 1] + _c[3];
            }

            for(int j = 0; j < college.Count; j++)
            {
                List<int[]> b = college[j];
                foreach(int[] r in b)
                    Console.WriteLine(Join(r));
                if(j != college.Count - 1)
                    Console.WriteLine(new string('#', 20));
            }
        }
    }
}

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

using namespace std;

int main(void) {
    int N, M, C;
    cin >> N >> M >> C;
    vector<int> B(M);
    for_each(begin(B), end(B), [](auto &e) {
        cin >> e;
    });
    vector<vector<int>> A(N, vector<int>(M));
    for_each(begin(A), end(A), [](auto &a) {
        for_each(begin(a), end(a), [](auto &e) {
            cin >> e;
        });
    });

    int ans = 0;
    for (auto a : A) {
        int sum = C;
        for (int i = 0; i < M; i++) {
            sum += a[i] * B[i];
        }
        if (sum > 0) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	_, a := readLengthAndSlice()

	c := make([]int, 4)
	for i := range a {
		c[a[i]%4]++
	}
	c13 := c[1] + c[3]
	if c[2] == 0 {
		if c[0] == 0 {
			println("No")
			return
		}
		if c13 <= c[0]+1 {
			println("Yes")
		} else {
			println("No")
		}
	} else {
		if c[0] == 0 {
			if c13 == 0 {
				println("Yes")
			} else {
				println("No")
			}
		} else {
			if c13 <= c[0] {
				println("Yes")
			} else {
				println("No")
			}
		}
	}
}

// -----------------------------------------------------------------------------

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}


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

int vis[26];

int main(){
	string s; cin >> s;
	if (s.length() < 26){
		for (int i = 0; i < s.length(); i++){
			vis[s[i] - 'a']++;
		}
		for (int i = 0; i < 26; i++){
			if (vis[i]) continue;
			cout << s << char(i + 'a') << endl;
			return 0;
		}
	}
	for (int i = s.length() - 1; i >= 0; i--){
		int pos = -1;
		for (int j = i + 1; j < s.length(); j++){
			if (s[j] > s[i] && (pos == -1 || s[pos] > s[j])) pos = j;
		}
		if (pos == -1) continue;
		for (int j = 0; j < s.length(); j++){
			if (j >= i) continue;
			cout << s[j];
		}
		cout << s[pos] << endl;
		return 0;
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 256
x = list(map(int,input().split()))
x.sort()
ans=0
while not x[0]==x[1]==x[2]:
    if x[0]%2 != x[1]%2:
        x[1]+=1
        x[2]+=1
        ans+=1
    elif x[1]!=x[2]:
        x[0]+=1
        x[1]+=1
        ans+=1 
    else:
        x[0]+=2
        ans+=1
print(ans)


Measured memory_bytes: 3060
#整数の入力
N,K = map(int, input().split())

d_list = []
A_list_list = []
for i in range(K):
  #整数の入力
  d = int(input())
  d_list.append(d)
  #スペース区切りの整数の入力リスト
  A_list = list(map(int, input().split()))
  #print(A_list)
  A_list_list.extend(A_list)
#print(A_list)
counter = 0
for i in range(N):
  if((i+1 in A_list_list) ==True):
    counter = counter
  else:
    counter = counter + 1
print(counter)

Measured memory_bytes: 9140
import math
N = input()
l = len(N)
N =int(N)
a = b  =0
# def up(num):
    #100098,1 →110000
    #100098,2 → 101000
    #
MAX = 10 ** 9
for i in range(0,19):
    juu = 10 ** i
    dived = math.ceil(N / juu)
    # print(dived * juu)
    x1 = dived
    y2 = juu
    x2 = dived * juu - N
    y1 = 1

    # print(c,d,e,f)
    if MAX >= x1 >= 0 and MAX >= x2 >= 0 and MAX >= y1 >= 0 and MAX >= y2 >= 0 :
        print(a, b, x1, y1, x2,y2)
        exit(0)
    #







Measured memory_bytes: 38384
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
k = na()
k = sorted(k)
m = n//2

print(k[m]-k[m-1])

Measured memory_bytes: 52636
#include<stdio.h>
int main(void)
{
	int t,n,s,f;
	int i,sum,aum;
	while(1){
		scanf("%d",&t);
		if(t==0){
			break;
		}
		sum=0;
		scanf("%d",&n);
		for(i=1;i<=n;i++){
			scanf("%d",&s);
			scanf("%d",&f);
			aum=f-s;
			sum=sum+aum;
		}
		if(t<=sum){
			printf("OK\n");
		}
		else{
			printf("%d\n",t-sum);
		}
	}
	return 0;
}


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

const int N=100100;
typedef long long ll;
pair<int,int>a[N];
int n;
ll ans[N];
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;++i)cin>>a[i].first,a[i].second=i;
	sort(a+1,a+n+1);
	for(int i=n,mn=a[n].second;i;--i){
		ans[mn]+=(ll)(a[i].first-a[i-1].first)*(n-i+1);
		mn=min(mn,a[i-1].second);
	}
	for(int i=1;i<=n;++i)cout<<ans[i]<<'\n';
	return 0;
}


Measured memory_bytes: 2688
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>

#define MODULE 
#define RAND(min,max) (rand()%(max-min+1)+min)
#define LOGI(log) printf("\n%d\n",log);
#define LOGS(log) printf("\n%s\n",log);
#define DEBUG() {printf("\nDEBUG %d\n",num_debug);num_debug++;}
char num_debug = 0;

int main(void) {
	srand((unsigned)time(NULL));

	unsigned int N, A[200000];
	unsigned int u = 0;

	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%u", &A[i]);
		u ^= A[i];
	}

	for (int i = 0; i < N; i++) {
		printf("%u ", A[i] ^ u);
	}

	return 0;
}

Measured memory_bytes: 3308
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter

private val MOD = 1000000007L

fun solve() {
    val n = inf.readLine()!!.toInt()
    val a = inf.readLine()!!.zip(inf.readLine()!!).map { arrayOf(it.first, it.second) }.toTypedArray()
    val dp = Array(n) { Array(3) { LongArray(3) } }
    for (i in 0..2) {
        for (j in 0..2) {
            if ((i == j) == (a[0][0] == a[0][1])) dp[0][i][j] = 1L
        }
    }
    for (i in 1 until n) {
        for (j in 0..2) {
            for (j1 in 0..2) if ((j == j1) == (a[i][0] == a[i - 1][0])) {
                for (k in 0..2) if ((j == k) == (a[i][0] == a[i][1])) {
                    for (k1 in 0..2) if ((k == k1) == (a[i][1] == a[i - 1][1])) {
                        dp[i][j][k] = (dp[i][j][k] + dp[i - 1][j1][k1]) % MOD
                    }
                }
            }
        }
    }
    println(dp[n - 1].fold(0L) { q, w -> (q + w.sum()) % MOD })
}

fun main(args: Array<String>) {
    solve()
    ouf.close()
}

val inf = BufferedReader(InputStreamReader(System.`in`))
val ouf = PrintWriter(System.out)

Measured memory_bytes: 33856
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int f(string s){
    int ret = 0;
    rep(i,s.size()){
        ret+=s[i]-'0';
    }
    return ret;
}

int main(void) {
    int i,j;
    int n;
    cin >> n;
    int ans = INF;
    loop(i,1,n){
        int a = i;
        int b = n-i;
        ans = min(ans, f(to_string(a))+f(to_string(b)));
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

X,Y = map(int,read().split())

MOD = 10**9 + 7

def cumprod(arr,MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
    for n in range(1,Lsq):
        arr[n] *= arr[n-1,-1]; arr[n] %= MOD
    return arr.ravel()[:L]

def make_fact(U,MOD):
    x = np.arange(U,dtype=np.int64); x[0] = 1
    fact = cumprod(x,MOD)
    x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD)
    fact_inv = cumprod(x,MOD)[::-1]
    return fact,fact_inv

U = 10**6
fact, fact_inv = make_fact(U,MOD)

if (X+Y) % 3 != 0:
    print(0)
    exit()
A = (2*X - Y) // 3
B = (2*Y - X) // 3
if A < 0 or B < 0:
    print(0)
    exit()
answer = fact[A+B] * fact_inv[A] % MOD * fact_inv[B] % MOD
print(answer)

Measured memory_bytes: 60468
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include<time.h>
#include<stdlib.h>
#define pb push_back
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define clr(x) x.clear()
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vi>
#define mp make_pair
#define hell 1000000007

using namespace std;

int main()
{
    IOS
    int n;
    cin>>n;
    int arr[n][3];
    int dp[n][3]={0};
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
            cin>>arr[i][j];
    }
    for(int j=0;j<3;j++)
        dp[0][j]=arr[0][j];
    for(int i=0;i<n-1;i++)
    {
        for(int j=0;j<3;j++)
            {
                for(int k=0;k<3;k++)
                {
                    if(k!=j)
                        dp[i+1][k]=max(dp[i+1][k],dp[i][j]+arr[i+1][k]);
                }
            }
    }
    int maxi=INT_MIN;
    for(int j=0;j<3;j++)
        maxi=max(maxi,dp[n-1][j]);
    cout<<maxi<<"\n";
    return 0;
}


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

int main(){
    int n, tmp, sum;
    cin >> n;
    tmp = n;
    while(tmp > 0){
        sum += tmp % 10;
        tmp /= 10;
    }
    if(n % sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000


int main(){

	int N;
	cin>>N;
	
	vector<int> A(N);
	
	for(int i=0;i<N;i++)cin>>A[i];
	
	multiset<int> S;
	
	for(int i=0;i<N;i++){
		auto it = S.lower_bound(A[i]);
		if(it==S.begin())S.insert(A[i]);
		else{
			it--;
			S.erase(it);
			S.insert(A[i]);
		}
	}
	
	cout<<S.size()<<endl;
	
	
	return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,s,f) for(i=s;i<f;i++)
#define print(v) for(auto &z:v) cout<<z<<' ';cout<<'\n'
#define db cout<<"db: "
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define all(v) v.B,v.E
#define sz(v) (int)((v).size())
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define clk1 clock_t start_time=clock()
#define clk2 cout<<(clock()-start_time)/(double)CLOCKS_PER_SEC
#define clean(arr) memset(arr,0,sizeof(arr))
// #define mod 1000000007
#define mod 998244353
#define space 100005
//<<fixed << setprecision(9)

int main()
{
    int n,i,j,t;
    boost;

    int k;
    cin>>n>>k;
    pii arr[k];
    rep(i,0,k)cin>>arr[i].F>>arr[i].S;
    ll dp[n+1]={0};
    ll pref[n+1]={0};
    pref[1]=dp[1]=1;
    rep(i,2,n+1)
    {
        rep(j,0,k)
        {
            int l=arr[j].F, r=arr[j].S;
            int L=i-r, R=i-l;
            if(R<=0)continue;
            L=max(L,1);
            dp[i]+= pref[R]-pref[L-1];
            dp[i]%=mod;
        }
        pref[i]=pref[i-1]+dp[i];
        pref[i]%=mod;
    }
    dp[n]+=mod;
    cout<<dp[n]%mod;
    return 0;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N;
ll A[1100];

ll f(int l, int r, std::vector<int> &instr){
    if(l == -1){
        int mx_i = std::max_element(A + 1, A + 1 + N) - A;

        for(int i=N;i>mx_i;--i){
            instr.emplace_back(i);
        }

        for(int i=0;i<mx_i-1;++i){
            instr.emplace_back(1);
        }

        return A[mx_i];
    }

    for(int i=N;i>r;--i){
        instr.emplace_back(i);
    }

    ll v = A[r];

    r -= 2;

    while(l <= r){
        if(A[r] >= 0){
            v += A[r];
            instr.emplace_back(r + 1);
        }else{
            instr.emplace_back(r);
        }

        r -= 2;
    }

    for(int i=0;i<l-1;++i){
        instr.emplace_back(1);
    }

    return v;
}

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

    std::cin >> N;

    for(int i=1;i<=N;++i){
        std::cin >> A[i];
    }

    int l1 = -1, r1 = -1, l2 = -1, r2 = -1;

    for(int i=1;i<=N;i+=2){
        if(A[i] >= 0){
            l1 = i;
            break;
        }
    }

    for(int i=N-!(N&1);i>=1;i-=2){
        if(A[i] >= 0){
            r1 = i;
            break;
        }
    }

    std::vector<int> instr1;
    ll v1 = f(l1, r1, instr1);

    for(int i=2;i<=N;i+=2){
        if(A[i] >= 0){
            l2 = i;
            break;
        }
    }

    for(int i=N-(N&1);i>=2;i-=2){
        if(A[i] >= 0){
            r2 = i;
            break;
        }
    }    
    
    std::vector<int> instr2;
    ll v2 = f(l2, r2, instr2);
    
    if(v1 < v2){
        std::swap(v1, v2);
        std::swap(instr1, instr2);
    }

    std::cout << v1 << std::endl;
    std::cout << instr1.size() << std::endl;

    for(int i : instr1){
        std::cout << i << std::endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fore(x,a,b) for(int x=a, qwerty=b; x<qwerty; x++)
#define ALL(a) (a).begin(),(a).end()
#define SZ(a) ((int)(a).size())
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define fst first
#define snd second
using namespace std;
typedef long long ll;

const int N=105;
int A, B;
char ans[N][N];

int main(){
    cin >> A >> B;
    fore(y,0,50)fore(x,0,100)ans[x][y]='.';
    fore(y,50,100)fore(x,0,100)ans[x][y]='#';
    A--; B--;
    for(int y=0; y<50; y+=2)
        for(int x=0; x<100; x+=2)if(B){
            B--;ans[x][y]='#';
        }
    for(int y=51; y<100; y+=2)
        for(int x=0; x<100; x+=2)if(A){
            A--;ans[x][y]='.';
        }
    cout << "100 100\n";
    fore(x,0,100){
        fore(y,0,100)cout<<ans[x][y];
        cout << "\n";
    }
}


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

using namespace std;

long long combination(long long n, long long k){
  long long c[n+1][n+1];
  for(long long i=0;i<=n;i++){
    for(long long j=0;j<=n;j++){
      if(i==j || j==0) c[i][j] = 1;
      else if(j>i){
        c[i][j] = 0;
      }
      else c[i][j] = c[i-1][j-1] + c[i-1][j];
    }
  }
  if(n >= k) return c[n][k];
  else return 0;
}

int main(void){
  long long N,tmp;
  long long A[200010];
  long long B[200010];
  B[0] = 1;
  long long sum=0;
  map<long long, long long> mp;
  // cin >> N;
  scanf("%lld",&N);
  for(long long i=0;i<N;i++){
    // cin >> A[i];
    scanf("%lld",&A[i]);
    mp[A[i]]++;
    //どうせnC2をしか使わないので先に計算しちゃう
    // B[i+1] = combination(i+1,2);
    //なんなら再帰計算もしない
    B[i+1] = i*(i+1)/2;
  }
  //(n-1)C2 = nC2 - (n-1)C1なので先にsumを計算してからn-1を引けばいい
  for(auto itr=mp.begin();itr!=mp.end();itr++){
    sum+=B[itr->second];
  }
  // for(auto itr=mp.begin();itr!=mp.end();itr++){
  //   cout << itr->second << "\n";
  // }
  long long ans;
  for(int k=0;k<N;k++){
    // cout << "sum:"<< sum << " mp[A[k]]" << mp[A[k]] << endl;
    ans = sum - mp[A[k]] + 1;
    printf("%lld\n",ans);
    // cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 12672
S = gets.chomp
A = S[0].to_i
B = S[1].to_i
C = S[2].to_i
D = S[3].to_i

(0...(1<<3)).each do |n|
  x = A
  x = (n&1)==0 ? x + B : x - B
  x = (n&2)==0 ? x + C : x - C
  x = (n&4)==0 ? x + D : x - D
  if x == 7
    puts "#{A}#{(n&1)==0 ? "+" : "-"}#{B}#{(n&2)==0 ? "+" : "-"}#{C}#{(n&4)==0 ? "+" : "-"}#{D}=7"
    exit
  end
end


Measured memory_bytes: 1788
#include<iostream>
#include<cstdlib>
#include<cmath>
using namespace std;
int main(void)
{
	double a,b,h,m;
	cin>>a>>b>>h>>m;
	double ans,theta1,theta2,diff;
	theta1 = (m)*6;
	theta2 = (60*h+m)/2;
    //diff = min(360 - abs(theta1 - theta2) , abs(theta1 - theta2));
	double Theta = (M_PI*abs(theta1 - theta2))/180;
	ans = sqrt(a*a + b*b - 2*a*b*cos(Theta));
	printf("%0.10lf\n",ans);
	return 0;
}


Measured memory_bytes: 4188
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 100005;

int n;
int a[N];

int main(){
	n=get();
	fo(i,1,n)a[i]=get();
	sort(a+1,a+1+n);
	int v=abs(a[n]-a[1]*2),key=a[1];
	fo(i,2,n-1)
	if (v>abs(a[n]-a[i]*2))v=abs(a[n]-a[i]*2),key=a[i];
	printf("%d %d\n",a[n],key);
	return 0;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;

namespace ABC125_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split(' ');

            int A = int.Parse(line[0]);
            int B = int.Parse(line[1]);
            int T = int.Parse(line[2]);

            List<int> multiple = new List<int>();
            for(int i = 1; i <= T; ++i)
            {
                multiple.Add(i * A);
            }

            int count = 0;

            foreach(int n in multiple)
            {
                if(n <= T)
                {
                    count += B;
                }
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13268
#include <stdio.h>
#include <stdlib.h>
int main(){
  int flag,i,j,size,n,tmp,c=0;
  int *A;
  scanf("%d",&size);
  A = (int *)malloc(size * sizeof(int));
  flag = 1;
  for(i=0;i<size;i++){
    scanf("%d",&A[i]);
  }
  while(flag==1){
    flag = 0;
    for(j=size-1; j>=1; j--){
      if(A[j] < A[j-1]){
	tmp = A[j-1];
	A[j-1] = A[j];
	A[j] = tmp;
	flag = 1;
	c++;
      }
    }
  }

  for(i=0;i<size-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[i]);
  printf("%d\n",c);
  return 0;
}



Measured memory_bytes: 2084
#include<bits/stdc++.h>
#define ll long long
#define MAX 1000005
#define MOD (ll)(1e9+7)
#define INF INT32_MAX
#define INFL INT64_MAX
#define con(x,y)	((x)*(m)+(y))
using namespace std;

void solve()	{
	string s;
	cin >> s;
	int n = s.size();
	string r = "keyence";
	set<string> st;
	for(int i=0; i<n; i++)	{
		if(st.find("keyenc")!=st.end() && s.substr(i,1)=="e" && i==n-1)	{
			cout << "YES\n";
			return;
		}
		if(st.find("keyen")!=st.end() && s.substr(i,2)=="ce" && i+1==n-1)	{
			cout << "YES\n";
			return;
		}
		if(st.find("keye")!=st.end() && s.substr(i,3)=="nce" && i+2==n-1)	{
			cout << "YES\n";
			return;
		}
		if(st.find("key")!=st.end() && s.substr(i,4)=="ence" && i+3==n-1)	{
			cout << "YES\n";
			return;
		}
		if(st.find("ke")!=st.end() && s.substr(i,5)=="yence" && i+4==n-1)	{
			cout << "YES\n";
			return;
		}
		if(st.find("k")!=st.end() && s.substr(i,6)=="eyence" && i+5==n-1)	{
			cout << "YES\n";
			return;
		}
		if(s.substr(i,7)=="keyence" && (i==0 || i+6==n-1))	{
			cout << "YES\n";
			return;
		}
		if(s.substr(i,6)=="keyenc" && i==0)	st.insert("keyenc");
		else if(s.substr(i,5)=="keyen" && i==0)	st.insert("keyen");
		else if(s.substr(i,4)=="keye" && i==0)	st.insert("keye");
		else if(s.substr(i,3)=="key" && i==0)	st.insert("key");
		else if(s.substr(i,2)=="ke" && i==0)	st.insert("ke");
		else if(s.substr(i,1)=="k" && i==0)	st.insert("k");
	}
	cout << "NO\n";
}

int main()	
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin >> t;
	for(int i=1; i<=t; i++)	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3652
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>
#include<unordered_map>
#include<deque>
#include<cmath>





using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const ll INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 1000 * 1000 * 1000 + 7;


void solve() {
    string s;
    cin >> s;
    int a = s.size(), z = 0;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'A')
            a = min(i, a);
        if (s[i] == 'Z')
            z = i;
    }
    cout << z - a + 1 << endl;

}


//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    solve();



#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}


Measured memory_bytes: 720
from math import sqrt
n, k = map(int, input().split())
MOD = 10**9 + 7
max1 = int(sqrt(n))
dp1 = [[0 for _ in range(max1+1)] for _ in range(k)]
for j in range(1, max1+1):
	dp1[0][j] = 1
max2 = int(n/(max1+1))
dp2 = [[0 for _ in range(max2+1)] for _ in range(k)]
for j in range(1, max2+1):
	dp2[0][j] = int(n/j) - int(n/(j+1))

for i in range(k-1):
	csum1 = (sum(dp1[i])+sum(dp2[i])) % MOD
	dp1[i+1][1] = csum1
	for j in range(2, max1+1):
		dp1[i+1][j] = (dp1[i+1][j-1] - dp2[i][j-1]) % MOD
	csum2 = sum(dp1[i][:max2+1]) % MOD
	dp2[i+1][max2] = (csum2*dp2[0][max2]) % MOD
	for j in range(max2-1, 0, -1):
		csum2 -= dp1[i][j+1]
		csum2 %= MOD
		dp2[i+1][j] = (csum2*dp2[0][j]) % MOD

print((sum(dp1[k-1])+sum(dp2[k-1]))%MOD)

Measured memory_bytes: 106108
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

int main() {
  int n, l;
  cin >> n >> l;
  vector <int> vec;
  for (int i = 1; i <= n; i++) {
    vec.push_back(l + i - 1);
  }
  sort(vec.begin(), vec.end());
  int best = 2e9, what;
  int ans = 0;
  for (int i = 0; i < vec.size(); i++) {
    ans += vec[i];
  }
  for (int i = 0; i < vec.size(); i++) {
    ans -= vec[i];
    if (abs(ans - (ans + vec[i])) < best) {
      best = abs(ans - (ans + vec[i]));
      what = ans;
    }
    ans += vec[i];
  }
  cout << what << endl;
  return 0;
}


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

using namespace std;
#define ALL(x)              (x).begin(),(x).end()
typedef long long           ll;
#define REP(i, n)           for (ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)       for (ll i = m ; i < (ll)n ; ++i)
#define INF                 (ll)1e15
#define MOD                 (1000 * 1000 * 1000 + 7)
#define Ceil(x, n)          (((((x))+((n)-1))/n))
#define CeilN(x, n)         (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)        ((x)-(x)%(n))
#define IsOdd(x)            (((x)&0x01UL) == 0x01UL)
#define IsEven(x)           (!IsOdd((x)))
#define M_PI                3.14159265358979323846
typedef pair<ll, ll>	    P;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
ll N, M, Q;
vector<ll> a, b, c, d;
ll ans = 0;
void dfs(vector<ll> &A, int depth)
{
	if (depth == N) {
		ll ansOne = 0;
		REP(j, Q) {
			ll dif = A[b[j]] - A[a[j]];
			if (dif == c[j]) {
				ansOne += d[j];
			}
		}
		if (ans < ansOne) {
			ans = ansOne;
		}
		return;
	}
	
	REP(i, M) {
		A[depth] = i + 1;
		if (0 < depth) {
			if (A[depth - 1] <= A[depth]) {
				dfs(A, depth + 1);
			}
		} else {
			dfs(A, depth + 1);
		}
	}
}

int main()
{
	cin >> N >> M >> Q;
	a.resize(Q), b.resize(Q), c.resize(Q), d.resize(Q);
	REP(i, Q) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--; b[i]--;
	}

	vector<ll> A(N);
	dfs(A, 0);

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


Measured memory_bytes: 3612
#include<stdio.h>
#include<string.h>
#include<vector>
using namespace std;
vector<int> l[1000][1000];
bool isline[1000][1000];
int upoint[1000];
int dpoint[1000];
int min(int a,int b){return a<b?a:b;}
int main(){
	while(1){
	int n,m,h,k;
	int i,j;
	scanf("%d %d %d %d",&n,&m,&h,&k);
	if(n==0)return 0;
	for(i=0;i<n;i++)scanf("%d",&dpoint[i]);
	for(i=0;i<n;i++)for(j=0;j<h;j++)isline[i][j]=false;
	for(i=0;i<m;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		isline[a-1][b]=true;
	}
	int pos;
	for(i=0;i<n;i++){
		pos=i;
		for(j=0;j<h;j++){
			if(isline[pos][j]){
				l[pos][j].push_back(i);
				pos++;
			}
			else if(pos!=0&&isline[pos-1][j]){
				l[pos-1][j].push_back(i);
				pos--;
			}
			if(j==h-1){
				upoint[i]=dpoint[pos];
			}
		}
	}
	int total=upoint[0];
	for(i=1;i<k;i++){
		total+=upoint[i];
	}
	int ans=total;
	for(i=0;i<n;i++){
		for(j=0;j<h;j++){
			if(l[i][j].empty())continue;
			if(l[i][j].front()<k&&l[i][j].back()>=k)ans=min(ans,total+upoint[l[i][j].back()]-upoint[l[i][j].front()]);
			if(l[i][j].front()>=k&&l[i][j].back()<k)ans=min(ans,total+upoint[l[i][j].front()]-upoint[l[i][j].back()]);
		}
	}
	printf("%d\n",ans);
	}
}

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

#define rep(i, n) REP(i, 0, n)
#define REP(i, k, n) for(auto i = k; i != n; i++)
#define rrep(i, n) RREP(i, n, 0)
#define RREP(i, n, k) for(auto i = n; i != k; i--)
#define all(x, r) (x), (x)+(r)
#define ALL(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " " << x << endl
#define exst(x, data) (data).find(x) != (data).end()
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define np next_permutation
#define b32 bitset<32>

using ll = long long;
using Pii = pair<int,int>;
using Tiii = tuple<int, int, int>;
template<class T>using V = vector<T>;
using Vi = vector<int>;
using VVi = vector<vector<int>>;

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

    int H, W; cin >> H >> W;
    int c[10][10]; rep(i,10) rep(j,10) cin >> c[i][j];
    VVi A = VVi(H, Vi(W)); rep(h,H) rep(w,W) cin >> A[h][w];

    rep(i,10) rep(j,10) rep(k,10) c[j][k] = min(c[j][k], c[j][i]+c[i][k]);

    ll ans = 0;
    rep(h,H) rep(w,W) {
        if(A[h][w] != -1) {
            ans += c[A[h][w]][1];
        }
    }
    cout << ans << endl;

    // rep(i,10) {
    //     rep(j,10) cout << c[i][j];
    //     cout << endl;
    // }
    return 0;
}


Measured memory_bytes: 384
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <utility>
using namespace std;

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;

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

    vector<int64_t> pm(n + 1), pc(n + 1);
    for (int i = 0; i < n; ++i) {
        pm[i + 1] = pm[i] + (s[i] == 'M');
        pc[i + 1] = pc[i] + (s[i] == 'C');
    }

    vector<int64_t> pmc(n + 1);
    for (int i = 0; i < n; ++i) {
        pmc[i + 1] = pmc[i] + (s[i] == 'C' ? pm[i] : 0);
    }

    for (int query = 0; query < q; ++query) {
        int64_t result = 0;
        int K = k[query];
        for (int i = 0; i < n; ++i) {
            if (s[i] == 'D') {
                int le = i + 1;
                int ri = min(n, i + K);
                result += pmc[ri] - pmc[le] - pm[le] * (pc[ri] - pc[le]);
            }
        }
        cout << result << endl;
    }
}


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

int H, W; char c[15][15], d[15][15]; bool ans = false;
string U[15];
map<string, int>M, M2;

void solve() {
	for (int i = 0; i < W; i++) {
		U[i] = "";
		for (int j = 0; j < H; j++) U[i] += d[j][i];
	}
	M.clear(); M2.clear();
	for (int i = 0; i < W; i++) M[U[i]]++;
	int Z1 = 0, Z2 = 0;
	for (int i = 0; i < W; i++) {
		if (M2[U[i]] == 1) continue;
		int V1 = M[U[i]];
		string U2 = U[i]; reverse(U2.begin(), U2.end());
		if (U[i] != U2) V1 += M[U2];
		if (U[i] == U2 && V1 % 2 == 1) Z2++;
		else if (V1 % 2 == 1) Z1++;

		M2[U[i]] = true; M2[U2] = true;
	}
	if (W % 2 == 0 && Z1 + Z2 == 0) ans = true;
	if (W % 2 == 1 && Z1 == 0 && Z2 == 1) ans = true;
}

void dfs(vector<pair<int, int>>vec) {
	if (vec.size() == H / 2) {
		vector<int>G;
		bool uses[12]; for (int i = 0; i < 12; i++) uses[i] = false;
		for (int i = 0; i < vec.size(); i++) { G.push_back(vec[i].first); uses[vec[i].first] = true; uses[vec[i].second] = true; }
		for (int i = 0; i < H; i++) { if (uses[i] == false) G.push_back(i); }
		for (int i = vec.size() - 1; i >= 0; i--) { G.push_back(vec[i].second); }

		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) d[i][j] = c[G[i]][j];
		}
		solve();
		return;
	}
	bool used[12]; for (int i = 0; i < 12; i++) used[i] = false;
	for (int i = 0; i < vec.size(); i++) { used[vec[i].first] = true; used[vec[i].second] = true; }
	for (int i = 0; i < H; i++) {
		for (int j = i + 1; j < H; j++) {
			if (used[i] == true || used[j] == true) continue;
			pair<int, int>S = make_pair(0, 0); if (vec.size() >= 1) S = vec[vec.size() - 1];
			if (S >= make_pair(i, j)) continue;
			vector<pair<int, int>>vec2 = vec;
			vec2.push_back(make_pair(i, j));
			dfs(vec2);
		}
	}
}

int main() {
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) cin >> c[i][j];
	}
	dfs(vector<pair<int, int>>{});
	if (ans == true) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
  string s;
  cin >> s;
  sort(s.begin(), s.end());
  if(s[0]==s[1] && s[2]==s[3] && s[0]!=s[2]) cout << "Yes";
  else cout << "No";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define f(a, b, c, d) for(ll a = b; a < c; a += d)

void solve()
{
	ll n;
	cin >> n;
	ll a[n], lst, ht = 0;
	f(i, 0, n, 1)
	{
		cin >> a[i];
		if (i == 0)
			lst = a[i];
		else
		{
			if (a[i] < lst)
			{
				ht += lst - a[i];
			}
			lst = max(a[i], lst);
		}
	}
	cout << ht;
}

signed main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	ll t = 1;
	//cin >> t;
	while (t--)
		solve();
}

Measured memory_bytes: 5176
object Main extends App {
  import scala.io.Source.stdin

  val b = new StringBuilder

  for(d<-stdin.getLines.map(_.toInt)) {
    var i = 0
    var s = 0
    while(i*d < 600) {
      s += i*i
      i += 1
    }
    b.append(s*d*d*d+"\n")
  }
  print(b.result)
}

Measured memory_bytes: 43940
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N; cin >> N;
  vector<ll> A(N); rep(i,N)  cin >> A[i];
  ll ans = 0;
  vector<ll> pow2(63);
  pow2[0]=1;
  rep(i,62){
    pow2[i+1] = pow2[i]*2;
    pow2[i+1] %= mod;
  }

  rep(i,62){
    vector<ll> cnt(2, 0);
    rep(j,N){
      cnt[A[j]&1]++;
      A[j] >>= 1;
    }
    ans += (((pow2[i]*cnt[0])%mod)*cnt[1])%mod;
    ans %= mod;
  }

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


Measured memory_bytes: 2560