akhauriyash/Code-Regression huggingface dataset:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    def f(x):
        if x % 2:
            if x == 1:
                return 1
            elif max(0, x - 3) % 4 == 0:
                return 0
            else:
                return 1
        else:
            t = f(x - 1)
            return t ^ x

    a, b = map(int, input().split())

    res = f(b) ^ f(a - 1)
    print(res)


if __name__ == '__main__':
    resolve()


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

int X, Y, A, B, C;
int P[1 << 18];
int Q[1 << 18];
int R[1 << 18];

int main() {
	cin >> X >> Y >> A >> B >> C;
	for (int i = 0; i < A; i++) cin >> P[i];
	for (int i = 0; i < B; i++) cin >> Q[i];
	for (int i = 0; i < C; i++) cin >> R[i];
	sort(P, P + A); reverse(P, P + A);
	sort(Q, Q + B); reverse(Q, Q + B);
	for (int i = 0; i < X; i++) R[C + i] = P[i];
	for (int i = 0; i < Y; i++) R[C + X + i] = Q[i];
	sort(R, R + C + X + Y);
	reverse(R, R + C + X + Y);

	long long score = 0;
	for (int i = 0; i < X + Y; i++) score += R[i];
	cout << score << endl;
	return 0;
}

Measured memory_bytes: 2048
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;

int main()
{
	int tate, yoko, kosuuK;
	cin >> tate >> yoko >> kosuuK;
	bool kekka = false;
	for (int hhh = 0; hhh < tate + 1; hhh++)
	{
		for (int j = 0; j < yoko + 1; j++)
		{
			if (j * tate + hhh*yoko - j*hhh * 2 == kosuuK)
			{
				kekka = true;
			}
		}
	}
	if (kekka)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	return 0;
}



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

{
int a,b,sum=0;
  cin>>a>>b;
  int arr[a];
  for(int i=0; i<a; i++)
  cin>>arr[i];
  sort(arr, arr+a, greater<int>()); 
  for(int i=0; i<a; i++)
  sum+=arr[i];
  float l=sum/(4.0*b);
  int c=0, f=0;
  for(int i=0; i<a; i++)
  {
      if(arr[i]>=l)
      {
          c++;
          if(c>=b)
          {
              f=1;break;
          }
      }
      else{
          
      }
  }
  if(f==1)
  cout<<"Yes\n";
  else
  cout<<"No\n";
  


}

Measured memory_bytes: 256
from collections import deque
H, W = map(int, input().split())
f_inf = float('inf')
C = [input() for _ in range(H)]

def bfs():
  dist = [[False]*W for _ in range(H)]
  D = ((1,0), (0,1), (-1,0), (0,-1))
  
  que = deque([])
  que.append((0,0))
  dist[0][0] = 0
  
  while que:
    p = que.popleft()
    for d in D:
      nx = p[0] + d[0]
      ny = p[1] + d[1]
      if H > nx >= 0 and W > ny >= 0 and C[nx][ny] != '#' and dist[nx][ny] is False:
        que.append((nx,ny))
        dist[nx][ny] = dist[p[0]][p[1]]+1
  return dist[H-1][W-1]

cnt = 0
for c in C:
  cnt += c.count('.')
  
ans = bfs()
if ans is False:
  print(-1)
else:
  print(cnt - 1 - ans)
  


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
int main () {
  string S;
  cin >> S;
  if(S == "Sunny")cout << "Cloudy" << endl;
  else if(S == "Cloudy") cout << "Rainy" << endl;
  else cout << "Sunny" << endl;
  return 0;
}


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

using namespace std;

#define    fastio        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define    f             first
#define    s             second
#define    ub            upper_bound
#define    lb            lower_bound
#define    pb            push_back
#define    mset(x,val)   memset(x,val,sizeof(x))
#define    all(x)        (x).begin(),(x).end()
#define    foo(i,a,b)    for(long long i=(a);i<=(b);i++)
#define    rep(i,a,b)    for(long long i=(a);i>=(b);i--)
#define    FOR(i,v)      for(auto &(i):(v))

using  ll    =   long long;
using  ld    =   long double;
using  vl    =   vector<ll>;
using  pll   =   pair<ll, ll>;
using  vll   =   vector<pll>;
using  MAP   =   map<ll, ll>;
using  sl    =   set<ll>;
using  sll   =   set<pll>;
using  MAPs  =   map<ll, sl>;
using  MAPv  =   map<ll, vl>;


const ll inf = LLONG_MAX;
const ll mod = 1e9 + 7;
const ll N   = 2e5 + 5;//change it if u have to

int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};

/*********************************************************************************************************/
/***************************************** VARIABLE DECLARATIONS *****************************************/
ld n, d;

/***************************************** FUNCTION IMPLEMENTATIONS **************************************/
ld dist(ll x, ll y) {
    ll tmp = (x * x) + (y * y);
    return sqrt(tmp);
}

/***************************************** START OF MAIN FUNCTION ****************************************/
void MAIN() {
    cin >> n >> d;

    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        ll x, y;
        cin >> x >> y;

        if (dist(x, y) <= d) {
            cnt++;
        }
    }

    cout << cnt << "\n";
}

int main() {
    fastio;
    int t = 1;

    // cin>>t;
    while (t -- > 0) {
        MAIN();
    }

// #ifndef ONLINE_JUDGE
//     cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
// #endif

}


Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

int main() {
    // 頂点数と辺数
    int N, M; cin >> N >> M;

    // グラフ入力受取 (ここでは無向グラフを想定)
    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        G[a-1].push_back(b);
        G[b-1].push_back(a);
    }

    // BFS のためのデータ構造
    vector<int> u(N, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;

    // 初期条件 (頂点 1 を初期ノードとする)
    u[0] = 0;
    que.push(1); // 1 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v-1]) {
            if (u[nv-1] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            u[nv-1] = v;
            que.push(nv);
        }
    }

    // 結果出力 (各頂点の頂点 0 からの距離を見る)
    cout << "Yes" << endl;
    for (int v = 1; v < N; ++v) cout << u[v] << endl;
}

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

using namespace std;
using namespace __gnu_pbds; 
  
#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int mod = (int)1e9 + 7;
const int MX = (int)1e5 + 10;

void add_self(int &x, int y){x += y; if(x >= mod) x -= mod;}
void sub_self(int &x, int y){x -= y; if(x < 0) x += mod;}
void mul(int &x, int y){x = x * 1LL * y % mod;}

int main(){

	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(0);

	string s;
	int Q;
	cin >> s >> Q;

	deque<char> dq;
	for(auto &c : s) dq.push_back(c);

	int dir = 0;

	while(Q--){
		int t;
		cin >> t;
		if(t == 1){
			dir ^= 1;
		}
		else{
			int f; char x;
			cin >> f >> x;
			if(f == 1){
				if(dir == 0) dq.push_front(x);
				else dq.push_back(x);
			}
			else{
				if(dir == 0) dq.push_back(x);
				else dq.push_front(x);
			}
		}
	}

	string res;
	if(dir) while(!dq.empty()) res += dq.back(), dq.pop_back();
	else while(!dq.empty()) res += dq.front(), dq.pop_front();

	cout << res << endl;
	
	return 0;
}

Measured memory_bytes: 1368
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#include<deque>
#define rep(i,rept)	for(int i = 0; i<(ll)rept;++i)
typedef long long ll;
using namespace std;


int main() {

	int n = 0, b = 0, a = 0;
	std::cin >> n;
	if (n == 1) {
		cout << "Hello World" << endl;
		return 0;
	}
	else {
		std::cin >> a >> b;
		cout << a + b << endl;
		return 0;
	}




}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    bool flag = true;
    cin >> N;
    rep(i, N) {
        ll temp;
        cin >> temp;
        if(temp % 2 == 0) {
            if(temp % 3 != 0 && temp % 5 != 0) flag = false;
        }
    }
    if(flag) cout << "APPROVED";
    else cout << "DENIED";
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    map<char,char> mp;
    for(char c='a',C='A';c<='z';c++,C++){
        mp[c] = C;
    }

    string s;
    getline(cin,s);
    for(char c : s){
        if(c==' ' or c=='.') cout << c;
        else cout << mp[c];
    }
    cout << endl;
}

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

int main()
{
	string str;
	cin>>str;
	int year = 0;
	for(int i = 0; i < str.size(); i++)
	{
		if(str[i]=='/')
		{
			if(year==2017)
			{
				cout<<"2018";
			}
			else if(year< 10)
			{
				cout<<'0'<<year;
			}
			else
			cout<<year;
			cout<<'/';
			year = 0;
		}
		else
		year = year*10 + (str[i]-'0');
		//cout<<year<<endl;
	}
	if(year < 10)
	cout<<'0';
	cout<<year;
	cout<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a,b,c;
  cin>>a>>b>>c;
  if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0])cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define p first
#define d second
using namespace std;

int main() {
  while(1) {
  int n,m;
  cin >> n >> m;
  if(n == 0 && m == 0) break;

  pair <int,int> pd[10001];
  for(int i=0;i<n;i++) cin >> pd[i].d >> pd[i].p;
  sort(pd,pd+n);

  int ans = 0;
  for(int i=n-1;i>=0;i--)
    if(m >= pd[i].d) m-=pd[i].d;
    else if(m > 0) ans += (pd[i].d-m)*pd[i].p,m = 0;
    else ans+=pd[i].d*pd[i].p;
 
  cout << ans <<endl;
  }
  return 0;
}

Measured memory_bytes: 1236
#include <iostream>
#include <algorithm>

using namespace std;

long long d[40][40],z[510][510],a[40][3],ans;
int main(){
	int n,c,i,j,k;
	cin >> n >> c;
	for(i=1;i<=c;i++){
		for(j=1;j<=c;j++){
			cin >> d[i][j];
		}
	}
	
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			cin >> z[i][j];
		}
	}
	
	ans = 9000000000000;
	
	for(k=1;k<=c;k++){
		a[k][0]=0;
		a[k][1]=0;
		a[k][2]=0;
		for(i=1;i<=n;i++){
			for(j=1;j<=n;j++){
				if((i+j)%3==0){
					a[k][0] += d[z[i][j]][k];
				}
				if((i+j)%3==1){
					a[k][1] += d[z[i][j]][k];
				}
				if((i+j)%3==2){
					a[k][2] += d[z[i][j]][k];
				}
			}
		}
	}
	
	for(i=1;i<=c;i++){
			for(j=1;j<=c;j++){
				if(i!=j){
					for(k=1;k<=c;k++){
						if(i!=k && j!=k){
							ans = min(ans,a[i][0]+a[j][1]+a[k][2]);
						}
					}
				}
			}
	}
	cout << ans << endl;
}
						
		

Measured memory_bytes: 2304
n=int(input())

if 400 <= n and  n <= 599:
    print(8)
elif 600 <= n and  n <= 799:
    print(7)
elif 800 <= n and  n <= 999:
    print(6)
elif 1000 <= n and  n <= 1199:
    print(5)
elif 1200 <= n and  n <= 1399:
    print(4)
elif 1400 <= n and  n <= 1599:
    print(3)
elif 1600 <= n and  n <= 1799:
    print(2)
elif 1800 <= n and  n <= 1999:
    print(1)

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

int main(){
   int A, B;
   cin >> A >> B;

   if (A >=13)
      cout << B << endl;
   else if (A>=6 && A<=12)
      cout << B/2 << endl;
   else
      cout << 0 << endl;
}



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

using namespace std; 
const int MAX_N = 1005; 
const int MOD = 1000000007; 
string a[MAX_N]; 
int dp[MAX_N][MAX_N]; 
int n, m; 

int main () {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin >> n >> m; 
	for (int i = 0; i < n; i++) {
		cin >> a[i]; 
	}

	dp[0][0] = 1; 
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (dp[i][j] > 0) {
				if (i < n - 1 && a[i + 1][j] == '.') {
					(dp[i + 1][j] += dp[i][j]) %= MOD; 
				}
				
				if (j < m - 1 && a[i][j + 1] == '.') {
					(dp[i][j + 1] += dp[i][j]) %= MOD; 
				}
			}
		}
	}

	cout << dp[n - 1][m - 1]; 
	return 0; 
}

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

#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)

ll dp[100009];
int main(){
    fast;
    ll n,k;cin>>n>>k;
    ll a[n];
    for(ll i=0;i<n;++i){
        cin>>a[i];
    }
    sort(a,a+n);
    dp[0] = -1;
    for(ll i=1;i<=k;++i){
        if(i<a[0])
            dp[i] = -1;
        else{
            for(ll j=0;j<n;++j){
                if(i-a[j]>=0 && dp[i-a[j]]==-1){
                    dp[i] = 1;
                    break;
                }
                else{
                    dp[i] = -1;
                }
            }
        }
    }
    /*for(ll i=0;i<=k;++i){
        cout<<i<<' '<<dp[i]<<endl;
    }*/
    if(dp[k]==1){
        cout<<"First";
    }
    else{
        cout<<"Second";
    }

    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int R=1,C=1,H[2000010],N[2000010];
//ティツゥツ陛、ツセツ。テゥツ鳴「テヲツ閉ーテッツシツ暗」ツ??」ツ?セテ」ツ?ッMINテッツシツ?
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]<N[H[b]]?1:0;
}
//テヲツ個ソテ・ツ?・テゥツ鳴「テヲツ閉ー
void hin(int a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//テ・ツ渉姪」ツつ甘・ツ?コテ」ツ?凖ゥツ鳴「テヲツ閉ー
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
int p[100010]={0};
int d[100010]={0};
int Find(int a,int b){
  int r,n;
  for(r=++a;p[r];r=p[r]);
  for(;n=p[a];a=n)p[a]=r;
  for(r=++b;p[r];r=p[r]);
  for(;n=p[b];b=n)p[b]=r;
  return a-b?1:0;
}
int Union(int a,int b){
  if(Find(a,b)){
    for(++a;p[a];a=p[a]);
    for(++b;p[b];b=p[b]);
    d[a]<d[b]?(p[a]=b):(p[b]=a);
    if(d[a]==d[b])d[a]++;
    return 1;
  }
  return 0;
}
int main(){
  int a[10010],b[10010],c,n,m,i,j;
  while(scanf("%d %d",&n,&m),n){
    for(i=0;i<n+2;i++)p[i]=d[i]=0;
    R=C=1;
    for(i=0;i<m;i++){
      scanf("%d %d %d",&a[R],&b[R],&c);
      hin(c);
    }
    for(i=0;i<n/2;i+=Union(a[j],b[j]))c=N[j=hout()];
    printf("%d\n",c);
  }
  return 0;
}

Measured memory_bytes: 2780
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,tot,num[105];
int main()
{
    scanf("%lld",&n);
    while(n)
        num[++tot]=n%10,n/=10;
    ll sum=0,ans=0;
    for(int i=tot;i>=1;i--)
        if(num[i])
    {
        ans=max(ans,sum+num[i]-1+9*(i-1));
        sum+=num[i];
    }
    ans=max(ans,sum);
    printf("%lld\n",ans);
}


Measured memory_bytes: 256
//
// Created by sark2 on 23-10-2019.
//

#include "bits/stdc++.h"

using namespace std;
#define PB push_back
#define IOS cin.sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define CASES int t;cin>>t;while(t--)
#define MP make_pair

using ll = long long;
using ld = long double;

ll mod = 1e9 + 7;

int main() {
    IOS

   int n; cin>>n;

   string s; cin>>s;

   int ans = 1;
   int curr = s[0];

   for(int i = 1; i < n; i++){
       if(s[i] != curr){
           ans++;
           curr = s[i];
       }
   }

   cout<<ans;



}


Measured memory_bytes: 512
n = int(input())
def sitigo(num):
    if int(num) > n:
        return 0
    count3 = False
    count5 = False
    count7 = False
    s = 0

    for i in range(len(str(num))):
        if str(num)[i] == "3":
            count3 = True
        if str(num)[i] == "5":
            count5 = True
        if str(num)[i] == "7":
            count7 = True
        if count3 and count5 and count7:
            s = 1

    return sitigo(int(str(num)+"3")) + sitigo(int(str(num)+"5")) + sitigo(int(str(num)+"7")) + s
print(sitigo(0))


Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DEBUG 0
#define rep(i,a,f) for(int i=(a);i<(f);i++)
#define rrep(i,a,f) for(int i=(f)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) if(DEBUG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DEBUG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
using ll = long long; using ull = unsigned long long; using pii = pair<int, int>;
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const int MOD = 1e9 + 7;

signed main() {
	bool f[110] = {};
	int b[110] = {}, w[110] = {};
	for (int W, Q; cin >> W >> Q && (W || Q);) {
		fill(f, f + W, false);
		rep(i, 0, Q) {
			char c; int id; cin >> c >> id;
			if (c == 's') {
				cin >> w[id];
				dump(w[id]);
				bool flag2 = false;
				rep(j, 0, W - w[id] + 1) {
					dump(j);
					bool flag = false;
					rep(k, j, j + w[id]) {
						if (f[k]) {
							flag = true;
							break;
						}
					}
					if (flag)continue;
					flag2 = true;
					rep(k, j, j + w[id])f[k] = true;
					cout << j << endl;
					b[id] = j;
					dumpc(f);
					break;
				}
				if (!flag2)cout << "impossible" << endl;
			}
			else {
				rep(k, b[id], b[id] + w[id])f[k] = false;
			}
		}
		cout << "END" << endl;
	}
	return 0;
}

Measured memory_bytes: 2980
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
void A(vector<char>&);
void B(vector<char>&);
void C(vector<char>&);
void D(vector<char>&);
char get(vector<char>&, bool, int);
int main() {
	int n, m;
	while (cin >> n >> m&&n != 0) {
		vector<char> line(n + 1, '#');
		for (int i = 0; i < m; ++i) {
			char num;
			cin >> num;
			if (num == 'A') {
				A(line);
			}
			else if (num == 'B') {
				B(line);
			}
			else if (num == 'C') {
				C(line);
			}else{
				D(line);
			}
		}
		for (int i = 1; i < line.size(); ++i) {
			cout << line[i];
		}
		cout << endl;
	}
	return 0;
}

char get(vector<char>&line, bool right, int place) {
	if (right) {
		if (place == line.size() - 1)return '#';
		else return line[place + 1];
	}
	else {
		return line[place - 1];
	}
}

void A(vector<char> &line) {
	for (int i = 1; i < line.size(); ++i) {
		if (line[i] == '#') {
			line[i] = 'A';
			break;
		}
	}
}

void B(vector<char> &line) {
	for (int i = line.size() - 1; i > 0; --i) {
		if (line[i] == '#'&&get(line, true, i) != 'A' && get(line, false, i) != 'A') {
			line[i] = 'B';
			return;
		}
	}
	for (int i = 1; i < line.size(); ++i) {
		if (line[i] == '#') {
			line[i] = 'B';
			return;
		}
	}
}

void C(vector<char> &line) {
	for (int i = 1; i < line.size(); ++i) {
		if (line[i] != '#') {
			if (i != line.size() - 1 && line[i + 1] == '#') {
				line[i + 1] = 'C';
				return;
			}
			else if (i != 1 && line[i - 1] == '#') {
				line[i - 1] = 'C';
				return;
			}
		}
	}
	if (line.size() % 2 == 0) {
		line[line.size() / 2] = 'C';
		return;
	}
	else {
		line[line.size() / 2 + 1] = 'C';
	}
}

void D(vector<char> &line) {
	vector<int> dline(line.size());
	int num = line.size() + 1;
	bool flag = false;
	for (int i = 1; i < line.size(); ++i) {
		++num;
		if (line[i] != '#') {
			num = 0;
			flag = true;
		}
		dline[i] = num;
	}
	if (!flag) {
		line[1] = 'D';
		return;
	}
	num = line.size() + 1;
	for (int i = line.size() - 1; i > 0; --i) {
		++num;
		if (line[i] != '#') {
			num = 0;
		}
		dline[i] = min(dline[i], num);
	}
	int mn = 0, mp = 0;
	for (int i = 1; i < line.size(); ++i) {
		if (mn < dline[i]) {
			mn = dline[i];
			mp = i;
		}
	}
	line[mp] = 'D';
}

Measured memory_bytes: 3096
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define v vector
#define ALL(x) x.begin(),x.end()
#define rALL(x) x.rbegin(),x.rend()
#define endl '\n'
#define F first
#define S second
#define DEBUG

template<typename T> void DBG(const char* name, T&& H) {
	cerr << name << " = " << H << ')' << endl;
}

template<typename T, typename... Args> void DBG(const char* names, T&& H, Args&&... args) {
	const char* NEXT = strchr(names+1, ',');
	cerr.write(names, NEXT-names) << " = " << H << " |";
	DBG(NEXT+1, args...);
}

#ifdef DEBUG
	#define dbg(...) cerr << __FUNCTION__ << ' ' <<__LINE__ << " : (", DBG(#__VA_ARGS__, __VA_ARGS__)
#else
	#define dbg(...)
#endif

using ll = long long;
using ld = long double;

const long long mod = 998244353;
const long double PI = acos(-1.0);
const long long INF = 1e18;
const int maxN = 2e5+1;

void Solve() {
	string s;
	cin >> s;
	for(int i = 1; i <= s.size(); i ++) {
		if(s[i] == s[i-1]) {
			cout << i << " " << i+1 << endl;
			return;
		}
		if(i >= 2) {
			if(s[i] == s[i-2]) {
				cout << i-1 << " " << i+1 << endl;
				return;
			}
		}
	}
	cout << -1 << " " << -1 << endl;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int tt = 1;
	while(tt --) {
		Solve();
	}
	
	return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  int N; cin >> N;
  vector<long long> a(N);
  vector<long long> S(N, 0);
  for(int i = 0; i < N; ++i) {
    cin >> a[i];
    if(i==0) S[0] = a[0];
    else S[i] = S[i-1] + a[i];
  }
  long long ans = (int)1e11;
  for(int i = 0; i < N-1; ++i) {
    long long x = S[i];
    long long y = S[N-1] - S[i];
    ans = min(ans, abs(x-y));
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3328
N, Q = map(int, input().split())
S = input()

total = [0]*(N+1)
for i in range(2, N+1):
    if S[i-2]=='A' and S[i-1]=='C':
        total[i] = total[i-1]+1
    else:
        total[i] = total[i-1]

for i in range(Q):
    l, r = map(int, input().split())
    print(total[r]-total[l])

Measured memory_bytes: 6164
#include <bits/stdc++.h>
using namespace std;
#define array_input int n;cin>>n;int a[n+1],i;for(i=1;i<=n;i++){cin>>a[i];}
#define array_output for(i=1;i<=n;i++){cout<<a[i]<<" ";}cout<<endl;
#define INF 2147483647
#define long_INF 18446744073709551615
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
const double pi=acos(-1);
const double eps=1e-6;

int main()
{
	ios::sync_with_stdio(false);
	int a,b,c;
	cin>>a>>b>>c;
	if (a+b>=c)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}


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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
void chmin(long long &a, long long b) { if (a > b) a = b; }

int main(){
  ll i, j;
  ll n;
  cin >> n;
  vector<ll> a(n), b(n);
  ll result = 0;
  vector<ll> plus(n);
  ll sumplus = 0;
  ll summinus = 0;
  for(i = 0; i < n; i++)
    cin >> a[i];
  
  for(i = 0; i < n; i++){
    cin >> b[i];
    if(a[i] >= b[i]){
      plus[i] = a[i] - b[i];
      sumplus += a[i] - b[i];
    }
    else{
      result++;
      summinus += b[i] - a[i];
    }
  }
  if(sumplus < summinus)
    result = -1;
  else{
    sort(ALL(plus));
    reverse(ALL(plus));
    for(i = 0; summinus > 0; i++){
      summinus -= plus[i];
      result++;
    }
  }
    

  cout << result << endl;


  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
    int main(){
      long long N;
      cin >>N;
      long long ans=0;
      for(int i=1;i<N+1;i++){
        if(i%3!=0&&i%5!=0){
          ans+=i;
        }
      }
  cout <<ans<<endl;
        
    }

Measured memory_bytes: 3592
L, R = map(int, input().split())
g = 2019
ans = 0

cl = L // g
cr = R // g
if cl == cr:
    ans = 2019
    for i in range(L, R+1):
        for j in range(i+1, R+1):
            ans = min(ans, i * j % g)

print(ans)


Measured memory_bytes: 2940
#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;
#pragma endregion

void solve() {
    int n;
    ll x;
    cin >> n >> x;
    vector<ll> a(n);
    for (int i=0; i<n; i++) {
        cin >> a.at(i);
    }

    ll res = LINF;
    vector<ll> mini(n, LINF);
    for (int shift=0; shift<n; shift++) {
        ll cost = x * shift;
        for (int i=0; i<n; i++) {
            int cur = i - shift;
            if (cur < 0) cur += n;
            chmin(mini.at(i), a.at(cur));
            cost += mini.at(i);
        }
        chmin(res, cost);
    }

    cout << res << '\n';
}

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

    solve();

    return 0;
}


Measured memory_bytes: 256
N, M, C = map(int, input().split())
B = list(map(int, input().split()))

A = []
for _ in range(N):
    A.append(list(map(int, input().split())))

ans = 0
for i in range(N):
    sum = C
    for j in range(M):
        sum += A[i][j] * B[j]

    if sum > 0:
        ans += 1
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
long long int f(long long int a,long long int x){
  if(a==-1){
    return 0;
  }else{
    return a/x+1;
  }
}
int main() {
  long long int a, b, x;
  cin >> a >> b >> x;
  cout << f(b,x)-f(a-1,x) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cctype>

using namespace std;

#define ll long long

const int mod = 998244353;
int n, m;
int l, r;
ll dp[200005];
ll sum[200005];
vector<pair<int, int> > vec;

int main() {
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++) {
        scanf("%d %d", &l, &r);
        vec.push_back(make_pair(l, r));
    }
    dp[0] = sum[0] = 0;
    dp[1] = sum[1] = 1;
    for (int i = 2; i <= n; i++) {
        for (int j = 0; j < vec.size(); j++) {
            r = max(0, i - vec[j].first);
            l = max(0, i - vec[j].second - 1);
            dp[i] = (dp[i] + (sum[r] - sum[l] + mod)) % mod;
        }
        sum[i] = (sum[i - 1] + dp[i]) % mod;
    }
    printf("%lld\n", dp[n]);
    return 0;
}

Measured memory_bytes: 6312
#include <algorithm>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> P;
lli MOD = 1000000007;

int main()
{
    int n;
    cin >> n;
    string s, t;
    cin >> s;
    cin >> t;
    int m;
    for (int j = 0; j < n; j++) {
        bool flag = true;
        rep(i, n)
        {
            if (i + j >= n)
                break;
            if (s[i + j] != t[i])
                flag = false;
        }
        if (flag) {
            cout << j + n << endl;
            return 0;
            rep(i, j)
            {
                cout << s[i];
            }
            rep(i, n)
            {
                cout << t[i];
            }
            return 0;
        }
    }
    cout << 2 * n << endl;
}


Measured memory_bytes: 256
n,a,b=map(int,input().split())
h=[int(input()) for _ in range(n)]
def bisearch(k):# k回で倒せるかどうか
  ret=0
  for hi in h:
    ret+=max(0,(hi-b*k+a-b-1)//(a-b))
  return ret<=k
l,r=0,pow(10,9)
while r-l>1:
  x=(l+r+1)//2
  if bisearch(x):
    r=x
  else:
    l=x

print(r)


Measured memory_bytes: 7072
#include<bits/stdc++.h>
#define ll long long int
#define mk make_pair
#define pb push_back
#define INF (ll)1e18
#define pii pair<ll,ll>
#define mod 1000000007 //998244353
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fb(i,a,b) for(ll i=a;i>b;i--)
#define ff first
#define ss second
#define PI 3.141592653589793238
#define pq priority_queue<ll>
#define pqr priority_queue<ll,vector<ll>,greater<ll>()>
using namespace std;
ll pow_mod(ll a,ll b)
{
	ll res=1;
	while(b!=0)
	{
		if(b&1)
		{
			res=(res*a)%mod;
		}
		a=(a*a)%mod;
		b/=2;
	}
	return res;
}
void solve()
{ 
    string s;
    
    cin>>s;
    
    ll rem=0;
    
    ll n=s.size();
    
    for(ll i=0;i<n;i++){
        ll x=(ll)(s[i]-'0');
        
        rem+=x;
        
        rem%=9;
    }
    
    if(rem==0)
    cout<<"Yes\n";
    else
    cout<<"No\n";
}
int32_t main()
{    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     
//Start from Here.

  ll t;
  t=1;
  //cin>>t;
  while(t--)
  solve();
  
//Good Bye!
    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);

int main(){
  ll X,Y;

  cin >> X >> Y;
  int ans=0;
  ll x=X;
  while(x<=Y){
    x *= 2;
    ans++;
  }

  cout << ans << endl;
}



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

int main(){
  int n;
  scanf("%d",&n);
  int a=n/4+1,b=0;
  //aは4$,bは7$
  while((a*4+b*7!=n)&&a>0){
    a--;
    b=0;
    while(a*4+b*7<n)
      b++;
  }
  if(a*4+b*7==n)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3744
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> ump;
typedef pair<ll, ll> P;

ump mp;

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        string s;
        cin >> s;
        ll dp[s.length() + 10][4];
        rep(i, s.length() + 10) rep(j, 4) dp[i][j] = 0;
        dp[0][0] = 1;
        rep(i, s.length()) {
            rep(j, 4) {
                if (s[i] == '?') dp[i + 1][j] += dp[i][j] * 3; // i番目を選ばなかった時
                else dp[i + 1][j] += dp[i][j]; // i番目を選ばなかった時
                dp[i + 1][j] %= mod;
            }
            if (s[i] == 'A' || s[i] == '?') {
                dp[i + 1][1] += dp[i][0]; // 選んだ時
                dp[i + 1][1] %= mod;
            }
            if (s[i] == 'B' || s[i] == '?') {
                dp[i + 1][2] += dp[i][1]; // 選んだ時
                dp[i + 1][2] %= mod;
            }
            if (s[i] == 'C' || s[i] == '?') {
                dp[i + 1][3] += dp[i][2]; // 選んだ時
                dp[i + 1][3] %= mod;
            }
        }

        cout << dp[s.length()][3] << endl;


#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 3584
#include <stdio.h>

int main()
{
    int H,N;
    scanf("%d %d",&H,&N);
    int A[N];
    for(int i=0;i<N;i++) {
        scanf("%d",&A[i]);
    }
    int s=0;
    for(int i=0;i<N;i++) {
        s+=A[i];
    }
    if (s>=H) {
        printf("Yes");
    } else {
        printf("No");
    }

    return 0;
}

Measured memory_bytes: 512
N = int(input())
A = list(map(int, input().split()))

def bubbleSort(A, N):
    count = 0
    flag = 1
    while flag:
        flag = 0
        j = N - 1
        while j > 0:
            if A[j] < A[j - 1]:
                A[j], A[j - 1] = A[j - 1], A[j]
                count += 1
                flag = 1
            j -= 1
    return count


c = bubbleSort(A, N)
for i in range(len(A)):
    if i != len(A) - 1:
        print(A[i], end=" ")
    else:
        print(A[i])
print(c)



Measured memory_bytes: 5604
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
constexpr bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
constexpr bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll k, n;
  cin >> k >> n;
  vll a(n);
  rep(i, n){
    cin >> a[i];
  }
  ll ma = 0;
  rep(i, n){
    chmax(ma, (a[(i+1)%n]-a[i]+k)%k);
  }
  print(k-ma);
}


Measured memory_bytes: 1792
import math

n = int(input())

#ケーキ0個からN/4個まで
for c in range(0,math.floor(n/4)+1,1):
  #ドーナツ0～N/7個まで
  for d in range(0,math.floor(n/7)+1,1):
    if c*4 + d*7 == n:
      print('Yes')
      exit()
      
print('No')

Measured memory_bytes: 3060
import java.io.{BufferedReader, InputStreamReader}

import scala.annotation.tailrec

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val Array(a, b) = in.readLine().split("\\s+").map(_.toLong)

    System.err.println(gcd(a,b))
    System.out.println(a * b / gcd(a,b))
  }

  def gcd(a: Long, b: Long): Long = {
    @tailrec
    def inner(a: Long, b: Long): Long = {
     a % b match {
       case 0 => b
       case r => inner(b, r)
     }
    }

    if (a > b) {
      inner(a, b)
    } else {
      inner(b, a)
    }
  }
}


Measured memory_bytes: 27460
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define M 1101
#define MOD 1000000007
#define fi first
#define se second
#define vi vector<int>
#define vl vector<ll>
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define repl(i,l,r) for(long long i=l;i<=r;++i)
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define ins insert
#define inf INT_MAX
#define vp vector< pair<int,int> >
int n;
int v[21];
int c[21];
vi x;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    rep(i,0,n-1)
    {
        cin>>v[i];
    }
    rep(i,0,n-1)
    {
        cin>>c[i];
    }
    rep(i,0,n-1)
    {
        x.pb(v[i]-c[i]);
    }
    sort(allr(x));
    int ans=0;
    for(int i:x)
    {
        if(i>=0)
        {
            ans+=i;
        }
    }
    cout<<ans<<"\n";
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



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

        rep(i, 0, N) {
                cout << S[i] << T[i];
        }
        cout << endl;
}

Measured memory_bytes: 3616
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
#define pb push_back
int main()
{
    int n;
    cin >> n;
    string str;
    cin >> str;
    int ans = 0;
    rep(i, n-1)
    {
        string s = str.substr(0, i-0+1);
        string t = str.substr(i + 1, (n-1)-(i+1)+1);
        int cc = 0;
        for (char a = 'a'; a <= 'z'; a++)
        {
            if (s.find(a) != string::npos && t.find(a) != string::npos)
            {
                cc++;
            }
        }
        ans = max(ans, cc);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
L = list(map(int,input().split()))

L = sorted(L)

while len(L) != 1 :
    L = sorted(L)
    while L[0] == 0 :
        L.pop(0)
    if len(L) >= 2 :
        for i in range(1,len(L)) :
            L[i] = L[i] % L[0]
print(L[0])


Measured memory_bytes: 15020
n = int(input())
d = [list(map(int, input().split())) for i in range(n)]
cnt = 0
for i in range(n):
    if d[i][0] == d[i][1]:
        cnt += 1
    else:
        cnt = 0
    if cnt == 3:
        print("Yes")
        exit(0)
print("No")


Measured memory_bytes: 9172
#include<stdio.h>

int dp[50];

int fib(int n){
  if(n==0||n==1)return dp[n] =1;
  if(dp[n]!=-1)return dp[n];
  return dp[n] = fib(n-1)+fib(n-2);
}

int main(){
  int n,i;
  for(i=0;i<50;i++) dp[i]=-1;

  scanf("%d",&n);
  printf("%d\n",fib(n));

  return 0;
}



Measured memory_bytes: 2044
from collections import deque
def dfs(v):
    global adjacency_mat, visited
    st = deque([]) # stack
    st.append(v)
    while st:
        # stackから取り出す
        h = st.pop()
        visited[h] = True
        for i in range(N):
            # 辺がないなら何もしない
            if adjacency_mat[h][i] == None:
                continue
            # すでに到達したことがあるなら何もしない
            if visited[i] == True:
                continue
            # stackに加える
            st.append(i)

if __name__ == "__main__":
    N, M = map(int, input().split())
    list_ab = [[] for _ in range(M)]
    adjacency_mat = [[None]* N for _ in range(N)]
    for i in range(M):
        a, b = map(int, input().split())
        list_ab[i].append(a-1)
        list_ab[i].append(b-1)
        adjacency_mat[a-1][b-1] = 1
        adjacency_mat[b-1][a-1] = 1
        
    ans = 0
    for a, b in list_ab:
        visited = [False] * N
        # ある辺をなくす
        adjacency_mat[a][b] = None
        adjacency_mat[b][a] = None
        # 全ての辺を訪れることができるかどうか探索
        dfs(0)
        # 全ての辺を訪れることができるかどうか
        if sum(visited) < N:
            ans += 1
        # 元に戻す
        adjacency_mat[a][b] = 1
        adjacency_mat[b][a] = 1
    print(ans)

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

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

    else{
        cout << "safe" << endl;
    }
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {

    int N, L;
    cin >> N >> L;

    int minimum_i = 1;

    for (int i = 1; i <= N; i++) {
        if (abs(L + i - 1) < abs(L + minimum_i - 1)) minimum_i = i;
    }

    int sum = 0;
    for (int i = 1; i <= N; i++) {
        if (i != minimum_i) sum += L + i - 1;
    }

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

Measured memory_bytes: 256
# intのn, mに入力のNとMを，aに配列として，使用できる数であるA_1 ~ A_jを入力する
n,m,*a=map(int,open(0).read().split())

# d[0]: dpi(0)=0を表す
# 使用できるマッチの本数N * 9の-1を用意する(9は，全マッチ棒を使用した場合の領域も確保している)
"""
d: [マッチ棒が0の時は0,
    
"""
d=[0]+[-1]*n*9

# 1 ~ (使用できるマッチ棒の本数)までの最大桁数(解説のdpi(N-1)に相当)を全探索で求める
for i in range(1,n+1):
    # d[1] ~ d[n]を全探索で求める
    # d[i]は次のaの各要素jの最大値
    #   max{j + d[i - (jの数を作るのに必要なマッチの本数)] * 10 } (つまり，jは一番下の桁に使う)
    d[i]=max(j + d[i-int('0255456376'[j])]*10 for j in a)
print(d[n])

Measured memory_bytes: 15092