akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc145/tasks/abc145_e>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    int N,T; cin >> N >> T;
    vector<ll> A(N),B(N);
    for(int i = 0; i < N;i++){
        cin >> A[i] >> B[i];
    }
    
    vector<vector<ll>> dp1(N+1,vector<ll>(T));
    vector<vector<ll>> dp2(N+1,vector<ll>(T));
    
    auto chmax = [](ll& l,const ll r){
        l = max(l,r);
    };
    // 右から
    for(int i = 0; i < N;i++){
        for(int j = 0; j < T;j++){
            chmax(dp1[i+1][j],dp1[i][j]);
            if(j+A[i]<T) chmax(dp1[i+1][j+A[i]],dp1[i][j]+B[i]);
        }
    }
    // 左から
    for(int i = N-1; i >= 0; i--){
        for(int j = 0; j < T;j++){
            chmax(dp2[i][j],dp2[i+1][j]);
            if(j+A[i]<T) chmax(dp2[i][j+A[i]],dp2[i+1][j]+B[i]);
        }
    }
    
    for(int i = 0; i < N;i++){
        for(int j = 0; j <= T-1;j++){
            res = max(res,dp1[i][j]+dp2[i+1][T-1-j]+B[i]);
        }
    }
    
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 141184
#include<stdio.h>
int main()
{
  int n,m,r,t;
  char a[100],b[100],c[100];
  scanf("%s",&a);
  scanf("%s",&b);
  scanf("%d %d",&n,&m);
  scanf("%s",&c);
  r = strcmp(a,c);
  if(r==0)
  {
      n= n-1;
  }
  else
  {
      m= m-1;
  }
  printf("%d %d",n,m);
  return 0;
}


Measured memory_bytes: 1716
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < n; i++)
        {
            var s = Console.ReadLine().Trim();
            if (s.Substring(0, 2) == ">'" && checkA(s)) Console.WriteLine("A");
            else if (s.Substring(0, 2) == ">^" && checkB(s)) Console.WriteLine("B");
            else Console.WriteLine("NA");
        }
    }
    public static bool checkA(string s)
    {
        if (s[s.Length - 1] != '~') return false;
        var sL = s.Length;
        var a1 = s.Substring(2, sL - 3);
        if (a1.Length % 2 == 0 | a1.Length == 1) return false;
        var t = (a1.Length - 1) / 2;
        if (a1[t] != '#') return false;
        if (a1.Replace("=", "") != "#") return false;
        return true;
    }
    public static bool checkB(string s)
    {
        var sL = s.Length;
        if (s.Substring(sL - 2) != "~~") return false;
        var a1 = s.Substring(2, sL - 4);
        if (a1.Length % 2 == 1 | a1.Length == 0) return false;
        for (int i = 0; i <= a1.Length - 2; i += 2)
            if (a1.Substring(i, 2) != "Q=") return false;
        return true;
    }
}

Measured memory_bytes: 9384
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
	if(was_output)cout << " ";
	cout << a;
	was_output = true;
}
void outendl(){
	was_output = false;
	cout << endl;
}


ll func(int n){
	ll MAX_HP = 0;
	vector<ll> hps(n);
	foreach(i, hps)cin>>i;
	foreach(i, hps)chmax(MAX_HP, i);
	int m;
	cin >> m;
	vector<pll> single_magic;
	vector<pll> wide_magic;
	rep(i, m){
		string name;
		ll mp, damage;
		cin >> name >> mp >> name >> damage;
		if(name=="All"){
			wide_magic.emplace_back(mp, damage);
		}else{
			single_magic.emplace_back(mp, damage);
		}
	}
	vector<ll> dp(MAX_HP+1, INFLL);
	dp[0] = 0;
	rep(i, MAX_HP){
		rep(j, single_magic.size()){
			int next_damage = min(MAX_HP, i + single_magic[j].second);
			ll next_mp = dp[i] + single_magic[j].first;
			chmin(dp[next_damage], next_mp);
		}
	}
	vector<pll> mins;
	//damage mp
	mins.emplace_back(INFLL, INFLL);
	per(i, MAX_HP+1){
		if(mins.back().second>dp[i]){
			mins.emplace_back(i, dp[i]);
		}
	}
	reverse(all(mins));
	dp.assign(MAX_HP+1, INFLL);
	dp[0] = 0;
	rep(i, MAX_HP){
		rep(j, wide_magic.size()){
			int next_damage = min(MAX_HP, i + wide_magic[j].second);
			ll next_mp = dp[i] + wide_magic[j].first;
			chmin(dp[next_damage], next_mp);
		}
	}
	
	ll res = INFLL;
	rep(wide, MAX_HP+1){
		ll sum = dp[wide];
		rep(i, n){
			int now_hp = hps[i] - wide;
			sum += lower_bound(all(mins), pll(now_hp, 0))->second;
			chmin(sum, INFLL);
		}
		chmin(res, sum);
	}

	return res;

}

int main(){
	int n;
	while(cin>>n&&n){
		cout << func(n) << endl;
	}
	return 0;
}



Measured memory_bytes: 4020
N = int(input())
A = [ int(input()) for i in range(N)]

_A =sorted(A, reverse=True)
A_max = _A[0]
A_second_max = _A[1]

for i in range(N):
    if A[i] == A_max:
        print(A_second_max)
    else:
        print(A_max)

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


int seg[400005];
int lz[400005];
void build(int ver,int tl,int tr)
{
    if(tl>tr)
        return ;
    else if(tl==tr)
    {
        lz[ver]=1e17;
        seg[ver]=1e17;
    }
    else
    {
        int tm=(tl+tr)/2;
        build(2*ver,tl,tm);
        build(2*ver+1,tm+1,tr);
        seg[ver]=1e17;
        lz[ver]=1e17;
    }
}

void push(int ver)
{
    seg[2*ver]=min(seg[2*ver],lz[ver]);
    seg[2*ver+1]=min(seg[2*ver+1],lz[ver]);
    lz[2*ver]=min(lz[2*ver],lz[ver]);
    lz[2*ver+1]=min(lz[2*ver+1],lz[ver]);
    lz[ver]=1e17;
}

void upd(int ver,int tl,int tr,int l,int r,int val)
{
    if(tl>tr||l>r||tr<l||r<tl)
        return ;
    else if(tl==l&&tr==r)
    {
        seg[ver]=min(seg[ver],val);
        lz[ver]=min(lz[ver],val);
    }
    else
    {
        int tm=(tl+tr)/2;
        if(lz[ver]!=1e17)
            push(ver);
        upd(2*ver,tl,tm,l,min(tm,r),val);
        upd(2*ver+1,tm+1,tr,max(tm+1,l),r,val);
        seg[ver]=min(seg[2*ver],seg[2*ver+1]);
    }    
}

int get(int ver,int tl,int tr,int l,int r)
{
    if(tl>tr||l>r||tr<l||r<tl)
        return 1e17;
    else if(tl==l&&tr==r)
    {
        return seg[ver];
    }
    else
    {
        int tm=(tl+tr)/2;
        if(lz[ver]!=1e17)
            push(ver);
        int z= min(get(2*ver,tl,tm,l,min(tm,r)),get(2*ver+1,tm+1,tr,max(tm+1,l),r));
        seg[ver]=min(seg[2*ver],seg[2*ver+1]);
        return z;        
    }    
}

signed main()
{
 
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   
 
#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif      

    int n,m;
    cin>>n>>m;
    int x,y,z;
    vector<pair<pair<int,int>,int> >pp;
    for(int i=0;i<m;i++)
    {
        cin>>x>>y>>z;
        pp.push_back({{x,y},z});
    }
    build(1,1,n);
    sort(pp.begin(),pp.end());
    upd(1,1,n,1,1,0);
    for(auto i:pp)
    {
        int z=get(1,1,n,i.first.first,i.first.first);
        upd(1,1,n,i.first.first,i.first.second,z+i.second);
    }
    z=get(1,1,n,n,n);
    if(z==1e17)
        cout<<-1;
    else
        cout<<z;

}

Measured memory_bytes: 9764
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 500005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
char s[MAXN];
int N;
int nxt[MAXN],suf[MAXN];
bool vis[MAXN];
int gcd(int a,int b) {
    return b == 0 ? a : gcd(b,a % b);
}
void Solve() {
    scanf("%s",s + 1);
    N = strlen(s + 1);
    for(int i = 2 ; i <= N ; ++i) {
	int p = nxt[i - 1];
	while(p && s[p + 1] != s[i]) p = nxt[p];
	if(s[p + 1] == s[i]) nxt[i] = p + 1;
	else nxt[i] = 0;
    }
    if(nxt[N] == N - 1) {
	out(N);enter;puts("1");
    }
    else if(nxt[N] == 0 || N % (N - nxt[N]) != 0) {
	puts("1");puts("1");
    }
    else {
	int cnt = 0,l = N - nxt[N];
	suf[N] = N + 1;
	for(int i = N - 1 ; i >= 1 ; --i) {
	    int p = suf[i + 1];
	    while(p <= N && s[p - 1] != s[i]) p = suf[p];
	    if(s[p - 1] == s[i]) suf[i] = p - 1;
	    else suf[i] = N + 1;
	}
	for(int i = N - 1 ; i > 1 ; --i) {
	    if(suf[i] - i < (N + 1 - i) && (N + 1 - i) % (suf[i] - i) == 0) vis[i - 1] = 1;
	}
	for(int i = 2 ; i <= N ; ++i) {
	    if(i - nxt[i] < i && i % (i - nxt[i]) == 0) vis[i] = 1;
	}
	for(int i = 1 ; i < N ; ++i) {
	    if(!vis[i]) ++cnt;
	}
	puts("2");out(cnt);enter;
    }
}

int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 5120
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#define MOD 1000000007ll

using namespace std;

using ii = pair<int, int>;
using i64 = long long int;
using ii64 = pair<long long int, long long int>;

int main()
{
	i64 x, y;
	scanf("%lld %lld", &x, &y);

	int k = 0;
	while (x <= y)
	{
		x *= 2;
		k++;
	}

	printf("%d", k);

	return 0;
}



Measured memory_bytes: 256
#include <cassert>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
#include "limits.h"
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " <<"LINE:"<<__LINE__<<"  "<< #i <<":"<< i << std::endl

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<ll, ll>;

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

  ll n;
  std::cin>>n;

  ll max=0;
  std::vector<ll> a(n);
  std::vector<bool> used(n,false);
  rep(i,0,n){
    std::cin>>a[i];
    chmax(max,a[i]);
  }

  if(max%2){
    rep(_,0,2){
      for(ll i=max;i>=(max+1)/2;i--){
        bool isok=false;
        rep(j,0,n){
          if(a[j]==i&&!used[j]){
            isok=true;
            used[j]=true;
            break;
          }
        }
        if(!isok){
          std::cout<<"Impossible\n";
          return 0;
        }
      }
    }

    rep(i,0,n){
      if(!used[i]&&a[i]<=(max+1)/2){
        std::cout<<"Impossible\n";
        return 0;
      }
    }

    std::cout<<"Possible\n";
  }else{
    rep(_,0,2){
      for(ll i=max;i>=max/2+1;i--){
        bool isok=false;
        rep(j,0,n){
          if(a[j]==i&&!used[j]){
            isok=true;
            used[j]=true;
            break;
          }
        }
        if(!isok){
          std::cout<<"Impossible\n";
          return 0;
        }
      }
    }

    {
      bool isok=false;
      rep(j,0,n){
        if(a[j]==max/2&&!used[j]){
          isok=true;
          used[j]=true;
          break;
        }
      }
      if(!isok){
        std::cout<<"Impossible\n";
        return 0;
      }
    }

    rep(i,0,n){
      if(!used[i]&&a[i]<=max/2){
        std::cout<<"Impossible\n";
        return 0;
      }
    }

    std::cout<<"Possible\n";
  }

  return 0;
}

Measured memory_bytes: 256
import math
Q=int(input())
MAX=10**5
lim=int(math.sqrt(MAX))
primes=[2]
table=[i+1 for i in range(2,MAX,2)]
while lim>table[0]:
  primes.append(table[0])
  table=[j for j in table if j%table[0]!=0]
primes=set(primes+table)

ans=[0]*(MAX+1)
for i in range(3,MAX+1,2):
  if i in primes and (i+1)//2 in primes:
    ans[i]=1
for i in range(1,MAX+1):
  ans[i]=ans[i]+ans[i-1]
for _ in range(Q):
  l,r=map(int,input().split())
  print(ans[r]-ans[l-1])

Measured memory_bytes: 13148
//package AtCoder_163;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args)throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int r=Integer.parseInt(br.readLine());
        System.out.println(2*Math.PI*r);
    }
}


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

ll n,k;
vector<ll> v(101);

ll solve(){
	ll dp[n+2][k+2];
	
	for(ll i=0;i<=k;i++){
	  dp[1][i]=(i > v[1])?0:1;
	}
	
	for(ll i=2;i<=n;i++){
		for(ll j=0;j<=k;j++){
			if(j==0)
				dp[i][j]=dp[i-1][j]%mod;
			else{
				dp[i][j]=(mod + dp[i][j-1]+dp[i-1][j]-((j-v[i]-1>=0)?dp[i-1][j-v[i]-1]:0))%mod;
			}
		}
	}
	return dp[n][k]%mod;
}

int main(){
	cin>>n>>k;
	for(ll i=1;i<=n;i++){
		cin>>v[i];
	}
	cout<<solve()<<endl;
}

Measured memory_bytes: 78976
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef map<int, int> mii;
typedef map<ll, ll> mll;

const int INF = 1000000000;
const int MOD = 1000000007;

ll powMod(ll n, ll p, ll m) {
	if (p == 0) return 1;
	if (p == 1) return n % m;
	ll e = powMod(n, p / 2, m);
	e = (e * e) % m;
	if (p & 1)
		e = (e * n) % m;
	return e;
}

ll fn(ll i, vll &ns) {
	if (ns[i] != -1)
		return ns[i];
	return 1 + fn(i % __builtin_popcount(i), ns);
}

int main() {FIN
    
    ll n, m = 0, i, p, d;
    string s;
    cin >> n;
    vll ns(n + 1, -1);
    vvll md(n + 1, vll(2));
    cin >> s;
    for (i = 0; i < n; i++)
		if (s[i] == '1') m++;
	
	ns[0] = 0;
	for (i = 1; i <= n; i++) {
		ns[i] = fn(i, ns);
	}
	
	if (m - 1 > 0) {
		p = 1;
		for (i = n - 1; i >= 0; i--) {
			if (s[i] == '1')
				md[i][0] = (md[i + 1][0] + p) % (m-1); 
			else
				md[i][0] = md[i + 1][0];
			p = (2 * p) % (m-1);
		}
	}
	if (m + 1 <= n) {
		p = 1;
		for (i = n - 1; i >= 0; i--) {
			if (s[i] == '1')
				md[i][1] = (md[i + 1][1] + p) % (m+1); 
			else
				md[i][1] = md[i + 1][1];
			p = (2 * p) % (m+1);
		}
	}
	
	for (i = 0; i < n; i++) {
		if (s[i] == '1') {
			d = m > 1 ? (1 + ns[((md[i + 1][0] + (((md[0][0] - md[i][0]) + (m-1)) % (m-1))) % (m-1))]) : 0;
		} else {
			d = 1 + ns[((((md[i + 1][1] + (((md[0][1] - md[i][1]) + (m+1)) % (m+1))) % (m+1)) + powMod(2, n-i-1, m+1)) % (m+1))];
		}
		cout << d << "\n";
	}
    
    return 0;
}


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

using namespace std;

#define debug(x) cerr << endl << "DEBUG: (" << (#x) << " = " << x << ")" << endl;
#define debugArray(v) for (auto i : v) cerr << i << " "; cerr << endl;

const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const long long INFLL = 0x3f3f3f3f3f3f3f3fLL;
const long double EPS = 1e-9;
const long double PI = acos(-1.0);

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

    int a;

    cin >> a;
    cout << a + (a * a) + (a * a * a) << endl;

    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int A, B;

int main()
{
    cin >> A >> B;
    A--, B--;

    vector<vector<char>> grid(100, vector<char>(100));
    for (int i = 0; i < 100; i++)
    {
        for (int j = 0; j < 100; j++)
        {
            if (i < 50)
                grid[i][j] = '#';
            else
                grid[i][j] = '.';
        }
    }

    for (int i = 0; i < 49 && A > 0; i += 2)
    {
        for (int j = 0; j < 100 && A > 0; j += 2)
        {
            grid[i][j] = '.';
            A--;
        }
    }

    for (int i = 51; i < 100 && B > 0; i += 2)
    {
        for (int j = 0; j < 100 && B > 0; j += 2)
        {
            grid[i][j] = '#';
            B--;
        }
    }

    puts("100 100");

    for (int i = 0; i < 100; i++)
    {
        for (int j = 0; j < 100; j++)
        {
            cout << grid[i][j];
        }
        cout << "\n";
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
 
#define barsik ios::sync_with_stdio(false)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::unordered_set <int> u_si;
const double PI = acos(-1);
const long double EPS = 1e-9;
using namespace std;

void solve(){
    int n;
    cin >> n;
    int a[140];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n);
    int sum1 = 0, sum2 = 0;
    bool ok = true;
    for(int i = n - 1; i >= 0; i--){
        if(ok){
            sum1 += a[i];
            ok = false;
        }
        else{
            sum2 += a[i];
            ok = true;
        }
    }
    cout << sum1 - sum2;
}

int main(){
    int q = 1;
    //cin >> q;}
    while(q--) solve();
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007

using namespace std;

int main(void) {
	int total = 0;
	int n;
	int t;
	
	while (cin >> n) {
		total = 0;
		t = 600 - n;
		while (t>0) {
			total += t*t*n;
			t -= n;
		}
		cout << total << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3092
///HELLO THERE~!
///CREATED BY MD SADMAN MEHEDI SIVAN(IUT CSE[SWE'19])

#include<bits/stdc++.h>
using namespace std;

#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define READ            freopen("input.txt","r",stdin);
#define WRITE           freopen("red.txt","w",stdout);

using ll=long long;
using ull=unsigned long long;
const double pi = 2*acos(0.0);
const long long MX = 2e5+7;
 vector<ll>v;

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

   vector<pair<ll,ll>>v;

   for(ll i=0;i<n;i++)
   {
       ll r;
       cin>>r;
       v.push_back(make_pair(r,i+1));
   }
   sort(v.begin(),v.end());

   for(ll i=0;i<v.size();i++)
   {
       cout<<v[i].second<<" ";
   }



}


Measured memory_bytes: 5368
from itertools import combinations
N, K = map(int, input().split())

def solve():
    uni = []  # max is uni !!!
    for i in range(N-1):
        v = i + 2
        uni.append((1, v))
    f = (N - 1) * (N - 2) // 2

    for edge in combinations(range(2, N+1), 2):
        if f == K:
            break
        uni.append(edge)
        f -= 1
    
    return len(uni), uni
    

if K > (N - 1) * (N - 2) // 2:
    print(-1)
else:
    M, G = solve()
    print(M)
    for g in G:
        print(g[0], g[1])

Measured memory_bytes: 3992
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
print((1000-n%1000)%1000)

Measured memory_bytes: 65524
#include<stdio.h>

typedef struct model{
  char suit;
  int num;

}Card;

int BubbleSort(Card [], int);
int SelectionSort(Card [], int);
int Compare(Card [], Card[], int);

int main()
{
  int n;
  int i;
  Card A[40]={};
  Card B[40]={};
  char card[3];
  
  scanf("%d",&n);

  for(i=0;i < n;i++){
    scanf("%s",card);
    A[i].suit = card[0];
    A[i].num = (int)(card[1]-'0');

    B[i] = A[i];
  }

  BubbleSort(A,n);
  for(i=0;i < n;i++){
    if(i) printf(" ");
    printf("%c%d",A[i].suit, A[i].num);
  }
  printf("\n");
  printf("Stable\n");

  SelectionSort(B,n);
  for(i=0;i < n;i++){
    if(i) printf(" ");
    printf("%c%d",B[i].suit, B[i].num);
  }
  printf("\n");
  
  if( Compare(A,B,n) ){
    printf("Stable\n");
  }
  else printf("Not stable\n");

  return 0;
}

int BubbleSort(Card A[],int n)
{
  int i,j;
  Card temp;
  
  for(i=0;i < n;i++){
    for(j=n-1;j > i;j--){
      if(A[j-1].num > A[j].num){
	temp = A[j-1];
	A[j-1] = A[j];
	A[j] = temp;
      }
    }
  }
  return 0; 
}

int SelectionSort(Card A[],int n)
{
  int i,j;
  
  int mini;
  Card temp;
  
  for(i=0;i < n;i++){
    mini = i;
    
    for(j = i+1;j < n;j++){
      if(A[j].num < A[mini].num) mini = j;
    }
    
    temp = A[mini];
    A[mini] = A[i];
    A[i] = temp;
  }
  return 0; 
}

int min(int a, int b)
{
  if(a < b) return a;
  else return b;
}

int Compare(Card A[], Card B[], int n)
{
  int i;

  for(i=0;i < n;i++){
    if(A[i].suit != B[i].suit){
      return 0;
    }
  }
  return 1;
}



Measured memory_bytes: 2144
import sys
readline=sys.stdin.readline

S=readline().rstrip()
Q=int(readline())

cur=True
front=""
back=""
for i in range(Q):
  q=list(readline().rstrip().split())
  if q[0]=="1":
    cur^=True
  elif q[0]=="2":
    f,c=q[1],q[2]
    if f=="1":
      if cur:
        front+=c
      else:
        back+=c
    elif f=="2":
      if cur:
        back+=c
      else:
        front+=c
front=front[::-1]
ans=front+S+back
if not cur:
  ans=ans[::-1]
  
print(ans)
    


Measured memory_bytes: 4396
#include<bits/stdc++.h>
#define reg register
typedef long long ll;
using namespace std;
const int MN=3e5+5;
int n,m,L[MN],R[MN],id[MN];
int d[MN];
#define lowbit(x) (x&-x)
inline void update(int x,int v){while(x<=m)d[x]+=v,x+=lowbit(x);}
inline void update(int l,int r,int v){update(l,v);update(r+1,-v);}
inline int query(int x){reg int res=0;while(x)res+=d[x],x-=lowbit(x);return res;}
int main(){
	scanf("%d%d",&n,&m);
	for(reg int i=1;i<=n;i++)scanf("%d%d",L+i,R+i),id[i]=i;
	sort(id+1,id+1+n,[](int a,int b){
		return R[a]-L[a]<R[b]-L[b];
	});
	reg int cur=1,Ans;
	for(reg int d=1;d<=m;d++){
		while(cur<=n&&R[id[cur]]-L[id[cur]]+1<d)
			update(L[id[cur]],R[id[cur]],1),cur++;
		Ans=n-cur+1;
		for(reg int i=d;i<=m;i+=d)Ans+=query(i);
		printf("%d\n",Ans);
	}
	return 0;
}

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

int main(){
    int N;string S;
    cin>>N>>S;
    long long r=0,g=0,b=0;
    for(auto c:S){
        if(c=='R')++r;
        else if(c=='G')++g;
        else ++b;

    }
    long long all=r*g*b;
    long long sub=0;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            if(S[i]==S[j])continue;
            int k=2*j-i;
            if(k>=N || S[i]==S[k]||S[j]==S[k])continue;
            sub++;
        }
    }
    cout<<all-sub<<endl;
}

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

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

long long MOD = 1000000000 + 7;
long long MAX = 1000000000000000000;

int main(){
  cout << setprecision(10);
  int N;
  cin >> N;
  for(int i = 0; i <= 50000; i++){
    int x = (double)(i) * 1.08;
    if(N == x){
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = int(input())
btree = list(map(int, input().split()))

for i in range(1, N + 1):
    result = ""
    result += "node {0}: key = {1}, ".format(i, btree[i - 1])
    if i // 2 > 0:
        result += "parent key = {0}, ".format(btree[(i // 2) - 1])
    if i * 2 <= N:
        result += "left key = {0}, ".format(btree[i * 2 - 1])
    if i * 2 + 1 <= N:
        result += "right key = {0}, ".format(btree[i * 2])

    print(result)


Measured memory_bytes: 5628
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

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

signed main() {
  init();
  ll N;
  cin >> N;
  COUT(24 - N + 24);
  return 0;
}

Measured memory_bytes: 3624
# include <bits/stdc++.h>
 
/*
// ordered_set 
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
# define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
*/
 
using namespace std;
 
typedef long long                                        ll;
typedef long double                                      ld;
typedef pair <int, int>                                  pii;
typedef pair <pii, int>                                  ppi;
typedef pair <int, pii>                                  pip;
typedef pair <pii, pii>                                  ppp;
typedef pair <ll, ll>                                    pll;
 
# define A                                               first
# define B                                               second
# define endl                                            '\n'
# define sep                                             ' '
# define all(x)                                          x.begin(), x.end()
# define kill(x)                                         return cout << x << endl, 0
# define SZ(x)                                           int(x.size())
# define Sort(x)                                         sort(all(x))
# define InTheNameOfGod                                  ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
 
ll power(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));}
 
const int xn = 5e3 + 10;
const int xm = - 20 + 10;
const int SQ = 320;
const int sq = 320 + 10;
const int inf = 1e9 + 10;
const ll INF = 1e18 + 10;
const int MOD = 1e9 + 7;
const int TM = 3;
const int BASE = 257;

ll n, m, dp[xn][xn];
string s;

int main(){
    InTheNameOfGod;
    
	cin >> n >> s;
	m = s.size();
	dp[0][0] = 1;
	for (int i = 1; i <= n; ++ i){
		for (int j = 0; j <= i; ++ j){
			dp[i][j] = dp[i - 1][j + 1];
			if (j) dp[i][j] = (dp[i][j] + dp[i - 1][j - 1] + dp[i - 1][j - 1]) % MOD;
			if (!j) dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;
		}
	}
	cout << dp[n][m] * power(power(2, m, MOD), MOD - 2, MOD) % MOD;

    return 0;
}


Measured memory_bytes: 120276
#include <bits/stdc++.h>
#define rep(i , n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({a * c , a * d , b * c , b * d}) << endl;
}


Measured memory_bytes: 3636
N, M = map(int, input().split())
ab = []
for _ in range(M):
    ab.append(tuple(map(int, input().split())))

bucket = [0] * N
for el in ab:
    a, b = el
    bucket[a - 1] += 1
    bucket[b - 1] += 1
if all([x % 2 == 0 for x in bucket]):
    print('YES')
else:
    print('NO')

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

int main() {
  int countA, countB;
  string S;
  cin >> S;
  for (int i=0; i<S.size(); i++) {
    if (S.at(i) == 'o') countA++;
    else countB++;
  }
  if (countA >= 7 && countB <= 7) cout << "YES" << endl;
  else cout << "NO" << endl;
}



Measured memory_bytes: 256
M, D = map(int, input().split())

ans = 0
for m in range(1, M+1):
    for i in range(1, 10):
        if m%i == 0 and i >= 2:
            k = m//i
            if 2 <= k <= 9 and 10*i+k <= D:
                ans += 1
print(ans)

Measured memory_bytes: 3060
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    static int N;
    static int[] a;
    static int[] b;
    static PriorityQueue<Pair> queue;

    private static void init() {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        a = new int[N];
        b = new int[N];
        queue = new PriorityQueue<>();

        for(int i = 0; i < N; i++) {
            int cost = scanner.nextInt();
            int end = scanner.nextInt();
//            a[i] = cost;
//            b[i] = end;

            Pair p = new Pair(cost, end);
            queue.add(p);
        }
        scanner.close();
    }


    public static void main(String[] args) {
        init();


        int time = 0;
        boolean isFinished = true;
        while (!queue.isEmpty()) {
            Pair p = queue.poll();
            time += p.first;
            if(p.second < time) {
                isFinished = false;
                break;
            }
        }

        if(isFinished) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

class Pair implements Comparable<Pair> {
    long first;
    long second;

    public Pair(long first, long second) {
        this.first = first;
        this.second = second;
    }

    public long getSecond() {
        return second;
    }

    @Override
    public int compareTo(Pair p) {
        if(this.second < p.second) {
            return -1;
        } else if(this.second > p.second) {
            return 1;
        } else if(this.first > p.second) {
            return -1;
        } else if(this.first < p.second) {
            return 1;
        } else {
            return 0;
        }
    }

}

Measured memory_bytes: 110008
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;
struct abcd{
    int a,b,c,d;
};

vector<abcd> vec;
int N,M,Q;

template<typename T>
void cout_vec(vector<T> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

vector<int> arr;
int calc(){
    int ret=0;
    for(auto x: vec){
        if(arr[x.b]-arr[x.a]==x.c){
            ret+=x.d;
        }
    }
    return ret;
}

int full_search(int n){
    if(n==N){
        return calc();
    }
    
    int max_=arr[n-1];
    int ret=0;
    for(int i=max_; i<=M; i++){
        arr[n]=i;
        ret=max(ret,full_search(n+1));
    }
    return ret;
}

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

    vec=vector<abcd>(0);
    for(int i=0; i<Q; i++){
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        a--;b--;
        vec.push_back((abcd){a,b,c,d});
    }

    arr = vector<int>(10,1);
    cout << full_search(1) << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " =", (x), " "
#define A(a, i) #a "[" #i " =", i, "] =", a[i], " "
const int MXN = 1e6+6;
string s[MXN];
int mi[MXN];
int mi_rev[MXN];
int sum[MXN];

int main()
  {
  ios_base::sync_with_stdio(0); 
  int n;
  cin >> n;
  VI all;
  REP(i, n)
    {
    cin >> s[i];
    for(auto j: s[i])
        {
        sum[i] += (j == '(') ? 1 : -1;
        mini(mi[i], sum[i]);
        }
    all.PB(i);

    reverse(ALL(s[i]));
    int ss = 0;
    for(auto j: s[i])
      {
      ss += j == ')' ? 1 : -1;
      mini(mi_rev[i], ss);
      }
    }
  sort(ALL(all), [&](int a, int b){
    if((sum[a] >= 0) != (sum[b] >= 0))return (sum[a] >= 0) > (sum[b] >= 0);
    if(sum[a] >= 0)
      {
      return mi[a] > mi[b];
      }
    else
      {
      return mi_rev[a] < mi_rev[b];
      }
  });

  int s = 0;
  for(auto i: all)
    {
    if(s + mi[i] < 0)
      {
      puts("No");
      return 0;
      }
    s += sum[i];
    }
  if(s == 0)puts("Yes");
  else puts("No");
  }


Measured memory_bytes: 50400
n, x = map(int, input().split())

a, p = [1], [1]

for i in range(n):
  a.append(a[i] * 2 + 3)
  p.append(p[i] * 2 + 1)

def f(N, X):
  if N == 0:
    if X <= 0:
      return 0
    else:
      return 1  
  elif X <= 1 + a[N - 1]:
    return f(N - 1, X - 1)
  else:
    return p[N - 1] + 1 + f(N - 1, X - 2 - a[N - 1])

print(f(n, x))

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

using namespace std;
using ll = long long;
template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  string L;
  cin >> L;
  int n = (int)L.length();
  ll dp[L.length()+1][2] = {{0},{0}}; //0は等しい,1は小さい
  dp[0][0] = 1;
  REP(i,n) {
    if(L[i]=='1'){
      //small -> small
      dp[i+1][1] += dp[i][1]*3;
      //eq -> small
      dp[i+1][1] += dp[i][0];
      //eq -> eq
      dp[i+1][0] += dp[i][0]*2;
      
      dp[i+1][0] %= MOD;
      dp[i+1][1] %= MOD;
    }else {
      //small -> small
      dp[i+1][1] += dp[i][1]*3;
      //eq -> eq
      dp[i+1][0] += dp[i][0];
      
      dp[i+1][0] %= MOD;
      dp[i+1][1] %= MOD;
    }
  }
  cout << (dp[n][0]+dp[n][1])%MOD << endl;
  return 0;
}

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

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

    if(x=="Sunny"){
        cout<<"Cloudy"<<endl;
    }else if(x=="Cloudy"){
        cout<<"Rainy"<<endl;
    }else{
        cout<<"Sunny"<<endl;
    }

    return 0;
}

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

const int dy[4] = {0, 1, 0, -1};
const int dx[4] = {1, 0, -1, 0};
const int MAX_H = 30;
const int MAX_W = 30;

int h, w;
char maze[MAX_H][MAX_W];

const int INI = -1;
int dist[MAX_H][MAX_W];

int bfs2(int sy, int sx)
{
    if(maze[sy][sx] == '#') return 0;

    /*初期化*/
    rep(i, MAX_H) rep(j, MAX_W) dist[i][j] = INI;
    dist[sy][sx] = 0;

    queue<P> que;
    que.push(P(sy, sx));

    while(que.size())
    {
        auto p = que.front();
        que.pop();
        rep(i, 4)
        {
            int ny = p.first + dy[i], nx = p.second + dx[i];
            if(ny >= 0 && nx >= 0 && ny < h && nx < w && 
            dist[ny][nx] == INI && maze[ny][nx] != '#')
            {
                que.push(P(ny, nx));
                dist[ny][nx] = dist[p.first][p.second] + 1;
            }
        }

    }

    int ret = 0;
    rep(i, h) rep(j, w) ret = max(ret, dist[i][j]);

    return ret;
}



int main()
{
    cin >> h >> w;
    rep(i, h) rep(j, w) cin >> maze[i][j];
    
    int res = 0;
    rep(i, h)
    {
        rep(j, w)
        {
            res = max(bfs2(i, j), res);
        }
    }
    cout << res << endl;

    return 0;
}

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

int main() {
  ll n,t;cin>>n>>t;
  vector<ll> vec(n);
  rep(i,n)cin>>vec[i];
  int ans=t;
  rep(i,n-1){
    ans+=min(t,vec[i+1]-vec[i]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4828
chaser_init, chaser_move = map(int, input().split())
target_init, target_move = map(int, input().split())
time = int(input())


if chaser_init < target_init:
    if chaser_move < target_move:
        answer = 'NO'
        
    else:
        if chaser_init + time*chaser_move >= target_init + time * target_move:
            answer = 'YES'
            
        else:
            answer = 'NO'
            

else:
    if chaser_move < target_move:
        answer = 'NO'
        
    else:
        if chaser_init - time*chaser_move <= target_init - time * target_move:
            answer = 'YES'
            
        else:
            answer = 'NO'
            

print(answer)

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

using namespace std;

typedef long long int lli;

int main() {
    int h, w, a[501][501];

    cin >> h >> w;
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            cin >> a[i+1][j+1];
        }
    }

    bool coin = false;
    int y = 1, x = 1, xdir = 1;
    vector<int> ans;
    while (y <= h) {
        //cout << y << " " << x << endl;
        if (a[y][x] % 2) {
            coin = !coin;
            ans.push_back(y);
            ans.push_back(x);
        }
        else if (coin) {
            ans.push_back(y);
            ans.push_back(x);
            ans.push_back(y);
            ans.push_back(x);
        }

        if (x+xdir < 1 || w < x+xdir) {
            xdir *= -1;
            y++;
        }
        else {
            x += xdir;
        }
    }

    cout << ans.size()/4 << endl;
    for (int i=0, len = ans.size(); i+3<len; i+=4) {
        cout << ans[i] << " " << ans[i+1] << " " << ans[i+2] << " " << ans[i+3] << endl;
    }


    return 0;
}


Measured memory_bytes: 5104
import itertools
n, k = [int(_) for _ in input().split()]
q = [(int(_) + 1) / 2 for _ in input().split()]
cum = list(itertools.accumulate([0] + q))
ans = -1
for x in range(k, n + 1):
    ans = max(ans, cum[x] - cum[x - k])
print(ans)


Measured memory_bytes: 23616
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;
const int MAX=3000;
int fac[MAX],finv[MAX],inv[MAX];
 
void COMinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
 
int COM(int n,int k){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

signed main(){
    COMinit();
    int N,K;cin>>N>>K;
    REPS(i,K){
        cout<<COM(N-K+1,i)*COM(K-1,i-1)%MOD<<endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1<<29;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int t[1001]={};
int c[1001][1001]={};

int main() {

	int h,w;
	int a,b;

	cin>>h>>w>>a>>b;

	for(int i=0; i<b; i++){
		for(int j=a; j<w; j++){
			c[j][i]=1;
		}
	}
	for(int i=b; i<h; i++){
		for(int j=0; j<a; j++){
			c[j][i]=1;
		}
	}

	rep(i,h){
		rep(j,w){
			cout<<c[j][i];
		}
		cout<<endl;
	}

	return 0;
}


Measured memory_bytes: 5120
# -*- coding: utf-8 -*-
# Luis Yoichi Morales January 2019

from sys import stdin
import numpy as np



N,M, X,Y = map(int, raw_input().split())
x_max = max( map(int, raw_input().split()) )
y_min = min( map(int, raw_input().split()) )

if X <= x_max < y_min <= Y :
    print 'No War'
else:
    print 'War'

Measured memory_bytes: 17032
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

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

int X, Y, A, B, C; 
vector<long long> a, b, c;
vector<long long> p, q;

void solve() {
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());

  p.resize(X);
  q.resize(Y);

  rep(i, X) {
    long long temp = a.back();
    a.pop_back();
    p[i] = temp;
  }
  rep(i, Y) {
    long long temp = b.back();
    b.pop_back();
    q[i] = temp;
  }

  vector<long long> cand;
  rep(i, X) {
    cand.push_back(p[i]);
  }
  rep(i, Y) {
    cand.push_back(q[i]);
  }
  rep(i, c.size()) {
    cand.push_back(c[i]);
  }

  sort(cand.begin(), cand.end(), greater<long long>());

  long long sum = 0;
  
  rep(i, X + Y) {
    sum += cand[i];
  }


  // cout << p[0] << " " << p[1] << " " << q[0] << " " << q[1] << " " << q[2] << endl;
  cout << sum << endl;
}

int main() {
  cin >> X >> Y >> A >> B >> C;
  a.resize(A);
  b.resize(B);
  c.resize(C);
  rep(i, A){
    cin >> a[i];
  }
  rep(i, B){
    cin >> b[i];
  }
  rep(i, C){
    cin >> c[i];
  }
  solve();
  return 0;
}

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

int main(){
  int n;
  cin >> n;
  int count = 0;
  vector<char> s(n);
  for(int i=0;i<n;i++){
    cin >> s.at(i);
    if(s.at(i)=='Y'){
      count++;
      break;
    }
  }
  if(count==0){
    cout << "Three" << endl;
  }
  else{
    cout << "Four" << endl;
  }
}


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

uint xor128(){
	static uint x=123456789;
	static uint y=333333333;
	static uint z=555555555;
	static uint w=88888888;
	uint t=x^(x<<11);
	x=y;y=z;z=w;
	return w=(w^(w>>19))^(t^(t>>8));
}
struct node{
	node*l,*r;
	int cnt,val,Min;
};
node pool[400000];
int p;

inline int cnt(node*t){return t?t->cnt:0;}
inline int Min(node*t){return t?t->Min:INF;}

inline node*update(node*t){
	t->cnt=cnt(t->l)+cnt(t->r)+1;
	t->Min=min({t->val,Min(t->l),Min(t->r)});
	return t;
}
inline node*merge(node*l,node*r){
	if(!l)return r;
	if(!r)return l;
	if(xor128()%(cnt(l)+cnt(r))<(unsigned int)cnt(l)){
		l->r=merge(l->r,r);
		return update(l);
	}
	else{
		r->l=merge(l,r->l);
		return update(r);
	}
}
inline pair<node*,node*>split(node*t,int k){
	if(!t)return make_pair((node*)NULL,(node*)NULL);
	if(k<=cnt(t->l)){
		auto p=split(t->l,k);
		t->l=p.second;
		return make_pair(p.first,update(t));
	}
	else{
		auto p=split(t->r,k-cnt(t->l)-1);
		t->r=p.first;
		return make_pair(update(t),p.second);
	}
}

int main(){
	int n,q;scanf("%d%d",&n,&q);
	node*root=NULL;
	rep(i,n){
		int a;scanf("%d",&a);
		node*t=&pool[p++];
		*t={NULL,NULL,1,a,a};
		root=merge(root,t);
	}
	rep(i,q){
		int x,y,z;scanf("%d%d%d",&x,&y,&z);
		if(x==0){
			z++;
			auto a=split(root,y);
			auto b=split(a.second,z-y-1);
			auto c=split(b.second,1);
			root=merge(merge(merge(a.first,c.first),b.first),c.second);
		}
		else if(x==1){
			z++;
			auto a=split(root,y);
			auto b=split(a.second,z-y);
			printf("%d\n",Min(b.first));
			root=merge(merge(a.first,b.first),b.second);
		}
		else{
			auto a=split(root,y);
			auto b=split(a.second,1);
			b.first->val=z;
			update(b.first);
			root=merge(merge(a.first,b.first),b.second);
		}
	}
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int x = stoi(s.substr(2));
  int y = stoi(s.substr(0, 2));
  if (x <= 12 && x > 0 && y <= 12 && y > 0) {
    cout << "AMBIGUOUS";
  } else if (x <= 12 && x > 0) {
    cout << "YYMM";
  } else if (y <= 12 && y > 0) {
    cout << "MMYY";
  } else {
    cout << "NA";
  }
  cout << '\n';
  return 0;
}

Measured memory_bytes: 256