akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define int long long int
using namespace std;

void desperate_optimization(bool submitting=true,int precision=10)
{
  if(!submitting) return;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios::fixed);
  cout.setf(ios::showpoint);
  cout.precision(precision);
}
int heights[100005];
int n;
int memo[100005];
int dpfunction(int startingindex)
{
  if(memo[startingindex]!=-1) return memo[startingindex];
  if(startingindex==n-1) {memo[startingindex]=0; return memo[startingindex];}
  int answer=(abs(heights[startingindex]-heights[startingindex+1])+dpfunction(startingindex+1));
  if(startingindex<n-2) answer=min(answer,abs(heights[startingindex]-heights[startingindex+2])+dpfunction(startingindex+2));
  return memo[startingindex]=answer;
}
int32_t main()
{
  desperate_optimization(false);
  //freopen("input.txt","r",stdin);
  memset(memo,-1,sizeof(memo));
  cin>>n;
  for(int i=0;i<n;i++) cin>>heights[i];
  cout<<dpfunction(0);

  return 0;
}

Measured memory_bytes: 4096
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] v = new int[n];
            for (int i = 0; i < n; ++i) v[i] = in.nextInt();
            Arrays.sort(v);
            int[] res = new int[2];
            int r = 0;
            for (int i = n - 2; i >= 0; i--) {
                if (r == 2) continue;
                if (v[i] == v[i + 1]) {
                    res[r] = v[i];
                    ++r;
                    --i;
                }
            }
            out.println((long) res[0] * res[1]);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 36192
#include <bits/stdc++.h>
using namespace std;
int n, k;
int sol[100010], h[100010];

int main() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> h[i], sol[i] = 2000000000;

    sol[1] = 0;
    for (int i = 1; i <= n; i++)
        for (int j = i + 1; j <= min(n, i + k); j++)
            sol[j] = min(sol[j], sol[i] + abs(h[i] - h[j]));

    cout << sol[n];
    return 0;
}





Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}


int main()
{
  int n, k ;
  cin >> n >> k ;
  vint hei(n) ;
  int ans = INF ;
  int hoge ;
  
  REP(i,n){
    cin >> hei.at(i) ;
  }
  
  sort(ALL(hei)) ;
  
  REP(i,n-k+1){
    hoge = hei.at(i+k-1) - hei.at(i) ;
    ans = min(ans,hoge) ;
  }
  
  cout << ans <<endl ;


  return 0 ;
}

Measured memory_bytes: 768
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>

int main(void){
    int n;
    scanf("%d",&n);
    if (n<1200){
        printf("ABC\n");
    } else if (n<2800){
        printf("ARC\n");
    } else {
        printf("AGC\n");
    }
	return 0 ;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
using namespace std;
//int main()
//{
//    int a,b;
//    while(~scanf("%d%d",&a,&b))
//    {
//        printf("%d\n",a*a-b);
//    }
//
//}
int main()
{
    int a;
    while(~scanf("%d",&a))
    {
        int a1=a/10;
        int a2=a%10;
        if(a2==9||a1==9)
        {
            printf("Yes\n");
        }
        else
        {
            printf("No\n");
        }
    }
}

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

int main(){
  long long i,N,M,p,wa,ac;
  string s;
  cin>>N>>M;
  ac=wa=0;
  vector<long long> vec(N+1,0);
  vector<long long> vec_wa(N+1,0);

  for(i=0;i<M;i++){
    cin>>p>>s;  
    if(vec.at(p)!=0) continue;
    if(s=="AC"){
      ac++;
      wa+=vec_wa.at(p);
      vec.at(p)=1;
    }
    else{
      vec_wa.at(p)++;
    }
  }
  cout<<ac<<" "<<wa;
}

Measured memory_bytes: 1792
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        String[] line = new Scanner(System.in).nextLine().split(" ", 2);
        int a = Integer.parseInt(line[0]);
        int b = Integer.parseInt(line[1]);

        if ((a * b) % 2 == 0) {
            System.out.println("Even");
        } else {
            System.out.println("Odd");
        }
    }
}


Measured memory_bytes: 21076
import math

n, m = map(int, input().split())

diff = abs(n - m)

if diff > 1:
    print(0)
    exit()

if diff == 1:
    print(math.factorial(n) * math.factorial(m) % (10 ** 9 + 7))
else:
    print(math.factorial(n) * math.factorial(m) * 2 % (10 ** 9 + 7))


Measured memory_bytes: 5184
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int n;
long long ansCount;

int main()
{
	ansCount = 0;
	
	scanf("%d", &n);
	for (int i = 1 ; i < n ; i++) {
		int a = i;
		int b = n / a;
		if (n % a == 0) b--;
		
		if (b > a) {
			ansCount = ansCount + (b - a) * 2;
		}
		if (b >= a) {
			ansCount = ansCount + 1;
		}
	}
	
	
	printf("%d\n", ansCount);
	
	return 0;
}




Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int H,W,N;
    cin>>H>>W>>N;
    int a=max(H,W);
    if(N%a==0) cout<<N/a<<endl;
    else cout<<N/a+1<<endl;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    int X, Y, Z, K;
    scan(X, Y, Z, K);
    auto a = readln.split.to!(long[]).sort();
    auto b = readln.split.to!(long[]).sort();
    auto c = readln.split.to!(long[]).sort();

    alias Cake = Tuple!(long, "v", int, "i", int, "j", int, "k");

    auto bh = new BinaryHeap!(Array!Cake, "a.v < b.v")();
    foreach (i ; 0 .. X) {
        foreach (j ; 0 .. Y) {
            bh.insert(Cake(a[i] + b[j] + c[$ - 1], i, j, Z - 1));
        }
    }

    foreach (_ ; 0 .. K) {
        auto ck = bh.front;
        bh.popFront();
        writeln(ck.v);

        int i = ck.i, j = ck.j, k = ck.k;
        if (k > 0) {
            bh.insert(Cake(a[i] + b[j] + c[k - 1], i, j, k - 1));
        }
    }
}



void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll n,k,s;

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

  cin>>n>>k>>s;
  vector<ll> sums(n+1,0);

  repl(i,1,n+1){
  	if(k>0){
  		sums[i]=sums[i-1]+s;
  		k--;
  	}else{
  		if(s==1e9) sums[i]=sums[i-1]+s-1;
  		else sums[i]=sums[i-1]+s+1;
  	}
  }
  rep(i,n){
  	cout<<sums[i+1]-sums[i]<<" ";
  }
  cout<<endl;

  return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;

const i64 MOD = 1e9 + 7;

struct int_m {
    static int64_t mod;
    int64_t v;
    int_m() {}
    int_m(int64_t x) : v(x) {}
    int_m operator+(const int_m &y) { return (v + y.v) % mod; }
    int_m operator-(const int_m &y) { return (v - y.v + mod) % mod; }
    int_m operator*(const int_m &y) { return (v * y.v) % mod; }
    void operator+=(const int_m &y) { *this = *this + y; }
    void operator-=(const int_m &y) { *this = *this - y; }
    void operator*=(const int_m &y) { *this = *this * y; }
    friend istream &operator>>(istream &ist, int_m &m) { return ist >> m.v; }
    friend ostream &operator<<(ostream &ost, int_m &m) { return ost << m.v; }
};

int64_t int_m::mod = MOD;

int main() {
    int H, W, K;
    cin >> H >> W >> K;

    vector<int_m> fib(W + 5, 0);
    fib[1] = 1;
    for(int i = 0; i < W; i++) {
        fib[i + 2] = fib[i + 1] + fib[i];
    }

    vector<int_m> dp[2] = {vector<int_m>(W), vector<int_m>(W)};
    dp[0][0] = 1;
    for(int y = 0; y < H; y++) {
        int b = y & 1;
        for(int x = 0; x < W; x++) {
            dp[1 - b][x] = dp[b][x] * fib[x + 1] * fib[W - x];
            if(x > 0) {
                dp[1 - b][x] += dp[b][x - 1] * fib[x] * fib[W - x];
            }
            if(x < W - 1) {
                dp[1 - b][x] += dp[b][x + 1] * fib[x + 1] * fib[W - (x + 1)];
            }
        }
    }
    cout << dp[H & 1][K - 1] << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque
h,w,k = map(int,input().split())
a = []
for i in range(h):
  b = input()
  tmp = []
  for j in range(w):
    tmp.append(b[j])
    if b[j] == "S":
      sx = i
      sy = j
  a.append(tmp)
ma = [[0]*w for i in range(h)]
def dfs(x,y,z):
  if ma[x][y] == 1:
    return
  if z>k:
    return
  ma[x][y] = 1
  if x > 0 and a[x-1][y]== ".":
    que.append([x-1,y,z+1])
  if y > 0 and a[x][y-1]== ".":
    que.append([x,y-1,z+1])
  if x <h-1 and a[x+1][y]==".":
    que.append([x+1,y,z+1])
  if y <w-1 and a[x][y+1]==".":
    que.append([x,y+1,z+1])
que = deque([[sx,sy,0]])
while que:
  x,y,z = que.popleft()
  dfs(x,y,z)
ans = float("inf")
for i in range(h):
  for j in range(w):
    if ma[i][j] == 1:
      ans = min(ans,1+(h-i-1)//k+ (1 if (h-i-1)%k else 0),1+(w-j-1)//k+ (1 if (w-j-1)%k else 0),
               1+(i)//k+ (1 if (i)%k else 0),1+(j)//k+ (1 if (j)%k else 0))
print(ans)

Measured memory_bytes: 118364
#include <iostream>
#include <vector>
#include <cmath>
#include <deque>
#include <algorithm>
#include <string>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <sstream>
#include <numeric>
using namespace std;
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define pf push_front
#define fs first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
int main() {
    fastio
    ll n;
    cin>>n;
    ll sum = 0;
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=n;j++){
            for(ll k=1;k<=n;k++){
                ll t = gcd(i,j);
                sum += gcd(t,k);
            }
        }
    }
    cout<<sum<<endl;
}



Measured memory_bytes: 3192
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>

#define rep(i,p) for(long long int i=0;i<p;i++)
#define reep(i,p) for(long long int i=1;i<=p;i++)
#define ll long long

using namespace std;

int main(){

string S;
cin >> S;


ll int N;
N = S.size();
rep(i,N){
	if(i%2 == 0){
		if(S[i] == 'L'){
			cout << "No";
			return 0;
		}
		else{}
	}
	else{
		if(S[i] == 'R'){
			cout << "No";
			return 0;
		}
		else{}
	}
}
cout << "Yes";












	return 0;

}



Measured memory_bytes: 3576
a, v = gets.split.map(&:to_i)
b, w = gets.split.map(&:to_i)
t = gets.to_i

if a > b 
    puts b - w * t >= a - v * t ? "YES" : "NO"
else
    puts b + w * t <= a + v * t ? "YES" : "NO"
end

Measured memory_bytes: 14284
n=int(input())
l=list(map(int,input().split()))
mod=10**9+7
if n%2==0:
    d={i:2 for i in range(1,n,2)}
else:
    d={i:2 for i in range(0,n,2)}
    d[0]=1
for a in l:
    if a in d:
        d[a]-=1
    else:
        print(0)
        exit()
for i in d.values():
    if i!=0:
        print(0)
        exit()
print((2**(n//2))%mod)

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

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

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

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

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

int main()
{
int a,b;
cin>>a>>b;
cout<<a*b<<endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define SIZE 10
#define PI 3.141592653589793

using namespace std;
typedef long long ll;

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

	ll N,A,B;
	int i,j;
	int tmp;
	ll answer=0;
	int counter=0;
	vector<int> given;

	cin >> N >> A >> B;

	answer+=(N/(A+B))*A;

	if(N%(A+B)<A)
		answer+=N%(A+B);
	else
		answer+=A;
	
	cout << answer << endl;

	return 0;
}



Measured memory_bytes: 3576
<?php
/*
    Problem URL : http://agc013.contest.atcoder.jp/tasks/agc013_a

    Score  :
    Result :
    Time   : ms
    Memory : KB
 */


define('DEBUG', true);
// define('DEBUG', false);

fscanf(STDIN, "%d %d %d", $A, $B, $C);

if ($A <= $C && $C <= $B) {
    echo "Yes\n";
} else {
    echo "No\n";
}


Measured memory_bytes: 4728
# include <stdio.h>

int main(){

	int n;
	int fac = 1;
	int aa = 3;
	int ss = 0;

	scanf("%d", &n);

	while (aa > 0){
		ss = fac * n;
		fac = ss;
		aa = aa - 1;
	}
	printf("%d\n", ss);



	return 0;
}


Measured memory_bytes: 128
while True:
    m, f, r = map(int, input().split())
    if m == f == r == -1:
        break

    if m == -1 or f == -1:
        print("F")
    elif m + f >= 80:
        print("A")
    elif m + f >= 65:
        print("B")
    elif m + f >= 50:
        print("C")
    elif m + f >= 30:
        if r >= 50:
            print("C")
        else:
            print("D")
    else:
        print("F")


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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b && a == c){
		cout << 1 << endl;
	}else if(a != b && b != c && c != a){
		cout << 3 << endl;
	}else{
		cout << 2 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int (i) = 0;(i) < (n) ; ++(i))
#define REPS(a,i,n) for(int (i) = (a) ; (i) < (n) ; ++(i))
#define REVERSE(i,n) for(int (i) = n-1;(i) >= 0 ; --i)
#define ALL(c) (c).begin() , (c).end()
#define LL long long
#define int LL
#define inf  (1LL << 60)
#define mod 1000000007
#define QUICK_CIN ios::sync_with_stdio(false); cin.tie(0);
#define lower lower_bound
#define upper upper_bound
#define ZERO(c,n) memset(&c[0],0,sizeof(int)*n)
#define ZERO2(c,n) memset(&c[0][0],0,sizeof(int)*n
#define pl(a) cout << ""#a": " << a << endl;
#ifdef _DEBUG
#define debug_io fstream cin("input.txt");ofstream cout("output.txt");
#else
#define debug_io ;
#endif
#define debug_input debug_io
#define DOWN(T) std::greater<T>()
template<class T>void scan(vector<T>& a, int n, istream& cin)
{
	T c; REP(i, n) { cin >> c; a.push_back(c); }
}
using vs = vector<string>; using vi = vector<int>; using pii = pair<int, int>;
using psi = pair<string, int>; using vvi = vector<vi>; using pss = pair<string, string>;
using vpii = vector<pii>;
template<class T>bool valid(T x, T w) { return 0 <= x&&x < w; }
int dx[4] = { 1, -1, 0, 0 }; int dy[4] = { 0, 0, 1, -1 };
//-----------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------

int dp[1000000];
int a[1000000];

signed main()
{
	QUICK_CIN;
	debug_input;

	int N, Q;
	int D;
	vi d, q;

	cin >> N >> D;
	REP(i, N) {
		int c;
		cin >> c;
		d.push_back(c);
	}
	cin >> Q;
	REP(i, Q) {
		int c;
		cin >> c;
		q.push_back(c-1);
	}

	dp[N - 1] = 1;

	REP(i, N) {
		if (dp[N - 1 - i] <= floor(d[N - 1 - i] / 2.0)) {
			dp[N - 2 - i] = dp[N - 1 - i];
		}
		else {
			dp[N - 2 - i] = dp[N - 1 - i] + d[N - 1 - i];
		}
	}
	a[0] = D;
	REP(i, N) {
		a[i + 1] = min(a[i], abs(a[i] - d[i]));
	}

	REP(i, Q) {
		if (a[q[i]] >= dp[q[i]]) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}

}

Measured memory_bytes: 20460
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scanf("%d %d", &a, &b)
	switch {
	case a == b:
		fmt.Println("Draw")
	case a == 1:
		fmt.Println("Alice")
	case b == 1:
		fmt.Println("Bob")
	case a > b:
		fmt.Println("Alice")
	default:
		fmt.Println("Bob")
	}
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int siz=2e5;
const int inf=1e9;
int main(){
	long N; cin>>N;
	long sum = 0;
	rep(i,1,N+1){
		long x = N / i;
		sum += x * (x + 1) / 2 * i;
	}cout<<sum<<endl;
}

Measured memory_bytes: 3620
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

    int n;
    cin >> n;
    ll a[n], b[n];
    vector <pair<ll, int>> sm;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        sm.push_back(make_pair(a[i]+b[i], i));
    }

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

    ll ans = 0LL;
    for (int i = n-1; i >= 0; i--) {
        if ((n-1-i) % 2 == 0) {
            ans += a[sm[i].second];
        } else {
            ans -= b[sm[i].second];
        }
    }

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

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define LEN 100005

//プロセスを表す構造体
typedef struct pp{
  char name[100];
  int t;
}P;

//Pの構造体をLEN+1個作って、その群れをQ列（データが格納されるキュー）と名付ける
P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
    Q[tail] = x;
    tail = (tail+1) % LEN;
}

P dequeue(){
    P x = Q[head];
    head = (head+1) % LEN;
    return x;
}

int min(int a, int b){
    return a < b ? a : b;
}

int main(){
  //情報の入力
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
}

head = 1;
tail = n+1;

//計算
while(head != tail){
    u = dequeue(); //処理するプロセスの取り出し
    c = min(q, u.t);
    u.t -= c; //必要時間　と 処理時間の 小さい方を必要時間から引く
    elaps += c;
    if(u.t > 0) enqueue(u);
    else{
        printf("%s %d\n", u.name, elaps);
    }
}
  return 0;
}


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

int main() {
    ll n, k;
    cin>>n>>k;
    vector<pair<ll, ll>> v;
    for(int i = 0; i < n; i++){
        int a, b;
        cin>>a>>b;
        v.push_back({a, b});
    }
    
    ll dp[n][k+1];
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= k; j++){
            dp[i][j] = 0;
        }
    }
    
    sort(v.begin(), v.end());
    for(int i = 0; i <= k; i++){
        if(i >= v[0].first){
            dp[0][i] = v[0].second;
        }
    }
    
    for(int i = 1; i < n; i++){
        for(int j = 0; j <= k; j++){
            if(j < v[i].first){
                dp[i][j] = dp[i-1][j];
            }
            else{
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-v[i].first] + v[i].second);
            }
        }
    }
    
    cout<<dp[n-1][k];
    
    return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<int, int> P;
#define INF 10000000000000
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

int main()
{
	ll K;
	string s;
	int r = 0;

	cin >> s >> K;

	while (K > 0)
	{
		rep(i, s.size())
		{
			if (r == 0)
			{
				if (s[i] == 'a')
					continue;
			}

			if ('z' + 1 - s[i] <= K)
			{
				K = K - ('z' + 1 - s[i]);
				s[i] = 'a';
			}
		}

		if (K < 'z' + 1 - 'a')
		{
			s[s.size() - 1] += K;
			K = 0;
		}

		r++;
	}


	cout << s << endl;

	return 0;
}

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

using namespace std;

int X, Y, E, x, y;
bool D[110][110] = {};
int PY[100];
bool V[110];
bool match(int x){
  if (x < 0) return true;
  if(V[x]) return false;
  V[x] = true;

  for(int y = 0; y < Y; y++){
    if(!D[x][y]) continue;
    if(match(PY[y])){
      PY[y] = x;
      return true;
    }
  }
  return false;
}

int main(){
  cin >> X >> Y >> E;
  for(int i = 0; i < E; i++){
    cin >> x >> y;
    D[x][y] = true;
  }
  
  fill(PY, PY + Y, -1);
  int count = 0;
  for(int x = 0; x < X; x++){
    fill(V, V+X, false);
    if(match(x))
      count++;
  }
  cout << count << endl;

}

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

int main() {
    // 入力
    int s,w;
    cin >> s >> w;
    if(w>=s){
        cout << "unsafe";
    }else{
        cout << "safe";
    }
    return 0;
}

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


YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str):
    print(YES if S[2] == S[3] and S[4] == S[5] else NO)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == '__main__':
    main()


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

// int/long:            -2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:      -9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

/*
int     gcd(int A, int B) {
        while (0!=B) {
                A %=B;
                swap(A, B);
        }
        return A;
}
*/

#define MOD 1000000007

int     main() {
        int S;
        cin >>S;
        int s=S%60;
        S/=60;
        int m=S%60;
        S/=60;
        cout <<S <<':' <<m <<':' <<s <<endl;
        return 0;
}


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

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

#define FOR(i, s, e) for (ll(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (ll(i) = (s); (i) > (e); (i)--)
#define debug(x) cout << #x << ": " << x << endl
#define mp make_pair
#define pb push_back
const ll MOD = 1000000007;
const int INF = 1e9;
const ll LINF = 1e16;
const double PI = acos(-1.0);
int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

/* -----  2017/04/29  Problem: ARC 073 C / Link: http://arc073.contest.atcoder.jp/tasks/arc073_c  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

ll N;

ll ans = 0LL;

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

  cin >> N;
  ll x[200200];
  ll y[200200];
  vector<pll> s;
  FOR(i, 0, N) {
	  cin >> x[i] >> y[i];
	  if (x[i] > y[i])swap(x[i], y[i]);
	  //x<y;
	  s.push_back(mp(x[i], y[i]));
  }
  sort(s.begin(), s.end());

  ll rmin = LINF, bmin = LINF;
  ll rbig = 0, bbig = 0;
  //r min,b max
  FOR(i, 0, N) {
	  rmin = min(rmin, s[i].first);
	  rbig = max(rbig, s[i].first);
	  bmin = min(bmin, s[i].second);
	  bbig = max(bbig, s[i].second);
  }
  ans = (rbig - rmin)*(bbig - bmin);
  //r min r max
  ll ran = (bbig - rmin);
  bmin = s[0].first;
  bbig = s[N-1].first;
  ll bminmin = LINF;
  FOR(i, 0, N - 1) {
	  bmin = s[i + 1].first;
	  bminmin = min(bminmin,s[i].second);
	  bbig = max(bbig, s[i].second);
	  ans = min(ans, ran*(bbig - min(bmin, bminmin)));
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 9456
#include "bits/stdc++.h"
#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

int main() {
	speed;
	int a, b,t;
	cin >> a >> b>>t ;
	t += 0.5;
	int ans = (t / a)*b;
	cout << ans;
	ed;
	return 0;
}


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

typedef long long ll;

using namespace std;

int main(){
    string S;
    cin >> S;
    int size = S.size();
    vector<int> splitIndexList, rBoundaryList, lBoundaryList;
    int child[size];

    // 文字列S をR...RL...L に分解する
    // 分解する位置と、境界のRL の位置を記録しておく
    splitIndexList.push_back(0);
    REP(i, size - 1) 
    {
		if (S[i] == 'R') 
		{
			if (S[i + 1] == 'R') 
			{
				continue;
			}
			else if (S[i + 1] == 'L')
			{
				rBoundaryList.push_back(i);
				lBoundaryList.push_back(i + 1);
			}
		}
		else if (S[i] == 'L') 
		{
			if (S[i + 1] == 'R') 
			{
				splitIndexList.push_back(i + 1);
			}
			else if (S[i + 1] == 'L') 
			{
				continue;
			}
		}
    }

    // 解答となる配列の初期化
    REP(i, size) child[i] = 0;

    int splitNum = splitIndexList.size();
    for (int i = 0; i < splitNum; ++i) 
    {
    	int end;
    	if (i < splitNum - 1) end = splitIndexList[i + 1];
    	else end = size;
    	for (int j = splitIndexList[i]; j < end; ++j) 
    	{
    		// dist : 分割したR...RL...L の文字列の境界のRL までの距離
    		int dist;
    		if (S[j] == 'R') 
    		{
    			dist = rBoundaryList[i] - j;
    			if (dist % 2 == 0) child[rBoundaryList[i]]++;
    			else child[lBoundaryList[i]]++;
    		}
    		else if (S[j] == 'L') 
    		{
    			dist = j - lBoundaryList[i];
    			if (dist % 2 == 0) child[lBoundaryList[i]]++;
    			else child[rBoundaryList[i]]++;
    		}
    	}
    }

    REP(i, size) 
    {
    	cout << child[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 1912
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int ans,num,a,b;
    cin>>a>>b;
    ans=__gcd(a,b);
    for(int i=2;i<n;i++)
    {
        cin>>num;
        ans=__gcd(ans,num);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>

#pragma region 定義
#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin4(X,Y,Z,W) scanf("%d %d %d %d",&X,&Y,&Z,&W)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define f_cin(X) scanf("%f",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)

#define  i_cout(X) printf("%d\n",X)
#define  f_cout(X) printf("%g\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  ll_cout(X) printf("%lld\n",X)

typedef long long  ll;
#define rept(x, s, n) for (int x = s; x < n; x++)

#define S_RTN(S)  s_cout(S);return 0


#define _itoa(A,N) sprintf(A, "%d", N);

int i_cins(int n, int* A);
int l_cins2(int n, long* A, long* B);
int s_dsort(const void* a, const void* b);
int s_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);


int s_asorts(const void* a, const void* b);

//昇順
int s_asorts(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int s_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}
int l_cins2(int n, long* a, long* b) {
	int i;
	rept(i, 0, n) {
		l_cin2(*(a + i), *(b + i));
	}
	return 0;
}
int i_cins(int n, int* a) {
	int i;
	for (i = 0; i < n; i++) {
		i_cin(*(a + i));
	}

	return 0;
}
int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}

long _max(long a, long b) {
	return a > b ? a : b;
}
long _min(long a, long b) {
	return a < b ? a : b;
}
int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}
#pragma endregion


#include <stdio.h>

#include<stdio.h>

int main(void)
{
	int  i, cnt = 0;
	int  x,a[101],n;

	i_cin2(n,x);
	i_cins(n, a);
	qsort(a,n,sizeof(int),s_asort);
	
	for (i = 0; i < n; i++) {
		if (!a[i]) continue;
		cnt++;
		x -= a[i];
		if (x <= 0)break;
	}
	
	(!x) ? i_cout(cnt) : i_cout(cnt - 1);
	return 0;
}



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

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

   vector<int> ans(N, 1);
   for(int i = 0; i < N - 1; i++) {
       if(S[i] == S[i + 1] && S[i] == 'R') {
           ans[i + 2] += ans[i];
           ans[i] = 0;
       }
   }

   for(int i = N - 1; i > 0; i--) {
       if(S[i] == S[i - 1] && S[i] == 'L') {
           ans[i - 2] += ans[i];
           ans[i] = 0;
       }
   }

   
   for(int i = 0; i < N; i++) cout << " " << ans[i];

    return 0;
}

Measured memory_bytes: 3844
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
main(){
  long long int n;
  cin>>n;
  long long int dp[n+1]={0};
     dp[0]=1;
    dp[1]=0;
    dp[2]=0;
    for(long long int  i=3;i<=n;i++)
    {
        for(long long int j=3;j<=i;j++)
        {
            dp[i]=(dp[i]+dp[i-j])%mod;
        }
    }
    cout<<dp[n]<<endl;
}
      

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

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PDD;

#define _upgrade                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
template <typename _T>
inline void _DBG(const char *s, _T x)
{
    cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a)
{
    while (*s != ',')
        cerr << *s++;
    cerr << " = " << x << ',';
    _DBG(s + 1, a...);
}

#ifdef LOCAL
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr \
    if (0)   \
    cout
#endif

// ********************** CODE ********************** //

const int N = 1e5 + 7;

int n, root, ans;
vector < int > G[N];

bool dfs(int v, int f)
{
    //DBG(v, f);
    if(sz(G[v]) == 1)
    {
        return false;
    }
    int ile = 0;
    if(f == -1) ile--;
    for(int i = 0; i < sz(G[v]); i++)
    {
        int u = G[v][i];
        if(u == f) swap(u, G[v].back());
        if(u == f) continue;
        ile += dfs(u, v);
    }
    //DBG(v, f, ile);
    if(ile + 2 < sz(G[v]))
    {
        ans += sz(G[v]) - ile - 2;
        return true;
    }
    if(f == -1) ile++;
    if(ile == 0)
    {
        return false;
    }
    return true;
}

int main()
{
    _upgrade
    cin >> n;
    for(int i = 1; i < n; i++)
    {
        int a, b; cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    if(n == 2)
    {
        cout << 1 << "\n";
        return 0;
    }
    root = 0;
    for(int i = 0; i < n; i++)
    {
        if(sz(G[i]) > sz(G[root]))
            root = i;
    }
    dfs(root, -1);

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


Measured memory_bytes: 11904
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> T gcd(T a, T b){return !b?a:gcd(b,a%b);}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
//const int N = ;
int x,a,res;
int main() {
	read(x);
	while(1){
		res++;a=(a+x)%360;
		if(!a)break;
	}
	cout<<res;
	return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=998244353;
const int siz=2e5;
const int inf=1e9;
int main(){
	char a; cin>>a;
	if('a' <= a && a <= 'z') cout<<"a"<<endl;
	else cout<<"A"<<endl;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define print printf("==================\n");
typedef    long long ll;
typedef   unsigned long long ull;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define min3(a,b,c) min(a,min(b,c));
#define max3(a,b,c) max(a,max(b,c));
#define readf                freopen("in.txt", "r", stdin);
#define writef               freopen("out.txt", "w", stdout);
typedef pair<ll,ll   > payar;
priority_queue<int, vector<int>,  greater<int> > pq; ///accending
vector< pair<int,payar  > > vpp;
vector< pair<int,  pair<int,payar  > > > own;
vector < payar >  vp;
#define pi aco 10e12;
#define EPS 1e-9
#define  mod   1000000007
#define  mod2  998244353
#define all(x) x.begin(),x.end()
#define endl "\n"
const int N=1e6+5;
ll cumonel[N];
ll cumtwol[N];
ll cumoner[N];
ll cumtwor[N];
int ara[N+5];
int arr[N+5];

int main()
{
    IOS;

    string s ;
    cin>>s;
    string ss=s;
    reverse(all(s));
    int ans=0;
    for(int i = 0 ; 2*i<(int)s.size(); i++ ){
        ans+=(s[i]!=ss[i]);
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
//set many funcs
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define inf 1072114514
#define llinf 1145141919810364364
#define mod 1000000007

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}

int main(void){
    int n,i,a,b,za,zb=inf;
    scanf("%d",&n);
    for(i=1;i<=n;i++){scanf("%d%d",&a,&b);
        if(zb>b){za=a;zb=b;}
    }
    printf("%d\n",za+zb);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;


const int MAX_N = 100010;

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, x; cin >> n >> x;
	int ans = 0;
	VE a(n); rep(i, n)cin >> a[i];
	rep(i, n-1) {
		int sum = a[i] + a[i + 1];
		if (sum > x) {
			int tmp = sum - x;
			if (a[i + 1] >= tmp) {
				ans += tmp;
				a[i + 1] -= tmp;
			}
			else {
				ans += a[i + 1];
				tmp -= a[i + 1];
				a[i + 1] = 0;
				ans += tmp;
				a[i] -= tmp;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
def main():
    H1, M1, H2, M2, K = [int(value) for value in input().split(" ")]

    # K(min)-> Time min
    H = K // 60
    M = K % 60
    
    
    NH = H2 - H
    NM = M2 - M
    if NM < 0:
        NH -= 1
        NM = 60 + NM
    if NM - M1 < 0:
        RM = (NH - H1-1)*60 + 60+(NM-M1)
    else:
        RM = (NH - H1)*60 + (NM-M1)

    if RM < 0:
        RM = 0
    print(RM)

if __name__=="__main__":
    main()

Measured memory_bytes: 9204
import math
import string
import collections
from collections import Counter
from collections import deque


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
a1 = readints()
a2 = readints()
# print(a1)
# print(a2)
ans = 0
for i in range(n):
    tmp = 0
    tmp += sum(a1[:i+1])
    tmp += sum(a2[i:])
    ans = max(tmp, ans)
print(ans)


Measured memory_bytes: 38896
import sys
from collections import Counter

input = sys.stdin.readline


def calc_prime_factors(n, count=False):
    """Trial division"""
    factors = []
    # factor: 2
    while n % 2 == 0:
        factors.append(2)
        n //= 2
    # factor: 3, 5, 7, 11, ...
    f = 3
    while f ** 2 <= n:
        if n % f == 0:
            factors.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        factors.append(n)
    if count:
        factors = Counter(factors).items()
    return factors


def main():
    N = int(input())

    factors = calc_prime_factors(N, count=True)
    ans = 0
    for _, count in factors:
        n = 1
        while True:
            if n * (n + 1) // 2 <= count:
                n += 1
            else:
                break
        ans += (n - 1)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9416
#include<stdio.h>

int main(){

	int high[10];
	int i, j, k, kara;

	for (i = 0 ; i < 10 ; i++) {
		scanf("%d", &high[i]);
	}

	for (j = 0 ; j < 10 ; j++) {
		for (k = j + 1 ; k < 10 ; k++) {
			if (high[j] < high[k]) {
				kara = high[k];
				high[k] = high[j];
				high[j] = kara;
			}
		}
	}

	for (i = 0 ; i < 3 ; i++) {
		printf("%d\n", high[i]);
	}

    return 0;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

#define UF_NUM 505050

li parent[UF_NUM];

inline void init_uf() {
    rep(i, UF_NUM)parent[i] = i;
}

inline li find(li x) {
    if (parent[x] == x)return x;
    else return (parent[x] = find(parent[x]));
}

inline void union_(li x, li y) {
    li parent_x = find(x);
    li parent_y = find(y);
    parent[parent_x] = parent_y;
}

li a[101010];
li rev[101010];

int main() {
    init_uf();
    li n, m;
    cin >> n >> m;
    rin{
        cin >> a[i];
        a[i]--;
        rev[a[i]] = i;
    }
    rep(i, m) {
        li x, y;
        cin >> x >> y;
        x--;
        y--;
        union_(x, y);
    }

    li res = 0;
    rin{
        if (find(i) == find(rev[i])) {
            ++res;
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 5760