akhauriyash/Code-Regression huggingface dataset:
/*
For Bantako San
By shyyhs.

Using hash to insert and search for a perticular number.
Every insert and search is O(1) ideally.
*/

#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define ll long long
//#define Hsize 100009
#define Hsize (1<<17)
#define MAXN 201001 
ll sumZ=0; //sum from the beginning
int Ai; //This is Ai in the problem, we use it only once so array is not necessary.
int N; //N in the problem

struct T
{
    ll number,times;
    T* next;
}hashBucket[MAXN];
int top=0;
int hashIndex[Hsize];
inline ll read(){ll tmp=0; char c=getchar(),f=1; for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1; for(;'0'<=c&&c<='9';c=getchar())tmp=tmp*10+c-'0'; return tmp*f;}

//x->hash(x)
inline int hashFunc(ll x)
{
    return (x&(0x0001FFFF));
}

//add the current sumZ to the hash table
inline void addToHash(ll sumZ)
{
    int HsumZ;
    T *index, *beginP;
    HsumZ = hashFunc(sumZ);
    for (beginP=index=&hashBucket[hashIndex[HsumZ]]; (index->times>0); index=index->next)
        if (index->number==sumZ)
        {
            index->times++;
            return;
        }
    hashIndex[HsumZ]=(++top);
    index=&hashBucket[top];
    index->number = sumZ;
    index->times = 1;
    index->next = beginP;
}

void init()
{
    N = read();
    addToHash(0);
    for (int i=0; i<N; ++i)
    {
        Ai = read();
        sumZ=sumZ+Ai;
        addToHash(sumZ);
    }
}

void work()
{
    ll answer=0;
    for (int i=1; i<=top; ++i)
    if (hashBucket[i].times>1)
        answer=answer+(((hashBucket[i].times)*(hashBucket[i].times-1))>>1) ;
    cout<<answer<<endl;
}
    
int main()
{
    init();
    work();
    return 0;
}


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

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

  vector<int> R(n);
  rep(i, n) cin >> R.at(i);

  int minv = R.at(0);
  int maxv = R.at(1) - R.at(0);
  for (int i = 1; i < n; i++)
  {
    maxv = max(maxv, R.at(i) - minv);
    minv = min(minv, R.at(i));
  }

  cout << maxv << endl;

  return 0;
}


Measured memory_bytes: 3592
arr = map(int,list(raw_input()))

printed = False

def comb(strs,sums,i):
		global printed
		if i == 3 and sums == 7 and not printed: 
			print str(arr[0]) + strs[0] + str(arr[1]) + strs[1] + str(arr[2]) + strs[2] + str(arr[3]) + "=7"
			printed = True

		elif i < 3:
			comb(strs+'+',sums+arr[i+1],i+1)
			comb(strs+'-',sums-arr[i+1],i+1)



comb('',arr[0],0)

Measured memory_bytes: 2568
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define rando mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ld long double
#define ll long long
#define int ll
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
int32_t main(){
    boost;
    string a,b;
    cin>>a>>b;
    cout<<b+a;
    return 0;
}
//long long
//array bounds
//special cases
//binary search

Measured memory_bytes: 256
import java.util.Scanner;

class Main
{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		
		int[] c = new int[20000];
		int i = 0;
		int d = 0;
		
		while(d==0){
			int a = scan.nextInt();
			String op = scan.next();
			int b = scan.nextInt();
			
			if (op.equals("+")){
				c[i] = a + b;}
			else if (op.equals("-")){
				c[i] = a - b;}
			else if (op.equals("*")){
				c[i] = a * b;}
			else if (op.equals("/")){
				c[i] = a / b;}
			else{
				break;}
			
			i++;}
			
		for (int q=0; q<i; q++){
			System.out.println(c[q]);}
	}
}


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

int main() {
  int r,g,b;cin>>r>>g>>b;
  if ((10*g+b)%4==0) cout<<"YES";
  else cout<<"NO";
}


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

int main()
{
    int a, b;
    cin >> a >> b;

 
    cout << (a-1)*(b-1) << endl;

    return 0;
}

Measured memory_bytes: 3652
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <bitset>
#include <vector>
#include <queue>
using namespace std;
 
const int N = 3e5 + 10;
const int INF = 1e9;
int dp[N], a[N] = {0};

struct TreeNode {
    int l, r;
    int max;
}tree[N * 4];

void build(int p, int l, int r) {
    tree[p].l = l;
    tree[p].r = r;
    if (tree[p].l == tree[p].r) {
        tree[p].max = 0;
        return ;
    }
    int mid = (tree[p].l + tree[p].r) / 2;
    build(p * 2, l, mid);
    build(p * 2 + 1, mid + 1, r);
    tree[p].max = max(tree[p * 2].max, tree[p * 2 + 1].max);
}

void update(int p, int x, int v) {
    if (tree[p].l == tree[p].r) {
        tree[p].max = v;
        return ;
    }
    int mid = (tree[p].l + tree[p].r) / 2;
    if (x <= mid) {
        update(p * 2, x, v);
    } else {
        update(p * 2 + 1, x, v);
    }
    tree[p].max = max(tree[p * 2].max, tree[p * 2 + 1].max);
}

int query(int p, int l, int r) {
    if (l <= tree[p].l && tree[p].r <= r) {
        return tree[p].max;
    }
    int mid = (tree[p].l + tree[p].r) / 2;
    int ans = -INF;
    if (l <= mid) {
        ans = max(ans, query(p * 2, l, r));
    }
    if (r > mid) {
        ans = max(ans, query(p * 2 + 1, l, r));
    }
    return ans;
}

int main() {
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    #endif
    int n, k;
    scanf("%d %d", &n, &k);
    build(1, 1, N);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
        int l = max(0, a[i] - k);
        int r = min(N, a[i] + k);
        int res = query(1, l, r);
        dp[i] = res + 1;
        update(1, a[i], dp[i]);
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans = max(ans, dp[i]);
    }
    printf("%d\n", ans);
    return 0;
}

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

using namespace std;

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

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
    for (auto a: v)
        out << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const set<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const multiset<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename S, typename T>
ostream& operator<<(ostream& out, const map<S, T>& M) {
    for (auto m: M)
        cout << "(" << m.first << "->" << m.second << ") ";
    return out;
}

template<typename S, typename T>
pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

template<typename S, typename T>
pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first - b.first, a.second - b.second);
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a, b;
    cin >>a >> b;
    if (a >= 1 && a <= 9 && b >=  1  && b <= 9)
        cout << a * b << endl;
    else
        cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int N, M, X;
int A[12][12];
int sum[12];
int C[12];

void clear(){
    for(int i = 0; i < M; i++) sum[i] = 0;
}

bool judge(){
    for(int i = 0; i < M; i++){
        if(sum[i] < X) return false;
    }
    return true;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> M >> X;
    for(int i = 0; i < N; i++){
        cin >> C[i];
        for(int j = 0; j < M; j++) cin >> A[i][j];
    }
    int ans = 1e9;
    for(int i = 0; i < (1<<N); i++){
        int tmp = 0;
        for(int j = 0; j < N; j++){
            int m = (1<<j);
            if(i&m) {
                tmp += C[j];
                for(int k = 0; k < M; k++){
                    sum[k] += A[j][k];
                }
            }
        }
        if(judge()) ans = min(ans, tmp);
        clear();
    }
    if(ans == 1e9) cout << -1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 3656
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset

#include <math.h>
#include <stdlib.h>


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

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

//INT_MAX	2,147,483,647 = 2*1.0e9



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

  vector<ll> A(N);
  for(int i = 0; i < N; i++) cin >> A[i];

  vector<ll> sum(N+1,0);
  map<ll, ll> mp;
  set<ll> modkey;
  for(int i = 0; i < N; i++){
    sum[i+1] = sum[i]+A[i];
    ll mod = sum[i+1] % M;
    mp[mod]++;
    modkey.insert(mod);
  }
  ll ans = 0;
  for(ll i : modkey){
    ans += (ll)mp[i] * (mp[i] -1) /2;
  }
  ans += mp[0];

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 8704
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b % mod; if (a >= mod) a -= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12); // debuged
    int T;
    T = 1;
    while (T--) solve();
}

// https://atcoder.jp/contests/abc147/submissions/15394248
const int N = 83;
int dp[N][N][4 * N * N];
void solve() {
    int h, w;
    cin >> h >> w;
    
    vector<vector<int> > a(h + 1, vector<int>(w + 1));
    rep(i, h) rep(j, w) cin >> a[i][j];
    rep(i, h) rep(j, w) { int b; cin >> b; a[i][j] -= b; }
    
    dp[0][0][2 * N * N] = 1;
    rep(i, h) rep(j, w) {
        rep(k, 4 * N * N) {
            if (dp[i][j][k] == 0) continue;
            dp[i + 1][j][k + a[i][j]] = 1;
            dp[i][j + 1][k + a[i][j]] = 1;
            dp[i + 1][j][k - a[i][j]] = 1;
            dp[i][j + 1][k - a[i][j]] = 1;
        }
    }
    int ans = inf;
    rep(k, 4 * N * N) if (dp[h][w - 1][k] || dp[h - 1][w][k]) chmin(ans, abs(2 * N * N - k));
    cout << ans << endl;
}



Measured memory_bytes: 357792
#include <bits/stdc++.h>
using namespace std;
string s;
int l[1000];
int main(){
    cin>>s;
    for(int i=0;i<s.size();i++){
        l[s[i]-'a'] ++;
    }
    for(int i=0;i<50;i++){
        if(l[i]%2!=0){
            cout<<"No"<<endl;
            exit(0);
        }
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
l = []
for _ in range(m):
    a,b = map(int,input().split())
    l.append([a,b])

a = []
b = []
for x in l:
    if x[0] == 1:
        a.append(x[1])
    if x[1] == n:
        b.append(x[0])

if set(a) & set(b):
    print ("POSSIBLE")
else:
    print ("IMPOSSIBLE")


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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}


int main() {
  int a[100001], b[100001], c[100001];
  int n;
  cin >> n;
  rep(i, 0, n) cin >> a[i];
  rep(i, 0, n) {
    if(!b[i]) {
      int d[100001] = {}, e = i;
      while(1) {
        if(!d[e]) d[e] = 1, e = (e + a[e]) % n, b[e] = 1;
        else {
          int si = (e + a[e]) % n;
          c[e] = 1;
          while(1) {
            if(si == e) break;
            else c[si] = 1, si = (si + a[si]) % n;
          }
          break;
        }
      }
    }
  }
  int ans = 0;
  rep(i, 0, n) {
    if(c[i]) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4764
#include <algorithm>
#include <deque>
#include <iostream>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  deque<int> a;
  int q;
  cin >> q;
  REP(i, q) {
    int n;
    cin >> n;
    if (n == 0) {
      int d, x;
      cin >> d >> x;
      if (d == 0)
        a.push_front(x);
      else
        a.push_back(x);
    } else if (n == 1) {
      int p;
      cin >> p;
      cout << a[p] << endl;
    } else {
      int d;
      cin >> d;
      if (d == 0)
        a.pop_front();
      else
        a.pop_back();
    }
  }
  return 0;
}


Measured memory_bytes: 4612
#include <iostream>
#include <vector>

using namespace std;

int
main()
{
    int a, b;
    cin >> a >> b;
    --a;
    --b;

    int h = 100, w = 100;

    int turn = 0;
    cout << h << " " << w << endl;
    for (int i = 0; i < h; ++i) {
        if (turn % 2 == 0) {
            for (int j = 0; j < 49; ++j) {
                if (b && j % 2 == 0) {
                    cout << '#';
                    --b;
                } else {
                    cout << '.';
                }
            }
            cout << ".#";
            for (int j = 51; j < w; ++j) {
                if (a && j % 2) {
                    cout << '.';
                    --a;
                } else {
                    cout << '#';
                }
            }
        } else {
            for (int j = 0; j < 50; ++j) {
                cout << '.';
            }
            for (int j = 0; j < 50; ++j) {
                cout << '#';
            }
        }
        turn ^= 1;
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
#define st first
#define nd second
#define FORE(i,a,b) for(int i=(a),b_=(b);i<=b_;++i)
#define FORD(i,a,b) for(int i=(a),b_=(b);i>=b_;--i)
#define TR(c, it) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++)


int main()
{
#define TASK "NAME"
    // freopen(TASK".inp","r",stdin);
    // freopen(TASK".out","w",stdout);
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int a;
    string s;
    cin >> a ;
    cin >> s ;
    if (a >= 3200){
        cout << s ;
    }
    else {
        cout << "red";
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    long long int h, w;
    cin >> h >> w;
    if (h % 3 == 0 || w % 3 == 0) {
        cout << 0 << endl;
        return 0;
    }
    long long int res = min(w, h);
    for (long long int i = 1; i < h; i++) {
        long long int n1 = i * w, n2 = (w - w / 2) * ( h - i), n3 = w / 2 * (h - i);
        long long int r = max(n1, max(n2, n3)) - min(n1, min(n2, n3));
        res = min(r, res);
    }
    for (long long int i = 1; i < w; i++) {
        long long int n1 = i * h, n2 = (h - h / 2) * ( w - i), n3 = h / 2 * (w - i);
        long long int r = max(n1, max(n2, n3)) - min(n1, min(n2, n3));
        res = min(r, res);
    }
    cout << res << endl;
}


Measured memory_bytes: 3580
/**
* I'm sorry I was an Idiot
*/
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int main(){
	int N,L;
	cin >> N >> L;
	vector<int> nums(N);
	int tot = 0;
	for(int i = 0; i < N; ++i){
		int val = L + i;
		nums[i] = val;
		tot += val;
	}
	int best = abs(nums[0]);
	int ind = 0;
	for(int i = 1; i < N;++i){
		if(abs(nums[i]) < best){
			best = abs(nums[i]);
			ind = i;
		}
	}
	cout << tot - nums[ind] << endl;
	return 0;
}

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

int main()
{
	int cnt[101];
	fill(cnt,cnt+101,0);

	int ans=0,i;
	while(cin>>i)
	{
		cnt[i]++;
		ans=max(ans,cnt[i]);
	}

	for (int i = 0; i < 101; ++i)
	{
		if(cnt[i]==ans) cout<<i<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
struct _I { _I() {cin.tie(0);ios::sync_with_stdio(false);}} __I;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_h(const vector<T>& c, int n=INT_MAX)
{ rep(i, min(n, (int)c.size())) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define D1(a) cout<<#a<<":"<<a<<"\n"
#define D2(a,b) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<endl 
#define D3(a,b,c) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl 
#define MOD 1000000007

int main()
{
    int H,W,K;cin>>H>>W>>K;
    vector<string> cake(H); cin >> cake;

    vvi ans(H, vi(W, 0));

    int sect = 1;
    int h_begin = 0;
    bool h_ichigo_ok = false;
    rep(i, H+1) {
        bool found = (i != H && count(all(cake[i]), '#')>0);
        if (i == H || (h_ichigo_ok && found)) {
            bool w_ichigo_ok = false;
            int w_begin = 0;
            rep(j, W+1) {
                bool w_found = false;
                if (j != W) {
                    for (int k = h_begin; k <= i-1; k++) {
                        if (cake[k][j]=='#') {
                            w_found = true;
                            break;
                        }
                    }
                }
                if (j == W || (w_ichigo_ok && w_found)) {
                    
                    for (int y = h_begin; y <= i-1; y++) {
                        for (int x = w_begin; x <= j-1; x++) {
                            ans[y][x] = sect;
                        }
                    }
                    sect++;
                    w_begin = j;
                } else if (w_found) {
                    w_ichigo_ok = true;
                }
            }

            h_begin = i;
        } else if (found) {
            h_ichigo_ok = true;;
        }
    }

    rep(i, H) cout_h(ans[i]);
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
	int n,y,x,s=0;
	
	cin>>n;
	
	x=n;
	do{
		y=x%10;     
		s+=y;      
		x=x/10;     
	}while(x!=0);
	
	if(n%s==0)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	else
	{
		cout<<"No"<<endl;
		return 0;
	}
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		char[] s = sc.next().toCharArray();
		char[] t = sc.next().toCharArray();
		int ans = 0;
		for(int i = 0; i < s.length; i++) {
			if(s[i] != t[i]) {
				ans++;
			}
		}
		System.out.println(ans);
	}

	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


Measured memory_bytes: 37428
#include<bits/stdc++.h>
#define scan($) scanf("%d",&$)
#define test() int $;scan($);while($--)
using namespace std;
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    printf("%d\n",6-(a+b));
    return 0;
}


Measured memory_bytes: 3828
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstdlib>
#include <memory.h>
#include <ctime>
#include <bitset>

using namespace std;

#define ABS(a) ((a>0)?a:-(a))
#define MIN(a,b) ((a<b)?(a):(b))
#define MAX(a,b) ((a<b)?(b):(a))
#define FOR(i,a,n) for (int i=(a);i<(n);++i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define pnt pair <int, int>
#define mp make_pair
#define PI 3.1415926535897
#define MEMS(a,b) memset(a,b,sizeof(a))
#define LL long long
#define U unsigned

vector<vector<int>> g;

vector<int> visited;
vector<int> res;
int was[100100];

void dfs(int v) {
	was[v] = 1;
	FOR(i, 0, g[v].size()) {
		int to = g[v][i];
		if (was[to]) {
			continue;
		}
		dfs(to);
		break;
	}
	visited.push_back(v);
}

int main()
{
#ifdef Fcdkbear
	freopen("in.txt", "r", stdin);
	double beg = clock();
	//freopen("out.txt", "w", stdout);
#endif

	int n, m;
	scanf("%d%d", &n, &m);
	g.resize(n);
	FOR(i, 0, m) {
		int v1, v2;
		scanf("%d%d", &v1, &v2);
		v1--;
		v2--;
		g[v1].push_back(v2);
		g[v2].push_back(v1);
	}
	dfs(0);
	res = visited;
	visited.clear();
	dfs(0);
	visited.pop_back();
	reverse(visited.begin(), visited.end());
	FOR(i, 0, visited.size()) {
		res.push_back(visited[i]);
	}
	printf("%d\n", res.size());
	FOR(i, 0, res.size()) {
		if (i) {
			printf(" ");
		}
		printf("%d", res[i] + 1);
	}
	cout << endl;
	
#ifdef Fcdkbear
	double end = clock();
	fprintf(stderr, "*** Total time = %.3lf ***\n", (end - beg) / CLOCKS_PER_SEC);
#endif
	return 0;
}

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

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n;
  scanf("%d",&n);
  int a[100000];
  int i;
  for(i=0;i<n;i++) scanf("%d",a+i);
  int dp[100001];
  for(i=1;i<=n;i++) dp[i]=(1<<30);
  dp[0]=-1;
  int max=0;
  for(i=0;i<n;i++){
    int l=0;
    int r=max+1;
    while(l+1<r){
      int m=(l+r)/2;
      if(dp[m]<a[i]){
	l=m;
      } else {
	r=m;
      }
    }
    dp[r]=a[i];
    if(r>max) max=r;
  }
  printf("%d\n",max);
  return;
}

int main(void){
  run();
  return 0;
}



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

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

  int X; cin >> X;
  int ans = 1;
  for (int i = 2; i * i <= X; i++) {
    int res = i;
    while (res * i <= X) res *= i;
    ans = max(ans, res);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        if (n >= 1000) {
            System.out.println("ABD");
        } else {
            System.out.println("ABC");
        }
    }
}


Measured memory_bytes: 23764
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String keyword = scan.next();
        int count = 0;

        while (true) {
            String text = scan.next();
            if (text.equals("END_OF_TEXT")) break;
            if (text.equalsIgnoreCase(keyword)) count++;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 25980
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds; 

#define int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout<<(x)<<endl
#define watch2(x,y) cout<<(x)<<" "<<(y)<<endl
#define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld; 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

const int INF = 9e18;
const int mod = 1e9 + 7;
const int N = 105;

int i,j,k,c,n,a[N],dp[N][100005],pref[N][100005];

void solve()
{
    cin>>n>>c;
    for(i=1;i<=n;++i)
    {
        cin>>a[i];
    }
    dp[0][0]=1;
    for(i=1;i<=n;++i)
    {
        pref[i-1][0]=dp[i-1][0];
        for(j=1;j<=c;++j)
        {
            pref[i-1][j]=dp[i-1][j];
            pref[i-1][j]+=pref[i-1][j-1];
            pref[i-1][j]%=mod;
        }
        for(j=0;j<=c;++j)
        {
            dp[i][j]+=pref[i-1][j];
            if(j>=a[i]+1)
                dp[i][j]-=pref[i-1][j-a[i]-1];
            dp[i][j]+=mod;
            dp[i][j]%=mod;
        }
    }
    cout<<dp[n][c];
}

signed main()
{
    fastio;
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 160000
#include <cstdio>

bool is_prime(int n) {
    if (n == 2) return true;

    if ((n & 1) == 0) {
        return false;
    }

    for (int i = 3; i*i <= n; i += 2)
        if (n % i == 0) {
            return false;
        }

    return true;
}

int main(int argc, char const *argv[])
{
    int n, count = 0;
    scanf("%d", &n);

    while (n-- > 0) {
        int i;
        scanf("%d", &i);
        if (is_prime(i))
            count++;
    }

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

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

using namespace std;

long double dp[3010][3010], p[3010];
long double ans;
int n;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> p[i];
	
	dp[0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= i; j++) {
			dp[i + 1][j + 1] += dp[i][j] * p[i];
			dp[i + 1][j] += dp[i][j] * (1 - p[i]);
		}
	}
	
	for (int i = (n + 1) / 2; i <= n; i++) ans += dp[n][i];
	cout << fixed << setprecision(10) << ans << '\n';
}


Measured memory_bytes: 139776
# 入力
x1, y1, x2, y2 = list(map(int, input().split()))

a, b = x2 - x1, y2 - y1
x3, y3 = x2 - b, y2 + a
x4, y4 = x3 - a, y3 - b

print("{} {} {} {}".format(x3, y3, x4, y4))


Measured memory_bytes: 2940
S = input()
if S == 'SUN':
    print(7)
elif S == 'MON':
    print(6)
elif S == 'TUE':
    print(5)
elif S == 'WED':
    print(4)
elif S == 'THU':
    print(3)
elif S == 'FRI':
    print(2)
elif S == 'SAT':
    print(1)

Measured memory_bytes: 38384
#include <stdio.h>

int main(int argc, char *argv[])
{
    long long A, B, C;
    long long ans = 0;

    scanf("%lld %lld %lld", &A, &B, &C);

    if (C > A + B) {
        ans = A + B + 1;
    } else {
        ans = C;
    }

    ans += B;

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

    return 0;
}


Measured memory_bytes: 128
import math
h,w = map(int,input().split())
if h == 1 or w == 1:
  result = 1
elif h % 2 == 0:
  result = math.floor(h / 2 * w)
elif w % 2 ==0:
  result = math.floor((h // 2 + 1)) * math.floor(w//2) + math.floor((h//2)) * math.floor(w//2)
else:
  result = math.floor((h//2 + 1)) * math.floor((w//2 + 1)) +  math.floor((h//2)) * math.floor(w//2)
  
print(result)

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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    double ans = 0;
    cin >> n;
    int half = n / 2;
    vector<double> p(n);
    rep (i, n) cin >> p[i];
    vector<vector<double> > dp(n + 1, vector<double>(n + 1, 0));
    dp[0][0] = 1;
    rep (i, n) {
        rep (j, i + 1) {
            dp[i + 1][j + 1] += dp[i][j] * p[i];
            dp[i + 1][j] += dp[i][j] * (1 - p[i]);
        }
    }

    rep (i, n + 1) {
        if (i > half) ans += dp[n][i];
    }
    cout << fixed << setprecision(9);
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 70784
#include<bits/stdc++.h>
using namespace std;
     
#define int long long
#define hell 1000000007  
#define endl "\n"
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define MAX_SIZE 100002



int32_t main()
{   
    io
    
    int n, m;

    cin>>n>>m;
    multiset<pair<int, int>> v;
    int x;
    int total=0;

    map<int, int> freq;

    for(int i=0;i<n;i++)
    {
        cin>>x;
        freq[x]++;
        v.insert(pair<int, int>(x, freq[x]));
    }

    multiset <pair<int, int>> :: iterator itr;
    while(m--)
    {
        itr = v.end();
        itr--;
        v.erase(*itr);

        int prev_num = (*itr).first;
        int new_num = prev_num/2;

        freq[prev_num]--;

        freq[new_num]++;

        v.insert(pair<int, int>(new_num, freq[new_num]));
    }

    for(auto y:v)
        total += y.first;

    cout<<total;

return 0;
}

Measured memory_bytes: 18304
n,k,s = map(int,input().split())
ans_l = []
count = 0
for i in range(n):
    if count != k:
        ans_l.append(str(s))
        count += 1
    else:
        if s == 1:
            ans_l.append(str(2))
        else:
            ans_l.append(str(s-1))
print(" ".join(ans_l))


Measured memory_bytes: 13464
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(K: int, S: str):
    if len(S) > K:
        S = S[:K] + '...'
    print(S)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(K, S)

if __name__ == '__main__':
    main()


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

int main()
{
    int n;
    cin >> n;
    int a;
    vector<int> p(n + 1);

    rep(i, n)
    {
        cin >> p[i] >> a;
    }
    p[n] = a;
    //cout<<"in end"<<endl;

    vector <vector <int> > m(n, vector<int>(n));

    for (int l = 0; l < n; l++)
    {
        for (int i = 0; i < n; i++)
        {
            int j = i + l;
            if(j>=n)break;
            if (i == j) m[i][j] = 0;
            else
            {   
                m[i][j]=m[i][i]+m[i+1][j]+p[i]*p[i+1]*p[j+1];
                for (int k = i;k < j;k++){
                    m[i][j]=min(m[i][k] + m[k+1][j] + p[i] * p[k + 1] * p[j + 1],m[i][j]);
                }
            }
        }
    }

    cout<<m[0][n-1]<<endl;
}


Measured memory_bytes: 3212
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

def main():
  s = list(input().strip())
  _min = 1000
  for i in range(len(s)-2):
    kouho = abs(753 - int(''.join(s[i:i+3])))
    if _min > kouho:
      _min = kouho
  print(_min)

if __name__=='__main__':
  main()

Measured memory_bytes: 2940
A, B, C, D = gets.chomp.split.map(&:to_i)

a = Array.new(100, 0)
(A...B).each do |i|
  a[i] = 1
end
(C...D).each do |i|
  a[i] = true if a[i] == 1
end

p a.count { |i| i == true }

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

using namespace std;
#define ll long long
#define ull unsigned long long
#define mp make_pair
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int> > small_heap;
typedef priority_queue<int> big_heap;
int a[100][100], b[100][100];
bool dp[100][100][25609];
int n, m;

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)scanf("%d", &a[i][j]);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)scanf("%d", &b[i][j]);
    dp[1][1][a[1][1] - b[1][1] + 12800] = 1;
    dp[1][1][b[1][1] - a[1][1] + 12800] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (i == 1 && j == 1)continue;
            for (int k = 0; k <= 25600; k++) {
                int temp1 = a[i][j] - b[i][j];
                int temp2 = b[i][j] - a[i][j];
                if (dp[i - 1][j][k - temp1] || dp[i - 1][j][k - temp2])dp[i][j][k] = 1;
                if (dp[i][j - 1][k - temp1] || dp[i][j - 1][k - temp2])dp[i][j][k] = 1;
            }
        }
    }
    int s = 12800, e = 12800;
    while (1) {
        if (dp[n][m][s] || dp[n][m][e])break;
        e++;
        s--;
    }
    printf("%d\n", e - 12800);
    return 0;
}

Measured memory_bytes: 200960
l,r = gets.chomp.split(" ").map(&:to_i)

if r - l >= 2019 then
  puts 0
  exit 0
end

l = l % 2019
r = r % 2019

if r < l then
  tmp = l
  l = r
  r = tmp
end

min = 2018
(l..r-1).each do |i|
  (i+1..r).each do |j|
    mod = (i * j) % 2019
    min = mod if mod < min
  end
end

puts min


Measured memory_bytes: 1788
import sys
from itertools import accumulate
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


MAX = 10**5


def eratosthenes(n):
    is_prime = [1] * n
    is_prime[0] = 0

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = 0
                j += i
    return is_prime


def main():
    q = int(input())
    is_prime = eratosthenes(MAX)

    a = [0] * (MAX+1)
    for i in range(MAX+1):
        if is_prime[i-1] and is_prime[(i+1)//2-1]:
            a[i] = 1

    s = [0] + a
    s = list(accumulate(s))

    for _ in range(q):
        l, r = map(int, input().split())
        print(s[r+1] - s[l])


if __name__ == '__main__':
    main()


Measured memory_bytes: 53152
use proconio::input;
use proconio::marker::{Chars};
use std::iter::Iterator;
use std::collections::HashSet;

fn main() {
    input! {
    s: i32,
    w: i32,
    }

    if w >= s {
        println!("unsafe")
    }else{
        println!("safe")
    }
}


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

int main() {
  int N, i, j;
  string h;
  j = 0;
  cin >> N;
  for (i = 0; i < N; i++) {
    cin >> h;
    if (h == "Y") {
      j = 1;
    }
  }
  if (j == 1) {
    cout << "Four" << endl;
  }
  else {
    cout << "Three" << endl;
  }
}


Measured memory_bytes: 256
def main():
    infinity = 1e10

    n, k, height = getInputs()

    cost = [infinity] * n
    cost[0] = 0
    cost[1] = abs(height[0] - height[1])

    for i in range(2, n):
        for j in range(i - 1, i - k - 1, -1):
            if j >= 0:
                cost[i] = min(cost[i], cost[j] + abs(height[i] - height[j]))

    print(cost[-1])

def getInputs():
    n, k = map(lambda x: int(x), input().split())
    height = tuple(map(lambda x: int(x), input().split()))

    return n, k, height

main()


Measured memory_bytes: 87760
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
using namespace std;

int main() {
    int H, W;
    while (cin >> H >> W, H) {
        for (int i=0; i<H; ++i) {
            for (int j=0; j<W; ++j) {
                if (i % (H-1) == 0 || j % (W-1) == 0) {
                    cout << "#";
                } else {
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
n = int(input())
a = [0] + list(map(int, input().split())) + [0]
cost = 0
for i in range(n+1):
    cost += abs(a[i] - a[i+1])
    
for j in range(1, n+1):
    if a[j-1] <= a[j] <= a[j+1] or a[j-1] >= a[j] >= a[j+1]:
        print(cost)
    else:
        print(cost - min(abs(a[j] - a[j-1]), abs(a[j] - a[j+1]))*2)

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

using namespace std;

int main(void) {
  int N; cin >> N;
  int A[N+1];
  long long child = 0;
  for (int i = 0; i <= N; i++) {
    cin >> A[i];
    child += A[i];
  }

  long long ans = 0, node = 1, cnum = child;

  for (int i = 0; i <= N; i++) {
    ans += node;
    cnum -= A[i];
    node -= A[i];

    if (i != N) {
      if (node <= 0) {
        cout << -1 << endl;
        return 0;
      }
    } else {
      if (node < 0) {
        cout << -1 << endl;
        return 0;
      }
    }

    node = min(node*2, cnum);
  }

  cout << ans << endl;

  return 0;
}

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

#define pb push_back
#define fst first
#define snd second
#define INF 0x7fffffff
#define INFLL 0x7FFFFFFFFFFFFFFF
#define lenA(ar) sizeof(ar)/sizeof(*ar)
#define fill(a,c) memset(&a, c, sizeof(a))
#define fore(i,x,y) for(ll i=x;i<y;i++)
#define foreI(i,x,y) for(ll i=x-1;i>=y;i--)
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;
const int MAXN = 1e5+2;
ll dp[MAXN][3];
ll mat[MAXN][3];
int n;
ll solve(int row, int col){
    if(row==n-1)return mat[row][col];
    ll &r = dp[row][col];
    if(r>-1)return r;
    ll ans = 0;
    fore(i,0,3){
        if(i!=col)
            ans = max(ans,solve(row+1,i)+mat[row][col]);
    }
   
    return r=ans;
}
int main() {FIN;
    
    cin>>n;
    fore(i,0,n){
        fore(j,0,3)cin>>mat[i][j];
    }
    fill(dp,-1);
    ll ans = 0;
    ans = max3(solve(0,0),solve(0,1),solve(0,2));
    cout<<ans<<"\n";
    return 0;
}




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

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


int main(){
    int N;
    cin>>N;
    vector<int> a(3*N);
    rep(i,3*N)cin>>a[i];
    sort(a.begin(),a.begin()+3*N,greater<int>());
    llint ans=0;
    for (int i = 1; i < 2*N; )
    {
        ans+=a[i];
        i+=2;
    }
    cout<<ans<<endl;
    
}

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

int main()
{
    int n, k;
    cin >> n >> k;
    long long h[n];
    rep(i, n) cin >> h[i];

    sort(h, h+n, greater<int>());

    long long ans = 0;
    for (int i = 0; i < n; i++) {
        if (k > 0) {
            k--;
        }
        else {
            ans += h[i];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
arr = [0] * 100101
n,k = map(int,input().split())
for i in range(n):
    a,b = map(int,input().split())
    arr[a] += b
for i in range(100100):
    arr[i + 1] += arr[i]

for i,j in enumerate(arr):
    if j >= k:
        print(i)
        exit()

Measured memory_bytes: 9456
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
	private	static	BufferedReader	br = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}
 
    /**
     * @param args
     */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int[][] map = null;

		while((map = parseMap()) != null) {
			System.out.println(calcMaxSum(map));
		}
	}

	private static int calcMaxSum(int[][] map) {
		int	max = 0;

		for (int i = 0; i < map.length; i++) {
			for (int j = 0; j < map[i].length; j++) {
				int	l = map[i][j];
				// 理論上、これ以上最大値を更新できない場合は計算しない
				if (l * (map.length-i) > max) {
					for (int k = 0; i+k < map.length; k++) {
						l = Math.min(l, map[i+k][j]);
						max = Math.max(max, l * (k+1));
					}
				}
			}
		}

        return max;
	}

	private static int[][] parseMap() {
		int[][]	map = null;
		int[]	len = parseLen();

        if (len != null) {
			map = new int[len[0]][len[1]];

			for (int y = 0; y < len[0]; y++) {
				String	strin = null;
		        if ((strin = parseStdin()) != null) {
		        	for (int x = len[1]-1; x >= 0; x--) {
		        		if (strin.charAt(x) == (char)'.') {
		        			map[y][x] = (x < len[1]-1) ? ((map[y][x+1] != 0) ? map[y][x+1]+1 : 1) : 1;
		        		}
		        	}
		        }
			}
        }
 
        return map;
	}

	private static int[] parseLen() {
		int[]	params = null;
        String	stdin  = null;

        if ((stdin = parseStdin()) != null) {
			if (!stdin.equals("0 0")) {
				String[]	lines = stdin.split(" ");

				params    = new int[2]; 
				params[0] = Integer.parseInt(lines[0]);
				params[1] = Integer.parseInt(lines[1]);
			}
        }
 
        return params;
	}

	private static String parseStdin() {
        String  stdin = null;
        
        try {
        	String  tmp = br.readLine();
        	if (!tmp.isEmpty()) stdin = tmp;
        }
        catch (IOException e) {}
 
        return stdin;
	}
}

Measured memory_bytes: 27540
package main

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

func getNextLine(scanner *bufio.Reader) string {
	var buffer string
	for {
		line, isPrefix, _ := scanner.ReadLine()
		buffer += string(line)
		if isPrefix == false {
			break
		}
	}
	return buffer
}

func getIntList(scanner *bufio.Reader) []int {
	list := strings.Split(getNextLine(scanner), " ")
	l := len(list)
	result := make([]int, l)
	for i := 0; i < l; i++ {
		result[i], _ = strconv.Atoi(list[i])
	}
	return result
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := bufio.NewReader(fp)

	A := 0
	B := 1
	C := 2
	s := getNextLine(scanner)
	l := len(s)
	dp := make([][3]int, l+1)
	q := 1
	for i := 0; i < l; i++ {
		r := int(s[i] - 'A')
		for ii := 0; ii < 3; ii++ {
			dp[i][ii] %= 1000000007
			dp[i+1][ii] = dp[i][ii]
			if s[i] == '?' {
				dp[i+1][ii] *= 3
			}
		}
		if r == A || s[i] == '?' {
			dp[i+1][A] += q
		}
		if r == B || s[i] == '?' {
			dp[i+1][B] += dp[i][A]
		}
		if r == C || s[i] == '?' {
			dp[i+1][C] += dp[i][B]
		}
		if s[i] == '?' {
			q *= 3
			q %= 1000000007
		}
	}
	fmt.Println(dp[l][C] % 1000000007)
}


Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll MOD = 998244353 ;
const ll dx[4] = { -1,1,0,0 };
const ll dy[4] = { 0,0,-1,1 };
const ll MAX =  3e5 + 10 ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
long long gcd(long long  a, long long  b) { return (b == 0 ? a : gcd(b, a % b)); }
ll n , m , x , k , Q , ans ; string s;
int dp[MAX];
int h[MAX];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);  cout.tie(0);
//    freopen("test.in","r",stdin);
    int k ;
    cin>>n>>k;

    for(int i = 0 ; i < n ; ++i)
        cin>>h[i];

    for(int i = 0 ; i < n ; ++i)
        dp[i] = 2*MOD;

    dp[0] = 0 ;


    for(int i = 1 ; i < n ; ++i)
        for(int j = max(0,i - k) ; j < i ; ++j)
            dp[i] = min(dp[j] + abs(h[i] - h[j]), dp[i]);

    cout<<dp[n - 1]<<'\n';

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int cnt[100005] = {0};
int n, q;
long long sum = 0;

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        int a;
        scanf("%d", &a);
        cnt[a]++;
        sum += a;
    }

    scanf("%d", &q);
    for (int i = 0; i < q; ++i) {
        int x, y;
        scanf("%d %d", &x, &y);
        sum += (y - x) * cnt[x];
        cnt[y] += cnt[x];
        cnt[x] = 0;
        printf("%lld\n", sum);
    }
    return 0;
}


Measured memory_bytes: 4196