akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
 
#ifndef ONLINE_JUDGE
	#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif
using namespace std;
 
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define PER(i, N) for(int (i) = (N)-1; (i) >= 0; (i)--)
#define REP(i, N) for(int (i) = 0; (i) < (int)(N); (i)++)
#define rep(i, j, N) for(int (i) = j; (i) < (int)(N); (i)++)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
 
typedef pair<int, int> pii;
typedef vector<int> vi;
 
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.x >> p.y; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.x << ' ' << p.y; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }
const int MOD = 1000000007;

vector< pair<int, pair<int,int>>> nxt[55];
ll bestTime[55][5555];
void solve(istream& cin, ostream& cout) {
	int n,m,S;
	cin >>n>>m>>S;
	S = min(S, 5111);
	vector<int> C(n), D(n);
	REP(i, m) {
		int u,v,a,b;
		cin >>u>>v>>a>>b;
		u--;v--;
		nxt[u].pb({v, {a,b}});
		nxt[v].pb({u, {a,b}});
	}
	REP(i, n) {
		int cc,dd;
		cin>>cc>>dd;
		C[i]=cc;
		D[i]=dd;
	}
	minheap<pair<ll, pair<int, int>>> Q;
	Q.push({0, {0, S}});
	REP(i, n) {
		REP(j, 5544) bestTime[i][j] = 1LL<<62;
	}
	bestTime[0][S] = 0;
	while(!Q.empty()) {
		auto curr = Q.top();
		Q.pop();
		ll cTime = curr.first;
		int u = curr.second.first;
		int coins = curr.second.second;
		if(cTime != bestTime[u][coins])
			continue;
		for(auto& E : nxt[u]) {
			int v = E.first;
			int dist = E.second.second;
			int cost = E.second.first;
			if(coins >= cost && cTime+dist < bestTime[v][coins-cost]) {
				bestTime[v][coins-cost] = cTime+dist;
				Q.push({cTime+dist, {v, coins-cost}});
			}
		}
		int ncoins = min(5111, coins+C[u]);
		if(bestTime[u][ncoins] > cTime+D[u]) {
			bestTime[u][ncoins] = cTime+D[u];
			Q.push({cTime+D[u], {u, ncoins}});
		}
	}
	REP(i, n-1) {
		ll ans = 1LL<<62;
		REP(j, 5544) ans = min(ans, bestTime[i+1][j]);
		cout <<ans<<endl;
	}
}


int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	solve(cin, cout);
	/*
	{
		istringstream instr("2\n2\n14");
		solve(instr, cout);
	}
 */
	return 0;
}


Measured memory_bytes: 9228
#include<stdio.h>
#include<stdlib.h>
int main(){

    int A,B,N,c;

    scanf("%d%d%d",&N,&A,&B);

    c=N*A;

    if(c<=B){
        printf("%d",c);
    }else{
        printf("%d",B);
    }

    return 0;

}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<=(b);++i)
#define rv(i,a,b) for(int i=(a);i>=(b);--i)
#define inf 0x3f3f3f3f
#define SZ(x) ((int)x.size())
using namespace std;
const int M = 220000;
typedef long long ll;
int n,m,k,t;
struct node{
    int a,b;
}e[M];
ll dp[60]={0};
int main(){
    cin>>n>>t;
    fo(i,1,n) cin>>e[i].a>>e[i].b;
    sort(e+1,e+1+n,
        [](const node & u,const node & v)->bool{
        return 1ll*u.a*(v.b+1)>1ll*v.a*(u.b+1);
    });
    memset(dp,inf,sizeof(dp));
    k=40;
    dp[0]=0;
    vector<ll> zero;
    fo(i,1,n){
        if(!e[i].a) {
            zero.push_back(e[i].b+1);
            continue;
        }
        rv(j,k,0){
            if(dp[j]>t) continue;
            ll ti=dp[j]+1;
            ti=e[i].a*ti+e[i].b+ti;
            dp[j+1]=min(dp[j+1],ti);
        }
    }
    int ans=0;
    if(SZ(zero)){
        sort(zero.begin(),zero.end());
        fo(i,1,SZ(zero)-1) zero[i]+=zero[i-1];
        fo(i,0,k){
            if(dp[i]>t) break;
            int now=i;
            int it = upper_bound(zero.begin(), zero.end(), t-dp[i]) - zero.begin();
            if(it==SZ(zero)) --it;
            if(zero[it]<=t-dp[i]) now+=it+1;
            else now+=it;
            ans = max(ans, now);
        }
    }
    else
    {
        rv(i,k,1)
            if(dp[i]<=t){
                ans=i;
                break;
            }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3956
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
	int N,i;
	cin >> N;
	long long A[N],B[N],minB=999999999,M=0,f=0;
	for (i=0;i<N;++i) {
		cin >> A[i] >> B[i];
		if (A[i]>B[i]) {
			if (B[i]<minB) {
				minB=B[i];
			}
		}
		M+=A[i];
		if (A[i]!=B[i]) f=1;
	}
	if (f==0) {
		cout << 0 << endl;
		return 0;
	}
	cout << M-minB << endl;
	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
int main(void){
	int a,b;
	scanf("%d %d",&a,&b);
		if(a<b){printf("a < b\n");
		}else if(a>b){printf("a > b\n");
		}else{printf("a == b\n");
		}
	return 0;
}



Measured memory_bytes: 2100
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cassert>
#include <utility>
#include <numeric>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#define rep(i,n) for (int i=0; i<(n); ++i)

using namespace std;
using ll = long long;

int main (){
    ll H;
    cin >> H;
    ll c=1;
    ll ans=0;
    
    while(true){
        if (H==1){
            ans += c;
            break;
        }
        else{
            ans += c;
            c *=2;
            if(H%2==0){
                H = H/2;
            }
            else{
                H = (H) /2;
            }

        }
    }

    cout << ans;


    

    
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){
  string s;
  std::cin >> s;
  char nowc=s[0];
  int now=0;
  std::vector<int> v(1,0);
  int odd=0;
  int even=1;
  int i;
  for (i = 1; i < s.size(); i++) {
    v.push_back(0);
    if(s[i]==nowc){
      if((i-now)%2==0)even++;
      else odd++;
    }
    else{
      if(nowc=='R'){
        v[i]+=odd;
        v[i-1]+=even;

      }
      if(nowc=='L' ){
        v[now-1]+=odd;
        v[now]+=even;
      }
      even=1;
      odd=0;
      nowc=s[i];
      now=i;
    }
  }


  if(nowc=='R'){
    v[i]+=odd;
    v[i-1]+=even;

  }
  if(nowc=='L' ){
    v[now-1]+=odd;
    v[now]+=even;
  }

  for (int i = 0; i < s.size(); i++) {
    std::cout <<v[i] << '\n';
  }

  return 0;
}


Measured memory_bytes: 1144
#! /usr/bin/env python3

def primefactor(n):
    r = []
    a, b = 0, 2
    while b * b <= n:
        if n % b == 0:
            n //= b
            r += [b]
        else:
            b += 1 + a
            a = 1
    if n > 1 : r += [n]
    return r

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

p = set(primefactor(min(A)))

for i in A:
    p = set([x for x in p if i % x == 0])
    if len(p) == 0 : break

if (K < max(A) and (len(p) == 0 or all(K % x == 0 for x in p))) or K in A:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

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

int ans;
/*
int dp(int index,int arr[],int deja[])
{
    if(index>=n-1)
        return 0;

        if(deja[index])
            return deja[index];

        int choice1=INT_MAX,choice2=INT_MAX;
        if(index<n-1)
     choice1=dp(index+1,arr,deja)+abs(arr[index+1]-arr[index]);
     if(index<n-2)
     choice2= dp(index+2,arr,deja)+abs(arr[index+2]-arr[index]);
    //cout<<choice1<<" "<<choice2<<endl;
    deja[index] = min(choice1,choice2);
     return deja[index];

}*/
int main()
{

int n,k;
cin>>n>>k;

int arr[n],dp[n+1];
for(int index=0;index<n;index++)
{
    cin>>arr[index];
    dp[index+1]=INT_MAX;
}
dp[0]=0;
for(int i=1;i<=n;i++)
{

for(int j=1;j<=k;j++)
if(i-j>=0)
        dp[i]=min(dp[i-j]+abs(arr[i-j]-arr[i]),dp[i]);

       // cout<<dp[i]<<endl;
}
cout<<dp[n-1]<<endl;

    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main()
{
		// input value
		int a,b;
		// operator
		char op;
		// answear
		int ans;
		// end check
		int check = 1;


		while(check){
				scanf("%d %c %d", &a, &op ,&b);
				switch(op){

						case '+':
							ans = a + b;
							printf("%d\n",ans);
							break;

						case '-':
							ans = a - b;
							printf("%d\n",ans);
							break;

						case '*':
							ans = a * b;
							printf("%d\n",ans);
							break;

						case '/':
							ans = a / b;
							printf("%d\n",ans);
							break;

						case '?':
							check = 0;

						break;

						default:
							break;
				}

// output 	


		}

		return 0;


}


Measured memory_bytes: 2048
n=int(input())
p=list(map(float,input().split()))
dp=[[0 for _ in range(n+1)]for _ in range(n)]
dp[0][0]=1-p[0]
dp[0][1]=p[0]
for i in range(1,n):
  for j in range(i+2):
    dp[i][j]=dp[i-1][j-1]*p[i]+dp[i-1][j]*(1-p[i])
print(sum(dp[-1][(n+1)//2:]))

Measured memory_bytes: 223876
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC128
{
    class B
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] s = new string[n];
            string[] s2 = new string[n];
            int[] index = new int[n];
            int[] p = new int[n];
            int count = 0;
            for (int i = 0; i < n; i++)
            {
                string[] a = Console.ReadLine().Split().ToArray();
                s[i] = a[0];p[i] = int.Parse(a[1]);
                index[i] = i;
                bool flag = true;
                for (int k = 0; k < i; k++)
                {
                    if (s[k] == a[0]) { flag = false; }
                }
                if (flag) { count++; }
            }
            Array.Copy(s, s2, n);
            Array.Sort(s, p);
            Array.Sort(s2,index);
            int[] answer = new int[n];
            List<int> list1 = new List<int>();list1.Add(0);
            List<int> list2 = new List<int>();
            int j = 0;
            for (int i = 0; i < n-1; i++)
            {
                if (s[i + 1] != s[j]) { list1.Add(i+1);list2.Add(i); j = i + 1; }
            }
            list2.Add(n - 1);
            for (int i = 0; i < n; i++)
            {
                answer[i] -= p[i];
                for (int k = 0; k < list1.Count; k++)
                {
                    if (s[i] == s[list1[k]]) { answer[i] += k * 200; }
                }
            }
            Array.Sort(answer, index);
            for (int i = 0; i < n; i++)
            {
                Console.WriteLine(index[i]+1);
            }
        }
    }
}


Measured memory_bytes: 13536
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()
const long long INF = 1e15;
using namespace std;
typedef long long ll;
int main() {
  string s;
  cin >> s;
  REP(i, s.size()) {
    if (i % 2 == 0) {
      if (!(s[i] == 'R' || s[i] == 'U' || s[i] == 'D')) {
        cout << "No" << endl;
        return 0;
      }
    } else {
      if (!(s[i] == 'L' || s[i] == 'U' || s[i] == 'D')) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
def LI(): return list(map(int, input().split()))

n = int(input())
h = LI()
h1 = [abs(h[i+1] - h[i]) for i in range(n-1)]
h2 = [abs(h[i+2] - h[i]) for i in range(n-2)]

dp = [0] * n
dp[0], dp[1] = 0, abs(h[1] - h[0])
for i in range(n-2):
    dp[i+2] = min(
        dp[i+1] + h1[i+1],
        dp[i] + h2[i],
    )

print(dp[-1])


Measured memory_bytes: 19064
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
  return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
  os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}



signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll k;cin>>k;
  ll ans=1,now=7;
  rep(i,0,k+3){
    if(now%k==0){
      cout<<ans<<ENDL;
      return 0;
    }
    ++ans;
    now*=10;
    now+=7;
    now%=k;
  }
  cout<<-1<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  N %= 10;
  if (N == 2 || N == 4 || N == 5 || N == 7 || N == 9) cout << "hon" << endl;
  if (N == 0 || N == 1 || N == 6 || N == 8) cout << "pon" << endl;
  if (N == 3) cout << "bon" << endl;
  return 0;
}


Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner scan = new Scanner(System.in);
		long A = scan.nextInt();
		long B = scan.nextInt();

		long gcd = GCD(A,B);
		long lcm = LCM(A,B,gcd);
		System.out.println(lcm);

	}

public static long GCD(long a, long b) {
	for(long i = a; i > 0; i--) {
		if(a%i == 0 && b%i == 0) {
			return i;
		}
	}
	return 1;
}

public static long LCM(long a, long b, long gcd) {
	return a*b/gcd;
}
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n;
string s[50];

int main() {
	cin >> n;
	inc(i, n) { cin >> s[i]; }
	
	incII(c, 'a', 'z') {
		int mc = 100;
		inc(i, n) {
			int cc = 0;
			inc(j, s[i].size()) {
				if(s[i][j] == c) { cc++; }
			}
			setmin(mc, cc);
		}
		inc(k, mc) { printf("%c", c); }
	}
	
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;cin>>s;
  int n=s.size();
  int ans=(n+1)/2;
  if(n%2==0){
    for(int i=0;i<n/2;i++){
      if(s[n/2-1-i]==s[n/2]&&s[n/2+i]==s[n/2])ans++;
      else{
        cout<<ans<<endl;
        return 0;
      }
    }
    cout<<n<<endl;
    return 0;
  }
  else{
    for(int i=0;i<n/2;i++){
      if(s[n/2-1-i]==s[n/2]&&s[n/2+1+i]==s[n/2])ans++;
      else{
        cout<<ans<<endl;
        return 0;
      }
    }
    cout<<n<<endl;
  }
}
  

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

H, W, K = map(int,input().split())
c = list(list(input()) for _ in range(H))
ans = 0

#bit演算
for i in range(2 ** H):
  for j in range(2 ** W):
    b = 0
    for k in range(H):
      for l in range(W):
        #縦も横も塗らない色が黒のマスを数える
        if i >> k & 1 and j >> l & 1 and c[k][l] == "#": b += 1
    if b == K: ans += 1

print(ans)

Measured memory_bytes: 9228
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

  n = n % 10;

  if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9)
  {
    cout << "hon" << endl;
  }
  else if (n == 0 || n == 1 || n == 6 || n == 8)
  {
    cout << "pon" << endl;
  }
  else
  {
    cout << "bon" << endl;
  }


  return 0;
}

Measured memory_bytes: 3676
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
//const lld MAXN = 1e9;

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

	string sol;
	int cnt=0;

	for(int i = 0; i < s.size(); i++)
	{
		if (s[i] != 'B')
		{
			sol[cnt] = s[i];
			cnt++;
		}else
		{
			cnt--;
			if (cnt < 0)
			{
				cnt = 0;
			}
		}
	}

	for(int i = 0; i < cnt; i++)
	{
		cout << sol[i];
	}
	cout << endl;

	return 0;
}

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

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

    vector<vector<bool>> dp(N + 1, vector<bool>(1 << 24, false));
    dp[0][1] = true;

    int D;
    for (int i = 1; i <= N; i++)
    {
        cin >> D;
        if (D == 0)
        {
            continue;
        }
        for (int j = 0; j < (1 << 24); j++)
        {
            if (dp[i - 1][j])
            {
                if (j != (j | (1 << D)))
                {
                    dp[i][(j | (1 << D))] = true;
                }
                if (j != (j | (1 << (24 - D))))
                {
                    dp[i][(j | (1 << (24 - D)))] = true;
                }
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < (1 << 24); i++)
    {
        if (dp[N][i])
        {
            int s = INT_MAX;
            bitset<24> b(i);
            for (int j = 0; j < 24; j++)
            {
                for (int k = 0; k < j; k++)
                {
                    if (b[j] && b[k])
                    {
                        int d = j - k;
                        s = min(s, min(d, 24 - d));
                    }
                }
            }
            if (s != INT_MAX)
            {
                ans = max(ans, s);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 107008
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main() {
    map<string, int> mp;

    int n;
    cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        mp[s[i]]++;
    }

    int m;
    cin >> m;
    vector<string> t(m);
    for (int j = 0; j < m; j++) {
        cin >> t[j];
        mp[t[j]]--;
    }

    int r = 0;
    for (int i = 0; i < n; i++) {
        r = max(r, mp[s[i]]);
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const ll inf=1e9+7;

int main(){
  string s,t;
  cin>>s>>t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());

  if(s<t) cout<<"Yes";
  else cout<<"No";
  cout<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--)
#define reprev(i,n) reprrev(i,0,n)
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll INF = 1LL<<60;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct UnionFind {
    vector<int> par, rank;

    UnionFind(int n) : par(n , -1), rank(n, 0) { }
    void init(int n) { par.assign(n, -1), rank.assign(n, 0); }

    int root(int x) {
        if (par[x] == -1) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

int main(){
    char b;
  	cin >> b;
  	if(b == 'A') cout << 'T' << endl;
  	if(b == 'T') cout << 'A' << endl;
  	if(b == 'C') cout << 'G' << endl;
  	if(b == 'G') cout << 'C' << endl;
}

Measured memory_bytes: 768
'use strict'
 
function main(s) {
 
  s = s.split('\n');
  const n = Number(s[0].split(' ')[0]);
  const x = Number(s[0].split(' ')[1]);
  const donuts = s.slice(1, -1).map(el => Number(el));
 
  donuts.sort((a, b) => a - b);
  const sum = donuts.reduce((a, b) => a + b);
  const ans = Math.floor((x - sum) / donuts[0]) + donuts.length;
 
  console.log(ans);
}
 
main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define yes(c) cout << ((c) ? "yes" : "no") << endl;
 
#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;

int main() {
  
  int h,n,a;
  cin >> h >> n;
  
  int goukei = 0;
  
  for ( int i = 0; i < n; i++){
    cin >> a;
    goukei += a;
    if ( goukei >= h ){
      cout << "Yes" << endl;
      return 0;
    }
  }
  
  cout << "No" << endl;
  
  return 0;

}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define PII pair<int,int>
#define MP make_pair
#define fir first
#define sec second
#define PB push_back
#define db long double
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
int n;
int lowbit(int x) {
	int y=1;
	while(!(x&y)) y<<=1;
	return y;
}
int main() {
	rd(n);
	int k=1; while(k<n) k<<=1;
	if(k==n) { printf("No\n"); return 0; }
	printf("Yes\n");
	printf("%d %d\n",n+1,n+2);
	printf("%d %d\n",n+2,3);
	printf("%d %d\n",3,1);
	printf("%d %d\n",1,2);
	printf("%d %d\n",2,n+3);
	for(int j=4;j+1<=n;j+=2) {
		int k=j+1;
		printf("%d %d\n",j,1);
		printf("%d %d\n",j,n+k);
		printf("%d %d\n",k,1);
		printf("%d %d\n",k,n+j);
	}
	if(!(n&1)) {
		for(int x=2;x<=n-1;++x) {
			int y=n^x^1;
			if(y>=2&&y<=n-1) {
				printf("%d %d\n",n+n,x);
				printf("%d %d\n",n,y);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

vector<int> inedge[100000];
int step[100000];
vector<int> canMoveTo[100000];
int parentNode[100000];
int searched[100000];
int main() {
    int N, M;

    cin >> N >> M;
    for (int i=0; i<N-1+M; i++) {
        int a, b;
        cin >> a >> b;
        inedge[b-1].push_back(a-1);
        canMoveTo[a-1].push_back(b-1);
    }
    int rootNode = -1;
    for (int i=0; i<N; i++) {
        if (inedge[i].size() == 0) rootNode = i;
    }
    if (rootNode == -1) return -1;
    //bfs
    queue<int> q;
    q.push(rootNode);
    step[rootNode] = 0;
    parentNode[rootNode] = 0;
    while (!q.empty()) {
        int node = q.front();
        q.pop();
        for (auto child : canMoveTo[node]) {
            searched[child]++;
            if (searched[child] == inedge[child].size()) {
                int putting = step[node] + 1;
                step[child] = putting;
                parentNode[child] = node+1;
                q.push(child);
            }
        }
    }
    //cerr << "bfs end" << endl;

    for (int i=0; i<N; i++) {
        cout << parentNode[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 12928
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

int N, D[100000];
ll res, c[100000];

ll pw(ll x, int y) {
	ll a = 1;
	while (y) {
		if (y & 1)a = a*x%mod998;
		x = x*x%mod998;
		y /= 2;
	}
	return a;
}

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> D[i];
		c[D[i]]++;
	}
	if (c[0] >= 2 || D[0]) {
		cout << 0 << endl;
		return 0;
	}
	res = 1;
	int s = 1;
	for (int i = 1; s < N; i++) {
		s += c[i];
		res *= pw(c[i - 1], c[i]);
		res %= mod998;
	}
	cout << res << endl;
}

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

using namespace std;

int main()
{
  string s;
  cin >> s;
  char t[10];
  int i = 0;
  for (char c : s) {
    if (c == '0') {
      t[i] = '0';
      i++;
    } else if (c == '1') {
      t[i] = '1';
      i++;
    } else if (c == 'B' && i > 0) {
      i--;
    }
  }

  for (int j = 0; j < i; j++) {
    cout << t[j];
  }
  cout << endl;

  return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF (1LL<<25)     //33554432
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

int a[100010];
signed main(void)
{
  int n;
  cin >> n;
  REP(i, n) cin >> a[i];

  ll ret = 0;
  REP(i, n) {
    while(a[i] >= 2) {ret++; a[i] -= 2;}
    if(i != n-1 && a[i] > 0 && a[i+1] > 0) {ret++; a[i]--; a[i+1]--;}
  }

  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>

using namespace std;

double solve (int n) {
	vector<double> s(n);
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	
	double sum = 0;
	for (double e : s) sum += e;
	double ave = sum / double(n);
	
	double a = 0;
	for (double e : s) a += (e - ave) * (e - ave);
	
	return sqrt(a / n);
}

int main() {
	cout << fixed << setprecision(10);
	
	while (true) {
		int n;
		cin >> n;
		if (n) cout << solve(n) << '\n';
		else break;
	}
	
	return 0;
}
	


Measured memory_bytes: 3300
#include<iostream>
#include<vector>
#include<algorithm>

int main() {
  long long H, W;
  std::cin >> H >> W;
  long long ans = std::numeric_limits<long long>::max();
  for (int tmp = 0; tmp < 2; ++tmp) {
    for (int i = 1; i < H; ++i) {
      long long s1 = i * W;
      long long s2 = (H - i) * (W / 2);
      long long s3 = (H - i) * (W - W / 2);
      ans = std::min(
          ans,
          std::max(std::max(s1, s2), s3) - std::min(std::min(s1, s2), s3));
    }
    if (H % 3 == 0) { ans = 0; }
    else { ans = std::min(ans, W); }
    std::swap(H, W);
  }
  std::cout << ans << std::endl;
  return 0;
}

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

int main()
{
    int N,K;
    int H[200000];
    cin >> N >> K;
    for(int i=0; i<N; i++)
    {
        cin >> H[i];
    }

    sort(H,H+N);
    K = min(N,K);
    for(int j=N-1; j>=N-K; j--)
    {
        H[j] = 0;
    }

    unsigned long long int sum = 0;

    for(int k=0; k<N; k++)
    {
        sum += H[k];
    }

    cout << sum;


    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<stdio.h>
using namespace std;
int a[10],num;
int main(){
	scanf("%d",&num);
	int res=0;
	while(num!=0){
		a[++res]=num%10;
		num/=10;
	}
	bool flag=1;
	for(int i=1;i<=3;i++){
		if(a[i]==a[i+1])flag=0;
	}
	if(flag==0)puts("Bad");
	else puts("Good");
	return 0;
}


Measured memory_bytes: 256
import sys 
try:
	sys.stdin = open('input.txt', 'r') 
	sys.stdout = open('output.txt', 'w')
except:
	pass
n = int(input())
s = input()
red = []
blue = []
green = []
for i in range(n):
	if s[i] == 'R':
		red.append(i)
	elif s[i] == "G":
		green.append(i)
	else:
		blue.append(i)
temp = [(len(red),'R'), (len(blue),'B'), (len(green),'G')]
temp.sort()

if temp[0][1] == 'R':
	first = list(red)
elif temp[0][1] == 'G':
	first = list(green)
else:
	first = list(blue)

if temp[1][1] == 'R':
	second = list(red)
elif temp[1][1] == 'G':
	second = list(green)
else:
	second = list(blue)

if temp[2][1] == 'R':
	third = list(red)
elif temp[2][1] == 'G':
	third = list(green)
else:
	third = list(blue)

final = []
for i in first:
	for j in second:
		gg = max(i,j)
		ss = min(i,j)
		diff = gg-ss
		check = []
		if (gg+ss)%2==0:
			check.append((gg+ss)//2)
		if gg+diff < n:
			check.append(gg+diff)
		if ss-diff >= 0:
			check.append(ss-diff)
		final.append(check)
# print(final)
# print(first,second,third)
ll = len(third)
d_third = {i:1 for i in third}
		
ans = 0

for item in final:
	sub = 0
	for i in item:
		if i in d_third:
			sub += 1
	ans += ll - sub
print(ans)

Measured memory_bytes: 299292
from collections import defaultdict
s=input()
x=set()
d=defaultdict(int)
for v in s:
  d[v]+=1
  x.add(v)
if len(d)==2:
  for k in d:
    if d[k]!=2:
      print("No")
      exit(0)
  print("Yes")
else:
  print("No")
   
  

Measured memory_bytes: 3316
import numpy as np
n=int(input())
l=list(map(int,input().split()))


arr=np.array(l)
arr2=np.append(np.hstack((0,arr)),0)

dif=np.diff(arr2)
differ=np.sum(np.abs(dif))
for i in range(1,n+1):
    difference=abs(dif[i]+dif[i-1])-abs(dif[i])-abs(dif[i-1])
    print(differ+difference)

   


Measured memory_bytes: 22824
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}


fn main(){
    let line: Vec<u32> = read_as_vec();
    let (n, k) = (line[0], line[1]);
    let mut ans: f64 = 0.0;
    let a: f64 = 16.0;
    for dice in 1..n+1{
        if k <= dice{
            ans += 1_f64/n as f64;
        }else{
            let num_hit = (k as f64/dice as f64).log2().ceil() as i32;
            //let est = 1_f64 /(2 as u64).pow(num_hit) as f64;
            let est = 0.5_f64.powi(num_hit);
            ans += est/(n as f64);
        }
    }

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


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


int main()
{
	int a;
	cin >> a;
	int b = 0, temp = a;
	while (temp > 0) {
		b += temp % 10;
		temp /= 10;
	}
	if (a%b == 0) {
		cout << "Yes" << endl;
	}
	else
		cout << "No" << endl;
	return 0;
}

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

using namespace std;

const int INF = 2000000007;

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

  int N;
  cin >> N;

  int zmax = -INF, zmin = INF, wmax = -INF, wmin = INF;
  for(int i = 0; i < N; ++i) {
    int x, y;
    cin >> x >> y;
    
    zmax = max(zmax, x + y);
    zmin = min(zmin, x + y);
    wmax = max(wmax, x - y);
    wmin = min(wmin, x - y);
  }

  cout << max(zmax - zmin, wmax - wmin) << "\n";
  return 0;
}


Measured memory_bytes: 3612
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TOPSIC2
{
    class Program
    {
        static void Main(string[] args)
        {
            double H = double.Parse(Console.ReadLine());
            double W = double.Parse(Console.ReadLine());
            double N = double.Parse(Console.ReadLine());

            if (N / H >= N / W)
            {
                Console.WriteLine(Math.Ceiling(N / W));
            }
            else
            {
                Console.WriteLine(Math.Ceiling(N / H));
            }

        }
    }
}


Measured memory_bytes: 11092
#!/usr/bin/env php
<?php
// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)

function genInputs() {
    while(($input = rtrim(fgets(STDIN))) !== false) {
        foreach (explode(' ', $input) as $v) {
            yield $v;
        }
    }
}
function getNext($gen) {
    $value = $gen->current();
    $gen->next();
    return $value;
}
$gen = genInputs();

$N = (int)getNext($gen);
$K = (int)getNext($gen);
for ($i = 0; $i < $N; $i++) {
    $A[] = (int)getNext($gen);
}
$map = array_count_values($A);
asort($map);
echo array_sum(array_slice($map, 0, count($map) - $K)).PHP_EOL;


Measured memory_bytes: 35308
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>

using namespace std;

int a[102];

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

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll m=1e9+7;
ll power(ll a,ll b)
{
	ll res=1;
	while(b>0)
	{
		if(b&1) res=(res*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return res;
}
int main() 
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		int c=0;
		for(int a=1;a<=n;a++) 
		{
			c+=n/a;
			if(n%a==0) c--;
		}
		cout<<c<<endl;
	}
	return 0;
}


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

// #define int long long
#define endl '\n'

#define IOS ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;

#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<vi>
#define vp vector<pii>
#define vs vector<string>
#define all(v) v.begin(),v.end()

#define lb  lower_bound
#define ub  upper_bound
#define bs  binary_search
#define ff  first
#define ss  second
#define sz(x) ((int)(x).size())
#define rep(i,l,r) for(int i=(l);i<(r);++i)

#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))

#define pi 3.14159265358979323846264338327950L
#define MOD 1000000007
int a[104];

int32_t main()
{



    int x, n;
    cin >> x >> n;
    set<int> s;
    for(int i = 0; i < n; i++)
    {
        int temp;
        cin >> temp;
        s.insert(temp);
    }
    for(int i = 0; i <= 100; i++)
    {
        int temp = x - i;
        if(s.find(temp) == s.end())
        {
            cout << temp << "\n";
            break;
        }
        temp = x + i;
        if(s.find(temp) == s.end())
        {
            cout << temp << "\n";
            break;
        }
    }
    return 0;
    return 0;

}




Measured memory_bytes: 3600
#include <iostream>

#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
using namespace std;


string s;
vector<int> vec;

int main(){
    cin>>s;
    int len=s.length();
    char last=s[0];
    int _to_push=0;
    vec.push_back(_to_push);
    _to_push^=1;
    for(int i=1;i<len;i++){
        if(s[i]!=last){
            vec.push_back(_to_push);
            _to_push^=1;
            last=s[i];
        }
    }
    int n=vec.size();
    printf("%d\n",n-1);
    



    return 0;
}

Measured memory_bytes: 1020
from collections import deque
n=int(input())
dq=deque()

for i in range(n):
    cmd=input().split()
    if cmd[0]=="insert":
        dq.appendleft(cmd[1])
    elif cmd[0]=="deleteFirst":
        dq.popleft()
    elif cmd[0]=="deleteLast":
        dq.pop()
    elif cmd[0]=="delete":
        try:
            dq.remove(cmd[1])
        except:
            pass
print(*dq)

Measured memory_bytes: 71780
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

const i64 INF = 1LL << 40;

using VP = vector<tuple<i64, i64>>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  VP pu, pr, pd, pl;
  REP(i, N) {
    i64 x, y;
    char u;
    cin >> x >> y >> u;
    if (u == 'R') {
      pr.emplace_back(x, y);
    } else if (u == 'L') {
      pl.emplace_back(x, y);
    } else if (u == 'U') {
      pu.emplace_back(x, y);
    } else {
      assert(u == 'D');
      pd.emplace_back(x, y);
    }
  }
  i64 ans = INF;

  auto rotate = [&](const VP& p, int k, VP& pout) {
    pout.resize(p.size());
    REP(i, p.size()) {
      auto [x, y] = p[i];
      REP(j, k) {
        i64 tmp = x;
        x = -y;
        y = tmp;
      }
      pout[i] = {x, y};
    }
  };

  auto check_ud = [&](const VP& pu, const VP& pd) {
    map<i64, set<i64>> t;
    for (auto [x, y] : pd) {
      t[x].insert(y);
    }
    for (auto [x, y] : pu) {
      auto& s = t[x];
      auto it = s.lower_bound(y);
      if (it == s.end()) continue;
      ans = min<i64>(ans, (*it - y) * 5);
    }
  };
  check_ud(pu, pd);

  VP pr_r, pl_r;
  rotate(pr, 1, pr_r);
  rotate(pl, 1, pl_r);
  check_ud(pr_r, pl_r);

  auto check_dr = [&](const VP& pd, const VP& pr) {
    map<i64, set<i64>> t;
    for (auto [x, y] : pd) {
      t[y - x].insert(x);
    }
    for (auto [x, y] : pr) {
      auto& s = t[y - x];
      auto it = s.lower_bound(x);
      if (it == s.end()) continue;
      ans = min<i64>(ans, 10 * (*it - x));
    }
  };
  check_dr(pd, pr);
  VP p1, p2;
  rotate(pl, 1, p1);
  rotate(pd, 1, p2);
  check_dr(p1, p2);
  rotate(pu, 2, p1);
  rotate(pl, 2, p2);
  check_dr(p1, p2);
  rotate(pr, 3, p1);
  rotate(pu, 3, p2);
  check_dr(p1, p2);
  if (ans == INF) {
    cout << "SAFE" << endl;
  } else {
    cout << ans << endl;
  }
}


Measured memory_bytes: 33984
module Main (main) where

import Control.Monad
import qualified Data.ByteString.Char8 as C8
import Data.Bool
import Data.Maybe

main :: IO ()
main = do
  [[n],[a]] <- replicateM 2 readInts
  print . showAnswer $ solve (n,a)

type Input  = (Int, Int)
type Output = Bool

solve :: Input -> Output
solve (n,a) = n `mod` 500 <= a

showAnswer :: Output -> Answer
showAnswer = YesNo

-- utils
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

data Answer
  = YesNo Bool
  | YESNO Bool
  | AB Bool
  | Number Int
  | String String
  | Compare Ordering
  | Compare2 Ordering

instance Show Answer where
  show (YesNo b)    = bool "No" "Yes" b
  show (YESNO b)    = bool "NO" "YES" b
  show (AB b)       = bool "B"  "A" b
  show (Number i)   = show i
  show (String s)   = s
  show (Compare o)  = ordering "<" "=" ">" o
  show (Compare2 o) = ordering "Right" "Balanced" "Left" o

ordering :: a -> a -> a -> Ordering -> a
ordering lt eq gt o = case o of
  LT -> lt
  EQ -> eq
  GT -> gt

Measured memory_bytes: 380
#define _GLIBCXX_DEBUG
#include"bits/stdc++.h"

using namespace std;

//loops
#define REP(i,n) for(int i=0;i<(ll)(n);i++)
#define REPD(i,n) for(int i=(ll)(n)-1;i>=0;i--)
#define OneToN(i,n) for(int i=1;i<(ll)(n+1);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)

//arrays
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define add push_back

//pair
#define fir first
#define sec second

//types
#define ll long long
#define vec vector
//UNCOMMENT WHEN NEEDED
//#define int ll

//input
template <class T> T get(){ T s; cin >> s; return(s);}
#define gi get<int>()
#define gs get<string>()

template <class T> vector<T> getv(int n) { vec<T> v(n); REP(i, n) cin >> v[i]; return v; }
#define giv(n) getv<int>(n)
#define gsv(n) getv<string>(n)

//output
void print(int a){ cout << a << endl; }
void print(string a){ cout << a << endl; }
void print(double a, int dig){ cout << std::setprecision(dig) << a << endl; }

template <class T = int>
void print(vec<T> v){ for (T item: v) { cout << item << " "; } cout << endl; }

void YesNo1(bool i = true){ return print(i?"Yes":"No"); }
void YESNO2(bool i = true){ return print(i?"Yes":"N1010o"); }

//debug output
#define var_name(var) #var
template <class T> void debug(T &var, int nest = 0, string before = "") { cout << string("          ", nest) << before; print(var); }

//name replacement
#define y0 y0__
#define y1 y1__
#define j0 j0__
#define j1 j1__
#define next next__
#define prev prev__

//bool lambdas
#define lamb(exp) [](auto i){return exp;}
#define isEven [](int i){return i % 2 == 0;}
#define isOdd [](int i){return i % 2 != 0;}

//constants
const ll INF = 1e18;
const int MOD = 10000007;

void Main() {
    //code here
    int
    n = gi,
    a = gi,
    b = gi;
    int res = 0;
    OneToN(i, n) {
        int sum = 0;
        string str = to_string(i);
        for(char c: str) {
            sum += c - '0';
        }
        if (a <= sum && sum <= b) {
            res += i;
        }
    }
    print(res);
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Main();
}

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

using namespace std;
const int N = 5e5 + 10;
const int MOD = 1e9 + 7;

void _psum (int &, int);
int _sum (int, int);
int _mul (int, int);
int _pow (int, int);
int gcd (int, int);

int n, m, k, inv[N], f[N], res[N];
vector <int> X;

int x[] = {0, 0, -1, +1};
int y[] = {-1, +1, 0, 0};
string s[N];

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

	long long cnt[20] = {};
	
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string wtf;
		cin >> wtf;
		int dex = 0;
		switch (wtf[0]) {
			case 'M': dex++;
			case 'A': dex++;
			case 'R': dex++;
			case 'C': dex++;
			case 'H': dex++;
		}
		if (dex)
			cnt[dex - 1]++;
	}

	long long ans = 0;
	for (int i = 0; i < 5; i++)
		for (int j = i + 1; j < 5; j++)
			for (int k = j + 1; k < 5; k++)
				ans += 1LL * cnt[i] * cnt[j] * cnt[k];
	cout << ans << endl;
}

int gcd (int a, int b) {
	return !b? a : gcd (b, a % b);
}

// int choose (int r, int k) {
// 	return _mul (f[k], _mul(inv[r], inv[k - r]));
// }

void _psum (int &a, int b) {
	a += b;
	if (a >= MOD)
		a -= MOD;
}

int _sum (int a, int b) {
	return a + b - (a + b >= MOD? MOD : 0);
}

int _mul (int a, int b) {
	return 1LL * a * b % MOD;
}

int _pow (int a, int b) {
	if (!b) 
		return 1;
	int res = _pow (a, b >> 1);
	res = _mul (res, res);
	if (b & 1)
		res = _mul (res, a);
	return res;
}

// SamMHD :: Jun27-2019 :: Another Day with Shayan...

Measured memory_bytes: 4352
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,x;
int32_t main(){
CODE_START;
ll ans=0;
cin>>n;
for(ll i=1;i<=n;i++)
{
    cin>>x;
    if(i%2==1&&x%2==1)ans++;
}
cout<<ans<<endl;
}



Measured memory_bytes: 3596
#include<iostream>
#include <string> 
#include <vector>  
#include<math.h>
#include <algorithm>
#include<iomanip>
#define INF 1000000000
#define LM 55555
#define LL long long
using namespace::std;


long long x[100000],y[100000],z[100000], b, c,now, N, K, M, ans, A[100000], AA[100000];
string S, s[100];
bool h, k[100];
char cc;

LL gcd(LL a, LL b) {
	LL temp;
	while ((temp = a%b) != 0) {
		a = b;
		b = temp;
	}
	return b;
}
int main() {
	cin >> N>>K;
	now = 2000000000;
	
	for (int i = 0; i < N; i++) {
		cin >> x[i];
		y[i] = abs(x[i] - K);
		if(y[i]!=0)
		now = min(now, y[i]);
	}
	if (N == 1) {
		cout << y[0] << endl;
		return 0;
	}
	c = 0;
	for (int i = 1; i <= now; i++) {
		if (now%i == 0) {
			z[c] = i;
			c++;
		}
	}

	for (int i = c-1; i > -1; i--) {
		for (int j = 0; j < N; j++) {
			if (y[j] % z[i] != 0) {
				break;
			}
			if (j == N - 1) {
				cout << z[i] << endl;
				return 0;
			}
		}
	}
		cout << ans<< endl;

	return 0;

}

Measured memory_bytes: 1792