akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 8002

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii;

#define maxn 100005

i64 grundy( i64 x )
{
    if(x==0) return 0 ;
    i64 z = 1 ;
    while( x%(z*2) == 0 ) z *= 2 ;
//    printf("----%lld %lld\n",x,z) ;
    return z ;
}

int edge[maxn][2] ;
int nodeCnt = 0 ;
char s[maxn] ;

int addNode()
{
    nodeCnt++ ;
    return nodeCnt ;
}

void add( int i, int cur )
{
    if(s[i]=='\0') return ;
    int b = s[i] - '0' ;
    if( edge[cur][b] == 0 ) edge[cur][b] = addNode() ;
    add(i+1,edge[cur][b]) ;
}

i64 L ;
i64 ans = 0 ;

void traverse( int l, int cur )
{
    if( !edge[cur][0] && !edge[cur][1] ) return ;
    if( !edge[cur][0] ) ans ^= grundy(L-l) ;
    if( !edge[cur][1] ) ans ^= grundy(L-l) ;
    traverse(l+1,edge[cur][0]) ; traverse(l+1,edge[cur][1]) ;
}

int main()
{
    int n;
    scanf("%d %lld",&n,&L) ;

    int root = addNode() ;

    for(int i=1 ; i<=n ; i++)
    {
        scanf("%s",s) ;
        add(0,root) ;
    }

    traverse(0,root) ;

    if(ans) printf("Alice\n") ;
    else printf("Bob\n") ;

    return 0 ;
}


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

const int INF=1001001001;
int dp[100010];

int main(){
    int n;
    cin>>n;
    vector<int>h(n);
    rep(i,n)cin>>h[i];
    rep(i,100010)dp[i]=INF;
    dp[0]=0; dp[1]=abs(h[0]-h[1]);
    for(int i=0; i<n; ++i){
        dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i+1]));
        dp[i+2]=min(dp[i+2],dp[i]+abs(h[i]-h[i+2]));
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 4012
a = input().split()
b = int(a[0])
c = int(a[1])
import math

minb = math.ceil(b * 12.5)

if b % 2 == 1:
  maxb = int((b+1) * 12.5 - 1)
else:
  maxb = int(math.floor((b+1) * 12.5))

minc = c * 10
maxc = (c+1) * 10 - 1

if max([minb,minc]) <= min([maxb,maxc]):
  print(max([minb,minc]))
else:
  print("-1")

Measured memory_bytes: 9208
n = int(input())
k = 1000
A = list(map(int,input().split()))
A.append(0)
for i in range(len(A)-1):
    if A[i] < A[i+1]:
        stock = k//A[i]
        cash = k - A[i]*stock
        k = cash+stock*A[i+1]
print(k)

Measured memory_bytes: 9172
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast","no-stack-protector","unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define debug(x) cout<<(#x)<<"="<<x<<"\n";
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define f first
#define s second
#define ll long long
#define INF 2000000000
char s[5005];
int dp[5005][5005];
int main(){
        int n;
        while(~getI(n)){
                scanf("%s",s);
                F(i,0,n) F(j,0,n) dp[i][j]=0;
                F(i,1,n) if(s[0]==s[i]) dp[0][i]=1;
                F(i,1,n) F(j,i+1,n) if(s[i]==s[j]) dp[i][j]=min(dp[i-1][j-1]+1,j-i);
                int ans=0;
                F(i,0,n) F(j,0,n) ans=max(ans,dp[i][j]);
                printf("%d\n",ans);
        }
}


Measured memory_bytes: 98048
//自分用テンプレート・ライブラリ

#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i,N) for(int i=0; i<N; i++)
#define cinv(v,N) vector<int> v(N); for(int i=0; i<N; i++){ cin >> v[i]; }
#define mt make_tuple
#define vll vector<long long int>
#define vvll vector<vector<long long int>>
#define vvvll vector<vector<vector<long long int>>>
#define all(v) (v).begin(),(v).end()
const ll MOD2 = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll H, W; cin >> H >> W;
  vector<string> s(H); FOR(i,H){ cin >> s[i]; }
  ll INF = 1e18;
  vvvll dp(H+1,vector<vector<ll>>(W+1,vector<ll>(2,INF)));
  /*FOR(i,){ dp[i][i][0] = 0LL; }
  FOR(j,W+1){ dp[0][j][0] = 0LL; }*/
  dp[0][0][0] = 0; dp[0][1][0] = 0; dp[1][0][0] = 0;
    
  for(int i=1; i<=H; i++){
    for(int j=1; j<=W; j++){
      if(s[i-1][j-1] == '.'){
        dp[i][j][0] = min({dp[i][j][0],dp[i-1][j][0],dp[i][j-1][0],dp[i-1][j][1],dp[i][j-1][1]});
        //dp[i][j][1] = min({dp[i][j][1],dp[i-1][j][0]+1,dp[i][j-1][0]+1,dp[i-1][j][1],dp[i][j-1][1]});
      }else{
        //dp[i][j][0] = min({dp[i][j][0],dp[i-1][j][0],dp[i][j-1][0],dp[i-1][j][1]+1,dp[i][j-1][1]+1});
        dp[i][j][1] = min({dp[i][j][1],dp[i-1][j][0]+1,dp[i][j-1][0]+1,dp[i-1][j][1],dp[i][j-1][1]}); 
      }
    }
  }
    
  

  //main
  ll ans = min(dp[H][W][0],dp[H][W][1]);
  
  // output
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

struct ANS
{
	int x1,y1,x2,y2;
};

int main()
{
	int h,w;
	cin >> h >> w;
	vector<vector<int>> a(h,vector<int>(w));
	vector<ANS> ans;
	for(int i =0;i<h;++i)
	{
		for(int j =0;j<w;++j)
		{
			cin >> a[i][j];
		}
	}
	for(int i = 0;i<h;++i)
	{
		for(int j = 0;j<w-1;++j)
		{
			if(a[i][j]&1)
			{
				a[i][j]--;
				a[i][j+1]++;
				ANS foo;
				foo.x1 = i+1;
				foo.y1 = j+1;
				foo.x2 = i+1;
				foo.y2 = j+2;
				ans.push_back(foo);
			}
		}
	}
	for(int i =0;i<h-1;i++)
	{
		
		if(a[i][w-1]&1)
		{
			//cout<<';'<<endl;
			a[i][w-1]--;
			a[i+1][w-1]++;
			ANS foo;
			foo.x1 = i+1;
			foo.y1 = w;
			foo.x2 = i+2;
			foo.y2 = w;
			ans.push_back(foo);
		}
	}
	cout<<ans.size()<<endl;
	for(int i =0;i<ans.size();i++)
	{
		cout<<ans[i].x1<<' '<<ans[i].y1<<' '<<ans[i].x2<<' '<<ans[i].y2<<endl;
	}
	//for(int i = 0;i<h;i++){for(int j = 0;j<w;j++)cout<<a[i][j]<<' ';cout<<endl;}
	return 0;
}

Measured memory_bytes: 5232
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

using namespace std;

int getGCD(int a, int b)
{
	if (a > b)
	{
		swap(a, b);
	}
	return (a == 0) ? b : getGCD(a, b % a);
}

int getLCM(int a, int b)
{
	return (a / getGCD(a, b)) * b;
}

int main()
{
	int a, b;
	for (; cin >> a >> b;)
	{
		cout << getGCD(a, b) << " " << getLCM(a, b) << endl;
	}
}


Measured memory_bytes: 3016
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Rishabhdeep Singh
 */

// doot diddly donger cuckerino Hahahahahah
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;

// @formatter:off
#define PB              push_back
#define EB              emplace_back
#define F               first
#define S               second
#define all(x)          begin(x), end(x)
#define rall(x)         rbegin(x), rend(x)
#define sz(x)           (long long) (x).size()
#define IOS             ios::sync_with_stdio(false);cin.tie(NULL); cout << fixed << setprecision(12);
#define IN_REP          int tt; cin >> tt; while(tt--)
#define sim             template<typename T
#define ris             return *this
#define dor             > debug & operator <<
#define eni(x)          sim > typename enable_if<sizeof dud<T>(0) x 1, debug&>::type operator<<(T i)
sim> struct rge { T b, e; };
sim> rge<T> range(T i, T j) { return rge<T>{i, j}; }
sim> auto dud(T *x) -> decltype(cerr << *x, 0);
sim> char dud(...);
struct debug {
#ifdef LOCAL
  ~debug() { cerr << endl; }
  eni(!=) { cerr << boolalpha << i; ris; }
  eni(==) { ris << range(all(i)); }
  sim, typename U dor(pair<U, T> d) { ris << "(" << d.first << ", " << d.second << ")"; }
  sim dor(rge<T> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
  sim dor(const T&) { ris; }
#endif
};
#define pr(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vb = vector<bool>;

using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const ll MOD = (ll) 1e9 + 7;
const ld PI = acos(-1);

template<typename T> T gcd(T x, T y) { return (y == 0) ? x : gcd(y, x % y); }
template<typename T> void mini(T& x, T y) { x = min(x, y); }
template<typename T> void maxi(T& x, T y) { x = max(x, y); }
template<typename T, typename U> string to_string(pair<T, U> p) { return to_string(p.F) + " " + to_string(p.S); }
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
// @formatter:on


class AACOrWA {
  public:

    void solve(std::istream& cin, std::ostream& cout) {
        int n, m;
        cin >> n >> m;
        cout << (m >= n ? "Yes\n" : "No\n");

    }
};

int main() {
    IOS;
	AACOrWA solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

int l;

int main(){
	while(1){
		cin>>l;
		if(!l) break;
		int m,n,mon=0;
		bool used=0;
		for(int i=0;i<12;i++){
			cin>>m>>n;
			mon+=m-n;
			if(mon>=l&&!used){
				cout<<i+1<<endl;
				used=1;
			}
		}
		if(!used) cout<<"NA"<<endl;
	}
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,A,B;
	int P[1000];
	int c1=0,c2=0,c3=0;
	scan(N);scan(A);scan(B);
	rep(i,N){
		scan(P[i]);
		if(P[i]<=A) c1++;
		else if(P[i]<=B) c2++;
		else c3++;
	}
	prin(min(c1,min(c2,c3)));
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d;
int e,f;
int solve(int limit){
	int ret = 0;
	for(int i=0; i<=limit/c; i++){
		for(int j=0; j<=limit/d; j++){
			int sugar = c*i+d*j;
			if(sugar>limit) continue;
			ret = max(ret,sugar);
		}
	}
	return ret;
}
int main(){
	cin>>a>>b;
	a*=100;
	b*=100;
	cin>>c>>d>>e>>f;
	int maxmass=a;
	int maxsugar=0;
	
	for(int i=0; i<=30; i++){
		for(int j=0; j<=30; j++){
			int water = i*a+j*b;
			if(water>f) continue;
			int sugar_limit = min(water/100*e,f-water);
			int sugar_mass=solve(sugar_limit);
			int total = water+sugar_mass;
			if(sugar_mass*maxmass>total*maxsugar){
				maxmass = total;
				maxsugar = sugar_mass;
			}
		}
	}
	cout<<maxmass<<" "<<maxsugar;
}

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

using namespace std;

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> grid(h), temp;
    for(int i = 0; i < h; ++i) {
        cin >> grid[i];
    }
    int x, y, ans = 0;
    for(x = 0; x < (1 << h); ++x) {
        for(y = 0; y < (1 << w); ++y) {
            temp = grid;
            for(int i = 0; i < h; ++i) {
                if(x & (1 << i)) {
                    for(int j = 0; j < w; ++j) {
                        temp[i][j] = 'c';
                    }
                }
            }
            for(int i = 0; i < w; ++i) {
                if(y & (1 << i)) {
                    for(int j = 0; j < h; ++j) {
                        temp[j][i] = 'c';
                    }
                }
            }

            int count = 0;
            for(int i = 0; i < h; ++i) {
                for(int j = 0; j < w; ++j) {
                    if(temp[i][j] == '#') {
                        ++count;
                    }
                }
            }
            if(count == k) {
                ++ans;
            }
            // cout << x << ' ' << y << ' ' << count << ' ' << ans << '\n';
            // for(string s: temp) {
            //     cout << s << '\n';
            // }
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3632
n, m = list(map(int, input().split()))
h = list(map(int, input().split()))
bests = [1] * n
for k in range(m):
    a, b = list(map(int, input().split()))
    if h[a -1] > h[b - 1]:
        bests[b - 1] = 0
    elif h[a -1] < h[b - 1]:
        bests[a - 1] = 0
    else:
        bests[a - 1] = 0
        bests[b - 1] = 0
print(sum(bests))

Measured memory_bytes: 20128
from collections import Counter
n = int(input())
D = list(map(int, input().split()))
m = int(input())
T = list(map(int, input().split()))
Dc = Counter(D)
Tc = Counter(T)
for t in Tc.keys():
    if Dc.get(t) == None:
        print('NO')
        exit()
    if Tc[t] > Dc[t]:
        print('NO')
        exit()
print('YES')

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

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(int i=0; i<(n); i++)
#define REPj(n) for(int j=0; j<(n); j++)
#define REPinit(i,a,n) for(int i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(int j=(a); j<(n); j++)

//algorithm
//#define SORT(c) sort((c).begin(),(c).end())

//constant

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/* 
	add utility Algorithm
*/

int main(int argc, char const *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;
    cout << ((N >= 30) ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3608
loop do
  n = gets.to_i
  break if n == 0
  
  str = gets.chomp.split('').map(&:to_i)
  
  n.times do
    str = str.reduce([]){ |arr, i|
      if arr.last(2)[1] == i
        arr[arr.length - 2] += 1
      else
        arr << 1 << i
      end
      
      arr
    }.join('').split('').map(&:to_i)
  end
  
  puts str.join('')
end

Measured memory_bytes: 13176
#include<stdio.h>
#define N 100

void paint_map(
    int h,int w,char map[N][N],
    int x,int y,char fruit){
  if(x==-1 || y==-1 || x==h || y==w)
    return ;
  if( map[x][y]!=fruit ||
      map[x][y]=='.')
    return ;

  map[x][y]='.';

  paint_map(h,w,map,x-1,y,fruit);
  paint_map(h,w,map,x+1,y,fruit);
  paint_map(h,w,map,x,y-1,fruit);
  paint_map(h,w,map,x,y+1,fruit);
}

int main(void){
  int i,j;
  int h,w;
  char map[N][N],hoge;
  int count;

  for(;;){
    scanf("%d%d",&h,&w);
    if(h==0 && w==0)
      break;

    for(i=0;i<h;i++){
      scanf("%c",&hoge);
      for(j=0;j<w;j++)
        scanf("%c",&map[i][j]);
    }

    count=0;
    for(i=0;i<h;i++)
      for(j=0;j<w;j++)
        if(map[i][j]!='.'){
          count++;
          paint_map(h,w,map,i,j,map[i][j]);
        }

    printf("%d\n",count);
  }

  return 0;
}

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

int main(void) {
    int n;
    cin >> n;
    vector<int> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x.at(i);
    }
    int ans = 1e9;
    for (int p = 1; p <= 100; p++) {
        int po = 0;
        for (int i = 0; i < n; i++) {
            po += (x.at(i) - p) * (x.at(i) - p);
        }
        ans = min(ans, po);
    }
    cout << ans << endl;
    return 0;
}

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

int T[501][501];

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

  int N, M, Q;
  cin >> N >> M >> Q;

  rep(i, M) {
    int l,r; cin >> l >> r;
    T[l][r]++;
  }

  for(int i = 1; i <= 500; i++) {
    for(int j = i; j <= 499; j++) {
      T[i][j+1] += T[i][j];
    }
  }
  for(int j = 500; j >= 1; j--) {
    for(int i = j - 1; i >= 1; i--) {
      T[i][j] += T[i+1][j];
    }
  }

  rep(_, Q) {
    int p,q; cin >> p >> q;
    cout << T[p][q] << endl;
  }
}


Measured memory_bytes: 1920
#include<cstdio>

int main()
{
	int n;
	scanf("%d",&n);
	bool flag=false;
	while (n)
	{
		int rem = n%10;
		if ( rem==7 )
		{
			flag=true;
			break;
		}
		n /= 10;
	}
	if ( flag==true )
	printf("Yes\n");
	else
	printf("No\n");
	return 0;
}


Measured memory_bytes: 1600
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
 
int main(){
    long N;
    cin >> N;
    vector<LL> a,b,c;
    long bm[N];
    fill(bm,bm+N,0);
    for(int i=0;i<N;i++){
        LL s;
        cin >> s;
        a.push_back(-s);
    }
    for(int i=0;i<N;i++){
        LL s;
        cin >> s;
        b.push_back(s);
    }
    for(int i=0;i<N;i++){
        LL s;
        cin >> s;
        c.push_back(s);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    LL count=0;
    for(int i=0;i<N;i++){
        auto aitr=upper_bound(a.begin(),a.end(),-b[i]);
        auto citr=upper_bound(c.begin(),c.end(),b[i]);
        count+=(a.end()-aitr)*(c.end()-citr);
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 4084
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define int ll


int n;

signed main(){
  cin>>n;
  int a = 3,i=0;
  while(n>a){
    a*=3;
    i++;
  }

  cout<<i+(n%a!=0||n%a!=a)<<endl;

}


Measured memory_bytes: 3112
from math import sin,cos,pi
a, b, h, m = [int(i) for i in input().split()]
t = (h + m / 60)*2*pi
 
ax, ay = a * cos(t / 12), a * sin(t / 12)
bx, by = b * cos(t), b * sin(t)
print(((ax-bx)**2+(ay-by)**2)**0.5)

Measured memory_bytes: 9564
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_variables)]

use std::io::stdin;
use std::str::FromStr;
use std::collections::VecDeque;

fn read<T: FromStr>() -> T {
    let mut str = String::new();
    stdin().read_line(&mut str).ok();
    str.trim().parse().ok().unwrap()
}

fn read_vec<T: FromStr>() -> Vec<T> {
    let mut str = String::new();
    stdin().read_line(&mut str).ok();
    str.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_n_vec<T: FromStr>(n: u32) -> Vec<Vec<T>> {
    let mut v_outer = Vec::new();
    for _ in 0..n {
        let v_inner = read_vec();
        v_outer.push(v_inner);
    }
    v_outer
}

fn main() {
    let s: String = read();
    println!("{}", if s.chars().nth(2) == s.chars().nth(3) &&
        s.chars().nth(4) == s.chars().nth(5) {
        "Yes"
    } else { "No" });
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

struct BIT { //0-origin!!! update and get just like lazy_segtree
	int n; vl bit0, bit1;
	void init(int mx) {
		n = mx;
		bit0 = vl(n + 1, 0); bit1 = vl(n + 1, 0);
	}
	BIT(int mx = 0) { init(mx); } 

	ll ga(vl& bit, int i) {
		ll s = 0;
		while(i > 0) { s += bit[i]; i -= i & -i; }
		return s;
	}
	void app(vl& bit, int i, ll x) {
		while(i <= n) { bit[i] += x; i += i & -i; }
	}
	void update(int a, int b, ll x) { //[a, b)
		a++;
		app(bit0, a, -x * (a - 1));
		app(bit1, a, x);
		app(bit0, b + 1, x * b);
		app(bit1, b + 1, -x);
	}
	ll get(int a, int b) { //[a, b)
		a++;
		return (ga(bit1, b) * b + ga(bit0, b)) 
			- (ga(bit1, a - 1) * (a - 1) + ga(bit0, a - 1));
	}
};

ll N;
ll A[MAX_N];
int S[MAX_N];
pi P[MAX_N];

bool ok(ll m) {
	rep(i, 0, N) {
		if(A[i] <= m) S[i + 1] = 1;
		else S[i + 1] = -1;
	}
	// debug(m, vi(S + 1, S + N + 1));
	rep(i, 0, N) {
		S[i + 1] += S[i];
	}
	rep(i, 0, N + 1) {
		P[i] = pi(S[i], -i);
	}
	sort(P, P + N + 1);
	ll res = 0;
	BIT bit(N + 1);
	rep(i, 0, N + 1) {
		int at = P[i].sec * -1;
		bit.update(at, at + 1, 1);
		res += bit.get(0, at);
	}
	return res > N * (N + 1) / 4;
}

void solve() {
	cin >> N;
	rep(i, 0, N) cin >> A[i];
	ll lv = 0, rv = inf;
	while(rv - lv > 1) {
		ll m = (lv + rv) / 2;
		if(ok(m)) rv = m;
		else lv = m;
	}
	cout << rv << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 3852
from math import sqrt

N = 10 ** 6
p = [True] * (N + 1)
p[0] = False
p[1] = False
n = int(sqrt(N) + 1)

for i1 in range(4, N+1, 2):
  p[i1] = False
for i2 in range(3, n+1, 2):
  if p[i2]:
    for i3 in range(i2+i2, N+1, i2):
      p[i3] = False

X = int(input())
for i4 in range(X, N+1):
  if p[i4]:
    print(i4)
    break

Measured memory_bytes: 10868
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    ll N;
    cin >> N;
    vector<pll> p(N);
    rep(i, N){
        ll a, b;
        cin >> a >> b;
        p[i] = make_pair(b, a);
    }
    sort(all(p));
    ll time = 0;
    rep(i, N){
        time += p[i].second;
        if(time > p[i].first){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
}

Measured memory_bytes: 3328
package main

import "fmt"

func main() {
	var (
		K  int
		NS string
	)

	fmt.Scanf("%s\n%d\n", &NS, &K)
	var dp [102][4][2]int
	n := len(NS)
	dp[0][0][0] = 1
	for i := 0; i < n; i++ {
		for j := 0; j < 4; j++ {
			for k := 0; k < 2; k++ {
				nd := int(NS[i] - '0')
				for d := 0; d < 10; d++ {
					ni, nj, nk := i+1, j, k
					if d != 0 {
						nj++
					}
					if nj > K {
						continue
					}
					if k == 0 {
						if d > nd {
							continue
						}
						if d < nd {
							nk = 1
						}
					}
					dp[ni][nj][nk] += dp[i][j][k]
				}
			}
		}
	}
	fmt.Println(dp[n][K][0]+dp[n][K][1])
}


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

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

  bool b = true;
  int l = 0;
  int maxl = 0;
  for (int i=0; i<s.length(); i++) {
    char c = s[i];
    if (c == 'A' || c == 'G' || c == 'T' || c == 'C') {
      if (b) {
        l++;
        maxl = max(maxl, l);
      } else {
        b = true;
        l = 1;
      }
    } else {
      if (b) {
        maxl = max(maxl, l);
        b = false;
        l = 0;
      }
    }
  }

  cout << maxl << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 150
int main(void)
{
  int i,j,n,h[N]={},ct=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",h+i);
  }
  ct++;
  for(i=1;i<n;i++){
    for(j=0;j<i;j++){
      if(h[i]<h[j]){
        break;
      }
      if(j==i-1){
        ct++;
      }
    }
  }
  printf("%d\n",ct);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
using namespace std;

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }
  sort(a,a+n);
  for (int i = 1; i < n; i++){
    if (a[i] == a[i-1]) {
      cout << "NO\n";
      return 0;
    }
  }
  cout << "YES\n";
  return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int n = N;
		int sum = 0;
		while(N >= 1) {
			sum = sum + (N % 10);
			N = N  / 10; 
		}
		if(n % sum == 0) {
			System.out.println("Yes");
		}
		else if(n % sum != 0) {
			System.out.println("No");
		}
		sc.close();

	}
}


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

const int MAXP = 1000001;
bool isP[MAXP];
vector<int> Ps;

int main() {
  fill(isP, isP+MAXP, true);
  isP[0] = isP[1] = false;
  for(int i = 2; i < MAXP; ++i) {
    if(!isP[i]) continue;
    Ps.push_back(i);
    for(int j = i*2; j < MAXP; j += i) isP[j] = false;
  }
  for(int n; cin >> n && n;) {
    int res = 0;
    for(int i = 0; i < Ps.size(); ++i) {
      int p = Ps[i];
      int q = n - Ps[i];
      if(p <= q && isP[q]) {
        ++res;
      }
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll A, B , C;
    cin >> A >> B >> C;
    ll K; cin >> K;
    ll m = max(A,B); m = max(m,C);
    
    cout << m*pow(2,K)-m +A + B + C << endl;
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;

void solve(){
   int n,k;
   cin >> n >> k;

   ld a[n + 1] , b[n + 1] , c[n+1];
   a[0] = b[0] = c[0] = 0;

   f(i,1,n+1){
      cin >> a[i];
      c[i] = log10(a[i]);
      b[i] = log2(a[i]);
      a[i] = log(a[i]);
      a[i] += a[i-1];
      b[i] += b[i-1];
      c[i] += c[i-1];
   }

   f(i,k+1,n+1){
      ld x1 = a[i] - a[i-k];
      ld x2 = a[i-1] - a[i-1-k];
      ld y1 = b[i] - b[i-k];
      ld y2 = b[i-1] - b[i-1-k];
      ld z1 = c[i] - c[i-k];
      ld z2 = c[i-1] - c[i-1-k];
      cout << (x1 > x2 && y1 > y2 && z1 > z2 ? "Yes" : "No") << "\n";
   }
}

int32_t main(){
   fast;
   int t = 1;
   // cin >> t;
   while(t--)  solve();   
}

Measured memory_bytes: 13188
n = int(input())
h = list(map(int, input().split()))

dp = [0] * n
dp[1] = abs(h[0] - h[1])

for i in range(2, n):
    dp[i] = min(abs(h[i] - h[i-1]) + dp[i-1], abs(h[i]- h[i-2])+dp[i-2])
    # print(dp)

print(dp[n-1])

Measured memory_bytes: 13980
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
  int N;
  cin >> N;

  // 4より小さい場合は終わり
  if(N < 4) {
    cout << "No" << endl;
    return 0;
  }

  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N; j++) {
      if (4 * i + 7 * j == N) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3632
use std::io::*;
use std::str::FromStr;

fn main() {
    let h: usize = read();
    let w: usize = read();
    let a: Vec<Vec<i64>> = (0..h).map(|_| (0..w).map(|_| read()).collect()).collect();
    let b: Vec<Vec<i64>> = (0..h).map(|_| (0..w).map(|_| read()).collect()).collect();
    
    let max_diff: i64 = 2 * 80 * 160;
    let mid = max_diff / 2;
    let mut dp: Vec<Vec<Vec<bool>>> = vec![vec![vec![false;max_diff as usize];w];h];
    dp[0][0][(b[0][0] - a[0][0] + mid) as usize] = true;
    dp[0][0][(- b[0][0] + a[0][0] + mid) as usize] = true;

    for i in 0..h {
        for j in 0..w {
            for l in 0..(max_diff as usize) {
                if !dp[i][j][l] {
                    continue;
                }
                if i+1 <= h-1 {
                    dp[i+1][j][l + b[i+1][j] as usize - a[i+1][j] as usize] = true;
                    dp[i+1][j][l + a[i+1][j] as usize - b[i+1][j] as usize] = true;
                }
                if j+1 <= w-1 {
                    dp[i][j+1][l + b[i][j+1] as usize - a[i][j+1] as usize] = true;
                    dp[i][j+1][l + a[i][j+1] as usize - b[i][j+1] as usize] = true;
                }
            }
        }
    }
    let mut ans = max_diff;
    for i in 0..(max_diff as usize) {
        if dp[h-1][w-1][i] {
            ans = std::cmp::min(ans, if i as i64 >= mid {i as i64 -mid} else {mid - i as i64});
        }
    }
    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

A,B=map(int,input().split())
S=input()

ans=True
for i in range(A+B+1):
	if i==A :
		if S[i]!='-':
			ans=False
	elif S[i]=='-':
		ans=False

print("Yes" if ans else "No")


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

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> board(h);
    int cnt = 0;
    for (int i = 0; i < h; ++i) {
        cin >> board[i];
        for (char j : board[i]) {
            if (j == '#') cnt++;
        }
    }
    vector<vector<int>> dist(h, vector<int>(w, -1));
    dist[0][0] = 0;
    queue<pair<int, int>> q;
    q.push(make_pair(0, 0));
    while (!q.empty()) {
        pair<int, int> v = q.front();
        q.pop();
        int x = v.first; int y = v.second;
        vector<pair<int, int>> go = {make_pair(x + 1, y), make_pair(x, y + 1), make_pair(x - 1, y), make_pair(x, y - 1)};
        for (pair<int, int> i : go) {
            if (i.first >= h || i.second >= w || i.first < 0 || i.second < 0) continue;
            if (board[i.first][i.second] == '#') continue;
            if (dist[i.first][i.second] != -1) continue;
            dist[i.first][i.second] = dist[x][y] + 1;
            q.push(make_pair(i.first, i.second));
        }
    }
    cout << (dist[h - 1][w - 1] == -1 ? -1 : h * w - cnt - 1 - dist[h - 1][w - 1]) << endl;
}


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

int main() {
    
    int N,M;
    int a,b;
    int answer=0;

    cin >> N;
    cin >> M;
    
    vector<int> input[M+1];
    priority_queue<int> q;
    
    for (int i = 0; i < N; i++)
    {
        cin >> a;
        cin >> b;
        
        if(a > M){
            continue;
        }
        input[a].push_back(b);
    }
    
    for (int i=0; i<M+1; i++){
        for(int j:input[i]){
            q.push(j);
        }
        if(q.empty()){
            continue;
        }
        answer += q.top();
        q.pop();
    }
    
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9


int main(){
    int n,x;
    cin>>n>>x;
    int sum = 0;
    int res = 1;
	for(int i=0;i<n;i++){
		int tmp;
		cin>>tmp;
		sum+=tmp;
		if(sum<=x)res++;

	}

	cout<<res<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define erep(i,a,b) for(int i=a;i<=(int)(b);i++)
#define per(i,a,b) for(int i=(b)-1;i>(a);i--)
#define eper(i,a,b) for(int i=((int)(a));i>=b;i--)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n, m, a[1100], b[1100], c[1100], g[1100][1100];
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n >> m;
    rep(i, 0, 1100) {
        rep(j, 0, 1100) {
            g[i][j] = INF;
            if (i == j) g[i][j] = 0;
        }
    }
    rep(i, 0, m) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--, b[i]--;
        g[a[i]][b[i]] = min(g[a[i]][b[i]], c[i]);
        g[b[i]][a[i]] = min(g[b[i]][a[i]], c[i]);
    }
    rep(k, 0, n) {
        rep(i, 0, n) {
            rep(j, 0, n) {
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }
    int ans = m;
    rep(i, 0, m) {
        bool flag = false;
        rep(j, 0, n) {
            if (g[j][a[i]] + c[i] == g[j][b[i]]) 
                flag = true;
        }
        if (flag) ans--;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include <algorithm>
#include <vector>
#define INF (1<<30)
using namespace std;
int main() {
	cin.tie(0);ios::sync_with_stdio(false);
	int H, W; cin >> H >> W;
	vector<vector<int>> ans(H, vector<int>(W, INF));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W;j++) {
			char c; cin >> c;
			if (c == 'c') {
				ans[i][j] = 0;
			}
		}
	}

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W;j++) {

			if (ans[i][j] == 0) {

				for (int k = j + 1; k < W;k++) {
					ans[i][k] = min(ans[i][k], ans[i][k - 1] + 1);
				}

			}

		}
	}

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W;j++) {
			if (ans[i][j] == INF) {
				cout << -1;
			}else{
				cout << ans[i][j];
			}
			if (j != W - 1)cout << " ";
		}
		cout << endl;
	}
}

Measured memory_bytes: 3268
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int inf=1e9,mod=1e9+7;
typedef long long ll;
int read() {
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
	while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}
int a[1000001];
priority_queue<int,vector<int>,greater<int> > q;
main() {
	int n=read(),m=read(),maxx=0;
	for(int i=1; i<=n; i++)
		a[i]=read();
	for(int i=0; i<=min(m,n); i++)
		for(int j=0; j<=min(n-i,m-i); j++)
			for(int z=n+1; z>=max(n-(m-i-j)+1,i+1); z--) {
				if(i+(n-z+1)<=j) continue;
				for(int k=1; k<=i; k++)
					q.push(a[k]);
		//	cout<<i<<" "<<z<<" "<<j<<endl;
				for(int k=n; k>=z; k--)
					q.push(a[k]);
				for(int k=1; k<=j; k++)
					q.pop();
				int ans=0;
				while(!q.empty())
					ans+=q.top(),q.pop();
				maxx=max(ans,maxx);
			}
	cout<<maxx;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int area = a*b;
    int length = 2*a + 2*b;
    System.out.println(area + " " + length);
  }
}



Measured memory_bytes: 26136
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
using namespace std;

int main(){
    int N;
    cin >> N;
    int a[N];
    for(int i=0; i<N; i++){
        cin >> a[i];
    }
    sort(a,a+N,greater<int>());
    
    int alice=0,bob=0;
    for(int i=0; i<N; i++){
        if(i%2==0){
            alice+=a[i];
        }else{
            bob+=a[i];
        }
    }
    
    cout<<alice-bob<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;

int main(){
  int n,ma,mb;
  cin >> n >> ma >> mb;
  vector<int> a(n),b(n),c(n);
  rep(i,n){ cin >> a[i] >> b[i] >> c[i]; }
  vector<vector<vector<int>>> dp(45,vector<vector<int>>(520, vector<int>(520,inf)));
  dp[0][0][0]=0;
  rep(i,n){
    rep(j,410)rep(k,410){
      dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k]);
      dp[i+1][j+a[i]][k+b[i]]=min(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i]);
    }    
  }
  int ans=inf;
  for(int i=1; i<=40; i++){
    ans = min(ans,dp[n][ma*i][mb*i]);
  }
  if(ans==inf){ans=-1;}
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 49792
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<unsigned> a(N), b(N);
  for (size_t i=0; i<N; ++i)
    scanf("%u", &a[i]);

  for (size_t i=0; i<N; ++i)
    scanf("%u", &b[i]);

  unsigned res=0;
  for (unsigned i=(1<<28); i; i>>=1) {
    std::sort(a.begin(), a.end());
    std::sort(b.begin(), b.end());

    size_t i1=0, i2=0, i3=0;
    size_t ii=2*i, iii=3*i;
    unsigned cur=0;
    for (size_t j=N; j--;) {
      while (i1 < N && a[j]+b[i1] < i) ++i1;
      while (i2 < N && a[j]+b[i2] < ii) ++i2;
      while (i3 < N && a[j]+b[i3] < iii) ++i3;
      cur += (i2-i1) + (N-i3);
    }
    if (cur & 1)
      res |= i;

    for (size_t j=0; j<N; ++j) {
      a[j] &= i-1;
      b[j] &= i-1;
    }
  }

  printf("%u\n", res);
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
//#include <tuple>

//#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

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

  for (char st : s) {
    char a = st + N;
    if (a > 90) {
      a -= 26; 
    }
    cout << a;
  }
  
  cout << endl;

}


Measured memory_bytes: 256
import java.util.Scanner;

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

        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] marray = new int[m];

        for (int i = 0; i < n; i++) {
            int num = sc.nextInt();
            for (int j = 0; j < num; j++) {
                int work = sc.nextInt();
                marray[work - 1]++;
            }
        }

        int cnt = 0;

        for (int a : marray) {
            if (a == n) {
                cnt++;
            }
        }
        sc.close();
        System.out.println(cnt);
    }
}


Measured memory_bytes: 21712
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <set>

#define rep2(i, b, n) for(int i=b; i < n; ++i)
#define repm(i, b, n) for(int i=b; i > n; --i)
#define rep(i, n) rep2(i, 0, n)

using namespace std;

int main( void )
{
	int n, m;
	
	while (cin >> n)
	{
		set<string> s;
		string in;
		
		rep (i, n)
		{
			cin >> in;
			s.insert( in );
		}
		
		cin >> m;
		bool opened = false;
		
		rep (i, m)
		{
			cin >> in;
			if (s.count( in ))
			{
				if (opened)
					cout << "Closed by " << in << endl;
				else
					cout << "Opened by " << in << endl;
					
				opened = !opened;
			}
			else
				cout << "Unknown " << in << endl;
		}
		
	}
	return 0;
}

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

int main()
{

    std::ios_base::sync_with_stdio(false);
    int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin>>k;
    cout<<a[k-1];

}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    long INF = Long.MAX_VALUE;
    long[] dp;
    long n;
    long S;

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] A = new long[N + 1];
        long[] B = new long[N];
        long ans = 0;
        for (int i = 0; i <= N; i++) {
            A[i] = sc.nextLong();
        }
        for (int i = 0; i < N; i++) {
            B[i] = sc.nextLong();
        }
        for (int i = 0; i <= N; i++) {
            if (i == 0) {
                if (B[i] >= A[i]) {
                    ans += A[i];
                    B[i] -= A[i];
                } else {
                    ans += B[i];
                    B[i] = 0;
                }
                continue;
            }
            if (i == N) {
                if (B[i - 1] >= A[i]) {
                    ans += A[i];
                } else {
                    ans += B[i - 1];
                }
                continue;
            }
            A[i] -= B[i - 1];
            if (A[i] < 0) {
                ans += (B[i - 1] + A[i]);
                A[i] = 0;
                continue;
            }
            ans += B[i - 1];
            A[i] -= B[i];
            if (A[i] < 0) {
                ans += (B[i] + A[i]);
                B[i] -= ((B[i] + A[i]));
                A[i] = 0;
                continue;
            }
            ans += B[i];
            B[i] = 0;
        }
        System.out.println(ans);
    }

    int gcd(int m, int n) {
        if (m < n) {
            return gcd(n, m);
        }
        if (n == 0) {
            return m;
        }
        return gcd(n, m % n);
    }
}


Measured memory_bytes: 85792
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np

MOD = 10**9 + 7

H,W,N = map(int,input().split())
R,C = np.array(sys.stdin.read().split() + [H,W],dtype=np.int64).reshape(N+1,2).T

ind = np.argsort((R<<32)+C)
R = R[ind]
C = C[ind]

def cumprod(arr):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
    for n in range(1,Lsq):
        arr[n] *= arr[n-1,-1]; arr[n] %= MOD
    return arr.ravel()[:L]

U = 2 * 10**5 + 10
x = np.arange(U,dtype=np.int64)
x[0] = 1
fact = cumprod(x)
x = np.arange(U,0,-1,dtype=np.int64)
x[0] = pow(int(fact[-1]),MOD-2,MOD)
fact_inv = cumprod(x)[::-1]

dp = np.zeros(N+1,dtype=np.int64)
dp += fact[R+C-2] * fact_inv[R-1] % MOD * fact_inv[C-1] % MOD

for i,(r,c) in enumerate(zip(R,C)):
    j = np.where((R<=r)&(C<=c)&(R+C<r+c))
    dx,dy = r-R[j],c-C[j]
    dp[i] -= (dp[j] * fact[dx+dy] % MOD * fact_inv[dx] % MOD * fact_inv[dy] % MOD).sum()
    dp[i] %= MOD

answer = dp[-1]
print(answer)

Measured memory_bytes: 20504
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <string>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    int n; cin >> n;
    long long array[n]; for(int i = 0; i<n; ++i)cin >> array[i];
    long long min1 = 0;
    long long sum1 = 0;
    for(int i = 0; i<n; ++i){
        sum1 += array[i];
        if(i%2 == 0){
            if(sum1 <= 0){
                min1 += abs(sum1)+1;
                sum1 = 1;
            }
        }else{
            if(sum1 >= 0){
                min1 += abs(sum1)+1;
                sum1 = -1;
            }
        }
    }
    long long  min2 = 0;
    long long sum2 = 0;
    for(int i = 0; i<n; ++i){
        sum2 += array[i];
        if(i%2 == 1){
            if(sum2 <= 0){
                min2 += abs(sum2)+1;
                sum2 = 1;
            }
        }else{
            if(sum2 >= 0){
                min2 += abs(sum2)+1;
                sum2 = -1;
            }
        }
    }
    cout << min(min1, min2) << endl; return 0;
}

Measured memory_bytes: 1024