akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
#define repprev(i,a,b) for(ll i=b-1;i>=a;i--)
#define reprev(i,n) repprev(i,0,n)
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
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; }
template<class T> int former(const vector<T> &v, T x){
   return upper_bound(v.begin(),v.end(),x) - v.begin() - 1;
}
template<class T> int latter(const vector<T> &v, T x){
    return lower_bound(v.begin(),v.end(),x) - v.begin();
}
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define BIT_FLAG_0 (1<<0) // 0000 0000 0000 0001
#define BIT_FLAG_1 (1<<1) // 0000 0000 0000 0010
#define BIT_FLAG_2 (1<<2) // 0000 0000 0000 0100
#define BIT_FLAG_3 (1<<3) // 0000 0000 0000 1000
#define BIT_FLAG_4 (1<<4) // 0000 0000 0001 0000
#define BIT_FLAG_5 (1<<5) // 0000 0000 0010 0000
#define BIT_FLAG_6 (1<<6) // 0000 0000 0100 0000
#define BIT_FLAG_7 (1<<7) // 0000 0000 1000 0000
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll LLINF = 1LL<<60;
const int INF = 1<<29;

const int MAX = 510000;
const int MOD = 1000000007;



const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};


int main(void) {
	ios::sync_with_stdio(false);
	cin.tie(0);  
	string s;
	cin >> s;
	int ans = INF;
	rep(i,s.size()-2){
		
		chmin(ans,abs(753 - stoi(s.substr(i,3))));
	}                           
	cout << ans << endl;                                    
}


Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
MS = []
m.times do |i|
  MS << gets.split.map(&:to_i)[1..-1]
end
PS = gets.split.map(&:to_i)

COUNT = []
def call(ary)
  size = (MS.select.with_index do |m, i|
    (m & ary).size%2 == PS[i]
  end).size
  if size == MS.size
    COUNT << 1
  end
end

def add(ary, i)
  if i <= 0
    call(ary)
  else
    tmp_ary = ary.dup
    add(tmp_ary, i-1)
    ary << i
    add(ary, i-1)
  end
end

ary = []
add(ary, n)

puts COUNT.size


Measured memory_bytes: 2172
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int n,a;
    cin>>n>>a;
    n%=500;
    
    if(n>a)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(s);
  REP(i,s.size()){
    if(i%2==0) t.pb(s[i]);
  }
  OUT(t);
}

Measured memory_bytes: 592
parseInt(x) = parse(Int, x)
parseArray(x::Array{SubString{String}, 1}) = map(parseInt, x)

function main()
  N,L = readline() |> split |> parseArray

  ix=collect(1:N)
  _,i=findmin(abs(ix+L-1))
  result=sum(ix+L-1)-(i+L-1)

  println(result)
end

main()


Measured memory_bytes: 169580
#include<bits/stdc++.h>
#define mod 1000000007
#define endl '\n'
typedef long long int ll ;
using namespace std;
int main()
{
   ll n;
   cin>>n;
   ll arr[n+3];
   for(int i=1;i<=n;i++){
       ll a;
       cin>>arr[i];
   }
   ll sum=0;
   for(int i=1;i<=n;i++){
       for(int j=i+1;j<=n;j++){
           sum+=arr[i]*arr[j];
       }
   }
   cout<<sum<<endl;
}

Measured memory_bytes: 256
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,avx,avx2,mmx,abm")
#pragma GCC optimize("unroll-loops,inline")
#include <bits/stdc++.h>

using namespace std;

const int MOD = 998244353;

int add(int a, int b) {
	a += b;
	if (a >= MOD) a -= MOD;
	return a;
}

const int MAXN = 3010;
int n, s;
int a[MAXN];
int dp[MAXN];

signed main() {
	scanf("%d%d", &n, &s);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	int ans = 0;
	for (int i = 0; i <= s; i++)
		dp[i] = 0;
	for (int i = 1; i <= n; i++) {
		for (int w = s - a[i]; w >= 1; w--) {
			dp[w + a[i]] = add(dp[w + a[i]], dp[w]);
		}
		dp[a[i]] = add(dp[a[i]], i);
		ans = add(ans, dp[s]);
	}
	printf("%d\n", ans);
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  string p;
  string q;
  for(int i=0;i<n;i++) {
    int a;
    cin >> a;
    p += to_string(a);
  }
  for(int i=0;i<n;i++) {
    int a;
    cin >> a;
    q += to_string(a);
  }
  string r;
  int a = 0;
  int b = 0;
  for(int i=0;i<n;i++) r += to_string(i+1);
  sort(r.begin(), r.end());

  int index = 1;
  do {
    if(r == p) a = index;
    if(r == q) b = index;
    index++;
  } while (next_permutation(r.begin(), r.end()));

  cout << abs(a-b) << endl;
}

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

using namespace std;

using ll = long long;

constexpr char newl = '\n';

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

    int n;
    cin >> n;

    vector<int> ju(n, false);
    for (int i = 0; i < n; i++) {
        int d1, d2;
        cin >> d1 >> d2;
        ju[i] = (d1 == d2);
        if (i >= 2) {
            if (ju[i - 2] && ju[i - 1] && ju[i]) {
                cout << "Yes\n";
                return 0;
            }
        }
    }
    cout << "No\n";

    return 0;
}

Measured memory_bytes: 3652
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>

//AtCoderC++.cpp

using namespace std;

template<typename T> void Show(vector<vector<T>> v) {
	for (int i = 0; i < v.size(); i++) {
		for (int j = 0; j < v[i].size(); j++) {
			cout << v[i][j];
			if (j != v[i].size() - 1) {
				cout << " ";
			} else {
				cout << endl;
			}
		}
	}
}


template<typename T> void Show(vector<T> v) {
	for (int i = 0; i < v.size(); i++) {
		cout << v[i];
		if (i != v.size() - 1) {
			cout << " ";
		} else {
			cout << endl;
		}
	}
}


int main() {
	int N,A;
	cin >> N>>A;
	cout << N * N - A << endl;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define int long long
using namespace std;
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 (a>b) { a=b; return 1; } return 0; }

const int INF=1e18;

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

    int N,M; cin>>N>>M;
    vector<int> a(M),T(M);
    for(int i=0;i<M;i++){
        int k; cin>>a[i]>>k;
        while(k--){
            int c; cin>>c;
            c--;
            T[i]|=1<<c;
        }
    }

    vector<vector<int>> dp(M+1,vector<int>(1<<N,INF));
    dp[0][0]=0;
    for(int i=0;i<M;i++){
        for(int S=0;S<(1<<N);S++){
            chmin(dp[i+1][S],dp[i][S]);
            chmin(dp[i+1][S|T[i]],dp[i][S]+a[i]);
        }
    }
    int ans=dp[M][(1<<N)-1];
    cout<<(ans==INF? -1:ans)<<endl;
    return 0;
}

Measured memory_bytes: 32384
#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 W, H;
vector<string> S;
vector<vector<int>> cost;
int bfs(){
    int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

    queue<P> que;
    que.push(make_pair(0, 0));
    cost[0][0] = 0;

    while(!que.empty()) {
        auto p = que.front();
        que.pop();
        if(p == make_pair(H-1, W-1)) return cost[H-1][W-1];

        rep(i, 4) {
            int ny = p.first + dy[i], nx = p.second + dx[i];
            if(nx < 0 || ny < 0 || nx >= W || ny >= H) continue;
            if(S[ny][nx] == '#') continue;
            if(cost[ny][nx] != -1) continue;

            cost[ny][nx] = cost[p.first][p.second] + 1;
            que.push(make_pair(ny, nx));
        }
    }
    return -1;
}

int main() {
    cin >> H >> W;
    S = vector<string>(H);
    rep(i, H) cin>>S[i];

    int white = 0;
    rep(i, H)
        rep(j, W) if(S[i][j] == '.') white++;

    cost = vector<vector<int>>(H, vector<int>(W, -1));
    int min_cost = bfs();
    if (min_cost == -1) cout << -1 << endl;
    else cout << white - (min_cost+1) << endl;

    return 0;
}


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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#define unordered_map __fast_unordered_map
template<class Key, class Value, class Hash = std::hash<Key>>
using unordered_map = __gnu_pbds::gp_hash_table<Key, Value, Hash>;

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif


int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);

  vector<int> counts(13);
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    int v;
    cin >> v;
    ++counts[v];
  }

  int best_res = 0;
  for (int mask = 0; mask < (1 << 12); ++mask) {
    vector<int> taken(24);
    taken[0] = 1;

    for (int t = 0; t <= 12; ++t) {
      taken[t] += counts[t];
      if (t && (mask & (1 << (t - 1))) && counts[t]) {
        --taken[t];
        ++taken[24 - t];
      }
    }

    taken.push_back(1);

    int max_dist = 1e9;

    for (int i = 0; i <= 24; ++i) {
      if (taken[i] >= 2) { max_dist = 0; }

      for (int j = i + 1; j <= 24; ++j)
        if (taken[i] && taken[j])
          mini(max_dist, j - i);
    }

    maxi(best_res, max_dist);
  }

  cout << best_res << "\n";
}


Measured memory_bytes: 256
# シェルソート

N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

cnt = 0


def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        for j in range(i-g, -1, -g):
            if A[j+g] < A[j]:
                A[j + g], A[j] = A[j], A[j + g]
                cnt += 1
            else:
                break


def shellSort(A, n):
    # gn+1 = 3gn + 1
    h = 1
    G = []
    while h <= n:
        G.append(h)
        h = 3 * h + 1
    G.reverse()
    print(len(G))
    print(" ".join([str(x) for x in G]))
    for g in G:
        insertionSort(A, n, g)


shellSort(A, N)
print(cnt)
for a in A:
    print(a)



Measured memory_bytes: 45520
#include<math.h>
#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    if (a>b) printf("a > b\n");
    if (a==b) printf("a == b\n");
    if(a<b) printf("a < b\n");
    return 0;
}





Measured memory_bytes: 2700
#include<iostream>
#include<cmath>
using namespace std;
int main(void){
  for(int n;cin>>n,n;){
    int y;
    cin>>y;
    double m=0;
    int bn;
    for(int i=1;i<=n;i++){
      int b,r,t;
      cin>>b>>r>>t;
      double cm=((t==1)?1+y*r/100.:pow(1+r/100.,y));
      if(cm>m){
    m=cm;
    bn=b;
      }
    }
    cout<<bn<<endl;
  }
  return 0;
}



Measured memory_bytes: 3112
#!/usr/bin/env pypy
from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__


def main():
    n = int(input())
    a = [int(wi) for wi in input().split()]

    pref_sums = [0] * (n + 1)
    for i in range(n):
        pref_sums[i + 1] = pref_sums[i] + a[i]

    suff_sums = [0] * (n + 1)
    for i in reversed(range(n)):
        suff_sums[i] = suff_sums[i + 1] + a[i]

    res = 10**18
    for i in range(n):
        res = min(res, abs(pref_sums[i] - suff_sums[i]))
    print(res)


# region fastio

BUFSIZE = 8192


class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 29292
#include<cmath>
#include<bits/stdc++.h>
#define MAX(a,b) (a>b? a:b)
#define MIN(a,b) (a>b? b:a)
#define rep(i,n) for(lint i=0;i<(lint)(n);i++)
#define repr(i,n) for(lint i=(lint)(n);i>0;--i)
#define reps(i,a,b) for(lint i=a;i<=(lint)(b);i++)
typedef long long lint;
typedef long double ld;
using namespace std;
const ld PI = acos(-1.0);

int main(){
    int N;
    cin >> N;
    vector<int> H(N);
    rep(i,N) cin >> H[i];
    int max=H[0];
    int cnt = 1;
    rep(i,N-1) {
        max=MAX(max,H[i]);
        if(H[i+1]>=max) cnt++;
    }
    cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
//agrawal117
//chahatagrawal117
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
typedef long long int ll;
using namespace std;
#define MAX 100005
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n; cin>>n;
    vector<pair<ll,ll>> v;
    for(int i=1;i<=n;i++){
        ll a,b; cin>>a>>b;
        ll x=a-b; ll y=a+b;
        v.push_back({x,y});
    }
    sort(v.begin(),v.end());
    set<ll> st;
    st.insert(v[0].second);
    ll ans=0;
    for(int i=1;i<v.size();i++){
        ans=max(ans,abs(v[i].first-v[0].first));
        auto it=st.begin();
        ans=max(ans, abs(*it-v[i].second));
        it=st.end();
        it--;
        ans=max(ans,abs(*it-v[i].second));
        st.insert(v[i].second);
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 15848
#include <algorithm>
#include <iomanip>
#include <iostream>

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

using namespace std;

/** Problem0110 : Alphametic **/
string sum(string a, string b)
{
	string  s;
	int n, tmp, la, lb;
	bool up=false;
	
		s=""; up=0;
		
		reverse(a.begin(), a.end());
		reverse(b.begin(), b.end());
		la=(int)a.length();
		lb=(int)b.length();
		
		if (la < lb) {
			swap(la, lb);
			swap(a, b);
		}
		
		for (int i = 0; i<la-lb; i++) b+='0';
		
		for (int i=0; i<la; i++) {
			tmp = (a[i]-'0') + (b[i] - '0') + (up?1:0);
			if (tmp>=10) {
				s += '0'+tmp%10;
				up = true;
			} else {
				s += '0'+tmp;
				up = false;
			}
		}
		
		if (up)
			s+='1';
		reverse(s.begin(), s.end());
		
		return s;
}

int main()
{
	string s;
	while (1) {
		getline(cin, s);
		if (cin.eof()) break;
		
		rep(j, 10) {
			string a, b, ans;
			
			int i=0;
			for(; i<s.length(); i++) {
				if (s[i]=='X')
					a+=j+'0';
				else if (s[i]!='+')
					a+=s[i];
				else
					break;
			}
			
			for(i++; i<s.length(); i++) {
				if (s[i]=='X')
					b+=j+'0';
				else if (s[i]!='=')
					b+=s[i];
				else
					break;
			}
			
			for(i++; i<s.length(); i++) {
				if (s[i]=='X')
					ans+=j+'0';
				else
					ans+=s[i];
			}
			
			if (a.length()>=2 && a[0]=='0') continue;
			if (b.length()>=2 && b[0]=='0') continue;
			if (ans.length()>=2 && ans[0]=='0') continue;

			if (sum(a, b) == ans) {
				cout << j << endl;
				goto end;
			}
		}
		cout << "NA" << endl;
	end:;
	}
	
	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rrep(i,n) for(int i=1; i<=(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

//const ll mod=1000000007;

int main() {
    int N;
    cin>>N;
    vector<pii> P;
    rep(i,N) {
        int a,b;
        cin>>a>>b;
        P.pb(make_pair(b,a));
    }
    sort(all(P));
    ll counter=0;
    for(auto c : P) {
        counter+=c.se;
        if(counter>c.fi) {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}

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

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define lp(i, a, b) for (int i=a; i<(b); i++)
#define lpd(i,a,b) for (int i = (b)-1; i >= a; i--)
	
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;

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

    const int mod = 1e9 + 7;
    int n;
    cin>>n;

    unordered_map<string, int> dp[n+1];

    lp(j, 0, 4){
        lp(k, 0, 4){
            lp(l, 0, 4){
                string sj = to_string(j);
                string sk = to_string(k);
                string s = to_string(l);
                s = s + sk + sj;
                if (s!="021" && s!="012" && s!="201")
                    dp[3][s] = 1;
            }
        }
    }

    lp(i, 4, n+1){
        lp(j, 0, 4){
            lp(k, 0, 4){
                lp(l, 0, 4){
                    lp(m, 0, 4){
                        string sj = to_string(j);
                        string sk = to_string(k);
                        string sl = to_string(l);
                        string sm = to_string(m);
                        string s = sl + sk + sj;
                        string s1 = sm + sl + sj;
                        string s2 = sm + sk + sj;
                        string ss = sm + sl + sk;

                        if (s=="021" || s=="012" || s=="201") continue;
                        if (s1=="021" || s2=="021") continue;
                        
                        dp[i][s] += dp[i-1][ss];
                        dp[i][s] %= mod;
                    }
                }
            }
        }
    }
    
    int sum = 0;
    lp(j, 0, 4){
        lp(k, 0, 4){
            lp(l, 0, 4){
                string s = to_string(j) + to_string(k) + to_string(l);
                sum += dp[n][s];
                sum %= mod;
            }
        }
    }

    cout<<sum<<endl;

    return 0;
}

Measured memory_bytes: 896
#include <iostream>

using namespace std;

int d[1005][1005];

int edit_distance(string& s1, string& s2)
{
    for(int i = 0; i < 1005; ++i){
        d[0][i] = i;
        d[i][0] = i;
    }
    for(int i = 1; i <= s1.size(); ++i){
        for(int j = 1; j <= s2.size(); ++j){
            d[i][j] = min(d[i][j - 1] + 1, min(d[i - 1][j] + 1, d[i - 1][j - 1] + (s1[i - 1] != s2[j - 1])));
        }
    }
    return d[s1.size()][s2.size()];
}

int main()
{
    string s1, s2;
    cin >> s1 >> s2;
    cout << edit_distance(s1, s2) << endl;
}

Measured memory_bytes: 7172
'''
Created on 2020/08/28

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N,M=map(int,pin().split())
  if 2*N>M:
    print(M//2)
  else:
    print(N+((M-2*N)//4))
  return 

main()

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

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	
	rep(i, N-1) {
		int a;
		cin >> a;
		A[a-1] += 1;
	}
	rep(i, N) cout << A[i] << endl;
}

Measured memory_bytes: 3924
#include<cstdio>
using namespace std;
int main(void){
	int a,b,c,d,p,q;
	double x,y;
	while(scanf("%d%d%d%d%d%d",&a,&b,&p,&c,&d,&q)!=EOF){
		x=(double)(d*p-b*q)/(a*d-b*c);
		y=(double)(c*p-a*q)/(b*c-a*d);
		if(-0.001<x&&x<0.001)	x=0;
		if(-0.001<y&&y<0.001)	y=0;
		printf("%.3lf %.3lf\n",x,y);
	}
	return 0;
}


Measured memory_bytes: 2608
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main(int argc, const char * argv[]){
    
    int f = 0,len;
    char ch[21],temp;
    scanf("%s",ch);
    len = (int)strlen(ch) - 1;
    //ch[(int)strlen(ch)] = "\0";
    
    while(1){
        if(len < f || len == f ){
            printf("%s\n",ch);
            break;
        }
        temp = ch[len];
        ch[len] = ch[f];
        ch[f] = temp;
        //printf("%s\n",ch);
        f++;
        len--;
    }
    
    //printf("%s\n",ch);
    return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
	int n;
	cin >> n;
	string s[n], t;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	cin >> t;
	int Left = 0, Right = 0;
	for (int i = 0; i < n; i++) {
		string SubString = s[i];
		for (int j = 0; j < s[i].size(); j++) {
			if (s[i][j] == '?') {
				SubString[j] = 'a';
			}
		}
		bool FlagL = false, FlagR = false;
		if (SubString == t) {
			Right++;
			continue;
		} else if (SubString < t) {
			FlagL = true;
		} else {
			FlagR = true;
		}
		SubString = s[i];
		for (int j = 0; j < s[i].size(); j++) {
			if (s[i][j] == '?') {
				SubString[j] = 'z';
			}
		}
		if (SubString == t) {
			Right++;
			continue;
		} else if (SubString < t) {
			FlagL = true;
		} else {
			FlagR = true;
		}
		if (FlagL && FlagR) {
			Right++;
		} else if (FlagL) {
			Left++;
		}
	}
	for (int i = Left; i <= Left + Right; i++) {
		cout << i + 1 << (i == Left + Right ? (char)'\n' : (char)' ');
	}
	return 0;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
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()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  string s, t, u; int a, b; cin >> s >> t >> a >> b >> u;
  if (s == u) {
    cout << a - 1 << ' ' << b << '\n';
  } else {
    cout << a << ' ' << b - 1 << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		long ans = 0;

		if (n == 1 && m >= 3)
			ans = m - 2;
		else if (m == 1 && n >= 3)
			ans = n - 2;
		else if (n == 1 && m == 1)
			ans = 1;
		else if (n != 1 && m != 1)
			ans = (long) (n - 2) * (long) (m - 2);
		else
			ans = 0;

		System.out.println(ans);

	}
}


Measured memory_bytes: 23632
import copy

n = int(input())
t = list(map(int,input().split()))
m = int(input())


for i in range(m):
    x,y = map(int,input().split())
    s = copy.copy(t)
    s[x-1] = y
    ans = 0

    for j in range(n):
        ans += s[j]

    print(ans)

Measured memory_bytes: 3572
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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; }
///////////////////////////////////////////////////////////////////////////////////////////////////

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

using mint = modint<MOD>;

int N;
vector<vector<int>> G;
int cnt[202020];
mint beki[202020];
mint dp[202020];
int dfs1(int v, int pv) {
    cnt[v] = 1;
    for (auto nv: G[v]) {
        if (nv == pv) continue;
        cnt[v] += dfs1(nv,v);
    }
    return cnt[v];
}

void dfs2(int v, int pv) {
    dp[v] = beki[N-1] - beki[N-cnt[v]];
    for (auto nv : G[v]) {
        if (nv == pv) continue;
        dp[v] -= (beki[cnt[nv]]-1);
        dfs2(nv,v);
    }
}
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    cin >> N;
    G.resize(N);
    rep(i,N-1) {
        int u,v; cin >> u >> v;
        --u; --v;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }
    beki[0] = 1;
    rep(i,N) beki[i+1] = beki[i]*2;
    dfs1(0,-1);
    dfs2(0,-1);

    mint ans = 0;
    rep(i,N) ans += dp[i];
    ans /= beki[N];
    cout << ans.a << ln;
}

Measured memory_bytes: 19584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9 + 7;
const int MAX = 510000;

int main() {
    ll n,m; cin >> n >> m;
    vvl G(n);
    rep(i,m){
        ll a,b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    queue<ll> q;
    q.push(0);
    vl d(n,inf);
    d[0] = 0;
    while (!q.empty()){
        ll u = q.front(); q.pop();
        for(auto v : G[u]){
            if(d[v] != inf) continue;
            d[v] = d[u] + 1;
            q.push(v);
        }
    }
    if(d[n-1]==2) puts("POSSIBLE");
    else puts("IMPOSSIBLE");
}

Measured memory_bytes: 15208
n,k=map(int,input().split())
*h,=map(int,input().split())

dp=[0]*n
for i in range(1,n):
    dpmin=[]
    for j in range(max(0,i-k),i):
        dpmin.append(dp[j]+abs(h[i]-h[j]))
    dp[i]=min(dpmin)
print(dp[-1])


Measured memory_bytes: 56032
import sys
import math
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7


def main():
  N, K = map(int, readline().split())
  if N<K:
    ans = 1
  else:
    ans = math.ceil(math.log(N,K))
  print(ans)
  
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,m;

int main(){
  ll ans=0;
  cin >> n >> m;

  ll a=min(n,m);
  ll b=max(n,m);
  REP(i,b){
    ans*=10;
    ans+=a;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

ll H,W,ans=1e9,A,B,C,w;

int main(){
    cin>>H>>W;
    repi(i,1,H){
        A=i*W;
        w=(H-i)/2;
        B=w*W;
        C=(H-i-w)*W;
        ans=min(ans,max(A,max(B,C))-min(A,min(B,C)));
        w=W/2;
        B=(H-i)*w;
        C=(H-i)*(W-w);
        ans=min(ans,max(A,max(B,C))-min(A,min(B,C)));
    }
    repi(i,1,W){
        A=i*H;
        w=(W-i)/2;
        B=w*H;
        C=(W-i-w)*H;
        ans=min(ans,max(A,max(B,C))-min(A,min(B,C)));
        w=H/2;
        B=(W-i)*w;
        C=(W-i)*(H-w);
        ans=min(ans,max(A,max(B,C))-min(A,min(B,C)));
    }
    out(ans);
}


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

const int N = 100100;

vector <int> G[N], vec[2];
int cnt, flag;
int vis[N];

void dfs(int u, int f) {
  ++ cnt;
  for (int v : G[u]) {
    if (v == f) continue;
    if (vis[v]) {
      if (vis[v] == vis[u]) flag = 1; continue;
    }
    vis[v] = 3 - vis[u];
    dfs(v, u);
  }
}

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0, u, v; i < m; i ++)
    scanf("%d %d", &u, &v), G[u].push_back(v), G[v].push_back(u);
  int num = n;
  for (int i = 1; i <= n; i ++) {
    if (vis[i]) continue;
    flag = cnt = 0;
    vis[i] = 1;
    dfs(i, 0);
    if (cnt == 1)
      num --;
    else if (flag)
      vec[0].push_back(cnt);
    else
      vec[1].push_back(cnt);
  }
  LL ans = 1LL * n * n - 1LL * num * num;
  ans += 1LL * (vec[0].size() + vec[1].size()) * (vec[0].size() + vec[1].size()) + 1LL * vec[1].size() * vec[1].size();
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
  int a;
  cin >> a;

  int ans = a;
  ans += a * a;
  ans += a * a * a;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

const int mod = 1e9 + 7;

long long fact_mod(long long x) {
	long long ret = 1;

	while (x > 1) {
		ret = ret * x % mod;
		x--;
	}

	return ret;
}

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

	long long ans = 0;
	if (abs(n - m) > 1) {
		ans = 0;
	} else {
		ans = fact_mod(n) * fact_mod(m) % mod;
		if (n == m) {
			ans = ans * 2 % mod;
		}
	}

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


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

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  fspcnt = 0;
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}*/


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  int64_t n;
  cin >> n;
  vector<int64_t> a(n);
  rep(i,n){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  int64_t total1 = 0;
  int64_t total2 = 0;
  /*rep(i,n){
    cout << a[i] << ",";
  }
  cout << endl;*/
  if(n % 2 == 0){
    rep(i,(n-2)/2){
      total1 += (-2)*a[i];
    }
    total1 += (-1)*a[(n-2)/2];
    total1 += a[((n-2))/2+1];
    rep(i,(n-2)/2){
      total1 += 2*a[((n-2))/2+2+i];
    }  
  }else{
    rep(i,((n-2)/2)+1){
      total1 += (-2)*a[i];
    }
    total1 += a[((n-2)/2)+1];
    total1 += a[((n-2)/2)+2];
    rep(i,(n-2)/2){
      total1 += 2*a[((n-2))/2+3+i];
    }  
    
    rep(i,((n-2)/2)){
      total2 += (-2)*a[i];
    }
    total2 += -a[((n-2)/2)];
    total2 += -a[((n-2)/2)+1];
    rep(i,(n-2)/2+1){
      total2 += 2*a[((n-2))/2+2+i];
    }  
  }
  cout <<max(total1,total2)<< endl;
}

Measured memory_bytes: 1024
def main():
    S = input()
    n = len(S)
    bit = 0
    total = 0
    ans = ''
    for bit in range(1<<n-1):
        tmp_total = int(S[0])
        ops = ''
        for i in range(n-1):
            if (1<<i) & bit:
                tmp_total += int(S[i+1])
                ops += '+'
            else:
                tmp_total -= int(S[i+1])
                ops += '-'
        if tmp_total == 7:
            ans = S[0]
            for i,op in enumerate(ops):
                ans += op + S[i+1]
            ans += '=7'
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import sys
from pprint import *
N,K=map(int,input().split())
input=sys.stdin.readline
dpb=[[0 for _ in range(2*K+1)] for _ in range(2*K+1)]
def getmatnum(x1,y1,x2,y2,mat):#左上を(x1,y1)右下を(x2,y2)にしてmatの中の左上~右下の領域の和を算出
    return mat[y2][x2]-mat[y1][x2]-mat[y2][x1]+mat[y1][x1]

for i in range(N):
    x,y,c=input().split()
    x=int(x)
    y=int(y)
    #print(x,y,c)
    if c=="W":
        dpb[(y%(2*K))+1][((x+K)%(2*K))+1]=dpb[(y%(2*K))+1][((x+K)%(2*K))+1]+1
    else:
        dpb[(y % (2*K))+1][(x % (2*K))+1] = dpb[(y % (2*K))+1][(x % (2*K))+1] + 1
#pprint(dpw)
#pprint(dpb)

for i in range(1,2*K+1):
    for j in range(1,2*K+1):
        dpb[i][j]=dpb[i][j-1]+dpb[i][j]

for i in range(1,2*K+1):
    for j in range(1,2*K+1):
        dpb[i][j]=dpb[i-1][j]+dpb[i][j]

ans=0
for i in range(K):
    for j in range(K):
        k=i+K
        l=j+K
        b1=getmatnum(0,0,i,j,dpb)+getmatnum(k,0,2*K,j,dpb)+getmatnum(i,j,k,l,dpb)+getmatnum(0,l,i,2*K,dpb)+getmatnum(k,l,2*K,2*K,dpb)
        b2=getmatnum(i,0,k,j,dpb)+getmatnum(0,j,i,l,dpb)+getmatnum(k,j,2*K,l,dpb)+getmatnum(i,l,k,2*K,dpb)
        ans=max(ans,b1,b2)

        #print(i,j,k,l)
print(ans)
        #
#pprint(dpw)
#pprint(dpb)

Measured memory_bytes: 109164
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb emplace_back
#define mkp make_pair
#define p_q priority_queue
#define INF 2000000000
#define PI 3.1415926
#define coutdb cout << fixed << setprecision(10)

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

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

  int Q, A, B; cin >> Q;
  REP(query, Q){
    cin >> A >> B;
    if(A>B) swap(A, B);
    int ans = 2*A-2;
    int low = -1, high = B-A+1;
    while(high - low > 1){
      int mid = (high + low) / 2;
      int ng = 0;
      for(int x = mid/2-3; x <= mid/2+3; x++){
        if(x < 1 or x > mid) continue;
        ng |= (A+x)*(A+mid-x) >= A*B;
      }
      if(ng) high = mid;
      else low = mid;
    }
    ans += high-1;
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
module Main where

import Data.Functor
import Data.Char

main :: IO ()
main =  do
  { w  <- map toLower <$> getLine
  ; ws <- loop
  ; print $ length $ filter (w ==) ws
  }

loop :: IO [String]
loop = do
  { l <- getLine
  ; if l == "END_OF_TEXT" then return []
    else return . (words (map toLower l) ++) =<< loop
  }

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

#define int long long
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define yn(x) ((x) ? "Yes" : "No")

typedef pair <int, int> ii;
typedef pair <int, ii> iii;

const int siz = 2e5 + 10;
const int SIZ = 1e6 + 10;
const int mod = 1e9 + 7;
const int maxx = 2e9;
const int MAXX = 1e18;
const string file = "3";



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

//    freopen ((file + ".inp").c_str(), "r", stdin);
//    freopen ((file + ".out").c_str(), "w", stdout);

    int n, d;
    cin >> n >> d;

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        int x, y;
        cin >> x >> y;

        if (ceil(sqrt(x * x + y * y)) <= d) {
            ans++;
        }
    }

    cout << ans << "\n";

//    cerr << "Time: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

    return 0;
}


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

using namespace std;

int main(){
	int n,m;
	cin >> n >> m;
	vector<int> list(n);
	for(int i=0;i<n;i++){
		cin >> list[i];
	}
	sort(list.begin(),list.end());
	int ans=0;
	for(int i=n-1;i>=n-m;i--){
		ans+=list[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9 + 7

n = int(input())
li = [int(input()) for i in range(n)]
li.sort()
sumli = sum(li)
if sumli%10 != 0:
    print(sumli)
else:
    ans = 0
    for i in range(n):
        d = sumli - li[i]
        if d%10 != 0:
            ans = max(ans,d)
    print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    ll n;cin>>n;
    vector<vector<ll> >a(n,vector<ll>(n));
    ll sum=0;
    bool f=1;
    rep(i,n)rep(j,n){
        cin>>a[i][j];
        sum+=a[i][j];
    }
    sum/=2;
    rep(i,n-1){
        REP(j,i+1,n){
            rep(k,n){
                if(k!=i&&k!=j){
                    if(a[i][k]+a[k][j]<a[i][j]){
                        f=0;
                    }
                    if(a[i][k]+a[k][j]==a[i][j]){
                        sum-=a[i][j];
                        break;
                    }
                }
                if(!f)break;
            }
            if(!f)break;
        }
        if(!f)break;
    }
    cout<<(f?sum:-1)<<endl;
}

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

using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

string S;
int dp[220000][5];

int dfs(int idx, int n) {
    if (idx + n == S.length())return 1;
    if (dp[idx][n] != -1)return dp[idx][n];
    int ret = 0;
    for (int i = 1; i < 5; i++) {
        if (idx + n + i > S.length())continue;
        if (S.substr(idx, n) == S.substr(idx + n, i))continue;
        ret = max(ret, dfs(idx + n, i) + 1);
    }
    return dp[idx][n] = ret;
}

signed main() {
    cin >> S;
    int ans = 0;
    for (int i = 0; i < 220000; i++)for (int j = 0; j < 5; j++)dp[i][j] = -1;
    for (int i = 1; i < 5; i++)ans = max(ans, dfs(0, i));
    cout << ans << endl;
}


Measured memory_bytes: 33284
#include<iostream>
using namespace std;
#define N 1000001

int arr1[N+5],arr2[N+5];
int main()
{
    int n,m,a,b;

    cin>>n>>m;
    for(int i=0; i<m; i++)
    {
        cin>>a>>b;
        if(a==1)
            arr1[b]=1;//第一次的终点
        if(b==n)
            arr2[a]=1;//第二次的起点
    }

    int p=0;
    for(int i=1; i<=m; i++)
    {
        if(arr1[i]&&arr2[i])
        {
            cout<<"POSSIBLE"<<endl;
            p=1;
        }
    }

    if(p==0)
        cout<<"IMPOSSIBLE"<<endl;

    return 0;
}



Measured memory_bytes: 5120
#include <bits/stdc++.h>
 
using namespace std;
vector<long long> tree, lazy;
long long treeSize;
 
long long pot(long long x){
    long long tmp = 1;
    while(x){
        x/=2;
        tmp*=2;
    }
    return tmp;
}
 
void update(long long a, long long b){
    long long va = a+treeSize, vb = b+treeSize;
 
    tree[va]++;
    if(va!=vb) tree[vb]++;
 
    while(va/2!=vb/2){
        if(va%2==0) lazy[va+1]++;
        if(vb%2==1) lazy[vb-1]++;;
        va/=2; vb/=2;
    }
}
long long qur(long long a, long long q = 0, long long r = treeSize-1, long long pt = 1){
    if(q==r){
        tree[pt]+=lazy[pt];
        lazy[pt] = 0;
        return tree[pt];
    }
 
    lazy[pt*2] += lazy[pt];
    lazy[pt*2+1] += lazy[pt];
    lazy[pt] = 0;
    long long mid = (q+r)/2;
    long long out = 0;
    if(a<=mid)  return qur(a, q, mid, pt*2);
    else return qur(a, mid+1, r, pt*2+1);
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
    map<int, int> mp;
    long long n, q; cin>>n>>q;
    treeSize = pot(n);
    tree.resize(treeSize*2+1);
    lazy.resize(treeSize*2+1);
    vector<long long> tab;
    vector<pair<long long, pair<long long, long long>>> zap;
    for(long long i = 0; i < n; i++){
        long long a; cin>>a;
        tab.push_back(a);
    }
 
    for(long long i = 0; i < q; i++){
        long long a, b; cin>>a>>b;
        zap.push_back(make_pair(b, make_pair(a, i)));
    }
 
    sort(zap.begin(), zap.end());
    vector<long long> wyn(q);
    long long pt = 0;
    bool pos = true;
    for(long long i = 0; i < n; i++){
        update(mp[tab[i]], i);
        mp[tab[i]] = i+1;
        while(zap[pt].first==i+1){
            long long a = zap[pt].second.first, b = zap[pt].first, c = zap[pt].second.second;
            wyn[c] = qur(a-1);
            pt++;
            if(pt>=q){
                pos = false;
                break;
            }
        }
        if(!pos) break;
    }
    for(auto it:wyn) cout<<it<<endl;
}

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

int main(){
  int N, K;
  cin >> N >> K;
  int x;
  int cnt = 0;
  
  for (int i =0; i < N ; i++){
    cin >> x;
    if ( abs(K -x) < x ){
      cnt += 2 * abs(K - x);
    }
    else {
      cnt += 2*x;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256