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

template<typename T>
struct Segtree {
    int n, n_org;
    T e;
    vector<T> dat;
    typedef function<T(T a, T b)> Func;
    Func f;

    Segtree(){}
    Segtree(int n_input, Func f_input, T e_input){
        initialize(n_input, f_input, e_input);
    }
    void initialize(int n_input, Func f_input, T e_input){
        n_org = n_input;
        f = f_input;
        e = e_input;
        n = 1;
        while(n < n_input) n <<= 1;
        dat.assign(2*n-1, e);
    }

    void build(vector<T>& A){
        for(int k=0; k<int(A.size()); k++) dat[k+n-1] = A[k];
        for(int k=n-2; k>=0; k--) dat[k] = f(dat[2*k+1], dat[2*k+2]);
    }

    void update(int k, T a){
        k += n - 1;
        dat[k] = a;
        while(k > 0){
            k = (k - 1)/2;
            dat[k] = f(dat[2*k+1], dat[2*k+2]);
        }
    }

    T get(int k){
        return dat[k+n-1];
    }

    void add(int k, T a){
        update(k, get(k) + a);
    }

    T between(int a, int b){
        return query(a, b+1, 0, 0, n);
    }

    T query(int a, int b, int k, int l, int r){
        if(r<=a || b<=l) return e;
        if(a<=l && r<=b) return dat[k];
        T vl = query(a, b, 2*k+1, l, (l+r)/2);
        T vr = query(a, b, 2*k+2, (l+r)/2, r);
        return f(vl, vr);
    }
};

int main(){
    int H, W, M;
    cin >> H >> W >> M;
    const int Z = 300000;
    vector<vector<int>> X2Y(Z);
    vector<int> numX(Z), numY(Z);
    for(int i=0; i<M; i++){
        int x, y;
        cin >> x >> y;
        x--; y--;
        X2Y[x].push_back(y);
        numX[x]++;
        numY[y]++;
    }

    Segtree<int> st(Z, [](int a, int b){ return max(a, b); }, 0);
    st.build(numY);

    int ans = 0;
    for(int x=0; x<Z; x++){
        for(int y : X2Y[x]) st.add(y, -1);
        ans = max(ans, numX[x] + st.dat[0]);
        for(int y : X2Y[x]) st.add(y, 1);
    }

    cout << ans << endl;
    return 0;
}


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

typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi> vii;

typedef long long ll;

#define F first
#define S second

#define ERR 1e-9

#if !ONLINE_JUDGE && !EVAL
    #define dbg_var(x) cerr << #x << ": " << x << "\n";
    #define dbg_iter(x, y) cerr  << #x << ": " << print_iterable(x, y) << "\n";
#else
    #define dbg_var(x)
    #define dbg_iter(x, y)
#endif // ONLINE_JUDGE

template <typename T1, typename T2>
string print_iterable( T1 begin_iter, T2 end_iter){
    bool first = true;
    stringstream res;
    res << "[ ";
    for(; begin_iter != end_iter; ++begin_iter){
        if(!first) res << ", ";
        first = false;
        res << *begin_iter;
    }
    res << " ]";
    return res.str();
}

void aggMax(int & res, int x){ if(x > res)res = x; }
void aggMin(int & res, int x){ if(x < res)res = x; }

int II(){ int i; cin >> i; return i; }
void OI(int i){ cout << i; }

// constraints
#define MAXN 1000000

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s;
    cin >> s;

    int anno = stoi(s.substr(0,4)), mese = stoi(s.substr(5, 2)), giorno = stoi(s.substr(8, 2));

    if(anno != 2019){
        cout << (anno < 2019 ? "Heisei" : "TBD");
    }else if(mese != 4){
        cout << (mese < 4 ? "Heisei" : "TBD");
    }else{
        cout << (giorno <= 30 ? "Heisei" : "TBD");
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
#define rep(i,n) for(i=0;i<n;i++)
#define repl(k,n) for(k=0;k<n;++k)

int main() {
	string T,S;
	cin >> S >> T ;
	int i,j,k;
	int chain=0;
	int max=0;
	for (i = 0; i < S.size()-T.size()+1; i++) {
		k = i;
		for (j = 0; j < T.size(); j++) {
			if (S[k] == T[j]) {
				chain++;
			}
			k++;
		}
		if (max < chain)max = chain;
		chain = 0;
	}
	cout << T.size() - max;
	return 0;
}

Measured memory_bytes: 3616
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		ArrayList<Integer> result = new ArrayList<>();
		Scanner sc = new Scanner(System.in);

		String[] num = sc.nextLine().split(" ");

		for (int i = 0; i < num.length; i++) {
			if (num[i].matches("^[0-9]*$")) {
				result.add(Integer.parseInt(num[i]));
			} else {
				int num1 = result.get(result.size() - 2);
				int num2 = result.get(result.size() - 1);
				if (num[i].equals("+")) {
					result.set(result.size() - 2, num1 + num2);
				} else if (num[i].equals("-")) {
					result.set(result.size() - 2, num1 - num2);
				} else if (num[i].equals("*")) {
					result.set(result.size() - 2, num1 * num2);
				}
				result.remove(result.size() - 1);
			}
		}

		System.out.println(result.get(0));
	}
}


Measured memory_bytes: 26396
#include <iostream>

int main()
{
    int w,h,x,y,r;
    std::cin >> w >> h >> x >> y >> r;
    
    if(x+r>w || x-r<0 || y+r>h || y-r<0)
        std::cout << "No" << std::endl;
    else
        std::cout << "Yes" << std::endl;
}


Measured memory_bytes: 3100
N=int(input())
H=list(map(int,input().split()))
if N==1:
  print("Yes")
  exit()
for i in range(N-1):
  if H[i]-1<=H[i+1]:
    if i!=0:
      if H[i-1]<H[i]:
        H[i]-=1
  elif H[i]==H[i+1]:
    continue
  else:
    print("No")
    exit()
for i in range(N-1):
  if H[i]>H[i+1]:
    print("No")
    exit()
print("Yes")

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

signed main(){
  char A;
  cin>>A;
  if(isupper(A)){
    cout<<'A'<<endl;
  }else{
    cout<<'a'<<endl;
  }
  return 0;
}

Measured memory_bytes: 3560
# import sys
# import math #sqrt
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# import itertools
# import collections # deque
# from operator import itemgetter
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def main():
    n = int(input())
    k = int(input())
    x = list(map(int,input().split()))
    ans = 0
    for i in range(n):
        ans += min(x[i],abs(x[i]-k)) * 2
    print(ans)
    return

if __name__=='__main__':
    main()

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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define bit(n) (1<<(n))

#define out(x) cout<<(x)<<endl;
#define err(x) cerr<<(x)<<endl;
#define errr(x,y) cerr<<(x)<<" "<<(y)<<endl;

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

#define inf5 100002

int main(){
	int n, p[50] = {}, po[50] = {};
	cin >> n;
	rep(i, n) cin >> p[i];
	memcpy(po, p, sizeof(p));

	sort(p, p+n);

	int c = 0;
	rep(i, n){
		if (p[i] != po[i]){
			++c;
		}
	}

	if (c < 3) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int a = sc.nextInt();
                int b = sc.nextInt();
                int c = sc.nextInt();
                sc.close();
                boolean 遭難者 = true;
                for(int i = 0 ; i <= b ; i++){
                        if((a * i - c) % b == 0) 遭難者 = false;
                }
                if(遭難者) System.out.println("NO");
                else System.out.println("YES");
        }
}

Measured memory_bytes: 35700
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner stdIn = new Scanner(System.in);
		
		for (; ;) {
			int h = stdIn.nextInt();
			int w = stdIn.nextInt();
			
			if (h == 0 && w == 0) break;
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					if ((i + j) % 2 == 0) {
						System.out.print("#");
					} else {
						System.out.print(".");
					}
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}



Measured memory_bytes: 34940
AV = list(map(int,input().split()))
BW = list(map(int,input().split()))
T = int(input())

A = AV[0]
V = AV[1]
B = BW[0]
W = BW[1]

pos_A = A
pos_B = B

if A <= B:
    pos_B = B + T*W
    pos_A = A + T*V
    if pos_A >= pos_B:
        print('YES')
    else:
        print('NO')
else:
    pos_B = B - T*W
    pos_A = A - T*V
    if pos_A <= pos_B:
        print('YES')
    else:
        print('NO')

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

long long l,r;
int main(){
	scanf("%lld%lld",&l,&r);
	if(r-l+1>=2019)cout<<0<<endl;
	else{
		long long ans=2019;
		for(long long i=l;i<r;i++){
			for(long long j=i+1;j<=r;j++){
				ans=min(i*j%2019,ans);
			}
		}
		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 pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#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 repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
ll f(ll x){
	if(x==1) return 1;
  	return f(x/2)*2 + 1;

}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
  
	ll h;
  	cin >> h;
  	cout << f(h) <<endl;
 	
  	return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
ka = [list(map(int,input().split()))for i in range(N)]
count = [0]*(M+1)
ans = 0
for i in range(N):
    for k in range(1,ka[i][0]+1):
        count[ka[i][k]]+=1
for i in range(M+1):
    if count[i] == N:
        ans+=1
print(ans)

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

using namespace std;

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

int main (){
    int x, t;
    cin >> x >> t;

    if(x - t < 0){
        cout << 0 << endl;
    }else{
        cout << x - t << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<stack>
#include<queue>
using namespace std;

#define read(x) scanf("%d",&x)
#define readl(x) scanf("%lld",&x)
#define ll long long 
#define ull unsigned long long
#define MOD 998244353 
#define inf 2147483647

char s1[15],s2[15];

int main()
{
	scanf("%s",s1);
	scanf("%s",s2);
	for(int i=0;i<strlen(s1);i++)
	{
		if(s1[i]==s2[i]) continue;
		else {printf("No\n");return 0;}
	}
	printf("Yes\n");
	return 0;	
}


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

typedef long long ll;

using namespace std;

ll MAX = 1e9+1;
const int MOD = 1e9 + 7;

void solve() {
    int n;
    cin >> n;

    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    vector< vector< pair<ll,ll> > > dp(n+1, vector< pair<ll,ll> >(n+1, make_pair(LLONG_MAX,0)));
    // dp[i][j] ~ tuple of 1. min cost to combine a[i:j] 
    //                     2. size of current slime
    // dp[i][i] = (0, a[i])
    // dp[i][j].first = min{  dp[i][k].first + dp[k+1][j].first } for k = i ... j-1
    // update dp[i][j].second accordingly

    for (int level = 0; level < n; level++) {
        for (int i = 0; i < n-level; i++) {
            int j = i + level;
            if (level == 0)
                dp[i][j] = make_pair(0, a[i]);
            else {
                for (int k = i; k <= j-1; k++) {
                    ll lCost = dp[i][k].first;
                    ll lSize = dp[i][k].second;
                    ll rCost = dp[k+1][j].first;
                    ll rSize = dp[k+1][j].second;

                    ll total = lCost + rCost + lSize + rSize;
                    if (total < dp[i][j].first)
                        dp[i][j] = make_pair(total, lSize + rSize);
                }
            }
        }
    }

    //for (int i = 0; i < n; i++) {
    //    for (int j = 0; j < n; j++) {
    //        cout << dp[i][j] << " ";
    //    }
    //    cout << endl;
    //}
    cout.precision(20);
    cout << dp[0][n-1].first << endl;
}


int main() {
    solve();
	return 0;
}



Measured memory_bytes: 2816
/* * * * * * * * * * * **
*                      *
*	   saurabh8522	   *
*	  I will handle	   *
*		   it.		   *
*                      *
* * * * * * * * * * * **/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ld long double
#define zero(a) memset((a),0,sizeof((a)))
#define one(a) memset((a),1,sizeof((a)))
#define minus(a) memset((a),-1,sizeof((a)))
#define all(g) g.begin(),g.end()
#define ppb pop_back
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> //indexed_set;
typedef long long int ll;
#define MOD 1000000007
ll extgcd(ll a,ll b,ll& x,ll& y){if(b==0){x=1;y=0;return a;}else{int g=extgcd(b,a%b,y,x);y-=a/b*x;return g;}}
ll modpow(ll a,ll b,ll m) {ll res=1;a%=m;for(;b;b>>=1){if(b&1)res=res*a%m;a=a*a%m;}return res;}
ll numdigit(ll n){return floor(log10(n)) + 1;}
bool isPowerTwo (ll x) { return x && (!(x&(x-1))); } 
int  main(){
	FastRead;
	ll t=1;
	// cin>>t;
	while(t--){
		string s;
		cin>>s;
		map<int,int>mp;
		ll res=0;
		mp[0]++;
		ll rem=0,p=1;
		for(int i=s.size()-1;i>=0;i--){
			rem=(rem+(s[i]-'0')*p)%2019;
			res+=mp[rem];
			mp[rem]++;
			p=p*10%2019;
		}
		cout<<res<<endl;
	}
}

Measured memory_bytes: 3720
n = input().rstrip()
n_sp = list(map(int, list(n)))
dig  = len(n_sp)
odd = 0
 
if dig == 1:
    print(n_sp[0])

else:
    for i in range(1, dig, 2):
        odd += int("9" * i) - 10 ** (i-1) + 1
 
    if dig%2 == 1:
        odd += int(n) - 10 ** (dig-1) +1
 
    print(odd)

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

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
 
    string s;
    cin >> s;
  
std::string target = "?";     
std::string replacement = "D"; 
if (!target.empty()) {
  std::string::size_type pos = 0;
  while ((pos = s.find(target, pos)) != std::string::npos) {
    s.replace(pos, target.length(), replacement);
    pos += replacement.length();
  }
}
 
      cout << s << "\n";
    
  return 0;
}

Measured memory_bytes: 3784
import numpy as np
N = int(input())
T = list(map(int, input().split()))
V = list(map(int, input().split()))
T = [0, 0] + T + [0]
V = [0] + V + [0]
accT = np.cumsum(T)
INF = 10 ** 9

t2_max = accT[-1] * 2
speeds = np.ones(t2_max + 1) * INF
for t0, t1, v in zip(accT[:-1], accT[1:], V):
    sptmp = np.ones(t2_max + 1) * v
    sptmp[:t0 * 2] += np.arange(t0, 0, -0.5)
    sptmp[t1 * 2:] += np.arange(0, accT[-1] - t1 + 0.5, 0.5)
    speeds = np.minimum(speeds, sptmp)

ans = sum(speeds) / 2

print(ans)

Measured memory_bytes: 13840
#include<cstdio>
#include<algorithm>
#include<map>
#include<numeric>
#include<functional>

using namespace std;

typedef long long ll;

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

ll nCr[51][51];

int main(){
	nCr[0][0] = 1;
	rep(i, 50) rep(j, 50){ nCr[i + 1][j] += nCr[i][j]; nCr[i + 1][j + 1] += nCr[i][j]; }
	int n, a, b; scanf("%d %d %d", &n, &a, &b);
	ll v[50]; map<ll, int> c, u;
	rep(i, n){ scanf("%lld", &v[i]); c[v[i]]++; }
	sort(v, v + n, greater<ll>());
	rep(i, a) u[v[i]]++;
	double avg = (double)accumulate(v, v + a, 0LL) / a;
	printf("%.30f\n", avg);
	if(u.size() > 1) printf("%lld\n", nCr[c[v[a - 1]]][u[v[a - 1]]]);
	if(u.size() == 1) printf("%lld\n", accumulate(nCr[c[v[a - 1]]] + a, nCr[c[v[a - 1]]] + b + 1, 0LL));
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>

using namespace std;

int main(){

    int A,B,K;

    cin >> A >> B >> K;

    for(int i=0;i<K;++i){
        if(A+i>B){
            break;
        }else{
            cout << fixed << setprecision(20) << A+i << "\n";
        }
    }

    for(int i=0;i<K;++i){
        if(B-K+1+i>=A+K){
            cout << fixed << setprecision(20) << B-K+1+i << "\n";
        }
    }

}

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

string str;
int convert(char a){
    if(a == 'I') return 1;
    else if(a == 'V') return 5;
    else if(a == 'X') return 10;
    else if(a == 'L') return 50;
    else if(a == 'C') return 100;
    else if(a == 'D') return 500;
    else return 1000;
}
int main(){
    bool state=false;
    int a, b;
    int ans;
    int i;
    while(cin >> str){
        ans = 0;
        for(i=1;i<str.size();i++){
            a = convert(str[i-1]);
            b = convert(str[i]);
            if(a < b){
                ans+=b-a;
                i++;
            }else{
                ans+=a;
            }
        }
        if(i==str.size()){
            ans += convert(str[i-1]);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1180
/*input
0 2
*/

#include <bits/stdc++.h>
#define ll long long

using namespace std;

void run() {
	int n, m, ret=0;
	cin >> n >> m;
	ret = max(0, (n*(n-1))/2) + max(0, (m*(m-1))/2);
	cout << ret << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);		
	int t = 1;
	// cin >> t;
	while(t--) {
		run();
	}
}


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

struct Node{
  int key;
  struct Node *right, *left, *parent;
};

struct Node *root,*NIL;

void insert(int);
void inorder(struct Node *);
void preorder(struct Node *);
int search(struct Node *,int);

int main(){
  int m,i,z;
  char s[10];
  int *find,n;
  scanf("%d",&m);
  find = (int *)malloc(sizeof(int)*m);

  for(i=0; i<m; i++){
    scanf("%s",s);
    if(strcmp(s,"insert") == 0){
      scanf("%d",&z);
      insert(z);
    }
    else if(strcmp(s,"print") == 0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if(strcmp(s,"find") == 0){
        scanf("%d",&n);
        if(search(root,n) == 0) printf("yes\n");
        else printf("no\n");
    }
  }
  return 0;
}

void insert(int k){
  struct Node *y = NIL;
  struct Node *x = root;
  struct Node *z;

  z = (struct Node *)malloc(sizeof(struct Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while( x != NIL){
    y = x;
    if(z->key < x->key) {
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
  z->parent = y;
  if(y == NIL){
    root = z;
  }
  else{
    if(z->key < y->key ){
      y->left = z;
    }
    else {
      y->right = z;
    }
  }
}

void inorder(struct Node *u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(struct Node *u){
  if(u == NIL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int search(struct Node *u, int n){
    while(u != NULL){
        if(n == u->key) return 0;
        else if(n < u->key) u = u->left;
        else u = u->right;
    }
    return -1;
}

Measured memory_bytes: 19368
package main

import "fmt"

var (
	a, b, c int
)

func main() {
	fmt.Scan(&a, &b, &c)
	fmt.Println(a + b + c - max(a, b, c))
}

func max(x, y, z int) int {
	if x < y {
		if y < z {
			return z
		}
		return y
	}

	if x < z {
		return z
	}
	return x
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(){
    int n;
    long long a;
    long long minValue=1000000;
    long long maxValue=-1000000;
    long long sum=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        if(a<minValue)minValue=a;
        if(a>maxValue)maxValue=a;
        sum+=a;
    }
    cout<<minValue<<" "<<maxValue<<" "<<sum<<endl;
}

Measured memory_bytes: 3100
#include <stdio.h>
int main(void){
	
	long int n;
	long int a;
	long int b;
	scanf("%ld %ld %ld",&n,&a,&b);

	if((b-a)%2==0){
		printf("%ld",((b-a)/2));
	}else
	/*{
		if(b-1<n-a){
			printf("%ld",b-1);
		}else{
			printf("%ld",n-a);
		}
	*/
	{
		long int count=0;
		if(a-1<n-b){
			count+=a-1+1;
			count+=(b-a)/2;
			printf("%ld",count);
		}else{
			count+=n-b+1;
			count+=(b-a)/2;
			printf("%ld",count);
		}	
	}
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;

int main()
{
    int n, m, x;
    std::cin >> n >> m >> x;

    std::vector<bool> is_tall_gate(n + 1, false);

    for (int i = 0; i < m; i++) {
        int temp;
        std::cin >> temp;

        is_tall_gate[temp] = true;
    }

    std::cout << std::min(std::count(is_tall_gate.begin(), is_tall_gate.begin() + x, true), std::count(is_tall_gate.begin() + x, is_tall_gate.end(), true)) << std::endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] s = new int[n];
		int max = 0;
		int min = 1001;

		for (int i=0; i<n; i++){
			s[i] = sc.nextInt();
			if (s[i] >= max){
				max = s[i];
			}
			if (s[i] <= min){
				min = s[i];
			}
		}

		System.out.println(max-min);

	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>

using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i, n) for(int i = 0; i < n; i++)


int main() {
    string s, t, u;
    int a, b;
    
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;

    if (u == s) cout << a-1 << " " << b << endl;
    else cout << a << " " << b-1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){
    int D,N;

    cin >> D >> N;

    int j = 1;

    for(int i = 0; i < D; i++){
        j *= 100;
    }

    if(N == 100){
        cout << j*(N+1) << endl;
    }else{
        cout << j*N << endl;
    }
 
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define MAX 100000

int n, s[MAX];

int numsearch(int );

int main()
{
  int i, j, ans, count=0, q, t[MAX];

  scanf("%d", &n);

  for( i=0; i<n; i++){
    scanf("%d", &s[i]);
  }

  scanf("%d", &q);

  for( i=0; i<q; i++){
    scanf("%d", &t[i]);
  }

  for( i=0; i<q; i++){
    if( numsearch(t[i]) == 1 )count++;
  }

  printf("%d\n", count);

  return 0;
}

int numsearch(int num)
{
  int left, mid, right;

  left = 0;
  right = n;

  while( left < right ){
    mid = ( left + right ) / 2;

    if( s[mid] == num ) return 1;
    else if( num < s[mid] ) right = mid;
    else left = mid +1;
  }

  return 0;
}

Measured memory_bytes: 1188
import sys
sys.setrecursionlimit(10 ** 9)

n, m = map(int, input().split())

root = [-1] * n

def r(x):
    if root[x] < 0:
        return x
    else:
        root[x] = r(root[x])
        return root[x]

def unite(x, y):
    x = r(x)
    y = r(y)
    if x == y:
        return
    root[x] += root[y]
    root[y] = x

def size(x):
    x = r(x)
    return -root[x]

for i in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    unite(x,y)

max_size = max(map(size, range(n)))

print(max_size)

Measured memory_bytes: 35808
/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#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, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
const int mod=1000000007;
  i64 poww(i64 a, i64 b)
  {
    a%=mod;
    i64 res=1;
    while(b)
      {
if(b&1)res=res*a%mod;

      a=a*a%mod;
      b/=2;

      }
      return res;
  }
  i64 inv(i64 a)
  {
    return poww(a,mod-2);
  }


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

    // ifstream fin(".in");
    // ofstream fout(".in");



i64 n;
string s;
cin>>n>>s;
reverse(all(s));
int cnt=0;
forn(i,s.size())cnt+=(s[i]-'0');
i64 pw=1,sum=0,sum1=0,sum2=0,pw1=1,pw2=1;
vvi p(3,vi(n+1));
if(cnt==0)pw=0;
if(cnt==1)pw2=0;
forn(i,s.size())
{
  if(s[i]=='1')
  {
    // sum+=pw;
    // sum%=cnt;
    sum1+=pw1;
    sum1%=(cnt+1);
    sum2+=pw2;
    if(cnt>1)
    sum2%=(cnt-1);
else sum2=0;
  }
p[0][n-1-i]=pw;
p[1][n-1-i]=pw1;
p[2][n-1-i]=pw2;
  // pw=pw*2%cnt;
  pw1=pw1*2%(cnt+1);
  if(cnt>1)
  pw2=pw2*2%(cnt-1);
else
pw2=0;
}
vi c(s.size(),sum);

reverse(all(s));
forn(i,s.size())
{
  if(s[i]=='0')
  {c[i]=sum1;
    pw=p[1][i];
    c[i]+=pw;




c[i]%=(cnt+1);
if(c[i]<0)c[i]+=cnt+1;
  }
  else
  {
    c[i]=sum2;
    pw=p[2][i];
    c[i]-=pw;
    if(c[i]<0)c[i]+=cnt-1;
    // c[i]%=cnt;
    // c[i]++;
if(cnt>1)
    c[i]%=(cnt-1);
else c[i]=0;
  }

}
// reverse(all(c));
forn(i,n)
{
  i64 ans=1;
if(cnt==1&&c[i]==0&&s[i]=='1')ans=0;
  // cout<<c[i]<<" ";
  while(c[i])
  {
    c[i]%=__builtin_popcount(c[i]);
    ans++;
  }
  cout<<ans<<"\n";
}

    return 0;
  }


Measured memory_bytes: 6776
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

long long gcd(long long x, long long y) {
	return y ? gcd(y, x % y) : x;
}

int main() {
	string s;
	while (cin >> s, s != "#") {
		reverse(s.begin(), s.end());
		long long ans1 = 0;
		int num = 0;
		for (int i = 0; i < s.size(); ++num) {
			if (s[i] == 'h') {
				if (i != 0) ans1 *= 2, ans1--;
				i += 5;
			} else ans1 *= 2, ans1++, i += 4;
		}
		ans1 *= 90;
		long long ans2 = 1LL << (num - 1);
		int tmp = gcd(ans1, ans2);
		ans1 /= tmp, ans2 /= tmp;
		if (ans2 == 1) cout << ans1 << endl;
		else cout << ans1 << "/" << ans2 << endl;
	}

	return 0;
}


Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s; cin >> s;
  int n = (int)s.size();
  bool f = true;
  for(int i = 0; i < n; ++i){
    f &= s[i] == s[n-i-1];
  }
  cout << (f?"Yes":"No") << endl;
}

Measured memory_bytes: 3624
n=int(input())
lst=[input() for _ in range(n)]
#print(lst)
dict={}
for str in lst:
    if str in dict:
        dict[str]+=1
    else:
        dict[str]=1
#print(dict)
max_value=max(dict.values())
ans=[k for k,v in dict.items() if v==max_value]
ans.sort()
[print(ans[i]) for i in range(len(ans))]


Measured memory_bytes: 35216
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <map>
#include <cmath>
#include <bitset>
#include <deque>
#include <queue>
#define INF (1LL<<31)
#define fst first
#define snd second
typedef long long ll;
typedef std::pair<int,int> ii;
using namespace std;

class ver{
public:
  ver(){}

  void push(int v,ll dist){
    pair<int,ll> p;
    p.fst=v;p.snd=dist;
    child.push(p);
  }
  bool empty(){
    return child.empty();
  }
  pair<int,ll> front(){
    return child.front();
  }

  void pop(){
    child.pop();
  }
  
  queue<pair<int,ll> > child;
};
ver V[100001];
int n,k;
bool used[100001]={};
ll dk[100001]={};

void dfs(int v){
  while(!V[v].empty()){
    pair<int,ll> nv;
    nv=V[v].front();V[v].pop();
    if(used[nv.fst])continue;
    used[nv.fst]=true;
    dk[nv.fst]=dk[v]+nv.snd;
    dfs(nv.fst);
  }
}

int main(){
  int q;
  ii Q[100000];
  cin>>n;
  for(int i=1;i<n;i++){
    int a,b;
    ll c;
    cin>>a>>b>>c;
    V[a].push(b,c);
    V[b].push(a,c);
  }
  cin>>q>>k;
  used[k]=true;
  dfs(k);

  for(int i=0;i<q;i++){
  int x,y;
  cin>>x>>y;
  Q[i].fst=x;Q[i].snd=y;
  }
  
  for(int i=0;i<q;i++){
  cout<<dk[Q[i].fst]+dk[Q[i].snd]<<endl;
  }

  return 0;
}


Measured memory_bytes: 75392
#include<iostream>
#include<math.h>
#include<stdio.h>
using namespace std;

int main()
{
  double n,m,s[1000],bun;

  while(cin>>n && n){
    m=0;bun=0;
    for(int i=0;i<n;i++){
      cin>>s[i];
      m+=s[i];
    }
    m/=n;
    for(int i=0;i<n;i++){
      bun+=(s[i]-m)*(s[i]-m);
    }
    bun/=n;
    printf("%.8f\n",sqrt(bun));
  }
  return 0;
}
      



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

int partition(int A[], int p, int r){
    int x = A[r];
    int i = p-1;
    int aaa, j;
    for(j=p; j<r; j++){
        if(A[j]<=x){
            i = i+1;
            aaa = A[j];
            A[j] = A[i];
            A[i] = aaa;
        }
    }
    aaa = A[r];
    A[r] = A[i+1];
    A[i+1] = aaa;
    return i+1;
}

int main(){
    int n;
    scanf("%d", &n);
    int arr[n];
    for(int i=0; i<n; i++){
        scanf("%d", &arr[i]);
    }

    int xxx = partition(arr, 0, n-1);

    for(int i=0; i<xxx; i++){
        printf("%d ", arr[i]);
    }
    printf("[%d] ", arr[xxx]);
    for(int i=xxx+1; i<n; i++){
        if(i==n-1){
            printf("%d\n", arr[i]);
        }
        else printf("%d ",arr[i]);
    }

    return 0;
}


Measured memory_bytes: 2108
def solve(n):
    res = 0
    for i in range(1, n + 1):
        if i % 3 == 0 or i % 5 == 0:
            continue
        else:
            res += i
    return res


def main():
    n = int(input())
    res = solve(n)
    print(res)


def test():
    assert solve(15) == 60
    assert solve(1000000) == 266666333332


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 9184
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#if __cplusplus >= 201103L
#include <chrono>
using namespace std::chrono;
#endif
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
#ifdef LOCAL
#define prln(x) (cout << #x << ' ' << x << endl)
#define pr(x) (cout << #x << ' ' << x << ' ' )
#define prv(x) (cout << x << ' ')
#else
#define prln(x) 
#define pr(x)
#define prv(x)
#endif
#define clr(x) memset((x), 0, sizeof((x)))
#define clr1(x) memset((x), -1, sizeof((x)))
#define endl "\n"
#define pi acos(-1)
#define rep(i, st, ed) for (int i = (st); i <= (ed); ++i)
#define rep0(i, st, ed) for (int i = (st); i < (ed); ++i)
#define per(i, st, ed) for (int i = (st); i >= ed; --i)
template<class T> void _sf(T &x) {cin >> x;}
void _sf(int &x) {scanf("%d", &x);}
void _sf(ll &x) {scanf("%lld", &x);}
void _sf(double &x) {scanf("%lf", &x);}
void _sf(char &x) {scanf(" %c", &x);}
void _sf(char *x) {scanf("%s", x);}
void sf() {}
template <class T, class...U> void sf(T & head, U&... tail) { _sf(head); sf(tail...);}
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

int read() {
	int x = 0, f = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		if (ch == '-') f = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9') {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * f;
}

priority_queue<pii> q;

int main(){
	#ifdef LOCAL
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
		#if __cplusplus >= 201103L
		auto start = steady_clock::now();
		#endif
	#endif
	int n = read(), m = read();
	rep(i, 1, n) {
		int t = read();
		q.push(make_pair(t, 1));
	}
	rep(i, 1, m) {
		int a = read(), b = read();
		q.push(make_pair(b, a));
	}
	int tot = 0;
	ll ans = 0;
	while (tot < n) {
		pii temp = q.top();
		q.pop();
		int d = temp.second;
		if (tot + d > n) {
			d = n - tot;
		}
		ans += 1LL * temp.first * d;
		tot += d;
	}
	cout << ans << endl;

	#ifdef LOCAL
		#if __cplusplus >= 201103L
		auto end = steady_clock::now();
		duration<double> time_span = duration_cast<duration<double>>(end - start);;
		printf("Total time: %.6fs\n", time_span.count());
		#endif
	#endif
	return 0;
}

Measured memory_bytes: 2420
# -*- coding: utf-8 -*-

import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for k in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for k in range(c)] for k in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 998244353

def dijkstra(N: int, nodes: list, src: int) -> list:
    """ ダイクストラ高速化版(頂点数, 隣接リスト(0-indexed), 始点) """
    from heapq import heappush, heappop

    # 頂点[ある始点からの最短距離]
    res = [INF] * N
    # スタート位置
    que = [src]
    res[src] = 0
    # キューが空になるまで
    while len(que) != 0:
        # 距離*N + 現在のノード
        cur = heappop(que)
        # 距離とノードに分ける
        dist = cur // N
        cur %= N
        # 出発ノードcurの到着ノードでループ
        for nxt, cost in nodes[cur]:
            # 今回の経路のが短い時
            if dist + cost < res[nxt]:
                res[nxt] = dist + cost
                # 距離*N+ノード番号 の形でキューに詰める
                heappush(que, (dist+cost)*N+nxt)
    # ノードsrcからの最短距離リストを返却
    return res

N, M = MAP()
nodes = [[] for i in range(N)]
# 1つ手前の頂点に戻るコスト0の辺を張る
for i in range(N-1):
    nodes[i+1].append((i, 0))

for i in range(M):
    l, r, c = MAP()
    l -= 1
    r -= 1
    # 一番遠くまで行く辺を張る
    nodes[l].append((r, c))

res = dijkstra(N, nodes, 0)

if res[N-1] != INF:
    print(res[N-1])
else:
    print(-1)


Measured memory_bytes: 41848
;; F - Division and Subtraction

(defun divisible (n d) (zerop (mod n d)))

(defun divisors (n)
  "約数のリスト"
  (loop for d from 1 while (<= (* d d) n)
        when (divisible n d)
        append (let ((q (floor n d)))
                 (if (eql d q) (list d) (list d q)))))

(defun goodp (n k)
  "kがnに対して条件を満たす"
  (or (divisible (1- n) k) ; kはn-1の約数
      (and (divisible n k)
           (goodp (floor n k) k))))

(defun solve (n)
  "nに対して条件を満たすkの個数"
  ; n-1の2以上の約数はnに対して条件を満たす.
  ; nの約数kのうちn/kに対して条件を満たすkはnに対しても条件を満たす.
  (+ (loop for k in (divisors n)
           count (and (not (divisible (1- n) k)) ; n-1の約数は別途数える
                      (goodp n k)))
     (1- (length (divisors (1- n)))))) ; 1以外のn-1の約数の個数

(defun main ()
  (let ((n (read)))
    (princ (solve n))))

(main)


Measured memory_bytes: 15968
import math
def a():return input()#s
def ai():return int(input())#a,n or k
def ma():return map(int, input().split())#a,b,c,d or n,k
def ms():return map(str, input().split())#,a,b,c,d
def lma():return list(map(int, input().split()))#x or y
def lms():return list(map(str, input().split()))#x or y
k= []
a,b = ma()
mod = 10**9 + 7
m = max(a,b)
n = min(a,b)
k=math.factorial(n)
if abs(a-b)>1:print(0)
elif m!=n:
    print(((k**2)*m)%mod)
else:
    print(((k**2)*2)%mod)

Measured memory_bytes: 4732
#include<algorithm>
#include<cstring>
#include<stdio.h>
using namespace std;
int a[10]={0,1,2,4,8,16,32,64};
int main(){
	int n;
	scanf("%d",&n);
	for(int i=7;i>=1;i--)
		if(a[i]<=n){printf("%d\n",a[i]);break;}
	return 0;
}


Measured memory_bytes: 128
//This is getting accepted!
// I HATE BUG
// God Of The Bugs
// 12/11/2016
#include<bits/stdc++.h>

using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define FI first
#define SE second
#define pb push_back
#define mp make_pair
#define ll long long
#define sz(a) ((int)(a).size())
#define __builtin_popcount __builtin_popcounll
#define ld long double

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> ppi;

const double PI = acos(0) * 2;
const double EPS = 1e-8;
const ll MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const int oo = 1e9;
const double foo = 1e30;

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcounll(s);}
template<class T> T sqr(T x) { return x * x; }

inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}

int n;
vector<pair<ll, int> > a;
ll ans[MAXN];

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

	cin >> n;
	for (int i=0; i<n; i++) {
		ll x;
		cin >> x;
		a.pb(mp(x, i));
	}
	
	sort(a.begin(), a.end());
	
	ll cnt = 1;
	int minCur = a.back().SE;
	for (int i=sz(a)-2; i>=0; i--) {
		if (a[i].FI != a[i + 1].FI) {
			ll rem = a[i + 1].FI - a[i].FI;
			ll tot = rem * cnt;
			ans[minCur] += tot;
		}
		
		cnt++;
		minCur = min(minCur, a[i].SE);
	}
	ans[minCur] += n * a[0].FI;
	
	for (int i=0; i<n; i++) cout << ans[i] << endl;
}


Measured memory_bytes: 3568
#include <stdio.h>

int main (void){
  int n;
  scanf("%d",&n);
  
  int s = 111 , ans;
  for(int i = 1;i <= 9;i ++){
    if(n <= 111*i){
      ans = i;
      break;
    }
  }
  
  printf("%d\n",ans*111);
  
  return 0;
}
      

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main()
{
    Fast;
    long long n,m,t,i,j,k,x=0,y=2000000000,z,q,l,r;
    cin>>n;
    long long a[n+5],b[n+5];
    for(i=1;i<=n;i++){
        cin>>a[i];
        y=min(y,a[i]);
        b[i]=y;
    }
    for(i=1;i<=n;i++){
        if(b[i]==a[i]){
            x++;
        }
    }
cout<<x<<endl;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

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

vector<string> s;

int main() {
  int H, W;
  cin >> H >> W;

  s.clear();
  for (int i = 0; i < H; ++i) {
    string str;
    cin >> str;
    s.push_back(str);
  }

  int flag;

  vector<vector <int> > res(H, vector<int>(W, 0));
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (s[i][j] == '.') continue;
      flag = 0;
      for (int k = 0; k < 4; ++k) {
        int ni = i + dx[k], nj = j + dy[k];
        if (ni < 0 || ni >= H || nj < 0 || nj >= W) continue;
        if (s[ni][nj] == '#') ++flag;
      }
      if (flag == 0) {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;
  return 0;
}


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

using namespace std;

int main(void) {
  int N;
  long long K;
  cin >> N >> K;

  int A[N+1];
  for (int i = 1; i <= N; i++) cin >> A[i];

  if (A[1] == 1) {
    cout << 1 << endl;
    return 0;
  }

  int t[N+2];
  memset(t, 0xFF, sizeof(t));
  t[1] = 0;

  int p = 1;
  for (int i = 1; i <= N; i++) {
    p = A[p];

    if (i == K) {
      cout << p << endl;
      return 0;
    }

    if (t[p] != -1) {
      K -= t[p];
      K %= i - t[p];
      int L = K;
      for (int i = 0; i < L; i++) {
        p = A[p];
      }
      cout << p << endl;
      return 0;

    } else {

      t[p] = i;
    }
  }

  return 0;
}

Measured memory_bytes: 5188
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <cstring>
using namespace std;

const int mask = (1 << 17) - 1;
const int mod = 1e9 + 7;

int hs(int x, int y) {
	return x | (1 << (y - 1));
}

int power(int x, int times) {
	int rt = 1, base = x;
	while (times) {
		if (times & 1) rt = (long long)rt * base % mod;
		base = (long long)base * base % mod;
		times >>= 1;
	}
	return rt;
}

int f[41][mask + 1];
int main() {
	int n, x, y, z;
	scanf("%d%d%d%d", &n, &x, &y, &z);
	int S = 0;
	S = hs(S, x + y + z); S = hs(S, x + y); S = hs(S, x);
	
	f[0][0] = 1;
	for (int i = 1; i <= n; i++) 
		for (int j = 0; j <= mask; j++) 
			if (f[i - 1][j] != 0) 
				for (int k = 1; k <= 10; k++) {
					int ns = hs(j << k, k) & mask;
					if ((ns & S) != S) 
						(f[i][ns] += f[i - 1][j]) %= mod;
				}
	int ans = 0;
	for (int i = 0; i <= mask; i++) (ans += f[n][i]) %= mod;
//	cout << power(10, n) << ' ' << ans << endl;
	
	ans = (power(10, n) - ans + mod) % mod;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 19328
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rep2(i, a, b) for(int i = (a); i <= (b); ++i)

const int N = 100;
char s[N];
map<char, int> mp;
int i;
int number() { return mp[s[i++]]; }
int expr() {
    if(s[i] == '(') {
        i++;
        int a = expr();
        if(s[i] == '*') {
            i++;
            int b = expr();
            i++;
            return a & b;
        } else if(s[i] == '^') {
            i++;
            int b = expr();
            i++;
            return a ^ b;
        } else
            assert(0);
    } else if(s[i] == '-') {
        i++;
        return 1 - expr();
    } else {
        return number();
    }
}

template <typename T> void chmin(T &a, T b) { a = min(a, b); }
main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    mp['0'] = 0, mp['1'] = 1;
    vector<int> v(1 << 16, INT_MAX);
    // 0
    v[0] = 1;
    // 1
    v[(1 << 16) - 1] = 1;
    // a ~ d
    int c[4];
    rep(i, 4) {
        int now = 0;
        rep(mask, 1 << 4) {
            if(mask & 1 << i) now += 1 << mask;
        }
        c[i] = now;
        v[now] = 1;
    }
    rep(_, 7) {
        vector<int> w;
        rep(i, 1 << 16) if(v[i] <= 16) w.emplace_back(i);
        // -
        rep(i, w.size()) chmin(v[((1 << 16) - 1) ^ w[i]], v[w[i]] + 1);
        w.clear();
        rep(i, 1 << 16) if(v[i] <= 16) w.emplace_back(i);
        rep(i, w.size()) rep(j, w.size()) chmin(v[w[i] ^ w[j]], v[w[i]] + v[w[j]] + 3);
        rep(i, w.size()) rep(j, w.size()) chmin(v[w[i] & w[j]], v[w[i]] + v[w[j]] + 3);
    }
    while(1) {
        string S;
        cin >> S;
        rep(i, S.size()) s[i] = S[i];
        s[S.size()] = 0;
        int ans = 0;
        if(s[0] == '.') break;
        rep(mask, 1 << 4) {
            rep(j, 4) mp['a' + j] = (mask & 1 << j) > 0;
            i = 0;
            ans ^= expr() << mask;
        }
        cout << v[ans] << endl;
    }
}



Measured memory_bytes: 3208
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
#define llMAX 9223372036854775807
#define llMIN -9223372036854775808
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

int main(){
  ll ans=0;
  string s,t,u;
  cin>>s>>t;
  cin >> n >> k;
  cin>>u;

  if (s==u)n--;
  if (t==u)k--;
  cout<<n<<" "<<k<<endl;
  return 0;
}

Measured memory_bytes: 764
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao Twitter/QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????统一类型        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    ll k,n;cin>>n>>k;
    vector<ll>h(n);
    for(ll i=0;i<n;i++)cin>>h[i];
    sort(all(h));reverse(all(h));
    ll ans=0;
    for(ll i=k;i<n;i++)ans+=h[i];
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------









Measured memory_bytes: 1792
import sys

def get():
	return [int(x) for x in sys.stdin.readline().rstrip().split(" ")]

N, M = get()
A = get()

tukaukazu = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

memo = [0 for x in range(N + 1)]

def search(n):
	if n < 0:
		return None
	else:
		return memo[n]

for n in range(1, N + 1):
	answer = None
	for d in A:
		senzinnnotie = search(n - tukaukazu[d])
		if senzinnnotie is not None:
			candidate = senzinnnotie * 10 + d
			if (answer is None) or (candidate > answer):
				answer = candidate
	memo[n] = answer

print(search(n))


Measured memory_bytes: 14548
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();
    int d = sc.nextInt();

    int div = 2 * d + 1;

    int ans = 0;
    if (n % div == 0) {
      ans = n / div;
    } else {
      ans = n / div + 1;
    }

    os.println(ans);
  }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
const int MOD=1000000007;
vector<int> G[100001];
bool visited[100001];
int ans=0;
//グラフの連結判定
int cnt=0;
void dfs(int now){//訪れたところに印を付けながら進んでいくイメージ
    if(visited[now]){
        cnt++;
        return ;
        //探索時点ですでに訪れていた->つながってる
        //n-cntが連結成分の数
    }
    visited[now] = true;
    for(int i=0;i<G[now].size();i++){
        //iが訪れておらず、nowとiがつながっていれば探索する
        int child = G[now][i];
        if(!visited[child]){
            dfs(child);
        }
    }
    
}
int main(){
    int n,m;
    cin>>n>>m;
    vector<int> x(m),y(m),z(m);
    rep(i,m){
        cin>>x[i]>>y[i]>>z[i];
        x[i]--,y[i]--;
        //connect[x[i]][y[i]]=
        G[x[i]].push_back(y[i]);
        G[y[i]].push_back(x[i]);
    }
    rep(i,n){
        visited[i]=false;
    }
    rep(i,n){
        dfs(i);
    }
    cout<<n-cnt<<endl;
}

Measured memory_bytes: 10112