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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll a,b,q; cin>>a>>b>>q;
  vll s;
  s.push_back(-INF);
  rep(i,a){
    ll x; cin>>x;
    s.push_back(x);
  }
  s.push_back(INF);
  vll t;
  t.push_back(-INF);
  rep(i,b){
    ll x; cin>>x;
    t.push_back(x);
  }
  t.push_back(INF);
  vll res;
  rep(_,q){
    ll ans=INF;
    ll x; cin>>x;
    ll si=lower_bound(all(s),x)-s.begin();
    ll ti=lower_bound(all(t),x)-t.begin();
    chmin(ans,max(s[si],t[ti])-x);
    chmin(ans,abs(min(s[si-1],t[ti-1])-x));
    chmin(ans,(s[si]-x)*2+x-t[ti-1]);
    chmin(ans,(t[ti]-x)*2+x-s[si-1]);
    chmin(ans,(x-s[si-1])*2+t[ti]-x);
    chmin(ans,(x-t[ti-1])*2+s[si]-x);
    res.push_back(ans);
  }
  for(auto e: res){
    cout<<e<<endl;
  }
}


Measured memory_bytes: 3828
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INF (1<<20)

int m[10][10], d[10], c[10];

void dijkstra_init(){
	for(int i=0; i<10; i++){
		d[i]=INF;
		c[i]=WHITE;
	}
	return;
}

void dijkstra(int s){
	d[s]=0;
	while(1){
		int minv=INF, u=-1;
		for(int i=0; i<10; i++){
			if(minv>d[i] && c[i]!=BLACK){
				u=i;
				minv=d[i];
			}
		}
		if(u==-1) break;
		c[u]=BLACK;
		for(int v=0; v<10; v++){
			if(c[v]!=BLACK && m[u][v]!=INF){
				if(d[u]+m[v][u]<d[v]){
					d[v]=d[u]+m[v][u];
					c[v]=GRAY;
				}
			}
		}
	}
	return;
}

int main(){
	int h, w;
	cin >> h >> w;
	for(int i=0; i<10; i++){
		for(int j=0; j<10; j++){
			cin >> m[i][j];
		}
	}
	vector<int> cnt(10, 0);
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			int a;
			cin >> a;
			if(a!=-1) cnt[a]++;
		}
	}
	dijkstra_init();
	dijkstra(1);
	int sum=0;
	for(int i=0; i<10; i++) sum+=d[i]*cnt[i];
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <cstdlib>
#include <utility>
#include <map>

using namespace std;

int main(){
    string s;
    cin >> s;
    int a[4] = {0, 0, 0, 0};
    for(int i = 0; i < s.size(); i++){
        if(i % 2 == 0){
            if(s[i] == '0'){
                a[0]++;
            }else{
                a[1]++;
            }
        }else{
            if(s[i] == '0'){
                a[2]++;
            }else{
                a[3]++;
            }
        }
    }
    if(a[0] >= a[1] && a[2] <= a[3]){
        cout << s.size() -  a[0] - a[3];
    }
    else if(a[0] >= a[1] && a[2] >= a[3]){
        if(a[0] >= a[2]){
            cout << s.size() - a[0] - a[3];
        }else{
            cout << s.size() - a[1] - a[2];
        }
    }
    else if(a[0] <= a[1] && a[2] <= a[3]){
        if(a[1] >= a[3]){
            cout << s.size() - a[1] - a[2];
        }else{
            cout << s.size() - a[0] - a[3];
        }
    }
    else if(a[0] <= a[1] && a[2] >= a[3]){
        cout << s.size() -  a[1] - a[2];
    }
    
}

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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

void solve() {
	int h, w; scanf("%d%d", &h, &w);
	if (h > w) swap(h, w);
	long long ans = 2e18;
	for (long long i = 1; i < h; ++i) {
		long long a = i*w;
		long long b = (h-i)*(w/2);
		long long c = (h-i)*(w/2+w%2);
		//debug(a); debug(b); debug(c);
		ans = min(ans, max({a, b, c})-min({a, b, c}));
		b = ((h-i)/2)*w;
		c = ((h-i)/2+(h-i)%2)*w;
		ans = min(ans, max({a, b, c})-min({a, b, c}));
	}
	for (long long i = 1; i < w; ++i) {
		long long a = i*h;
		long long b = (w-i)*(h/2);
		long long c = (w-i)*(h/2+h%2);
		//debug(a); debug(b); debug(c);
		ans = min(ans, max({a, b, c})-min({a, b, c}));
		b = ((w-i)/2)*h;
		c = ((w-i)/2+(w-i)%2)*h;
		ans = min(ans, max({a, b, c})-min({a, b, c}));
	}
	printf("%lld", ans);
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
// Goods things are coming, just keep believing 
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
 
#define FOR(i, x, n) for(ll i = x; i < n; i++) 
#define pb push_back
#define pf push_front
#define ll long long
#define hii cout << "hii" << endl
#define okay cout << "okay" << endl
// #define hey cout << "hey" << endl
#define pii pair<int, int>
#define pll pair<ll, ll>
// #define mpp make_pair
#define endl '\n'
#define ff first 
#define int unsigned long long
#define ss second
#define vi vector<int>
#define all(s) s.begin(), s.end()
#define si size()
 #define ld long double
#define INF 1000000000;
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; } 
 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE
 
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
 
 
 
const int N = 2e5 + 5;
const int LG = 20;
const int mod = 1e9 + 7;

int arr[N];
int pos[N];
vector<int> v[N];

int n;

int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b); 
} 

void solve()
{
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < n; i++)
	{
		cin >> arr[i];
		arr[i] /= 2;
	}
	sort(arr, arr + n);
	int ans = arr[0]; 
    for(int i = 1; i < n; i++) 
    {
        ans = (((arr[i] * ans)) / (gcd(arr[i], ans)));
        if(ans > m)
        {
        	cout << 0 << endl;
        	return;
        }
    }
    for(int i = 0; i < n; i++) 
    {
        if((ans / arr[i]) % 2 == 0)
        {
        	cout << 0 << endl;
        	return ;
        }
    }
	int no = m / ans;
	cout << (no + 1) / 2 << endl;
}
 
int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int t = 1;
	// cin >> t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 7168
#abc095d

n,c=map(int,raw_input().split())
temp=[0 for i in xrange(n+1)]
x=[]
v=[]
for i in xrange(n):
 xi,vi=map(int,raw_input().split())
 x.append(xi)
 v.append(vi)
xr=[]
vr=[]
for i in xrange(n):
 xr.append(c-x[n-i-1])
 vr.append(v[n-i-1])
s=v[0]
sr=vr[0]
w,w2=[max(s-x[0],0)],[max(s-x[0]*2,0)]
wr,w2r=[max(sr-xr[0],0)],[max(sr-xr[0]*2,0)]
for i in xrange(1,n):
 s+=v[i]
 sr+=vr[i]
 w.append(max(s-x[i],w[i-1]))
 w2.append(max(s-x[i]*2,w2[i-1]))
 wr.append(max(sr-xr[i],wr[i-1]))
 w2r.append(max(sr-xr[i]*2,w2r[i-1]))
res=0
for i in xrange(n-1):
 res=max(res,w[i]+w2r[n-i-2])
 res=max(res,wr[i]+w2[n-i-2])
res=max(res,max(w))
res=max(res,max(wr))
print res


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

int n, m, fa[2005], dep[2005], a[2005], b[2005], d[2005], cov[2005], st[2005], ed[2005], dfs_clock;
bool fix[2005];
vector<int> g[2005];

bool cover_dir(int i, int u) {
	return st[a[i]] >= st[u] && st[a[i]] <= ed[u] && (st[b[i]] < st[u] || st[b[i]] > ed[u]);
}
bool cover(int i, int u) {
	return (st[a[i]] >= st[u] && st[a[i]] <= ed[u]) ^ (st[b[i]] >= st[u] && st[b[i]] <= ed[u]);
}

void dfs(int u) {
	st[u] = ++dfs_clock;
	for (int v : g[u])
		if (v != fa[u])
			fa[v] = u, dep[v] = dep[u] + 1, dfs(v);
	ed[u] = dfs_clock;
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1, u, v; i < n; ++i) {
		scanf("%d%d", &u, &v);
		g[u].push_back(v), g[v].push_back(u);
	}
	dfs(1);
	for (int i = 1; i <= m; ++i) {
		scanf("%d%d", a + i, b + i);
		for (int u = a[i], v = b[i]; u != v;) dep[u] > dep[v] ? (++d[u], u = fa[u]) : (++d[v], v = fa[v]);
	}
	int ans = 0;
	for (int i = 2; i <= n; ++i) ans += min(2, d[i]);
	printf("%d\n", ans);
	for (int cnt = 1; cnt <= m; ++cnt) {
		int u = -1;
		for (int i = 2; i <= n; ++i) if (d[i] == 1 && (cov[i] == 1 || cov[i] == 2)) u = i;
		if (u == -1) for (int i = 2; i <= n; ++i) if (d[i] >= 2) u = i;
		for (int i = 1; i <= m; ++i)
			if (!fix[i] && cover(i, u)) {
				fix[i] = true;
				if (cov[u] == 2 ^ cover_dir(i, u)) swap(a[i], b[i]);
				for (int u = a[i], v = b[i]; u != v;)
					dep[u] > dep[v] ? (cov[u] |= 1, --d[u], u = fa[u]) : (cov[v] |= 2, --d[v], v = fa[v]);
				break;
			}
	}
	for (int i = 1; i <= m; ++i)
		printf("%d %d\n", a[i], b[i]);
	return 0;
}


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

using namespace std;

int n;
int R[200009];

int main(void){
  cin >> n;
  cin >> R[0];
  int maxj = -999999999;
  int minj = R[0];
  for(int i = 1; i < n; i++){
    cin >> R[i];
    maxj = max(maxj, R[i] - minj);
    minj = min(minj, R[i]);
  }
  cout << maxj << endl;
}


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

int N,M,X;
int C[12];
int A[12][12];
int RIKAI[12];
int MIN,temp;
int main() {
    cin >> N >> M >> X;
    for (int i = 0; i < N; i++)
    {
        cin >> C[i];
        for (int j = 0; j < M; j++)
        {
            cin >> A[i][j];
        }
    }
    MIN = 100000000;
    for (int bit = 0; bit < (1<<N); ++bit)
    {
        for (int i = 0; i < M; i++)
        {
            RIKAI[i] = 0;
        }
        temp = 0;
        for (int i = 0; i < N; ++i) {
            if (bit & (1<<i)) { // i番目の参考書を買う
                for (int j = 0; j < M; j++)
                {
                    RIKAI[j] += A[i][j]; //理解度が上がる
                }
                temp += C[i]; // C[i]円かかる
            }
            for (int j = 0; j < M; j++)
            {
                if(RIKAI[j] < X) break;
                if(j == M-1) MIN = min(temp,MIN);
            }
        }
    }
    if(MIN == 100000000) cout << -1 << endl;
    else cout << MIN << endl;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

const int MOD = 1000000007;
int dp[105][4][4][4];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    dp[0][3][3][3] = 1;
    rep(i, n) {
        rep(j, 4) rep(k, 4) rep(l, 4) rep(m, 4) {
            if (k == 0 && l == 1 && m == 2) continue;
            if (k == 0 && l == 2 && m == 1) continue;
            if (k == 1 && l == 0 && m == 2) continue;
            if (j == 0 && k == 1 && m == 2) continue;
            if (j == 0 && l == 1 && m == 2) continue;
            dp[i+1][k][l][m] += dp[i][j][k][l];
            dp[i+1][k][l][m] %= MOD;
        }
    }
    int ans = 0;
    rep(j, 4) rep(k, 4) rep(l, 4) {
        ans += dp[n][j][k][l];
        ans %= MOD;
    }
    cout << ans << endl;
}

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

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

// code starts
#define INF 1020304050
typedef pair<int,int> P;

int main()
{
  int nv,ne,r;cin>>nv>>ne>>r;
  vector<int> s(ne);
  vector<int> t(ne);
  vector<int> d(ne);
  int i;
  rep(i,ne)cin>>s[i]>>t[i]>>d[i];
  vector<vector<P>> g(nv);
  rep(i,ne)
  {
    g[s[i]].emplace_back(make_pair(t[i],d[i]));
  }
  vector<int> ans(nv,INF);
  ans[r]=0;
  priority_queue<P, vector<P>, greater<P>> q;
  q.push(make_pair(0,r));
  while(!q.empty())
  {
    P nowp=q.top();
    q.pop();
    int v=nowp.second;
    if(ans[v]<nowp.first)continue;
    rep(i,g[v].size())
    {
      P nowe=g[v][i];
      if(ans[nowe.first]>ans[v]+nowe.second)
      {
        ans[nowe.first]=ans[v]+nowe.second;
        q.push(make_pair(ans[nowe.first],nowe.first));
      }
    }
  }
  rep(i,nv)
  {
    if(ans[i]==INF)cout<<"INF"<<endl;
    else cout<<ans[i]<<endl;
  }
}




Measured memory_bytes: 18668
#include<iostream>
#include<cstdio>
#include<cmath>
 
using namespace std;
 
int main()
{
    int n,a=0,b=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int x;cin>>x;
        a+=x;b+=x*x;
    }
    int k=floor(a*1.0/n+0.5);
    cout<<n*k*k-2*a*k+b;
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace abc153
{
    class Program
    {
        static void Main(string[] args)
        {
            if (File.Exists("input.txt"))
            {
                Console.SetIn(new StreamReader("input.txt"));
            }
			solve_abc153C();
        }
        public static void solve_abc153C()
        {
            int[] nk = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int n = nk[0];
            int k = nk[1];
            int[] h = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

            Array.Sort(h, (a, b) => b.CompareTo(a));

            long cnt = 0;
            for (int i = k; i < n; i++)
            {
                cnt += h[i];
            }
            Console.WriteLine(cnt);
        }

        public static void solve_abc153B()
        {
            int[] hn = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int h = hn[0];
            int n = hn[1];
            int[] a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            for (int i = 0; i < n; i++)
            {
                h -= a[i];
            }
            if (h <= 0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }

        public static void solve_abc153A()
        {
            int[] ha =  Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            Console.WriteLine((ha[0] + ha[1] - 1) / ha[1]);
        }
    }
}


Measured memory_bytes: 30940
#include<stdio.h>
int main(){
  char s[5];
  int i,j;
  scanf("%s",s);
  for(i=0;i<8;i++)if((s[0]-'0')+(s[1]-'0')*(1-2*((i&1)==0))+(s[2]-'0')*(1-2*((i&2)==0))+(s[3]-'0')*(1-2*((i&4)==0))==7){
    printf("%c",s[0]);
    for(j=0;j<3;j++)printf("%c%c",i&1<<j?'+':'-',s[j+1]);
    printf("=7");
    return 0;
  }
}


Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
LL A[1001];
LL B[1001]; 
int main(){
   cin>>N;
   LL ans=0;
   REP(i,N){
       cin>>A[i]>>B[i];
       ans+=(B[i]-A[i]+1);
   }
   cout<<ans<<endl;
   return(0);
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
using namespace std;
signed main() {
	long double t, x;
	cin >> t >> x;
	cout << t * t / (x*t) << endl;
	getchar(); getchar(); return 0;
}

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

int main(){
   ll n,t[10000],a[10000];
   cin>>n;
   for(int i=0;i<n;i++) cin>>t[i]>>a[i];
   ll c,p=t[0],q=a[0]; 
   if(n==1){ cout<<p+q<<endl; return 0;}
   for(int i=1;i<n;i++){
       c=max((p+t[i]-1)/t[i],(q+a[i]-1)/a[i]);
       p=t[i]*c; q=a[i]*c;
   }
   cout<<p+q<<endl; 
   return 0;
}

Measured memory_bytes: 256
import sys
#input = sys.stdin.buffer.readline
from collections import Counter

def main():
    S = input()
    P = 2019

    ans,base = 0,1
    MOD_list = [0]

    for st in S[::-1]:
        num = int(st)
        MOD = (MOD_list[-1]+num*base)%P
        MOD_list.append(MOD)
        base *= 10
        base %= P

    c = Counter(MOD_list)
    for v in c.values():
        ans += (v*(v-1))//2
        
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 16816
#include<iostream>
#include<vector>

using namespace std;

int main(){
    vector<int> h(5,0),frg(5,0);

    while(1){
        cin >> h[0];
        if(h[0]==0)break;
        for(int i=1;i<5;i++)cin >> h[i];
        for(int i=0;i<5;i++)frg[h[i]-1]++;

        if(frg[0]*frg[1]*frg[2]!=0 || frg[0]==5 || frg[1]==5 || frg[2]==5){
            for(int i=0;i<5;i++)cout << "3" << endl;
        }else if(frg[0]>0){
            if(frg[1]>0){
                for(int i=0;i<5;i++){
                    if(h[i]==1)cout << "1" << endl;
                    else cout << "2" << endl;
                }
            }else{
                for(int i=0;i<5;i++){
                    if(h[i]==3)cout << "1" <<endl;
                    else cout << "2" << endl;
                }
            }
        }else{
            for(int i=0;i<5;i++){
                if(h[i]==2)cout << "1" << endl;
                else cout << "2" << endl;
            }
        }

        for(int i=0;i<5;i++){
            frg[i]=0;
            h[i]=0;
        }
    }


    return 0;


}

Measured memory_bytes: 2980
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"	
	typedef long long LL;
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define mod2 998244353
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define sz(v) ((ll)(v).size())
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define pb push_back
	#define f first
	#define s second
	#define dbg(a) cout<<#a<<" --> "<<(a)<<"\n";
	#define forn(i,n) for (ll i=0; i<(n); ++i)
	#define fornd(i,n) for (ll i=(n)-1; i>=0; --i)	
	#define forab(i,a,b) for (ll i=(a); i<=(b); ++i)
	#define read(a) ll a; cin >> a;
	#define reads(s) string s; cin >> s;
	#define readb(a, b) ll a, b; cin >> a >> b;
	#define readc(a, b, c) ll a, b, c; cin >> a >> b >> c;
	#define readarr(a, n) int a[(n) + 1] = {}; forab(i, 0, (n-1)) {cin >> a[i];}
	#define readmat(a, n, m) int a[n + 1][m + 1] = {}; forab(i, 1, n) {forab(j, 1, m) cin >> a[i][j];}
	#define readv(A,n) vll A(n,0); forn(i,n) cin>>A[i]; 
	#define print(a) cout << a << endl;
	#define printarr(a, n) forab (i, 1, n) cout << a[i] << " "; cout << endl;
	#define printv(v) for (int i: v) cout << i << " "; cout << endl;
	#define printmat(a, n, m) forab(i, 1, n) {forab (j, 1, m) cout << a[i][j] << " "; cout << endl;}
	 
	#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
	using namespace std;
	bool isPowerOfTwo(int x) {
    return x && (!(x & (x - 1)));
	}
	int takemod(int x) {
    return (x % mod + mod) % mod;
	}
 
	int fpow(int base, int power, int MOD) {
    int result = 1;
    base = base % MOD;
    while (power) {
        if (power & 1)
            result = (result * base) % MOD;
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result;
	}
 
	int modinv(int x) {return fpow(x, mod - 2, mod);}
	void solve()
	{
		ll n,d;
		cin>>n>>d;
		ll er=0;
		ll ans=0;
		forn(i,n)
		{
			ll x,y;
			cin>>x>>y;
			er=x*x+y*y-d*d;
			if(er<=0)
			{
				ans++;
			}
		}
		cout<<ans<<endl;
	}
	int main()
	{	
		#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		#endif
		fast_io;
		int T=1;
		//cin>>T;
		// cin.ignore(); must be there when using getline(cin, s)
		while(T--)
		{
			solve();
		}
		return 0;
	}

	
	

Measured memory_bytes: 3652
N, K = gets.split.map(&:to_i)
s = gets.chomp

a = []

prec = nil
idx = -1
s.each_char do |c|
    if prec == c
        a[idx] += (c == "R" ? 1 : (-1))
    else
        a.push(c == "R" ? 1 : (-1))
        idx += 1
    end
    prec = c
end

K.times do
    if a.length == 1
        break
    elsif a.length == 2
        aa = a.pop
        a[0] -= aa
        break
    else
        a1 = a.delete_at(-2)
        a2 = a.delete_at(-2)
        a[-1] += (a2 - a1)
    end
end

ans = 0
a.each do |x|
    ans += x.abs() - 1
end

puts ans





Measured memory_bytes: 4476
#include <stdio.h>
#include <stdlib.h>

int main(){
	char *str1, *str2, *str3;
	str1 = (char*)malloc(sizeof(char)*11);
	str2 = (char*)malloc(sizeof(char)*1000001);
	str3 = (char*)malloc(sizeof(char)*11);
	scanf("%s %s %s", str1, str2, str3);
	printf("A%cC", str2[0]);
	free(str1);
	free(str2);
	free(str3);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std ;
const int N = 1e9+7 ;
int main(){
int n ;
scanf("%d",&n) ;
string s ; 
cin >> s ;  
int x[26] ;
for(int i=0;i<26;i++)
    x[i] = 1 ;
for(auto i:s){
	x[i-'a']++ ;
}
long long ans = 1 ;
for(auto i:x){
	ans *= i ;
  	ans %= N ;
}
cout << (ans-1+N)%N << '\n' ;  
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

#include <set>
#include <map>
#include <iomanip>

using namespace std;

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

struct q
{
	int last;
	ll b, c;
};

bool comp(const q l, const q r)
{
	return l.c < r.c;
}

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

	vector<ll> card(n);
	vector<q> qs(m);
	rep(i, n)
	{
		cin >> card[i];
	}

	rep(i, m)
	{
		cin >> qs[i].b >> qs[i].c;
		qs[i].last = -1;
	}

	sort(all(card));
	sort(all(qs), comp);
	reverse(all(qs));

	int idx = 0;
	for (int i = n - 1; i >= 0; i--)
	{
		if (qs[idx].c > card[i])
		{
			qs[idx].last = i;
			i++;
			idx++;
		}

		if (idx >= qs.size())
		{
			break;
		}
	}

	ll sum = 0;
	idx = 0;
	rep(i, n)
	{
		if (idx >= qs.size())
		{
			sum += card[i];
			continue;
		}

		if (i + qs[idx].b <= qs[idx].last)
		{
			sum += qs[idx].b * qs[idx].c;
			i += qs[idx].b - 1;
			idx++;
		}
		else if (i <= qs[idx].last)
		{
			ll cnt = qs[idx].last - i + 1;

			sum += cnt * qs[idx].c;
			i += cnt - 1;
			idx++;
		}
		else
		{
			sum += card[i];
		}
	}

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

Measured memory_bytes: 3456
#include<iostream>
using namespace std;int X, Y, A, i, j;
main(){while (true){cin>>A;if(A==0){break;}
for(i=A;i>=2;i--){for(j=2;j*j<=i;j++){if(i%j==0){goto E;}}X=i;goto F;E:;}
F:;for(i=A;i<(1<<27);i++){for(j=2;j*j<=i;j++){if(i%j==0){goto G;}}Y=i;goto H;G:;}
H:; cout<<Y-X<<endl;}}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
bool dp[100010];

int main()
{
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }
  for (int i = 1; i <= K; i++)
  {
    for (int j = 0; j < N; j++)
    {
      if (i - A.at(j) >= 0)
      {
        dp[i] |= !dp[i - A.at(j)];
      }
    }
  }
  cout << (dp[K] ? "First" : "Second") << endl;
}


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

#define ll long long

struct Line {
    ll k, m;
    mutable ll p;
    bool operator<(const Line& o) const {
        return k < o.k;
    }
    bool operator<(const ll&x) const {
        return p < x;
    }
};

struct LineContainer : multiset<Line, less<>> {
    // (for doubles, use inf = 1/.0, div(a,b) = a/b)
    const ll inf = numeric_limits<ll>::max();
    ll div(ll a, ll b) { // floored division
        return a / b - ((a ^ b) < 0 && a % b);
    }
    bool isect(iterator x, iterator y) {
        if (y == end()) { x->p = inf; return false; }
        if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
        else x->p = div(y->m - x->m, x->k - y->k);
        return x->p >= y->p;
    }
    void add(ll k, ll m) {
        auto z = insert({k, m, 0}), y = z++, x = y;
        while (isect(y, z)) z = erase(z);
        if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
        while ((y = x) != begin() && (--x)->p >= y->p)
            isect(x, erase(y));
    }
    ll query(ll x) {
        assert(!empty());
        auto l = *lower_bound(x);
        return l.k * x + l.m;
    }
};


int main(){
    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll c, a[200005] = {};
    int n;
    cin >> n >> c;
    for (int i = 0; i < n; i++) cin >> a[i];
    LineContainer lc;
    lc.add(0, 0);
    ll f = 0;
    for(int i = 0; i < n; i++){
        f = lc.query(a[i]);
        f -= a[i] * a[i] + c;
        if (!i) f = 0;
        lc.add(a[i] + a[i], -a[i] * a[i] + f);
    }
    cout << -f;
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||debg||local||debug
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T>vector<T> _vec(size_t a,T v){return vector<T>(a,v);}
template<class T, class... Ts>auto _vec(size_t a, Ts... ts){return vector<decltype(_vec<T>(ts...))>(a, _vec<T>(ts...));}

int main(){

  vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin>>k;
  k--;
  cout<<a[k]<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  if (n % 2 == 0)
    cout << n * n / 4 << endl;
  else
    cout << (n / 2) * (n / 2 + 1) << endl;
}

Measured memory_bytes: 3580
#include <stdio.h>

int main(void){
    int n,i,num,s[13]={0},h[13]={0},c[13]={0},d[13]={0};
    char ch;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("\n%c %d",&ch,&num);
        switch(ch){
            case 'S':s[num-1]++;break;
            case 'H':h[num-1]++;break;
            case 'C':c[num-1]++;break;
            case 'D':d[num-1]++;break;
        }
    }
        for(i=0;i<13;i++)
            if(s[i] != 1)
                printf("S %d\n",i+1);
        for(i=0;i<13;i++)
            if(h[i] != 1)
                printf("H %d\n",i+1);
        for(i=0;i<13;i++)
            if(c[i] != 1)
                printf("C %d\n",i+1);
        for(i=0;i<13;i++)
            if(d[i] != 1)
                printf("D %d\n",i+1);
        return 0;
}

Measured memory_bytes: 596
x,y = [int(i) for i in input().split()]

groupa = [1,3,5,7,8,10,12]
groupb = [4,6,9,11]

if (x in groupa) and (y in groupa):
  print("Yes")
elif x in groupb and y in groupb:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> p(n+2);
  p[0] = 0;
  p[n+1] = 0;
  for(int i = 0;i < n;i++) cin >> p[i+1];
  int sum = 0;
  for(int i = 1;i <= n+1;i++){
    sum += abs(p[i]-p[i-1]);
  }
  for(int i = 1;i <= n;i++){
    int answer;
    answer = sum;
    answer -= abs(p[i]-p[i-1]) + abs(p[i+1]-p[i]);
    answer += abs(p[i+1]-p[i-1]);
    cout << answer << endl;
  }
}

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

int main() {
  string s;
  cin >> s;
  int a = s.find("A");
  int z = s.rfind("Z"); 
  cout << z-a+1 <<endl;
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  int d[101]={};
  int i,j,l,m;
  int a,b;
  for(i=0;i<n;i++){
    cin >> a >> b;
    d[a-1]=b;
  }
  int dp[101][4][4]={{{}}};
  if(d[0]!=0){
    dp[0][0][d[0]]=1;
  }else{
    dp[0][0][1]=1;
    dp[0][0][2]=1;
    dp[0][0][3]=1;
  }
  for(i=1;i<n;i++){
    for(j=0;j<4;j++){
      for(l=1;l<4;l++){
        if(d[i]!=0){
          if(!(j==l&&l==d[i]))
          dp[i][l][d[i]]+=dp[i-1][j][l]%10000;
        }else{
          for(m=1;m<4;m++){
            if(j==l&&l==m) continue;
            
            dp[i][l][m]+=dp[i-1][j][l]%10000;
          }
        }
      }
    }
  }
  int o=0;
  for(j=0;j<4;j++){
    for(l=0;l<4;l++){
      o+=dp[n-1][j][l];
    }
  }
  cout << o%10000 << endl;
  return 0;
}

Measured memory_bytes: 1168
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
    long long int N,K;
    cin>>N>>K;
    vector<long long int>v;
    long long int tree;
    for(int i=0;i<N;i++){
        cin>>tree;
        v.push_back(tree);
    }
    sort(v.begin(),v.end());
    long long int min=10*10*10*10*10*10*10*10*10;
    for(int i=0; i<=N-K; i++){
        if(min>v[i+K-1]-v[i]){
            min = v[i+K-1]-v[i];
            //cout << v[i+K-1] <<" "<<v[i]<<endl;
        }
    }
    cout << min << endl;
    return 0;
}


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

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VC> VVC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

//memo
// setprecision()

LL Gcd(LL a, LL b) {
  if (a < b) {
    return Gcd(b,a);
  }
  if (b == 0) {
    return a;
  }
  else {
    return Gcd(b,a%b);
  }
}

LL Lcm(LL a, LL b) {
  LL abd = Gcd(a,b);
  LL x = a / abd, y = b / abd;
  
  return x*y*abd;
}


LL RepSqu(LL N, LL P, LL M) {
  if(P == 0) {
    return 1;
  }
  if(P%2 == 0) {
    LL t = RepSqu(N, P/2, M);
    return t*t % M;
  }
  return (N * RepSqu(N, P-1, M)) % M;
}


int main() {
  
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string S;
  cin >> S;
  
  if(S.at(0) == S.at(1) && S.at(1) == S.at(2)){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
//#define _USE_MATH_DEFINES
#include <iostream>
//#include <stdio.h>
//#include <iomanip>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <functional>
//#include <cmath>
//#include <time.h>

using namespace std;

#define N_MAX 1000000

int kouho[N_MAX / 2];

int main(){

	//clock_t c1,c2;
	//c1 = clock();

	vector <int> sosuu;
	int check;
	//int kouho[N_MAX / 2];
	int n;
	int cnt;


	for (int i = 0; i < N_MAX / 2; i++){
		kouho[i] = i * 2 + 1;
	}
	kouho[0] = 0;

	sosuu.push_back(2);
	check = 3;

	while (check < 1000){
		sosuu.push_back(check);
		for (int i = check; i < N_MAX; i += (check*2)){
			kouho[(i - 1) / 2] = 0;
		}

		for (int i = check/2; i < N_MAX / 2; i++){
			if (kouho[i] != 0){
				check = kouho[i];
				break;
			}
		}
	}


	
	while (cin >> n){
		cnt = 0;
		if (n <= 1000){
			for (int i = 0; i < sosuu.size(); i++){
				if (sosuu[i] <= n)cnt++;
				else break;
			}
		}
		else{
			cnt += sosuu.size();
			for (int i = 0; i < N_MAX /2; i++){
				if (kouho[i] > n){
					break;
				}
				else{
					if (kouho[i] != 0)cnt++;
				}
			}
		}
		cout << cnt << endl;
	}

	//c2 = clock();

	//cout << "time = " << (double)(c2 - c1) / CLOCKS_PER_SEC << "[sec]" << endl;


	return 0;
}

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

int64_t solve();

int main()
{
	printf("%lld\n", solve());

	return 0;
}

int64_t solve()
{
	int N;
	scanf("%d", &N);
	std::vector<int64_t> A(N), B(N);
	for (auto& e: A) scanf("%lld", &e);
	for (auto& e: B) scanf("%lld", &e);
	std::queue<int> que;
	for (int i{}; i < N; i++)
		if (A[i] > B[i])
			return -1;
	for (int i{}; i < N; i++)
		if (B[i] > B[(i + N - 1) % N] + B[(i + 1) % N] && B[i] > A[i])
			que.push(i);
	int64_t ans{};
	while (!que.empty())
	{
		int now{que.front()};
		que.pop();
		int next{(now + 1) % N}, prev{(now + N - 1) % N};
		int64_t quo{(B[prev] + B[next])}, rest{B[now] % quo};
		if (A[now] > rest)
		{
			if (A[now] % quo != rest) return -1;
			ans += (B[now] - A[now]) / quo;
			B[now] = A[now];
		}
		else
		{
			ans += B[now] / quo;
			B[now] = rest;
		}

		if (B[next] > B[now] + B[(next + 1) % N] && B[next] > A[next])
			que.push(next);
		if (B[prev] > B[now] + B[(prev + N - 1) % N] && B[prev] > A[prev])
			que.push(prev);
	}
	for (int i{}; i < N; i++)
		if (A[i] != B[i])
			return -1;
	return ans;
}

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

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};

int main(void)
{
	int H, W;
	cin >> H >> W;
	char c[H][W];
	int map[H][W];

	int count = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> c[i][j];
			map[i][j] = -1;
			if (c[i][j] == '#')
				count++;
		}
	}

	queue<tuple<int, int, int>> q;
	map[0][0] = 0;
	q.push(make_tuple(0, 0, 0));
	while (q.size() != 0) {
		auto v = q.front();
		q.pop();

		int x = get<0>(v);
		int y = get<1>(v);
		int val = get<2>(v);
		for (int i = 0; i < 4; i++) {
			int nx = x + dx[i];
			int ny = y + dy[i];

			if (nx >= 0 && nx < W && ny >= 0 && ny < H) {
				if (c[ny][nx] == '.' && map[ny][nx] == -1) {
					map[ny][nx] = val+1;
					q.push(make_tuple(nx, ny, val+1));
				}
				if (ny == H-1 && nx == W-1)
					goto fin;
			}
		}
	}
fin:

	if (map[H-1][W-1] == -1)
		cout << "-1" << endl;
	else
		cout << H*W-(map[H-1][W-1]+1)-count << endl;

	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits.h>

using namespace std;

vector< vector< pair<int, long long> > > nodes;
vector< pair<int, long long> > v;
int N, M;
vector<long long> m;

int is_visited(int n)
{
    for(int i = 0; i < v.size(); i++) {
        if(n == v[i].first) return i;
    }
    return -1;
}

vector<int> r;
bool reach(int n) {
    r.push_back(n);
    if(n == N-1) {
        r.pop_back();
        return true;
    }
    for(int i = 0; i < nodes[n].size(); i++) {
        bool flag = false;
        for(int j = 0; j < r.size(); j++) {
            if(r[j] == nodes[n][i].first) flag = true;
        }
        if(flag) continue;
        if(reach(nodes[n][i].first)) {
            r.pop_back();
            return true;
        }
    }
    r.pop_back();
    return false;
}

void dfs(int n)
{
    m[n] = v.back().second;
    for(int i = 0; i < nodes[n].size(); i++) {
        if(m[nodes[n][i].first] >= v.back().second + nodes[n][i].second) continue;
        int t;
        if((t = is_visited(nodes[n][i].first)) != -1) {
            if(v[t].second < v.back().second + nodes[n][i].second) {
                if(reach(n)) {
                    cout << "inf" << endl;
                    exit(0);
                }
            }
        } else {
            v.push_back(make_pair(nodes[n][i].first, v.back().second + nodes[n][i].second));
            dfs(nodes[n][i].first);
            v.pop_back();
        }
    }
}

int main()
{
    cin >> N >> M;
    nodes.resize(N);
    m.resize(N);
    for(int i = 0; i < N; i++) m[i] = LONG_LONG_MIN;
    for(int i = 0; i < M; i++) {
        int a, b;
        long long c;
        cin >> a >> b >> c;
        nodes[a-1].push_back(make_pair(b-1, c));
    }
    v.push_back(make_pair(0, 0));
    dfs(0);
    cout << m.back() << endl;
    return 0;
}

Measured memory_bytes: 384
n = int(input())
a = list(map(int, input().split()))

sums = 0
ans = 0
# プラスがはじめ
for itr, val in enumerate(a):
  sums += val
  if itr % 2 == 0:
    if sums <= 0:
      ans += 1 - sums
      sums = 1
  else:
    if sums >= 0:
      ans += sums + 1
      sums = - 1
gans = ans

sums = 0
ans = 0
# マイナスがはじめ
for itr, val in enumerate(a):
  sums += val
  if itr % 2 != 0:
    if sums <= 0:
      ans += 1 - sums
      sums = 1
  else:
    if sums >= 0:
      ans += sums + 1
      sums = - 1
kans = ans
print(min(gans, kans))

Measured memory_bytes: 63984
#include <bits/stdc++.h> 
using namespace std;
int main() {
    int n;
    scanf("%d", &n);
    map<pair<int,int>, int> cnt;
    for(int rep = 0; rep < n; ++rep) {
        double x;
        scanf("%lf", &x);
        long long i = llround(x * 1e9);
        int two = 0, five = 0;
        while(i % 2 == 0) {
            two++;
            i /= 2;
        }
        while(i % 5 == 0) {
            five++;
            i /= 5;
        }
        ++cnt[{two,five}];
    }
    long long answer = 0;
    for(auto p1 : cnt) {
        for(auto p2 : cnt) {
            if(p1.first.first+p2.first.first >= 18 && p1.first.second+p2.first.second >= 18) {
                if(p1 < p2) {
                    answer += (long long) p1.second * p2.second;
                }
                else if(p1 == p2) {
                    answer += (long long) p1.second * (p1.second - 1) / 2;
                }
            }
        }
    }
    printf("%lld\n", answer);
}

Measured memory_bytes: 3804
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
PII d[2][2];
int a[SIZE];
void update(PII e[],PII x){
    if(x.F>e[0].F){
        e[1]=e[0];
        e[0]=x;
    }
    else if(x.F>e[1].F){
        e[1]=x;
    }
}
int main(){
    int n;
    R(n);
    map<int,int>AA[2];
    REP(i,n){
        R(a[i]);
        AA[i&1][a[i]]++;
    }
    REP(i,2){
        for(auto x:AA[i]){
            update(d[i],MP(x.S,x.F));
        }
    }
    if(d[0][0].S!=d[1][0].S){
        W(n-d[0][0].F-d[1][0].F);
    }
    else{
        W(n-max(d[0][0].F+d[1][1].F,d[0][1].F+d[1][0].F));
    }
    return 0;
}


Measured memory_bytes: 5376
s = int(input())

ans = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(ans[s-1])


Measured memory_bytes: 2940
#include<iostream>

using namespace std;

int main(){
  int a,b;

  cin >> a >> b;

  if(a<b){
    cout << "a < b" << endl;
  }
  else if(a>b){
    cout << "a > b" << endl;
  }
  else {
   cout << "a == b" << endl;
  }
}

Measured memory_bytes: 1156
import java.io.*;
import java.util.*;

public class Main {

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public float nextFloat() {
            return Float.parseFloat(next());
        }

    }

    static InputReader r = new InputReader(System.in);
    static PrintWriter pw = new PrintWriter(System.out);

    /** CHECKLIST:
     * LIMITS (DOES BRUTE FORCE WORK?)
     * CHECK ALL PARAMETERS
     * INT VS LONG
     */
    public static void main(String[] args) {
        int n = r.nextInt();
        int[][] points = new int[n][3];
        int[][] dp = new int[n][3];
        for(int i = 0; i < n; i++){
            points[i][0] = r.nextInt();
            points[i][1] = r.nextInt();
            points[i][2] = r.nextInt();
        }
        dp[0][0] = points[0][0];
        dp[0][1] = points[0][1];
        dp[0][2] = points[0][2];
        for(int i = 1; i < n; i++){
            dp[i][0] = points[i][0] + Math.max(dp[i-1][1], dp[i-1][2]);
            dp[i][1] = points[i][1] + Math.max(dp[i-1][0], dp[i-1][2]);
            dp[i][2] = points[i][2] + Math.max(dp[i-1][0], dp[i-1][1]);
        }
        pw.println(Math.max(Math.max(dp[n-1][0], dp[n-1][1]), dp[n-1][2]));
        pw.close();
    }
}

/**
                _        _                 _                                                
               | |      | |               | |                                               
   ___ ___   __| | ___  | |__  _   _    __| | __ _ _ __ _ __ ___ _ __     _   _  __ _  ___  
  / __/ _ \ / _` |/ _ \ | '_ \| | | |  / _` |/ _` | '__| '__/ _ \ '_ \   | | | |/ _` |/ _ \ 
 | (_| (_) | (_| |  __/ | |_) | |_| | | (_| | (_| | |  | | |  __/ | | |  | |_| | (_| | (_) |
  \___\___/ \__,_|\___| |_.__/ \__, |  \__,_|\__,_|_|  |_|  \___|_| |_|   \__, |\__,_|\___/ 
                                __/ |                               ______ __/ |            
                               |___/                               |______|___/             
 */

Measured memory_bytes: 53104