akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
 
public class Main {
 
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		boolean key = false;
		for (int i = 1; i < 10001; i++) {
			if ((A*i-C)%B == 0) {
				key = true;
			}
		}
		System.out.println(key ? "YES" : "NO");
	}
}

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

int main()
{
  string s, res = "";
  cin >> s;
  int prefix = stoi(s.substr(0, 2));
  int suffix = stoi(s.substr(2, 2));
  if(prefix == 0 && suffix == 0 ||
    prefix == 0 && suffix > 12 ||
    prefix > 12 && suffix == 0 ||
    prefix > 12 && suffix > 12)
  {
    res = "NA";
  }
  else if((prefix > 12 || prefix == 0) && suffix <= 12)
    res = "YYMM";
  else if(prefix <= 12 && (suffix > 12 || suffix == 0))
    res = "MMYY";
  else
    res = "AMBIGUOUS";
  
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3592
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner input = new Scanner(System.in);
		while(true){
			int num = input.nextInt();
			if(num == 0)break;
			int[] a = new int[num];
			for(int i = 0 ; i < num ; i++){
				a[i] = input.nextInt();
			}
			int max = Integer.MIN_VALUE;
			for(int i = 0 ; i < num ; i++){
				int tmp = 0;
				for(int j = i ; j < num ; j++){
					tmp += a[j];
					max = Math.max(max, tmp);
				}
			}
			System.out.println(max);
		}
		input.close();
	}
}

Measured memory_bytes: 26488
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace ConsoleApplication40
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> b = new List<int>();
            for (int a = 0; a < 10; a++)
            {
                int c = int.Parse(Console.ReadLine());
               b.Add(c);
            }
            b.Sort();
            Console.WriteLine(b[9]);
            Console.WriteLine(b[8]);
            Console.WriteLine(b[7]); 
        }
    }
}

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

using namespace std;
using ll = long long;
using ld = long double;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) ((x).begin()), ((x).end())

#define READ(x) (cin >> (x))
#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))
#define WRITE_YESNO(x) (WRITE_N((x) ? "Yes" : "No"))

#define PRECISE_COUT std::cout << std::setprecision(15) << std::fixed

bool xor_logic(bool x, bool y) { return (x && y) || (!x && !y); }

#define N_MAX 1000000
#define N_MAX_SQRT 1000

ll fact[N_MAX];

void init_fact() {
  std::vector<ll> prime_vec;

  fact[1 - 1] = 1;
  for (size_t i = 2; i <= N_MAX; i++) {
    bool is_prime = true;
    for (auto &&p : prime_vec) {
      if (i % p == 0) {
        fact[i - 1] = p;
        is_prime = false;
        break;
      }
      if (p * p > i) {
        break;
      }
    }

    if (is_prime) {
      fact[i - 1] = i;
      prime_vec.push_back(i);
    }
  }
}

map<ll, ll> factorize(ll n) {
  map<ll, ll> retv;
  while (n > 1) {
    ll f = fact[n - 1];
    retv[f]++;
    n /= f;
  }

  return retv;
}

ll count_divider(ll n) {
  map<ll, ll> factor_dict = factorize(n);
  ll retv = 1;
  for (auto &&p : factor_dict) {
    retv *= p.second + 1;
  }
  return retv;
}

ll solve(ll N) {
  init_fact();
  ll ans = 1;
  for (ll i = 2; i < N; i++) {
    ans += count_divider(i);
  }

  return ans;
}

int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;
  // main procedure
  ll ans = solve(N);

  // output
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 11724
#include<iostream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#define pow2(a) ((a)*(a))
#define inf (1<<29)
using namespace std;

const double r = 6378.1;

struct Point3
{
  double x,y,z;
  Point3(double x=inf,double y=inf,double z=inf):x(x),y(y),z(z){}
};

Point3 getPoint3(double a,double b)
{//see P.133
  return Point3(r*sin(a)*cos(b),r*sin(a)*sin(b),r*cos(a));
}

double getArg(double a,double b,double c)
{
  return acos((b*b+c*c-a*a)/(2.0*b*c));
}

int main()
{
 
  double a,b,c,d;
  while(true)
    {
      cin >> a >> b >> c >> d;
      if(a == -1 && b == -1 && c == -1 && d == -1)break;
      a = 90 - a;
      a = a*M_PI/180.0;
      b = b*M_PI/180.0;
      c = 90 - c;
      c = c*M_PI/180.0;
      d = d*M_PI/180.0;
      Point3 p1,p2;
      p1 = getPoint3(a,b);
      p2 = getPoint3(c,d);

      double dist = sqrt(pow2(p1.x-p2.x)+pow2(p1.y-p2.y)+pow2(p1.z-p2.z));
      double arg = getArg(dist,r,r);

      cout << (int)round(r * arg) << endl;

    }
  return 0;
}

Measured memory_bytes: 1276
d = int(input())
clst = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
t = [int(input()) for _ in range(d)]
last = [0 for _ in range(26)]

def score_minus(d):
    minus = 0
    for c, ls in zip(clst, last):
        minus += c * (d - ls)
    return minus
    
ans = 0
for d, num in enumerate(t, start = 1):
    ans += s[d - 1][num - 1]
    last[num - 1] = d
    ans -= score_minus(d)
    print(ans)

Measured memory_bytes: 9320
// Optimise
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

// #define MULTI_TEST
#ifdef LOCAL
#include "/home/shahraaz/bin/debug.h"
#else
#define db(...)
#define pc(...)
#endif

#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()
auto TimeStart = chrono::steady_clock::now();
auto seed = TimeStart.time_since_epoch().count();
std::mt19937 rng(seed);
using ll = long long;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using Random = std::uniform_int_distribution<T>;

const int NAX = 2e5 + 5, MOD = 1000000007;

class Solution
{
private:
public:
    Solution() {}
    ~Solution() {}
    void solveCase()
    {
        int n, m;
        cin >> n >> m;
        if (n == m)
            cout << "Yes\n";
        else
            cout << "No\n";
    }
};

int32_t main()
{
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    int t = 1;
#ifdef MULTI_TEST
    cin >> t;
#endif
    Solution mySolver;
    for (int i = 1; i <= t; ++i)
    {
        mySolver.solveCase();
#ifdef TIME
        cerr << "Case #" << i << ": Time " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " s.\n";
        TimeStart = chrono::steady_clock::now();
#endif
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    vector<vector<char>> c(2, vector<char>(3));
    rep(i, 2) rep(j, 3) cin >> c[i][j];
    bool ok = true;
    rep(i, 2) rep(j, 3) {
        if ( c[i][j] != c[1-i][2-j] ) {
            ok = false;
            break;
        }
    }
    if ( ok ) cout << "YES" << endl;
    else      cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//解説写し
long long f(vector<pair<int,int>>p){
  int n=p.size();
  for(int i=0;i<n;i++){
    p[i].first=min(p[i].first,n);
  }
  vector<vector<int>>s(n+1);
  for(int i=0;i<n;i++){
    s[p[i].first].push_back(p[i].second);
  }
  long long res=0;
  priority_queue<int>q;
  for(int i=n;i>=1;--i){
    for(int x:s[i])q.push(x);
    if(q.size()>0){
      res+=q.top();q.pop();
    }
  }
  return res;
}
void solve(){
  int n;
  cin>>n;
  vector<pair<int,int>>pl,pr;
  long long ans=0;
  for(int i=0;i<n;i++){
    int k,l,r;
    cin>>k>>l>>r;
    int m=min(l,r);
    ans+=m;
    l-=m;
    r-=m;
    if(l>0)pl.emplace_back(k,l);
    else pr.emplace_back(n-k,r);
  }
  ans+=f(pl);
  ans+=f(pr);
  cout<<ans<<endl;
}
int main(){
  int ts;
  cin>>ts;
  for(int ti=0;ti<ts;ti++){
    solve();
  }
  return 0;
}

Measured memory_bytes: 10548
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() {
  int n;
  cin >> n;
  vi v(n,0);
  rep(i,n-1) {
    int m;
    cin >> m;
    m--;
    v[m]++;
  }
  rep(i,n) cout << v[i] << endl;
  return 0;
}

Measured memory_bytes: 4052
import bisect

N, M = map(int, input().split())
P = [0 for _ in range(M)]
Y = [0 for _ in range(M)]
y_p = [[] for _ in range(1, N+1)]
for i in range(M):
    P[i], Y[i] = map(int, input().split())
    y_p[P[i]-1].append(Y[i])

for p in set(P):
    y_p[p-1].sort()

for p, y in zip(P, Y):
    order = bisect.bisect_left(y_p[p-1], y)
    ans = str(p).zfill(6) + str(order+1).zfill(6)
    print(ans)

Measured memory_bytes: 28792
#include <stdio.h>

main()
{
  int a[100];
  int n, i, j, k, minj, count=0;

  scanf("%d", &n);

  for(i=0; i<n; i++){
	scanf("%d", &a[i]);
  }
  
  for(i=0; i<n-1; i++){
	minj = i;
	for(j=i; j<=n-1; j++){
	  if(a[j]<a[minj]){
		minj = j;
	  }
	}
	if(minj != i){
	  k = a[i];
	  a[i] = a[minj];
	  a[minj] = k;
	  count++;
	}
  }
  
  for(i=0; i<n; i++){
	printf("%d", a[i]);
	if(i== n-1) printf("\n");
	else printf(" ");
  }
  printf("%d\n", count);

  return 0;
}

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

using namespace std;

int main(){
    int N;
    cin >> N;
    long long x;
    cin >> x;
    vector<long long> a(N);
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }

    long long ans = 0;
    long long v;
    for(int i = 1; i < N; i++){
        if(a[i-1] + a[i] > x){
            v = (a[i-1] + a[i]) - x;
            ans += v;
            if(a[i] >= v){
                a[i] -= v;
            }else{
                a[i-1] -= (v - a[i]);
                a[i] = 0;
            }
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<string,int> P;


int main(){
  bool flag=false;
  int N,ans=0,count=0;
  string s;
  cin>>N>>s;
  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++,count=0){
      //cout<<j<<endl;
      if(flag==false){
        if(s[i]==s[j]){
          while(j+count<N && i+count<j && s[i+count]==s[j+count]){
            count++;
          }
        }
      }else{
        if(i+ans>=j){
          j=i+ans; continue;
        }else{
          if(j+ans>=N) break;
          if(s.substr(i,ans)!=s.substr(j,ans)) continue;
          while(j+ans+count<N && i+count+ans<j && s[i+ans+count]==s[j+ans+count]){
            count++;
          }
        }
      }

      if(flag==false) ans=max(ans,count);
      else ans+=count;
      //j+=count;
      //cout<<i<<" "<<j<<endl;
      if(ans>0) flag=true;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int  main()
{
   int n,k;
   cin>>n>>k;
   long long num[n+1];
   num[0]=0;
   for(int i=1;i<=n;i++){
     num[i]=num[i-1]+i;
   }
   long long  ans=0;
   
   for(int i=k;i<=n;i++){
       long long  max= (num[n]-num[n-i]);

       long long  min=num[i-1];

       ans+= (max-min+1);
   }
   ans++;
   cout<<ans%(1000000000+7)<<endl;
   
  
}

Measured memory_bytes: 5092
#include<stdio.h>

int main(){

   int a=0, b=0;      // input, 1<=a, b<=100
   int equivalent=0;  // output_1
   int length=0;      // output_2

   scanf("%d %d", &a, &b);

   equivalent = a * b;
   length = (a + b) * 2;

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

Measured memory_bytes: 596
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
    const int MAX =200002;
const int MOD =1000000007;
   int modpow(int a, int n, int mod) {
    int res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
     signed main(){
 int n,ans1=0,ans2=0;
 cin>>n;
 int a;
 for(int i=0;i<n;i++){
     cin>>a;
     ans1=(ans1+a*a)%MOD;
     ans2=(ans2+a)%MOD;
 }
 cout<<(ans2*ans2%MOD+MOD-ans1)%MOD*modpow(2,MOD-2,MOD)%MOD<<endl;
   }
     


 


 






    





      

        


Measured memory_bytes: 3636
#include <stdio.h>

int main(){
  int p,q,r;
  scanf("%d%d%d",&p,&q,&r);
  
  int a = p + q;
  int b = q + r;
  int c = r + p;
  
  if (a <= b && a <= c){
    printf("%d",a);
  }else if ( b <= a && b <= c){
    printf("%d",b);
  }else{
    printf("%d",c);
  }
  
  return 0;
  
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
using namespace std;
typedef long long ll;

int main() {
  ll x;
  cin >> x;

  ll ans = 0;
  ll current = 100;
  while (true) {
    ans++;
    current = current * 1.01;
    if (current >= x) {
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
N=int(input())
A=[int(i) for i in input().split()]
u=[]
for i in range(N):
    u.append(A[i]-i)
a=sorted(u)
if len(a)%2==0:
    p=a[len(a)//2]
else:
    p=a[len(a)//2]
ans=0
for j in range(N):
    ans+=abs(a[j]-p)
print(ans)

Measured memory_bytes: 25200
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
int N,M;
VV<int> G;
V<int> memo;
int dfs(int v){
	if(memo[v] != -1) return memo[v];
	memo[v] = 0;
	for(int u:G[v]) chmax(memo[v],dfs(u)+1);
	return memo[v];
}
int main(){
	cin>>N>>M;
	G.resize(N);
	memo = V<int>(N,-1);
	rep(i,M){
		int x,y;
		cin>>x>>y;
		x--,y--;
		G[x].pb(y);
	}
	int ans = 0;
	rep(i,N) chmax(ans,dfs(i));
	cout<<ans<<endl;
}

Measured memory_bytes: 8192
/* YOU LOST THE GAME */
#include <bits/stdc++.h>     // [PRIMES]               1777 ~2^10.80
using namespace std;                     //                       10333 ~2^13.33
using ll=long long;                      // seq 1 128 | factor   100333 ~2^16.61
using vl=vector<ll>;                     //   | grep -v ' .* '  1300111 ~2^20.31
using vvl=vector<vl>;                    //                    10300777 ~2^23.30
using vb=vector<bool>;                   //                   100400999 ~2^26.58
using vs=vector<string>;                 //                  1300400999 ~2^30.28
using pll=pair<ll,ll>;                   //                 10200500333 ~2^33.25
const ll oo =0x3f3f3f3f3f3f3f3fLL;       //                100200400777 ~2^36.54
const double eps=1e-9;                   //               1200300700111 ~2^40.13
#define sz(c) ll((c).size())             //              10200300500777 ~2^43.21
#define all(c) begin(c),end(c)           //             100200300400777 ~2^46.51
#define mp make_pair                     //            1200300400600999 ~2^50.09
#define mt make_tuple                    //           10200300400600111 ~2^53.18
#define pb push_back                     //          100200300400600333 ~2^56.48
#define eb emplace_back                  //         1200300400500800999 ~2^60.06
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main(){
  ll N;
  cin >> N;

  vl A(N);
  FOR (i, 0, N)
  {
    cin >> A[i];
  }

  sort (all (A));

  double res = A[0];

  FOR (i, 1, N)
  {
    res = (res + A[i]) / 2.;
  }

  cout << res << endl;

  return 0;
} //cin.tie(0) bei schnellem Wechseln



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a%3==0||b%3==0||(a+b)%3==0)
    {
        cout<<"Possible"<<endl;
    }
    else
    {
        cout<<"Impossible"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
long long arr[205][205];
long long min(long long a,long long b) {
	return a>b?b:a;
}
int main() {
	long long n,m;
	while(scanf("%lld %lld",&n,&m)!=EOF) {
		long long x,y,c;
		for(int i=0; i<205; i++) {
			for(int j=0; j<205; j++) {
			arr[i][j]=10000000000;
			}
		}
		for(long long j=1; j<=m; j++) {
			scanf("%lld %lld %lld",&x,&y,&c);
//				arr[x][y]=min(arr[x][y],c);
				arr[x][y]=c;
		}
		for(int k=0; k<n; k++) {
			for(int i=0; i<n; i++) {
				for(int j=0; j<n; j++) {
				    if(arr[i][k]<10000000000&&arr[k][j]<10000000000){
				      arr[i][j]=min(arr[i][j],arr[i][k]+arr[k][j]);	
					}
				}
			}
		}
//		printf("\n");
		int t=0;
		for(int i=0; i<n; i++) {
			if(arr[i][i]<0) {
				t=1;
			}
		arr[i][i]=0;	
		}
		if(t==1) {
			printf("NEGATIVE CYCLE\n");
		} else {
			for(int i=0; i<n; i++) {
				for(int j=0; j<n; j++) {
					if(arr[i][j]==10000000000){
						if(j!=n-1) printf("INF ");
						 else printf("INF");
					}else{
						if(j!=n-1) printf("%lld ",arr[i][j]);
						 else  printf("%lld",arr[i][j]); 
					} 
				}
				printf("\n");
			}
		}
	}
	return 0;
}
































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

bool isprime(int x) {
  bool res = true;
  if (x == 2)
    res = true;
  else if (x == 1 || x % 2 == 0)
    res = false;
  else {
    for (int i=3;i*i<=x;i++) {
      if (x % i == 0)
        res = false;
    }
  }
  return res;
}

int main() {
  int n, cnt = 0;
  cin >> n;
  for (int i=0;i<n;i++) {
    int now;
    cin >> now;
    if (isprime(now))
      cnt++;
  }
  cout << cnt << endl;
}



Measured memory_bytes: 3096
/*program from Wolfycz*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline char gc(){
	static char buf[1000000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int frd(){
	int x=0,f=1; char ch=gc();
	for (;ch<'0'||ch>'9';ch=gc())	if (ch=='-')	f=-1;
	for (;ch>='0'&&ch<='9';ch=gc())	x=(x<<3)+(x<<1)+ch-'0';
	return x*f;
}
inline int read(){
	int x=0,f=1; char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar())	if (ch=='-')	f=-1;
	for (;ch>='0'&&ch<='9';ch=getchar())	x=(x<<3)+(x<<1)+ch-'0';
	return x*f;
}
inline void print(int x){
	if (x<0)	putchar('-'),x=-x;
	if (x>9)	print(x/10);
	putchar(x%10+'0');
}
const int N=2e3;
int v[N+10][N+10],Lf[N+10][N+10],Rg[N+10][N+10],Up[N+10][N+10];
int main(){
	int n=read(),m=read();
	for (int i=1;i<=n;i++){
		static char s[N+10];
		scanf("%s",s+1);
		for (int j=1;j<=m;j++)	v[i][j]=(s[j]=='#');
	}
	for (int i=1;i<=n;i++)	for (int j=1;j<=m;j++)	v[i][j]^=v[i+1][j]^v[i][j+1]^v[i+1][j+1];
	int Ans=max(n--,m--);
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++)	Lf[i][j]=v[i][j]?0:Lf[i][j-1]+1;
		for (int j=m;j>=1;j--)	Rg[i][j]=v[i][j]?0:Rg[i][j+1]+1;
	}
	memset(Lf[0],127,sizeof(Lf[0]));
	memset(Rg[0],127,sizeof(Rg[0]));
	for (int i=1;i<=n;i++){
		for (int j=1;j<=m;j++){
			if (v[i][j])	Up[i][j]=0,Lf[i][j]=Rg[i][j]=inf;
			else{
				Up[i][j]=Up[i-1][j]+1;
				Lf[i][j]=min(Lf[i][j],Lf[i-1][j]);
				Rg[i][j]=min(Rg[i][j],Rg[i-1][j]);
				Ans=max(Ans,(Up[i][j]+1)*(Lf[i][j]+Rg[i][j]));
			}
		}
	}
	printf("%d\n",Ans);
	return 0;
}

Measured memory_bytes: 63360
#include <iostream>
#include <algorithm>
#include <vector>
#define INF 100000000000000LL
using namespace std;
int n, c;
int cost[501][501];
int grid[501][501];
vector <int> colors1[31];
vector <int> colors2[31];
vector <int> colors3[31];
int rc(int ro, int co) {
	return ro * n + co;
}
int main() {
	cin >> n >> c;
	for (int i = 0; i < c; i++) {
		for (int j = 0; j < c; j++) {
			cin >> cost[i][j];
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> grid[i][j];
			grid[i][j]--;
			if ((i + j) % 3 == 0) {
				//cout << "TYPE 1: " << i << ' ' << j << '\n';
				colors1[grid[i][j]].push_back(rc(i, j));
			}
			else if ((i + j) % 3 == 1) {
				//cout << "TYPE 2: " << i << ' ' << j << '\n';
				colors2[grid[i][j]].push_back(rc(i, j));
			}
			else {
				//cout << "TYPE 3: " << i << ' ' << j << '\n';
				colors3[grid[i][j]].push_back(rc(i, j));
			}
		}
	}
	long long int minchange = INF;
	for (int i = 0; i < c; i++) {
		for (int j = 0; j < c; j++) {
			for (int k = 0; k < c; k++) {
				if (i == j || j == k || i == k)
					continue;
				long long int curchange = 0;
				for (int l = 0; l < c; l++) {
					curchange += colors1[l].size() * cost[l][i];
				}
				for (int l = 0; l < c; l++) {
					curchange += colors2[l].size() * cost[l][j];
				}
				for (int l = 0; l < c; l++) {
					curchange += colors3[l].size() * cost[l][k];
				}
				//cout << i << ' ' << j << ' ' << k << ' ' << curchange << '\n';
				minchange = min(minchange, curchange);
			}
		}
	}
	cout << minchange << '\n';
}

Measured memory_bytes: 2816
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cctype>


int strcmp_sync(const char* s1, const char* s2) {
	for (; !(*s1 == '\0' && *s2 == '\0'); ++s1, ++s2) {
		if (*s1 == '\0') {
			return -1;
		}
		if (*s2 == '\0') {
			return 1;
		}
		if (isdigit(*s1) || isdigit(*s2)) {
			if (!isdigit(*s2)) {
				return -1;
			}
			if (!isdigit(*s1)) {
				return 1;
			}

			const int u1 = atoi(s1);
			const int u2 = atoi(s2);
			if (u1 < u2) {
				return -1;
			}
			if (u2 < u1) {
				return 1;
			}
		}
		else {
			if (*s1 < *s2) {
				return -1;
			}
			if (*s2 < *s1) {
				return 1;
			}
		}
	}
	return 0;
}


int main(int argc, char* argv[]) {
	int n;
	char s0[16], s[16];
	scanf("%d %s", &n, s0);

	while (n--) {
		scanf(" %s", s);

		const int det = strcmp_sync(s, s0);
		if (det < 0) {
			puts("-");
		}
		else {
			puts("+");
		}
	}

	return EXIT_SUCCESS;
}



Measured memory_bytes: 2692
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;

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

  vector < vector<pair<int, int> > > XY(N);
  for (int i = 0; i < N; i++){
    int A; cin >> A;
    for (int j = 0; j < A; j++){
      int X, Y; cin >> X >> Y; X--;
      XY[i].push_back(make_pair(X, Y));
    }
  }

  int all = pow(2, N);
  int ans = 0;
  for (int i = 0; i < all; i++){
    int num = i;
    vector <bool> real(N);
    bool flag = true;
    int cnt = 0;
    for (int j = 0; j < N; j++){
      real[j] = num % 2;
      cnt += num % 2;
      num /= 2;
    }

    for (int j = 0; j < N; j++){
      if (real[j] == true){
        for (int k = 0; k < XY[j].size(); k++){
          if (real[XY[j][k].first] != XY[j][k].second){
            flag = false;
          }
        }
      }
    }

    if (flag == true) ans = max(ans, cnt);
  }
  cout << ans << endl;
  

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

// value


void solve() {

	int A, B, C;
	cin >> A >> B >> C;

	if (A == B && B == C) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return;

}

int main() {

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

	solve();

	return 0;

}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
from functools import reduce
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
_gcd = lambda x, y: _gcd(y, x%y) if (x%y) else y
_lcm = lambda x, y: x*y // _gcd(x, y)
def gcd(*numbers):
    return reduce(_gcd, numbers)
def lcm(*numbers):
    return reduce(_lcm, numbers)
def factorial(n):
    if (n==0) or (n==1):
        return 1
    ret = 1
    for i in range(2, n+1):
        ret *= i
    return ret
def combination(n, k):
    return factorial(n)//factorial(k)//factorial(n-k)
sys.setrecursionlimit(1000000)
INF = float('inf')
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

s = S()
t = S()

#dp[s][t]
dp = [[0]*(len(t)+1) for i in range(len(s)+1)]

for i in range(len(s)):
    for j in range(len(t)):
        if (s[i] == t[j]):
            dp[i+1][j+1] = dp[i][j] + 1
        else:
            dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])

i = len(s)
j = len(t)
res = ""
while (i>0  and j>0):
    if (dp[i][j] == dp[i-1][j]):
        i -= 1
    elif (dp[i][j] == dp[i][j-1]):
        j -= 1
    else:
        i -= 1
        j -= 1
        res = s[i] + res

print(res)

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

int main(){
  int N,X,Y;
  cin >> N >> X >> Y;
  X--;
  Y--;
  vector<vector<int>> graph(N);
  for(int i=0;i<N-1;i++){
    graph.at(i).push_back(i+1);
    graph.at(i+1).push_back(i);
  }
  graph.at(X).push_back(Y);
  graph.at(Y).push_back(X);

  vector<int> ans(N,0);
  priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
  for(int i=0;i<N;i++){
    vector<int> dis(N,1e9);
    dis.at(i)=0;
    pq.push(make_pair(0,i));

    while(!pq.empty()){
      int cost=pq.top().first;
      int v=pq.top().second;
      pq.pop();
      if(dis.at(v)<cost)  continue;
      ans.at(cost)++;

      for(int i=0;i<graph.at(v).size();i++){
        int nv=graph.at(v).at(i);
        if(dis.at(nv)<=dis.at(v)+1) continue;
        dis.at(nv)=dis.at(v)+1;
        pq.push(make_pair(dis.at(v)+1,nv));
      }
    }
  }
  for(int i=1;i<N;i++) cout << ans.at(i)/2 << endl;

  return 0;
}

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

int main(){
    int x;
    cin >>x;
    int a;
    int b;
    a = x/500;
    b = (x-a*500)/5;

    cout << 1000*a+5*b << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void solve(int test,int test1)
{
 int n;
 cin>>n;

 int arr[n];
 for(int i=0;i<n;i++)
    cin>>arr[i];
 vector<int> dp(n,0);
 dp[0]=0;
 dp[1]=abs(arr[0]-arr[1]);
 for(int i=2;i<n;i++)
 {
    dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));

 }
 cout<<dp[n-1];
}

int main()
{
    int test;
   // cin>>test;
   test=1;
    int test1=test;

  while(test--)
  {

    solve(test,test1);

  }


    return 0;
}


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

int main()
{
	int N;

	cin >> N;

	int *takoyaki = new int[N];
	int sum = 0;

	for (int i = 0; i < N; i++) {
		cin >> takoyaki[i];
		for (int j = 0; j < i; j++) {
			sum += takoyaki[i] * takoyaki[j];
		}
	}

	cout << sum << endl;

	delete takoyaki;

	return 0;
}

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

using namespace std;

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

LL dist[100010];
bool visit[100010];
vector<P> a[100010];
int dfs(int v, LL d) {
    visit[v] = true;
    dist[v] = d;
    for (int i = 0; i < a[v].size(); i++) {
        int nxt = a[v][i].first;
        LL dd = a[v][i].second;
        if (!visit[nxt]) {
            dfs(nxt, d + dd);
        }
    }
}

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

    for (int i = 0; i < n - 1; i++) {
        int ta, tb;
        LL tc;
        cin >> ta >> tb >> tc;
        a[ta].push_back(make_pair(tb, tc));
        a[tb].push_back(make_pair(ta, tc));
    }
    int q, k;
    cin >> q >> k;
    vector<int> x(q), y(q);
    for (int i = 0; i < q; i++) {
        cin >> x[i] >> y[i];
    }

    dfs(k, 0);

    for (int i = 0; i < q; i++) {
        cout << dist[x[i]] + dist[y[i]] << endl;
    }

    return 0;
}


Measured memory_bytes: 15232
#include <iostream>
#include <vector>
#include <utility>
using namespace std;

int main(){
	string s;
	cin >> s;
	vector<pair<char,int>> vec;
	for(int i = 0;i < 4;i++){
		if(i == 0){
			vec.push_back(make_pair(s.at(0),1));
		}else{
			for(int j=0;j < vec.size();j++){
				if(vec[j].first == s.at(i)){
					vec[j].second += 1;
                 
					break;
				}
              	if(j == vec.size() - 1){
					vec.push_back(make_pair(s.at(i),1));
                   break;
                }
			}
		}
	}
	if(vec.size() == 2){
		if(vec[0].second == 2 && vec[1].second == 2){
			cout << "Yes" << endl;
		}else{
      
			cout << "No" << endl;
		}
	}else{
      
			cout << "No" << endl;
		}
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 10000
#define Q 500

int main(){
  
  int n,q,i,j,S[N],T[Q],C=0;
  
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d",&S[i]);
  }

  scanf("%d",&q);
  for(j = 0; j < q; j++){
    scanf("%d",&T[j]);
  }
  
  for(j = 0; j < q; j++){    
    for(i = 0; i < n; i++){
      if(S[i] == T[j]){
	C++;
	break;
      }
    }
  }
  printf("%d\n",C);
  return 0; 
}

Measured memory_bytes: 640
#include<stdio.h>

int main(){
    int num = 0;
    int i;
    int j;

    scanf("%d",&num);
    int arry[num];
    int arryb[num];
    
    for(i=0;i<num;i++){
        scanf("%d",&arry[i]);
    }
    j=num-1;
    for(i=0;i<num;i++){
        arryb[j]=arry[i];
        j=j-1;
    }
    
    for(i=0;i<num;i++){
        printf("%d",arryb[i]);
        
        if(i != num-1){
            printf(" ");
        }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2040
n = int(input())

a = list(map(int,input().split()))

b = [0]
for i in range(n-1):
    s = a[i+1] - (a[i] + b[i])
    if s < 0:
        b.append(abs(s))
    else:
        b.append(0)

c = sum(b)
print(c)


Measured memory_bytes: 32380
n = int(input())
A = list(map(int, input().split()))
A.sort()
A.reverse()

# Initialize
Alice = 0
Bob = 0

for i in range(0, n):
    # print(i, A[i])
    if i % 2 == 0:
        Alice += A[i]
    else:
        Bob += A[i]

print(Alice - Bob)

Measured memory_bytes: 3064
import math
import heapq
n,k=map(int,input().split())
a=list(map(int,input().split()))
SUM=sum(a)
ans=[]
y=k

for i in range(n):
    x=a[i]*k//SUM
    ans.append([-math.ceil(a[i]/(1+x)),x,i])
    y-=x

heapq.heapify(ans)
#print(y)
#print(ans)
for i in range(y):
    temp=heapq.heappop(ans)
    temp[0]=-math.ceil(a[temp[2]]/(2+temp[1]))
    temp[1]+=1
    heapq.heappush(ans,temp)

temp=heapq.heappop(ans)
print(-temp[0])

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

using namespace std;
using ll = long long;

const ll nax = 1e5 + 12;
const ll md = 1e9 + 7;

ll dp[nax][15];
ll n;
string s;

ll add (ll &a, ll b)
{
  a += b;
  if (a > md) {
    a -= md;
  }
}

ll solve (ll pos, ll rem)
{
  if (pos == n) {
    return (rem == 5);
  }
  if (dp[pos][rem] != -1) {
    return dp[pos][rem];
  }
  ll ans = 0;
  if (s[pos] == '?') {
    for (ll digit = 0; digit <= 9; digit++) {
      ll new_rem = (rem * 10 + digit) % 13;
      add (ans, solve (pos + 1, new_rem) );
    }
  } else {
    ll new_rem = (rem * 10 + (s[pos] - '0') ) % 13;
    add (ans, solve (pos + 1, new_rem) );
  }
  return dp[pos][rem] = ans;
}

int main()
{
  ios_base::sync_with_stdio (0);
  cin.tie (0);
  memset (dp, -1, sizeof (dp) );
  cin >> s;
  n = (int) s.length();
  cout << solve (0, 0) << '\n';
  return 0;
}


Measured memory_bytes: 18512
/* *****fireice**** */

#include<bits/stdc++.h>

#define ll long long int
#define vi vector<int>
#define vc vector<char>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define pii pair<int,int>
#define pb push_back
#define el '\n'
#define N 1000000007
#define re return
#define F first
#define S second
#define L length
#define mp make_pair
#define PI 3.14159265
#define all(a) (a).begin(),(a).end()
#define forup(i,n) for(int i=0;i<n;i++)
#define forf(i,x,n) for(int i=x;i<n;i++)
#define ford(i,n) for(int (i)=(n)-1;i>=0;(i)--)
#define take(a,n) forup(i,n) cin>>a[i];
using namespace std;

int gcdExtended(int a, int b, int *x, int *y)
{
    // Base Case
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }

    int x1, y1; // To store results of recursive call
    int gcd = gcdExtended(b%a, a, &x1, &y1);

    // Update x and y using results of recursive
    // call
    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}

ll modInverse(int a, int m)
{
    int x, y;
    int g = gcdExtended(a, m, &x, &y);
        // m is added to handle negative x
    ll res = ((ll)x%m + (ll)m) % m;

    return res;
}

ll poww(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return poww(x*x,n/2);
    else                             //n is odd
        return x*poww(x*x,(n-1)/2);
}

ll modularExponentiation(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}

inline ll max(ll a, ll b)
{
  if(a>b) re a;
  else re b;
}

inline ll min(ll a, ll b)
{
  if(a>b) re b;
  else re a;
}

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

    if (a == b)
        return a;

    if (a > b)
        return gcd(a-b, b);
    else return gcd(a, b-a);
}

ll ncr(int n,int r)
{
  ll ans=1;
  r=min(r,n-r);
  forup(i,r)
  {
    ans=(ans*(n-i)/(i+1))%N;
  }
  re ans;
}

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

  int t=1;
  //cin>>t;
  while(t--)
  {
    ll n,m,k;
    cin>>n;
    m=0;
    m=(n/500)*1000;
    n%=500;
    m+=(n/5)*5;
    n%=5;
    cout<<m<<el;

  }


  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            (long N, long T) = Slice2<long>();
            var ti = Sarray();
            var ans = 0L;
            for (var i = 1; i < N; ++i)
                ans += Min(T, ti[i] - ti[i - 1]);
            WriteLine(ans + T);
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

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

#define INF 1000000000

using namespace std;


int main()
{
    int n;
    cin >> n;
    if(n < 100)
    {
        cout << 0 << endl;
        return 0;
    }
    for(int i = 2;i<= 953; i++)
    {
        if(n<100*i && n>105*(i-1))
        {
            cout << 0 << endl;
            return 0;
        }
    }
    cout << 1 << endl;
   return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
ab = {}
for i in range(n):
    a, b = map(int, input().split())
    try:
        ab[a] += b
    except:
        ab[a] = b
count = 0
ans = 0
for key in sorted(ab.keys()):
    count += ab[key]
    if count >= k:
        ans = key
        break
print(ans)


Measured memory_bytes: 10596
"use strict";

var main = function main(input) {
  var args = input.split('');
  var A = parseInt(args[0], 10);
  var B = parseInt(args[1], 10);
  var C = parseInt(args[2], 10);
  var D = parseInt(args[3], 10);

  if (A + B + C + D == 7) {
    console.log("".concat(A, "+").concat(B, "+").concat(C, "+").concat(D, "=7"));
  } else if (A - B + C + D == 7) {
    console.log("".concat(A, "-").concat(B, "+").concat(C, "+").concat(D, "=7"));
  } else if (A + B - C + D == 7) {
    console.log("".concat(A, "+").concat(B, "-").concat(C, "+").concat(D, "=7"));
  } else if (A + B + C - D == 7) {
    console.log("".concat(A, "+").concat(B, "+").concat(C, "-").concat(D, "=7"));
  } else if (A - B - C + D == 7) {
    console.log("".concat(A, "-").concat(B, "-").concat(C, "+").concat(D, "=7"));
  } else if (A - B + C - D == 7) {
    console.log("".concat(A, "-").concat(B, "+").concat(C, "-").concat(D, "=7"));
  } else if (A - B - C - D == 7) {
    console.log("".concat(A, "-").concat(B, "-").concat(C, "-").concat(D, "=7"));
  } else if (A + B - C - D == 7) {
    console.log("".concat(A, "+").concat(B, "-").concat(C, "-").concat(D, "=7"));
  }
};

main(require('fs').readFileSync('/dev/stdin', 'utf-8'));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
 
typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> P;
 
#define M 1005
#define MOD 1000000007
#define ep emplace_back
#define mk make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
//	freopen("input.txt","rt",stdin);
	
	int n;
	cin>>n;
	
	lli sum = 0;
	for(int i=1;i<=n;i++)
	{
		if(i%3==0 && i%5==0)
			continue;
		if(i%3==0)
			continue;
		if(i%5==0)
			continue;
		sum += i;
	}
	
	cout<<sum<<"\n";
	
	
}


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>

using namespace std;

const int MAX_H = 1000;
const int MAX_W = 1000;

typedef pair<int, int> P;
typedef pair<P, int> PP;
int H, W;

queue<PP> que;
char field[MAX_H][MAX_W];
bool visited[MAX_H][MAX_W];
int di[4] = {-1, 0, 1, 0};
int dj[4] = {0, 1, 0, -1};

int cnt;
int ans;
char cell;
int main()
{
  cin >> H >> W;
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      cin >> cell;
      if (cell == '#')
      {
        visited[i][j] = true;
        que.push(make_pair(make_pair(i, j), 0));
      } else {
        visited[i][j] = false;
      }
      field[i][j] = cell;
    }
  }
  PP pp;
  P p;
  int i, j, ni, nj;
  while (que.size())
  {
    pp = que.front();
    que.pop();
    p = pp.first;
    cnt = pp.second;
    i = p.first;
    j = p.second;
    for (int d = 0; d < 4; d++)
    {
      ni = i + di[d];
      nj = j + dj[d];
      if (ni >= 0 && ni < H && nj >= 0 && nj < W && !visited[ni][nj] && field[ni][nj] == '.')
      {
        que.push(make_pair(make_pair(ni, nj), cnt+1));
        visited[ni][nj] = true;
        field[ni][nj] = '#';
      }
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 14080
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int n;
ll z, w;
vector<int> a;
vector<vector<ll>> memo(2020, vector<ll>(2, -1LL));

ll dfs(int i, int turn, ll x, ll y) {
    if(i == n) {
        return llabs(x - y);
    }
    if(memo[i][turn] >= 0) {
        return memo[i][turn];
    }
    ll res;
    if(turn == 0) {
        res = -LLINF;
        for(int j = i + 1; j <= n; j++) {
            chmax(res, dfs(j, 1, a[j - 1], y));
        }
        return memo[i][turn] = res;
    } else {
        res = LLINF;
        for(int j = i + 1; j <= n; j++) {
            chmin(res, dfs(j, 0, x, a[j - 1]));
        }
        return memo[i][turn] = res;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> z >> w;
    a.resize(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    cout << dfs(0, 0, z, w) << endl;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main()
{
	long long a,b,m;
	cin>>a>>b;
	m=b-a+1;
	if(a<b)
	{
		if(a>0&&b>0)
		{
			cout<<"Positive"<<endl;
		}
		else
		{
			if(a<=0&&b>0)
			{
				cout<<"Zero"<<endl;
			}
			else
			{
				if(a<0&&b<=0)
				{
					if(b==0)
					{
						cout<<"Zero"<<endl;
					}
					else
					{
						if(m%2==0)
						{
							cout<<"Positive"<<endl;
						}
						else
						{
							cout<<"Negative"<<endl;
						}
					}
				}
			}
		}
	}
	else
	{
		return 0;
	}
	return 0;	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 100100100100100100;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N),B(N);
    rep(i,N) cin >> A[i];
    ll pre = 0;
    rep(i,N){
        pre = A[i] - pre;
    }
    B[0] = pre;
    FOR(i,1,N){
        B[i] = (A[i-1] - B[i-1] / 2) * 2;
    }
    rep(i,N) cout << B[i] << ' ';
    cout << endl;
}


Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <cstring>
#include <queue>
using namespace std;

typedef int W;
const int MAXV = 105;
const int MAXE = 10005 * 25 * 2;
const int INF = 1<<29;

struct St { int c, v; };
bool operator<(const St &s, const St &t) {
    return (s.c != t.c) ? s.c > t.c : s.v < t.v;
}

struct ShortestPath {
    int V, E, edge[MAXE], prev[MAXE], to[MAXE];
    W dist[MAXV], cost[MAXE];
    ShortestPath(int n) : V(n), E(0) { memset(edge, -1, sizeof(edge)); }
    void add_edge(int s, int t, W d) {
        to[E] = t; cost[E] = d; prev[E] = edge[s]; edge[s] = E; E++;
    }
    W shortest_path(int s) {
        for (int i=0; i<V; ++i) dist[i] = -1;
        dist[s] = 0;
        priority_queue<St> q; q.push((St){0, s});
        while(!q.empty()) {
            St s = q.top(); q.pop();
            for (int e = edge[s.v]; e != -1; e = prev[e]) {
                int w = to[e];
                if (dist[w] == -1 || dist[w] > dist[s.v] + cost[e]) {
                    dist[w] = dist[s.v] + cost[e];
                    q.push((St){dist[w], w});
                }
            }
        }
    }
};

int dist[25][151][151];
int p[21];
int q[21][51], r[21][51];

int calc(int c, int d) {
    int ret = 0, prev = 0;
    for (int i=0; i<p[c]-1 && d > 0; ++i) {
        if (d >= q[c][i]) {
            ret += q[c][i] * r[c][i];
            d -= q[c][i] - prev;
        } else {
            ret += d * r[c][i];
            d = 0;
            break;
        }
    }
    ret += d * r[c][p[c]-1];
    return ret;
}

int main() {
    int n, m, c, s, g;
    while(cin>>n>>m>>c>>s>>g, n|m|c|s|g) {
        s--, g--;
        for (int d=0; d<c; ++d)
            for (int i=0; i<n; ++i) {
                for (int j=0; j<n; ++j)
                    dist[d][i][j] = INF;
                dist[d][i][i] = 0;
            }
        for (int i=0; i<m; ++i) {
            int x,y,d,cc;
            cin>>x>>y>>d>>cc;
            cc--, x--, y--;
            dist[cc][x][y] = dist[cc][y][x] = min(dist[cc][x][y], d);
        }
        for (int cc=0; cc<c; ++cc) {
            for (int k=0; k<n; ++k)
                for (int i=0; i<n; ++i)
                    for (int j=0; j<n; ++j)
                        dist[cc][i][j] = min(dist[cc][i][j], dist[cc][i][k] + dist[cc][k][j]);
        }

        for (int i=0; i<c; ++i) cin>>p[i];
        for (int i=0; i<c; ++i) {
            for (int j=0; j<p[i]-1; ++j) cin>>q[i][j];
            for (int j=0; j<p[i]; ++j) cin>>r[i][j];
        }
        for (int i=0; i<c; ++i) {
            for (int j=p[i]-2; j>=1; --j) q[i][j] -= q[i][j-1];
        }

        ShortestPath sp(n);
        for (int cc=0; cc<c; ++cc) {
            for (int i=0; i<n; ++i) {
                for (int j=0; j<n; ++j) {
                    if (i == j) continue;
                    if (dist[cc][i][j] >= INF) continue;
                    sp.add_edge(i, j, calc(cc, dist[cc][i][j]));
                    sp.add_edge(j, i, calc(cc, dist[cc][j][i]));
                }
            }
        }
        sp.shortest_path(s);
        cout<<sp.dist[g]<<endl;
    }
}

Measured memory_bytes: 10304
#include <bits/stdc++.h>
using namespace std;
int n;
int x[100100], y[100100], t[100100];
int dx, dy, dt;

int main()
{
    cin >> n;
    cin >> t[0] >> x[0] >> y[0];
    
    if(abs(x[0])+abs(y[0]) > t[0] || (abs(x[0])+abs(y[0])-t[0]) % 2 != 0)
    {
        cout << "No" << endl;
        return 0;
    }
    
    for(int i = 1; i < n; i++)
    {
        cin >> t[i] >> x[i] >> y[i];
        dt = t[i] - t[i-1];
        dx = x[i] - x[i-1];
        dy = y[i] - y[i-1];
        if(abs(dx)+abs(dy) > dt || (abs(dx)+abs(dy)-dt) % 2 != 0)
        {
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes" << endl;
}


Measured memory_bytes: 1408
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int n, a, b;
  cin >> n >> a >> b;
  if (a + b - 1 > n) return !puts("-1");
  if ((long long)a * b < n) return !puts("-1");
  int cur = 0, p = 0;
  while (cur + b < n) {
    cur += b;
    p ++;
    for (int i = 1; i <= b; i ++)
      printf("%d ", cur + 1 - i);
    if (a - (1 + p) + b + cur > n) break;
  }
  if (n - (a - p) == cur)
    for (int i = n - (a - p) + 1; i <= n; i ++) printf("%d ", i);
  else {
    for (int i = n - (a - (1 + p)); i > cur; i --) printf("%d ", i);
    for (int i = n - (a - (1 + p)) + 1; i <= n; i ++) printf("%d ", i);
  }
  puts("");
  return 0;
}


Measured memory_bytes: 2176