akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include<functional>
#include<queue>
#include<regex>
#include<time.h>
#include<type_traits>

using namespace std;
using ll = long long;

constexpr ll MOD = 1000000007;
constexpr ll INF = 1050000000;
constexpr ll LONGINF = 1050000000000000000;

int a[] = { 1,3,5,7,8,10,12 };
int b[] = { 4,6,9,11 };
int c[] = { 2 };

int main() {
	int x, y; cin >> x >> y;

	bool flagx = false;
	bool flagy = false;
	for (auto i : a) {
		if (i == x) {
			flagx = true;
		}
		if (i == y) {
			flagy = true;
		}
	}
	if (flagx&&flagy) {
		cout << "Yes" << endl;
		return 0;
	}
	flagx = false;
	flagy = false;

	for (auto i : b) {
		if (i == x) {
			flagx = true;
		}
		if (i == y) {
			flagy = true;
		}
	}
	if (flagx&&flagy) {
		cout << "Yes" << endl;
		return 0;
	}
	flagx = false;
	flagy = false;

	for (auto i : c) {
		if (i == x) {
			flagx = true;
		}
		if (i == y) {
			flagy = true;
		}
	}
	if (flagx&&flagy) {
		cout << "Yes" << endl;
		return 0;
	}

	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    static MyReader in = new MyReader();
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int N = in.i();
        char[] S = in.s(N);

        int left = 0;
        int extra = 0;
        for (int i = 0; i < N; i++) {
            if (S[i] == '(') {
                left++;
            } else if (left == 0) {
                extra++;
            } else {
                left--;
            }
        }


        for (int i = 0; i < extra; i++) {
            out.print('(');
        }
        out.print(new String(S));
        for (int i = 0; i < left; i++) {
            out.print(')');
        }
        out.close();
    }
}

class IntStack {
    final int MAX;
    int[] array;
    int head = 0;

    IntStack(int N) {
        MAX = N;
        array = new int[N];
    }

    void push(int n) {
        array[head++] = n;
    }

     int pop() {
        return array[--head];
    }

    boolean isEmpty() {
        return head == 0;
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    void back() {
        head--;
    }

    boolean minus() {
        boolean minus;
        while (true) {
            char c = next();
            if (!isDelimiter(c)) {
                if (!(minus = c == '-')) back();
                return minus;
            }
        }
    }

    void skip() {
        while (isDelimiter(next()));
        back();
    }

    char[] s(int N) {
        char[] cbuf = new char[N];
        read(cbuf, 0, N);
        return cbuf;
    }

    public int read(char[] cbuf, int off, int len) {
        skip();
        int i;
        for (i = 0; i < cbuf.length; i++) {
            char c = next();
            if (isDelimiter(c)) {
                break;
            }
            cbuf[i] = c;
        }
        return i;
    }

    boolean isDelimiter(char c) {
        return c == ' ' || c == '\n' || c == '\r';
    }

    int i() {
        boolean minus = minus();
        int n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        boolean minus = minus();
        long n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }
}


Measured memory_bytes: 32992
n,k = [int(e) for e in input().split()]
p = [int(e) for e in input().split()]
sum = 0
max_index = 0
for i in range(0,k):
    sum += p[i]
max_sum = sum
for i in range(1,n-k+1):
    sum = sum - p[i-1] + p[i+k-1]
    if sum > max_sum:
        max_sum = sum
        max_index = i

res = 0
for i in range(0,k):
    res += (p[max_index + i] + 1)/2

print(res)

Measured memory_bytes: 24676
using System;
using System.Linq;
class P{
  static void Main(){
    var _=Console.ReadLine();
    var s=Console.ReadLine().Split().Select((x,i)=>new{a=int.Parse(x),b=i});
    Console.WriteLine(s.OrderBy(x=>Math.Abs(x.a-s.Average(y=>y.a))).First().b);
  }
}

Measured memory_bytes: 13524
/********   All Required Header Files ********/
#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 <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
typedef pair<int, int>  pii;
typedef vector<int>     vi;
typedef vector<pii>     vpii;
typedef vector<vi>      vvi;
//=======================
const int MOD = 1000000007;
const int N = 2e6+13, M = N;
//=======================
vi g[N];
int a[N];
int  m, k , i;
//=======================

void solve() {
    int n ;
    cin>>n;

    // vector<int> fre(101,0);

    // fo(i,n){
    //     cin>>m;
    //     fre[m]++;
    // }

    // int a = -1 , b = -1;
    // int c = 0;
    // for(i = 0 ; (i<101) && (c<2);i++){

    //     cout<<fre[i]<<" at "<<i<<endl;

    //     if(fre[i]>=2)continue;

    //     else if(fre[i] == 1 && a<0)a = i,c++;
    //     else if ( fre[i] ==1)b  =i , c++;
    //     else {
    //         if(a<0)a = i;
    //         if(b<0)b = i;
    //         c+=2;
    //     }
    // }

    unordered_set<int> a,b;

    fo(i,n){
        cin>>m;

        if(a.count(m)){
            b.insert(m);
        }else {
            a.insert(m);
        }
    }

    fo(i, 101)if(!a.count(i))break;

    int ans = i;

    fo(i,101)if(!b.count(i))break;

    ans +=i;

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

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

    int t = 1;
    cin >> t;
    
	if(t==0)cout<<1;
  else cout<<0;
    return 0;
}

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

int main() {
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    
    if(x >= r && y >= r && W >= (x+r) && H >= (y+r)) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
 using namespace std;
 int main() {
     int firstIn, secondIn,value,temp1,temp2;
     cin >> firstIn>> secondIn;
     temp1=firstIn%2;
     temp2=secondIn%2;

      if(temp1!=temp2)
        cout << "IMPOSSIBLE" << endl;
      else
      {
          value= (firstIn + secondIn) / 2;
          cout <<value<< endl;
      }

     return 0;
}


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

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

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

from collections import deque

def main():
	h,w=MI()
	ch,cw=MI()
	dh,dw=MI()
	ch+=1
	cw+=1
	dh+=1
	dw+=1

	S=[["#"]*(w+4)]
	S.append(["#"]*(w+4))
	for _ in range(h):
		S.append(["#"]*2+list(RD())+["#"]*2)
	S.append(["#"]*(w+4))
	S.append(["#"]*(w+4))

	#print(S)

	S[ch][cw]=0
	Q=deque()
	Q.append([0,ch,cw])


	d1=[(0,1),(0,-1),(-1,0),(1,0)]
	d2=[(i,j) for i in range(-2,3) for j in range(-2,3)]

	while Q:
		#print(Q)
		d,x,y=Q.popleft()

		for xx,yy in d1:
			if S[x+xx][y+yy]==".":
				S[x+xx][y+yy]=d
				Q.appendleft([d,x+xx,y+yy])
			elif S[x+xx][y+yy]=="#":
				continue
			elif S[x+xx][y+yy]>d:
				S[x+xx][y+yy]=d
				Q.appendleft([d,x+xx,y+yy])

		for xx,yy in d2:
			if S[x+xx][y+yy]==".":
				S[x+xx][y+yy]=d+1
				Q.append([d+1,x+xx,y+yy])
			elif S[x+xx][y+yy]=="#":
				continue
			elif S[x+xx][y+yy]>d+1:
				S[x+xx][y+yy]=d+1
				Q.appendleft([d+1,x+xx,y+yy])



	#print(S[2:-2])

	print(-1 if S[dh][dw]=="." else S[dh][dw])


if __name__ == "__main__":
	main()


Measured memory_bytes: 173020
import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;

class Main {
    static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static final PrintWriter pw = new PrintWriter(System.out);
    public static void main(String[] args) throws IOException {
        int num = Integer.parseInt(br.readLine());
        double ans = num * 2 * Math.PI;

        pw.println(ans);
        pw.flush();
    }
}

Measured memory_bytes: 33380
import copy
import heapq
import math
import fractions

def j(n):
    if n:print("Yes")
    else:print("No")
    exit(0)
rem = 10 ** 9 + 7

"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def ipmultiplerow(n):
    a = []
    for i in range(n):
        a.append(ip())
    return a
def printrow(a):
    for i in a:
        print(i)
def printlist(a):
    for i in range(len(a)-1):
        print(a[i],end = " ")
    print(a[-1])

a = input()
l = len(a)
s = [0 for i in range(len(a))]
ct = 0
intersect = 0
#print(l)
for i in range(l):
    if a[i] == 'L':
        ct+=1
        s[i] = intersect+ct%2
    else:
        ct = 0
        intersect = i
for i in range(l-1,-1,-1):
    if a[i] == 'R':
        ct += 1
        s[i] = intersect - ct % 2
    else:
        ct = 0
        intersect = i
#printlist(s)
b = [0 for i in range(l)]
for i in s:
    b[i]+=1
printlist(b)

Measured memory_bytes: 11084
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String line = reader.readLine();
		int n = Integer.parseInt(line);
		int ans = 0;
		int Acount = 0;
		int Bcount = 0;
		boolean[] Aflag  = new boolean[n];
		boolean[] Bflag = new boolean[n];
		boolean final_flag = false;
		for (int i = 0; i < n; i++) {
			String[] str = reader.readLine().split("");
			if (str[str.length-1].equals("A")) {
				Aflag[i] = true;
				Acount++;
			}
			if (str[0].equals("B")) {
				Bflag[i] = true;
				Bcount++;
			}
			for (int k = 0; k < str.length; k++) {
				if (str[k].equals("A") && k < str.length-1 && str[k+1].equals("B")) {
					ans++;
				}
			}
		}
		for (int i = 0; i < n; i++) {
			if ((Aflag[i] && !Bflag[i]) || (!Aflag[i] && Bflag[i])) {
				final_flag = true;
			}
		}
		if (final_flag) {
			ans += Math.min(Acount, Bcount);
		}
		else {
			ans += Math.max(Math.min(Acount, Bcount) - 1, 0);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 36948
n, m = map(int, input().split())

A = 0
B = 1
cnt = [0] * (n+1)
ab = []

for i in range(m):
    a,b = map(int, input().split())
    ab.append([a, b])
    if a == 1:
        cnt[b] += 1
    elif b == n:
        cnt[a] += 1

for i in range(n+1):
    if cnt[i] == 2:
        print("POSSIBLE")
        exit()

print("IMPOSSIBLE")

Measured memory_bytes: 75864
#include<iostream>
#include<fstream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
#include<set>
#include<map>
#include<bitset>
#include<ctime>
#include<queue>
using namespace std;
#define int long long
#define pii pair <int, int>
#define XX first
#define YY second

// constants:
const int mn = 200005;
const int mod = 1000000007;
const long long inf = 4444444444444444444;
const int sminf = 1111111111;
const bool is_multitest = 0;
const bool is_interactive = 0;

// i/o methods:
const bool input_from_file = 0;
const bool output_to_file = 0;
#define filename ""
#define in_extension "inp"
#define out_extension "out"

// data preprocessing: (e.g.: divisor generating, prime sieve)
void preprocess()
{
    
}

// global variables:
int n;
int A[mn];
int k;
// main solution goes here:
void execute(int test_number)
{
    cin>>n>>k;
    for (int i=1; i<=n; i++) cin>>A[i];
    for (int i=k+1; i<=n; i++) {
        if (A[i] > A[i-k]) cout<<"Yes\n";
        else cout<<"No\n";
    }
}
// REMEMBER TO CHOOSE TEST METHODS
// PLEASE REMOVE cout AND cerr DEBUG LINES BEFORE SUBMITTING PROBLEMS
// Solution by low_



















signed main()
{
#ifdef lowie
    if (!is_interactive)
    {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
#else
    if (input_from_file) freopen(filename"."in_extension, "r", stdin);
    if (output_to_file) freopen(filename"."out_extension, "w", stdout);
#endif
    if (!is_interactive)
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }

    preprocess();
    int ntest;
    if (is_multitest) cin >> ntest;
    else ntest = 1;

    for (int testno = 1; testno <= ntest; testno++)
    // use for instead of while to serve facebook hacker cup test format
    {
        execute(testno); // only start coding in this function, not in main
    }
}
// Template by low_
// Contact me via mail: ttuandung1803@gmail.com
// ...or codeforces: www.codeforces.com/profiles/low_
// ...or if you're interested in food: www.instagram.com/lowie.exe/

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

int main(int argc, const char * argv[]) {
    char in[101];
    int count=0,i,j,len;
    
    while(scanf("%s",in)!=EOF){
        len=strlen(in);
        i=0;
        j=len-1;
        while(1){
            //printf("%c %d %c %d\n",in[i],i,in[j],j);
            if(in[i]!=in[j]){
                break;
            }
            if(i>=j){
                count++;
                break;
            }
            i++;
            j--;
            //printf("%d %d\n",i,j);
        }
    }
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 1764
#include<bits/stdc++.h>
#define reps(i,j,k) for(int i=j;i<k;i++)
#define rep(i,j) reps(i,0,j)
#define fs first
#define sc second 

using namespace std;

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

int main(){
	int n,m,x,y;
	cin >> n >> m >> x >> y;
	int xx=-111, yy=111, t;
	rep(i,n){
		cin >> t;
		x = max(x, t);
	}
	rep(i,m){
		cin >> t;
		y = min(y, t);
	}
	cout << (x < y? "No War" : "War") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <cmath>
#include <random>
#include <cctype>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define MK make_pair
#define PB push_back
#define VI vector<int>
#define VII vector<int,int>
#define MSI map<string,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define W1 while(1);
const int MOD = 1000000007;
int main()
{
	string S;
	cin >> S;
	int i = 0;
	int j = S.size()-1;
	while (1)
	{
		if (S.at(i) == 'A')break;
		i++;
	}
	while (1)
	{
		if (S.at(j) == 'Z')break;
		j--;
	}
	cout << (j - i)+1 << endl;
	return 0;

}

Measured memory_bytes: 640
from collections import defaultdict
N = int(input())
twofive = defaultdict(int)
for i in range(N):
    a = round(float(input()) * (10**9))
    b = 0
    c = 0
    while a % 2 == 0 and b < 18:
        b += 1
        a //= 2
    while a % 5 == 0 and c < 18:
        c += 1
        a //= 5
    twofive[(b, c)] += 1
ans = 0
for b, c in twofive.keys():
    for d, e in twofive.keys():
        if b + d >= 18 and c + e >= 18:
            if (b, c) != (d, e):
                ans += twofive[(b, c)] * twofive[(d, e)]
            else:
                ans += twofive[(b, c)] * (twofive[(b, c)] - 1)
print(ans//2)


Measured memory_bytes: 71012
#include <stdio.h>

int main(void)
{
int n, m, l, i, j, k;
long int A[101][101];
long int B[101][101];
long int C[101][101];

scanf("%d %d %d", &n, &m, &l);

for(i = 0;i < n; i++){
 for(j = 0; j < m; j++)
  scanf("%ld", &A[i][j]);
}

for(i = 0;i < m; i++){
 for(j = 0; j < l; j++)
  scanf("%ld", &B[i][j]);
}

for(i = 0;i < n; i++){
 for(j = 0; j < l; j++)
  C[i][j] = 0;
}

for(i = 0;i < n; i++){
 for(j = 0; j < l; j++){
  for(k = 0; k < m; k++)
   C[i][j] += A[i][k] * B[k][j];

 if(j != l-1)
   printf("%ld ", C[i][j]);
 else
   printf("%ld", C[i][j]);
 }
 printf("\n");
}


return 0;

}




Measured memory_bytes: 2100
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long

using namespace __gnu_pbds;
using namespace std;

template <class T> using oset = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

void usaco(string name = "")
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(name.size())
    {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}

int main()
{
    usaco();
    ll n, k, ans = -1;
    cin >> n >> k;
    vector <vector <ll>> dp(n+1, vector <ll> (100001, 1e18));
    vector <ll> w(n), v(n);
    for (ll i = 0; i < n; ++i) cin >> w[i] >> v[i];
    dp[0][0] = 0;
    for (ll i = 1; i <= n; ++i)
    {
        for (ll j = 0; j < 100001; ++j)
        {
            dp[i][j] = min(dp[i-1][j], dp[i][j]);
            if (j >= v[i-1]) dp[i][j] = min(dp[i][j], dp[i-1][j-v[i-1]]+w[i-1]);
        }
    }
    for (ll i = 0; i <= 1e5; ++i)
        if (dp[n][i] <= k)
            ans = i;
    cout << ans << '\n';
}


Measured memory_bytes: 83132
#include <iostream>
#include <string>
#include <algorithm>
#define N 90
using namespace std;

typedef long long ll;

int main()
{
	int n;
	cin >> n;
	ll L[N];
	L[0] = 2;
	L[1] = 1;
	for (int i = 2; i < 88; i++)
		L[i] = L[i - 1] + L[i - 2];
	cout << L[n];
	string str;
	//cin >> str;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<n;i++)
#define rep2(i,k,n) for(int i=k;i<=n;i++)
#define EPS 10e-8
typedef long long ll;
using namespace std;
int main()
{
    int N,H,W;
    cin >> N >> H >> W;
    ll ans=0;
    rep(i,0,N){
        int A,B;
        cin >> A >> B;
        if(A>=H&&B>=W){++ans;}
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N,A,B=map(int,input().split())
S=list(input())
yesno=[]
a=0
b=0
c=1
for i in range(N):
    if S[i]=='a':
        if a+b<A+B:
            yesno.append('Yes')
            a+=1
        else:
            yesno.append('No')
    elif S[i]=='b':
        if a+b<A+B and c<=B:
            yesno.append('Yes')
            b+=1
            c+=1
        else:
            yesno.append('No')
    else:
        yesno.append('No')
for i in range(N):
    print(yesno[i])

Measured memory_bytes: 84256
n = int(input())
ans = 0
for i in range(8, n+1):
    #8回割れるかどうか
    divisor_cnt = 0
    for j in range(1, n+1):
        if i % j == 0 and j % 2 == 1:
            divisor_cnt += 1
    if divisor_cnt == 8:
        ans += 1
print(ans)



Measured memory_bytes: 9164
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            list.add(sc.nextInt());
        }
        int k = sc.nextInt();
        int max = Collections.max(list);
        for (int i = 0; i < k; i++) {
            max *= 2;
        }
        Collections.sort(list);
        max += list.get(0);
        max += list.get(1);
        System.out.println(max);
    }
}

Measured memory_bytes: 35652
/**
 *    author:  [itmo] enot.1.10
 *    created: 01.10.2016 15:02:03       
**/
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),a.end()
#define pw(x) (1LL<<(x))

using namespace std;

typedef long long ll;
typedef double dbl;
typedef vector<int> vi;
typedef pair<int, int> pi;

const int inf = 1.01e9;
const dbl eps = 1e-9;

/* --- main part --- */

const int N = 1 << 18;

int a[N];

pi t[2 * N];

inline pi get(int l, int r)
{
    l += N;
    r += N;
    pi res = t[l];
    while (l <= r)
    {
        if ((l & 1) == 1) res = min(res, t[l]);
        if ((r & 1) == 0) res = min(res, t[r]);
        l = (l + 1) >> 1;
        r = (r - 1) >> 1;
    }
    return res;
}

ll res = 0;

void go(int l, int r)
{
    if (l > r) return;
    int m = get(l, r).S;
    res += (m - l + 1) * (ll)(r - m + 1) * a[m];
    go(l, m - 1);
    go(m + 1, r);
}
    

int main()
{
    #ifdef home
        assert(freopen("1.in", "r", stdin));
        assert(freopen("1.out", "w", stdout));
    #endif
    int n;
    scanf("%d", &n);
    forn(i, n) scanf("%d", a + i);
    forn(i, n) t[i + N] = {a[i], i};
    for (int i = N - 1; i > 0; --i) t[i] = min(t[2 * i], t[2 * i + 1]);
    go(0, n - 1);
    printf("%lld\n", res);
    
    #ifdef home
        eprintf("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
    #endif
    return 0;
}


Measured memory_bytes: 13952
// C++ includes
#include <bits/stdc++.h>
// 俳句
using namespace std;

// alias templates
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

// alias declaration
using ll = long long;
using str = string;

using vll = V<ll>;
using vvll = V<vll>;
using vs = V<str>;

// loops
#define FOR(i, a, b)  for (ll i = (a); i <= (ll)(b); i++) // [a,b]
#define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) // [b,a]
#define REP(i, a) FOR((i), 0, (ll)(a)-1) // [0,a-1]

// for debug
#define dbg(a) cerr << "  " << (#a) << ": " << (a) << "\n";

// procon common constants
const ll MOD_BIG = 1e9 + 7;

int main(void){
    ll h, n, s;
    cin >> h >> n;
    vll a(n);
    s=0;
    REP(i,n){
        cin >> a[i];
        s += a[i];
    }


    if(h <= s){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	int N, M;
	int ans = 0;
	vector<int> H;
	vector<vector<int>> G;
	
	cin>>N>>M;
	
	H.resize(N);
	G.resize(N);
	
	
	for(int i = 0; i < N; i++){
		cin>>H[i];
	}
	
	for(int i = 0; i < M; i++){
		int A, B;
		
		cin>>A>>B;
		
		A--, B--;
		
		G[A].push_back(B);
		G[B].push_back(A);
	}
	
	for(int i = 0; i < N; i++){
		int maxi = -1;
		
		for(int y : G[i]){
			maxi = max(maxi, H[y]);
		}
		
		if(maxi < H[i]) ans++;
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 9800
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    int n,l;
    while(cin>>n>>l)
    {
        string s[105];
        int a[105];
        for(int i = 0 ; i < n ; i++ )
            cin>>s[i];
        sort(s+0,s+n);
       /* for(int i=0;i<n;i++)
             cout<<s[i]<<endl;*/
        for(int j = 0;j < n;j++ )
            cout<<s[j];
        cout<<endl;

    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {

        Scanner s = new Scanner(System.in);

        int n =s.nextInt();
        long sum=0;

        for(int i=1;i<=n;i++){
            if(i%3!=0 && i%5!=0){
                sum=sum+i;
            }
        }

        System.out.println(sum);

    }
}






Measured memory_bytes: 35604
#include <cstdio>

int n,ice[10];

int main(){
	while(scanf("%d", &n),n){
		for(int i = 0; i < 10; i++) ice[i] = 0;
		for(int i = 0; i < n; i++){
			int x; scanf("%d", &x);
			ice[x]++;
		}
		for(int i = 0; i < 10; i++){
			if(ice[i] == 0) printf("-\n");
			else{
				for(int j = 0; j < ice[i]; j++) printf("*");
				printf("\n");
			}
		}
	}
}

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

bool isPrime(ll num){
	if(num==2)
		return true;
	ll sq=ceil(sqrt(num));
	for(ll j=2;j<=sq;j++){
		if(num%j==0){
			return false;
		}
	}
	return true;
	
}

int main(){
	ll a,i;
	bool found=false;
	cin>>a;
	assert(a>=2 && a<=100000);
	
	i=a;
	while(!found){
		if(isPrime(i)){
			cout<<i<<endl;
			break;
		}
		else
			i++;	
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int N;
  int ans = 0;
    // スペース区切りの整数の入力
    scanf("%d",&N);
    int i,t;
	for(i=1;i<10;i++){    
		for(t=i;t<10;t++){
          ans = i*t;
          if(N == ans){
			printf("Yes");
            return 0;
          }
   		 }
	}
  
    printf("No");//printf("%c",s[0])//文字一つ分のみを出力
    
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define pb push_back
#define Int long long
using namespace std;

const int MAXN=500005;
const long MOD=(long)(1e9+7);
vector<int> adj[MAXN];
vector<pair<int,int>> G[MAXN];

Int N,M,K;
Int B,C,H,W;
Int X,Y,Z;
vector<Int> A;

Int ceilS(Int x,Int y){
    return (x+y-1)/y;
}
using D=long double;

Int perform(Int x){
    return (x*(x+1))/2LL;
}

int main()
{
        cin>>N;
        A.resize(N);
        map<Int,Int> mp;
        for(auto &x:A) cin>>x,++mp[x];
        Int primeS=*min_element(A.begin(),A.end());
        Int primeL=*max_element(A.begin(),A.end());
        Int best=0;
        for(int i=primeS;i<primeL+1;++i){
            best=max(best,mp[i-1]+mp[i]+mp[i+1]);
        }
        cout<<best<<"\n";
        
        
}

Measured memory_bytes: 33432
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30

using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,P> PP;

int f[55][55];
int c[4];
int h,w,ans = -1;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
bool memo[55][55][4];

bool can(int y,int x) {
    if(0 <= y && y < h && 0 <= x && x < w) return true;
    return false;
}

void func() {
    priority_queue<PP,vector<PP>,greater<PP> > que;
    que.push(PP(P(0,0),P(0,0)));
    
    memset(memo,0,sizeof(memo));

    while(que.size()) {
        PP p = que.top();
        que.pop();

        int cost = p.first.first;
        int d = p.first.second;
        int y = p.second.first;
        int x = p.second.second;

        if(y == h-1 && x == w-1) {
            ans = cost;
            break;
        }

        if(memo[y][x][d]) continue;
        memo[y][x][d] = true;

        rep(i,4)
        {
            int nd = (d+i)%4;
            int ny = y + dy[nd];
            int nx = x + dx[nd];

            if(can(ny,nx)) {
                if(f[y][x] == i) {
                    que.push(PP(P(cost,nd),P(ny,nx)));
                }
                else {
                    que.push(PP(P(cost+c[i],nd),P(ny,nx)));
                }
            }
        }
    }
}
int main() {
    
    while(cin >> w >> h) {
        if(w == 0 && h == 0) break;
        
        memset(f,0,sizeof(f));
        rep(i,h) {
            rep(j,w) {
                cin >> f[i][j];
            }
        }

        rep(i,4) cin >> c[i];

        func();
        cout << ans << endl;
    }

    return 0;
}

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

int main(){
	/*input*/
	int x;	cin >> x;
	/*calculation*/
	int ans = 1;
	for(int b = 2; pow(b, 2) <= x; b++){
		for(int p = 2; pow(b, p) <= x; p++){
			int tmp = pow(b, p);
			if(ans < tmp)ans = tmp;
		}
	}
	/*output*/
	cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

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

    int* A = new int[N];
    int sum = 0;

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

    int count = 0;
    for (int i = 0; i < N; i++)
    {
        double pomer = (double)A[i] / (double)sum;
        if ( pomer >= 1.0 / (4.0 * (double)M))
            count++;
    }

    if (count>=M)
        cout << "Yes";
    else
        cout << "No";


    return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

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; }

template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;

int main() {
	string n;
	cin >> n;
	switch (n[n.size() - 1]) {
	case '2':
	case '4':
	case '5':
	case '7':
	case '9':
		cout << "hon" << endl;
		break;
	case '0':
	case '1':
	case '6':
	case '8':
		cout << "pon" << endl;
		break;
	case '3':
		cout << "bon" << endl;
		break;
	}
	return 0;
}

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

template <typename T> void chmin(T &x,const T &y)
{
	if(x>y)x=y;
}
typedef long long s64;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
const int N=2000+5;
s64 f(s64 x,s64 y)
{
	s64 ans=0;
	while(x)
	{
		s64 _y=y%x;
		ans+=(y-_y)*2;
		y=x;x=_y;
	}
	return ans-y;
}
int n,k;
vector<int>lk[N];
int dp[N][N];

void dfs(int x,int fr)
{
	dp[x][0]=1;
	for(auto y:lk[x])
	if(y!=fr)
	{
		dfs(y,x);
		dp[x][0]+=dp[y][0];
		per(j,k,1)
			dp[x][j]=min(dp[y][j-1]+dp[x][min(j,k-(j-1))],dp[x][j]+dp[y][min(j-1,k-j)]);
		rep(j,1,k)chmin(dp[x][j],dp[x][j-1]);
	}
}

int main()
{
	//freopen("1.in","r",stdin);
	cin>>n>>k;
	rep(i,1,n-1)
	{
		int x,y;
		cin>>x>>y;
		lk[x].push_back(y);
		lk[y].push_back(x);
	}
	++k;
	dfs(1,0);
	int ans=dp[1][k];
	rep(i,1,n)chmin(ans,dp[i][k]+n-dp[i][0]);
	cout<<ans<<endl;
}

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

#define rep(i, n) for(int i = 0; i < n; i++)

typedef long long ll;
using namespace std;
int mod = 1000000007;

struct edge{
    int no;
    int to;
    edge(int n, int t){
        no = n;
        to = t;
    }
};

bitset<50> S[20];
vector<edge> nodes[50];

bool dfs(int idx, int p, int s, int goal){
    if(s == goal) return true;
    bool ret = false;
    rep(i, nodes[s].size()){
        int to = nodes[s][i].to;
        int edge_no = nodes[s][i].no;
        if(to == p) continue;
        bool temp = dfs(idx, s, to, goal); //goalがtoを選択した先にあるか
        if(temp) S[idx].set(edge_no);
        ret |= temp;
    }
    return ret;
}

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

    int N; cin >> N;
    rep(i, N-1){
        int a, b; cin >> a >> b;
        nodes[a-1].push_back(edge(i, b-1));
        nodes[b-1].push_back(edge(i, a-1));
    }

    int M; cin >> M;
    rep(i, M){
        int u, v; cin >> u >> v;
        u--; v--;
        //uからvに行く経路で使った辺をS[i]にぶっこむ
        dfs(i, -1, u, v);
    }

    ll ans = (1ll << (N-1));
    int bs_size = (1 << M);
    vector<bitset<50>> bs(bs_size);
    vector<int> bt(bs_size); //bt[i]: iの立っている最上位ビット
    for(int i = 1; i < bs_size; i++) bt[i] = floor(log2(i));
    for(int i = 1; i < bs_size; i++){
        int num_stand = __builtin_popcount(i);
        bs[i] = S[bt[i]] | bs[i - (1 << bt[i])];
        ll inc = (1ll << (N-1-bs[i].count()));
        if(num_stand % 2) ans -= inc;
        else ans += inc;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12800
import java.util.Scanner;

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

		int num1 = Integer.valueOf(inputSplit[0]);
		int num2 = Integer.valueOf(inputSplit[2]);
		int ans = 0;

		if (inputSplit[1].equals("+")) {
			ans = num1 + num2;
		} else {
			ans = num1 - num2;
		}

		System.out.println(ans);
	}
}

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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(ll i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

const ll inf = 1ll<<62;
const ll mod = 1e9+7;

int main(){
#define int ll
  int n,m,d; cin >> n >> m >> d;
  double a,b = pow(n,2);
  if(d == 0)
    a = ((double)m - 1) * (double)n;
  else if(d < n)
    a = ((double)m - 1) * ((double)n - d) * 2;
  else
    a = 0;
  printf("%.10f\n",a/b);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string a,b;
int n,m;
int t[3003][3003];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>a>>b;
	n=a.size();
	m=b.size();
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(a[i-1]==b[j-1]){
				t[i][j]=t[i-1][j-1]+1;
			}
			else{
				t[i][j]=max(t[i-1][j],t[i][j-1]);
			}
		}
	}
	stack<char>wyp;
	while(t[n][m]!=0){
			if(a[n-1]==b[m-1]){
				wyp.push(a[n-1]);
				n--;
				m--;
			}
			else{
				if(t[n-1][m]>t[n][m-1]){
					n--;
				}
				else{
					m--;
				}
			}
		}
	while(!wyp.empty()){
		cout<<wyp.top();
		wyp.pop();
	}
	return 0;
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

int main() {
    int N;
    string S, S1, S2;
    cin >> S;

    N = S.length();
    S1 = S; S2 = S;
    if (S2[0] == '0') S2[0] = '1';
    else S2[0] = '0';

    int res = 0, pos = 1, ans;
    REP(i, N-1){
        if (S1[i] == S1[i+1]){
            res++;
            if (S1[i+1] == '0') S1[i+1] = '1';
            else S1[i+1] = '0';
        }
    }

    REP(i, N-1){
        if (S2[i] == S2[i+1]){
            pos++;
            if (S2[i+1] == '0') S2[i+1] = '1';
            else S2[i+1] = '0';
        }
    }

    ans = min(res, pos);
    cout << ans << endl;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    int n; cin >> n;
    vll a(n), b(n);
    ll tota = 0;
    ll totb = 0;
    ll cnt1 = 0;
    ll cnt2 = 0;
    
    rep(i, n) {
        cin >> a[i];
        tota += a[i];
    }
    rep(i, n) {
        cin >> b[i];
        if(a[i] > b[i]) cnt1 += a[i] - b[i];
        else cnt2 += (b[i] - a[i])/2;
        totb += b[i];
    }
    
    // cout << tota << " " << totb << endl;
    // cout << cnt1 << " " << cnt2 << endl;
    if( cnt1 > cnt2 ) cout << "No" << endl;
    else cout << "Yes" << endl;
    
    return;
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
typedef long long ll;
typedef long int lint;
typedef vector<char> vchar;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
#define vsort(v) sort((v).begin(), (v).end())
#define vrsort(v) sort((v).rbegin(), (v).rend())
#define vreverse(v) reverse((v).begin(), (v).end())
#define pb(a) push_back(a)
#define INF 2000000009
#define MOD 1000000007
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //input
  ll i,n,a,b,sz;string s;cin>>n>>a>>b>>s;sz=s.size();
  //caricurate
  ll allyosen=0;ll kaigaiyosen=0;
  for(i=0;i<sz;i++){
   if(s.at(i) =='a'){
    if(allyosen<(a+b)){
     cout<<"Yes"<<endl;allyosen++;continue;
    }else{
     cout<<"No"<<endl;continue;
    }
   }else if(s.at(i) =='b'){
    if((kaigaiyosen<b)&&(allyosen<(a+b))){
     cout<<"Yes"<<endl;allyosen++;kaigaiyosen++;continue;
    }else{
     cout<<"No"<<endl;
    }
   }else{
     cout<<"No"<<endl;
   }
  }
}

Measured memory_bytes: 848
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
#define rep(src,dst)    for(int i=src; i<dst;  i++)
#define rep2(src,dst)   for(int j=src; j<dst;  j++)
#define INF 1000000000000 //1e+12
#define MOD 10000007 //1e9+7
#define PI  acos(-1)
#define ll long long
template<typename T> inline void cMin(T* a, T* b)  {if(*a>*b) *a=*b;}
template<typename T> inline void chMax(T* a, T* b) {if(*a<*b) *a=*b;}
template<typename T> inline int  divUp(T a, T b)   {return ((a+b-1)/b);}
template<typename T> inline bool isEven(T a)       {return (a%2==0? true : false );}

int main(){
    int n; cin >> n;
    int ecnt=0;
    vector<int> even(n);
    rep(0,n){
        int a;
        cin >> a;
        if(!(a&1))  even[ecnt++] = a;
    }
    rep(0,ecnt){
        if(!(even[i]%3==0 || even[i]%5==0)){
            cout << "DENIED" << endl;
            return 0;
        }
    }
    cout << "APPROVED" << endl;
    return 0;
}
/*

*/


Measured memory_bytes: 3600
#include <iostream>
#include <map>

using namespace std;

int main(){
    int array[5];
    for(int i = 1;i <= 4;i++){
        array[i] = 0;
    }
    for(int i = 0;i < 3;i++){
        int a,b;
        cin >> a >> b;
        array[a]++;
        array[b]++;
    }
    for(int i = 1;i <= 4;i++){
        if(array[i] >= 3){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;

int main(){
	int N,M;
	cin >> N >> M;
	if(N<10&&N>0){
		if(M<10&&M>0){
			cout << N * M << endl;
		}
		else cout << -1;
	}
	else cout << -1;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+1;
int n,a[N],l,r;
int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
    while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}
int c1(int x,int y,int z){return x>z&&y>z;}
int c2(int x,int y,int z){return x<=z&&y<=z;}
int check(int k){int p=n>>1;++p;
	for(int i=0;i<(n>>1);i++){
		if(c1(a[p+i],a[p+i+1],k)||c1(a[p-i],a[p-i-1],k)) return 0;
		if(c2(a[p+i],a[p+i+1],k)||c2(a[p-i],a[p-i-1],k)) return 1;
	}return a[1]<=k;
}
int main(){
	n=read();n=n<<1;n--;
	for(int i=1;i<=n;i++)
		a[i]=read(),r=max(r,a[i]);
	while(l<r){
		int mid=l+r>>1;
		if(check(mid)) r=mid;
		else l=mid+1;
	}printf("%d\n",r);
	return 0;
}
/*
  5
  1 9 2 3 6
*/


Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define pb push_back

ll power(int x, unsigned int y){
    ll res = 1;
    while(y > 0){
        if(y & 1) res = res * x;
        y >>= 1;
        x *= x;
    }
    return res;
}

// Check for number of Cases!!
void solve() {
    
    int n; cin >> n;

    int arr[n];

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

    ll ans = 0;

    for(int i = 1; i < n; i++) {
        if(arr[i] < arr[i-1]) {
            ans += arr[i-1] - arr[i];
            arr[i] = arr[i-1];
        }
    }

    cout << ans << '\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int t = 1;
    // cin >> t;
    while(t--) {
      solve();
    }
}

Measured memory_bytes: 4432
def search(u, g, visited):
	if visited[u]:
		return
	visited[u] = True
	for v in g[u]:
		search(v, g, visited)

def resolve():
	n, m = map(int, input().split())
	edges = [list(map(int, input().split())) for _ in range(m)]
	ans = 0
	for i in range(m):
		g = [[] for _ in range(n)]
		for j in range(m):
			if i == j:
				continue
			a, b = edges[j]
			g[a-1].append(b-1)
			g[b-1].append(a-1)
		visited = [False]*n
		search(0, g, visited)
		if visited.count(True) != n:
			ans += 1
	print(ans)
resolve()

Measured memory_bytes: 68876
#include <stdio.h>

    int checar_palindromo (int n){
    int t, inverso=0;

    t=n;

    while (t != 0){
        inverso= inverso*10;
        inverso= inverso + t%10;
        t=t/10;
    }
    if (n==inverso){
        return 1;
    } else{
        return 0;
    }
}
int main (){
    int a, b, i;
    int totalpalin =0;

    scanf ("%d", &a);
    scanf ("%d", &b);

for (i=a; i<=b; i++){
    if (checar_palindromo(i)){
        totalpalin++;
    }
}

printf("%d", totalpalin);

return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int x,y; cin>>x>>y;
	for (int a=0; a<=100; a++) {
	for (int b=0; b<=100; b++)
		if (a+b==x&&2*a+4*b==y) {
			cout<<"Yes";
			return 0;	
		}
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3644
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
using namespace std;

typedef long long ll;
const ll N = 1e5 + 10;
ll p[N], s[N], ans[N];
ll sum, n, m;
int x[N], y[N];

pair <ll, ll> pairs[N];

int find(int x) {
	return (p[x] == x ? x : p[x] = find(p[x]));
}

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

	for (int i = 1; i <= n; i++) {
		p[i] = i;
		s[i] = 1;
	}

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

	sum = 1LL * n*(n - 1) / 2;
	for (int i = m - 1; i >= 0; i--) {
		ans[i] = sum;
		int x = pairs[i].first, y = pairs[i].second;
		x = find(x), y = find(y);

		if (x != y) {
			p[y] = x;
			sum -= s[x] * s[y];
			s[x] += s[y];
		}
	}

	for (int i = 0; i < m; i++)
		cout << ans[i] << endl;

	return 0;
}

Measured memory_bytes: 5504
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>//pair
#include<cmath>//abs,sqrt
#include<cstring>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
const int INF=1e+9;
const ll INFLL=1e+17;
int n;
ll a[200010];
ll sum[200010];
void add(){
  sum[0]=0;
  rep1(i,n){
    sum[i]=sum[i-1]+a[i-1];
  }
}
ll solve(){
  ll res,res1=0,res2=0;
  ll x=0;
  add();
  rep1(i,n){
    ll s=sum[i]+x;
    if(i%2==1&&s<=0){
      x=x-s+1;
      res1=res1-s+1;
    }
    else if(i%2==0&&s>=0){
      x=x-s-1;
      res1=res1+s+1;
    }
  }
  x=0;
  rep1(i,n){
    ll s=sum[i]+x;
    if(i%2==0&&s<=0){
      x=x-s+1;
      res2=res2-s+1;
    }
    else if(i%2==1&&s>=0){
      x=x-s-1;
      res2=res2+s+1;
    }
  }
  res=min(res1,res2);
  return res;
}
int main(){
  cin>>n;
  rep(i,n) cin>>a[i];
  prin(solve());
  return 0;
}


Measured memory_bytes: 1792
n = int(input())
alist =list(map(int,input().split()))
blist =list(map(int,input().split()))
clist =list(map(int,input().split()))
cscore =0
for i in range(n-1):
   if alist[i+1]==alist[i]+1:
      cscore =cscore+clist[alist[i]-1]
print(sum(blist)+cscore)





Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
long long  n,k,*p,*dp;
    cin>>n;
    cin>>k;
    p=new long long[n];
    for(long long y=0;y<n;y++){
        cin>>p[y];
    }
    dp=new long long[n];
    dp[0]=0;
    dp[1]=abs(p[1]-p[0]);
    for(long long i=2;i<n;i++){
        long long minimo=dp[i-1]+abs(p[i]-p[i-1]);
        for(long long t=1;t<min(i,k);t++){ 
               minimo=min(minimo,dp[i-(t+1)]+abs(p[i]-p[i-(t+1)]));
        }
        dp[i]=minimo;}
    cout<<dp[n-1];
    
    delete[]p;
    delete[]dp;
    return 0;
}

Measured memory_bytes: 1792
n = int(input())
a = list(map(int, input().split()))
c = 0
d = 0
for i in range(n):
    if a[i]%2==0:
        d += 1
        if a[i]%3==0 or a[i]%5==0:
            c += 1
    else:
        continue
if c == d:
    print("APPROVED")
else:
    print("DENIED")

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

using ll = long long;
using vi = vector<int>;
using pii = pair<int,int>;
#define f(i,a,b) for (int i = a; i < b; i++)
#define pb push_back

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	clock_t start = clock();
#endif

	int n;
	cin>>n;
	vi adj[n];
	int a[n],b[n],c[n];
	f(i,0,n-1) {
		cin>>a[i]>>b[i]>>c[i];
		adj[--a[i]].pb(i);
		adj[--b[i]].pb(i);
	}
	int subsz[n];
	ll ans = 0;
	function<int(int,int)> dfssubsz = [&](int v, int e) {
		subsz[v] = 1;
		for (int ee : adj[v]) if (ee != e) {
			int w = a[ee]^b[ee]^v;	
			subsz[v] += dfssubsz(w,ee);
		}
		if (e != -1) ans += 2LL*c[e]*min(subsz[v],n-subsz[v]);
		return subsz[v];
	};
	function<pii(int,int)> dfscentroid = [&](int v, int e) {
		for (int ee : adj[v]) {			
			int w = a[ee]^b[ee]^v;
			if (ee != e && subsz[w]*2>=n)
				return dfscentroid(w,ee);
		}
		return pii(v,e); 
	};
	dfssubsz(0,-1);
	pii res = dfscentroid(0,-1);
	int centroid = res.first, e = res.second;
	if (subsz[centroid]*2 == n)
		ans -= c[e];
	else {
		int lo = 1e9;
		for (int ee : adj[centroid])
			lo = min(lo,c[ee]);
		ans -= lo;
	}
	cout << ans << endl;

#ifdef LOCAL
	cout << setprecision(12) << (long double)(clock()-start) / CLOCKS_PER_SEC << endl;
#endif
	
	return 0;
}



Measured memory_bytes: 15232
import math

N = int(input())

factors = []
d = math.floor(N**(1/2))
for i in range(1,d+1):
	if N%i==0:
		factors.append(i)
		factors.append(N//i)

ans = 0
for f in factors:
	if f == 1:
		continue
	s,t = divmod(N,f-1)
	if s == t:
		ans += f-1

print(ans)

Measured memory_bytes: 3276