akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long 
using namespace std;

int main()
{
	int n,x,y;
	cin >> n;
	int ans = 0;
	for(int i=0;i<n;i++){
		cin >> x >> y;
		ans += (y-x)+1;
	}
	cout<< ans << '\n';
	return 0; 
}

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

using ll = long long int;

constexpr int MAX_N = 2 * 1e5 + 10;

int n;
ll a[MAX_N];
ll dp[MAX_N][2];

int main()
{
    std::cin >> n;

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

        std::cin >> a[i];
    }

    dp[1][0] = 0;
    dp[1][1] = a[1];

    if (n % 2)
    {
        for (int i = 2; i <= n; ++i)
        {
            if (i % 2)
            {
                dp[i][0] = std::max(dp[i - 1][1], dp[i - 2][0] + a[i]);
                dp[i][1] = dp[i - 2][1] + a[i];
            }
            else
            {
                dp[i][0] = dp[i - 1][0];
                dp[i][1] = std::max(dp[i - 1][1], dp[i - 2][1] + a[i]);
            }
        }
    }

    else
    {
        for (int i = 2; i <= n; ++i)
        {
            if (i % 2)
            {
                dp[i][0] = dp[i - 1][0];
                dp[i][1] = dp[i - 2][1] + a[i];
            }
            else
            {
                dp[i][0] = std::max(dp[i - 1][1], dp[i - 1][0] + a[i]);
            }
        }
    }

    std::cout << dp[n][0] << std::endl;

    return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

template<typename T>
void O(T t){
  cout << t << endl;
}

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  string s,t;
  set<string> m;
  rep(i,n){
    cin >> s >> t;
    if(s == "insert"){
      m.insert(t);
    }
    else{
      if(m.find(t) == m.end()){
        cout << "no" << endl;
      }
      else{
        cout << "yes" << endl;
      }
    }
  }
  return 0;
}

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

ll N, A[100005], S1[100005], S2[100005];

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

	cin >> N;
	for (ll i = 0; i < N; i++) {
		cin >> A[i];
	}
	S1[0] = A[0];
	for (ll i = 1; i < N; i++) {
		S1[i] = __gcd(S1[i-1], A[i]);
	}
	S2[N-1] = A[N-1];
	for (ll i = N-2; i >= 0; i--) {
		S2[i] = __gcd(S2[i+1], A[i]);
	}

	ll ans = S1[N-1];
	ans = max(ans, S2[1]);
	ans = max(ans, S1[N-2]);
	for (ll i = 0; i < N-2; i++) {
		ans = max(ans, __gcd(S1[i], S2[i+2]));
	}

	cout << ans << "\n";
}

Measured memory_bytes: 2560
#include <stdio.h>
int main(){
    int x, y;
    while(1){
    scanf("%d %d", &x, &y);
    if ( x == 0 && y == 0 ) break; 
    if(x < y){
        printf("%d %d\n", x, y);
    }else{
        printf("%d %d\n", y, x);
    }
    }
    return 0;
}


Measured memory_bytes: 2040
#include<iostream>
#include<fstream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<unordered_map>
#include<map>
#include<string>
#include<cstring>
#include<stack>
#include<cmath>

#define vint vector<int>
#define vstr vector<string>
#define vll vector<long long>
#define ll long long
#define pf printf
#define sf scanf
#define sfd(n) scanf("%d", &n)
#define sflf(n) scanf("%lf", &n)
#define sfll(n) scanf("%lld", &n)
#define pfd(n) printf("%d", n)
#define pflf(n) printf("%lf", n)
#define pfll(n) printf("%lld", n)
#define pft	printf("\t")
#define pfn printf("\n")
#define pfk printf(" ")
#define PI 3.1415926
#define MAX 100000
#define M 1e18

using namespace std;

int main() {
	string str;
	cin >> str;
	if( str=="SUN" ) {
		pfd(7);
	}else if( str=="MON" ) {
		pfd(6);
	}else if( str=="TUE" ) {
		pfd(5);
	}else if( str=="WED" ) {
		pfd(4);
	}else if( str=="THU" ) {
		pfd(3);
	}else if( str=="FRI" ) {
		pfd(2);
	}else if( str=="SAT" ) {
		pfd(1);
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

#define ALL(x) (x).begin(), (x).end()
#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)


void solve(long long X){
    lint val = 100;
    lint cnt = 0;
    while(1){
        if (val >= X){
            break;
        }
        cnt += 1;
        val = val * 1.01;
    }
    cout << cnt << "\n";
}

int main(){

    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}



Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll a,b;
    cin>>a>>b;
    printf("%lld %lld %0.5lf\n",a/b,a%b,double(a*1.00/b*1.00));
    return 0;
}



Measured memory_bytes: 3180
import itertools
h, w, k = map(int, input().split())
ans = 0
s = [input() for _ in range(h)]
for hi in itertools.product([0, 1], repeat=h):
	tmp = s[:]
	for j in range(h):
		if hi[j] == 1:
			tmp[j] = "."*w
	for wi in itertools.product([0, 1], repeat=w):
		cnt = 0
		for i in range(h):
			for j in range(w):
				if wi[j]:
					if tmp[i][j] == "#":
						cnt += 1
		if cnt == k:
			ans += 1
print(ans)


Measured memory_bytes: 9068
#include <cstdio>
#include <set>
#include <algorithm>
#include <vector>

int main(void) {
  int n;
  while (scanf("%d", &n) == 1) {
    std::vector<int> v(n);
    for (auto &x : v) {
      scanf("%d", &x);
    }

    std::sort(v.begin(), v.end(), std::greater<>());
    std::multiset<int> ms;
    int res = 0;
    for (auto x : v) {
      bool found = false;
      for (int i = 31; i >= 1; i--) {
        int nx = int(((long long)1 << i) - x);
        if (nx < x) {
          break;
        }
        auto it = ms.find(nx);
        if (it != ms.end()) {
          res++;
          ms.erase(it);
          found = true;
          break;
        }
      }
      if (!found) {
        ms.insert(x);
      }
    }

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


Measured memory_bytes: 10368
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    long[] a = new long[N];
    long[] s = new long[N + 1];
    for (int i = 0; i < N; i++) {
      a[i] = scanner.nextInt();
      s[i + 1] = s[i] + a[i];
    }

    long[][] dp = new long[N][N];
    for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) dp[i][j] = Long.MAX_VALUE;
    for (int i = 0; i < N; i++) dp[i][i] = 0;
    for (int l = 1; l < N; l++) {
      for (int i = 0; i < N - l; i++) {
        int j = i + l;
        for (int k = i; k < j; k++) {
          dp[i][j] = Math.min(dp[i][j], s[j + 1] - s[i] + dp[i][k] + dp[k + 1][j]);
        }
      }
    }
    System.out.println(dp[0][N - 1]);
  }
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
typedef map<int, int> MPII;
typedef set<int> SETI;

const int mxN = 2e5;
const ld pi = 4.0 * atanl(1.0);
const int iinf = 1e9 + 10;
const int inf = 1e18 + iinf + 10;
const int mod = 1000000007;
const ld prec = .000001;

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()

int n, m, t, a[mxN];
vi v;

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

int main() {
  fast();
  cin >> n >> m;
  int ans = 0, o = 1;

  while (o < m) {
    --o;
    o += n;
    ++ans;
  }
  cout << ans;

  return 0;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
typedef pair<int, int> P;
const int MAX_N = 810;
const int INF = 1e9;

struct edge{
   int to, cost;
};
vector<edge> G[MAX_N];
int dist[MAX_N][MAX_N];

void dfs(int st, int now, int pre, int cost){
    dist[st][now] = cost;
    rep(i, 0, G[now].size()){
        int nxt = G[now][i].to;
        if(nxt == pre) continue;
        dfs(st, nxt, now, cost + G[now][i].cost);
    }
}

int main(){
    int n;
    while(cin >> n, n){
        rep(i, 0, n) G[i].clear();
        rep(i, 0, n) rep(j, 0, n) dist[i][j] = INF;
        vector<int> p(n), d(n);
        int ans = 0;        
        rep(i, 1, n){
            cin >> p[i]; p[i]--;
        }
        rep(i, 1, n){
            cin >> d[i];
            ans += 3 * d[i];
        }
        rep(i, 1, n){
            G[i].push_back({p[i], d[i]});
            G[p[i]].push_back({i, d[i]});
        }
        vector<bool> leaf(n);
        rep(i, 0, n){
            if(G[i].size() == 1){
                leaf[i] = true;
                ans -= 2 * G[i][0].cost;
            }
        }
        rep(i, 0, n) if(leaf[i] == false) dfs(i, i, -1, 0);
        int MAX = 0;
        rep(i, 0, n){
            rep(j, 0, n){
                if(leaf[i] == false && leaf[j] == false){
                    MAX = max(MAX, dist[i][j]);
                }
            }
        }
        cout << ans - MAX << endl;
    }
}


Measured memory_bytes: 5808
#include <bits/stdc++.h>
 
using namespace std;
 
#define int long long 
#define INF 1e9
#define LINF 1e18
 
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> Pi;
typedef pair<P, P> PP;
 
const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };
 
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int A, B;
    cin >> A >> B;
    int res;
    if(A % 2) {
        if((B - A) / 2 % 2) {
            if(B % 2) res = A^1;
            else res = A^B^1;
        }
        else {
            if(B % 2) res = A;
            else res = A^B;
        }
    }
    else {
        if((B - A + 1) / 2 % 2) {
            if(B % 2) res = 1;
            else res = B ^ 1;
        }
        else {
            if(B % 2) res = 0;
            else res = B;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

typedef long long ll;
const ll INF = 1e15;

ll H, W;

ll get_distance(std::vector< std::string >& vs)
{
  ll sx = 0;
  ll sy = 0;
  ll gx = W - 1;
  ll gy = H - 1;

  std::vector< ll > tmp(W, INF);
  std::vector< std::vector< ll > > distance(H, tmp);

  ll dx[4] = { -1, +1,  0,  0 };
  ll dy[4] = {  0,  0, -1, +1 };

  distance[0][0] = 0;

  while (1) {
    bool was_updated = false;

    for (ll y = 0; y < H; y++) {
      for (ll x = 0; x < W; x++) {
	for (ll axis = 0; axis < 4; axis++) {
	  ll nx = x + dx[axis];
	  ll ny = y + dy[axis];
	  if (nx >=0 && nx < W &&
	      ny >=0 && ny < H &&
	      vs[ny][nx] != '#' &&
	      distance[ny][nx] > distance[y][x] + 1) {
	    distance[ny][nx] = distance[y][x] + 1;
	    was_updated = true;
	  }
	}
      }
    }

    if (! was_updated) {
      break;
    }
  }

  if (distance[H-1][W-1] == INF) {
    return -1;
  }

  return distance[H-1][W-1];
}

int main(int argc, char* argv[])
{
  std::cin >> H >> W;
  std::string s;
  std::vector< std::string > vs;
  s.resize(W);
  vs.resize(H);
  fill(vs.begin(), vs.end(), s);

  ll sharp_num = 0;
  for (ll y = 0; y < H; y++) {
    for (ll x = 0; x < W; x++) {
      std::cin >> vs[y][x];
      if (vs[y][x] == '#') {
	sharp_num++;
      }
    }
  }

  ll ans = -1;
  ll distance = get_distance(vs);
  if (distance != -1) {
    ans = H * W - (distance + 1) - sharp_num;
  }

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


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

int n;
set<int> e[100005];
bool vis[100005];

set<pair<int, int>> nice;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);

	cin >> n;
	for (int i=1; i<n; i++) {
		int u, v;
		cin >> u >> v;
		e[u].insert(v);
		e[v].insert(u);
	}

	// check if it's a path
	//dva lista
	int l = 0;
	{
		for (int i=0; i<n; i++) {
			if (e[i].size() == 1) {
				l++;
			}
		}

		if (l == 2) {
			cout << "1\n";
			return 0;
		}
	}
	
	{
		queue<int> q;
		// list-bfs
		for (int i=0; i<n; i++) {
			if (e[i].size() == 1) {
				q.push(i);
				vis[i] = true;
			}
		}

		// kreni
		while (!q.empty()) {
			int x = q.front(); q.pop();

			// dodaj grane u nice
			for (int y : e[x]) {
				nice.insert({x, y});
				nice.insert({y, x});
				if (e[y].size() == 2 && !vis[y]) {
					q.push(y);
					vis[y] = true;
				}
			}
		}

		int k = 0;

		// obradi brojke
		for (int i=0; i<n; i++) {
			if (e[i].size() > 2) {
				for (int j : e[i]) {
					if (nice.count({i, j})) {
						k++;
						break;
					}
				}
			}
		}

		cout << l-k << '\n';
	}


}

Measured memory_bytes: 23808
# -*- coding: utf-8 -*-


W,H,x_0,y_0 = map(float, input().split())

S = "{0:.6f}".format(float(W*H/2))
if W == 2 * x_0 and H == 2 * y_0:
    print(S, 1)
else:
    print(S, 0)


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

int main(void) {
  string stations;
  cin >> stations;
  if (stations == "AAA" || stations == "BBB") {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <limits>

constexpr int MAX_HEAP_SIZE = 2000000;
int H[MAX_HEAP_SIZE + 1];
int heap_size = 0;

int parent(int i) {return i / 2;};
int left(int i) {return i * 2;};
int right(int i) {return i * 2 + 1;};

void MaxHeapify(int* H, int i) {
    int l = left(i);
    int r = right(i);
    int largest;
    if ((l <= heap_size) && (H[l] > H[i])) {
        largest = l;
    }else{
        largest = i;
    }
    if ((r <= heap_size) && (H[r] > H[largest])) {
        largest = r;
    }

    if (largest != i) {
        std::swap(H[i], H[largest]);
        MaxHeapify(H, largest);
    }
}

void IncreaseHeapKey(int *H, int tgt, int key) {
    if (H[tgt] > key) {
        std::cerr << "Setting key should be higher." << std::endl;
        exit(-1);
    }
    H[tgt] = key;
    while ((tgt > 1) && (H[parent(tgt)] < H[tgt]) ) {
        std::swap(H[parent(tgt)], H[tgt]);
        tgt = parent(tgt);
    }
}
void Insert(int *H, int key) {
    heap_size++;
    H[heap_size] = std::numeric_limits<int>::min();
    IncreaseHeapKey(H, heap_size, key);
}

int ExtractMax(int *H) {
    if (heap_size < 1) {
        std::cerr << "Heap under flow" << std::endl;
        exit(-1);
    }
    int max = H[1];
    H[1] = H[heap_size];
    heap_size--;
    MaxHeapify(H, 1);
    return max;
}


void BuildMaxHeap(int *H) {
    for (int i = heap_size / 2; i > 0; i--) {
        MaxHeapify(H, i);
    }
}

int main() {
    while (true) {
        std::string str;
        std::cin >> str;
        if (str == "extract") {
            std::cout << ExtractMax(H) << std::endl;
            continue;
        }
        if (str == "insert") {
            int k;
            std::cin >> k;
            Insert(H, k);
            continue;
        }
        break;
    }
    return 0;
}


Measured memory_bytes: 7120
#include<stdio.h>
#include <string.h>

int main()
{
	char str[99 + 1];
	int i,j,N,k=0;
	scanf("%s", str);
	N = strlen(str);

	for ( i = 0; i < N; i++)
	{
		if (str[i] != str[N - 1 - i])
		k++;
	}

	for (i = 0; i <(N-1)/2-1; i++)
	{
		if (str[i] != str[(N - 1) / 2 - 1 - i])
		k++;
	}
	j = 0;
	for (i = (N+3)/2 -1; i < N; i++)
	{
		if (str[i] != str[N - 1 - j])
		k++;

		j++;
	}

	(k == 0) ? printf("Yes") : printf("No");

	return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    if N == 1 and M == 0:
        print(0)
        return
    ans = [-1] * N
    ok = True
    for i in range(M):
        s, c = map(int, input().split())
        if (ans[s-1] != -1 and ans[s-1] != c) or (N!=1 and s==1 and c==0):
            ok = False
        ans[s-1] = c
    if ans[0] == -1:
        ans[0] = 1
    for i in range(1, N):
        if ans[i] == -1:
            ans[i] = 0
    
    if ok:
        print("".join(map(str, ans)))
    else:
        print(-1)



if __name__ == "__main__":
    main()


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


#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define ll long long
#define el '\n'

using namespace std;

int n;
vector <int> pos,neg;

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

    cin >> n;
    for (int i=0;i<n;i++){
        int tm;
        cin >> tm;
        if (tm>0) pos.pb(tm);
        else neg.pb(tm);
    }

    if (!neg.empty()) sort(neg.begin(),neg.end(),greater<int>());
    if (!pos.empty()) sort(pos.begin(),pos.end());
//    cerr << neg.size() << el;
    

    int totn=0,totp=0;
    for (auto x : neg) totn-=x;
    for (auto x : pos) totp+=x;

  //  cerr << totn << " " << totp << el;

 
    int plen=pos.size(),nlen=neg.size();
    if (plen>0 && nlen>0){
        cout << totp + totn << el;

        int idp=plen-1,idn=0,tot1=pos[0];
        while (idn<nlen-1){
            cout << tot1 << " " << neg[idn] << el;
            tot1-=neg[idn];
            idn++;
        }

        int tot2=neg[nlen-1];
        while (idp>0){
            cout << tot2 << " " << pos[idp] << el;
            tot2-=pos[idp];
            idp--;
        }
        cout << tot1 << " " << tot2 << el;

        return 0;
    }
    if (plen>0){
        if (plen==1){
            cout << totp << el;
            return 0;
        } else{
            cout << totp-pos[0]-pos[0] << el;
            int tot1=pos[0],idn=1;
            while (idn<plen-1){
                cout << tot1 << " " << pos[idn] << el;
                tot1-=pos[idn]; 
                idn++;
            }
            cout << pos[plen-1] << " " << tot1 << el;

            return 0;
        }
    } else {
        if (nlen==1){
            cout << totn << el;
            return 0;
        } else{
            cout << totn+neg[0]+neg[0] << el;
            int tot1=neg[0],idn=1;
            while (idn<nlen-1){
                cout << tot1 << " " << neg[idn] << el;
                tot1-=neg[idn];
                idn++;
            }
            cout << tot1 << " " << neg[nlen-1] << el;

            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 2424
#include<bits/stdc++.h>
using namespace std;
char s[5];

int main()
{
	scanf("%s",s+1);
	if(s[1]=='A')cout<<"T"<<endl;
	if(s[1]=='C')cout<<"G"<<endl;
	if(s[1]=='G')cout<<"C"<<endl;
	if(s[1]=='T')cout<<"A"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pq priority_queue
#define P pair<int, int>
#define P2 pair<int, P>
#define P3 pair<int, P2>
using namespace std;
typedef long long ll; typedef long double ld;
constexpr int gcd(int a, int b){return b ? gcd(b, a % b) : a;}
constexpr int lcm(int a, int b){return a / gcd(a, b) * b;}
constexpr int INF = 1e9, MOD = INF + 7, around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
constexpr int inv(const int x, int n, const int mod){ll ret=1,pos=x;while(n){if(n&1)(ret*=pos)%=mod;(pos*=pos)%=mod;n>>=1;}return ret;}
template<int n> struct Factorial{ll arr[n+1],ary[n+1];constexpr Factorial():arr(),ary(){arr[0]=1;ary[0]=1;for(int i=0;i<n;i++){arr[i+1]=arr[i]*(i+1)%MOD;ary[i+1]=inv(arr[i+1],MOD-2,MOD);}}};
constexpr Factorial<10> fact;
constexpr int comb(int a, int b){ll pos = fact.arr[a], pot = fact.ary[a - b], por = fact.ary[b];return pos * pot % MOD * por % MOD;}
constexpr int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};
constexpr int sqrtN = 512, logN = 32;
constexpr ld PI = abs(acos(-1));
constexpr ll LINF=1e18;

int main(){
	int n; cin >> n; int a[100010]; char b[100010]; cin >> a[0];
	for(int i = 1; i < n; i++) cin >> b[i] >> a[i];
	
	ll s = a[0];
	for(int i = 1; i < n; i++){
		if(b[i] == '+') s += a[i];
		else s -= a[i];
	}
	
	ll pos = 0, pot = 0, ma = s;
	for(int i = n - 1; i > 0; i--){
		if(b[i] == '+') pot += 2 * a[i];
		else{
			ma = max(ma, s + pos - pot);
			pos += 2 * a[i];
			pot = 0;
		}
	}
	
	cout << ma << endl;
	return 0;
}


Measured memory_bytes: 768
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define co(x) cout << (x) << "\n"
#define pb push_back
#define Never
#define To

using namespace std;

int main(){

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

	int N;
	vector<tuple<string, int, int>> t;

	cin >> N;

	for(int i = 0 ; i < N; i++){
		string s;
		int p;
		cin >> s >> p;
		t.push_back(make_tuple(s, 100 - p, i+1));
	}

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

	for(int i = 0; i < N; i++){
		cout << get<2>(t[i]) << endl;
	}

	Never To return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
#define dis2(x) (x)*(x)
double map[21][21],maxn;
int m,n;
bool num[21];
struct node{
	double l,a,b;
}p[21];
double dis(node x,node y){
	return dis2(x.a-y.a)+dis2(x.b-y.b)+dis2(x.l-y.l);
}
void check(){
	int ln=0,cnt[21];
	double ans=0;
	for(int i=1;i<=n;i++)
		if(num[i])
			cnt[++ln]=i;
	if(ln>m)
		return;
	for(int i=1;i<=ln;i++)
		for(int j=i+1;j<=ln;j++)
			ans+=map[cnt[i]][cnt[j]];
	if(ans>maxn)
		maxn=ans;
}
void solve(int t){
	if(t>n){
		check();
		return;
	}
	num[t]=true;
	solve(t+1);
	num[t]=false;
	solve(t+1);

}
int main(){
	while(scanf("%d%d",&n,&m)!=EOF){
		for(int i=1;i<=n;i++)
			scanf("%lf%lf%lf",&p[i].l,&p[i].a,&p[i].b);
		memset(num,false,sizeof(num));
		for(int i=1;i<=n;i++){
			map[i][i]=0;
			for(int j=i+1;j<=n;j++)
				map[i][j]=map[j][i]=dis(p[i],p[j]);
		}
		maxn=-1;
		solve(1);
		printf("%lf\n",maxn);
	}
	return 0;
}

Measured memory_bytes: 940
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...) 42
#endif
#define y0 y12345
#define y1 y54321
typedef unsigned long ul;
typedef long long ll;
//typedef pair<int, int> mpair;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
using namespace std;

int main() {
	cin.tie(0);
	cerr.tie(0);
   	ios::sync_with_stdio(false);
   	int n,m;int p,q,r;cin>>p>>q>>r;
	int a = p+q+r;
	//cerr << a << endl;
	cout << min(a-p,min(a-q,a-r)) << endl;
	return 0;
}


Measured memory_bytes: 256
/* ***********************************************
Author        :yang12138
Created Time  :2018年07月01日 星期日 20时54分40秒
File Name     :D_.cpp
************************************************ */
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef pair<ll,ll>pii;
#define lson (root<<1)
#define rson (root<<1|1)

const int N=2e5+10;
const ll INF=1e18;

ll a[N],s[N];

pii cal1(int u,int v){
	int l=u,r=v-1;
	ll tot=s[v]-s[u-1];
	while(l<r){
		int m=(l+r+1)>>1;
		if(2*(s[m]-s[u-1])>=tot) r=m-1;
		else l=m;
	}
	return pii(s[l]-s[u-1],s[v]-s[l]);
}

pii cal2(int u,int v){
	int l=u,r=v-1;
	ll tot=s[v]-s[u-1];
	while(l<r){
		int m=(l+r)>>1;
		if(2*(s[m]-s[u-1])>=tot) r=m;
		else l=m+1;
	}
	return pii(s[l]-s[u-1],s[v]-s[l]);
}

ll solve(pii l,pii r){
	ll b[4]={};
	b[0]=l.first,b[1]=l.second;
	b[2]=r.first,b[3]=r.second;
	sort(b,b+4);
	if(!b[0]) return INF;
	return b[3]-b[0];
}

void solve(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%lld",a+i),s[i]=s[i-1]+a[i];

	ll ans=INF;
	for(int i=2;i<=n-2;i++){
		ans=min(ans,solve(cal1(1,i),cal1(i+1,n)));
		ans=min(ans,solve(cal1(1,i),cal2(i+1,n)));
		ans=min(ans,solve(cal2(1,i),cal1(i+1,n)));
		ans=min(ans,solve(cal2(1,i),cal2(i+1,n)));
	}
	printf("%lld\n",ans);
}

int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    
	solve();
    return 0;
}


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

int X[1000000], Y[1000000];
int main() {
	int N, W, H; scanf("%d%d%d", &N, &W, &H);
	rep(i, N) {
		int x, y, w; scanf("%d%d%d", &x, &y, &w);
		X[max(0, x - w)]++; X[x + w]--;
		Y[max(0, y - w)]++; Y[y + w]--;
	}
	bool flag = true;
	rep(i, W) {
		if (i)X[i] += X[i - 1];
		if (!X[i]) {
			flag = false;
			break;
		}
	}
	if (!flag) {
		flag = true;
		rep(i, H) {
			if (i)Y[i] += Y[i - 1];
			if (!Y[i]) {
				flag = false;
				break;
			}
		}
	}
	puts(flag ? "Yes" : "No");
}

Measured memory_bytes: 4700
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
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; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    int A,B;cin >> A >> B;
    int ans = A*B;
    if(ans % 2 == 1)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

from collections import deque

def main():
	n,c=MI()

	li=[[0]*c for _ in range(10**5+1)]
	#print(li)

	for _ in range(n):
		s,t,cc=MI()
		for i in range(s-1,t):
			li[i][cc-1]=1

	ans=0

	for A in li:
		ans=max(ans,sum(A))
	print(ans)









if __name__ == "__main__":
	main()


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>bool chmin(T&a,const T&b){return a>b?(a=b,1):0;}
template<class T>bool chmax(T&a,const T&b){return a<b?(a=b,1):0;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 100000 + 10;
int A[MAX_N];
int B[MAX_N];
int C[MAX_N];

ll b[MAX_N];
ll bb[MAX_N];

int main2() {
  int N = nextInt();
  REP(i, N) A[i] = nextInt();
  REP(i, N) B[i] = nextInt();
  REP(i, N) C[i] = nextInt();
  sort(A, A + N);
  sort(B, B + N);
  sort(C, C + N);

  bb[0] = 0;
  REP(i, N) {
    b[i] = lower_bound(A, A+N, B[i]) - A;
    bb[i+1] = bb[i] + b[i];
  }
  // pv(b, b + N);
  // pv(bb, bb + N + 1);
  ll ans = 0;
  REP(i, N) {
    int pos = lower_bound(B, B+N, C[i]) - B;
    ans += bb[pos];
  }
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}



Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  int left = a + b;
  int right = c + d;
 
  if (left == right) {
    cout << "Balanced" << endl;
  } else if (left > right) {
    cout << "Left" << endl;
  } else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define POINT 100
int main(){
    int W,H,N;
    int x[POINT],y[POINT],a[POINT];
    int x_start,x_end,y_start,y_end;
    int x_len,y_len;

    cin>>W>>H>>N;
    x_start=y_start=0;
    x_end=W,y_end=H;

    for(int i=0;i<N;i++){
        cin>>x[i]>>y[i]>>a[i];
        switch(a[i]){
            case 1:
                if(x_start<x[i]){
                    x_start=x[i];
                }
                break;
            case 2:
                if(x_end>x[i]){
                    x_end=x[i];
                }
                break;
            case 3:
                if(y_start<y[i]){
                    y_start=y[i];
                }
                break;
            case 4:
                if(y_end>y[i]){
                    y_end=y[i];
                }
                break;
            default:
                break;
        }
    }
    x_len=x_end-x_start;
    y_len=y_end-y_start;
    if(x_len<=0||y_len<=0){
        cout<<0<<endl;
    }else{
        cout<<x_len*y_len<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(ll (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000

using namespace std;

string s[50];

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

	cout << 0 << endl;
	cin >> s[0];
	int count = 0;
	int badyo = (n+2)/2-1;
	int waru = 2;
	int tansaku = (n+1) / 2-1;
	while (s[count] != "Vacant") {
		count ++;
		waru = waru * 2;
		cout << badyo << endl;
		cin >> s[count];
		if (s[count] == "Vacant")break;
		tansaku = (tansaku) / 2 + (tansaku) % 2;
		if (tansaku ==1) tansaku = 1;

		if (badyo % 2 == 0 && s[count] == s[0])badyo += tansaku;
		else if (badyo % 2 == 0 && s[count] != s[0])badyo -= tansaku;
		else if (badyo % 2 == 1 && s[count] == s[0])badyo -= tansaku;
		else if (badyo % 2 == 1 && s[count] != s[0])badyo += tansaku;
	}

	return 0;
}

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

int main() {
  int a,b,c;
  cin >> a;
  cin >> b;
  cin >> c;
  if (a==c && b!=a){
    cout << "Yes";
  } else if (a==b && a!=c ) {
    cout << "Yes";
  } else if (b==c && b!=a ){
    cout << "Yes";
  }else{
    cout << "No";
  }
  
	return 0;
  
}


Measured memory_bytes: 3644
N,A,B = map(int, input().split())

def sumQ5(num):
    ret = 0
    for s in str(num):
        ret += int(s)
    return ret
ret = 0
for i in range(N+1):
    total = sumQ5(i)
    if A<=total and total<=B:
        ret += i
print(ret)

Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,c) x = max(x,c)
#define mins(x,c) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("0"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}

const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;



int main() {
  int n, m;
  scanf("%d%d",&n,&m);
  vi x(n), c(n,1);
  x[0] = 1;
  rep(i,m) {
    int a, b;
    scanf("%d%d",&a,&b);
    --a; --b;
    if (x[a]) x[b] = 1;
    c[a]--; c[b]++;
    if (c[a] == 0) x[a] = 0;
  }
  int ans = 0;
  rep(i,n) ans += x[i];
  cout<<ans<<endl;
  return 0;
}







Measured memory_bytes: 1024
#include <stdio.h>

int main()
{
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    if(a>c)
        printf("NO\n");
    else if(b>=(c-a))
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}


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

using namespace std;
using i64 = int64_t;

int main(){
    int n;
    cin >> n;
    vector<i64> b(n-1);
    for(auto&& x:b)cin >> x;
    vector<i64> a(n);
    i64 ret = 0;
    a[0] = b[0];
    for(int i=0;i<n-1;i++){
        a[i] = min(a[i], b[i]);
        a[i+1] = max(a[i+1], b[i]);
    }
    for(auto&& x:a)ret += x;
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)	for(int i=0;i<n;i++)
typedef long long ll;
int main(){
	int h,w,n;	cin>>h>>w>>n;
	map<int,map<int,int>> list;
	rep(i,n){
		int a,b;	cin>>a>>b;
		for(int x=-1;x<2;x++){
			for(int y=-1;y<2;y++){
				if(a+x<=1||h<=a+x)	continue;
				if(b+y<=1||w<=b+y)	continue;
				list[a+x][b+y]++;
			}
		}
	}
	ll ret=(ll)(h-2)*(w-2);
	for(auto i:list){
		ret-=i.second.size();
	}
	cout<<ret<<endl;
	for(int j=1;j<10;j++){
		ret=0;
		for(auto a:list){
			for(auto b:a.second){
				if(list[a.first][b.first]==j)	ret++;
			}
		}
		cout<<ret<<endl;
	}
	return 0;
}


Measured memory_bytes: 70528
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define erep(i,a,b) for(int i=a;i<=(int)(b);i++)
#define per(i,a,b) for(int i=(b)-1;i>(a);i--)
#define eper(i,a,b) for(int i=((int)(a));i>=b;i--)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}

map<char, int> m;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    for (char s = 'a'; s <= 'z'; s++) m[s] = 0;
    char c;
    while (cin >> c) {
        for (char s = 'a'; s <= 'z'; s++) {
            if (s == tolower(c))
              m[tolower(c)]++;
        }
    }
    for (map<char, int>::iterator itr = m.begin(); itr != m.end(); itr++) {
        printf("%c : %d\n", itr->first, itr->second);
    }
    return 0;
}


Measured memory_bytes: 3208
// G++ MACRO.CPP -STD=C++17
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
 
#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
 
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
 
#define FOREACH(x,a) for(auto& (x) : (a) )
 
#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])
 
#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl
 
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}
 
#define ALL(obj) (obj).begin(),(obj).end()
 
#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
 
template <class T = ll>
T IN(){T x;cin>>x;return (x);}
 
template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}
 
template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}
 
#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc
 
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int
 
#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>
 
#define pb(a) push_back(a)
#define mp make_pair
 
int main(){
  CIN(n,m);
  VC2(n,a,b);VC2(m,c,d);
 
  REP(i,n){
    ll num = 0;
    ll dist = LINF;
    REP(j,m){
      if(dist > abs(a[i]-c[j]) + abs(b[i]-d[j])){
        dist = abs(a[i]-c[j]) + abs(d[j]-b[i]);
        num = j+1;
      }
    }
    COUT(num);
 
  }
 
  return 0;
}

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


using namespace std;

#define ll long long int

int main(){
    ll n, k; cin >> n >> k;
    if(k >n ) {
        cout<< 0 << endl;
        return 0;
    }
    vector<ll> v(n);
    for(ll i=0; i<n ;i++) scanf("%lli", &v[i]);
    sort(v.begin(), v.end());

   // for(ll i=0; i<n ;i++) cout << v[i] << " " ;
    // cout << endl;
    ll ans = 0;

    for(int i=0; i< n -k ; i++) ans += v[i];
        

        
    
    

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

Measured memory_bytes: 1792
H,N=map(int,input().split())
A=[0]*N
B=[0]*N
for i in range(N):
  A[i],B[i]=map(int,input().split())
dp = [99999999999]*(H+1)
dp[0]=0
for h in range(H):
  for i in range(N):
    dp[min(H,h+A[i])]=min(dp[h] + B[i], dp[min(H,h+A[i])])
print(dp[-1])

Measured memory_bytes: 73996
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        TreeMap<Long, Long> map = new TreeMap<>();
        for(int i = 0; i < n; i++) {
            long a = sc.nextLong();
            long b = sc.nextLong();
            map.put(a, map.getOrDefault(a, 0L) + b);
        }
        long minYen = 0;
        for(long yen: map.keySet()) {
            long amount = map.get(yen);
            if(amount < m) {
                minYen += (amount * yen);
                m -= amount;
            } else {
                minYen += (m * yen);
                break;
            }
        }
        System.out.println(minYen);
    }
}


Measured memory_bytes: 91788
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
const int INF=1001001001;

int main() {
  int D;
  cin>>D;
  if(D==25){cout<<"Christmas"<<endl;}
  if(D==24){cout<<"Christmas Eve"<<endl;}
  if(D==23){cout<<"Christmas Eve Eve"<<endl;}
  if(D==22){cout<<"Christmas Eve Eve Eve"<<endl;}
  return 0;
}

Measured memory_bytes: 3552
N,A,B = map(int,input().split())
if A+B-1>N or N>A*B:
    print(-1)
else:
    G = {i:[] for i in range(1,A+1)}
    i = A
    cnt = 0
    cur = N
    while cur>A:
        G[i].append(cur)
        cnt += 1
        cur -= 1
        if cnt==B-1:
            cnt = 0
            i -= 1
    C = []
    for i in range(1,A+1):
        C += G[i]
        C.append(i)
    print(*C)

Measured memory_bytes: 126200
# coding: utf-8
import sys

# from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
printout = sys.stdout.write
sprint = sys.stdout.flush
# from heapq import heappop, heappush
# from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
# import math
# from itertools import product, accumulate, combinations, product
# import bisect
# import numpy as np
# from copy import deepcopy
#from collections import deque
# from decimal import Decimal
# from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 998244353


def intread():
    return int(sysread())
def mapline(t=int):
    return map(t, sysread().split())
def mapread(t=int):
    return map(t, read().split())

def next_val(An, M):
    return (An * An) % M

def run():
    N, X, M = mapline()
    arr = [X]
    valset = {}
    valset[X] = 0
    while True:
        an = arr[-1]
        next_a = next_val(an, M)
        if not next_a in valset.keys():
            arr.append(next_a)
            valset[next_a] = len(arr) - 1
        else:
            break
    idx1 = valset[next_a]
    K = len(arr)
    ans = 0
    if N > idx1:
        ans += sum(arr[:idx1])
    else:
        ans += sum(arr[:N])
        print(ans)
        return

    N -= idx1
    l = K - idx1
    sums = sum(arr[idx1:])
    cycle = N // l
    ans += sums * cycle
    N %= l
    ans += sum(arr[idx1:idx1+N])
    print(ans)






if __name__ == "__main__":
    run()


Measured memory_bytes: 15804
#include <bits/stdc++.h>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define N 1010
#define pb push_back
#define fi first
#define se second
#define si size()
#define ll long long
#define mp make_pair
#define iter ::iterator
#define all(v) v.begin(), v.end()
#define READ(f) freopen (f, "r", stdin)
#define WRITE(f) freopen (f, "w", stdout)
#define pp pop_back
#define mapiter map<int, int>::iterator
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forn1(i, n) for(int i = 1; i <= n; ++i)
#define forr(i, n) for(int i = n - 1; i >= 0; --i)
#define forr1(i, n)	for(int i = n; i >= 1; --i)
#define barnarnar ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define elif else if
#define lld long double
#define r0 return 0
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define db(x) cerr << #x << ": " << x << endl;

const int inf = 2e9; 
const ll infl = 2e17;
const ll modw = 998244353ll;
 
const ll mods[2] = {1000000009ll, 1000000007ll};
const ll pp[2] = {31, 53};
const int K = 355;

using namespace std;
using namespace __gnu_pbds;



int main()
{
	barnarnar
	string t;
	cin >> t;
	if(t[t.si - 1] == 'e' || t[t.si - 1] != 's')	cout << t + "s";
	else	cout << t + "es";
	r0;
}
// #_# ok



Measured memory_bytes: 3596
s=input() 
ans=0
for i in range(0,len(s),2):
  if s[i]!='R' and s[i]!='U'  and s[i]!='D':
    ans=1
for j in range(1,len(s),2):
  if s[j]!='U' and s[j]!='L' and s[j]!='D':
    ans=1
if ans==0:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 8792
#include <iostream>
#define MAX 1000000001
using namespace std;

int sum;
void merge(int A[],int left,int mid,int right)
{
    int L[mid-left+1],R[right-mid+1];
    for(int i=0;i<mid-left;i++)
        L[i]=A[left+i];
    L[mid-left]=MAX;
    for(int i=0;i<right-mid;i++)
        R[i]=A[mid+i];
    R[right-mid]=MAX;
    int L_index=0,R_index=0;
    for(int i=left;i<right;i++)
    {
        if(L[L_index]<=R[R_index])
        {
            A[i]=L[L_index];
            L_index++;
        }
        else{
            A[i]=R[R_index];
            R_index++;
        }
        sum++;
    }
}
void mergeSort(int A[],int left,int right){
    if(left+1<right)
    {
        int mid=(left+right)/2;
        mergeSort(A,left,mid);
        mergeSort(A,mid,right);
        merge(A,left,mid,right);
    }
}
int main()
{
    int n,A[500000];
    sum=0;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>A[i];
    mergeSort(A,0,n);
    int isn=0;
    for(int i=0;i<n;i++)
    {
        if(isn++>0)
            cout<<" ";
        cout<<A[i];
    }
    cout<<endl;
    cout<<sum<<endl;
    return 0;
}


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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define FOR(i,m,n) for(int i=(m) ; i<(n) ; i++)
#define FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)

#define All(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1e9;

int main(){
   string o,e;
   cin >> o >> e;
   int s = o.size();
   for(int i=0;i<s;i++){
         cout << o[i];
         if(i < e.size())cout << e[i];
   }
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

int A[200010];

int main() {
	int N;
	cin >> N;
	for(int i=0; i<N; ++i) cin >> A[i];
	sort(A, A+N);
	for(int i=1; i<N; ++i){
		if(A[i-1]==A[i]){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 1024