akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
//
#define int long long
#define ALL(x) (x).begin(), (x).end()
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))
// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((a) >> (b)) & 1
#define bitcount(a) __builtin_popcountll((a))
//
typedef long long lint;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;
//
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
//
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

signed main() {
  string s;
  cin >> s;

  int ans = 0;
  int gc = 0, pc = 0;
  for (int i = 0; i < (int)s.size(); i++) {
    if (pc + 1 > gc) {
      gc++;
      if (s[i] == 'p') {
        ans--;
      }
    } else {
      pc++;
      if (s[i] == 'g') {
        ans++;
      }
    }
  }

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


Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
	int n,i;
	int C,A,N;
	int group;
	
	scanf("%d", &n);
	
	for (i = 0; i < n;i++){
		group = 0;
		scanf("%d %d %d", &C, &A, &N);
		while(1){
			if (C>=1 && A>=1 && N>=1){
				group++;
				C--;
				A--;
				N--;
			}
			else if (C >= 2 && A >= 1){
				group++;
				C -= 2;
				A--;
			}
			else if (C >= 3){
				group++;
				C -= 3;
			}
			else {
				break;
			}
		}
		printf("%d\n", group);
	}
	
	return (0);
}

Measured memory_bytes: 600
h,w = map(int,input().split())

ls = [list(input()) for i in range(h)]

t=True

for i in range(h):
    for j in range(w):
        if (ls[i][j]=='#'):
            count=0
            for x in range(-1,2):
                for y in range(-1,2):
                    if (0<=i+x<h and 0<=j+y<w):
                        if not((x==1 and y==1) or (x==1 and y==-1) or (x==-1 and y==1) or (x==-1 and y==-1)or(x==0 and y==0)):
                      	  if(ls[i+x][j+y]=='#'):
                              count+=1
                      	  else:
                              continue
                        else:
                          continue
                    else:
                      continue
            if(count==0):
              t = False
              break
        else:
          continue      
if(t):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long int k; 
  cin >> k;

  string s;
  cin >> s;


  if ( s.size() > k ) {
    char c;
    for (int i = 0; i < k; i++){
      c = s.at(i);    
      cout << c;
    }
    cout << "...";
  } else {
    cout << s;
  }
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;


int main(){
    int a,b,theta=90;
    double x=0,y=0,pi=3.141592653589;
    char k;
    for(;;){
        scanf("%d,%d",&a,&b);
        if(a==0 && b==0){
            break;
        }
        y+=a*sin(theta/180.0*pi);
        x+=a*cos(theta/180.0*pi);
        theta+=b;
    }
    printf("%d\n%d\n",(int)-x,(int)y);
    return 0;
}

Measured memory_bytes: 1176
#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);
	
	string S;
	string c;
	
	// c = "coffee";
	
	cin>>S;
	
	if(S[2] == S[3] && S[4] == S[5]) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
letToCode :: Char -> String
letToCode ch = case ch of
                ' ' -> "101"
                '\''-> "000000"
                ',' -> "000011"
                '-' -> "10010001"
                '.' -> "010001"
                '?' -> "000001"
                'A' -> "100101"
                'B' -> "10011010"
                'C' -> "0101"
                'D' -> "0001"
                'E' -> "110"
                'F' -> "01001"
                'G' -> "10011011"
                'H' -> "010000"
                'I' -> "0111"
                'J' -> "10011000"
                'K' -> "0110"
                'L' -> "00100"
                'M' -> "10011001"
                'N' -> "10011110"
                'O' -> "00101"
                'P' -> "111"
                'Q' -> "10011111"
                'R' -> "1000"
                'S' -> "00110"
                'T' -> "00111"
                'U' -> "10011100"
                'V' -> "10011101"
                'W' -> "000010"
                'X' -> "10010010"
                'Y' -> "10010011"
                'Z' -> "10010000"

binToDec str = sum$zipWith(*)(iterate(*2)1)(map(\x->if x=='1' then 1 else 0)(reverse str))

codeToLet :: String -> Char
codeToLet bin = let dec = binToDec bin
                in case dec of
                    0 -> 'A'
                    1 -> 'B'
                    2 -> 'C'
                    3 -> 'D'
                    4 -> 'E'
                    5 -> 'F'
                    6 -> 'G'
                    7 -> 'H'
                    8 -> 'I'
                    9 -> 'J'
                    10 -> 'K'
                    11 -> 'L'
                    12 -> 'M'
                    13 -> 'N'
                    14 -> 'O'
                    15 -> 'P'
                    16 -> 'Q'
                    17 -> 'R'
                    18 -> 'S'
                    19 -> 'T'
                    20 -> 'U'
                    21 -> 'V'
                    22 -> 'W'
                    23 -> 'X'
                    24 -> 'Y'
                    25 -> 'Z'
                    26 -> ' '
                    27 -> '.'
                    28 -> ','
                    29 -> '-'
                    30 -> '\''
                    31 -> '?'

splitAtN _ []  = []
splitAtN n str = fst(splitAt n str) : (splitAtN n (snd(splitAt n str)))

strAddZero str = let len = length str
                 in if len`mod`5==0 then str else str ++ (replicate (5-len`mod`5) '0')


main = do{
    getContents>>=mapM_ putStrLn.map((map codeToLet).splitAtN 5.strAddZero.(foldr(++)"").(map letToCode)).lines;
}

Measured memory_bytes: 4584
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
	public static void Main()
	{
		var s = ReadLine();
		var f = int.Parse(s.Substring(0, 2));
		var b = int.Parse(s.Substring(2, 2));
		var isMf = 1 <= f && f <= 12;
		var isMb = 1 <= b && b <= 12;
		if(isMf && isMb)
			WriteLine("AMBIGUOUS");
		else if(!isMf && isMb)
			WriteLine("YYMM");
		else if(isMf && !isMb)
			WriteLine("MMYY");
		else
			WriteLine("NA");
	}
}


Measured memory_bytes: 17556
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    static class APlacingMarbles
    {        
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            const int length = 3;
            var count = 0;

            for (int i = 0; i < length; i++)
            {
                if (s.Substring(i, 1) == "1")
                {
                    count++;
                }
            }

            Console.WriteLine(count);
            Console.ReadLine();
        }
  }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

int main() {
  int n;
  cin>>n;
  vector<vector<int>> IDs(n, vector<int>(n,-1));
  int id=0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      IDs[i][j]=id;
      IDs[j][i]=id;
      id++;
    }
  }
  vector<vector<int>> G(n*(n-1)/2);
  vector<int> h(n*(n-1)/2,0);
  vector<int> length(n*(n-1)/2,-1);
  int t,bufid,vsid;
  for(int i=0;i<n;i++){
    bufid=-1;
    for(int j=0;j<n-1;j++){
      cin>>t;t--;
      vsid=IDs[i][t];
      if(bufid!=-1){
        G[bufid].push_back(vsid);
        h[vsid]++;
      }
      bufid=vsid;
    }
  }
  queue<int> que;
  vector<int> ans;
  for(int i=0;i<n*(n-1)/2;i++){
    if(h[i]==0) {
      que.push(i);
      length[i]=0;
    }
  }
  while(!que.empty()){
    int cur=que.front();
    que.pop();
    ans.push_back(cur);
    for(int next:G[cur]){
      h[next]--;
      length[next]=max(length[next],length[cur]+1);
      if(h[next]==0) que.push(next);
    }
  }
  bool cannot= (int)(ans.size())==n*(n-1)/2;
  if(!cannot) cout<<-1<<endl;
  else{
    int tem=*max_element(length.begin(),length.end());
    cout<<tem+1<<endl;
  }
  return 0;
}


Measured memory_bytes: 40472
import math
import collections
import fractions
import itertools
import functools
import operator

def solve():
    s = list(input())
    a = s.count("a")
    b = s.count("b")
    c = s.count("c")
    hoge = [a, b, c]
    for i in range(2):
        if abs(hoge[i] - hoge[i+1]) > 1 or abs(hoge[0] - hoge[2]) > 1:
            print("NO")
            break
    else:
        print("YES")
    return 0

if __name__ == "__main__":
    solve()


Measured memory_bytes: 82680
import java.util.Scanner;
import java.util.Vector;

public class Main {
	static long dp[][];
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		dp = new long [n][k+1];
		for (int i=0;i<n;i++) {
			int a=sc.nextInt();
			for (int j=0;j<=k;j++) {
				dp[i][j] = 0;
				if (i==0) {
					if (a>=j) dp[i][j] = 1;
				} else {
					if (j==0) dp[i][j] = 1;
					else {
						dp[i][j] = (dp[i][j-1] + dp[i-1][j])%1000000007;
						if (j>=a+1) dp[i][j] = (dp[i][j]+ 1000000007  - dp[i-1][j-a-1])%1000000007;
					}
				}
			}
		}
		System.out.println(dp[n-1][k]);
	}
}


Measured memory_bytes: 128084
#include <iostream>
#include <algorithm>
#include <queue>
#include <iomanip>


using namespace std;

int main(){
    int N;
    double v[50];
    cin >> N;
    priority_queue<double, vector<double>, greater<double>> que;
    for(int i = 0; i < N; i++){
        cin >> v[i];
        que.push(v[i]);
    }
    
    for(int i = 0; i < N-1; i++){
        double v1, v2;
        v1 = que.top();
        que.pop();
        v2 = que.top();
        que.pop();
        double v3 = (v1+v2)/2;
        que.push(v3);
    }
    cout << fixed << setprecision(10);

    cout << que.top() << endl;
}

Measured memory_bytes: 256
import random

class Dice():
    def __init__(self, numbers):
        self.numbers = numbers
        S = [1, 5, 2, 3, 0, 4]
        N = [4, 0, 2, 3, 5, 1]
        W = [3, 1, 0, 5, 4, 2]
        E = [2, 1, 5, 0, 4, 3]
        self.tumble = {0: S, 1: N, 2: W, 3: E}
        
    def rol(self, command):
        prev = self.numbers.copy()
        for i, t in enumerate(self.tumble[command]):
            self.numbers[t] = prev[i]
                
numbers = list(map(int, input().split()))
q = int(input())

dice = Dice(numbers)
for _ in range(q):
    query = list(map(int, input().split()))
    while True:
        dice.rol(random.randint(0, 3))
        if dice.numbers[0] == query[0] and dice.numbers[1] == query[1]:
            print(dice.numbers[2])
            break


Measured memory_bytes: 8188
#include<iostream>
using namespace std;
int main(){
    int h,w,k ;
    cin>> h >> w >> k;
    
    char a[h][w];
    for(int i = 0 ; i< h ; i++ ){
        for(int j = 0 ;j<w ; j++ ){
            cin>>a[i][j];
        }
    }
    
    int ans = 0;
    for( int row = 0 ; row < (1<<h) ; row ++ ){
        for( int col =0 ; col < (1<<w) ; col ++ ){
            int cnt = 0;
            for(int i = 0 ; i < h ; i++){
                for(int j = 0 ; j< w ; j++){
                    if( (row>>i)&1 && (col>>j)&1 && a[i][j] == '#'){
                        cnt++;
                    }
                }
            }
            
            if(cnt == k ){
                ans++;
            }
        }
    }

    cout << ans;
}

Measured memory_bytes: 3568
#include<stdio.h>

int main(){
int r,g,b,n,cnt=0;
scanf("%d %d %d %d",&r,&g,&b,&n);
for(int i=n/r;i>=0;i--){
for(int j=(n-i*r)/g;j>=0;j--){
if((n-i*r-j*g)%b==0)cnt++;
}
}
printf("%d",cnt);
return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SORT(x) sort(rng(x))
#define RSORT(x) sort(rrng(x))
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

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 h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  vvi cnt(h,vi(w));
  rep(i,h) {
    vi done(w);
    rep(j,w) {
      if (s[i][j] == '#') continue;
      if (done[j]) continue;
      int l = 0;
      while (j+l<w) {
        if (s[i][j+l] == '#') break;
        ++l;
      }
      rep(k,l) {
        cnt[i][j+k] += l;
        done[j+k] = 1;
      }
    }
  }
  rep(j,w) {
    vi done(h);
    rep(i,h) {
      if (s[i][j] == '#') continue;
      if (done[i]) continue;
      int l = 0;
      while (i+l<h) {
        if (s[i+l][j] == '#') break;
        ++l;
      }
      rep(k,l) {
        cnt[i+k][j] += l;
        done[i+k] = 1;
      }
    }
  }
  int ans = 0;
  rep(i,h)rep(j,w) ans = max(ans, cnt[i][j]-1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 20096
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

const int INF = 1e9 + 5;

int main() {
  string s,t;
  cin>>s>>t;
  int sl = s.size(), tl = t.size();
  vector<vector<int>> dp(tl+1,vector<int>(sl+1));
  for (int i = 0; i <= tl; i++)
  {
    for (int j = 0; j <= sl; j++)
    {
      if(i==0 || j==0){
        dp[i][j] = 0;
      }
      else if(s[j-1] == t[i-1]){
        dp[i][j] = dp[i-1][j-1]+1;
      }
      else{
        dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
      }
    }
  }
  if(dp[tl][sl]==0){
    puts("");
  }
  else{
     int index = dp[tl][sl]; 
  
   // Create a character array to store the lcs string 
   char lcs[index+1]; 
   lcs[index] = '\0'; // Set the terminating character 
  
   // Start from the right-most-bottom-most corner and 
   // one by one store characters in lcs[] 
   int i = tl, j = sl; 
   while (i > 0 && j > 0) 
   { 
      // If current character in X[] and Y are same, then 
      // current character is part of LCS 
      if (t[i-1] == s[j-1]) 
      { 
          lcs[index-1] = t[i-1]; // Put current character in result 
          i--; j--; index--;     // reduce values of i, j and index 
      } 
  
      // If not same, then find the larger of two and 
      // go in the direction of larger value 
      else if (dp[i-1][j] > dp[i][j-1]) 
         i--; 
      else
         j--; 
   }
   puts(lcs);
  }
    
}

Measured memory_bytes: 35584
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

template <typename T>
using vec = vector<T>;

template <typename T>
using vec2 = vector<vector<T>>;

template <typename T>
using vec3 = vector<vector<vector<T>>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 61;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

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

    Int n, w;
    cin >> n >> w;
    vec<Int> val(n), wei(n);
    vec2<Int> wv(n, vec<Int>(2)), dp(n + 1, vec<Int>(w + 1));
    for (Int i = 0; i < n; i++) {
        cin >> wei[i] >> val[i];
    }

    for (Int i = 0; i < n; i++) {
        for (Int j = 0; j <= w; j++) {
            if (0 <= j - wei[i]) {
                dp[i + 1][j] = max(dp[i][j], dp[i][j - wei[i]] + val[i]);
            } else {
                dp[i + 1][j] = dp[i][j];
            }
        }
    }

    cout << dp[n][w] << endl;

    return 0;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int N; cin >> N;
	vi L(2 * N);
	REP(i,2 * N) cin >> L[i];
	sort(ALL(L), greater<int>());
	int res = 0;
	for (int i = 1; i < 2 * N; i += 2) res += L[i];
	cout << res << endl;
}

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


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//do {
//    print(v);
//  } while (std::next_permutation(v.begin(), v.end()));

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
	int N;
	cin>>N;
	VI A(N);
	REP(i,N)cin>>A[i];
	VI dp(N+1);
	dp[0]=0;
	dp[1]=abs(A[0]-A[1]);
	FOR(i,2,N)
		dp[i]=min(dp[i-2]+abs(A[i]-A[i-2]),dp[i-1]+abs(A[i-1]-A[i]));
		
	cout<<dp[N-1]<<endl;
	
	return 0;
}




















Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  ll n; cin >> n;
  vector<ll> a(n); rep(i, n) cin >> a[i];
  sort(a);
  ll dist = 0xffffffff, mid = 0;

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

  cout << a[n-1] << " " << mid << endl;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long int
#define nl "\n"
#define vec vector<ll>
#define pb push_back
#define MOD 1000000007
#define test ll t;cin>>t;while(t--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
int main()
{
	ll k;
	cin>>k;
	for(int i=0;i<k;i++)
	cout<<"ACL";
	cout<<endl;
}


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

using namespace std;

int main(){
	int h, w;
	cin>>h>>w;
	int n;
	cin>>n;
	vector<int> ai(n);
	vector<vector<int>> c(h,vector<int>(w));
	for(int i=0; i<n; i++){
		cin>>ai[i];
	}

	int k=0;
	for(int i=0; i<h; i++){
		if(i&1){
			for(int j=w-1; j>-1; j--){
				if(ai[k]==0) k++;
				c[i][j]=k+1;
				ai[k]--;
			}
		}else{
			for(int j=0; j<w; j++){
				if(ai[k]==0) k++;
				c[i][j]=k+1;
				ai[k]--;
			}
		}
	}

	for(auto x : c){
		for(auto y:x){
			cout<<y<<" ";
		}
		cout<<endl;
	}
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<atcoder/all>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; using namespace atcoder;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int H, W;
string S[50];
vector<pair<int,int>> circles;
int dist[101][50][50];
ll BASE = inf;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> H >> W;
	rep(y, 0, H) cin >> S[y];

	int id = 0;
	rep(y, 0, H) rep(x, 0, W) if (S[y][x] == 'o') {
		circles.push_back({ x, y });
		rep(xx, 0, W) rep(yy, 0, H) dist[id][yy][xx] = inf;
		queue<tuple<int,int, int>> que;

		dist[id][y][x] = 0;
		que.push(make_tuple(x, y, 0));
		while (!que.empty()) {
			int x, y, cst;
			tie(x, y, cst) = que.front(); que.pop();

			if (x + 1 < W && S[y][x + 1] != '#' && dist[id][y][x + 1] == inf) {
				dist[id][y][x + 1] = cst + 1;
				que.push(make_tuple(x + 1, y, cst + 1));
			}

			if (y + 1 < H && S[y + 1][x] != '#' && dist[id][y + 1][x] == inf) {
				dist[id][y + 1][x] = cst + 1;
				que.push(make_tuple(x, y + 1, cst + 1));
			}
		}

		id++;
	}

	mcf_graph<int, ll> g(H * W + id + 2);
	int st = H * W + id;
	int gl = st + 1;

	rep(i, 0, id) {
		g.add_edge(st, H * W + i, 1, 0);
		rep(y, 0, H) rep(x, 0, W) if (dist[i][y][x] < inf) g.add_edge(H * W + i, y * W + x, 1, BASE - dist[i][y][x]);
	}
	rep(y, 0, H) rep(x, 0, W) if (S[y][x] != '#') g.add_edge(y * W + x, gl, 1, 0);
	
	ll ans = -(g.flow(st, gl).second - BASE * id);
	cout << ans << endl;
}







Measured memory_bytes: 9836
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

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

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

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

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

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    System.out.println(a * b - a - b + 1);
  }
}

Measured memory_bytes: 21204
program caracal
implicit none
integer(8) :: h,n
n = 0
read(*,*)h
do while(h .ge. 0)
    if (h == 1) then
        write(*,*)2**(n+1)-1
        exit
    else 
        h = h/2
        n = n + 1
    end if
end do


end program caracal

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

int dd[200010] = {};
vector<vector<int>> d(200010);
int ans[200010] = {};
int n, q, a, b, p, x;
int tmp;

void dfs(int x, int tmp){
  ans[x] += tmp;
  for(auto next: d[x]){
    dfs(next, tmp+dd[next]);
  }
}

int main() {
  cin>>n>>q;
  rep(i, n-1){
    cin>>a>>b;
    d[a].emplace_back(b);
  }
  rep(i, q){
    cin>>p>>x;
    dd[p] += x;
  }
  dfs(1, dd[1]);
  REP(i, 1, n){
    cout<<ans[i]<<" ";
  }
  cout<<ans[n]<<endl;
  return 0;
}

Measured memory_bytes: 20864
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define ALL(v) v.begin(),v.end()
#define mp make_pair
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}}
template <class X> void prrr(X test){int f=0;for(auto it:test){cout<<(f++!=0?" ":"")<<it;}cout<<endl;}
template<typename X>
istream&operator>>(istream&i,vector<X>&v){for(X&x:v)i>>x;return i;}

class UF { // union find from https://github.com/kartikkukreja/blog-codes (MIT)
    // [usage]
    // auto uf = new UF(n);
    // uf->merge(l, r); // 0 <= l, r <= n-1
    // ...
public:
    int *id; // inner id
    int cnt; // number of all vartices
    int *sz; // sz[i] means size of i's set
    UF(int N)   {
        cnt = N;
        id = new int[N];
        sz = new int[N];
        for(int i=0; i<N; i++) {
            id[i] = i;
            sz[i] = 1;
        }
    }
    ~UF() {
        delete [] id;
        delete [] sz;
    }
    int find(int p) {
        int root = p;
        while (root != id[root]) root = id[root];
        while (p != root) {
            int newp = id[p];
            id[p] = root;
            p = newp;
        }
        return root;
    }
    void merge(int x, int y) {
        int i = find(x);
        int j = find(y);
        if (i == j) return;
        
        if (sz[i] < sz[j]) {
            id[i] = j;
            sz[j] += sz[i];
        } else {
            id[j] = i;
            sz[i] += sz[j];
        }
        cnt--;
    }
    bool connected(int x, int y) {
        return find(x) == find(y);
    }
    int count() {
        return cnt;
    }
};

// return sorted 約数list 1 <= x <= n
vector<ll> divv(ll n) {
  vector<ll> v;
  for(ll i = 1; i*i <= n; i++) {
    if(n%i == 0) {
      v.push_back(i);
      if(i*i != n) v.push_back(n/i);
    }
  }
  sort(ALL(v));
  return v;
}

int main() {
    int h,w;
    string s;
    cin>>h;
    vector<pair<ll,ll>> v;
    rep(i, h){
        ll x, y;
        cin>>x>>y;
        v.push_back(mp(x,y));
    }
    unordered_map<ll, unordered_map<ll,ll>> m;
    ll ma = 0;
    rep(i, h) {
        rep(k, h){
            if (k == i) continue;
            auto x = v[i].first - v[k].first;
            auto y = v[i].second - v[k].second;
            m[x][y]++;
            ma = max(m[x][y], ma);
        }
    }
    pr(h - ma);

    
}


Measured memory_bytes: 888
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;

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


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

W,H=map(int,input().split())
p=sorted(int(input()) for i in range(W))
q=sorted(int(input()) for i in range(H))
ans=sum(p)*(H+1)+sum(q)*(W+1)
for i in range(W+H):
  if p[len(p)-1]>=q[len(q)-1]:
    ans-=p[len(p)-1]*len(q)
    p.pop()
    if p==[]:
      print(ans)
      exit()
  else:
    ans-=q[len(q)-1]*len(p)
    q.pop()
    if q==[]:
      print(ans)
      exit()

Measured memory_bytes: 11616
#include<bits/stdc++.h>
#include<iomanip>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define ar array
#define mxn 2005
#define mod 1000000007
#define ld long double
#define pb push_back
#define inf 1e18
#define fi first
#define se second
typedef long long int ll;
using namespace std;
ll dp[mxn],ans;
int main(void){
	fast;
	ll s,i,j;
	cin>>s;
	dp[0]=1;
	for(i=1;i<=s;i++){
		for(j=0;j<=s;j++){
			if(i-j>=3)
			dp[i]+=dp[j];
		}
		dp[i]%=mod;
	}
	cout<<dp[s];
}


Measured memory_bytes: 3636
N, A = [int(_) for _ in input().split()]
X = [int(_) - A for _ in input().split()]
X_plus = [_ for _ in X if _ > 0]
X_minus = [-_ for _ in X if _ < 0]
l_plus = len(X_plus)
l_minus = len(X_minus)
l_zero = len(X) - l_plus - l_minus
s_plus = sum(X_plus)
s_minus = sum(X_minus)
dp_plus = [1] + [0] * s_plus
dp_minus = [1] + [0] * s_minus
for i in range(l_plus):
    dp_plus_old = dp_plus.copy()
    for j in range(s_plus + 1 - X_plus[i]):
        dp_plus[j + X_plus[i]] += dp_plus_old[j]
for i in range(l_minus):
    dp_minus_old = dp_minus.copy()
    for j in range(s_minus + 1 - X_minus[i]):
        dp_minus[j + X_minus[i]] += dp_minus_old[j]
c_zero = 2 ** l_zero
ans = c_zero - 1
for j in range(1, min(s_plus, s_minus) + 1):
    ans += c_zero * dp_plus[j] * dp_minus[j]
print(ans)


Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
    int N; cin >> N;
    string S; cin >> S;
    int ans = 0;
    rep(i,1000){
        string t = to_string(i);
        int m = t.size();
        int a,b,c;
        if(m == 1){
            a = 0;
            b = 0;
            c = t[0]-'0';
        }
        else if(m == 2){
            a = 0;
            b = t[0]-'0';
            c = t[1]-'0';
        }
        else{
            a = t[0]-'0';
            b = t[1]-'0';
            c = t[2]-'0';
        }
        bool ok = false;
        int now = 0;
        rep(j,N){
            if(now == 0 && S[j]-'0' == a) now++;
            else if(now == 1 && S[j]-'0' == b) now++;
            else if(now == 2 && S[j]-'0' == c){
                ok = true;
            }
        }
        if(ok) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{

  int a[100];
  int i,n;
  scanf("%d",&n);
  
  for(i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }
   
  for(i = n-1; i >= 0; i--){
    if(i != n-1) printf(" "); 
    printf("%d", a[i]);
  }
  printf("\n");
	
	return 0;
}

Measured memory_bytes: 600
package main
 
import (
	"fmt"
  //"sort"
	//"strconv"
)
 
func main() {
  var N,R int
  fmt.Scanf("%d %d",&N,&R)
  if N>=10{
    fmt.Print(R)
  }else{
    fmt.Print(R+100*(-1*(N-10)))
  }
}

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

#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)

int main(){
	int n, k;
	while(cin >> n >> k , n|k){
		int t[110];
		bool possible = true;
		rep(i, 110)t[i] = 0;
		rep(i, k)cin >> t[i];
		rep(i, n){
			rep(j, k){
				int input;
				cin >> input;
				t[j]-= input;
			}
		}
		rep(i, k) if(t[i] < 0) possible = false;	
		if(possible) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i,n) for(ll i=0;i<(int)(n);i++)
#define REP(i,m,n) for(ll i=m;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; }
typedef long long ll;
typedef pair<ll,ll> pint;
const long long INF = 1LL<<60;
const ll MOD = 1000000007;
ll gcd(ll a,ll b){
    if(b==0){
        return a;
    }
    else{
        return gcd(b,a%b);
    }
}
int main(){
    ll n,k;cin>>n>>k;
    vector<ll> a(n);
    rep(i,n)cin>>a[i];
    vector<ll> visited(n,-1);
    ll rength = 0;
    ll now=0;
    visited[0]=0;
    ll cnt=1;
    ll next= 0;
    while(1){
        next=a[now]-1;
        //cout<<next<<endl;
        if(visited[next]!=-1){
            rength=cnt-visited[next];
            cnt=visited[next];
            break;
        }
        else{
            visited[next]=cnt;
            now=next;
            cnt++;
        }
    }
    //cout<<rength<<endl;
    ll ren =0;
    if(cnt<k){
        k-=cnt;
        //cout<<k<<endl;
        ren = k%rength;
        now = next;
        rep(i,ren){
            //cout<<next<<endl;
            next=a[now]-1;
            now=next;
        }
        cout<<next+1;
    }
    else{
        rep(i,n){
            if(visited[i]==k){
                cout<<i+1<<endl;
            }
        }
    }
}


Measured memory_bytes: 6428
//Om Sree Sai Ram
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
long long multiply(long long a,long long b)
{
	a = a%2019;
	b = b%2019;
	return (a*b)%2019;
}


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

string s;
cin>>s;
long long n = s.length();
//cout<<" n = "<<n<<endl;
vector<long long> dp(n);
long long count =0;
long long mul = 1;
for(long long i=n-1;i>=0;i--)
{
	long long pre = (i==n-1)?0:dp[i+1];
	pre %=2019;
	long long tmp = s[i]-'0';
	dp[i] = (pre+multiply(mul,tmp));
	dp[i] = dp[i]%2019;
	if(dp[i]<0)
	{
		dp[i]+=2019;
	}
	if(dp[i]==0)
	{
		count++;
	}
	mul *= 10;
	mul%=2019;
}
unordered_map<long long,long long> mp;
// for(auto c:dp)
// {
// 	cout<<c<<" ";
// }
//cout<<endl;
for(long long i=0;i<n;i++)
{
	mp[dp[i]]++;
}
long long ans =0;
for(auto c:mp)
{
	long long t = c.second;
	ans+=(t*(t-1))/2;
}
//cout<<" ans = "<<ans<<endl;
cout<<(ans+count)%mod<<endl;
}


Measured memory_bytes: 5208
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
  int N;
  cin>>N;
  
  int a[11];
  for(int i=0;i<N;++i){
    cin>>a[i];
  }
  
  int m=0;
  int sum=0;
  for(int i=0;i<N;++i){
    m=max(m,a[i]);
  }
  
  for(int i=0;i<N;++i){
    sum=sum+a[i];
  }
  
  if(2*m<sum)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  
}


Measured memory_bytes: 256
#include <iostream>  // cin,cout
#include <stdio.h>   // printf,scanf (standard input/output)
#include <cmath>     // abs(x),pow(x,2)
#include <string>
#include <string.h>  // strlen, strcmp
#include <algorithm> // min,max, sort(v.begin(),v.end())
#include <vector>
#include <time.h>
using namespace std;


void Print_vec (vector<char> v) {
    for (int i=0;i<v.size();i++) cout << v[i] << " " ; cout << endl;
}


int main() {
    

    
    vector<char> s;
    vector<char> t;
    
    string temp, temp2;
    cin >> temp;
    cin >> temp2;
    for (int i=0;i<temp.length();i++) {
        s.push_back(temp[i]);
    }
    for (int i=0;i<temp2.length();i++) {
        t.push_back(temp2[i]);
    }
    
    sort(s.begin(),s.end());
//    Print_vec(s);
    sort(t.begin(),t.end(),greater<int>());
//    Print_vec(t);
    
    char aaa[100], bbb[100];
    for (int i=0;i<temp.length();i++) {
        aaa[i] = s[i];
    }
    for (int i=0;i<temp2.length();i++) {
        bbb[i] = t[i];
    }
    
    string S = aaa;
    string T = bbb;
    
//    cout << S << endl;
//    cout << T << endl;
    
    if (S<T) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// NOT MY SOLUTION
int main(void){
    int k,v,u;
    cin>>k;
    vector<int> dp(k, 46);
    dp[1] = 1;
    deque<int> deq = {1};
    while(v = deq.front()){
        deq.pop_front();
        u = (v*10)%k;
        if(dp[u] > dp[v]){
            dp[u] = dp[v];
            deq.push_front(u);
        }
        u = (v+1)%k;
        if(dp[u] > dp[v]+1){
            dp[u] = dp[v]+1;
            deq.push_back(u);
        }
    }
    cout << dp[0];

}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdint>
#include <numeric>
#include <functional>

using Int = std::int64_t;

int main() {
	Int n, p, q;
	std::cin >> n >> p >> q;

	std::vector<Int> c(n);
	for (size_t i = 0; i < c.size(); ++i) {
		std::cin >> c[i];

		c[i] = p * (i + 1) + c[i];
	}

	std::sort(c.begin(), c.end(), std::greater<>{});
	for (int i = 1; i < n; ++i)
		c[i] += c[i - 1];

	Int minDelta = 0;
	for (int m = 1; m <= n; ++m) {
		const auto delta = m * p * (q + 2 * n) - p * m * m - c[m - 1];

		if (delta < minDelta)
			minDelta = delta;
	}

	std::cout << p * n * (2 * q + n - 1) / 2 - minDelta << std::endl;
}


Measured memory_bytes: 6788
package main

import (
    "bufio"
    "os"
    "strconv"
    "strings"
    "fmt"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
    sc.Scan()
    lst := strings.Split(sc.Text(), " ")
    ab, _ := strconv.Atoi(lst[0])
    bc, _ := strconv.Atoi(lst[1])
    fmt.Println(ab * bc / 2)
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t

//ライブラリ始まり

//定数

//円周率
const double PI = 3.1415926535897932384;

//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 1000000000000000; // = 10^15

//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";

//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7

//データ構造

//Union_Find木
struct UnionFind {
  vector<int> UF; // UF.at(i) : iの親の番号
  UnionFind(int N) : UF(N) { // 最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) {
      UF.at(i) = i;
    }
  }
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (UF.at(x) == x) {
      return x;
    }
    return UF.at(x) = root(UF.at(x));
  }
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); // xの根をrx
    int ry = root(y); // yの根をry
    if (rx == ry) {
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    }
    UF.at(rx) = ry; // xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

//関数

//ctoi
int ctoi(char c){
  if (c == '0') {
    return 0;
  }
  if (c == '1') {
    return 1;
  } 
  if (c == '2') {
    return 2;
  } 
  if (c == '3') {
    return 3;
  }
  if (c == '4') {
    return 4;
  } 
  if (c == '5') {
    return 5;
  } 
  if (c == '6') {
    return 6;
  }
  if (c == '7') {
    return 7;
  } 
  if (c == '8') {
    return 8;
  } 
  if (c == '9') {
    return 9;
  }
  return -1;  
}

//素数判定
bool PN(int x) {
  if (x <= 1) {
    return false; // 1や0,-1は素数ではない
  }
  if (x == 2) {
    return true; // √2 + 1 > 2 なので下でやると 2 ％ 2 = 0 となり判定できない
  }
  for (int i = 2; i < sqrt(x) + 1; i++) {
    if (x % i == 0) {
      return false; // 割れたら素数じゃない
    }
  }
  return true;
}

//ライブラリ終わり

int main() {
  int W, H, N;
  cin >> W >> H >> N;
  int MIX = 0, MAX = W;
  int MIY = 0, MAY = H;
  for (int i = 0; i < N; i++) {
    int X, Y, A;
    cin >> X >> Y >> A;
    if (A == 1) {
      MIX = max(X, MIX);
    }
    if (A == 2) {
      MAX = min(X, MAX);
    }
    if ( A == 3) {
      MIY = max(Y, MIY);
    }
    if (A == 4) {
      MAY = min(Y, MAY);
    }
  }
  if (MAX > MIX && MAY > MIY) {
    cout << (MAX - MIX) * (MAY - MIY) << endl;
  }
  else {
    cout << 0 << endl;
  }
}

Measured memory_bytes: 3676
#include<stdio.h>
int main(){
  int a,b[200000],n,max,min;
  scanf("%d",&a);
  for(n=0;n<a;n++){
    scanf("%d",&b[n]);
  }
  min=b[0];
  max=b[1]-b[0];
  for(n=1;n<a;n++){
    if(max<b[n]-min){
      max=b[n]-min;
    }
    
    if(min>b[n]){
      min=b[n];
    }
    
  }
  
  
  printf("%d\n",max);
  return 0;
}



Measured memory_bytes: 2520
s = %w(a b c)

h = Hash.new()
3.times{ |i| h.store(s[i], gets.chomp.reverse) }

pos = ?a

loop do
  # p "#{pos} #{h}"
  if h[pos] == ""
    puts pos.upcase
    exit
  end
  
  tmp = h[pos][-1]
  h[pos].chop!
  pos = tmp
end


Measured memory_bytes: 3836
def main():
    n = int(input())
    ans = solve(n)
    print(ans)

def F(a, b):
    #print(f'{a = } {b = }')
    return max(len(str(a)), len(str(b)))

def solve(n):
    for a in range(int(n ** (1 / 2)), 0, -1):
        if n % a == 0:
            return F(a, n // a)
    return


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define zero(v) memset(v,0,sizeof(v))
#define rep(i,n) for(int i=0;i<(n);i++)
#define foreach(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
#define all(v) (v).begin(),(v).end()
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
typedef long long ll;
typedef unsigned uint;
const int INF=0x3f3f3f3f;
const double EPS=1e-10;
typedef pair<int,int>P;
int inline in(){int x=0,c;for(;(uint)((c=getchar())-'0')>=10;)
{if(c=='-')return -in();if(!~c)throw ~0;}do{x=(x<<3)+(x<<1)+(c-'0');}
while((uint)((c=getchar())-'0')<10);return x;}
int n;
const int Maxv=5e6;
bitset<Maxv>B;
int main(){
	cin>>n;
	int sum=0;
	B[0]=1;
	for(int i=1;i<=n;i++){
		int x;cin>>x;sum+=x;
		B|=(B<<x);
	}
	rep(i,Maxv){
		if(B[i]&&2*i>=sum){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 2048
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
#include <cmath>
using namespace std;

struct UnionFind {
        int n;
        vector<int> parent;
        vector<int> rank;
        vector<long long> num;
        int find(int x) {
                if (parent[x] == x) return  x;
                return parent[x] = find(parent[x]);
        }
        UnionFind(int n_) {
                n = n_;
                parent.resize(n);
                for (int i = 0; i < n; i ++) parent[i] = i;
                rank.assign(n, 0);
                num.resize(n);
        }
        void unite(int x, int y) {
                if ((x = find(x)) != (y = find(y))) {
                        if (rank[x] < rank[y]) {
                                parent[x] = y;
                                num[y] += num[x];
                        } else {
                                parent[y] = x;
                                if (rank[x] == rank[y]) rank[x] ++;
                                num[x] += num[y];
                        }
                        n --;
                }
        }
        bool same(int x, int y) { return find(x) == find(y); }
        int get() { return n; }
        int get(int x) { return num[find(x)]; }
};

int main() {
        int n, m;
        scanf("%d%d", &n, &m);
        UnionFind uf(n);
        vector<pair<long long, int>> c(n);
        vector<int> bs(n);
        for (int i = 0; i < n; i ++) {
                int a, b;
                scanf("%d%d", &a, &b);
                c[i] = make_pair(max(0LL, (long long) a - b), i);
                uf.num[i] = b;
        }
        sort(c.begin(), c.end());
        vector<vector<int>> g(n);
        for (int i = 0; i < m; i ++) {
                int a, b;
                scanf("%d%d", &a, &b);
                a --, b --;
                g[a].push_back(b);
                g[b].push_back(a);
        }
        vector<long long> dp(n);
        vector<bool> used(n, false);
        for (int i = 0; i < n; i ++) {
                long long mi = c[i].first;
                int u = c[i].second;
                for (auto v : g[u]) if (used[v]) {
                        int ch = uf.find(v);
                        mi = min(mi, max(dp[ch], c[i].first - uf.num[ch]));
                }
                used[u] = true;
                for (auto v : g[u]) if (used[v]) {
                        uf.unite(u, v);
                }
                dp[uf.find(u)] = mi;
        }
        printf("%lld\n", dp[uf.find(0)] + uf.num[uf.find(0)]);
        return 0;
}



Measured memory_bytes: 10236