akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f3f3f3f3f
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<ll, int>P;

vector<P>E[100000];
ll d[100000];
struct st {
	int a, b, d;
}v[200000];
int main() {
	ll n, m, c; scanf("%lld%lld%lld", &n, &m, &c);
	ll sum = 0;
	rep(i, m) {
		int a, b, d; scanf("%d%d%d", &a, &b, &d); a--; b--;
		E[a].push_back(P(d, b)); E[b].push_back(P(d, a));
		v[i] = { a,b,d }; sum += d;
	}
	priority_queue<P, vector<P>, greater<P>>que;
	memset(d, 0x3f, sizeof(d));
	que.push(P(0, 0)); d[0] = 0;
	while (!que.empty()) {
		P p = que.top(); que.pop();
		if (d[p.second] != p.first)continue;
		for (P u : E[p.second]) {
			if (d[u.second] > p.first + u.first) {
				d[u.second] = p.first + u.first;
				que.push(P(d[u.second], u.second));
			}
		}
	}
	sort(v, v + m, [&](st&a, st&b) {return max(d[a.a], d[a.b]) < max(d[b.a], d[b.b]); });
	ll Min = sum, Max = 0;
	rep(i, m) {
		Max = max(Max, (ll)max(d[v[i].a], d[v[i].b]));
		sum -= v[i].d;
		Min = min(Min, c*Max + sum);
	}
	printf("%lld\n", Min);
}

Measured memory_bytes: 19680
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
#define SortAsc(c) std::sort(c.begin(), c.end())
#define SortDesc(c) std::sort(c.rbegin(), c.rend())
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};

int main() {
  int n;
  ll k;
  cin >> n >> k;

  vector<int> t(n);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    a--;
    t.at(i) = a;
  }

  int current = 0;
  int loop = 0;
  int start = 0;
  vector<bool> visited(n, false);
  visited[0] = true;

  // find loop start
  for (int i = 0; i < n; i++) {
    loop++;
    current = t.at(current);
    if (visited[current]) {
      start = current;
      break;
    }
    visited[current] = true;
  }

  // cout << "start " << start << endl;

  // offset to loop start
  current = 0;
  int offset = 0;
  while (current != start) {
    offset++;
    current = t.at(current);
  }

  // loop count
  loop -= offset;

  //   cout << "offset " << offset << endl;
  //   cout << "loop " << loop << endl;

  k = min((k - offset) % loop + offset, k);
  current = 0;
  for (ll i = 0; i < k; i++) {
    current = t.at(current);
  }

  cout << current + 1 << endl;
}

Measured memory_bytes: 4000
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <tuple>
#include <math.h>
#include <deque>
#include <stack>

using namespace std;

typedef long long ll;

int main(void){
  string s,t;
  cin >> s >> t;
  ll cnt = 0;
  for(ll i = 0;i < 3;i++){
    cnt = s[i] == t[i] ? cnt + 1 : cnt;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 764
#include <stdio.h>
#include <algorithm>
 
using namespace std;
 
int main(){
    int n,max_num = -1000001,min_num = 1000001,tmp;
    long long int sum = 0;
    scanf("%d",&n);
    for(int i = 0; i < n; i++){
        scanf("%d",&tmp);
        sum += tmp;
        max_num = max(max_num,tmp);
        min_num = min(min_num,tmp);
    }
    printf("%d %d %lld\n",min_num,max_num,sum);
}



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

int main(){
  int N;
  cin >> N;
  vector<long long> A(N+1);
  for(int i=1;i<N+1;i++){
    long long B=i;
    while(B<N+1){
      A.at(B)++;
      B+=i;
    }
  }
  long long sum=0;
  for(int i=0;i<N;i++){
    sum+=(i+1)*A.at(i+1);
  }
  cout << sum << endl;
}

Measured memory_bytes: 81332
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
typedef long long ll;
struct edge { ll s, t, x; };
typedef pair<ll, ll> P;
typedef pair<double, P> event;
const ll MAX = 510000;
const ll MOD = 1000000007;
#define INF (ll)10000000000000000

int main() {
  ll N;
  cin>>N;
  vector<ll>A(N);
  ll money=1000ll;
  ll num=0ll;
  rep(i,N){
    cin>>A[i];
  }
  int memo[N];
  //-1は売り時(A)、1は買い時(V)
  if(A[0]>A[1]){memo[0]=1;}
  if(A[0]==A[1]){memo[0]=0;}
  if(A[0]<A[1]){memo[0]=-1;}
  for(int i=0;i<N-2;i++){
    if(A[i]>=A[i+1]&&A[i+1]<A[i+2]){memo[i+1]=-1;}
    else if(A[i]<=A[i+1]&&A[i+1]>A[i+2]){memo[i+1]=1;}
    else{memo[i+1]=0;}
  }
  memo[N-1]=1;
  rep(i,N){
    if(memo[i]==-1){
      ll p=money/A[i];
      money-=p*A[i];
      num+=p;
    }
    if(memo[i]==1){
      money+=num*A[i];
      num=0ll;
    }
  }
  cout<<money;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>



int main() {
    int n, l; std::cin >> n >> l;
    int s = 0, mi = 1e9;
    for (int i = 0; i < n; i++) {
        s += l + i;
        if (abs(l + i) < abs(mi)) {
            mi = l + i;
        }
    }
    std::cout << s - mi << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

/* 配列の要素を順番に出力 */
void trace(int A[], int N) {
  int i;
  for ( i = 0; i < N; i++ ) {
    if ( i > 0 ) printf(" "); /* 隣接する要素の間に1つの空白を出力 */
    printf("%d", A[i]);
  }
  printf("\n");
}

/* 挿入ソート (0オリジン配列) */
void insertionSort(int A[], int N) {
  int j, i, v;
  for ( i = 1; i < N; i++ ) {
    v = A[i];
    j = i - 1;
    while ( j >= 0 && A[j] > v ) {
      A[j + 1] = A[j];
      j--;
    }
    A[j + 1] = v;
    trace(A, N);
  }
}

int main() {
  int N, i, j;
  int A[100];

  scanf("%d", &N);
  for ( i = 0; i < N; i++ ) scanf("%d", &A[i]);

  trace(A, N);
  insertionSort(A, N);

  return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
const int p=31;
const int m=1e9+7;
typedef long long ll;
typedef int in;
#define ff first
#define ss second
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 int ll
in main (){
	int n;
	cin>>n;
	vector<int>a(n),b(n);
	unordered_map<int,pair<int,int>>ct;

	for(int i=0;i<n;++i){
		cin>>a[i];
		ct[a[i]].ff+=1;
	}

	for(int i=0;i<n;++i){
		cin>>b[i];
		ct[b[i]].ss+=1;
	}
	bool hai=true;
	for(int i=0;i<n;++i){
		if(ct[a[i]].ff+ct[a[i]].ss>n)
			{
				hai=false;
				break;
			}
	}

	if(!hai){
		cout<<"No";
		return 0;
	}
	cout<<"Yes\n";
	vector<int>r(n);
	r=b;
	reverse(r.begin(),r.end());
	int kha=-1,val=-1;
	for(int i=0;i<n;++i){
		if(r[i]==a[i]){
			kha=i;
			val=r[kha];
			break;
		}
	}	
	if(kha!=-1)
	for(int i=0;i<n && kha<n;++i){	
		if(a[i]!=val && r[i]!=val){
		swap(r[i],r[kha]);
		++kha;
	}
	   if(kha<n &&(r[kha]!=val ||a[kha]!=val ))break;
	}		

	for(int i=0;i<n;++i){
		cout<<r[i]<<' ';
	}

    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; //check time    
}
    
/*
12
1 1 2 3 3 4 4 5 6 7 8 9
1 3 3 3 3 3 5 6 6 6 6 6
*/

Measured memory_bytes: 13764
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]

ans = 0
for i in range(n-1, -1, -1):
  a = ab[i][0]
  b = ab[i][1]
  if (a+ans) % b != 0:
    ans += b-(a+ans)%b
print(ans)

Measured memory_bytes: 27236
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
int main()
{
    int N;
    cin >> N;
    vector<lint> A(N);
    REP(i, N) cin >> A[i];
    lint left = A[0];
    lint right = 0;
    REP(i, N-1) {
        right += A[i+1];
    }
    lint ans = 1e12;
    REP(i, N-1) {
        lint price = 0;
        lint minlen = max(i+1, N-1-i);
        lint left_tmp = left;
        lint right_tmp = right;
        if(left < minlen) {
            left_tmp += minlen - left;
            price += minlen - left;
        }
        if(right < minlen) {
            right_tmp += minlen - right;
            price += minlen - right;
        }

        price += abs(left_tmp - right_tmp);

        if(price < ans) ans = price;
        left += A[i+1];
        right -= A[i+1];
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N = I()
V = LI()
C = LI()

ans = 0
for i in range(N):
    v,c = V[i],C[i]
    if v-c > 0:
        ans += v-c

print(ans)

Measured memory_bytes: 61760
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const int N = 1000001;

int k, vis[N];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> k;
    int cur = 7 % k;
    int ans = 1;
    while(true){
        if(vis[cur]) break;
        vis[cur] = 1;
        if(cur == 0) finish(ans);
        cur = (10 * cur + 7) % k;
        ans++;
    }
    cout << -1 << endl;
}


Measured memory_bytes: 7512
h, w = map(int, input().split())
s = [list(input()) for j in range(h)]
ans = 'Yes'
for j in range(h):
  for i in range(w):
    ok = False
    if s[j][i] == '#':
      if j-1>=0:
        if s[j-1][i] == '#': ok = True
      if i-1>=0:
        if s[j][i-1] == '#': ok = True
      if j+1<h:
        if s[j+1][i] == '#': ok = True
      if i+1<w:
        if s[j][i+1] == '#': ok = True
      if ok == False:
        print('No')
        exit()
print(ans)

Measured memory_bytes: 3064
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] line = br.readLine().split(" ");
        double x1 = Double.parseDouble(line[0]);
        double y1 = Double.parseDouble(line[1]);
        double x2 = Double.parseDouble(line[2]);
        double y2 = Double.parseDouble(line[3]);
        double dis = Math.sqrt(Math.pow(x1-x2,2)+Math.pow(y1-y2,2));

        System.out.println(dis);
    }
}

Measured memory_bytes: 24588
#include "bits/stdc++.h"
using namespace std;

int main() {
	int H, W, dx[4] = { 1, -1, 0, 0 }, dy[4] = { 0, 0, 1, -1 };
	cin >> H >> W;
	vector<string> S(H);
	for (int i = 0; i < H; i++) cin >> S[i];
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (i % 2 == 0 && j % 2 == 0) {
				if ((i + j) % 4 == 0) {
					if (S[i][j] != '6') {
						S[i][j] = '#';
						for (int k = 0; k < 4; k++) {
							int nx = i + dx[k], ny = j + dy[k];
							if (0 <= nx && nx < H && 0 <= ny && ny < W) {
								S[nx][ny] = '#';
							}
						}
					}
				}
				else {
					if (S[i][j] != '1') {
						S[i][j] = '#';
						for (int k = 0; k < 4; k++) {
							int nx = i + dx[k], ny = j + dy[k];
							if (0 <= nx && nx < H && 0 <= ny && ny < W) {
								S[nx][ny] = '#';
							}
						}
					}
				}
			}
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (i % 2 != 0 || j % 2 != 0) continue;
			char v[4];
			if (i % 4 == 0 && j % 4 == 0) v[0] = '2', v[1] = '5', v[2] = '3', v[3] = '4';
			if (i % 4 == 0 && j % 4 == 2) v[0] = '2', v[1] = '5', v[2] = '4', v[3] = '3';
			if (i % 4 == 2 && j % 4 == 0) v[0] = '5', v[1] = '2', v[2] = '3', v[3] = '4';
			if (i % 4 == 2 && j % 4 == 2) v[0] = '5', v[1] = '2', v[2] = '4', v[3] = '3';
			for (int k = 0; k < 4; k++) {
				int nx = i + dx[k], ny = j + dy[k];
				if (0 <= nx && nx < H && 0 <= ny && ny < W) {
					if (S[nx][ny] != v[k]) S[nx][ny] = '#';
				}
			}
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (S[i][j] != '#') S[i][j] = '.';
		}
	}
	queue<pair<int, int> > Q;
	bool V[100][100] = {};
	V[0][0] = true;
	Q.push({ 0, 0 });
	while (!Q.empty()) {
		pair<int, int> P = Q.front();
		Q.pop();
		for (int i = 0; i < 4; i++) {
			int nx = P.first + dx[i], ny = P.second + dy[i];
			if (0 <= nx && nx < H && 0 <= ny && ny < W) {
				if (S[nx][ny] == '.' && !V[nx][ny]) {
					Q.push({ nx, ny });
					V[nx][ny] = true;
				}
			}
		}
	}
	cout << (V[H - 1][W - 1] ? "YES" : "NO") << endl;
}


Measured memory_bytes: 3232
# coding: utf-8
import numpy as np
N = int(input())
A = []
for _ in range(2):
    A.append(list(map(int, input().split())))
dp = [[0] * N] * 2
dp = np.array(dp)
dp[0][0] = A[0][0]
dp[1][0] = A[0][0] + A[1][0]
for i in range(1, N):
    dp[0][i] = dp[0][i-1] + A[0][i]
    dp[1][i] = max(dp[0][i], dp[1][i-1]) + A[1][i]
print(dp[1][N-1])

Measured memory_bytes: 21168
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll, ll> pii;
 
#define REP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define PER(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)
 
void ii(ll &x){ cin >> x; }
void is(string &x){ cin >> x; }
void oi(ll &x){ cout << x << " "; }
void os(string &x){ cout << x; }
void oie(ll &x){ cout << x << endl; }
void ose(string &x){ cout << x << endl; }
void oe(){ cout << endl; }
 
int main(){
    ll N, K;
    ii(N);
    ii(K);
    vector<ll> A(N);
    REP(i,0,N) ii(A[i]);
    sort(A.begin(), A.end());
    ll l=-1e18-1;
    ll r=1e18;
    while(l<r-1){
        ll m = ll((l+r)/2);
        ll s = 0;
        REP(i,0,N){
            if(A[i]==0){
                if(m>=0){
                    s+=N;
                }
            }else if(A[i]>0){
                long double v = (long double)m/A[i];
                s+=std::upper_bound(A.begin(), A.end(), v)-A.begin();
            }else{
                long double v = (long double)m/A[i];
                s+=N-(std::lower_bound(A.begin(), A.end(), v)-A.begin());
            }
            if(A[i]*A[i]<=m) s--;
        }
        if(s>=K*2){
            r=m;
        }else{
            l=m;
        }
    }
    oie(r);
    return 0;
}

Measured memory_bytes: 1792
# coding=utf-8


def surround_odd_check(board_cond, r, c):
    try:
        right = board_cond[r][c+1] % 2
    except IndexError:
        right =2

    try:
        down = board_cond[r+1][c] % 2
    except IndexError:
        down = 2

    return [right, down]


if __name__ == '__main__':
    H, W = map(int, input().split())

    board = [list(map(int, input().split())) for i in range(H)]
    ctr = 0
    moves = []
    odd_counter = 0
    for i in range(H):
        for j in range(W):
            if board[i][j] % 2 == 1:
                odd_counter += 1

    for i in range(H):
        for j in range(W):
            flag = surround_odd_check(board, i, j)
            if board[i][j] % 2 == 1:
                if flag[0] == 1:
                    ctr += 1
                    board[i][j] -= 1
                    board[i][j+1] += 1
                    moves.append([i+1, j+1, i+1, j+2])
                    odd_counter -= 2
                elif flag[1] == 1:
                    ctr += 1
                    board[i][j] -= 1
                    board[i+1][j] += 1
                    moves.append([i+1, j+1, i+2, j+1])
                    odd_counter -= 2
                elif flag[0] == 0 and odd_counter > 0:
                    ctr += 1
                    board[i][j] -= 1
                    board[i][j+1] += 1
                    moves.append([i+1, j+1, i+1, j+2])
                elif flag[1] == 0 and odd_counter > 0:
                    ctr += 1
                    board[i][j] -= 1
                    board[i+1][j] += 1
                    moves.append([i+1, j+1, i+2, j+1])

    print(ctr)
    [print(' '.join(map(str, elm))) for elm in moves]


Measured memory_bytes: 30684
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
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 all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    ll n;cin>>n;
    vector<ll>p(n);
    rep(i,n){
        ll a;cin>>a;p[n-a]=i;
    }
    set<ll>st;
    st.insert(p[0]);
    st.insert(n);
    st.insert(-1);
    ll ans=0;
    set<ll>st2;
    st2.insert(n-p[0]-1);
    st2.insert(n);
    st2.insert(-1);
    REP(i,1,n){
        if(*st.upper_bound(p[i])!=n){
            auto itr=st.upper_bound(p[i]);
            auto itr2=st.upper_bound(*itr);
            auto itr3=st2.upper_bound(n-1-p[i]);
            ans+=(*itr2-*itr)*(*itr3-(n-p[i]-1))*(n-i);
            //cout<<*itr<<' '<<*itr2<<' '<<n-1-*itr3<<endl;
        }
        if(*st2.upper_bound(n-1-p[i])!=n){
            auto itr=st2.upper_bound(n-1-p[i]);
            auto itr2=st2.upper_bound(*itr);
            auto itr3=st.upper_bound(p[i]);
            ans+=(*itr2-*itr)*(*itr3-p[i])*(n-i);
        }
        st.insert(p[i]);
        st2.insert(n-p[i]-1);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 10368
def printMissingNumber(cards, mark):
    for cardNum in range(1, 13 + 1):
        if not cardNum in cards:
            print("{0} {1}".format(mark, cardNum))


n = int(input())
s_cards = []
h_cards = []
c_cards = []
d_cards = []

for i in range(n):
    shape, num = input().split()
    num = int(num)
    target = None
    if shape == "H":
        target = h_cards
    elif shape == "D":
        target = d_cards
    elif shape == "C":
        target = c_cards
    elif shape == "S":
        target = s_cards
    target.append(num)

printMissingNumber(s_cards, "S")
printMissingNumber(h_cards, "H")
printMissingNumber(c_cards, "C")
printMissingNumber(d_cards, "D")

Measured memory_bytes: 7736
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
	long long b = M, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= M;
	if (u < 0) u += M;
	return u;
}
vector<vector<ll>> mul(vector<vector<ll>> a,vector<vector<ll>> b,int n){
	int i,j,k,t;
	vector<vector<ll>> c(n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			t = 0;
			for (k = 0; k < n; k++)
				t = (t + a[i][k]*b[k][j] % M)%M;
			c[i].push_back(t);
		}
	}
	return c;
}
int main() {
	int n, m, q, l, r, c[555][555], sum[555][555], i, j, a, b;
	cin >> n >> m >> q;
	for (i = 1; i <= n; i++)
		for (j = 1; j <= n; j++)
			c[i][j] = 0;
	for (i = 0; i < m; i++) {
		cin >> l >> r;
		c[l][r]++;
	}
	for (j = 0; j <= n; j++)
		sum[n + 1][j] = 0;
	for (i = 1; i <= n; i++)
		sum[i][0] = 0;
	for (i = n; i >= 1; i--)
		for (j = 1; j <= n; j++)
			sum[i][j] = sum[i][j - 1] + sum[i + 1][j] - sum[i + 1][j - 1] + c[i][j];
	for (i = 0; i < q; i++) {
		cin >> a >> b;
		cout << sum[a][b] << endl;
	}
}

Measured memory_bytes: 7936
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>   
using namespace std;
using namespace __gnu_pbds;
typedef long long ll; 
#define int long long
typedef unsigned long long lu;
typedef vector<ll> v;
typedef vector<vector<ll> > vv;
typedef vector<string>  vs;
typedef vector<pair<ll,ll>> vpr;
typedef vector<bool>vb;
typedef vector<double>vd;
typedef long double ld;
#define f(i,n) for(ll i = 0; i < n; i++)
#define ff(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define amax(x,y) if(y>x) x=y;
#define amin(x,y) if(y<x)x=y;
#define bg(x) x.begin()
#define sz(x) (ll)x.size()
#define in(x,n) for(ll i=0;i<n;i++)cin>>x[i]
#define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" " 
#define mxt(a) *(max_element(a.begin(),a.end()))
#define mnt(a) *(min_element(a.begin(),a.end())
#define tc ll t;cin>>t;while(t--)
typedef pair<ll,ll> pi;
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define yesno(f) if(f) yes else no
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
const ld PI = 2 * acos(0.0);
ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;}
ll power(ll a,ll b,ll m)
{
    if(b==0)
        return 1;
    ll d=power(a,b/2,m);
    d=(d*d)%m;
    if(b&1)
        d=(d*a)%m;
    return d;
}
const ll mod=1e9+7;
int MOD(int a)
{
    if(a<0)
        a+=mod;
    if(a>=mod)
        a%=mod;
    return a;
}
// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
/*string operations :
str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
str.substr (x) : returns a substring str[x],... end of string
str.find(qtr) : returns the first occurenece of qtr in str */
int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int n,x,t;cin>>n>>x>>t;
    cout<<t*cel(n,x)<<endl;
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
//#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n, y, a, b, c;
  cin >> n >> y;
  y/=1000;
  y-=n;
  bool able=0;
  for(b=0; 4*b<=y; b++) {
    c=y-4*b;
    if(c%9==0) {c/=9; able=1; break;}
  }
  a=n-b-c;
  if(able && a>=0) cout << c << " " << b << " " << a << newl;
  else cout << "-1 -1 -1" << newl;
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]", B: "List[int]"):
    A.sort()
    B.sort(reverse=True)
    if N % 2 == 0:
        Xa1 = A[N // 2 - 1]
        Xa2 = A[N // 2]
        Xb1 = B[N // 2 - 1]
        Xb2 = B[N // 2]
        print(Xb2 + Xb1 - (Xa2 + Xa1) + 1)
    else:
        Xa = A[(N + 1) // 2 - 1]
        Xb = B[(N + 1) // 2 - 1]
        print(Xb - Xa + 1)
        
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, A, B)

if __name__ == '__main__':
    main()

Measured memory_bytes: 76420
#include <bits/stdc++.h>
using namespace std;
 typedef long long ll;
 
int main() {
ll l,r;
cin>>l>>r;
ll ans=2020;
for(ll i=l;(i<r) && (i<l+2020);i++){
for(ll j=i+1;(j<=r) && (j<i+2021);j++){
    ans=min(ans, i*j%2019);
}
}
cout<<ans<<endl;
}


Measured memory_bytes: 256
from collections import defaultdict

def run():
    n = int(input())
    s = defaultdict(int)
    lst = []

    for _ in range(n):
        string = input()
        s[string] += 1
    
    max_ = 0
    
    for key in s:
        if max_ < s[key]:
            lst = [key]
            max_ = s[key]
        elif max_ == s[key]:
            lst.append(key)
    lst = sorted(lst)
    for i in lst:
        print(i)
        
    

if __name__ == "__main__":
    run()

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
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; }
const ll MOD = 1e9+7;

ll X[100100];

ll mod_pow(ll x, ll n, ll mod){
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}


int main(){
    ll N, K;
    cin >> N >> K;
    for(ll k = K; k >= 1; k--){
        ll x = mod_pow(K/k, N, MOD);
        for(ll m = 2*k; m <= K; m += k){
            x += MOD - X[m];
            x %= MOD;
        }
        X[k] = x;
    }

    ll ans = 0;
    REPi(k,1,K+1){
        ans += k*X[k];
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


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

int selection_sort(int A[], int N) {
  int sw = 0;

  for (int i = 0; i < N; i++) {
    int minj = i;
    for (int j = i; j < N; j++) {
      if (A[minj] > A[j]) {
        minj = j;
      }
    }
    swap(A[i], A[minj]);
    if (i != minj) sw++;
  }
  return sw;
}

int main() {
  int A[100];
  int N;
  int sw;

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

  sw = selection_sort(A, N);

  for (int i = 0; i < N; i++) {
    if (i) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n%d\n", sw);
  return 0;
}


Measured memory_bytes: 3212
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

ss = input().split(' ')
print((ss[0][0]+ss[1][0]+ss[2][0]).upper())

Measured memory_bytes: 3832
r=a=o=0
while 1:
 l,m,n=sorted(list(map(int,input().split())))
 if l+m<=n:break
 c=l*l+m*m-n*n
 if c>0:a+=1
 elif c<0:o+=1
 else:r+=1
print(r+a+o,r,a,o)


Measured memory_bytes: 5596
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

vector<int> detectOrder(int n) {
  int i;
  long m, res;
  m = 0;
  vector<int> v(2);
  
  if(n < 0) {
    i = 1;
    while(true) {
      res = -2*pow(2,(i-1));
      m += res;
      if(m <= n) {break;}
      i += 2;
    }
  } else if(n > 0) {
    i = 0;
    while(true) {
      res = pow(2,i);
      m += res;
      if(m >= n) {break;}
      i += 2;
    }
  }
  
  v[0] = i;
  v[1] = res;
  return v;
}

int main() {
  int N, tmp;
  string s = "";
  vector<int> v(2);
  
  cin >> N;
  if(N==0) {
    cout << 0 << endl;
    return 0;
  }
  tmp=-1;
  while(N!=0) {
    v = detectOrder(N);
    for(int i=0; i<tmp-v[0]-1; i++) {s+='0';}
    s += '1';
    tmp = v[0];
    N -= v[1];
  }
  for(int i=0; i<tmp; i++) {s+='0';}

  cout << s << 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 all(x) (x).begin(), (x).end()
typedef long long ll;
const int INF (1<<30);

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

  if (a1+a2+a3 >= 22) cout << "bust" << endl;
  else cout << "win" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int h[1501], w[1501];
  int n, m, i, j;
  
  while(scanf("%d%d", &n, &m) && (n|m)) {
    int dat[1500001] = {};
    n++, m++;
    h[0] = w[0] = 0;
    for(i=1; i<n; i++) { scanf("%d", &h[i]); h[i] += h[i-1]; }
    for(i=1; i<m; i++) { scanf("%d", &w[i]); w[i] += w[i-1]; }
    
    for(i=0; i<m-1; i++)
      for(j=i+1; j<m; j++)
	dat[w[j]-w[i]] ++;
    
    int cnt = 0;
    for(i=0; i<n-1; i++)
      for(j=i+1; j<n; j++)
	cnt += dat[h[j]-h[i]];
    
    printf("%d\n", cnt);
  }
  
  return 0;
}

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

// Shrotening
#define fst first
#define snd second
#define pb push_back
#define mp std::make_pair

// Loop
#define FOR(i,a,b) for(auto i=(a);i<(b);++i)
#define RFOR(i,a,b) for(auto i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::pair<int,int> PII;

typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;
typedef std::vector<PII> VPII;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

int N, M;
VI memo(1 << 20, -1);
VI2 b(21, VI(100001, 0));

int dp(int k,int bit){
    if(k == N) return 0;
    if(memo[bit] != -1) return memo[bit];

    int ret = std::numeric_limits<int>::max();
    FOR(i, 1, M+1) {
        if( ( bit&1 << (i-1)) == 0){
            int x = N-b[i][N];
            int y = b[i][k+x]-b[i][k];
            ret = std::min(ret,dp(k+x,bit|1<<(i-1))+y);
        }
    }
    return memo[bit] = ret;
}

int main(){
    std::cin >> N >> M;
    FOR(i, 1, N+1) {
        int a;
        std::cin >> a;
        FOR(j, 1, M+1) {
            if(j != a) b[j][i]++;
            b[j][i] += b[j][i-1];
        }
    }
    std::cout << dp(0, 0) << std::endl;
}


Measured memory_bytes: 15380
#include <iostream>
#include <algorithm>
#include <queue>
#include <tuple>
#include <stack>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define INF INT_MAX>>1 //要climits#includ

typedef long long ll;

using namespace std;

int main(void){
	int r, d, x; cin >> r >> d >> x;
	for(int i=0; i<10; i++){
		x = r*x - d;
		cout << x << endl;
	}
}

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

inline int read()
{
	int ret=0; char c=getchar();
	while(c<48||c>57)c=getchar();
	while(c>=48 && c<=57)ret=ret*10+c-48,c=getchar();
	return ret;
}
#define N 500005
char ss[N];
int s[N],n,t[N],T,a[N],b[N],ma;
int main()
{
	n=read();
	scanf("%s",ss+1); //() %c 97 
	for(int i=1; i<=n; ++i)a[i]=ss[i]=='E',b[i]=ss[i]=='W';
	for(int i=1; i<=n; ++i)t[i]=t[i-1]+b[i];
	for(int i=n; i; --i)s[i]=s[i+1]+a[i];
	ma=n;
	for(int i=1; i<=n; ++i)ma=min(ma,t[i-1]+s[i+1]);
	printf("%d\n",ma);
}

Measured memory_bytes: 7680
#include <iostream>
#include <vector>
using namespace std;
int main( void )
{
	int N; // óÎÌÂ
	while ( cin >> N && N != 0 )
	{
		// óÎÌÀWÝè
		vector < vector <int> > G( 20+1, vector <int>( 20+1, 0 ) );
		for ( int i = 0; i < N; i++ )
		{
			int Xi, Yi;
			cin >> Xi >> Yi;
			G[Yi][Xi] = 1;
		}

		// {bgÌì
		int M;
		cin >> M;

		int x = 10;
		int y = 10;

		int cnt = 0;
		for ( int i = 0; i < M; i++ )
		{
			string operation;	// ûü
			int step;			// Ú®Ê
			cin >> operation >> step;

			// NCECSCW
			if ( operation == "N" )
			{
				for ( int j = 0; j < step; j++ )
				{
					y++;
					if ( G[y][x] )
					{
						G[y][x] = 0;
						cnt ++;
					}
				}
			}

			else if ( operation == "E" )
			{
				for ( int j = 0; j < step; j++ )
				{
					x++;
					if ( G[y][x] )
					{
						G[y][x] = 0;
						cnt ++;
					}
				}
			}

			else if ( operation == "S" )
			{
				for ( int j = 0; j < step; j++ )
				{
					y--;
					if ( G[y][x] )
					{
						G[y][x] = 0;
						cnt ++;
					}
				}
			}

			else if ( operation == "W" )
			{
				for ( int j = 0; j < step; j++ )
				{
					x--;
					if ( G[y][x] )
					{
						G[y][x] = 0;
						cnt ++;
					}
				}
			}

		}

		if ( cnt == N )
		{
			cout << "Yes" << endl;
		}
		else
		{
			cout << "No" << endl;
		}

	}

	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	int s1,s2,s3;
	s1 = a+b;
	s2 = a-b;
	s3 = a*b;
	cout<<max(s1,max(s2,s3))<<endl;
	return 0;
}

Measured memory_bytes: 256
<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
$d = trim(fgets(STDIN));
$e = trim(fgets(STDIN));

$data["a"] = $a;
$data["b"] = $b;
$data["c"] = $c;
$data["d"] = $d;
$data["e"] = $e;

$sort["a"] = $a % 10;
$sort["b"] = $b % 10;
$sort["c"] = $c % 10;
$sort["d"] = $d % 10;
$sort["e"] = $e % 10;
asort($sort);

foreach( $sort as $key => $val )
{
  if( $val != 0 )
  {
    $min = $data[$key];
    unset($data[$key]);
    break;
  }
}

$sum = 0;
foreach( $data as $key => $val )
{
  $add = 0;
  if( $sort[$key] != 0 ) { $add = 10 - $sort[$key]; }
  $sum += $val + $add;
}

$sum += $min;
echo $sum;
?>


Measured memory_bytes: 4604
import java.util.*;

public class Main {
    public static long gcd(long a, long b) {
        while (a % b != 0) {
            long tmp = a % b;
            a = b;
            b = tmp;
        }
        return b;
    }
    public static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    }
    public static long divnum(long a, long b, long x) {
        return b / x - (a - 1) / x;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        if (d % c == 0) {
            System.out.println(b - a + 1- divnum(a, b, c));
        } else {
            System.out.println(b - a + 1- divnum(a, b, c) - divnum(a, b, d) + divnum(a, b, lcm(c, d)));
        }
    }
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
template <typename T> bool chmax(T &u, const T z) { if (u < z) {u = z; return true;} else return false; }
template <typename T> bool chmin(T &u, const T z) { if (u > z) {u = z; return true;} else return false; }
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
typedef pair<ll, ll> P;
const ll INF = 1LL << 60;
//const int MOD = 1000000007;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

int main(){
  string s;
  cin>>s;
  cout<<s;
  if(s[s.size()-1]=='s'){
    cout<<"es"<<endl;
  }else{
    cout<<"s"<<endl;
  }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define rushb() scanf("%d",&t);while(t--)
#define rusha() scanf("%d",&n);rep(i,1,n)scanf("%d",&a[i]);
#define debug() cout<<"LBWNB"<<'\n'
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define p() puts("");
using namespace std;
typedef long long ll;
const int mod=998244353;
const int inf=1e9+7;
const int maxn=2e5+7;
ll n,m;
int main(){
    scanf("%lld%lld",&n,&m);
    if(n==1||m==1) {puts("1");return 0;}
    printf("%lld\n",n*m/2+(n*m)%2);
    return 0;
}










//const int M=1<<20;
//ll t1[M*2+5],t2[M*2+5],ans,ca[M],cb[M];
//inline void upd(int i){t1[i]=t1[i<<1]+t1[i<<1|1];t2[i]=max(t2[i<<1],t1[i<<1]+t2[i<<1|1]);}
//inline void add(int i,int v){for(t1[i+=M]+=v;i>>=1;upd(i));}
//int n,m,p,x,y,i,j;
//struct mons{int x,y,z;}a[M];
//int main(){
//	for(i=0;i<M;++i)ca[i]=cb[i]=1ll<<60;ans=-(1ll<<60);
//	scanf("%d%d%d",&n,&m,&p);
//	for(i=1;i<=n;++i)scanf("%d%d",&x,&y),ca[x]=min(ca[x],(ll)y);
//	for(i=1;i<=m;++i)scanf("%d%d",&x,&y),cb[x]=min(cb[x],(ll)y);
//	for(i=0;i<M;++i)t2[i+M]=-cb[i];for(i=M-1;i;--i)upd(i);
//	for(i=1;i<=p;++i)scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].z);
//	sort(a+1,a+p+1,[&](const mons&a,const mons&b){return a.x<b.x;});
//	for(i=0,j=1;i<M;++i){
//		for(;j<=p && a[j].x<i;++j)add(a[j].y,a[j].z);
//		ans=max(ans,t2[1]-ca[i]);
//	}
//	printf("%lld\n",ans);
//	return 0;
//}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main(void) {
	int R[MAX], n;
	
	cin >> n;
	for(int i=0;i<n;i++) cin >> R[i];
	
	int maxv = -2000000000;
	int minv = R[0];
	
	for(int i=1; i<n; i++) {
		maxv = max(maxv, R[i] - minv);
		minv = min(minv,R[i]);
	}
	
	cout << maxv << endl;
	
	return 0;
}

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

signed main() {
  std::vector<int> v(3);
  cin>>v[0]>>v[1]>>v[2];
  sort(v.begin(),v.end());
  if((v[0]*v[1]*v[2])%2==0)cout<<0;
  else cout<<v[0]*v[1];
  cout<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
void reverseArray(int arr[], int start, int end) 
{ 
    while (start < end) 
    { 
        int temp = arr[start];  
        arr[start] = arr[end]; 
        arr[end] = temp; 
        start++; 
        end--; 
    }  
}  
 
int main() {
int n, i;
cin >> n;
int arr[n];
for(int i = 0; i < n; i++) {
cin >> arr[i];
}
reverseArray(arr, 0, n-1);
for(int j = 0; j < n; j++) {
    cout << arr[j];
    if(j == n-1) {
        cout << endl;
    } else {
        cout << " ";
    }
}
}


Measured memory_bytes: 3088
from sys import *

for s in stdin:
    d = float(s)
    if d <= 48.0: print "light fly"; continue
    if d <= 51.0: print "fly"; continue
    if d <= 54.0: print "bantam"; continue
    if d <= 57.0: print "feather"; continue
    if d <= 60.0: print "light"; continue
    if d <= 64.0: print "light welter"; continue
    if d <= 69.0: print "welter"; continue
    if d <= 75.0: print "light middle"; continue
    if d <= 81.0: print "middle"; continue
    if d <= 91.0: print "light heavy"; continue
    print "heavy"

Measured memory_bytes: 4228
#include<stdio.h>
int a,b;
int i;
int n;

int max(int x,int y){
	if(x>=y)return x;
	else return y;
}

int main(){
	a=0;
	b=0;
	for(i=0;i<4;i++){
		scanf("%d",&n);
		a+=n;
	}
	for(i=0;i<4;i++){
		scanf("%d",&n);
		b+=n;
	}
	printf("%d\n",max(a,b));
	return 0;
}

Measured memory_bytes: 1020
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(1000000)

def main():
    n, m = map(int, input().split())
    parents = [i for i in range(n)]
    for i in range(m):
        x, y, z = map(int, sys.stdin.readline().split())
        unite(x - 1, y - 1, parents)
    uniq = {find(i, parents) for i in range(n)}
    print(len(uniq))

def unite(x, y, parents):
    px = find(x, parents)
    py = find(y, parents)
    parents[py] = px

def find(x, parents):
    if parents[x] == x:
        return x
    fx = find(parents[x], parents)
    parents[x] = fx
    return fx

if __name__ == "__main__":
    main()


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

using namespace std;

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

  int a1,a2,a3; cin>>a1>>a2>>a3;
  int sum = a1+a2+a3;
  cout << (sum >= 22 ? "bust" : "win") << endl;

  return 0;
}


Measured memory_bytes: 256
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
Main();
function next(){return obj.next();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var N = nextInt();
  var list = nextIntArray();
  var used = {};
  for(var i = 0; i < N; i++){
    if(N % 2 == 0 && list[i] % 2 == 0){
      myout(0);
      return; 
    }else if(N % 2 == 1 && list[i] % 2 == 1){
      myout(0);
      return;
    }
    if(used[list[i]] == null){
       used[list[i]] = 1;
    }else{
       used[list[i]]++;
    }
  }
  
  var keys = Object.keys(used);
  var keyLength = keys.length;
  var output = 1;
  for(var i = 0; i < keyLength; i++){
    if(used[keys[i]] != 1 && keys[i] == 0){
       myout(0);
      return;
    }else if(used[keys[i]] != 2 && keys[i] != 0){
       myout(0);
      return;
    }else{
      output = (output * used[keys[i]]) % 1000000007;
    }
  }
  
  myout(output);
}

Measured memory_bytes: 32612
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) ((x).begin()),((x).end())
#define int ll
using pii = pair <int, int>;
#define INF 0x7f7f7f7f7f7f7f7f
const bool debug = false;

int cnt[202020];
int n;
int best;
vector <int> v;
inline int nc2(int x)
{
    if (x <= 0) return 0;
    return x*(x-1)/2;
}
int32_t main()
{
    usecppio
    cin >> n;
    for (int i = 0; i<n; i++)
    {
        int x; cin >> x;
        v.push_back(x);
        cnt[x]++;
    }
    for (int i = 0; i<=200000; i++)
    {
        best += nc2(cnt[i]);
    }
    for (int i = 0; i<n; i++)
    {
        cout << best-(nc2(cnt[v[i]])-nc2(cnt[v[i]]-1)) << '\n';
    }
}

Measured memory_bytes: 4848
import java.util.Arrays;
import java.util.Scanner;

public class Main {
        public static long setdp(char[][] maze ,long[][] dp , int i , int j , int rows , int cols , int mod){

            //System.out.println(i+" "+j+" check");

            if(i<0 || j<0 ) return 0;
            if(i>=rows || j>=cols) return 0;
            if(maze[i][j]=='#') return 0;
            if(dp[i][j]!=-1) return dp[i][j]%mod;

            else
                dp[i][j] = setdp(maze,dp,i-1,j,rows,cols,mod)+setdp(maze,dp,i,j-1,rows,cols,mod);

            return dp[i][j]%mod;

        }

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        int mod = 1000000007;
        int rows = in.nextInt();
        int col = in.nextInt();

        char[][] maze = new char[rows][col];

        for(int i=0;i<rows;i++)
        {

            String x = in.next();
            maze[i] = x.toCharArray();

        }


        long[][] dp = new long[rows][col];

        for(int i=0;i<rows;i++)
            Arrays.fill(dp[i],-1);


        dp[0][0]=0;

        for(int i =0 ;i<rows;i++){

            for(int j=0;j<col;j++ ){

                    if(i==0 && j==0 ) dp[i][j] = 1;
                    else
                    setdp(maze,dp, i, j, rows, col,mod);
                }

            }



//        for(int i =0 ;i<rows;i++){
//
//            for(int j=0;j<col;j++ ){
//
//                System.out.print(dp[i][j]+" ");
//
//
//            }
//
//            System.out.println();
//
//        }


        System.out.println(dp[rows-1][col-1]%mod);




    }



}


Measured memory_bytes: 49204
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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 h, w, k;
int xs, ys, xg, yg;
vector<vector<char>> c;

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

void solve() {
	cin >> h >> w >> k;
    cin >> xs >> ys >> xg >> yg;
    -- xs, -- ys, -- xg, -- yg;
    c.assign(h, vector<char>(w));
    rep(i, h) {
        rep(j, w) {
            cin >> c[i][j];
        }
    }
    queue<P> que;
    vector<vector<int>> dist(h, vector<int>(w, INF));
    que.push(P{xs, ys});
    dist[xs][ys] = 0;
    while(!que.empty()) {
        P p = que.front(); que.pop();
        int x = p.fr, y = p.sc;
        rep(i, 4) {
            int nx = x, ny = y;
            for(int j = 0; j < k; ++ j) {
                nx += dx[i], ny += dy[i];
                if(0 <= nx && nx < h && 0 <= ny && ny < w && c[nx][ny] == '.') {
                    if(chmin(dist[nx][ny], dist[x][y] + 1)) {
                        que.push(P{nx, ny});
                    } else if(dist[nx][ny] < dist[x][y] + 1) {
                        break;
                    }
                } else {
                    break;
                }
            }
        }
    }
    if(dist[xg][yg] == INF) {
        cout << -1 << endl;
        return;
    }
    cout << dist[xg][yg] << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 19896