akhauriyash/Code-Regression huggingface dataset:
#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;
}

int main() {
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> a(A);
    vector<int> b(B);
    int amin = 1e9;
    int bmin = 1e9;
    for(int i = 0; i < A; i++) {
        cin >> a[i];
        chmin(amin, a[i]);
    }
    for(int i = 0; i < B; i++) {
        cin >> b[i];
        chmin(bmin, b[i]);
    }
    int ans = amin + bmin;
    while(M--) {
        int x, y, c;
        cin >> x >> y >> c;
        x--;
        y--;
        chmin(ans, a[x] + b[y] - c);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#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)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

int x;

int main()
{
    cin >> x;
    int ans = 1;
    for(int i = 2; i < 35; i++){
        int val = i;
        while(1){
            val *= i;
            if(val <= x) ans = max(ans, val);
            else break;
        }
    }
    cout << ans << endl;

    return 0;

}

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

int main(){
  long double n, m;
  cin >> n >> m;
  
  long double time = m*1900 + (n-m)*100;
  long double ans = 0;
  
  long double pro = pow(2, m);
  long double ntime = time, npro = 1 / pro;
  long double ex = ntime * npro;
  pro = 1 - npro;
  while(ex >= 0.001){
    ans += ex;
    ntime += time;
    npro *= pro;
    ex = ntime * npro;
  }
  
  cout << (long long)(ans+0.5) << endl;
}

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

#define int long long
const int INF = 1e18;

signed main() {
  int D, E;
  while ( cin >> D >> E, D ) {
    double ans = (double)INF;
    for ( int i = 0; i <= D; i++ ) {
      ans = min(ans, abs(sqrt(i*i+(D-i)*(D-i))-E));
    }

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



Measured memory_bytes: 3200
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { os << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;


int n;

int query(int x) {
	x %= n;
	cout << x << endl;
	string s;
	cin >> s;
	if(s == "Male") {
		return 0;
	} else if(s == "Female") {
		return 1;
	} else {
		exit(0);
	}
}

int main()
{
	cin >> n;
	int x = query(0);
	int y = query(n-1);
	int l = 0, r = n-1;
	// if(n/2%2 == 1) {
	// 	if(x == y) {
	// 		l = 0;
	// 		r = n/2;
	// 	} else {
	// 		l = n/2;
	// 		r = n;
	// 		swap(x, y);
	// 	}
	// } else {
	// 	if(x != y) {
	// 		l = 0;
	// 		r = n/2;
	// 	} else {
	// 		l = n/2;
	// 		r = n;
	// 		swap(x, y);
	// 	}
	// }
	if((r-l)%2 != 0) {
		x = query(l+1);
		l++;
	}

	while(true) {
		DEBUG(l); DEBUG(r); DEBUG(x); DEBUG(y);
		if((r-l) == 2) {
			int m = l+(r-l)/2;
			query(l+1);
		} else {
			int m = l+(r-l)/2;
			if(m%2 == 1) m++;
			int res = query(m);
			assert((r-l)%2 == 0);
			 {
				if(x == res) {
					l = m;
					x = res;
					
				} else {
					r = m;
					y = res;
				}
			}
			
		}
	}
	return 0;
}


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

struct UnionFind{
    vector<int> par;
    UnionFind(int n) : par(n){
       REP(i, n) par[i] = -1;
    }
    int root(int x){
        if(par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    int size(int x){
        return (-par[root(x)]);
    }
    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(x > y) swap(x, y);
        if(size(x) < size(y)) swap(x, y);
        par[x] += par[y];
        par[y] = x;
    }
    bool same(int x, int y){
        return root(x) == root(y);
    }
};

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

    int n, k, l;
    cin >> n >> k >> l;

    UnionFind UF1(n);
    UnionFind UF2(n);
    REP(i, k){
        int p, q;
        cin >> p >> q;
        p--; q--;
        UF1.unite(p, q);
    }
    REP(i, l){
        int r, s;
        cin >> r >> s;
        r--; s--;
        UF2.unite(r, s);
    }

    map<pair<int, int>, int> mp;
    REP(i, n){
        mp[make_pair(UF1.root(i), UF2.root(i))]++;
    }
    REP(i, n){
        int ans = mp[make_pair(UF1.root(i), UF2.root(i))];
        if(i) cout << " " << ans;
        else cout << ans;
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 13568
#include<bits/stdc++.h>
#define ll long long
#define dl double
#define mp make_pair
#define pb push_back
#define F first
#define S second
using namespace std;

//***********************************************************************

// hash struct for unordered_map
struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};

int MAXNUM = 5e3+5;
vector <int>vis(MAXNUM);
vector<int> pr;
void sieve() {
	pr.push_back(2);
	for(ll i=3;i<MAXNUM;i+=2) if(!vis[i]) {
		pr.push_back(i);
		for(ll j=i*i;j<MAXNUM;j+=2*i) vis[j]=true;
	}
}
//************************************************************************

void solve()
{
ll n,x,t;
	cin >> n >>x >> t;
	ll ans=n/x;
	if(n%x)
	ans++;
	cout <<t*ans << endl;
}

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

	return 0;
}

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

using namespace std;

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

    int m, n; cin >> n >> m; vector< pair< int, int > > city( m ); map< int, vector< int > > order;

    for( int i = 0; i < m; i++ )
        cin >> city[ i ].first >> city[ i ].second, order[ city[ i ].first ].push_back( city[ i ].second );

    for( auto& p: order )
    {
        auto& t = p.second; sort( t.begin(), t.end() );
    }

    const auto ID = [] ( int x )
    {
        string s = to_string( x ); return string( 6 - s.size(), '0' ) + s;
    };

    for( int i = 0; i < m; i++ )
    {
        int p = city[ i ].first; auto& t = order[ p ]; auto it = t.begin(), iu = it - 1;

        cout << ID( p ) + ID( lower_bound( it, t.end(), city[ i ].second ) - iu ) << '\n';
    }
}


Measured memory_bytes: 13184
L,R=map(int, input().split())
#2019の倍数が入っていれば０→R-Lが２０１９以上
if R-L>=2019:
    print(0)
    exit()

ans=2019
for i in range(L,R):
    for j in range(i+1,R+1):
        ans=min(ans, (i*j)%2019)
print(ans)

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = sc.nextInt();
        }
        Arrays.sort(arr);
        System.out.println(Math.abs(arr[0] - arr[n-1]));
    }
}


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

int main(){
  int CurrencyNum, result;
  cin >> CurrencyNum >> result;
  
  //
  for(int i = 0; i <= CurrencyNum; i++){
     for(int ii = 0; ii <= CurrencyNum - i; ii++){
       int z = CurrencyNum - (i + ii);
        if(10000*i + 5000*ii + 1000*z == result){
            cout << i << " " << ii <<  " " << z;
           return 0;
        }
     }
  }
  std::cout << "-1 -1 -1";
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int A = Integer.parseInt(sc.next());
		int B = Integer.parseInt(sc.next());
		int C = Integer.parseInt(sc.next());
		int D = Integer.parseInt(sc.next());
		String S = sc.next();
		sc.close();
		
		boolean ac = !S.substring(A-1, C-1).contains("##");
		boolean bd = !S.substring(B-1, D-1).contains("##");
		if(C<D){
			if(ac&&bd){
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
		}else{
			boolean bd2 = S.substring(B-2, D+1).contains("...");
			if(ac&&bd&&bd2){
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
		}
	}
}

Measured memory_bytes: 26844
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()

ans = pow(N/3, 3)
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
using namespace std;

int k, s;
int ans;

int main() {
   cin >> k >> s;

   for (int i = 0; i <= k; i++) {
      for (int j = 0; j <= k; j++) {
         int z = s-i-j;
         if (z >= 0 && z <= k) ans++;
      }
   }

   cout << ans << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef pair<ll, pair<ll, ll> > pp;

vector<pp> v;
pp edge[1111111];
pair<ll, ll> x[111111], y[111111];
ll parent[111111];

ll Find(ll val)
{
	if (parent[val] == val)
		return val;
	else
		return parent[val] = Find(parent[val]);
}

int main(void)
{
    ll n, i, cnt = 0;

    scanf("%lld" ,&n);
    for (i = 1; i <= n; i++)
	{
		scanf("%lld %lld" ,&x[i].first, &y[i].first);
        x[i].second = y[i].second = i;
	}

	sort(x + 1, x + n + 1);
	sort(y + 1, y + n + 1);

    for (i = 1; i < n; i++)
	{
		edge[++cnt] = make_pair(x[i + 1].first - x[i].first, make_pair(x[i].second, x[i + 1].second));
		edge[++cnt] = make_pair(y[i + 1].first - y[i].first, make_pair(y[i].second, y[i + 1].second));
	}

	sort(edge + 1, edge + cnt + 1);

	for (i = 1; i <= n; i++)
		parent[i] = i;

    for (i = 1; v.size() < n - 1; i++)
	{
        ll a = Find(edge[i].second.first);
        ll b = Find(edge[i].second.second);

		if (a != b)
		{
            parent[b] = a;
            v.push_back(edge[i]);
		}
	}

	ll ans = 0;
	for (i = 0; i < v.size(); i++)
        ans += v[i].first;

	printf("%lld" ,ans);
	return 0;
}

Measured memory_bytes: 14964
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    ll n,ans;
    cin>>n;
    for(ll i=1;i*i<=n;i++) if(!(n%i)) ans=i;
    cout<<ans+n/ans-2;
}

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

// ll row_blacks[10];
// ll col_blacks[10];

int main() {
  // std::cout << std::fixed << std::setprecision(10);

  ll h, w, k;
  scanf("%lld %lld %lld", &h, &w, &k);

  vector<string> lines;
  for (ll i = 0; i < h; i++) {
    string line;
    cin >> line;

    lines.emplace_back(line);
  }

  ll sum = 0;
  for (ll y = 0; y < h; y++) {
    ll count = 0;
    for (ll x = 0; x < w; x++) {
      if (lines[y][x] == '#') {
        sum++;
      }
    }
  }

  // // count row
  // for (ll y = 0; y < h; y++) {
  //   ll count = 0;
  //   for (ll x = 0; x < w; x++) {
  //     if (lines[y][x] == '#') {
  //       count++;
  //       sum++;
  //     }
  //   }
  //   row_blacks[y] = count;
  // }

  // // count col
  // for (ll x = 0; x < w; x++) {
  //   ll count = 0;
  //   for (ll y = 0; y < h; y++) {
  //     if (lines[y][x] == '#') {
  //       count++;
  //     }
  //   }
  //   col_blacks[x] = count;
  // }

  // cout << "sum:" << sum << endl;

  ll offset = sum - k;

  ll base = 2;
  // ll K = 6;
  ll bits1[20];
  fill_n(bits1, 10, 0);

  ll bits2[20];
  fill_n(bits2, 10, 0);

  ll ans = 0;

  for (;;) {
    bool finish1 = false;
    // for (ll i = h - 1; i >= 0; i--) {
    //   cout << bits1[i];
    // }
    // cout << endl;

    for (;;) {
      bool finish = false;
      // for (ll i = w - 1; i >= 0; i--) {
      //   cout << bits2[i];  // 3
      // }
      // cout << endl;

      ll blacks = 0;
      for (ll x = 0; x < w; x++) {
        for (ll y = 0; y < h; y++) {
          if (bits1[y] || bits2[x]) {
            if (lines[y][x] == '#') {
              blacks++;
            }
          }
        }
      }
      // // 2:row_blacks
      // for (ll i = h - 1; i >= 0; i--) {
      //   if (bits1[i]) {
      //     blacks += row_blacks[i];
      //   }
      // }
      // // 3:col_blacks
      // for (ll i = w - 1; i >= 0; i--) {
      //   if (bits2[i]) {
      //     blacks += col_blacks[i];
      //   }
      // }

      if (blacks == offset) {
        ans++;
      }
      // cout << "blacks:" << blacks << endl;

      for (ll i = 0; i < w; i++) {
        if (bits2[i] + 1 < base) {
          bits2[i] += 1;
          break;
        } else {
          bits2[i] = 0;

          if (i == w - 1) {
            finish = true;
            break;
          }
        }
      }
      if (finish) {
        break;
      }
    }

    for (ll i = 0; i < h; i++) {
      if (bits1[i] + 1 < base) {
        bits1[i] += 1;
        break;
      } else {
        bits1[i] = 0;

        if (i == h - 1) {
          finish1 = true;
          break;
        }
      }
    }
    if (finish1) {
      break;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 3696
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

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

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int n, m;
  cin >> n >> m;
  int a[m], b[m], c[m][n];
  for(int i = 0; i < m; i++){
    cin >> a[i] >> b[i];
    for(int j = 0; j < b[i]; j++){
      cin >> c[i][j];
    }
  }

  int d[m];
  for(int i = 0; i < m; i++){
    d[i] = 0;
    for(int j = 0; j < b[i]; j++){
      d[i] |= 1 << (c[i][j] - 1);
    }
  }

  int dp[m + 1][1 << n];

  for(int i = 0; i < m + 1; i++){
    fill(dp[i], dp[i] + (1 << n), INF_INT);
  }

  dp[0][0] = 0;

  for(int i = 0; i + 1 <= m; i++){
    for(int j = 0; j < (1 << n); j++){
      dp[i + 1][j] = dp[i][j];
    }
    for(int j = 0; j < (1 << n); j++){
      dp[i + 1][j | d[i]] = min(dp[i][j] + a[i], dp[i + 1][j | d[i]]);
    }
  }

  int ans = dp[m][(1 << n) - 1];
  if(ans == INF_INT) ans = -1;

  cout << ans << endl;

  return 0;
}


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

int gcd(int x, int y){
	if(x==1||y==1) return 1;
	if(x == y) return x;
	else if(x>y){
		if(x%y == 0) return y;
		else return gcd(y, x%y);
	} 
	else {
		if(y%x == 0) return x;
		else return gcd(x, y%x);
		}
}

int main(){
	int x,y;
	cin>>x>>y;
	cout<<gcd(x,y)<<endl;
	return 0;
}

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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

template <typename T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<typename T, size_t size> void fill(T (&ary)[size], const T& val){
    fill_n((T*)ary, size, val);
}

void solve() {
    const i64 mod = 1'000'000'007;

    i64 N,M;
    cin >> N >> M;
    vector<i64> S(N),T(M);
    rep(i,0,N) cin >> S[i];
    rep(i,0,M) cin >> T[i];

    vector<vector<i64>> dp(N,vector<i64>(M));
    rep(i,0,N){
        rep(j,0,M){
            if(i-1>=0){
                dp[i][j]+=dp[i-1][j];
                dp[i][j]%=mod;
            }
            if(j-1>=0){
                dp[i][j]+=dp[i][j-1];
                dp[i][j]%=mod;
            }
            if(S[i]==T[j]){
                dp[i][j]+=((i==0 or j==0? 0:dp[i-1][j-1])+1)%mod;
                dp[i][j]%=mod;
            }
                if(i>0 and j>0) {
                    dp[i][j] -= dp[i - 1][j - 1];
                    dp[i][j] %= mod;
                    dp[i][j] += mod;
                    dp[i][j] %= mod;
                }
        }
    }

    cout << (dp[N-1][M-1]+1)%mod << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 31616
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

N = input()
digits = len(N)
mod = (10**9)+7

#DP[tight][0~digits-1]
DP = [[0]*(digits+1) for _ in range(2)]
#tightな0桁目の選び方は1、tightでない0桁目の選び方は無い
DP[1][0] = 1
DP[0][0] = 0


for i in range(1, digits+1):
  DP[0][i] = (DP[0][i-1] * 3) % mod
  if N[i-1] == '0':
    DP[1][i] = DP[1][i-1]
  else:
    DP[0][i] += DP[1][i-1]
    DP[0][i] %= mod
    DP[1][i] = (DP[1][i-1] * 2) % mod


print((DP[1][digits] + DP[0][digits]) % mod)



Measured memory_bytes: 41328
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

int read(){
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
void print(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) print(x/10);
    putchar(x%10+'0');
}

#define MAXN 100000
#define MAXM 200000
#define INF 0x3f3f3f3f
#define PII pair<int,int>
struct Edge{
    int u,v,w;
    Edge(){}
    Edge(int a,int b){
        v=a,w=b;
    }
}E[MAXM+5];
int N,M,cnt;
map<PII,int> Num;
vector<int> I[MAXN+5];
vector<Edge> G[MAXN*20+5];

inline void AddEdge(int u,int v,int w){
    G[u].push_back(Edge(v,w));
    G[v].push_back(Edge(u,w));
}

int dist[MAXN*20+5];
bool vis[MAXN*20+5];
int SPFA(int S,int T){
    queue<int> Q;Q.push(S);
    fill(dist+1,dist+cnt+1,INF);
    dist[S]=0,vis[S]=1;
    while(!Q.empty()){
        int u=Q.front();
        Q.pop();vis[u]=0;
        for(int i=0;i<int(G[u].size());i++){
            int v=G[u][i].v,w=G[u][i].w;
            if(dist[u]+w<dist[v]){
                dist[v]=dist[u]+w;
                if(!vis[v]){
                    vis[v]=1;
                    Q.push(v);
                }
            }
        }
    }
    if(dist[T]==INF)
        return -1;
    return dist[T];
}

int main(){
    //freopen("trip.in" ,"r", stdin);
    //freopen("trip.out","w",stdout);
    N=read(),M=read();
    for(int i=1;i<=M;i++){
        E[i].u=read(),E[i].v=read(),E[i].w=read();
        I[E[i].u].push_back(E[i].w),I[E[i].v].push_back(E[i].w);
    }
    cnt=N;
    for(int i=1;i<=N;i++){
        for(int j=0;j<int(I[i].size());j++){
            PII tmp(i,I[i][j]);
            if(!Num.count(tmp)){
                Num[tmp]=++cnt;
                AddEdge(i,cnt,1);
            }
        }
    }
    for(int i=1;i<=M;i++)
        AddEdge(Num[make_pair(E[i].u,E[i].w)],Num[make_pair(E[i].v,E[i].w)],0);
    int Ans=SPFA(1,N);
    if(Ans==-1) printf("-1");
    else printf("%d",Ans/2);
}


Measured memory_bytes: 105088
#include <bits/stdc++.h>
using namespace std;
static const long long INF = (1LL << 32);

int V, E;
vector<vector<long long> > D;

void init()
{
  D.resize(V, vector<long long>(V, INF));
  for (int i = 0; i < V; i++)
  {
    D.at(i).at(i) = 0;
  }
}

void solve()
{
  for (int k = 0; k < V; k++)
  {
    for (int i = 0; i < V; i++)
    {
      if (D.at(i).at(k) == INF)
      {
        continue;
      }
      for (int j = 0; j < V; j++)
      {
        if (D.at(k).at(j) == INF)
        {
          continue;
        }
        D.at(i).at(j) = min(D.at(i).at(j), D.at(i).at(k) + D.at(k).at(j));
      }
    }
  }
}

int main()
{
  cin >> V >> E;
  init();
  for (int i = 0; i < E; i++)
  {
    long long d;
    int s, t;
    cin >> s >> t >> d;
    D.at(s).at(t) = d;
  }
  solve();
  bool have_negative_cycle = false;
  for (int i = 0; i < V; i++)
  {
    if (D.at(i).at(i) < 0)
    {
      have_negative_cycle = true;
    }
  }
  if (have_negative_cycle)
  {
    cout << "NEGATIVE CYCLE" << endl;
  }
  else
  {
    for (int i = 0; i < V; i++)
    {
      for (int j = 0; j < V; j++)
      {
        if (j)
        {
          cout << " ";
        }
        long long d = D.at(i).at(j);
        if (d == INF)
        {
          cout << "INF";
        }
        else
        {
          cout << d;
        }
      }
      cout << endl;
    }
  }
}


Measured memory_bytes: 3240
#include<iostream>
#include<algorithm>
using namespace std;
 
int main(){
    char s[3];
    cin>>s[0]>>s[1]>>s[2];
    sort(s,s+3);
    if(s[0]=='a' && s[1]=='b' && s[2]=='c')cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int main(){
  long long A,B,C,K;
  cin >> A >> B >> C >> K;

  if(abs(A - B) > (long long)pow(10,18)){
    cout << "Unfair" <<endl;
    return 0;
  }
  if(K % 2 == 0){
    A = A-B;
  }
  else{
    A = B-A;
  }
  cout << A <<endl;
  return 0;
}


Measured memory_bytes: 256
A, B, AB, X, Y = map(int, input().split(' '))

AV = (A + B) / 2

cost = 0

if AB <= AV:
    n = min(X, Y)
    cost += AB * n * 2
else:
    n = min(X, Y)
    cost += (A + B) * n

X -= n
Y -= n

if X > 0:
    if 2 * AB <= A:
        cost += 2 * AB * X
    else:
        cost += A * X
elif Y > 0:
    if 2 * AB <= B:
        cost += 2 * AB * Y
    else:
        cost += B * Y

print(cost)


Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <math.h>

int main(void)
{
	int dp[256][128]; 		// dp[日数][前回着た服の派手さ]
	int temperature[256];
	int clothes_min[256];
	int clothes_max[256];
	int clothes_cool[256];
	int d, n;
	int i, j, k;
	int ans;
	
	scanf("%d %d", &d, &n);
	for (i = 0; i < d; i++){
		scanf("%d", temperature + i);
	}
	for (i = 0; i < n; i++){
		scanf("%d %d %d", clothes_min + i, clothes_max + i, clothes_cool + i);
	}

	memset(dp, -1, sizeof(dp));
	for (i = 0; i < n; i++){
		if (clothes_min[i] <= temperature[0] && clothes_max[i] >= temperature[0]){
			dp[0][clothes_cool[i]] = 0;
		}
	}

	for (i = 1; i < d; i++){
		for (j = 0; j <= 100; j++){
			if (dp[i - 1][j] != -1){
				for (k = 0; k < n; k++){
					if (clothes_min[k] <= temperature[i] && clothes_max[k] >= temperature[i]){
						dp[i][clothes_cool[k]] = fmax(dp[i - 1][j] + fabs(j - clothes_cool[k]), dp[i][clothes_cool[k]]);
					}
				}
			}
		}
	}

	ans = 0;
	for (i = 0; i <= 100; i++){
		ans = fmax(dp[d - 1][i], ans);
	}

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

	return (0);
}

Measured memory_bytes: 744
#include<iostream>
#include<algorithm>

using namespace std;

int main(void){

  int c1,c2,c3;
  while(cin >> c1 >> c2 >> c3){
    double p=0;

    for(int i=1;i<=10;i++){
      if(i==c1 || i==c2 || i==c3)continue;
      if(c1+c2+i<=20)p+=(double)1/(double)7;
    }
    
    if(p>=0.5)cout << "YES" << endl;
    else cout << "NO" << endl;
  }

  return 0;
}

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

using namespace std;

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair
#define fi first
#define se second

typedef long long lli;
typedef pair<int, int> ii;
typedef pair<lli, lli> ll;

int main() {
	string s;
	int len;
	cin >> s;
	cout << s;
	len = s.size();
	if (s[len - 1] == 's')
		putchar('e');
	puts("s");
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>

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

using namespace std;

int main(void)
{
  int num;
  int a[4];
  cin >> num;
  a[0] = num / 1000;
  a[1] = (num / 100) - (10 * a[0]);
  a[2] = (num / 10) - (100 * a[0]) - (10 * a[1]);
  a[3] = num - (1000 * a[0]) - (100 * a[1]) - (10 * a[2]);
  rep(i, 3)
    if(a[i] == a[i+1])
    {
      cout << "Bad";
      return 0;
    }
  cout << "Good";
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>


int main() {
	int n, x,  c = 0, count = 0;
	int b[100] = {};
	for (;;) 
	{
		scanf("%d%d", &n, &x);
		if (n == 0 && x == 0)break;
		for (int i = 1; i < n - 1;i++) {
			for (int j = i + 1; j < n; j++) {
				for (int k = j + 1; k <= n; k++) {
					if (i + j + k == x)c++;
				}
			}
		}
		b[count] = c;
		c = 0;
		count++;
	}
	
	for (int i = 0; i < count; i++) {
		printf("%d\n", b[i]);
	}

	return 0;
}

Measured memory_bytes: 2672
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(){
   
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    
    if(a*b>=c*d){
        cout<<a*b<<endl;
    }else{
        cout<<c*d<<endl;
    }
    
    
    
    
    
    
    return 0;
}






Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
using namespace std;
#define ll int64_t
#define REP(i, n) for (ll i=0; i<n; i++)

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

    ll N;
    string S;
    cin >> N >> S;

    vector<ll> e(N+1, 0);
    REP(i, N){
        e[i+1] = e[i] + (S[i] == 'E');
    }
    // REP(i, e.size()) cout << e[i] << endl;

    // cout << "temp" << endl;

    ll ans = 1000000;
    REP(i, N){
        ll temp = (i - e[i] + e[N] - e[i+1]);
        // cout << temp << "\n";
    ans = min(ans, temp);
    }

    cout << ans << "\n";

}   

Measured memory_bytes: 2964
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstdio>

using namespace std;

int main(void)
{
	int h, m, s;
	int n;
	cin >> n;
	int num = n;
	h = num / 3600;
	num = num - 3600 * h;
	m = num / 60;
	num = num - 60 * m;
	s = num;
	cout << h << ':' << m << ':' << s << endl;
	return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBUG = true;

int main(){

    int n;
    cin >> n;

    bool flag = true;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        if(x % 2 == 0){
            if( (x % 3)  && (x % 5) ) flag = false;
        }
    }

    if(flag){
        cout << "APPROVED" << endl;
    }
    else{
        cout << "DENIED" << endl;
    }


}

Measured memory_bytes: 256
const readline = require('readline');
(async function processLineByLine() {
  const rl = readline.createInterface({
    input: process.stdin,
    crlfDelay: Infinity
  });
  for await (const line of rl) {
    let payment = Math.ceil(line / 1000) *1000;
    console.log(payment - line);
  }
})();

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

int main(void) {
    int n, k;
    cin >> n >> k;
    vector< int > a(n);
    int d, e;
    for (int i = 0; i < k; i++) {
        cin >> d;
        for (int j = 0; j < d; j++) {
            cin >> e;
            a[e-1] = 1;
        }
    }
    int count = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == 0) {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

int main() {
    using ll = long long;

    int n, m;
    cin >> n >> m;

    vector<pair<ll, ll>> a(n);

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

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

    ll ans = 0;

    for (int i = 0; i < n; i++) {
        if (m > a[i].second) {
            ans += a[i].first * a[i].second;
            m -= a[i].second;
        } else {
            ans += a[i].first * m;
            break;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 1792
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
from functools import reduce
import sys
import math
import bisect
import random
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return list(map(float, sys.stdin.readline().split()))
def LS():return sys.stdin.readline().split()
def SR(n): return [list(sys.stdin.readline())[:-1] for i in range(n)]
def IR(n): return [int(sys.stdin.readline()) for i in range(n)]
def LIR(n): return [list(map(int, sys.stdin.readline().split())) for i in range(n)]
def LSR(n): return [list(map(list, sys.stdin.readline().split())) for i in range(n)]
_gcd = lambda x, y: _gcd(y, x%y) if (x%y) else y
_lcm = lambda x, y: x*y // _gcd(x, y)
def gcd(*numbers):
    return reduce(_gcd, numbers)
def lcm(*numbers):
    return reduce(_lcm, numbers)
sys.setrecursionlimit(1000000)
INF = float('inf')
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

N = I()
A = LI()

acc = [0]*(N+1)
for i in range(N):
    acc[i+1] = acc[i] + A[i]

dp = [[0]*(N+1) for i in range(N+1)]
for i in range(N):
    dp[i][i+1] = A[i]


for l in range(N)[::-1]:
    for r in range(l+1, N+1):
        dp[l][r] = max((acc[r]-acc[l+1])-dp[l+1][r]+A[l], (acc[r-1]-acc[l]-dp[l][r-1]+A[r-1]))

print(2*dp[0][N]-acc[-1])

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

int partition(int A[],int p,int r){ 
  int x = A[r];
  int i= p-1;
  for(int j=p;j<r;j++){
    if(A[j] <= x){
       i = i+1;
       swap(A[i],A[j]);
     }
  }
  swap(A[i+1],A[r]);
  return i+1;
}

int main(){
  int num=0;
  cin >> num;
  int array[num];
  for(int i=0;i<num;i++){
    cin >> array[i];
  }

  int index = partition(array,0,num-1);

  for(int i=0;i<num;i++){
    if(i==index)
       cout << "[" << array[i] << "]";
    else{
       cout << array[i];
    }
   if(i!=num-1){
     cout << " ";
    }
  }
cout << endl;
  return 0;
}

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

using namespace std;
inline void I(int&a,int&b){scanf("%d%d",&a,&b);}

int main() {
    int a, b;
    scanf("%d%d", &a, &b);
    a * b % 2 == 0 ? puts("Even") : puts("Odd");

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>


int top, S[1000];

void push(int x){
	S[++top]=x;
}

int pop(){
 top--;
	return S[top+1];


}


int main(){
	int a,b;
	top = 0;
	char s[100];
	while(scanf("%s",s)!=EOF){
		if(s[0]=='+'){
			a=pop();
			b=pop();
			push(a+b);
		}else if(s[0]=='-'){
			b=pop();
			a=pop();
			push(a-b);
		}else if(s[0]=='*'){
			a=pop();
			b=pop();
			push(a*b);
		}else{
			push(atoi(s));
		
		}
	}

	printf("%d\n",pop());
	return 0;
	
}





Measured memory_bytes: 2128
n, w = map(int, input().split())
wv = [tuple(map(int, input().split())) for _ in range(n)]

dp = [0] * (w+1)

for wi, vi in wv:
    for sum_w in range(w, wi-1, -1):
        if sum_w - wi >= 0:
            dp[sum_w] = max(dp[sum_w], dp[sum_w - wi] + vi)
print(dp[w])



Measured memory_bytes: 42092
#
# AIZU ONLINE JUDGE: QQ
# cf. http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0000&lang=jp
#

qq = [str(x) + "x" + str(y) + "=" + str(x * y) for x in range(1,10) for y in range(1,10)]
for q in qq:
    print q

Measured memory_bytes: 4204
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <cmath>

typedef long long ll;

using namespace std;

int main(){
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    int f = a * 60 + b;
    int g = c * 60 + d;
    int h = g - f;
    int ans = h - e;
    cout << ans << endl;
}

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

int main(){
	int K,N;
	cin >> K >> N;
	vector<int> A(N);
	for(int i=0; i<N; i++) cin >> A[i];

	int max_d=0;
	for(int i=1; i<N; i++){
		if( abs(A.at(i)-A.at(i-1)) > max_d ){ max_d = abs(A.at(i)-A.at(i-1));}
	}
	int a = abs(K-A[N-1]) + A[0];
	if(a>max_d)max_d = a;

	cout << K-max_d << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
int INF=1e9;
int MOD=1000000007;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
int main(){
  string s;
  while(cin>>s){
    REP(i,s.size()){
      s[i]=(s[i]-'A'+23)%26+'A';
    }
    cout<<s<<endl;
  }
}

Measured memory_bytes: 1180
#include<stdio.h>

int main(void)
{
	int a, b, n, m;
	while(scanf( "%d %d", &a, &b) != EOF) {
		n = a + b;
		m = 0;
		do{
			m++;
			n = n / 10;
		}while( n >= 1);
		printf( "%d\n", m);
	}
	return 0;
}

Measured memory_bytes: 600
N, K = map(int, input().split())
p = list(map(int, input().split()))

dp = [0] * (N)
dp_sub = [0] * (N)

dp[0] = (p[0] + 1) / 2
dp_sub[0] = (p[0] + 1) / 2

for i in range(1, K):
    dp_sub[i] = (p[i] + 1) / 2
    dp[i] = dp[i - 1] + dp_sub[i]

for i in range(K, N):
    dp_sub[i] = (p[i] + 1) / 2
    dp[i] = dp[i - 1] + dp_sub[i] - dp_sub[i-K]
    
print(max(dp))

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

const double pi = 3.14159265358979323846;
const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n, T; cin >> n >> T;
	int ans = 10000; int tmp = T;
	rep(i,n){
		int c, t; cin >> c >> t;
		if(T >= t){
			ans = min(ans, c);
		}
	}
	if(ans == 10000) cout << "TLE" << endl;
	else cout << ans << endl;
} 

Measured memory_bytes: 512
#include<iostream>

int n, m, ans = 0;
bool *use;
bool **map;

void dfs(int now,int old) {
	use[now] |= 1;
	bool flag = true;
	for (int i = 0; i < n; i++)flag &= use[i];
	if (flag) {
		ans++;
		return;
	}
	/*
	for (int i = 0; i < n; i++) {
		printf("%d", use[i]);
	}
	printf("\n");*/
	for (int i = 0; i < n; i++) {
		if (i != old && map[i][now] && !use[i]) {
			dfs(i, now);
			use[i] &= 0;
		}
	}
}

int main() {
	std::cin >> n >> m;
	use = new bool[n];
	map = new bool*[n];
	bool *base = new bool[n*n];
	for (int i = 0; i < n; i++) {
		use[i] = false;
		map[i] = &base[i*n];
		for (int j = 0; j < n; j++) {
			map[i][j] = false;
		}
	}
	for (int i = 0; i < m; i++) {
		int a, b;
		std::cin >> a >> b;
		a--;
		b--;
		map[a][b] = true;
		map[b][a] = true;
	}
	
	/*
	for (int i = 0; i < n*n; i++) {
		printf("%d", map[i / n][i%n]);
		if (i%n == n - 1)printf("\n");
	}
	printf("\n");*/

	dfs(0, -1);

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

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

int main(){
    int N;
    cin >> N;
    vector<LL>  a(N), d(N);
    for(int i = 0;i < N;i++)    cin >> a[i];
    for(int i = 1;i < N;i++)    d[i] = a[i]-a[i-1];
    int dig = 0;
    int ans = 1;
    for(int i = 1;i < N;i++){
        if(dig == 0){
            if(!d[i])   continue;
            dig = d[i];
        }else if(dig*d[i] < 0){
            ans++;
            dig = 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
/**
 *	author: abhiy13
 *	created: 07.01.2019 12:39:26
**/
#include <bits/stdc++.h>

using namespace std;


string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef ABHI
  #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
  #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
  #define debug(...) 42
  #define eprintf(...) 42
#endif


int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<vector<int>> ar(N, vector<int>(3));
  for(auto &x : ar) {
    for(int &y : x) {
      cin >> y;
    }
  }
  for(int i = 1; i < N; ++i) {
    for(int j = 0; j < 3; ++j) {
      int x, y, z;
      if(j == 0) x = 0;
      else x = ar[i - 1][0];
      if(j == 1) y = 0;
      else y = ar[i - 1][1];
      if(j == 2) z = 0;
      else z = ar[i - 1][2];
      ar[i][j] += max({x, y, z});
    }
  }
  debug(ar);
  cout << max({ar[N - 1][0], ar[N - 1][1], ar[N - 1][2]}) << '\n';
  return 0;
}

Measured memory_bytes: 5760
//
//  second.cpp
//  CoderTest
//
//  Created by yuya on 2019/05/23.
//  Copyright © 2019 yuya. All rights reserved.
//

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



int main()
{
    int N,M,X,Y;
    cin >> N >> M >> X >> Y;
    int maxx = -100,miny = 100 ,x,y;
    for(int i=0;i<N;i++){
        cin >> x;
        maxx = max(maxx,x);
    }
    for(int i=0;i<M;i++){
        cin >> y;
        miny = min(miny,y);
    }
    
    maxx = max(maxx,X);
    miny = min(miny,Y);
    
    if(maxx < miny){
        cout << "No War" << endl;
    } else {
        cout << "War" << endl;
    }
    
    
    
    
    
    return 0;
}


Measured memory_bytes: 764
/*
                                Shahriar Hasan
                          "University of Chittagong"
                                CSE 18 Batch
*/
#include <bits/stdc++.h>
using namespace std;

#define nln puts("")                    // newline
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))    //max/min from 3 input

#define even(x) x%2==0                  //even odd
#define odd(x) x%2!=0

#define PI acos(-1)                     // constant + math
#define lcm(a,b) (a*b/gcd(a,b))

#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)          // algorithm habijabi
#define srt(a,n) sort(a,a+n)
#define srtt sort(a.begin(),a.end())
#define cnt(x) count(a,a+n,x)
#define F first
#define S second
#define all(p) p.begin(),p.end()

#define for0(i,n) for(int i=0;i<n;i++)
#define for1(i,n) for(ull i=1;i<=n;i++)         //loop
#define forr(i,n) for(int i=n-1;i>=0;i--)
#define mem(a,b) memset(a, b, sizeof(a))
#define fill(a,b) fill(a.begin(),a.end(),b)
#define fill_n(a,n,b) fill_n(a.begin(),n,b)
                        //input
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define print0(a) for(int i=0;i<a.size();i++)cout<<a[i]<<endl;
#define print1(a) for(int i=1;i<=a.size();i++)cout<<a[i]<<endl;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef set<int> si;
typedef vector<ll> vl;
typedef pair<int,int> pii;           // datatype
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

///////////////////////////////////////////////////////////
//long long： -9223372036854775808~9223372036854775807
//int： -2147483648~2147483647
//double： -1.7*10^-308~1.7*10^308，15~16位有效数字
//long double： -1.2*10^-4932~1.2*10^4932，18~19位有效数字
///////////////////////////////////////////////////////////


int gcd(int a, int b)               //gcd
{if(b==0)return a;return gcd(b,a%b);}

ull power(int a,int n)              // to the power
{ll multi=1;for(int i=1;i<=n;i++)multi=multi*a; return multi;}
bool isPrime(ull n)                // prime number check
{if(n==2||n==3)return true;else{ull m=power(2,n-1);if(m%n==1 && n%2==1)return true;else return false;}}
vi getdiv(ll n){vi div;int i;
    for(i=1;i*i<n;i++)
    {if(n%i==0){div.pb(i);div.pb(n/i);}}if(i*i==n)div.pb(i);            // divisor nirnoy kora
    //sort(div.begin(),div.end());
    return div;}
bool isPalindrome(int n){int num=n,sum=0,mod;
    while(n){mod=n%10;n=n/10;sum=sum*10+mod;}
    if(sum==num)return true;else return false;}
////////////////////////////////////////////////////end///////////////////////////////////////////////////////////
////////////////////////////////////////////////////end///////////////////////////////////////////////////////////

int main()
{
    int n;
    string s;
    cin >> n;
    cin >> s;
    int len=s.size();
    for0(i,len)
    {
        if(s[i]+n<='Z'&&s[i]+n>='A')
            printf("%c",s[i]+n);
        else
            printf("%c",(64+(n-(90-s[i]))));
    }
    nln;
    return 0;
}



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

using 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)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  string s; std::cin >> s;
  char cur;
  int c0 = 0, c1 = 0;
  rep(i, s.size()) {
    if (s[i] == '0') c0++;
    else c1++;
  }
  std::cout << min(c0, c1) * 2 << "\n";
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int compare_int(const void *a, const void *b) {
    return *(int *)a - *(int *)b;  //昇順
                                   // return *(int*)b - *(int*)a;//降順
}

int main() {
    int n;
    cin >> n;
    int *a = new int[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    qsort(a, n, sizeof(int), compare_int);
    string s = "YES";
    for (int i = 0; i < n - 1; i++) {
        if (a[i] == a[i + 1]) {
            s = "NO";
            break;
        }
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 4764
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  string s = std::to_string(N);

  int rt = std::sqrt(N) + 1;

  vector<int> div;
  bool found = true;
  while(found) {
    found = false;

    for(int i = 2; i <= rt; i++) {
      if (N % i == 0) {
        div.push_back(i);
        N /= i;
        rt = std::sqrt(N) + 1;
        found = true;
        break;
      }
    }
  }
  div.push_back(N);

  int mn = s.size();  // N x 1
  for(int i = 1; i <= std::pow(2, div.size()); i++) {
    long long a = 1;
    long long b = 1;

    for(int j = 0; j < div.size(); j++) {
      if (1<<j & i) a *= div[j];
      else b *= div[j];
    }

    string sa = std::to_string(a);
    string sb = std::to_string(b);
    int mn2 = std::max(sa.size(), sb.size());
    mn = std::min(mn, mn2);
  }

  cout << mn << endl;

  return 0;
}


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

int main()
{
    int N, K;
    int64_t sum=0;
    cin >> N >> K;
    vector<int> P(N);
    for(int i = 0; i < N; i++){
        cin >> P.at(i);
    }
    sort(P.begin(), P.end());
    for(int j = 0; j < K; j++){
        sum += P.at(j);
    }
    cout<<sum;
}

Measured memory_bytes: 3628
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

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

fun main() {
    val (A, B) = nextList()
    println(if ((A == "H" && B == "H") || (A == "D" && B == "D")) "H" else "D")
}

Measured memory_bytes: 34112