akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<math.h>

#define A 100

int main(){
    int a,b,i,j,k,l;
    int x[A],m[A][A];
    
    scanf("%d",&a);
    
    for(i = 1;i <= a;i++){
        scanf("%d%d",&x[i - 1],&x[i]);
    }
    
    for(i = 1;i <= a;i++){
        m[i][i] = 0;
    }
    
    for(i = 2;i <= a;i++){
        for(j = 1;j <= a - i + 1;j++){
            l = i + j - 1;
            m[j][l] = INFINITY;
            
            for(k = j;k <= l - 1;k++){
                b = m[j][k] + m[k + 1][l] + x[j - 1]*x[k]*x[l];
                if(m[j][l] > b) m[j][l] = b;
            }
        }
    }
    
    printf("%d\n",m[1][a]);
    return 0;
}



Measured memory_bytes: 2108
#include <iostream>
using namespace std;
int main() {
    string s;int n;
    int a=0;
    int b=0;
    int c=0;
    int d=0;
    cin>>n;
    while(n--){
        cin>>s;
        if(s=="AC"){
            a++;
        }
        else if(s=="WA"){
            b++;
        }
        else if(s=="TLE"){
            c++;
        }
        else{
            d++;
        }
    }
    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<b<<endl;
    cout<<"TLE x "<<c<<endl;
    cout<<"RE x "<<d<<endl;
    return 0;

}


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

using namespace std;
using ll = long long;


int main()
{
    string s, t; cin >> s >> t;
    int n = s.size(), m = t.size();
    int q; cin >> q;

    vector<int> sa(n + 1), ta(m + 1);
    for(int i = 0; i < n; i++)sa[i + 1] = sa[i] + (s[i] == 'A');
    for(int i = 0; i < m; i++)ta[i + 1] = ta[i] + (t[i] == 'A');

    while(q--) {
        int ls, rs, lt, rt; cin >> ls >> rs >> lt >> rt;
        ls--, lt--;
        int nums = rs - ls;
        nums = sa[rs] - sa[ls] + (nums - (sa[rs] - sa[ls])) * 2;
        //nums個のaをなんとかする
        int numt = rt - lt;
        //cerr << nums << endl;
        nums += (numt - (ta[rt] - ta[lt]));
        //cerr << nums << endl;
        nums -= ta[rt] - ta[lt];
        //cerr << nums << endl;
        cout << (nums % 3 ? "NO" : "YES") << endl;
    }
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16000000")
using namespace std;

const int Maxn = 100005;

int n;
int a[Maxn], ax;
int b[Maxn], bx;
vector <int> un1, un2;
vector <int> neigh[Maxn];
bool tk[Maxn];
int res;

void Read(int a[], int &x, vector <int> &un)
{
    x = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        x ^= a[i];
        un.push_back(a[i]);
    }
    un.push_back(x);
    sort(un.begin(), un.end());
}

void Traverse(int v)
{
    if (tk[v]) return;
    tk[v] = true;
    for (int i = 0; i < neigh[v].size(); i++)
        Traverse(neigh[v][i]);
}

int main()
{
    scanf("%d", &n);
    Read(a, ax, un1);
    Read(b, bx, un2);
    if (un1 != un2) { printf("-1\n"); return 0; }
    for (int i = 0; i < n; i++) {
        a[i] = lower_bound(un1.begin(), un1.end(), a[i]) - un1.begin();
        b[i] = lower_bound(un1.begin(), un1.end(), b[i]) - un1.begin();
        res += a[i] != b[i];
        if (a[i] != b[i]) neigh[b[i]].push_back(a[i]);
    }
    ax = lower_bound(un1.begin(), un1.end(), ax) - un1.begin();
    bx = lower_bound(un1.begin(), un1.end(), bx) - un1.begin();
    Traverse(ax);
    for (int i = 0; i < n; i++)
        if (a[i] != b[i] && !tk[a[i]]) {
            res++;
            Traverse(a[i]);
        }
    printf("%d\n", res);
    return 0;
}


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

using namespace std;

int main(){
	int num,stone;
	while(1){
		cin >> num >> stone;
		if(num==0&&stone==0){ break; }
		vector<int> vec(num, 0);
		int flag, who;
		while(1){
			for(int i=0;i<vec.size();i++){
				flag = 0;
				if(stone>1){
					vec[i]++;
					stone--;
				}else if(stone==1){
					for(int j=0;j<vec.size();j++){
						if(vec[j]!=0 && i!=j){
							flag = 1;
							break;
						}
					}
					vec[i]++;
					stone--;
					if(flag==0){
						who = i;
						flag = 2;
					}	
				}else{
					stone += vec[i];
					vec[i] = 0;
				}
				if(flag==2){ break;	}
			}
			if(flag==2){ break;	}
		}
		cout << who << endl;
	}	
	return 0;
}

Measured memory_bytes: 908
#include<stdio.h>
#include<string.h>
int main()
{
    char s[11], t[11];
    int i, len1, len2;

    gets(s);
    gets(t);

    len1=strlen(s);
    len2=strlen(t);

    for(i=0; i<len1; i++){
        if(s[i]!=t[i]){
            printf("No\n");
            return 0;
        }
    }
    if(t[len2-1]>=97 && t[len2-1]<=122 && len2==(len1+1)) printf("Yes\n");
    else printf("No\n");

    return 0;
}


Measured memory_bytes: 1484
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod 			1000000007
#define tc(t) 			int t;cin >> t;while(t--)
#define for0(i , n)		for(int i=0;i<n;i++)
#define loop(i , a, b)	for(int i=a;i<=b;i++)
#define endl 			'\n'
#define inf 			1e18
#define fi 				first
#define se 				second

int XX[8] = { +1, +1, +1, 0, 0, -1, -1, -1};
int YY[8] = { +1, 0, -1, +1, -1, +1, 0, -1};
int dx[4] = { -1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};


int dp[100001][101][2];
string k;
int D;

int solve(int pos, int d, bool tight) {

	if (dp[pos][d][tight] != -1) return dp[pos][d][tight];
	int ub = (tight) ? (k[pos] - '0') : 9;
	if (pos == k.length() - 1) {
		int ans = 0;
		for (int x = 0; x <= ub; x++) {
			if (x % D == d) ans++;
		}

		return ans;
	}

	int ans = 0;
	for (int x = 0; x <= ub; x++) {
		ans = (ans + solve(pos + 1, (D + d - x % D) % D, tight && (x == ub))) % mod;
	}

	return dp[pos][d][tight] = ans;
}

signed main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

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

	cin >> k;
	cin >> D;

	memset(dp, -1, sizeof(dp));

	cout << (mod + solve(0, 0, 1) - 1) % mod;

	return 0;
}

Measured memory_bytes: 162236
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
#define repr(i ,n) for(int i=n;i>(int)(n);--i)
#define rep1(i ,n) for(int i=1;i<=(int)(n);++i)
#define ALL(a) a.begin(), a.end()
#define RSORT(a) sort(ALL(a),greater<>())
#define SORT(a) sort(ALL(a))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define PRINT(x) cout << (x) << endl;
#define ENDL cout << endl;
using namespace std;
typedef long long int i64;
typedef unsigned long long u64;
template<class T> using V = vector<T>;
using VI = V<int>;
const int INF = 2e9;
const i64 MOD = 1e9 + 7;
const double PI = acos(-1);

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;}
struct Init_On{
    Init_On(){
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(16);
    }
};

signed main(){
    Init_On start;
    double a , b , h , m;
    cin >> a >> b >> h >> m;
    double ans;
    double degree = fabs((m/60)*360-(h/12*360+m/60*30));
    double radian = degree*PI/180;
    ans = sqrt(a * a + b * b - 2 * a * b * cos(radian));
    cout << ans << endl;
}

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

using namespace std;

int main() {
  int total = 0, max_sub = 0;

    for ( int i = 0; i < 5; i++ ) {
      int a;
      cin >> a;
      if( a % 10 == 0 ) {
          total += a;
      } else {
          for ( int j = 1; j < 10; j++ ) {
              if ( ( a + j ) % 10 == 0 ) {
                  total += ( a + j );
                  max_sub = max( max_sub, j );
              }
          }
      }
    }
    cout << total - max_sub << endl;
  return 0;
}

Measured memory_bytes: 256
# D - Not Divisible
def main():
    N, *A = map(int, open(0).read().split())
    lim = max(A) + 1
    sieve = [0] * lim
    for a in A:
        sieve[a] += 1
        if sieve[a] > 1:
            continue
        for i in range(a * 2, lim, a):
            sieve[i] = 2
    print(sum(sieve[a] == 1 for a in A))


if __name__ == "__main__":
    main()


Measured memory_bytes: 33144
A = []

for i in range(3):
    A.append(list(map(int, input().split())))
N = int(input())
b = []
for i in range(N):
    b.append(int(input()))

for i in range(3):
    if A[i][0] in b and A[i][1] in b and A[i][2] in b:
        print('Yes')
        exit()
for i in range(3):
    if A[0][i] in b and A[1][i] in b and A[2][i] in b:
        print('Yes')
        exit()
if A[0][0] in b and A[1][1] in b and A[2][2] in b:
    print('Yes')
    exit()
if A[2][0] in b and A[1][1] in b and A[0][2] in b:
    print('Yes')
    exit()



print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <cstring>
#include <algorithm>
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(typeof(a) i=a;i!=(b);++i)
using namespace std;

int main(){
    int N;
    cin >> N;
    int m = 0, sum = 0;
    while((sum += ++m) < N){}
    int r = sum - N;
    FOR(i,1,m+1){
        if(i != r){
            cout << i << endl;
        }
    }
}

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

int main()
{
  int a, b;
  cin >> a >> b;
  
  int sa = a;
  int sb = b;
  
  for (int i = 1; i < b; i ++)
    sa = sa * 10 + a;
  
  for (int i = 1; i < a; i ++)
    sb = sb * 10 + b;
    
  if (a > b) cout << sb << endl;
  else cout << sa << endl;
  
  return 0;
}


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

int main() {
  int A, B, sum;
  cin >> A >> B;
  sum = 0;
  
  for (int i=A; i<=B; i++){
    
    int a, b, c, d, e;
    a = i/10000;
    b = (i%10000)/1000;
    c = (i%1000)/100;
    d = (i%100)/10;
    e = (i%10);
    
     if (a==e && b==d){
       sum ++;
     }
    
  }
  
    cout << sum << endl;
  }


    

    



Measured memory_bytes: 256
H,W=map(int,input().split())
A=[input() for _ in range(H)]

Flag=True
x,y=0,0
for _ in range(H+W-2):
    if x+1 < H and A[x+1][y] == '#':
        x += 1
        continue
    if y+1 < W and A[x][y+1] == '#':
        y += 1
        continue
    Flag=False
    
Flag= Flag and (sum(x.count("#") for x in A)==H+W-1)
if Flag:
    print("Possible")
else:
    print("Impossible")
    

        


Measured memory_bytes: 3064
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using IP = pair<int, P>;
using LLP = pair<ll, LP>;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;

// template specialization of std::hash for std::pair
namespace std {
template<typename T, typename U>
struct hash<pair<T, U> > {
    size_t operator()(const pair<T, U> &key) const noexcept {
        size_t h1 = hash<T>()(key.first);
        size_t h2 = hash<U>()(key.second);
        return h1 ^ (h2 << 1);
    }
};
} // namespace std

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    size_t sz = v.size();
    os << "[";
    for (size_t i = 0; i < sz-1; i++) {
        os << v[i] << ", ";
    }
    os << v[sz-1] <<  "]";
    return os;
}

template<typename T>
void printArray(T *arr, size_t sz) {
    cerr << "[";
    for (size_t i = 0; i < sz-1; i++) {
        cerr << arr[i] << ",";
    }
    cerr << arr[sz-1] <<  "]" << endl;
}

static inline ll mod(ll x, ll m)
{
    ll y = x % m;
    return (y >= 0 ? y : y+m);
}

struct Compare {
    //vector<ll> &x_, &y_;
    //Compare(vector<ll> &x, vector<ll> &y): x_(x), y_(y) {}
    //bool operator()(const P &lhs, const P &rhs) {
    //    return x_[lhs.fi]+y_[lhs.se] < x_[rhs.fi]+y_[rhs.se];
    //}
    bool operator()(const int x, const int y) {
        return x < y;
    }
};

// print floating-point number
// cout << fixed << setprecision(12) <<

// }}}

string s;
int K;
ll dp[110][2][10];

void solve()
{
    auto sz = s.size();
    dp[0][0][0] = 1;
    REP (i, sz) {
        int d = s[i] - '0';
        REP (j, 4) {
            FOR (k, 0, 10) {
                dp[i+1][1][j+(k != 0 ? 1 : 0)] += dp[i][1][j];
                if (k <= d) dp[i+1][(d > k ? 1 : 0)][j+(k != 0 ? 1 : 0)] += dp[i][0][j];
            }
        }
    }
    cout << dp[sz][0][K] + dp[sz][1][K] << endl;
}

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

// vim:set foldmethod=marker:


Measured memory_bytes: 256
A,B,C,D = map(int, input().split())

if A % D == 0:
	TK = A // D
else:
	TK = A // D + 1

if C % B == 0:
	AO = C // B
else:
	AO = C // B + 1

if AO <= TK:
	print("Yes")
else:
	print("No")


Measured memory_bytes: 9172
#include <stdio.h>
int main(){
  int n,i,count=0;
  int a[100000],arrive[100000]={0};

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  
  i=0;
  while(i!=1){
    count++;
	arrive[i]++;
    i=a[i]-1;
    if(arrive[i]>0){
      printf("-1");
      return 0;
    }
  }
  printf("%d",count);
}

Measured memory_bytes: 896
import math

n = int(input())

pos = []
for i in range(n):
    pos.append(list(map(int, input().split(' '))))

total = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        total += math.sqrt((pos[i][0] - pos[j][0]) ** 2 + (pos[i][1] - pos[j][1]) ** 2)

nroot = (n - 1) * n / 2 / (n - 1)
print(total / nroot)

Measured memory_bytes: 3064
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(char &c){
  int i;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = my_getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
int N;
char S[1100];
int main(){
  N = rd(S);
  if(S[N-1]=='s'){
    S[N++] = 'e';
  }
  S[N++] = 's';
  S[N] = '\0';
  wt_L(S);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200916-1

// --- original code ---
// int N;
// char S[1100];
// {
//   rd(S@N);
//   if(S[N-1]=='s') S[N++] = 'e';
//   S[N++] = 's';
//   S[N] = '\0';
//   wt(S);
// }


Measured memory_bytes: 3536
#include<bits/stdc++.h>
#define int long long
#define dd second
#define mp make_pair
#define pb push_back
#define ff first
#define dd second
#define pp pair<int,int>
using namespace std;
int n;
int tab[51];
int val = 0;
int best = 0;
int ind = 0;
main()
{
    ios_base::sync_with_stdio(false);
    cin >> n;
    for(int i = 0 ; i < n; ++i)
    {
        cin >> tab[i];
        if(abs(tab[i]) >= best)
        {
            best = abs(tab[i]);
            val = tab[i];
            ind = i;
        }
    }

    vector<pp> ans;

    for(int i = 0; i < n; ++i)
    {
        tab[i] += val;
        ans.pb(mp(ind, i));
    }

    for(int i = 0; i < n; ++i)
    {
        if(abs(tab[i]) >= best)
        {
            best = abs(tab[i]);
            val = tab[i];
            ind = i;
        }
    }

    if(val >= 0)
    {
        for(int i = 1; i < n; ++i)
        {
            //if(tab[i] < tab[i-1])
            //{
                ans.pb(mp(ind,i));
                //tab[i] += val;
                //val = tab[i];
                ind = i;
            //}
        }
    }
    else
    {
        for(int i = n-1; i >= 0; --i)
        {
            //if(tab[i] > tab[i+1])
            //{
                ans.pb(mp(ind,i));
            //    tab[i] += val;
             //   val = tab[i];
                ind = i;
            //}
        }
    }
    cout << ans.size() << "\n";
    for(auto &i:ans)
    {
        cout << i.ff+1 << " " << i.dd+1 << endl;
    }
    //for(int  i = 0; i < n; ++i) cout << tab[i] << " ";
    //cout << endl;
}



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

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

//===

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

int main() {

	int N, M;
	cin >> N >> M;
	vector<Vi> to(N);
	for (int i = 0; i < M; ++i) {
		int u, v;
		scanf("%d %d", & u, &v);
		--u, --v;
		to[u].push_back(v);
	}
	int S, T;
	cin >> S >> T;
	--S; --T;

	int (*dist)[3] = new int[N][3];
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < 3; ++j) {
			dist[i][j] = INF;
		}
	}

	queue<Pii> q;
	q.emplace(S,0);
	dist[S][0] = 0;
	while (!q.empty()) {
		int v = q.front().first;
		int l = q.front().second;
		q.pop();
		for (const auto& u : to[v]) {
			int nl = (l + 1) % 3;
			if (dist[u][nl] != INF) continue;
			dist[u][nl] = dist[v][l] + 1;
			q.emplace(u, nl);
		}
	}

	int ans = dist[T][0];
	delete[] dist;

	if (ans == INF) ans = -1;
	else ans /= 3;
	cout << ans << endl;
}


Measured memory_bytes: 6912
#include<stdio.h>
int main (){
    int a,b;
    char x;
     
    while(1){
    scanf("%d %c %d",&a,&x,&b);
    if (x=='+'){
    printf("%d\n",a+b);
    }else if (x=='-'){
    printf("%d\n",a-b);
    }else if (x=='*'){
    printf("%d\n",a*b);
    }else if (x=='/'){
    printf("%d\n",a/b);
    }else if (x=='?'){
    break;
    }
    }
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL)


int main() {
	fastIO;
	int n, k;
	cin >> n >> k;
	vector<int> v(n);
	for (auto& i : v) {
		cin >> i;
	}
	int mx = 0;
	for (int i = -1; i < n; i++) {
		for (int j = i+1; j < n+1; j++) {
			int items = i+1 + n-j;
			if (items > k)
				continue;
			vector<int> taken;
			for (int l = 0; l <= i; l++) {
				taken.push_back(v[l]);
			}
			for (int r = n-1; r >= j; r--) {
				taken.push_back(v[r]);
			}
			sort(taken.begin(), taken.end());
			for (int l = 0; l < min(k-items, (int)taken.size()); l++) {
				if (taken[l] < 0)
					taken[l] = 0;
			}
			int sum = 0;
			for (auto item : taken) {
				sum += item;
			}
			mx = max(mx, sum);
		}
	}
	cout << mx;

}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL;
  typedef pair<ll,char> PLC;
  typedef pair<char,ll> PCL;

int main(void){
  int a,b,c,d;cin >> a >> b >> c >> d;
  if(abs(a-c) <= d || ( abs(a-b) <= d && abs(b-c) <= d) ) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

int main()
{
    int n,i,d;
    int a[105];
    scanf(" %d",&n);

    for(i=0;i<n;i++){
        scanf(" %d",&a[i]);
    }
    sort(a,a+n);
    printf("%d\n",a[n-1]-a[0]);
    return 0;
}


Measured memory_bytes: 256
import sys,heapq,math,resource
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def setrlim():
  sys.setrecursionlimit(250000)
  soft,hard = resource.getrlimit(RLIMIT_STACK)
  # setrlimit works on ubuntu (and atcoder), but not on WSL
  #resource.setrlimit(RLIMIT_STACK, (128*1024*1024,hard))

a = inn()
s = input()
if a>=3200:
    print(s)
else:
    print('red')


Measured memory_bytes: 3444
#include <iostream>

int main(){
	std::string str;
  std::cin >> str;
  bool lstR = false;
  int ret = 0;
  int cur = 0;
  for (auto it : str) {
  	if (it == 'R') {
    	cur ++;
      lstR = true;
    }else if (it == 'S'){
    	if (lstR) {
        	cur = 0;
        }
      lstR = false;
    }
    ret = ret > cur ? ret : cur;
  }
  std::cout << ret << std::endl;
}

Measured memory_bytes: 3608
//#pragma GCC optimize("Ofast")
	//#pragma GCC target("avx,avx2,fma")
	//#pragma GCC optimization ("unroll-loops")
	
    #include<bits/stdc++.h>
    using namespace std;
	
    #define ll long long
    #define ull unsigned long long
    #define ld long double
    #define ff first
    #define ss second
    #define null NULL
    #define MAX 1000000000  // 1x10^9
    #define all(c) (c).begin(),(c).end()
    #define eb emplace_back
    #define pb push_back
    #define pf push_front
    #define lb lower_bound   //used for sortted 
    #define ub upper_bound 
    #define m_p make_pair      
    #define mod 1000000007
    #define For(i,n) for(int i=(0);i<(n);++i)
    #define FOR(i,a,b) for(int i=(a);i<=(b);++i)
	#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
    #define in(s3) inserter((s3), (s3).begin())  //	set_union(all(s1),all(s2),in(s3));
    typedef vector<ll> vl;
    typedef vector< vl > vvl;
    typedef pair< ll,ll> pll;
    typedef map< ll,ll> mll;
    
    //  A-65 Z-90 a-97 z-122   A-a = 32   Z-A = z-a = 35
    //	v.push_back(make_pair(min(2 * k[i], l[i]) - min(k[i], l[i]), i));      //int pos = v[i].second;
    //	floor(log10(no) + 1);                   //	to_string(no).length();             ----- length of a number
	//  llabs - long long of abs
	//  labs -long of abs
	//  sqrtf - sq root of float
	//  sqrtl - sq of long double    ( cout << fixed << setprecision(12) << sqrtl(val2) << endl; )
	//  it = find (all(vec), e);     if(it != vec.end());       it - vec.begin();
   	//	size_t found = str.find(str1);    if(found != string::npos); 	 cout<<found;
    	 
	/*	
		1. ^ is XOR and is used to to check odd occurance of number as a number XORed with itself results in zero so all even	occurrances result in zero.
		2.   & is used to check even or odd. (x & 1) ? printf("Odd") : printf("Even"); 
		3.   left shift(<<) - *         right shift(>>) - /
		4.   int a[] = { 1, 7, 2, 4, 8, 3 }; 
    		 int l = sizeof(a) / sizeof(a[0]); 
    		 sort(a, a + l);  reverse(a, a + l); accumulate(a, a + l, 0); *max_element(a, a + l);
	*/
	
	string to_string(char& x) {      
		string s(1,x);
		return s;    
	} 
	struct obj {
		ull val1;
		ull val2;
		ull pos;
	};
	bool cmp(const pair<int,int>&a,const pair<int,int>&b) {
		if(a.first==b.first)
		return a.second<b.second;
		return a.first<b.first;
	}

	int main() {
		ull sum=0,n,no,sum1=0,total=0;
		vector<ull> v;
		cin>>n;
		while(n--)
		{
			cin>>no;
			v.pb(no);
		}
		
		for(ull i=0;i<v.size();i++)
		{
			sum=(sum+v[i])%mod;
		}
		
		for(ull i=0;i<v.size();i++)
		{
			sum1=(sum1+v[i])%mod;
			total=(total+((v[i]*(sum-sum1+mod)%mod)%mod))%mod; //wrong due to this line as sum can be less than sum1 so sum-sum1 is not appropriate.
			
		}
		cout<<total;
		return 0;
	}
/*
		ll n;
		cin>>n;
	   ll a;
	   ll sum=0,ans=0;
	   for(ll i=0;i<n;i++){
		cin>>a;

		ans=(ans+((sum*a)%mod))%mod;
	   
		sum=(sum+a)%mod;
	   }
	   cout<<ans<<endl;
	   return 0;
*/


Measured memory_bytes: 5344
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

ll modiro(ll x,ll y){
    vector<ll> vec(30);
    rep(i,30){
        vec[i] = y;
        y = y * y % 998244353;
    }
    ll c = x;
    c = c * vec[0] % 998244353;
    c = c * vec[1] % 998244353;
    c = c * vec[2] % 998244353;
    c = c * vec[3] % 998244353;
    c = c * vec[4] % 998244353;
    c = c * vec[5] % 998244353;
    c = c * vec[6] % 998244353;
    c = c * vec[7] % 998244353;
    c = c * vec[8] % 998244353;
    c = c * vec[9] % 998244353;
    c = c * vec[10] % 998244353;
    c = c * vec[11] % 998244353;
    c = c * vec[12] % 998244353;
    c = c * vec[13] % 998244353;
    c = c * vec[14] % 998244353;
    c = c * vec[15] % 998244353;
    c = c * vec[16] % 998244353;
    c = c * vec[17] % 998244353;
    c = c * vec[18] % 998244353;
    c = c * vec[19] % 998244353;
    c = c * vec[20] % 998244353;
    c = c * vec[21] % 998244353;
    c = c * vec[22] % 998244353;
    c = c * vec[24] % 998244353;
    c = c * vec[25] % 998244353;
    c = c * vec[27] % 998244353;
    c = c * vec[28] % 998244353;
    c = c * vec[29] % 998244353;
    return c;
}


int main(){
    ll N,M,K;
    cin >> N >> M >> K;
    ll ans_sub = 1;
    ll nki = 1;
    rep(i,N - K - 1){
        ans_sub = (ans_sub * (M - 1)) % 998244353;
        nki = (nki * (i + 1)) % 998244353;
    }
    ll n_1 = 1;
    rep(i, N - 1){
        n_1 = (n_1 * (i + 1)) % 998244353;
    }
    ll ans = 0;
    vector<ll> vec(K + 1);
    vec[0] = 1;
    rep(i,K){
        vec[i + 1] = (vec[i] * (i + 1)) % 998244353;
    }
    rep(i, K + 1){
        ll ans_sub_sub = 1;
        ans_sub_sub = (ans_sub_sub * M) % 998244353;
        ans_sub_sub = (ans_sub_sub * ans_sub) % 998244353;
        ans_sub_sub = ans_sub_sub * (modiro(n_1, (vec[K - i] * nki) % 998244353)) % 998244353;
        ans = (ans_sub_sub + ans) % 998244353;
        ans_sub = (ans_sub * (M - 1)) % 998244353;
        nki = (nki * (N - K + i)) % 998244353;
    }
    cout << ans << endl;
}


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

const int MX = 100005;

vector<P> g[MX];
int x[MX];
bool used[MX];

vector<int> ans;
int dfs(int v) {
  used[v] = true;
  int res = x[v];
  for (P e : g[v]) {
    if (used[e.first]) continue;
    int r = dfs(e.first);
    if (r) ans.push_back(e.second);
    res ^= r;
  }
  return res;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<P> a(n);
  rep(i,n) cin >> a[i].first >> a[i].second;
  sort(a.begin(), a.end());
  x[0] = a[0].second;
  rep(i,n-1) x[i+1] = a[i].second^a[i+1].second;
  x[n] = a[n-1].second;

  rep(i,m) {
    int lv, rv,l,r;
    cin >> lv >> rv;
    l = lower_bound(a.begin(),a.end(),P(lv,0))-a.begin();
    r = upper_bound(a.begin(),a.end(),P(rv,1))-a.begin();
    g[l].emplace_back(r,i+1);
    g[r].emplace_back(l,i+1);
  }

  rep(i,n+1) {
    if (used[i]) continue;
    if (dfs(i)) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << ans.size() << endl;
  sort(ans.begin(), ans.end());
  rep(i,ans.size()) printf("%d ", ans[i]);
  cout << endl;
  return 0;
}


Measured memory_bytes: 15228
#include <cstdio>
#include <iostream>
#include <queue>

using namespace std;

const double INFTY=1e10;

struct Edge{
	int src,dst,dist,limit;
	Edge(){}
	Edge(int s,int d,int di,int li):src(s),dst(d),dist(di),limit(li){}
};
typedef vector<vector<Edge> > Graph;

struct State{
	int src,dst,ver;
	double time;
	State(){}
	State(int s,int d,int v,double t):src(s),dst(d),ver(v),time(t){}
	bool operator<(const State& s)const{return time<s.time;}
	bool operator>(const State& s)const{return time>s.time;}
};

int main()
{
	for(int n,m;cin>>n>>m,n|m;){
		int start,goal; cin>>start>>goal;
		start--; goal--;
		Graph g(n);
		for(int i=0;i<m;i++){
			int s,d,di,li; cin>>s>>d>>di>>li;
			s--; d--;
			g[s].push_back(Edge(s,d,di,li));
			g[d].push_back(Edge(d,s,di,li));
		}
		
		double dist[30][30][31];
		for(int i=0;i<30;i++)
			for(int j=0;j<30;j++)
				for(int k=0;k<31;k++)
					dist[i][j][k]=INFTY;
		
		priority_queue<State,vector<State>,greater<State> > pq;
		pq.push(State(start,start,0,0));
		while(pq.size()){
			State cur=pq.top(); pq.pop();
			if(dist[cur.src][cur.dst][cur.ver]!=INFTY)
				continue;
			dist[cur.src][cur.dst][cur.ver]=cur.time;
			for(int i=0;i<g[cur.dst].size();i++){
				Edge e=g[cur.dst][i];
				if(e.dst==cur.src)
					continue;
				for(int j=-1;j<=1;j++){
					int nv=cur.ver+j;
					if(nv<=0 || e.limit<nv || dist[e.src][e.dst][nv]!=INFTY)
						continue;
					pq.push(State(e.src,e.dst,nv,cur.time+(double)e.dist/nv));
				}
			}
		}
		
		double res=INFTY;
		for(int i=0;i<n;i++)
			res=min(res,dist[i][goal][1]);
		if(res==INFTY)
			puts("unreachable");
		else
			printf("%f\n",res);
	}
	return 0;
}

Measured memory_bytes: 11000
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	    StringBuilder result = new StringBuilder();
	    while (true) {
		    String line = br.readLine();

		    if ("-".equals(line)) break;

		    int shuffleCount = Integer.parseInt(br.readLine());

		    for (int i = 0; i < shuffleCount; i++) {
		    	int h = Integer.parseInt(br.readLine());
		    	// shuffle
		    	line = line.substring(h, line.length()) + line.substring(0, h);

		    }
		    result.append(line).append("\n");
	    }
	    System.out.print(result.toString());
	}
}

Measured memory_bytes: 24216
import math


def validate(src_point, tgt_point, duration):
    s_x, s_y = src_point
    t_x, t_y = tgt_point

    if not 0 <= s_x <= 1e5: return False
    if not 0 <= s_y <= 1e5: return False
    if not 0 <= t_x <= 1e5: return False
    if not 0 <= t_y <= 1e5: return False

    dist = math.fabs(t_x - s_x) + math.fabs(t_y - s_y)

    if duration % 2 == 1:
        if dist <= duration and dist % 2 == 1:
            return True
        else:
            return False
    else:
        if dist <= duration and dist % 2 == 0:
            return True
        else:
            return False

N = int(input())
# src_point = (0, 0)
prev_point = (0, 0)
prev_time = 0

flag = True
for i in range(N):
    cur_time, *cur_point = list(map(int, input().split()))

    if not validate(prev_point, cur_point, cur_time - prev_time):
        flag = False
        break

    prev_time = cur_time
    prev_point = cur_point
if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  rep(i,n) a[i]--;
  vector<int> idx(n);
  rep(i,n) idx[a[i]] = i;
  set<int> s;
  ll ans = 0;
  for (int x = n-1; x >= 0; --x) {
    int i = idx[x];
    ll c = 0;
    { // calc c
      s.insert(i);
      vector<int> l(2,-1);
      vector<int> r(2,n);
      { // calc l
        auto it = s.find(i);
        rep(j,2) {
          if (it == s.begin()) break;
          --it;
          l[j] = *it;
        }
      }
      { // calc r
        auto it = s.find(i);
        rep(j,2) {
          ++it;
          if (it == s.end()) break;
          r[j] = *it;
        }
      }
      vector<int> ls(2);
      ls[0] = i-l[0]; ls[1] = l[0]-l[1];
      vector<int> rs(2);
      rs[0] = r[0]-i; rs[1] = r[1]-r[0];
      c = (ll)ls[0]*rs[1] + (ll)ls[1]*rs[0];
    }
    ans += c*(x+1);
  }
  cout << ans << endl;
  return 0;
}

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

#define mx 100005
#define ll long long
#define mod 1000000007

int ar[mx];
char ch[mx];


int main()
{
    long long int n,k,ans=0;
    cin>>n>>k;
    vector<long long int>a(200001);
    a[0]=1;
    for(long long int i=1;i<200002;i++){
    	a[i]=(a[i-1]+i);
    }
    for(long long int i=k;i<n+1;i++){
    	ans+=(a[i]-a[k-1]+1)%1000000007;
    }
    cout<<(ans+1)%1000000007<<endl;
    return 0;

    return 0;
}


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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

const ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int n; cin >> n;
	ld ans = ld(n/2+n%2)/n;
	cout << fixed << setprecision(10) <<  ans << '\n';
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 3788
#include<iostream>
#include<complex>
#define EPS 1e-10
using namespace std;

typedef complex<double>P;

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		double ra,rb;
		P pa,pb;
		
		cin>>pa.real()>>pa.imag()>>ra;
		cin>>pb.real()>>pb.imag()>>rb;
		double d=abs(pa-pb);
		if(d<rb-ra)cout<<-2<<endl;
		else if(d<ra-rb)cout<<2<<endl;
		else if(d<=ra+rb)cout<<1<<endl;
		else cout<<0<<endl;
	}
}

Measured memory_bytes: 1248
n,m = map(int,input().split())
A = [input() for i in range(n)]
B = [input() for i in range(m)]
 
flag = False
for i in range(n-m+1):
    for j in range(n-m+1):
        flag = True
        for k in range(m):
            if B[k] != A[i+k][j:j+m]:
                flag = False
        if flag:
            print("Yes")
            exit()
print("No")

Measured memory_bytes: 9020
#include <iostream>
#include <algorithm>
#include <functional>
#include <climits>
#include <string>
#include <cstring>
#include <cmath>
#include <cassert>

#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using ld = long double;
// using ht = gp_hash_table<int, int>;
// using ordered_set = tree<pii, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int) (x).size()
#define all(x) x.begin(), x.end()
#define lc (i << 1)
#define rc (i << 1 | 1)
// #define m ((l + r) >> 1)

const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = 1e9 + 7;
const double EPS = 1e-6;
const int MN = 1001, LN = 17;

ll N;

int main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    cin >> N;
    ll temp = N - 1;
    ll tot = 1;
    if (temp != 1) {
        for (int i = 2; i <= sqrt(temp); i++) {
            if (temp % i == 0) {
                int cnt = 0;
                while (temp % i == 0) cnt++, temp /= i;
                tot *= (cnt + 1);
            }
        }
        if (temp > 1) tot *= 2;
    }
    temp = N;
    for (int i = 2; i <= sqrt(temp); i++) {
        if (temp % i == 0) {
            ll other = N / i;
            while (other % i == 0) other /= i;
            if (other % i == 1) tot++;
        }
    }
    cout << tot << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include  <vector>
using namespace std;
#define INF 0x3f3f3f3f
const int N = 501;
int mod = 1e9 + 7;
typedef long long ll;

int D[31][31];
int main()  
{
  //  freopen("in.txt", "r", stdin); 
    int n, c;
    while (~scanf("%d%d", &n, &c))
    {
        int t[3][31] = {0};
        for (int i = 1; i <= c; i++)
            for (int j = 1; j <= c; j++)
                scanf("%d", D[i] + j);
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++)
            {
                int x;
                scanf("%d", &x);
                int r = (i+j)%3;
                t[r][x]++;
            }
        ll ans = 1LL<<50;
        for (int i = 1; i <= c; i++)
            for (int j = 1; j <= c; j++)
                for (int k = 1; k <= c; k++)
                    if (k != i && i != j && k != j)
                    {
                        ll tmp = 0;
                        int col[3] = {i, j, k};//printf("%d %d %d\n", i, j, k);
                        for (int it = 0; it < 3; it++)
                        {
                            for (int ci = 1; ci <= c; ci++)
                                if (t[it][ci] && ci != col[it])
                                {
                                
                                    tmp += t[it][ci]* D[ci][col[it]];
                                    // printf("%d * %d = %d\n", t[it][ci] * D[ci][col[it]], t[it][ci], D[ci][col[it]]);
                                }
                        }
                        ans = min(ans, tmp);
                    }
        cout<<ans<<endl;

    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    ll a[n],b[n+1],c[n+1];
    b[0]=c[0]=0;
    for(ll i=0;i<n;i++){
        cin>>a[i];
        b[i+1]=b[i]+a[i];
        c[i+1]=c[i]+max(0ll,a[i]);
    }
    ll ans=0;
    for(ll i=0;i<=n-k;i++){
        ans=max(ans,c[n]-c[i+k]+c[i]+max(0ll,b[i+k]-b[i]));
    }
    cout <<ans<<endl;
    return 0;
}




Measured memory_bytes: 2560
H, W = map(int, input().split())
sh, sw = map(int, input().split())
gh, gw = map(int, input().split())

sh += 1
sw += 1
gh += 1
gw += 1

S = [0]*(H+4)
S[0] = '*'*(W+4)
S[1] = '*'*(W+4)
S[-2] = '*'*(W+4)
S[-1] = '*'*(W+4)
for h in range(2,H+2):
  S[h] = '**' + input() + '**'

visited = [[float('inf')]*(W+4) for _ in range(H+4)]
dh1 = [0,1,0,-1]
dw1 = [1,0,-1,0]
dh2 = [2,2,2,2,2,1,1,1,1,0,0,-1,-1,-1,-1,-2,-2,-2,-2,-2]
dw2 = [-2,-1,0,1,2,-2,-1,1,2,-2,2,-2,-1,1,2,-2,-1,0,1,2]

from collections import deque
d = deque()

d.append((sh,sw,0))

while len(d)>0:
  h,w,cnt = d.popleft()
  if visited[h][w]<=cnt:
    continue
  visited[h][w] = cnt
  for i in range(4):
    h1 = h+dh1[i]
    w1 = w+dw1[i]
    if S[h1][w1]=='.':
      if visited[h1][w1]>cnt:
        d.appendleft((h1,w1,cnt))
  for i in range(20):
    h2 = h+dh2[i]
    w2 = w+dw2[i]
    if S[h2][w2]=='.':
      if visited[h2][w2]>cnt+1:
        d.append((h2,w2,cnt+1))
ans = visited[gh][gw] if visited[gh][gw]<float('inf') else -1
print(ans)

Measured memory_bytes: 183772
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

int INF = 1e09;
int dp[41][401][401];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, ma, mb;
  cin >> n >> ma >> mb;
  vector<int> a(n), b(n), c(n);
  REP(i, n) cin >> a[i] >> b[i] >> c[i];

  REP(i, n + 1){
    REP(j, 401){
      REP(k, 401) dp[i][j][k] = INF;
    }
  }
  dp[0][0][0] = 0;

  REP(i, n){
    REP(j, 401){
      REP(k, 401){
        dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
        if(j + a[i] <= 400 && k + b[i] <= 400){
          dp[i + 1][j + a[i]][k + b[i]] = min(dp[i][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
        }
      }
    }
  }

  int ans = INF;
  REP(j, 400){
    REP(k, 400){
      if((j + 1) * mb == (k + 1) * ma){
        ans = min(ans, dp[n][j + 1][k + 1]);
      }
    }
  }
  if(ans >= 10000) cout << -1 << endl;
  else cout << ans << endl;
}


Measured memory_bytes: 25984
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define INF 1000000
using namespace std;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
bool flag_table[40][40][4];
int table[40][40];
int ans,cnt,w,h;
typedef pair<int,int> P;
queue<P> que;
int bfs(){
    que.push(P(0,0));
    table[0][0] = 1;
    while(!que.empty()){
        P tmp = que.front();
        que.pop();
        if(tmp.first == h-1 && tmp.second == w-1) break;
        rep(i,4){
            int ny = tmp.first+dy[i];
            int nx = tmp.second+dx[i];
            if(ny < 0 || nx < 0 || ny >= h || nx >= w) continue;
            if(table[ny][nx] != -1 || flag_table[tmp.first][tmp.second][i] == true) continue;
            table[ny][nx] = table[tmp.first][tmp.second] + 1;
            que.push(P(ny,nx));
        }
    }
    return table[h-1][w-1];
}
int main(){
    while(cin >> w >> h){
        if(w == 0 && h == 0) break;
        memset(flag_table,false,sizeof(flag_table));
        memset(table,-1,sizeof(table));
        rep(i,h){
            rep(j,w-1){
                int n; cin >> n;
                if(n != 1) continue;
                flag_table[i][j][0] = true;
                flag_table[i][j+1][2] = true;
            }
            if(i == h-1) continue;
            rep(j,w){
                int n; cin >> n;
                if(n != 1) continue;
                flag_table[i][j][1] = true;
                flag_table[i+1][j][3] = true;
            }
        }
        if(bfs() == -1) cout << 0 << endl;
        else cout << bfs() << endl;
    }
}


Measured memory_bytes: 3068
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    int n;
    cin >> n;
    vector<int> a(n+1);
    rep(i, n) cin >> a[i];

    int height = 0;
    rep(i, n){
        if(a[i] < a[i+1] && a[i] + 1 != a[i+1]){
            cout << -1 << endl;
            return 0;
        }
        if(a[i] == 0){
            height = 1;
            continue;
        }
        if(height >= a[i]){
            height++;
            continue;
        }
        cout << -1 << endl;
        return 0;
    }

    int ans = 0;
    for(int i = n; i > 0; i--){
        if(a[i-1] >= a[i]){
            ans += a[i-1];
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2424
#include<bits/stdc++.h>
using namespace std;
int n,k;
int a[233],odd[3],top;
int main()
{
	ios_base::sync_with_stdio(false);
	cin>>n>>k;
	for(int i=1;i<=k;i++)
	{
		cin>>a[i];
		if(a[i]%2)
		{
			odd[++top]=i;
		}
	}
	if(top>2)return puts("Impossible"),0;
	else if(top==2)
	{
		swap(a[1],a[odd[1]]);
		swap(a[k],a[odd[2]]);
	}
	else if(top==1)
	{
		swap(a[1],a[odd[1]]);
	}
	for(int i=1;i<=k;i++)cout<<a[i]<<' ';cout<<endl;
	cout<<k-(a[1]==1)+(k==1)<<endl;
	if(a[1]!=1)cout<<a[1]-1<<' ';
	for(int i=2;i<k;i++)cout<<a[i]<<' ';
	if(k!=1)cout<<a[k]+1<<endl;
	else cout<<1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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 add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

void solve(){
    int X, Y;
    cin >> X >> Y;
    for(int i=0;i<=X;i++){
        int y = X - i;
        if(i * 2 + 4 * y == Y){
            cout << "Yes" << endl;
            return;
        }
    }
    cout << "No" << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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;
}


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll N; cin >> N;
  // ll N, K; cin >> N >> K;
  // ll x, y, z; cin >> x >> y >> z;
  // ll a, b, c; cin >> a >> b >> c;
  // string s; cin >> s;
  // vector<ll> a(N); rep(i, N) cin >> a[i];
  
  ll ans = 0;
  rep1(i, N) {
    ans += (N - 1) / i;
  }

  cout << ans << endl;
  // cout << (ok?"Yes":"No") << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 3676
import std.stdio, std.string, std.conv, std.algorithm, std.array;

enum VMAX = 15 + 1;
enum INF = 1 << 29;

int[VMAX][VMAX] table;
int[1<<VMAX][VMAX] dp;
int V, E;

int solve(int S, int v) {
    if ( dp[v][S] >= 0 ) {
        return dp[v][S];
    }

    if ( S == (1 << V) - 1 && v == 0 ) {
        return dp[v][S] = 0;
    }

    int tmp = INF;
    for( int u=0; u<V; ++u ) {
        if ( !( S >> u & 1 ) ) {
            // goto u from v
            tmp = min(tmp, solve(S | 1 << u, u) + table[u][v]);
        }
    }

    return dp[v][S] = tmp;
}

void main() {
    fill(table[0..$][0..$], INF);

    auto ss = readln.chomp.split(" ").map!(to!int).array;
    V = ss[0];
    E = ss[1];

    for( int i=0; i<E; ++i ) {
        auto sss = readln.chomp.split(" ").map!(to!int).array;
        immutable start = sss[0], end = sss[1], cost = sss[2];
        table[end][start] = cost;
    }


    fill(dp[0..$][0..$], -1);

    immutable ans = solve(0, 0);
    (ans == INF ? -1 : ans).writeln;
}

Measured memory_bytes: 5200