akhauriyash/Code-Regression huggingface dataset:
N,x = map(int,input().split())
A = list(map(int,input().split()))

if sum(A) < x:
    print(N-1)
else:
    A.sort()
    count = 0
    while(x > 0):
        x -= A[count]
        if x >= 0:
            count += 1
    print(count)

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

int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i=0; i<n; i++){
        cin >> a[i];
    }
    for (int j=0; j<n-1; j++){
        cout << a[n-1-j] << " ";
        }
        cout << a[0] << endl;
    return 0;
}


Measured memory_bytes: 3088
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 998244353
#define inv2 499122177
#define eps 1e-8
int n;
ll a[1001000],f[1001000],g[1001000];
int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

void fwt_xor(int lim,ll *a,int typ)
{
    int mid;
    for (mid=1;mid<lim;mid<<=1)
    {
        int len=(mid<<1),sta,j;
        for (sta=0;sta<lim;sta+=len)
        {
            for (j=0;j<mid;j++)
            {
                ll x=a[sta+j],y=a[sta+j+mid];
                a[sta+j]=(x+y)%maxd;
                a[sta+j+mid]=(x+maxd-y)%maxd;
                if (typ==-1) {a[sta+j]=a[sta+j]*inv2%maxd;a[sta+j+mid]=a[sta+j+mid]*inv2%maxd;}
            }
        }
    }
}

ll qpow(ll x,int y)
{
    ll ans=1;
    while (y)
    {
        if (y&1) ans=ans*x%maxd;
        x=x*x%maxd;y>>=1;
    }
    return ans;
}

int main()
{
    n=read();int lim=(1<<n);
    ll sum=0;
    rep(i,0,lim-1) {a[i]=read();sum=(a[i]+sum)%maxd;}
    sum=qpow(sum,maxd-2);
    rep(i,0,lim-1) {f[i]=maxd-1;g[i]=a[i]*sum%maxd;}
    f[0]=lim-1;g[0]=(g[0]+maxd-1)%maxd;
    fwt_xor(lim,f,1);fwt_xor(lim,g,1);
    rep(i,0,lim-1) f[i]=f[i]*qpow(g[i],maxd-2)%maxd;
    fwt_xor(lim,f,-1);
    rep(i,0,lim-1)
        printf("%lld\n",(f[i]-f[0]+maxd)%maxd);
    return 0;
}


Measured memory_bytes: 15104
/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1000 * 1000 + 10;
int arr[MAXN];
int main(){
string a, b;
cin >> a >> b;
int n = a.size();
int f = 1;
for(int i = 0; i < n; i++){
	if(a[i] != b[i]){
		f = 0;
		break;
	}
}if(f == 1){
	cout << "Yes";
}else{
	cout << "No";
}

return 0;
}

Measured memory_bytes: 3628
A,B,K =map(int,input().split())

L = []
for i in range(K):
    x = A+i
    y = B-i
    if x not in L and x >= A and x <= B:
        L.append(x)
    if y not in L and x >= A and x <= B:
        L.append(y)
L.sort()

for x in L:
    print(x)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Lamp | diff Lamp.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Lamp.cpp && ./a.out

/*
 
 6/9/2019
 
 5:12-5:39 AC
 
 */

const int MAX_N=2010+1;
string A[MAX_N];
int N,M;

int pos[4][MAX_N][MAX_N];
void solve() {
//  REPE(i,N+1) dump(A[i]);
  
  // l
  FORE(i,1,N)FORE(j,1,M) pos[0][i][j]=A[i][j]=='#'?j:pos[0][i][j-1];
  // r
  FORE(i,1,N) {
    pos[1][i][M+1]=M+1;
    for(int j=M; j>=1; --j) pos[1][i][j]=A[i][j]=='#'?j:pos[1][i][j+1];
  }
  // t
  FORE(j,1,M)FORE(i,1,N)pos[2][i][j]=A[i][j]=='#'?i:pos[2][i-1][j];
  // b
  FORE(j,1,M) {
    pos[3][N+1][j]=N+1;
    for(int i=N; i>=1; --i)pos[3][i][j]=A[i][j]=='#'?i:pos[3][i+1][j];
  }
  int res=0;
  FORE(i,1,N)FORE(j,1,M) if(A[i][j]!='#') {
    int x=pos[1][i][j]-pos[0][i][j]-1;
    int y=pos[3][i][j]-pos[2][i][j]-1;
    SMAX(res,x+y-1);
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>M;
  REPE(i,N+1) A[i]=string(M+2,'#');
  REP(i,N) {
    string s; cin>>s;
    FORE(j,1,M) A[i+1][j]=s[j-1];
  }
  solve();
  
  return 0;
}


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

int main(){

  long long int n,a[200000],ssize = 0;
  cin >> n;
  for(int i = 0; i < n; i++){
  cin >> a[i];
  ssize += a[i];
  }
  
  long long s = 0,ans = ssize;
  for(int i = 0; i < n; i++){
  s += a[i];
  ans = min(ans , abs(s - (ssize - s))); 
  }
  
  cout << ans << endl;
  
  
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
 using namespace std;
 int main() { 
   long long a,b,c,k;
   cin>>a>>b>>c>>k;
   int ans=0;
   while(a>0&&k>0){
     ans++;
     a--;
     k--;
   }
   while(b>0&&k>0){
     b--;
     k--;
   }
   while(c>0&&k>0){
     c--;
     k--;
     ans--;
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 3640
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        sc.close();
        if ((A - B) % 2 == 0) {
            System.out.println((A + B) / 2);
        } else {
            System.out.println("IMPOSSIBLE");
        }
    }
}


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

int main(){
    int x,y,s;
    while(cin>>x>>y>>s,x){
        int res=0;
        for(int r=1;r<=s;r++)
            for(int k=1;k<=s;k++)
                if(int(double(100+x)/100*r+0.00001)+int(double(100+x)/100*k+0.00001)==s)
                    res=max(res,int(double(100+y)/100*r+0.000001)+int(double(100+y)/100*k+0.000001));

        cout<<res<<endl;




    }


    return 0;
}

Measured memory_bytes: 3056
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << endl
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
int dx8[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy8[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, 1, 0, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

vvi d;
int V,E;
void warshall_floyd(int n) {
for (int i = 0; i < n; i++){
 for (int j = 0; j < n; j++){
 for (int k = 0; k < n; k++) {
if(d[j][i] == INF || d[i][k] == INF) continue;//overflow対策
 d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
 }
}
}
}

int main(void) {
    int H,W;
    cin >> H >> W;
    d.assign(10,vi(10));
    rep(i,10){
        rep(j,10){
            cin >> d[i][j];
        }
    } 
    
    vvi A(H,vi(W));
    rep(i,H){
        rep(j,W){
            cin >> A[i][j];
        }
    }

    warshall_floyd(10);
    
    ll ans=0;
    rep(i,H){
        rep(j,W){
            if(A[i][j] == -1 || A[i][j] == 1) continue;
            ans += d[A[i][j]][1];
        }
    }

    fin(ans);
}

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

int main() {
  string N; cin >> N;
  
  bool seven = false;
  for (int i = 0; i < 3; i++) {
    if (N[i] == '7') seven = true;
  }
  
  if (seven) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int main() {
	int N; cin >> N;
	vector<int> v(N);
	rep(i, N) cin >> v[i];
	sort(all(v));
	reverse(all(v));

	ll a = 0, b = 0;
	rep(i, N) {
		if(i % 2) b += v[i];
		else a += v[i];
	}
	printf("%lld\n", a - b);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
const ll BIG=1e15;

int main(){
    ll N,K; cin>>N>>K;
    vector<ll> d(N+1,0);
    
    ll ans=0;
    for(int i=1;i<N+1;i++){
        ll x; cin>>x;
        x--;
        x=(x%K);
        d.at(i)=(d.at(i-1)+x)%K;
    }
    
    if(K<N){
        vector<ll> m[K];
        for(int i=0;i<=N;i++) {
            m[d.at(i)].push_back(i);
        }
        

        for(int i=0;i<K;i++){
            int X=m[i].size();
            if(X>1){
                int memory=1;
                for(int j=0;j<X-1;j++){
                    while(memory<X){
                        if(m[i].at(memory)-m[i].at(j)<K) memory++;
                        else break;
                    }
                    if(memory==X) memory--;
                    else if(m[i].at(memory)-m[i].at(j)>=K) memory--;

                    //cout<<'*'<<memory<<' '<<j<<endl;
                    ans+=(memory-j);
                }
            }
        }
    }

    else{
        sort(d.begin(),d.end());
        vector<ll> V;
        ll memory=d.at(0);
        ll count=1;
        ll x=1;
        while(true){
            if(x==N+1) break;
            if(d.at(x)==memory) count++;
            else {
                V.push_back(count);
                count=1;
                memory=d.at(x);
            }
            x++;
        }
       // for(int i=0;i<d.size();i++) cout<<d.at(i)<<endl;
        
        V.push_back(count);
        for(int i=0;i<V.size();i++) {
            //cout<<V.at(i)<<' '; 
            ans+=(V.at(i)-1)*V.at(i)/2;
        }
        //cout<<endl;
    }

    cout<<ans<<endl;


}


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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll,int> ii;
typedef pair <ii,int> iii;

const int mod = 1e9 + 7;
const ll INF = (1LL<<50);
const int N = 100005;

ll dp[3005][3005];

int main(){
	fastio;
	int n;
	cin >> n;
	vector<int> v(n);
	for(int i = 0; i < n; i++)
		cin >> v[i];
	// dp[i][j] = max diff with indices from i to j
	for(int L = n-1; L >= 0; L--){
		for(int R = L; R < n; R++){
			if(L == R){
				dp[L][R] = v[L];
			} else {
				dp[L][R] = max(v[L] - dp[L+1][R], v[R] - dp[L][R-1]);
			}
		}
	}
	cout << dp[0][n-1] << '\n';
	return 0;
}


Measured memory_bytes: 49692
#include<iostream>
#include<array>
#include<set>
#include<vector>

using namespace std;

typedef array<int,6> Dice;
int TF[2][3][3];
Dice dice[24];
Dice puzzle[3][3][3];
set<int> ans;

void rot(Dice &d,vector<int> v){
  auto t=d[v[0]];
  d[v[0]]=d[v[1]];
  d[v[1]]=d[v[2]];
  d[v[2]]=d[v[3]];
  d[v[3]]=t;
}

void dfs(int d){
  if(d==27){
    int s=0;
    for(int i=0;i<3;i++){
      for(int j=0;j<3;j++){
	s+=puzzle[i][j][2][2];
      }
    }
    ans.insert(s);
  }else{
    int z=d/9,y=d/3%3,x=d%3;
    for(auto e:dice){
      if(z){
	if(puzzle[z-1][y][x][4]+e[1]!=7)continue;
      }else{
	if(TF[1][y][x]&&TF[1][y][x]!=e[1])continue;
      }
      if(y){
	if(puzzle[z][y-1][x][5]+e[0]!=7)continue;
      }else{
	if(TF[0][2-z][x]&&TF[0][2-z][x]!=e[0])continue;
      }
      if(x&&puzzle[z][y][x-1][2]+e[3]!=7)continue;
      puzzle[z][y][x]=e;
      dfs(d+1);
    }
  }
}

int main(){
  Dice d{1,2,3,4,5,6};
  for(int i=0;i<6;i++){
    if(i%2){
      rot(d,{0,1,5,4});
    }else{
      rot(d,{0,2,5,3});
    }
    for(int j=0;j<4;j++){
      rot(d,{1,2,4,3});
      dice[i*4+j]=d;
    }
  }
  int N;
  cin>>N;
  while(N--){
    for(int i=0;i<2;i++){
      for(int j=0;j<3;j++){
	for(int k=0;k<3;k++){
	  cin>>TF[i][j][k];
	}
      }
    }
    ans.clear();
    dfs(0);
    if(ans.empty()){
      cout<<0<<endl;
    }else{
      bool f=false;
      for(auto e:ans){
	if(f++){
	  cout<<' ';
	}
	cout<<e;
      }
      cout<<endl;
    }
  }
}

Measured memory_bytes: 1200
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n).map(|_| iterator.next().unwrap().parse().unwrap()).collect();

    let k: usize = keta(*a.iter().max().unwrap());
    let mut v: Vec<Vec<usize>> = vec![vec![0, 0]; k];
    for i in 0..n {
        let mut ai = a[i];
        for j in (0..k).rev() {
            v[j][ai % 2] += 1;
            ai /= 2;
        }
    }

    const MOD: usize = 1_000_000_007;
    let mut ans: usize = 0;
    let mut x = 1;
    for i in (0..k).rev() {
        ans += (((v[i][0] * v[i][1]) % MOD) * x) % MOD;
        ans %= MOD;
        x = (x * 2) % MOD;
    }
    ans.to_string()
}

fn keta(mut x: usize) -> usize {
    if x == 0 {
        return 0;
    }
    let mut result = 0;
    while x > 0 {
        x /= 2;
        result += 1;
    }
    result
}


Measured memory_bytes: 10000
import numpy as np,math,itertools



def func(n:str):
   b=[]
   ll=[]
   for i in n:
      if not i in b:
         b+=[i]
      ll+=[b.index(i)]
   return ll


s=input()
t=input()
rs=False
##print(func(s))
if func(s)==func(t):print("Yes")
else:print("No")

Measured memory_bytes: 21648
#include <stdio.h>

typedef struct{int m,x[10],y[10];} sen;

int test(sen *s,int i){
 int j,pat,dx,dy;
 pat=0;
 for(j=1;j<s[0].m;j++){
  dx=s[0].x[j]-s[0].x[j-1];
  dy=s[0].y[j]-s[0].y[j-1];
  if(j==1){
   if(s[i].x[j]-s[i].x[j-1]==dx &&s[i].y[j]-s[i].y[j-1]==dy) pat=1;
   if(s[i].x[j]-s[i].x[j-1]==-dy&&s[i].y[j]-s[i].y[j-1]==dx) pat=2;
   if(s[i].x[j]-s[i].x[j-1]==-dx&&s[i].y[j]-s[i].y[j-1]==-dy)pat=3;
   if(s[i].x[j]-s[i].x[j-1]==dy &&s[i].y[j]-s[i].y[j-1]==-dx)pat=4;
  }else{
   if(pat==1)if(s[i].x[j]-s[i].x[j-1]!=dx ||s[i].y[j]-s[i].y[j-1]!=dy)pat=0;
   if(pat==2)if(s[i].x[j]-s[i].x[j-1]!=-dy||s[i].y[j]-s[i].y[j-1]!=dx)pat=0;
   if(pat==3)if(s[i].x[j]-s[i].x[j-1]!=-dx||s[i].y[j]-s[i].y[j-1]!=-dy)pat=0;
   if(pat==4)if(s[i].x[j]-s[i].x[j-1]!=dy ||s[i].y[j]-s[i].y[j-1]!=-dx)pat=0;
  }
  if(!pat)break;
 }
 return pat?1:0;
}

int main(){
 int i,j,n,flag,pat,dx,dy;
 sen s[52];
 for(;;){
  scanf("%d",&n);
  if(!n)break;
  for(i=0;i<=n;i++){
   scanf("%d",&(s[i].m));
   for(j=0;j<s[i].m;j++){
    scanf("%d%d",s[i].x+j,s[i].y+j);
   }
   if(!i || s[i].m!=s[0].m)continue;
//non-reverse
   if(test(s,i)){printf("%d\n",i);continue;}
//reverse
   for(j=0;j<s[i].m;j++){
    s[i+1].x[s[i].m-j-1]=s[i].x[j];
    s[i+1].y[s[i].m-j-1]=s[i].y[j];
   }
   if(test(s,i+1)){printf("%d\n",i);continue;}
  }
  printf("+++++\n");
 }
 return 0;
}

Measured memory_bytes: 0
N=int(input())
flag=0

x=[list(map(int,input().split())) for _ in range(N)]
x.insert(0,[0,0,0])



for i in range(N):
  if abs(x[i][0]-x[i+1][0])<(abs(x[i][1]-x[i+1][1])+abs(x[i][2]-x[i+1][2])):
    flag=1
  if x[i][1]==x[i+1][1] and x[i][2]==x[i+1][2]:
    flag=1
  if abs(x[i][0]-x[i+1][0])%2!=(abs(x[i][1]-x[i+1][1])+abs(x[i][2]-x[i+1][2]))%2:
    flag=1

if flag==0:
  print("Yes")
else:
  print("No")
    

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

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	long long int n, m;
	cin >> n >> m;
	if(n < m){
		swap(n, m);
	}
	if(m == 1){
		cout << abs(n-2) << '\n';
		return 0;
	}
	else{
		long long int corner, ed, in;
		corner = 4;
		in = (n-2)*(m-2);
		ed = n*m - in - corner;
		cout << in << '\n';
	}

	return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	pair<int, int> p[n];
	for(int i=0; i<n; i++){
		cin >> p[i].first >> p[i].second;
	}

	double ans=0.0;
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			ans+=sqrt(pow((double)(p[i].first-p[j].first), 2.0)+pow((double)(p[i].second-p[j].second), 2.0));
		}
	}
	printf("%.9f\n", ans/n);
	return 0;
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

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

int main(){
  double n, k;
  cin >> n >> k;
  double ans = 0.;
  if (n >= k) {
    ans += (n - k + 1.)/n;
  }
  ll lim = min(k, n + 1);

  FOR(i, 1, lim) {
    int x = log2(k) - log2(i);
    while (true) {
      if (pow(2, x) * i >= k)
        break;
      else
        x++;
    }
    ans += (1. / n) * (1. / pow(2, x));
  }
  printf("%0.10f\n", ans);
  return 0;
}


Measured memory_bytes: 384
require 'bigdecimal'

def f(x)
  BigDecimal.new(x.to_s, $d)
end

loop do
  n, k, m, r = gets.split.map{|x| x.to_i}
  break if n == 0
  $d = r + 10
  ans = f(1) / f(n)
  if m == 1
    s = f(1)
    (1..n-1).each {|i| s += f(1) / f(i) }
    ans *= s
  end
  puts ans.to_s("F").ljust($d, "0")[0..r+1]
end

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

using namespace std;
using ll = long long;


int main()
{
    int n;ll v; cin >> n >> v;
    vector<vector<ll>> a(4, vector<ll>(n));
    for(int i = 0; i < 4; i++) {
        for(int j = 0; j < n; j++)cin >> a[i][j];
    }
    vector<ll> fr, bc;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++)fr.emplace_back(a[0][i] + a[1][j]);
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++)bc.emplace_back(a[2][i] + a[3][j]);
    }

    sort(fr.begin(), fr.end());
    sort(bc.begin(), bc.end());
    ll cnt = 0;
    for(ll i : fr) {
        cnt += upper_bound(bc.begin(), bc.end(), v - i) - lower_bound(bc.begin(), bc.end(), v - i);
    }
    cout << cnt << endl;
}


Measured memory_bytes: 23144
#include <stdio.h>

int main(){
	int H,W,i,j;
	while(1){
		scanf("%d %d",&H,&W);
		if(H==0 && W==0)break;
		for(i=1;i<=H;i++){
			for(j=1;j<=W;j++){
				printf("#");
			}
			puts("");
		}
		puts("");
	}
return 0;
}


Measured memory_bytes: 2132
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long ll;
 
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())

int main() {

    int N; cin >> N;
    vector<int> a(N);
    REP(i,N) cin >> a[i];

    sort(a.begin(),a.end());

    cout << a[a.size() - 1] - a[0] << endl;

    return 0;
}

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

int main(){
	int n,q,s[100000],t[50000];
	scanf("%d",&n);
	for (int i=0;i<n;i++)
		scanf("%d",s+i);
	scanf("%d",&q);
	for (int i=0;i<q;i++)
		scanf("%d",t+i);
	int count=0;
	for (int i=0;i<q;i++){
		if (*lower_bound(s,s+n,t[i])==t[i]){
			count++;
		}		
	}
	printf("%d\n",count);
}	


Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
#define rep(i,m,n) for(int i=m;i<n;i++)
using ll=long long;
ll mod=1e9+7;

int main(){
  string s;
  cin>>s;
  int n=s.size();
  ll a=0;
  ll b=0;
  ll c=0;
  ll cur=1;
  rep(i,0,n){
    if(s[i]=='A'){
      a+=cur;
      a%=mod;
    }
    else if(s[i]=='B'){
      b+=a;
      b%=mod;
    }
    else if(s[i]=='C'){
      c+=b;
      c%=mod;
    }
    else{
      ll d=3*a+cur;
      ll e=3*b+a;
      ll f=3*c+b;
      d%=mod;
      e%=mod;
      f%=mod;
      a=d;
      b=e;
      c=f;
      cur*=3;
      cur%=mod;
    }
  }
  //cout<<a<<endl;
  //cout<<b<<endl;
  cout<<c<<endl;
}

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

int main(void)
{
	int num[101], tempn, index[101][31], i, j, k, l, m, alc, count;
	char word[101][31],tempw[31],dict[101][31];

	i = 0;
	while (~scanf("%s %d", word[i], &num[i]))
		i++;
	i = i - 1;
	j = 0;  
	while (j < i)    
	{      
		if (strcmp(word[j], word[j+1]) > 0)
		{
			strcpy(tempw, word[j]);
			strcpy(word[j], word[j+1]);
			strcpy(word[j+1], tempw);
			tempn = num[j];
			num[j] = num[j+1];
			num[j+1] = tempn;      
			j=0;
		}    
		else
			j++;
	}

	l = 0;
	alc = 0;
	count = 0;
	for (k = 0; k <= i; k++)    
	{      
		if (k == 0)
		{      
			strcpy(dict[0], word[0]);
			index[0][0] = num[0];
			l++;
		}      
		else    
		{      
			if (strcmp(dict[l-alc-1], word[k]) != 0)
			{          
				count = 0;
				strcpy(dict[l-alc], word[k]);
				index[l-alc][0] = num[k];
				l++;
			}      
			else
			{
				count++;
				alc++;
				index[l-alc][count] = num[k];
				l++;
			}
		}
	}
	for (k=0;k<i;k++)
	{
		m = 0;
		while (index[k][m+1] != 0)
		{
			if (index[k][m] > index[k][m+1])
			{
				tempn = index[k][m];
				index[k][m] = index[k][m+1];
				index[k][m+1] = tempn;
				m = 0;
			}
			else
				m++;
		}
	}
	for (k = 0; k < l-alc; k++)
	{
		m = 0;
		printf("%s\n", dict[k]);
		while (index[k][m+1] != 0)
		{
			printf("%d ", index[k][m]);
			m++;
		}
		printf("%d\n", index[k][m]);
	}

	return 0;
}

Measured memory_bytes: 648
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <queue>
#include <sstream>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), a + n
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)

using namespace std;

typedef long long ll;

const double EPS = 1e-10;
const double PI = acos(-1.0);

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

int main() {
	int n;
	scanf("%d", &n);
	vector<int> a(n);
	vector<int> b(n);
	vector<int> c(n - 1);
	for(auto&& e : a) {
		scanf("%d", &e);
	}
	for(auto&& e : b) {
		scanf("%d", &e);
	}
	for(auto&& e : c) {
		scanf("%d", &e);
	}

	int result = 0;
	REP(i, n) {
		result += b[a[i] - 1];
		if(i != n - 1) {
			if(a[i] + 1 == a[i + 1]) {
				result += c[a[i] - 1];
			}
		}
	}

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

Measured memory_bytes: 256
h,w = map(int,input().split())
s = [list(input()) for _ in range(h)]
u = [[0]*w for _ in range(h)]
d = [[0]*w for _ in range(h)]
l = [[0]*w for _ in range(h)]
r = [[0]*w for _ in range(h)]
for i in range(h):
  l[i][0] = int(s[i][0] != "#")
  for j in range(1,w):
    if s[i][j] == "#":
      l[i][j] = 0
    else:
      l[i][j] = l[i][j-1] + 1
  r[i][w-1] = int(s[i][w-1] != "#")
  for j in range(w-2,-1,-1):
    if s[i][j] == "#":
      r[i][j] = 0
    else:
      r[i][j] = r[i][j+1] + 1 
for i in range(w):
  d[0][i] = int(s[0][i] != "#")
  for j in range(1,h):
    if s[j][i] == "#":
      d[j][i] = 0
    else:
      d[j][i] = d[j-1][i] + 1
  u[h-1][i] = int(s[h-1][i] != "#")
  for j in range(h-2,-1,-1):
    if s[j][i] == "#":
      u[j][i] = 0
    else:
      u[j][i] = u[j+1][i] + 1
ans = 0
for i in range(h):
  for j in range(w):
    cur = l[i][j] + r[i][j] + u[i][j] + d[i][j]
    if cur>ans:
      ans = cur
print(ans - 3)

Measured memory_bytes: 309768
using System;
using System.ComponentModel;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            if (str == "ABC")
            {
                Console.WriteLine("ARC");
            }
            else
            {
                Console.WriteLine("ABC");
            }
        }
    }
}


Measured memory_bytes: 25796
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

const int INF = 1e9;
const long long LINF = 1e18;

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

    if (a >= 3200) {
        cout << s << endl;
    } else {
        cout << "red" << endl;
    }

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] % 2 != 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  bool flag = true;
  for (int i = 0;; i++) {
    for (int j = 0; j < N; j++) {
      if (A[j] % 2 == 0) {
        A[j] /= 2;
      } else {
        flag = false;
        break;
      }
    }
    if (flag == false) {
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <cmath>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <stdio.h>

using namespace std;

typedef long long ll;
ll k, a, b;
ll sum;
int main() {
	scanf("%lld%lld%lld", &k, &a, &b);
	sum = 1;
	if (b - a <= 1 || k <= a - 1) { printf("%lld\n", k + 1); return 0; }
	k = k - a + sum;
    sum = a;
    sum += b*(k / 2);
	sum -= a * (k / 2);
    if (k & 1) sum++;
	printf("%lld\n", sum);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
typedef lli elm;
typedef vector<elm> vec;
typedef vector<vec> mat;

lli N, M, A, B, C, T;

mat getE(int n) {
  mat e(n, vec(n, 0));
  for(int i = 0; i < n; ++i) {
    e[i][i] = 1;
  }
  return e;
}

mat multiply(const mat &a, const mat &b) {
  if(a.size() == 0 || b.size() == 0 ||
     a[0].size() != b.size()) return mat();
  int s = a.size();
  int t = b.size();
  int u = b[0].size();
  mat c(s, vec(u, 0));
  for(int i = 0; i < s; ++i) {
    for(int j = 0; j < u; ++j) {
      for(int k = 0; k < t; ++k) {
        ( c[i][j] += a[i][k] * b[k][j] % M ) %= M;
      }
    }
  }
  return c;
}

mat pow(const mat &a, const lli &n) {
  if(n == 0) return getE(a.size());
  mat b = pow(multiply(a, a), n/2);
  if(n & 1) return multiply(b, a);
  else return b;
}

int main() {
  while(cin >> N >> M >> A >> B >> C >> T &&
        (N|M|A|B|C|T)) {
    mat S(N, vec(1));
    for(int i = 0; i < N; ++i) cin >> S[i][0];

    mat D(N, vec(N));
    for(int i = 0; i < N; ++i) {
      if(i-1 >= 0) D[i][i-1] = A;
      D[i][i] = B;
      if(i+1 < N) D[i][i+1] = C;
    }
    D = pow(D, T);
    S = multiply(D, S);
    for(int i = 0; i < N; ++i) {
      if(i) cout << " ";
      cout << S[i][0];
    }
    cout << endl;
  }
  return 0;
}

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

int main() {
  int A, B, C;
  cin >> A >>B >>C;
  cout << min(B / A, C) << endl;
  return 0;
}


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

long long N, S, A[1 << 18], B[1 << 18];

int main() {
	cin >> N; A[0] = (1 << 30); A[N] = (1 << 30);
	for (int i = 1; i <= N - 1; i++) cin >> A[i];
	for (int i = 1; i <= N; i++) B[i] = min(A[i - 1], A[i]);
	for (int i = 1; i <= N; i++) S += B[i];
	cout << S << endl;
	return 0;
}

Measured memory_bytes: 2304
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			int N = Integer.parseInt(str);
			str = br.readLine();
			String[] s = str.split(" ",0);
			int[] a = new int[8];
			for(int i = 0;i<8;i++) {
				a[i] = 0;
			}
			int count = 0;
			int over = 0;
			for(int i = 0;i < N; i++) {
				int x = Integer.parseInt(s[i]);
				if(x >=3200) {
					over++;
				}else if(a[x/400] == 0) {
					count++;
					a[x/400]++;
				}
			}
			int min = count;
			if(min == 0) min = 1;
			int max = over+count;
			System.out.println(min+" "+max);
//			long max  = 1000000007;
		}catch (Exception e) {
			System.exit(0);
		}
	}
}


Measured memory_bytes: 21204
#include <iostream>
using namespace std;
int f[4]={1,505,-1,-505},I,n,p,x,y,i,j,X,Y,d[255025],a,w[255025];
void D(int x){
    for(int i=0;i<4;++i){
        int X=x+f[i];
        if(d[X]>d[x]+w[X])
			d[X]=d[x]+w[X],D(X);
	}
}
int main(){
	cin>>n;
	for(I=0;I<n*n;++I){
      x=I/n+1,y=I%n+1;
      i=x*505+y;
      w[i]=1,d[i]=min(min(x,n-x+1),min(y,n-y+1));
    }
	for(i=1;i<=n*n;++i){
		cin>>p;p--;x=p/n+1;y=p%n+1;x=x*505+y;
		a+=--d[x];w[x]=0;D(x);
	}
	cout<<a<<endl;
}


Measured memory_bytes: 20920
#include <bits/stdc++.h>
using namespace std;
int main(){
   int a;
   cin >> a;
   a %= 10;
   if(a == 3)cout << "bon" << endl;
   else if(a == 0 or a == 1 or a == 6 or a == 8)cout << "pon" << endl;
   else cout << "hon" << endl;
}

Measured memory_bytes: 3672
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));
        String str;
 
        while(!(str=br.readLine()).equals("0")){
            int n = Integer.parseInt(str);
            long score=0;
            long max = Long.MIN_VALUE;
 
            for(int i=0; i<n; i++){
                int a =Integer.parseInt(br.readLine());
                score = Math.max(score+a, a);
                max = Math.max(score, max);
            }
            System.out.println(max);
        }
    }
}

Measured memory_bytes: 21548
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int total = sc.nextInt();
		int participant = sc.nextInt();
		if (total % participant == 0) {
			System.out.println(0);
		} else {
			System.out.println(1);
		}
	}
}


Measured memory_bytes: 22740
#include<iostream>
#include<string>
using namespace std;
 
int main(){
	long long x,y;
	string ans = "No";

	cin >> x >> y;

	for(int i = 0; i <= x; i++){
		if(((i*2) + ((x-i)*4)) == y){
			ans = "Yes";
			break;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 3616
#include <stdio.h>
 
int main(void){
  int i;
  char st,al[53] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
   
  do{
    scanf("%c", &st);
 
    for(i=0;i<52;i++)
      if(al[i] == st){
        st = al[ (i+26)%52 ];
        break;
      }
 
    printf("%c", st);
 
  }while(st != '\n');
 
  return 0;
}


Measured memory_bytes: 2052
using System;
using System.Linq;
public class B{
    public static void Main(){
        int n = int.Parse(Console.ReadLine());
        int[] l = Console.ReadLine().Split().Select(x=>int.Parse(x)).ToArray();
        int sum = l.Sum();
        int max = l.Max();
        if (max*2<sum){
            Console.Write("Yes");
        }
        else{
            Console.Write("No");
        }
    }
            
}  
        
    



Measured memory_bytes: 13396
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, const T& t){ return v2<T>(r, vector<T>(c, t)); }
#define F first
#define S second

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

    vector<pair<int, int>> p(n);
    for(int i = 0; i < n; ++i) cin >> p[i].F >> p[i].S;

    int mxxpy=INT_MIN, mnxpy=INT_MAX;
    int mxxmy=INT_MIN, mnxmy=INT_MAX;
    for(int i = 0; i < n; ++i){
        int x = p[i].F;
        int y = p[i].S;

        mxxpy = max(mxxpy, x+y);
        mnxpy = min(mnxpy, x+y);

        mxxmy = max(mxxmy, x-y);
        mnxmy = min(mnxmy, x-y);
    }

    int ans = max(mxxpy-mnxpy, mxxmy-mnxmy);
    cout << ans << "\n";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 4776
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
int t[1010];

int main(){
    
    // 1. 入力情報.
    int N, A, B;
    scanf("%d %d %d", &N, &A, &B);
    
    // 2. 出席する授業の数.
    int ans = N;
    rep(i, N){
        int t;
        scanf("%d", &t);
        ans -= (t >= A && t < B) ? 1 : 0;
    }
    
    // 3. 出力.
    printf("%d\n", ans);
    return 0;
    
}

Measured memory_bytes: 256
def solve():
    N, K = [int(_) for _ in raw_input().split()]
    S = raw_input()
    elms = [S[0]]
    cnts = []
    cnt = 1
    for i in range(1,N):
        if S[i] == elms[-1]:
            cnt += 1
        else:
            cnts.append(cnt)
            elms.append(S[i])
            cnt = 1
    cnts.append(cnt)
    num_elm = len(elms)
    max_cont1 = 0
    tmp = 0
    for i in range(num_elm):
        if i == 0:
            if elms[i] == '0':
                tmp = sum(cnts[i:(i+2*K)])
                max_cont1 = max(max_cont1, tmp)
            if elms[i] == '1':
                tmp = sum(cnts[i:(i+2*K+1)])
                max_cont1 = max(max_cont1, tmp)
        elif i == 1:
            if elms[i] == '1':
                tmp -= cnts[i-1]
                if i + 2*K - 1 < num_elm:
                    tmp += cnts[i + 2*K - 1]
                if i + 2*K < num_elm:
                    tmp += cnts[i + 2*K]
                max_cont1 = max(max_cont1, tmp)
        else:
            if elms[i] == '1':
                tmp -= cnts[i - 2]
                tmp -= cnts[i - 1]
                if i + 2*K - 1 < num_elm:
                    tmp += cnts[i + 2*K - 1]
                if i + 2*K < num_elm:
                    tmp += cnts[i + 2*K]
                max_cont1 = max(max_cont1, tmp)
    print str(max_cont1)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 9952
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;

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

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = 0;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}


//ここまでライブラリ
//ここから本文


int main() {
	string s;
	cin >> s;
	int saisyo = 1000;
	int z = 0;
	for (int i = 0; i < s.size() - 2; i++) {
		int d = ((int)s.at(i) - '0') * 100 + ((int)s.at(i + 1) - '0') * 10 + ((int)s.at(i + 2) - '0');
		if (saisyo > abs(753 - d)) {
			saisyo = abs(753 - d);
			z = d;
		}
	}
	cout << saisyo << endl;
}


Measured memory_bytes: 256
#include<iostream>
#define MAX 10
#define S_MAX 330

using namespace std;

int gn;
int ganses[MAX+1][S_MAX+1];
int gp[MAX];
int gnums[MAX];
int qq[MAX+1][MAX+1];

/* genperm1 from http://www5.airnet.ne.jp/tomy/cpro/pe1.htm (C) Tomy */
void genperm1(int p[], int n)
{
	int c[MAX], *pc, *q;
	int k, t;

	for(k = 1, q = p, pc = c; k <= n; )	*q++ = *pc++ = k++;
	k = 1;
	pc = c;
	do
	{
		int tmp = 0;

		t = *(p + k);
		*(p + k) = *(q = p + ((k & 1)? *pc: 0));
		*q = t;
		for(int i = 0; i < n; i++) tmp += qq[i + 1][gnums[p[i] - 1]];
		ganses[n][tmp]++;
		k = 1;
		pc = c;
		while(*pc == 0)	*pc++ = k++;
		(*pc)--;
	} while(k < n);
}

void comb(int n, int k){
	bool loop = false;

	for(int i = 0; i < k; i++) gnums[i] = i;

	do{
		loop = false;

		// TODO
		genperm1(gp, k);
		
		for(int pk = k - 1; pk >= 0; pk--){
			gnums[pk]++;
			if( gnums[pk] <= n - (k - pk) ){
				for(int j = pk + 1; j < k; j++) gnums[j] = gnums[j - 1] + 1;
				pk++;
				loop = true;
				break;
			}
		}
	}while(loop);
}

int main(){
	for(int i = 0; i < sizeof(qq)/sizeof(qq[0]); i++){
		for(int j = 0; j < sizeof(qq[0])/sizeof(qq[0][0]); j++){
			qq[i][j] = i * j;
		}
	}
	for(int i = 1; i <= MAX; i++){
		comb(MAX,i);
	}
	while( 1 ){
		int n, s, ans = 0;

		cin >> n >> s;
		if( cin.eof() ) break;

		if( s >= 0 && s <= S_MAX ) ans = ganses[n][s];

		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 760
// C - HonestOrUnkind2
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int N, A[15], X[15][15], Y[15][15];

int check(int bits){
	int count = 0;
	rp(i, 0, N)
		if(bits>>i&1){
			count++;
			rp(j, 0, A[i]) if((bits>>X[i][j]&1) != Y[i][j]) return 0;
		}
	return count;
}

int main(){
	scanf("%d",&N);
	rp(i, 0, N){ scanf("%d",A+i); rp(j, 0, A[i]){ scanf("%d%d",X[i]+j,Y[i]+j); X[i][j]--; } }
	int ans = 0;
	rp(bits, 1, 1<<N) ans = max(ans, check(bits));
	printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
int read(){
	register int x = 0;
	register char f = 1, ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') f ^= 1;
	for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ '0');
	return f ? x : -x;
}
int n, m;
int main(){
	n = read(), m = read();
	if (n <= 9 && m <= 9) printf("%d\n", n * m);
	else printf("-1\n");
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**8)

s = input()

words = ['dream', 'dreamer', 'erase', 'eraser']
def dfs(idx):
    if idx == len(s):
        return True
    ans = False
    for word in words:
        if s[idx:idx+len(word)] == word:
            ans = ans or dfs(idx + len(word))

    return ans

if dfs(0):
    print("YES")
else:
    print("NO")


Measured memory_bytes: 19036
import sys

# 関数 solve は，もちろん，問題に応じて書き換える
def solve(x,y):
    answer = x+y//2
    return answer

# ここから下は，入力・出力形式が同じであれば，変えなくて良い．
def readQuestion():
    line = sys.stdin.readline().rstrip()
    [str_a, str_b] = line.split(' ')
    return (int(str_a), int(str_b))

def main():
    a, b = readQuestion()
    answer = solve(a, b)
    print(answer)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
#define FOR(i,l,r) for (int i = (l); i < (r); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUM(c) accumulate(ALL(c), 0)
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define SZ(c) ((int)(c).size())
#define debug(x) cerr << #x << " = " << (x) << '\n';
using P = pair<int,int>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
static const double EPS = 1e-10;
static const double PI  = acos(-1.0);
static const ll MOD = 1000000007;
// static const ll MOD = 998244353;
static const int INF = 1 << 30;
// static const ll INF = 1LL << 62;
// --------------------------------------------------------


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);

    int N; cin >> N;

    int ans = 0;
    FOR(A, 1, N) {
        ans += (N - 1) / A;
    }
    cout << ans << '\n';

    return 0;
}


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

int main(){
    int n,k;
    cin >> n >> k;
    int s=k;
    for(int i=0;i<n-1;i++){
        s*=(k-1);
    }
    cout << s;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl; 有効桁数指定
// *min_element(c + l, c + r) *max_element(c + l, c + r) 配列の中のmin-max
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// ~ は、-1の時だけfalse
// struct Edge {
//   int to, id;
//   Edge(int a, int b): to(a), id(b) {}
// };

int main(int argc, char const *argv[])
{
	int n,m;cin>>n>>m;

	int a[110],sum=0;
	rep(i,n) {
		cin>>a[i];
		sum+=a[i];
	}

	// int x = sum/(4*m);

	int x;

	if (sum%(4*m)==0) {
		x = sum/(4*m);
	} else {
		x = sum/(4*m) + 1;
	}

	sort(a,a+n);
	reverse(a,a+n);

	// cout<<x<<" "<<a[2]<<endl;

	// rep(i,n) {
	// 	if (a[i]>=x) {
	// 		if (i+1>=m) {
	// 			cout<<"Yes"<<endl;
	// 			return 0;
	// 		} 
	// 	}
	// 	else {
	// 		cout<<"No"<<endl;
	// 		return 0;
	// 	}
	// }

	if (a[m-1]>=x) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <cstdio>      /* printf, scanf, puts, NULL */
#include <cstdlib>     /* srand, rand */
#include <ctime>       /* time */
#include <fstream>
#include <algorithm>
#include <vector>
#include <map>
#include <list>

using namespace std;

int x;
long long res, total;

int main() {

    std::ios::sync_with_stdio(false);
	// freopen("test.txt", "r", stdin);


    cin >> x;

    res = 0;
    total = 0;

    while (total < x) {
        res++;
        total += res;
    }

    cout << res << endl;

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
#define NUM 100001

void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int GCD(int a,int b){int c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
int LCM(int a,int b){return a*b/GCD(a,b);}
int POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return (int)ans;}
int icmp(const void* a,const void* b){return *(int*)a-*(int*)b;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int scmp(const void* a,const void* b){return strcmp(*(char**)a,*(char**)b);}
LL fac[NUM],finv[NUM],inv[NUM];
void comi(){int i;fac[0]=fac[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){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||n<0||k<0)return 0;return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;}


typedef struct{LL A,B;}P;
int cmp(const void* a,const void* b){return ((P*)a)->A-((P*)b)->A;}

int main(){
  LL N,M,i,ans=0;
  scanf("%lld%lld",&N,&M);
	P p[N];
	FOR(i,0,N)scanf("%lld%lld",&p[i].A,&p[i].B);
	qsort(p,N,sizeof(P),cmp);
	FOR(i,0,N){
		LL a=p[i].A,b=p[i].B;
		if(b<=M){
			ans+=a*b;
			M-=b;
		}
		else{
			ans+=a*M;
			break;
		}
	}

  printf("%lld\n",ans);
	return 0;
}


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

#define M 1046527
#define L 14

int getChar(char);
long long getKey(char*);
int h1(int);
int h2(int);
int find(char*);
void insert(char*);

char H[M][L];

int main(){
  int i,n,h;
  char str[L],com[9];

  for(i=0;i<M;i++) H[i][0]='\0';

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s %s",com,str);

    if(com[0]=='i'){
      insert(str);
    }
    else{
      if(find(str)){
	printf("yes\n");
      }
      else printf("no\n");

    }
  }

  return 0;
}

int getChar(char ch){
  if(ch=='A') return 1;
  else if(ch=='C') return 2;
  else if(ch=='G') return 3;
  else if(ch=='T') return 4;
  else return 0;
}

long long getKey(char *str){
  long long sum=0,i,p=1;

  for(i=0;i<strlen(str);i++){
    sum+=p*(getChar(str[i]));
    p*=5;
  }

  return sum;
}

int h1(int key){
  return key%M;
}

int h2(int key){
  return 1+(key%(M-1));
}

int find(char *str){
  long long key,i,h;

  key=getKey(str);
  
  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0) return 1;
    else if(strlen(H[h])==0) return 0;
  }

  return 0;
}

void insert(char *str){
  long long key,i,h;
  
  key=getKey(str);

  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0) return;
    else if(strlen(H[h])==0){
      strcpy(H[h],str);
      return;
    }
  }

  return;
}



Measured memory_bytes: 16044