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

int main() {
  int A,B,C,K;
  cin >> A >> B >> C >> K;
  
  if (K <= A){
    cout << K << endl;
  }
  else if (K <= A + B){
    cout << A << endl;
  }
  else {
    cout << A - K + A + B << endl;
  }
}
 

Measured memory_bytes: 3612
#include <iostream>
#include <iomanip>
//#include <string>
//#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
#include <math.h>
using namespace std ;
using ll = long long ;
using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	fix_cout() ;
	ll a,b,h,m ;
	cin >> a >> b >> h >> m ;
	ld d = h*30.0+m*0.5 ;
	ld e = m*6.0 ;
	ld f = abs(d-e) ;
//	cout << d << " " << e << endl ;
	f = min(f,360-f) ;
	if(f==0){
		cout << abs((ld)a-b) << endl ;
		return 0 ;
	}
	if(f==180){
		cout << a+b << endl ;
		return 0 ;
	}
	f = acos(-1)*f/180 ;
	cout << sqrt(a*a+b*b-2*a*b*cos(f)) << endl ;
}


Measured memory_bytes: 4160
#include <iostream>
using namespace std;
int main(){
    int t,n,s,f,sum=0;
    while(1){
        cin>>t;
        if(t==0){
            break;
        }cin>>n;
        for(int i=0;i<n;i++){
            cin>>s>>f;
            sum+=f-s;
        }
        if(sum>=t){
            cout<<"OK"<<endl;
        }
        else{
            cout<<t-sum<<endl;
        }
        sum=0;
    }
    return 0;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define lli long long int
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF 9223372036854775807+1

int main() {
  int N;
  cin >> N;
  if(0<=N && N<=99)
    cout << 0<< endl;
  
    else if(106<=N &&N<=199)
    cout << 0<< endl;
    else if(211<=N &&N<=299)
    cout << 0<< endl;
    else if(316<=N &&N<=399)
    cout << 0<< endl;
    else if(421<=N &&N<=499)
    cout << 0<< endl;
    else if(526<=N &&N<=599)
    cout << 0<< endl;
    else if(631<=N &&N<=699)
    cout << 0<< endl;
    else if(736<=N &&N<=799)
    cout << 0<< endl;
    else if(841<=N &&N<=899)
    cout << 0<< endl;
    else if(946<=N &&N<=999)
    cout << 0<< endl;
    else if(1051<=N &&N<=1099)
    cout << 0<< endl;
    else if(1156<=N &&N<=1199)
    cout << 0<< endl;
    else if(1261<=N &&N<=1299)
    cout << 0<< endl;
    else if(1366<=N &&N<=1399)
    cout << 0<< endl;
    else if(1471<=N &&N<=1499)
    cout << 0<< endl;
    else if(1576<=N &&N<=1599)
    cout << 0<< endl;
    else if(1681<=N &&N<=1699)
    cout << 0<< endl;
    else if(1786<=N &&N<=1799)
    cout << 0<< endl;
    else if(1891<=N &&N<=1899)
    cout << 0<< endl;
    else if(1996<=N &&N<=1999)
    cout << 0<< endl;
    else 
    cout << 1<< endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
int main(){
    int n,m,c;
    cin >> n >> m >> c;
    int b[m];
    for(int i = 0;i<m;i++){
        cin >> b[i];
    }
    int a[m];
    int ans = 0;
    int p;
    for(int i = 0;i<n;i++){
        p = 0;
        for(int j = 0;j<m;j++){
            cin >> a[j];
        }
        for(int j = 0;j<m;j++){
            p = p + a[j]*b[j];
        }
        if(p + c > 0){
            ans++;
        }
    }
    cout << ans << endl;
}

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

class C7{
  struct Node{
    internal int left;
    internal int right;
  }

  static void Main(){
    int n = int.Parse(Console.ReadLine());

    Node[] nodes = new Node[n];
    bool[] child = new bool[n];

    for(int i = 0;i < n;i++){
      int[] input = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);

      nodes[input[0]].left = input[1];
      nodes[input[0]].right = input[2];

      if(input[1] != -1) child[input[1]] = true;
      if(input[2] != -1) child[input[2]] = true;
    }

    int root = Array.IndexOf(child,false);

    StringBuilder sb = new StringBuilder();
    sb.AppendLine("Preorder");
    Preorder(nodes,root,sb);
    Console.WriteLine(sb);

    sb = new StringBuilder();
    sb.AppendLine("Inorder");
    Inorder(nodes,root,sb);
    Console.WriteLine(sb);

    sb = new StringBuilder();
    sb.AppendLine("Postorder");
    Postorder(nodes,root,sb);
    Console.WriteLine(sb);
  }

  static void Preorder(Node[] nodes,int x,StringBuilder sb){
    if(x == -1) return;

    sb.Append(" " + x);
    Preorder(nodes,nodes[x].left,sb);
    Preorder(nodes,nodes[x].right,sb);
  }

  static void Inorder(Node[] nodes,int x,StringBuilder sb){
    if(x == -1) return;

    Inorder(nodes,nodes[x].left,sb);
    sb.Append(" " + x);
    Inorder(nodes,nodes[x].right,sb);
  }

  static void Postorder(Node[] nodes,int x,StringBuilder sb){
    if(x == -1) return;

    Postorder(nodes,nodes[x].left,sb);
    Postorder(nodes,nodes[x].right,sb);
    sb.Append(" " + x);
  }
}


Measured memory_bytes: 17904
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000

const int MAXN = 10010;
int N, A[MAXN], B[MAXN];

int main() {
  int i;
  double t;
  scanf("%d", &N);
  for(i = 1; i <= N; i++) scanf("%d", &A[i]);
  for(i = 1; i <= N; i++) scanf("%d", &B[i]);

  ll canDec = 0, toDec = 0;
  for(i = 1; i <= N; i++) {
    t = A[i] - B[i];
    if(t < 0) canDec += (-t) / 2;
    if(t > 0) toDec += t;
  }
  printf(toDec <= canDec ? "Yes" : "No");
  cout<<endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
using namespace std;
int n, m, ans, a, b;
int t[100005];
int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> t[i];
        ans += t[i];
    }
    cin >> m;
    for(int i = 1; i <= m; i++){
        cin >> a >> b;

        cout << ans - t[a] + b << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX 100005
int main()
{ 
	int n,a[MAX];
	int Max=0,MH=0,NMH=0,h=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		Max=max(Max,a[i]);
	}
	MH=(Max+1)/2;
	for(int i=0;i<n-1;i++)
	{
	if(MH>a[i]&&a[i]>h)
	{
		NMH=a[i];
		h=a[i];
	}
	else if(MH<=a[i]&&Max-a[i]>h)
	{
		NMH=a[i];
		h=Max-a[i];
	}
	}
	printf("%d %d",Max,NMH);
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>

int main() {
  int n, i, j;
  int c = 0;
  int temp;
  int *A;

  scanf("%d", &n);
  A = malloc(n*sizeof(int));
  for(i = 0; i < n; i++) {
    scanf("%d", &A[i]);
  }

  for(i = 0; i < n; i++) {
    for(j = n-1; j > i; j--) {
      if(A[j-1] > A[j]) {
	temp = A[j];
	A[j] = A[j-1];
	A[j-1] = temp;
	c++;
      }
    }
  }

  for(i = 0; i < n; i++) {
    printf("%d", A[i]);
    if(i != n-1) {
      printf(" ");
    }
  }
  printf("\n%d\n", c);

  return 0;
}

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

int main()
{
  int i;
  string S, a[4];
  cin >> S;

  if(S[0] == S[1] && S[2] == S[3] && S[0] == S[2]){
    cout << "No" << endl;
  }else if(S[0] == S[1] && S[2] == S[3]){
    cout << "Yes" << endl;
  }else if(S[0] == S[2] && S[1] == S[3]){
    cout << "Yes" << endl;
  }else if(S[0] == S[3] && S[1] == S[2]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}


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

#define N 8
#define FREE -1
#define NOT_FREE 1

int row[N], col[N], dpos[2*N-1], dneg[2*N-1];

bool X[N][N];

void initialize(){
    for(int i=0; i<N; i++) row[i]=FREE, col[i]=FREE;
    for(int i=0; i<2*N-1; i++) dpos[i]=FREE, dneg[i]=FREE;
}

void printBoard(){
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            if(X[i][j]){
                if(row[i] != j) return;
            }
        }
    }
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            cout << ((row[i] == j)? "Q" : ".");
        }
        cout << endl;
    }
}

void recursive(int i){
    if(i == N){
        printBoard(); return;
    }

    for(int j=0; j<N; j++){
        //(i, j)がほかのクイーンに襲撃されている場合は無視
        if( NOT_FREE == col[j] ||
            NOT_FREE == dpos[i+j] ||
            NOT_FREE == dneg[i-j+N-1]) continue;
        //(i, j)にクイーンを配置する
        row[i] = j; col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;
        //次の行を試す
        recursive(i+1);
        //(i, j)に配置されているクイーンを取り除く
        row[i] = col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
    }
    //クイーンの配置に失敗
}

int main(){
    initialize();

    for(int i=0; i<N; i++)
        for(int j=0; j<N; j++) X[i][j] = false;
    
    int k; cin >> k;
    for(int i=0; i<k; i++){
        int r, c; cin >> r >> c;
        X[r][c] = true;
    }

    recursive(0);

    return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int a, b, c;
    cin >> a >> b >> c;

    int t = a;
    while(t <= 100000) {
        if(t % b == c) {
            cout << "YES" << endl;
            return 0;

        }
        t += a;
    }
    cout << "NO" << endl;
    return 0;
}



Measured memory_bytes: 256
import sys
import math
import collections
import itertools
import array
import inspect
import pprint

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# Set 2 dimension list
def dim2input(N):
    li = []
    for _ in range(N):
        li.append(list(map(int, input())))
    return li

""" input template
S = input()
N = int(input())
L = list(map(int, input().split()))
a, b = list(map(int, input().split()))
SL = list(input())
"""

# --------------------------------------------

def main():
    delta_x = [-1, 0, 0, 1]
    delta_y = [0, -1, 1, 0]

    H, W = list(map(int, input().split()))

    S = []
    for _ in range(H):
        S.append(list(input()))

    S[0][0] = 0

    reached = [[0, 0]]
    move = 1

    while len(reached) != 0:
        new_reached = []

        for r in reached:
            for dx, dy in zip(delta_x, delta_y):
                new_y = r[0] + dy
                new_x = r[1] + dx

                if not (0 <= new_y < H):
                    continue

                if not(0 <= new_x < W):
                    continue

                if S[new_y][new_x] == ".":
                    S[new_y][new_x] = move
                    new_reached.append([new_y, new_x])

        move += 1
        reached = new_reached

    if S[-1][-1] == "." or S[-1][-1] == "#":
        print(-1)
        return


    i = H-1
    j = W-1
    while True:
        current = S[i][j]

        if current == 0:
            break
        S[i][j] = "#"


        for dx, dy in zip(delta_x, delta_y):
            new_y = i + dy
            new_x = j + dx

            if not (0 <= new_y < H):
                continue

            if not(0 <= new_x < W):
                continue

            if S[new_y][new_x] == current - 1:
                i = new_y
                j = new_x
                break

    S[0][0] = "#"

    point = 0
    for row in S:
        for cell in row:
            if isinstance(cell, int) or cell == ".":
                point += 1

    print(point)





main()


Measured memory_bytes: 4676
#include<bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 13;
int n, ans, val[maxN][50 + 13];
vector<int> adj[maxN];
void dfs (int x, int par) {
    for (auto a : adj[x]) {
	if (a != par) {
	    dfs(a, x);
	    for (int i = 0; i <= 50; i++)
		val[x][i] += val[a][i];
	}
    }
    int cur = 0;
    for (int i = 0; i <= 50; i++) {
	//cout << x << " " << i << " " << val[x][i] << endl;
	if (val[x][i] >= 2)
	    cur = i + 1;
    }
    while (val[x][cur])
	cur++;
    ans = max(ans, cur);
    for (int i = 0; i < cur; i++)
	val[x][i] = 0;
    //cout << x << " " << cur << endl;
    val[x][cur] = 1;
}

int main () {
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
	int a, b;
	cin >> a >> b;
	adj[a].push_back(b);
	adj[b].push_back(a);
    }

    dfs(1, 1);
    cout << ans << endl;
}


Measured memory_bytes: 35968
#include <stdio.h>

void swap(int *i,int *j){
	int k;
	k=*i;
	*i=*j;
	*j=k;
}

int main (){
	int i,x=0,y=0,z=0,u;
	for(i=0;i<10;i++){
		scanf("%d",&u);
		if(u>x)swap(&x,&u);
		if(u>y)swap(&y,&u);
		if(u>z)swap(&z,&u);
	}
	printf("%d\n%d\n%d\n",x,y,z);
	return 0;
}

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

using namespace std;

int main(void)
{
    long long int N;
    stack<char> buff;
    cin >> N;
    
    while(N != 0){
        int q = --N % 26;
        
        buff.push((char)('a' + q));
        N /= 26;
    }
    while(!buff.empty()){
        cout << buff.top();
        buff.pop();
    }
    cout << endl;
    cout << endl;
    return 0;
}

Measured memory_bytes: 3608
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long LL;
#define M(a,b) memset(a,b,sizeof(a))
#define pb push_back
const int maxn = 100000+10;
const LL mod = 1000000007;
char s[maxn<<1];
int main() {

    scanf("%s",s);
    int l=maxn<<1,r=0;
    for (int i=0;s[i];++i) {
        if (s[i]=='A'&&l>i) {
            l=i;
        }
        if (s[i]=='Z'&&r<i) {
            r=i;
        }
    }
    printf("%d\n",l<=r?r-l+1:0);
    return 0;
}

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

using namespace std;

int main() {
    int N; 
    cin >> N;
    
    vector<long long int> d(N);
    for(int n=0; n<N; n++) {
        cin >> d[n];
    }
    
    long long int sum=0;
    for(int n1=0; n1<N-1; n1++) {
        for(int n2=n1+1; n2<N; n2++) {
            sum += d[n1]*d[n2];
        }
    }
    
    cout << sum << endl;

    return 0;
    
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n;
    scanf("%d", &n);
    int i;
    for(i=0;i<=(int)(n/7);i++)
        if ((n - (7 * i)) % 4 == 0)
        {
            printf("Yes\n");
            return 0;
        }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli > plli;
typedef vector<lli> vlli;
typedef vector<plli > vplli;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define lcm(a, b) ((a * b) / gcd(a, b))
#define sqr(x) (x)*(x)
#define all(a) a.begin(),a.end()
#define UN(v) sort(all(v)), v.resize(unique(all(v))-v.begin())

#define endl '\n'

const long long INF = 100000000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;
const double PI = acos(-1);

lli dx[]={0,0,-1,1,-1,-1,1,1};
lli dy[]={1,-1,0,0,1,-1,-1,1};

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

void solve() {
    lli a, b, c;
    cin >> a >> b >> c;

    lli val = c - a - b;
    if (val * val > 4 * a * b and val > 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

int main()
{
    IOS;
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; i++) {
        //cout << "Case " << i << ": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);List<float[]>l=new Stack<float[]>(),r;Comparator<float[]>c=new Comparator<float[]>(){public int compare(float[]a,float[]b){return Float.compare(a[1],b[1]);}};for(int t=3,i;t--> 0;Collections.sort(r,c),p(r.get(0)),p(r.get(1)),l.addAll(r.subList(2,8)))for(r=new Stack<float[]>(),i=8;i-->0;)r.add(new float[]{s.nextInt(),s.nextFloat()});Collections.sort(l,c);p(l.get(0));p(l.get(1));}static void p(float[]f){System.out.printf("%.0f %.2f\n",f[0],f[1]);}}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int n;
  cin>>n;
  int t[n];
  REP(i,n){
    cin>>t[i];
  }
  int m;
  cin>>m;
  int p[m],x[m];
  REP(i,m){
    cin>>p[i]>>x[i];
  }
  
  int ans=0;
  REP(i,m){
    REP(j,n){
      if(j==(p[i]-1)){
        ans += x[i];
      }else{
        ans += t[j];
      }
    }
    cout<<ans<<endl;
    ans = 0;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    string S;
    cin >> S;
    ll N = S.size();

    map<ll, ll> cnt;
    for(ll i = 0; i < (1<<N-1); i++){
        ll t = 0, p = S[0] - '0';
        for(ll j = 0; j < N-1; j++){
            if(i & (1LL << j)){
                t += p;
                //cerr << p << "+";
                p = 0;
            }
            p *= 10;
            p += S[j+1] - '0';
        }
        t += p;
        //cerr << p << endl;
        cnt[t]++;
    }

    ll ans = 0;
    for(auto p : cnt) ans += p.first * p.second;
    cout << ans << endl;
    return 0;
}

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

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long long llong;
typedef long double ld;

using namespace std;

template <typename T> void dprint(T begin, T end) {
    for (auto i = begin; i != end; i++) {
        cerr << (*i) << " ";
    }
    cerr << "\n";
}

string s;

int main() {
    cin >> s;
    int ans = s.size();
    for (int i = 0; i < 26; ++i) {
        for (int j = 0; j < ans; ++j) {
            int lst = 0;
            int fl = 0;
            for (int k = 0; k < s.size(); ++k) {
                if (s[k] == 'a' + i) {
                    if (lst < k - j)
                        fl = 1;
                    lst = k + 1;
                }
            }
            if (fl == 0 && lst >= (int)s.size() - j)
                ans = min(ans, j);
        }
    }
    cout << ans << "\n";
    return 0;
}




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

using namespace std;

vector<long> vertex;

long root(long x) {
    if(vertex[x]<0){
        return x;
    }
    return vertex[x] = root(vertex[x]);
}

void unite(long x, long y) {
    x = root(x);
    y = root(y);

    if (x == y){
        return;
    }
    if(-vertex[x] < -vertex[y]){
        swap(x, y);
    }
    vertex[x] -= -vertex[y];
    vertex[y] = x;
}

bool same(long x, long y) {
    return root(x) == root(y);
}
long size(long x) {
    return -vertex[root(x)];
}


int main(){
    int N, M;
    cin>>N>>M;

    vector<long> A(M), B(M);
    for(int i=0; i<M; ++i){
        cin>>A[i]>>B[i];
    }

    vertex.resize(N+1, 0);
    for(int i=1; i<=N; ++i){
        vertex[i] = -1;
    }
    vector<long> ans(M, 0);
    ans[M-1] = 1;
    for(int i=0; i<M; ++i){
        unite(A[i], B[i]);
    }
    for(int i=0; i<N; ++i){
        if(vertex[i] < 0){
            ans[M-1] *= (-vertex[i])*(-vertex[i]-1)/2;
        }
    }

    vertex.resize(N+1, 0);
    for(int i=1; i<=N; ++i){
        vertex[i] = -1;
    }
    for(int i=M-1; i>0; --i){
        if(same(A[i], B[i])){
            ans[i-1] = ans[i];
        }else{
            ans[i-1] = ans[i] - size(A[i]) * size(B[i]);
            unite(A[i], B[i]);
        }
    }

    for(int i=0; i<M; ++i){
        cout<<ans[i]<<endl;
    }

    return 0;
}

Measured memory_bytes: 4480
def solve():
    data = read()
    result = think(data)
    write(result)


def read():
    return read_line()


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(data):
    odd = data[::2]
    even = data[1::2]

    return 'Yes' if odd.find('L') == -1 and even.find('R') == -1 else 'No'


def write(result):
    print(result)


if __name__ == '__main__':
    # import doctest
    # doctest.testmod()
    # import sys
    # sys.setrecursionlimit(10000)
    solve()

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// head

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

    ll n;
    cin >> n;
    cout << (n) * (n + 1) / 2 - n << endl;
    return 0;
}


Measured memory_bytes: 3556
N, M = [int(_) for _ in input().split()]
SC = [[int(_) for _ in input().split()] for _ in range(M)]
digit = [-1] * (N + 1)
ok = True
for s, c in SC:
    if digit[s] == -1:
        digit[s] = c
    elif digit[s] != c:
        ok = False
if N == 1 and digit[1] in [0, -1]:
    print(0)
    exit()
if digit[1] == 0:
    ok = False
for i in range(1, N + 1):
    if digit[i] == -1:
        digit[i] = 1 if i == 1 else 0
if ok:
    print(*digit[1:], sep='')
else:
    print(-1)


Measured memory_bytes: 38256
N=input()
S=input().split()
buf=-2
for n,i in enumerate(S):
  if i=="0":
    buf=0
if buf!=0:
  for n,i in enumerate(S):
    if n==0:
      buf=int(i)
    else:
      buf=buf*int(i)
    if buf>1000000000000000000:
      buf=-1
      break
print(buf)

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

using namespace std;

int n;

int main() {
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n);
    int repeats = 0;
    for (int i = 1; i < n; i++) {
        if (a[i] == a[i - 1]) {
            repeats++;
        }
    }
    int operations = (repeats + 1) / 2;
    cout << n - operations * 2 << endl;

    return 0;
}


Measured memory_bytes: 640
#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()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int h, w;
  cin >> h >> w;
  vector<string> v(h);
  rep(i,h) cin >> v[i];
  rep(i, h+2) {
    rep(j,w+2) {
      if (i == 0 || i == h+1 || j == 0 || j == w+1) cout << '#';
      else cout << v[i-1][j-1];
    }
    cout << endl;
  }
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 3656
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using VecVec = vector<Vec>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
template <typename T>
void co(const T n){cout << n << endl;}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << endl;}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); cout << endl;}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); cout << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;

int main(void){
	ll n, k;
	cin >> n >> k;
	string s;
	cin >> s;

	ll ans = 0;
	ll l = 0, r = 0, cnt = 0;
	while(r < n){
		if(s[r] == '1') chmax(ans, r-l+1);
		else if(s[r] == '0'){
			cnt++;
			while(s[r] == '0' && r < n) r++;
			if(r == n) r--;
			if(cnt > k){
				while(s[l] == '1') l++;
				while(s[l] == '0') l++;
				cnt--;
			}
			chmax(ans, r-l+1);
		}
		//co({l, r, cnt});
		r++;
	}
	co(ans);

	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(a,b) printf(a,b);
#define o(s) cout<< s << endl;
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
   string s; cin>>s;
   s.insert(4," ");
   cout<<s<<endl;
   
}


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

int x(int i){
      int k=0;

      while(i > 0){
            k+=i%10;
            i/=10;
      }
      return k;
}
              

int main(){
      int N,A,B;cin >> N >> A >> B;
      int ans=0;
      for(int i=1;i<=N;i++){
            int a = x(i);
            if(a >= A && a <= B)ans+=i;
      }
      cout << ans << endl;
}


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

int main(){
	
	int t1,t2;
	cin >> t1 >> t2;
	ll a1,a2;
	cin >> a1 >> a2;
	ll b1,b2;
	cin >> b1 >> b2;
	
	ll dist1 = (a1-b1)*t1; // not 0
	ll dist2 = (a2-b2)*t2; // not 0
	
	if(dist1 + dist2 == 0){
		cout << "infinity" << endl;
		return 0;
	}
	
	if(dist1>0){
		dist1 *= -1;
		dist2 *= -1;
	}
	
	if(dist1 + dist2 < 0){
		cout << 0 << endl;
		return 0;
	}
	
	
	ll amari = -dist1%(dist1+dist2);
	if(amari == 0){
		cout << -dist1/(dist1+dist2) * 2 << endl;
	}
	else{
		cout << -dist1/(dist1+dist2) * 2 + 1<< endl;
	}
	
	return 0;
}

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

int main() {
    //N種類の果物の中からK種類を選ぶ
    int N, K;
    cin >> N >> K;
    
    //N回入力を受ける
    vector<int> vec(N);
    for (int i=0; i<N; i++) {
        cin >> vec.at(i);
    }

    //受け取った配列を数が少ない順にソートする
    sort(vec.begin(), vec.end());

    //配列の0番目からK番目までを足し算する
    int answer = 0;
    for (int i=0; i<K; i++) {
        answer += vec.at(i);
    }

    cout << answer;
    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
int main(void){
    // Your code here!
  int a;
  int i;
  char moji[101];
  scanf("%d", &a);
  scanf("%s", &moji);
  if(strlen(moji) <= a){
    printf("%s",moji);
  }else{
    for(i = 0;i < a;i++){
  	  printf("%c", moji[i]);
    }
    printf("...");
  }
}


Measured memory_bytes: 1688
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"

vector<long long int>v;
map<pair<long long int,long long int>, int>mp;
int solve(long long int n,long long int from) {
	if (mp.find(make_pair(from,n)) == mp.end()) {
		
		{
			int ans = -1000;
			for (int i = 0; i <=from;++i){
				long long int a = v[i];
				if (n%a == 0) {
					if (a == n)ans = max(1, ans);
					else{

						ans = max(ans, 1 + solve(n / a,i));
					}
				}
			}
			mp[make_pair(from, n)] = ans;
		}
	}
	return mp[make_pair(from, n)];
}

int main() {
	long long int N; cin >> N;
	for (int i = 1; i <= 18; ++i) {
		for (int j = 0; j < (1 << i); ++j) {
			bitset<18>bs(j);
			long long int n = 0;
			for (int k = 0; k < i; ++k) {
				n *= 10;
				n += bs[i-k-1] ? 8 : 2;
			}
			v.emplace_back(n);
		}
	}
	int ans = solve(N,v.size()-1);
	if (ans < 0)ans = -1;
	cout << ans << endl;
	return 0;
} 

Measured memory_bytes: 7048
import numpy as np
N = int(input())
A = np.array([int(i) for i in input().split()])

minus = len(A[np.where(A < 0)])
abs_list = [abs(0-i) for i in A]
res = sum(abs_list)
if minus % 2 != 0:
    m = min(abs_list)
    res -= m * 2
print(res)

Measured memory_bytes: 23300
import collections
N = int(input())
A = list(map(int, input().split()))

sumA = [0]*(N+1)
table = collections.defaultdict(int)
table[0] += 1
for i in range(N):
    sumA[i+1] = sumA[i]+A[i]
    table[sumA[i+1]] += 1
ans = 0
table = table.values()
table = [x for x in table if x > 1]
for x in table:
    ans += x*(x-1)//2

print(ans)


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

N=int(input())
ARM=[list(map(int,input().split())) for i in range(N)]

OE=[(ARM[i][0]+ARM[i][1])%2 for i in range(N)]

if len(set(OE))==2:
    print(-1)
    sys.exit()

if OE[0]==1:
    
    m=38
    print(m)
    print(*[1<<i for i in range(m)])

    def URLD(x,y,m):
        
        if abs(x)>=abs(y):
            if x>=0:
                return "R",(x-(1<<m),y)
            else:
                return "L",(x+(1<<m),y)

        else:
            if y>=0:
                return "U",(x,y-(1<<m))
            else:
                return "D",(x,y+(1<<m))

    for x,y in ARM:
        ANS=[]
        for i in range(m-1,-1,-1):
            a,(x,y)=URLD(x,y,i)
            ANS.append(a)

        print("".join(ANS[::-1]))
        
else:

    m=39
    print(m)
    print(1,*[1<<i for i in range(m-1)])

    def URLD(x,y,m):
        
        if abs(x)>=abs(y):
            if x>=0:
                return "R",(x-(1<<m),y)
            else:
                return "L",(x+(1<<m),y)

        else:
            if y>=0:
                return "U",(x,y-(1<<m))
            else:
                return "D",(x,y+(1<<m))

    for x,y in ARM:
        ANS=[]
        for i in range(m-2,-1,-1):
            a,(x,y)=URLD(x,y,i)
            ANS.append(a)

        if x==1:
            ANS.append("R")
        elif x==-1:
            ANS.append("L")
        elif y==1:
            ANS.append("U")
        else:
            ANS.append("D")

        print("".join(ANS[::-1]))
    
            


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
char s[200002];
int L[200002], R[200002];
int dp[200002];
int main(){
    int n, k, c, l = 1;
    scanf("%d%d%d", &n, &k, &c);
    scanf("%s", s+1);

    int last = 0;
    for(int i=1;i<=n;i++){
        if(s[i] == 'x') continue;
        while(s[l] == 'x' || i-l > c){
            last = max(last, L[l]);
            l++;
        }
        L[i] = last+1;
    }

    l = n;
    last = 0;
    for(int i=n;i>=1;i--){
        if(s[i] == 'x') continue;
        while(s[l] == 'x' || l-i > c){
            last = max(last, R[l]);
            l--;
        }
        R[i] = last+1;
    }

    int ans = 0;
    for(int i=1;i<=n;i++){
        ans = max(ans, L[i]+R[i]);
    }

    if(ans-1 > k) return 0;

    for(int i=1;i<=n;i++){
        if(L[i]+R[i] == ans){
            dp[L[i]]++;
        }
    }
    for(int i=1;i<=n;i++){
        if(L[i]+R[i] == ans){
            if(dp[L[i]] == 1) printf("%d\n", i);
        }
    }
}

Measured memory_bytes: 4096
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int N;
	cin>>N;
	int res=0;
	if(N%1000==0)
	{
		cout<<res;
	}
	else
	{
		N=N%1000;
		res=1000-N;
		cout<<res;
	}
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define INFTY 1<<20
typedef long long int ll;
const int MOD=1000000007;
using Graph = vector<vector<int>>;
#define rep(i,n) for (int i = 0; i < (n); ++i)

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main(){
ll x;
cin>>x;
for (int i = -120; i < 120; i++)
{
  for (int j = -120; j < 120; j++)
  {
    if(pow(i,5)-pow(j,5)==x){
      printf("%d %d",i,j);
      return 0;
    }
  }
  
}

  return 0;
}

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

int main(){
  ll n; cin >>n;
  string ans = "";
  while(n>0){
    n--;
    ans += (n%26)+'a';
    n /= 26;
  }
  reverse(ans.begin(), ans.end());
  cout << ans << endl;
  return 0; 
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
using namespace std;

typedef long long ll;

// O(N*2^N)
ll mod = 1e9 + 7;
ll dp[(1 << 21) + 3];
bool a[23][23];

int main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
		}
	}
	dp[0] = 1;
	for (int s = 1; s < (1 << n); s++) {
		int i = -1;
		for (int j = 0; j < n; j++) i += (s >> j)&1;
		for (int j = 0; j < n; j++) {
			if (!((s >> j)&1)) continue;
			if (!a[i][j]) continue;
			dp[s] += dp[s&~(1 << j)];
			dp[s] %= mod;
		}
	}
	cout << dp[(1 << n) - 1] << endl;
	return 0;
}

Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define quick ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
int main()
{
	quick;
	double a,b,c;
	cin>>a>>b>>c;
	if(int(b/a)>c)
		cout<<c<<endl;
	else
		cout<<int(b/a)<<endl;
	return 0;
}
 

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $a);
fscanf(STDIN, "%d", $b);
fscanf(STDIN, "%d", $c);
fscanf(STDIN, "%d", $x);

$ans = 0;

for ($i=0; $i <$a+1 ; $i++) {
  // 500円
  for ($j=0; $j <$b+1 ; $j++) {
    // 100円
    for ($k=0; $k <$c+1 ; $k++) {
      // 50円
      if (500*$i + 100*$j + 50*$k ==$x) {
        $ans++;
      }
    }
  }
}
echo $ans;
?>


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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << (b - a == c - b ? "YES" : "NO") << endl; 
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;


const int BIG_NUM = 1e8;
const ll INF = 1000000000000000000;

const int ALPHABET = 26;

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


	cout << (1000 - n % 1000) % 1000 << endl;

}

Measured memory_bytes: 3604
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        int ans = (s.length() - s.replace("+", "").length()) -
                (s.length() - s.replace("-", "").length());

        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main()
{
	int i,j,a,c,b,s=0;
	cin>>a>>b;
	for(i=1;i<=b;i++)
	{
		cin>>c;
		s+=c;
	}
	if(s>=a)  cout<<"Yes";
	else cout<<"No";
 } 

Measured memory_bytes: 256
n = int(input())
nums = [int(i) for i in input().split()]
box = [-1] * n
for i in range(1, n + 1)[::-1]:
    c = i * 2
    ball = nums[i - 1]
    while c <= n:
        ball = ball ^ box[c - 1]
        c += i
    box[i - 1] = ball

ans = box.count(1)
print(ans)
ball = []
for i in range(n):
    if box[i] == 1:
        ball.append(i + 1)
print(*ball)


Measured memory_bytes: 14132
package main

import (
	"container/heap"
	"fmt"
	"os"
)

type S struct {
	A int
	B int
}

type IntHeap []int

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	// Push and Pop use pointer receivers because they modify the slice's length,
	// not just its contents.
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func main(){
	var N, M int
	fmt.Fscanf(os.Stdin, "%d %d", &N, &M)

	m := make(map[int][]int)
	for i := 0; i < N; i++ {
		var a, b int
		fmt.Fscanf(os.Stdin, "%d %d", &a, &b)
		m[a] = append(m[a], b)
	}

	total := 0
	h := &IntHeap{}
	heap.Init(h)
	for i := 1; i <= M; i++ {
		if _, ok := m[i]; ok {
			for _, v := range m[i] {
				heap.Push(h, v)
			}
		}
		
		if h.Len() > 0 {
			total += heap.Pop(h).(int)
		}
	}
	fmt.Println(total)
}


Measured memory_bytes: 12800
from collections import deque
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

def solve():
  h,w,d  = (int(i) for i in input().split())
  a = deque([])
  for i in range(h):
    tmp = list(int(i) for i in input().split())
    a.append(tmp)

  query = [False]*(h*w)
  distance = [0]*(h*w+1)
  for i in range(h):
    for j in range(w):
      query[a[i][j] - 1] = (i,j)
  q = int(input())
  
  for i in range(d,h*w):
    leftx,lefty = query[i-d]
    rightx,righty = query[i]
    distance[i] = distance[i-d]+abs(rightx-leftx)+abs(righty-lefty)
  #print(distance)
  ans = []
  for i in range(q):
    l,r = (int(m) for m in input().split())
    ans.append(distance[r-1]-distance[l-1])
  print("\n".join(map(str,ans)))
solve()

Measured memory_bytes: 29476
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
const Int MAX = 2e18;

void chmin(Int &a,Int b){if(a>b) a=b;}

Int dfs(Int a,Int b,Int t,Int f,Int u,Int k){
  Int res=1LL<<(t-k);
  if(u!=3) res--;
  chmin(res,MAX);
  return res;
}

void restore(Int n){
  //cout<<n<<":::"<<endl;
  Int k=1;
  for(;;k++){
    Int tmp=0;
    for(Int a=0;a<10;a++){
      for(Int b=a+1;b<10;b++){
	if(a!=0) tmp+=dfs(a,b,k,0,1,1); //use a
	tmp+=dfs(a,b,k,1,2,1);          //use b > 0
	chmin(tmp,MAX);
      }
    }
    if(tmp>n) break;
    n-=tmp;
  }
  // cout<<k<<endl;
  Int c,d;
  string ans;
  for(c=1;c<10;c++){
    Int tmp=0;
    for(Int a=0;a<c;a++){
      tmp+=dfs(a,c,k,1,2,1);
      chmin(tmp,MAX);
    }
    for(Int b=c+1;b<10;b++){
      tmp+=dfs(c,b,k,0,1,1);
      chmin(tmp,MAX);
    }
    if(tmp>n){
      ans+=char('0'+c);
      break;
    }
    n-=tmp;
  }
  //cout<<k<<" "<<c<<endl;
  Int l=k-1;
  while(l--){
    Int flg=0;
    for(d=0;d<c;d++){
      Int tmp=dfs(d,c,k,1,3,k-l);
      if(tmp>n){
	ans+=char('0'+d);
	flg=1;
	break;
      }
      n-=tmp;
    }
    if(flg) break;
    Int tmp=0;
    for(Int e=0;e<c;e++){
      tmp+=dfs(e,c,k,1,2,k-l);
      chmin(tmp,MAX);
    }
    for(Int e=c+1;e<10;e++){
      tmp+=dfs(c,e,k,0,1,k-l);
      chmin(tmp,MAX);
    }
    if(tmp>n){
      ans+=char('0'+c);
      continue;
    }
    n-=tmp;
    for(d=c+1;d<10;d++){
      Int tmp=dfs(c,d,k,0,3,k-l);
      if(tmp>n){
	ans+=char('0'+d);
	flg=1;
	break;
      }
      n-=tmp;
    }
    if(flg) break;
  }
  //cout<<c<<":"<<d<<endl;
  while(l--){
    if(c<d){
      Int tmp=dfs(c,d,k,0,3,k-l);
      if(tmp>n){
	ans+=char('0'+c);
      }else{	
	ans+=char('0'+d);
	n-=tmp;
      }
    }else{
      Int tmp=dfs(d,c,k,1,3,k-l);
      if(tmp>n){
	ans+=char('0'+d);
      }else{	
	ans+=char('0'+c);
	n-=tmp;
      }
    }
  }
  cout<<ans<<endl;
}
signed main(){
  Int n;
  while(cin>>n,n){
    restore(n-1);
  }
  return 0;
}



Measured memory_bytes: 3112
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
    private static FastScanner sc = new FastScanner();
    private static boolean DEBUG_FLG = false;

    public static void main(String[] args) {
    	int N = sc.nextInt();
    	char[] s = sc.next().toCharArray();
    	int red = 0;
    	int blue = 0;
    	for(int i=0; i<N; i++) {
    		if(s[i] == 'R') {
    			red++;
    		} else {
    			blue++;
    		}
    	}
    	if(red > blue) {
    		System.out.println("Yes");
    	} else {
    		System.out.println("No");
    	}
    }

    static void debug(long... args) {
    	if(!DEBUG_FLG) return;
    	boolean flg = false;
    	for(long s : args) {
    		if(flg) System.out.print(" ");
    		flg = true;
    		System.out.print(s);
    	}
    	System.out.println();
    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if(ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch(IOException e) {
                    e.printStackTrace();
                }
                if(buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}


Measured memory_bytes: 24660
#include <cstdio>
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <numeric>
#include <functional>

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
typedef long long ll;

int gcd(int x, int y) {
  if (x < y) return gcd(y, x);

  if (y == 0) {
    return x;
  } else {
    return gcd(y, x % y);
  }
}

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

  int x, y;

  cin >> x >> y;
  cout << gcd(x, y) << endl;
  
  return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstdio>

using namespace std;

const long long INF = 100000000;
const long long MOD = 1000000007;

std::vector<bool> IsPrime;

void sieve(size_t max)
{
  if (max + 1 > IsPrime.size())
  {                                // resizeで要素数が減らないように
    IsPrime.resize(max + 1, true); // IsPrimeに必要な要素数を確保
  }
  IsPrime[0] = false; // 0は素数ではない
  IsPrime[1] = false; // 1は素数ではない

  for (size_t i = 2; i * i <= max; ++i)     // 0からsqrt(max)まで調べる
    if (IsPrime[i])                         // iが素数ならば
      for (size_t j = 2; i * j <= max; ++j) // (max以下の)iの倍数は
        IsPrime[i * j] = false;             // 素数ではない
}

class Pointer{
public:
  long long p;
  long long w;
};

int main()
{
  long long N;
  cin >> N;
  long long ans = 0;
  for (int i = 0; i < N; i++)
  {
    long long l, r;
    cin >> l >> r;
    ans+=(r - l + 1);
  }
  cout <<ans<< endl;

}


Measured memory_bytes: 256