akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,M=MI()
    A=LI()
    B=[0]*M
    C=[0]*M
    for i in range(M):
        B[i],C[i]=MI()
    
    C,B=zip(*sorted(zip(C,B)))
    B=B[::-1]
    C=C[::-1]
    
    import heapq
    heapq.heapify(A)
    
    for i in range(M):
        b=B[i]
        c=C[i]
        for _ in range(b):
            a=heapq.heappop(A)
            if a>=c:
                heapq.heappush(A,a)
                break
            else:
                heapq.heappush(A,c)
                
    ans=0
    for i in range(N):
        a=heapq.heappop(A)
        ans+=a
        
    print(ans)

main()


Measured memory_bytes: 102672
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int m=0,n,aa[110000],a,b,cnt=1000;
pair<int,int> p[220000];
string s,ss[220000];
char c;
signed main(){
    cin>>n;
    rep(i,n){
        cin>>aa[i];
        while(1){
            if(aa[i]%2==1){
                cnt=min(cnt,m);
                break;
            }
            m++;
            aa[i]/=2;
        }
        m=0;
    }
    cout<<cnt;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
const int maxn=50;
const long long maxl=1000000000;
long long sx=maxl+1,bx=-maxl-1,sy=maxl+1,by=-maxl-1;
long long x[maxn+1],y[maxn+1];
int n,k;
long long ans=(maxl*2+1)*(maxl*2+1);
long long xmin,ymin,xmax,ymax;
bool judge(){
	int cnt=0;
	for(int i=1;i<=n;++i){
		if(xmin<=x[i]&&x[i]<=xmax&&ymin<=y[i]&&y[i]<=ymax)
			++cnt;
		if(cnt>=k)return true;
	}
	return false;
}
int main(int argc,char *argv[]){
	if(argc>=2){freopen(argv[1],"r",stdin);}
	if(argc>=3){freopen(argv[2],"w",stdout);}
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;++i)scanf("%lld%lld",&x[i],&y[i]);
	for(int i=1;i<=n;++i)
	for(int j=i;j<=n;++j)
	for(int k=j;k<=n;++k)
	for(int l=k;l<=n;++l){
		xmin=min(min(x[i],x[j]),min(x[k],x[l]));
		ymin=min(min(y[i],y[j]),min(y[k],y[l]));
		xmax=max(max(x[i],x[j]),max(x[k],x[l]));
		ymax=max(max(y[i],y[j]),max(y[k],y[l]));
		long long mianji=(xmax-xmin)*(ymax-ymin);
		if(mianji>=ans)continue;
		if(judge())ans=mianji;
		//printf("here\n");
	}
			
	printf("%lld",ans);
	fclose(stdin);fclose(stdout);
	return 0;
}


Measured memory_bytes: 256
import numpy as np

N = int(input())
A_s = []
for i in range(N):
  A_s.append(int(input()))
  
A_s = np.array(A_s)
  
m_index = A_s.argmax()
sort_A_s = sorted(A_s)
m_value = A_s[m_index]
m_second = sort_A_s[N-2]

for i in range(N):
  if i != m_index:
    print(m_value)
  else:
    print(m_second)

Measured memory_bytes: 24192
#include<cmath>
#include<stdio.h>
#include<algorithm>
#define ll long long
using namespace std;
const int N=1000100;
inline ll read(){
	ll x=0,f=0,c=getchar();
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';c=getchar())
	x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
int l,x,y;ll ans;
int main(){
	l=read();ans=read();read();
	x=read();y=read();read();read();
	//ans+=l/2*2;l%=2;
	//ans+=x/2*2;x%=2;
	//ans+=y/2*2;y%=2;
	if(x%2+y%2+l%2>1){
		if(x%2+y%2+l%2==3)ans+=3;
		if(x%2+y%2+l%2==2){
			if(y%2==0){
				if(y)ans+=3,y--;
			}
			if(x%2==0){
				if(x)ans+=3,x--;
			}
			if(l%2==0){
				if(l)ans+=3,l--;
			}
		}
	}
	ans+=l/2*2;l%=2;
	ans+=x/2*2;x%=2;
	ans+=y/2*2;y%=2;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main{
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		int A = sc.nextInt() - 1;
		int B = sc.nextInt();
		sc.close();
		
		System.out.println((B + A - 2) / A);
	}
}

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

int main(){
  int n;
  cin>>n;
  int a[110][110] = {};
  for(int i=1;i<=n;i++){
    int u,k;
    cin>>u>>k;
    for(int j=0;j<k;j++){
      int v;
      cin>>v;
      a[i][v]=1;
    }
  }
  for (int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      if(j!=n){
	cout<<a[i][j]<<" ";
      }else{
	cout<<a[i][j]<<endl;
      }
    }
  }
}

Measured memory_bytes: 3132
#include<iostream>
using namespace std;
int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		int input;
		cin >> input;
		if(input % 2 ==0){
			if(input % 3 !=0 && input % 5 !=0){
				cout << "DENIED" << endl;
				return 0;
			}
		}
	}
	cout << "APPROVED" << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for(auto i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const long double EPS = 1e-8;
using vi = vector <int>;
using vvi = vector <vi>;

signed main() {
	int a, b;
	cin >> a >> b;
	cout << ( a * b % 2 ? "Odd" : "Even") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
// g++ Main.cpp -std=gnu++1y -O2 -I/opt/boost/gcc/include -o main && ./main

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vll = vector<vl>;
using vii = vector<vi>;
using pii = pair<int, int>;

#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i, a, b) for(int (i) = a; (i) < (b);(i)++)
#define MAX(a, b) ((a > b) ? a : b)
#define MIN(a, b) ((a > b) ? b : a)

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


const int MOD = 1e9 + 7;

int main(){
  int n, z, w; cin >> n >> z >> w;
  vi A(n);REP(i, n) cin >> A.at(i);
  if(n == 1){cout << abs(A.at(0) - w) << endl; return 0;}
  int s = (A.at(n - 1) - A.at(n - 2)); s = abs(s);
  int t = A.at(n - 1) - w; t = abs(t);
  cout << MAX(s, t) << endl;
  return 0;
}

Measured memory_bytes: 256
open System
 
let flip f a b = f b a
let read() = Console.ReadLine()
let pi = Math.PI
let pi2 = pi * 2.0
 
[<EntryPoint>]
let main _ =
    let str = read().Split(' ')
    let a = float str.[0]
    let b = float str.[1]
    let h = float str.[2]
    let m = float str.[3]
    
    let rad = ((h + m / 60.0) / 12.0 - m / 60.0) * pi2
    
    let len = sqrt(a * a + b * b - 2.0 * a * b * cos(rad))
    
    printfn "%.16f" len
    
    0 

Measured memory_bytes: 30408
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

s = input().strip()

if 'R' not in s:
    print(0)
    sys.exit(0)
else:
    if s == 'RRR':
        print(3)
        sys.exit(0)
    elif 'RR' in s:
        print(2)
        sys.exit(0)
    else:
        print(1)
        sys.exit(0)


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

int top = 0, S[1000];

void push(int x) {
  S[++top] = x;
}

int pop(void) {
  top--;
  return S[top+1];
}

int main(void) {
  int a, b;
  top = 0;
  char s[100];
  while(scanf("%s",s) != EOF) {
    if(s[0] == '+') {
      a = pop();
      b = pop();
      push(a + b);
    } else if(s[0] == '-') {
      b = pop();
      a = pop();
      push(a - b);
    } else if(s[0] == '*') {
      a = pop();
      b = pop();
      push(a * b);
    } else {
      push(atoi(s));
    }
  }
  printf("%d\n",pop());

  return 0;
}




Measured memory_bytes: 2104
A,B,N = gets.chomp.split.map(&:to_i)

if N <= (B - 1)
  puts ((A * N) / B).floor - A * (N / B).floor
else
  q = N / B
  if N % B == (B - 1)
    puts ((A * N) / B).floor - A * (N / B).floor
  else
    m = (q - 1) * B + B - 1
    puts ((A * m) / B).floor - A * (m / B).floor
  end
end

Measured memory_bytes: 14344
#include<bits/stdc++.h>
using namespace std;
int main()
{
      ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
long long a,b,c,k;
	 cin>>a>>b>>c>>k;
	if(a>=k)cout<<k;
	else if(a<k&&a+b>=k)cout<<a;
	else {
		cout<<a-(k-(a+b));
	}
      return 0;
}


Measured memory_bytes: 3520
import java.util.Scanner;

public class Main {
    static long n;
    static int[] g;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextLong();
        long gcm = 1;
        for (int i = 0; i < n; i++) {
            long num = sc.nextLong();
            gcm = LCM(gcm, num);
        }
        System.out.println(gcm);
    }
    //最大公約数
    static long GCM (long x, long y) {
        long tmp = x % y;
        if (tmp == 0) return y;
        return GCM(y, tmp);

    }
    //最小公倍数
    static long LCM(long x, long y) {
        return x / GCM(x,y) * y;
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

int main(int argc, char *argv[])
{
	int a, b;
	cin >> a >> b;

	cout << (a + b + 1) / 2 << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

import static java.util.Comparator.reverseOrder;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        List<Long> inputList = new ArrayList<Long>();
        for(int i = 0; i < n ;i++) {
            inputList.add(sc.nextLong());
        }

        /*
        List<Integer> sortedList = inputList.stream().sorted(reverseOrder()).collect(Collectors.toList());
        for(int a: sortedList) {
            System.out.println(a);
        }
        */
        List<Long> sortedList = inputList.stream().sorted(reverseOrder()).collect(Collectors.toList());
        long result = sortedList.get(0);
        int index = 1;
        int count = 0;
        for (int i = 0; i < n - 2 ; i++) {
            result += sortedList.get(index);
            count = count + 1;
            if (count == 2) {
                count = 0;
                index = index + 1;
            }
        }
        System.out.println(result);
    }
}

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

from fractions import gcd
import numpy as np

MOD = 10 ** 9 + 7

S = int(input())

M = 10**4

def type_1(S):
    cnt = 0
    # S 2種の桁数k,k+1からなる。さらにk>=9を仮定する。
    # 項数nとすると、kn < S < (k+1)n となる(k,n)の個数を数える
    # まずk > Mとなるものを数える。このとき1<=n<=Mである。
    n = np.arange(1,M+1)
    k_max = (S-1)//n
    k_min = np.maximum(M+1,S//n)
    cnt += np.maximum(0,k_max - k_min + 1).sum()
    # 次に、9<=k<=Mとなるものを数える
    k = np.arange(9,M+1)
    n_max = (S-1)//k
    n_min = S//(k+1) + 1
    cnt += np.maximum(0,n_max-n_min+1).sum()
    return cnt

type_1(S)

def type_2(S):
    # S 1種の桁数からなる。
    cnt = 0
    div = np.arange(1,M+1,dtype=np.int64)
    div = set(div[S%div==0])
    div |= set(S//x for x in div)
    for d in div:
        n = S//d
        # d桁のものをn個使うようにしたい
        if d < 10:
            total = 9 * 10 ** (d-1)
            cnt += max(0,total-n+1)
        else:
            total = 9 * pow(10,int(d)-1,MOD)
            cnt += total-n+1
    return cnt % MOD

def type_3(S):
    cnt = 0
    # S 2種以上の桁数からなる。9桁の数以下しか使わない。
    # ここは適当にいけそう
    for R in range(1,10):
        for L in range(1,R):
            mid = sum(i*9*10**(i-1) for i in range(L+1,R)) # 途中の桁数の寄与
            rest = S - (L+mid+R)
            if rest < 0:
                continue
            # Lが1+x個、Rが1+y個として
            # Lx + Ry = rest, 0<=x<=x_max, 0<=y<=y_max
            x_max = 9*10**(L-1)-1
            y_max = 9*10**(R-1)-1
            g = gcd(L,R)
            if rest % g != 0:
                continue
            L0 = L//g
            R0 = R//g
            rest //= g
            # x mod R0が一意に決まる
            for x0 in range(R0):
                if (L0*x0-rest)%R0 == 0:
                    break
            y0 = (rest-L0*x0)//R0
            # (x0 + tR, y0-tL)として解がパラメータ表示できる
            # 0 <= x0 + tR <= x_max
            t_min = 0
            t_max = (x_max-x0)//R0
            # y0-tL >= 0
            t_max = min(t_max,y0//L0)
            # y0-tL <= y_max iff y0-y_max <= tL
            t_min = max(t_min,(y0-y_max+L-1)//L0)
            cnt += max(0, t_max - t_min + 1)
    return cnt

answer = (type_1(S) + type_2(S) + type_3(S)) % MOD
print(answer)

Measured memory_bytes: 16972
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int[][] p=new int[m][2];
		for(int i=0;i<m;i++){
			p[i][0]=sc.nextInt();
			p[i][1]=sc.nextInt();
		}
		sc.close();
		UnionFind uf = new UnionFind(n);
		long[] ans = new long[m];
		long now = (long)n * (n -1) / 2;
		for(int i=m-1;i>=0;i--){
			ans[i] = now;
			int a = uf.find(p[i][0] - 1);
			int b = uf.find(p[i][1] - 1);
			if (a != b) {
				now -= (long)uf.size[a] * uf.size[b];
			}
			uf.union(p[i][0]-1, p[i][1]-1);
		}
	    for (long v : ans) {
	    	System.out.println(v);
	    }
	}

	static class UnionFind {
		private int[] parent;
		private int[] rank;
		public int g;
		public int[] size;

		public UnionFind(int s) {
			parent = new int[s];
			rank = new int[s];
			for (int i = 0; i<s; i++) {
				this.parent[i] = i;
				this.rank[i] = 1;
			}
			this.g = s;
			size = new int[s];
			Arrays.fill(size, 1);
		}

		public boolean isSame(int n1, int n2) {
			return find(n1) == find(n2);
		}

		public int find(int n) {
			if (parent[n] == n) {
				return n;
			} else {
				return parent[n]=find(parent[n]);
			}
	    }

		public void union(int n1, int n2) {
	    	int root1 = find(n1);
	    	int root2 = find(n2);
	    	if (root1 != root2) g --;
	    	if (root1 != root2) {
	    		int x = size[root1] + size[root2];
	    		size[root1] = x;
	    		size[root2] = x;
	    	}
	    	if (rank[root1] < rank[root2]) {
	    		parent[root1] = root2;
	    	} else if (rank[root1] > rank[root2]) {
	    		parent[root2] = root1;
	    	} else if (root1 != root2) {
	    		parent[root2] = root1;
	    		rank[root1]++;
	    	}
		}
	}
}

Measured memory_bytes: 103356
#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 10, INF = 1e9 + 1;
int sol[N];         //suma u prvih i kolona
int matr[11][1001], sum[11][1001];
int main()
{
    int h,w,lol;
    cin >> h >> w >> lol;
    string unos;
    for(int i = 1; i <= h; i++){
        cin >> unos;
        for(int j = 0; j < unos.length(); j++){
            matr[i][j + 1] = unos[j] - '0';
        }
    }
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            sum[i][j] = sum[i][j-1] + matr[i][j];
        }
    }
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            sum[i][j] = sum[i][j] + sum[i-1][j];
       //     printf("%d ",sum[i][j]);
        }
    //    printf("\n");
    }
    for(int i = 0; i < 1 << ( h - 1); i++){
        vector<int> bits;
        for(int j = 0; j < h; j++){
            if(1<<j & i){
                bits.push_back(j+1);            //prvih tolko redova
            }
        }
        vector<int> sume[bits.size() + 1];
        for(int j = 0; j < bits.size() + 1; j++)
            sume[j].push_back(0);
        for(int j = 1; j <= w; j++){
            int cur = 0;
            for(int k = 0; k < bits.size(); k++){
                sume[k].push_back(sum[bits[k]][j] - sum[cur][j]);
                cur = bits[k];
            }
            sume[bits.size()].push_back(sum[h][j] - sum[cur][j]);                //oformio sume po bitnim vrstama
        }


/*        cout << "Za "<< i<<endl;
        for(int j = 0; j < bits.size() + 1; j++){
            for(int k = 0; k <= w; k++){
                cout << sume[j][k] << " ";
            }
            cout << endl;
        }
*/

        vector<int> last[bits.size() + 1];
        for(int j = 0; j < bits.size() + 1; j++)
            last[j].push_back(0);                       //poslednji dodati
        int l = 0;
        int ok = 1, ok2 = 1;
        int resenje = 0;
        for(int j = 1; j <= w; j++){
            ok2 = 1;
            if(!ok)
                break;
            for(int k = 0; k < bits.size() + 1; k++){
                if(sume[k][j] - last[k].back() > lol){
                    if(j - l == 1){
               //         cout << "Sranje " << j << " "<<sume[k][j]<<" " << last[k].back() << endl;
                        ok = 0;
                        sol[i] = INF;
                        break;
                    }
                    else{
                        ok2 = 0;
                        break;
                    }
                }
            }
            if(!ok2){                                       //ponovi seriju
                resenje++;
                for(int s = 0; s < bits.size() + 1; s++)
                    last[s].push_back(sume[s][j-1]);
                l = --j;
            }
        }
        if(ok)
            sol[i] = resenje + bits.size();
    }
    int mini = INF;
    for(int i = 0; i < 1<< (h - 1); i++){
        mini = min(mini,sol[i]);
    }
    cout << mini;
    return 0;
}


Measured memory_bytes: 384
// AtCoder_146B. ROT N
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

#define FIO         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ALL(v)      v.begin(), v.end()
#define PB          push_back
#define MP          make_pair
#define UB          upper_bound
#define LB          lower_bound
#define PI          2*acos(0.0)
#define MOD         1000000007
#define GCD(a, b)   __gcd(a, b)
#define LCM(a, b)   ((a)*(b)) / GCD(a, b)
#define INPUT       freopen("input.txt", "r", stdin);
#define OUTPUT      freopen("output.txt", "w", stdout);
#define PRINT(a)    for(auto i : a) cout << i << " "; cout << endl;
#define PRINTS(s)   for(auto i=s.begin(); i!=s.end(); i++) cout << *i << " "; cout << endl;
#define PRINTM(m)   for(auto i=m.begin(); i!=m.end(); i++) cout << i->first << " " << i->second << endl;

int month[] = {31,28,31,30,31,30,31,31,30,31,30,31};
string lowerCase = "abcdefghijklmnopqrstuvwxyz";
string upperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

/// Graph moves
const int fxKing[] = {+1,+1,+0,-1,-1,-1,+0,+1}; /// King's move
const int fyKing[] = {+0,+1,+1,+1,+0,-1,-1,-1}; /// King's move
const int fxKnight[] = {+2,+1,-1,-2,-2,-1,+1,+2}; /// Knight's move
const int fyKnight[] = {+1,+2,+2,+1,-1,-2,-2,-1}; /// Knight's move

ll q, t, a, b, c, d, m, n, k;
ll cnt, Mn, Mx, sum, sum1, sum2, ck;
ll arr1[1000], arr2[1000];

map <ll, ll> mp1, mp2;
set <ll> st1, st2;
vector <ll> vec1, vec2;
string str1, str2, str3;

int main()
{
    FIO;
    t = 1;
    string s;
    int x;
    while(t--)
    {
        cin >> x ;
        cin >> s ;
        for(int i=0; i<s.size(); i++)
        {
            int p = s[i] - 'A' + x;
            p %= 26;
            cout << upperCase[p];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
/*
    Problem 28
    https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_11_C
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 105;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
vector<vector<int>> G(MAX, vector<int>(MAX));
vector<int> dist(MAX, -1);
/* function */
void bfs() {
    queue<int> q;
    q.push(0);
    dist[0] = 0;  // distで訪れたかどうかcheck
    while (!q.empty()) {
        int from = q.front();
        q.pop();
        for (int to : G[from]) {
            if (dist[to] != -1) continue;
            dist[to] = dist[from] + 1;
            q.push(to);
        }
    }
}
/* main */
int main(){
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        int u, k;
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            v--;
            // 有効グラフ
            G[u].push_back(v);
        }
    }

    bfs();

    for (int i = 0; i < N; i++) cout << i+1 << ' ' << dist[i] << '\n';
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
const long long inf = 1000000001; // const 書き換え禁止
const double PI = 3.14159265358979323846; //M_PI はライブラリ

int main(void){
    int a,b;
    cin >> a >> b;
    for(int i=1;i<=3;i++){
        int ans = a * b * i;
        if(ans % 2 == 1){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 3588
import sys
X = int(input())
if 1 <= X and X < 100:
    print("0")
    sys.exit()
i = 0
dp = [0]*(X+1)
dp[0] = 1
for i in range(100, X+1):
    for j in range(6):
        if dp[i-(100+j)] == 0:
            pass
        else:
            dp[i] = 1
print(dp[X])

Measured memory_bytes: 3828
#include "bits/stdc++.h"
using namespace std;
int main() {
  string s;cin >> s;
  int n = s.size(),c1 = 0, c2 = 0;
  for (int i = 0; i < n; ++i) {
    if (i % 2 == s[i] - '0')
      ++c1;
    else
      ++c2;
  }
  cout << min(c1, c2) << endl;
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //b
  int k, x;
  cin >> k >> x;
  vector<int> ans;
  for (int i = -1000000; i <= 1000000; i++) {
    if (abs(i - x) + 1 <= k) {
      ans.push_back(i);
    }
  }
  for (int i = 0; i < (int) ans.size(); i++) {
    if (i > 0) cout << " ";
    cout << ans[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long sum = 0;

		for (int i = 1; i < N + 1; i++) {
			if (i % 3 != 0 && i % 5 != 0) {
				sum += i;
			}
		}
		System.out.println(sum);

	}

}


Measured memory_bytes: 35640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int Node[500001];
int parent(int i ){return i/2;}
int left(int i){return 2*i;}
int right(int i){return 2*i+1;}
int n;

void maxHeap(int i)
{
	int l = left(i);
	int r = right(i);
	int largest;
	if(l<=n&&Node[l]>Node[i])largest = l;
	else largest = i;

	if(r<=n&&Node[r]>Node[largest])largest = r;


	if(i != largest)
	{
		swap(Node[i],Node[largest]);
		maxHeap(largest);
	}
}

void buildMaxHeap()
{
	for(int i = n/2;i>0;i--)
	{
		maxHeap(i);
	}
}

int main()
{
	cin >> n;
	for(int i =0;i<n;i++)
	cin >> Node[i+1];


	buildMaxHeap();

	for(int i = 1;i<=n;i++)
	{
	cout<<' ';
		cout<<Node[i];
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 5052
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll X,i,N;cin>>X>>N;
  if(N==0)cout<<X<<endl;
  else{
    ll p[N],j=0;
    REP(i,N)cin>>p[i];
    sort(p,p+N);i=X;
    while(binary_search(p,p+N,i)){
      if(j>=0)j++;
      else j--;
      j*=-1;i+=j;
    }
    cout<<i<<endl;
  }
  return 0;
}

Measured memory_bytes: 3628
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

typedef tuple<int, int, int> tup;

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

    int n, m, p;
    cin >> n >> m >> p;

    vector<tup> vt(m);
    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        vt[i] = make_tuple(a, b, c);
    }

    auto edge = initVec2<int>(n + 1, 0);
    rep(i, m){
        int a, b, c;
        tie(a, b, c) = vt[i];

        edge[b].push_back(a);
    }
    vector<bool> used(n + 1, false);
    stack<int> st;
    st.push(n);
    while(not st.empty()){
        int v = st.top();
        st.pop();

        if(used[v]){
            continue;
        }
        used[v] = true;

        for(int u : edge[v]){
            if(used[u]){
                continue;
            }
            st.push(u);
        }
    }
    //Bellman-Ford
    vector<int> dist(n + 1, INF);
    vector<int> prev(n + 1, -1);
    dist[1] = 0;
    bool negative_cycle = false;
    for (int i = 0;; i++) {
        bool update = false;
        rep(j, m){
            int a, b, c;
            tie(a, b, c) = vt[j];

            if(not used[a] || not used[b]){
                continue;
            }
            if (dist[a] != INF && dist[b] > dist[a] - c + p) {
                dist[b] = dist[a] - c + p;
                prev[b] = a;
                update = true;
            }
        }
        if (!update) break;
        if (i > n) { negative_cycle = true; break; }
    }

    if(negative_cycle){
        cout << -1 << endl;
    }else{
        cout << max(-dist[n], 0LL) << endl;
    }
    return 0;
}


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

#define ll long long 
#define mkp make_pair 
#define fi first 
#define se second

using namespace std ;

ll z ;

int	 main ( ) {

	int a[100007];
	for(int i = 0 ; i < 100007 ; i ++ ){
		a[i] = 0 ;
	}
	int n ;
	cin >> n ;
	for(int i = 0 ; i < n ; i ++ ){
		int c , b ;
		cin >> c >> b ;
		for(int j = c ; j <= b ; j ++ ){
			a[j] = 1 ;
		}
	}

	for(int i = 0 ; i < 100007 ; i ++ ){
		if( a[i] == 1 ){
			z ++ ;
		}
	}

	cout << z ;

}


Measured memory_bytes: 640
import sys
input = sys.stdin.readline
import fractions


def main():
    N = int(input())
    a = [int(x) for x in input().split()]
    
        

    ans = 1
    for v in a:
        ans = (ans * v) // fractions.gcd(ans, v)

    ans2 = 0
    for v in a:
        ans2 += (ans - 1) % v

    print(ans2)


if __name__ == '__main__':
    main()




Measured memory_bytes: 5348
a, b, c = map(int, input().split())
if a == 5 and b == 5 and c == 7:
    print('YES')
elif a == 7 and b == 5 and c == 5:
    print('YES')
elif a == 5 and b == 7 and c == 5:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
# coding:utf-8

n, y = [int(x) for x in input().split(' ')]

max_iti_man = y // 10000

for iti_man in range(max_iti_man + 1):
    for go_sen in range(int(n) - iti_man + 1):
        itigo = 5000 * go_sen + 10000 * iti_man
        sen = n - iti_man - go_sen
        if 1000 * sen + itigo == y:
            print("{} {} {}".format(iti_man,go_sen,sen))
            exit()

print("-1 -1 -1")


Measured memory_bytes: 2940
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 *
 * @author k16069kk
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        double r = Double.parseDouble(line);
        
        double S = r * r * Math.PI;
        double l = 2 * r * Math.PI;
        
        System.out.println(String.format("%8f", S) + " " + String.format("%8f", l));
    }
    
}



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

int main() {
  int a,b;
  cin>>a>>b;
  if(b==100){
    if(a==0){
      cout<<"101"<<endl;
      return 0;
    }
    if(a==1){
      cout<<"10100"<<endl;
      return 0;
    }
    if(a==2){
      cout<<"1010000"<<endl;
      return 0;
    }
  }
  int answer=1;
  for(int i=0;i<a;i++){
    answer*=100;
  }
  cout<<b*answer<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    sort(a.rbegin(), a.rend());
    priority_queue<int> pq; // 差を管理
    ll ans = 0;
    for(auto t : a){
        if(!pq.empty()){
            ans += pq.top();
            pq.pop();
            pq.push(t);
            pq.push(t);
        }else{
            pq.push(t);
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
  
  int sum = 700;
  
  rep(i,3) {
    char a;
    cin >> a;
    if (a == 'o') sum += 100;
  }
  
  cout << sum << endl;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int n;
    while(cin >> n, n) {
        int ans = 0;
        for(int i=0; i*i<=n; i++) {
            for(int j=i; j*j<=n-i*i; j++) {
                for(int k=j; k*k<=n-i*i-j*j; k++) {
                    for(int l=k; l*l<=n-i*i-j*j-k*k; l++) {
                        if(i*i + j*j + k*k + l*l == n) ans++;
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3004
n,k = map(int,input().split())
lst = [0]*10**5
for i in range(n):
  a,b=map(int,input().split())
  lst[a-1] += b
  ans = 0
for j in range(10**5):
  ans += lst[j]
  if ans >= k:
    print(j+1)
    exit()

Measured memory_bytes: 11512
#include<cstdio>
#include<algorithm>
using namespace std;
int a[105];
int n,x;
int main(){
    scanf("%d",&n);
    int sum = 0;
    for(int i = 1;i <= n;i++)
        scanf("%d",&a[i]),sum += a[i];
    if(sum % 10)
        printf("%d\n",sum);
    else{
        sort(a+1,a+1+n);
        for(int i = 1;i <= n;i++){
            if(a[i] % 10 != 0)
                return 0 * printf("%d\n",sum-a[i]);
        }
        printf("0\n");
    }
    return 0;
}


Measured memory_bytes: 128
def main():
    n = int(input())
    a = [0] + [int(x) for x in input().split()]
    balls = [0 for _ in range(n + 1)]
    answer = []
    for i in range(n, 0, -1):
        if sum(balls[i::i]) % 2 != a[i]:
            balls[i] += 1
            answer.append(i)
    print(sum(balls))
    print(" ".join(map(str, answer)))


if __name__ == '__main__':
    main()



Measured memory_bytes: 19864
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T> void DEBUG(string str, T e){if(DEBUG_OUT == false)return;std::cout <<str<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


//CODE
void solve(void)
{  
  vector<int> vec(3);
  for (int i = 0; i < 3; i++)
  {
    cin>>vec[i];
  }
  sort(ALL(vec));
  cout<<vec[2]*10 + vec[1] + vec[0]<<endl;
  
  
  
  
  return;
}


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

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll MOD=1e9+7;
const int INF=1<<30;

int main(){
  ll r,D,x;
  cin >> r >> D >> x;
  vector<ll> res(10);
  res[0]=r*x-D;
  rep(i,9){
    res[i+1]=r*res[i]-D;
  }
  rep(i,10){
    cout << res[i] << endl;
  }
  
}

Measured memory_bytes: 256
while True:
    n,m = map(int,input().split())
    if n==0 and m==0: break
    taro = [int(input()) for i in range(n)]
    hanako = [int(input()) for i in range(m)]
    d = sum(taro)-sum(hanako)
    def search():
       for i in taro:
           for j in hanako:
               if (i-j)*2 == d: 
                   print(i,j)
                   return
       print(-1)
    search()


Measured memory_bytes: 5600
/*
 * src.cpp
 *
 *  Created on: 2016/09/11
 *      Author: joi
 */

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

string S[3];
int cnt[3];
int p;

bool gend(){
	REP(i,3){
		if (cnt[i]==(int)S[i].length() && p==i){
			return true;
		}
	}
	return false;
}

int main(){
	REP(i,3){
		cin>>S[i];
	}
	while (!gend()){
		cnt[p]++;
		p=S[p][cnt[p]-1]-'a';
	}
	cout<<(char)('A'+p)<<endl;
	return 0;
}




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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL) x=x->left;
  return x;
}

Node treeMaximum(Node x){
  while(x->right!=NIL) x=x->right;
  return x;
}

Node treeSearch(Node u, int k){
  while(u!=NIL && k!=u->key){
    if(k<u->key) u=u->left;
    else u=u->right;
  }
  return u;
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL) return treeSuccessor(x->right);
  y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL || z->right==NIL) y=z;
  else y=treeSuccessor(z);
  if(y->left!=NIL) x=y->left;
  else x=y->right;
  if(x!=NIL) x->parent=y->parent;
  if(y->parent==NIL) root=x;
  else if(y==y->parent->left) y->parent->left=x;
  else y->parent->right=x;
  if(y!=z) z->key=y->key;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key) x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL) root=z;
  else if(z->key<y->key) y->left=z;
  else y->right=z;
}

void inorder(Node u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 25124
#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() {
  ll a,b,k;
  cin >> a >> b >> k;
  if(a >= k){
    a -= k;
  }else if(k <= a+b){
    b -= k-a;
    a = 0;
  }else{
    a = 0;
    b = 0;
  }
  cout << a <<" "<< b << endl;
  }


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

int main(){
	char a[11], b[11], c[11];
	scanf("%s %s %s", a,b,c);
	int d=strlen(a)-1,e=strlen(b)-1;
	if(a[d]==b[0] && b[e]==c[0]){
		puts("YES");
	}else{
		puts("NO");
	}
	
	
	return 0;
}

Measured memory_bytes: 1640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll a;
    char s;
    ll b;
    cin >> a >> s >> b;
    if (s == '+')cout << a + b << endl;
    else cout << a-b << endl;
}

Measured memory_bytes: 3644
// AUTHOR: ROSHAN SRIVASTAVA
// WEBSITE: https://www.youtube.com/channel/UC6uQdd7kLLOdlHSVklhV7Cw

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

int n; 

int main(){

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    cin >> n;

    vector<ll> a(n);

    for(int i = 0; i < n; i++)
        cin >> a[i];

    ll ans = 0ll;

    for(int i = 1; i < n; i++) {
        ans += (max(0ll, a[i - 1] - a[i]));
        a[i] = max(a[i], a[i - 1]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4836
#include<iostream>
#include<cmath>
using namespace std;
int main() {
    string a, b;
    cin >> a >> b;
    int c = stoi(a + b);
    for (int i = 4; i <= (int)sqrt(c) + 1; i++) {
        if (c == i * i) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


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

#define F first 
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HI;
typedef priority_queue<int, vector<int>, greater<int> > HDI;

const int N = 100010, M = 1010;

int n, m;
int a[N];

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i ++ ) cin >> a[i];
	
	int res = 0;
	for (int l = 0; l <= min(n, m); l ++ )
		for (int r = 0; r <= min(n - l, m - l); r ++ )
		{
			int t = m - l - r, sum = 0;
			HDI heap;
			for (int i = 0; i < l; i ++ )
			{
				heap.push(a[i]);
				sum += a[i];
			}
			for (int i = n - 1; i >= n - r; i -- )
			{
				heap.push(a[i]);
				sum += a[i];
			}
			while (t > 0 && heap.size() && heap.top() < 0)
			{
				sum -= heap.top();
				heap.pop();
				t -- ;
			}
			res = max(res, sum);
		}
		
	cout << res << endl;
    return 0;
}


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

""" ビット全検索をちゃんと使ってみる版3 """

D, G = map(int, input().split())

# 各点数問題毎の、全問解いた場合の回答数と得点を保持
class ScoreSet:
    def __init__(self, times, score):
        self.times = times
        self.score = score

# 各パターン毎の、合計回答数と合計得点と、どの点数問題を全問解いたのかを保持
class ScoreSetSum:
    def __init__(self, times, score, bool_list):
        self.times = times
        self.score = score
        self.bool_list = bool_list

# 入力内容から、ScoreSetのリストを作成
scoreSetList = [0] * D
for i in range(D):
    p, c = map(int, input().split())
    scoreSetList[i] = ScoreSet(p, p*100*(i+1) + c)

# ビット全検索のループとScoreSetのリストから、ScoreSetSumのリストを作成
scoreSetSumList = [0] * (1<<D)
for i in range(1<<D):
    times_tmp = 0
    score_tmp = 0
    bool_list = [False] * D
    for j in range(D):
        if 1 & i>>j == 1:
            times_tmp += scoreSetList[j].times
            score_tmp += scoreSetList[j].score
            bool_list[j] = True
    scoreSetSumList[i] = ScoreSetSum(times_tmp, score_tmp, bool_list)

# ScoreSetSumのリストを元に、適切なパターンを探していく
ans = float("inf")
for scoreSetSum in scoreSetSumList:
    tmp = float("inf")
    # 得点が既にG以上であれば、そのままその回答数が候補
    if scoreSetSum.score >= G:
        tmp = scoreSetSum.times
    else:
        # 足りなかったら、全問解いていない点数問題から最も高いもの選ぶ
        for i in range(D-1, -1, -1):
            if scoreSetSum.bool_list[i] == False:
                score = scoreSetSum.score
                times = scoreSetSum.times
                # 選んだ点数問題を1問ずつ解いていく
                for j in range(scoreSetList[i].times):
                    score += 100*(i+1)
                    times += 1
                    # G以上に達した時点で、その時の回答数が候補
                    if score >= G:
                        tmp = times
                        break
                    # 最後まで解いてもG以上にならなければ、このパターンは候補外
                break
    # 今までの最小と今回の候補を比較
    ans = min(ans, tmp)

print(ans)

Measured memory_bytes: 3400
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()
A = LI()
ans = A[0]
if 0 in A:
    ans = 0
else:
    for i in range(1, N):
        if ans > 10**18:
            ans = -1
            break
        else:
            ans = ans*A[i]
if ans > 10**18:
    ans = -1
print(ans)

Measured memory_bytes: 93720
#include<stdio.h>
int main(){
  int a,b,s,i;
  int m[12]={31,29,31,30,31,30,31,31,30,31,30,31};
  while(1){ 
 scanf("%d%d",&a,&b);
 if(a==0&&b==0)break;
 s=b;
 for(i=0;i<a-1;i++)s+=m[i];
 if(s%7==1)printf("Thursday\n");
 else if(s%7==2)printf("Friday\n");
 else if(s%7==3)printf("Saturday\n");
 else if(s%7==4)printf("Sunday\n");
 else if(s%7==5)printf("Monday\n");
 else if(s%7==6)printf("Tuesday\n");
 else if(s%7==0)printf("Wednesday\n");
  }
  return 0;
}

Measured memory_bytes: 1012
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j

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

int main(){
	ll N;
	cin >> N;
	ll ans = 0;
	repR(i, N, 0){
		ll temp = (int)sqrt(i);
		if (i == temp * temp){
			ans = i;
			break;
		}
	}
	cout << ans << endl;
 	return 0;
}


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

using namespace std;

typedef vector<vector<int> > G;
G graph;

int color[100050];

bool dfs(int u, int c){
    color[u] = c;
    for(int i=0; i<graph[u].size(); i++){
        int v = graph[u][i];
        if(color[v] == c){
            return false;
        }
        if(color[v] == 0 && !dfs(v, -c) ){
            return false;
        }
    }   
    return true;
}

int main(void){
    long long n, m;
    cin >> n >> m;
    graph = G(n);
    for(int i=0; i<m; i++){
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    long long B=0, W=0;
    if(dfs(0, 1)){
        for(int i=0; i<n; i++){
            if(color[i] == 1){
                B++;
            }else if(color[i] == -1){
                W++;
            }
        }
        cout << B*W - m << endl;
    }else{
        cout << ( (n*(n-1)) /2) - m << endl;
    }
    
    return 0;
}

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

void solve() 
{
    ll n,ans=0;;cin>>n;
    rep(a,1,1000010){
        ll b=n/a;if(b==0)break;
        rep(bb,1,b+1){
            ll c=n-a*bb;if(c==0)continue;
            ans++;
        }
    }
    cout<<ans<<endl;
}

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

Measured memory_bytes: 3648
#include <iostream>

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)

int main() {
	int X, A, B; cin >> X >> A >> B;

	cout << ((-A + B <= 0) ? "delicious" : ((-A + B <= X) ? "safe" : "dangerous")) << endl;

	return 0;
}

Measured memory_bytes: 256