akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>

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

    std::vector<std::pair<int, int>> p(n);

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

    std::sort(p.begin(), p.end(), std::greater<std::pair<int, int>>());

    std::cout << p[0].first + p[0].second << std::endl;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  std::array<std::array<i64, 3>, 3> A = {0};
  for (auto& A_i : A) {
    for (auto& A_ij : A_i) {
      std::cin >> A_ij;
    }
  }
  i64 N;
  std::cin >> N;
  std::unordered_set<i64> b;
  for (i64 i = 0; i < N; ++i) {
    i64 b_i;
    std::cin >> b_i;
    b.insert(b_i);
  }

  bool answer = false;
  for (i64 i = 0; i < 3; ++i) {
    for (i64 j = 0; j < 3; ++j) {
      if (b.find(A[i][j]) == b.end()) goto SKIP_1;
    }
    answer = true;
  SKIP_1:
    ;
  }
  for (i64 i = 0; i < 3; ++i) {
    for (i64 j = 0; j < 3; ++j) {
      if (b.find(A[j][i]) == b.end()) goto SKIP_2;
    }
    answer = true;
  SKIP_2:
    ;
  }
  for (i64 i = 0; i < 3; ++i) {
    if (b.find(A[i][i]) == b.end()) goto SKIP_3;
  }
  answer = true;
SKIP_3:
  ;
  for (i64 i = 0; i < 3; ++i) {
    if (b.find(A[i][2 - i]) == b.end()) goto SKIP_4;
  }
  answer = true;
SKIP_4:
  ;

  std::cout << (answer ? "Yes" : "No") << std::endl;
  return 0;
}

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

typedef long long ll;
typedef const void cv;
int upll(cv *a, cv *b) { 
  return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0;
}


int main(void){

	ll a[100000],b,result=1;
    int n,i;
    scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%lld",&a[i]);
  }
  qsort(a,n,sizeof(ll),upll);
  for(i=0;i<n;i++){
  if(powl(10,18)/result<a[i]){
    result = -1;
    break;
  }else if(a[i]==0){
    result = 0;
    break;
  }
    result *= a[i];
  }
    printf("%lld", result);
    
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;

int cnt[2][100100];

int main() {
	string S, T;
	cin >> S;
	int N = S.size();
	for (int i = 0; i < N; i++) {
		cnt[0][i+1] = cnt[0][i] + (S[i] == 'A' ? 1 : 2);
	}
	cin >> T;
	N = T.size();
	for (int i = 0; i < N; i++) {
		cnt[1][i+1] = cnt[1][i] + (T[i] == 'A' ? 1 : 2);
	}
	int Q;
	cin >> Q;
	while (Q--) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		--a; --c;
		int s = (cnt[0][b] - cnt[0][a]);
		int t = (cnt[1][d] - cnt[1][c]);
		//cout << s << " " << t << endl;
		int diff = t - s;
		diff = ((diff%3)+3)%3;
		if (!diff) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}


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

int main()
{
  int N;
  cin >> N;
  int A[N];
  for(int i = 0; i < N; i++)
  {
    cin >> A[i];
  }
  unsigned long count = 0;
  for(int i = 1; i < N; i++)
  {
    if(A[i-1] > A[i])
    {
      int dif = A[i-1] - A[i];
      count += dif;
      A[i] += dif;
    }
  }
  
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 4408
#include <bits/stdc++.h>
    #define REP(i, n) for(int i = 0;i < n;i++)
    #define REPR(i, n) for(int i = n;i >= 0;i--)
    #define FOR(i, m, n) for(int i = m;i < n;i++)
    #define FORR(i, m, n) for(int i = m;i >= n;i--)
    #define SORT(v, n) sort(v, v+n);
    #define VSORT(v) sort(v.begin(), v.end());
    #define llong long long
    #define pb(a) push_back(a)
    #define INF 1000000000000000000LL
    #define MOD 1000000007
    using namespace std;
    typedef pair<int, int> P;
    typedef pair<llong, llong> LP;
    typedef pair<int, P> PP;
    typedef pair<llong, LP> LPP;
    //vector<tuple<long long, long long, long long>>vec;

    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 dy[]={0, 0, 1, -1, 0};
    int dx[]={1, -1, 0, 0, 0};


    int main()
    {
        int h, w;
        string s[55];

        cin >> h >> w;
        REP(i, h)
        {
            string str = "";
            REP(j, w + 2)
                str += ".";
            s[0] = str;
            s[h + 1] = str;
        }
        REP(i, h)
        {
            cin >> s[i + 1];
            s[i + 1] = "." + s[i + 1] + ".";
        }

        for (int i = 1; i <= h; i++)
        {
            for (int j = 1; j <= w; j++)
            {
                if (s[i][j] == '#')
                {
                    cout << "#";
                    continue;
                }

                int cnt = 0;
                for (int k = -1; k <= 1; k++)
                {
                    for (int l = -1; l <= 1; l++)
                    {
                        cnt += s[i + k][l + j] == '#';
                    }
                }

                cout << cnt;
            }

            cout << endl;
        }

        return 0;
    }

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
absmin = 0
minnum = 0
for i in range(n):
  if abs(a[i]) < abs(a[absmin]):
    absmin = i
  if a[i] <= 0:
    minnum += 1
  a[i] = abs(a[i])
if minnum % 2 == 1:
  a[absmin] = -1 * abs(a[absmin])
ans = 0
for i in range(n):
  ans += a[i]
print(ans)

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	vector<int>a(3); int k; for(auto&i:a)cin>>i; cin>>k;
	sort(a.begin(),a.end());
	while(k--)a.back()*=2;
	cout<<accumulate(a.begin(),a.end(),0)<<"\n"s;
}

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

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

int main(){

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

    qsort(p,n,sizeof(p[0]),compare_int);
    int count=0;
    for(int i=0;i<n;i++){
        if(p[i]!=p0[i]){
            count++;
        }
    }
    if(count<=2){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
    
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();
    int max = Math.min(A, B);
    int min = 0;
    if (A + B - N > 0) min = A + B - N;
    System.out.println(max + " " + min);
  }
}


Measured memory_bytes: 24276
var input = require('fs').readFileSync('/dev/stdin', 'utf8').split(/\n/g);
var a = input[0] - 0;
if (a < 2) console.log(1);
else if (a < 4) console.log(2);
else if (a < 8) console.log(4);
else if (a < 16) console.log(8);
else if (a < 32) console.log(16);
else if (a < 64) console.log(32);
else if (a < 128) console.log(64);


Measured memory_bytes: 7372
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
 
void solve() {
	ll N, ans = 1; cin >> N;
    vector<char> S(N);
    ll count[30] = {0};

    rep(i, N) {
        cin >> S[i];
        count[S[i] - 'a'] ++;
    }

    rep(j, 26) {
        ans *= (count[j] + 1);
        ans %= mod;
    }

    cout << ans - 1 << endl;
}
int main() {
	solve();
	return 0;
}

Measured memory_bytes: 384
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int N=Integer.parseInt(sc.next());
int[] A=new int[N];
for(int i=0;i<N;i++){
A[i]=Integer.parseInt(sc.next());
}
Arrays.sort(A);
int max=A[N-1]-A[0];
System.out.println(max);

}
}

Measured memory_bytes: 21844
#include<iostream>
using namespace std;
int main(){
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    if(k<=a){
        cout << k;
    }
    if(a<k && k<=a+b){
        cout << a;
    }
    if(a+b<k){
        cout << 2*a + b - k;
    }
}

Measured memory_bytes: 3564
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  string s, t;
  cin >> s >> t;
  int a, b;
  cin >> a >> b;
  string u;
  cin >> u;
  if (u == s) a--;
  if (u == t) b--;
  cout << a << ' ' << b << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


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

int main() {
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; ++i) cin >> a[i];
    sort(a, a + n);
    int cnt = 0;
    int tmp = 1;
    for(int i = 0; i < n; ++i) {
        if(i && a[i - 1] == a[i]) {
            ++tmp;
        } else if(i && tmp && tmp % 2) ++cnt, tmp = 1;
        else tmp = 1;
    }
    if(tmp && tmp % 2) ++cnt;


    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 640
N, K = map(int, input().split())
H = list(map(int, input().split()))

if N <= K:
  print(0)
elif K == 0:
  print(sum(H))
else:
  H.sort()
  H_hissatsued = H[:-K]
  #print(H_hissatsued)
  print(sum(H_hissatsued))

Measured memory_bytes: 26024
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
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 print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True


def main():
    H, W, K = MI()
    graph = [None] * H
    black_cnt = 0
    dic = defaultdict(int)
    ans = 0

    for i in range(H):
        s = S()
        graph[i] = s

        for j in range(len(s)):
            if s[j] == '#':
                dic[(i, j)] += 1
                black_cnt += 1

    N = H + W
    for i in range(2 ** N):
        row = []
        col = []
        for j in range(N):
            if ((i >> j) & 1):
                if j < H:
                    row.append(j)
                else:
                    col.append(j - H)

        current_cnt = black_cnt
        visited = defaultdict(int)
        for i in row:
            for j in range(W):
                visited[(i, j)] += 1
                if (i,j) in dic:
                    current_cnt -= 1

        for i in range(H):
            for j in col:
                if (i,j) in visited:
                    continue
                visited[(i, j)] += 1
                if (i,j) in dic:
                    current_cnt -= 1

        if current_cnt == K:
            ans += 1
        # print('row', row)
        # print('col', col)

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 76092
#include<iostream>
using namespace std;
const int64_t mod = 1e9 + 7;
int64_t dp[301][301][301]={};
int main(){
    int N,M;
    cin>>N>>M;
    dp[0][1][1]=1;
    for(int i=0;i<M;i++){//i日目の行動
        for(int j=1;j<=N;j++){//これまで行ったことのある頂点数
            for(int k=1;k<=j;k++){//1を含む強連結成分数   dp[i][j][k]から次の状態への遷移を求める。
                if(dp[i][j][k]!=0){
                    dp[i+1][j][k]=(dp[i+1][j][k]+dp[i][j][k]*(j-k))%mod;
                    dp[i+1][j][j]=(dp[i+1][j][j]+dp[i][j][k]*k)%mod;
                    dp[i+1][j+1][k]=(dp[i+1][j+1][k]+dp[i][j][k]*(N-j))%mod;
                }
            }
        }
    }
    cout<<dp[M][N][N]<<endl;
    return 0;
}

Measured memory_bytes: 107648
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if ((ct = *ci++) >= '0') {
			tmp = tmp * 10 + ct - '0';
			if (*ci++ == '0') {
				tmp = tmp * 10;
				ci++;
			}
		}
	}
	return tmp;
}

int A[200000];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint();
	int saidai = 1;
	rep(i, N) {
		A[i] = getint();
		if (A[i] > saidai) saidai = A[i];
	}
	nth_element(A, A + N / 2, A + N);

	ll kotae = 0;
	for (int i = N / 2; i < N; i++) kotae += A[i];

	printf("%lld\n", kotae * 2 - saidai - N % 2 * A[N / 2]);

	Would you please return 0;
}

Measured memory_bytes: 2488
#include <bits/stdc++.h>
using namespace std;
template <typename Functor>
struct fix_type
{
    Functor functor;
    template <typename... Args>
    decltype(auto) operator()(Args&&... args) const& { return functor(functor, std::forward<Args>(args)...); }
};
template <typename Functor>
fix_type<typename std::decay<Functor>::type> fix(Functor&& functor) { return {std::forward<Functor>(functor)}; }
constexpr int INF = 1 << 30;
int main()
{
    int N, E, Q;
    cin >> N >> E >> Q;
    vector<map<int, int>> c(N);
    auto addEdge = [&](const int u, const int v) -> void { c[u][v] = c[v][u] = 1; };
    auto cutEdge = [&](const int u, const int v) -> void { c[u].erase(v), c[v].erase(u); };
    auto flow = [&](const int s, const int t, const int limit) {
        vector<bool> used(N, false);
        auto dfs = fix([&](auto&& self, const int s, const int t, const int f) -> int {
            if (s == t) { return f; }
            used[s] = true;
            for (auto& e : c[s]) {
                if (used[e.first] or e.second == 0) { continue; }
                const int res = min(f, e.second);
                const int d = self(self, e.first, t, res);
                if (d == 0) { continue; }
                return e.second -= d, c[e.first][s] += d, d;
            }
            return 0;
        });
        for (int flow = 0; flow < limit;) {
            fill(used.begin(), used.end(), false);
            const int f = dfs(s, t, limit - flow);
            if (f == 0) { return flow; }
            flow += f;
        }
        return limit;
    };
    for (int i = 0, F, T; i < E; i++) {
        cin >> F >> T;
        addEdge(F - 1, T - 1);
    }
    int ans = flow(0, N - 1, INF);
    for (int q = 0; q < Q; q++) {
        int M, A, B;
        cin >> M >> A >> B;
        A--, B--;
        if (M == 1) {
            addEdge(A, B);
        } else {
            const int cap = c[A][B];
            cutEdge(A, B);
            if (cap == 2) { swap(A, B); }
            if (cap != 1 and flow(A, B, 1) == 0) { ans--, flow(A, 0, 1), flow(N - 1, B, 1); }
        }
        cout << (ans += flow(0, N - 1, 1)) << endl;
    }
    return 0;
}



Measured memory_bytes: 4988
#include <bits/stdc++.h>
using namespace std;
double minco(int k, vector<int> xs, vector<int> ys){
    double ans, sum = 0;
    if (k == -1){
        double max = 0;
        for (int i=0; i<xs.size(); i++){
            if (max < fabs(xs.at(i) - ys.at(i))) {
                max = fabs(xs.at(i) - ys.at(i));
            }
        }
        return max;
    }
    for (int i=0; i<xs.size(); i++){
        sum += pow(fabs(xs.at(i) - ys.at(i)), k);
    }
    ans = pow(sum, 1.0/k);
    return ans;
}

int main(){
    int n;
    cin >> n;
    vector<int> L1(n), L2(n);
    for (int i=0; i<n; i++){
        cin >> L1.at(i);
    }for (int i=0; i<n; i++){
        cin >> L2.at(i);
    }
    cout << fixed << setprecision(8) << minco(1, L1, L2) << endl;
    cout << minco(2, L1, L2) << endl;
    cout << minco(3, L1, L2) << endl;
    cout << minco(-1,L1, L2)<< endl;
    return 0;
}


Measured memory_bytes: 3464
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    String[] input = sc.nextLine().split("");
    
    for(int i=0; i<input.length; i++){
      if((i+1)%2 !=0){
      System.out.print(input[i]);
      }
    }
  }
}


Measured memory_bytes: 35452
import java.util.*;
class Main {
	public static void main(String...args) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int[] frame = {scan.nextInt() , scan.nextInt()};
		int y = frame[0];
		int x = frame[1];
		int total = 0;
		int[][] sheet = new int[y + 1][x + 1];
		for(int i = 0; i < y; i++) {
			for(int n = 0; n < x; n++) {
				int z = scan.nextInt();
				sheet[i][n] = z;
				total += z;
			}
		}
		//SumRow
		for(int i = 0; i < y; i++) {
			int sumRow = 0;
			for(int n = 0; n < x; n++) {
				sumRow += sheet[i][n];
			}
			sheet[i][x] = sumRow;
		}
		//SumColumn
		for(int i = 0; i < x; i++) {
			int sumCol = 0;
			for(int n = 0; n < y; n++) {
				sumCol += sheet[n][i];
			}
			sheet[y][i] = sumCol;
		}
		//print sheet
		for(int i = 0; i <= y; i++) {
			for(int n = 0; n <= x; n++) {
				if(i == y && n == x) {
					sb.append(total);
				} else {
				    sb.append(sheet[i][n]);
				
				}
				if(n != x)sb.append(" ");
			}
			sb.append("\n");
		}
		System.out.print(sb.toString());
	}
}



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

n, m = map(int,input().split())
H = list(map(int,input().split()))
A = [list(map(int,input().split())) for i in range(m)]
for i in range(m):
    for j in range(2):
        A[i][j] -= 1

ANS = [0] * n

for i in range(m):
    for j in range(2):
        ANS[A[i][j]] += 1

for i in range(m):
    if H[A[i][0]] > H[A[i][1]]:
        ANS[A[i][0]] -= 1
    elif H[A[i][0]] < H[A[i][1]]:
        ANS[A[i][1]] -= 1

print(ANS.count(0))

Measured memory_bytes: 91520
while (m, f, r = gets.split.map(&:to_i)) != [-1,-1,-1]
  if m == -1 || f == -1
    puts "F"
    next
  end
 
  score = m + f
  case score
  when 80..100 then puts "A"
  when 65...80 then puts "B"
  when 50...65 then puts "C"
  when 30...50
    if r >= 50
      puts "C"
    else puts "D"
    end
  when 0...30 then puts "F"
  end
end

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

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> x(n),s(n);
  for(Int i=0;i<n;i++) cin>>x[i]>>s[i];
  vector<Int> a(n+1,0);
  for(Int i=0;i<n;i++) a[i+1]=a[i]+s[i];
  
  Int ans=0,res=-1e18;
  for(Int i=0;i<n;i++){
    chmax(res,x[i]-a[i]);
    chmax(ans,(a[i+1]-x[i])+res);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

constexpr int mod = 1000000007;
int mod_pow(int x, int y) {
    if (y == 0) return 1;
    long long a = mod_pow(x, y / 2);
    if (y % 2) return a * a % mod * x % mod;
    else return a * a % mod;
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    vector<map<int, int>> fac(N);
    rep(i, N) {
        int a = A[i];
        for (int j = 2; j * j <= A[i]; ++j) {
            while (a % j == 0) {
                ++fac[i][j];
                a /= j;
            }
        }
        if (a != 1) ++fac[i][a];
    }
    map<int, int> mp;
    rep(i, N) {
        for (auto p : fac[i]) {
            mp[p.first] = max(mp[p.first], p.second);
        }
    }
    long long LCM = 1;
    for (auto p : mp) {
        LCM *= mod_pow(p.first, p.second);
        LCM %= mod;
    }
    long long ans = 0;
    rep(i, N) {
        ans += LCM * mod_pow(A[i], mod - 2) % mod;
        ans %= mod;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3072
def LI(): return list(map(int,input().split()))
A,B,C,X,Y = LI()
ans = float('INF')
for i in range(max(X,Y)+1):
    price = A*max(X-i,0)+B*max(Y-i,0)+C*2*i
    ans = min(ans,price)
print(ans)

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    map<int, ll> mp;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        mp[a[i]]++;
    }

    ll res = 0;
    for (auto &x : mp){
        res += x.second * (x.second - 1) / 2;
    }

    ll x;
    for (int i = 0; i < n; ++i) {
        x = res - mp[a[i]] * (mp[a[i]] - 1) / 2;
        x += (mp[a[i]] > 1) ? (mp[a[i]] - 1) * (mp[a[i]] - 2) / 2 : 0;
        cout << x << endl;
    }
}

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

int main(){
  int a,b;
  double t;
  cin >> a >> b >> t;
  int i = a,ans = 0;
  while(i < t + 0.5){
    ans += b;
    i += a;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
def resolve():
  n, m = map(int, input().split())
  ab = []
  for i in range(n):
    ab.append(list(map(int, input().split())))
  cd = []
  for i in range(m):
    cd.append(list(map(int, input().split())))

  for a in ab:
    ans = 0
    dist = 10000000000
    for i in range(m):
      tmp = abs(a[0] - cd[i][0]) + abs(a[1] - cd[i][1])
      if tmp < dist:
        ans = i+1
        dist = tmp
    print(ans)
  return

if __name__ == "__main__":
  resolve()


Measured memory_bytes: 3064
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<set>

#define P 1000000007

using namespace std;

int main() {
  string s;
  cin >> s;
  int x, y;
  cin >> x >> y;
  vector<int> xx, yy;
  int id = 0;
  for(; s[id] == 'F'; id++);
  x -= id;
  bool dir = true;
  int c = 0;
  for(int i = id; i < s.size(); i++) {
    if(dir) {
      if(s[i] == 'T') {
        dir = false;
        xx.push_back(c);
        c = 0;
      } else c++;
    } else {
      if(s[i] == 'T') {
        dir = true;
        yy.push_back(c);
        c = 0;
      } else c++;
    }
  }
  if(dir) xx.push_back(c);
  else yy.push_back(c);
  if(x < 0) x = -x;
  if(y < 0) y = -y;
  int sx = 0, sy = 0;
  for(int i = 0; i < xx.size(); i++) sx += xx[i];
  for(int i = 0; i < yy.size(); i++) sy += yy[i];
  if(x == sx && y == sy) {
    cout << "Yes" << endl;
    return 0;
  }
  if(x > sx || y > sy || (sx - x) % 2 == 1 || (sy - y) % 2 == 1) {
    cout << "No" << endl;
    return 0;
  }
  sx = (sx - x) / 2;
  sy = (sy - y) / 2;
  bool dpx[xx.size() + 1][sx + 1] = {0};
  dpx[0][0] = true;
  for(int i = 0; i < xx.size(); i++) for(int j = 0; j < sx + 1; j++) {
    dpx[i + 1][j] = dpx[i][j];
    if(j - xx[i] >= 0) dpx[i + 1][j] = dpx[i][j - xx[i]];
  }
  if(!dpx[xx.size()][sx]) {
    cout << "No" << endl;
    return 0;
  }
  bool dpy[yy.size() + 1][sy + 1] = {0};
  dpy[0][0] = true;
  for(int i = 0; i < yy.size(); i++) for(int j = 0; j < sy + 1; j++) {
    dpy[i + 1][j] = dpy[i][j];
    if(j - yy[i] >= 0) dpy[i + 1][j] = dpy[i][j - yy[i]];
  }
  if(!dpy[yy.size()][sy]) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+7;
#define ll long long
int f[N];
int main(){
	int n;
	scanf("%d",&n);
	f[0]=1;
	for(int i = 1;i<=n;i++){
		if(i>=4) f[i]=max(f[i],f[i-4]);
		if(i>=7) f[i]=max(f[i],f[i-7]);
	}
	if(f[n]){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define ll long long
#define ull unsigned long long
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define eps 1e-9
#define P pair<int, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()

void YES() { cout << "YES\n"; }
void NO() { cout << "NO\n"; }
void Yes() { cout << "Yes\n"; }
void No() { cout << "No\n"; }
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

int main() {
	string s;
	cin >> s;
	if (s[0] == s[2])
		Yes();
	else
		No();

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
inline int read(){
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9'){ if(ch == '-') f = -1; ch = getchar(); }
	while(ch >= '0' && ch <= '9'){ x = x * 10 + (ch ^ 48); ch = getchar(); }
	return x * f;
}
int a = read(), b = read(), c = read(), d = read();
int main(){
	return puts((c - 1) / b <= (a - 1) / d ? "Yes" : "No") & 0;
}

Measured memory_bytes: 3592
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int x = 0;

  cin >> x;

  if(x < 1200) cout << "ABC" << endl;
  else cout << "ARC" << endl;


  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back

void solve(){
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<ll> P(a), Q(b), R(c);
    REP(i, a) cin >> P[i];
    REP(i, b) cin >> Q[i];
    REP(i, c) cin >> R[i];

    sort(P.rbegin(), P.rend());
    sort(Q.rbegin(), Q.rend());

    vector<ll> res;

    REP(i, x) res.pb(P[i]);
    REP(i, y) res.pb(Q[i]);
    REP(i, R.size()) res.pb(R[i]);

    sort(res.rbegin(), res.rend());

    ll ans = 0;
    REP(i, x+y) ans += res[i];

    cout << ans << endl;

}

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

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

int main() {
    string S;
    cin >> S;
    vector<int> c(26, 0);
    for (int i = 0; i < S.size(); i++) {
        c.at(int(S.at(i)) - int('a')) = 1;
    }
    if (S.size() < 26) {
        for (int i = 0; i < 26; i++) {
            if (c.at(i) == 0) {
                cout << S << char(i + int('a')) << endl;
                break;
            }
        }
    } else if (S == "zyxwvutsrqponmlkjihgfedcba") {
        cout << -1 << endl;
    } else {
        vector<int> d(26, 0);
        bool f = false;
        for (int i = 25; i >= 0; i--) {
            d.at(int(S.at(i)) - int('a')) = 1;
            for (int j = int(S.at(i) - int('a') + 1); j < 26; j++) {
                if (d.at(j) == 1) {
                    cout << S.substr(0, i) << char(j + int('a')) << endl;
                    f = true;
                    break;
                }
            }
            if (f) break;
        }
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 101

int D[MAX];

bool check(){
    if ( D[1]%2 == 0 || D[2]%2 == 0 ) return false;
    for ( int i = 3; i < MAX; i++ ) if ( D[i]%2 ) return false;
    return true;
}

main(){
    int a, b;
    while( cin >> a >> b ){
	for ( int i = 1; i <= MAX; i++ ) D[i] = 0;
	D[a]++; D[b]++;
	while(1){
	    cin >> a >> b;
	    if ( a == 0 && b == 0) break;
	    D[a]++; D[b]++;
	}
	cout << (check()?"OK":"NG") << endl;
    }
}

Measured memory_bytes: 0
/**
 *   author: Shubham Srivastava
 *   created: 02 December 2019  18:41:06
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    string s;cin>>s;
    string year = "", month = "";
    for(int i=0;i<4;i++){
        year += s[i];
    }
    if(year < "2019"){
        cout<<"Heisei";
        return 0;
    }
    else if(year > "2019"){
        cout<<"TBD";
        return 0;
    }
    else{
        for(int i=5;i<7;i++)
            month += s[i];
        if(month > "04")
            cout<<"TBD";
        else
            cout<<"Heisei";
    }
return 0;
}

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

typedef long long ll;
const int MOD = 1000000007;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(b-a == c-b){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
N = int(input())
b = list(map(int, input().split()))
ans = []
cnt = 0
while cnt <= N:
	for j in range(len(b) - 1, -1, -1):
		if b[j] == j + 1:
			ans.append(j + 1)
			del b[j]
			break
	cnt += 1
if len(b) == 0:
	for k in range(N):
		print(ans[N - k - 1])
else:
	print(-1)


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

c1 = 0
s = 0

for i in range(n):
    s += a[i]
    if i % 2 == 1:
        if s <= 0:
            c1 += 1 - s
            s = 1

    else: 
        if s >= 0:
            c1 += 1 + s
            s = -1

c2 = 0
t = 0

for i in range(n):
    t += a[i]
    if i % 2 == 1:
        if t >= 0:
            c2 += 1 + t
            t = -1
    else:
        if t <= 0:
            c2 += 1 - t
            t = 1

print(min(c1, c2))


Measured memory_bytes: 14468
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
int W,H;
constexpr Int mod = 1e9 + 7;
int main(){
    cin >> H >> W;
    vector<string>grid(H);
    for(auto& s : grid) cin >> s;
    vector<vector<Int>>dp(H,vector<Int>(W,0LL));
    for(int i = 0; i < H and grid[i][0] != '#'; ++i) dp[i][0] = 1;
    for(int j = 0; j < W and grid[0][j] != '#'; ++j) dp[0][j] = 1;
    for(int i = 1; i < H; ++i){
        for(int j = 1; j < W; ++j){
            if(grid[i][j] == '#') continue;
            dp[i][j] = dp[i-1][j] + dp[i][j-1];
            dp[i][j] %= mod;
        }
    }
    cout << dp.back().back() << endl;
}


Measured memory_bytes: 9216
#include <stdio.h>

int main(void)
{
	int a,b,i;
	char c[51];
	
	scanf("%d %d",&a,&b);
	scanf("%s",&c);
	for(i=0;i<a;i++){
		if(i==b-1)c[i]=c[i]+0x20;
	}
	
	printf("%s",c);
	
	printf("\n");
	
	return 0;
}


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

int main(){
  vector<int>number(3);
  cin>>number.at(0)>>number.at(1)>>number.at(2);
  
  sort(number.begin(),number.end());
  
  int margin=2*number.at(2)-number.at(1)-number.at(0);
  
  if(margin%2==0)
    cout<<margin/2;
  else
    cout<<margin/2+2;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define fi first
#define se second
#define pb(i) push_back(i)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define mes(a,b) memset(a,b,sizeof(a))
#define sbs(i,j) substr(i,j)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6+10;
const int INF = 0x3f3f3f3f;
const int inf = - INF;
const int mod = 1e9+7;
const double pi = acos(-1.0);


int main(){
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;   
    getchar();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

#define MAX 3000

template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
    if (a < b) a = b;
}

ll item[MAX + 1][MAX + 1];
ll dp[MAX + 1][MAX + 1][4];

signed main() {
    int R, C, k;
    cin >> R >> C >> k;
    int r, c, v;
    rep(i, k) {
        cin >> r >> c >> v;
        item[r][c] = v;
    }
    for (int i = 1; i <= R; i++) {
        for (int j = 1; j <= C; j++) {
            for (int k = 0; k <= 3; k++) {
                if (item[i][j] > 0) {
                    if (k > 0)
                        chmax(dp[i][j][k], dp[i][j - 1][k - 1] + item[i][j]);
                    chmax(dp[i][j][1], dp[i - 1][j][k] + item[i][j]);
                }
                chmax(dp[i][j][k], dp[i][j - 1][k]);
                chmax(dp[i][j][0], dp[i - 1][j][k]);
            }
        }
    }
    ll ans = 0;
    for (int k = 0; k <= 3; k++) {
        chmax(ans, dp[R][C][k]);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    map<ll,ll> mp;
    for(int i = 0;i < n;i++){
        cin >> a[i];
        mp[a[i]]++;
    }
      
    ll total = 0;
      
    for(auto p : mp){
        ll n = p.second;
        total += n*(n-1)/2;
    }
    
    for(int i = 0;i < n;i++){
        ll ans = total;
        ll mi = mp[a[i]] * (mp[a[i]] - 1)/2;
        ll pl = (mp[a[i]]-1)*(mp[a[i]]-2)/2;
        ans -= mi;
        ans += pl;
        cout << ans << endl;
    }
}

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

int main(){
//srandom((unsigned long)time(NULL));
long long n;
cin>>n;
vector<long long> a;
long long sum=0;
for(long long i=0;i<n;i++){
    long long x;
    cin>>x;
    a.emplace_back(x);
    sum+=x-1;
}
cout<<sum<<endl;



return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;

int N;
ll A[202020];

ll f(ll k){
  ll res=0;
  for(ll i=0;i<N;i++) res-=abs(A[i]-(k+i+1));
  return res;
}

int main(){
  cin>>N;
  rep(i,N) cin>>A[i];
  ll left=-1e10,right=1e10,cnt=0;
  while(cnt<1000){
    if(f((left*2+right)/3)>f((left+right*2)/3)){
      right=(left+right*2)/3;
    }else{
      left=(left*2+right)/3;
    }
    cnt++;
  }
  ll ans=LLONG_MAX/2;
  for(ll i=left;i<=right;i++){
    ll x=-1LL*f(i);
    ans=min(ans,x);
  }
  cout<<ans<<endl;
  return 0;
}


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

int main(){
    int n, k;
    cin >> n >> k;
    int ans = 0;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        if(a >= k)ans++;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MN 2000 
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
char s[5];
int f[MN+5][MN+5],n,p1[MN+5],p2[MN+5],g1[MN+5][MN+5],g2[MN+5][MN+5],ans;
int main()
{
	n=read();
	for(int i=1;i<=n*2;++i)
	{
		scanf("%s",s+1);int x=read();
		if(s[1]=='W') p1[x]=i;
		else p2[x]=i;
	}
	for(int i=1;i<=n;++i)
		for(int j=1;j<i;++j)
			ans+=(p1[j]>p1[i])+(p2[j]>p2[i]);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			g1[i][j]=g1[i][j-1]+(p2[j]>p1[i]),
			g2[i][j]=g2[i][j-1]+(p1[j]>p2[i]);
	memset(f,40,sizeof(f));f[0][0]=0;
	for(int i=0;i<=n;++i) for(int j=0;j<=n;++j)
	{
		if(i) f[i][j]=min(f[i][j],f[i-1][j]+g1[i][j]);
		if(j) f[i][j]=min(f[i][j],f[i][j-1]+g2[j][i]);	
	}
	cout<<f[n][n]+ans;
	return 0;
}



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

const int MAXN = 1005;

int dp[500005];
vector<int> to[5000005];
bool visited[500005];
bool calc[500005];
int id[1005][1005];

int dfs(int v){
//  cout<<'t';
  if (visited[v]) {
    if (!calc[v])return -1;
    return dp[v];
  }
//  cout<<'n';
  visited[v]=true;
//  cout<<v<<'v'<<endl;
  for(int t:to[v]){
//    cout<<t<<'t'<<endl;

  //  cout<<dp[v]<<endl;
    int res=dfs(t);
    if (res==-1) return -1;
    dp[v]=max(dp[v],res+1);
  }
  calc[v]=true;
  return dp[v];
}

int main() {
  rep(i,500000)dp[i]=1;
  rep(i,500000)visited[i]=false;
  rep(i,500000)calc[i]=false;
  int n;
  cin>>n;
  int a[n][n-1];
  rep(i,n){
    rep(j,n-1){
      cin>>a[i][j];
      a[i][j]--;
    }
  }
int V=0;
rep(i,n-1){
  for(int j=i+1;j<n;j++){
    id[i][j]=V;
//    cout<<V<<'v'<<i<<'i'<<j<<'j'<<endl;
    V++;
  }
}

rep(i,n)rep(j,n-1){
  if (i<a[i][j])a[i][j]=id[i][a[i][j]];
  else a[i][j]=id[a[i][j]][i];
}
rep(i,n){
  rep(j,n-2){
  //  cout<<i<<' '<<j<<endl;

    to[a[i][j]].push_back(a[i][j+1]);
  //  cout<<a[i][j]<<a[i][j+1]<<i<<'i'<<j<<'j'<<endl;
  }
}

//cout<<to[0][1]<<'c'<<endl;
int ans=0;
rep(i,V){
  if (dfs(i)==-1){
    cout<<-1;
    return 0;
  }
  ans=max(ans,dfs(i));
//  cout<<dfs(V);}
}
cout<<ans;
}


Measured memory_bytes: 143872
#include <stdio.h>
int main(){
  long i,n,result,tmp,tmp_w,want;
  long a[40]={0};
  
  scanf("%ld",&n);
  
  i=0;
  result=0;
  for(tmp=2;tmp*tmp<=n;tmp++){
    if(n%tmp==0){
      a[i]=tmp;
      i++;
      n=n/tmp;
//    printf("+%ld\n",tmp);
      tmp=1;
    }
  }
  if(n!=1) a[i]=n;
  
  i=0;
  tmp=a[0];
  tmp_w=0;
  want=1;
  while(a[i]!=0){
    if(tmp==a[i]){
      tmp_w++;
      if(tmp_w==want){
        result++;
//        printf(" %ld,%ld\n",tmp,tmp_w);
        want++;
        tmp_w=0;
      }
    } else {
      tmp=a[i];
      tmp_w=0;
      want=2;
      result++;
//      printf(" %ld,1\n",tmp);
    }
    i++;
  }
  
  printf("%ld",result);
}

Measured memory_bytes: 1732
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

int le[2000][2000], ri[2000][2000], up[2000][2000], down[2000][2000];

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

    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for (int i = 0; i < h; i++)
    {
        cin >> s[i];
    }
    for (int i = 0; i < h; i++)
    {
        if (s[i][0] != '#')
            le[i][0] = 1;
        for (int j = 1; j < w; j++)
        {
            if (s[i][j] != '#')
                le[i][j] = le[i][j - 1] + 1;
        }
    }
    for (int i = 0; i < h; i++)
    {
        if (s[i][w - 1] != '#')
            ri[i][w - 1] = 1;
        for (int j = w - 2; j >= 0; j--)
        {
            if (s[i][j] != '#')
                ri[i][j] = ri[i][j + 1] + 1;
        }
    }
    for (int j = 0; j < w; j++)
    {
        if (s[0][j] != '#')
            up[0][j] = 1;
    }
    for (int i = 1; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (s[i][j] != '#')
                up[i][j] = up[i - 1][j] + 1;
        }
    }
    for (int j = 0; j < w; j++)
    {
        if (s[0][j] != '#')
            down[h - 1][j] = 1;
    }
    for (int i = h - 2; i >= 0; i--)
    {
        for (int j = 0; j < w; j++)
        {
            if (s[i][j] != '#')
                down[i][j] = down[i + 1][j] + 1;
        }
    }
    int ret = 0;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (s[i][j] == '#')
                continue;
            ret = max(ret, le[i][j] + ri[i][j] + up[i][j] + down[i][j] - 3);
        }
    }
    cout << ret << endl;
}


Measured memory_bytes: 67072
N, M, Q = map(int, input().split())

S = [[0 for _ in range(N+1)] for _ in range(N+1)]

for i in range(M):
    l, r = map(int, input().split())
    S[l][r] += 1
    
for i in range(1, N+1):
    for j in range(N+1):
        S[i][j] += S[i-1][j]
        
for i in range(N+1):
    for j in range(1, N+1):
        S[i][j] += S[i][j-1]
      
for i in range(Q):
    p, q = map(int, input().split())
    print(S[q][q]-S[q][p-1]-S[p-1][q]+S[p-1][p-1])

Measured memory_bytes: 13400
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

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

	int dmax = (K+A[0])-A[N-1];
	for(int i=0; i<N-1; i++) dmax = max(dmax, A[i+1]-A[i]);

	cout << K -dmax << endl;

	return 0;
}


Measured memory_bytes: 1024
from collections import defaultdict

def main():

    W = input()
    d = defaultdict(int)

    for w in W:
        d[w] += 1

    for v in d.values():
        if v % 2 != 0:
            return 0

    return 1 


if main():
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3316
#include <iostream>
#include <stdio.h>
#include <string.h>
#define MAX_N 100005
#define int long long

using namespace std;

int n,c,ans=0;
int x[MAX_N];
int v[MAX_N];
int p[MAX_N];
int d[MAX_N];

signed main()
{
	scanf("%lld%lld",&n,&c);
	for(int i=1;i<=n;i++) scanf("%lld%lld",&x[i],&v[i]);
	int sum=0;
	for(int i=1;i<=n;i++)
	{
		sum+=v[i];
		p[i]=max(p[i-1],sum-x[i]);
		d[i]=max(d[i-1],sum-(x[i]<<1));
		ans=max(ans,sum-x[i]);
	}
	sum=0;
	for(int i=n;i>=1;i--)
	{
		sum+=v[i];
		ans=max(ans,sum-(c-x[i]));
		ans=max(ans,sum-((c-x[i])<<1)+p[i-1]);
		ans=max(ans,sum-(c-x[i])+d[i-1]);
	}
	printf("%lld\n",ans);
}


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

int main(){
  int N, l, r, S;
  S = 0;
  cin >> N;
  for(int i=0; i<N; i++){
    cin >> l >> r;
    S = S + r + 1 - l;
  }
  cout << S << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 10000000000000000LL;
const ll MAX = 1000000000000000LL;
struct edge{ ll to,cost; };
typedef pair<ll,ll> P;

vector<ll> dijkstra(vector< vector< edge > > G, int si){
  vector<ll> d( G.size() , INF );
  d[si]=0;
  priority_queue< P , vector<P> , greater<P> > Q;
  Q.push( P(0,si) );
  while(!Q.empty()){
    P p=Q.top();
    Q.pop();
    ll pos=p.second;
    ll cost=p.first;
    if( d[ pos ] < cost )continue;
    for(int i=0;i<(int)G[pos].size();i++){
      edge e=G[pos][i];
      ll ncost=e.cost+cost;
      if(ncost < d[e.to]){
        d[e.to]=ncost;
        Q.push( P(ncost,e.to));
      }
    }
  }
  return d;
}

int main(){
  vector< vector< edge > > GA;
  vector< vector< edge > > GB;
  
  int n,m,s,t;
  cin>>n>>m>>s>>t;
  GA.resize(n);
  GB.resize(n);
  
  s--,t--;
  for(int i=0;i<m;i++){
    ll u,v,a,b;
    cin>>u>>v>>a>>b;
    u--,v--;
    GB[u].push_back((edge){v,b});
    GB[v].push_back((edge){u,b});

    GA[u].push_back((edge){v,a});
    GA[v].push_back((edge){u,a});
  }

  vector<ll> DA = dijkstra( GA , s );
  vector<ll> DB = dijkstra( GB , t );

  vector<ll> ans(n, INF);
  for(int i=n-1;i>=0;i--){
    ans[i]=DA[i]+DB[i];
    if(i+1 < n)ans[i]=min(ans[i],ans[i+1]);
  }

  for(int i=0;i<n;i++){
    cout<<MAX-ans[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 26684