akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
typedef long long ll;
using namespace std;

struct edge {
	int to, dist;
};

int N, M, L, Q;
int dist[300][300];
vector<edge>v[300];

int main() {
	scanf("%d%d%d", &N, &M, &L);
	for (int i = 0; i < M; i++) {
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		if (c > L)continue;
		a--;
		b--;
		v[a].push_back({ b,c });
		v[b].push_back({ a,c });
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			dist[i][j] = -1;
		}
	}
	for (int i = 0; i < N; i++) {
		priority_queue<pair<pair<int, int>, int>, vector<pair<pair<int, int>, int>>, greater<pair<pair<int, int>, int>>>pq;
		pq.push({ {0,0},i });
		while (!pq.empty()) {
			int x = pq.top().second;
			int f = pq.top().first.first;
			ll d = pq.top().first.second;
			pq.pop();
			if (dist[i][x] == -1) {
				dist[i][x] = f;
				for (edge e : v[x]) {
					if (dist[i][e.to] == -1) {
						if (d + e.dist > L) {
							pq.push({ {f + 1,e.dist},e.to });
						}
						else {
							pq.push({ {f,d + e.dist}, e.to });
						}
					}
				}
			}
		}
	}
	scanf("%d", &Q);
	while (Q--) {
		int s, t;
		scanf("%d%d", &s, &t);
		s--;
		t--;
		printf("%d\n", dist[s][t]);
	}
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const double eps = 1e-7;
#define endl '\n'
#define pb(a) push_back(a)
#define ALL(x) x.begin(), x.end()
#define SIZE(x) int(x.size())
#define IOS ios::sync_with_stdio(0);

int n;
int a[N];
int main() {
	scanf("%d",&n);
	ll sum=0;
	for(int i=1;i<=n;++i) {
		int x;
		scanf("%d",&x);
		a[x]++;
		sum+=1ll*x;
	}
	int q;
	scanf("%d",&q);
	while(q--) {
		int b,c;
		scanf("%d%d",&b,&c);
		sum+=1ll*(c-b)*a[b];
		printf("%lld\n",sum);
		a[c]+=a[b]; 
		a[b]=0;
		
	}
	return 0;
	
} 

Measured memory_bytes: 4148
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d;cin>>a>>b>>c>>d;
    int x = c-a;
    int y = d-b;
    printf("%d %d %d %d\n",c-y,d+x,a-y,b+x);
    //cout<<c-y<<d+x<<a-y<<b+x<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10 ;

int main () {
    int a[3];
    set<int> s;
    for (int i = 0 ; i < 3 ; ++ i){
        scanf("%d", a + i);
        s.insert(a[i]);
    }
    puts((int)s.size() == 2 ? "Yes" : "No");
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 256
DBG = !true
n,q = gets.split.map{|x| x.to_i}
a = gets.split.map{|x| x.to_i}
xx = []
for i in 0...q
  xx << gets.to_i
end
if DBG
  print "n #{n} q #{q} x: "
  print xx
  puts ""
  print "a: "
  print a
  puts ""
end

sum = 0
acc = []
eoacc = Array.new(n+2)
for i in 0...n
  sum += a[i]
  acc << sum
end
esum = 0
osum = 0
for i in 0..(n/2)
  break if 2*i == n
  esum += a[2*i]
  eoacc[2*i] = esum
  break if 2*i+1 == n
  osum += a[2*i+1]
  eoacc[2*i+1] = osum
end

for x in xx
  # decide T by binary search
  puts "x #{x} start" if DBG
  if n <= 2
    puts "#{a[n-1]}"
    next
  elsif n <= 4
    if DBG
      puts "x #{x} an2 #{a[n-2]} an3 #{a[n-3]} mid #{(a[n-2]+a[n-3])/2}"
    end
    puts "#{a[n-1] + (x>(a[n-2]+a[n-3])/2 ? a[n-3] : a[n-2])}"
    next
  elsif 2*x > (a[n-2]+a[n-3])
    puts "#{eoacc[n-1]}"
    next
  end
  bot = 1
  ceil = (n-1)/2
  while ceil - bot > 1
    t = (bot + ceil)/2
    y = a[n-t] + a[n-2*t+1]
    z = a[n-t-1] + a[n-2*t-1]
    if y >= 2*x
      bot = t
    elsif 2*x > z
      ceil = t
    end
    if DBG
      puts "t #{t} y #{y} z #{z} bot #{bot} ceil #{ceil} 2x #{2*x}"
      puts "   ant #{a[n-t]} an2tp1 #{a[n-2*t+1]}"
      puts "   ant1 #{a[n-t-1]} an2tm1 #{a[n-2*t-1]}"
    end
  end
  ans = -1
  puts "now bot #{bot}" if DBG
  for t in [bot-3, 1].max..[bot+3,(n+1)/2-1].min
    puts "t=#{t}" if DBG
    y = a[n-t] + a[n-2*t+1]
    z = a[n-t-1] + a[n-2*t-1]
    if y >= 2*x && 2*x > z
      ans = t
      break
    end
  end
  puts "ANSWER: #{ans}" if DBG

  if ans == -1
    val = acc[n-1] - acc[n/2 - 1]
  else
    puts "n/2 #{n/2} ans #{ans} eacc #{eacc[n/2-ans]}" if DBG
    val = acc[n-1] - acc[n-ans-1] + eoacc[n - 2*ans - 1]
  end
  puts "#{val}"
end


Measured memory_bytes: 16396
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    ll a,b,c; cin >> a >> b >> c;
    cout << min(c, a+b+1) + b << endl;
}

Measured memory_bytes: 256
N, A, B = map(int, input().split())
S = input()

count = 0
countb = 0
for i, v in enumerate(S):
    if (v == 'c'):
        print('No')
    elif(v == 'a'):
        if (count < A + B):
            print('Yes')
            count += 1
        else:
            print('No')
    elif (v == 'b'):
        countb += 1
        if (count < B + A and countb <= B):
            print('Yes')
            count += 1
        else:
            print('No')


Measured memory_bytes: 4016
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    void solve() {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] s = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            s[i] = in.nextInt();
            sum += s[i];
        }
        Arrays.sort(s);
        int i = 0;
        while (sum % 10 == 0 && i < n) {
            if (s[i] % 10 != 0) {
                sum -= s[i];
            }
            i++;
        }
        if (i == n) {
            sum = 0;
        }

        System.out.println(sum);
    }

    public static void main(String[] args) {
        new Main().solve();
    }
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    bool a_win;
    bool a_turn = true;
    while (true) {
        if (a_turn) {
            C -= B;
            if (C <= 0) {
                a_win = true;
                break;
            }
        }
        else {
            A -= D;
            if (A <= 0) {
                a_win = false;
                break;
            }
        }
        a_turn ^= true;
    }

    cout << (a_win ? "Yes\n" : "No\n");
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 3652
using System.Linq;
using static System.Math;
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        var n = long.Parse(Console.ReadLine().Trim());
        var a = getDiv(n);
        a.Remove(1);
        var a2 = check(n, a);
        var b = getDiv(n - 1);
        b.Remove(1);
        var hs = new HashSet<long>();
        foreach (var x in a2) hs.Add(x);
        foreach (var x in b) hs.Add(x);
        Console.WriteLine(hs.Count());
    }
    static List<long>  check (long n, List<long> a)
    {
        var ans = new List<long>();
        foreach (var x in a)
        {
            var t = n;
            while (true)
            {
                if (t % x == 0) t /= x;
                else break;
            }
            if (t % x == 1) ans.Add(x);
        }
        return ans;
    }
     static List<long> getDiv(long n)
    {
        var ans = new List<long>();
        for (int i = 1; i <= Sqrt(n); i++)
        {
            if (n % i == 0)
            {
                ans.Add(i);
                if (n != i * i) ans.Add(n / i);
            }
        }
        return ans;
    }
}


Measured memory_bytes: 13536
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};


int main() {
    int n,ans = 0; cin >> n;
    string s; cin >> s;

    int ala[26],alb[26];

    for(int i = 1; i < n; i++){
        rep(k,26) {ala[k] = 0; alb[k] = 0;}
        int cnt = 0;
        for(int j = 0; j < i; j++){
            ala[(int) s[j] - 97]++;
        }
        for(int j = i; j < n; j++){
            alb[(int) s[j] - 97]++;
        }

        for(int j = 0; j < 26; j++){
            if(ala[j] && alb[j]) cnt++;
        }
        ans = max(ans,cnt);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e16;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;
int n;
void h(int k,string s){
    if (k == 0){
        PRINT(s);
        return;
    }
    int l = s.length();
    bool a[26] = {0};
    rep(i,l){
        a[s[i]-'a'] = 1;
    }
    s += "a";
    rep(i,26){
        if (a[i] == 0){
            rep(j,i+1){
                s[l] = 'a'+j;
                h(k-1,s);
            }
            break;
        }
    }
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    h(n,"");
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define ld long double
#define vi vector<int>
#define umap unordered_map
#define pii pair<int, int>
#define vpii vector<pii>
#define uset unordered_set
#define frw(i, a, b) for(auto i = (a); i < (b); i++)
#define bck(i, a, b) for(auto i = (a); i > (b); i--)
#define T() int testcases; cin >> testcases; frw(TC, 1, testcases + 1)
#define tez ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define fi first
#define se second
#define pow asdihagsiduh
#define pub push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) (int)(a.size())
#define sq(a) ((a) * (a))

#define trace(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1> 
void ZZ(const char* name, Arg1&& arg1){
    cerr << name << " = " << arg1 << endl;
}
template<typename Arg1, typename... Args>
void ZZ(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " = " << arg1;
    ZZ(comma, args...);
}

//console o/p without variable names
#define trace1(...) ZZ(__VA_ARGS__)
template<typename Arg1>
void ZZ(Arg1&& arg1){
    cerr << arg1 << endl;
}
template<typename Arg1, typename... Args>
void ZZ(Arg1&& arg1, Args&&... args){
    cerr << arg1 << ' ';
    ZZ(args...);
}

vi aux;

void gen(int n){
    if(n > 1e9) return;
    string s = to_string(n);
    sort(all(s));
    s.resize(unique(all(s)) - s.begin());
    if(sz(s) == 3)   aux.pub(n);
    gen(n * 10 + 3);
    gen(n * 10 + 5);
    gen(n * 10 + 7);
}

signed main(){
    tez
    gen(0);
    sort(all(aux));
    aux.resize(unique(all(aux)) - aux.begin());
    int n; cin >> n;
    cout << upper_bound(all(aux), n) - aux.begin();
}

Measured memory_bytes: 640
#pragma region

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;

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

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &pair) {
  cin >> pair.first >> pair.second;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

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

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

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16);
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int main() {
  init();

  ll X;
  cin >> X;
  ll m = 100, i = 0;
  while (1) {
    i++;
    m *= 1.01;
    if (m >= X) {
      out(i);
      return 0;
    }
  }
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define pb push_back
#define ins insert
#define F first
#define S second
#define var auto
using namespace std;
typedef long long ll;
const int Max = 1e5 + 10;
const int Mod = 1e9 + 7;


int main()
{
	int n;cin >> n;
	bool last = false;
	int ans = 0;
	for(int i = 1; i <= n ; i++)
	{
		int p;cin >> p;
		if(p == i)
		{
			if(last)
			{
				ans++;
				last = false;
			}
			else
				last = true;
		}
		else
		{
			if(last)
			{
				ans++;
				last = false;
			}
		}
	}
	cout << ans + int(last) << '\n';;
}



Measured memory_bytes: 3596
ret = []
while True:
   n, x = map(int, raw_input().split())
   num_arr = [i for i in range(1, n+1)]
   if (n, x) == (0, 0): 
       break   

   cnt = 0
   for i in range(len(num_arr)):
       for j in range(i + 1, len(num_arr)):
           for k in range(j + 1, len(num_arr)):
               work = num_arr[i] + num_arr[j] + num_arr[k]
               if x == work:
                   cnt += 1
   ret += [cnt]
for i in ret:
    print i

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

int main(){
    int n;
    cin >> n;
    vppil l(n);
    rep(i,n){
        int a;
        cin>>a;
        rep(j,a){
            pint xy;
            cin>>xy.first>>xy.second;
            xy.first--;
            l.at(i).push_back(xy);
        }
    }
    //end input
    //binary search
    int ans=0;
    rep(bit,1<<n){
        bool flag=true;
        rep(i,n){
            if(bit&(1<<i)){//is bit true
                //get items from l;
                for(pint xy:l.at(i)){
                    if((bit&(1<<xy.first))>>xy.first!=xy.second){
                        flag=false;
                        i+=n;
                        break;//=>gotonext
                    }
                }
            }
        }
        //gotonext
        if(flag){ans=max(__builtin_popcount(bit),ans);}
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3564
from collections import Counter


H, W, K = [int(x) for x in input().split()]
grid = [[int(x) for x in input()] for r in range(H)]

best = float("inf")
for cuts in range(2 ** H):
    # Initialize numCuts to the number of horizontal cuts
    hCutIndices = [r for r in range(H) if (1 << r) & cuts]
    numCuts = len(hCutIndices)

    # The count for each horizontal cut since last cut
    cumulativeCount = Counter()

    for c in range(W):
        # The count for each horizontal cut for this column
        columnCount = {}
        curr = 0
        for r in range(H):
            curr += grid[r][c]
            if (1 << r) & cuts or r == H - 1:  # Note: last row is always a cut
                columnCount[r] = curr
                curr = 0

        # Add column count to cumulative count if possible
        if all(cumulativeCount[r] + columnCount[r] <= K for r in columnCount):
            for r in columnCount:
                cumulativeCount[r] += columnCount[r]
        else:
            # Cut and reset cumulative count to this column
            numCuts += 1
            cumulativeCount = columnCount
            # If counts within just the column is no good, the current set of horizontal cuts is impossible
            if any(counts > K for r, counts in columnCount.items()):
                numCuts = float("inf")
                break
    best = min(best, numCuts)

print(best)


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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
}

void solve() {
	string s; cin >> s;
	if ((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3])) cout << "Yes";
	else cout << "No";
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define black 1
#define white 0
#define BIG 2000000000

int n,c[100][100], A[100], color[100];

void Keiro() {
    int i, min, u, v;
    
    for (i = 0; i < n; ++i) {
        color[i]  = white;
        A[i] = BIG;
    }
    
    A[0] = 0;
    
    while(1) {
        min = BIG;
        
        u = -1;
        for(i = 0; i < n; i++) {
            if (min > A[i] && color[i] != black) {
                u = i;
                min = A[i];
            }
        }
        if (u == -1) break;
        
        color[u] = black;
        for (v = 0; v < n; ++v) {
            if (color[v] != black && c[u][v] != BIG) {
                if (A[v] > A[u] + c[u][v]) {
                    A[v] = A[u] + c[u][v];
                }
            }
        }
        
    }
    
}
int main() {
    int i, j, k, a, b;
    scanf("%d", &n);
    
    for (i = 0; i < n; ++i){
        for (j = 0; j < n; ++j) {
            c[i][j] = BIG;

        }
    }
    for (i = 0; i < n; ++i) {
        scanf("%d %d", &a, &k);
        for (j = 0; j < k; ++j) {
            scanf("%d %d", &a, &b);
            c[i][a] = b;
        }
    }
    Keiro();
    
    for (i = 0; i < n; ++i) {
        printf("%d %d\n", i, A[i]);
    }

    return 0;
}

Measured memory_bytes: 1820
#include <string>
#include <cmath>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>
#include <tuple>
#include <functional>
#include <set>

using namespace std;

int main()
{
	int R, G;
	cin >> R >> G;
	cout << 2 * G - R << endl;
}

Measured memory_bytes: 256
import java.util.*;
//import java.io.*;
import java.util.stream.IntStream;

public class Main{
    static int sum=0;
    public static void main (String args[]){
        //初期処理
        Scanner sc=new Scanner(System.in);
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        // try{
            // int n = Integer.parseInt(br.readLine());
        int n = sc.nextInt();
        for(int i=0; i<n; i++){
            Vector p0 = new Vector(sc.nextInt(), sc.nextInt());
            Vector p1 = new Vector(sc.nextInt(), sc.nextInt());
            Vector p2 = new Vector(sc.nextInt(), sc.nextInt());
            Vector p3 = new Vector(sc.nextInt(), sc.nextInt());

            if(Vector.intersect(p0, p1, p2, p3)){
                System.out.println(1);
            }else{
                System.out.println(0);
            }
        }

    }
}

class Vector{
    public static final double EPS = 1e-10;
    public static final int COUNTER_CLOCKWISE=1;
    public static final int CLOCKWISE=-1;
    public static final int ONLINE_BACK=2;
    public static final int ONLINE_FRONT=-2;
    public static final int ON_SEGMENT=0;

    public double x,y;

    public Vector(){}
    public Vector(double x, double y){this.x=x;this.y=y;}

    public Vector plus(Vector p){return new Vector(this.x+p.x, this.y+p.y);}
    public Vector minus(Vector p){return new Vector(this.x-p.x, this.y-p.y);}
    public Vector multiple(double a){return new Vector(this.x*a, this.y*a);}
    public Vector divide(double a){return new Vector(this.x/a, this.y/a);}

    public double abs(){return Math.sqrt(this.norm());}
    public double norm(){return x*x+y*y;}

    
    public static double dot(Vector a, Vector b){
        return a.x*b.x+a.y*b.y;
    }

    public static double cross(Vector a, Vector b){
        return a.x*b.y-a.y*b.x;
    }

    //point.projectで垂線の足の座標
    public Vector project(Vector seg1, Vector seg2){
        Vector seg = seg2.minus(seg1);
        Vector relPoint = this.minus(seg1);
        double t = dot(seg, relPoint)/seg.norm();
        return seg1.plus(seg.multiple(t));
    }
    
    //point.reflectionで対称点
    public Vector reflection(Vector seg1, Vector seg2){
        Vector projected = this.project(seg1, seg2);
        Vector ashi = projected.minus(this);
        return this.plus(ashi.multiple(2));
    }

    //p0が始点
    public static int ccw(Vector p0, Vector p1, Vector p2){
        Vector s1 = p1.minus(p0);
        Vector s2 = p2.minus(p0);

        double cross = Vector.cross(s1, s2);
        double dot = Vector.dot(s1, s2);

        if(cross>0){return COUNTER_CLOCKWISE;}
        if(cross<0){return CLOCKWISE;}
        if(dot<0){return ONLINE_BACK;}
        if(s1.abs()<s2.abs()){return ONLINE_FRONT;}
        return ON_SEGMENT;
    }

    public static Boolean intersect(Vector p0, Vector p1, Vector p2, Vector p3){
        if(ccw(p0, p1, p2)*ccw(p0, p1, p3)<=0 && ccw(p2, p3, p0)*ccw(p2, p3, p1)<=0){
            return true;
        }else{
            return false;
        }
    }
}


Measured memory_bytes: 39320
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mxn= 5e5+5;
#define mod 1000000007
#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int main() {
    int n,k;
    cin>>k>>n;
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    int temp=0,cnt=0;
    for(int i=0;i<n-1;i++){
        temp=max(temp,arr[i+1]-arr[i]);
        cnt+=arr[i+1]-arr[i];
    }
    cnt+=k-arr[n-1]+arr[0];
    temp=max(temp,k-arr[n-1]+arr[0]);
    cout<<cnt-temp;
}



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

// TYPEDEF
// ----------------------------------------
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pair;
typedef vector<ll> vll;
typedef vector<vector<ll>> Graph;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> Pll;
typedef queue<ll> qll;

// REPEAT
// ----------------------------------------
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REPA(i,a) for(ll i=0;i<(ll)(a.size());i++);
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;
#define COUTA(i,a) for(ll i=0;i<(ll)(a.size());i++) {cout << (a)[i] << " ";} cout << endl;

// UTIL
// ----------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())

// DEBUG
// ----------------------------------------
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

// BIT FLAG
// ----------------------------------------
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000

// CONST
// ----------------------------------------
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI=3.14159265358979323846; // or M_PI
constexpr int MOD = 1000000007;


void Main() {
    ld d, t, s;
    cin >> d >> t >> s;

    if (d / s <= t) {
      COUT("Yes");
    }
    else {
      COUT("No");
    }

}

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


/*

3 2
*/


Measured memory_bytes: 3752
n=int(input())
b=[0,0,0,0,0,0]
for i in range(n):
    s=float(input())
    if s<165:
        b[0]+=1
    elif 165<=s<170:
        b[1]+=1
    elif 170<=s<175:
        b[2]+=1
    elif 175<=s<180:
        b[3]+=1
    elif 180<=s<185:
        b[4]+=1
    else:
        b[5]+=1
a=[print(str(i+1)+":"+"*"*b[i]) for i in range(len(b))]


Measured memory_bytes: 5612
<?php
    $linea = trim(fgets(STDIN));
    $line1 = str_split($linea);
    $line2 = str_split(trim(fgets(STDIN)));
    
    $count =0;
    for($i=0;$i<strlen($linea);$i++){
        if($line1[$i] != $line2[$i]){
            $count++;
        }
    }
    
    echo $count."\n";

?>

Measured memory_bytes: 41296
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <algorithm>
#include <unordered_map>
#define int                long long
#define pb                 push_back
#define pi                 pair<int,int>
#define vi                 vector<int>
#define all(v)             v.begin(),v.end()
#define MOD                1000000007
#define F                  first
#define S                  second
#define FOR(i,r)           for(int i=0;i<r;i++)
#define REP(i,l,r)         for(int i=l;i<r;i++)
#define RER(i,l,r)         for(int i=l;i>=r;i--)
#define print(v)           for(auto i : v)cout << i << ' ';
#define FASTIO             ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mem(arr,k)         memset(arr,k,sizeof(arr));
#define pii                acos(-1.0)
#define PI                 3.1415926535897932385
#define Sin(a)             sin((pi*a)/180)
#define test()             int x;cin >> x;while(x--)
using namespace std;
int hehe;
int n,mat[21][21],dp[21][3000001];
int rec(int cur,int mask){
	if(cur == n){
		if(mask != hehe){
			return 0;
		}
		return 1;
	}
	if(dp[cur][mask]!=-1)
		return dp[cur][mask];
	int ways = 0;
	for(int i=0;i<n;i++){
		// Check if the ith bit is set and its compatible
		if(!(mask & (1<<i)) && mat[cur][i]){
			//cout << cur << ' ' << i << ' ' << 1<<i << endl; 
			ways += rec(cur+1,mask+(1<<i));
			ways %= MOD;
		}
	}
	dp[cur][mask] = ways;
	return ways;
}
int32_t main(){

	
	FASTIO;
	mem(dp,-1);
	cin >> n;
	hehe = pow(2,n)-1;
	REP(i,0,n){
		REP(j,0,n){
			cin >> mat[i][j];
		}
	}
	cout << rec(0,0) << endl;
    return 0;

}


Measured memory_bytes: 492416
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;

int main()
{
	auto d = vector<long long int>(33);
	d[0] = 0;
	d[1] = 1;
	int p = 2;
	long long int t = -2;
	while(t != 2LL << 31){
		d[p] = t + d[p - 2];
		++p;
		t *= -2;
	}
	int n;
	cin >> n;
	string ans;
	p = 32;
	while(p > 1){
		if((p % 2 == 0 && d[p] <= n && n < d[p - 2]) || (p % 2 == 1 && d[p - 2] < n && n <= d[p])){
			ans += '1';
			n -= (int)(d[p] - d[p - 2]);
		}else{
			if(!ans.empty()) ans += '0';
		}
		--p;
	}
	if(n == 1){
		ans += '1';
	}else{
		ans += '0';
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
/**
  * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_5_A
  * Structured Program I - Print a Rectangle
  */
object Main {
  def main(args: Array[String]): Unit = {
    Iterator.continually(io.StdIn.readLine()).takeWhile(_ != null).map(_.split(" ").map(_.toInt)).map { case Array(h, w) => (h, w) }
      .takeWhile(_ != (0, 0))
      .map { case (h, w) => createARectangle(h, w) }
      .foreach(_.foreach(println))
  }

  def createARectangle(h: Int, w: Int): Seq[String] = {
    (1 to h).map(_ => "#" * w) :+ ""
  }
}

Measured memory_bytes: 45156
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
using namespace std;
int go(int n,int size,vector<int>&v,vector<int>&memo)
{
    if(n==0)
    {
       return 0;
    }
    if(n==1)
    {
        return abs(v[1]-v[0]);
    }
    if(memo[n]!=-1)
    {
        return memo[n];
    }
    int m=go(n-1,size,v,memo)+abs(v[n]-v[n-1]);
    int l=go(n-2,size,v,memo)+abs(v[n]-v[n-2]);
    return memo[n]=min(m,l);
}
main()
{
  int i,j;
  int n;
  cin>>n;
  vector<int>v;
  for(i=0;i<n;i++)
  {
      int a;
      cin>>a;
      v.push_back(a);
  }
  vector<int>memo;
  for(i=0;i<n;i++)
  {
      memo.push_back(-1);
  }
  cout<<go(n-1,n,v,memo);
}

Measured memory_bytes: 12112
#include<stdio.h>
int main()
{ int i,sum=1;
  char s[3];
  for(i=0;i<3;i++)
  {
  scanf("%c" ,&s[i]);
  }
  if(s[0]=='R'&&s[0]==s[1]){sum++;}
  if(s[1]=='R'&&s[1]==s[2]){sum++;}
 if(s[0]=='S'&&s[0]==s[1]&&s[1]==s[2]){sum=0;}
 printf("%d",sum);
return 0;
}

Measured memory_bytes: 2060
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0){ break; }
		vector<int> v(n);
		for(int i = 0; i < n; ++i){ cin >> v[i]; }
		int best_s = 0, best_a = 0, best_c = 0;
		double best_score = 1e20;
		const int MOD = 256;
		for(int s = 0; s <= 15; ++s){
			for(int a = 0; a <= 15; ++a){
				for(int c = 0; c <= 15; ++c){
					int r = s;
					vector<int> occur(MOD);
					for(int i = 0; i < n; ++i){
						r = (a * r + c) % MOD;
						occur[(v[i] + r) % MOD]++;
					}
					double score = 0.0;
					for(int i = 0; i < MOD; ++i){
						if(occur[i] == 0){ continue; }
						double t = static_cast<double>(occur[i]) / n;
						score -= t * log(t);
					}
					if(score + 1e-9 < best_score){
						best_s = s; best_a = a; best_c = c;
						best_score = score;
					}
				}
			}
		}
		cout << best_s << " " << best_a << " " << best_c << endl;
	}
	return 0;
}

Measured memory_bytes: 1240
<?php
$n=trim(fgets(STDIN));
list($a,$b)=explode(" ",trim(fgets(STDIN)));
$p=explode(" ",trim(fgets(STDIN)));
$ans=array(0,0,0);
$i=0;
while($i<$n){
  $c=$p[$i];
  if($c<=$a){
    ++$ans[0];
  }elseif($c<=$b){
    ++$ans[1];
  }else{
    ++$ans[2];
  }
  ++$i;
}
echo min($ans);

Measured memory_bytes: 4728
from collections import defaultdict
dic = defaultdict(int)
N, X, M = map(int, input().split())
A = [X]
ans = X
fir = -1
if N>1:
    temp = 1
    dic[X]=temp
    for i in range(2, N+1):
        a = A[-1]*A[-1]%M
        if dic[a]>0:
            fir = dic[a]
            break
        A.append(a)
        ans+=a
        temp+=1
        dic[a]=temp
    if fir!=-1:
        T = temp-fir+1#周期
        Tsum = 0 #周期の和
        TempSum = 0 #後半あまりの和
        M=N-fir+1 # 先頭のぞく 
        amari = M%T # 後半あまり
        for k in dic:
            if dic[k]>=fir and dic[k]<=temp:
                Tsum+=k
            if dic[k]>=fir and dic[k]<fir+amari:
                TempSum += k
        ans+=TempSum
        ans+=Tsum*(M//T-1)
    print(ans)
else:
    print(ans)

Measured memory_bytes: 77984
fun main(args: Array<String>) {
    edpc()
}

fun edpc() {
    val n = readLine()!!.toInt()
    val vacations = (1..n)
        .map { readLine()!!.split(" ").map { it.toLong() } }

    val dp = Array(n + 1) { LongArray(3) { 0 } }
    dp[0][0] = vacations[0][0]
    dp[0][1] = vacations[0][1]
    dp[0][2] = vacations[0][2]

    for (i in 1 until n) {
        for (j in 0..2) {
            (0..2).filter { it != j }.map { dp[i - 1][it] }.forEach {
                dp[i][j] = Math.max(dp[i][j], it + vacations[i][j])
            }
        }
    }

    val answer = dp[n - 1].max()!!

    println(answer)
}


Measured memory_bytes: 100032
#![allow(unused_imports)]
#![allow(non_snake_case)]
use proconio::{input, fastout};
use proconio::marker::{Chars, Bytes, Usize1};

use std::collections::VecDeque;

#[fastout]
fn main() {
    input!{
        H:usize, W:usize,
        ch:Usize1, cw:Usize1,
        dh:Usize1, dw:Usize1,
        g: [String; H]
    }
    let mut G: Vec<Vec<char>> = Vec::new();
    for x in g {
        G.push(x.chars().collect());
    }
    let arr: Vec<(i32, i32)> = vec![(0, 1), (1, 0), (0, -1), (-1, 0)];
    let mut dist = vec![vec![H*W; W]; H];
    dist[ch][cw] = 0;
    let mut q = VecDeque::new();
    q.push_back((ch, cw, 0));
    while !q.is_empty() {
        let (u, v, c) = q.pop_front().unwrap();
        if c > dist[u][v] { continue; };
        for &(du, dv) in &arr {
            let nu = u.wrapping_add(du as usize);
            let nv = v.wrapping_add(dv as usize);
            if nu < H && nv < W && G[nu][nv] == '.' && dist[nu][nv] > c {
                dist[nu][nv] = c;
                q.push_front((nu, nv, c));
            }
        }
        for du in -2i32..3 {
            for dv in -2i32..3 {
                let nu = u.wrapping_add(du as usize);
                let nv = v.wrapping_add(dv as usize);
                if nu < H && nv < W && G[nu][nv] == '.' && dist[nu][nv] > c + 1 {
                    dist[nu][nv] = c + 1;
                    q.push_back((nu, nv, c+1));
                }
            }
        }
    }
    let ans = dist[dh][dw];
    println!("{}", if ans == H * W {-1} else {ans as i32});
}


Measured memory_bytes: 15140
from time import time

t0 = time()

from random import randrange

D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]

N = 26


t = [max(range(26), key=lambda x: si[x]) for si in s]


while time() - t0 < 1.8:
    # init
    diff = 0

    di = randrange(D)
    qi = randrange(N)

    # delete
    old_type = t[di]

    for next_d in range(di + 1, D):
        if t[next_d] == old_type:
            break
    else:
        next_d = D

    for prev_d in range(di - 1, -1, -1):
        if t[prev_d] == old_type:
            break
    else:
        prev_d = -1

    diff -= s[di][old_type]
    diff -= (next_d - di) * (di - prev_d) * c[old_type]

    # insert
    for next_d in range(di + 1, D):
        if t[next_d] == qi:
            break
    else:
        next_d = D

    for prev_d in range(di - 1, -1, -1):
        if t[prev_d] == qi:
            break
    else:
        prev_d = -1

    diff += s[di][qi]
    diff += (next_d - di) * (di - prev_d) * c[qi]

    # saiyou
    if diff >= 0:
        t[di] = qi

ans = [ti + 1 for ti in t]
print(*ans, sep="\n")


Measured memory_bytes: 81552
N = int(input())
numbers = []
for i in range(N):
  numbers.append(int(input()))

maxv = -1 *10**9
minv = numbers[0]

for i in range(1,N):
  maxv = max(maxv,numbers[i]-minv)
  minv = min(minv,numbers[i])

print(maxv)



Measured memory_bytes: 13596
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
ll dp[105][100005],x[100005];
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
     ll N,K;
     cin>>N>>K;
     ll a[N],i,j,k;
     for(i=0;i<N;i++) cin>>a[i];
     for(i=0;i<N;i++)
     {
        for(j=0;j<=K;j++)
        {
            if(i==0) { if(j<=a[i]) dp[i][j]=1; }
            else if(j==0) dp[i][j]=1;
            else
            {
                if(j-(a[i]+1)>=0) dp[i][j]=(x[j]-x[j-(a[i]+1)]+mod)%mod;
                else dp[i][j]=x[j];
            }
        }
        memset(x,0,sizeof x);
        x[0]=dp[i][0];
        for(ll i1=1;i1<=K;i1++)
        { x[i1]=x[i1-1]+dp[i][i1]; if(x[i1]>=mod) x[i1]-=mod; }
     }
     dp[N-1][K]=(dp[N-1][K]+mod)%mod;
     cout<<dp[N-1][K]<<'\n';
    return 0;
}


Measured memory_bytes: 80128
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> PLL;
#define chmax(x, y) do { x = max(x, y); } while(0)
#define chmin(x, y) do { x = min(x, y); } while(0)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (ll i = static_cast<ll>(a); i < static_cast<ll>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;

signed main() {
  string s;
  cin >> s;
  for (auto &c : s) {
    if (c == '?')
      c = 'D';
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 3756
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int func(char* s, int n, int m)
{
    int i, sum=0;
    char* p=s;
    for(i=0;i<n;++i) if (m&(1<<i)) {
        char t=s[i+1];
        s[i+1]=0;
        sum+=atoi(p);
        s[i+1]=t;
        p=s+i+1;
    }
    return sum+atoi(p);
}

int main(void)
{
    int target;
    char paper[10];
    while (scanf("%d%s", &target, paper), target) {
        int n=strlen(paper);
        int i, res=0, best=-1, cnt=0;
        for(i=(1<<(n-1));i<(1<<n);++i) {
            int t=func(paper, n, i);
            if (t<=target) {
                if (best<t) {
                    best=t; res=i; cnt=1;
                }
                else if (best==t) {
                    ++cnt;
                }
            }
        }
        if (cnt!=1) {
            puts(!cnt ? "error" : "rejected");
        }
        else {
            printf("%d ", best);
            for(i=0;i<n;++i) {
                putchar(paper[i]);
                if (res&(1<<i)) putchar(i==n-1?'\n':' ');
            }
        }
    }
    return 0;
}

Measured memory_bytes: 620
#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> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int N;
    string S;
    cin >> N >> S;

    map<pair<string,string>,i64> x,y;

    rep(i,0,1<<N){
        string a,b;
        rep(j,0,N){
            if(i&(1<<j)) a+=S[j];
            else b+=S[j];
        }
        reverse(begin(b),end(b));
        ++x[make_pair(a,b)];
    }
    rep(i,0,1<<N){
        string a,b;
        rep(j,N,2*N){
            if(i&(1<<(j-N))) a+=S[j];
            else b+=S[j];
        }
        reverse(begin(b),end(b));
        ++y[make_pair(a,b)];
    }

    i64 ans=0;
    for(auto& p:x){
        string a=p.first.first,b=p.first.second;
        ans+=p.second*y[make_pair(b,a)];
    }

    cout << ans << 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: 103424
#include <iostream>
using namespace std;
int main(){
  int r,c,mat[101][101],i,j,sum;
  cin >> r >> c;
  for(i=0;i<r;i++){
    for(j=0;j<c;j++){
      cin >> mat[i][j];
    }
  }
  for(i=0;i<r;i++){
    sum=0;
    for(j=0;j<c;j++){
      sum+=mat[i][j];
    }
    mat[i][j]=sum;
  }
  for(i=0;i<c;i++){
    sum=0;
    for(j=0;j<r;j++){
      sum+=mat[j][i];
    }
    mat[j][i]=sum;
  }
  sum=0;
  for(i=0;i<c;i++) sum+=mat[r][i];
  mat[r][c]=sum;
  for(i=0;i<=r;i++){
    for(j=0;j<=c;j++){
      if(j!=c) cout << mat[i][j] << ' ';
      else cout << mat[i][j];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <cmath>
#include <vector>
#include <ctime>
#include <bitset>
using namespace std;
#define pb push_back
#define sd(n) scanf("%d",&n)
#define sdd(n,m) scanf("%d%d",&n,&m)
#define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define sld(n) scanf("%lld",&n)
#define sldd(n,m) scanf("%lld%lld",&n,&m)
#define slddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define sf(n) scanf("%lf",&n)
#define sff(n,m) scanf("%lf%lf",&n,&m)
#define sfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define ss(str) scanf("%s",str)
#define ans() printf("%d",ans)
#define ansn() printf("%d\n",ans)
#define anss() printf("%d ",ans)
#define lans() printf("%lld",ans)
#define lanss() printf("%lld ",ans)
#define lansn() printf("%lld\n",ans)
#define fansn() printf("%.10f\n",ans)
#define r0(i,n) for(int i=0;i<(n);++i)
#define r1(i,e) for(int i=1;i<=e;++i)
#define rn(i,e) for(int i=e;i>=1;--i)
#define rsz(i,v) for(int i=0;i<(int)v.size();++i)
#define szz(x) ((int)x.size())
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define lowbit(a) (a&(-a))
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pli pair<ll,int>
#define mp make_pair
#define lrt rt<<1
#define rrt rt<<1|1
#define X first
#define Y second
#define PI (acos(-1.0))
#define sqr(a) ((a)*(a))
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1000000000+7;
const double eps=1e-9;
const int inf=0x3f3f3f3f;
const ll infl = 10000000000000000;
const int maxn=  100000+10;
const int maxm = 100000+10;

int in(int &ret)
{
    char c;
    int sgn ;
    if(c=getchar(),c==EOF)return -1;
    while(c!='-'&&(c<'0'||c>'9'))c=getchar();
    sgn = (c=='-')?-1:1;
    ret = (c=='-')?0:(c-'0');
    while(c=getchar(),c>='0'&&c<='9')ret = ret*10+(c-'0');
    ret *=sgn;
    return 1;
}


int num[maxn];
int cnt[maxn];

int main()
{
#ifdef LOCAL
    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
#endif // LOCAL

    int n;
    sd(n);
    int ans = 0;
    r1(i,n)
    {
        sd(num[i]);
        if(++cnt[num[i]-1]>ans)ans = cnt[num[i]-1];
        if(++cnt[num[i]]>ans)ans = cnt[num[i]];
        if(++cnt[num[i]+1]>ans)ans = cnt[num[i]+1];
    }
    ansn();

    return 0;
}


Measured memory_bytes: 1024
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
void solve(); int main() { solve(); return 0; }

const ll INF = 1000000000000000000;
int n,m,l;
ll D[305][305];
ll D2[305][305];
void asap(ll G[305][305]) {
  loop(k,0,n) {
   loop(u,0,n) {
     if (G[u][k] == INF) continue;
     loop(v,0,n) {
       if (G[k][v] == INF) continue;
       G[u][v] = min(G[u][v], G[u][k] + G[k][v]);
     }
   }
  }
}

void solve() {
  cin >> n>>m>>l;
  loop(i,0,n+1) loop(j,0,n+1) D[i][j] = D2[i][j] = INF;
  loop(i,0,m) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;b--;
    D[a][b] = D[b][a] = c;
  }
  
  asap(D);
  
  loop(i,0,n) loop(j,0,n) {
    if (D[i][j] <= l) D2[i][j] = 1;
  }
  
  asap(D2);
  
  int q;
  cin >> q;
  loop(i,0,q) {
    int s, t;
    cin >> s >> t;
    s--;t--;
    if (D2[s][t]==INF) { cout << -1 << endl; continue; }
    cout << D2[s][t] -1 << endl;
  }
}


Measured memory_bytes: 5040
# n, k = map(int, input().split())
s = input()

mm = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']
if s[:2] in mm and s[2:] in mm:
  print('AMBIGUOUS')
elif s[:2] in mm:
  print('MMYY')
elif s[2:] in mm:
  print('YYMM')
else:
  print('NA')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
int main() {
    int n, k; cin >> n >> k;
    vector< vector<long long> > v(n+1, vector<long long>(k+2, 0));
    v[0][k] = 1;
    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        for (int j = 0; j <= k; j++) {
            v[i+1][max(0, j-a)] = (v[i+1][max(0, j-a)] + v[i][j]) % mod;
            v[i+1][j+1] = (v[i+1][j+1] - v[i][j] + mod) % mod;
        }
        for (int j = 0; j <= k; j++) {
            v[i+1][j+1] = (v[i+1][j+1] + v[i+1][j]) % mod;
        }
    }
    cout << v[n][0] << endl;
    return 0;
}

Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int m,d,cnt=0;
	cin >> m >> d;
	for(int i=1;i<=m;i++){
		for(int j=1;j<=d;j++){
			int a=j/10;
			int b=j%10;
			if(i==a*b&&a!=1&&b!=1)
			  cnt++;
		}
	}
	cout << cnt;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

#define SQ(x) ((x)*(x))

using namespace std;

int a[3];

int main()
{
  int n;
  scanf("%d", &n);
  while(n--){
    for(int i=0;i<3;i++)
      scanf("%d", a+i);

    sort(a, a+3);
    puts(SQ(a[0])+SQ(a[1]) == SQ(a[2])?"YES":"NO");
  }
  return 0;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin>>n;
  vector<tuple<int,int>> vp;
  map<tuple<int,int>, int> needs, rem;
  REP(i,n) {
    int x;
    cin>>x;
    --x;
    vp.emplace_back(x, i+1);
    needs[make_tuple(x, i+1)] = i;
  }
  sort(ALL(vp));
  bool ok = true;
  auto itr = begin(vp);
  vecint ans(n*n);
  REP(i,n*n) {
    if (itr != end(vp) && get<0>(*itr) == i) {
      int x, j;
      tie(x, j) = *itr;
      if (needs[*itr] > 0) {
        ok = false;
        break;
      }
      ans[i] = j;
      rem[*itr] = n-j;
      ++itr;
    } else {
      bool done = false;
      for (auto&& p : needs) {
        if (p.second > 0) {
          int x, j;
          tie(x, j) = p.first;
          ans[i] = j;
          --p.second;
          done = true;
          break;
        }
      }
      if (done) continue;
      for (auto&& p : rem) {
        if (p.second > 0) {
          int x, j;
          tie(x, j) = p.first;
          ans[i] = j;
          --p.second;
          done = true;
          break;
        }
      }
      if (!done) {
        ok = false;
        break;
      }
    }
  }
  if (ok) {
    cout<<"Yes\n";
    REP(i,n*n) {
      if(i)cout<<" ";
      cout<<ans[i];
    }
    cout<<"\n";
  } else {
    cout<<"No\n";
  }
  return 0;
}


Measured memory_bytes: 2176
n = int(input())
h = list(map(int,input().split()))
dp = [0 for i in range(n)]

dp[0] = 0
dp[1] = abs(h[0]-h[1])

for i in range(n-2):
    dp[i+2] = min(dp[i+1] + abs(h[i+1]-h[i+2]),dp[i] + abs(h[i]-h[i+2]))

print(dp[n-1])

Measured memory_bytes: 13928