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

int main() {
    int A,B,C,D;
    string s;
    cin >> s;
    A = s[0]-'0';
    B = s[1]-'0';
    C = s[2]-'0';
    D = s[3]-'0';
    vector<int> X={A,B,C,D};
    for(int i=0; i<8; i++){
        int ans=X[0];
        for(int j=0; j<3; j++){
            if((i>>j)%2==0){
                ans+=X[j+1];
            }
            else{
                ans-=X[j+1];
            }
        }
        if (ans==7){
            cout <<X[0];
            for(int j=0; j<3; j++){
                if((i>>j)%2==0){
                    cout << "+";
                }
                else{
                    cout << "-";
                }
                cout <<X[j+1];
            }
            cout << "=7"<< endl;
            return 0;
        }
        
    }

}

Measured memory_bytes: 384
def find(x):
    if(p[x] == x):return x
    else: 
        p[x] = find(p[x])
        return p[x]
def unite(x,y):
    x = find(x)
    y = find(y)

    if x==y:return
    if rank[x] < rank[y]:
        p[x] = y
    else:
        p[y] = x
        if rank[x] == rank[y]:
            rank[x]+=1

def same(x,y):
    if find(x) == find(y):
        return 1
    else: return 0

if __name__=='__main__':
    n, q = (int(x) for x in input().split())
    p = [i for i in range(n)]
    rank = [0 for i in range(n)]
        
    for i in range(q):
        com, x, y = (int(x) for x in input().split())
        if com == 0:unite(x,y)
        else:print(same(x,y))



Measured memory_bytes: 6036
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

int main(){
    ll n, m, k; cin >> n >> m >> k;
    vector<ll> a(n), b(m);
    vector<ll> as(n+1, 0), bs(m+1, 0);
    rep(i, n){
        cin >> a[i];
        as[i+1] = as[i] + a[i];
    }
    rep(i, m){
        cin >> b[i];
        bs[i+1] = bs[i] + b[i];
    }
    ll ans = 0, j = m;
    rep(i, n+1){
        if(as[i] > k) break;
        while(bs[j] > k - as[i]) j--;
        ans = max(ans, i+j);
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9536
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;

signed main(){
	cin>>N;
	int Y=0;
	int S=0;
	for(int i=1;i<=N;i++){
		if(i*(i+1)/2<N&&N<=(i+1)*(i+2)/2){
			Y=i,S=(i+1)*(i+2)/2-N;
		}
	}
	DEB(Y)END
	set<int> U;
	for(int i=1;i<=Y+1;i++){
		U.insert(i);
	}
	if(S!=0){
		U.erase(S);
	}
	for(auto x:U){
		cout<<x<<endl;
	}
}


Measured memory_bytes: 512
<?php

$arr = array_fill(0, 101, 0);

$max = 0;
while($line = fgets(STDIN)){
	$n = intval($line);
	$arr[$n]++;
	if($arr[$n] > $max){
		$max = $arr[$n];
	}
}

for($i = 1; $i <= 100; $i++){
	if($arr[$i] == $max){
		echo $i."\n";
	}
}

Measured memory_bytes: 15076
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 1010101010101010;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(){
  int n,k; cin>>n>>k;
  vll a(n); rep(i,n) cin>>a[i];
  ll ans=l_INF;
  rep(i,1<<(n-1)){
    int cnt=0;
    set<int> select;
    vll b(n);
    rep(j,n-1){
      if((i>>j)&1){
        cnt++;
        select.insert(j);
      }
    }
    ll sum=0;
    if(cnt==k-1){
      b[0]=a[0];
      rep(j,n-1){
        if(select.count(j)){
          if(a[j+1]>b[j]) b[j+1]=a[j+1];
          else b[j+1]=b[j]+1;
        }else{
          if(a[j+1]>=b[j]) b[j+1]=a[j+1];
          else b[j+1]=b[j];
        }
      }
      for(auto x:select){
        sum+=b[x+1]-a[x+1];
        //cout<<b[x+1]<<" ";
      }
      ans=min(ans,sum);
      //cout<<ans<<" ";
    }
  }
  //cout<<endl;
  cout<<ans<<endl;
}


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

#define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
#define pb push_back
#define sz(s) (int)s.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define for1(i,n) for(int i=1;i<=(int)n;i++)
#define ford(i, b, a) for (int i = (int)(b); i >= a; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
const ll N = (ll)1e5+77;
const ll inf = (ll) 1e16+7;
const ll mod = (ll) 998244353;
const ld pi = acos(-1);

int main() {
    fast;
    ll k, a, b, ans = 1;
    cin >> k >> a >> b;
    ans += min(a - 1, k);
    k -= min(a - 1, k);
    if (b - a > 2) {
        ans += (k / 2) * (b - a);
        if (k % 2) ++ans;
    } else {
        ans += k;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <limits>
using namespace std;
// 素因数分解
typedef pair<long long, long long> P;
vector<P> prime_factorize(long long n)
{
vector<P> res;
for (long long p = 2; p * p <= n; ++p)
{
if (n % p != 0)
continue;
int num = 0;
while (n % p == 0)
{
++num;
n /= p;
}
res.push_back(make_pair(p, num));
}
if (n != 1)
res.push_back(make_pair(n, 1));
return res;
}
// 因数分解
long long gcd(long long x, long long y)
{
  if (y == 0)
  {
    return x;
  }
  else
  {
    return gcd(y, x % y);
  }
}
const int MOD = 1000000007;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    ll r = 0, g = 0, b = 0;
    for(auto c:s){
        if(c=='R'){
            r++;
        }else if(c=='G'){
            g++;
        }else{
            b++;
        }
    }
    ll all = r * g * b;
    ll equel = 0;
    for (int i = 0; i < n ; i++)
    {
        for (int j = i + 1; j < n ;j++){
            int k = 2 * j - i;
            if(k>=n){
                continue;
            }
            if(s[i]==s[j]||s[i]==s[k]||s[j]==s[k]){
                continue;
            }
            equel++;
        }
    }
    cout << all - equel << endl;
    return 0;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define ll unsigned long long
using namespace std;
int main(){
    int sum=0;
    REP(i,3){
        int a;cin>>a;
        sum+=a;
    }
    cout<<(sum>=22?"bust":"win")<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int n; cin>>n;
	vl vec(n);
	ll total=0;
	rep(i,0,n){
		ll a; cin>>a;
		vec[i]=a;
		total+=a;
	}
	ll v=0,ans=1e10;
	rep(i,0,n-1){
		v+=vec[i];
		ll w=total-v;
		ans=min(ans,abs(v-w));
	}
	cout<<ans;
		
	return 0;
}

Measured memory_bytes: 1792
import glob

# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = 'ABC\\165\\C'

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'

class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class C(Common):

    def rec(self, A, now_index):

        point1 = 0
        point2 = 0
        if now_index == self.N-1:
            for i in self.abcd:
                if A[i[1]-1] - A[i[0]-1] == i[2]:
                    point1 += i[3]

        else:
            for i in range(A[now_index], self.M+1):
                A[now_index+1] = i
                tmp = self.rec(A, now_index+1)
                if tmp > point2:
                    point2 = tmp

        if point1 > point2:
            return point1
        return point2

    def resolve(self):

        self.N, self.M, self.Q = map(int, self.input_data().split())
        self.abcd = []

        for i in range(self.Q):
            self.abcd.append(list(map(int, self.input_data().split())))

        A = [0]*self.N
        A[0] = 1

        point = self.rec(A, 0)
        print(str(point))

solver = C(REL_PATH)
solver.exec_resolve()

Measured memory_bytes: 9976
using System;
class c
{
  static void Main()
  {
    string[]s=Console.ReadLine().Split(' ');
    string ans="NO";
    int n0=s[0].Length-1;
    int n1=s[1].Length-1;
    if(s[0][n0]==s[1][0]&&s[1][n1]==s[2][0])ans="YES";
    Console.WriteLine(ans);
  }
}


Measured memory_bytes: 11092
#include <iostream>
using namespace std;
int main(){
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int x=0, y=0, z=0;
  while(a >= c){
    c *= 2;
    z++;
  }
  while(a >= b){
    b *= 2;
    y++;
  }
  while(b >= c){
    c *= 2;
    z++;
  }
  if(x+y+z <= k){
    cout << "Yes" << endl;
  } else{
    cout << "No" << endl;
  }
}

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

using namespace std;

const int MAX = 100005;

vector<int> adj[MAX], dst(MAX, 0), dep(MAX, 0), par(MAX);

void dfs(int v, int p){
    par[v] = p;
    for(int u : adj[v])
        if( u != p )
            dst[u] = dst[v]+1, dfs(u, v), dep[v] = max(dep[v], dep[u]);
    dep[v]++;
}

int main(){

    int n, u, v;
    cin >> n >> u >> v;
    int a, b;
    for(int i = 0; i < n-1; i++){
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    dfs(v, -1);
    int mv = 0;
    if( dst[u]&1 ){
        int cur = ( dst[u]-1 )/2;
        mv = mv + cur;
        while(cur){
            u = par[u];
            cur--;
        }
        mv = mv + dep[u]-1;
    }else{
        int cur = dst[u]/2 - 1;
        mv = mv + cur;
        while(cur){
            u = par[u];
            cur--;
        }
        mv = mv + dep[u];
    }

    cout << mv << endl;

    return 0;
}

Measured memory_bytes: 12032
const main = (input) => {
  const [, ...arr] = input.trim().split('\n')
  let count = 0

  for (let i=0; i<arr.length; i++) {
    const [a, b] = arr[i].split(' ').map(Number)

    if (a !== b) count = 0

    if (a === b) {
      count++
      if (count === 3) return console.log('Yes')
    }
  }
  return console.log('No')
}

process.env.MYTEST
  ? (process.env.MYTEST === 'test' ? test() : main(require('fs').readFileSync('dev/stdin', 'utf8')))
  : main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 29704
#include  <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 1000000007
//P pa(114,514);   ,vector<P>vec(N,0);
//vector<vector<int>> vec(縦, vector<int>(横));
#define REP(i,N) for(int i=0;i<N;i++)
int gcd(int a, int b) {
    if(a>b){
        swap(a,b);
        }
    while(b%a!=0){
        b%=a;
        swap(a,b);
    }
    return a;
}
//cout << setprecision(123);
//a=atoi(S.c_str());
//S=to_string(a);
int main(){
  int N,ans=0;
  cin>>N;
  vector<int>V(N);
  REP(i,N){
    cin>>V[i];
  }
  
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      ans+=V[i]*V[j];
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define fs first
#define sc second
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)

int main(){
    string w; cin >> w;
    vei check(26);
    rep(i,26) check[i] = 0;
    rep(i,w.size()) check[w[i] - 'a'] += 1;
    bool ans = true;
    rep(i,26) if(check[i] % 2  == 1) ans = false;
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long INF = 1e18;
//const ll mod = 1000000007;

ll f(vector<l_l> v) {
    //cerr << "----f----" << endl;
    sort(v.begin(), v.end(), greater<l_l>());
    ll ret = 0;
    set<ll> st;
    for(int i = 0; i < v.size(); i++) {
        st.insert(i);
    }
    for(auto tmp : v) {
        ll day = v.size() - tmp.second;
        //cerr << v.size() << " " << tmp.second << " " << day << endl;
        auto itr = st.lower_bound(day);
        if(itr != st.end()) {
            //cerr << *itr << " " << tmp.first << endl;
            ret += tmp.first;
            itr = st.erase(itr);
        } else {
            itr = st.begin();
            itr = st.erase(itr);
        }
    }
    return ret;
}


void solve() {
    ll N;
    cin >> N;
    vector<l_l> pos, neg;
    ll ans = 0;
    for(int i = 0; i < N; i++) {
        ll k, l, r;
        cin >> k >> l >> r;
        ans += min(l, r);
        if(l > r) {
            pos.push_back({l - r, k});
        }
        if(r > l) {
            neg.push_back({r - l, N - k});
        }
    }
    //cerr << ans << endl;
    ans += f(pos);
    ans += f(neg);
    cout << ans << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int T;
    cin >> T;
    while(T--) solve();
    return 0;
}


Measured memory_bytes: 12656
from collections import deque
n , m , k = map(int,input().split())
tomo = [set() for i in range(n+1)]
to = [0 for i in range(n+1)]
bro = [set() for i in range(n+1)]
for i in range(m):
    a , b = map(int,input().split())
    tomo[a].add(b)
    tomo[b].add(a)
    to[a] += 1
    to[b] += 1
for i in range(k):
    c , d = map(int,input().split())
    bro[c].add(d)
    bro[d].add(c)

visit = [True for i in range(n+1)]
kurasuta = []
for i in range(1,n+1):
    if visit[i]:
        kar = {i}
        d = deque()
        d.append(i)
        cou = 1
        visit[i] = False
        while d:
            now = d.popleft()
            for j in tomo[now]:
                if visit[j]:
                    visit[j] = False
                    kar.add(j)
                    d.append(j)
                    cou += 1
        kurasuta.append([kar,cou])
    else:
        continue
ans = [0 for i in range(n)]

for i in range(len(kurasuta)):
    for j in kurasuta[i][0]:
        ans[j-1] = kurasuta[i][1] - to[j] - 1 - len(kurasuta[i][0] & bro[j])

print(*ans)

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

int main(){
	long long int a; cin>>a;
  	string b; cin>>b;
  	long long int c = 100*(b[0]-'0')+10*(b[2]-'0')+(b[3]-'0');
  	long long int ans = a*c;
  	ans = ans/100;
  	cout<<ans;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;  // or pb_ds;

using namespace std;

#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#ifndef DEBUG
#define endl "\n"
#endif
#define fff ff
#define sss ss.ff
#define ttt ss.ss
#define INF (1 << 30)
#define LLF (1ll << 60)
#define PRIME (1000000007)
#define FASTIO std::ios::sync_with_stdio(false)
#ifdef DEBUG
#define debug(x) cerr << #x << " = " << x << endl
#else
#define debug(x)
#endif
#define rep(i, begin, end)                            \
  for (__typeof(end) i = (begin) - ((begin) > (end)); \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define FILE_INPUT                  \
  freopen("input.txt", "r", stdin); \
  freopen("output.txt", "w", stdout)

#define all(x) x.begin(), x.end()

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<string> vs;

template <typename T, typename B = null_type>
using oset =
    tree<T, B, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order / order_of_key

const ld eps = 1e-12;

/*-----------------END TEMPLATE-----------------*/

vi vals;
vi valsR;

int(((((((((((((((main)))))))))))))))() {
  FASTIO;
  ll n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;

  for (int i = 0; i < n; i++) {
    if (s[i] == 'x') continue;
    vals.eb(i);
    valsR.eb(n - i - 1);
  }
  sort(valsR.begin(), valsR.end());

  vi ansInit;
  int mx = 0;
  for (int j = 0; j < vals.size() && ansInit.size() < k; j++) {
    if (vals[j] >= mx) {
      ansInit.pb(vals[j]);
      mx = vals[j] + c + 1;
    }
  }

  vi ansEnd;
  mx = 0;
  for (int j = 0; j < valsR.size() && ansEnd.size() < k; j++) {
    if (valsR[j] >= mx) {
      ansEnd.pb(n - valsR[j] - 1);
      mx = valsR[j] + c + 1;
    }
  }

  sort(ansEnd.begin(), ansEnd.end());

  for (int i = 0; i < k; i++) {
    if (ansEnd[i] >= ansInit[i] + 1) {
      continue;
    } else {
      cout << ansInit[i] + 1 << endl;
    }
  }
}

/*

0 1 2 3 4
      x

*/

Measured memory_bytes: 5000
import math

k = int(input())

ans = 0

while ans == 0:
    factor = 0
        
        # 2以外の偶数は素数ではないので無視する
    if k % 2 == 0 and k != 2:
        k +=1
        continue
        
        # 繰り返しの上限を半分にする
    for divisor in range(2, k//2):
        if k % divisor == 0:
            factor += 1
                
    if factor == 0:
        ans =k
    
    k +=1    
            
print(ans) 

Measured memory_bytes: 40464
/* Author - thiolhub */

#include <bits/stdc++.h>

using namespace std;

#define ll              long long int
#define ld              long double
#define db              double
#define pi              3.1415926535897932384626
#define PI              acos(-1.0)
#define endl            "\n"
#define mod             1000000007
#define mk              make_pair
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            ll t; cin>>t; while(t--)
#define sc(a)	        scanf("%lld",&a);
#define pr(a)	        printf("%lld\n",a)
#define f(i,a,n)		for(ll i=a;i<n;i++)
#define m(a)		    memset(a,0,sizeof(a))
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)


int main(){ FastIO;

ll h;cin>>h;
ll c=0,k=0;
while(h>0)
{
	c+=pow(2,k);
	h=h/2;
	k++;
}
cout<<c;

return 0;
}

Measured memory_bytes: 384
n,*s=map(str,open(0).read().split())
a=[0]*5
ans=0
for i in s:
    if i[0] in "MARCH":
        a["MARCH".index(i[0])]+=1
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            ans+=a[i]*a[j]*a[k]
print(ans)

Measured memory_bytes: 11036
#include<bits/stdc++.h>
#define lli long long int
using namespace std;
//469
//ar[1] = 4 , ar[2] = 6 , ar[3] = 9
int ar[20];
lli dp[20][200][2];

lli getSum(int pos , int n , lli sum , bool flag)
{
	if(pos > n) return sum;
	
	if(dp[pos][sum][flag] != -1) return dp[pos][sum][flag];
	
	int limit = 9;
	if(!flag) limit = ar[pos];
	
	lli res = 0;
	for(int i=0;i<=limit;i++)
	{
		if(flag || i != limit)
		res = max(res,getSum(pos + 1 , n , sum + i , true));
		else
		res = max(res,getSum(pos + 1 , n , sum + i , false));
//		if(pos ==1 ) cout<<res<<" ";
	}
	return dp[pos][sum][flag] = res;
}

int digitSum(string num)
{
	int res = 0;
	for(char digit : num)
	res += digit - '0';
	
	return res;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string a;
		cin>>a;
		
		//if(a == "-1") break;
		
		lli L;
		
		//for L
		for(int i=0;i<a.size();i++)
		ar[i+1] = a[i] - '0';
		
		memset(dp , -1 , sizeof dp);
		L = getSum(1 , a.size() , 0 , 0);
		cout<<L<<endl;
}


Measured memory_bytes: 3664
#include <iostream> 
#include <vector>
#include <string>
#include <math.h>
using namespace std;

int main() {
  int a[5],k;
  int MAX = 0,MIN = 155;
  for ( int i = 0; i < 5; i++ ) {
    cin >> a[i];
    MAX = max(MAX,a[i]);
    MIN = min(MIN,a[i]);
  }
  cin >> k;

  if( (MAX - MIN) > k ) cout << ":(" << endl;
  else cout << "Yay!" << endl;
  return 0;
}


Measured memory_bytes: 888
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
  
N, M = map(int,input().split()) 
uf = UnionFind(N)
for _ in range(M):
  a, b = map(int,input().split())
  uf.union(a-1,b-1)

ans = 0
for i in range(N):
  ans=max(ans, uf.size(i))
print(ans)


Measured memory_bytes: 14540
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#define REP(i, N) for(int i=0; i<N; i++)
using namespace std;
 
//#include "atcoder.hpp"
 
long long gcd(long long a, long long b) {
    if (a>b) swap(a,b);
    
    auto r = b % a;
    
    return (r ? gcd(r, a) : a);
}
 
int main() {
    long long X, Y, Z, K;
    
    cin >> X >> Y >> Z >> K;
    long long A[1000], B[1000], C[1000];
    
    REP(i,X)
        cin >> A[i];
    REP(i,Y)
    cin >> B[i];
    REP(i,Z)
    cin >> C[i];
    
    multiset<long long> XY;
    
    REP(i,X) REP(j,Y) {
        long long tmp = A[i] + B[j];
        if (XY.size() < 3000 || tmp > *XY.begin()) XY.insert(tmp);
    }
    
    priority_queue<long long> XYZ;
    int cnt = 3000;
    for (auto it = XY.rbegin(); cnt-- && it != XY.rend(); ++it)
    REP(i,Z) {
        XYZ.push(*it + C[i]);
    }
    
    while (K--) {
    cout << XYZ.top() << endl;
        XYZ.pop();
    }
    
    return 0;
}
 

Measured memory_bytes: 81892
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(abs(a-c)<=d||abs(a-b)<=d&&abs(b-c)<=d)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
//============================================================================
// Name        : abc117c.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;

int main() {
	int N;
	int M;
	cin >> N >> M;
	vector<long long> A(M);
	vector<long long> B;
	for(int i = 0; i < M; ++i){
		cin >> A[i];
	}
	sort(A.rbegin(), A.rend());

	for(int i = 0; i < M - 1; ++i){
		B.push_back(A[i] - A[i + 1]);
	}
	sort(B.rbegin(), B.rend());

	long long ans = A[0] - A.back();
	for(int i = 0; i < min(N - 1, (int)B.size()); ++i){
		ans -= B[i];
	}
	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 2168
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func sum(a []int) int {
	ret := 0
	for _, v := range a {
		ret += v
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	x, y, a, b, c := nextInt(), nextInt(), nextInt(), nextInt(), nextInt()
	p, q, r := nextInts(a), nextInts(b), nextInts(c)
	sort.Sort(sort.IntSlice(p))
	sort.Sort(sort.IntSlice(q))
	sort.Sort(sort.IntSlice(r))

	p = p[a-x:]
	q = q[b-y:]

	for i, j, k := 0, 0, c-1; (i < x || j < y) && k >= 0; k-- {
		if i < x && j < y && p[i] < q[j] && p[i] < r[k] {
			// pの要素が最小
			p[i] = r[k]
			i++
		} else if i < x && j < y && p[i] > q[j] && q[j] < r[k] {
			// qの要素が最小
			q[j] = r[k]
			j++
		} else if i < x && p[i] < r[k] {
			p[i] = r[k]
			i++
		} else if j < y && q[j] < r[k] {
			q[j] = r[k]
			j++
		} else {
			break
		}
	}

	ans := sum(p) + sum(q)

	puts(ans)
}

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 6016
while True:
    a,b=map(int,input().split())
    if a==0 and b==0:
        break
    else:
        for i in range(a):
            for j in range(b):
                if (i+j)%2==0:print('#',end="")
                else:print('.',end="")
            print()
        print()



Measured memory_bytes: 7004
#include<stdio.h>
int main()
{
    int N;
    // 整数の入力
    scanf("%d", &N);
    int ans = 0;
    for(int i = 0; 2*i+1<=N; i++){
        int l = 0;
        for(int j = 0; j <= i ; j++){
            if((2*i+1)%(2*j+1)==0){
                l++;
            }
        }
        if(l==8){ans++;}
    }
    // 出力
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
/**
	*    author:  accesss_denied
	**/
	#include <bits/stdc++.h>
	using namespace std;
	#define ll long long int
	#define ff first
	#define ss second
	#define pb push_back
	#define endl "\n"
	#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	ll mod=1e9+7;			
	ll inf=1e18;
    ll bit[3]={0};

               

	int main() {
				fast
				// #ifndef ONLINE_JUDGE
				// freopen("input.txt","r",stdin);
				// freopen("output.txt","w",stdout);
				// #endif

				ll t;
				t=1;
				while(t--)
				{
					ll n,m;
					cin>>n>>m;
					vector<pair<pair<ll,ll>,ll>> arr;
					for(ll i=0;i<n;i++)
					{
                        ll a,b,c;
                        cin>>a>>b>>c;
                        arr.pb({{a,b},c});
                    }

                    ll ans=0;
                    for(ll k=0;k<8;k++)
                    {
                        for(ll j=0;j<=2;j++) bit[j]=0;
                        for(ll j=2;j>=0;j--)
                        {
                            if(k&(1<<j))
                            bit[j]=1;
                        }
                        vector<ll> temp;

                        for(ll i=0;i<n;i++)
                        {
                            ll arr2[3]{arr[i].ff.ff,arr[i].ff.ss,arr[i].ss};
                            for(ll j=0;j<3;j++)
                            {
                                if(bit[j]==0)
                                arr2[j]=-arr2[j];
                            }
                            temp.pb(arr2[0]+arr2[1]+arr2[2]);
                        }
                        sort(temp.rbegin(),temp.rend());
                        ll ans2=0;
                        for(ll i=0;i<m;i++)
                        ans2+=temp[i];
                        ans=max(ans,ans2);
                    }
                    cout<<ans<<endl;
					
				}
				return 0;
			}	




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

int main() {
	int A, B, X, minx = (1 << 30); cin >> A >> B >> X;
	for (int i = 0; i <= 1000; i++) {
		for (int j = 0; j <= 1000; j++) {
			int S = i * 1000 + j * 500;
			if (S >= X) minx = min(minx, A * i + B * j);
		}
	}
	cout << minx << endl;
	return 0;
}


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

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" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include<atcoder/all>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007

ll floor_sum(ll n,ll m,ll a,ll b){
  ll res = 0;
  if(a >= m){
    res += (n-1)*n*(a/m)/2;
    a %= m;
  }
  if(b >= m){
    res += n*(b/m);
    b %= m;
  }
  ll y_max = (a*n+b)/m;
  if(y_max == 0)return res;
  res += floor_sum(y_max,a,m,a*n+b-y_max*m);
  return res;
}

int main(){
  
  int T;
  cin >> T;
  rep(_,T){
    ll n,m,a,b;cin >> n >> m >> a >> b;
    cout << floor_sum(n,m,a,b) << "\n";
  }
  


  return 0;
}


Measured memory_bytes: 3612
def cnter(List,c):
  ans = [0]*c
  for i in List:
    ans[i-1] += 1
  return ans
n,c = map(int, input().split())
d = []
e = []
for i in range(c):
  d1 = list(map(int, input().split()))
  d.append(d1)
for i in range(n):
  e1 = list(map(int, input().split()))
  e.append(e1)
mod0 = []
mod1 = []
mod2 = []
for i in range(n):
  for j in range(n):
    b = i + j
    if b % 3 == 0:
      mod2.append(e[i][j])
    elif b % 3 == 1:
      mod0.append(e[i][j])
    else:
      mod1.append(e[i][j])
mod0 = cnter(mod0,c)
mod1 = cnter(mod1,c)
mod2 = cnter(mod2,c)
len_0, len_1, len_2= sum(mod0), sum(mod1), sum(mod2)
mod0_p = []
mod1_p = []
mod2_p = []
md0 = 0
md1 = 0
md2 = 0
for i in range(c):
  md0 = 0
  md1 = 0
  md2 = 0
  for j in range(c):
    md0 += d[j][i] * mod0[j]
    md1 += d[j][i] * mod1[j]
    md2 += d[j][i] * mod2[j]
  mod0_p.append(md0)
  mod1_p.append(md1)
  mod2_p.append(md2)
ans = 2**31-1
for i in range(c):
  for j in range(c):
    for k in range(c):
      if i != j and j != k and k != i:
        if mod0_p[i] + mod1_p[j] + mod2_p[k] < ans:
          ans = mod0_p[i] + mod1_p[j] + mod2_p[k]
print(ans)

Measured memory_bytes: 7768
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n, i, j, k, ans=0, r[10000]={0}, g[10000]={0}, b[10000]={0};
    string s;
    cin >> n >> s;
    for(i=1;i<=n;i++){
        r[i]=r[i-1];g[i]=g[i-1];b[i]=b[i-1];
        if(s[i-1]=='R') r[i]++;
        else if(s[i-1]=='G') g[i]++;
        else b[i]++;
    }
    for(i=0;i<n-1;i++){
        for(j=i+1;j<n;j++){
            if((s[i]=='R' && s[j]=='G') || (s[i]=='G' && s[j]=='R')) {
                ans+=b[n]-b[j+1];
              if(2*j-i<n){
                if(s[2*j-i]=='B') ans--;
              }
            }
            else if((s[i]=='R' && s[j]=='B') || (s[i]=='B' && s[j]=='R')) {
                ans+=g[n]-g[j+1];
              if(2*j-i<n){
                if(s[2*j-i]=='G') ans--;
              }
            }
            else if((s[i]=='G' && s[j]=='B') || (s[i]=='B' && s[j]=='G')) {
                ans+=r[n]-r[j+1];
              if(2*j-i<n){
                if(s[2*j-i]=='R') ans--;
              }
            }
        }
    }
    cout << ans <<endl;
}


Measured memory_bytes: 3832
#include<cstdio>
#include<algorithm>

using namespace std;

int calc(int x, int k){
	if(x < k){
		return 0;
	}
	if(x % k == 0){
		return x / k;
	}
	int a = x / k;
	int r = x % k;
	r %= (a + 1);
	if(r == 0) return a;
	int tmp = a * k + r;
	return calc(tmp - a - 1, k);
}

int N;

int main(){
	int res = 0;
	scanf("%d", &N);
	for(int i = 0; i < N; ++i){
		int A, K;
		scanf("%d%d", &A, &K);
		int val = calc(A, K);
		res ^= val;
	}
	if(res == 0) printf("Aoki\n");
	else printf("Takahashi\n");
	return 0;
}


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

int main(){
  long long N,K,U;
  cin >> N >> K;
  U=N;
  long long ans1=0;
  long long ans2=0;
  ans1=U%K;
  ans2=K-U%K;
  cout << min(ans1,ans2) << endl;
}


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

#pragma region Macros
using ll = long long;
#define int ll
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
#define IOS\
    ios::sync_with_stdio(false);\
    cin.tie(0);\
    cout.tie(0);
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SORT(name) sort(name.begin(), name.end())
#define RSORT(name)\
    SORT(name);\
    reverse(all(name));
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
template <class T> inline void print(T x){ cout << x << '\n';}
template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
#pragma endregion

#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const int MOD = 1000000007;
const int MAX_N = 100010;

int H, W, M;
map<int, int> row, col;
map< pii, bool> exist;

signed main() {
    IOS;

    cin >> H >> W >> M;
    REP(i, M) {
        int h, w;
        cin >> h >> w;
        row[h]++;
        col[w]++;
        exist[mp(h, w)] = true;
    }
    V<pii> row_v, col_v;
    for(auto b : row) {
        row_v.pb(mp(b.second, b.first));
    }
    RSORT(row_v);
    for(auto c : col) {
        col_v.pb(mp(c.second, c.first));
    }
    RSORT(col_v);

    int ans = 0;
    for(int i = 0; i < min(5LL, (ll)row_v.size()); ++i) {
        for(int j = 0; j < (ll)col_v.size(); ++j) {
            int cand = row_v[i].first + col_v[j].first;
            if (exist.count(mp(row_v[i].second, col_v[j].second)) > 0) {
                cand--;
            }
            chmax(ans, cand);
        }
    }
    for(int i = 0; i < (ll)row_v.size(); ++i) {
        for(int j = 0; j < min(5LL, (ll)col_v.size()); ++j) {
            int cand = row_v[i].first + col_v[j].first;
            if (exist.count(mp(row_v[i].second, col_v[j].second)) > 0) {
                cand--;
            }
            chmax(ans, cand);
        }
    }
    print(ans);

    return 0;
}


Measured memory_bytes: 76484
import sys

def dijkstra(W, n):
    U = [i for i in range(1, n)]
    D = [W[0][i] for i in range(n)]
    D[0] = 0

    while len(U) != 0:
        mind, minu = 200001, -1
        for u in U:
            if D[u] <= mind:
                mind, minu = D[u], u
        U.remove(minu)
        for i in range(1, n):
            D[i] = min(D[i], D[minu] + W[minu][i])

    return D

lines = sys.stdin.readlines()
n = int(lines.pop(0))

W = [[200001] * n for _ in range(n)]
for line in lines:
    l = map(int, line.split())
    for i in range(l[1]):
        W[l[0]][l[2 * i + 2]] = l[2 * i + 3]

D = dijkstra(W, n)

for i in range(n):
    print i, D[i]

Measured memory_bytes: 6484
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  string s;
  cin >> s;
  char c = s[0];
  ll ans = 0;
  for (int i = 1; i < s.size(); i++) {
    if(c!=s[i]){
      ans++;
      c = s[i];
    }
  }
  cout << ans << endl;
}

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


def resolve():
    N = int(_input())
    t, x, y = 0, 0, 0
    for _ in range(N):
        next_t, next_x, next_y = map(int, _input().split())
        diff_xy = abs(x - next_x) + abs(y - next_y)
        diff_t = next_t - t
        if diff_xy > diff_t or (diff_xy % 2 != diff_t % 2):
            print('No')
            exit(0)
    print('Yes')


if __name__ == '__main__':
    resolve()

Measured memory_bytes: 3060
#include <iostream>

const int days[12]={31,29,31,30,31,30,31,31,30,31,30,31};
const std::string str[7]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};

int m2d(int month)
{
	if(month==0)
		return 0;
	return days[month-1] + m2d(month-1);
}

int main(void)
{
	int m,d;
	while(true)
	{
		std::cin >> m >> d;
		if(!m)
			break;

		std::cout << str[(m2d(m-1)+d+4-1)%7] << std::endl;
	}
	return 0;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N;
std::string S[100100];

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

  std::cin >> N;

  for(int i=0;i<N;++i){
      std::cin >> S[i];

      std::sort(S[i].begin(), S[i].end());
  }

  std::sort(S, S + N);

  ll res = 0;

  for(int i=0,j=1;i<N;){
      while(j < N && S[j] == S[i]){
          j += 1;
      }
      
      int n = j - i;

      res += 1ll * (n - 1) * n / 2;

      i = j;
      j += 1;
  }

  std::cout << res << std::endl;
}


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

typedef long long ll;

int main() {
	ll s, c;
	cin >> s >> c;
	if (c <= 2 * s) {
		cout << c / 2 << endl;
	} else {
		cout << s + (c - 2 * s) / 4 << endl;
	}
}

Measured memory_bytes: 3528
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
using namespace std;
constexpr int64_t MOD = 1e9 + 7;

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

  int32_t K, N;
  cin >> K >> N;
  vector<int> dist(N);
  for (auto& d : dist) {
    cin >> d;
  }
  int64_t max_diff = 0;
  int64_t prev = dist[N-1] - K;
  for (auto d : dist) {
    int64_t diff = d - prev;
    max_diff = max(max_diff, diff);
    prev = d;
  }
  cout << K - max_diff << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef pair<ul, ul> P;

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

int main(){
    int N;
    int p[60], sortP[60];

    cin >> N;
    rep(i,N){
        int a;
        cin >> a;

        p[i] = a;
        sortP[i] = a;
    }
    sort(sortP, sortP + N);

    int falseCounter = 0;
    rep(i,N){
        if(sortP[i] != p[i]) falseCounter++;
    }

    if(falseCounter == 2 || falseCounter == 0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
n = int(input())
b = list(map(int,input().split()))

a = [0 for _ in range(n)]

for i in range(n-1):
    if i == 0:
        a[i] = b[i]
        a[i+1] = b[i]
    if b[i] < b[i-1] and i > 0:
        a[i] = b[i]
        a[i+1] = b[i]
    elif b[i] >= b[i-1] and i > 0:
        a[i+1] = b[i]

print(sum(a))


Measured memory_bytes: 9112
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

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

    set<pair<int,int>> setL;
    int ans=0;
    rep(n,0,N){
        int a; cin>>a;
        pair<int,int> love,loved;
        love=make_pair(n+1,a);
        loved=make_pair(a,n+1);

        if(setL.count(loved)){setL.erase(loved); ans++;}
        else setL.insert(love);
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 4992
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use proconio::*;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let s: String = read!();
    let mut ans = 0;

    if s.contains("R") {
        ans += 1;
    }

    if s.contains("RR") {
        ans += 1;
    }

    if s.contains("RRR") {
        ans += 1;
    }

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


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

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  ll ans = 0;
  for (int l = 0, r = 0, x = 0; l < n; ++l) {
    while (r < n && (x & a[r]) == 0) x |= a[r++];
    ans += r - l;
    x &= ~a[l];
  }
  cout << ans;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = ReadInt();
            var b = ReadInt();
            WriteLine(6 - a - b);
        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11092
import java.util.Scanner;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        long A = 0;
        long ANS = 0;
        long ans = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            A += a[i];
            if (i % 2 == 0 && A <= 0) {
                ans += Math.abs(A - 1);
                A = 1;
            }
            if (i % 2 == 1 && A >= 0) {
                ans += Math.abs(A + 1);
                A = -1;
            }
        }
        ANS = ans;
        A = 0;
        ans = 0;
        for (int i = 0; i < n; i++) {
            A += a[i];
            if (i % 2 == 0 && A >= 0) {
                ans += Math.abs(A + 1);
                A = -1;
            }
            if (i % 2 == 1 && A <= 0) {
                ans += Math.abs(A - 1);
                A = 1;
            }
        }
        ANS = Math.min(ANS, ans);
        System.out.println(ANS);
    }
}


Measured memory_bytes: 50984
A,B,C,X,Y=[int(x) for x in input().split(' ')]

cmin=max([X,Y])
lis=[]
for i in range(cmin+1):
	i_c=i*2
	i_a, i_b=X-i,Y-i
	# print(i_a,i_b,i_c)
	if i_a>=0 and i_b>=0:
		lis.append(i_c*C+i_b*B+i_a*A)
	if i_a<0:
		if i_b<0:
			lis.append(i_c*C)
		else:
			lis.append(i_c*C+i_b*B)
	elif i_b<0:
		lis.append(i_c*C+i_a*A)


print(min(lis))


Measured memory_bytes: 7064
use std::io;
use std::str::FromStr;
use std::cmp;


fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn two(mut x: u32) -> u32 {
    let mut count = 0;
    loop {
        if x % 2 == 0 {
            x = x / 2;
            count = count + 1;
        }
        else {
            break;
        }
    }
    count
}

fn main(){
    let n:u32 = read_line().trim().parse().unwrap();
    let num:Vec<u32> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let mut sum = 0;
    for i in num {
        sum = sum + two(i);
    }
    println!("{}", sum);
}


Measured memory_bytes: 4352
def main():
    x = int(input())
    
    if x ==1:
        print(1,0)
        return
    for i in range(-1000,1000):
        for j in range(-1000,1000):
          if i**5 - j**5 == x:
            print(i,j)
            return

if __name__ == "__main__":
    main()

Measured memory_bytes: 64540
#include<iostream>
#include<fstream>
using namespace std;
int n;
long long dp[1005][1005];
long long slimes[100005];
long long p[100005];
void init()
{
    for(int i = 0; i <= n; i++)
        for(int j = 0; j <= n; j++)
            dp[i][j] = 10000000000006;
    //for(int i = 0; i <= n; i++)
      //  slimes[i] = 0;
}
void prelucrare();
void read()
{
    cin >> n;
    init();
    for(int i = 1; i <= n; i++)
    {
        dp[i][i] = 0;
        cin >> slimes[i];
        p[i] = p[i-1] + slimes[i];

    }
    prelucrare();
}
void prelucrare()
{
    for(int i = 1; i+ 1 <= n ; i++)
        for(int j = 1; i + j  <= n; j++)
        {
            int x = i + j;
            for(int k = j; k < x; k++)
            {
                if(dp[j][x] > dp[j][k] + dp[k + 1][x] + p[x] - p[j - 1])
                    dp[j][x] = dp[j][k] + dp[k + 1][x] + p[x] - p[j - 1];
            }
        }
}
void show()
{
    cout << dp[1][n];
}
int main()
{
read();
show();
}

Measured memory_bytes: 4736