akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T vals) {if (a > vals) a = vals;}template<class T> void smax(T& a, T vals) {if (a < vals) a = vals;}
const int N = 13;
const int X = 1e3 + 10;

int n, m;
int cost[X], b[X];
int c[X];
int dp[1LL<<N];
int cons = 0;
// unordered_map<bitset<N>, int> M;

int solve(int mask){
   if (mask == cons){
      return 0;
   }

   int &ans = dp[mask];
   if(~ans)
      return ans;

   ans = inf;
   for (int i = 0; i < m; ++i)
   {
      smin(ans, cost[i] + solve(mask | c[i]));
   }
 
   return ans;
}
 
int32_t main(){_
 
   cin>>n>>m;

   cons = (1LL << (n)) - 1;

   for (int i = 0; i < m; ++i)
   {
      int tot;
      cin >> cost[i] >> tot;
      for (int j = 0; j < tot; ++j)
      {
         int x;
         cin >> x;
         --x;
         c[i] |= 1LL << x;
      }
   }

   memset(dp, -1, sizeof dp);
   int ans = solve(0);
   if(ans > 1e15)
      ans = -1;

   cout<<ans;
 
   return 0;
}

Measured memory_bytes: 384
# import itertools
# import math

import sys
input = sys.stdin.readline


def solve(N, A, B):
    defeat_monstar = 0
    for nn in range(N):
        # 最初の街のモンスターのみ倒せる場合
        if A[nn] >= B[nn]:
            defeat_monstar += B[nn]
        else:
            B[nn] -= A[nn]
            # 次の街のモンスターも全て倒せる場合
            if A[nn + 1] <= B[nn]:
                defeat_monstar += A[nn] + A[nn + 1]
                A[nn + 1] = 0
            else:
                A[nn + 1] = A[nn + 1] - B[nn]
                defeat_monstar += A[nn] + B[nn]

    return defeat_monstar


N = int(input())
# S = input()
# A, B = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

# P = []
# S = []
# for i in range(N):
#     pp, ss = map(int, input().split())
#     P.append(pp)
#     S.append(ss)

print(solve(N, A, B))


Measured memory_bytes: 18624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    ll S;
    cin >> S;
    ll x1 = 1e9, x2 = 1, y1, y2;
    y2 = (S+x1-1)/x1;
    y1 = x1*y2-S;
    cout << 0 << ' ' << 0 << ' ' << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << endl;
}

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

int main() {
  int N;
  cin >> N;
  long X[N+1];
  long Y[N];
  long cnt=0;
  for(int i=0; i<N+1; ++i) cin >> X[i];
  for(int i=0; i<N; ++i) cin >> Y[i];
  for(int i=0; i<N; ++i){
    cnt += fmin(Y[i], X[i]);
    cnt += fmin(Y[i]- fmin(Y[i], X[i]), X[i+1]);
    X[i+1] -= fmin(Y[i]- fmin(Y[i], X[i]), X[i+1]);
  }
  cout << cnt << endl;
}

Measured memory_bytes: 1792
#include<string>
#include<iostream>

int main() {
	int A, B, C, D;
	std::cin >> A >> B >> C >> D;
	std::string kachimake;
	while (true) {
		C -= B;
		if (C <= 0) {
			kachimake = "Yes";
			break;
		}
		A -= D;
		if (A <= 0) {
			kachimake = "No";
			break;
		}
	}
	std::cout << kachimake << std::endl;
}

Measured memory_bytes: 3020
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<stack>
#include<cmath>
using namespace std;
int main() {
	int n;
	cin >> n;
	if (n == 3 || n==5 || n==7)puts("YES");
	else puts("NO");
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	int N, M;
	cin >> N >> M;
	vector<pair<int, int> > A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i].first >> A[i].second;
	}
	sort(A.begin(), A.end());
	long long ans = 0;
	for (int i = 0; i < N; ++i) {
		int use = min(M, A[i].second);
		M -= use;
		ans += (long long)(use) * A[i].first;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4052
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define uniq(x) (x).erase(unique(ALL(x)),(x).end())
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))
#define foreach(it,x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define debug(x) cerr<<#x<<"="<<(x)<<endl
#define gett() cerr<<"Time:"<<clock()<<"ms."<<endl
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rlcfpoj(x) scanf("%I64d",&x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define plcfpoj(x) printf("%I64d",x)
#define lfd() printf("\n")
#define sp() printf(" ")
#define inrep(x) int x;scanf("%d",&x);while(x--)
#define testbit(mask,i) (((mask)>>(i))&1)
#define setbit(mask,i) ((mask)|(1<<i))
#define delbit(mask,i) ((mask)^(1<<i))
int n,k;
int a[100100];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+n+1);
	int res=0;
	for(int i=n;i>=n-k+1;i--){
		res+=a[i];
	}
	cout<<res<<endl;
	return 0;
}


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

using namespace std;

int a;
int b;
int c;
int res;

int main() {
    scanf("%d%d%d", &a, &b, &c);
    if(b < c) swap(b, c);
    if(a < b) swap(a, b);
    if(b < c) swap(b, c);
    if((2 * a - b - c) & 1) printf("%d\n", (2 * a - b - c + 3) / 2);
    else printf("%d\n", (2 * a - b - c) / 2);
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    int d[n];
    for (int i = 0; i < n; i++)
        cin >> d[i];
    set<int> values;
    for (int i = 0; i < n; i++)
        values.insert(d[i]);
    
    cout << values.size() << endl;
    return 0;
}

Measured memory_bytes: 256
K = int(input())
c = 0
s = 0
LIM = 1000000
if K % 2 == 0 or K % 5 == 0:
  print("-1")
else:
  while (c <= LIM):
    c = c + 1
    s = (s*10 + 7) % K
    if (s == 0):
      break
  if ( c > LIM):
    print("-1")
  else:
    print(c)


Measured memory_bytes: 9120
H,W = map(int,input().split())
S=[input() for i in range(H)]
A=[ [0]*W for i in range(H)] # extensionable size at row direction
B=[ [0]*W for i in range(H)] # extentionable size at collum direction
# make extension table
for i in range(H):
  for j in range(W):
    if S[i][j] == "#":
      A[i][j] = B[i][j] = 0
      continue
    # Calcurate extension case
    if j== 0 or A[i][j-1] == 0:
      numA = 0 # extension size of row 
      k = j
      while True:
        numA += 1
        if k == W-1 or S[i][k+1] == "#": # boundary point
          A[i][j] = numA
          break
        k += 1
    else:
      A[i][j] = A[i][j-1]
    
    if i == 0 or B[i-1][j] == 0:
      numB =0
      k = i
      while True: # extension size of cullum
        numB += 1
        if k == H-1 or S[k+1][j] == "#": # boundary point
          B[i][j] = numB
          break
        k += 1
    else:
      B[i][j] = B[i-1][j]

# max of A[i][j]+B[i][j]-1
ans = 0
for i in range(H):
  for j in range(W):
    ans = max(ans,A[i][j]+B[i][j]-1)
    #print(A[i][j]+B[i][j]-1,end=",") # for debug
  #print("")
print(ans)
      



        

        


      





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

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(ll i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

const ll inf = 1ll<<62;
const ll mod = 1e9+7;

struct node {
  ll v, d;
  node(ll _a, ll _b):v(_a),d(_b){}
  bool operator<(const node &n) const { return d > n.d; }
};
struct edge {
  ll to, d;
  edge(ll _to, ll _d):to(_to),d(_d){}
};
class dijkstra{
public:
  vector<vector<edge>> G;
  vector<ll> dist;
  vector<ll> prev;

  dijkstra(ll s,const vector<vector<edge>> &_G):G(_G){ // sからの最短経路
    dist.resize(G.size(),1ll << 59);
    //prev.resize(G.size(),-1);
  
    priority_queue<node> que;
    que.push(node(s, 0));
    dist[s] = 0;
    
    while(!que.empty()){
      ll v = que.top().v, d = que.top().d;
      que.pop();
      
      rep(i, G[v].size()){
	ll tmp = d + G[v][i].d;
	if(dist[G[v][i].to] > tmp){
	  dist[G[v][i].to] = tmp;
	  //prev[G[v][i].to] = v;
	  que.push(node(G[v][i].to, tmp));
	}
      }
    }
  }

  vector<ll> getpath(ll t){ // tへの最短経路を返す
    vector<ll> path;
    while(t != -1){
      path.push_back(t);
      t = prev[t];
    }
    reverse(path.begin(), path.end());
    return path;
  }
};

int main(){
#define int ll
  int k; cin >> k;
  vector<vector<edge>> g(k);
  rep(i,k){
    g[i].pb(edge((i+1)%k,1));
    g[i].pb(edge((i*10)%k,0));
  }
  dijkstra d(1,g);
  cout << d.dist[0]+1 << endl;
}

Measured memory_bytes: 16252
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const ll LINF = 1LL<<60;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    if (fopen("input.in", "r")) {
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }

    int n; cin >> n;
    vector<ll> h(n), dp(n, LINF);
    for (int i = 0; i < n; i++) cin >> h[i];
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        if (i+1 < n) dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1]-h[i]));
        if (i+2 < n) dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2]-h[i]));
    }

    cout << dp[n-1] << endl;

    return 0;
}

Measured memory_bytes: 1792
import java.io.*;

class Main{
	
	public static void main(String[] args)throws IOException{
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] num = str.split(" ");
		
		int a = Integer.parseInt(num[0]);
		int b = Integer.parseInt(num[1]);
		int c = Integer.parseInt(num[2]);
		
		if(a < b && b < c){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
		
	}
	
}

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

int main()
{
	int tmp, d[6];
	string dir;
	for (int i = 0; i < 6; i++)
		cin >> d[i];
	cin >> dir;
	for (int i = 0; i < (dir.size()); i++) {
		if(dir[i]=='E') {
			tmp = d[0];
			d[0] = d[3];
			d[3] = d[5];
			d[5] = d[2];
			d[2] = tmp;
		}
		else if(dir[i]=='W') {
			tmp = d[0];
			d[0] = d[2];
			d[2] = d[5];
			d[5] = d[3];
			d[3] = tmp;
		}
		else if(dir[i]=='S') {
			tmp = d[0];
			d[0] = d[4];
			d[4] = d[5];
			d[5] = d[1];
			d[1] = tmp;
		}
		else {
			tmp = d[0];
			d[0] = d[1];
			d[1] = d[5];
			d[5] = d[4];
			d[4] = tmp;
		}
	}
	cout << d[0] << endl;
	return 0;
}

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

int main()
{
  ll n,x;
  cin>>n;
  int a[n];
  for(ll i=0;i<n;i++)
  {
  	cin>>x;
  	a[i]=x;
  }
  ll count=1;
  ll ans=0;
  
  for(ll i=0;i<n;i++)
  {
  	if(a[i]!=count)
  	ans++;
  	else
  	{
  		count++;
	  }
  	
  }
  sort(a,a+n);
  if(a[0]!=1)
  cout<<"-1";
  else
  cout<<ans;
 

}

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

int main()
{
    int64_t A, B, N;
    cin >> A >> B >> N;
    int64_t x = min(B - 1, N);
    int64_t ans = floor(A * x / B);
    cout << ans << endl;
}

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

int main() {
  char a, b;
  cin >> a >> b;
  string as(b - '0', a), bs(a - '0', b);
  if (as > bs) {
    cout << bs << endl;
  } else {
    cout << as << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  char S;
  int t=0;
  int i=0;
  int a[3];
  while(i!=3){
    scanf("%c",&S);
    if(S=='R'){
     t=t+1;
  }else{
      t=0;
    }
    a[i]=t;
  	i=i+1;
  }
  
  int max=a[0];
  for(i=1; i<3; ++i)
    if(max<a[i]) max=a[i];
  //printf("%d %d %d\n",a[0],a[1],a[2]);
  printf("%d\n",max);
  return 0;
}

Measured memory_bytes: 1652
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using vi = vector<int>;

#define in(v) v; cin >> v;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rrep(i,n) for(long long i=(n);i>=0;--i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))

// ========== debug ==========
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(size_t i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
ostream& operator<<(ostream& os,const vector<char>&v){for(size_t i=0;i<v.size();++i)os<<v[i];return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}

#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
void debug2() {cerr << "\n";}
template<class First> void debug2(const First& first) {cerr<<first<<" ";}
template<class First, class... Rest> void debug2(const First& first, const Rest&... rest) {cerr<<first<<" ";debug2(rest...);}
#else
#define debug(...) 42
#define debug2(...) 42
#endif
// ===========================

int main() {
  int N;
  ins(N);

  map<long long, long long> m;
  ll sum = 0;
  rep(i, N) {
    int a; cin >> a;
    ++m[a];
    sum += a;
  }
  int Q; cin >> Q;
  rep(i, Q) {
    int b, c;
    ins(b, c);
    sum -= m[b] * b;
    sum += m[b] * c;
    m[c] += m[b];
    m[b] = 0;
    cout << sum << endl;
  }

  return 0;
}


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

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

using namespace std;

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

  char alphab = 'a';
  bool ok = false;

  rep(i, 26) {
    bool dup = false;
    rep(j, s.size()) {
      if (alphab + i == s[j]) {
        dup = true;
        break;
      }
    }
    if (!dup) {
      ok = true;
      alphab += i;
      break;
    }
  }

  if (ok) {
    std::cout << alphab << std::endl;
  } else {
    std::cout << "None" << std::endl;
  }
  return 0;
}


Measured memory_bytes: 3756
#include<stdio.h>

int main(void){
    int A, B, C;
    scanf("%d %d %d", &A, &B, &C);
    if(A < C && C < B  ){
        printf("Yes\n");
    }else if(B < C && C < A){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define ll long long 
#define rep(i,a,b) for(signed i=a;i<(b);++i)
#define erep(i,a,b) for(signed i=a;i<=(b);++i)
#define per(i,a,b) for(signed i=(a);i>(b);--i)
#define eper(i,a,b) for(signed i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define ALL(x) begin(x),end(x)
#define F first
#define S second
#define debug(x)  cout << #x << ": " << (x) << '\n';
const long long INF=1001001001001001001;
const int MOD=(int)1e9 + 7;
const double EPS=1e-9;
using namespace std;
using Pii = pair<int,int>;
using vii = vector<int>;
template<class T>using  PS_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> ostream& operator<<(ostream &os,const vector<vector<T> > &v) {
    ITR(u,begin(v),end(v))ITR(w,begin(*u),end(*u))os<<*w<<(w==end(*u)-1?"\n":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct edge { int from, to, cost; };
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};
// cout << fixed << setprecision(10) << val;

string s, t;
signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  cin >> s >> t;
  int ans = 0;
  rep(i, 0, 3) {
    if (s[i] == t[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <utility>
#include <numeric>
using namespace std;

int main() {
    int N; cin >> N;
	vector<int> h(N+2);
	h[0] = 0; h[N+1] = 0;
	for(int i = 1; i <= N; i++) cin >> h[i];

	vector<int> cur(N+2, 0);
	int count = 0;
	int l = 0, r = 0;
	bool end = false;
	while(!end){
		for(int i = 1; i <= N; i++){
			if(cur[i-1] == h[i-1] && cur[i] < h[i]){
				l = i;
			}
			if(cur[i] < h[i] && cur[i+1] == h[i+1]){
				r = i;
				break;
			}
			if(i==N){
				end = true;
			}
		}
		if(!end){
			for(int i = l; i <= r; i++){
				cur[i]++;
			}
			count++;
		}
	}
	cout << count << endl;
}

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

int main(){
  string wea;
  cin >> wea;
  if(wea == "RRR"){
    cout << 3 << endl;
  }
  else if(wea == "RRS" || wea == "SRR"){
    cout << 2 << endl;
  }
  else if(wea == "SSS"){
    cout << 0 << endl;
  }
  else{
    cout << 1 << endl;
  }
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define _IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const ll N=2e5+9,mod=998244353,inf=1e18;

ll seg[4*N],lzy[4*N],pw[N],dig[11][N];

void propagate(ll rt)
{
    if(lzy[rt]==0)return;
    lzy[rt*2]=lzy[rt];
    lzy[rt*2+1]=lzy[rt];
    lzy[rt]=0;
}

void marge(ll rt,ll l,ll r)
{
    ll md=(l+r)/2;
    ll lft=rt*2;
    ll rgt=lft+1;

    if(lzy[lft]==0)seg[rt]=seg[lft];
    else seg[rt]=dig[ lzy[lft] ][ md-l+1 ];

    seg[rt]=(seg[rt]*pw[r-md])%mod;

    if(lzy[rgt]==0)seg[rt]=(seg[rt]+seg[rgt])%mod;
    else seg[rt]=(seg[rt]+dig[lzy[rgt]][r-md])%mod;
}

void update(ll rt,ll l,ll r,ll i,ll j,ll v)
{
    if(l>j||r<i)return;
    if(l>=i&&r<=j)
    {
        lzy[rt]=v;
        return;
    }
   propagate(rt);
   ll md=(l+r)/2;
   ll lft=rt*2;
   ll rgt=lft+1;
   update(lft,l,md,i,j,v);
   update(rgt,md+1,r,i,j,v);
   marge(rt,l,r);
}

int main()
{
    _IO;
    ll n,q;cin>>n>>q;
    pw[0]=1;
    for(ll i=1;i<=n;i++)pw[i]=(pw[i-1]*10)%mod;
    for(ll i=1;i<=9;i++)
    {
        dig[i][0]=0;
        for(ll j=1;j<=n;j++)
        {
            dig[i][j]=(dig[i][j-1]*10+i)%mod;
        }
    }

    for(ll i=1;i<=n;i++)update(1,1,n,i,i,1);
    while(q--)
    {
        ll l,r,d;cin>>l>>r>>d;
        update(1,1,n,l,r,d);
        if(l==1&&r==n)cout<<dig[d][n]<<"\n";
        else cout<<seg[1]<<"\n";
    }

}



Measured memory_bytes: 25444
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>
#include <cstdint>
#define _USE_CMATH_DEFINES

const long INF = (1l << 30);
const long LINF = (1l << 60); //1.15*10^18

int main(){
    std::string s;
    std::cin >> s;
    long sum = 0;
    for(int i = 0; i < s.length(); i++){
        sum += s[i] - '0';
    }
    if(sum % 9 == 0){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
}


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

#define fo(i, n) for(ll i = 0; i < n; i++)
#define of(i, n) for(ll i = n - 1; i >= 0; i--)
#define ll long long
#define vec vector<ll>
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)


ll mod= 1e9+7;

#define umap unordered_map

string t;

ll sub(string s)
{
    ll l=0,h=s.length();
    ll j=0;
    for (int i=0; i<s.length()&&j<t.length(); i++)
       if (t[j] == s[i])
         j++;

    return (j==t.length());
}

ll check(ll n, string s)
{
    ll l,h;
    l=0;h=n-1;
    while(h<s.length()){
        if(sub(s.substr(l,h))) return 1;
        l++;h++;
    }
    return 0;
}

ll ab(ll x)
{
    if(x<0) x*=-1;
    return x;
}
int main()
{
    fio;
    ll n,k;
    cin>>n;
    cin>>k;
    ll h[n];
    fo(i,n) cin>>h[i];
    ll c[n];
    //cout<<llabs(-29);
    fo(i,n) c[i]=1e9;
    c[0]=0;
    c[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;i++)
    {
        ll y ;
        if(i-k<0) y=i;
        else y=k;
        y++;
        while(y--){
        c[i] = min(c[i],c[i-y]+abs(h[i]-h[i-y]));
        }
    }
    cout<<c[n-1]<<endl;

}






Measured memory_bytes: 1792
#include <stdio.h>
#define MAX 2000000

int H, A[MAX + 1];

void maxHeapity(int i)
{
	int l, r, largest;
	l = 2*i;
	r = 2*i + 1;
	
	if(l <= H && A[l] > A[i]) {largest = l;}
	else {largest = i;}
	if(r <= H && A[r] > A[largest]) {largest = r;}
	
	if(largest != i)
	{
		int tmp=0;
		tmp=A[i];
		A[i]=A[largest];
		A[largest]=tmp;
		maxHeapity(largest);
	}
}


int main()
{
	scanf("%d", &H);
	
	for(int i = 1; i <= H; i++){
		scanf("%d", &A[i]);
	}
	
	for(int i = H/2; i>=1; i--){
		maxHeapity(i);
	}
	
	for(int i = 1; i <= H; i++){
		printf(" %d", A[i]);
	}
	printf("\n");
	
	return 0;
}




Measured memory_bytes: 3656
l = list(map(int,input().split()))
go = 0
shichi = 0
for i in range(3):
  if l[i] == 5:
    go += 1
for i in range(3):
  if l[i] == 7:
    shichi += 1
if go == 2 and shichi ==1:
  print('YES')
else:
  print('NO')


Measured memory_bytes: 38256
#include<bits/stdc++.h>
typedef long long ll;
#define pii pair<int,int>
#define ff first
#define ss second
using namespace std;
void fast()
{
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
int main()
{
    ll n,k,x,y;
    cin>>n>>k>>x>>y;
    if(n>=k)
    cout<<k*x+(n-k)*y<<endl;
    else
    cout<<n*x<<endl;
    return 0;
}


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

int main() {
  string s;
  cin>>s;
  int n=s.size();
  string ans="Yes";
  for(int i=0;i<n;i++){
    if(i==0) {
      if(s[i]!='h'){
      ans="No";
      break;
      }
    }
    if(i%2==0){
      if(s[i]!='h'){
      ans="No";
      break;
      }
    }
    if(i%2==1){
      if(s[i]!='i'){
        
      ans="No";
      break;
      }
    }
    if(i==n-1 && s[i]!='i') ans="No";
  }
  cout<<ans<<endl;
  
}

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

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

    int n, M;
    cin>>n>>M;
    map<int, int> cnt;

    int sum = 0;
    cnt[sum]++;

    for (int i=1; i<=n; i++) {
        int x;
        cin>>x;
        sum = (sum+x)%M;
        cnt[sum]++;
    }

    long long ans = 0;
    for (auto pr: cnt)  ans += 1LL*pr.second*(pr.second-1)/2;
    cout<<ans<<endl;
}


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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, x, y) for(ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define MSGF(x, n) MSG(fixed << setprecision(n) << x)
#define END(x) cout << x << endl; return(0);
#define IPT(v, n) REP(i, 0, n){ cin >> v[i]; }
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<ull> vul;
typedef vector<vector<ull>> vvul;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
const static ll INF = 1LL << 30;

ll a, b, c, d, k, l, m, n, h, w, q, x, y;
string s, t;

ll ans = 0;
ll sum = 0;
ll cnt = 0;
ll cur = 0;
ll tmp = 0;
ll mini = INF;
ll maxi = 0;

double ave = 0.0;

ll mod_pow(ll base, ll power) {
    if (power == 0) return 1;
    if (power == 1) return base % MOD;
    if (power % 2 == 0) return ((mod_pow(base % MOD, (power / 2)) % MOD) * (mod_pow(base, (power / 2)) % MOD)) % MOD;
    return (base % MOD * (mod_pow(base % MOD, power - 1) % MOD)) % MOD;
}

ll mod_fact(ll number) {
    ll ret = 1;
    ll count = 1;
    while (count <= number) {
        ret *= (count % MOD);
        ret %= MOD;
        count++;
    }
    return ret % MOD;
}

ll gcd(ll a, ll b) {
    if (a < b) {
        return gcd(b, a);
    }
    ll c = a % b;
    while (c != 0) {
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
    cin >> s;
    MSG(s.substr(0, 3))
}


Measured memory_bytes: 3480
#include<stdio.h>
#define ll long long
ll gcd(ll a,ll b)
{
return b?gcd(b,a%b):a;
}
ll lcm(ll a,ll b)
{
	return a/gcd(a,b)*b;
}
int main()
{
	int n,i,j;
	long long sum,str[110];
	while(~scanf("%d",&n))
	{sum=1;
	for(i=0;i<n;i++){
	scanf("%lld",&str[i]);
	sum=lcm(sum,str[i]);}
	printf("%lld\n",sum);
}return 0;}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1 << 21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

// 0118c
ll gcd(ll x, ll y){
    if(x<y) swap(x, y);
    if(y==0) return x;
    return gcd(y, x%y);
}

int main(){
    int n;
    cin >> n;
    ll a[n];
    rep(i, n) cin >> a[i];
    sort(a, a+n);
    ll ans = a[0];
    rep(i, n){
        if (i==0) continue;
        ans = gcd(ans, a[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000000000000



int main(){
	
	int N,K;
	cin>>N>>K;
	
	if(N%K==0){
		cout<<0<<endl;
	}
	else{
		cout<<1<<endl;
	}
	
    return 0;
}


Measured memory_bytes: 256
struct FenwickTree {
    n: usize,
    v: Vec<i32>,
}

impl FenwickTree {
    fn new(n: usize) -> FenwickTree {
        FenwickTree {
            n,
            v: vec![0; n + 1],
        }
    }

    fn add(&mut self, mut i: usize, x: i32) {
        while i <= self.n {
            self.v[i] += x;
            i += i & (!i + 1);
        }
    }

    fn sum(&self, mut i: usize) -> i32 {
        let mut res = 0;
        while i > 0 {
            res += self.v[i];
            i -= i & (!i + 1);
        }
        res
    }
}

use std::io::{BufRead, Write};
use std::collections::VecDeque;

fn main () {
    let stdin = std::io::stdin();
    let stdout = std::io::stdout();
    let mut reader = std::io::BufReader::new(stdin.lock());
    let mut writer = std::io::BufWriter::new(stdout.lock());

    let (n, q): (usize, usize) = {
        let mut buf = String::new();
        reader.read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    };
    
    let c: Vec<usize> = {
        let mut buf = String::new();
        reader.read_line(&mut buf).unwrap();
        let iter = buf.split_whitespace();
        iter.map(|x| x.parse::<usize>().unwrap() - 1).collect()
    };

    let mut ft = FenwickTree::new(n);
    let mut v = vec![VecDeque::new(); n];
    for i in (0..n).rev() {
        if v[c[i]].is_empty() {
            ft.add(i + 1, 1);
        }
        v[c[i]].push_front(i);
    }

    let mut l: Vec<usize> = Vec::with_capacity(q);
    let mut r: Vec<usize> = Vec::with_capacity(q);
    for _ in 0..q {
        let mut buf = String::new();
        reader.read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        l.push(iter.next().unwrap().parse::<usize>().unwrap() - 1);
        r.push(iter.next().unwrap().parse().unwrap());
    }

    let mut order: Vec<usize> = (0..q).collect();
    order.sort_by(|&i, &j| r[j].cmp(&r[i]));

    let mut ans = vec![0; q];
    let mut i = n;
    for j in order {
        while r[j] < i {
            i -= 1;
            v[c[i]].pop_back();
            ft.add(i + 1, -1);
            if let Some(k) = v[c[i]].back() {
                ft.add(k + 1, 1);
            }
        }
        ans[j] = ft.sum(n) - ft.sum(l[j]);
    }

    for i in 0..q {
        writeln!(writer, "{}", ans[i]).unwrap();
    }
}

Measured memory_bytes: 58844
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long P = 1000000007L;
    int N = sc.nextInt();
    long answer =1;
    for(int i=1;i<=N;i++){
      answer=(answer*i)%P;
    }
    System.out.println(answer);
  }
  

  
}

Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
using ll = long long;

int main (){
    string s;
    cin >> s ;
    string rev = s;
    reverse(rev.begin(),rev.end());
    int ans = 0;
    for (int i = 0; i < s.size(); i++){
        if (s[i] != rev[i])ans++;
    }
    cout << ans/2 << endl;
    return 0;
}   

Measured memory_bytes: 3188
#include<stdio.h>

long gcd(long a,long b)
{
	long r =1;
	while(r !=0)
	{
		r=a%b;
		a=b;
		b=r;
	}
	
	return a;
}

int main(void)
{
	long a;
	long b;
	
	scanf("%ld%ld",&a,&b);
	printf("%ld",a*b/gcd(a,b));
	return 0;
}

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

using namespace std;
using P = pair<int64_t, int>;

int main(){
    int64_t N, M;
    while(true){
        cin >> N >> M;
        if(N == 0 && M == 0) break;
        vector<P> pd(N);
        for(int i = 0; i < N; ++i){
            cin >> pd[i].second >> pd[i].first;
        }
        sort(pd.begin(), pd.end());
        for(int i = N-1; i >= 0; --i){
            if(pd[i].second <= M){
                M -= pd[i].second;
                pd[i].second = 0;
            } else {
                pd[i].second -= M;
                M = 0;
            }
        }
        int64_t sum = 0;
        for(int i = 0; i < N; ++i){
            sum += pd[i].first * pd[i].second;
        }
        cout << sum << endl;
    }
}


Measured memory_bytes: 3168
#include <iostream>

int main(int argc, const char **argv)
{
  	int hpt = 0, atkt = 0, hpa = 0, atka = 0, turn = 0;
  	std::cin >> hpt >> atkt >> hpa >> atka;
  
  	while ( true )
    {
      	if ( hpt <= 0 || hpa <= 0 ) break;
      	if ( turn % 2 == 0 ) hpa -= atkt;
      	else hpt -= atka;
      	turn++;
    }
  
  	if ( hpt > 0 ) std::cout << "Yes" << std::endl;
  	else std::cout << "No" << std::endl;
  
  	return 0;
}

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

int main() {
	int D;
	cin >> D;
	long int arr[D];
	for(int i=0;i<D;i++){
			cin>>arr[i];
		}
		
	long int counter = 0;
	for(int i=0;i<D;i++){
			while((arr[i] & 1) == 0){
					counter++;
					arr[i] >>= 1;
				}
		}
		
		cout<<counter<<endl;
	return 0;
}


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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv){vprint(v)};

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

    ll S;
    cin >> S;

    vll dp(S+1, 0);
    dp[0] = dp[3] = dp[4] = dp[5] = 1;
    REP(i, 6, S+1){
        ll s = 0;
        REP(j, 3, i+1){
            s = (s+dp[i-j]) % 1000000007;
        }
        dp[i] = s;
    }
    cout << dp[S] << endl;
}


Measured memory_bytes: 3660
from collections import deque
from math import ceil
import sys
def input():
	return sys.stdin.readline()[:-1]

H, W, k = map(int, input().split())
m = [input() for _ in range(H)]
q = deque()
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

step = [[10**10 for _ in range(W)] for _ in range(H)]

for h in range(1, H-1):
	for w in range(1, W-1):
		if m[h][w] == "S":
			q.appendleft([h, w])
			sx, sy = h, w

step[sx][sy] = 0
while q:
	label = q.pop()
	if step[label[0]][label[1]] == k:
		continue
	for i in range(4):
		h, w = label[0] + dx[i], label[1] + dy[i]
		if 0 <= h < H and 0 <= w < W:
			if m[h][w] == "." and step[h][w] > step[label[0]][label[1]] + 1:
				q.appendleft([h, w])
				step[h][w] = step[label[0]][label[1]] + 1

min_dis = max(H, W)
for h in range(H):
	for w in range(W):
		if step[h][w] <= k:
			min_dis = min(min_dis, h, w, H-h-1, W-w-1)

print(1+ceil(min_dis/k))

Measured memory_bytes: 59612
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] as = br.readLine().split(" ");
		
		long a = Long.parseLong(as[0]);
		long b = Long.parseLong(as[1]);
		long c = Long.parseLong(as[2]);
//		double ad = Math.sqrt(a);
//		double ab = Math.sqrt(b);
//		double ac = Math.sqrt(c);
		if(c < a+b ) {
			System.out.println("No");
		}else if(a*b*4 < (c -a -b)*(c-a-b) ) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}


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

int main() {
  int N;
  cin >> N;
  vector<long long> A(N+1), B(N);
  rep(i, N+1) cin >> A.at(i);
  rep(i, N) cin >> B.at(i);
  long long mon_count = 0;
  rep(i, N) {
    if (A.at(i) < B.at(i)) {
      mon_count += A.at(i);
      B.at(i) -= A.at(i);
      A.at(i) = 0;
      if (A.at(i+1) >= B.at(i)) { 
        mon_count += B.at(i);
        A.at(i+1) -= B.at(i);
      }
      else {
        mon_count += A.at(i+1);
        A.at(i+1) = 0;
      }
    }
    else {
      A.at(i) -= B.at(i);
      mon_count += B.at(i);
    }
  }
  cout << mon_count << endl;
}

Measured memory_bytes: 4844
#include<iostream>
#include<stack>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;
typedef long long ll;

ll r, c, n;

bool isEnd(ll x, ll y){
	return ((x == 0 || x == r || y == 0 || y == c) ? 1 : 0);
}

ll leng(ll x, ll y){
	if(!x){
		return y;
	}else if(x == r){
		return (r + c + c - y);
	}else if(!y){
		return (2 * c + r + r - x);
	}else{
		return (c + x);
	}
}

int main(){
	cin >> r >> c >> n;
	vector< pair<ll, ll> > v;
	for(ll i = 0; i < n; ++i){
		ll x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
		if(isEnd(x1, y1) && isEnd(x2, y2)){
			v.push_back(pair<ll, ll>(leng(x1, y1), i));
			v.push_back(pair<ll, ll>(leng(x2, y2), i));
		}
	}
	sort(v.begin(), v.end());
	stack<ll> s;
	s.push(v[0].second);
	for(ll i = 1; i < v.size(); ++i){
		if(!s.empty() && s.top() == v[i].second){
			s.pop();
		}else{
			s.push(v[i].second);
		}
	}
	cout << (s.empty() ? "YES\n" : "NO\n");
	return 0;
}

Measured memory_bytes: 6512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
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; }
//get the biggest element.
template<typename KeyType, typename ValueType>
std::pair<KeyType,ValueType> get_max( const std::map<KeyType,ValueType>& x ) {
  using pairtype=std::pair<KeyType,ValueType>;
  return *std::max_element(x.begin(), x.end(), [] (const pairtype & p1, const pairtype & p2) {
        return p1.second < p2.second;
  });
}
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;

int main() {
  //cin.tie(0);ios::sync_with_stdio(false);
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  vector<string> strs;
  strs.push_back("maerd");
  strs.push_back("remaerd");
  strs.push_back("esare");
  strs.push_back("resare");

  bool ok = true;
  while (ok) {
    ok = false;
    for (auto v : strs) {
      if (s.substr(0, v.size()) == v) {
        s.erase(0, v.size());
        ok = true;
      }
    }
  }
  if (!s.size()) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 3768
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main {

	static PrintWriter out;
	static InputReader ir;

	static void solve() {
		out.println(ir.nextLong() - ir.nextLong() + 1);
	}

	public static void main(String[] args) {
		ir = new InputReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}

		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}

		public boolean hasNext() {
			skip();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}

	static void tr(Object... o) {
		out.println(Arrays.deepToString(o));
	}
}


Measured memory_bytes: 22612
#include<bits/stdc++.h>
     
    using namespace std;
     
    int main() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int N;
        cin >> N;
        vector<queue<int> > g(N + 1);
        queue<pair<int, int> > q;
        for (int i = 1; i < N + 1; ++i) {
            for (int j = 0; j < N - 1; ++j) {
                int a;
                cin >> a;
                g[i].push(a);
            }
        }
        for (int i = 1; i < N + 1; ++i) {
            if (g[g[i].front()].front() == i && i < g[i].front()) q.push({i, g[i].front()});
        }
        int ans = 0;
        for (int cnt = 0; cnt < N * (N - 1) / 2; ++ans) {
            if (q.empty()) {
                // is cyclic
                puts("-1");
                return 0;
            }
            for (int i = q.size(); i--; ++cnt, q.pop()) {
                int a = q.front().first;
                g[a].pop();
                if (g[g[a].front()].front() == a) {
                    q.push({a, g[a].front()});
                }
                a = q.front().second;
                g[a].pop();
                if (g[g[a].front()].front() == a) {
                    q.push({a, g[a].front()});
                }
            }
        }
        printf("%d\n", ans);
        return 0;
    }

Measured memory_bytes: 4736
import static java.lang.System.out;
import java.lang.Math;
import java.io.InputStream;
import java.io.IOException;
import java.util.NoSuchElementException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Collections;

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

    MyInput in = new MyInput();
    public void run() {
        int n = in.nextInt();
        int[] a = new int[n];
        double all = 0;
        for(int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            all += a[i];
        }
        double ave = all / n;
        int neari = 0;
        double nearsa = Math.abs(ave - a[0]);
        double sa;
        for(int i = 1; i < n; i++) {
            sa = Math.abs(ave - a[i]);
            if(sa < nearsa) {
                neari = i;
                nearsa = sa;
            }
        }
        out.println(neari);
    }
}

class MyInput {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr= 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if(ptr < buflen) {
            return true;
        }else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch(IOException e) {
                e.printStackTrace();
            }
            if(buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    public int readByte() {
        if (hasNextByte()) return buffer[ptr++];
        else return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <=126;
    }

    private void skipUnprintable() {
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
    }

    public boolean hasNext() {
        skipUnprintable();
        return hasNextByte();
    }

    public String next() {
        if(!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if(!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if(b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true) {
        if('0' <= b && b <= '9') {
            n *= 10;
            n += b - '0';
        }else if(b == -1 || !isPrintableChar(b)) {
            return minus ? -n : n;
        }else {
            throw new NumberFormatException();
        }
            b = readByte();
        }
	}

    public int nextInt() {
        long nl = nextLong();
        if(nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}



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

const int MAX_N = 1e5 + 5, INF = 1e5 + 5;
int N, dist[2][MAX_N];
vector<int> E[MAX_N];

void bfs(int s, int c){
    dist[c][s] = 0;
    queue<int> q; q.push(s);

    while(!q.empty()){
        int u = q.front(); q.pop();
        for(auto v : E[u]){
            if(dist[c][v] == INF){
                dist[c][v] = dist[c][u] + 1;
                q.push(v);
            }
        }
    }
}

int main(){
    cin >> N;
    for(int i=0;i<N-1;i++){
        int a, b; cin >> a >> b;
        E[a].push_back(b); E[b].push_back(a);
    }

    for(int i=0;i<2;i++) for(int j=1;j<=N;j++) dist[i][j] = INF;
    bfs(1, 0); bfs(N, 1);

    int cnt = 0;
    for(int i=1;i<=N;i++) if(dist[1][i]<dist[0][i]) cnt++;

    if((N+1)/2<=cnt) cout << "Snuke" << endl;
    else cout << "Fennec" << endl;
    return 0;
}

Measured memory_bytes: 6656
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<iostream>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
using namespace std;
int main(){
  ll n;
  cin >> n;
  ll ans=n-1;
  for(ll i=1;i<1000001;i++){
    if(n%i==0) {
      ll a=n/i;
    ans=min(ans,i+a-2);
    }
  }
  cout <<ans<<endl;
}

Measured memory_bytes: 256