akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define REV(s) (s).rbegin(), (s).rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

int main(){
	int n;
	while(cin >> n, n){
		bool ok = false;
		int ans = 1;
		rep(i, n){
			int k;
			cin >> k;
			if(k >= 1) ++ans;
			if(k >= 2) ok = true;
		}
		if(ok) cout << ans << endl;
		else cout << "NA" << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <set>

int main() {
    int A, B, C;

    std::cin >> A >> B >> C;

    std::set<int> a;
    a.insert(A);
    a.insert(B);
    a.insert(C);

    if (a.size() == 2) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define dd double
#define endl "\n"
#define pb push_back
#define all(v) v.begin(),v.end()
#define mp make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pll pair<ll,ll>
#define fo(i,n) for(int i=0;i<n;i++)
#define fo1(i,n) for(int i=1;i<=n;i++)
ll mod=1000000007;
ll n,k,t,m,q,flag=0;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(a) -- no. of elements strictly less than a
// s.find_by_order(i) -- itertor to ith element (0 indexed)
ll min(ll a,ll b){if(a>b)return b;else return a;}
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll gcd(ll a , ll b){ if(b > a) return gcd(b , a) ; if(b == 0) return a ; return gcd(b , a%b) ;}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #ifdef NOOBxCODER
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #else 
    #define NOOBxCODER 0
    #endif
    //cin>>t;
    t=1;
    while(t--){
        ll a,b,c;
        cin>>a>>b>>c>>k;
        ll ans=0;
        while(b<=a){b*=2; ans++;}
        while(c<=b){c*=2; ans++;}
        if(ans<=k)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;





        
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}


Measured memory_bytes: 3744
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e18
typedef long long ll;
typedef pair<int,int> P;



int main(void){
    int n,a,b,c,d;
    string s;
    cin>>n>>a>>b>>c>>d;
    cin>>s;
    if(c<d){
        for(int i=b-1;i<d-1;i++){
            if(s[i]=='#'){
                if(s[i+1]=='#'){
                    cout<<"No"<<endl;
                    return 0;
                }
            }
        }
        for(int i = a-1;i<c-1;i++){
            if(s[i]=='#'){
                if(s[i+1]=='#'){
                    cout<<"No"<<endl;
                    return 0;
                }
            }
        }
        cout<<"Yes"<<endl;
    }
    else{
        for(int i=b-1;i<d-1;i++){
            if(s[i]=='#'){
                if(s[i+1]=='#'){
                    cout<<"No"<<endl;
                    return 0;
                }
            }
        }
        for(int i = a-1;i<c-1;i++){
            if(s[i]=='#'){
                if(s[i+1]=='#'){
                    cout<<"No"<<endl;
                    return 0;
                }
            }
        }
        int len = 0;
        bool can = false;
        for(int i=b-1;i<=d-1;i++){
            if(i+1>n)continue;
            if(s[i-1]=='.'){
                if(s[i]=='.'){
                    if(s[i+1]=='.'){
                        can = true;
                        break;
                    }
                }
            }
        }
        if(can){
            cout<<"Yes"<<endl;
        }
        else cout<<"No"<<endl;
    }
	return 0; 
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <sstream>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <map>
#include <climits>
#include <bitset>
using namespace std;
#define MATH_PI 3.14159265358979323846
int main(){
	ios::sync_with_stdio(false);
	int a, b, c;
	cin >> a >> b >> c;
	cout << (a + c == 2 * b ? "YES\n" : "NO\n");
endapp:
	//system("pause > nul");
	return 0;
}

Measured memory_bytes: 256
inf = input().split()
N = int(inf[0])
M = int(inf[1])
ls = [[] for i in range(N)]
state = [0 for i in range(M)]
count = 0
log = []

for i in range(M):
    line = input().split()[1:]
    for a in line:
        ls[int(a)-1] += [i]

rule = [int(i) for i in input().split()]

for n in range(2**N):
    s = n
    for m in range(N)[::-1]:
        if n>=(2**m):
            n -= 2**m
            for i in ls[m]:
                state[i] += 1
    for i in range(M):
        if not state[i]%2 == rule[i]:
            break
    else:
        count += 1
    state = [0 for i in range(M)]
print(count)


Measured memory_bytes: 3064
import java.util.Scanner;

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

    double a = scan.nextDouble();

 System.out.println(String.format("%.6f",a * a * Math.PI)+" "+String.format("%.6f",2 * a * Math.PI));
  }
}


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

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

int main()
{
    ll i,j;
    ll h,w,m;
    cin >> h >> w >> m;
    map<pair<ll,ll>,ll> mp;
    vector<ll> hh(h,0);
    vector<ll> ww(w,0);
    rep(i,m){
        ll th, tw;
        cin >> th >> tw;
        --th, --tw;
        ++hh.at(th);
        ++ ww.at(tw);
        mp[make_pair(th, tw)]++;
    }

    ll maxh = -1;
    rep(i,h){
        maxh = max(maxh, hh.at(i));
    }
    vector<ll> listh;
    rep(i,h){
        if(hh.at(i) == maxh) listh.push_back(i);
    }

    ll maxw = -1;
    rep(i,w){
        maxw = max(maxw, ww.at(i));
    }
    vector<ll> listw;
    rep(i,w){
        if(ww.at(i) == maxw) listw.push_back(i);
    }
    
    for(i = 0;i < listh.size();++i){
        for(j = 0;j < listw.size();++j){
            if(mp.count(make_pair(listh.at(i), listw.at(j)))) continue;
            else{
                cout << hh.at(listh.at(i)) + ww.at(listw.at(j)) << endl;
                return 0;
            }
        }
    }
    cout << hh.at(listh.front()) + ww.at(listw.front()) - 1 << endl;

    return 0;
}

Measured memory_bytes: 34896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
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; }

int main(){
  ll n;
  cin >> n;
  vi a(n);
  rep(i,n){
    cin >> a[i];
  }
  sort(all(a));
  print(a[n-1]-a[0]);
}

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

#define N 101
#define BLACK 200
#define WHITE 201
#define GRAY 202
void BFS(int);
void Enqueue(int);
int Dequeue();

int t =0,num = 0,head =0,tail =0,save=0,change=1000000;
int d[N],color[N],num4[N][N];
int Q[N];

int main(){
  int i,j,num2,num3,num5,flag;
  scanf("%d",&num);
 
  for(i=1;i<=num;i++){
    for(j=1;j<=num;j++){
      num4[i][j] = 0;
    }
  }
 
   for(i=1;i<=num;i++){
     scanf("%d",&num5);
     save = num5;
     if(save < change) change = save;

     scanf("%d",&num2);
     if(num2 == 0)continue;  
     else{
       for(j=0;j<num2;j++){
	 scanf("%d",&num3);
	 num4[i][num3] = 1;  
       }
     }    
   }


  
     BFS(change);  //i=min ???? 
   


   for(i=1;i<=num;i++){
     if(d[i]==1000000000){
       d[i] = -1;
}

     printf("%d %d\n",i,d[i]);
     }
      
   
   return 0;
}


void BFS(int s){
  int i,v,Q;
  for(i=1;i<=num;i++){
    color[i]=WHITE;
    d[i]=1000000000;
  }
  color[s] =GRAY;
  d[s] = 0;
  
  Enqueue(s);
  
  while(head !=tail){
    i = Dequeue();
    for(v=1;v<=num;v++){

      if(color[v] == WHITE && num4[i][v] == 1){

	color[v] = GRAY;
	d[v] =d[i] + 1;
       	Enqueue(v);
      } 
    }
 
    color[i] = BLACK;
 }
  
}

void Enqueue(int x){

  Q[tail] = x;
  tail++;

}

int Dequeue(void){

  int x;

  x = Q[head];
  head++;

  return x; 
}

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

#define pb push_back
#define ppp pop_back
#define fi first
#define se second
#define pii pair<int,int>

const int N = 1e5 + 5;

int a[N];
int b[500][N];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    int n;
    cin >> n;
    for (int i=1; i<N; i++) a[i] = 0;
    for (int k=2; k*(k-1)/2 < N; k++) a[k*(k-1)/2] = k;
    if (a[n]) {
        int k = a[n];
        for (int i=1; i<=k; i++) {
            for (int j=1; j<=n; j++) {
                b[i][j] = 0;
            }
        }
        int col = 1;
        for (int i=1; i<=k-1; i++) {
            for (int j=i+1; j<=k; j++) {
                b[i][col] = 1;
                b[j][col] = 1;
                col++;
            }
        }
        cout << "Yes\n";
        cout << k << "\n";
        for (int i=1; i<=k; i++) {
            cout << k-1 << " ";
            for (int j=1; j<=n; j++) {
                if (b[i][j]) cout << j << " ";
            }
            cout << "\n";
        }
    }

    else cout << "No\n";
    return 0;
}


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

using namespace std;
typedef long long ll;

const int N = 3010;
int n;
ll a[N];
ll dp[N][N][2];
bool vis[N][N][2];

ll solve(int l, int r, int t)
{
	if (l > r)
		return 0;
	ll &ret = dp[l][r][t];
	if (vis[l][r][t])
		return ret;
	vis[l][r][t] = true;
	if (t == 0)
	{
		ll val = max(a[l] + solve(l + 1, r, 1), a[r] + solve(l, r - 1, 1));
		ret = val;
	}
	else
	{
		ll val = min(-a[l] + solve(l + 1, r, 0), -a[r] + solve(l, r - 1, 0));
		ret = val;
	}
	return ret;
}

int main()
{
	ios_base::sync_with_stdio(false);

	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	memset(dp, -1, sizeof(dp));
	memset(vis, false, sizeof(vis));
	ll ans = solve(1, n, 0);
	cout << ans;

	return 0;
}

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

int main() {
    ll X;
    cin >> X;

    if (X == 2) {
        cout << 2 << endl;
        exit(0);
    }
    
    while (true) {
        
        vector<ll> num(X-2);
        for (ll j=2; j<=X-1; j++) {
            num.at(j-2) = j;
        }
        // 素数判定---------------------
        ll count = 0;
        for (ll j=0; j<X-2; j++) {
            if (X%num.at(j)==0) {
                break;
            }
            else {
                count++;
                if (count == X-2) {
                    cout << X << endl;
                    exit(0);
                }
            }
        }
        X++;
    }
    
}

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

for i in range(3500):
  for j in range(3500):
    if(4*(i+1)*(j+1)-n*(i+1)-n*(j+1)!=0):
      hoge=n*(i+1)*(j+1)/(4*(i+1)*(j+1)-n*(i+1)-n*(j+1))
      if(hoge%1==0):
        if(0<=hoge and hoge<=3500):
          print(i+1,j+1,int(hoge))
          exit()

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

int32_t main()
{
	int h,w;
	cin>>h>>w;
	vector<vector<char> > grid(h, vector<char>(w));
	for(int i=0; i<h; i++)
		for(int j=0; j<w; j++)
			cin>>grid[i][j];
	vector<vector<int> > dp(h, vector<int> (w,0));
	dp[0][0]=1;
	bool flag=true;
	for(int i=1; i<h; i++)
		{
			if(flag&&grid[i][0]=='.')
				dp[i][0]=1;
			else
				{
					flag=false;
					dp[i][0]=0;
				}
		}
	flag=true;
	for(int i=1; i<w; i++)
		{
			if(flag&&grid[0][i]=='.')
				dp[0][i]=1;
			else
				{
					flag=false;
					dp[0][i]=0;
				}
		}
	for(int i=1; i<h; i++)
	{
		for(int j=1; j<w; j++)
		{
			if(grid[i][j]=='#')
				dp[i][j]=0;
			else
				dp[i][j]=((dp[i-1][j]%MOD)+(dp[i][j-1]%MOD))%MOD;
		}
	}	
	cout<<dp[h-1][w-1];
	return 0;
}


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

using namespace std;

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

ll gcd(ll a, ll b){
	return (b > 0LL ? gcd(b, a%b) : a);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N; cin >> N;
	vector<ll> T(N, 0LL);
	rep (i, N) cin >> T[i];
	sort(ALL(T));

	if (N == 1){
		cout << T[0] << endl;
	}else
	if (N == 2){
		ll g = gcd(T[0],T[1]);
		ll l = T[0] / g * T[1];
		cout << l << endl;
	}else{
		ll g = gcd(T[0],T[1]);
		ll l = T[0] / g * T[1];
		for (int i = 2; i < N; ++i){
			g = gcd(l, T[i]);
			l = T[i] / g * l;
		} // end for
		cout << l << endl;
	} // end if		
	
	return 0;
}

Measured memory_bytes: 256
# Input
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,m = li()
ab = []
for _ in range(m):
    ai, bi = li_()
    ab.append((ai, bi))

ab.sort(key=lambda x: x[1])

ans = 0
cur = -1
for ai, bi in ab:
    if ai >= cur:
        ans += 1
        cur = bi

print(ans)




Measured memory_bytes: 18200
#include <bits/stdc++.h>
using namespace std;
#define N_PRIME 1000000007
#define ll int64_t


int main(void){
    string s;
    cin >> s;
    if( s[0] == 'a' || s[0] == 'i' || s[0] == 'u' || s[0] == 'o' || s[0] == 'e' ){
        cout << "vowel" << endl;
    }else{
        cout << "consonant" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;
/*
*ios::sync_with_stdio(false);
*cin.tie(0);
*/

int main(){
  ll N,M,X;cin >> N >> M >> X;
  vector<ll> cost(N);
  vector<vector<ll>> a(N,vector<ll>(M));
  ll ans = infl;
  rep(i,N){
    cin >> cost[i];
    rep(j,M){
      cin >> a[i][j];
    }
  }


  for(ll bit=0;bit<(1<<N);bit++){
    vector<ll>sum(M,0);
    ll total = 0;
    for(ll i=0;i<N;i++){
      if(bit&(1<<i)){
        total +=cost[i]; 
        rep(j,M){
          sum[j] += a[i][j];
        }
      }
    }
    bool check = true;
    rep(i,M){
      if(sum[i] < X) {
        check = false;
        break;
      } 
    }
    if(check) chmin(ans,total); 
  }
  if(ans == infl) cout << -1 << endl;
  else cout << ans << endl;
}

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

#define all(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back

using namespace std;
// using namespace __gnu_pbds;


typedef long long int ll;
typedef pair<int, int> pii;

const int N = (int) 8080;
const double PI = acos(-1);
const double E = 1e-5;

void solve() {
    int d; cin >> d;
    double dt = d * PI / 180.0;
    double angle = dt;
    int ans = 1;
    double x = 0, y = 1;
    while(true) {
        if(abs(x) <= E && abs(y) <= E) break;
        x += sin(angle);
        y += cos(angle);
        angle += dt;
        ++ans;
    }
    cout << ans << endl;
}

int main() {
    // freopen("input.in", "r", stdin);
    // freopen("input.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    solve();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3980
n, k = map(int, input().split())
a_s = list(map(int, input().split()))
dp = [0] * (k + 1)
for i in range(k + 1):
    if dp[i] == 0:
        for a in a_s:
            ii = i + a
            if ii > k: break
            dp[ii] = 1
print("First") if dp[-1] else print("Second")


Measured memory_bytes: 3828
#include <atcoder/scc>;
#include <atcoder/convolution>
#include <atcoder/modint>
#include <atcoder/math>
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using namespace atcoder;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}
ll mod = 998244353;
int main() {
	ll n, m;
	cin >> n >> m;
	vector<ll> A(n);
	vector<ll> B(m);
	rep(i, n) {
		cin >> A.at(i);
	}
	rep(i, m) {
		cin >> B.at(i);
	}
	vector<ll> c = convolution(A, B);

	rep(i, n + m - 1) {
		cout << c.at(i)%mod <<" ";
	}
}

Measured memory_bytes: 27280
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());

typedef long long ll;

vector<int> d(0);
int n_max;

void yaku(int a,int n){
  if(a%n == 0){
    d.push_back(n);
    yaku(a/n,n);
  }
  else{
    if(n*n > n_max){
      if(a > 1) d.push_back(a);
      return;
    }
    yaku(a,n+1);
  }
}

int main(){
  int n;
  cin >> n;
  int ans = 0;
  for(int i=1;i<=n;i += 2){
    d = {};
    n_max = i;
    yaku(i,2);
    map<int,int> mp;
    for(int y : d){
      mp[y] ++;
    }
    int tmp = 1;
    for(auto p : mp){
      tmp *= (p.second+1);
    }
    if(tmp == 8) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    s = input().rstrip()
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            print(i+1, i+2)
            exit()
    for i in range(len(s)-2):
        if s[i]==s[i+2]:
            print(i+1, i+3)
            exit()
    print(-1, -1)

if __name__ == '__main__':
    main()

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

using namespace std;

void restore(int root, vector<vector<int>> &graph, vector<int> &tree){
  queue<int> q;
  q.push(root);
  
  while(!q.empty()){
    int node = q.front();
    q.pop();
    for(int child : graph[node]){
      tree[child]++;
      if(!tree[child]){
        tree[child] = node + 1;
        q.push(child);
      }
    }
  }
}

int main(){
  int N, M;
  cin >> N >> M;
  
  vector<int> tree(N, 0);
  vector<vector<int>> graph(N);
  
  for(int j = 0; j < N - 1 + M; j++){
    int A, B;
    cin >> A >> B;
    A--;
    B--;
    
    graph[A].push_back(B);
    tree[B]--;
  }
  
  int root;
  for(int i = 0; i < N; i++){
    if(!tree[i]){
      root = i;
      break;
    }
  }
  
  restore(root, graph, tree);
  
  for(int i = 0; i < N; i++){
    cout << tree[i] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 6656
#include<bits/stdc++.h>
using namespace std;
int main()
  {
  int n;
  cin>>n;
  if(n<1200)
    cout<<"ABC"<<endl;
  else if(n>=1200&&n<2800)
    cout<<"ARC"<<endl;
  else if(n>=2800)
    cout<<"AGC"<<endl;
    }

Measured memory_bytes: 3520
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#include<iomanip>//浮動小数点数を出力する制度の指定
//使い方　数値をnumとして　cout<<setprecision(n)<<num ;nは桁数
#define rep(i,n) for(int i = 0; i < (n);i++)
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
using namespace std;
using ll =long long;
using db = double;
#define INF 2000000000
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
/*覚えてないことメaモ
  数値型から文字列に変換　to_string(number);これは簡単
  文字列から数値型に変換　stoi(number)
  文字列からllに変換　stoll(number)
  __gcd(a,b)は最大公約数を取ってくれる、aとb
  の大きい方をNとしたとき、計算量は√N
 */

//ここから書き始める
int main(){
	int a,b,t;
	cin >> a>> b >> t;
	int times = t / a;
	cout << times * b << endl;

}



Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	for(;;){
	int H, W;
	scanf("%d %d", &H, &W);
	if(H==0 && W==0) break;

	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if((i%2==0 && j%2!=0) ||(i%2!=0&&j%2==0))
				printf(".");
			else
				printf("#");
		}
		printf("\n");
	}
	printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2044
mod = 10**9 + 7
def iip(listed = False):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def inv(n, mod):
    return power(n, mod-2)

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret

n = iip()
A = iip(listed=True)

def main():
    ss = []
    for a_i in A:
        for s in ss:
            if a_i % s == 0:
                a_i //= s

        ss.extend(soinsuu_bunkai(a_i))

    #print(ss)
    all = 1
    for s in ss:
        all *= s
        all %= mod

    ans = 0
    for a_i in A:
        ans += (all * inv(a_i, mod)) % mod
        ans %= mod
    print(ans)


main()

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n; 
  cin>>n;
  long long int arr[n];
  for (int i=0; i<n; i++) cin>>arr[i];
  sort(arr, arr+n);
  long long int comfort = arr[n-1];
  int ptr = n-2, ctr = 0;
  for (int i=n-2; i>=1; i--) {
    comfort += arr[ptr];
    ctr++;
    if (ctr == 2) {
      ctr = 0;
      ptr--;
    }
  }
  cout<<comfort<<'\n';
}

Measured memory_bytes: 5224
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define repds(i, n) for (int i = (n); i > 0; --i)
#define loop(i, x, n) for (int i = (x); i < (n); ++i)
#define loops(i, x, n) for (int i = (x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (x); i > (n); --i)
#define loopds(i, x, n) for (int i = (x); i >= (n); --i)
#define itrep(i, a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i, a) for (auto i = rbegin(a); i != rend(a); ++i)
#define each(i, x) for (auto &&i : x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(a) ((int)a.size())
#define pow2(n) (n * n)
#define int ll
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
using priority_queuel = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-9;
ll mod = static_cast<ll>(1e9 + 7);
template <class T, class... Args>
constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); }
template <class T, class... Args>
constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); }
template <class F>
class FixPoint : private F {
public:
    explicit constexpr FixPoint(F &&f) : F(std::forward<F>(f)) {}
    template <class... Args>
    constexpr decltype(auto) operator()(Args &&... args) const { return F::operator()(*this, std::forward<Args>(args)...); }
};
template <class F>
constexpr decltype(auto) funcs(F &&f) { return FixPoint<F>{std::forward<F>(f)}; }
template <class T>
std::vector<T> vecs(int n, T &&val) { return std::vector<T>(std::forward<int>(n), std::forward<T>(val)); }
template <class... Args>
decltype(auto) vecs(int n, Args &&... args) { return std::vector<decltype(vecs(std::forward<Args>(args)...))>(std::forward<int>(n), vecs(std::forward<Args>(args)...)); }
template <class V, class T>
void fill(V &x, const T &val) { x = val; }
template <class V, class T>
void fill(vector<V> &vec, const T &val) {
    for (auto &&v : vec)
        fill(v, val);
}

void solve() {
    int n;
    cin >> n;
    n += 1;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    vector<int> val(n);
    repd(i, n) {
        if (i < n - 1) val[i] += val[i + 1];
        val[i] += a[i];
    }

    int ans = 0;
    rep(i, n) {
        if (i == 0)
            val[i] = 1;
        else
            mins(val[i], (val[i - 1] - a[i - 1]) * 2);
        if ((i == n - 1 && val[i] < a[i]) || (i < n - 1 && val[i] < a[i])) {
            cout << -1 << endl;
            return;
        }
        ans += val[i];
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout.flush();
    return 0;
}

Measured memory_bytes: 4792
import sys
sys.setrecursionlimit(10 ** 7)
class Tree:
  C, RL = {}, {}
  R, N, D, S, P, T = None, None, None, None, None, None
  TL = None
  def __init__(s, num):
    s.N = num
  def set(s, a, b):
    if a in s.C: s.C[a].append(b)
    else: s.C[a] = [b]
    if b in s.C: s.C[b].append(a)
    else: s.C[b] = [a]
  def makeRank(s, root):
    s.R = [0] * s.N #各ノードのランク
    s.R[root] = 1
    s.RL[1] = [root] #各ランクのノード
    s.S = {} #各ノードの子ノード
    s.P = [-1] * s.N #各ノードの親ノード
    F = [root]
    s.D = 2
    while F != []:
      Ft = []
      s.RL[s.D] = []
      for i in F:
        for j in s.C[i]:
          if s.R[j] == 0:
            s.R[j] = s.D
            Ft.append(j)
            s.RL[s.D].append(j)
            if i not in s.S:
              s.S[i] = [j]
            else:
              s.S[i].append(j)
            s.P[j] = i
      s.D += 1
      F = Ft
  def dfs(s, x, y, r): #xからyまでの道O(M)
    if x == y:
      return [x]
    for i in s.C[x]:
      if i != r:
        t = s.dfs(i, y, x)
        if t != False:
          return [x] + t
    return False
  def dist(s, x): #最遠のノード,距離
    t = [-1] * s.N
    S = [x]
    ans = x
    ansn = 0
    t[x] = 0
    while S != []:
      k = S.pop()
      for i in s.C[k]:
        if t[i] == -1:
          t[i] = t[k] + 1
          S.append(i)
          if t[i] > ansn:
            ansn = t[i]
            ans = i
    return ans, ansn
  def getDi(s, x = 0): #直径
    a, _ = s.dfs(x)
    b, ans = s.dfs(a)
    return ans
  def getDeep(s, x): #xの子孫のうち一番深い深さ
    ans = 0
    if x in s.S:
      for i in s.S[x]:
        ans = max(ans, s.getDeep(i))
      return ans + 1
    else:
      return 0
  def getParent(s, x, n): #xのn世代前の親
    if n == 0:
      return x
    if s.P[x] == -1:
      return -n
    return s.getParent(s.P[x], n - 1)
  def abList(s):
    A = []
    B = []
    for i in range(s.N):
      if s.R[i] % 2 == 0:
        A.append(i)
      else:
        B.append(i)
    if len(A) > len(B):
      return [B, A]
    else:
      return [A, B]



N = int(input())
ab = [list(map(int, input().split())) for _ in range(N - 1)]

A = []
B = []
C = []

for i in range(1, N + 1):
  if i % 3 == 0:
    C.append(i)
  elif i % 3 == 1:
    A.append(i)
  else:
    B.append(i)

T = Tree(N)
for a, b in ab:
  a -= 1
  b -= 1
  T.set(a, b)

T.makeRank(0)

A, B = T.abList()

c = N // 3

Ans = [0] * N
if len(A) <= c:
  t = 3
  k = 1
  for i in A:
    Ans[i] = t
    t += 3
    c -= 1
  for i in range(N):
    if Ans[i] == 0:
      if c != 0:
        Ans[i] = t
        c -= 1
        t += 3
      else:
        Ans[i] = k
        k += 1
        if k % 3 == 0:
          k += 1
else:
  t = 3
  n = N // 3
  if N % 3 != 0:
    n += 1
  k = 1
  for i in range(n):
    Ans[A[i]] = k
    k += 3
  for i in range(n, len(A)):
    Ans[A[i]] = t
    t += 3
  n = N // 3
  if N % 3 == 2:
    n += 1
  k = 2
  for i in range(n):
    Ans[B[i]] = k
    k += 3
  for i in range(n, len(B)):
    Ans[B[i]] = t
    t += 3

print(" ".join(list(map(str, Ans))))


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

int main() {
    long long a, b, c, k;

    cin >> a >> b >> c >> k;

    if (k <= a) {
        cout << k << endl;
    }

    else if (a < k && k <= a + b) {
        cout << a << endl;
    }

    else {
        cout << 2 * a - k + b << endl;
    }
}

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

int main(){
  string s;
  cin >>s;
  int ans = 0;
  int cnt = 0;
  rep(i,s.size()){
    if(s[i]=='A' || s[i]=='T' || s[i]=='G' || s[i]=='C'){
      cnt++;
      ans = max(ans,cnt);
    }
    else cnt = 0;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	public static int INF = 1 << 24;
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int cost[][] = new int[n][n];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				cost[i][j] = stdIn.nextInt();
			}
		}
		long ans = 0; 
		for(int i = 0; i < n;i++) {
			for(int j = i+1; j < n; j++) {
				ans += Math.min(cost[i][j], cost[j][i]);
			}
		}
		System.out.println(ans);
	}
	
}

  

Measured memory_bytes: 31328
#include<stdio.h>
int main() {
  long s;
  int i,d,min=999;
  scanf("%ld",&s);
  for(i=0;i<8;i++){
    d=abs(s%1000-753);
    if(min>d) {
      min=d;
    }
    s/=10;
  }
  printf("%d",min);
}
  

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

#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;
const int INF = 2e18;
const int MOD = 1e9 + 7;
const int MB = 60;
const int maxN = 3001;

struct SegmentTree {
	vector<int> lazy, mx;
	int n;
	SegmentTree(int x) {
		n = x;
		lazy.resize(n << 2);
		mx.resize(n << 2);
	}

	int start, end, value;
	void update(int l, int r, int v) {
		start = l;
		end = r + 1;
		value = v;
		updateTree(1, 0, n);
	}

	int get(int v) {
		return mx[v] + lazy[v];
	}

	void push(int v, int vl, int vr) {
		mx[v] += lazy[v];
		lazy[vl] += lazy[v];
		lazy[vr] += lazy[v];
		lazy[v] = 0;
	}

	void updateTree(int v, int l, int r) {
		if (start <= l && r <= end) {
			lazy[v] += value;
			return;
		}

		int m = (l + r) >> 1;
		int vl = v << 1;
		int vr = vl + 1;

		push(v, vl, vr);

		if (start < m) updateTree(vl, l, m);
		if (m < end) updateTree(vr, m, r);

		mx[v] = max(get(vl), get(vr));
	}

	int res;
	int get(int l, int r) {
		start = l;
		end = r + 1;
		res = 0;
		getTree(1, 0, n);
		return res;
	}

	void getTree(int v, int l, int r) {
		if (start <= l && r <= end) {
			res = max(res, get(v));
			return;
		}

		int m = (l + r) >> 1;
		int vl = v << 1;
		int vr = vl + 1;

		push(v, vl, vr);

		if (start < m) getTree(vl, l, m);
		if (m < end) getTree(vr, m, r);

		mx[v] = max(get(vl), get(vr));
	}
};

void solve() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> del(n + 2), add(n + 2);
	vector<int> left(m), right(m), value(m);
	for (int i = 0; i < m; i++) {
		int l, r, v;
		cin >> l >> r >> v;
		left[i] = l;
		right[i] = r;
		value[i] = v;
		add[l].pb(i);
		del[r + 1].pb(i);
	}
	
	vector<int> dp(n + 1);
	int now = 0;
	SegmentTree tree(n + 1);

	for (int i = 1; i <= n; i++) {
		for (int j : add[i]) {
			now += value[j];
		}
		for (int j : del[i]) {
			tree.update(left[j], right[j], value[j]);
			now -= value[j];
		}
		dp[i] = tree.get(0, i - 1) + now;
		tree.update(i, i, dp[i] - now);
	}
	
	cout << *max_element(all(dp));
}

signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	solve();
}


Measured memory_bytes: 40960
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include "math.h"

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int N,Y;
vector <int > H;





int main()
{

	cin >> N >> Y;

	REP(i,N+1){
		REP(j,N+1){
			if(i+j>N) break;
			int k = N-(i+j);
			if(i*10000+j*5000+k*1000==Y){
				cout << i << " " << j << " " << k << endl;
				return 0;
			}
		}
	}

	cout << "-1 -1 -1" << endl;



}


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

int main(){
  int n,m,k;
  int a[31] = {};
  cin >> n >>m;
  for(int i=0;i<n;i++){
    int temp;
    cin >> temp;
    for(int j=0;j<temp;j++){
      int temp2;
      cin >> temp2;
    a[temp2]++;
    }
  }
  int ans = 0;
  for(int i=0;i<31;i++){
    if(a[i] == n)ans++;
  }
  cout << ans << endl;
  // for(int i=0;i<31;i++)cout  << " " << a[i] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <tuple>

const int Q = 37;

int main()
{
    std::vector<std::tuple<int, int, int>> ps;
    for (int x = 0; x < Q; ++ x) {
        for (int y = 0; y < Q; ++ y) {
            for (int z = 0; z < Q; ++ z) {
                if (x == 1 || (x == 0 && y == 1) || (x == 0 && y == 0 && z == 1)) {
                    ps.emplace_back(x, y, z);
                }
            }
        }
    }
    printf("%d %d\n", (int)ps.size(), Q + 1);
    for (auto p : ps) {
        bool first = true;
        for (int i = 0; i < (int)ps.size(); ++ i) {
            if ((std::get<0>(p) * std::get<0>(ps[i]) + std::get<1>(p) * std::get<1>(ps[i]) + std::get<2>(p) * std::get<2>(ps[i])) % Q == 0) {
                if (first) {
                    first = false;
                } else {
                    putchar(' ');
                }
                printf("%d", i + 1);
            }
        }
        puts("");
    }
}


Measured memory_bytes: 512
// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

typedef long long LL;
const int N = 1e5+50;
int n, m;
int a[N];
int main(int argc, char const *argv[]) {
    // code
    scanf("%d%d", &n, &m);
    int sum = 0;
    for (int i=0; i<n; ++i) {
        scanf("%d", &a[i]);
        sum += a[i];
    }
    int x = (sum + 4*m-1) / (4*m);
    int cnt = 0;
    for (int i=0; i<n; ++i) {
        if (a[i] >= x)
            ++cnt;
    }
    if (cnt >= m)
        puts("Yes");
    else
        puts("No");
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef pair<int,int> P;
vector<P> v[110];
bool vis[110];
priority_queue<P,vector<P>,greater<P> > Q;
int n,m;
int main(){
	while(cin>>n&&n){
	cin>>m;
	for(int i=0;i<n;i++){
		v[i].clear();
		vis[i]=false;
	}
	for(int i=0;i<m;i++){
		int a,b,c;char z;cin>>a>>z>>b>>z>>c;c=c/100-1;
		v[a].push_back(make_pair(c,b));
		v[b].push_back(make_pair(c,a));
	}
	Q.push(make_pair(0,0));int ans=0;
	while(!Q.empty()){
		int x=Q.top().first,y=Q.top().second;//y???x??§?????????
		Q.pop();
		if(vis[y])continue;vis[y]=true;ans+=x;
		for(int i=0;i<v[y].size();i++){
			Q.push(make_pair(v[y][i].first,v[y][i].second));
		}
	}
	cout<<ans<<endl;
	}
	return 0;
}

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

int index(int numToFind, std::vector<int> vectorToFindIn) {int len = vectorToFindIn.size();for (int i = 0; i < len; i++){if (vectorToFindIn[i] == numToFind){return i;}}return -1;}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int k,x;
	cin>>k>>x;
	for (int i=x-k+1;i<x+k;++i)
	{
		cout<<i<<" ";
	}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;

class Program
{
    static void Main()
    {
        new Magatro().Solve();
    }
}

class Magatro
{
    private int N, M;
    private int[] A;
    private int Count = 0;
    private int[] Map;
    private int[] C;

    private void Scan()
    {
        var line = Console.ReadLine().Split(' ');
        N = int.Parse(line[0]);
        M = int.Parse(line[1]);
        A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    }

    private void Q()
    {
        int x, y;
        var line = Console.ReadLine().Split(' ');

        x = int.Parse(line[0]);
        y = int.Parse(line[1]);
        int xx = A[x - 1];
        A[x - 1] = y;
        Map[xx]--;
        int p = xx - Map[xx];
        if (p >= 1)
        {
            C[p]--;
            if (C[p] == 0)
            {
                Count++;
            }
        }
        Map[y]++;
        int q = y - Map[y] + 1;

        if (q >= 1)
        {
            if (C[q] == 0)
            {
                Count--;
            }
            C[q]++;
        }
    }

    public void Solve()
    {
        Scan();
        Map = new int[N + 1];
        C = new int[N + 1];
        foreach (int i in A)
        {
            Map[i]++;
        }
        for (int i = 1; i <= N; i++)
        {
            for (int j = 0; j < Map[i]; j++)
            {
                int p = i - j;
                if (p >= 1)
                {
                    C[i - j]++;
                }
            }
        }
        for (int i = 1; i <= N; i++)
        {
            if (C[i] == 0)
            {
                Count++;
            }
        }

        var sb = new StringBuilder();

        for (int n = 0; n < M; n++)
        {
            Q();
            sb.AppendLine(Count.ToString());
        }
        Console.WriteLine(sb.ToString());
    }
}


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

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; }

using ll = long long;
using P = pair<int,int>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    int K,T;
    cin>>K>>T;
    vector<int> a(T);
    rep(i,T) cin>>a[i];
    sort(a.begin(),a.end());
    if(K-a[T-1]>=a[T-1]-1) cout<<0<<endl;
    else cout<<a[T-1]-1-K+a[T-1]<<endl;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m, p; cin >> n >> m >> p;
  vector<int> us(m), vs(m), ws(m);
  rep(i, m) {
    cin >> us[i] >> vs[i] >> ws[i]; us[i]--; vs[i]--; ws[i] -= p;
  }
  const ll inf = 1e18;
  vector<ll> dist(n, -inf);
  dist[0] = 0;
  rep(k, n*2) rep(i, m) if (dist[ us[i] ] != -inf) {
    if (dist[ vs[i] ] < dist[ us[i] ] + ws[i]) {
      if (k < n - 1) {
        dist[ vs[i] ] = dist[ us[i] ] + ws[i];
      } else {
        dist[ vs[i] ] = inf;
      }
    }
  }
  if (dist[n - 1] >= inf) {
    cout << -1 << endl;
  } else {
    cout << max(0LL, dist[n - 1]) << endl;
  }
}


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

int main()
{
	int H, W;
	cin >> H >> W;
	vector<string> s( H );
	for( int i = 0; i < H; i++ ) {
		cin >> s[i];
	}

	vector<vector<int>> dp( H, vector<int>( W, INT32_MAX / 2 ) );
	dp[0][0] = 0;
	if( s[0][0] == '#' ) dp[0][0] = 1;
	int dx[2] = { 0, 1 };
	int dy[2] = { 1, 0 };
	for( int y = 0; y < H; y++ ) {
		for( int x = 0; x < W; x++ ) {
			for( int i = 0; i < 2; i++ ) {
				int ny = y + dy[i];
				int nx = x + dx[i];
				if( ny >= H || nx >= W ) continue;
				int a = 0;
				if( s[y][x] == '.' && s[ny][nx] == '#' ) a = 1;
				dp[ny][nx] = min( dp[ny][nx], dp[y][x] + a );
			}
		}
	}
	int ans = dp[H - 1][W - 1];

	cout << ans << endl;
}


Measured memory_bytes: 3680
#include<stdio.h>
int main(void)
{
	int a,i,s,ss,sss;
	for(i=0;i<4;i++){
		scanf("%d",&a);
		s+=a;
	}
	ss=s/60;
	sss=s%60;
	printf("%d\n",ss);
	printf("%d\n",sss);
	return 0;
}

Measured memory_bytes: 1024
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
ll solve(ll a, ll b){
    //cout << a << " " << b << endl;
    ll res = 0;
    res += b * (a / b) * 2;
    if(a % b == 0) return res - b;
    res += solve(max(a % b, b), min(a % b, b));
    return res;
}
int main(void){
    ll n, x;
    cin >> n >> x;

    ll ans = n;

    ans += solve(max(n - x, x), min(n - x, x));

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<set>
#include<stdlib.h>
#include<algorithm>
using namespace std;
typedef long long int lli;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    lli t, n, i, ans, x, m, y, j, cnt;
    cin >> n >> t;
    cout << n-t+1 << endl;
    return 0;
}

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

using namespace std;

typedef long long llint;

const int MAXN = 200005;
const llint INF = 1000000000000000000LL;

llint n, m, ofs = 1, sol;
llint dp[MAXN];
vector < pair <llint, llint> > lef[MAXN], rig[MAXN];

struct cvor {
    llint mx, prop;
} t[4*MAXN];

void propagate (int x) {
    if (t[x].prop == 0) return;
    t[x].mx += t[x].prop;
    if (x < ofs) {
        t[2*x].prop += t[x].prop;
        t[2*x+1].prop += t[x].prop;
    }
    t[x].prop = 0;
}

void update (int x, int from, int to, int low, int high, llint val) {
    propagate(x);
    if (to < low || high < from) return;
    if (from <= low && high <= to) {
        t[x].prop += val;
        propagate(x);
        return;
    }
    update(2*x, from, to, low, (low+high)/2, val);
    update(2*x+1, from, to, (low+high)/2+1, high, val);
    t[x].mx = max(t[2*x].mx, t[2*x+1].mx);
}

llint upit (int x, int from, int to, int low, int high) {
    propagate(x);
    if (to < low || high < from) return -INF;
    if (from <= low && high <= to) return t[x].mx;
    return max(upit(2*x, from, to, low, (low+high)/2), upit(2*x+1, from, to, (low+high)/2+1, high));
}

void sweep () {
    llint curr = 0;
    for (int i=1; i<=n; i++) {
        for (int j=0; j<lef[i].size(); j++) {
            llint rr = lef[i] [j].first, cost = lef[i] [j].second;
            update(1, i, rr, 0, ofs-1, -cost);
            curr += cost;
        }
        for (int j=0; j<rig[i].size(); j++) {
            llint ll = rig[i] [j].first, cost = rig[i] [j].second;
            update(1, ll, i-1, 0, ofs-1, cost);
            curr -= cost;
        }
        dp[i] = upit(1, 0, i-1, 0, ofs-1) + curr;
        update(1, i, i, 0, ofs-1, dp[i]);
        sol = max(sol, dp[i]);
    }
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    while (ofs < n+2) ofs *= 2;
    for (int i=0; i<m; i++) {
        int l, r, c;
        cin >> l >> r >> c;
        lef[l].push_back(make_pair(r, c));
        rig[r+1].push_back(make_pair(l, c));
    }
    sweep();
    cout << sol;
    return 0;
}


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

int main(){
    double r; cin >> r;
    printf("%.10lf\n", 2*M_PI*r);

    return 0;
}

Measured memory_bytes: 3772
#include<stdio.h>
int main(){
char a,b,c;
scanf("%c%c%c",&a,&b,&c);
int price = 700;
if(a == 'o') price += 100;
if(b == 'o') price += 100;
if(c == 'o') price += 100;
printf("%d",price);
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    int n;
    cin >> n;
    unordered_set<string> set;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        set.insert(s);
    }
    cout << set.size() << endl;
}


Measured memory_bytes: 17596
#include <bits/stdc++.h>
#define ll long long


using namespace std;



int main() {
    //fstream cin("A.in");
    //ofstream cout("A.out");
    int n;
    ios::sync_with_stdio(false);
    cin >> n;
    if(n / 100 == n % 10)
        cout << "Yes";
    else
        cout << "No";
    //cin.close();
    //cout.close();
    return 0;
}


Measured memory_bytes: 256