akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
using namespace std;

struct Node
{
    int key;
    Node *right, *left, *parent;
};

Node *root, *NIL;

Node *find(Node *u, int k)
{
    while (u != NIL && k != u->key)
    {
        if (k < u->key)
            u = u->left;
        else
            u = u->right;
    }
    return u;
}

void insert(int k)
{
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while (x != NIL)
    {
        y = x;
        if (z->key < x->key)
        {
            x = x->left;
        }
        else
        {
            x = x->right;
        }
    }
    z->parent = y;
    if (y == NIL)
    {
        root = z;
    }
    else
    {
        if (z->key < y->key)
        {
            y->left = z;
        }
        else
        {
            y->right = z;
        }
    }
}

void inorder(Node *u)
{
    if (u == NIL)
        return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u)
{
    if (u == NIL)
        return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

int main()
{
    int n, i, x;
    string com;

    scanf("%d", &n);

    for (i = 0; i < n; i++)
    {
        cin >> com;
        if (com[0] == 'f')
        {
            scanf("%d", &x);
            Node *t = find(root, x);
            if (t != NIL)
                printf("yes\n");
            else
                printf("no\n");
        }
        else if (com == "insert")
        {
            scanf("%d", &x);
            insert(x);
        }
        else if (com == "print")
        {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }

    return 0;
}


Measured memory_bytes: 22052
N = int(input())
S = input()
newS = ''
A = ord('A')
Z = ord('Z')
for k in range(len(S)):
    if ord(S[k]) + N > Z:
        newS += chr(ord(S[k]) + N - Z + A - 1)
    else:
        newS += chr(ord(S[k]) + N)
print(newS)


Measured memory_bytes: 9188
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(),x.end()
#define show(x) cout<<(#x)<<" is "<<(x)<<endl

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set=tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef vector<vector<int>> matrix;

const ll INF=1e18+123;
const ld EPS=1e-9;
const int inf=1e9+123;
const int MOD=1e9+7;
const int N=5e5+123;
const int M=1e6+123;
const int dx[]={0,0,1,-1};
const int dy[]={1,-1,0,0};

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,k;
    cin>>n>>k;
    n=(n+1)/2;
    if(n>=k)cout<<"YES";
    else cout<<"NO";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
#define ll long long


int main(){
    int n;
    cin>>n;
    ll res[100];
    res[0]=2;
    res[1]=1;
    for(int i=2;i<=n;i++){
        res[i]=res[i-1]+res[i-2];
    }
    cout<<res[n]<<endl;
    return 0;
}

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

int main(){
  int n;cin>>n;
  vector<int> v(n+1,0);
  for(int i=0;i<n;++i){
    int a;cin>>a;
    v[a]=v[a-1]+1;
  }
  int ans=n;
  for(int i=0;i<n+1;++i) ans=min(ans,n-v[i]);
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#define N 200003
#define IL inline
#define REP(a,b,c) for(a=b;a<=c;a++)
using namespace std;
typedef long long lol;
lol ans;
struct edge{int u,v,w;};
struct Heap{
	int len;edge a[N<<1];
	IL void up(int i){
		int j=i>>1,x=a[i].w;edge y=a[i];
		while(j && x<a[j].w)a[i]=a[j],i=j,j>>=1;
		a[i]=y;
	}
	IL void down(int i){
		int j=i<<1,x=a[i].w;edge y=a[i];
		while(j<=len){
			if(j<len && a[j+1].w<a[j].w)j++;
			if(a[j].w<x)a[i]=a[j],i=j,j<<=1;else break;
		}
		a[i]=y;
	}
	IL void push(edge b){a[++len]=b;up(len);}
	IL edge pop(){edge b=a[1];a[1]=a[len--];down(1);return b;}
}O,H;
int n,q,fa[N];
IL int rd(){
	int res=0;char c;while((c=getchar())<'0'||c>'9');
	while(c>='0'&&c<='9')res=res*10+c-'0',c=getchar();return res;
}
IL int getf(int a){return a==fa[a]?a:fa[a]=getf(fa[a]);}
IL bool link(int a,int b){a=getf(a),b=getf(b);if(a==b)return false;fa[b]=a;return true;}
int main(){
  n=rd(),q=rd();int t,i,u,v,w;edge e;t=n-1;REP(i,1,t)fa[i]=i;
	REP(i,1,q)u=rd(),v=rd(),w=rd(),O.push((edge){u,v,w});
	REP(t,2,n){
		while(1){
			if(O.len &&(!H.len || O.a[1].w<H.a[1].w)){
				e=O.pop();
				H.push((edge){e.u,(e.u+1)%n,e.w+1});
				H.push((edge){e.v,(e.v+1)%n,e.w+2});
				if(link(e.u,e.v)){ans+=e.w;break;}
			}else{
				e=H.a[1];
				if(!link(e.u,e.v))H.pop();
				else{
					ans+=e.w;e.u=e.v,e.v=(e.v+1)%n,e.w+=2,H.a[1]=e,H.down(1);break;
				}
			}
		}
	}
	printf("%lld",ans);
  return 0;
}

Measured memory_bytes: 8320
#include <iostream>
#include <cmath>
using namespace std;
#define NUM 123456

int main()
{
	int prime[NUM*2+1]={0},count=0,inp;
	prime[0]=1;
	prime[1]=1;
	for(int i=2;i<=sqrt(NUM*2);i++)
		if(prime[i]==0)
			for(int j=i+1;j<=NUM*2;j++)
				if(j%i==0)
					prime[j]=1;

	while(cin>>inp,inp!=0)
	{
		for(int i=inp+1;i<=inp*2;i++)
			if(prime[i]==0)
				count++;
		cout<<count<<endl;
		count=0;
	}
}

Measured memory_bytes: 2132
#Coding:Utf-8

N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
last=0
total=0
for i in range(N):
    total+=B[A[i]-1]
    if last==A[i]-1 and last!=0:
        total+=C[last-1]
    last=A[i]

print(total)


Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF /*1000000007*/ 1000000000000000003
#define MOD 1000000007

using namespace std;
using P = pair<int, long long>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };

vector<edge>tree[100010];
vector<P> connect[100005];
long long cost[100005];

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

int main() {

	int N, K;
	cin >> N >> K; 

	int ans = 0;
	for (int i = 0; i < N; ++i) {
		int h;
		cin >> h;
		if (K <= h)ans++;
	}

	cout << ans << endl;
}


Measured memory_bytes: 4992
from functools import reduce
MOD = 10**9 + 7
class MyRange(object):
    def __init__(self, l, r): 
        self.l = l
        self.r = r

    def __and__(self, other):
        return MyRange(max(self.l, other.l), min(self.r, other.r))

    def __len__(self):
        return self.r - self.l

    def __str__(self):
        return "[{}, {})".format(self.l, self.r)

def hoge(arr):
    res = [MyRange(arr[0], arr[0]+1)]
    for pre, cur in zip(arr, arr[1:]):
        if pre < cur:
            res.append(MyRange(cur, cur+1))
        else:
            res.append(MyRange(1, cur+1))
    return res

if __name__ == "__main__":
    N = int(input())
    T = [int(i) for i in input().split()]
    A = [int(i) for i in input().split()]
    B = [t & a for t, a in zip(hoge(T), hoge(A[::-1])[::-1])]
    # print(*B)
    try:
        C = list(map(len, B))
        print(reduce(lambda a, b: (a * b) % MOD, C))
    except ValueError:
        print(0)


Measured memory_bytes: 70372
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
//#define int long long

void solve() {
    ll N, M; cin >> N >> M;
    ll fact[100100];
    fact[0] = 1LL;
    rep(i, 100010) {
        fact[i + 1] = fact[i] * (i + 1) % mod;
    }
    if(N > M + 1 || M > N + 1) {
        cout << 0 << endl;
    } else {
        if(N == M) {
            cout << 2LL * fact[N] * fact[M] % mod<< endl;
        } else {
            cout << fact[N] * fact[M] % mod << endl;
        }
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for (int i = 0; i < (int)c; i++)
int n, a[3][3], b[10];
bool appear[3][3];
int main() {
    rep (i, 3) {
        rep (j, 3) {
            cin >> a[i][j];
        }
    }
    cin >> n;
    rep (i, n) cin >> b[i];
    rep (i, n) {
        rep (j, n) {
            appear[i][j] = false;
            rep (k, n) {
                if(a[i][j] == b [k]) appear[i][j] = true;
            }
        }
    }
    string ans = "No";
    rep (i, 3) if(appear[i][0] and appear[i][1] and appear[i][2]) ans = "Yes";
    rep (i, 3) if(appear[0][i] and appear[1][i] and appear[2][i]) ans = "Yes";
    if(appear[0][0] and appear[1][1] and appear[2][2]) ans = "Yes";
    if(appear[0][2] and appear[1][1] and appear[2][0]) ans = "Yes";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        a: usize,
        b: usize,
        c: usize,
    }

    if a-b > c {
        println!("{}", 0);
    } else {
        println!("{}", c-(a-b));
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int const INF = 1001001001;


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

ll h;
cin >> h;

int cnt = 0;

while(h >= 1){
    h /= 2;
    cnt ++;
}

ll ans = pow(2,cnt) - 1;
cout << ans << endl;

return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
//#include<con>
using namespace std;
int n,a[100+5],x,y,h;
int main()
{
  scanf("%d",&n);
  for(int i=1;i<=n;i++){scanf("%d",&a[i]);h+=a[i];}
  scanf("%d",&n);
  for(int i=0;i<n;i++)
  {
    scanf("%d%d",&x,&y);
    printf("%d\n",h-a[x]+y);
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
#define watch(x) cout<<(#x)<<" is "<<x<<endl;
#define ll long long int
#define pb push_back
#define in insert
#define mp make_pair
#define F first
#define S second
#define N 1000000
#define MOD 1000000007
#define PI acos(-1)
int main()
{
	IOS
	ll x;
	ll a=100;
	cin>>x;
	ll ans=0;
	ll y;
	while(a<x)
	{
		ans++;
		y=0.01*a;
		a=a+y;
	}
	cout<<ans;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1e9+7;
int modinv(int a, int b=MOD-2) {
    int ret = 1, mult = a % MOD;
    while(b) {
        if(b&1) ret = (ret*mult)%MOD;
        mult = (mult*mult)%MOD;
        b /= 2;
    }
    return ret;
}
int frac(int a, int b) {
    return (a*modinv(b))%MOD;
}
const int MX = 2e5+2;
int fac[MX];
int C(int n, int r) {
	return frac(fac[n], (fac[n-r]*fac[r])%MOD); 
}
int32_t main() {
	ios::sync_with_stdio(0);cin.tie(0);
	fac[0] =1;
	for(int i=1; i<MX; i++) {
		fac[i] = (fac[i-1]*i)%MOD;
	}
	int n, k, ans = 0;
	cin >> n >> k;
	for(int i=1; i<=min(n-1, k)+1; i++) {
		int add = C(n-1, i-1)*C(n, i-1);
		//printf("at i=%d add=%d\n", i, add);
		ans += add;
		ans %= MOD;
	}
	cout << ans;
}

Measured memory_bytes: 1792
#include"stdio.h" 
int main(){int c[3][3];for(int i=0;i<3;i++)for(int j=0;j<3;j++)scanf("%d",&c[i][j]);int flag=1;for(int i=0;i<3;i++){if(c[0][1]-c[0][0]!=c[i][1]-c[i][0])flag=0;if(c[0][2]-c[0][1]!=c[i][2]-c[i][1])flag=0;if(c[1][0]-c[0][0]!=c[1][i]-c[0][i])flag=0;if(c[2][0]-c[1][0]!=c[2][i]-c[1][i])flag=0;}if(flag==1)printf("Yes");else printf("No");return 0;}



Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <list>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

int main() {
    ll x, y;
    cin >> x >> y;
    int ans = 0;
    ll now = x;
    while(now <= y) {
        ans += 1;
        now *= 2;
    }

    cout << ans << endl;
}



Measured memory_bytes: 256
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,n) n = unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;

/*
struct point
{
long long dist; long long name;
bool operator<(const point& rhs) const {
return dist > rhs.dist;
}
};
*/

ll const MAX = 1000006;
string s;
ll n;
ll m[MAX], c[MAX], mc[MAX];

ll f(ll x,ll k) {
	return min(x + k - 1, n);
}

void init() {
	m[0] = c[0] = mc[0] = 0;
	REP(i, 1, n) {
		char cur = s[i - 1];
		c[i] += c[i - 1] + ('C' == cur);
		m[i] += m[i - 1] + ('M' == cur);
		mc[i] = mc[i - 1] + ('C' == cur)*m[i - 1];
		//cout << c[i] << m[i] << mc[i] << endl;
	}
	
}

int main() {
	ll q;
	cin >> n >>  s >> q;
	init();
	REP(j, 1, q) {
		ll ans = 0;
		ll k;
		cin >> k;
		REP(i, 1, n) {
			char cur = s[i - 1];
			if (cur == 'D') {
			//	cout << i << endl;
				ans += mc[f(i, k)] - mc[i - 1] - (m[i - 1] * (c[f(i, k)] - c[i - 1]));
			}
		}
		cout << ans << endl;

	}
}

Measured memory_bytes: 24836
def operate(a, op, b):
        if op == '+':
            return a + b
        if op == '-':
            return a - b
        if op == '*':
            return a * b
        if op == '/':
            return a // b


while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)
    if op == '?':
        break
    print(operate(a, op, b))


Measured memory_bytes: 5596
#include <iostream>
using namespace std;
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)-1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
void tmpInit(int *c,ll m) {ll i;rep(i,m) c[i]=i;}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
  
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0,r,w;
  int a[LIMIT2]={0};
  string s;
  cin >> n;
  cin >> s;
  string t;
  rep(i,n){
    t+="W";
  }
  r=0;w=0;
  rep(i,n){
    if(s[i]!=t[i]){
      if(s[i]=='R'){
        r++;
      }else{
        w++;
      }
    }
  }
  result = r;
  rep(i,n){
    if(s[i]!=t[i]){
      if(s[i]=='R'){
        r--;
      }else{
        w--;
      }
    }
    t[i]='R';
    if(s[i]!=t[i]){
      if(s[i]=='R'){
        r++;
      }else{
        w++;
      }
    }
    //cout << t << " " << max(r,w) << endl;
    result = min(result,max(r,w));
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3916
#include<bits/stdc++.h>
 using namespace std;
int main()
{
int r,g,b,n,i,j,ans,a;
  cin >> r >> g >> b >> n;
  ans=0;
  for(i=0;i*r<=n;i++)
  {
  for(j=0;(j*g+i*r)<=n;j++)
  {
    a=n-j*g-i*r;
    if(a%b==0)
      ans++;
  }
  }
  cout << ans << endl;
}
  


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>

int main()
{
    int N;
    std::cin >> N;

    std::string S;
    std::cin >> S;

    // 各アルファベットの登場箇所
    std::array<std::vector<short>, 26 * 26> top;
    for (int i = 0; i < (N - 1); ++i) {
        top[(((size_t)S[i] - 'a') * 26) + (size_t)S[(size_t)i + 1] - 'a'].push_back((short)i);
    }

    size_t max = 0;

    for (auto& alpha : top) {
        const int size = (int)alpha.size();
        for (int i = 0; i < (size - 1); ++i) {
            for (int j = i + 1; j < size; ++j) {
                const size_t maxLength = std::min(std::min(alpha[j] - alpha[i], (N + 1) / 2), N - alpha[j]);
                if (maxLength < max) {
                    // すでに短い
                    continue;
                }
                // 先頭2文字は合致しているので2スタート
                size_t length;
                for (length = 2; length < maxLength; ++length) {
                    // 一致文字数を調べる
                    if (S[alpha[i] + length] != S[alpha[j] + length]) {
                        // 違う文字が見つかった
                        break;
                    }
                }
                if (max < length) {
                    max = length;
                }
            }
        }
    }

    if (max <= 1) {
        max = 0;
    }

    std::cout << max;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int n;
int id;
int t[100000];
int u[100000];
int v[100000];
int w[100000];
int tmp[100000];
  
void setdepth(int x){
  if(t[x]==-1){
    w[x]=0;
    return;
  }
  if(w[x]!=-1)return;
  setdepth(t[x]);
  w[x]=w[t[x]]+1;
}
  
void init(){
  int i;
  for(i=0;i<100000;i++){
    t[i]=-1;
    u[i]=-1;
    v[i]=-1;
    w[i]=-1;
  }
}
  
int main(){
  int i,j,k,pos;
  
  init();
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&id);
    scanf("%d",&k);
    for(j=0;j<k;j++){
      scanf("%d",&tmp[j]);
      t[tmp[j]]=id;
      if(j>0)v[tmp[j-1]]=tmp[j];
    }
    if(k)u[id]=tmp[0];
  }
  
  
  for(i=0;i<n;i++){
    setdepth(i);
    printf("node %d: parent = %d, depth = %d, ",i,t[i],w[i]);
    if(w[i]==0)printf("root, ");
    else if(u[i]==-1)printf("leaf, ");
    else printf("internal node, ");
    pos=u[i];
    printf("[");
    if(pos!=-1){
      while(1){
    printf("%d",pos);
    pos=v[pos];
    if(pos==-1)break;
    printf(", ");
      }
    }
    printf("]\n");
      
  }
  return 0;
}


Measured memory_bytes: 4500
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int top = 0, S[150];

void push(int x){
    top = top + 1;
    S[top] = x;
}

int pop(){
    top = top - 1;
    return S[top + 1];
}

int main( void ){
    int a, b, i, num, flag, n;
    top = 0;
    char s[500];
    fgets(s, 500, stdin);
    flag = 0;
    num = 0;
    for(i = 0; s[i] != '\n'; i++){
        if(s[i] == '+'){
            a = pop();
            b = pop();
            push(a + b);
        }
        else if(s[i] == '-'){
            a = pop();
            b = pop();
            push(b - a);
        }
        else if(s[i] == '*'){
            a = pop();
            b = pop();
            push(a * b);
        }
        else if(s[i] == ' '){
            if(flag >= 1){  //1個前が数字の場合
                for(n = 1; n <= flag; n++){
                    num += (s[i - n] - '0') * pow(10, n - 1);   //正しい10進数の数になおす
                }
                push(num);
                flag = 0;
                num = 0;
            }
        }
        else{
            flag += 1;
        }
        /*
        int j;
        for(j = 0; j < 10; j++){
            printf("%d ", S[j]);
        }
        printf("\ntop = %d\n", top);
        printf("s[%d] = %c\n\n",i,s[i]);*/    //11 2 + 13 4 - *
    }
    printf("%d\n", pop());
    return 0;
}



Measured memory_bytes: 2108
//package Atcoder;
import java.util.*;
import java.io.*;
public class Main
{
	static final int mod=2019;
	static final int inf=(int)1e9;
	static final long INF=(long)1e18;
	public static void main(String[] args)
	{
		FastScanner fs=new FastScanner();
		char arr[]=fs.next().toCharArray();
		int power=1,suf=0;
		int cnt[]=new int[mod+1];
		long ans=0;
		cnt[suf]++;
		for(int i=arr.length-1;i>=0;i--)
		{
			int digit=arr[i]-'0';
			suf=(suf+digit*power)%mod;
			power=(power*10)%mod;
			ans+=cnt[suf];
			cnt[suf]++;
		}
		System.out.println(ans);
	}
}
class FastScanner 
{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		public String next() 
		{
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
			
		}
		
		long pow(long x,long n)
		{
			long res=1;
			while(n>0)
			{
			   	if(n%2!=0)
			   	{
			   		res=(res*x);n--;
			   	}
			   	else
			   	{
			   		x=(x*x);n/=2;
			   	}
			}
			return res;
		}
		int gcd(int a,int b)
		{
			if(b==0)
			{
				return a;
			}
			return gcd(b,a%b);
		}
		long longgcd(long a,long b)
		{
			if(b==0)
			{
				return a;
			}
			return longgcd(b,a%b);
		}
		int[] sort(int arr[])
		{
			ArrayList<Integer> list = new ArrayList<Integer>();
			for(int i:arr)list.add(i);
			Collections.sort(list);
			for(int i=0;i<arr.length;i++)
			{
				arr[i]=list.get(i);
			}
			return arr;
		}
		char[] charsort(char arr[])
	        {
	    	ArrayList<Character> list = new ArrayList<>();
	    	for(char c:arr)list.add(c);
	    	Collections.sort(list);
	    	for(int i=0;i<list.size();i++)
	    	{
	    		arr[i]=list.get(i);
	    	}
	    	return arr;
	        }
		long[] longsort(long arr[])
		{
			ArrayList<Long> list = new ArrayList<Long>();
			for(long i:arr)list.add(i);
			Collections.sort(list);
			for(int i=0;i<arr.length;i++)
			{
				arr[i]=list.get(i);
			}
			return arr;
		}
		public int nextInt() 
		{
			return Integer.parseInt(next());
		}
		public int[] readArray(int n)
		{
			int[] arr=new int[n];
			for (int i=0; i<n; i++) arr[i]=nextInt();
			return arr;
		}	
		public long nextLong()
		{
			return Long.parseLong(next());
		}
		public long[] longreadArray(int n) 
		{
			long[] a=new long[n];
			for (int i=0; i<n; i++) a[i]=nextLong();
			return a;
		}
}

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


int main(){
    string S, T;
    cin >> S >> T;

    int diff =100000;
    for(int s=0; s<=S.size() - T.size(); ++s){
        int tmp = 0;

        for(int t=0; t<T.size(); ++t){
            if(S[s+t] != T[t]){
                tmp++;
            }
        }
        diff = min(diff, tmp);
    }

    cout << diff << endl;
}

Measured memory_bytes: 3600
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod 10000000
#define int long long
#define double long double
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n;
string s;
map<pair<string, string>, int> mp[2];
signed main() {
	cin >> n >> s;
	reverse(s.begin() + n, s.end());
	rep(i, ((ll)1 << n)) {
		string t, r;
		rep(j, n) {
			if ((i >> j) & 1)t += s[j];
			else r += s[j];
		}
		mp[0][make_pair(t, r)]++;
	}

	rep(i, ((ll)1 << n)) {
		string t, r;
		rep(j, n) {
			if ((i >> j) & 1)t += s[j + n];
			else r += s[j + n];
		}
		mp[1][make_pair(t, r)]++;
	}
	int ans = 0;
	for (auto p : mp[0]) {
		ans += mp[1][p.first] * p.second;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
using ll = long long;

int main() {
  ll a,b,x;
  cin>>a>>b>>x;
  if (x==1) {
    cout<<(b-a+1)<<endl;
    return 0;
  }

  ll res = b/x - (a-1)/x;
  if (a==0) res++;
  cout<<res;
  
  return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>

int main(void)
{
  int h[101], n, count = 0;
  int i, j, k;
  
  scanf("%d", &n);
  for( i = 0; i < n; i++){
    scanf("%d", &h[i]);
  }
  
  for( i = 0; i < n; i++ ){
    for( j = i; h[i] != 0; j++ ){
      if( h[i] == 0 ){
        printf("0zo\n");
        break;
      }
      for( k = i; k < n; k++){
        if( h[k] != 0 ){
          h[k] -= 1;
        } else {
          break;
        }
      }
      count++;
    }
  }
  
  printf("%d\n", count);
} 
  

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>
#include<queue>
#include<deque>
#include<fstream>
#include<random>
#include<set>
 
#define rep(i, n) for (ll i = 0; i < n; i++) 
#define rrep(i, n) for(ll i = n-1; i>=0; i--)
#define range(i, n, m) for (ll i = n; i < m; i++) 
#define rrange(i, n, m) for (ll i = n - 1; i => m; i--) 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vp vector<pair<ll, ll> >
#define vvp vector<vector<pair<ll, ll> > >
#define First first
#define Second second.first
#define Third second.second
#define Sort(X) sort(X.begin(), X.end())
#define RSort(X, T) sort(X.begin(), X.end(), greater<T>())
//#define MOD 998244353
#define MAX 100000
 
typedef long long int ll;
typedef unsigned long long int ull;
 
using namespace std;
 
template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return true; } return false; }

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


	string S;
	cin >> S;
	ll out = 0;

	if (S == "SUN") out = 7;
	else if (S == "MON") out = 6;
	else if (S == "TUE") out = 5;
	else if (S == "WED") out = 4;
	else if (S == "THU") out = 3;
	else if (S == "FRI") out = 2;
	else if (S == "SAT") out = 1;

	cout << out;

	return 0;
}

Measured memory_bytes: 888
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
typedef pair<int,int> pii;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define inf 1000000000

const long double PI = acos(-1);

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}


void solve(){
   
    long double a,b,x;
    cin >> a >> b >> x;
    //x = a*a*b-x;
    long double ans ;
    if(a*a*b/2.0 <= x) ans = atan(2*(a*a*b - x)/(a*a*a));
    else ans = PI/2.0 - atan(2*x/(a*b*b));

    cout << fixed << setprecision(10) << ans*180.0/PI << endl;

} 

signed main() 
{   
    IOS;
    int t = 1;
    //cin >> t;

    for(int i = 1;i<=t;i++){
        solve();
    }
    return 0;
} 

 


Measured memory_bytes: 256
def main(N,Y):
    for i in range(N+1):
        for j in range(N+1-i):
            k = N-i-j
            if 10000*i + 5000*j + 1000*k == Y:
                return i,j,k
                break
    else:
        return -1,-1,-1

N,Y = map(int, input().split())
print(*main(N,Y))

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

int binarySearch(vector<int> S, int key){
  int left = 0, right = S.size();
  while(left < right){
    int mid = (left + right) / 2;
    if(S[mid] == key) return mid;
    else if(S[mid] > key) right = mid;
    else if(S[mid] < key) left = mid + 1;
  }
  return -1;
}

int main(void){
  vector<int> S;
  int n, q, cnt = 0;

  cin >> n;
  for(int i = 0; i < n; i++){
    int num;
    cin >> num;
    S.push_back(num);
  }
  sort(S.begin(), S.end());

  cin >> q;
  for(int i = 0; i < q; i++){
    int key;
    cin >> key;
    if(binarySearch(S, key) >= 0) cnt++;
  }

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

Measured memory_bytes: 1936
def main():
    n,k = map(int,input().split())
    a = list(map(int, input().split()))

    if max(a) < k:
        print("IMPOSSIBLE")
    else:
        from fractions import gcd
        gmax = a[0]
        for i in range(1, n):
            gmax = gcd(gmax, a[i])

        if k % gmax == 0:
            print("POSSIBLE")
        else:
            print("IMPOSSIBLE")

    


if __name__ == '__main__':
    main()


Measured memory_bytes: 81684
#pragma region head
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using vi = vector<int>;
    using vll = vector<ll>;
    using pi = pair<int, int>;
    using pll = pair<ll,ll>;
    template <class T> using vv = vector<vector<T>>;
    #define rep(i,n) for(int i = 0; i < (int)(n); i++)
    #define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
    #define rrep(i,n) for(int i = (int)(n)-1; i >= 0; i--)
    #define rrepi(i,a,b) for(int i = (int)(b)-1; i >= (int)(a); i--)
    #define all(x) (x).begin(), (x).end()
    #define rall(x) (x).rbegin(), (x).rend()    
    #define bit(n) (1LL<<(n))
    template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
    template<class T> inline bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
#pragma endregion head

#pragma region library
const int MOD = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  // for prime MOD
  mint inv() const {
    return pow(MOD-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
ostream& operator<< (ostream& os, const mint& value) {
  os << value.x;
  return os;
}

#pragma endregion library

int main(){
    int n; cin >> n;
    vi a(n); rep(i,n) cin >> a[i];
    vector<mint> ac(n);
    ac[0] = a[0];
    rep(i,n-1){
        ac[i+1] = ac[i] + a[i+1];
    }
    mint ans = 0;
    repi(i,1,n){
        ans += (mint)a[i]*ac[i-1];
    }
    cout << ans << '\n';
    

}


Measured memory_bytes: 5568
MAX = pow(10,16)+1000
K = int(input())
N = 50
kaisu = [K//N for _ in range(N)]
ans = [-1 for _ in range(N)]
nokori = K%N
for i in range(nokori):
  kaisu[i] += 1
#print(kaisu)

for i in range(N):
  temp = (N+1)*kaisu[i]+N-1-K
  ans[i] = temp

print(N)
print(*ans)

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


using namespace std;
typedef long long ll;

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

  int len = n.size();

  char cr = n.at(len-1);

  if(cr == '3') res = "bon";
  else if(cr == '0' || cr == '1' || cr == '6' || cr == '8') res = "pon";
  else res = "hon";





  cout << res << endl;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <queue>
#include <algorithm>

using namespace std;

struct node {
	long long X, H;
	bool operator < (const node& x) const {
		return X < x.X;
	}
}a[200000];
queue<node> h;
long long N, D, A, s, ans;

int main() {
	scanf("%lld%lld%lld", &N, &D, &A);
	D = 2 * D + 1;
	for (int i = 0; i < N; ++i) scanf("%lld%lld", &a[i].X, &a[i].H);
	sort(a, a + N);
	for (int i = 0; i < N; ++i) {
		while (!h.empty() && h.front().X <= a[i].X) {
			s -= h.front().H;
			h.pop();
		}
		if (s < a[i].H) {
			long long d = (a[i].H - s - 1) / A + 1;
			h.push({a[i].X + D, A * d});
			ans += d;
			s += A * d;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();
		int[] r = new int[n];
		for(int i=0; i<n; i++) {
			r[i] = sc.nextInt();
		}

		int minPrice = 2000000001;
		int maxProfit = -2000000001;
		for(int i=0; i<n; i++) {
			if (r[i]-minPrice > maxProfit) {
				maxProfit = r[i]-minPrice;
			}
			if (r[i] < minPrice) {
				minPrice = r[i];
			}
		}

		System.out.println(maxProfit);
	}
}



Measured memory_bytes: 101988
#include <stdio.h>
#include <iostream>
#include <algorithm>


using namespace std;
typedef long long LL;
#define MAXN 100005
LL N,res=0;
LL a[MAXN],b[MAXN],c[MAXN];
LL lnb[MAXN]={0},unb[MAXN]={0};


int main(int argc, char const *argv[])
{
	cin>>N;
	for (int i = 0; i < N; ++i) cin>>a[i];
	for (int i = 0; i < N; ++i)	cin>>b[i];
	for (int i = 0; i < N; ++i) cin>>c[i];
	sort(a,a+N); sort(b,b+N); sort(c,c+N);



	// for (int i = 0; i < N; ++i){
	// 	for (int j = 0; j < N; ++j){
	// 		if(j==N-1 && a[j]<b[i]){
	// 			lnb[i]=N; 
	// 			break;
	// 		}
	// 		if(a[j]>b[i]){
	// 			lnb[i]=j;			
	// 			break;
	// 		}
	// 	}
	// }

	// for (int i = 0; i < N; ++i){
	// 	for (int j = 0; j < N; ++j){
	// 		if(j==0 && c[j]>b[i]){
	// 			unb[i]=N;
	// 		}
	// 		if (b[i]>c[j]){
	// 			unb[i]=N-j-1;
	// 			break;
	// 		}
	// 	}
	// }

    for(int i = 0; i < N; ++i)
	     lnb[i] = lower_bound(a,a+N,b[i]) - a;
	for(int i = 0; i < N; ++i)
	     unb[i] = N - (upper_bound(c,c+N,b[i]) - c);
	for (int i = 0; i < N; ++i){
		res+=lnb[i]*unb[i];
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 4096
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N;
i64 T, ti[202020];

int main()
{
	scanf("%d%lld", &N, &T);
	for (int i = 0; i < N; ++i) scanf("%lld", ti + i);

	i64 ret = 0, last = 0;
	for (int i = 0; i < N; ++i) {
		ret += min(ti[i] - last, T);
		last = ti[i];
	}
	ret += T;
	printf("%lld\n", ret);

	return 0;
}


Measured memory_bytes: 1792
import itertools

n, m, q = map(int, input().split())
abcd = []
for i in range(q):
    abcd.append(list(map(int, input().split())))
ans = 0
j = [0] * 10
for i1 in range(1, m + 1):
    j[0] = i1
    for i2 in range(i1, m + 1):
        j[1] = i2
        for i3 in range(i2, m + 1):
            j[2] = i3
            for i4 in range(i3, m + 1):
                j[3] = i4
                for i5 in range(i4, m + 1):
                    j[4] = i5
                    for i6 in range(i5, m + 1):
                        j[5] = i6
                        for i7 in range(i6, m + 1):
                            j[6] = i7
                            for i8 in range(i7, m + 1):
                                j[7] = i8
                                for i9 in range(i8, m + 1):
                                    j[8] = i9
                                    for i10 in range(i9, m + 1):
                                        j[9] = i10
                                        temp = 0
                                        for i in range(q):
                                            if j[abcd[i][1] - 1] - j[abcd[i][0] - 1] == abcd[i][2]:
                                                temp += abcd[i][3]
                                        ans = max(ans, temp)
print(ans)

Measured memory_bytes: 9176
#![allow(unused_imports)]
#![allow(unused_macros)]
use std::cmp::{max, min};
use std::collections::*;
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, $var:ident $($r:tt)*) => {
        let $var = parse_val!($it, usize);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: tt),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, u1) => {
        $it.next().unwrap().parse::<usize>().unwrap() -1
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

#[cfg(debug_assertions)]
macro_rules! debug {
    ($( $args:expr ),*) => { eprintln!( $( $args ),* ); }
}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($( $args:expr ),*) => {
        ()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize);
    let mut a = BTreeMap::<i64, BTreeSet<(i64, char)>>::new();
    let mut b = BTreeMap::<i64, BTreeSet<(i64, char)>>::new();
    let mut c = BTreeMap::<i64, BTreeSet<(i64, char)>>::new();
    let mut d = BTreeMap::<i64, BTreeSet<(i64, char)>>::new();
    for _ in 0..n {
        parse!(it, x: i64, y: i64, u: char);
        a.entry(x - y).or_default().insert((x, u));
        b.entry(x + y).or_default().insert((x, u));
        c.entry(y).or_default().insert((x, u));
        d.entry(x).or_default().insert((y, u));
    }

    let mut ret = std::i64::MAX;
    let small = std::i64::MIN / 100;
    for (g, ctv, p) in &[
        (a, vec![('U', 'L'), ('R', 'D')], 10),
        (b, vec![('R', 'U'), ('D', 'L')], 10),
        (c, vec![('R', 'L')], 5),
        (d, vec![('U', 'D')], 5),
    ] {
        for set in g.values() {
            for &(c, t) in ctv {
                let mut prevx = small;
                for &(x, d) in set {
                    if d == t {
                        ret = min(ret, (x - prevx) * p);
                    } else if d == c {
                        prevx = x;
                    }
                }
            }
        }
    }

    if ret > 20000000 {
        println!("{}", "SAFE");
    } else {
        assert!(ret > 0);
        println!("{}", ret);
    }
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 194040
#include <iostream>
using namespace std;
int main(void){
    int S;
    int h=0;
    int m=0;
    int s=0;
    
    scanf("%d",&S);
    
    while(S>=3600){
    S -=3600;
    h++;
    }
    
    while(S>=60){
    S -= 60;
    m++;
    }
    
    s = S;
    
    printf("%d:%d:%d\n",h,m,s);
    
}



Measured memory_bytes: 3212
from  heapq import heappush, heappop, heapify
import math

N, K = map(int, input().split())

A = list(map(int, input().split()))

l = 0
r = 10 ** 9

def check(m):
    now = 0
    for i in range(N):
        #A[i]-1してるのは、たとえばm=3のときは4,7から回数が増えるため
        now += (A[i]-1) // m
    return now <= K

#差が1になったら終了
while r - l > 1:
    m = (l + r) // 2

    if check(m):
        r = m
    else:
        l = m

print(r)

Measured memory_bytes: 104784
#include <stdio.h>
int search(int A[], int n, int key);
int main(void){
  int i, n, A[10000+1], q, key, sum = 0;
  scanf("%d",&n);
  for(i=0; i<n; i++) scanf("%d", &A[i]);
  scanf("%d",&q);
  for(i=0; i<q; i++) {
    scanf("%d", &key);
    if(search(A, n, key))sum++;
  }
  printf("%d\n", sum);
  return 0;
}

int search(int A[], int n, int key){
  int i = 0;  A[n] = key;
  while(A[i] != key) i++;
  return i != n;
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()

#define pb push_back
#define mp make_pair

#define F first
#define S second

using ll = long long;
using namespace std;

void chmin(ll &a, ll b) { if (a > b) a = b; }

const int mod = 1000000007;
const int INF = 1e+9;

ll n, A, B, C;

vector<ll> l;

ll dfs (ll cur,ll a, ll b, ll c) {
    if (cur == n) {
        // 1本は使うようにする
        if (!a || !b || !c) return INF;
        return abs(a - A) + abs(b - B) + abs(c - C); 
    }
    cerr << l[cur] << endl;
    ll res = dfs(cur+1, a, b, c);
    // 1本目はコストなし、2本目からはコスト10かかる
    chmin(res, dfs(cur+1, a+l[cur], b, c) + (a ? 10 : 0));
    chmin(res, dfs(cur+1, a, b+l[cur], c) + (b ? 10 : 0));
    chmin(res, dfs(cur+1, a, b, c+l[cur]) + (c ? 10 : 0));

    return res;
}

int main() {
    cin >> n >> A >> B >> C;
    l.resize(n);
    for (int i = 0; i < n; i++) cin >> l[i];

    cout << dfs(0, 0, 0, 0) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card
{
  char suit;
  int value;
};

struct Card L[MAX/2+2],R[MAX/2+2];

void merge(struct Card A[],int n,int left,int mid,int right)
{
  int i,j,k;
    int n1=mid-left;
  int n2=right-mid;
  for(i=0;i<n1;i++) L[i]=A[left+i];
  for(i=0;i<n2;i++) R[i]=A[mid+i];
  L[n1].value=R[n2].value=SENTINEL;
  i=j=0;
  for(k=left;k<right;k++)
    {
      if(L[i].value<=R[j].value)
	{
	  A[k]=L[i++];
	}
      else
	{
	  A[k]=R[j++];
	}
    }
}

void mergeSort(struct Card A[],int n,int left,int right)
{
  int mid;
  if(left+1<right)
    {
      mid=(left+right)/2;
      mergeSort(A,n,left,mid);
      mergeSort(A,n,mid,right);
      merge(A,n,left,mid,right);
    }
}

int part(struct Card A[],int n,int p,int r)
{
  int i,j;
  struct Card t,x;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++)
    {
      if(A[j].value <= x.value)
	{
	  i++;
	  t=A[i];A[i]=A[j];A[j]=t;
	}
    }
  t=A[i+1];A[i+1]=A[r];A[r]=t;
  return i+1;
}

void quick(struct Card A[],int n, int p,int r)
{
  int q;
  if(p<r)
    {
      q=part(A,n,p,r);
      quick(A,n,p,q-1);
      quick(A,n,q+1,r);
    }
}

int main ()
{
  int n,i,v;
  struct Card A[MAX],B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d",&n);

  for(i=0;i<n;i++)
    {
      scanf("%s %d",S,&v);
      A[i].suit =B[i].suit=S[0];
      A[i].value=B[i].value = v;
    }

  mergeSort(A,n,0,n);
  quick(B,n,0,n-1);

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

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



Measured memory_bytes: 4096
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }


signed main()
{
	string S;
	cin >> S;
	int ans = 0;
	for (int i = 0; i < S.length(); i++)
	{
		int cnt = 0;
		for (int j = i; j < S.length(); j++)
		{
			bool a = false;
			switch (S[j])
			{
				case 'A':
				case 'C':
				case 'G':
				case 'T':
					cnt++;
					break;
				default:
					a = true;
					break;
			}
			if (a) break;
		}
		ans = max(ans, cnt);
	}
	cout << ans << endl;
}



Measured memory_bytes: 3124