akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

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

    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = 0;
    ll pre = 0;
    rep(i, n) {
        ll x;
        cin >> x;
        if (i == 0) {
            pre = x;
            continue;
        }
        ans += min(a * (x - pre), b);
        pre = x;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;


void solve(){
  int n; cin >> n;
  vector<int> x(n), y(n), h(n);
  for(int i = 0; i < n; i++) cin >> x[i] >> y[i] >> h[i];
  for(int j = 0; j <= 100; j++){
    for(int k = 0; k <= 100; k++){
      //cout << endl;
      vector<pair<int, int> > ans;
      for(int i = 0; i < n; i++){
        long long int t = abs(x[i] - j) + abs(y[i] - k);
        if(h[i] == 0){
          ans.push_back(pair<int, int>(0, t));
        }
        else ans.push_back(pair<int, int>(h[i] + t, h[i] + t));
      }
      /*for(int i = 0; i < ans.size(); i++){
        cout << ans[i].first << " " << ans[i].second << endl;
      }*/
      int left = ans[0].first;
      int right = ans[0].second;
      for(int i = 1; i < ans.size(); i++){
        left = max(ans[i].first, left);
        right = min(ans[i].second, right);
      }
      if(left == right){
        cout << j << " " << k << " " << left << endl;
        return;
      }
    }
  }


  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    ll n;
    cin >> n;
    Vi l(n);
    rp(i,n) cin >> l[i];
    ll ctr=0;
    rp(i,n-2){
        repi(j,i+1,n-1){
            repi(k,j+1,n){
                if(l[i]==l[j]) continue;
                if(l[i]==l[k]) continue;
                if(l[k]==l[j]) continue;
                if(abs(l[i]-l[j])<l[k]&&l[k]<l[i]+l[j]) ctr++;
            }
        }
    }
    print(ctr);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

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

#define int long long
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;

const unsigned int M = 1e9 + 7;

int32_t main() {
	fastio;

	int h;
	cin >> h;
	int x = 1;
	while(2 * x <= h) x *= 2;
	cout << 2 * x - 1;

	return 0;
}


Measured memory_bytes: 3624
def examA():
    N = DI()/dec(7)
    ans = N
    print(N)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    N, K = LI()
    H = LI()
    H.insert(0,0)
    dp = [[[inf]*(K+1)for _ in range(N+1)] for _ in range(N+1)]
    dp[0][0][0] = 0
    for i in range(N):
        for j in range(i+1):
            for k in range(K+1):
                dp[i+1][i+1][k] = min(dp[i+1][i+1][k],dp[i][j][k]+max(0,H[i+1]-H[j]))
                if k<K:
                    dp[i+1][j][k+1] = min(dp[i+1][j][k+1],dp[i][j][k])

    ans = inf
    for j in range(N+1):
        ans = min(ans,dp[-1][j][-1])
    #for v in dp:
    #    print(v)
    print(ans)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examF()

"""
8 7
7 3 9 1 5 2 8 3
"""

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

int main(void)
{
	int n;
	scanf("%d",&n);
	vector<int> dp(3);
	for(int day=0;day<n;day++){
		vector<int> pd(3,0);
		vector<int> c(3);
		for(int j=0;j<3;j++){
			scanf("%d",&c[j]);
		}
		for(int i=0;i<3;i++){
			for(int j=0;j<3;j++){
				if(i!=j){
					pd[j] = max(pd[j] , dp[i] + c[j]);
				}
			}
		}
		dp = pd;
	}
	printf("%d\n",max({dp[2],dp[0],dp[1]}));
	return 0;
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n;cin>>n;
  std::vector<int> v(n);
  for(int i=0;i<n;i++){
    cin>>v[i];v[i]--;
  }

  int cnt=0;
  for(int i=0;i<n;i++){
    if(v[i]!=i){
      cnt++;
    }
  }
  if(cnt == 0 || cnt == 2){
    cout<<"YES"<<endl;
  } else {
    cout<<"NO"<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;

int gcd(int a, int b)
{
    if (a < b)
    {
        swap(a, b);
    }

    if (b == 0)
    {
        return a;
    }

    return gcd(b, a % b);
}

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

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

    //自身を含めて左側、右側の数の最大公約数
    vector<int> left(n);
    vector<int> right(n);
    left[0] = numbers[0];
    right[n - 1] = numbers[n - 1];
    for (size_t i = 1; i < n; i++)
    {
        left[i] = gcd(left[i - 1], numbers[i]);
        right[n - i - 1] = gcd(right[n - i], numbers[n - i - 1]);
    }

    //自身を除いた左側、右側の数の最大公約数の最大公約数
    int m = 0;
    for (size_t i = 0; i < n; i++)
    {
        int g;
        if (i == 0)
        {
            g = right[i + 1];
        }
        else if (i == n - 1)
        {
            g = left[i - 1];
        }
        else
        {
            g = gcd(right[i + 1], left[i - 1]);
        }

        m = max(m, g);
    }

    cout << m << endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <vector>
#include <cmath>
#include <cstdint>
#include <string>
#include <climits>
#include <queue>

using namespace std;

void bubbleSort(std::vector<int>& xs) {
  int swapCount = 0;
  for (int i = 0; i < xs.size(); ++i) {
    for (int j = xs.size() - 1; j > i; --j) {
      if (xs[j] < xs[j - 1]) {
        swap(xs[j], xs[j - 1]);
        ++swapCount;
      }
    }
  }
  for (int i = 0; i < xs.size(); ++i) {
    if (i != 0) cout << " ";
    cout << xs[i];
  }
  cout << endl;
  cout << swapCount << endl;
}

int main() {
  int n;
  cin >> n;
  std::vector<int> xs(n);
  for (int i = 0; i < n; ++i) {
    cin >> xs[i];
  }
  bubbleSort(xs);
}



Measured memory_bytes: 3084
n, m = map( int, input().split() )
a = list( map( int, input().split() ) )

def f( a_k ): # 2で割り切れる回数
    count = 0
    while a_k % 2 == 0:
        count += 1
        a_k = a_k // 2
    return count

b = []
f_0 = f( a[ 0 ] )
for a_k in a:
    f_k = f( a_k )
    if f_k != f_0:
        print( 0 )
        exit()
    b.append( a_k // pow( 2, f_k ) )

import math
def lcm( x, y ):
    return x * y // math.gcd( x, y )

b_lcm = 1
for b_k in b:
    b_lcm = lcm( b_lcm, b_k )

a_lcm = b_lcm * pow( 2, f_0 )
# print( b_lcm, f_0, b )
print( ( m + a_lcm // 2 ) // a_lcm )

Measured memory_bytes: 19976
from sys import stdin
import heapq
def main():
    #入力
    readline=stdin.readline
    x,y,z,k=map(int,readline().split())
    a=list(map(int,readline().split()))
    a.sort(reverse=True)
    b=list(map(int,readline().split()))
    b.sort(reverse=True)
    c=list(map(int,readline().split()))
    c.sort(reverse=True)

    s={(0,0,0)}
    h=[[-(a[0]+b[0]+c[0]),(0,0,0)]]
    heapq.heapify(h)
    for _ in range(k):
        li=heapq.heappop(h)
        n=-li[0]
        co=li[1]
        print(n)

        if co[0]+1<x:
            co_1=(co[0]+1,co[1],co[2])
            n_1=a[co_1[0]]+b[co_1[1]]+c[co_1[2]]
            n_1=-n_1
            if co_1 not in s:
                heapq.heappush(h,[n_1,co_1])
                s.add(co_1)

        if co[1]+1<y:
            co_2=(co[0],co[1]+1,co[2])
            n_2=a[co_2[0]]+b[co_2[1]]+c[co_2[2]]
            n_2=-n_2
            if co_2 not in s:
                heapq.heappush(h,[n_2,co_2])
                s.add(co_2)

        if co[2]+1<z:
            co_3=(co[0],co[1],co[2]+1)
            n_3=a[co_3[0]]+b[co_3[1]]+c[co_3[2]]
            n_3=-n_3
            if co_3 not in s:
                heapq.heappush(h,[n_3,co_3])
                s.add(co_3)

if __name__=="__main__":
    main()

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

namespace AtTest.ABC_153
{
    class A
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[] ha = ReadInts();
            int h = ha[0];
            int a = ha[1];
            int res = h / a;
            if (h % a > 0) res++;
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13140
using System;
using System.Collections.Generic;

namespace agc040_a
{
  class Program
  {
    static void Main(string[] args)
    {
      var s = CIn.Read().ToCharArray();

      var sum = 0L;

      for (var i = 0; i < s.Length; i++)
      {
        var count = 0;

        for (var j = i + 1; j <= s.Length; j++)
        {
          if (j == s.Length)
          {
            if (s[i] == '<')
            {
              if (count == 0)
              {
                sum += (long)(j - i) * (j - i + 1) / 2;
              }
              else
              {
                var max = Math.Max(count, j - i - count);
                var min = Math.Min(count, j - i - count);

                sum += (long)max * (max + 1) / 2 + (long)min * (min - 1) / 2;
              }
            }
            else
            {
              sum += (long)(j - i) * (j - i + 1) / 2;
            }

            i = j - 1;
            break;
          }

          if (count == 0 && s[i] == '<' && s[j] == '>')
          {
            count = j - i;
          }

          if (count > 0 && s[i] == '<' && s[j] == '<')
          {
            var max = Math.Max(count, j - i - count);
            var min = Math.Min(count, j - i - count);

            sum += (long)max * (max + 1) / 2 + (long)min * (min - 1) / 2;

            i = j - 1;
            break;
          }

          if (s[i] == '>' && s[j] == '<')
          {
            sum += (long)(j - i) * (j - i + 1) / 2;

            i = j - 1;
            break;
          }
        }
      }

      Console.WriteLine(sum);
    }
  }

  static class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }
      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(long n)
    {
      var array = new string[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }
      return array;
    }

    public static int[] ReadIntArray(long n)
    {
      var array = new int[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }
      return array;
    }

    public static long[] ReadLongArray(long n)
    {
      var array = new long[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }
      return array;
    }

    public static double[] ReadDoubleArray(long n)
    {
      var array = new double[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }
      return array;
    }
  }
}

Measured memory_bytes: 14048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int p[100];
vector<int> v;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    for(int i = 1; i <= N; i++) {
        cin >> p[i];
        if(p[i] != i) v.push_back(i);
    }
    if(v.size() > 2) {
        cout << "NO" << endl;
        return 0;
    }
    if(v.size() == 2) {
        swap(p[v[0]], p[v[1]]);
        for(int i = 1; i <= N; i++) {
            if(p[i] != i) {
                cout << "NO" << endl;
                return 0;
            }
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
void Min_Max_Sum(long* SUM, int* MIN, int* MAX)
{
    unsigned short i,n;
    int a;

    scanf("%d", &n);
    for(i=0;i<n;i++)
    {
        scanf("%d", &a);
        *SUM+=a;
        if(*MIN>a)
        {
            *MIN=a;
        }
        if(*MAX<a)
        {
            *MAX=a;
        }        
    }
}

int main()
{
    int min=1000000,max=-1000000;
    long sum=0;
    Min_Max_Sum(&sum, &min, &max);
    printf("%d %d %lld\n",min, max, sum);
    return 0;
}


Measured memory_bytes: 2100
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll h,w,k,x,y;

int main(){
  
  cin >> h >> w>>k;
  vvi data(h, vi(w));  // N * M の2次元配列
  REP(i,h){
    REP(j,w){
      data[i][j]=-1;
    }
  }

  string s;
  
  int cnt=0;
  REP(i,h){
    cin>>s;
    REP(j,w){
      if (s[j]=='#'){
        data[i][j]=cnt;
        cnt++;
      }
    }
  }
  

  //x方向で塗りつぶし
  REP(i,h){
    for(int j=1;j<w;j++){
      if (data[i][j]==-1){
        if (data[i][j-1]!=-1){
          data[i][j]=data[i][j-1];
        }
      }
    }

    
    for(int j=w-2;j>=0;j--){
      if (data[i][j]==-1){
        if (data[i][j+1]!=-1){
          data[i][j]=data[i][j+1];
        }
      }
    }

  }

  //これで横方向にイチゴがあれば横長長方形ができた

  //縦コピー

  REP(j,w)
  {
    for(int i=1;i<h;i++)
    {
      if (data[i][j]==-1){
        if (data[i-1][j]!=-1){
          data[i][j]=data[i-1][j];
        }
      }
    }


    for(int i=h-2;i>=0;i--)
    {
      if (data[i][j]==-1){
        if (data[i+1][j]!=-1){
          data[i][j]=data[i+1][j];
        }
      }
    }

  }


  //2次元配列結果REP cout
  REP(i,h){
    REP(j,w){
      cout<<(data[i][j]+1)<<" ";
    }
    cout<<endl;
  }




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

Measured memory_bytes: 1536
#include<iostream>
using namespace std;
 
int main(){
	long long a,b,sum=0,cnt=0;
	
	cin >> a >> b;
	
	//未使用の差込口1口
	sum = 1;
	while(sum < b){
		sum += a - 1;
		cnt++;
	}

	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define INF 1e9L
#define EPS 1e-9
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define pb push_back
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;

int main(void)
{
    ll n,k;
    cin >> n >> k;
    vector<ll> mx, px;
    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        if(tmp >= 0) px.pb(tmp);
        else mx.pb(abs(tmp));
    }
    SORT(px);
    SORT(mx);

    vector<int> v;
    if(mx.size() >= k) v.pb(mx[k-1]);
    if(px.size() >= k) v.pb(px[k-1]);
    REP(i, k){
        int pid = i;
        int mid = k-i-2;
        if(px.size() <= pid || pid < 0) continue;
        if(mx.size() <= mid || mid < 0) continue;
        int p = px[pid];
        int m = mx[mid];
        v.pb(m > p ? m+p*2 : p+m*2);
    }
    SORT(v);
    pr(v[0]);
}

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

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

int main() {
    ll n; cin >> n;
    vector<ll> s(n);
    for(ll i = 0; i < n; i++) {
        cin >> s.at(i);
    }
    ll count = 0;
    for(ll i = 0; i < n; i++) {
        for(ll j = n-1; j > i; j--) { 
            if( s.at(j) < s.at(j-1)) {
                swap(s.at(j-1), s.at(j));
                count++;
            }
        }
    }

    for (ll j = 0; j < n-1; j++) { cout << s.at(j) << ' '; }
    cout << s.at(n-1) << endl;
    cout << count << endl;
    return 0;
}





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

int main() {
    long long int l, r;
    cin>>l>>r;
    long long int diff = r - l;
    l = l % 2019;
    r = r % 2019;
    if(diff >= 2019){
        cout<<0<<endl;
        return 0;
    }
    long long int ans = LLONG_MAX;
    if(l >= r){
        cout<<0<<endl;
        return 0;
    }
    for(long long int i = l;i<=r;i++){
        for(long long int j = i+1;j<=r;j++){
            ans = min(ans, ((i * j) % 2019));
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <cstring>
#include <algorithm>
#include <set>
#include <climits>
#include <numeric>

//usings
using namespace std;

//type def
typedef long long int64;
typedef pair<int, int> ii;

//consts
const int mod = 1e9 + 7;

//methods
template<typename T>
bool chmax(T& source, const T& compare_to) {
    if(source < compare_to) {
        source = compare_to;
        return true;
    }
    return false;
}

int modpow(int64 base, int n) {
    int64 ret = 1;
    while(n) {
        if(n & 1) ret = ret * base % mod;
        base = base * base % mod;
        n >>= 1;
    }
    return ret;
}

class Solution {
private:
public:
    string solve(int h1, int a1, int h2, int a2) {
        while(h2 > 0 && h1 > 0) {
            h2 -= a1;
            if(h2 <= 0) break;
            h1 -= a2;
        }
        return h1 > 0 ? "Yes" : "No";
    }
};

int main() {
    int s, w;
    cin >> s >> w;
    string ret = w >= s ? "unsafe" : "safe";
    cout << ret << endl;
}

Measured memory_bytes: 3596
#include "bits/stdc++.h"
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
#define int ll
// #define double long double
//#define slld(t) scanf("%lld",&t)
//#define sd(t) scanf("%d",&t)
//#define pd(t) printf("%d\n",t)
//#define plld(t) printf("%lld\n",t)
#define vec vector < int >
#define vecp vector < pair < int , int > >
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define pii pair < int , int >
#define pll pair < ll , ll > 
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define mod  1000000007
#define N   200005
#define MAX 300005
#define mod1 1000000007
#define mod2 998244353
#define bitcnt __builtin_popcountll
#define PI acos(-1)
//#define endl "\n"
#define inf 1e+15
priority_queue<int> ql;
priority_queue<int , vector<int> , greater<int>> qr;
signed main(){
  fast;
  int q , type , a , b;
  int c = 0 , l = 0 , r = 0 , ans;
  cin>>q;
  while(q--){
  	  cin >> type;
  	  if(type==1){
  	  	   cin >> a >> b;
  	  	     c += b;
  	  	   if(ql.size()==0 && qr.size()==0){ 
  	  	   	       ql.push(a);
  	  	   	       l-=a;

  	  	   	   }
  	  	   else if(ql.size() > 0 && qr.size()==0){
  	  	   	   if(a < ql.top()){
  	  	   	   	 qr.push(ql.top());  r += ql.top(); l += ql.top() ;
  	  	   	   	 ql.pop(); 
  	  	   	   	 ql.push(a);  l -= a;
  	  	   	   }
  	  	   	   else{
  	  	   	   	 qr.push(a);
  	  	   	   	 r += a;
  	  	   	   }
  	  	   }
  	  	   else{
  	  	   	  if(a <= ql.top() && ql.size() == qr.size()){
  	  	   	  	 ql.push(a) ;
  	  	   	  	  l -= a;
  	  	   	  	  // cout << l << " " << r<< endl;
  	  	   	  	}
  	  	   	  else if(a<= ql.top() && ql.size() > qr.size()){
  	  	   	  	   qr.push(ql.top());  r += ql.top(); l += ql.top();
  	  	   	  	   ql.pop();    
  	  	   	  	   ql.push(a);  l -= a;
  	  	   	  }
  	  	   	  else if(a > ql.top() && qr.size()==ql.size()){
  	  	   	  	   qr.push(a);   r += a;
  	  	   	  	   ql.push(qr.top());   l -= qr.top(); r -= qr.top();
  	  	   	  	   qr.pop();     
  	  	   	  }
  	  	   	  else if(a > ql.top() && qr.size() < ql.size()){
  	  	   	  	   qr.push(a);
  	  	   	  	     r += a;
  	  	   	  }
  	  	   }
  	  	   // cout << l << " "  << r << endl;
  	  	   
  	  }
  	  else{
  	  	if(ql.size() > qr.size())   ans = l + r + c + ql.top();
  	  	else ans = l + r + c;
  	  	// cout << l << " " << r << " " << c << endl;
  	  	cout << ql.top()<<" " << ans << endl;
  	  }
  }

}
  


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

int main() {
	
	int a, b;
	cin >> a >> b;
	cout << max({a + b, a - b, a * b}) << endl;
	
	return 0;
}

Measured memory_bytes: 256
a = gets.to_i
henkan = "abcdefghijklmnopqrstuvwxyz"
aans = []
 
loop {
  a = a - 1
  amari = a % 26
  shou = a / 26
  ans = henkan[amari]
  aans.push(ans)
  a = shou
  if a == 0
    break
  end
}
  
puts aans.reverse.join



Measured memory_bytes: 14332
using System;
using System.Linq;

namespace abc067_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Array.Sort(l);
            Array.Reverse(l);
            long ret = 0;
            for (int i = 0; i < x[1]; i++)
            {
                ret += l[i];
            }
            Console.WriteLine(ret);
        }
    }
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n,a,b;
  cin>>n>>a>>b;
  pair<int,int> A={1,0},B={0,1};
  pair<int,int> total[12];
  rep(i,12){
    total[i]={A.fst*a +  A.scd*b, B.fst*a +  B.scd*b};
    //cout<<total[i].fst<<" "<<total[i].scd<<endl;
    if(i%2==0){A.fst-=B.fst;A.scd-=B.scd;}
    else{B.fst+=A.fst;B.scd+=A.scd;}
  }
  n%=12;
  cout<<total[n].fst<<" "<<total[n].scd<<endl;
  

  return 0;
}



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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int y = stoi(s.substr(0, 4));
  int m = stoi(s.substr(5, 2));
  int d = stoi(s.substr(8, 2));
  if (y < 2019) {
    cout << "Heisei" << endl;
  } else if (y == 2019 && m < 4) {
    cout << "Heisei" << endl;
  } else if (y == 2019 && m == 4 && d <= 30) {
    cout << "Heisei" << endl;
  } else {
    cout << "TBD" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import math

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

    minimum = 10**12
    for i in range(1,math.floor(N**0.5) + 1):
        if(N % i == 0):
            x = i
            y = N // i

            if(minimum > x+y):
                minimum = x + y

    print(minimum - 2)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include <stdio.h>

int main(void)
{
	int i,j,N;
	int p[50]={};
	int m;

	scanf("%d",&N);

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

	m = 0;
	for (i=0;i<N;i++){
		if (p[i] != i+1){
			m++;
		}
	}
	
	if ((m==0) || (m==2)){
		printf("YES");
	}

	else {
		printf("NO");
	}
	return 0;	
	
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
cout.precision(17);
  int n;cin>>n;
  vector<int> xs(n), ys(n);
  vector<int> perm(n);
  for(int i=0;i<n;i++){
    cin>>xs[i]>>ys[i];
    perm[i]=i;
  }

  int way = 1;
  for(int i=1;i<=n;i++){ 
    way *= i;
  }

  double res=0;
  do{
    double dist = 0;
    for(int i=1;i<n;i++){
      int cur = perm[i-1];
      int nx = perm[i];
      dist += sqrt( pow(xs[nx]-xs[cur], 2) + pow(ys[nx]-ys[cur], 2) );
    }
    res += (dist / way);
  } while(next_permutation(perm.begin(), perm.end()));

  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
namespace IO
{
	template <typename T> inline void read(T &x)
	{
		int f = 1; x = 0; char c = getchar();
		for (; !isdigit(c); c = getchar()) if (c == '-') f = -1;
		for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);
		x *= f;
	}

	template <typename T> inline void chkmax(T &x, T y) { x = x > y ? x : y; }
	template <typename T> inline void chkmin(T &x, T y) { x = x < y ? x : y; }

	template <typename T> inline void write(T x)
	{
		if (x < 0) putchar('-'), x = -x;
		if (x > 9) write(x / 10);
		putchar(x % 10 + '0');
	}
	template <typename T> inline void writesp(T x) { write(x); putchar(' '); }
	template <typename T> inline void writeln(T x) { write(x); putchar('\n'); }
}
using namespace IO;
int n;
int main(){
	read(n);
	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		int st = i, ed = i * (n / i), del = i;
		ans += 1ll * (st + ed) * ((ed - st) / del + 1) / 2;
	}
	writeln(ans);
  return 0;
}

Measured memory_bytes: 3632
ref = "23456789TJQKA"
def judge(hand,led):
    l = hand[led][1]
    mx = tx = w = -1
    for i in xrange(4):
        num,s = ref.index(hand[i][0]),hand[i][1]
        if s == t and num > tx: tx,w = num,i
        elif tx == -1 and s == l and num > mx: mx,w = num,i
    return w
    
while 1:
    t = raw_input()
    if t == "#": break
    hands = [raw_input().split() for i in xrange(4)]
    hands = zip(hands[0],hands[1],hands[2],hands[3])
    led = 0
    win = [0]*2
    for hand in hands:
        led = judge(hand, led)
        win[led%2] += 1
    if win[0] > win[1]: print "NS",win[0]-6
    else: print "EW",win[1]-6

Measured memory_bytes: 4256
import sys
from bisect import bisect, bisect_left

class SquareDiv(): #区間の最大値を求める
    def __init__(self, N, V):
        k = 1
        while k ** 2 < N: k += 1
        self.array = [V] * k
        self.size = k
        self.indivisual = [V] * N

    def update(self, i, v): #i番目をvに更新する
        self.indivisual[i] = v
        self.array[i // self.size] = max(self.array[i // self.size], v)

    def search(self, left, right): #[left, right]の最大値を求める
        lk, rk = left // self.size, right // self.size
        if lk == rk:
            maxN = 0
            for i in range(left, right + 1): maxN = max(maxN, self.indivisual[i])
            return maxN
        else:
            maxN = self.search(left, (lk + 1) * self.size - 1)
            for k in range(lk + 1, rk): maxN = max(maxN, self.array[k])
            maxN = max(maxN, self.search(rk * self.size, right))
            return maxN

def solve():
    input = sys.stdin.readline
    N = int(input())
    R = [[int(i) for i in input().split()] for _ in range(N)]
    R.sort()
    mod = 998244353
    X = [R[i][0] for i in range(N)]
    Connect = SquareDiv(N, 0)
    DP = dict()
    DP[N] = 1
    for i in reversed(range(N)):
        right = max(i, Connect.search(i, bisect_left(X, sum(R[i])) - 1))
        Connect.update(i, right)
        DP[i] = (DP[right + 1] + DP[i + 1]) % mod
    print(DP[0])
    

    return 0

if __name__ == "__main__":
    solve()


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

using namespace std;
int N;
vector<int> V, W;
unordered_map<int, int> mp;
int dp[1024][100001];
int rec(int v, int L) {
	if (v < 1024) return dp[v][L];
	int res = rec(v / 2, L);
	if (L >= W[v]) {
		res = max(res, rec(v / 2, L - W[v]) + V[v]);
	}
	return res;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	V.resize(N + 1);
	W.resize(N + 1);
	for (int i = 0; i < N; i++) {
		cin >> V[i + 1] >> W[i + 1];
		//V[i + 1] = W[i + 1] = 1;
	}
	int Q;
	cin >> Q;
	for (int i = 1; i <= min(N, 1023); i++) {
		int p = i / 2;
		for (int j = 0; j < 100001; j++) {
			dp[i][j] = dp[p][j];
			if (j >= W[i]) {
				dp[i][j] = max(dp[i][j], dp[p][j - W[i]] + V[i]);
			}
		}
	}
	for (int i = 0; i < Q; i++) {
		int v, L;
		cin >> v >> L;
		//v = i + 1;
		//L = i + 1;
		cout << rec(v, L) << "\n";
	}
	cout << endl;
	return 0;
}

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

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in = new Scanner(System.in);
		int k=in.nextInt();
		int x=in.nextInt();
		for(int i=-k+1;i<k;i++)
		{
			System.out.print(x+i+" ");
		}
			
	}
}
	

Measured memory_bytes: 21844
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
import numpy as np
import bisect
N = int(input())
A = np.array(readline().split(),np.int64)
S = sum(A)
#print(S)
AA = np.cumsum(A)
half = S // 2
std = bisect.bisect_left(AA,half)
#print(std)
#print(AA)
if S % 2 == 0 and S // 2 in AA:
  print(0)
  exit()
#if N % 2 == 1:
#  a = AA[N // 2]
#  b = AA[-1] - a
#else:
#  a = AA[N // 2 - 1]
#  b = AA[-1] - a
a = AA[std-1]
b = AA[-1] - a
aa = AA[std]
bb = AA[-1] - aa
print(min(abs(a - b),abs(aa - bb)))

Measured memory_bytes: 37300
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
#define VECIN(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;

int main(){
	int n;
    cin>>n;
    vector<int> a(3*n);
    REP(i,3*n){
        cin>>a[i];
    }
    sort(ALL(a));
    reverse(ALL(a));
    ll ans=0;
    for(int i=1;i<2*n;i+=2){
        ans+=a[i];
    }
    OUT(ans);
	return 0;
}

Measured memory_bytes: 1408
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e8
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func abc177_a(D, T, S int) string {
	if D > T*S {
		return "No"
	} else {
		return "Yes"
	}
}

func main() {
	var D, T, S int = nextInt(), nextInt(), nextInt()
	fmt.Println(abc177_a(D, T, S))
}


Measured memory_bytes: 1772
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000000+7;

//マクロ
//型エイリアス
using ll = long long;
using P=pair<long long,long long>;
using vl=vector<long long>;
//ショートカット
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,k,n) for(int i=k;i<n;i++) //半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
//入力
#define vin(v,N) for(long long i=0;i<N;i++) cin>>v.at(i)
#define lin(n) long long n;cin>>n
#define vlin(v,N) vector<long long>v(N);for(long long i=0;i<N;i++)cin>>v.at(i)

//関数
//最大公約数
long long gcd(long long m,long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m,long long n){
  return m*n/gcd(m,n);
}
//xのn乗
long long power(long long x,long long N){
  long long ret=1;
  for(long long i=0;i<N;i++)   
    ret*=x;
  return ret;
}
//nCr
long long C(long long n, long long r);
//nCr (mod)
long long modC(long long n, long long r) {
    vector<long long> f(n+1),inv(n+1),invf(n+1);
    f[0]=f[1]=1;
    invf[0]=invf[1]=1;
    inv[1]=1;
    for (long long i=2;i<n+1;i++) {
        f[i]=(i*f[i-1])%mod;
        inv[i]=mod-((mod/i)*inv[mod%i])%mod;
        invf[i]=(inv[i]*invf[i-1])%mod;
    }
    long long cmb=f[n]*(invf[r]*invf[n-r]%mod)%mod;
    if (n>=r) return cmb;
    else return 0;
}
//素因数分解(mapで返す)
map<long long,long long> factor(long long p){
  ll p1=p;
  map<long long,long long>ret;
  for(long long i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//素数判定
bool is_prime(long long N){
  for(long long i=2;i*i<=N;i++){
    if(N%i==0)
      return false;
  }
  return true;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}

//メイン関数
int main(){
  //doubleの桁数
  cout<<fixed<<setprecision(10);
  
  lin(N);
  vlin(a,N);vlin(b,N);
  vl r(N); ll d=0;
  ll res=0;
  rep(i,N){
    if(b[i]-a[i]>0){
      res++;
      d+=b[i]-a[i];
    }
    else
      r[i]=a[i]-b[i];
  }
  sort(rall(r));
  
  //cout<<d<<endl;
  
  bool NG=true;
  rep(i,N){
    if(d>0){
      res++;
      d-=r[i];
    }
  }
  
  if(d>0)
    cout<<-1<<endl;
  else
    cout<<res<<endl;
  
  //rep(i,N) cout<<r[i];
}

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

using namespace std;

int main() {
    string s;
    int k;
    cin >> s >> k;
    int n = s.length();
    for (int i = 0; i+1 < n; ++i) {
        int dst = ((s[i] == 'a') ? 0 : (26 - s[i] + 'a'));
        if (dst <= k) {
            s[i] = 'a';
            k -= dst;
        }
    }

    k %= 26;
    while (k--) {
	int num = s.back() - 'a';
	s.back() = 'a' + (num+1)%26;	
}
cout << s << "\n";
return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <math.h>

using namespace std;

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

  vector<long long> x(N);
  vector<long long> y(N);
  vector<long long> z(N);
  for (int i = 0; i < N; ++i) {
    cin >> x[i] >> y[i] >> z[i];
  }
  
  vector<int> v = {-1, 1};
  long long ans = 0;
  
  for (auto sign1 : v) {
    for (auto sign2 : v) {
      for (auto sign3 : v) {
	vector<long long> scores(N);
	for (int i = 0; i < N; ++i) {
	  scores[i] = sign1 * x[i] + sign2 * y[i] + sign3 * z[i];
	}
	sort(scores.begin(), scores.end());
	reverse(scores.begin(), scores.end());
	long long total = 0;
	for (int i = 0; i < M; ++i) {
	  total += scores[i];
	}
	ans = max(ans, total);
      }
    }
  }

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


Measured memory_bytes: 256
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

bool chkempty(vector<LL> a){
    REP(i,a.size())
        if(a[i]!=0)return false;
    return true;
}

void solve(long long K, long long T, std::vector<long long> a){
    SORT(a);
    LL at = a[a.size()-1];
    cout<<max(at-1-(K-at), (LL)0)<<endl;
}

int main(){
    long long K;
    scanf("%lld",&K);
    long long T;
    scanf("%lld",&T);
    std::vector<long long> a(T);
    for(int i = 0 ; i < T ; i++){
        scanf("%lld",&a[i]);
    }
    solve(K, T, std::move(a));
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define f first
#define se second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(v) (v).begin(),(v).end()
typedef long long ll ;
typedef long double ld ;
typedef long long int lli;

using namespace std;
//reference: geeks
ll mult(ll a,ll b, ll p=mod){	return ((a%p)*(b%p))%p;	}
ll add(ll a, ll b, ll p=mod){return (a%p + b%p)%p;}
ll sub(ll a, ll b, ll p=mod){return (a%p - b%p + p)%p;}
ll fpow(ll n, ll k, ll p = mod) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = mod) {return fpow(a, p - 2, p);}
#define INF 10000000000

int main()
{	
	ios
	int n,k;
	cin>>n;
	int a[n],b[n],c[n];
	int dp[n][3];
	for(int i=0;i<n;i++)	cin>>a[i]>>b[i]>>c[i];
	dp[0][0]=a[0];
	dp[0][1]=b[0];
	dp[0][2]=c[0];
	
	for(int i=1;i<n;i++)
	{
		dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
		dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
		dp[i][2]=max(dp[i-1][1],dp[i-1][0])+c[i];
	}
	
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, sum = 0;
  cin >> n;
  vector<int> d(n);
  for(int i = 0; i < n; i++){
    cin >> d[i];
  }
  for(int i = 0; i < n - 1; i++){
    for(int j = i + 1; j < n; j++){
      sum += d[i] * d[j];
    }
  }
  cout << sum << endl;
}

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

#define fi first
#define se second
#define forn(i,n) for(int i=0; i< (int)n; ++i)
#define for1(i,n) for(int i=1; i<= (int)n; ++i)
#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)
#define ford(i,n) for(int i=(int)(n) - 1; i>= 0; --i)
#define fored(i,l,r) for(int i=(int)r; i>= (int)l; --i)
#define pb push_back
#define el '\n'
#define d(x) cout<< #x<< " " << x<<el

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<char,int> pci;
typedef tuple<int, int, int> tiii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

const ll INF = LONG_LONG_MAX;
const double PI = atan(1)*4;
const int MAXN = 1e5+20;
const double EPS= 1e-10;
int n;
vector<int> g[MAXN];
pll dp[MAXN]; // fi: blanco, se: negro
bool seen[MAXN];
const int mod = 1e9+7;

pll dfs(int a, int parent){
    pll ans = pll(1,1);
//    d(a);
    for(int b : g[a]){
        if(b!= parent){
            pll p = dfs(b, a);

            ans.fi = (ans.fi* (p.fi + p.se))%mod;
            ans.se = (ans.se* p.fi )%mod;
        }
    }
//    if(g[a].size()==1 && g[a][0]==parent){
//        return pll(1,1);
//    }
    return ans;
}

int main(){
    cin>> n;
    if(n==1){
        cout<< 2<<el;
        return 0;
    }
    int x, y;
    forn(i,n-1){
        cin>> x>> y;
        x; y;
        g[x].pb(y);
        g[y].pb(x);
    }
    pll a =dfs(1,-1);
    cout<< (a.fi+ a.se)%mod<<el;

//                dp[x].fi = (dp[x].fi* (dp[y].fi + dp[y].se)%mod )%mod;
//                dp[x].se = (dp[x].se* dp[y].fi )%mod;

}




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

using ll=long long;
const int inf=100000000;

int in(){
  int a;
  cin >> a;
  return a;
}//int型関数の受け取り

void forin(int* x,int y){
  for (int i=0;i<y;i++){
    cin >> x[i];
  }
}//(x,y) int型配列x[y]の受け取り

int intpow(int x,int y){
  double a=x,b=y;
  return pow(a,b);
}//(x,y) xをy乗

int intfabs(int x){
  double a=x;
  return fabs(a);
}//(x) xの絶対値

int fact(int x){
  if (x == 1) return 1;
  return x*fact(x-1);
}//(x) x!

int fib(int x){
  if (x <= 2) return x;
  int a[x];
  a[0]=1;
  a[1]=2;
  for (int i=2;i<x;i++){
    a[i]=a[i-1]+a[i-2];
  }
  return a[x-1];
}//(x) フィボナッチ数列のx番目

int div1(ll x){
  return x%1000000007;
}

main(){
  int a[5],k;
  forin(a,5);
  k=in();
  for (int i=0;i<4;i++){
    for (int i2=i+1;i2<5;i2++){
      if (a[i2]-a[i]>k){
        cout << ":(" << endl;
        return 0;
      }
    }
  }
  cout << "Yay!" << endl;
}

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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int L; cin >> L;
    double d = L/3.0;
    cout << fixed << setprecision(10) << (d*d*d) << '\n';
}



Measured memory_bytes: 256
# coding:utf-8

import sys
from collections import deque
from operator import itemgetter

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n, m = LI()

G = [[] for _ in range(n)]
RG = [[] for _ in range(n)]
indegree = [0] * n

for _ in range(n + m - 1):
    a, b = LI_()
    G[a].append(b)
    RG[b].append(a)
    indegree[b] += 1

# Topological sort
que = deque()
for i in range(n):
    if indegree[i] == 0:
        que.append(i)

res = []
while que:
    v = que.popleft()
    res.append(v)
    for v2 in G[v]:
        indegree[v2] -= 1
        if indegree[v2] == 0:
            que.append(v2)

# 親の候補が複数ある場合
# 木の高さが最大になるような候補を選ぶ
# -> トポロジカル順序で最も後ろにある候補を選ぶ
order = [i for i, n in sorted(enumerate(res), key=itemgetter(1))]
for i in range(n):
    if len(RG) == 0:
        print(0)
        continue

    parent = -1
    d = -1
    for j in RG[i]:
        if order[j] > d:
            parent = j
            d = order[j]

    print(parent + 1)


Measured memory_bytes: 46852
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n;i>=0;i--)
#define INF 100000005
#define MAX 100001
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

int solve(int x, int y){
	int ans;
	if(y <= x)ans = y%3;
	else ans = x%3;
	if(!ans)return 3;
	else return ans;
}

int main(){
	int n, k, x, y;
	scanf("%d%d", &n, &k);
	int m = (n+1)/2;
	for(int i = 0;i < k;i++){
		scanf("%d%d", &x, &y);
		x = min(x, n-x+1);
		y = min(y, n-y+1);
		printf("%d\n", solve(x, y));
	}
	return 0;
}

Measured memory_bytes: 3224
import numpy
a,b,x=map(int,input().split())
V=a*a*b
if x<=V/2:
    y=2*x/b/a
    theta=numpy.arctan(b/y)
    print(theta*360/2/numpy.pi)
else:
    x=V-x
    y=2*x/a/a
    theta=numpy.arctan(y/a)
    print(theta*360/2/numpy.pi)


Measured memory_bytes: 26744
//
//  main.cpp
//  CoderTest
//
//  Created by yuya on 2019/05/20.
//  Copyright © 2019 yuya. All rights reserved.
//

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




int main(){
    
    int N,A,B,C,D;
    string S;
    cin >> N >> A >> B >> C >> D >> S;
    A--;B--;C--;D--;
    int fail = 0;
    int sccs = 0;
    
    if(C < D){
        for(int i=max(1,A);i<C;i++){
            if(S.substr(i-1,2)=="##") {
                fail = 1;
                break;
            }
        }
        for(int i=max(1,B);i<D;i++){
            if(S.substr(i-1,2)=="##") {
                fail = 1;
                break;
            }
        }
        if(fail) cout << "No"  << endl;
        else cout << "Yes" << endl;
        return 0;
    } else {
        for(int i=max(1,A);i<C;i++){
            if(S.substr(i-1,2)=="##") {
                fail = 1;
                break;
            }
            if(B-1<=i && i+1<=D && S.substr(i,3)=="..."){
                sccs=1;
            }
        }
        if(sccs && fail==0) cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;
    }
    
    return 0;
}


Measured memory_bytes: 640