akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
using P = pair <int,int>; //to, cost
using WeightedGraph = vector<vector <P>>; //to cost
const long long INF = 1LL << 60;
const int MOD = 1000000007;
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; }
//https://www.creativ.xyz/dump-cpp-652/
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
 
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}

#ifdef DEBUG_
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif

signed main(void) { cin.tie(0); ios::sync_with_stdio(false);
    string s; cin>>s;
    rep(i,s.size()){
        cout<<'x';
    }
}

Measured memory_bytes: 256
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(n)]

cnt = 0
for i in range(n):
    ans = c
    for j in range(m):
        ans += a[i][j] * b[j]
    if ans > 0:
        cnt += 1
print(cnt)

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

int main() {
	// your code goes here
	int n;
	cin>>n;
	vector<double> p(n);
	for(int i=0;i<n;i++)
	    cin>>p[i];
    vector<vector<double>> dp(n+1,vector<double>(n+1,0));
    dp[0][0] = 1.0;
    
    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]);
        }
    }
    
    double ans=0.0;
    for(int i=(n+1)/2;i<=n;i++)
        ans+=dp[n][i];
        
    cout<<fixed<<setprecision(10)<<ans<<endl;
	return 0;
}


Measured memory_bytes: 70784
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
/*
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
*/
#define ull unsigned long long int
#define ll long long int
#define MAX 1000000007
//1e9+7
#define pll pair<ll,ll>
#define pii pair<int,int>
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FO ifstream fin("a.in");ofstream fout("a.out");
#define TEST ll T;cin>>T;while(T--)
#define all(x) (x).begin(),(x).end()
#define mset0(x) memset((x), 0, sizeof((x)));
#define mset1(x) memset((x), -1, sizeof((x)));
typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
int n,m,b;
ll a,c,ans=0,dif;
priority_queue<ll> pq;
map<ll,int> mp;
vector<ll> v,w;
vector<pll> u;
void solve(){
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>a;
        v.push_back(a);
    }
    for(int i=0;i<m;i++){
        cin>>b>>c;
        u.push_back(pll(c,b));
    }
    sort(u.begin(),u.end());
    for(int i=m-1;i>=0;i--){
        c=u[i].first;b=u[i].second;
        while(b--) w.push_back(c);
        if(w.size()>=n) break;
    }
    for(auto x:v) w.push_back(x);
    sort(w.rbegin(),w.rend());
    for(int i=0;i<n;i++){
        ans+=w[i];
    }
    cout<<ans;

    return;
}
int main(){
    IO
    //TEST
    solve();
    return(0);
}


Measured memory_bytes: 5744
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
#include <set>
#include <cstdio>
using namespace std;

typedef long long ll;
typedef pair<int,int> P1;
typedef pair<int,P1> P2;
const ll inf=100000000000000;
struct edge{
	int to,cost;
};

int main() {
	int n;
	ll x;
	ll a[2001]={};
	cin>>n>>x;
	ll b[2001]={};
	for(int i=0;i<n;++i)b[i]=inf;
	for(int i=0;i<n;++i)cin>>a[i];
	ll t=inf;
	for(int i=0;i<n;++i){
		ll r=0;
		for(int j=0;j<n;++j){
			b[j]=min(b[j],a[(j-i+n)%n]);
			r+=b[j];
		}
		t=min(t,r+x*i);
	}
	cout<<t<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

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


int main(void) {
    int p,q;
    string t = "(){}[]";
    while(cin >> p >> q, p){
        vi v(6,0);
        vector<vi> x(p,vi(4));
        rep(i,p){
            string in;
            cin >> in;
            rep(j,3) x[i][j] = v[2*j] - v[2*j+1];
            int j = 0;
            while(in[j] == '.')j++;
            x[i][3] = j;
            //rep(j,4)cout << " " << x[i][j];cout << endl;
            rep(j,in.size())rep(k,6)if(in[j] == t[k])v[k]++;
        }
        vector<vi> par(3);
        loop(r,1,21)loop(c,1,21)loop(s,1,21){
            bool b = true;
            rep(i,p){
                if(r*x[i][0] + c*x[i][1] + s*x[i][2] != x[i][3]) b = false;
            }
            if(b){
                //cout << r << " " << c << " " << s << endl;
                par[0].push_back(r);
                par[1].push_back(c);
                par[2].push_back(s);
            }
        }
        rep(i,3){
            sort(all(par[i]));
            par[i].erase(unique(all(par[i])),par[i].end());
            //cout << i << endl;
            //rep(j,par[i].size())cout << " " << par[i][j];cout << endl;
            if(par[i].size() > 1)par[i][0] = -10000;
            else if(par[i].size() == 0)par[i].push_back(-10000);
        }
        v = vi(6,0);
        rep(i,q){
            int ans = 0;
            rep(j,3)ans += par[j][0]*(v[2*j] - v[2*j+1]);
            if(ans < 0){
                bool c = true;
                rep(j,p){
                    int cnt = 0;
                    rep(k,3)if(x[j][k] == v[2*k] - v[2*k+1])cnt++;
                    if(cnt == 3) ans = x[j][3];
                }
                if(ans < 0)ans = -1;
            }
            cout << ans;
            if(i < q-1) cout << " ";
            else cout << endl;
            string in;
            cin >> in;
            rep(j,in.size())rep(k,6)if(in[j] == t[k])v[k]++;
        }


    }
}



Measured memory_bytes: 3344
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,n) (int i=a;i<n;i++)
#define per(i,a,n,s) (int i=n-1;i>=a;i--)
#define range(...) _overload3(__VA_ARGS__,per,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define vecin(x) for(auto&youso_: (x) ) cin >>  youso_
#define vecout(x) for(auto&youso_: (x) ) cout << youso_ << " " ; cout << endl
template<class T>inline bool chmax(T &a, const T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T b) { if (b<a) { a=b; return 1; } return 0; }
const int inf = 1e9+10;
const int mod = 1e9+7;
const long long llinf = 1e18;
#define _GLIBCXX_DEBUG
// head

int main(){
    int n,k,ans=0;
    cin >> n>> k;
    vector<int> l(n);
    vecin(l);
    sort(all(l),greater<int>());
    for range(i,k){
        ans+=l[i];
    }
    cout << ans << endl;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] a = new int[3];
		for (int i = 0; i < 3; i++) a[i] = sc.nextInt();
		Arrays.parallelSort(a);
		System.out.println(a[0]+a[1]==a[2]?"Yes":"No");
		sc.close();
	}
}

Measured memory_bytes: 23764
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

#define FOR(t,x,v) for(t x=0, v_=(v);x < v_; x++)
#define FORR(t,x,v) for(t x=(v); x >= 0; x--)

int N;
ll A[201010];

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N;
    FOR(int,x,N) cin >> A[x];

    ll total = 0; 
    FOR(int,x,N) total += A[x];

    ll ans = numeric_limits<ll>::max();
    ll acc = A[0];
    for (int j = 1; j < N; ++j) {
        ans = min(ans, abs(acc - (total - acc)));
        acc += A[j];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

ll d, c[33], s[444][33];

vector<ll> score(vector<ll> t) {
    ll last[33] = {}, i, j, sc = 0;
    vector<ll> v;
    for (i = 1; i <= d; i++){
        sc += s[i-1][t[i-1]];
        last[t[i-1]] = i;
        for (j = 0; j < 26;j++)
            sc -= c[j] * (i - last[j]);
        v.pb(sc);
    }
    return v;
}

int main(){
    ll i, j;
    cin >> d;
    for (i = 0; i < 26;i++)
        cin >> c[i];
    for (i = 0; i < d;i++)
        for (j = 0; j < 26;j++)
            cin >> s[i][j];
    vector<ll> v;
    ll t;
    for (i = 0; i < d;i++){
        cin >> t;
        v.pb(--t);
    }
    auto ans = score(v);
    for (i = 0; i < d;i++)
        cout << ans[i] << endl;
}

Measured memory_bytes: 3736
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
	/* input */
	int X, Y, A, B, C;
	cin >> X >> Y >> A >> B >> C;
	vector<int> p(A), q(B), r(C);
	for (int i = 0; i < A; ++i) cin >> p[i];
	for (int i = 0; i < B; ++i) cin >> q[i];
	for (int i = 0; i < C; ++i) cin >> r[i];
	/* sort */
	sort(p.begin(), p.end());
	sort(q.begin(), q.end());
	sort(r.begin(), r.end());
	/* select from p, q */
	vector<int> pq(X + Y);
	for (int i = 1; i <= X; ++i)
		pq[i - 1] = p[A - i];
	for (int i = 1; i <= Y; ++i)
		pq[X + i - 1] = q[B - i];
	sort(pq.begin(), pq.end());
	/* accumulate */
	vector<ll> acc_pq(X + Y + 1, 0LL);
	for (int i = 1; i <= X + Y; ++i)
		acc_pq[i] = acc_pq[i - 1] + pq[i - 1];
	/* solve */
	ll res = 0;
	ll no_color = 0;
	for (int x = 0; x <= min(X + Y, C); ++x) {
		if (x) no_color += r[C - x];
		int left = X + Y - x;
		ll red_green = acc_pq[X + Y] - acc_pq[X + Y - left];
		res = max(res, red_green + no_color);
	}
	cout << res << endl;
	return 0;
}

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

int main() {
  string S, answer="Good";
  cin >> S;
  REP(i,4) {
    if(S[i]==S[i+1]) {
      answer="Bad";
      break;
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n = int(input())
a = [int(input()) for i in range(n-1)]
parent = [0 for i in range(n+1)]
nch = [0]*(n+1)
for i in range(n-1):
  parent[i+2] = a[i]
  nch[a[i]] += 1
stack = []
for i in range(1,n+1):
  if nch[i] == 0:
    stack.append(i)
dp = [0]*(n+1)
child = [[] for i in range(n+1)]
while stack:
  x = stack.pop()
  if child[x]:
    cnum = len(child[x])
    child[x].sort(reverse=True)
    k = 0
    for j in range(cnum):
      k = max(k,child[x][j]+j)
    k += 1
    dp[x] = k
  y = parent[x]
  nch[y] -= 1
  child[y].append(dp[x])
  if nch[y] == 0:
    stack.append(y)
print(dp[1])

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
//#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N; cin >> N;
	vector<int> v(N), pos(N + 1); rep(i, 0, N) {
		cin >> v[i];
		pos[v[i]] = i;
	}
	int ans(0);
	set<int>s;
	s.insert(-1);
	s.insert(N);
	dump(s);
	rrep(i, 1, N + 1) {
		dump(i);
		auto x = s.insert(pos[i]);
		dump(s);
		set<int>::iterator l, r;
		l = r = x.first;
		l--, r++;
		dump(*l, *r);
		auto rr = r;
		rr++;

		if (rr != s.end()) {
			int a = *rr - *r;
			int b = *x.first - *l;
			dump(a, b);
			ans += i * a*b;

		}
		dump(ans);
		if (l != s.begin()) {
			auto ll = l;
			ll--;
			int a = *r - *x.first;
			int b = *l - *ll;
			dump(a, b);
			ans += i * a*b;
		}

		dump(ans);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<limits.h>
#include<string>
#include<iomanip>
#include<numeric>
#include<queue>
using namespace std;

long long  mod = 1000000007;

long max(long x, long y) {
	return x > y ? x : y;
}

long min(long x, long y) {
	return x < y ? x : y;
}

long factorial(long n) {
	if (n == 1) {
		return 1;
	}
	else {
		return n * factorial(n - 1);
	}
}

long long  fel(long long  n,long long  f) {

		if (f == 1) {
			return n % mod;
		}
		else if (f % 2 == 0) {
			return (fel(n,f / 2) * fel(n,f / 2)) % mod;
		}
		else {
			return ((n  * fel(n,f / 2) %mod) * fel(n,f / 2))% mod;
		}
	

}


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

	if (a > k) {
		cout << a - k << " " << b;
	}
	else if (b>k-a){
		cout << 0 << " " << b - k + a;
	}
	else {
		cout << 0 << " " << 0;
	}

	}




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;

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

	vector<int> vec(N);
	for (int i = 0; i < N; i++) {
		cin >> vec[i];
	}

	//ここにSTL関数？みたいなやつで低い順にソート
	sort(vec.begin(), vec.end());

	int X = Y;
	int P = 0;
	for (int i = 0; i < N; i++) {
		if (i < N) {
			X -= vec[i];
			P++;
		}
	}

	int Q = 0;
	for (int i = 0; i < Y; i++) {
		if (vec[0] <= X) {
			X -= vec[0];
			Q++;
		}
		else if (vec[0] > X) {
			break;
		}
	}
	cout << P + Q << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> S(N);
    vector<P> cnt;

    rep(i, N) {
        char c;
        cin >> c;
        S[i] = c - '0';
    }

    int st = S[0];
    int en = S[N - 1];
    int ch = 1;
    cnt.push_back(P(0, 0));
    repd(i, 1, N) {
        if (st != S[i]) {
            cnt.push_back(P(ch, st));
            st = S[i];
            ch = 1;
        }
        else {
            ch++;
        }
    }
    if (ch != 0) cnt.push_back(P(ch, st));
    st = S[0];

    //rep(i, cnt.size()) cout << cnt[i] << endl;
    rep(i, (int)cnt.size() - 1) cnt[i + 1].first += cnt[i].first;
    //rep(i, cnt.size()) cout << cnt[i].first << ":" << cnt[i].second << endl;
    int state = ((st == 1) ? K * 2 + 1 : K * 2);
    int ans = 0;
    if (state >= (int)cnt.size()) ans = cnt[(int)cnt.size() - 1].first;
    repd(i, state, cnt.size()) {
        //if (en == 0 && i == (int)cnt.size() - 1) state = K * 2;
        if (cnt[i].second == 0) state = K * 2;
        else state = K * 2 + 1;
        if (i - state < 0) state += i - state;
        //cout << "i:" << i << "state:" << state << endl;
        ans = max(ans, cnt[i].first - cnt[i - state].first);
    }

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

Measured memory_bytes: 1784
package main

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

func main() {
	nextReader = newScanner()
	a, b := float64(nextInt()), float64(nextInt())
	amin := math.Ceil(a / 0.08)
	amax := math.Floor((a+1)/0.08 - 0.1)
	bmin := math.Ceil(b / 0.1)
	bmax := math.Floor((b+1)/0.1 - 0.1)
	if amax < bmin || amin > bmax {
		fmt.Println(-1)
		return
	}
	fmt.Println(max(amin, bmin))
}

func max(x, y float64) float64 {
	if x > y {
		return x
	}
	return y
}

// ---------------------------------------------------------------
// I/O
// ---------------------------------------------------------------
var nextReader func() string

func newScanner() func() string {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 1024), int(1e11))
	sc.Split(bufio.ScanWords)
	return func() string {
		sc.Scan()
		return sc.Text()
	}
}

func nextString() string { return nextReader() }

func nextInt() int { n, _ := strconv.Atoi(nextReader()); return n }

func nextInts(size int) []int {
	ns := make([]int, size)
	for i := 0; i < size; i++ {
		ns[i] = nextInt()
	}
	return ns
}


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

const int INF = 1001001001;
int di[] = { 1,-1, 0, 0};
int dj[] = { 0, 0, 1,-1};

int main(){
    int h,w,n;
    cin >> h >> w >> n;

    vector<string> map(h);
    rep(i,h) cin >> map[i];

    int si,sj;
    rep(i,h) rep(j,w) if(map[i][j] == 'S') {si = i; sj = j;}

    queue<P> q;
    q.emplace(si,sj);

    int dist[h][w];
    rep(i,h) rep(j,w) dist[i][j] = INF;
    dist[si][sj] = 0;

    int ans = 0;
    rep(goal,n){
        char G = goal + 1 + '0';
        int gi,gj;
        rep(i,h) rep(j,w) if(map[i][j] == G){gi = i; gj = j;}
        while(!q.empty()){
            P p = q.front(); q.pop();
            int i = p.first, j = p.second;
            rep(dir,4){
                int ni = i + di[dir];
                int nj = j + dj[dir];
                if(ni<0||nj<0||ni>=h||nj>=w)continue;
                if(map[ni][nj] == 'X'||dist[ni][nj] != INF)continue;
                dist[ni][nj] = dist[i][j] + 1;
                q.emplace(ni,nj);
            }
        }
        ans += dist[gi][gj];
        q.emplace(gi,gj);
        rep(i,h) rep(j,w) dist[i][j] = INF;
        dist[gi][gj] = 0;
    }

    cout << ans << endl;

    return 0;
}


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

#define DEBUG 1
 



int main() {
    int N,X,T;
    cin >> N >> X >> T;

    if(N % X == 0){
        cout << N / X * T << endl;
    }else{
        cout << (N / X + 1 ) * T << endl;
    }
  


    return 0;

}




Measured memory_bytes: 3628
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int h = sc.nextInt();
        int w = sc.nextInt();

        int result = (H*W) - (h*W) - (w*H) + (h*w);
        System.out.println(result);
        sc.close();
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=15;
char str[maxn];
int main()
{
    while(~scanf("%s",str))
    {
        int len=strlen(str);
        int n=1<<(len-1);
        ll ans=0;
        for(int i=0;i<n;i++)
        {
            ll t=str[0]-'0';
            for(int j=0;j<n;j++)
            {
                if(j==len-1||i&(1<<j))
                {
                    ans+=t;
                    t=0;
                    if(j==len-1)
                        break;
                }
                t=t*10+str[j+1]-'0';
            }
        }
        printf("%lld\n",ans);
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include "string"
#define endl '\n'
#define pi pair<int,int>
#define ff first
#define ss second
#define int long long 
#define boost ios_base::sync_with_stdio(false);cin.tie(nullptr)
const int N=1e5+5;
const int inf = 1e10;

int32_t main() { 
    boost;
    int n,w;
    cin>>n>>w;
    int a[n+1],v[n+1];
    for(int i=1;i<=n;i++)
    	cin>>a[i]>>v[i];
    int dp[n+1][N];
    dp[0][0]=0;
    for(int i=1;i<N;i++)
        dp[0][i]=inf;
    int ans=0;
    for(int i=1;i<=n;i++){
    	for(int j=0;j<N;j++){
    		dp[i][j]  = dp[i-1][j];
    		if(j-v[i]>=0)
    			dp[i][j] = min(dp[i][j],dp[i-1][j-v[i]]+a[i]);
   			if(dp[i][j]<=w)
                ans=max(ans,j);
    	}
    }
    cout<<ans<<endl;
}           





Measured memory_bytes: 79232
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
#define mp(a,b) make_pair(a,b)
using namespace std;


int main(){
	int e;
	while(cin>>e,e){
		int mini=1000000;
		int k;
		for(int z=0;(k=e-z*z*z)>=0;z++){
			int y=(int) sqrt(k)+0.00001;
			int x=k-y*y;
			mini=min(mini,x+y+z);
		}
		p(mini);
	}
	return 0;
}

Measured memory_bytes: 3080
from operator import itemgetter
import itertools


class Light:
    def __init__(self, _switch_list: list, p: int):
        self.switch_list = _switch_list
        self.p = p

    def is_on(self, all_switch_states: list) -> int:
        implemented_switches = itemgetter(*self.switch_list)(all_switch_states)
        if isinstance(implemented_switches, int):
            return implemented_switches == self.p
        else:
            return sum(implemented_switches) % 2 == self.p


if __name__ == '__main__':
    i = input()
    switch_total_number = int(i.split()[0])
    lights_total_number = int(i.split()[1])
    lines = [input() for i in range(lights_total_number)]
    p_list = [int(x) for x in input().split()]
    lights = []
    for index, line in enumerate(lines):
        switch_list = [int(x)-1 for x in line.split()]
        del switch_list[0]
        lights.append(Light(switch_list, p_list[index]))

    number_of_all_on = 0
    switch_pattern_iter = itertools.product([1, 0], repeat=switch_total_number)
    for switch_pattern in switch_pattern_iter:
        for light in lights:
            if not light.is_on(list(switch_pattern)):
                break
        else:
            number_of_all_on += 1
    print(number_of_all_on)


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        int k = scanner.nextInt();
        String s = scanner.next();

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            char c = s.charAt(i);
            if (i == k - 1) {
                sb.append(String.valueOf(c).toLowerCase());
            } else {
                sb.append(c);
            }
        }
        System.out.println(sb.toString());
    }
}

Measured memory_bytes: 21844
//
// Created by chen on 19-7-20.
//
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <cmath>
using namespace std;
int main(){
    int n,d;
    cin>>n>>d;
    if(n%(2*d+1)!=0)
        cout<<n/(2*d+1)+1;
    else
        cout<<n/(2*d+1);
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int N,M;
	cin>>N>>M;
	int ans=1;
	for(int i=1;i<=M/2;i++){
		if(M%i==0&&M/i>=N)ans=i;
	}
	if(N==1)ans=M;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
n = int(input())
cs, ss, fs = [], [], []
for _ in range(n - 1):
    c, s, f = map(int, input().split())
    cs.append(c)
    ss.append(s)
    fs.append(f)
cs.append(0)
ss.append(0)
fs.append(1)

res = []
for i in range(n - 1):
    arrives = [0]
    lefts = [ss[i]]
    for j in range(i, n - 1):
        a = lefts[-1] + cs[j]
        arrives.append(a)
        ns = ss[j + 1]
        if a > ss[j + 1]:
            nf = fs[j + 1]
            w = (nf - (a - ns) % nf) % nf
            lefts.append(a + w)
        else:
            lefts.append(ns)
    res.append(arrives[-1])
res.append(0)
for x in res:
    print(x)

Measured memory_bytes: 3188
import java.util.Scanner;

class Main{
      public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
    	int n = scan.nextInt();
    	int m = scan.nextInt();
    	int l = scan.nextInt();
    	
    	int[][] Vec_A = new int[n][m];
    	int[][] Vec_B = new int[m][l];
    	long[][] Vec_C = new long[n][l];
    	
    	for(int i = 0; i < n; i++){
    		for(int j = 0; j < m; j++){
        		Vec_A[i][j] = scan.nextInt();
        	}
    	}
    	for(int i = 0; i < m; i++){
    		for(int j = 0; j < l; j++){
        		Vec_B[i][j] = scan.nextInt();
        	}
    	}
    	
    	for(int i = 0; i < n; i++){
    		for(int j = 0; j < l; j++){
    			for(int k = 0; k < m; k++){
            		Vec_C[i][j] += Vec_A[i][k] * Vec_B[k][j]; 
            	}
    			
    			if(j != l - 1){
    				System.out.print(Vec_C[i][j] + " ");
    			}else{
    				System.out.println(Vec_C[i][j]);
    			}
        	}
    	}
    }
    	
}

Measured memory_bytes: 53820
#include<bits/stdc++.h>
using namespace std;
int n,m,a[80],b[80],c[80];
int main(){
  int l; cin>>l;
  for (int t=19; ~t; --t)
    if (l>>t&1){
      n=t+1;
      for (int i=1; i<n; ++i){
	a[++m]=i,b[m]=i+1;
	a[++m]=i,b[m]=i+1,c[m]=1<<(i-1);
      }
      for (int j=t-1; ~j; --j)
	if (l>>j&1)
	  a[++m]=j+1,b[m]=n,c[m]=(l>>(j+1))<<(j+1);
      cout<<n<<" "<<m<<endl;
      for (int i=1; i<=m; ++i)
	cout<<a[i]<<" "<<b[i]<<" "<<c[i]<<endl;
      return 0;
    }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
	int n;
	while(cin>>n){
		int a[n];
		for(int i=0;i<n;i++)
			cin>>a[i];
		int dp[n+1];
		dp[0]=0;
		dp[1]=abs(a[1]-a[0]);
		for(int i=2;i<n;i++)
			dp[i] =min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
		cout<<dp[n-1]<<endl;
	}
}




Measured memory_bytes: 1024
n = int(input())
a = [int(v) for v in input().split()]

num2 = 0
num4 = 0
for v in a:
    if v % 4 == 0:
        num4 += 1
    elif v % 2 == 0:
        num2 += 1

if num4 >= n // 2:
    print('Yes')
elif num4 * 2 + num2 >= n:
    print('Yes')
else:
    print('No')

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

int n, x, t;

int main(){
	scanf("%d %d %d", &n, &x, &t);
	
	int res = 0;
	while(n > 0){
		n -= x;
		res += t;
	}
	printf("%d\n", res);
	
	return 0;
}


Measured memory_bytes: 3784
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        m: usize,
        v: [[usize1; 2]; n + m - 1]
    }
    let mut t: Vec<Vec<usize>> = vec![Vec::new(); n];
    let mut rev: Vec<Vec<usize>> = vec![Vec::new(); n];
    for i in 0..n + m - 1 {
        t[v[i][0]].push(v[i][1]);
        rev[v[i][1]].push(v[i][0]);
    }
    let mut tab: Vec<[usize; 2]> = vec![[0, 0]; n];
    for i in 0..n {
        if t[i].is_empty() {
            let _ = dfs(&rev, i, &mut tab);
        }
    }
    for i in 0..n {
        println!("{}", tab[i][0]);
    }
}

fn dfs(t: &Vec<Vec<usize>>, v: usize, tab: &mut Vec<[usize; 2]>) -> usize {
    let mut len = 0;
    for &p in t[v].iter() {
        let lt = if tab[p][1] != 0 {
            tab[p][1] + 1
        } else {
            dfs(t, p, tab) + 1
        };
        if len < lt {
            len = lt;
            tab[v] = [p + 1, len];
        }
    }
    len
}


Measured memory_bytes: 31612
#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {1, -1, 0 ,0};

int main() {
    //ifstream cin("C.in");

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

    vector<string> a(n);
    
    pair<int, int> start;

    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        for(int j = 0; j < m; ++j)
            if(a[i][j] == 'S')
                start = make_pair(i, j);
    }
    
    vector<vector<int>> d(n, vector<int> (m, 1e9));

    queue<pair<int, int>> Q;
    Q.push(start);
    
    d[start.first][start.second] = 0;

    while(not Q.empty()) {
        auto node = Q.front();
        Q.pop();
        
        for(int dir = 0; dir < 4; ++dir) {
            int newX = node.first + dx[dir];
            int newY = node.second + dy[dir];

            if(newX < 0 or newX >= n or newY < 0 or newY >= m) {
                continue;
            }

            if(a[newX][newY] == '#' or d[newX][newY] < 1e9) {
                continue;
            }

            d[newX][newY] = d[node.first][node.second] + 1;
            Q.push({newX, newY});
        }
    }
        
    auto getMinFrom = [&] (pair<int, int> x) {
        int steps = min(min(x.first, x.second), min(n - 1 - x.first, m - 1 - x.second));
        return (steps / k) + (steps % k > 0);
    };

    int ans = 1e9;

    for(int i = 0; i < n; ++i)
        for(int j = 0; j < m; ++j)
            if(d[i][j] <= k)
                ans = min(ans, 1 + getMinFrom({i, j}));

    cout << ans << "\n";
}   

Measured memory_bytes: 3584
#include <iostream>
#include <stack>
#include <queue>
#include <map>
#include <vector>
#include <cstdio>
#include <string>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>

using namespace std;

long long int mod = 1000000007;

int main(){
    int n;
    cin>>n;
    if(n%10 == (n/100)){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void){
	char s[201];
	scanf("%s",s);
	int i,j,k,l;
	l = strlen(s);
	if(l%2==0)l-=2;
	else l-=1;
	for(i=l;i>=0;i-=2){
		k=0;
		for(j=i/2;j<i;k++,j++){
			if(s[k] != s[j])break;
		}
		if(j==i){
			printf("%d",i);
			return 0;
		}
	}
	
	
	printf("%d",i);
	return 0;
}

Measured memory_bytes: 128
N, K = map(int, input().split()) # 横に2個
A = list(map(int, input().split()))

A.sort(reverse=True)

dif = []
for i in range(N-1):
    d = A[i] - A[i+1]
    if d != 0:
        dif.append(d)
if dif:
    mind = min(dif)
else:
    mind = A[0]

ans = 'IMPOSSIBLE'
for a in A:
    if a < K:
        break
    if a == K:
        ans = 'POSSIBLE'
        break
    if (a-K) % mind == 0:
        ans = 'POSSIBLE'
        break

print(ans)

Measured memory_bytes: 14224
n,l = map(int,input().split())
ans = 0
if l > 0:
    for i in range(1,n):
        ans += l+i
elif l+n-1 >= 0:
    for i in range(n):
        ans += l+i
else:
    for i in range(n-1):
        ans += l+i

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define mem(i, j) memset(i, j, sizeof(i))
#define rep(i, j, k) for(int i = j; i <= k; i++)
#define dep(i, j, k) for(int i = k; i >= j; i--)
#define pb push_back
#define make make_pair
#define INF INT_MAX
#define inf llONG_MAX
#define PI acos(-1)
#define fir first
#define sec second
using namespace std;

const int N = 2e5 + 10;

pair < ll, ll > a[N], tmp;
ll c[N];
ll dp[100];

bool cmp(pair < ll, ll > A, pair < ll, ll > B) {
    return A.fir * (B.sec + 1) > B.fir * (A.sec + 1);
}

void solve() {

    int n; ll T;
    scanf("%d %lld", &n, &T);
    int cnt1 = 0, cnt2 = 0;
    rep(i, 1, n) {
        scanf("%lld %lld", &tmp.fir, &tmp.sec);
        if(tmp.fir == 0) c[++ cnt2] = tmp.sec + 1;
        else a[cnt1++] = tmp;
    }

    sort(c + 1 , c + cnt2 + 1);
    sort(a, a + cnt1, cmp);

    rep(i, 1, 30) dp[i] = T + 1;
    dp[0] = 0;
    rep(i, 1, cnt2 ) c[i] += c[i - 1];

    rep(i, 0, cnt1 - 1) {
        dep(j, 1, 30) {
            dp[j] = min(dp[j], (a[i].fir + 1) * (dp[j - 1] + 1) + a[i].sec);
        }
    }

    int ans = 0;
    rep(i, 0, 30) {
        if(dp[i] > T) continue;
        int add = 0;
        if(cnt2) add = upper_bound(c + 1, c + cnt2 + 1, T - dp[i]) - c - 1;
        ans = max(ans, i + add);
    }
    printf("%d\n", ans);
    return ;
}
int main() {
    solve();
    return 0;
}


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

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

ll ans;
int h, w;
ll k;
char c[10][10];

int main(void) {
    cin >> h >> w >> k;
    rep(i, 0, h) scanf("%s", c[i]);

    for (int i=0; i<(1<<h); i++) for (int j=0; j<(1<<w); j++) {
        int sum = 0;
        for (int hi=0; hi<h; hi++) for (int wi=0; wi<w; wi++) {
            if (!((i>>hi)&1) && !((j>>wi)&1) && c[hi][wi]=='#') sum++;
        }
        if (sum == k) ans++;
    }


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



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

using namespace std;

int main() {
	int a[4];
	for(int i=0;i<3;i++)cin >> a[i];
	sort(a,a+3);
	int ans=0;
	for(int i=0;i<2;i++)ans+=a[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define ll long long int 
using namespace std; 
  
int main() 
{  
    ios_base::sync_with_stdio(false) ;
    cin.tie(NULL);  
    int n;
     cin>>n;
     if(n<=2)  cout<<"0"<<endl; 
     else 
     {
         cout<<n/3<<endl;
     }
    return 0; 
} 


Measured memory_bytes: 3548
fun main(args: Array<String>) {
    val N = nextInt()
    val S = next()
    val Q = java.util.ArrayDeque<Char>()
    var openBracket = 0
    S.forEach { s ->
        when (s) {
            '(' -> openBracket += 1
            ')' -> if (openBracket > 0) openBracket -= 1
                   else Q.addFirst('(')
        }
        Q.addLast(s)
    }
    val ans = Q.joinToString("") + ")".repeat(openBracket)
    println(ans)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()


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

using namespace std;

int main() {
	int n, l;

	cin >> n >> l;
	vector<string> strs(n);
	for (auto &s : strs) {
		cin >> s;
	}
	sort(strs.begin(), strs.end());

	for (auto s : strs) {
		cout << s;
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.*;
import static java.lang.System.*;

class Main {
	public static Scanner sc = new Scanner(in);
	public static Random rand=new Random();

	public void run() {
		TCase:while(true){
			int W=sc.nextInt(),H=sc.nextInt();
			if(W==0 && H==0)return;
			char[][] map=new char[H][W];

			for(int h=0;h<H;h++){
				map[h]=sc.next().toCharArray();
			}

			BigInteger[][] dp=new BigInteger[H][W];

			for(int h=0;h<H;h++)for(int w=0;w<W;w++){
				BigInteger hprev=BigInteger.ZERO;
				if(h>=1){
					hprev=dp[h-1][w];
				}
				BigInteger wprev=BigInteger.ZERO;
				if(w>=1){
					wprev=dp[h][w-1];
				}
				if(Character.isDigit(map[h][w])){
					BigInteger max;
					if(hprev.compareTo(wprev)>0){
						max=hprev;
					}else{
						max=wprev;
					}
					dp[h][w]=max.multiply(BigInteger.TEN).add(new BigInteger(map[h][w]+""));
				}else{
					dp[h][w]=BigInteger.ZERO;
				}
			}
			BigInteger max=BigInteger.ZERO;
			for(int h=0;h<H;h++)for(int w=0;w<W;w++){
				if(dp[h][w].compareTo(max)>0)max=dp[h][w];
			}
			ln(max);
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}

	public int[] nextIntArray(int n){
		int[] res=new int[n];
		for(int i=0;i<n;i++){
			res[i]=sc.nextInt();
		}
		return res;
	}
	public static void pr(Object o) {
		out.print(o);
	}
	public static void ln(Object o) {
		out.println(o);
	}
	public static void ln() {
		out.println();
	}
}

Measured memory_bytes: 50692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()

int main() {
    int K, X;
    cin >> K >> X;
    for (int i = X - K + 1; i < X + K; i++) {
        cout << i;
        if (i == X + K - 1) cout << endl;
        else cout << " ";
    }
}

Measured memory_bytes: 256
N = int(input())
W = list(map(int, input().split()))
min = sum(W)
for i in range(1, N):
  S1 = sum(W[:i])
  S2 = sum(W[i:])
  if min > abs(S1-S2):
    min = abs(S1-S2)
print(min)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<numeric>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
//#define MOD 1000000007
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int Dh[] = {0,0,1,-1};
int Dw[] = {1,-1,0,0};

int main(){
    int h,w; cin >> h >> w;
    int ch,cw; cin >> ch >> cw;
    int dh,dw; cin >> dh >> dw;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    deque<Pi> dq;
    vector<vector<int>> dist(h,vector<int>(w,INF));
    ch--; cw--; dh--; dw--;
    dist[ch][cw] = 0;
    dq.push_back({ch,cw});
    while(!dq.empty()){
        auto u = dq.front();
        int u1 = u.first;
        int u2 = u.second;
        dq.pop_front();
        rep(i,4){
            int nh = u1+Dh[i];
            int nw = u2+Dw[i];
            if(nh >= 0 && nh < h && nw >= 0 && nw < w){
                if(s[nh][nw] == '#') continue;
                if(dist[nh][nw] > dist[u1][u2]){
                    dq.push_front({nh,nw});
                    dist[nh][nw] = dist[u1][u2];
                }
            }
        }
        for(int i = -2; i <= 2; i++){
            for(int j = -2; j <= 2; j++){
                int nh = u1+i;
                int nw = u2+j;
                if(nh >= 0 && nh < h && nw >= 0 && nw < w){
                    if(s[nh][nw] == '#') continue;
                    if(dist[nh][nw] > dist[u1][u2]+1){
                        dq.push_back({nh,nw});
                        dist[nh][nw] = dist[u1][u2]+1;
                    }
                }
            }
        }
    }   
    cout << (dist[dh][dw] == INF?-1:dist[dh][dw]) << endl;
}



Measured memory_bytes: 9548
#include "bits/stdc++.h"
using namespace std;

int main() {
  int n; cin >> n;
  string s; cin >> s;
  string ans = "";
  for (char c : s) {
    ans += (char)((c - 'A' + n) % 26 + 'A');
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
s = input()
l = "abcdefghijklmnopqrstuvwxyz"
flag = [False for i in range(26)]
for i in s:
    flag[l.index(i)] = True
if False in flag:
    print(s + l[flag.index(False)])
else:
    w = []
    for i in range(26):
        temp = s[-i - 1]
        w.append(temp)
        w.sort()
        if w[-1] == temp:
            continue
        else:
            print(s[:-i-1] + w[w.index(temp) + 1])
            break
    else:
        print(-1)

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

#define int long long
#define uint unsigned long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end());
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct Setup {
    static constexpr int PREC = 20;
    Setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int C;
signed main() {
    cin >> C;
    reps(i, 9) {
        reps(j, 9) {
            if (i * j == C) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef vector<vector<int> > mat;
int n,l,pos=0;
string s;
mat init(){
  mat res;
  res.resize(n,vector<int>(n));
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      res[i][j]=i*n+j;
  return res;
}

mat expr();
mat repet();

mat expr(){
  mat res=init();
  while(pos<l){
    //cout<<pos<<endl;
    if(isupper(s[pos])){
      char c=s[pos++];
      int m=0;
      while(isdigit(s[pos]))
	m=m*10+s[pos++]-'0';
      //cout<<c<<" "<<m<<endl;
      m--;
      if(c=='R'){
	int tmp=res[m][n-1];
	for(int j=n-1;j>0;j--) res[m][j]=res[m][j-1];
	res[m][0]=tmp;
      }
      if(c=='L'){
	int tmp=res[m][0];
	for(int j=0;j<n-1;j++) res[m][j]=res[m][j+1];
	res[m][n-1]=tmp;
      }
      if(c=='D'){
	int tmp=res[n-1][m];
	for(int j=n-1;j>0;j--) res[j][m]=res[j-1][m];
	res[0][m]=tmp;
      }
      if(c=='U'){
	int tmp=res[0][m];
	for(int j=0;j<n-1;j++) res[j][m]=res[j+1][m];
	res[n-1][m]=tmp;
      }
    }else if(s[pos]=='(') {
      mat tmp=repet();
      mat buf=res;
       for(int i=0;i<n;i++)
	 for(int j=0;j<n;j++)
	   res[i][j]=buf[tmp[i][j]/n][tmp[i][j]%n];
    }else break;
  }
  return res;
}

mat repet(){
  mat res=init();
  assert(s[pos]=='(');
  pos++;
  mat tmp[100];
  tmp[0]=expr();
  assert(s[pos]==')');
  pos++;
  int m=0;
  while(pos<l&&isdigit(s[pos]))
    m=m*10+s[pos++]-'0';

  /*
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      cout<<tmp[0][i][j]<<" \n"[j==n-1];
  */
  
  for(int k=0;(m>>k);k++){
    if((m>>k)&1){
      for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)
	  res[i][j]=tmp[k][res[i][j]/n][res[i][j]%n];
    }
    tmp[k+1]=init();
    
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
	tmp[k+1][i][j]=tmp[k][tmp[k][i][j]/n][tmp[k][i][j]%n];

    /*
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
	cout<<tmp[k+1][i][j]<<" \n"[j==n-1];
    */
  }
  
  return res;
}
signed main(){
  cin>>n>>l>>s;
  mat ans=expr();
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      cout<<ans[i][j]+1<<" \n"[j==n-1];
  return 0;
}

Measured memory_bytes: 58924