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


def main():
    n, m = map(int, input().split())

    if n == 1:
        a = int(input())
        for i in range(m):
            a //= 2
        print(a)
        exit()

    a = (list(map(int, input().split())))
    a = [-1 * i for i in a]
    heapq.heapify(a)

    for i in range(m):
        tmp = math.ceil(heapq.heappop(a) / 2)
        heapq.heappush(a, tmp)

    a = [-1 * i for i in a]
    print(sum(a))


if __name__ == '__main__':
    main()


Measured memory_bytes: 14380
N = gets.to_i
S = gets.chomp.chars
cnt = [[0, S.count(".")]]
S.each do |c|
  if c == "#"
    cnt << [cnt.last[0]+1, cnt.last[1]]
  else
    cnt << [cnt.last[0], cnt.last[1]-1]
  end
end
puts cnt.map {|a,b|a+b}.min

Measured memory_bytes: 29820
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0;i<n;i++)
using namespace std;
using ll =  long long ;
using P = pair<ll,ll> ;
const int INF = 1e9;
const int MOD = 1000000007;

int main(){
    ll n;
    cin >> n;
    vector<P> a(n);
    rep(i,n){
        cin >> a[i].first ;
        a[i].second = i;
    }
    sort(a.begin(),a.end(),greater<P>());
    //rep(i,n) cout << a[i].first << " " << a[i].second << endl;
    vector<vector<ll>> dp(n+1,vector<ll>(n+1,-1));
    dp[0][0] = 0;
    for(int i=1;i<=n;i++){
        rep(j,n+1){
            if(j==0) dp[i][j] = dp[i-1][j] + a[i-1].first * abs(a[i-1].second-(n-i));
            else{
                if(dp[i-1][j]>=0) dp[i][j] = max(dp[i][j],dp[i-1][j] + a[i-1].first * abs(a[i-1].second-(n-i+j)));
                if(dp[i-1][j-1]>=0) dp[i][j] = max(dp[i][j],dp[i-1][j-1] + a[i-1].first * abs(a[i-1].second - (j-1)));
            }
        }
    }/*
    rep(i,n+1){
        rep(j,n+1) cout << dp[i][j] <<" ";
        cout << endl;
    }*/
    ll ans = 0;
    rep(i,n+1) ans = max(ans,dp[n][i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 34680
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define digit(x) floor(log10(x))+1
#define mod 1000000007
#define endl "\n"
#define int long long
typedef long double ld;
typedef vector<vector<int> > matrix;
typedef vector<int> arr;
typedef vector<string> vs;
typedef vector<pair<int,int> > pv;
#define test() int t;cin>>t;while(t--)
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define ROF(i,a,b) for(int i=a;i>=b;--i)
#define all(x) x.begin(),x.end()
#define debug(x) cerr << #x << " is " << x << endl;
int bx[]={0,0,1,-1,1,-1,-1,1};
int by[]={1,-1,0,0,1,-1,1,-1};
//=================================================================//
int dp[1001][1001];
char mat[1001][1001];
int n,m;
int solve(int i, int j) {
    //base case
    if(i>=n || j>=m || mat[i][j]=='#') return 0;
    if(i==n-1 && j==m-1) return 1;

    //recursive case
    int &ans = dp[i][j];
    if(ans != -1) return ans%mod;

    return ans = (solve(i, j+1)%mod + solve(i+1,j)%mod)%mod;

}


#undef int
int main(){
#define int long long 
    fast;

    cin>>n>>m; 
    memset(dp, -1, sizeof dp);
    FOR(i,0,n-1) {
        FOR(j,0,m-1)
            cin>>mat[i][j];
    }
    cout<<solve(0,0)%mod;
    return 0;
}   

Measured memory_bytes: 9216
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>

using namespace std;

#define rep(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).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; }
template<typename T> inline bool smin(T &a, const T &b)   { return a > b ? a = b : a;    }
template<typename T> inline bool smax(T &a, const T &b)   { return a < b ? a = b : a;    }

typedef long long LL;

const int N = (int) 405, mod = (int) 0;
int a[N][N];
int main() {
	int n, m;
	cin >> n >> m;
	for (int x = 0; x < n; ++x) for (int y = 0; y < n; ++y) a[x][y] = 1;
	for (int j = 0; j < m; ++j) {
		int u, v;
		cin >> u >> v;
		--u, --v;
		if (a[u][v]) {
			a[u][v] = a[v][u] = 0;
			for (int x = 0; x < n; ++x) {
				if (!a[x][u]) {
					a[x][v] = a[v][x] = 0;	
				}
				if (!a[x][v]) {
					a[x][u] = a[u][x] = 0;	
				}
					
			}
		} else {
			for (int x = 0; x < n; ++x)
				a[x][u] = a[u][x] = a[v][x] = a[x][v] = 0;
		}
	}
	int res = 0;
	for (int x = 0; x < n; ++x)
		for (int y = x + 1; y < n; ++y)
			res += a[x][y];
	cout << res << endl;
}



Measured memory_bytes: 896
h,w=map(int, input().split())
a=[list(map(int, input().split())) for _ in range(h)]
n=0
ans=[]
for i in range(h):
    tw=w//2
    for j in range(tw):
        if a[i][j]%2==1:
            n+=1
            ans.append([i+1,j+1,i+1,j+2])
            a[i][j]-=1
            a[i][j+1]+=1
    for j in range(w-1,tw,-1):
        if a[i][j]%2==1:
            n+=1
            ans.append([i+1,j+1,i+1,j])
            a[i][j]-=1
            a[i][j-1]+=1
th=h//2
for i in range(th):
    if a[i][tw]%2==1:
        n+=1
        ans.append([i+1,tw+1,i+2,tw+1])
        a[i][tw]-=1
        a[i+1][tw]+=1
for i in range(h-1,th,-1):
    if a[i][tw]%2==1:
        n+=1
        ans.append([i+1,tw+1,i,tw+1])
        a[i][tw]-=1
        a[i-1][tw]+=1
print(n)
for t in ans:
    t=[str(t[i]) for i in range(4)]
    print(" ".join(t))


Measured memory_bytes: 31624
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let a: i32 = scan(tokens);
    let b: i32 = scan(tokens);
    let c: i32 = scan(tokens);
    println!("{}", std::cmp::max(0, c - (a - b)));
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <cstdlib>
#include <typeinfo>
#include <list>
#include <stdio.h>
#include <math.h>

using namespace std;


int MAX_N = 100005;


int main(int argc, char const *argv[]) {
  int n, l;
  long long max_time = 0;
  vector<int> icicles(MAX_N, 0);
  vector<int> valleys;
 
  scanf("%d %d", &n, &l);
  for (int i = 1; i <= n; i++) {
    int ai;
    scanf("%d", &ai);
    icicles[i] = ai;
  }
 
  valleys.push_back(1);
  for (int i = 2; i <= n - 1; i++) {
    if (icicles[i] < icicles[i - 1] && icicles[i] < icicles[i + 1]) {
      valleys.push_back(i);
    }
  }
  valleys.push_back(n);

  for (auto& pos: valleys) {
    auto left_time = l - icicles[pos], right_time = l - icicles[pos];
    auto left_peak = pos;
    while (icicles[left_peak - 1] > icicles[left_peak]){
      left_time += l - icicles[--left_peak];
    }
    auto right_peak = pos;
    while(icicles[right_peak + 1] > icicles[right_peak]){
      right_time += l - icicles[++right_peak];
    }
    if (left_time > max_time) max_time = left_time;
    if (right_time > max_time) max_time = right_time;
  }
  printf("%lld\n", max_time);
  return 0;
}

Measured memory_bytes: 3612
#include<stdio.h>

#define min(a,b) a<b?a:b
#define max(a,b) a>b?a:b
#define INF 2e9

int main(){
    int i;
    int n;
    int res = -INF;
    int r, mini=INF;
    scanf("%d", &n);
    for(i=0;i<n;i++){
        scanf("%d", &r);
        res = max(res, r-mini);
        mini = min(r, mini);
    }
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> P;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;
const ll mod=1000000007;
const ll INF=1e15;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

int main(){
  string S,T; cin>>S>>T;
  ll A,B; cin>>A>>B;
  string U; cin>>U;
  if(U==S) A--;
  else B--;
  cout<<A<<' '<<B<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;
using tiii = tuple<int, int, int>;

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

    vector<tiii> times;
    map<int, set<int>> t_set;
    rep(i, 0, n)
    {
        int s, t, c;
        cin >> s >> t >> c;

        times.emplace_back(s - 1, 0, c);
        times.emplace_back(t, 1, c);
        t_set[c].insert(t);
    }

    rep(i, 0, times.size())
    {
        int time, st, c;
        tie(time, st, c) = times[i];
        if (st == 1) continue;

        if (t_set[c].count(time + 1) > 0)
            times[i] = make_tuple(time + 1, 0, c);
        // for (auto tt: t_set[c])
        //     cout << tt << endl;
        // cout << time << ' ' << t_set[c].count(time + 1) << ' ' << t_set[c].size() << endl;
    }

    sort(times.begin(), times.end());
    int cnt = 0;
    map<int, int> t_cnt;
    rep(i, 0, times.size())
    {
        int time, st, c;
        tie(time, st, c) = times[i];

        if (st == 0)
        {
            ++cnt;
            t_cnt[time] = cnt;
        }
        else
        {
            --cnt;
            t_cnt[time] = cnt;
        }
    }
    assert (cnt == 0);

    int ans = 0;
    for(auto t_c: t_cnt)
        ans = max(ans, t_c.second);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12336
a, b, k = [int(i) for i in input().split()]

if a <= k:
  k = k - a
  a = 0
else:
  a = a - k
  k = 0

if b <= k:
  k = k - b
  b = 0
else:
  b = b - k
  k = 0

print(a, b)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool is_prime(ll n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された

    if(n%2 == 0) return false;
    if(n%3 == 0) return false;
    // 2と3の倍数でないので6の倍数ではないことが保証された

    if(n%6 != 1 && n%6 != 5) return false;
    // 6の倍数前後の数(素数かもしれない数)であることが保証された

    // 6の倍数前後の数を使って試し割りをする
    for(int i=5;i*i<=n;i+=6){
        if(n%i     == 0) return false; // 6n-1
        if(n%(i+2) == 0) return false; // 6n+1
    }

    return true;
}
int main(){
 ll x;
  cin >> x;
  while(1){
  if(is_prime(x)){
  cout << x << endl;
    break;
  }
    x++;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MAX_N 100
typedef long long ll;

int n;
int a[MAX_N];
int b[MAX_N]; //入力用

void solve()
{
    ll ans = 0;
    // 最初と最後は確定
    ans += b[0];
    ans += b[n - 2];

    int comp = b[0];

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

        comp = b[i];
    }

    cout << ans << endl;
}

int main()
{
    cin >> n;

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

    solve();
}


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

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

  bool isY = false;
  string S;

  for (int i = 0; i < N; i++) {
    cin >> S;
    if (S ==  "Y") {
      isY = true;
      break;
    }
  }

  if (isY) {
    cout << "Four" << endl;
  } else {
    cout << "Three" << endl;
  }
}


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

using namespace std;

int main(){
    string s;
    cin>>s;
    int cnt1=0, cnt2=0;
    for(int i=0;i<3;++i){
        if(s[i]=='A')++cnt1;
        else ++cnt2;
    }

    if(cnt1==3||cnt2==3)cout<<"No";
    else cout<<"Yes";

    return 0;
}


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

public class Main{
	public static void main(String[] args) {
		int x,a,b;
		Scanner sc = new Scanner(System.in);
		x = sc.nextInt();
		a = sc.nextInt();
		b = sc.nextInt();
		System.out.println((x - a) % b);
	}
}


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

int main()
{
  long long int z;
  while (cin >> z) {
    if (z == 0LL)
      break;

    long long int x3y3 = 0LL;
    for (long long int x = 1LL; x*x*x <= z*z*z; ++x) {
      for (long long int y = 1LL; x*x*x+y*y*y <= z*z*z; ++y)
	x3y3 = max(x3y3, x*x*x+y*y*y);
    }

    cout << z*z*z - x3y3 << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define M (L+R)/2
#define N 500009
#define inf 99999999999
#define ll long long
#define mod 1000000007
using namespace std;
ll a,b,ans;
int main(){

	ios::sync_with_stdio(0);
	
	cin>>a>>b;
	ans=a/b;
	if(a%b!=0)ans++;
	cout<<ans<<endl;

	return 0;
}



Measured memory_bytes: 256
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val x = nextInt()

    var ans = 1.0
    for (b in 2..x) {
        for (p in 2..x) {
            val cal = Math.pow(b.toDouble(), p.toDouble())
            if (cal <= x && cal > ans) {
                ans = cal
            }
            if (cal > x) break
        }
    }

    println(ans.toInt())
}

fun next() = readLine()!!
fun nextInt() = next().toInt()

fun println(value : Any) {
    pw.println(value)
}

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

int main()
{
    int N, n=0, keta=0, sum=0;
    cin >> N;
    n = N;
    for (int i = 1; i<=N;i++)
    {
        if(i<10)
            sum ++;
        else if(i>=100 && i<1000)
            sum++;
        else if (i>=10000 && i<100000)
            sum++;
    }
    

    cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int month[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	int m, d;
	
	while (true) {
		cin >> m >> d;
		if (m==0 || d==0) break;
		
		int day = 3; // 2013/12/31 is Wednesday
		
		for (int i=0; i<m-1; i++) day += month[i];
		day += d;
		
		switch (day%7) {
		case 0 :
			cout << "Sunday"; break;
		case 1 :
			cout << "Monday"; break;
		case 2 :
			cout << "Tuesday"; break;
		case 3 :
			cout << "Wednesday"; break;
		case 4 :
			cout << "Thursday"; break;
		case 5 :
			cout << "Friday"; break;
		case 6 :
			cout << "Saturday"; break;
		}
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 2976
def solve(string):
    h, w, d, *a = map(int, string.split())
    a, q, lr = a[:h * w], a[h * w], a[h * w + 1:]
    n = h * w
    index = [0 for _ in range(n)]
    for i, _a in enumerate(a):
        index[_a - 1] = i
    # index = [a.index(i + 1) for i in range(h * w)]
    diff = [0] * d + [
        abs(i0 // w - i1 // w) + abs(i0 % w - i1 % w) for i0, i1 in zip(index, index[d:])
    ]
    costs = []
    for i in range(n):
        if i < d:
            costs.append(diff[i])
        else:
            costs.append(diff[i] + costs[i - d])
    return "\n".join([str(costs[r - 1] - costs[l - 1]) for l, r in zip(lr[::2], lr[1::2])])


if __name__ == '__main__':
    n, m, d = map(int, input().split())
    ins = '{} {} {}\n'.format(n, m, d) + '\n'.join([input() for _ in range(n)])
    n = int(input())
    print(solve(ins + '\n{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))


Measured memory_bytes: 37004
if __name__ == '__main__':
    s = list(str(input()))
    t = list(str(input()))
    s.sort()
    t.sort(reverse=True)
    flag = False
    for n in range(min(len(s), len(t))):
        if s[n] < t[n]:
            flag = True
            print('Yes')
            break
        elif s[n] == t[n]:
            continue
        else:
            flag = True
            print('No')
            break
    if flag == False:
        if len(s) < len(t):
            print('Yes')
        else:
            print('No')
    
            

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.14159265358979 ;
const ll mod = 1e9 + 7 ;

void solve ( int test_case )
{
    int n , k ;
    cin >> n >> k ;

    int r , sc , p ;
    cin >> r >> sc >> p ;

    string s ;
    cin >> s ;

    int ans = 0 ;

    for ( int i=0 ; i < k ; i ++ )
    {
        if ( s[i] == 'r' ) ans += p ;
        else if ( s[i] == 'p' ) ans += sc ;
        else ans += r ;
    }

    for ( int i=k ; i < n ; i ++ )
    {
        if ( s[i] == s[i - k] )
            s[i] = '.' ;

        if ( s[i] == 'r' ) ans += p ;
        else if ( s[i] == 'p' ) ans += sc ;
        else if ( s[i] == 's' ) ans += r ;
    }

    cout << ans ; line
}

int main()
{fast
    int t = 1;
    // cin >> t;

    for ( int i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


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

vector<pair<ll, ll>> PrimeFactorization(ll n) {
  vector<pair<ll, ll>> res;
  for (ll p=2; p*p<=n; p++) {
    if (n%p!=0) continue;
    int num=0;
    while (n%p==0) { num++; n/=p; }
    res.push_back(make_pair(p, num));
  }
  if (n!=1) res.push_back(make_pair(n, 1));
  return res;
}

const int MAX=202020;
const int MOD=1000000007;

ll fac[MAX],finv[MAX],inv[MAX];
void COMinit() {
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (int i=2; i<MAX; i++) {
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}

ll COM(int n, int k) {
  if (n<k) return 0;
  if (n<0||k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int main() { 
  int n,m; cin>>n>>m;
  COMinit();
  auto vec=PrimeFactorization(m);
  ll res=1;
  for (auto x : vec) {
    int num=x.second;
    ll tmp=COM(num+n-1, n-1);
    res=(res*tmp)%MOD;
  }
  cout<<res<<endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define int long long
int inf = 10e17;
#define mod 1000000007

bool vis[200005];
vector<int> vec[2000005], v1;
vector<pair<int, int>> vec2[2000005];
int child[2000005];
int parent[2000005];
int div1[100005];
int min_indx[900005];
int count1 = 0;
int height = 0;
int max_indx[200005];
void dfs(int node)
{

    vis[node] = 1;

    for (int i = 0; i < vec[node].size(); i++)
    {
        if (!vis[vec[node][i]])
        {
            parent[vec[node][i]] = node;
            dfs(vec[node][i]);
        }
    }
}

int MAXN = 200005;
int LOGMAXN = (int)log2(200005) + 1;
int M[200005][60];
void process2(int A[], int N)
{
    int i, j;

    //initialize M for the intervals with length 1
    for (i = 0; i < N; i++)
        M[i][0] = i;
    //compute values from smaller to bigger intervals
    for (j = 1; 1 << j <= N; j++)
        for (i = 0; i + (1 << j) - 1 < N; i++)
            if (A[M[i][j - 1]] < A[M[i + (1 << (j - 1))][j - 1]])
                M[i][j] = M[i][j - 1];
            else
                M[i][j] = M[i + (1 << (j - 1))][j - 1];
}
//int parent[200005];
vector<int> vec1;
//bool vis[200005];
//int hei[200005];
int lev[200005];
int dis[200005];
bool cmp(pair<int, int> &a,
         pair<int, int> &b)
{
    return a.second < b.second;
}
void Ios()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //  int t;
}
 int arr[10000000] = {0};
int32_t main()
{
    //  Ios();
    //  int t;
    int n;
    cin >> n;
   
    for (int i = 1; i < 100; i++)
    {
        for (int j = 1; j < 100; j++)
        {
            for (int k = 1; k < 100; k++)
            {
                int p = (i * i + j * j + k * k + i * j + i * k + k * j);
                arr[p]++;
            }
        }
    }
    for (int i = 1; i <= n; i++)
        cout << arr[i] << "\n";
    return 0;
}


Measured memory_bytes: 97852
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate, gcd など
#include <cassert>    // assert
#include <stdexcept>
#include <bitset>
using namespace std;

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
// typedef int128_t ll;
// typedef cpp_int ll;

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

// #define NDEBUG 1
// debug用出力 https://trap.jp/post/998/
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << H << " ";
    debug_out(T...);
}
#ifdef NDEBUG
#define debug(...)
#else
#define debug(...) debug_out(__VA_ARGS__)
#endif

//////////////// //////////////// //////////////// //////////////// ////////////////
//////////////// //////////////// //////////////// //////////////// ////////////////

constexpr inline ll mod = 1'000'000'007;
// constexpr int max_n = 200'000 + 5;

int x,y;
ll res;

ll modfact(int n)
{
    ll res = 1;
    for (int i = 2; i <= n; i++)
    {
        res = res * i % mod;
    }
    return res;
}

ll modpow(ll n, ll k)
{
    if (k == 0)
    {
        return 1;
    }
    else if (k % 2 == 0)
    {
        ll res = modpow(n, k / 2);
        return res * res % mod;
    }
    else
    {
        ll res = modpow(n, k - 1);
        return res * n % mod;
    }
}

ll modinv(ll n)
{
    return modpow(n, mod - 2);
}

int main()
{
    // 入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(10); // 浮動小数の表示の精度

    cin>>x>>y;
    int z = x + y;
    if (z < 0 || y - 2*x > 0 || x - 2*y > 0 || z%3 != 0)
    {
        cout << 0 << '\n';
        return 0;
    }
    z /= 3;
    ll k = x - z, l = z - k; // l == 2*z - x == y - z
    res = modfact(z) * modinv(modfact(k)) % mod * modinv(modfact(l)) % mod;
    cout << res << '\n';

    return 0;
}


Measured memory_bytes: 3604
def BC133_C():
    l, r = map(int, input().split())
    a, b = divmod(l, 2019)
    c, d = divmod(r, 2019)
    e = 2018
    if b == 0 or d == 0:
        print(0)
    elif a < c:
        print(0)
    else:
        for i in range(b, d):
            for j in range(i + 1, d + 1):
                e = min(e, (i * j) % 2019)
        print(e)


BC133_C()

Measured memory_bytes: 3064
#include <stdio.h>

long n, a[200000];

long get_abs(long x, long y) {
    long tmp;
    
    tmp = x - y;
    if (tmp < 0) tmp *= -1;
    return tmp;
}

int main(void) {
    long i, sum = 0;
    long x, y, abs, min;
    
    scanf("%ld", &n);
    
    for (i = 0; i < n; ++i) {
        scanf("%ld", &a[i]);
        sum += a[i];
    }
    
    x = 0;
    y = sum;
    x += a[0];
    y -= a[0];
    abs = get_abs(x, y);
    min = abs;
    
    for (i = 1; i < n - 1; ++i) {
        x += a[i];
        y -= a[i];
        abs = get_abs(x, y);
        
        if (abs < min) {
            min = abs;
        }
    }
    
    printf("%ld\n", min);
    return 0;
}


Measured memory_bytes: 1664
#include <stdio.h>

typedef enum { top, south, east, west, north, bottom, NUM_SIDES } sides;

void roll(int *dice, const sides operator)
{
    int anti_op;
    switch( operator ){
    case south: anti_op = north; break;
    case east: anti_op = west; break;
    case west: anti_op = east; break;
    case north: anti_op = south; break;
    default: break;
    }

    int tmp = dice[operator];
    dice[operator] = dice[top];
    dice[top] = dice[anti_op];
    dice[anti_op] = dice[bottom];
    dice[bottom] = tmp;
}

int main()
{
    int i;

    int dice[NUM_SIDES];
    char operator[101];
    for( i = 0; i < NUM_SIDES; ++i )
        scanf("%d", &dice[i]);
    scanf("%s", operator);

    for( i = 0; operator[i]; ++i ){
        switch( operator[i] ){
        case 'E': roll(dice, east); break;
        case 'N': roll(dice, north); break;
        case 'S': roll(dice, south); break;
        case 'W': roll(dice, west); break;
        }
    }

    printf("%d\n", dice[top]);

    return 0;
}

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

int main() {
    string s, t;
    cin >> s >> t;

    string sb, tb;
    for (int i = 0; i < s.size(); i++) {
        if (i % 2) sb += s[i];
        else tb += s[i];
    }

    bool ans = false;
    int c = 0;
    for (int i = 0; i < t.size(); i++) {
        if (sb[c] == t[i]) c++;
    }
    if (c == sb.size()) ans = true;
    c = 0;
    for (int i = 0; i < t.size(); i++) {
        if (tb[c] == t[i]) c++;
    }
    if (c == tb.size()) ans = true;

    cout << (ans ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int h1,m1,h2,m2,k,d;
    cin>>h1>>m1>>h2>>m2>>k;
    d=((h2*60)+m2)-((h1*60)+m1)-k;
    cout<<d<<endl;
}


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<int> x(m);
	vector<int> brg(m - 1);
	rep(i, m) {
		cin >> x[i];
	}
	if (n >= m) {
		cout << 0 << endl;
		return 0;
	}
	sort(x.begin(), x.end());
	rep(i, m - 1) {
		brg[i] = x[i + 1] - x[i];
	}
	sort(brg.begin(), brg.end());
	int ans = 0;
	int res = n - 1;
	while (res > 0) {
		res--;
		brg.pop_back();
	}
	rep(i, brg.size()) ans += brg[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

using namespace std;

int N,ans;
char table[50][51],work[50][51];

bool strCmp(char* base, char* comp){
	int length1 = 0,length2 = 0;
	for(int i=0;base[i] != '\0'; i++)length1++;
	for(int i=0;comp[i] != '\0'; i++)length2++;
	if(length1 != length2)return false;

	for(int i=0;base[i] != '\0'; i++){
		if(base[i] != comp[i])return false;
	}
	return true;
}

void strcpy(char* to,char* str){
	for(int i=0;str[i] != '\0';i++){
		to[i] = str[i];
		to[i+1] = '\0';
	}
}

bool calc(int K){

	int calc_index,count = 0;
	char tmp[51];

	for(int i = 0; i < N; i++){
		tmp[0] = table[i][0];
		tmp[1] = '\0';
		calc_index = 1;
		for(int p = 1; table[i][p] != '\0' && calc_index < K;p++){
			if(table[i][p-1] == 'a' || table[i][p-1] == 'i' || table[i][p-1] == 'u' || table[i][p-1] == 'e' || table[i][p-1] == 'o'){ //???????????????????????§????????´???
				tmp[calc_index++] = table[i][p];
				tmp[calc_index] = '\0';
			}
		}
		for(int a = 0; a < i; a++){
			if(strCmp(work[a],tmp))return false;
		}
		strcpy(work[i],tmp);
		count++;
	}

	return count == N;
}


void func(){

	for(int i = 0; i < N; i++){
		scanf("%s",table[i]);
	}

	for(int K = 1; K <= 50; K++){
		if(calc(K)){
			ans = K;
			break;
		}
	}

	printf("%d\n",ans);
}

int main(){

  while(true){
	  scanf("%d",&N);
	  if(N == 0)break;

	  ans = -1;

	  func();
  }

    return 0;
}

Measured memory_bytes: 2712
#include <iostream>
#include <fstream>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>

using namespace std;

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

/*
    freopen("input","r",stdin);
    freopen("output","w",stdout);
*/

bool sieve[2210];

vector<ll> P;

void init() {
	memset(sieve, 0, sizeof(sieve));
	for (int i = 2;i <= 2200;i++) {
		if (sieve[i] == 0) {
			P.push_back(i);
			for (int j = i;j <= 2200;j += i) sieve[j] = 1;
		}
	}
	return;
}

bool sq(ll n) {
	ll a = sqrt(n);
	while (a * a < n) a++;
	while (a * a > n) a--;
	return a * a == n;
}

int main() {
    ios::sync_with_stdio(false);
    init();
    ll A[100010], B[100010], C[100010], D[100010];
    int N;
    cin >> N;
    for (int i = 0;i < N;i++) cin >> A[i];
    for (int i = 0;i < N;i++) {
    	ll crt = A[i];
    	ll rem = 1;
    	ll o = 1;
    	for (int j = 0;j < P.size();j++) {
    		if (crt % P[j] != 0) continue;
    		int ct = 0;
    		while (crt % P[j] == 0) {
    			ct++;
    			crt /= P[j];
    		}
    		if (ct % 3 == 1) {
    			rem *= P[j];
    			o *= P[j] * P[j];
    		}
    		else if (ct % 3 == 2) {
    			rem *= P[j] * P[j];
    			o *= P[j];
    		}
    	}
    	B[i] = rem;
    	C[i] = o;
    	D[i] = crt;
    }
    bool ok = 0;
    unordered_map<ll, ll> G, H;
    ll res = 0;
    for (int i = 0;i < N;i++) {
    	ll rem = B[i];
    	ll o = C[i];
    	if (rem == 1 && D[i] == 1) {
    		ok = 1;
    		continue;
    	}
    	if (D[i] == 1) {
    		G[rem]++;
    		H[rem] = o;
    		H[o] = rem;
    	}
    	else {
    		if (sq(D[i])) {
    			ll a = sqrt(D[i]);
				while (a * a < D[i]) a++;
				while (a * a > D[i]) a--;
				G[D[i] * rem]++;
				H[D[i] * rem] = o * a;
				H[o * a] = D[i] * rem;
    		}
    		else {
    			if (D[i] > 1E5 || D[i] * D[i] > 1E12 / o) {
    				res++;
    			}
    			else {
    				G[D[i] * rem]++;
    				H[D[i] * rem] = o * D[i] * D[i];
    				H[o * D[i] * D[i]] = D[i] * rem;
    			}
    		}
    	}
    }
    if (ok == 1) res++;
    unordered_map<ll, ll>::iterator it;
    ll tmp = 0;
    for (it = G.begin();it != G.end();++it) {
    	ll rem = it->first;
    	ll o = H[rem];
    	if (G.find(o) == G.end()) {
    		res += it->second;
    	}
    	else {
    		ll a = it->second;
    		ll b = G[o];
    		if (a > b) res += a;
    		if (a == b) tmp += a; 
    	}
    }
    res += tmp / 2;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 14060
// Input macro
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
    "8 6" => "Alice",
    "1 1" => "Draw",
    "13 1" => "Bob",
}

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        a: u8,
        b: u8,
    }

    if a == b {
        return String::from("Draw");
    } else if (b != 1 && a > b) || a == 1 {
        return String::from("Alice"); 
    } else {
        return String::from("Bob");  
    }
}

Measured memory_bytes: 4352
x, y, a, b, c = map(int, input().split())

p = [int(x) for x in input().split()]
p.sort(reverse=True)
p = p[:x]

q = [int(x) for x in input().split()]
q.sort(reverse=True)
q = q[:y]
r = [int(x) for x in input().split()]
r.sort(reverse=True)

sub = p+q+r
sub.sort(reverse=True)
ans = sum(sub[:x+y])
print(ans)

Measured memory_bytes: 22548
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define endl "\n"
#define vi vector<int>
#define vb vector<bool>
#define pii pair<int,int>
#define ss second
#define ff first
#define vpii vector<pii>
#define vvi vector<vi >
#define vs vector<string>
#define all(x) x.begin(),x.end()
#define mii map<int,int>
#define rep(i,n) for(ll i=0;i<n;i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define per1(i,n) for(ll i=n;i>0;i--)
#define repeat(i,start,n) for(ll i=start;i<n;i++)
#define print(a,n) for(ll i=0;i<n;i++){ cout<<a[i]<<" ";}
#define M 1000000007
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;
    //cin>>t;
    while(t--)
    {
        int n,k;
        cin>>n>>k;
        int arr[n];
        rep(i,n)
            cin>>arr[i];
        int cost[n];
        rep(i,n)
            cost[i]=INT_MAX;
        cost[0]=0;
        rep(i,n-1)
        {
            rep1(j,k)
            {
                if(i+j==n)
                    break;
                cost[i+j]=min(cost[i+j],cost[i]+abs(arr[i+j]-arr[i]));
            }
        }
        cout<<cost[n-1];
    }
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main()
{
  int n;
  cin>>n;
  int v[n];
  rep(i,n) cin>>v[i];

  map<int,int> even,odd;
  rep(i,n)
  {
    if(i%2==0)
    {
      if(even.find(v[i])==even.end()) even[v[i]]=1;
      else even[v[i]]++;
    }
    else
    {
      if(odd.find(v[i])==odd.end()) odd[v[i]]=1;
      else odd[v[i]]++;
    }
  }

  vector<P> ev,od;
  for(auto x:even)
  {
    ev.push_back(P(x.second,x.first));
  }
  for(auto x:odd)
  {
    od.push_back(P(x.second,x.first));
  }
  ev.push_back(P(0,0));
  od.push_back(P(0,0));

  sort(ev.begin(),ev.end());
  reverse(ev.begin(),ev.end());
  sort(od.begin(),od.end());
  reverse(od.begin(),od.end());

  int ans;
  if(ev.at(0).second!=od.at(0).second) ans=n-ev.at(0).first-od.at(0).first;
  else ans=min(n-ev.at(1).first-od.at(0).first,n-ev.at(0).first-od.at(1).first);

  cout<<ans<<endl;
}

Measured memory_bytes: 6520
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_3_B&lang=jp
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n,i=1;
  while(cin>>n,n){
    printf("Case %d: %d\n",i,n);
    i++;
  }
  return 0;
}



Measured memory_bytes: 3132
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <queue>
#include <math.h>
#include <cmath>
#include <unordered_map>

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

int main(){
    long long n;
    cin>>n;
    int mx=0;
    unordered_map<string, int> mp;
    string tmp="";
    rep(i,n){
        cin>>tmp;
        mp[tmp]++;
        mx=max(mp[tmp],mx);
    }
    vector<string> ans(0);
    for (pair<string,int>p: mp){
        if(mx==p.second)ans.push_back(p.first);
    }
    sort(ans.begin(),ans.end());
    for(int i=0;i<ans.size();i++){
        cout<<ans[i]<<endl;
    }


}

Measured memory_bytes: 26692
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

const int INF = 1.0e9;

int dp[10101];

int match[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6};

int main() {
    int N, M;
    int A[9];

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

    dp[0] = 0;
    for (int i = 1; i <= N; i++) {
        int max_digits = -INF;
        for (int j = 0; j < M; j++) {
            if (i - match[A[j] - 1] < 0) continue;
            max_digits = max(max_digits, dp[i - match[A[j] - 1]]);
        }
        dp[i] = (max_digits == -INF ? -INF : max_digits + 1);
    }
    sort(A, A + M);
    reverse(A, A + M);
    int num_match = N;
    while (num_match > 0) {
        for (int j = 0; j < M; j++) {
            if (num_match - match[A[j] - 1] >= 0 && dp[num_match] == dp[num_match - match[A[j] - 1]] + 1) {
                cout << A[j];
                num_match -= match[A[j] - 1];
                break;
            }
        }
    }
    cout << endl;
}

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

using namespace std;
typedef long double ll;
const int maxn = 1005;
int l[maxn], r[maxn];


int main()
{

        string st;
        ll k;
        cin>>st>>k;
        ll tmp = 5 * 1e15;
        for(int i=0;i<st.size();i++)
        {
            k = k - pow(st[i]-'0', tmp);
            if(k <= 0)
            {
                cout<<st[i]<<endl;
                return 0;
            }
        }
        cout<<st[st.size()-1]<<endl;



    return 0;
}


Measured memory_bytes: 512
#include <cmath>
#include <iostream>
#include <iomanip>

/*
ax + by = c
dx + ey = f

x = (c-by)/a
d(c-by)/a + ey = f
dc/a - dby/a + ey = f
ey - dby/a = f - dc/a
y(e-db/a) = f - dc/a
y = (f-dc/a)/(e-db/a)

aex + bey = ce
bdx + bey = bf
aex - bdx = ce - bf
x(ae - bd) = ce - bf
x = (ce - bf)/(ae - bd)
by = c - ax
y = (c - ax)/b
*/
int main()
{
    while(true){
        double a, b, c, d, e, f;
        std::cin >> a >> b >> c >> d >> e >> f;
        if(std::cin.eof()) break;
        double x, y;
        // if(b){
            x = (c*e - b*f) / (a*e - b*d);
            y = (c - a*x) / b;
        // }else{
        //     y = (f-d*c/a)/(e-d*b/a);
        //     x = (c-b*y)/a;
        // }
        if(x == -0) x = 0;
        if(y == -0) y = 0;
        std::cout << std::fixed << std::setprecision(3);
        std::cout << x << " " << y << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3116
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>

using namespace std;
using ll = long long;
#define MOD 1e9+7

vector< int > z_algorithm(const string &s) {
  vector< int > prefix(s.size());
  for(int i = 1, j = 0; i < s.size(); i++) {
    if(i + prefix[i - j] < j + prefix[j]) {
      prefix[i] = prefix[i - j];
    } else {
      int k = max(0, j + prefix[j] - i);
      while(i + k < s.size() && s[k] == s[i + k]) ++k;
      prefix[i] = k;
      j = i;
    }
  }
  prefix[0] = (int) s.size();
  return prefix;
}

int main(){
    int N;cin >> N;
    string s;cin >> s;
    ll ans = 0;
    for(int i = 0;i < N;i++){
        vector<int> uku = z_algorithm(s.substr(i, N));
        for(int j = 0;j < uku.size();j++){
            if(uku.at(j) <= j)ans = max((int)ans, uku.at(j));
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>

using namespace std;

#define mod 1000000007

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	int x = 3 * c - a - b;
	cout << a << " " << b << " " << x << endl;
	cout << b + 2 * x - 2 * c << " " << c << " " << a + c - x << endl;
	cout << a + b - c << " " << a + x - c << " " << b + x - c << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <iomanip>
#include <tuple>

using namespace std;
const long long mod=1e9+7;
const long long INF=1LL<<60;

int main(){
    int n;
    cin>>n;
    vector<long long> a(n),b(n);
    vector<tuple<long long,long long,long long>> c(n);
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        c[i]=make_tuple(a[i]+b[i],a[i],b[i]);
    }
    sort(c.begin(),c.end());
    reverse(c.begin(),c.end());
    long long ans=0;
    for(int i=0;i<n;i++){
        if(i%2==0)ans+=get<1>(c[i]);
        else ans-=get<2>(c[i]);
    }
    cout<<ans<<endl;
    
}
 
   

Measured memory_bytes: 4224
#include <stdio.h>
#include <math.h>
typedef struct {
        double x;
        double y;
}Point;
#define PI 3.141592
void kock(int n,Point p1,Point p2){
        Point s,t,u;
        if(n==0) {
                return;
        }
        s.x=(2*p1.x+p2.x)/3;
        s.y=(2*p1.y+p2.y)/3;
        t.x=(p1.x+2*p2.x)/3;
        t.y=(p1.y+2*p2.y)/3;

        u.x=(t.x-s.x)*cos(60*M_PI/180)-(t.y-s.y)*sin(60*M_PI/180)+s.x;
        u.y=(t.x-s.x)*sin(60*M_PI/180)+(t.y-s.y)*cos(60*M_PI/180)+s.y;

        kock(n-1,p1,s);
        printf("%f %f\n",s.x,s.y);
        kock(n-1,s,u);
        printf("%f %f\n",u.x,u.y);
        kock(n-1,u,t);
        printf("%f %f\n",t.x,t.y);
        kock(n-1,t,p2);
}

int main(){
        int n;
        Point p1,p2;
        p1.x=0;
        p1.y=0;
        p2.x=100;
        p2.y=0;
        scanf("%d",&n);
        printf("%f %f\n",p1.x,p1.y);
        kock(n,p1,p2);
        printf("%f %f\n",p2.x,p2.y);
        return 0;

}



Measured memory_bytes: 2060
import itertools
N = int(input())
if N < 3:
    print(0)
    exit()
L = [int(i) for i in input().split()]
L.sort()
ans = 0
for a,b,c in itertools.combinations(L,3):
    if a == b or b == c:
        continue
    if a + b > c:
        ans += 1
print(ans)

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

int a,b,c;

int main() {


        int a[3];cin >> a[0] >> a[1] >> a[2];

        int mx=INT_MAX;

        int k=6;

        while(k--) {

                mx=min(mx,abs(a[1]-a[0])+abs(a[2]-a[1]));
                next_permutation(a,a+3);


        }
        cout << mx << endl;


}


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

using namespace std;

template <class T,class U>
void maximize(T &x,U y){
    if(x < y)x = y;
}
template <class T,class U>
void minimize(T &x,U y){
    if(x > y)x = y;
}
template <class T>
T Abs(T x){
    return (x < (T)0 ? -x : x);
}

#define llong long long
#define MASK(i) ((1LL) << (i))
#define BIT(x,i) (((x) >> (i)) & 1)
#define all(c) (c).begin(),(c).end()
#define fn "test"    ///FILE_NAME_HERE

/*----------END_OF_TEMPLATE----------*/


namespace task{

    const int N = 2e5 + 5;
    int h[N];
    llong f[N];
    int n;
    llong c;

    struct Line{
    public:
        llong m,b;
    public:
        Line(llong _m,llong _b){
            this -> m = _m;
            this -> b = _b;
        }
        llong evalute(int x) const{
            return m * (llong)x + b;
        }
    };

    class ConvexHullTrick{
    public:
        vector <Line> hull;
    public:
        bool bad(Line la,Line lb,Line lc){
            return (lc.b - la.b) * (la.m - lb.m) <= (la.m -lc.m) * (lb.b - la.b);
        }
        void addLine(Line l){
            while(hull.size() >= 2 and bad(hull[hull.size() - 2],hull.back(),l)){
                hull.pop_back();
            }
            hull.emplace_back(l);
        }
        llong getMin(int x){
            int l = 0,r = hull.size() - 1;
            llong ret = 0;
            while(l < r){
                int mid = (l + r) >> 1;
                if(hull[mid].evalute(x) < hull[mid + 1].evalute(x)){
                    r = mid - 1;
                    minimize(ret,hull[mid].evalute(x));
                } else {
                    l = mid + 1;
                }
            }
            minimize(ret,min(hull[l].evalute(x),hull[r].evalute(x)));
            return ret;
        }
    };

    void solve(){
        cin>>n>>c;
        for(int i = 1;i <= n;++i){
            cin>>h[i];
        }
        ConvexHullTrick *cht = new ConvexHullTrick();
        cht -> addLine(Line(-2 * h[1],1LL * h[1] * 1LL * h[1]));
        for(int i = 2;i <= n;++i){
            f[i] = 1LL * h[i] * 1LL * h[i] + c + cht -> getMin(h[i]);
            cht -> addLine(Line(-2 * h[i],f[i] + 1LL * h[i] * 1LL * h[i]));
        }
        cout<<f[n];
    }
}

int main(void){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    //freopen(fn".inp","r",stdin);
    //freopen(fn".out","w",stdout);
    #endif // ONLINE_JUDGE
    task::solve();
}


Measured memory_bytes: 8560
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int MOD = 1000000007;

int Pow(int m, int n)
{
	if (n == 0) return 1;
	int res = Pow(m*m % MOD, n/2);
	if (n&1) res = res*m % MOD;
	return res;
}

signed main()
{
	int m, n;
	cin >> m >> n;
	printf("%lld\n", Pow(m, n));
	return 0;
}

Measured memory_bytes: 3196
#include<stdio.h>

int main(){
    int m, f, r;
    
    while(1){
        scanf("%d %d %d", &m, &f, &r);
        if(m == -1 && f == -1 && r == -1){
            break;
        }if(m == -1 || f == -1){
            printf("F\n");
        }else if ((m + f) >= 80){
            printf("A\n");
        }else if((m + f) >= 65 && (m + f) < 80){
            printf("B\n");
        }else if((m + f) >= 50 && (m + f) < 65){
            printf("C\n");
        }else if((m + f) >= 30 && (m + f) < 50){
            if(r >= 50){
                printf("C\n");
            }else printf("D\n");
        }else if((m + f) < 30){
            printf("F\n");
        }
    }
}


Measured memory_bytes: 2580
from sys import stdin

n = int(stdin.readline().strip())
a_lst = [int(x) for x in stdin.readline().strip().split()]
counter_dict = {}

# create counter dict
for a in a_lst:
  counter_dict[a] = counter_dict.get(a, 0) + 1

# check
max_val = -1
for x in range(min(a_lst), max(a_lst)+1):
  sum_val = counter_dict.get(x-1, 0) + counter_dict.get(x, 0) + counter_dict.get(x+1, 0)
  if sum_val > max_val:
    max_val = sum_val

print(max_val)

Measured memory_bytes: 19968
#include <iostream>

std::string add(std::string a, std::string b)
{
    while(a.size() < b.size()) a.insert(0, "0");
    while(b.size() < a.size()) b.insert(0, "0");
    int n = a.size();
    std::string res(n, ' ');
    for(int i=n-1, d=0; i>=0; --i)
    {
        int p   = a[i] - '0';
        int q   = b[i] - '0';
        int r   = p+q+d;
        d       = r/10;
        res[i]  = r%10 + '0';
        if(i == 0 && d != 0) res.insert(0, std::string(1, d+'0'));
    }
    return res;
}

int main()
{
    int wordsNum;
    std::cin >> wordsNum;
    for(int i=0; i<wordsNum; i++)
    {
        std::string a, b;
        std::cin >> a >> b;
        std::string tmp = add(a, b);
        if(tmp.size() > 80) std::cout << "overflow" << std::endl;
        else std::cout << tmp << std::endl;
        
    }
    return 0;
}

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

int main() {
    int N; cin >> N;
    string S; cin >> S;
    int cnt = 0;
    for(int i = 0; i < N - 2; ++i) {
        if(S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') 
            cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256