akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	long long int n;
	cin >> n;
	vector<long long int> a(n);
	long long int num = 1;
	for(long long int i=0;i<n;i++){
		cin >> a.at(i);
		if(a.at(i) == 0){
			cout << 0 << endl;
			return 0;
		}
	}
	for(long long int i=0;i<n;i++){
		num *= a.at(i);
		if(num > 1000000000000000000 || num < a.at(i)){
			cout << -1 << endl;
			return 0;
		}
	}
	cout << num << endl;
	return 0;
}

Measured memory_bytes: 4028
#include<stdio.h>
#include<string.h>


int main(void){
  
  int a;
  int i;
  int r = 0;
  int ao = 0;
  int len;
  char b[114514];
  
  

  scanf("%d", &a);
  scanf("%s", b);
  len = strlen(b);

  for(i = 0; i < len; i++){
    if(b[i] == 'R'){
      r++;
    }else{
      ao++;
    }
  }
  if(r > ao){
    printf("Yes");
  }else{
    printf("No");
  }
return 0;
}
    


Measured memory_bytes: 128
X = int(input().strip())

A = 1
B = -1
found = False
while (True):
    A5 = A ** 5
    B = -A
    while (True):
        if (B >= A):
            break
        if (X == A5 - B ** 5):
            found = True
            break
        B += 1
    if (found):
        break
    A += 1
    if (A > X):
        break

print(A,' ',B)


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

int main() {
    int a,b,c;
    cin>>a>>b>>c;
  if(a+b+c>=22){
   cout << "bust"<< endl;

  }else{
      cout<<"win"<<endl;
  }
    return 0;    
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int h, w;
    scanf("%d%d", &h, &w);
    int h_2, w_2;
    scanf("%d%d",&h_2,&w_2);
    printf("%d\n", h*w - (w * h_2 + h * w_2) + (h_2 * w_2));
    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include <string.h>

int main(){
	int i, n, low = 0, a = 0, b = 0, c = 0, d = 0, e = 0, hi = 0, y;
	while(scanf("%d", &n) != 0){
		if(n == 0) break;
		for(i = 0; i < n; i++){
			scanf("%d", &y);
			if(y < 10) low++;
			else if(y < 20) a++;
			else if(y < 30) b++;
			else if(y < 40) c++;
			else if(y < 50) d++;
			else if(y < 60) e++;
			else hi++;
		}
		printf("%d\n%d\n%d\n%d\n%d\n%d\n%d\n", low, a, b, c, d, e, hi);
		low = a = b = c = d = e = hi = 0;
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N, T;
    cin >> N >> T;
    vector<int> A(N), M(N), V(N);
    rep(i, N) cin >> A[i];
    int m = 0;
    for (int i = N - 1; i >= 0; i--) {
        m = max(m, A[i]);
        M[i] = m;
    }

    int cnt = 1;
    rep(i, N) {
        V[i] = M[i] - A[i];
    }

    sort(all(V));
    reverse(all(V));

    int cmp = V[0];
    repd(i, 1, N) {
        if (cmp == V[i]) cnt++;
        else break;
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

const int PRIME_SIZE = 1000000;
int psize;
bool bprime[PRIME_SIZE+1];
int prime[PRIME_SIZE+1];
int Eratosthenes(int n) {
  psize = 0;
  memset(bprime, true, sizeof(bprime));
  bprime[0] = bprime[1] = false;
  for (int i = 2; i <= n; i++) {
    if (!bprime[i]) { continue; }
    prime[psize++] = i;
    for (int j = i + i; j <= n; j += i) {
      bprime[j] = false;
    }
  }
  return psize;
}

// need Eratosthenes
int PrimeFactorization(int n) {
  double ret = n;
  for (int i = 0; i < psize && i * i <= n; i++) {
    if (prime[i] * prime[i] > n) { break; }
    int size = 0;
    while (n % prime[i] == 0) {
      n /= prime[i];
      size++;
    }
    if (size > 0) {
      ret *= (1.0 - 1.0 / prime[i]);
    }
  }
  if (n != 1) {
    ret *= (1.0 - 1.0 / n);
  }
  ret += 0.5;
  return ret;
}

ll naive(int n) {
  ll ret = 2;
  FOREQ(b, 1, n) {
    FOR(a, 1, b) {
      if (__gcd(a, b) == 1) { ret++; }
    }
  }
  return ret;
}


ll ans[1000100];
int main() {
  Eratosthenes(1000000);
  ans[0] = 0;
  ans[1] = 2;
  FOREQ(i, 2, 1000000) {
    ans[i] = PrimeFactorization(i) + ans[i - 1];
  }
  int test;
  scanf("%d", &test);
  while (test--) {
    int n;
    scanf("%d\n", &n);
    printf("%lld\n", ans[n]);
    //cout << n << endl;
    //assert(ans[n] == naive(n));
  }
}

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

int main(){
  int N,X,ans=1,p=0,l;
  cin >> N >> X;
  for(int i=0;i<N;i++){
    cin>>l;
    p+=l;
    if(p<=X){
      ans+=1;
    }
  }
  cout<<ans<<endl ;
}


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

int main() {
    int r,c,i,j;
    cin >> r >> c;
    int a[r+1][c+1];
    for(i=0;i<r+1;i++){
        for(j=0;j<c+1;j++){
            a[r][j] = 0;
            a[i][c] = 0;
        }
    }
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            cin >> a[i][j];
        }
    }
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            cout << a[i][j] << " ";
            a[i][c] += a[i][j];
        }
        cout << a[i][c] << endl;
    }
    for(j=0;j<c+1;j++){
        for(i=0;i<r;i++){
            a[r][j] += a[i][j];
        }
        cout << a[r][j];
        if (j != c)
            cout << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  int A, B, C;
  cin >> A >> B >> C;

  if (A == B && B == C) {
    if (A % 2)
      cout << 0 << endl;
    else
      cout << -1 << '\n';
    return 0;
  }

  int ans = 0;
  while (true) {
    if (A % 2 || B % 2 || C % 2)
      break;
    int a = (B + C) / 2, b = (C + A) / 2, c = (A + B) / 2;
    A = a, B = b, C = c;
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
# include<bits/stdc++.h>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-8
# define MOD 1000000007
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
# define AU(i,x)    for(auto i=x.begin(); i!=x.end(); ++i)
# define ALL(A) A.begin(),A.end()
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
inline char nc(){
    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 Scan(){
    char ch=nc();int sum=0, f=1;
    if (ch=='-') f=-1, ch=nc();
    while(!(ch>='0'&&ch<='9'))ch=nc();
    while(ch>='0'&&ch<='9')sum=sum*10+ch-48,ch=nc();
    return sum*f;
}
int ps4[4][2]={0,1,0,-1,1,0,-1,0};
int ps8[8][2]={0,1,0,-1,1,0,-1,0,1,1,1,-1,-1,-1,-1,1};
inline int min(int a,int b,int c) {return min(a,min(b,c));}
inline int max(int a,int b,int c) {return max(a,max(b,c));}
inline int min(int a,int b,int c,int d){return min(min(a,b,c),d);}
inline int max(int a,int b,int c,int d){return max(max(a,b,c),d);}
//struct Edge{int p, next, w;}edge[maxn];
//inline add_edge(int u, int v, int w){edge[cnt]=Edge{v,head[u],w}; head[u]=cnt++;}
const int N=200005;
///Code begin..................................................................


int n;

int main ()
{
    int ans=1, sum=1, n, x;
    cin>>n;
    FOR(i,1,n) {
        scanf("%d",&x);
        if (x%2==0) ans<<=1;
        sum*=3;
    }
    printf("%d\n",sum-ans);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)

{
	int a,b,c;
	
	scanf("%d %d %d",&a,&b,&c);
	
	if(a<b&&b<c)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	
	return 0 ;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=2e5+10;
ll K,Cnt,N,M,CstA[MAXN],CstB[MAXN],CurA,CurB=0;
inline void pre(){
    cin>>N>>M>>K;
    for(int i=1;i<=N;i++)
        cin>>CstA[i],CstA[i]+=CstA[i-1];
    for(int i=1;i<=M;i++)
        cin>>CstB[i],CstB[i]+=CstB[i-1];
    CurA=N;
}
int main(){
    pre();
    while(CurB<=M){
        while(CurA>=0&&CstA[CurA]+CstB[CurB]>K)
            CurA--;
        if(CurA<0)
            break;
        Cnt=max(Cnt,CurA+CurB);
        CurB++;
    }
    cout<<Cnt;
    return 0;
}

Measured memory_bytes: 6740
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const int MOD = 1000000007;
const ll INF=2e18;

ll N,M;
ll S,T;
map<P,vector<P> >mp;
map<P,ll> costs;
ll ans;
typedef pair<ll,P> V;

int main(){
    cin>>N>>M;
    for(int i=0;i<N;i++){
        for(int j=0;j<3;j++){
            costs[P(i,j)]=INF;
        }
    }
    for(int i=0;i<M;i++){
        int u,v;
        cin>>u>>v;
        u--;v--;
        mp[P(u,0)].push_back(P(v,1));
        mp[P(u,1)].push_back(P(v,2));
        mp[P(u,2)].push_back(P(v,0));
    }
    cin>>S>>T;
    S--;T--;
    priority_queue<V,vector<V>,greater<V> > pq;
    pq.push(V(0,P(S,0)));
    P g=P(T,0);
    costs[P(S,0)]=0;
    while(!pq.empty()){
        P now=pq.top().second;
        ll cost=pq.top().first;
        pq.pop();
        if(cost>costs[now])continue;
        for(auto o:mp[now]){
            if(costs[o]>costs[now]+1){
                costs[o]=costs[now]+1;
                pq.push(V(costs[o],o));
            }
        }
    }
    if(costs[g]!=INF){
        cout<< costs[g]/3<<endl;
    }else{
        cout<<"-1"<<endl;
    }

    
    return 0;
}


Measured memory_bytes: 51840
//PseudoName

    #pragma GCC optimize("O3")
    #include <bits/stdc++.h>
/*
	#include <ext/pb_ds/assoc_container.hpp>
	#include <ext/pb_ds/tree_policy.hpp>
	using namespace __gnu_pbds;
	template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/
    #define FOR(i,n) for(i=0;i<n;i++)
    #define FOR1(i,n) for(i=1;i<=n;i++)
    #define FOR2(I, A, B) for (int I = (A); I <= (B); ++I)
    #define pb push_back
    #define unique_sort(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
    #define print(v) for(auto it:v)cout<<it<<" ";cout<<endl
    #define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
    #define endl "\n"
    #define min3(a,b,c) min(a,min(b,c))
    #define forr(n) for(int i=0;i<n;i++)
    #define jorr(n) for(int j=0;j<n;j++)
    #define frr(n) for(int i=1;i<=n;i++)
    #define MAX 100005
    #define inf 200008

    using namespace std;

    typedef long long ll;
    typedef long li;
    typedef vector<int> vi;
    typedef vector<ll> vli;
    typedef vector<vi> vvi;
    typedef vector<vli> vvli;
    typedef pair<int,int> pi;
    typedef pair<ll,ll> pli;
    typedef vector<pi> vpi;
    typedef vector<pli> vpli;


    int main() {
        fast();
        int n,cap;
        cin>>n>>cap;
        ll wt[n],val[n];
        forr(n){cin>>wt[i];cin>>val[i];}
        ll K[n+1][cap+1];

       for (int i = 0; i <= n; i++)
       {
           for (int w = 0; w <= cap; w++)
           {
               if (i==0 || w==0)
                   K[i][w] = 0;
               else if (wt[i-1] <= w)
                     K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]);
               else
                     K[i][w] = K[i-1][w];
           }
       }
       cout<<K[n][cap]<<endl;
    }


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

#define N 1005

char s[N][N];

int h, w;
int d[N][N];

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

typedef pair <int, int> pii;

#define x first
#define y second

queue <pii> q;

int main() {
	scanf("%d %d", &h, &w);
	for (int i = 1; i <= h; i ++) scanf("%s", s[i]+1);
    for (int i = 1; i <= h; i ++) {
        for (int j = 1; j <= w; j ++) {
            d[i][j] = -1;
            if (s[i][j] == '#') {
				d[i][j] = 0;
                q.push(pii(i, j));
            }
        }
    }
    int ans = 0;
    while (!q.empty()) {
        pii top = q.front(); q.pop();
        ans = max(ans, d[top.x][top.y]);
        for (int i = 0; i < 4; i ++) {
            if (d[top.x + dx[i]][top.y + dy[i]] >= 0) continue;
            d[top.x + dx[i]][top.y + dy[i]] = d[top.x][top.y] + 1;
            q.push(pii(top.x + dx[i], top.y + dy[i]));
        }
    }
    printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 13328
#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;

int main(int argc, char const *argv[]) {
  double n;
  cin >> n;
  if (fmod(n, 2) != 0) {
    cout << fixed << setprecision(10) << (n + 1) / 2 / n << endl;
  } else {
    cout << "0.5000000000" << endl;
  }
  return 0;
}


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

int main(){
    int N,flag=0,p=0,q=0,r=0;
    cin >> N;
    int grid[N+1][3];
    grid[0][0]=0;
    grid[0][1]=0;
    grid[0][2]=0;
    for (int i=1;i<N+1;i++){
        cin >> grid[i][0];
        cin >> grid[i][1];
        cin >> grid[i][2];
    }
    for (int i=0;i<N;i++){
        p=abs(grid[i][1]-grid[i+1][1]);
        q=abs(grid[i][2]-grid[i+1][2]);
        r=abs(grid[i][0]-grid[i+1][0]);
        if((p+q)>r || (p+q)%2 != r%2){
            flag =1;
        }
    }
    if (flag == 0){
        cout << "Yes" <<endl;
    }else{
        cout << "No" <<endl;
    }
    return 0;
}

Measured memory_bytes: 1408
N = int(input())
A = list(map(int, input().split()))
# i<jとして、条件は j-i = A_i + A_j
# i + A_i = j - A_j

dict1 = {}
for i in range(1, N + 1):
    tmp = i + A[i - 1]
    if tmp not in dict1:
        dict1[tmp] = 1
    else:
        dict1[tmp] += 1

dict2 = {}
for i in range(1, N + 1):
    tmp = i - A[i - 1]
    if tmp not in dict2:
        dict2[tmp] = 1
    else:
        dict2[tmp] += 1

# print(dict1, dict2)
ans = 0
for k, v in dict1.items():
    if k in dict2:
        ans += v * dict2[k]
print(ans)


Measured memory_bytes: 59496
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define REP(i,a,n) for(int i = a ; i < n ; i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

void solve(){
}

int main(){
  while(1){
    int x[5];
    int cnt[] = {0,0,0};
    rep(i,5){
      if(cin>>x[i] && !x[i]) return 0;
      x[i]--;
      cnt[x[i]]++;
    }

    rep(i,5){
      if(cnt[0] && cnt[1] && cnt[2] || cnt[0] == 5 || cnt[1] == 5 || cnt[2] == 5){
        cout<<"3\n";
      }
      else if(cnt[(x[i] + 2) % 3]){
        cout<<"2\n";
      }
      else{
        cout<<"1\n";
      }
    }
  }
}

Measured memory_bytes: 0
import math
a,b=map(int,input().split())
tempa1=math.ceil(a/0.08)
tempa2=math.ceil((a+1)/0.08)-1
tempb1=math.ceil(b/0.1)
tempb2=int((b+1)/0.1)-1
if tempa1>tempb2 or tempa2<tempb1:
  print(-1)
else:
  print(max(tempa1,tempb1))

Measured memory_bytes: 3060
#include<algorithm>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iostream>
#include<istream>
#include<map>
#include<math.h>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;
int n,k;
int main(){
	cin>>n>>k;
	if (k*2-1<=n)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<complex>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<vector>
#include<map>
#include<sstream>
#include<ctime>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<deque>
#include<queue>
#include<climits>
#include<list>
#include<stack>
#include<fstream>
#include<ctime>
#define all(n) n.begin(),n.end()
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define F first
#define S second
#define pb push_back
#define INF (1<<27)
#define EPS 1e-10
#define equals(a,b) (fabs((a)-(b)) < EPS)

using namespace std;

typedef pair<int,int> P;
typedef pair<P,P> PP;
typedef unsigned long long ull;
typedef long long ll;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};


int main(){

  int a,b;
  while(cin >> a >> b){
    int c = a+b;
    stringstream ss;
    ss << c;
    string ret;
    ss >> ret;   
    cout << ret.size() << endl;
  }

  ofstream ofs("out2.txt");
  for(int i=0;i<=10000;i++){
    ofs << string(100000,'?') << endl;
  }

return 0;
}

Measured memory_bytes: 1368
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const ll LINF = 1LL<<60;

#define int long long

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);

    int n, m, X; cin >> n >> m >> X;
    vector<int> c(n);
    vector<vector<int>> a(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        for (int j = 0; j < m; j++) cin >> a[i][j];
    }

    int ans = LINF;

    for (unsigned int x = 0; x < (1<<n); x++) {
        int cost = 0;
        vector<int> l(m, 0);
        for (int i = 0; i < n; i++) {
            if (x & (1<<i)) {
                cost += c[i];
                for (int j = 0; j < m; j++) l[j] += a[i][j];
            }
        }
        bool ok = true;
        for (auto j : l) if (j < X) ok = false;
        if (ok) ans = min(ans, cost);
    }

    if (ans == LINF) cout << -1 << endl;
    else cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3664
#include <cstdio>
using namespace std;
int d[31][31];
int f[31];
int s[31];
int t[31];

int dfs(int first,int second,int third){
    
    int sum = 0;
    
    for(int i=1;i<=30;i++) {
        
        sum += f[i] * d[i][first];
        sum += s[i] * d[i][second];
        sum += t[i] * d[i][third];
    }
    
    return sum;
    
    
}
int main(int argc, const char * argv[]) {
    
    int n,c,num;
    
    scanf("%d %d",&n,&c);
    
    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++){
            scanf("%d",&num);
            int tmp = (i+j)%3;
            if(tmp==0) f[num]++;
            else if(tmp==1) s[num]++;
            else t[num]++;
        }
    }
    int ans = 987654321;
    for(int i=1;i<=c;i++){
        for(int j=1;j<=c;j++){
            if(i==j) continue;
            for(int k=1;k<=c;k++){
                if(i==k || j==k) continue;
                int tmp = dfs(i,j,k);
                if(ans > tmp) ans = tmp;
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    ll x, k, d;
    cin >> x >> k >> d;
    if(x<0) x = -x;
    if(x/d >= k) cout << x - k*d;
    else {
        cout << (((k-x/d)%2==0)?x%d: d-x%d); 
    }
}

Measured memory_bytes: 3644
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int n;
string s;
const ll mod = 1e9+7;
const ll basemod[2] = {1007, 1000000021};
ll basepow[2][323456];
//sのハッシュを計算
ll cal_hash(const string &s){
    ll temp[2] = {};
    rep(i,s.size()){
        rep(j,2){
            temp[j] = (temp[j] * basemod[j] + (ll) s[i]) % mod;
        }
    }
    //return temp[0];
    //return make_pair(temp[0], temp[1]);
    return (ll)(temp[0]<<30) + temp[1];
}
void make(){
    rep(i,2){
        basepow[i][0] = 1;
        rep(j,323455){
            basepow[i][j+1] = (basepow[i][j] * basemod[i]) % mod;
        }
    }
}
vector<ll> precal(const string &s, ll base){
    if(basepow[0][0] == 0)make();
    vector<ll>res(s.size()+1,0);
    rep(i,s.size()){
        res[i+1] = (res[i] * base + (ll) s[i]) % mod;
    }
    return res;
}
//[l,r)0-index
//pre1 = precal(s,basemod[0]), pre2 = precal(s,basemod[1]);
ll cal_hash(int l, int r, vector<ll> &pre1,vector<ll> &pre2){
    ll a = (pre1[r] - pre1[l] * basepow[0][r-l]) % mod;
    a = (a + mod) % mod;
    ll b = (pre2[r] - pre2[l] * basepow[1][r-l]) % mod;
    b = (b + mod) % mod;
    return (ll)(a<<30) + b;
}

vector<ll> pre1,pre2;
bool ok(int k){
    map<ll,int> mp;
    bool f = false;
    for(int i = 0; i < n - k + 1; i++){
        show(i,k);
        ll h = cal_hash(i,i+k,pre1,pre2);
        if(mp.count(h)){
            if(mp[h] <= i - k)return true;
        }else{
            mp[h] = i;
        }
    }
    return false;
}
int main(){
    cin >> n >> s;
    int l = 0;
    int r = n;
    
    make();
    pre1 = precal(s, basemod[0]);
    pre2 = precal(s, basemod[1]);
    while(r - l > 1){
        int mid = (l + r) / 2;
        if(ok(mid)){
            l = mid;
        }else{
            r = mid;
        }
    }
    cout << l << endl;
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define PI 3.14159265358979323846
//#define v vector<long long>
using namespace std;
using ll = long long;

// ----本問について----
// 問題：二分探索
// 問題文URL：https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_4_B
// 所要時間：
// 学んだこと：
// ------------------

// ----ここから本問のソースコード----
const ll N_MAX = 100000 + 10;
const ll Q_MAX = 50000 + 10;

// グローバル変数（入力）
ll n, q, S[N_MAX], T[Q_MAX];

bool bsearch(const ll array[], ll left, ll right, ll value) {
  while (left + 1 < right){
    ll med = (left + right) / 2;
    if (array[med] > value) { right = med; }
    else {
      left = med;
    }
  }
  return array[left] == value;
}

void solve() { 
  ll ans = 0;
  rep(i, q) {
    if (bsearch(S, 0, n, T[i])) { ans++; }
  }
  cout << ans << endl;
}

int main() { 
  cin >> n;
  rep(i, n) { cin >> S[i]; }
  cin >> q;
  rep(i, q) { cin >> T[i]; }
  solve();
}



Measured memory_bytes: 4176
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// std::ios::sync_with_stdio(false);

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

typedef pair<LL,LL> PLL;
const LL inf = 1e18 + 1e9;

int main()
{
    /* #ifndef ONLINE_JUDGE */
    /*     freopen("foo", "rt", stdin); */
    /* #endif */
    int N;
    while (cin >> N) {
        LL minn = inf, maxx = 0;
        vector<PLL> A;
        multiset<LL> X,Y;
        FOR(i,0,N) {
            LL x,y; cin >> x >> y;
            if (x > y)
                swap(x,y);
            A.push_back(PLL(x,y)); X.insert(x); Y.insert(y);
            minn = min(minn,x);
            maxx = max(maxx,y);
        }
        sort(ALL(A));
        LL ans = inf;
        const LL rmin = minn, bmax = maxx;
        const LL rmax = *X.rbegin(), bmin = *Y.begin();
        const LL res = (rmax-rmin) * (bmax-bmin);
        ans = min(ans,res);
        FOR(i,0,N) {
            const LL x = A[i].first;
            const LL y = A[i].second;
            X.erase(X.find(x)); Y.insert(x);
            Y.erase(Y.find(y)); X.insert(y);
            const LL rmin = *Y.rbegin(), rmax = *Y.begin();
            const LL bmin = *X.rbegin(), bmax = *X.begin();
            const LL res = (rmax-rmin) * (bmax-bmin);
            ans = min(ans,res);
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 23020
#include <algorithm>
//#include <cstdio>
//#include <functional>
//#include <bits/stdc++.h>
#include <iostream>
//#include <cfloat>
//#include <climits>
//#include <cstdlib>
//#include <cstring>
//#include <cmath>
//#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
#include <string>
//#include <time.h>
//#include <vector>
//#include <random>
//#include <unordered_set>
//#include <complex>
#define rt0 return 0
using namespace std;
 
int main()
{
	int a,b,c,x,y;
	int temp;

	cin>>a>>b>>c>>x>>y;

	int ans=min((a*x+b*y),(c*2*max(x,y)));
	if(x>y) temp=a*(x-y);
	else temp=b*(y-x);
	ans=min(c*2*min(x,y)+temp, ans);
		
	cout<<ans;
    rt0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

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

  vector<int> imos(n+1, 0);
  for(int i = 0; i < n; i++){
    imos[i+1] = imos[i] + a[i];
  }

  map<int, int> mp;
  int ans = 0;
  for(int i = 0; i <= n; i++){
    ans += mp[imos[i]];
    mp[imos[i]]++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 15872
#define _USE_MATH_DEFINES

#include<iostream>
#include<cmath>
using namespace std;

long long n, a, b;
long long h[100000];

bool judge(long long x) {
    long long cnt = 0;
    for (int i = 0; i < n; i++) {
        long long hh = h[i] - b * x;
        if (hh > 0) {
            cnt += (hh / (a - b));
            if (hh % (a - b) != 0) cnt++;
        }
    }
    return cnt <= x;
}

int solve(int low, int high) {
    if (low + 1 >= high) {
        if(judge(low)) return low;
            else return high;
    }
    int mid = (low + high) / 2;

    if (judge(mid)) {
        high = mid;
    } else {
        low = mid;
    }
    return solve(low, high);
}

int main() {
    cin >> n >> a >> b;
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }

    cout << solve(0, 1000000000) << endl;

    return 0;
}

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

using namespace std;

int main() {
    int N;
    cin >> N;
    map<string, int> data;
    data["AC"] = 0;
    data["WA"] = 0;
    data["TLE"] = 0;
    data["RE"] = 0;

    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        data[s]++;
    }

    cout << "AC x " << data["AC"] << endl;
    cout << "WA x " << data["WA"] << endl;
    cout << "TLE x " << data["TLE"] << endl;
    cout << "RE x " << data["RE"] << endl;
}

Measured memory_bytes: 3600
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

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

    vector<ll> a(n + 3), pok(n + 3, 0), v(n + 3, 0);

    for (ll i = 0; i <= n; i++)
    {
        cin >> a[i];
    }

    pok[0] = 1 - a[0];

    for (ll i = 1; i <= n; i++)
    {
        pok[i] = min(pok[i - 1] * 2 - a[i], INF);
    }

    v[n] = a[n];

    ll ans = 0;

    for (ll i = n - 1; i >= 0; i--)
    {
        v[i] = min(v[i + 1], pok[i]) + a[i];
    }

    for (ll i = 0; i <= n; i++)
    {
        ans += v[i];

        if (pok[i] < 0)
        {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << ans << endl;
}


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

int main(){
  int n,m,l;
  while(true){
    cin >> l;
    if(l==0)break;

    bool f = false;
    for(int i=0;i<12;i++){
      cin >> m >> n;
      l -= m-n;
      if(l<=0 && !f){
	cout << i+1 << endl;
	f = true;
      }
    }
  
    if(!f)cout << "NA" << endl;
  }
}

Measured memory_bytes: 1160
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.do_main();
    }
    public void do_main() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int M = scan.nextInt();
        Complain[] complains = new Complain[M];
        for (int i = 0; i < M; i++) {
            Complain b = new Complain();
            b.from = scan.nextInt()-1;
            b.to = scan.nextInt()-1;
            complains[i] = b;
        }
        int answer = solve(M, complains);
        System.out.println(answer);
    }

    public int solve(int M, Complain[] complains) {
        Arrays.sort(complains, new ToComplainComparator());
        int answer = 0;
        int pos = 0;
        for (int i = 0; i < M; i++) {
            Complain c = complains[i];
            if (pos <= c.from) {
                answer += 1;
                pos = c.to;
            }
        }
        return answer;
    }
    class Complain {
        int from = 0;
        int to = 0;
    }
    class ToComplainComparator implements Comparator<Complain> {
        @Override
        public int compare(Complain o1, Complain o2) {
            int result = Integer.compare(o1.to, o2.to);
            if (result != 0) {
                return result;
            }
            int distance_1 = o1.to - o1.from;
            int distance_2 = o2.to - o2.from;
            return Integer.compare(distance_1, distance_2);
        }
    }
}


Measured memory_bytes: 91288
#include <bits/stdc++.h>
typedef long long int ll;
#define FOR(i, a, b) for (ll i = (signed)(a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define MOD 1000000007
#define pb push_back
#define INF 93193111451418101
#define MIN -93193111451418101
#define EPS 1e-11
#define tp(a, b, c) make_tuple(a, b, c)
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
#define ub(a, b) upper_bound((a).begin(), (a).end(), (b))
#define bitcnt(a) (ll) __builtin_popcount((a))
using namespace std;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
template <typename T> void fill_all(T &arr, const T &v) { arr = v; }
template <typename T, typename ARR> void fill_all(ARR &arr, const T &v) {
  for (auto &i : arr) {
    fill_all(i, v);
  }
}
//------------------変数-----------------------//
//-------------------関数----------------------//
int main() {
  ll n, m, red[114514], cnt[114514];
  cin >> n >> m;
  red[0] = 1;
  fill_all(cnt, (ll)1);
  REP(i, m) {
    ll x, y;
    cin >> x >> y;
    x--;
    y--;
    red[y] |= red[x];
    if (cnt[x] == 1) {
      red[x] = 0;
    }
    cnt[x]--;
    cnt[y]++;
  }
  cout << count(red, red + n, (ll)1) << endl;
}


Measured memory_bytes: 1920
#include <iostream>
#include <string>
using namespace std;
int main() {
    int h, w;
    cin >> h >> w;
    string s[h+10];
    for (int i = 1; i <= h; i++)
    {
        cin >> s[i];
    }
    for (int i = 1; i <= h; i++)
    {
        for (int j = 0; j < s[i].size(); j++)
        {
            if (s[i][j] == '.')
            {
                int sum = 0;
                if (j > 0)
                {
                    if (s[i][j-1] == '#')
                        sum++;
                    if (i > 1 && s[i-1][j-1] == '#')
                        sum++;
                    if (i < h && s[i+1][j-1] == '#')
                        sum++;
                }
                if (j < s[i].size() - 1)
                {
                    if (s[i][j+1] == '#')
                        sum++;
                    if (i > 1 && s[i-1][j+1] == '#')
                        sum++;
                    if (i < h && s[i+1][j+1] == '#')
                        sum++;
                }
                if ( i > 1 && s[i-1][j] == '#')
                    sum++;
                if ( i < h && s[i+1][j] == '#')
                    sum++;
                s[i][j] = sum + '0';
            }
        }
    }
    for (int i = 1; i <= h; i++)
        cout << s[i] << "\n";
}

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

int main() {

	long long A, B;
	long long V, W;
	long double T;

	cin >> A >> V;
	cin >> B >> W;
	cin >> T;

	long long dis = abs(A - B);
	long long dif = V - W;

	if (dif <= 0) {
		cout << "NO" << endl;
	}
	else {
		if (T >= ((long double)dis / (long double)dif)) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}

	return 0;
}



Measured memory_bytes: 3744
#include <stdio.h>
#include <stdlib.h>

int main(void){
	int n,q,i,j,s[10000],key,res=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",&key);
		for(i=0;i<n;i++){
			if(s[i] == key){
				res++;
				break;
			}
		}
	}
	printf("%d\n",res);
	return 0;
}


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

int N; list<pair<int, long>> E[100005];
long dist[100005];
bool visited[100005];

void dfs(int u, long d) {
  dist[u] = d;
  for (auto it = E[u].begin(); it != E[u].end(); it++) {
    if (!visited[it->first]) {
      visited[it->first] = true;
      dfs(it->first, d + it->second);
    }
  }
}

int main() {
  cin >> N;
  int a, b; long c;
  for (int i = 0; i < N-1; i++) {
    cin >> a >> b >> c; a--; b--;
    E[a].push_back(make_pair(b, c)); E[b].push_back(make_pair(a, c));
  }
  int Q, K; cin >> Q >> K; K--;
  for (int i = 0; i < N; i++) visited[i] = false;
  visited[K] = true;
  dfs(K, 0);
  int x, y;
  for (int i = 0; i < Q; i++) {
    cin >> x >> y; x--; y--;
    cout << dist[x] + dist[y] << endl;
  }
}

Measured memory_bytes: 20820
S = input()

ans = 'NA'
L = int(S[ : 2])
R = int(S[2 :])

if 13 > L > 0 and 13 > R > 0:
    ans = 'AMBIGUOUS'
elif 13 > R > 0:
    ans = 'YYMM'
elif  13 > L > 0:
    ans = 'MMYY'

print(ans)

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    string s;
    cin >> s;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == '1') {
            cout << 9;
        }
        else {
            cout << 1;
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define LL long long
template<class T> inline void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

int main(void) {
	int W, H, N;
	cin >> W >> H >> N;

	vector<vector<int> > area(H,vector<int>(W,1));
	rep(i, N) {
		int x, y, a;
		cin >> x >> y >> a;
		if (a == 1) {
			for (int i = 0; i < H; i++)
			{
				for (int j = 0; j < x; j++)
				{
					area[i][j] = 0;
				}
			}
		}
		else if (a == 2) {
			for (int i = 0; i < H; i++)
			{
				for (int j = x; j < W; j++)
				{
					area[i][j] = 0;
				}
			}
		}
		else if (a == 3) {
			for (int i = 0; i < y; i++)
			{
				for (int j = 0; j < W; j++)
				{
					area[i][j] = 0;
				}
			}
		}
		else {
			for (int i = y; i < H; i++)
			{
				for (int j = 0; j < W; j++)
				{
					area[i][j] = 0;
				}
			}
		}

		
	}

	int count = 0;
	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			count += area[i][j];
		}
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define eb emplace_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"LINE %d: (%s) = ",__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }

const ll MAXn=2e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;


vector<ll> ad,su;
int main(){
    IOS();
    ll n;
    cin >> n;
    for (int i=0;i<n;++i) {
        ll x,y;
        cin >> x >> y;
        ad.eb(x+y);
        su.eb(x-y);
    }
    sort(ALL(ad));
    sort(ALL(su));
    cout << max(ad[n-1] - ad[0],su[n-1] - su[0]) << endl;
}


Measured memory_bytes: 6692
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	int a[102][102];//应设为 102，若为101，则下面的空间不够j+1; 
	char ch;
	 int l1,l2;
	int n,m;
	cin>>n>>m;
	memset(a,0,sizeof(a));
	for(int i=1;i<=n;i++)
	  for(int j=1;j<=m;j++)
	  {
	  	cin>>ch;
	  	if(ch=='#')
	  	  a[i][j]=-1;
		}  
	for(int i=1;i<=n;i++)
	{
	for(int j=1;j<=m;j++)
	  {
	  if(a[i][j]==-1) 
	    cout<<"#";
	    else
	  {				  
	  if(a[i-1][j]==-1) a[i][j]++;
	  if(a[i-1][j-1]==-1) a[i][j]++;
	  if(a[i-1][j+1]==-1) a[i][j]++;
	  if(a[i][j-1]==-1) a[i][j]++;
	  if(a[i][j+1]==-1) a[i][j]++;
	  if(a[i+1][j-1]==-1) a[i][j]++;
	  if(a[i+1][j]==-1) a[i][j]++;
	  if(a[i+1][j+1]==-1) a[i][j]++;
	  cout<<a[i][j];	
	  }
	  
	  }	
	  cout<<endl;
	  }  
	 return 0;    
}

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

int abs(int x) {
	return x >= 0 ? x : -x;
}

int main() {
	int n;
	cin >> n;
	bool yes = true;
	int old_t = 0;
	int old_x = 0;
	int old_y = 0;
	for(int i=0;i<n;i++) {
		int t, x, y;
		cin >> t >> x >> y;
		int p = t - old_t - abs(x - old_x) - abs(y - old_y);
		yes = yes && p >= 0 && (p % 2 == 0);
		old_t = t;
		old_x = x;
		old_y = y;
	}
	cout << (yes ? "Yes" : "No") << endl;
	return 0;
}



Measured memory_bytes: 256
def main():
    from sys import setrecursionlimit, stdin, stderr
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: stderr.write("\033[92m{}\033[0m".format(str(something)+'\n'))) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**18+10
    N,K = LMIIS()
    P = list(map(lambda x: int(x)-1,input().split()))
    C = LMIIS()
    score_sets = []
    used = [False]*N
    tmp = P[0]
    for i in range(N):
        if not used[i]:
            tmp = i
            score_set = []
            while not used[tmp]:
                used[tmp] = True
                tmp = P[tmp]
                score_set.append(C[tmp])
            score_sets.append(score_set)
        
    ans = -INF
    for score_set in score_sets:
        # 合計が最大になる区間を探す
        len_set = len(score_set)
        sum_score_set_real = sum(score_set)
        # sum_score_set = max(0,sum_score_set_real)


        
        for i in range(len_set):
            cum_sum_1 = 0
            for j in range(i,min(len_set, i+K)):
                cum_sum_1 += score_set[j]
                num_move = j-i+1
                tmp_max = cum_sum_1
                if sum_score_set_real > 0:
                    tmp_max += (K - num_move) // len_set * sum_score_set_real

                ans = max(ans, tmp_max)

        for i in range(1,len_set-1):
            cum_sum_2 = sum_score_set_real
            for j in range(i,min(len_set-1-(K-i),len_set-1)):
                cum_sum_2 -= score_set[j]
            for j in range(max(i,len_set-1-(K-i)),len_set-1):
                cum_sum_2 -= score_set[j]
                num_move = len_set - (j-i+1)
                tmp_max = cum_sum_2
                if sum_score_set_real > 0:
                    tmp_max += (K - num_move) // len_set * sum_score_set_real
                ans = max(ans,tmp_max)






        
                
    print(ans)

    
main()

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

int a[3010][3010];
long long dp[3010][3010][4];
int n,m,k;

int main()
{
	scanf("%d%d%d",&n,&m,&k);
	int x,y,c;
	for(int i=1;i<=k;i++)
	{
		scanf("%d%d%d",&x,&y,&c);
		a[x][y]=c;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			dp[i][j][0]=max(dp[i][j-1][0],max(max(dp[i-1][j][0],dp[i-1][j][1]),max(dp[i-1][j][2],dp[i-1][j][3])));
			dp[i][j][1]=max(dp[i][j-1][0],max(max(dp[i-1][j][0],dp[i-1][j][1]),max(dp[i-1][j][2],dp[i-1][j][3])))+a[i][j];
			for(int k=1;k<=3;k++)
			{
				dp[i][j][k]=max(dp[i][j][k],dp[i][j-1][k]);
				dp[i][j][k]=max(dp[i][j][k],dp[i][j-1][k-1]+a[i][j]);
			}
		}
	}
	printf("%lld\n",max(max(dp[n][m][0],dp[n][m][1]),max(dp[n][m][2],dp[n][m][3])));
} 

Measured memory_bytes: 321256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define maxn 100005
using namespace std;
int n;
char s[maxn];
int main()
{
	scanf("%s",s+1); n=strlen(s+1);
	int ans=n;
	for(int i=2;i<=n;i++)
		if(s[i]!=s[i-1])
			ans=min(ans,max(i-1,n-i+1));
	printf("%d\n",ans);
}


Measured memory_bytes: 384
#include <cstdint>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;
#define ARRAY_SIZE 100001
static priority_queue<uint64_t, vector<uint64_t>, greater<uint64_t>> before;
static priority_queue<uint64_t, vector<uint64_t>, less<uint64_t>> after;
static int64_t maximums[ARRAY_SIZE];
static int64_t minimums[ARRAY_SIZE];

int32_t main()
{
  uint32_t num;
  cin >> num;

  static vector<uint64_t> array(3 * num);
  static vector<uint64_t> rev_array(3 * num);

  for (uint32_t i = 0; i < 3 * num; i++) {
    uint64_t v;
    cin >> v;
    array[i] = v;
    rev_array[3 * num - 1 - i] = v;
  }

  int64_t maximum = 0, minimum = 0;
  for (uint32_t k = 0; k < num; k++) {
    before.push(array[k]);
    maximum += array[k];

    after.push(rev_array[k]);
    minimum += rev_array[k];
  }
  maximums[0] = maximum;
  minimums[0] = minimum;

  for (uint64_t k = 0; k < num; k++) {
    maximum += array[num + k];
    before.push(array[num + k]);
    maximum -= before.top();
    before.pop();

    maximums[k + 1] = maximum;

    minimum += rev_array[num + k];
    after.push(rev_array[num + k]);
    minimum -= after.top();
    after.pop();

    minimums[k + 1] = minimum;
  }

  int64_t val = INT64_MIN;
  for (uint32_t i = 0; i <= num; i++) {
    val = max(val, maximums[i] - minimums[num - i]);
  }

  cout << val << endl;

  return 0;
}


Measured memory_bytes: 8300