akhauriyash/Code-Regression huggingface dataset:
def main():
    n,k = map(int,input().split())
    x = list(map(int,input().split()))
    m,p = [],[]
    for i in range(n):
        if x[i]<0:
            m.append(x[i])
        else:
            p.append(x[i])
    M,P = len(m),len(p)
    ans = float('inf')
    for i in range(min(M+1,k+1)):
        t = 0
        if i>0:
            t += 2*abs(m[M-i])
        r = k-i
        if r==0:
            if t//2<ans:
                ans = t//2
        elif r<=P:
            t += p[r-1]
            if t<ans:
                ans = t
    for i in range(min(P+1,k+1)):
        t = 0
        if i>0:
            t += 2*p[i-1]
        r = k-i
        if r==0:
            if t//2<ans:
                ans = t//2
        elif r<=M:
            t += abs(m[M-r])
            if t<ans:
                ans = t
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 20296
import java.io.*;
import java.lang.*;
import java.util.*;

public class Main 
{
	static int[] c,s,f;
	public static void main(String[] args)
	{
		c = new int[510];
		s = new int[510];
		f = new int[510];
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 1;i < n;++i)
		{
			c[i] = sc.nextInt();
			s[i] = sc.nextInt();
			f[i] = sc.nextInt();
		}
		for (int i = 1;i <= n;++i)
		{
			int t = s[i];
			for (int j = i;j < n;++j)
			{
				if (t < s[j]) t = s[j];
				if (t % f[j] != 0) t = (t/f[j]+1)*f[j];
				t += c[j];
			}
			System.out.println(t);
		}
	}

}


Measured memory_bytes: 26536
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define Sort(v, n) sort(v, v+n);
#define VSort(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define cY cout<<"Yes";
#define cN cout<<"No";
#define cA(a) cout<<a;
const ll MOD = 1000000007;



int main() {
    int p,q,r;cin>>p>>q>>r;
    int ans =INF;
    ans = min(ans,p+q);
    ans = min(ans,p+r);
    ans = min(ans,r+q);
    cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <utility>
 
using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;

int main(void) {
    Int n;
    cin >> n;
    if (n == 1) {
        cout << "Hello World" << endl;
    } else {
        Int a, b;
        cin >> a >> b;
        cout << a + b << endl;
    }
    return 0;
}



Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include<math.h>
#include <iomanip>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int N,P;
vector <int > A;





int main()
{

	cin >> N >> P;

	A.resize(N);
	int odd=0,even=0;
	REP(i,N){
		cin >> A[i];
		if(A[i]%2==0){
			even++;
		}else{
			odd++;
		}
	}

	if(odd==0){
		if(P==0)
			cout << fixed << setprecision(0) <<pow(2,even) << endl;
		else
			cout << 0 << endl;
	} else {
		cout << fixed << setprecision(0) << pow(2,odd-1) * pow(2,even) << endl;
	}

}


Measured memory_bytes: 256
s = input()
a = b = c = 0
for i in range(len(s)):
  if s[i] == 'a':
    a += 1
  elif s[i] == 'b':
    b += 1
  elif s[i] == 'c':
    c += 1
maxv = max(a, max(b, c))
if (maxv-a > 1) or  (maxv-b > 1) or  (maxv-c > 1):
  print("NO")
else:
  print("YES")

Measured memory_bytes: 9144
function Main(input) {
	input = parseInt(input,10);
	returner = 0;
  
  	for(var i=1; i<=input; i++){
		if( (""+i).split("").length%2==1 ){
        	returner++;
        }
    }
  	console.log(returner);
}


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

Measured memory_bytes: 13500
#include<bits/stdc++.h>
using namespace std;
int main(){
  long k,a,b;
  cin >> k >> a >> b;
  if(a+2>=b || k<=a)cout << k+1 << endl;
  else{
    long ans = a;
    k -= a-1;
    if(k%2==1){
      ans++;
      k--;
    }
    ans += (b-a)*(k/2);
    cout << ans << endl;
  }
  return 0;
}


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

using namespace std;

const unsigned int MAX_N = 200005;

long long sub[MAX_N];
vector<long long> x, h;
int n;
long long D, A;

long long compute(){
    vector<pair<long long, long long> > vec(n);
    for(int i = 0; i < n; ++i){
        vec[i] = {x[i], i};
    }
    sort(vec.begin(), vec.end());
    for(int i = 0; i <= n; ++i) sub[i] = 0;
    long long cur = 0, ans = 0;
    for(int i = 0; i < n; ++i){
        cur -= sub[i];
        const long long H = h[vec[i].second];
        if(H - cur > 0){
            const int id = upper_bound(vec.begin() + i + 1, vec.end(), make_pair(vec[i].first + 2 * D, (long long)n)) - vec.begin();
            sub[id] += H - cur;
            ans += H - cur;
            cur += H - cur;
        }
    }
    return ans;
}

int main()
{
    cin >> n >> D >> A;
    x.resize(n), h.resize(n);
    for(int i = 0; i < n; ++i){
        cin >> x[i] >> h[i];
        h[i] = (h[i] + A - 1) / A;
    }
    long long ans1 = compute();
    for(int i = 0; i < n; ++i){
        x[i] = -x[i];
    }
    long long ans2 = compute();
    cout << min(ans1, ans2) << "\n";
}

Measured memory_bytes: 8136
#include<bits/stdc++.h>
#define io ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define PI atan(1)*4
typedef long long int ll;
using namespace std;
int main(){
	io;
	set<string> s;
	int n;
	cin >> n;
	string c;
	for(int i = 0;i < n;++i){
		cin >> c;
		s.insert(c);
	}
	cout << s.size();
	return 0;
} 

Measured memory_bytes: 19200
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
#include <cstdio>
#include <queue>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}
typedef pair<int,int> pii;
int main(void){
  int n,m;
  cin>>n>>m;
  map<int,int> mp;
  priority_queue<pii> q;
  rep(i,m){
    int a,b;
    cin>>a>>b;
    mp[a] += b;
    q.push(make_pair(mp[a],-a));
    while(true){
      pii p = q.top();
      if(mp[-p.second] == p.first){
	cout<<-p.second<<" "<<p.first<<endl;
	break;
      }
      q.pop();
    }
  }
}

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

int main(){
    int N;cin>>N;
    int info[10][10];
    rep(i,10)rep(j,10)info[i][j]=0;
    rep(i,N){
        int p=i+1;
        int q=(int)log10(p);
        q=pow(10,q);
        info[p/q][p%10]++;
    }
    ll ans=0;
    rep(i,10)rep(j,10){
        ans+=info[i][j]*info[j][i];
    }
    cout<<ans<<endl;
    return 0;
}

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


int main() {
  int n;
  int num;
  double ans;
  cin >> n;
  if(n % 2 == 0) {
    ans = (double)1 / 2;
  }else {
    num = n / 2;
    ans = (double)(num + 1) / n;
  }
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Node[] a = new Node[n];
		for (int i = 0; i < n; i++) {
			int id = sc.nextInt();
			a[id] = new Node();
			a[id].id = id;
			a[id].l = sc.nextInt();
			a[id].r = sc.nextInt();
			a[id].p = -1;
		}

		for (int i = 0; i < n; i++) {
			if (a[i].l != -1) a[a[i].l].p = a[i].id;
			if (a[i].r != -1) a[a[i].r].p = a[i].id;
		}
		
		int j = 0;
		while(a[j].p != -1) j++;
		int root = a[j].id;
		
		System.out.println("Preorder");
		preorder(a, root, a[root].l, a[root].r);
		System.out.println();

		System.out.println("Inorder");
		inorder(a, root, a[root].l, a[root].r);
		System.out.println();

		System.out.println("Postorder");
		postorder(a, root, a[root].l, a[root].r);
		System.out.println();
	}

	static void preorder(Node a[], int id, int l, int r) {
		System.out.print(" " + id);
		if (l != -1) preorder(a, a[l].id, a[l].l, a[l].r);
		if (r != -1) preorder(a, a[r].id, a[r].l, a[r].r);
	}

	static void inorder(Node a[], int id, int l, int r) {
		if (l != -1) inorder(a, a[l].id, a[l].l, a[l].r);
		System.out.print(" " + id);
		if (r != -1) inorder(a, a[r].id, a[r].l, a[r].r);
	}

	static void postorder(Node a[], int id, int l, int r) {
		if (l != -1) postorder(a, a[l].id, a[l].l, a[l].r);
		if (r != -1) postorder(a, a[r].id, a[r].l, a[r].r);
		System.out.print(" " + id);
	}
}

class Node {
	int id;
	int l;
	int r;
	int p;
}

Measured memory_bytes: 26188
//c
#include <iostream>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <functional>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>

#define REP(i,b,n) for(int i=b;i<n;i++)
#define REPR(i,b,n) for(int i=n-1;i>=b;i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define EACH(i, c) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define BIT(n, b) ((n>>b) & 1)
#define PB push_back
#define MP make_pair

using namespace std;

static const double PI = acos(-1.0);
static const double EPS = 1e-9;
typedef long long ll;
typedef pair<int, int> pii;

int n, m;
int amat[500][500];
int vtx[500];

int solve(){
	
	queue<int> qu;
	qu.push(0);
	
	for(int i=0; i<n; ++i)
		vtx[i] = 0;
	
	while(!qu.empty()){
		
		int now = qu.front();
		qu.pop();
		
		for(int i=0; i<n; ++i){
			
			if(now != i && amat[now][i] != 0 && (vtx[i] < vtx[now] + amat[now][i]) ){
				vtx[i] = vtx[now] + amat[now][i];
				qu.push(i);
			}
		}
	}
	
	return vtx[n-1];
}

int main(){
	
	cin >> n >> m;
	CLR(amat);
	
	int a, b, c;
	for(int i=0 ; i<m; ++i){
		cin >> a >> b >> c;
		amat[a][b] = c;
	}
	
	cout << solve() << endl;
	
	return 0;	
}

Measured memory_bytes: 2196
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;
#define MOD (ll)1000000007
#define PI 3.14159265359
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
//#define P pair<ll, ll>
#define dvec vector<vector<ll>>
//printf("%.10f\n")
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b){if (a < b) { a = b; return true; } return false;}
template<class T> inline bool chmin(T& a, T b){if (a > b) { a = b; return true; } return false;}
ll INF = 1e+18;
int iINF = 1e9;


int main()
{
  string S, T; cin >> S >> T;
  vector<int> si;
  for(auto x: S){
    si.push_back(x - '0');
  }
  int ssize = si.size();
 
  vector<int> ti;
  for(auto x: T){
    ti.push_back(x - '0');
  }
  int tsize = ti.size();

  int same = 0;
  vector<int> ps;
  rep(i, 0, ssize){
    rep(k, 0, tsize){
      if(si[i] < ti[k]){
        cout << "Yes" << endl;
        return 0;
      }
      if(find(ps.begin(), ps.end(), i) != ps.end()) continue;
        if(si[i] ==  ti[k]){
          ps.push_back(i);
          ++same;
      }
    }
  }

  if(same == ssize && ssize < tsize)cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3628
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	A
# CreatedDate:  2020-06-29 12:36:27 +0900
# LastModified: 2020-06-29 12:38:39 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    c = input()
    print(chr(ord(c)+1))


if __name__ == "__main__":
    main()


Measured memory_bytes: 9056
#include <stdio.h>

int H, W, K;
char s[512][512];

int answer[512][512];

int main(void) {
	int i, j;
	int next = 0;
	if (scanf("%d%d%d", &H, &W, &K) != 3) return 1;
	for (i = 0; i < H; i++) {
		if (scanf("%511s", s[i]) != 1) return 1;
	}
	for (i = 0; i < H; i++) {
		int exists = 0;
		for (j = 0; j < W; j++) {
			exists = exists || (s[i][j] == '#');
		}
		if (exists) {
			int first = -1;
			for (j = 0; j < W; j++) {
				if (s[i][j] == '#') {
					if (first < 0) first = j;
					next++;
				}
				answer[i][j] = next;
			}
			for (j = 0; j < first; j++) {
				answer[i][j] = answer[i][first];
			}
		}
	}
	for (i = 1; i < H; i++) {
		for (j = 0; j < W; j++) {
			if (answer[i][j] == 0) answer[i][j] = answer[i - 1][j];
		}
	}
	for (i = H - 2; i >= 0; i--) {
		for (j = 0; j < W; j++) {
			if (answer[i][j] == 0) answer[i][j] = answer[i + 1][j];
		}
	}
	for (i = 0; i < H; i++) {
		printf("%d", answer[i][0]);
		for (j = 1; j < W; j++) printf(" %d", answer[i][j]);
		putchar('\n');
	}
	return 0;
}


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

divs = [(1, N)]
for p in range(2, int(N**0.5)+1):
    if N % p == 0:
        divs.append((p, N//p))

ans = float('inf')
for xy in divs:
    ans = min(ans, xy[0] + xy[1] - 2)

print(ans)


Measured memory_bytes: 40172
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int a, b, c, d; cin >> a >> b >> c >> d;
  cout << min(a, b) + min(c, d) << '\n';
  return 0;
}


Measured memory_bytes: 256
def solve():
    N = int(input())
    Ass = [tuple(map(int, input().split())) for _ in range(N)]

    scores = [0] * (1<<N)
    for S in range(1, 1<<N):
        for i in range(N):
            if (S>>i) & 1:
                score = scores[S ^ (1<<i)]
                for j in range(i+1, N):
                    if (S>>j) & 1:
                        score += Ass[i][j]
                scores[S] = score
                break

    def enumSubset(S):
        subSs = []
        subS = S
        while True:
            subSs.append(subS)
            subS = (subS-1) & S
            if subS == S:
                break
        subSs.reverse()
        return subSs

    dp = [0] * (1<<N)
    for S in range(1<<N):
        subSs = enumSubset(S)
        dp[S] = max([scores[subS] + dp[S-subS] for subS in subSs])

    print(dp[-1])


solve()


Measured memory_bytes: 87184
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
   int N;
   cin>>N;
   vector<int>A(N);
   int ans=0;
   rep(i,N){
       cin>>A[i];
       ans+=A[i];
   }
   cout<<ans-N<<endl;
}

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

using namespace std;

int main() {
	int n;
	cin >> n;
	string s = "357";
	int c = 0;
	while (s.length() < 10 && stoi(s) <= n) {
		if (s.find('3') != -1 && s.find('5') != -1 && s.find('7') != -1)
			c++;
		auto it = s.rbegin();
		while (it != s.rend() && *it == '7')
			*it++ = '3';
		if (it == s.rend())
			s += '3';
		else *it += 2;
	}
	cout << c << endl;
	return 0;
}


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

int main(){
    int k,x;
    cin >> k >> x;
    if(500*k >= x) cout << "Yes" << endl;
    else  cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a,b,c,d;
    a=b=c=d=0;
    for (int i = 0; i < n; i++)
    {
        string s;
        cin>>s;
        if(s=="AC")a++;
        if(s=="WA")b++;
        if(s=="TLE")c++;
        if(s=="RE")d++;
        
    }
    printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n",a,b,c,d);
}

Measured memory_bytes: 3620
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def inp():
    return int(input())
def inps():
    return input().rstrip()
def inpl():
    return list(map(int, input().split()))
def inpls():
    return list(map(str, input().split()))
def _debug(obj):
    print(obj, file=sys.stderr)

# import decimal
# from decimal import Decimal
# decimal.getcontext().prec = 10

# from heapq import heappush, heappop, heapify
# import math
# from math import gcd
# import itertools as it
# import collections
# from collections import deque 

# ---------------------------------------
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
# ---------------------------

N, M = inpl()
graph = [[] for i in range(N + 1)]
uf = UnionFind(N + 1)

for i in range(M):
    a, b = inpl()
    uf.union(a, b)

print(len(uf.roots()) - 2)





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

long long solve(long long x){
    if(x%4==0) return x;
    else if(x%4==1) return 1;
    else if(x%4==2) return x+1;
    return 0;
}

int main(){
    long long A,B;
    cin >> A >> B;
    cout << (solve(A-1)^solve(B)) << endl;
}

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

using namespace std;

int main()
{
   string s;
   int num = 0;

   cin >> s;

   for(int i=1; i<(int)s.length(); i++){
      char before = s[i-1];
      if(s[i] == before){
         s[i] = (before == '1') ? '0' : '1';
         num++;
      }
   }

   cout << num << endl;

   return 0;
}



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

using namespace std;

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

    if ( S.size() <= K )
        cout << S << endl;
    else {
        for ( int i=0; i<K; i++ )
            cout << S.at(i);
        cout << "..." << endl;
    }

    return 0;
}


Measured memory_bytes: 3628
a,b,c = map(int,input().split())
ans = 0
if a == b == c and a%2 == 0:
    print(-1)
    exit()
while a%2 == b%2 == c%2 == 0:
    x,y,z = a//2, b//2, c//2
    a = y + z
    b = x + z
    c = x + y
    ans += 1
print(ans)


Measured memory_bytes: 3060
n = gets.to_i
ab = 0
sa = 0
sb = 0
sba = 0
n.times{
  s = gets.chomp
  sba += 1 if s[0]=='B' and s[-1]=='A' 
  sa += 1 if s[0]!='B' and s[-1]=='A'
  sb += 1 if s[0]=='B' and s[-1]!='A'
  ab += s.gsub(/AB/, "#").count("#")
}
if sba>0
    if sa==0 and sb==0
        p ab + sba - 1
    else
        p ab + [sa, sb].min + sba
    end 
else
   p ab + [sa, sb].min
end

Measured memory_bytes: 1916
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <functional>
#include <map>
#include <math.h>
#include <list>
#include <bitset>

using namespace std;
#define ll long long int

unsigned int btoui(const std::string& bin) {
	return strtoul(bin.c_str(), NULL, 2);
}

int main(void) {

	ios::sync_with_stdio(false);
	cin.tie(0);

    ll n; cin >> n;
    vector<bitset<32>> bit;
	bitset<32> abit = 0,bbit;
	int in;

	for (int i = 0; i < n; i++) {
		cin >> in;
		bit.push_back(in);
		abit = abit ^ bit[i];
	}


	
	for (int i = 0; i < n; i++) {
		bbit = bit[i] ^ abit;
		cout << btoui(bbit.to_string()) << ' ' << flush;
	}

	cout << endl;


	return 0;
}


Measured memory_bytes: 5300
s = map(int, raw_input())

def dfs(c, nums):
    if c==len(s):
        return sum(nums)
    res = 0
    res += dfs(c+1, nums + [s[c]])
    if c:
        nums2 = nums[:]
        nums2[-1] = nums2[-1]*10 + s[c]
        res += dfs(c+1, nums2)
    return res

print dfs(0, [])

Measured memory_bytes: 2568
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()

def score(hand):
    if hand == 's':
        return r
    if hand == 'p':
        return s
    if hand == 'r':
        return p

ans = 0
changed = [0] * n

for i in range(n):
    if i >= k and t[i] == t[i - k] and changed[i - k] == 0:
        changed[i] = 1
        continue    
    ans += score(t[i])

print(ans)


Measured memory_bytes: 10008
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun gcd(a:Long, b:Long):Long {
    val c = a % b
    if (c == 0L) return b
    return gcd(b, c)
}

fun gcd(a:Int, b:Int):Int {
    val c = a % b
    if (c == 0) return b
    return gcd(b, c)
}

fun gcd(a:Array<Int>):Int {
    val n = a.count()
    var ret = a[0]
    for (i in 1 until n) {
        ret = gcd(ret, a[i])
    }
    return ret
}

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val a = Array(n) { sc.nextInt() }
    println(gcd(a))
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 48028
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__;
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    ll K,N; cin >> K >> N;
    vector<ll> A(N); for(int i=0;i<N;i++){cin >> A[i];}
    ll out=K-A[N-1]+A[0];
    for(int i=0;i<N-1;i++){
        ll tmp = A[i+1]-A[i];
        if(out<tmp) out = tmp;

    }
    cout << K-out << endl;

    return 0;
}


Measured memory_bytes: 1792
import java.util.*;
 
class Main{
    public static void main(String[] args){
		double p1 = 0.0;
		double p2 = 0.0;
		double p3 = 0.0;
		double p4 = 0.0;
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] x = new int[n];
		int[] y = new int[n];
		for(int i=0; i<n; i++){
			x[i] = scan.nextInt();
		}
		for(int i=0; i<n; i++){
			y[i] = scan.nextInt();
		}
		for(int i=0; i<n; i++){
			p1 += (double)Math.abs(x[i] - y[i]);
			p2 += (double)Math.pow(Math.abs(x[i] - y[i]), 2);
			p3 += (double)Math.pow(Math.abs(x[i] - y[i]), 3);
			if(p4 < Math.abs(x[i] - y[i])){
				p4 = Math.abs(x[i] - y[i]);
			}
		}
		System.out.println(p1);
		System.out.println(Math.sqrt(p2));
		System.out.println(Math.cbrt(p3));
		System.out.println(p4);
    }
}

Measured memory_bytes: 26704
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

// XOR-Range; 排他的論理和：0~nまでの排他的論理和
ll xorRange(ll n){
    if(n%4 == 0) return n;
    if(n%4 == 1) return 1;
    if(n%4 == 2) return n^1LL;
    if(n%4 == 3) return 0;
}

int main(){
    Init();
    ll n; cin >> n;
    vi a(n);
    ll exor = 0;
    rep(i, n){
        cin >> a[i];
        exor ^= a[i];
    }
    for(ll i=0; i<n; i++){
        cout << (exor^a[i]) << ((i == n-1) ? endl : " ");
    }
}

Measured memory_bytes: 4784
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
    int a,b;
    cin >>a >> b;
    if(a>=b) {
        string ba;
        rep(i,a) ba += to_string(b);
        cout << ba << endl;
    }
    else {
        string ab;
        rep(i,b) ab += to_string(a);
        cout << ab << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  long long T;
  cin >> N >> T;
  long long ans = 0;
  int last = 0;
  for (int i = 0; i < N; i++) {
    long long t;
    cin >> t;
    if (t < last) ans -= last - t;
    ans += T;
    last = t + T;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define ll long long
#define FOR(i,x,y) for(int i = x; i <= y; ++i)
#define rFOR(i,x,y) for(int i = x; i >= y; --i)
#define MS(a,x) memset(a,x,sizeof a)
#define pb push_back

using namespace std;

int h,w;
char str[200];
int vis[30];

int main()
{
    scanf("%d%d",&h,&w);
    FOR(i,1,h)
    {
        scanf("%s",str);
        FOR(j,0,w - 1) vis[str[j] - 'a']++;
    }
    int tw = 0;
    if(h & 1) tw += w / 2;
    if(w & 1) tw += h / 2;
    int tot = w * h;
    tot -= tw * 2;
    if(h & 1 && w & 1) tot -= 1;
    tot /= 4;
    bool flag = true;
    FOR(i,1,tot)
    {
        bool ck = false;
        FOR(j,0,25) if(vis[j] >= 4)
        {
            vis[j] -= 4;
            ck = true;
            break;
        }
        if(!ck)
        {
            flag = false;
            break;
        }
    }
    FOR(i,1,tw)
    {
        bool ck = false;
        FOR(j,0,25) if(vis[j] >= 2)
        {
            vis[j] -= 2;
            ck = true;
            break;
        }
        if(!ck)
        {
            flag = false;
            break;
        }
    }
    if(flag) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 256
open Printf
open Scanf
open Num

let fact n =
  let d = num_of_int 1000000007 in
  let rec iter a x =
    if x = 1 then a
    else
      iter (mod_num ((num_of_int x) */ a ) d) (x-1)
  in iter (num_of_int 1) n

let () =
  let n, m = scanf "%d %d\n" (fun x y -> (x, y)) in
  begin
    match abs (n - m) with
      0 -> string_of_num (mod_num ((num_of_int 2) */ (fact n) */ (fact m)) (num_of_int 1000000007))
    | 1 -> string_of_num (mod_num ((fact n) */ (fact m)) (num_of_int 1000000007))
    | _ -> "0"
  end |> printf "%s\n"


Measured memory_bytes: 4480
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int 	     	  long long   // [9,223,372,036,854,775,807 to -9.....808] 19 digits
#define pb                push_back 
#define all(x)            (x).begin(),(x).end()
#define mp                make_pair
#define vi                vector<int> 
#define vpi               vector<pair<int,int>>
#define mii               map<int,int>
#define x                 first
#define y                 second 
#define mem(a,x)          memset(a,x,sizeof(a))
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define sz(x)             (int)((x).size())

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // find_by_order()  // order_of_key

//const int32_t hellhsh = 444440583533; const double pi=2*acos(0.0); 
const int32_t mod = 1e9+7;
const int32_t maxn=4e2+5;
int inf=1e18;

int n,a[maxn],dp[maxn][maxn],pre[maxn];

void solve(){
    cin>>n;
    rep(i,0,n) cin>>a[i];
    rep(i,0,n){
        rep(j,0,n){
            dp[i][j]=inf;
        }
    }
    rep(i,0,n) pre[i+1]=pre[i]+a[i],dp[i][i]=a[i];
    

    for(int l=n-1;l>=0;l--){
        rep(r,l,n){
            rep(i,l,r){
                dp[l][r]=min(dp[l][r],dp[l][i]+dp[i+1][r]+pre[r+1]-pre[l]);
            }
            //cout<<l<<' '<<r<<' '<<dp[l][r]<<'\n';
        }
    }
    cout<<dp[0][n-1]-pre[n];
}

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int tc=1,k=1;                                                                                                                  
    //cin>>tc;
    while(tc--){
        //cout<<"Case #"<<k++<<": ";
        solve();
    }
    return 0;
}

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

#define V vector
typedef long long ll;
typedef unsigned long long ull;

typedef V<int> vi;
typedef V<ll> vll;
typedef V<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define f(i,a) for(int i = 0 ; i < a ; i++)
#define fll(i,a) for(ll i = 0 ; i < a ;i++)
#define forab(i,a,b) for(int i = a ; i < b ; i++)
#define prec(x) cout<<fixed<<setprecision(x)
#define ff first
#define ss second
#define mod 1073741824

#define pb push_back
#define mp make_pair
#define numberofdigits(x) floor(log10(x)) + 1

void solve()
{
	string s;
	cin >> s;

	cout << s.substr(0 , 3) << "\n";
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int t = 1;
	//cin >> t;

	while (t--)
	{
		solve();
	}

	return 0;
}





Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll> > vvi;
typedef pair<ll, ll> pii;
const long long INF = 1LL << 58;
struct Edge
{
    ll s, t, d;
};
typedef vector<vector<Edge> > Graph;
typedef vector<pii> vpii;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

int main()
{
    ll N,M;
    cin>>N>>M;
    ll xyz[1001][3];
    REP(i,N)
    cin>>xyz[i][0]>>xyz[i][1]>>xyz[i][2];
    vi ans;
    vi lis;
    ll tmp;
    REP(i,1<<3){
        lis={};
        REP(j,N){
            tmp=0;
            REP(k,3){
                if(i&(1<<k)){
                    tmp=tmp+xyz[j][k];
                }else{
                    tmp=tmp-xyz[j][k];
                }
            }
            lis.push_back(tmp);
        }
        sort(ALL(lis));
        tmp=0;
        REP(j,M)
        tmp=tmp+lis[lis.size()-1-j];
        ans.push_back(tmp);
    }
    sort(ALL(ans));
    cout<<ans[ans.size()-1]<<endl;
    //system("pause");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=5e5;

  int n,k;
  int r[N];
int main()
{
  cin>>n>>k;
  if (k==1||k==n+n-1)
    puts("No"),exit(0);
  else
    puts("Yes");
  for (int i=n+n;~--i;)
    r[i]=i+1;
  r[k-2]=k+2;
  int x=0;
  for (int z=n-1;--z;)
    x=r[x];
  r[k+1]=r[x];
  r[x]=k-1;
  for (int z=n+n,i=0;--z;)
    printf("%d\n",i=r[i]);
  exit(0);
}

Measured memory_bytes: 2304
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, k = map(int, readline().split())
s = read().rstrip().decode()
ans = n - 1
for bf, af in zip(s, s[1:]):
    if bf != af:
        ans -= 1
print(min(n - 1, ans + k * 2))


Measured memory_bytes: 3380
S = input()

mod = 2019
ctr = [0] * mod
t = 0
for i, v in enumerate(reversed(S)):
    t = (t + int(v) * pow(10, i, mod)) % mod
    ctr[t] += 1

ans = ctr[0]
for v in ctr:
    ans += v * (v - 1) // 2
print(ans)


Measured memory_bytes: 68160
N=int(input())
k=1
ans=""
num2alpha = lambda c: chr(c+96)

#num2alpha(3) #==> C
while(1):
    if(N<=((((26**k)-1)*26)/25)):
        break
    else:
        k+=1
X=int(N-((((26**(k-1))-1)*26)/25))-1
#print(k)
#print(X)
for i in range(k):
    x= int(X // (26**(k-1-i)))
    #print(x)
    s=num2alpha(x+1)
    ans+=s
    X=X-x*(26**(k-1-i))
print(ans)


Measured memory_bytes: 9196
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin, (x).end()
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
	  fac[i] = fac[i-1] * i % MOD;
	  inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
	  finv[i] = finv[i-1] * inv[i] % MOD;
	}
}
//組み合わせ
long long COM (int n, int k) {
	if(n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
void solve() {
	int n; cin >> n;
	vector<long long> h(n);
	rep (i, n) {
		cin >> h[i];
	}
	if (n == 1) {
		cout << "Yes" << endl;
		return;
	}
	for (int i = n - 1; i > 0; --i) {
		if (h[i] < h[i - 1]) {
			h[i - 1]--;
			if (h[i] < h[i - 1]) {
				cout << "No" << endl;
				return;
			}
		}	
	}
	cout << "Yes" << endl;
	return;
}
int main() {
	solve();
	return 0;
}

Measured memory_bytes: 1024
#include <string>
#include <algorithm>
#include <vector> 
#include <math.h>
#include <iostream>
using namespace std;
long long mod = 1000000000 + 7;



int main()
{
	int a,b,c;
	cin >> a >> b >>c;

	string ans = "Yes";
	if (a > b) {
		if (c > a || b > c) {
			ans = "No";
		}
	}
	else {
		if (c > b || a > c) {
			ans = "No";
		}
	}
	
	
	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define pb              push_back
#define ppb             pop_back
#define endl            '\n'
#define mii             map<ll,ll>
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define vs              vector<string>
#define all(a)          (a).begin(),(a).end()
#define F               first
#define S               second
#define sz(x)           (ll)x.size()
#define hell            1000000007
#define inf             (ll)1e18 + 5
#define PI              3.14159265358979323844
#define rep(i,a,b)      for (ll i=a;i<b;i++)
#define repr(i,a,b)     for (ll i=a-1;i>=b;i--)
#define lbnd            lower_bound
#define ubnd            upper_bound
#define mp              make_pair
#define ios             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ordered_set     tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(...)      __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

using namespace std;
using namespace __gnu_pbds;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741

void solve() {
    ll arr[3];
    rep(i,0,3)cin>>arr[i];
    sort(arr,arr+3);
    if ((arr[0]==arr[1] && arr[1]!=arr[2]) || (arr[1]!=arr[0] && arr[1]==arr[2]))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

signed main() {
    ios
    ll test=1;
    //cin>>test;
    while (test--) solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define re register
#define rep(x,a,b) for (re int x=a;x<=b;++x)
#define drp(x,a,b) for (re int x=a;x>=b;--x)
#define LL long long 
using namespace std;
const int Max=8010;
const int mo=1e9+7;
int n,m,k,ans;
int f[4010][4010],inv[Max],mul[Max],a[200010],b[200010];
inline int ksm(int a,int b){
	int ans=1;
	while(b){
	  if(b&1) ans=(1ll*ans*a)%mo;
	  b>>=1;
	  a=(1ll*a*a)%mo;
	}
	return ans;
}
 
inline void pre(){
	mul[0]=mul[1]=1;
	rep(i,2,8000) mul[i]=(1ll*mul[i-1]*i)%mo;
	inv[0]=inv[1]=1;
	rep(i,2,8000)inv[i]=ksm(mul[i],mo-2);
}
 
inline int C(int n,int m){
	if(n>=0 && m>=0 && n>=m) return (1ll*mul[n]*inv[m]%mo*inv[n-m]%mo)%mo;
	return 0;
}
 
int main(){
	pre();
	scanf("%d",&n);
	rep(i,1,n) scanf("%d%d",&a[i],&b[i]),f[2001-a[i]][2001-b[i]]++;
	rep(i,1,4001)
	  rep(j,1,4001)
	    f[i][j]=(f[i][j]%mo+(f[i][j-1]+f[i-1][j])%mo)%mo;
 
	rep(i,1,n) ans=(ans+f[2001+a[i]][2001+b[i]])%mo;
	rep(i,1,n) ans=((ans-C((a[i]<<1)+(b[i]<<1),a[i]<<1))%mo+mo)%mo;
	ans=1ll*ans*(mo+1)/2%mo;
 	printf("%d",(ans%mo+mo)%mo);
	return 0;
}

Measured memory_bytes: 64512
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

int n, ans = 0;

void f(int x, bool three, bool five, bool seven) {
  if (n < x) return;
  if (three && five && seven) ans++;
  f(x * 10 + 3, 1, five, seven);
  f(x * 10 + 5, three, 1, seven);
  f(x * 10 + 7, three, five, 1);
}

signed main() {
  cin >> n;
  f(0, 0, 0, 0);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

int main(){
	
	string s,t;
	cin >> s >> t;
	int ans=t.size();
	for(int i=0;i<s.size()-t.size()+1;i++){
		{
			int cnt=0;
			for(int j=0;j<t.size();j++){
				if(s[i+j]==t[j])cnt++;
			}
			int a=t.size()-cnt;
			//cout << a << endl;
			ans=min(ans,a);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int p[] = new int[n];
		for (int i = 0; i < n; ++i)
			p[i] = sc.nextInt();
		sc.close();
		String ans[] = { "YES", "NO" };
		int an = 0;
		int cnt = 0;
		for (int i = 0; i < n; ++i)
			if (p[i] != i + 1)
				++cnt;
		if (cnt > 2)
			an = 1;
		System.out.println(ans[an]);

	}
}


Measured memory_bytes: 22868
#include <stdio.h>
#include <algorithm>

using namespace std;

int main(){
	int array[3];
	for(int i = 0; i < 3; i++) scanf("%d",&array[i]);
	for(int i = 2; i > 0; i--){
		for(int j = 0; j < i; j++){
			if(array[j] > array[j+1])swap(array[j],array[j+1]);
		}
	}
	printf("%d %d %d\n",array[0],array[1],array[2]);
}



Measured memory_bytes: 2696
from math import ceil
n,k = map(int,input().split())
a = list(map(int,input().split()))
l = 0
r = max(a)
def f(ln, x):
    return ceil(ln/x)-1
while r-l > 1:
    m = (r+l)//2
    cnt = 0
    for i in range(n):
        cnt += f(a[i],m)
    if cnt > k:
        l = m
    else:
        r = m
print(r)

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

int main()
{
  ll n, k;
  cin >> n >> k;
  vector<ll> ps(n);
  rep(i, n) cin >> ps[i];

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

  ll ans = 0;
  rep(i, k) {
    ans += ps[i];
  }

  cout << ans << endl;

   return 0;
}


Measured memory_bytes: 3628
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

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

#define ll long long
#define ld long double
#define mod 1000000007
#define pb push_back
#define inf 1000000000000000000
#define ff first
#define ss second
#define Clear(x) memset(x,0,sizeof(x))
#define all(x) (x).begin(),(x).end()

void checkpoint1()
{
	/******think more code less******/
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
}

bool comp(pair< ll,ll > &a,pair< ll,ll > &b)
{
	if(a.ff!=b.ff)
		return a.ff<b.ff;
	else
	{
		if(a.ss>b.ss)
			return b.ss<a.ss;
		else if(a.ss<b.ss)
			return a.ss<b.ss;
	}
	return a.ff>b.ff;
}

ll powe(ll a,ll b)
{
	ll res=1;
	while(b>0)
	{
		if(b&1)
		{
			res*=a;
			res%=mod;
		}
		a*=a;
		a%=mod;
		b>>=1;
	}
	return res;
}
int main()
{
	checkpoint1();
	ll n;
	cin>>n;
	ll dp[n][3];
	cin>>dp[0][0]>>dp[0][1]>>dp[0][2];
	for(ll i=1;i<n;i++)
	{
		ll x,y,z;
		cin>>x>>y>>z;
		dp[i][0]=x+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=y+max(dp[i-1][0],dp[i-1][2]);
		dp[i][2]=z+max(dp[i-1][1],dp[i-1][0]);
	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<"\n";
	return 0;
}

Measured memory_bytes: 5956
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
 
int main(){
    int N;
    cin >> N;
    ll A[N];
    for(int i=0;i<N;i++)
        cin >> A[i];

    ll ans = 0, sum;
    for(int i=N-2;i>=0;i--){
        sum += A[i+1];
        sum = sum % MOD;
        ans += A[i]*sum;
        ans = ans % MOD;
    }

    cout << ans << endl;

}

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

int main(){
    string s;
    cin >> s;
    auto ans = string();
    for(int i=0;i<(int)s.size();i++){
        if(s[i]=='1'){
            ans.push_back('1');
        }else if(s[i]=='0'){
            ans.push_back('0');
        }else{
            if(!ans.empty())
                ans.pop_back();
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
  ll n;
  cin >> n;
  ll ans = 0;
  if (n % 2 == 0){
    ll temp = n;
    ll tw = 0;
    while(temp >= 2){
      temp /= 2;
      tw += temp;
    }
    temp = n/2;
    ll fi = 0;
    while(temp >= 5){
      temp /= 5;
      fi += temp;
    }
    ans = min(tw, fi);
  }
  cout << ans << endl;
  
  return 0;
}

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

int main() {
  long long N, K;
  vector<int> A;
  cin >> N >> K;
  A.resize(N);
  for(int i = 0; i < N; i++) cin >> A[i];

  long long left = 0, right = 0;
  for(int i = 0; i < N; i++)
    for(int j = i+1; j < N; j++)
      if(A[i] > A[j]) left++;

  for(int i = N-1; i >= 0; i--)
    for(int j = i-1; j >= 0; j--)
      if(A[i] > A[j]) right++;

  const long long MOD = 1000000007;

  long long ans = 0;
  ans += K * (K+1) / 2 % MOD;
  ans = ans * left % MOD;

  long long rans = 0;
  rans += K * (K-1) / 2 % MOD;
  rans = rans * right % MOD;

  cout << ((ans+rans)%MOD);
}



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

typedef long double lf;
typedef pair<int, int> pii;

const lf PI = 3.14159265358979;

int N;
pii P[102];
vector<pair<lf, int> > Q;

int main() {
    scanf("%d", &N);

    for(int i = 0; i < N; i++) {
        scanf("%d %d", &P[i].first, &P[i].second);
    }

    cout << fixed;
    cout.precision(20);

    for(int i = 0; i < N; i++) {
        Q.clear();
        for(int j = 0; j < N; j++) {
            if(i == j) continue;

            Q.push_back(make_pair(atan2( P[j].second - P[i].second, P[j].first - P[i].first), j));
        }

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

        if(Q.back().first - Q[0].first + 1e-9 >= PI) {
            int p;
            for(int j = 0; j < Q.size(); j++) if(Q[j].first + 1e-9 < 0) {
                p = j;
            }

            if(Q[p + 1].first - Q[p].first + 1e-9 <= PI) {
                cout << 0 << endl;
            }
            else {
                cout << (Q[p + 1].first - Q[p].first - PI) / (2 * PI) << endl;
            }
        }
        else {
            cout << (PI - Q.back().first + Q[0].first) / (2 * PI) << endl;
        }
    }
}


Measured memory_bytes: 256