akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

int main(){
    int n;
    while(cin >> n, n){
        char m[1005][1005];
        int c[1005][1005] = {{0}};
        rep(i,n){
            rep(j,n){
                cin >> m[i + 1][j + 1];
            }
        }
        rep(i,n) m[i][0] = m[0][i] = m[i][n + 1] = m[n + 1][i] = '*';
        
        range(i,1,n + 1){
            range(j,1,n + 1){
                if(m[i][j] == '*') c[i][j] = 0;
                else c[i][j] = min(min(c[i - 1][j], c[i][j - 1]), c[i - 1][j - 1]) + 1;
            }
        }

        int maxi = 0;
        rep(i,n){
            rep(j,n){
                maxi = max(maxi, c[i + 1][j + 1]);
            }
        }
        cout << maxi << endl;
    }
}

Measured memory_bytes: 7908
#include <bits/stdc++.h>
const int MAX=1e6+10;
const int modn=1e9+7;
typedef long long ll ;
#define endl '\n'
#define cwk     freopen("D:\\workplace\\CLion\\in.in","r",stdin),freopen("D:\\workplace\\CLion\\out.out","w",stdout)
using namespace std;
int main() {
    ll x,k,d;
    cin>>x>>k>>d;
    ll cnt=abs(x)/d;
    if(k<cnt){
        if(x>0)
            cout<<x-d*k;
        else cout<<-d*k-x;
    }else {
        ll now = abs(x) - cnt * d;
        k -= cnt;
        k %= 2;
        if (k == 0) cout << now;
        else cout << d - now;
    }
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <unordered_map> 
#include <map>
#include <algorithm>
using namespace std;

int main(){
  map<int,int> m;
  long long int N,M;
  long long int ans = 0, pena = 0;
  unordered_map<int,int> num;
  cin >> N >> M;

  for(int i = 0;i<M;i++){
    long int p;
    string s;
    cin >> p >> s;
    if(s == "AC"){
      if(num[p] != 1){
	ans++;
	pena += m[p];
        num[p] = 1;
      }
    }
    else{
       if(num[p] != 1){
	 m[p]++;
       }
    }
  }

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


Measured memory_bytes: 8996
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>

#define MP make_pair
#define PB push_back
#define in int
#define ll long long
#define ull unsigned long long
#define vc vector
#define SQ(j) (j)*(j)
#define ch first
#define range second
//
//#define ld long double
#define dbl  double
#define pll pair<long long,long long>
#define pii pair<int,int>
#define sz(xxx) ((int)(xxx.size()))
#define all(j) j.begin(), j.end()
#define loop(xxx, yyy) for(int xxx = 0; xxx < yyy; xxx++)
//#define printf(fmt, ...) (0)
//#define HOME
//#define y0 ngacaleiebinvoaeu
//#define y1 gnarpipipaigare
#define j1 adsfndnasfafoasp

//#define printf(...) (0)
#define db(x) if(DEBUG) {cout << #x << " = " << x << endl;}
#define dbCont(x) if(DEBUG) {cout << #x << ": "; for(auto shun: x) cout << shun << ' '; cout<<endl;}

using namespace std;

template<class K, class V>
ostream &operator<<(ostream &out, pair<K, V> &elem) {
    out << "{" << elem.first << "," << elem.second << "}";
    return out;
}

// 4:13

int DEBUG = 1;

using namespace std;

const int N = 50;
int n,m;

char x[N][N];

int di[] = {0,1,0,-1};
int dj[] = {1,0,-1,0};

bool ins(int i, int j){
    return 0 <= i && i < n && 0 <= j && j < m;
}

int get(int si, int sj){

    queue<int> q;

    int dist[N][N];
    loop(i,n) loop(j,m) dist[i][j] = 1e9;

    int used[N][N];
    loop(i,n) loop(j,m) used[i][j] = 0;

    q.push(si);
    q.push(sj);
    used[si][sj] = 1;
    dist[si][sj] = 0;
    while(!q.empty()){
        int fi = q.front(); q.pop();
        int fj = q.front(); q.pop();

        loop(d,4){
            int ti = fi+ di[d];
            int tj = fj+ dj[d];
            if(ins(ti, tj) && !used[ti][tj] && x[ti][tj] == '.'){
                used[ti][tj] = 1;
                dist[ti][tj] = dist[fi][fj] + 1;
                q.push(ti);
                q.push(tj);
            }
        }
    }

    int mx = 0;
    loop(i,n){
        loop(j,m){
            if(used[i][j]) {
                mx = max(mx, dist[i][j]);
            }
        }
    }
    return mx;


}

int main() {
    cin >> n >> m;
    loop(i,n){
        string s;
        cin >> s;
        loop(j,m){
            x[i][j] = s[j];
        }
    }

    int ans = 0;
    loop(si,n){
        loop(sj, m){
            if(x[si][sj] == '.'){
                int mx = get(si,sj);

                ans = max(ans, mx);
            }
        }
    }

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

/*

7
1 0 0 5 0 0 2

 */

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

int main() {
    int N,A,B;
    cin >> N >> A >> B;
    int sum=0;

    for(int n = 1; n <=N; n++) {
        int a,b,c,d,e;
        e = n / 10000;
        d = n / 1000 - 10*e;
        c = n / 100 - 100*e - 10*d;
        b = n / 10 - 1000*e - 100*d - 10*c;
        a = n - 10000*e - 1000*d - 100*c - 10*b;
        if(A<= a+b+c+d+e && a+b+c+d+e <= B) sum+=n;

    }
    cout << sum << endl;



}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<cmath>
#include<cstdio>
using namespace std;
#define pi acos(-1)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    double f=(h*5)+(m/12),d;
    if(m==0)m=60;
    d=(max(f-m,m-f)*6);
    printf("%.16lf",sqrt((a*a)+(b*b)-(cos((pi*d)/180)*a*b*2)));
}


Measured memory_bytes: 4244
#include<cstdio>
#include<algorithm>
using namespace std;
int D[1<<26];
int n, w[201000];
char p[201000];
int main(){
    int i, j, t;
    scanf("%s",p+1);
    for(i=1;p[i];i++){
        w[i] = w[i-1]^(1<<(p[i]-'a'));
    }
    n = i-1;
    D[0]=1;
    for(i=1;i<=n;i++){
        t = 1e9;
        for(j=0;j<26;j++){
            if(D[w[i]^(1<<j)]) t = min(t, D[w[i]^(1<<j)]+1);
        }
        if(D[w[i]])t = min(t, D[w[i]]+1);
        if(!D[w[i]] || D[w[i]]>t)D[w[i]]=t;
    }
    printf("%d\n",t-1);
}


Measured memory_bytes: 263040
main = readAndDo

readAndDo = do
  line <- getLine
  if line == "0 0" then return ()
  else do
    let [a, b] = input line
    solve [a, b, a]
    putStrLn ""
    readAndDo

-- 入力
input :: String -> [Int]
input = (map read) . words

-- 解答
solve [0, b, c] = return ()
solve [a, 1, c] = do
  putStrLn "#"
  solve [a-1, 1, c]
solve [a, b, c]
  | a == 1 || a == c = do
    putStrLn $ foldr (++) "" $ replicate b "#"
    solve [a-1, b, c]
  | otherwise = do
    putStrLn $ "#" ++ (foldr (++) "" $ replicate (b-2) ".") ++ "#"
    solve [a-1, b, c]



Measured memory_bytes: 4168
#include<bits/extc++.h>
#ifdef _debug 
#define dout(i) cout << #i << ' ' << i << ' '
#else 
#include<bits/stdc++.h>
#define dout(i) 0&&0
#endif
#pragma GCC optimize("unroll-loops,no-stack-protector,O3")
#define eout(i) {cout << (i) << '\n';exit(0);}
#define rout(i) {return cout << (i) << '\n', 0;}
#define priority_queue __gnu_pbds::priority_queue
#define unordered_map __gnu_pbds::gp_hash_table
#define rep(a, b) {for(int _i = a;_i > 0;--_i){b;}}
#define multe int _T;for(cin >> _T;_T--;)
using namespace std;
using ll = long long;using ull = unsigned long long;using ul = unsigned;using db = double;
using __gnu_pbds::null_type;
template<typename T> void read(int n, T s){while(n--)cin >> *s, ++s;}
template<typename T> void write(int n, T s){while(n--)cout << *s << " \n"[n==0], ++s;}
template<typename T> using rbtree = __gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T> inline ostream& operator << (ostream &ou, const vector<T> &a){for(auto it = a.begin();it != a.end();++it)ou << (it != a.begin() ? " " : "") << *it;return ou;}
template<typename T1, typename T2>inline istream& operator >> (istream &in, pair<T1, T2> &a){return in >> a.first >> a.second;}
template<typename T1, typename T2>inline ostream& operator << (ostream &ou, const pair<T1, T2> &b){return ou << b.first << ' ' << b.second;}
template<typename T> inline long long pow(long long v, long long t, const T &p){long long res = 1;for(;t;t >>= 1, v = v * v % p)if(t & 1)res = res * v % p;return res;}
const int maxn = 300010;
ll b1[maxn], b2[maxn];
ll x[maxn], v[maxn];
ll rx[maxn], rv[maxn], n, c;
ll res;
void call(ll* x, ll* rx, ll* v, ll* rv){
	{
		vector<ll> pu(x, x+1+n), pd(rx, rx+1+n);
		for(int i = 1;i <= n;++i)pd[i] += rv[i];
		for(int i = 1;i <= n;++i)pd[i] = max(pd[i-1], pd[i]);
		res = max(res, pd[n]);
		dout(pd[n])<<'\n';
		for(int i = 1;i <= n;++i)res = max(res, pu[i]*2 + v[i] + pd[n-i]);
	}
}
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> c;
	for(int i = 1;i <= n;++i)cin >> x[i] >> v[i];
	for(int i = 1, j = n;i <= n;++i, --j)rx[i] = c-x[j], rv[i] = v[j];
	for(int i = 1;i <= n;++i)x[i] = -x[i], rx[i] = -rx[i];
	for(int i = 1;i <= n;++i)v[i] += v[i-1], rv[i] += rv[i-1];
	call(x, rx, v, rv), call(rx, x, rv, v);
	cout << res << '\n';
}

Measured memory_bytes: 8800
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i;
    double a[1000];
    cin>>n;
    for(i=0;i<n;i++)
    {
        scanf("%lf",&a[i]);
    }
    double s=0.0,x;
    for(i=0;i<n;i++)
    {
        x=1.0/a[i];
        s=s+x;
    }
    s=1/s;
    printf("%lf\n",s);
    return 0;
}


Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
s,t = input().split()
ans = ""
for i in range(n):
    ans += s[i] + t[i]
print(ans)


Measured memory_bytes: 10328
#include <bits/stdc++.h>
using namespace std;
int a[2001];
int main(){
    int n,m;
    cin>>n>>m;
    int s=0;
    for (int i=0;i<n;++i){
        cin>>a[i];
        s+=a[i];
    }
    sort(a,a+n);
    if (a[n-m]>=(s+4*m-1)/(4*m)) cout<<"Yes\n";
    else cout<<"No\n";
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	String s = sc.next();

        boolean isOK = true;
        for (int i = 0; i < 3; i++) {
            char c0 = s.charAt(i);
            char c1 = s.charAt(i+1);
            if (c0 == c1) {
                isOK = false;
                break;
            }
        }
        if (isOK) {
            System.out.println("Good");
        } else {
            System.out.println("Bad");
        }
   	}
}


Measured memory_bytes: 21716
import java.util.*;
public class Main
{
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n=in.nextInt(),c=0;
		int d=in.nextInt();
		for(int i=1;i<=n;i++)
		{
			long a=in.nextLong();
			long b=in.nextLong();
			if(Math.sqrt(a*a+b*b)<=d)
			{
				c++;
			}
		}
		System.out.println(c);
	}
}

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

int main(){
  int n,t,a;
  cin >> n >> t >> a;
  int h[n];
  for (int i=0;i<n;i++){
    cin >> h[i];
  }
  for (int i=0;i<n;i++){
	h[i]=1000*t-6*h[i];
  }
  int ans=1200000;
  for (int i=0;i<n;i++){
    h[i]=abs(1000*a-h[i]);
  ans=min(ans,h[i]);
  }
  int x;
  for (int i=0;i<n;i++){
    if(ans == h[i]){
      x=i;
    }
  }
  cout << x+1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
int main() {
    int N, M, X;
    cin >> N >> M >> X;
    long long int result = LLONG_MAX;
    Graph A(N, vector<int>(M));
    vector<int> C(N);
    for(int i = 0; i < N; i++) {
        cin >> C[i];
        for(int j = 0; j < M; j++) {
            cin >> A[i][j];
        }
    }
    for(int bit = 0; bit < (1<<N); bit++) {
        vector<int> S;
        vector<int> level(M, 0);
        for(int i = 0; i < N; i++) {
            if(bit & (1 << i)) {
                S.push_back(i);
            }
        }
        long long int tmp = 0;
        for(int i : S) {
            tmp += C[i];
            for(int j = 0; j < M; j++) {
                level[j] += A[i][j];
            }
        }
        bool ok = true;
        for(int i = 0; i < M; i++) {
            if(level[i] < X) {
                ok = false;
            }
        }
        if(ok) {
            result = min(result, tmp);
        }
    }
    if(result == LLONG_MAX) {
        result = -1;
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner kbd =new Scanner(System.in);
		 String s=kbd.next();
		 String t=kbd.next();
     int z=s.length();
 String x=t.substring(0, z);

 if(x.compareTo(s)==0){
	 System.out.println("Yes");
 }else {
	 System.out.println("No");
 }
	}
}


Measured memory_bytes: 35640
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <ctime>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <numeric>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define mp(a,b,c) make_pair(make_pair(a,b),c)
#define pb(a) push_back(a)
#define SS stringstream
#define DBG1(a) rep(_X,sz(a)){printf("%d ",a[_X]);}puts("");
#define DBG2(a) rep(_X,sz(a)){rep(_Y,sz(a[_X]))printf("%d ",a[_X][_Y]);puts("");}
#define bitcount(b) __builtin_popcount(b)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)

#define delete(a,n) a.erase(remove(all(a),n),a.end())
template<typename T, typename S> vector<T>& operator<<(vector<T>& a, S b) { a.push_back(b); return a; }
template<typename T> void operator>>(vector<T>& a, int b) {while(b--)if(!a.empty())a.pop_back();}
bool isprime(int n){ if(n<2)return false;  for(int i=2;i*i<=n;i++)if(n%i==0)return false;  return true;} 
ll b_pow(ll x,ll n){return n ? b_pow(x*x,n/2)*(n%2?x:1) : 1ll;}
string itos(int n){stringstream ss;ss << n;return ss.str();}
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()

typedef unsigned int uint;
int in() {
    int x = 0, c;
    for (; (uint)((c = getchar()) - '0') >= 10; ) { if (c == '-') return -in(); if (!~c) throw ~0; }
    do { x = (x << 3) + (x << 1) + (c - '0'); } while ((uint)((c = getchar()) - '0') < 10);
    return x;
}

int main(){
	int n,m;
	cin >> n >> m;
	if( m < 0 ){
		cout << 0 << endl;
		return 0;
	}
	int mx = m;
	for(int i = 0 ; i < n ; i++){
		int a,b;
		cin >> a >> b;
		m += a-b;
		if( m < 0 ){
			cout << 0 << endl;
			return 0;
		}
		mx = max(mx,m);
	}
	cout << mx << endl;
}

Measured memory_bytes: 1164
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
using namespace std;

int inf = (1 << 30);
int mod = 1e9;
long long long_inf = (1LL << 60);

int main(){

    int X, A, B;
    cin >> X >> A >> B;

    if(B - A <= 0){
        cout << "delicious" << endl;
    }else if(B - A <= X){
        cout << "safe" << endl;
    }else{
        cout << "dangerous" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
pub fn read_parameters<T>() -> Result<Vec<T>, String>
where
    T: std::str::FromStr,
{
    let mut line = String::new();
    std::io::stdin()
        .read_line(&mut line)
        .map_err(|err| format!("{:?}", err))?;

    let xs = line.trim().split_whitespace();
    let mut result = Vec::new();

    for x in xs {
        let ans = x.parse::<T>().map_err(|_| format!("{}", "parse error"))?;
        result.push(ans);
    }
    Ok(result)
}

fn main() {
    // let (a, b) = read_parameters::<usize>().map(|xs| (xs[0], xs[1])).unwrap();
    loop {
        let s = read_parameters::<String>().unwrap();
        let a = s[0].parse::<usize>().unwrap();
        let op = s[1].as_str();
        let b = s[2].parse::<usize>().unwrap();

        let ans: isize = match op {
            "+" => (a + b) as isize,
            "-" => a as isize - b as isize,
            "*" => (a * b) as isize,
            "/" => (a / b) as isize,
            "?" | _ => break,
        };

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



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

using namespace std;


int n;
int e[1000][1000];
int es;

void print(int m) {
    cout << "Yes\n" << m << '\n';
    for (int i = 0; i < m; i++) {
        cout << m - 1;
        for (int j = 0; j < m; j++) {
            if (i == j) continue;
            if (!e[i][j]) {
                e[i][j] = ++es;
                e[j][i] = e[i][j];
            }
            cout << ' ' << e[i][j];
        }
        cout << '\n';
    }
}

int main() {
    cin >> n;
    for (int i = 2; i*(i-1)/2 <= n; i++) {
        if (i*(i-1)/2 == n) {
            print(i);
            return 0;
        }
    }
    cout << "No\n";
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
void chmin(int& a, int b) { if (a > b) a = b; }
const int MAX_N = 55000;
const int INF = 1e9;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> coin(m);
    for (auto& e : coin) cin >> e;
    
    vector<int> dp(MAX_N, INF);
    dp[0] = 0;
    for (auto& v : coin) {
        for (int i = 0; i < MAX_N; i++) {
            if (i + v < MAX_N) chmin(dp[i+v], dp[i] + 1);
        }
    }
    
    cout << dp[n] << endl;
    return 0;
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
    int w, a, b; cin >> w >> a >> b;
    if(w + a < b){
        cout << b - w - a << endl;
    }else if(b + w < a){
        cout << a - w - b << endl;
    }else if(w == b){
        cout << 0 << endl;
    }else{
        int x = min(abs((a + w) - b), abs(a - (b + w)));
        cout << x << endl;
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> A(5);
  int X;
  string ans = "Yay!";
  for (int i=0; i<5; i++){
    cin >> A.at(i);
  }
  cin >> X;
  for (int i=0; i<4; i++){
    for (int j=i+1; j<5; j++){
      if (A.at(j)-A.at(i)>X){
        ans = ":(";
        break;
      }
    }
    if (ans == ":("){
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>

#include <utility>
typedef long long ll;
using namespace std;

int main(void){
  ll a1,a2,b1,b2,t1,t2,sum1,sum2;
  cin>>t1>>t2>>a1>>a2>>b1>>b2;
  sum1=a1*t1+a2*t2;
  sum2=b1*t1+b2*t2;

  if(sum1==sum2){
    cout<<"infinity"<<endl;
    return 0;
  }

  if(a1<b1){
    swap(a1,b1);
    swap(a2,b2);
    swap(sum1,sum2);
  }

  if(sum1>sum2){
    cout<<0<<endl;
    return 0;
  }
  if((((a1-b1)*t1)%(sum2-sum1))==0){
    cout<<(((a1-b1)*t1)/(sum2-sum1))*2<<endl;
    return 0;  
  }
  cout<<(((a1-b1)*t1)/(sum2-sum1))*2+1<<endl;
  return 0;
}


Measured memory_bytes: 256
x = int(input())

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

for i in range(x,10**9):
    if is_prime(i):
        print(i)
        break
    

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

int main()
{
    int s, w;
    cin >> s >> w;
    if (s<=w){
        cout << "unsafe" << endl;
        return 0;
    }
    cout << "safe" << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <stack>
using namespace std;

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

  vector<int> list[100];

  for(int i=0;i<n;i++){
    int u,k;
    cin >> u >> k;
    for(int j=0;j<k;j++){
      int v;
      cin >> v;
      list[u-1].push_back(v-1);
    }
  }
  
  int d[100],f[100];
  for(int i=0;i<n;i++) d[i]=f[i]=0;

  stack<int> cur;
  cur.push(0);
  d[0]=1;

  for(int t=2;!cur.empty();t++){
    bool fl=false;
    for(vector<int>::iterator it=list[cur.top()].begin();it!=list[cur.top()].end();it++){
      if(d[*it]==0){
        d[*it]=t;
        fl=true;
        cur.push(*it);
        break;
      }
    }
    if(fl) continue;

    f[cur.top()]=t;
    cur.pop();

    if(cur.empty()){
      for(int i=0;i<n;i++){
        if(d[i]==0){
          t++;
          cur.push(i);
          d[i]=t;
          break;
        }
      }
    }
  }

  for(int i=0;i<n;i++)
    cout << (i+1) << ' ' << d[i] << ' ' << f[i] << endl;

  return 0;
}

Measured memory_bytes: 3152
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    m, d = list(map(int, input().rstrip('\n').split()))
    m, d = list(map(int, input().rstrip('\n').split()))
    print(1 if d == 1 else 0)


if __name__ == '__main__':
    solve()


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

int N, A, B, C;
vec<int> l(8);

int dfs(int now, int a, int b, int c) {
    if(now == N){
        if(a==0 || b == 0 || c == 0) return 99999999;
        else return abs(A-a) + abs(B-b) + abs(C-c) - 30;
    }
    int ans1 = dfs(now+1,a+l[now],b,c) + 10;
    int ans2 = dfs(now+1,a,b+l[now],c) + 10;
    int ans3 = dfs(now+1,a,b,c+l[now]) + 10;
    int ans0 = dfs(now+1,a,b,c);
    return min({ans0,ans1,ans2,ans3});
}

int main() {
    cin >> N >> A >> B >> C;
    rep(i, N) cin >> l[i];
    cout << dfs(0,0,0,0) << endl;
}


Measured memory_bytes: 256
from collections import deque

X, Y, A, B, C = map(int, input().split())
P = sorted([int(p) for p in input().split()], reverse=True)[:X]
Q = sorted([int(q) for q in input().split()], reverse=True)[:Y]
R = sorted([int(r) for r in input().split()], reverse=True)

P = deque(P)
Q = deque(Q)
R = deque(R)

m = min(P[X-1], Q[Y-1])
while R[0] > m:
    if P[X-1] < Q[Y-1]:
        P.pop()
        P.appendleft(R[0])
        R.popleft()
    else:
        Q.pop()
        Q.appendleft(R[0])
        R.popleft()
    m = min(P[X-1], Q[Y-1])
    if len(R) == 0:
        break
print(sum(P) + sum(Q))


Measured memory_bytes: 113488
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, m;
    cin >> n >> m;
    multiset<int, greater<int>> s;
    for(int i=0; i<n; i++){
        int t;
        cin >> t;
        s.insert(t);
    }
    for(int i=0; i<m; i++){
        int val = *s.begin();
        s.erase(s.begin());
        val /= 2;
        s.insert(val);
    }
    long long sum = 0;
    for(auto it=s.begin(); it!=s.end(); it++){
        long long t = (long long)*it;
        sum += t;
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<iomanip>
#include<functional>
#include<algorithm>
#include<string>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<set>
#include<queue>
#include<cmath>

using namespace std;
#define LL long long

string s,t;

int main() {
	cin>>s>>t;
	sort(s.begin(),s.end());
	sort(t.rbegin(),t.rend());
	cout<<(s<t?"Yes":"No")<<endl;
	return 0;
}



Measured memory_bytes: 256
let is_prime = function
    1 -> false
  | 2 -> true
  | n when n mod 2 = 0 -> false
  | n -> let rec iter x =
           if x * x > n then true
           else if n mod x = 0 then false
           else iter (x+2) in
         iter 3
  
let rec read f n =
  if n <= 0 then []
  else
    let x = f () in
    x :: read f (n - 1)

let () =
  let n = read_int () in
  let xs = read read_int n in
  List.filter is_prime xs |> List.length |> string_of_int |> print_endline

Measured memory_bytes: 3528
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
using namespace std;
#define ll           long long
#define all(v)       (v).begin() , (v).end()
#define vi           vector <ll>
#define vii          vector <pair<ll,ll>>
#define ii           pair<ll,ll>
#define sz(v)	     ((int)((v).size()))
#define lp(i,a,b)    for(int i=a;i<b;i++)
#define pb           push_back
#define pf           push_front
#define F            first
#define S            second
#define endl         "\n"
#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const double PI = 3.14159265358979323846;
const ll inf=2e9,MOD=1e9+7,MAX=1e6+1;

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    ll d,res=0;
    cin>>n>>d;
    lp(i,0,n){
        ll x,y;
        cin>>x>>y;
        if(x*x+y*y<=d*d)
            res++;
    }
    cout<<res;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <algorithm>

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
inline int gcd(int a,int b){return b?gcd(b,a%b):a;}
inline int lcm(int a,int b){return a*b/gcd(a,b);}
typedef long long ll;
typedef std::vector<int> VI;
typedef std::pair<int, int> PII;

using namespace std;

int main()
{
  int N;
  cin >> N;
  int count = 0;
  REP(i,N) {
    int p;
    cin >> p;
    if (p != i+1) count++;
  }
  if (count != 2 && count != 0) cout << "NO" << endl;
  else cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 256
@n = gets.to_i
@memo = Array.new(@n+1) {Hash.new}
M = 10 ** 9 + 7

def calc(i, str)
    return @memo[i][str] if @memo[i][str]

    if i == @n
        return @memo[i][str] = str["AGC"] || str["GAC"] || str["ACG"] ? 0 : 1
    end

    r = 0
    "ACGT".each_char do |c|
        x = str + c

        if i > 2
            b = !3.times.any? do |j|
                t = x.dup
                t[j], t[j+1] = t[j+1], t[j]
                t["AGC"]
            end
            r += calc(i + 1, x[1, 3]) if b && !x["AGC"]
        else
            r += calc(i + 1, x)
        end
    end

    @memo[i][str] = r % M
end

p calc(0, "")
#p @memo

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


int popcount(int n){
    int ans=0;
    while(n!=0){
        ans += n%2;
        n = n/2;
    }
    return ans;
}

int times(int n){
    int ans=0;
    while(n!=0){
        n = n%popcount(n);
        ans++;
    }
    return ans;
}

int calc(int n,string s){
    int up=0;
    for(int i=0; i<n; i++){
        if(s.at(i) == '1') up++;
    }
    if(up ==0) return 0;
    int keta=1;
    int m=0;
    for(int i=0; i<n; i++){
        m = (m + keta * (s.at(n-1-i)-'0'))%up;
        keta = (keta*2)%up;
    }
    return times(m%up)+1;
}


int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;
    int up=0;
    for(int i=0; i<n; i++){
        if(s.at(i) == '1') up++;
    }
    if(up == 1){
        if(s.at(n-1) == '0'){
            for(int i=0; i<n-1; i++){
                if(s.at(i) == '0'){
                    cout << 1 << endl;
                }
                else cout << 0 << endl;
            }
            cout << 2 << endl;
        return 0;
        }
        else{
            for(int i=0; i<n-1; i++){
                cout << 2 << endl;
            }
            cout << 0 << endl;
            return 0;
        }
    }
    vector<int> keta_mod_up(n,1);
    vector<int> keta_mod_down(n,1);
    int keta=1;
    for(int i=0; i<n-1; i++){
        keta_mod_up.at(i+1) = (keta*2)%(up+1);
        keta = (keta*2)%(up+1);
    }
    keta=1;
    for(int i=0; i<n-1; i++){
        keta_mod_down.at(i+1) = (keta*2)%(up-1);
        keta = (keta*2)%(up-1);
    }
    int stay_up=0;
    int stay_down =0;
    for(int i=0; i<n; i++){
        stay_up = (stay_up+ keta_mod_up.at(i)*(s.at(n-1-i)-'0'))%(up+1);
    }
    for(int i=0; i<n; i++){
        stay_down = (stay_down+ keta_mod_down.at(i)*(s.at(n-1-i)-'0'))%(up-1);
    }
    for(int i=0; i<n; i++){
        bool z_to_o;
        if(s.at(i)=='0'){
            z_to_o = true;
        }
        else{
            z_to_o = false;
        }
        if(z_to_o){
            int k;
            k = (stay_up + keta_mod_up.at(n-1-i)) %(up+1);
            if(k%(up+1) == 0) cout << 1 << endl;
            else{
            cout << times(k) + 1 << endl;
            }
        }
        else{
            int k;
            k = (stay_down - keta_mod_down.at(n-1-i)) %(up-1);
            while(k <0){
                k += (up-1);
            }
            if(k%(up-1) == 0) cout << 1 << endl;
            else{
                cout << times(k) + 1 << endl;
            }
        }
    }
}


Measured memory_bytes: 5236
#include <iostream>
using namespace std;
int main() 
{
	int i, j, H, W;
	while (1) {
    		cin >> H >> W;
		if(H == 0 && W == 0) {
        			break;
		}	
		for (i = 1; i <= H; i++) {
			for (j = 1; j <= W; j++) {
				if(i > 1 && i < H && j < W && j > 1)
                        			cout << ".";
            			else
                     				cout << "#";
            		}
		 	cout << endl;
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX_N 1000001
#define MAX_M 100000
#define MOD = 1000000007;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecBvec vector<vector<bool>>
#define vecst vector<string>
#define veche vector<char>
#define vecd vector<double>
#define vecvec vector<vector<int>>
#define vecDvec vector<vector<double>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,m,n) for(int i=m;i<(int)n;++i)
#define INF 1e+9
#define ent cout<<endl
using P = pair<int, int>;
#define YES "Yes"
#define NO "No"
#define MAX_V 1000
#define PI 3.141592653589793
// cout << setprecision(15) << std::fixed;

// テレンス「もしかしてACですかーッ!?」　ジョセフ「Yse! Yse! Yse! Oh~MyGod」

int main(){
  int x,n=0;
  cin>>x;
  n=x/100;
  x=x%100;
  if(x==0||n*5>=x){
    cout<<1<<endl;
  }
  else{
    cout<<0<<endl;
  }
  // else{
  //   for(int i=0;i<n;i++){
  //     if(x>=5)x-=5;
  //     else if(x>=4) x-=4;
  //     else if(x>=3) x-=3;
  //     else if(x>=2) x-=2;
  //     else if(x>=1) x-=1;   
  //   }
  // }
  // if(x>0){
  //   cout<<0<<endl;
  // }
  // else{
  //   cout<<1<<endl;
  // }
}


Measured memory_bytes: 256
N = int(input())

def base_10_to_n(x, base):
  output = []
  while True:
    a = x % base
    output.append(a)
    x //= base
    if x == 0:
      for i in range(1, len(output)):
        if output[i-1] <= 0:
          output[i] = output[i] -1
      output = output[::-1]
      if output[0] == 0:
        output.pop(0)
      break
  return output

def base_10_from_n(x, base):
  output = 0
  for i in reversed(range(len(x)-1)):
    output += base ** i
  return output


base = 26
output = base_10_to_n(N, base)

alphabet_list = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
name = ''
for i in output:
  name += alphabet_list[i-1]
print(name)

Measured memory_bytes: 9260
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
typedef long long ll;
ll two(ll x) {
	ll count = 0;
	while (x % 2 == 0) {
		x /= 2;
		count++;
	}
	return count;
}
int main() {
	ll n, a[10001], count = 0;
	cin >> n;
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
		count += two(a[i]);
	}
	cout << count << endl;
	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const ll mod=1000000007;

ll a[200002],b[200002];
int main(void){
    ll n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<k;i++){
        fill(b,b+n,0);
        for(int j=0;j<n;j++){
            int L=max(ll(0),j-a[j]),R=min(n-1,j+a[j]);
            b[L]++,b[R+1]--;
        }
        for(int j=0;j<n;j++){
            if(j==0) a[0]=b[0];
            else{
                a[j]=a[j-1]+b[j];
            }
        }
        bool ok=true;
        for(int j=0;j<n;j++){
            if(a[j]!=n) ok=false;
        }
        if(ok) break;
    }
    for(int i=0;i<n;i++){
        cout<<a[i]<<endl;
    }
}

Measured memory_bytes: 6756
def main():
    _, W, *C = map(int, open(0).read().split())
    dp = [0]*(W+1)
    for v, w in zip(*[iter(C)]*2):
        for i in range(w, W+1):
            d_new = dp[i-w]+v
            if dp[i] < d_new:
                dp[i] = d_new
    print(max(dp))

if __name__ == '__main__':
    main()


Measured memory_bytes: 5720
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
long long modexp(long long b, long long e, long long m){
	long long r = 1;
	while(e > 0){
		if(e&1){
			r = (r*b)%m;
		}
		b = (b*b)%m;
		e >>= 1;
	}
	return r;
}
int main(){
	int n;
	cin >> n;
	long long ans = modexp(10,n,MOD)-2*modexp(9,n,MOD)+modexp(8,n,MOD);
	ans %= MOD;
	if(ans < 0){
		ans += MOD;
	}
	cout << ans << '\n';
}

Measured memory_bytes: 3636
import java.util.Scanner;
import java.util.TreeMap;

public class Main {


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long M = sc.nextLong();
		long Ai = 0;
		long Bi = 0;
		
		
		TreeMap <Long, Long> store = new TreeMap <Long, Long>();
		
		for (int i = 0; i<N; i++){
			Ai = sc.nextLong();
			Bi = sc.nextLong();
 
			if (store.containsKey(Ai)) 
				store.put(Ai, store.get(Ai) + Bi);
			 else 
				store.put(Ai, Bi);
			}
		
		sc.close();
		
		long price = 0;
		long buy = 0;
		
		for (Long cost : store.keySet()) {
			buy = Math.min(M, store.get(cost));
			price = price + cost*buy;
			M=M-buy;
			
		}
		System.out.println(price);
			
	}
}
	
	        

		

Measured memory_bytes: 97708
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
const int INF = 1e9 + 5;
int main()
{
    int n;
    scanf("%d",&n);
    vi dp(3);
    for(int i = 0; i < n; i++)
    {
        vi t(3, 0);
        vi c(3);
        scanf("%d%d%d",&c[0],&c[1],&c[2]);
        for(int j = 0; j < 3; j++)
            for(int k = 0; k < 3; k++)
            {
                if(j != k) t[k] = max(t[k]  , dp[j] + c[k]); 
            }
        dp = t;
    }
    printf("%d",max(dp[0], max(dp[1], dp[2])));
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> //tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

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

  int A[N];
  cin >> A[0];

  int shortest=0, max_dist=0, tmp_dist;
  for (int i = 1; i < N; i++) {
    cin >> A[i];
    tmp_dist = A[i] - A[i-1];
    shortest += tmp_dist;
    max_dist = tmp_dist > max_dist ? tmp_dist : max_dist;     
  }

  int head2tail = A[0] + (K - A[N-1]);
  if (head2tail < max_dist) {
    shortest = shortest - max_dist + head2tail;
  }
  cout << shortest << endl;
}

Measured memory_bytes: 1024
n = int(input())
B = list(map(int,input().split()))

A = [0 for i in range(n)]

A[0]=B[0]
A[n-1]=B[n-2]
for i in range(n-2):
    if B[i]<B[i+1]:
        A[i+1]=B[i]
    else:
        A[i+1]=B[i+1]

print(sum(A))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int N; cin >> N;
    mat rate(2, vec(3));
    REP(a, 2) cin >> rate[a];

    REP(a, 2){
        vec cost(3), val(3);
        REP(i, 3){
            cost[i] = rate[a][i];
            val[i] = rate[1 - a][i] - rate[a][i];
        }
        vec dp(N + 1, 0);
        REP(i, 3){
            REP(j, N) if(j + cost[i] <= N) Max(dp[j + cost[i]], dp[j] + val[i]);
        }
        N += dp[N];
    }

    Out(N);

    return 0;
}


Measured memory_bytes: 195584
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

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

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"2 2"# => r#"6"#,
r#"5 15"# => r#"1"#,
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        k: isize, s: isize,
    }
    let mut ans = 0;

    for x in 0..k + 1 {
        for y in 0..k + 1 {
            let z = s - x - y;
            if 0 <= z && z <= k {
                ans += 1;
            }
        }
    }

    ans.to_string()
}

Measured memory_bytes: 4352
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
pair<int, int>dfs(const int now,const vector<int>&dances, const vector<vector<int>>&edges,const int need) {
	if (edges[now].empty()) {
		if (dances[now] == -1) {
			return make_pair(1, 0);
		}
		if (dances[now] >= need) {
			return make_pair(0, 0);
		}
		else {
			return make_pair(1e6, 0);
		}
	}
	else {
		vector<pair<int, int>>ps(3);
		for (int i = 0; i < 3; ++i) {
			ps[i] = dfs(edges[now][i],dances,edges,need);
		}
		int okmin = 1e9;
		int notmax = 0;
		for (int i = 0; i < 3; ++i) {
			okmin = min(okmin, ps[i].second+ ps[(i + 1) % 3].first + ps[(i + 2) % 3].first);
			notmax = max(notmax, ps[i].second + ps[(i + 1) % 3].second + ps[(i + 2) % 3].second);
		}
		return make_pair(okmin, notmax);
	}
}

int main() {
	int N, M; cin >> N >> M;
	vector<int>dances(N,-1);
	for (int i = 0; i < M; ++i) {
		int d, p; cin >> d >> p; p--;
		dances[p] = d;
	}
	vector<int>rests(N-M);
	for (int i = 0; i < N-M; ++i) {
		cin >> rests[i];
	}
	sort(rests.begin(), rests.end());
	vector<vector<int>>edges(N + ((N - 1) / 2));
	vector<int>nums(N+((N - 1) / 2));
	int a=0;
	int b = N;
	for (int i = 0; i < (N - 1)/2; ++i) {
		edges[b].push_back(a);
		edges[b].push_back(a + 1);
		edges[b].push_back(a + 2);
		a += 3;
		b++;
	}
	int amin = 0;
	int amax = 1e9 + 1;
	while (amin + 1 != amax) {
		int amid = (amin + amax) / 2;
		auto p = dfs(N + ((N - 1) / 2)-1, dances, edges, amid);
		auto it = lower_bound(rests.begin(), rests.end(), amid);
		int upnum = rests.end() - it;
		if (upnum >= p.first) {
			amin = amid;
		}
		else {
			amax = amid;
		}
	}
	cout << amin<< endl;
	return 0;
}

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

int main() {
    int N, L; cin >> N >> L;
    int sum = 0;
    int j, k;

    if (L > 0) {j = 2; k = 1;}
    else if (L + N - 1 < 0) {j = 1; k = 0;}
    else {j = 1; k = 1;}

    for (int i = j; i < N + k; i++) {
        sum += (L + i - 1);
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
import numpy as np
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N, K = map(int, readline().split())
    A = list(list(map(int, readline().split())) for _ in range(N))
    A = np.array(A)
    def dot(A, B):
        C = np.zeros((N, N), np.int64)
        for n in range(N):
            C[n] = (A[n, :][:, None] * B % MOD).sum(axis=0) % MOD
        return C

    def matrix_power(A, n):
        if n == 0:
            return np.eye(N, dtype=np.int64)
        X = matrix_power(A, n // 2)
        X = dot(X, X)
        return dot(A, X) if n & 1 else X

    ans = matrix_power(A,K)
    print(ans.sum() %MOD)


if __name__ == '__main__':
    main()

Measured memory_bytes: 12520
#include<stdio.h>
#define MAX(x,y) ((x>y)?x:y)

int main(){
	int i,j,n,m,x,y,z,w,ans,f;
	
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		ans=0;
		while(n--){
			scanf("%d%d%d%d",&x,&y,&z,&w);
			x=x+y+z;
			if(x>160 || w>25)continue;
			if(x<=60)f=0;
			else if(x<=80)f=1;
			else if(x<=100)f=2;
			else if(x<=120)f=3;
			else if(x<=140)f=4;
			else if(x<=160)f=5;
			if(w<=2)f=MAX(f,0);
			else if(w<=5)f=MAX(f,1);
			else if(w<=10)f=MAX(f,2);
			else if(w<=15)f=MAX(f,3);
			else if(w<=20)f=MAX(f,4);
			else if(w<=25)f=MAX(f,5);
			ans+=(f+3)*200;
		}
		printf("%d\n",ans);
	}
	
	return 0;
}

Measured memory_bytes: 0
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        int[] list = new int[n];
        int lastValue = 0;
        for (int i = 1; i < n; i++) {
            if (s.substring(i - 1, i + 1).equals("AC")) {
                lastValue++;
            }
            list[i] = lastValue;
        }

        for (int i = 0; i < q; i++) {
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            System.out.println(list[r] - list[l]);
        }
    }
}

Measured memory_bytes: 63356
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long long ll;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n ; 
	cin >> n ; 
	vector<int> v(n) ; 
	for(int i=0;i<n;i++){
		cin >> v[i] ; 
	}
	for(int i=n-1;i>=0;i-=2){
		cout << v[i] << ' ' ; 
	}
	int start = 0 ; 
	if ( n & 1 ){
		start = 1 ; 
	}
	for(int i=start;i<n;i+=2){
		cout << v[i] << ' ' ; 
	}
	cout << endl;
    return 0 ;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
const ll inf=(1e18);
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;cin>>n;
string s;
cin>>s;
int cnt=0;
string tmp={};
for(int i=0;i<n;i++){
    if(s[i]=='(')cnt++;
    else cnt--;
    if(cnt<0){
        tmp+="(";
        cnt++;
    }
}
s=tmp+s;
if(cnt>0)for(int i=0;i<cnt;i++)s+=")";
cout<<s<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>

int main(void) {
	int n;
	std::cin >> n;
	std::vector<int> vec(n);
	for (int i = 0; i < n; i++) {
		std::cin >> vec[i];
	}
	double sum = 0;
	for (int i = 0; i < n; i++) {
		sum += ((double)1.0 / vec[i]);
	}
	std::cout << std::setprecision(8) << ((double)1.0 / sum) << std::endl;
	return 0;
}

Measured memory_bytes: 256