akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long ABCD)
{
    int d = ABCD % 10;
    ABCD /= 10;
    int c = ABCD % 10;
    ABCD /= 10;
    int b = ABCD % 10;
    ABCD /= 10;
    int a = ABCD % 10;

    for (int i = 0; i < 8; i++)
    {
        int ans = 0;
        string op1,op2,op3;
        if (i & 1)
        {
            op1 = "+";
            ans += (a + b);
        }
        else
        {
            op1 = "-";
            ans += (a - b);
        }
        if (i & 2)
        {
            op2 = "+";
            ans += c;
        }
        else
        {
            op2 = "-";
            ans -= c;
        }
        if (i & 4)
        {
            op3 = "+";
            ans += d;
        }
        else
        {
            op3 = "-";
            ans -= d;
        }

        if(ans == 7){
            cout << a << op1 << b << op2 << c << op3 << d << "=7" << endl;
            return;
        }
    }
}

int main()
{
    long long ABCD;
    cin >> ABCD;
    solve(ABCD);
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
deck = []
shuffle_f = False 
shuffle_n = 0
while True:
    line = sys.stdin.readline() 
    if not line: break 
    line = line.rstrip('\r\n') 
    if line.isdigit():
        if shuffle_f:
            n = int(line)
            shuffle_n += n
        shuffle_f = True
    else:
        if len(deck) != 0:
            n = shuffle_n % len(deck)
            print(deck[n:]+deck[:n])
        deck = line
        shuffle_f = False
        shuffle_n = 0



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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Question question = new Question();
        question.solve(sc);
    }

    static class Question {

        public int gcd(int a, int b) {
            return a == 0 ? b : gcd(b % a, a);
        }

        public void solve(Scanner sc) {
            int n = sc.nextInt();
            long sum = 0;
            for(int i = 1; i <= n; ++i) {
                for(int j = 1; j <= n; ++j) {
                    for(int k = 1; k <= n; ++k) {
                        int num = gcd(i, gcd(j, k));
                        sum += num;
                    }
                }
            }
            System.out.println(sum);
        }
    }
}


Measured memory_bytes: 35812
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#include<climits>
#include<stack>
#include<queue>
#include<unordered_map>
#include<map>
#include<set>
#include <fstream>
#include<list>

#define loopi(x,y) for(int i = x;i<(y);i++)
#define loopj(x,y) for(int j = x;j<(y);j++)
#define rloopi(x,y) for(int i = x;i>=(y);i--)
#define rloopj(x,y) for(int j = x;j>=(y);j--)


#define nl cout<<"\n";
#define ll long long int
#define mod  1000000007


using namespace std;

int main()
{

	ios :: sync_with_stdio(false);
	cin.tie(nullptr);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n, k;
	cin >> n >> k;
	vector<ll> a(n);
	ll q = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (a[i] > q)
			q = a[i];
	}

	ll p = 1;
	while (p < q)
	{
		ll mid = (p + q) / 2;
		ll count = 0;
		for (int i = 0; i < n; i++)
		{
			count += (a[i] - 1) / mid;
		}

		if (count <= k)
		{
			q = mid;
		}
		else
		{
			p = mid + 1;
		}
	}

	cout << p;





	return 0;
}

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

const int mod = (int) 1e9 + 7;

long long fact[200005], mmi[200005];

long long power(long long n, long long expo)
{
    long long ans = 1;

    while(expo)
    {
        if(expo % 2)
            ans = ans * n % mod;
        
        n = n * n % mod;
        expo /= 2;
    }

    return ans;
}

long long nCr(int n, int r)
{
    if(n < r)
        return 0;
    
    return fact[n] * mmi[r] % mod * mmi[n-r] % mod;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

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

    fact[0] = mmi[0] = 1;

    for(int i=1; i<=200000; i++)
    {
        fact[i] = fact[i-1] * i % mod;
        mmi[i] = power(fact[i], mod-2);
    }

    long long ans = 0;

    for(int z = 0; z <= min(n, k); z++)
        ans += nCr(n, z) * nCr(n - 1, z) % mod;

    cout << ans % mod << "\n";
    return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define For(i , j , k) for (int i = (j) , i##_end_ = (k) ; i <= i##_end_ ; ++ i)
#define Fordown(i , j , k) for (int i = (j) , i##_end_ = (k) ; i >= i##_end_ ; -- i)
#define Set(a , b) memset(a , b , sizeof(a))
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define INF (0x3f3f3f3f)
#define INF1 (2139062143)
#define Mod (1000000007)
#ifdef hany01
#define debug(...) fprintf(stderr , __VA_ARGS__)
#else
#define debug(...)
#endif 
using namespace std;
typedef long long LL;

inline void file()
{
#ifdef hany01 
	freopen("a.in" , "r" , stdin);
    freopen("a.out" , "w" , stdout);
#endif
}

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }

char c_; int _ , __;
inline int read()
{
    for (_ = 0 , __ = 1 , c_ = getchar() ; !isdigit(c_) ; c_ = getchar()) if (c_ == '-')  __ = -1;
    for ( ; isdigit(c_) ; c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
    return _ * __;
}

const int maxn = 300010;

int n, k, a[maxn];

inline void Solve1()
{
    int p = n / 2;
    printf("%d ", p);
    For(i, 2, k) printf("%d ", n);
}

inline void Solve2()
{
    if (n == 1)
    {
        For(i, 1, (k + 1) / 2) printf("1 ");
        return;
    }
    int p = (n >> 1) + 1, t;
    For(i, 1, k) a[i] = p;
    For(i, 1, k / 2)
    {
        -- a[t = k];
        while (!a[t]) {
            if (i >= k / 2) break;
            ++ i;
            For(j, t, k) a[j] = n;
            -- a[-- t];
        }
    }
    For(i, 1, k)
    {
        if (!a[i]) return;
        printf("%d ", a[i]);
    }
}

int main()
{
	file();
    n = read(); k = read();
    if (n % 2 == 0) Solve1(); else Solve2();
    return 0;
}


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

long long gcd(long long a, long long b){
    if(b > a) swap(a,b);
    if(b == 0) return a;
    return gcd(b, a%b);
}

int main(){
    long long a, b, c, d, e, res = 0;
    cin >> a >> b >> c >> d;
    e = c*d/gcd(c,d);
    cout << b-a+1 - (b/c - (a-1)/c) - (b/d - (a-1)/d) + (b/e - (a-1)/e); 
    return 0;
}

Measured memory_bytes: 384
import java.util.*;
class Main{
	public static void main(String args[]){
		Scanner s=new Scanner(System.in);
		int a;
		while(true){
			a=s.nextInt();
			if(a==0)System.exit(0);
			int ret=1;
			int B=5;
			int U=1;
			int R=3;
			int L=4;
			int F=2;
			int D=6;
			for(int i=0;i<a;i++){
				String str=s.next();
				if(str.equals("North")){
					int newB=U;
					int newU=F;
					int newD=B;
					int newF=D;
					B=newB;
					U=newU;
					F=newF;
					D=newD;
				}
				if(str.equals("East")){
					int newU=L;
					int newL=D;
					int newR=U;
					int newD=R;
					U=newU;
					L=newL;
					R=newR;
					D=newD;
				}
				if(str.equals("South")){
					int newB=D;
					int newU=B;
					int newD=F;
					int newF=U;
					B=newB;
					U=newU;
					F=newF;
					D=newD;
				}
				if(str.equals("West")){
					int newU=R;
					int newL=U;
					int newR=D;
					int newD=L;
					U=newU;
					L=newL;
					R=newR;
					D=newD;
				}
				if(str.equals("Right")){
					int newF=R;
					int newB=L;
					int newR=B;
					int newL=F;
					F=newF;
					B=newB;
					R=newR;
					L=newL;
				}
				if(str.equals("Left")){
					int newF=L;
					int newB=R;
					int newR=F;
					int newL=B;
					F=newF;
					B=newB;
					R=newR;
					L=newL;
				}
				ret+=U;
			}
			System.out.println(ret);
		}
	}
}



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

/**
 * The Number of Area
 */
public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int n = Integer.parseInt(line);
			System.out.println((n * (n + 1) >> 1) + 1);
		}
	}
}

Measured memory_bytes: 16860
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_b>
問題文============================================================
 問題文
 すぬけ君は a、b、c の 3 種類の文字のみからなる文字列 S を持っています。
 
 回文恐怖症のすぬけ君は S の文字を自由に並び替えて、
 2 文字以上の回文を部分文字列として含まないようにしようと思いました。
 これが可能かどうかを判定して下さい。
 
 制約
 1≤|S|≤10^5
 S は a、b、c 以外の文字を含まない。

=================================================================

解説=============================================================

================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    string S; cin >> S;
    int abc[3] = {};
    for(int i = 0; i < S.length();i++){
        abc[S[i]-'a']++;
    }
    int Min = min({abc[0],abc[1],abc[2]});
    abc[0] -= Min; abc[1] -= Min; abc[2] -= Min;
    if(abc[0] >= 2 || abc[1] >= 2 || abc[2] >= 2) cout << "NO" << endl;
    else cout << "YES" << endl;
	return 0;
}


Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
//#include"testlib.h"
#define endl "\n"
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define RT(s) return cout<<s,0
#define sz(s)    (int)(s.size())
#define PI acos(-1)
#define EPS 1e-8
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	//freopen("street.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
void fast() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
}
#define watch(x) cout << (#x)<<" = "<<x<<endl

int main() {
	file();
	fast();
	int n;
	ll k; cin >> n >> k;
	vi v1(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> v1[i];
	}
	unordered_map<int, bool> mp;
	vi qu(1, 1);
	int stand = 1;
	mp[stand] = 1;
	for (int i = 0; i < k; i++) {
		stand = v1[stand];
		if (mp[stand]) {
			int s = 0;
			int ti = 0;
			for (int j = 0; j < sz(qu); j++)
				if (qu[j] == stand) {
					s = sz(qu) - j;
					ti = j;
					break;
				}
			//watch(qu[ti]);
			//watch(s);
			k -= i;
			if (k % (s) == 0)
				RT(qu[ti + s - 1] << endl);
			int idx = (k % (s));
			//watch(idx);
			cout << qu[ti + idx - 1] << endl;
			return 0;

		}
		else {
			mp[stand] = 1;
			qu.push_back(stand);
		}
	}
	cout << stand << endl;
	return 0;
}

Measured memory_bytes: 11488
N,K=map(int,input().split())
dp=[1000000000000000 for i in range(N)]
h=[int(x) for x in input().split()]
dp[0]=0
for i in range(N):
    for j in range(i,i+K+1 if i+K+1 < N else N):
        dp[j] = dp[j] if dp[j]<dp[i]+abs(h[j]-h[i]) else dp[i]+abs(h[j]-h[i])
print(dp[-1])

Measured memory_bytes: 58352
a,b,c,d = input().split()
a = int(a)
b = int(b)
c = int(c)
d = int(d)

temp1 = a*c
temp2 = a*d
temp3 = b*c
temp4 = b*d

answer = max(temp1,temp2,temp3,temp4)

print(answer)

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

using namespace std;

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pll;

const int inf = 3000;

int n, k;
vector<vector<int> > g;
vector<int> subtree;
vector<vector<int> > dp;
vector<vector<int> > minn; // minn[v][dep] = min over dp[v][0], ..., dp[v][dep]

void dfs(int v, int p)
{
    subtree[v] = 1;
    vector<int> sons;
    for (int to : g[v]) {
        if (to != p) {
            dfs(to, v);
            sons.pb(to);
            subtree[v] += subtree[to];
        }
    }
    dp[v][0] = subtree[v] - 1;
    for (int dep = 1; dep < k; ++dep) {
        int x = min(dep - 1, k - dep - 1);
        int s = 0;
        for (int son : sons) {
            s += minn[son][x];
        }
        for (int son : sons) {
            dp[v][dep] = min(dp[v][dep], dp[son][dep - 1] + s - minn[son][x]);
        }
    }
    int s = subtree[v] - 1;
    for (int son : sons) {
        dp[v][k] = min(dp[v][k], dp[son][k - 1] + s - subtree[son]);
    }
    minn[v][0] = dp[v][0];
    for (int dep = 1; dep <= k; ++dep) {
        minn[v][dep] = min(minn[v][dep - 1], dp[v][dep]);
    }
}

int main()
{

    cin >> n >> k;
    g.resize(n);
    dp.resize(n);
    subtree.resize(n);
    minn.resize(n);
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        g[u].pb(v);
        g[v].pb(u);
    }

    for (int i = 0; i < n; ++i) {
        dp[i].assign(k + 1, inf);
        minn[i].resize(k + 1);
    }

    dfs(0, 0);
    /*for (int v = 0; v < n; ++v) {
        for (int dep = 0; dep <= k; ++dep) {
            cout << v << " " << dep << " " << dp[v][dep] << "\n";
        }
    }*/
    int ans = inf;
    for (int dep = 0; dep <= k; ++dep) {
        ans = min(ans, dp[0][dep]);
    }
    for (int v = 1; v < n; ++v) {
        for (int dep = 0; dep <= k; ++dep) {
            ans = min(ans, dp[v][dep] + n - subtree[v]);
        }
    }
    cout << ans << "\n";

}


Measured memory_bytes: 32000
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <climits>
#define bogo_sort   std::sort
#define bozo_sort   std::stable_sort
#define alles(obj)  obj.begin(), obj.end()
#define elif        else if
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define echo        std::cout <<
#define read        std::cin >>
#define endl        std::endl
#define fin         << '\n'
#define bash        push_back
#define fish        push_front
#define makePair    std::make_pair
#define _           << ' ' <<
// type-define
#define Stack       std::stack
#define Queue       std::queue
#define Deque       std::deque
#define PQueue      std::priority_queue
#define Set         std::set
#define Vector      std::vector
#define Pair        std::pair
#define Map         std::map
#define HashMap     std::unordered_map
#define Greater     std::greater
using String  =     std::string;
using llong   =     long long;
using boolean =     bool;
using Pii     =     Pair<int, int>;
using Vi      =     Vector<int>;
using Vii     =     Vector<Pii>;
// utils
constexpr int   dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int   dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int   INF  = 0x3f3f3f3f;
constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace {
    template<class A, class B> A power ( llong x, llong n, llong mod ) {
        llong ans = 1;
        while ( n > 0 ) {
            if ( n & 1 ) ans = ( ans * x ) % mod;
            x = ( x * x ) % mod;
            n >>= 1;
        }
        return ans;
    }
    template<class A, class B> A power ( A x, B n ) { return power( x, n, 1000000007 ); }
    template<class A> A gcd ( A x, A y ) { return x % y ? gcd( y, x % y ) : y; }
    template<class A, class B> A lcm   ( A x,  B y ) { return ( x / gcd(x, y) * y ); }
    template<class A> inline A abs ( A n ) { return ( n < 0 ) ? -n : n; }
    template<class A, class B> inline bool chmax ( A &a, const B &b ) { return b > a ? a = b, true : false; }
    template<class A, class B> inline bool chmin ( A &a, const B &b ) { return b < a ? a = b, true : false; }
    inline boolean isMovable ( int x, int y, int w, int h ) {
        return ( x >= 0 && y >= 0 && x < w && y < h );
    }
}

namespace Rlyeh {

    int cnt, a;

    signed call_of_Cthulhu( signed datum ) {

        String s;
        read s;
        for ( int i = 0; i < s.size(); i++ ) {
            if ( s[i] == '0' ) cnt++;
            else a++;
        }
        echo (2*std::min(a, cnt)) fin;

        return 0;
    }
}

signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); int main_result = Rlyeh::call_of_Cthulhu(114514); return 0;}


Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#include <stack>
#include <cctype>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)

#define AAA (1000000007) 


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;
typedef vector<int> vecI;

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;
}
ll powD(ll a, ll b) {
	ll ans = 1;
	a %= AAA;
	for (int i = 0; i < b; i++)
	{
		ans *= a;
		ans %= AAA;
	}
	return ans;
}


int main() {
	int i, j, k;
	//int N, M, K;

	ll X, K, D;
	cin >> X >> K >> D;

	X = abs(X);
	ll n = X / D;
	ll x1 = X - D * n;
	ll x2 = X - D * (n + 1);
	if (abs(n) >= K) {
		cout << abs(X - D * K * (n >= 0 ? 1 : -1)) << endl;
		return 0;
	}
	if ((K - abs(n)) % 2 == 0) {
		cout << abs(x1) << endl;
	}
	else {
		cout << abs(x2) << endl;
	}

	return 0;
}


Measured memory_bytes: 3588
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 29 20:51:40 2019

@author: makigon
"""

import fractions
from functools import reduce
 
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
 
N = int(input())
a = list(map(int,input().split()))
ans = 0

t_left = [0 for i in range(N)]
t_right = [0 for i in range(N)]

t_left[0] = a[0]
t_left[1] = fractions.gcd(a[0],a[1])

for i in range(2,N):
    t_left[i] = fractions.gcd(t_left[i-1],a[i])

t_right[N-1] = a[N-1]
t_right[N-2] = fractions.gcd(a[N-1],a[N-2])

for j in range(N-3,0,-1):
    t_right[j] = fractions.gcd(t_right[j+1],a[j])
    

for i in range(0,N-2):
    tmp = fractions.gcd(t_left[i],t_right[i+2])
    if tmp > ans:
        ans = tmp
    
print(max(ans,t_right[1],t_left[N-2]))

Measured memory_bytes: 16508
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int R, C, K;
int r[200030], c[200030], v[200030];

int B[3030][3030];

long long int dp[3030][3030][4];

int main(void) {

	cin >> R >> C >> K;
	for (int i = 1; i <= K; i++) {
		cin >> r[i] >> c[i] >> v[i];
		B[r[i]][c[i]] = v[i];
	}

	/*for (int i = 1; i <= R; i++) {
		for (int j = 1; j <= C; j++) {
			cout << " " << B[i][j];
		}cout << endl;
	}*/


	for (int i = 1; i <= R; i++) {
		for (int j = 1; j <= C; j++) {
			/*for (int k = 0; k <= 3; k++) {
				dp[i][j][0] = max(dp[i][j][0],dp[i - 1][j][k]);
			}
			for (int k = 0; k <= 3; k++) {
				dp[i][j][1] = max(dp[i][j][1], dp[i - 1][j][k]+B[i][j]);
			}

			for (int k = 0; k <= 3; k++) {
				dp[i][j][k] = max(dp[i][j][k], dp[i][j - 1][k]);
			}
			for (int k = 0; k <= 2; k++) {
				dp[i][j][k+1] = max(dp[i][j][k+1], dp[i][j - 1][k]+B[i][j]);
			}*/

			// 0

			dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j][0]);
			dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j][1]);
			dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j][2]);
			dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j][3]);
			dp[i][j][0] = max(dp[i][j][0], dp[i][j - 1][0]);

			// 1
			dp[i][j][1] = max(dp[i][j][1], dp[i - 1][j][0] + B[i][j]);
			dp[i][j][1] = max(dp[i][j][1], dp[i - 1][j][1] + B[i][j]);
			dp[i][j][1] = max(dp[i][j][1], dp[i - 1][j][2] + B[i][j]);
			dp[i][j][1] = max(dp[i][j][1], dp[i - 1][j][3] + B[i][j]);
			dp[i][j][1] = max(dp[i][j][1], dp[i][j - 1][0] + B[i][j]);
			dp[i][j][1] = max(dp[i][j][1], dp[i][j - 1][1]);

			// 2
			dp[i][j][2] = max(dp[i][j][2], dp[i][j - 1][2]);
			dp[i][j][2] = max(dp[i][j][2], dp[i][j - 1][1] + B[i][j]);

			//3
			dp[i][j][3] = max(dp[i][j][3], dp[i][j - 1][3]);
			dp[i][j][3] = max(dp[i][j][3], dp[i][j - 1][2] + B[i][j]);
		}
	}

	long long int ans = 0;

	for (int i = 0; i <= 3; i++) {
		ans = max(ans, dp[R][C][i]);
	}

	/*for (int i = 1; i <= R; i++) {
		for (int j = 1; j <= C; j++) {
			cout << " " << dp[i][j][1];
		}cout << endl;
	}*/

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 325452
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


def main():
    num = int(input())
    data = list(input())

    if data[0] == 'W' or data[-1] == 'W':
        print(0)
        sys.exit()

    dp = [0 for i in range(2 * num)]
    now_plus = 0
    for i in range(2 * num):
        now_str = data[i]
        # print(now_plus, now_str)
        if now_plus % 2 == 0 and now_str == 'B':
            dp[i] = 1
            now_plus += 1
        elif now_plus % 2 == 0 and now_str == 'W':
            dp[i] = 0
            now_plus -= 1
        elif now_plus % 2 == 1 and now_str == 'B':
            dp[i] = 0
            now_plus -= 1
        elif now_plus % 2 == 1 and now_str == 'W':
            dp[i] = 1
            now_plus += 1


    if now_plus != 0:
        print(0)
        sys.exit()

    mod = 10 ** 9 + 7

    # print(dp)


    count1 = 0
    ans = 1
    for i in range(2 * num):
        if dp[i]:
            count1 += 1
        else:
            ans *= count1
            ans %= mod
            count1 -= 1

    for i in range(1, num + 1):
        ans *= i
        ans %= mod

    print(ans)





if __name__ == '__main__':
    main()



Measured memory_bytes: 61552
//THIS IS THE AATMANIRBHAR SOLUTION I FOUND..!!!!!

#include<bits/stdc++.h>
using namespace std ;
// #define int double
#define int long long
#define pb push_back
#define mp make_pair
#define F first 
#define S second 
#define P push
#define vvi vector<vector<int>>
#define vi vector<int>
#define vf vector<float>
#define vc vector<char>
#define vs vector<string>
#define pii vector<pair<int, int>> 
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define s(v) sort(all(v))
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(j,a,b) for(int j=a-1;j>=b;j--) 
#define binod ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
const int N = 1e9 + 7 , N1 = 1e7 + 5 ;


void solve()
{
    int n,x,t;
    cin>>n>>x>>t;
    cout<<(n+x-1)/x*t;
}

signed main(){
    binod;
    int t1=1;  
    // cin>>t1;
    //cout<<fixed<<setprecision(6);
    while(t1--){ 
        solve();
        cout<<endl;
    }    
}
                                                                            
                                                                            //Don't judge me or anyone
                                                                            //this is life, 
                                                                            //not a reality show
                                                                            


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

void solve(int test_case) {
	string a,b;
	cin>>a>>b;
	if(a.length()>b.length()){
		cout<<"GREATER";
		return;
	}
	else if(a.length()<b.length()){
		cout<<"LESS";
		return;
	}
	for(int i=0;i<a.length();i++) {
		if(a[i]>b[i]) {
			cout<<"GREATER";
			return;
		}
		else if(a[i]<b[i]) {
			cout<<"LESS";
			return;
		}
	}
	cout<<"EQUAL";
}

int main() {
	
	////// FILE BASED IO////
	//freopen("in", "r", stdin);
	//freopen("out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
}	


Measured memory_bytes: 3568
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int n; string s;
	cin >> n >> s;
	int k = 0;
	int needl = 0;
	for (int i = 0; i < n; i++){
		if (s[i] == '(') {
			k++;
		}
		else{
			if (k == 0)needl++;
			else k--;
		}
	}
	for (int i = 0; i < needl; i++)cout << '(';
	cout << s;
	for (int i = 0; i < k; i++)cout << ')';
	cout << endl;
}

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

using ll = long long;
using P = pair<int, int>;
using PP = pair<int, P>;
#define rep1(i,n) for (int i=1; i<=(n); i++)
#define rep0(i,n) for (int i=0; i<(n); i++)
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; }
#ifdef _DEBUG
string _format(string args) { string r = "", t; istringstream s(args); while (getline(s, t, ',')) r += t+":%d "; return r + "\n"; }
#define debug(...) do{printf(_format(#__VA_ARGS__).c_str(), __VA_ARGS__);}while(0)
#define FAST_IOSTREAM() do{}while(0);
#else
#define debug(...) do{}while(0)
#define FAST_IOSTREAM() do{std::ios::sync_with_stdio(false); std::cin.tie(nullptr);}while(0)
#endif

int main() {
    FAST_IOSTREAM();

    int n;
    cin >> n;
   string ans = "No";
    while (n > 0) {
      if (n % 10 == 7) { ans = "Yes"; break; }
     n /= 10;
   }
 
    cout << ans   << endl;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    int n,T; cin>>n>>T;
    int ans=INF;
    rep(i,n){
        int c,t; cin>>c>>t;
        if(t<=T) ans=min(ans,c);
    }
    if(ans==INF) cout<<"TLE"<<endl;
    else cout<<ans<<endl;
    return 0;
}


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

bool isPrime(int n){
	if(n < 2)
		return false;
	else if(n == 2)
		return true;
	else if(n % 2 == 0)
		return false;
	for(int i = 3; i <= sqrt(n); i+=2){
		if(n%i == 0)
			return false;
	}
	return true;
}

int main(){
	bool p[100000] = {false};
	int c[100000] = {0};
	for(int i = 1; i < 100000; i++){
		p[i] = isPrime(i);
		c[i] += c[i-1];
		if(p[i] && p[(i+1)/2])
			c[i]++;
	}

	int Q;
	cin >> Q;
	for(int i = 0; i < Q; i++){
		int l, r;
		cin >> l >> r;
		cout << c[r] - c[l-1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int dp[3005][3005];
int main(){
    string s,t;
    cin>>s>>t;

    int n=s.size();
    int m=t.size();
    
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(i==0||j==0)
                dp[i][j]=0;
            else if(s[i-1]==t[j-1])
                dp[i][j]=dp[i-1][j-1]+1;
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }

    int i=n,j=m;
    string st="";
    //cout<<dp[n][m]<<endl;
    while(i>0 and j>0){
        if(s[i-1]==t[j-1]){
            st+=s[i-1];
            i--;
            j--;
        }
        else if(dp[i-1][j]>dp[i][j-1])
            i--;
        else
            j--;
    }

    reverse(all(st));
    cout<<st;
}

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

namespace ABC132_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var p = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var ans = 0;
            for (int i = 1; i < p.Length - 1; i++)
            {
                if (p[i - 1] < p[i] && p[i] < p[i + 1])
                {
                    ans++;
                }
                if (p[i - 1] > p[i] && p[i] > p[i + 1])
                {
                    ans++;
                }
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13268
/*
-------関数一覧--------
arr1dto2d(Array) 一次元配列を二次元配列にします
pf(N)因数分解した結果をオブジェクトで返します
gcd(a,b)最大公約数を返します
lcm(a,b)最小公倍数を返します
*/
function Main(input) {
  //write here!
  input = input.split("\n");
  var N = input[0];
  var arr = input[1].split(" ").map(Number)
  arr.sort(num)
  var ans=0;
  for(var i=0;i<N;i++){
    ans+=arr[i*2];
  }
  console.log(ans)
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
function arr1dto2d (arr){
	for(var i=0;i<arr.length;i++){
    arr[i]=arr[i].split(" ").map(Number);
    }
  return arr;
}
function pf(n) {
    var result = {};
    
    if (n === 1) {
        return {"1":1}
    }

    var init = 2;

    while (n !== 1) {
        var i = init;
        while (i < Number.MAX_SAFE_INTEGER) {
            if (n % i === 0) {
                n /= i;
                if (!(result[i] > 0)) {
                    result[i] = 0;
                }
                result[i]++;
                break;
            }
            i++;
        }
        init = i;
    }
    return result;
}
function gcd(a, b) {
    if (b === 0){
        return a
    }
    return gcd(b, a % b)
}
function lcm(a,b) {
    var g = (n, m) => m ? g(m, n % m) : n
    return a * b / g(a, b)
}
function num(a, b) {
  return a - b;
}

Measured memory_bytes: 21192
#include <stdio.h>
#define N 8
int A[N][N];
int Row[N];
int Col[N];
int Dpos[2*N-1];
int Dneg[2*N-1];

void printBoard(){
  int i, j;

  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++){
      if(A[i][j] == 1){
	if(Row[i] != j){
	  return;
	}
      }
    }
  }
  
  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++){
      if(Row[i] == j){
	printf("Q");
      }
      else printf(".");
    }
    printf("\n");
  }
}

int putQueen(int i){
  int j;
  
  if(i == N){
    printBoard();
    return 0;
  }

  for(j = 0; j < N; j++){
    if(Col[j] == 1 || Dpos[i+j] == 1 || Dneg[i-j+N-1] == 1){
      continue;
    }
    //put a queen at (i,j)
    Row[i] = j;
    Col[j] = Dpos[i+j] = Dneg[i-j+N-1] = 1;
    //try the next row
    putQueen(i+1);
    //remove the queen at (i,j) for backtracking
    Col[j] = Dpos[i+j] = Dneg[i-j+N-1] = 0;
  }
  
}

int main(){
  int k, i, r, c;
  
  scanf("%d",&k);
  for(i = 0; i < k; i++){
    scanf("%d %d",&r, &c);
    A[r][c] = 1;
  }

  putQueen(0);

  return 0;
}



Measured memory_bytes: 2112
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
int INF = INT_MAX / 2;
double EPS = 1e-10;

struct segment_tree_min {
	int n; vector<ll> v;
	segment_tree_min(int _n) {
		for (n = 1; n < _n; n *= 2);
		v = vector<ll>(n * 2 - 1, LLONG_MAX);
	}
	void set(int i, ll x) {
		int k = i + n - 1;
		v[k] = x;
		while (k > 0) {
			k = (k - 1) / 2;
			v[k] = min(v[k * 2 + 1], v[k * 2 + 2]);
		}
	}
	ll _get(int i, int j, int k, int l, int r) {
		if (r <= i || j <= l) return LLONG_MAX;
		if (i <= l && r <= j) return v[k];
		ll vl = _get(i, j, k * 2 + 1, l, (l + r) / 2);
		ll vr = _get(i, j, k * 2 + 2, (l + r) / 2, r);
		return min(vl, vr);
	}
	ll get(int i, int j) { return _get(i, j, 0, 0, n); }
};

int main() {
	ll N; int M, K, D, S;
	cin >> N >> M >> K >> D >> S;
	if (N > M) {
		cout << K * D << endl;
		return 0;
	}
	vector<int> a(M), b(M), c(M);
	priority_queue<i_i, vector<i_i>, greater<i_i> > pq;
	for (int i = 0; i < M; i++) {
		scanf("%d%d%d", &a[i], &b[i], &c[i]);
		c[i]--;
		pq.push(i_i(a[i], i));
	}
	int t = S + D;
	pq.push(i_i(t, M));
	segment_tree_min st(N);
	for (int j = 0; j < N; j++)
		st.set(j, 0);
	while (K) {
		int i = pq.top().second; pq.pop();
		if (i < M) {
			int start = max((ll)a[i], st.get(c[i], c[i] + 1));
			st.set(c[i], start + b[i]);
		}
		else {
			K--;
			int start = max((ll)t, st.get(0, N));
			if (K == 0) {
				cout << start - S << endl;
				return 0;
			}
			t = start + D;
			pq.push(i_i(t, M));
		}
	}
}

Measured memory_bytes: 5380
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);


// ===

fn main() {
    let a: String = read();
    let a: Vec<usize> = a.into_bytes().into_iter().map(|x| (x - 'a' as u8) as usize).collect();
    let n = a.len();

    let mut next_char: Vec<Vec<usize>> = vec![vec![n+1; 26]; n+1];
    let mut next: Vec<Vec<usize>> = vec![vec![n+1; n+2]; 20];

    let mut last: Vec<usize> = vec![n+1; 26];
    for i in (0..n).rev() {
        last[a[i]] = i + 1;
        next[0][i] = 0;
        for k in 0..26 {
            next_char[i][k] = last[k];
            next[0][i] = max(next[0][i], last[k]);
        }
    }

    for p in 1..20 {
        for i in 0..n {
            next[p][i] = next[p-1][next[p-1][i]];
        }
    }

    let req_length = length_from(0, n, &next) + 1;
    let mut answer: Vec<char> = vec![];

    let mut head: usize = 0;
    for i in 0..req_length {
        for j in 0..26 {
            if !can_go(next_char[head][j], n, req_length - 1 - i, &next) {
                answer.push(('a' as u8 + j as u8) as char);
                head = next_char[head][j];
                break;
            }
        }
    }

    println!("{}", answer.into_iter().collect::<String>());
}


fn can_go(from: usize, to: usize, req: usize, next: &Vec<Vec<usize>>) -> bool {
    let mut head = from;
    for p in (0..20).rev() {
        if req & (1<<p) >= 1 {
            head = next[p][head];
        }
    }
    head <= to
}


fn length_from(from: usize, to: usize, next: &Vec<Vec<usize>>) -> usize {
    let mut head = from;
    let mut total = 0;
    for p in (0..20).rev() {
        if next[p][head] <= to {
            total += 1 << p;
            head = next[p][head];
        }
    }
    total
}


Measured memory_bytes: 96636
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctype.h>
#include <math.h>
using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> vec(n);
    for(int i=0;i<n;i++){
        cin>>vec.at(i);
    }
    int alice=0;
    int bob=0;
    sort(vec.begin(),vec.end());
    reverse(vec.begin(),vec.end());
    for(int i=0;i<vec.size();i+=2){
        alice+=vec.at(i);
    }
    for(int i=0;i+1<vec.size();i+=2){
        bob+=vec.at(i+1);
    }
    cout<<alice-bob<<endl;
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Random;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	//static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	
	
	
	
	public static void main(String[] args) {
		//int N=sc.nextInt();for(int i=0;i<N;i++) {}
		//int a[]=new int[N];
		//Ae2+Be2=Ce2
		long a=sc.nextInt();
		long b=sc.nextInt();
		long c=sc.nextInt();
		
	
		
		if(4*a*b<(c-a-b)*(c-a-b)&&c-a-b>0) {
			p("Yes");
		}else {
			p("No");
		}
		
		}
		
		
	
	
	
	public static long lcm(long a, long b) {
        return a / gcd(a, b) * b;
	}
	
	public static long gcd(long a, long b) {
        return b == 0 ? a: gcd(b, a % b);
	}

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	
}
	


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

#define vi vector<int>

int main() {

    int N;
    cin >> N;

    int tmp;
    vi A;
    for (int i = 0; i < N; i++) {
        cin >> tmp;
        A.push_back(tmp);
    }

    for (int k = 0; k < N; k++) {
        cout << A[k];
        if (k != N - 1) {
            cout << " ";
        }
        else {
            cout << endl;
        }
    }
    int v, j;
    for (int i = 1; i < N; i++) {
        v = A[i];
        j = i - 1;
        while (j >= 0 && A[j] > v) {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        for (int k = 0; k < N; k++) {
            cout << A[k];
            if (k != N - 1) {
                cout << " ";
            }
            else {
                cout << endl;
            }
        }
    }

    return 0;
}



Measured memory_bytes: 3136
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
typedef long long int lli;
using namespace std;

int main(){
	int sum,result;
	while(cin >> sum&&sum){
		result=sum;
		for(int i=0; i<9; ++i){
			int tmp;
			cin >> tmp;
			result-=tmp;
		}
		cout << result << "\n";
	}
	return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cassert>
#include <algorithm>    
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <bitset>
#define pb push_back
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
// #define int long long
using namespace std;

typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef tuple<int, int, int> tiii;
typedef unsigned long long ull; 
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const int M = 1e9 + 7;
//__int128


const int maxn = 2e5;
std::vector<int> G[maxn], tree[maxn];
int p[maxn];
int c[maxn];
void dfs(int u) {
  for(auto i : G[u]) {
    if(p[i] == -1) {
      tree[u].eb(i);
      p[i] = u;
      dfs(i);
    } else if(i != p[u] && i < u) {
      cout << u << ' ' << i << endl;
      ++c[u];
    }
  }
}

void dfs(int u, int fa) {
  for(auto i : tree[u]) {
    if(fa != i) dfs(i, u);
  }
  if(c[u] & 1) {
    cout << u << ' ' << fa << endl;
  } else if(fa) {
    cout << fa << ' ' << u << endl;
    c[fa]++;
  }
}

signed main() {
  // freopen("in.txt", "r", stdin);
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n, m;
  cin >> n >> m;
  if(m & 1) {
    cout << -1 << endl;
    return 0;
  }
  memset(p, -1, sizeof(p));
  for(int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    G[u].eb(v);
    G[v].eb(u);
  }
  p[1] = 0;
  dfs(1);
  dfs(1, 0);
  return 0;
}

Measured memory_bytes: 27648
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

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

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int n,m;
	cin>>n>>m;
	vector<ll> a(n);
	for(int i = 0; i < n; i++){
		cin>>a[i];
	}
	vector<P> ch(m); //c_j,b_j
	for(int i = 0; i < m; i++){
		cin>>ch[i].second >> ch[i].first;
	}

	sort(all(a));
	sort(all(ch),greater<P>());

	int i = 0;
	for(int j = 0; j < m; j++){
		int cnt = 0;
		while(a[i]<ch[j].first && cnt < ch[j].second){
			if(i>=n)
				break;
			a[i] = ch[j].first;
			cnt++;
			i++;
		}
	}

	cout << accumulate(all(a),(ll)0) << endl;

	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

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; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<62;
constexpr double eps = (1e-9);

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

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  sort(ALL(a));

  vector<bool> dp(k+1, false);

  for (int i = 1; i <= k; i++) {
    for (auto& v : a) {
      if (i - v >= 0 && !dp[i-v]) dp[i] = true;
    }
  }

  if (dp[k]) cout << "First" << endl;
  else cout << "Second" << endl;

  return 0;
}



Measured memory_bytes: 3636
#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 <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (b - a == c - b)
		YES();
	else
		NO();

	return 0;
}

Measured memory_bytes: 256
from sys import stdin
N, W = [int(x) for x in stdin.readline().rstrip().split()]
 
baggage = [0]*N
 
for l in range(N):
    w, v = [int(x) for x in stdin.readline().rstrip().split()]
    baggage[l] = (w, v)
 
dp = [[0]*(W+1) for _ in range(N+1)]
 
for i in range(N):
    for w in range(W+1):
        if w >= baggage[i][0]:
            dp[i+1][w] = max(baggage[i][1]+dp[i][w-baggage[i][0]],dp[i][w])
 
        dp[i+1][w] = max(dp[i][w],dp[i+1][w])
print(dp[N][W])

Measured memory_bytes: 120812
#include <bits/stdc++.h>
#define rep(i,s,n) for(unsigned long long i=s;i<=n;i++)
using namespace std;
int main(){
	long long x;
	cin>>x;
	long long money=100;
	rep(i,1,1000000000000000000){
		money=money+money/100;
		if(money>=x){
			cout<<i<<endl;
			return 0;
		}
	}
	
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  cout << (n - 1) * n / 2 << endl;
  return 0;
}


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

int compare_int(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}

int main(void){
  char buf[1024] = { 0 };
  int num[128] = { 0 };
  char *tok = NULL;
  int N = 0;
  
  //入力読み込み
  fgets(buf, sizeof(buf), stdin);
  sscanf(buf, "%d", &N);
  
  fgets(buf, sizeof(buf), stdin);
  tok = strtok(buf, " ");
  int count = 0;
  while(tok != NULL && count < N){
    num[count++] = atoi(tok);
    tok = strtok(NULL,  " ");
  }
  
  qsort(num, N, sizeof(int), compare_int);
  //for(int i = 0; i < N; i++) printf("%d\n", num[i]);
  int score1 = 0;
  int score2 = 0;
  for(int i = 0; i < N; i++){
    if(i % 2 == 0) score1 += num[i];
    else score2 += num[i];
  }
  printf("%d\n", score1 - score2);
  return 0;
}

Measured memory_bytes: 1772