akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

// Begin {{{
using namespace std;
#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, b, e) for (i64 i = (b), i##_limit = (e); i <= i##_limit; ++i)
#define repr(i, b, e) for (i64 i = (b), i##_limit = (e); i >= i##_limit; --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<>>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
inline i64 sigma(i64 n) { return n * (1 + n) >> 1; }
inline i64 updiv(i64 n, i64 d) { return (n + d - 1) / d; }
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;
#ifndef DEBUG
#define dump(...)
#endif

inline void input() {}
template <class Head, class... Tail>
inline void input(Head&& head, Tail&&... tail) {
    cin >> head;
    input(forward<Tail>(tail)...);
}

inline void outs() { cout << "\n"; }
template <class Head, class... Tail>
inline void outs(Head&& head, Tail&&... tail) {
    cout << head << (sizeof...(tail) ? " " : "");
    outs(forward<Tail>(tail)...);
}

template <class T>
inline void outs(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e == &vec.back()]; }

template <class T>
inline void outs(vector<vector<T>> &df) { for (auto &vec : df) outs(vec); }

inline void outl() { cout << "\n"; }
template <class Head, class... Tail>
inline void outl(Head&& head, Tail&&... tail) {
    cout << head << (sizeof...(tail) ? "\n" : "");
    outl(forward<Tail>(tail)...);
}

template <class T>
inline void outl(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

inline void outn() {}
template <class Head, class... Tail>
inline void outn(Head&& head, Tail&&... tail) {
    cout << head;
    outn(forward<Tail>(tail)...);
}

template <class T>
inline void outn(vector<T> &vec) { for (auto &e : vec) cout << e; }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}
// }}} End

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    var(int, N);
    vector<pii> vec;
    rep(i, N) {
        var(int, a);
        vec.emplace_back(a, i + 1);
    }
    sort(all(vec));
    vector<i64> ans;
    for (auto &e : vec) {
        ans.emplace_back(e.second);
    }
    outs(ans);
    return 0;
}


Measured memory_bytes: 4208
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
As = []
for i in range(N):
    As.append(list(map(int, input().split())))

correct_answer_num = 0
for A in As:
    result = 0

    for j in range(M):
        result += A[j] * B[j]

    result += C
    if result > 0:
        correct_answer_num += 1

print("{}".format(correct_answer_num))


Measured memory_bytes: 3064
let f () = Scanf.scanf "%d %d\n" (fun a b -> a, b)

let () =
  let n, d = f () in
  let d2 = d * d in
  let rec g i s =
    if i = n then
      print_int s
    else
      let x, y = f () in
      if x * x + y * y <= d2 then
        g (i + 1) (s + 1)
      else
        g (i + 1) s
  in g 0 0


Measured memory_bytes: 5868
program main
  implicit none

  integer :: n, d, nec

  read *, n, d

  if ( mod ( n, 2 * d + 1 ) == 0 ) then
     nec = n / ( 2.0 * d + 1.0 )
  else
     nec = n / ( 2.0 * d + 1.0 ) + 1
  end if
  
  print *, nec

end program main



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <functional>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// --------------------------------------------------------------------------


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int W,A,B;
  cin >> W >> A >> B;
  if(W+A <= B){
    cout << B-(W+A) << "\n";
  }else if(B+W<=A){
    cout << A-(B+W) << "\n";
  }else{
    cout << 0 << "\n";
  }


  return 0;
}

Measured memory_bytes: 3580
import Control.Monad
import Data.List

addCsum :: [Int] -> [Int]
addCsum column = column ++ [sum column]
addRSum :: [[Int]] -> [[Int]]
addRSum rows = rows ++ [map sum (transpose rows)]

addSum :: [[Int]] -> [[Int]]
addSum table = addRSum (map addCsum table)

main = do
  [r, c] <- fmap (map read . words) getLine
  tbl <- replicateM r $ fmap (map read . words) getLine
  mapM_ (putStrLn . unwords . map show) $ addSum tbl

Measured memory_bytes: 6344
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=998244353;

int main(void){
    int n;
    cin>>n;
    map<int,int> A;
    long long sum=0;
    rep(i,n){
        int a;
        cin>>a;
        A[a]++;
        sum+=a;
    }
    int q;
    cin>>q;
    rep(i,q){
        int b,c;
        cin>>b>>c;
        int B=A[b];
        //cout<<A[b]<<A[c]<<endl;
        sum+=(long long)(c-b)*B;
        A[b]=0;
        A[c]+=B;
        cout<<sum<<endl;
    }
    return 0;
}

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

int main(){
  int N; cin>>N;
  vector<int> A(N+1);
  for(int i=1;i<=N;i++) cin>>A[i];
  A.push_back(0);
  int sum = 0;
  for(int i=1;i<A.size();i++)
    sum += abs(A[i] - A[i-1]);
  for(int i=1;i<=N;i++){
    int rm = abs(A[i] - A[i-1]) + abs(A[i] - A[i+1]);
    int add = abs(A[i+1] - A[i-1]);
    cout<<sum - rm + add<<endl;
  }
  return 0;
}


Measured memory_bytes: 1656
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MAX_INF 0x7f
#define MAX_INF_VAL 0x7f7f7f7f
#define pi 3.141592653589
#define eps 1e-6
//#define p 2173412051LL
#define sz 2

using namespace std;

char s[ 1000010 ];

int main() {
	int n, x, t;
	int ans = 0;
	scanf( "%s", s + 1 );
	n = strlen( s + 1 );
	s[ 0 ] = '0';
	for( int i = n; i >= 0; --i ) {
		x = s[ i ] - '0';
		if( x > 5 ) {
			t = i;
			while( t && s[ t - 1 ] == '9' ) {
				s[ t - 1 ] = '0';
				--t;
			}
			++s[ t - 1 ];
			ans += 10 - x;
		} else if( x < 5 ) {
			ans += x;
		} else {
			if( s[ i - 1 ] < '5' )
				ans += 5;
			else {
				t = i;
				while( t && s[ t - 1 ] == '9' ) {
					s[ t - 1 ] = '0';
					--t;
				}
				++s[ t - 1 ];
				ans += 5;
			}
		}
	}
	printf( "%d", ans );
	return 0;
}

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


int main()
{
	int n, x;
	while (cin >> n >> x, n || x){
		int count = 0;
		for (int i = 1; i <= n; i++){
			for (int j = i + 1; j <= n; j++){
				for (int k = j + 1; k <= n; k++){
					if (i + k + j == x){
						count++;
					}
				}
			}
		}
		cout << count << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
  string w;
  cin >>w;
  int x=w.size();
  vector<int> vec(26);
  int a=0;
  for(char p='a';p<='z';p++) {
    int count=0;
    rep(i,x) {
if(w.at(i)==p) {
  count++;
}
    }
    if (count%2==0) {
      vec.at(a)=1;
    }
    a++;
    
  }
  int counting=0;
  rep(i,26) {
    if(vec.at(i)==1) {
counting++;
    }
  }
if(counting==26) {
cout<<"Yes"<<endl;
}
else {
cout<<"No"<<endl;
}
  
  
  
}
    
  
  
      
    

Measured memory_bytes: 256
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
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>
using pq=priority_queue<T,vector<T>,greater<T>>;
const string YES = "Yes";
const string NO = "No";

ll N;
vl A;
vl B;
ll K;
vl V;
vl P;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> N;
    A = vl(N-1);
    B = vl(N-1);
    for(int i = 0; i < N-1; ++i){
        cin >> A[i];
        cin >> B[i];
    }
    cin >> K;
    V = vl(K);
    P = vl(K);
    for(int i = 0; i < K; ++i){
        cin >> V[i];
        cin >> P[i];
    }
    solve();
}

// 1 ≦ N ≦ 10^5
// 1 ≦ K ≦ N
// 1 ≦ A_i, B_i ≦ N (1 ≦ i ≦ N - 1)
// 1 ≦ V_j ≦ N (1 ≦ j ≦ K) (21:18, 制約の誤記を修正)
// 0 ≦ P_j ≦ 10^6 (1 ≦ j ≦ K)
// 与えられるグラフは木になることが保証される
// V_j はすべて相異なる

vvl g;
vl a,mx,mi,ans;

void no(){cout<<NO<<endl;exit(0);}

void dfs2(ll x,ll p){
    for(ll to:g[x]){
        if(to==p)continue;
        if(ans[to]!=-1){
            if(abs(ans[x]-ans[to])!=1)no();
            continue;
        }
        if(mi[to]<=ans[x]+1&&ans[x]+1<=mx[to])ans[to]=ans[x]+1;
        else if(mi[to]<=ans[x]-1&&ans[x]-1<=mx[to])ans[to]=ans[x]-1;
        else no();
        dfs2(to,x);
    }
}

void dfs(ll x,ll p=-1){
    for(ll to:g[x]){
        if(to==p)continue;
        dfs(to,x);
        chmin(mx[x],mx[to]+1);
        chmax(mi[x],mi[to]-1);
    }
    if(a[x]==-1)return;
    ans[x]=a[x];
    mx[x]=mi[x]=a[x];
    dfs2(x,p);
}

// ll N, vl A, vl B, ll K, vl V, vl P
// 残りのすべての頂点に書き込む整数を工夫することで木が条件を満たすようにできるならば Yes を、できないならば No を出力せよ。
// 条件を満たせる場合、追加で N 行出力せよ。このうちの v (1 ≦ v ≦ N) 行目には、頂点 v に書かれる整数を出力せよ。条件を満たすような整数の書き込み方が複数ある場合、そのうちいずれかひとつを出力すればよい。
void solve(){
    g.resize(N);
    rep(i,N-1){
        g[A[i]-1].push_back(B[i]-1);
        g[B[i]-1].push_back(A[i]-1);
    }

    mx.resize(N,INF);
    mi.resize(N,0);
    a.resize(N,-1);
    ans.resize(N,-1);
    rep(i,K)a[V[i]-1]=P[i];
    dfs(V[0]-1);

    cout<<YES<<endl;
    rep(i,N)cout<<ans[i]<<endl;
}


Measured memory_bytes: 17664
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
ll inf = 1LL << 60;
ll dp[3005][3005];
int main() {
	string s;
	cin >> s;
	string t;
	cin >> t;
	for (int i = 0; i <= s.size(); i++) {
		dp[0][i] = 0;
	}
	for (int i = 0; i <= t.size(); i++) {
		dp[i][0] = 0;
	}

	for (int i = 1; i <= t.size(); i++) {
		for (int j = 1; j <= s.size(); j++) {
			if (s[j-1] == t[i-1]) {
				dp[i][j] = dp[i-1][j-1] + 1;
			}
			else {
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	}
	
	string ans = "";
	int y = s.size();
	int x = t.size();
	while (x > 0 && y > 0) {
		if (dp[x][y] == dp[x - 1][y]) {
			x--;
		}
		else if(dp[x][y]==dp[x][y-1]){
			y--;
		}
		else {
			x--;
			y--;
			ans.push_back(t[x]);
		}
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 70784
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class BUnevenNumbers {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int N;
	    in >> N;
	    int answer = 0;
	    REP(i,1,N+1) {
	        if (toString(i).size() % 2 == 1) answer++;
	    }
	    out << answer << "\n";
	}
};


signed main() {
	BUnevenNumbers solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
signed main()
{
    ios_base::sync_with_stdio(0);
    int TESTS=1;
    // cin>>TESTS;
    while(TESTS--)
    {   
        int h,w;
        cin>>h>>w;
        string s[h];
        rep(i,0,h) cin>>s[i];
        int dp[h+1][w+1];
        rep(i,0,h+1)
        rep(j,0,w+1) dp[i][j] = 0;
        dp[1][1] = 1;
        rep(i,1,h+1){
            rep(j,1,w+1){
                if(i==1&&j==1) continue;
                if(s[i-1][j-1]=='#'){
                    dp[i][j] = 0;
                    continue;
                }
                dp[i][j] = (dp[i-1][j]+dp[i][j-1])%M;
            }
        }
        cout<<dp[h][w];
    }   
}     

Measured memory_bytes: 9088
n, m = map(int, input().split())
a = list(map(int, input().split()))
ans = [True] * n
for _ in range(m):
    aj, bj = map(int, input().split())
    aj -= 1
    bj -= 1
    if a[aj] <= a[bj]:
        ans[aj] = False
    if a[bj] <= a[aj]:
        ans[bj] = False

print(ans.count(True))

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

#define FOR(i,a,b) for(int i = (a);i < (int) (b);i++)
#define PB push_back
#define MP make_pair
#define ALL(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;

ll N,X;

long long gcd(long long x,long long y)
{
	while(y){
		x %= y;
		swap(x,y);
	}

	return x;
}

int main()
{
	cin >> N >> X;

	cout << 3 * (N - gcd(N,X)) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl
const int N = 1e5;  // limit for array size
ll n;  // array size

/*template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r){
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
*/
int main(){
    int n;cin>>n;
    long double a[n];
    for(int i=0;i<n;i++){
    	cin>>a[i];
	}
	
	sort(a,a+n);
	long double ans=a[0];
	for(int i=1;i<n;i++){
		ans=(ans+a[i])/2;
	}
	
	cout<<setprecision(15);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i <= n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n; cin >> n;
    VI dp(n+1,n);
    dp[0] = 0;
    VI num(1,1);
    int a = 1,b = 1;
    while(a <= n){
        if(b <= n) num.push_back(b*=9);
        num.push_back(a*=6);
    }
    FOR(i,1,n) rep(j,num.size()) if(i-num[j] >= 0) dp[i] = min(dp[i],dp[i-num[j]] + 1);
    OUT(dp[n]);

    return 0;
}

Measured memory_bytes: 1024
n = int(input())
h = list(map(int, input().split()))
move = []
hi = h[0]
c = 0

for i in range(1, n):
    if h[i] <= hi:
        c += 1
    elif c > 0:
        move.append(c)
        c = 0
    hi = h[i]
else:
        move.append(c)
print(max(move))

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

int main() {
	int w, h, n;
	cin >> w >> h >> n;
	vector<int> x(n), y(n), a(n);
	vector<int> p1, p2, p3, p4;
	int left, right, up, down;
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> a[i];
		if (a[i] == 1)
			p1.push_back(x[i]);
		if (a[i] == 2)
			p2.push_back(x[i]);
		if (a[i] == 3)
			p3.push_back(y[i]);
		if (a[i] == 4)
			p4.push_back(y[i]);
	}
	if (!p1.empty()) {
		sort(p1.rbegin(), p1.rend());
		left = p1[0];
	}
	else
		left = 0;
	if (!p2.empty()) {
		sort(p2.begin(), p2.end());
		right = p2[0];
	}
	else
		right = w;
	if (!p3.empty()) {
		sort(p3.rbegin(), p3.rend());
		down = p3[0];
	}
	else
		down = 0;
	if (!p4.empty()) {
		sort(p4.begin(), p4.end());
		up = p4[0];
	}
	else
		up = h;
	if (right - left < 0 && up - down < 0)
		cout << 0 << endl;
	else
		cout << max(0, (right - left) * (up - down)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = INT_MAX;
const int MOD = 1000000007;
const long long INF = LLONG_MAX;

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

int N, M;
int a[100], b[100], c[100], d[100];

int main() {
  cin >> N >> M;
  rep(i, 0, N) { cin >> a[i] >> b[i]; }
  rep(i, 0, M) { cin >> c[i] >> d[i]; }
  rep(i, 0, N) {
    int dist = inf;
    int ans = 0;
    rep(j, 0, M) {
      if (chmin(dist, abs(c[j] - a[i]) + abs(d[j] - b[i]))) {
        ans = j + 1;
      }
    }
    cout << ans << "\n";
  }
}


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

using ll = long long;
int main () {
  while(true) {
    int n, m;
    cin >> n >> m;
    if (n == 0) break;
    vector<int> v(n), w(m);
    for (int i = 0; i < n; i++) cin >> v[i];
    for (int i = 0; i < m; i++) cin >> w[i];
    ll sv = 0;
    ll sw = 0;
    for (int i = 0; i < n; i++) sv += v[i];
    for (int i = 0; i < m; i++) sw += w[i];
    pair<int, int> ans;
    int score = 1000000;
    for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) {
        ll diff = sv - sw;
        diff -= 2 * v[i];
        diff += 2 * w[j];
        if (diff != 0) continue;
        if (v[i] + w[j] < score) {
          score = v[i] + w[j];
          ans.first = v[i];
          ans.second = w[j];
        }
      }
    if (score == 1000000) cout << -1 << endl;
    else cout << ans.first << " " << ans.second << endl;
  }

  return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <cstring>

int main(int argc, char *argv[]) {  
	int n;
	std::cin >> n;
	int a = n/1000, b = (n%1000)/100, c = (n%100)/10, d = n%10;
	for(int i = -1; i <= 1; i+=2) {
		for(int j = -1; j <= 1; j+=2) {
			for(int k = -1; k <= 1; k+=2) {
				if(a+i*b+j*c+k*d == 7) {
					std::cout << a << (i==1?"+":"-") << b<< (j==1?"+":"-") << c << (k==1?"+":"-") << d << "=7\n";
					return 0;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef set<int> si;
typedef map<int,int> mii;

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
#define FORd(i,a,b) for (int i = b-1; i >= a; i--)
#define F0Rd(i,a) for (int i = a-1; i >= 0; i--)
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
 
const int MOD = 1000000007;
double PI = 4*atan(1);

ll pow3[64];

map<ll,ll> record;

int firstbit(ll N) {
	ll po = 63-__builtin_clzll(N); 
	for (int i = po-1; i >= 0; --i) if (N & ((ll)1<<i)) return po+1-i;
	return 999;
}

ll take(ll N) {
	if (N == 0) return 0;
	ll po = 63-__builtin_clzll(N);
	return N-((ll)1<<po);
}

ll solve(ll N) {
	if (N == 0) return 1;
	if (record.find(N) != record.end()) return record[N];

	ll newN = take(N);
	ll ans = solve(newN); // yes
	ll po = 63-__builtin_clzll(N);
	ll x = firstbit(N);
	
	for (int len = 2; len <= po+1; len++) {
		ans = (ans+pow3[po+1-len]) % MOD;
		if (len<x) ans = (ans+solve(newN)) % MOD;
		else if (len == x) {
			ans = (ans+solve(newN)-solve(take(newN))) % MOD;
			while (ans<0) ans += MOD;
		} else {
			ans = (ans+pow3[po+1-len]) % MOD;
		}
		// 49 to 55 need fixing
	}
	ans++;
	return record[N] = ans;
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	ll N; cin >> N;
	pow3[0] = 1;
	F0R(i,63) pow3[i+1] = (3*pow3[i]) % MOD;
	cout << solve(N);
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
using ll = long long;

struct io {
    io(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    }
    template<class T>
    io operator>>(T &v) {
        cin >> v;
        return *this;
    }

    template<class T>
    io operator<<(const T v) const {
        cout << v;
        return *this;
    }
}in;

int main() {
    int n, m;
    in >> n >> m;
    in << ((n * 100 + m * 1800) << m) << "\n";
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e18;

int main()
{
    ll n,k;
    cin >> n >> k;
    vector<ll> t(n),p;
    vector<pll> d(n);
    map<ll,ll> m;
    rep(i,n){
        cin >> t[i];
        cin >> d[i].fi;
        m[t[i]]=max(m[t[i]],d[i].fi);
    }
    rep(i,n){
        if(m[t[i]]==d[i].fi){
            d[i].se=1;
            p.push_back(d[i].fi);
            m[t[i]]=INF;
        }
    }
    sort(p.rbegin(),p.rend());
    sort(d.rbegin(),d.rend());
    ll sum=0;
    ll s=0;
    multiset<ll> mu;
    rep(i,k){
        sum+=d[i].fi;
        s+=d[i].se;
        if(d[i].se==0){
            mu.insert(d[i].fi);
        }
    }
    sum+=s*s;
    
    ll ans=sum;
    ll sz=p.size();
    for(ll i=s;i<sz;i++){
        if(mu.size()==0) break;
        sum+=p[i];
        ll v=*mu.begin();
        mu.erase(mu.find(v));
        sum-=v;
        sum+=2*i+1;
        ans=max(ans,sum);
    }
    cout << ans << endl;
    return 0;
} 

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

int main(){
  double n,t,a;
  cin >> n >> t >> a;
  int ans1;
  double ans;
  vector<double> h(n);
  for(int i = 0; i < n; i++){
    cin >> h[i];
    h[i] = t - h[i] * 0.006;
  }
  ans = abs(h[0] - a);
  ans1 = 1;
  for(int i = 1; i < n; i++){
    ans = min(ans, abs(h[i] - a));
    if(ans == abs(h[i] - a)) ans1 = i + 1;
  }
  cout << ans1 << endl;
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <utility>
#include <functional>
#include <queue>
#include <cmath>
#include <numeric>
#include <map>
#define REP(i, N) for(int i=0; i<N; i++)
using namespace std;

int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}

int main() {
	long long A, B;

	cin >> A >> B;

  auto mA = A % 2019LL;
  auto mB = B % 2019LL;
 // if (mA > mB) swap(mA, mB);
 // if (A > B) swap(A, B);
  
  long long r = 99999999999999;
  int lim = 2019;
  for (long long i = A; i < B; i++) {
  int limx = 2019;
  for (long long j = i+1; j <= B; j++){
    r = min(r, (i * j) % 2019LL);
     if (limx-- == 0) break;
  }
/*  for (long long i = A; i * i <= B; i++) {
    auto tmp = i * (B / i) % 2019LL;
    r = min(r, tmp);
   
  }
*/ if (lim-- == 0) break;
  }
  cout << r << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <set>
#include <vector>
#include <iomanip>
#define pb push_back
#define mp make_pair
using namespace std;
const int N = 5e6;
const int INF = 1e9;

int main() {
int n;
int ans = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
  	int l, r;
  	cin >> l >> r;
  	ans += r - l + 1;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int N;
  int ans = 0;
  long long a;
  scanf("%d",&N);

  for(int i = 0;i < N;i++){
    scanf("%lld",&a);
    while(a%2 == 0){
      a /= 2;
      ans++;
    }
  }

  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

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

    int n;
    cin >> n;

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

    int m;
    cin >> m;

    vector<int> t(m);
    for (int i = 0; i < n; i++) {
        cin >> t[i];
    }
    sort(t.begin(), t.end());

    int j = 0;
    for (int i = 0; i < m; i++) {
        for (;; j++) {
            if (j >= n || t[i] < d[j]) {
                cout << "NO" << endl;
                return 0;
            } else if (t[i] == d[j]) {
                j++;
                break;
            }
        }
    }

    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 1792
N, M = map(int, input().split())

ac_set = set()
wa_lst = [0] * (N + 1)  # 1~Nを使う
wa_sum = 0
for _ in range(M):
    p, s = input().split()
    p = int(p)
    if s == 'AC':
        if p not in ac_set:
            ac_set.add(p)
            wa_sum += wa_lst[p]
    else:
        wa_lst[p] += 1

print(len(ac_set), wa_sum)


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

using namespace std;

typedef long long int ll;
#define pb push_back
#define ALL(a) (a).begin() , a.end()

int mod = 1e9 + 7;
int add(int a, int b){
	if(a + b >= mod)return a+ b - mod;
	return a + b;
}
int mul(int a, int b){
	return 1LL * a * b  % mod;
}
int sub(int a, int b){
  if(a >= b)return a-b;
  return a - b + mod;
}
int power(int a, int b){
	int re = 1;
	while(b){
		if(b&1)re= mul(re, a);
		a = mul(a, a);
		b>>=1;
	}
	return re;
}
int const N = 100 *1001;

/********************i**********************************/
vector<int> vec[10];
void dfs(int a, int p){
  cout << a << " ";
  for(int b : vec[a]){
    if(b == p)continue;
    dfs(b, a);
  }
  cout << a << " ";
}
void solve(){
  ll n, a, d;
  cin >> n >> d >> a;
  vector<pair<int, int>> vec(n);
  for(auto &g : vec)cin >> g.first >> g.second;
  sort(ALL(vec));
  vector<ll> L(n+2, 0), R(n+2, 0);
  ll ans = 0, r = 0, sum = 0, window = d + d;
  for(int x = 0; x<n; x++){
    ll axis = vec[x].first, till = axis + window;
    int h = vec[x].second;
    while(r < n && vec[r].first <= till)r++;
    ll left = h - sum * a;
    if(left > 0){
      ll o = left/ a + (left % a != 0);
      R[r-1] += o;
      sum += o;
      ans += o;
    }
    // cout << axis << " " << h << endl;
    // cout << x << " x " << ans << " " << sum << " " << left <<  " r[x] " << R[x]  << endl;
    sum -= R[x];

  }
  cout << ans;
}
/******************************************************/
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	int t;
	t = 1;
	// cin >> t;
	while(t--){
		solve();
	}
}

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

int main(){
    ll n;
    cin >> n;
    vector<ll> v(n);
    rep(i,n) cin >> v[i];
    
    ll sa = 0,ans=0;
    for(int i=1;i<n;i++){
        if(v[i-1]<=v[i]) continue;
        sa = v[i-1] - v[i];
        ans += sa;
        v[i] = v[i-1];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4836
#pragma region

#include "bits/stdc++.h"
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;

using namespace std;
using ll = long long;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "vec[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

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

template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int main() {
  init();

  ll H, N;
  cin >> H >> N;
  vector<int> A(N), B(N);
  rep(i, N) cin >> A[i] >> B[i];

  vector<ll> dp(H + 1, INF);
  dp[0] = 0;
  rep(i, N) {
    rep(j, H) {
      chmin(dp[(j + A[i] > H) ? H : (j + A[i])], dp[j] + B[i]);
    }
  }

  out(dp[H]);
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <algorithm>
#define _USE_MATH_DEFINES
#include<math.h>
using namespace std;

int main() {
	int N, M;
	int A[10000];
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> A[i];
	}

	
	int sum = 0;
	for (int i = 0; i < M; i++) {
		sum += A[i];
	}
	if (N - sum >= 0) cout << N - sum << endl;
	else cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

int score[]={0,0,60,70,80};
int tb[5][5], dp[4][1<<2*4];

int main()
{
	int n; scanf("%d",&n);
	rep(i,n)
	{
		rep(i,5)rep(j,5)scanf("%d",tb[i]+j);
		rep(i,4)rep(j,1<<2*4)dp[i][j]=0;
		
		rep(i,1<<2*4){
			dp[0][i]=0;
			rep(j,5)if(tb[0][j]){
				int sc=tb[0][j];
				if(j>0)sc+=i>>2*j-2&3;
				if(j<4)sc+=i>>2*j&3;
				while(sc>4)sc-=4;
				
				dp[0][i]+=score[sc];
			}
		}
		
		for(int i=1;i<4;i++)rep(j,1<<2*4)rep(jj,1<<2*4){
			int sum=dp[i-1][j];
			rep(k,5)if(tb[i][k]){
				int sc=tb[i][k];
				if(k>0)sc+=(j>>2*k-2&3) + (jj>>2*k-2&3);
				if(k<4)sc+=(j>>2*k&3) + (jj>>2*k&3);
				while(sc>4)sc-=4;
				
				sum+=score[sc];
			}
			dp[i][jj]=max(dp[i][jj],sum);
		}
		
		int ans=0;
		rep(i,1<<2*4){
			int sum=dp[3][i];
			rep(j,5)if(tb[4][j]){
				int sc=tb[4][j];
				if(j>0)sc+=i>>2*j-2&3;
				if(j<4)sc+=i>>2*j&3;
				while(sc>4)sc-=4;
				
				sum+=score[sc];
			}
			ans=max(ans,sum);
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 892
S = input()
T = input()
ans = len(T)
for start in range(len(S) - len(T) + 1):
  dif = 0
  for i in range(len(T)):
    if T[i] != S[start + i]:
      dif += 1
  ans = min(ans, dif) 
print(ans)


Measured memory_bytes: 9044
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <limits.h>
#include <assert.h>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <math.h>
#include <stack>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long int
#define db double
#define ldb long double
#define MOD 1000000007
#define Fi first
#define Se second
#define INF INT_MAX
#define NINF INT_MIN
#define L_INF LLONG_MAX
#define L_NINF LLONG_MIN
#define gc getchar
#define sz(x) (int)(x).size()
#define pii pair<int,int>
#define pll pair<ll,ll>

void fsscan(){ios_base::sync_with_stdio(false);cin.tie(NULL);}

void scani(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;
}

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

vector<int> decToBinary(int n,int l) 
{ 
    vector<int> v(l,0);
    int i = 0; 
    while (n > 0) { 
  
        v[i]=(n % 2); 
        n = n / 2; 
        i++; 
    } 
    
    reverse(v.begin(),v.end());
    
    return v;
} 

int main()
{
    fsscan();
    int n,m;
    cin>>n>>m;
    vector<int> bulbs[m];
    
    for(int i=0;i<m;i++)
    {
        int s;
        cin>>s;
        while(s--)
        {
            int x;
            cin>>x;
            bulbs[i].pb(x);
        }
    }
    
    int p[m];
    for(int i=0;i<m;i++)
    {
        cin>>p[i];
    }
    
    int s=0;
    for(int i=0;i<pow(2,n);i++)
    {
        vector<int> v=decToBinary(i,n);
        int c=0;
        for(int j=0;j<m;j++)
        {
            int count=0;
            for(int k=0;k<bulbs[j].size();k++)
            {
                int index_val=bulbs[j][k];
                count+=v[index_val-1];
            }
            if(count%2==p[j])
            c++;
        }
        //cout<<i<<" "<<c<<endl;
        if(c==m)
        s++;
    }
    
    cout<<s;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string[] a = Console.ReadLine().Split(' ');
            int n = int.Parse(s);
            int i = 0;

            for (i = n-1; i > 0; i--)
            {
                Console.Write(a[i]+" ");
            }

            Console.Write(a[0]+"\n");

        }
    }
}

Measured memory_bytes: 5288
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
//long long int countt[200003];
#include<ext/pb_ds/assoc_container.hpp> // include the associative containers or group of templates such as set, multimap, map etc.
#include<ext/pb_ds/tree_policy.hpp> // include the tree_order_statistics_node update
using namespace __gnu_pbds; //necessary for the GNU based Policy based data structures.
typedef tree<pair<int,int> ,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define int long long
#define endl "\n"
const int mod=1e9+7;
signed main()
{
    FAST;
    
    int i=0,j=0,k=0,n=0,m=0,count=0,temp=0;
    int temp1=0,temp2=0,temp3=0,x=0,l=0,y=0,sum=0;
    int left=0,up=0,anss=0,start=0,end=0,r=0,qq=0,total=0;
    int maxx=0,minn=0,curr=0,ans=0,places=0,zeroes=0,low=0,high=0;
    int prev=0,mid=0,z=0,d=0,val=0,pos=0,shift=0,h=0,right=0,var=0;
    int reqd=0;
    
    cin>>n>>k;
    
    for(i=k;i<=n+1;i++)
    {
        minn = (i*(i-1))/2;
        maxx = i*(2*n + 1 - i);
        maxx=maxx/2;
        
        ans+=(maxx-minn+1);
        ans=ans%mod;
        
        //cout<<ans<<" "<<minn<<" "<<maxx<<endl;
    }
    cout<<ans<<endl;
    
    
    
    
}

Measured memory_bytes: 3660
#include <stdio.h>

struct DICE {
	int num[7];
};

void throwdice(char ch, struct DICE *dice)
{
	int temp;
	switch (ch) {
	case 'N':
		temp = dice->num[6] ;
		dice->num[6] = dice->num[5] ;
		dice->num[5] = dice->num[1] ;
		dice->num[1] = dice->num[2] ;
		dice->num[2] = temp;
		break;
	case 'S':
		temp = dice->num[6] ;
		dice->num[6] = dice->num[2] ;
		dice->num[2] = dice->num[1] ;
		dice->num[1] = dice->num[5] ;
		dice->num[5] = temp;
		break;
	case 'E':
		temp = dice->num[6] ;
		dice->num[6] = dice->num[3] ;
		dice->num[3] = dice->num[1] ;
		dice->num[1] = dice->num[4] ;
		dice->num[4] = temp;
		break;
	case 'W':
		temp = dice->num[6] ;
		dice->num[6] = dice->num[4] ;
		dice->num[4] = dice->num[1] ;
		dice->num[1] = dice->num[3] ;
		dice->num[3] = temp;
		break;
	}
}

int main(void)
{
	struct DICE dice;
	int i;
	char ch;
	
	for(i=1; i<=6; i++) {
		scanf("%d",&dice.num[i]);
	}
	scanf("%c",&ch);
	while(1) {
		scanf("%c",&ch);
		if(ch == '\n') break;
		throwdice(ch, &dice);
	}
	printf("%d\n", dice.num[1]);
	return 0;
}

Measured memory_bytes: 596
h, w = map(int,input().split())
g = [input() for i in range(h)]
 
d = [[200] * w for i in range(h)]

d[0][0] = ( g[0][0] == "#")
for i in range(h):
    for j in range(w):
        if i + 1 < h:
            d[i+1][j] = min(d[i+1][j], d[i][j]+(g[i+1][j] == '#' and g[i][j] == '.'))
        if j + 1 < w:
            d[i][j+1] = min(d[i][j+1], d[i][j]+(g[i][j+1] == '#' and g[i][j] == '.'))

print(d[-1][-1])

Measured memory_bytes: 3064
#include <cmath>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <unordered_map>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>

using namespace std;

#define forsn(i,s,n) for (int i = (s);i < (int)(n);i++)
#define forn(i,n) forsn(i,0,n)
#define dforsn(i,s,n) for (int i = (n-1);i >= (int)(s);i--)
#define dforn(i,n) dforsn(i,0,n)
#define all(v) (v).begin(), (v).end()
#define F first
#define S second

typedef long long int tint;

int res[300000];

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

	int n, a, b; cin >> n >> a >> b;
	
	if (a > n) {cout << -1 << endl; return 0;}
	if (b > n) {cout << -1 << endl; return 0;}

	forn(i,b) res[i] = b - i;
	
	int li = 1;
	
	int cur = b;
	while (cur != n) {
		int toPut = min((n - cur) - ((a - li) - 1), min(b, n - cur));

		if (toPut <= 0) {
			cout << -1 << endl;
			return 0;
		}
		forn(i, toPut) res[cur + i] = cur + toPut - i;
		cur += toPut;
		li++;
	}

	if (li != a) {
		cout << -1 << endl;
		return 0;
	}
	
	forn(i, n) cout << res[i] << " \n"[i == n - 1];
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define itn int

int main(void){
    long long x;
    cin >> x;
    
    int ans = 0,ans2 = 0;
    for(int i = -120;i <= 120;i++){
        for(int j = -120;j <= 120;j++){
            if(pow(i,5)-pow(j,5) == x){
                ans = i;
                ans2 = j;
            }
        }
    }
    cout << ans << " " << ans2 << endl;
}

Measured memory_bytes: 4080
import heapq
import math

N, M =  map(int, input().split())
A = list(map(lambda x: -x, map(int, input().split())))
heapq.heapify(A)

for i in range(M):
    item = heapq.heappop(A)
    heapq.heappush(A, math.ceil(item / 2))

print(-1 * sum(A))

Measured memory_bytes: 14532
S = str(input())
T = str(input())

def f(s,t):
    count = 0
    for i,j in zip(s,t):
        if i == j:
            count += 1
    return count

def F(S,T):
    len_s = len(S)
    len_t = len(T)
    max = 0
    for i in range(len_t,len_s+1):
        x = f(S[i-len_t:i],T)
        if x > max:
            max = x
    return len_t - max
print(F(S,T))

Measured memory_bytes: 9136
import java.util.*;
public class Main{   
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[][] a = new int[n][2];
      for(int i=0;i<n;i++){
        int x=sc.nextInt();
        int l=sc.nextInt();
        a[i][0]=x-l;
        a[i][1]=x+l;
      }
      Arrays.sort(a,(u,v) -> Integer.compare(u[1],v[1]));
      int cnt = 0;
      int t = -100000000;
      for(int i=0;i<n;i++){
        if(t<=a[i][0]){
          cnt++;
          t=a[i][1];
        }
      }
      System.out.println(cnt);
    }
    public static int lcm(int x, int y){
      return x*y/gcd(x,y);
    }
    public static int gcd(int x, int y){
      if(x < y)return gcd(y,x);
      if(y==0)return x;
      return gcd(y,x%y);
    }
}
class Pair{
    int a,b;

    Pair(int a, int b){
      this.a = a;
      this.b = b;
    }
}

Measured memory_bytes: 96372
#include <bits/stdc++.h>
#define int long long

using namespace std;
vector <vector<int>> a;
int f[3002][3002][4];
int r,c,k;

int calc(int i, int j, int cur)
{
    if (cur==3)
    {
        if (i+1<r)
            return calc(i+1,j-1,0);
        else return 0;
    }
    if (i==r-1 && j==c-1)
        return a[i][j];

    int &res=f[i][j][cur];
    if (res!=-1) return res;
     res=0;

    if (i+1<r)
        res=max(res,calc(i+1,j,0)+a[i][j]);
    if (j+1<c)
    {
        res=max(res,calc(i,j+1,cur));
        res=max(res,calc(i,j+1,cur+1)+a[i][j]);
    }
    return res;
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> r >> c >> k;
    a.resize(r+1,vector<int>(c+1,0));
    memset(f,-1,sizeof(f));
    while (k--)
    {
        int i,j;
        cin >> i >> j;
        --i;
        --j;
        cin >> a[i][j];
    }
    cout << calc(0,0,0);
    return 0;
}


Measured memory_bytes: 355616
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli uf[100001], size[100001];
lli n, m;
using P = pair<lli, lli>;
P e[100001];

lli root(lli i) { return i == uf[i] ? i : uf[i] = root(uf[i]); }
void unite(lli i, lli j) {
  lli ri = root(i), rj = root(j);
  uf[rj] = ri;
  size[ri] += size[rj];
  size[rj] = 0;
}
bool same(lli i, lli j) { return root(i) == root(j); }

int main() {
  cin >> n >> m;
  for (lli i=0; i<m; ++i) {
    cin >> e[i].first >> e[i].second;
  }

  for (lli i=1; i<=n; ++i) {
    uf[i] = i;
    size[i] = 1;
  }

  lli scr = n*(n-1)/2;
  vector<lli> res;
  res.push_back(scr);
  for (lli i=m-1; i>0; --i) {
    lli u = e[i].first, v = e[i].second;
    
    if (!same(u, v)) {
      lli su = size[root(u)], sv = size[root(v)];
      scr -= su * sv;

      unite(u, v);
    }

    res.push_back(scr);
  }

  while (!res.empty()) {
    cout << res.back() << '\n';
    res.pop_back();
  }
  return 0;
}


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

int main(void){
   char a;
   cin>>a;
   if('A'<=a&&a<='Z'){
      cout<<"A"<<endl;
   }else if('a'<=a&&a<='z'){
      cout<<"a"<<endl;
   }
   return 0;
}


Measured memory_bytes: 3580
#include<iostream>
#include<algorithm>
#include<vector>
#include<complex>
using namespace std;
#define chmax(a,b) a=max(a,b);
typedef long long ll;
typedef pair<ll,ll> P;
#define N 100010
vector<ll> v;
ll n,s[N];
int main(){
  cin>>n; char op='+';
  ll befpo=-1;
  for(int i=0;i<n;i++){
    if(i)cin>>op; ll a;cin>>a;
    if(op=='+'){
      if(~befpo)befpo+=a;
      else befpo=a;
    }
    else{
      if(~befpo)v.push_back(befpo); befpo=-1;
      v.push_back(-a);
    }
  }if(~befpo)v.push_back(befpo);
  n=v.size(); s[n]=0;
  for(int i=n-1;i>=0;i--){
    s[i]=s[i+1]+abs(v[i]);
  }
  //for(int i=0;i<n;i++)cout<<v[i]<<" ";cout<<endl;
  ll ans=-1e17,sum=0;
  for(int i=0;i<n-1;i++){
    sum+=v[i];
    if(v[i]>0)continue;
    chmax(ans,sum+-v[i+1]+s[i+2]);
  }
  sum+=v[n-1]; chmax(ans,sum);
  cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 1908
#include<bits/stdc++.h>
#define int long long int
using namespace std;
int n,m;
bool check(int x, int y){
    if(x >=0 and y >=0 and x < n and y < m) return true;
    return false;
}
signed main(){
    ios_base::sync_with_stdio(false);
   // freopen("input.txt", "r", stdin);
    int n, k; cin>>n>>k;
    int a[n+1];
    for(int i=1; i<=n; i++) cin>>a[i];
        //for(int i=0; i<n; i++) cout<<a[i]<<" "; cout<<endl;
    vector<int> dp(n+1, 0);
    int i=1, c=0; 
    for(; c <k; c++){
        if(dp[i]==0){
            dp[i]=1;
            i=a[i];
            //cout<<i<<" d"<<endl;
        }
        else break;
    }
       
    if(c==k) cout<<i<<endl;
    else{
        vector<int> d(n+1,0);
        int j=i, count=0;
        //d[j]=1;
        for(int z=0; z < n; z++){
            if(d[j]==0){
                d[j]=1;
                count++;
                j=a[j];
            }            
        }
        k -=(c-count);
        //int mod=c-j;
        k = (k%count);
        int e=0; 
        while(e<k){
            e++;
            i=a[i];
        }
        cout<<i<<endl;

    }
    
}

Measured memory_bytes: 8020