akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
#include <iomanip>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;


int main(){
    int h,w;
    cin >> h >> w;
    vector<pair<int,int>> wall(h+1);
    for(int i = 0; i < h; i++){
        cin >> wall[i].first >> wall[i].second;
    }

    map<int,int> pos;
    multiset<int> v;
    
    for(int i = 1; i <= w; i++){
        pos.insert({i,i});
        v.insert(0);
    }

    for(int i = 0; i < h; i++){
        auto it = pos.lower_bound(wall[i].first);
        int mr = -1;
        while(it != pos.end() && it->first <= wall[i].second){
            mr = max(mr, it->second);
            v.erase(v.find(it->first - it->second));
            pos.erase(it++);
        }
        if(mr != -1 && wall[i].second < w){
            if(it->first == wall[i].second+1){
                if(it->second < mr){
                    v.erase(v.find(it->first - it->second));
                    it->second = mr;
                    v.insert(it->first - it->second);
                }
            } else {
                pos[wall[i].second+1] = mr;
                v.insert(wall[i].second+1-mr);
            }
        }
        if(v.size() == 0){
            cout << -1 << endl;
        } else {
            auto ans = v.begin();
            cout << (*ans)+i+1 << endl;
        }
    }



    return 0;
}

Measured memory_bytes: 23584
#include<bits/stdc++.h>
#include <iomanip>
#include <unordered_map>
using namespace std;
#define ll long long 
#define pi pair<ll,ll>
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rrep(i,a) for(ll i=a;i>=0;i--)
ll mod=1e9+7;
/*ll power(ll x,ll n)
{
    ll ans=1;
    while(n)
    {
       if(n&1)
       ans=(ans*x)%mod;
       n>>=1;
       x=(x*x)%mod;
    }
   // ans%=mod;
    return ans;
}
/*
struct comp {
    bool operator()(const pair& x, const pair& y) const {
        if (x.second != y.second)
            return x.second < y.second;

        return x.first < y.first;
    }
};
void dfs(int source,vector<int> graph[],vector<int> &path,bool status[])
{
 path.push_back(source);
 status[source]=0;
 //int j=graph[source].size();
 for(int i=0;i<graph[source].size();i++)
 {
     if(status[graph[source][i]]==1)
     dfs(graph[source][i],graph,path,status);
 }
 return;
}*
bool solve(int i,int j,string s)
{
    while(i<j)
    {
      if(s[i]<s[j])
      return 0;
      if(s[i]>s[j])
      return 1;
      i++;
      j--;
    }
    return 1;
}
bool isprime(ll x)
{
    for(ll i=2;i<=sqrt(x);i++)
    {
        if(x%i==0)
        return 0;
    }
    return 1;
    
}
ll lg(ll x,ll n)
{
    ll ans=0;
    while(x/n!=0)
    {
        ans++;
        x/=n;
    }
    return ans;
}*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,j,k,q,t,y,x,k1,i1,j1,z,x1,y1,m,z1;
    cin>>n;
    ll a[n];
    rep(i,0,n)cin>>a[i];
    x=a[0];
    ll ans=0;
    for(i=1;i<n;i++)
    {
        if(x>a[i])
        ans+=(x-a[i]);
        x=max(x,a[i]);
    }
    cout<<ans;
}



Measured memory_bytes: 5180
//Andrew Yang
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <fstream>
#include <string>
#include <string.h>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>	
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <climits>
#include <deque>
using namespace std;
#define FOR(index, start, end) for(int index = start; index < end; ++index)
#define RFOR(index, start, end) for(int index = start; index > end; --index)
#define FOREACH(itr, b) for(auto itr = b.begin(); itr != b.end(); ++itr)
#define RFOREACH(itr, b) for(auto itr = b.rbegin(); itr != b.rend(); ++itr)
#define INF 1000000000
#define M 1000000007
typedef long long ll;
typedef pair<int, int> pii;
vector<int> edges[100001];
bool inPath[100001];
int main(void)
{
	int n, m;
	scanf("%d%d", &n, &m);
	FOR(i, 0, m)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		a--;
		b--;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	deque<int> d;
	d.push_back(0);
	inPath[0] = true;
	while (true)
	{
		int left = d.front();
		int right = d.back();
		bool done = true;
		for(int j : edges[left])
		{
			if (!inPath[j])
			{
				d.push_front(j);
				done = false;
				inPath[j] = true;
				break;
			}
		}
		for (int j : edges[right])
		{
			if (!inPath[j])
			{
				d.push_back(j);
				done = false;
				inPath[j] = true;
				break;
			}
		}
		if (done)
		{
			break;
		}
	}
	cout << d.size() << endl;
	for (int j : d)
	{
		cout << j + 1 << " ";
	}
	cout << endl;
}

Measured memory_bytes: 6912
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;


int main()
{
    long int N, K;
    cin >> N >> K;
    priority_queue<long int> H;
    for (int i = 0; i < N; ++i){
        int h;
        cin >> h;
        H.push(h);
    }

    if( H.size() < K){
        cout << 0 << endl;
    }else{
        for (int i = 0; i < K; ++i){
            H.pop();
        }
        long int ans = 0;
        for (int i = 0; i < N - K; ++i)
        {
            ans += H.top();
            H.pop();
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    int N, M; cin >> N >> M;
    bitset<100000> B;
    for (int i = 0; i < M; i++) {
        int a, b; cin >> a >> b; a--, b--;
        B.flip(a);
        B.flip(b);
    }
    cout << (B.none() ? "YES" : "NO") << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000


double dp[3005][3005];

int main()
{
    int n,i,j;
    double ara[3005],ans;
    cin>>n;

    for(int i=1; i<=n; i++)
    {
        cin>>ara[i];
    }


    dp[0][0]=1.0;



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

            if(j==0)
                dp[i][j] = dp[i-1][j]* (1.0-ara[i]);
            else
                dp[i][j] = dp[i-1][j] * (1.0-ara[i]) + dp[i-1][j-1]*ara[i];

        }
    }



    ans=0;
    for(int j=n/2+1; j<=n; j++)
    {

        ans = ans+dp[n][j];
    }

    printf("%0.9lf\n",ans);



    return 0;
}


Measured memory_bytes: 68992
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; ++i) {
            a[i] = s.nextInt();
        }
        for(int i = n - 1; 0 <= i; --i) {
            System.out.print(a[i]);
            if(1 <= i) System.out.print(' ');
        }
        System.out.println();
    }
}

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

#define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for(int i = (int)a; i <= (int)b; ++i)
#define sz(s) (int)s.size()
#define all(v) v.begin(),v.end()
#define rall(x) (x).rbegin(), (x).rend()

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll inf = (ll)1e14;
const ll N = (ll)2e5+77;
const ll mod = (ll)1e9+7;

ll n,m,k,a,b;
unordered_map<ll,ll> mp;

int main() {
    fast;
    cin >> n;
    forn(i, n) {
        cin >> m;
        mp[m]++;
    }
    cin >> m;
    forn(i, m) {
        cin >> k;
        if (!mp[k]) return cout << "NO\n", 0;
        mp[k]--;
    }
    cout << "YES\n";
    return 0;
}

Measured memory_bytes: 8520
import std.stdio, std.string, std.array, std.conv;

void main() {
    while (true) {
        int[] tmp = readln.chomp.split.to!(int[]);
        int n = tmp[0], x = tmp[1];
        int cnt = 0;
        if (n == 0 && x == 0) break;
        foreach (i; 1 .. n+1) {
            foreach (j; 1 .. i) {
                foreach (k; 1 .. j) {
                    if (i + j + k == x && i != j && j != k && k != i) ++cnt;
                }
            }
        }
        cnt.writeln;
    }
}


Measured memory_bytes: 2452
import java.util.Scanner;
import java.util.ArrayList;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int count = 0;
    ArrayList<Integer> array = new ArrayList<Integer>();
    for(int a=0;a<M*2;a++){
      array.add(sc.nextInt());
    }
    for(int b=1;b<=N;b++){
      count = 0;
      for(int c=0;c<M*2;c++){
        if(array.get(c)==b){
          count += 1;
        }
      }
      System.out.println(count);
    }
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
using namespace std;

long long d[50][5001];
long long C[50];
long long D[50];

vector <pair <pair<long long, long long>, int> > edges[50];

void dijikstra(int S, int N, long long max_A, long long S_coin){
    for(int i = 0; i < N; i++){
      for(int j = 0; j <= max_A; j++){
        d[i][j] = LLONG_MAX;
      }
    }


    priority_queue < pair <long long, pair<long long, int> >  , vector <pair <long long, pair<long long, int> > >, greater<pair <long long, pair<long long, int> > > > pq;
    d[S][min(max_A, S_coin)] = 0;
    pq.push(make_pair(0, make_pair(min(max_A, S_coin), S)));
    while(!pq.empty()){
        auto cur = pq.top();
        long long cur_cost = cur.first;
        int cur_node = cur.second.second;
        long long cur_coin_no = cur.second.first;
        pq.pop();
        //cout << cur_node << " " << cur_coin_no << endl;
        if(d[cur_node][cur_coin_no] < cur_cost){
            continue;
        }


        long long next_coin_no;
        if(cur_coin_no + C[cur_node] <= max_A){
          next_coin_no = cur_coin_no + C[cur_node];
        } else {
          next_coin_no = max_A;
        }
        long long next_cost = cur_cost + D[cur_node];
        if(d[cur_node][next_coin_no] > next_cost){
          d[cur_node][next_coin_no] = next_cost;
          pq.push(make_pair(next_cost, make_pair(next_coin_no, cur_node)));
        }

        for(int i = 0; i < edges[cur_node].size(); i++){
            auto next = edges[cur_node][i];
            auto next_node = next.second;
            auto cost = next.first.second;
            auto coin_cost = next.first.first;
            long long next_d = d[cur_node][cur_coin_no] + cost;
            long long next_coin_no = cur_coin_no - coin_cost;
            if(next_coin_no >= 0 && d[next_node][next_coin_no] > next_d){
                d[next_node][next_coin_no] = next_d;
                pq.push(make_pair(next_d, make_pair(next_coin_no, next_node)));
            }
        }
    }
}
int main(){
  int N;
  int M;
  long long S;
  cin >> N >> M >> S;
  long long max_A = 0;
  for(int i = 0; i < M; i++){
    long long U;
    long long V;
    long long A;
    long long B;
    cin >> U >> V >> A >> B;
    edges[U - 1].push_back(make_pair(make_pair(A, B), V - 1));
    edges[V - 1].push_back(make_pair(make_pair(A, B), U - 1));
    max_A += A;
  }

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

  dijikstra(0, N, max_A, S);

  for(int i = 1; i < N; i++){
    long long ans = LLONG_MAX;
    for(int j = 0; j <= max_A; j++){
      ans = min(ans, d[i][j]);
    }
    cout << ans << endl;
  }

  /*
  for(int i = 0; i < N; i++){
    for(int j = 0; j <= max_A; j++){
      cout << d[i][j] << " ";
    }
    cout << endl;
  }
  */
  return 0;
}


Measured memory_bytes: 7596
#include <bits/stdc++.h>
#define up(i, a, b) for (int i = a, _b = b; i <= _b; i++)
#define down(i, a, b) for (int i = a, _b = b; i >= _b; i--)
#define long long long
#define endl '\n'
#define X first
#define Y second
#define II pair<int, int>
#define debug(X) cerr << #X << " = " << X << endl
#define debug2(X, Y) cerr << #X << " = " << X << " , " << #Y << " = " << Y << endl
#define show(X, a, b) { cerr << #X << " = "; up(_, a, b) cerr << X[_] << " "; cerr << endl; }
#define gc getchar
#define pc putchar
using namespace std;
inline void read(int &x) {
        register int c = gc();
        x = 0;
        int neg = 0;
        for (; ((c<48 || c>57) && c != '-'); c = gc());
        if(c=='-') {neg=1; c=gc();}
        for(; c>47 && c<58; c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
        if(neg) x=-x;
}
inline void writeln(int x) {

        char buffor[21];
        register int i=0;
        int neg=0; if (x<0) {neg=1; x= -x;}
        do {
                buffor[i++]=(x%10)+'0';
                x/=10;
        } while(x);
        i--;
        if (neg) pc('-');
        while(i>=0) pc(buffor[i--]);
        pc('\n');
}
bool a[14];
int f[14][14][2];
void input() {
    up(i, 1, 13) a[i] = true;
    up(i, 1, 6) {
        int x; cin >> x; a[x] = false;
    }
}
bool win(int pl, int l, int r) {
    up(i, 1, 13)
      if (a[i] == pl)
        if (!(i >= l && i <= r)) return false;
    return true;
}
int getf(int l, int r, int pl) { //used [l, r], now turn player "pl"
    if (f[l][r][pl] != -1) return f[l][r][pl];
    if (win(1 - pl, l, r)) return f[l][r][pl] = 0;
    f[l][r][pl] = 0;
    if (l > 1 && a[l - 1] == pl && getf(l - 1, r, 1 - pl) == 0) f[l][r][pl] = 1;
    if (r < 13 && a[r + 1] == pl && getf(l, r + 1, 1 - pl) == 0) f[l][r][pl] = 1;
    if ((l == 1 || a[l - 1] != pl) && (r == 13 || a[r + 1] != pl)) f[l][r][pl] = 1 - getf(l, r, 1 - pl);
    return f[l][r][pl];
}
void solve() {
    up(i, 1, 13)
      up(j, 1, 13)
        up(k, 0, 1)
          f[i][j][k] = -1;
    if (getf(7, 7, 0)) cout << "yes" << endl;
    else cout << "no" << endl;
}
int main() {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);

  #ifdef I_Love_Pork
  #define TASK "tmp"
        freopen(TASK ".inp","r",stdin);
        freopen(TASK ".out","w",stdout);
  #endif

        int test; cin >> test;
        up(i, 1, test) {
         input();
         solve();
        }


        return 0;
}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define Max(a,b) ((a)>(b)?(a):(b)) 
#define Min(a,b) ((a)<(b)?(a):(b)) 

//FILE *fp,*fp2;
//fp=fopen("input.txt","r");
//fp2=fopen("output.txt","w");

int main()
{
    int n,l,r,add=0;
    cin>>n;
    while(n--)
    {
        cin>>l>>r;
        add=add+(r-l+1);
    }
    cout<<add<<endl;
    return 0;
}



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

int main() {
    int n; cin >> n;
    int a, b; cin >> a >> b;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    
    int c = 0, d = 0, e = 0;
    for (int i = 0; i < n; i++)
    {
        if (p[i] <= a) c++;
        if (p[i] >= a + 1 && p[i] <= b) d++;
        if (p[i] >= b + 1) e++;
    }
    
    int ans;
    ans = min(c, min(d, e));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
def main():
    n = int(input())
    max_a, max_b = 0, 0 # type:int
    for _ in range(n):
        a, b = map(int, input().split(' '))
        # a = int(a)
        if max_a < a:
            max_a = a
            max_b = b # int(b)
    print(max_a + max_b)
 
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

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; }
const int INF = 1001001001;
const long long INFL = LLONG_MAX / 3;
const double eps = (1e-9);


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

  ll n, m; cin >> n >> m;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(ALL(a), greater<ll>());

  vector<pair<ll, ll>> d;
  rep(i, m) {
    ll b, c;
    cin >> b >> c;
    d.emplace_back(c, b);
  }
  sort(ALL(d), greater<pair<ll,ll>>());

  ll ans = 0;
  bool flag = true;
  for (auto& p : d) {
    rep(i, p.second) {
      if (a.back() < p.first) {
        ans += p.first;
        a.pop_back();
        if (a.empty()) {
          flag = false;
          break;
        };
      } else {
        flag = false;
        break;
      }
    }
    if (!flag) break;
  }

  if (!a.empty()) ans += SUM(a);

  cout << ans << endl;

  return 0;
}


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

int main() {
  int a1, b1, a2, b2, a3, b3;
  cin >> a1 >> b1 >> a2 >> b2 >> a3 >> b3;

  int town[4] = {};
  town[a1 - 1]++, town[b1 - 1]++, town[a2 - 1]++, town[b2 - 1]++, town[a3 - 1]++, town[b3 - 1]++;

  int one = 0, two = 0;
  if (town[0] == 1) one++; if (town[0] == 2) two++;
  if (town[1] == 1) one++; if (town[1] == 2) two++;
  if (town[2] == 1) one++; if (town[2] == 2) two++;
  if (town[3] == 1) one++; if (town[3] == 2) two++;

  if (one == 2 && two == 2) cout << "YES" << endl; else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N,K;
  cin >> N >> K;
  ll count = 0;
  rep(i,N)
  {
    if(i==0)
    {
      count += K;
    }
    else
    {
      count *= (K-1);
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 3580
a = input()
a = int(a)

suuretu_list = []
kari_list = []

for i in range(a):
    b = int(input())
    suuretu_list.append(b)
    kari_list.append(b)

kari_list = sorted(kari_list)

c = max(suuretu_list)

d = suuretu_list.index(c)

for u in suuretu_list:
    if u != c:
        print(c)
    else:
        print(kari_list[-2])

Measured memory_bytes: 14936
#include <bits/stdc++.h>
#include "unistd.h"
using namespace std;
#define WA cout<<"char134217728";exit(0)
#define RE throw
#define TLE sleep(1000)
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end());
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e17;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int a, b, q;
V<ll> s, t;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> a >> b >> q;
  s.pb(-LINF);
  FOR(i, 0, a){
    ll _s;
    cin >> _s;
    s.pb(_s);
  }
  s.pb(LINF);

  t.pb(-LINF);
  FOR(i, 0, b){
    ll _s;
    cin >> _s;
    t.pb(_s);
  }
  t.pb(LINF);
  FOR(i, 0, q){
    ll x;
    cin >> x;
    ll ls = x - s[upper_bound(all(s), x)-s.begin()-1];
    ll rs = s[lower_bound(all(s), x)-s.begin()] - x;
    ll lt = x - t[upper_bound(all(t), x)-t.begin()-1];
    ll rt = t[lower_bound(all(t), x)-t.begin()] - x;
    ll ans = LINF;
    mins(ans, max(ls, lt));
    mins(ans, max(rs, rt));
    mins(ans, ls*2 + rt);
    mins(ans, lt*2 + rs);
    mins(ans, rs*2 + lt);
    mins(ans, rt*2 + ls);
    printf("%lld\n", ans);
  }
}

Measured memory_bytes: 3060
n=int(input())
s=[list(map(int, input().split())) for i in range(n)]

dp0=[0]*n
dp1=[0]*n
dp2=[0]*n

dp0[0]=s[0][0]
dp1[0]=s[0][1]
dp2[0]=s[0][2]

for i in range(1,n):
    dp0[i]=max(dp1[i-1]+s[i][0],dp2[i-1]+s[i][0])
    dp1[i]=max(dp0[i-1]+s[i][1],dp2[i-1]+s[i][1])
    dp2[i]=max(dp0[i-1]+s[i][2],dp1[i-1]+s[i][2])

print(max(dp0[n-1],dp1[n-1],dp2[n-1]))

Measured memory_bytes: 66008
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let k: usize = sc.read();
    let q: usize = sc.read();
    let mut count = vec![0; n];
    for _ in 0..q {
        let a = sc.read::<usize>() - 1;
        count[a] += 1;
    }

    for count in count.into_iter() {
        if k + count > q {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4732
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ri register int
const int N=500005,M=998244353;
int n;
long long f[N],ans;
char c[N];
void Count(int p)
{
	for(ri i=0;i<p;++i)
		f[p]=(f[p]*2+c[i]-'0')%M;
	++f[p];
	for(ri i=p;i<n;++i)
	{
		if(((c[i%p]-'0')^(i/p&1))<c[i]-'0')
			break;
		if(((c[i%p]-'0')^(i/p&1))>c[i]-'0')
		{
			--f[p];
			break;
		}
	}
	for(ri i=1;i<p;++i)
		if(p%i==0)
			f[p]=(f[p]-f[i])%M;
}
int main()
{
	scanf("%d",&n);
	scanf("%s",c);
	for(ri i=1;i<=2*n;++i)
		if(2*n%i==0)
			if(2*n/i&1)
				Count(i/2);
	for(ri i=1;i<=n;++i)
		ans=(ans+f[i]*2*i)%M;
	cout<<(ans%M+M)%M;
}


Measured memory_bytes: 2560
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
struct Edge
{
    ll from, to, cost;
    Edge(ll f, ll t, ll c){
        from = f, to = t, cost = c;
    }
    Edge(){}
};

ll N, M, pena;
vector<Edge> G;
vector<ll> d;
bool BF(){
    for(int i=0; i<N; i++){
        for(int j=0; j<M; j++){
            Edge e = G[j];
            if(d[e.from]!=INF and d[e.to]>d[e.from]+e.cost){
                d[e.to] = d[e.from]+e.cost;
            }
        }
    } 
    for(int i=0; i<N; i++){
        for(int j=0; j<M; j++){
            Edge e = G[j];
            if(d[e.from]!=INF and d[e.to]>d[e.from]+e.cost){
                d[e.to] = -INF;
            }
        }
    } 
    if(d[N-1]<=-INF) return false;
    return true;
}
signed main(){
    cin>>N>>M>>pena; 
    G.resize(M);
    d.resize(N, INF);
    d[0] = 0;
    for(int i=0; i<M; i++){
        ll a, b, c; cin>>a>>b>>c;
        a--, b--;
        G[i] = Edge(a, b, pena-c);
    }
    auto res = BF();
    if(res) cout << max(0ll, -d[N-1]) << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 384
// Union Find 木
package main

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

func find(parent []int, i int) int {
	if parent[i] < 0 {
		return i
	}
	parent[i] = find(parent, parent[i])
	return parent[i]
}

func unite(parent []int, i, j int) {
	i = find(parent, i)
	j = find(parent, j)
	if i == j {
		return
	}
	parent[j] += parent[i]
	parent[i] = j
}

func fill(a []int, x int) {
	for i := 0; i < len(a); i++ {
		a[i] = x
	}
}

func reverseInts(a []int) {
	l := len(a)
	for i := 0; i < l/2; i++ {
		a[i], a[l-1-i] = a[l-1-i], a[i]
	}
}

func main() {
	N := readInt()
	M := readInt()
	AB := make([]struct{ A, B int }, M)
	for i := 0; i < M; i++ {
		AB[i].A = readInt() - 1
		AB[i].B = readInt() - 1
	}

	parent := make([]int, N)
	fill(parent, -1)

	inconvenience := N * (N - 1) / 2
	var result []int
	for i := M - 1; i > -1; i-- {
		a := AB[i].A
		b := AB[i].B
		result = append(result, inconvenience)
		pa := find(parent, a)
		pb := find(parent, b)
		if pa != pb {
			inconvenience -= parent[pa] * parent[pb]
		}
		unite(parent, a, b)
	}

	reverseInts(result)
	printIntln(result...)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

func printIntln(v ...int) {
	b := make([]byte, 0, 4096)
	for i := 0; i < len(v)-1; i++ {
		b = append(b, strconv.Itoa(v[i])...)
		b = append(b, " "...)
	}
	b = append(b, strconv.Itoa(v[len(v)-1])...)
	fmt.Println(string(b))
}


Measured memory_bytes: 12700
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n, m;cin >> n >> m;
	vector<int> d(n, -1);
	bool b = true;
	for (int i = 0; i < m; ++i) {
		int s, c;cin >> s >> c;
		if (d[s-1] != -1 && d[s-1] != c) b = false;
		else if (s == 1 && c == 0 && n > 1) b = false;
		else d[s-1] = c;
	}
	if (!b) {
		cout << "-1\n";
		exit(0);
	}
	if (d[0] == -1 && d.size() > 1) d[0] = 1;
	for (int i = 0; i < n; ++i) 
		if (d[i] == -1) d[i] = 0;
	for (int u : d) cout << u;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
        int w,h,x,y,r;
        scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
        if(x + r > w || x - r < 0){
                printf("No\n");
        }else if(y + r > h || y - r < 0){
                printf("No\n");
        }else{
                printf("Yes\n");
        }
        return 0;
}

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

#define ll long long
const int mx = 2e5;


int main(void){
  
  ll K, N;
  ll loc[mx];
  ll dt[mx];
  dt[0]=0;
  ll min=0;
  cin >> K >> N;
  for(int i=0; i<N; i++){
    cin >> loc[i];
  }
  for(int i=0; i<N; i++){
    if(i!=(N-1)){
      dt[i] = loc[i+1]-loc[i];
    }else{
      dt[i] = loc[0] + (K-loc[i]);
    }
    if(dt[i]>min){
      min=dt[i];
    }
  }
   
  
  ll ans = K-min;
  cout << ans;
  
  return 0;
}

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

#define crap ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define CN cout<<"No\n"
#define CY cout<<"Yes\n"

using namespace std;
using ll = long long;
void solve()
{
    ll n; cin>>n;
    vector<ll>v(n);
    rep(i,n) cin>>v[i];
    vector<ll>c(n+1,0);
    for(int i=1;i<=n;i++)
    {
        c[i]=(c[i-1]+v[i-1])%1000000007;
    }
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        ans=(ans+(c[i]*v[i])%1000000007)%1000000007;
    }
    cout<<ans<<"\n";
}
int main()
{
    crap;
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r", stdin) ;
        freopen("output.txt","w", stdout) ;
        freopen("error.txt","w", stderr) ;
    #endif
    int t;t=1;
 //  cin>>t;
    while(t--)
        {solve();}
    return 0;
}

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

using namespace std;

int main() {
    long long int x,ans;
    cin >> x;
    if(x > 499){
       ans = 1000 * (x/500);
       x = x % 500;
    }
    if(x > 4){
       ans =ans + 5 * (x/5);
       //x = x % 5;
    }
    cout  << ans;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvpii = std::vector<vpii>;
using vch = std::vector<char>;
using vvch = std::vector<vch>;

const ll mod197 = 1000000007LL;
const ll INF = 200LL * 200 * 100000 + 10;

const double PI11 = 3.14159265359;


int main(void)
{

	string s;
	cin >> s;

	cout << s.rfind("Z") - s.find("A") + 1 << endl;

	return 0;
}

Measured memory_bytes: 640
#include <vector>
#include <iostream>

using namespace std;

long long gcd(long long a, long long b)
{
	if (a == 0) { return b; }
	if (b == 0) { return a; }

	if (a > b) { return gcd(b, a % b); }

	return gcd(a, b % a);
}

long long lcm(long long a, long long b)
{
	return a / gcd(a, b) * b;
}

vector<int> G; // i --> G[i] Graph

vector<bool> visited;

vector<vector<int> > cycles;

void rec(int p)
{
	visited[p] = true;

	cycles.back().push_back(p);

	if (!visited[G[p]])
	{
		rec(G[p]);
	}
}

int extgcd(int a, int b, int &x, int &y)
{
	int d = a;

	if (b != 0)
	{
		d = extgcd(b, a % b, y, x);

		y -= (a / b) * x;
	}
	else
	{
		x = 1; y = 0;
	}

	return d;
}

int modinv(int a)
{
	int x, y;

	extgcd(a, 1000000007, x, y);

	return (1000000007 + x % 1000000007) % 1000000007;
}

int main()
{
	int V, Q;

	scanf("%d", &V);
	scanf("%d", &Q);

	G = vector<int>(V);

	for (int i = 0; i < V; i++)
	{
		scanf("%d", &G[i]); G[i]--; // 1 -> 0 indexed
	}

	visited = vector<bool>(V, false);

	for (int i = 0; i < V; i++)
	{
		if (!visited[i])
		{
			cycles.push_back(vector<int>());

			rec(i);
		}
	}

	vector<int> val(V, 0), num(V, 0);

	for (int i = 0; i < cycles.size(); i++)
	{
		int sum = 0;

		for (int j = 0; j < cycles[i].size(); j++)
		{
			sum += cycles[i][j] + 1;
		}

		for (int j = 0; j < cycles[i].size(); j++)
		{
			val[cycles[i][j]] = sum;

			num[cycles[i][j]] = cycles[i].size();
		}
	}

	vector<vector<int> > sum(V, vector<int>(41));

	sum[0][num[0]] = 1;

	for (int i = 1; i < V; i++)
	{
		sum[i][num[i]] = 1;

		for (int j = 2; j <= 40; j++)
		{
			sum[i][j] += sum[i - 1][j];
		}
	}

	vector<int> sum2(V);

	sum2[0] = (1LL * modinv(num[0]) * val[0]) % 1000000007;

	for (int i = 1; i < V; i++)
	{
		sum2[i] = (sum2[i - 1] + 1LL * modinv(num[i]) * val[i]) % 1000000007;
	}

	int l, r;

	for (int i = 0; i < Q; i++)
	{
		scanf("%d", &l); l--; // 1 -> 0 indexed
		scanf("%d", &r); r--;

		long long rep = 1; int c;

		for (int i = 2; i <= 40; i++)
		{
			c = sum[r][i];

			if (l != 0)
			{
				c -= sum[l - 1][i];
			}

			if (c != 0)
			{
				rep = lcm(rep, i);
			}
		}

		int ret = sum2[r] + 1000000007;

		if (l != 0)
		{
			ret -= sum2[l - 1];
		}

		ret %= 1000000007;

		ret = 1LL * rep % 1000000007 * ret % 1000000007;

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

	return 0;
}

Measured memory_bytes: 24752
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ll x,y,a,b,c,temp;
    cin>>x>>y>>a>>b>>c;
    deque<ll>red,green,colorless;
    for(ll i=0;i<a;i++){
        cin>>temp;
        red.push_back(temp);
    }
     for(ll i=0;i<b;i++){
        cin>>temp;
        green.push_back(temp);
    }
     for(ll i=0;i<c;i++){
        cin>>temp;
        colorless.push_back(temp);
    }
    sort(red.begin(),red.end(),greater<int>());
    sort(green.begin(),green.end(),greater<int>());
    sort(colorless.begin(),colorless.end(),greater<int>());

    ll sum=0;

vector<ll> p;
for(ll i=0;i<x;i++){
    p.push_back(red[i]);
}
for(ll i=0;i<y;i++){
    p.push_back(green[i]);
}
for(ll i=0;i<c;i++){
    p.push_back(colorless[i]);
}
sort(p.begin(),p.end(),greater<int>());
for(ll i=0;i<x+y;i++ ){
    sum+=p[i];
}
    cout<<sum;
    return 0;
}


Measured memory_bytes: 8816
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>

using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

  // vector<vector<vector<int> > > DP =  vector<vector<vector<int> > >(100001,vector<vector<int> >(2,vector<int>(2,0)));
void solve(void)
{
  string str;
  cin>>str;
  int N = str.size();
  string str1 = str.substr(0,(N-1)/2);
  string str2 = str.substr((N+1)/2,N-1);
  string rstr = str;
  string rstr1 = str1;
  string rstr2 = str2;
  reverse(ALL(rstr));
  reverse(ALL(rstr1));
  reverse(ALL(rstr2));
  // DEBUG(rstr,rstr2);
  if(str==rstr && str1 == rstr1 && str2 == rstr2)
  {
    cout<<"Yes"<<endl;
  }
  else
  {
    cout<<"No"<<endl;
  }
  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 256
n, a, b, c = map(int, input().split())
q = [(0, 1) if s == 'AB' else (1, 2) if s == 'BC' else (0, 2) for s in (input() for _ in range(n))]
ans = []
ch = ('A', 'B', 'C')
d = [a, b, c]

for (x, y), t in zip(q, q[1:] + [()]):
    if d[x] + d[y] == 0:
        print('No')
        break
    if d[x] > d[y] or d[x] * d[y] == 1 and y in t:
        x, y = y, x
    d[x] += 1
    d[y] -= 1
    ans.append(ch[x])
else:
    print('Yes', *ans, sep='\n')


Measured memory_bytes: 12180
#include <iostream>
#include <map>
#include <utility>
#include <algorithm>
using namespace std;

int main() {
  int count = 0, n, t;
  map<pair<int, int>, bool> rec;
  cin >> n;
  for(int i = 1; i <= n; i++) {
    cin >> t;
    if(rec.find(make_pair(min(i, t), max(i, t))) != rec.end()) {
      count++;
    } else {
      rec.insert(make_pair(make_pair(min(i, t), max(i, t)), 1));
    }
  }
  cout << count << endl;
}


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

int main(){
  int n,k;
  cin >>n >>k;
  
  vector<int> h(n);
  for(int i=0;i<n;i++){
    cin>> h.at(i);
  }

  sort(h.begin(),h.end());
  
  int c=n;
  for(int i=0;i<n;i++){
    if(h.at(i)>=k){break;}
    else{
      c--;
    }
  }
  
  cout<<c<<endl;
  
  
  return(0);
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main() {
    int n;
    cin >> n;
    map<int, vector<int>> m;
    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        m[b].push_back(a);
    }
    int t = 0;
    for (pair<int, vector<int>> p : m) {
        for (int c: p.second) {
            t += c;
            if (t > p.first) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 22144
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);

        final String S = sc.next();
        final String ans = S
                .replace("eraser", "")
                .replace("erase", "")
                .replace("dreamer", "")
                .replace("dream", "");

        System.out.println(ans.length() == 0 ? "YES" : "NO");
    }
}


Measured memory_bytes: 28784
#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;
  cin >> n;
  ll mi=1001001001001001;
  rep(i,5) {
    ll x;
    cin >> x;
    mi=min(mi,x);
  }

  ll ans = (n+mi-1)/mi+4;

  cout << ans << endl;
}


Measured memory_bytes: 256
//In the name of God
#include<bits/stdc++.h>

using namespace std;

const int MOD = 1e9 + 7;
const int N = 2e5 + 10;

int n, a[N], b[N], res;
int f[4010][4010], c[4010][4010];

int g(int x){ return x + 2000; }

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for(int i = 0; i < n; i ++){
		cin >> a[i] >> b[i];
		f[g(a[i])][g(b[i])] ++;
	}
	for(int i = 2000; i > -2001; -- i)
		for(int j = 2000; j > -2001; -- j){
			f[g(i)][g(j)] += f[g(i + 1)][g(j)] + f[g(i)][g(j + 1)];
			if(f[g(i)][g(j)] >= MOD)	f[g(i)][g(j)]-= MOD;
		}
	for(int i = 0; i < 4001; i ++)
		c[i][0] = c[0][i] = 1;
	for(int i = 1; i < 4001; i ++)
		for(int j = 1; j < 4001; j ++){
			c[i][j] = c[i][j - 1] + c[i - 1][j];
			if(c[i][j] >= MOD)	c[i][j] -= MOD;
		}
	for(int i = 0; i < n; i ++){
		res += f[g(-a[i])][g(-b[i])];
		if(res >= MOD)	res -= MOD;
		res -= c[2 * b[i]][2 * a[i]];
		if(res < 0)	res += MOD;
	}
	res = 1LL * res * 500000004 % MOD;
	cout << res;
	return 0;
}

Measured memory_bytes: 127488
#include <cstdio>
#include <vector>
#include <stack>
using namespace std;
const long long MOD=1000000007;
struct matrix_exp{
    int s;
    vector<vector<long long> > pow;
    vector<vector<long long> > mat;
    vector<long long> empty_vector;
    long long mod;
    long long exp;
    matrix_exp(int _s,vector<vector<long long> > _mat, long long _exp, long long _mod){
        s=_s;
        for (int x=0;x<s;x++){
            pow.push_back(empty_vector);
            mat.push_back(empty_vector);
            for (int y=0;y<s;y++){
                pow[x].push_back(_mat[x][y]); mat[x].push_back(_mat[x][y]);
            }
        }
        mod=_mod;
        exp=_exp;
    }
    void mul(){
        long long arr[s][s];
        long long k;
        for (int x=0;x<s;x++){
            for (int y=0;y<s;y++){
                k=0;
                for (int z=0;z<s;z++){
                    k=(k+mat[x][z]*pow[z][y])%mod;
                }
                arr[x][y]=k;
            }
        }
        for (int x=0;x<s;x++){
            for (int y=0;y<s;y++){
                mat[x][y]=arr[x][y];
            }
        }
    }
    void sq(){
        long long arr[s][s];
        long long k;
        for (int x=0;x<s;x++){
            for (int y=0;y<s;y++){
                k=0;
                for (int z=0;z<s;z++){
                    k=(k+mat[x][z]*mat[z][y])%mod;
                }
                arr[x][y]=k;
            }
        }
        for (int x=0;x<s;x++){
            for (int y=0;y<s;y++){
                mat[x][y]=arr[x][y];
            }
        }
    }
    vector<vector<long long> > query(){
        stack<int> s;
        while (exp){
            if (exp&1){
                s.push(1);
                exp--;
            }
            else {
                s.push(0);
                exp>>=1;
            }
        }
        if (!s.empty()) s.pop();
        while (!s.empty()){
            if (s.top()&1){
                mul();
            }
            else{
                sq();
            }
            s.pop();
        }
        return mat;
    }
};
int n;
long long k;
int main(){
    scanf("%d%lld",&n,&k);
    vector<vector<long long> > v;
    int t;
    for (int x=0;x<n;x++){
        v.push_back(*new vector<long long>());
        for (int y=0;y<n;y++){
            scanf("%d",&t);
            v[x].push_back(t);
        }
    }
    v=(new matrix_exp(n,v,k,MOD))->query();
    long long ans=0;
    for (int x=0;x<n;x++){
        for (int y=0;y<n;y++){
            ans=(ans+v[x][y])%MOD;
        }
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
const ll inf = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////

int main() {
	int N, M; cin >> N >> M;
	vector<int>v(N);
	for (int i = 0; i < N; ++i) {
		int a; cin >> a;
		v[i] = a;
	}
	sort(v.begin(), v.end());
	vector<ll>sum;
	sum.push_back(0);
	for (int i = 1; i <= N; ++i) {
		sum.push_back(sum[i - 1] + v[i - 1]);
	}
	vector<pii>P;
	for (int i = 0; i < M; ++i) {
		int b, c; cin >> b >> c;
		P.push_back({ c,b });
	}
	sort(P.begin(), P.end(),greater<pii>());
	vector<int>key;
	int cnt = 0;
	for (int i = 0; i < M; ++i) {
		bool ok = false;
		for (int j = 0; j < P[i].second; ++j) {
			cnt++;
			key.push_back(P[i].first);
			if (cnt == N) {
				ok = true;
				break;
			}
		}
		if (ok)break;
	}
	vector<ll>sumk;
	sumk.push_back(0);
	for (int i = 1; i <= key.size(); ++i) {
		sumk.push_back(sumk[i - 1] + key[i - 1]);
	}
	ll ans = 0;
	for (int x = 0; x <= key.size(); ++x) {
		ll s = 0;
		s += sumk[x];
		s += (sum[N] - sum[x]);
		ans = max(ans, s);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4468
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int id[500][500];
long long cntb[200000],cntw[200000];
int h,w;
bool in(int y,int x){
    if(0<=y&&y<h&&0<=x&&x<w) return true;
    return false;
}
int main(){
    cin>>h>>w;
    string s[h]; rep(i,h) cin>>s[i];
    queue<pair<int,int>> q;
    int now=0;
    rep(i,h)rep(j,w){
        now++;
        if(id[i][j]!=0) continue;
        // id[i][j]=now;
        q.push({i,j});
        while(q.size()){
            auto p=q.front(); q.pop();
            int y=p.first,x=p.second;
            if(id[y][x]!=0) continue;
            // cout<<y<<" "<<x<<endl;
            id[y][x]=now;
            if(s[y][x]=='#') cntb[now]++;
            if(s[y][x]=='.') cntw[now]++;
            rep(k,4){
                int ny=y+dy[k],nx=x+dx[k];
                if(in(ny,nx)){
                    if(s[y][x]=='#'&&s[ny][nx]=='.'){
                        q.push({ny,nx});
                        // id[ny][nx]=now;
                    }
                    if(s[y][x]=='.'&&s[ny][nx]=='#'){
                        q.push({ny,nx});
                        // id[ny][nx]=now;
                    }
                }
            }
        }
    }
    // rep(i,3)rep(j,3){
    //     cout<<id[i][j]<<endl;
    // }
    long long ans=0;
    rep(i,200000){
        // cout<<cntb[i]<<" "<<cntw[i]<<endl;
        ans+=cntb[i]*cntw[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4224
// Bismillahirrahmanirrahim
// by Batrrr Tolkynbayev
#include <bits/stdc++.h>
// skripi krasava
#define respa return 0
#define all(x) x.begin(), x.end()
#define sz size
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 2e5 + 17, M = N << 2, mod = 1e9 + 7; 

int tt = 1, n;
string s, t;

void solve () {
	cin >> n >> s >> t;
	for (int i = 0; i < n; i++) {
		string f = s.substr(i, n - i);
		string h = t.substr(0, n - i);
		if (f == h) {
			cout << n + i; return;
		}
	}
	cout << (n << 1);
}

int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	// cin >> tt;
	while (tt--) solve();
	respa;
}

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

if A==B==C and A%2==0:
    print(-1)
    exit()

ans = 0
while A%2==0 and B%2==0 and C%2==0:
    tmpA = A//2
    tmpB = B//2
    tmpC = C//2
    A = tmpB+tmpC
    B = tmpC+tmpA
    C = tmpA+tmpB
    ans += 1

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()


int main(){
  ll N,a,b;
  cin >> N;
  vector<ll> X(N),Y(N);
  rep(i,N) {
    cin>> X.at(i);
    Y.at(i)=X.at(i);
  }
  sort(all(Y));
  a=Y.at(N/2-1);
  b=Y.at(N/2);
  rep(i,N){
    if(X.at(i)<=a){
      cout << b << endl;
    }else{
      cout << a << endl;
    }
  }
  
  
}
  

Measured memory_bytes: 5376