akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
const int N=2e5+5;
int L[N],R[N];
int stk[N],top,n;
int a[N],k,f[N];
int main() {
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++) {
        scanf("%d",a+i);
        if(i==1||a[i]<a[i-1]) f[i]=1;
        else f[i]=1+f[i-1];
        while(top&&a[stk[top-1]]<=a[i]) --top;
        if(!top) L[i]=1;
        else L[i]=stk[top-1]+1;
        stk[top++]=i;
    }
    top=0;
    for(int i=n;i;i--) {
        while(top&&a[stk[top-1]]>=a[i]) --top;
        if(!top) R[i]=n;
        else R[i]=stk[top-1]-1;
        stk[top++]=i;
    }
    int ans=0;
    int cnt=0;
    for(int i=k;i<=n;i++) {
        if(f[i]>=k) {
            cnt=1;
            continue;
        }
        if(i>k&&R[i-k]>=i&&L[i]<=i-k) continue;
        ans++;
    }
    printf("%d\n",ans+cnt);
    return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    int d1 = x2 - x1, d2 = y2 - y1;
    int x3 = x2 - d2, y3 = y2 + d1;
    int x4 = x1 - d2, y4 = y1 + d1;
    cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

struct Dinic{
  
  struct edge {
    int to;
    ll cap;
    int rev;
    edge(int a, ll b, int c):to(a),cap(b),rev(c){}
  };
  
  vector<vector<edge> > G;
  vector<int> level, iter;
  int MAX_V;
  
  Dinic(int max_v):G(max_v,vector<edge>()),MAX_V(max_v){}
  
  int add_edge(int from,int to,ll cap){
    int id = G[from].size();
    
    G[from].push_back(edge(to,cap,G[to].size()));
    G[to].push_back(edge(from,0,G[from].size() - 1));
    
    return id;
  }
  
  void bfs(int s){
    level.assign(MAX_V,-1);
    queue<int> q;
    level[s] = 0;
    q.push(s);
    while(q.size()){
      int v = q.front(); q.pop();
      for(int i=0;i<G[v].size();i++){
        edge &e = G[v][i];
        if(e.cap > 0 && level[e.to] < 0){
          level[e.to] = level[v] + 1;
          q.push(e.to);
        }
      }
    }
  }
  
  ll dfs(int v, int t, ll f){
    if(v == t) return f;
    for(int &i = iter[v];i < G[v].size(); i++){
      edge &e = G[v][i];
      if(e.cap > 0 && level[v] < level[e.to]){
        ll d = dfs(e.to, t, min(f,e.cap));
        if(d > 0){
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }
  
  ll solve(int s, int t){
    ll flow = 0;
    while(1){
      bfs(s);
      if(level[t] < 0) return flow;
      iter.assign(MAX_V,0);
      ll f;
      while((f = dfs(s, t, INF)) > 0) flow += f;
    }
  }
  
};

int main(){
  int v,e,s,t,c;

  scanf("%d%d",&v,&e);

  Dinic dinic(v);

  ll pow10_8 = 100000000;
  
  for(int i=0;i<e;i++){
    scanf("%d%d%d",&s,&t,&c);

    if(c > 1){
      dinic.add_edge(s, t, c*pow10_8 + c);
      dinic.add_edge(t, s, c*pow10_8 + c);
    }else{
      dinic.add_edge(s, t, pow10_8);
      dinic.add_edge(t, s, pow10_8);
    }
  }

  ll res = dinic.solve(0,v-1);

  ll ans0 = res/pow10_8;
  ll ans1 = res%pow10_8;

  if(ans0 > ans1){
    ans1 = ans0 - 1;
  }
  
  if(ans1 <= 10000LL)
    printf("%lld\n",ans1);
  else
    puts("-1");
  
  return 0;
}

Measured memory_bytes: 3800
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char ara[20];
     cin>>ara;
    if(ara[0]=='S')
    {
        cout<<"Cloudy\n";
    }
   else if(ara[0]=='R')
    {
        cout<<"Sunny\n";
    }
    else
    {
         cout<<"Rainy\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);

int main(){
 string s; cin>>s;
  rep(i,s.size()){
  if(i%2==0) cout<<s[i];
  }
  cout<<endl;
}

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

int main(){
  string str1;
  cin>>str1;
  if (str1.at(2)==str1.at(3) && str1.at(4)==str1.at(5)){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}
    


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
//#define mod 998244353ll
#define flagcount __builtin_popcount
#define flag(x) (1ll << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1ll << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return -1;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll count = 0;
    while (b <= a)
    {
        b *= 2;
        count++;
    }
    while (c <= b)
    {
        c *= 2;
        count++;
    }
    if (count <= k)
        putout("Yes");
    else
        putout("No");
    return 0;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int seg[1000005];
int n;
void upd(int i){
    ++seg[i+=n];
    while(i>1){
        i/=2;
        seg[i]= seg[2*i]+seg[2*i+1];
    }
}
int find(int l,int r){
    l+=n; r+=n;
    int res =0;
    while(l<r){
        if(l%2) res+=seg[l++];
        if(r%2) res+=seg[--r];
        l/=2; r/=2;
    }
    return res;
}
map<int,int> last;
vector<pair<int,int>> queries[500001];
int ans[500001];
int main(){
    int q; scanf("%d%d",&n,&q);
    int x[n];
    for(int i=0;i<n;i++) scanf("%d",&x[i]);
    for(int i=0;i<n;i++)  last[x[i]] = -1;
    for(int i=0;i<q;i++){
        int a,b; scanf("%d%d",&a,&b);
        --a; --b;
        queries[b].push_back({a,i});
    }
    for(int i=0;i<n;i++){
        if(last[x[i]]!=-1)
            upd(last[x[i]]);
        last[x[i]] = i;
        for(auto q : queries[i]){
            ans[q.second] = (i-q.first+1)-find(q.first,i);
        }
    }
    for(int i=0;i<q;i++)
        printf("%d\n",ans[i]);
}


Measured memory_bytes: 52812
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, n = map(int, read().split())

def main(N, n):
    if n in (1, 2 * N - 1):
        print('No')
        return
    if N == 2:
        A = [1, 2, 3]
        print('Yes')
        print(*A, sep='\n')
        return
    if n == 2:
        a, b, c, d = 3, 2, 1, 4
    else:
        a, b, c, d = n - 1, n, n + 1, n - 2
    nums = list(range(1, N + N))
    for x in (a, b, c, d):
        nums.remove(x)
    k = len(nums) // 2
    A = nums[:k] + [a, b, c, d] + nums[k:]
    print('Yes')
    print(*A, sep='\n')

main(N, n)

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

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

    n = int(input())
    at = [list(map(int, input().split())) for _ in range(n)]
    x, y = at[0]
    for i in range(1, n):
        nx, ny = at[i]
        if nx >= x and ny >= y:
            x = nx
            y = ny
        else:
            a = max((x+nx-1)//nx, (y+ny-1)//ny)
            x = nx * a
            y = ny * a
    print(x+y)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
 
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  int sum = c - (a-b);
  if(sum >= 0) cout << sum << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////
const ll MOD = 998244353;
ll dp[3020][3020][3];
void solve(){
    ll n,s;
    cin >> n >> s;
    Vi a(n);
    rp(i,n) cin >> a.at(i);
    dp[0][0][0]=1;
    repi(i,1,n+1){
        rp(j,s+1){
            dp[i][j][0]=dp[i-1][j][0];
            dp[i][j][1]=dp[i-1][j][1]+dp[i-1][j][0];
            if(j>=a[i-1]) dp[i][j][1]+=dp[i-1][j-a[i-1]][1]+dp[i-1][j-a[i-1]][0];
            dp[i][j][2]=dp[i-1][j][2]+dp[i-1][j][1];
            if(j>=a[i-1]) dp[i][j][2]+=dp[i-1][j-a[i-1]][1]+dp[i-1][j-a[i-1]][0];
            dp[i][j][0]%=MOD;
            dp[i][j][1]%=MOD;
            dp[i][j][2]%=MOD;
        }
    }
    print(dp[n][s][2]);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

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

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
	int n, a, b;
	int ans;
	cin >> n;
	int nm = n;
    ans = modpow(2, n, 1000000007);
	cin >> a;
	int am = a;
	cin >> b;
	int bm = b;
	ll c0 = 1;
	ll c1 = 1;
	for(int i=0; i<a; i++){
    	c0 *= nm;
   		c0 %= 1000000007;
    	c0 *= modpow(am, 1000000005, 1000000007);
   		c0 %= 1000000007;
    	nm--;
    	am--;
    }
	nm = n;
	for(int i=0; i<b; i++){
    	c1 *= nm;
   		c1 %= 1000000007;
    	c1 *= modpow(bm, 1000000005, 1000000007);
   		c1 %= 1000000007;
    	nm--;
    	bm--;
    }
	ans--;
	if(ans < 0) ans += 1000000007;
	ans -= c0;
	if(ans < 0) ans += 1000000007;
	ans -= c1;
	if(ans < 0) ans += 1000000007;
    cout << ans << endl;
}

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

int n,m;
string grid[100];
int dis[100][100];

void dfs(int y, int x, int mode){
  int dx[] = {0,0,1,-1}, dy[] = {1,-1,0,0};
  for(int i=0;i<4;i++){
    int sx = x + dx[i], sy = y+dy[i];
    if(sx<0 || sy<0 || m<=sy || n<=sx)continue;
    if(mode){
      if(dis[sy][sx] < 0){
	if(grid[sy][sx] == '#'){
	  dis[sy][sx] = dis[y][x];
	  dfs(sy,sx,mode);
	}
	if(grid[sy][sx] == '.')dis[sy][sx] = dis[y][x];
      }
    }else{
      if(dis[sy][sx] < 0){
	if(grid[sy][sx] == '.'){
	  dis[sy][sx] = dis[y][x];
	  dfs(sy,sx,mode);
	}
	if(grid[sy][sx] == '#')dis[sy][sx] = dis[y][x] + 1;
      }
    }
  }
}

int main(){
  while(1){
    cin >> n >> m;
    if(!n && !m)break;

    for(int i=0;i<m;i++)cin >> grid[i];
    
    for(int i=0;i<m;i++)
      for(int j=0;j<n;j++)
	dis[i][j] = -1;
    
    for(int i=0;i<m;i++)
      for(int j=0;j<n;j++)
	if(grid[i][j] == '&'){
	  dis[i][j] = 0;
	  grid[i][j] = '.';
	}
    
    int cnt = 0;
    while(1){
      bool f = false;
      for(int i=0;i<m;i++)
	for(int j=0;j<n;j++)
	  if(dis[i][j] == cnt && grid[i][j] == '.'){
	    dfs(i,j,0);
	    f = true;
	  }
      
      cnt++;

      for(int i=0;i<m;i++)
	for(int j=0;j<n;j++)
	  if(dis[i][j] == cnt && grid[i][j] == '#'){
	    dfs(i,j,1);
	    f = true;
	  }
      if(!f)break;
    }
    
    int ans = 10000;
    for(int i=0;i<m;i++)
      for(int j=0;j<n;j++)
	if(!i || !j || i==m-1 || j==n-1)ans = min(ans,dis[i][j]);
    
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
#include <cstdio>
#include <algorithm>
#include <cmath>
#define file(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout);
using namespace std;
typedef long long ll;
const int MAXN = 200005;
const int INF = 1e9 + 1;
int n;
int r_min, r_max, b_min, b_max;
ll ans = (ll)1e18;

pair<int, int> s[MAXN];

int main() {
    scanf("%d", &n);
    r_min = INF, r_max = 0;
    for (int i = 1, x, y; i <= n; i++) {
        scanf("%d %d", &x, &y);
        s[i] = x < y ? make_pair(x, y) : make_pair(y, x);
        r_max = max(r_max, s[i].second), r_min = min(r_min, s[i].second);
    }
    sort(s + 1, s + n + 1);
    b_min = s[1].first, b_max = s[n].first;
    ans = min(ans, 1ll * (b_max - b_min) * (r_max - r_min));
    r_min = s[1].first, b_max = max(b_max, s[1].second);
    int _min = s[1].second;
    for (int i = 2; i < n; i++) {
        if ((b_min = s[i].first) > _min)
            break;
        ans = min(ans, 1ll * (b_max - b_min) * (r_max - r_min));
        b_max = max(b_max, s[i].second);
        _min = min(_min, s[i].second);
    }
    b_min = _min, ans = min(ans, 1ll * (b_max - b_min) * (r_max - r_min));
    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

int a,b,c,d,e,f,g;
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>a>>b>>c>>d;
    e = min(a,b);
    f = min(c,d);
    g = e+f;
    cout<<g<<newl;

}


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

int main(){
	int n;
	cin >> n;
	vector<int> b(n-1);
	rep(i,n-1) cin >> b[i];
	vector<int> a(n);
	a[0] = b[0];
	for(int i = 1; i <= n-2; i++){
		a[i] = min(b[i],b[i-1]);
	}
	a[n-1] = b[n-2];
	int ans = 0;
	rep(i,n) ans += a[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int 
#define mk make_pair


int main(){
    int curr=0;
    int k;cin>>k;
    int ans=-1;
    bool visited[k]={false};
    int f=1;
    while(f){
        curr=(curr*10+7)%k;
        if(visited[curr])break;
        visited[curr]=true;
        if(curr==0){ans=f;break;}
        f++;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 4572
#include<bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace std;
long long k,n;
int num[100005];
int pos,mk=INT_MAX;
int main()
{
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
    {
    	scanf("%d",&num[i]);
    	if(mk>num[i])pos=i,mk=num[i];
    	k+=num[i];
	}
	if(k%(((n+1)*n)/2)==0)
	{
		long long c=k/(((n+1)*n)/2);
		bool p=true;
		if((long long)c*(long long)n>999999999)
		{
			c=k/(((n+1)*n)/2);
			bool p=true;
			c=c*(n-1);
			if(abs(num[n]-num[1])>c)p=false;
			for(int i=1;i<n;i++)
			{
				if(abs(num[i]-num[i+1])>c)p=false;
			}
		}
		else
		{
			while(c--)
			{
				int poss;
				for(int i=pos;i<=n;i++)
				{
					num[i]-=(i-pos+1);
					if(mk>num[i])mk=num[i],poss=i;
				}
				for(int i=1;i<pos;i++)
				{
					num[i]-=(i+(n-pos)+1);
					if(mk>num[i])mk=num[i],poss=i;
				}	
				pos=poss;
				/*for(int i=1;i<=n;i++)
				{
					printf("%d ",num[i]);
				}
				printf("pos %d %d\n",pos,mk);*/
				if(mk<=0)break;
				mk=INT_MAX;
			}
			for(int i=1;i<=n;i++)
			{
				//printf("%d ",num[i]);
				if(num[i]!=0)p=false;
			}	
		}
		if(p)printf("YES");
		else printf("NO");
	}
	else
	{
		printf("NO");
	}
}



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

#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()

typedef long long ll;

const char nl = '\n' ;


int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0);
   string a, b, c;
   cin >> a >> b >> c;
   reverse(all(a));
   reverse(all(b));
   reverse(all(c));
   char ch = 'a';
   while(1)
   {
      if(ch == 'a')
      {
         if(a.empty())
         {
            cout << "A" << nl;
            return 0;
         }
         ch= a.back();
         a.pop_back();
      }
      if(ch == 'c')
      {
         if(c.empty())
         {
            cout << "C" << nl;
            return 0;
         }
         ch= c.back();
         c.pop_back();
      }
      if(ch == 'b')
      {
         if(b.empty())
         {
            cout << "B" << nl;
            return 0;
         }
         ch= b.back();
         b.pop_back();
      }
   }






	return 0;
}


Measured memory_bytes: 3616
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

template<typename T>
vector<T> gen_v(size_t a) { return vector<T>(a); }
template<typename T, typename ...Ts>
auto gen_v(size_t a, Ts... ts) { return vector<decltype(gen_v<T>(ts...))>(a, gen_v<T>(ts...)); }
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	string s; cin >> s;
	int ans = 0;
	rep(i, 0, 1000) {
		int k = i;
		int cnt = 0;
		rrep(j, 0, N) {
			if (s[j] - '0' == k % 10) {
				k /= 10;
				cnt++;
				if (cnt == 3)break;
			}
		}
		if (cnt == 3)ans++;
	}
	cout << ans << endl;
	return 0;
}

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

#define fio                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ld long double
#define endl "\n"
#define ff first
#define ss second
#define pi pair<ll, ll>
#define PI 3.141592653589793238462643383279502884L
#define mp make_pair
#define pb push_back
#define fall(i, a, b) for (int i = a; i < b; i++)
#define sz(x) (ll) x.size()
#define all(x) x.begin(), x.end()
#define ed cout << "ed";
ll M = 1e9 + 7;

ll mod(ll a, ll m)
{
    if (a == 0)
        return 0;
    else
        return (a % m + m) % m;
}

int main()
{
    fio;
    string s, t;
    cin >> s >> t;
    if (s.compare(t.substr(0, t.length() - 1)) == 0)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <queue>
using namespace std;
int main() {
	int n, m, x, y;
    cin >> n >> m >> x >> y;
    int xx[200], yy[200];
    for(int i = 0; i < n; i++) cin >> xx[i];
    for(int j = 0; j < m; j++) cin >> yy[j];
    int xcounter = 0;
    int ycounter = 0;
    bool ans = 0;
    for(int k = x+1; k <= y; k++){
         for(int i = 0; i < n; i++){
             if(k > xx[i]) xcounter++;
         }
         for(int j = 0; j < m; j++){
             if(k <= yy[j]) ycounter++;
         }
         if(xcounter == n and ycounter == m){
             ans = 1;
             //cout << k << endl;
             break;
         }
         xcounter = 0;
         ycounter = 0;
    }

    if(ans == 1) cout << "No War" << endl;
    else cout << "War" << endl;
    return 0;
}

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

 int main() {
   int K, N, mx = 0;
   cin >> K >> N;

   vector<int> A(N);

   rep(i, 0, N) cin >> A.at(i);

   rep(i, 0, N - 1) {
     mx = max(A.at(i + 1) - A.at(i), mx);
   }

   mx = max(mx, K - A.at(N - 1) + A.at(0));

   cout << K - mx << endl;
 }


Measured memory_bytes: 1024
//https://atcoder.jp/contests/abc052/tasks/arc067_b
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
    ll N, A, B; cin>>N>>A>>B;
    vector<ll> xn(N);
    for(auto&& x:xn){
        cin>>x;
    }
    ll ans=0;
    ll now=0;
    FOR(i,1,xn.size()){
        auto len = xn.at(i) - xn.at(now);
        ans += min(len*A,B);
        now=i;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
object Main{
  def main(args:Array[String]) : Unit ={
    val sc = new java.util.Scanner(System.in)
    val str = sc.next()
    val r = """\d{4}/(\d{2})/\d{2}""".r
    val date = r.findFirstMatchIn(str)
    
    val month:Int = date.get.group(1).toInt
    
    println(if(month >= 5) "TBD" else "Heisei")
    
    
  }
}

Measured memory_bytes: 27700
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <numeric>
using namespace std;


int main()
{
    int a[6];
    for(int i=1;i<6;i++){
        cin>>a[i];
    }
    int k;
    cin>>k;
    bool flag=true;
    if(a[5]-a[1]>k){
        flag=false;
    }
    if(flag){
        cout<<"Yay!"<<endl;
    }
    else{
        cout<<":("<<endl;
    }

    }



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

int main(){
  int n,r;
  stack<int> sp;
  stack<int> cp;
  list<int> m;
  while(cin>>n>>r,n|r){
    for(int i=1;i<=n;i++){
      m.push_back(i);
    }
    int p,c;
    while(r--){
      cin>>p>>c;
      for(int i=0;i<p-1;i++){
       	sp.push(m.back());
	m.pop_back();
      }
      for(int i=0;i<c;i++){
	cp.push(m.back());
	m.pop_back();
      }
      for(int i=0;i<p-1;i++){
       	m.push_back(sp.top());
	sp.pop();
      }
      for(int i=0;i<c;i++){
       	m.push_back(cp.top());
	cp.pop();
      }
    }
    cout<<m.back()<<endl;
  }
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
pair<int,pair<int,int> > c[100005];
bool tree[200005];
int par[200005];
int find(int x)
{
	if (par[x]!=x)
	par[x]=find(par[x]);
	return par[x];
}
void Union(int x,int y)
{
	x=find(x);
	y=find(y);
	if (x==y)
	tree[x]=0;
	else
	{
		par[x]=y;
		tree[y]&=tree[x];
	}
}
int main()
{
	int n,h,w;
	scanf("%d%d%d",&n,&h,&w);
	for (int i=0;i<n;i++)
	scanf("%d%d%d",&c[i].second.first,&c[i].second.second,&c[i].first);
	sort(c,c+n);
	reverse(c,c+n);
	for (int i=1;i<=h+w;i++)
	{
		par[i]=i;
		tree[i]=1;
	}
	long long ans=0;
	for (int i=0;i<n;i++)
	{
		int c1=find(c[i].second.first),c2=find(c[i].second.second+h);
		if (tree[c1] || tree[c2])
		{
			ans+=c[i].first;
			Union(c1,c2);
		}
	}
	printf("%lld",ans);
}

Measured memory_bytes: 6524
object Main extends App {
  
  val sc = new java.util.Scanner(System.in)
  val array = Array.fill(3)(sc.nextInt()).sorted
  val diff = array(2) - array(0) + array(2) - array(1)
  if (diff % 2 == 0) {
    println(diff / 2)
  } else {
    println(diff / 2 + 2)
  }
}


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

int compar(const void *a, const void *b);

int main(void) {
  int a[3];

  scanf("%d %d %d", &a[0], &a[1], &a[2]);

  qsort(a, 3, sizeof(int), &compar);

  printf("%d %d %d\n", a[0], a[1], a[2]);
  return 0;
}

int compar(const void *a, const void *b) {
  //  printf("%d %d\n", *(int *)a, *(int *)b);
  return (*(int *)a - *(int *)b);
}

Measured memory_bytes: 600
a, b, c, x = map(int, [input() for i in range(0, 4)])
count = 0

for a_i in range(0, a + 1):
    if a_i * 500 > x:
        break
    for b_i in range(0, b + 1):
        for c_i in range(0, c + 1):
            if a_i * 500 + b_i * 100 + c_i * 50 == x:
                count += 1

print(count)


Measured memory_bytes: 3060
#include<stdio.h>
int main(){
  char s[4];
  int a=0,b=0,c=0,i;
  
  scanf("%s",s);
  
  for(i=0;i<3;i++){
    if(s[i]=='a')
      a++;
    if(s[i]=='b')
      b++;
    if(s[i]=='c')
      c++;
  }
  
  if(a==1&&b==1&&c==1)
    printf("Yes");
  else
    printf("No");
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORit(it,a) for(auto it=a.begin();it!=a.end();it++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define vec vector
#define pb push_back
#define pop pop_back
#define STF() shrink_to_fit()
#define all(x) x.begin(),x.end()
#define testcases ll t;cin>>t;while(t--)
#define mem(a,k) memset(a,k,sizeof(a))
#define F first
#define S second
#define MP(x,y) make_pair(x,y)
#define rt return
#define br break
#define ct continue
#define elif else if
#define ii pair<ll,ll>
#define arrin(a,n,index) for(int i=index;i<n;i++)cin>>a[i]
#define vecin(a,n,index) for(int i=index;i<n;i++)cin>>a[i]
#define arrout(a,n,index) for(int i=index;i<n;i++)cout<<a[i]<<" ";cout<<endl;
#define vecout(a,n,index) for(int i=index;i<n;i++)cout<<a[i]<<" ";cout<<endl;
//ll mod = 1000000007;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
	// START FROM HERE :)
	int n, x, t;
	cin >> n >> x >> t;
	ll ans = 0;
	ans = ceil(float(n) / float(x)) * t;
	cout << ans << endl;
}


Measured memory_bytes: 3632
K = int(input())

count = 0
if K % 2 == 0 or K % 5 == 0:
    print(-1)
    exit()

remain = 7 % K
set_remain = set()
while (True):
    count += 1
    if remain == 0:
        print(count)
        exit()
    if remain in set_remain:
        break
    else:
        set_remain.add(remain)
    remain = (remain * 10 + 7) % K

print(-1)

Measured memory_bytes: 77780
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)


using namespace std;


template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const ll &a, const ll &b){
    return abs(a)>abs(b);
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};


struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}


bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};


int main(){
    IOS;
    make(ll,x);
    cout<<(x^1)<<endl;


    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

const ll MOD = 1e9 + 7;
const int N = 1e5 + 1;
vi adj[N];
ll dp[N][2];

void dfs(int u, int p) {
	dp[u][0] = dp[u][1] = 1;
	for (int v : adj[u]) if (v != p) {
		dfs(v, u);
		dp[u][0] = (dp[u][0] * dp[v][1]) % MOD;
		dp[u][1] = (dp[u][1] * (dp[v][0] + dp[v][1])) % MOD;
	}
}

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n-1; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	dfs(1, 0);
	//for (int i = 1; i <= n; i++) printf("%lld %lld\n", dp[i][0], dp[i][1]);
	ll answer = (dp[1][0] + dp[1][1]) % MOD;
	printf("%lld\n", answer);
}


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

#define ll long long
#define vl vector<ll>
#define vvl vector<vector<ll>> //vvl data(10, vector<ll>(10);
#define fo(i,a,b) for(ll i=a; i<b; i++)

int main(){
    double A, B, H, M;
    cin >> A >> B >> H >> M;

    double pi = 2.0 * asin(1.0);
    double degree = abs((H*30 + M*0.5) - (M*6));
    double ans = sqrt(A*A + B*B - 2*A*B*cos(pi/180*degree));

    printf("%.20f\n", ans);

}

/*
　 ◇　　　　 ミ ◇
　◇◇　 /￣|　 ◇◇
◇◇＼　 L＿| ◇◇
　　彡Ｏ(・＿・)/
　 　　ヽ Ｐ`Ｏ
　　 ／彡#_|ミ＼
　　　 </LL凵>
　　　　∪ ∪
pass system test !!
*/

Measured memory_bytes: 4228
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()

    # maxの逆演算のため、hが0なものとそうでないものに分類
    xyh_0 = []
    xyh_not0 = []
    for _ in range(N):
        xyh = LI()
        if xyh[2] == 0:
            xyh_0.append(xyh)
        else:
            xyh_not0.append(xyh)

    for cx, cy in itertools.product(range(101), range(101)):
        H = []
        for x, y, h in xyh_not0:
            H.append(h + abs(x - cx) + abs(y - cy))
        # hが0でないものでOKだったら、hが0のもので辻褄が会うかどうか見る
        if len(set(H)) == 1:
            is_ok = True
            for x, y, h in xyh_0:
                if max(H[0] - abs(x - cx) - abs(y - cy), 0) != 0:
                    is_ok = False
            if is_ok:
                ans = (cx, cy, H[0])

    print(*ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9928
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    // インタラクティブ問題では除去した方がいいかも
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll n, m, l; cin >> n >> m >> l;

    vector<ll> a(m), b(m), c(m);
    vector<vector<ll>> d(n, vector<ll>(n, INF));
    REP(i, m) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--;
        if (c[i] <= l) {
            d[a[i]][b[i]] = d[b[i]][a[i]] = c[i];
        }
    }

    ll q; cin >> q;
    vector<ll> s(q), t(q);
    REP(i, q) {
        cin >> s[i] >> t[i];
        s[i]--; t[i]--;
    }
    
    // ワーシャルフロイド
    REP(k, n) REP(i, n) REP(j, n) {
        chmin(d[i][j], d[i][k] + d[k][j]);
    }
    
    vector<vector<ll>> dp(n, vector<ll>(n, INF));
    REP(i, n) REP(j, n) if (i != j) {
        if (d[i][j] <= l) {
            dp[i][j] = 1;
        }
    }

    // ワーシャルフロイド
    REP(k, n) REP(i, n) REP(j, n) {
        chmin(dp[i][j], dp[i][k] + dp[k][j]);
    }

    REP(i, q) {
        if (dp[s[i]][t[i]] == INF) {
            cout << "-1" << endl;
        } else {
            cout << dp[s[i]][t[i]] - 1 << endl;
        }
    }

    
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes                \
    cout << "Yes" << endl; \
    return 0;
#define No                \
    cout << "No" << endl; \
    return 0;
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template <typename T>
void print(const T &v);

int main()
{
    int N;
    cin >> N;
    vector<vector<int>> F(N, vector<int>(10));
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < 10; j++)
        {
            cin >> F[i][j];
        }
    }
    vector<vector<int>> P(N, vector<int>(11));
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < 11; j++)
        {
            cin >> P[i][j];
        }
    }
    int maxi = -INF;
    for (int i = 1; i <= 1023; i++) // 全通り試行する
    {
        int total = 0;
        for (int j = 0; j < N; j++) // j番目の店舗について試行する
        {
            bitset<10> bs(i);
            int cnt = 0;
            for (int k = 0; k < 10; k++)
            {
                if (bs.test(k)) // k日目のbitが立っているか
                {
                    if (F[j][k] == 1)
                    {
                        cnt++;
                    }
                }
            }
            total += P[j][cnt];
        }
        maxi = max(total, maxi);
    }
    cout << maxi << endl;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll int
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
const ll mod=998244353;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> data_struct;

int main()
{
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	if(a>=k)
      cout<<k;
    else if(a+b>=k)
		cout<<a;
	else
		cout<<a-(k-(a+b));
}

Measured memory_bytes: 3544
def args():
    N = int(input())
    H = tuple(map(int, input().split()))

    # print(N)
    # print(H)

    return N, H


def solve(N, H):
    DP = [float("inf")] * N
    DP[0] = 0

    for i in range(N - 1):
        # print(DP[i] + abs(H[i] - H[i + 1]))
        DP[i + 1] = min(DP[i + 1], DP[i] + abs(H[i] - H[i + 1]))
        if i + 2 < N:
            DP[i + 2] = min(DP[i + 2], DP[i] + abs(H[i] - H[i + 2]))

    # print(DP)

    return DP[-1]


if __name__ == '__main__':
    res = solve(*args())
    print(res)


Measured memory_bytes: 53576
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;


public class Main {
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    
    if (A <= C && C <= B) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }

}


class FastScanner {
	public static String debug = null;

	private final InputStream in = System.in;
	private int ptr = 0;
	private int buflen = 0;
	private byte[] buffer = new byte[1024];
	private boolean eos = false;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				if (debug != null) {
					buflen = debug.length();
					buffer = debug.getBytes();
					debug = "";
					eos = true;
				} else {
					buflen = in.read(buffer);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen < 0) {
				eos = true;
				return false;
			} else if (buflen == 0) {
				return false;
			}
		}
		return true;
	}

	private 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 isEOS() {
		return this.eos;
	}

	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() {
		return (int) nextLong();
	}

	public long[] nextLongList(int n) {
		return nextLongTable(1, n)[0];
	}

	public int[] nextIntList(int n) {
		return nextIntTable(1, n)[0];
	}

	public long[][] nextLongTable(int n, int m) {
		long[][] ret = new long[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextLong();
			}
		}
		return ret;
	}

	public int[][] nextIntTable(int n, int m) {
		int[][] ret = new int[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextInt();
			}
		}
		return ret;
	}
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

void compute() {

}

int main() {
  int n;
  cin >> n;
  vector<ll> A(n), B(n);
  rep(i,n) cin >> A[i] >> B[i];
  ll ans = 0, base = 0;
  for(int i=n-1;i>=0;--i) {
    ll v = ( A[i] + base ) % B[i];
    if( v ) v = B[i] - v;
    ans += v;
    base += v;
  }
  cout << ans << endl;
  compute();
  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<string>
#include<set>
#include<vector>
using namespace std;

int solve(){
  long long h;  cin >> h;
  long long n=0;
  while(h>0){
    h/=2;
    n++;
  }
  cout << to_string((long long)pow(2,n)-1) << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
typedef long long       ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define mem(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define f first
#define s second
#define fore(i, b, e)    for (int i = (int)b; i < (int)e; i++)
#define forr(i, b, e)    for (int i = (int)b; i < (int)e; i++)
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
//using namespace __gnu_pbds;

typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int INF = int(1e9 + 7);
const double EPS = 1e-9;
const double PI = acos(-1);
#define tam 3341

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    string t;
    cin>>t;
    if (t[2]==t[3] && t[4]==t[5])
        cout<<"Yes\n";
    else
        cout<<"No\n";
}
// PLUS ULTRA!


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

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

static const double eps = 1e-8;

int main(){
	int w;
	while(~scanf("%d",&w)){
		if(w==-1) break;
		printf("%d\n",4280 - (1150 + (w > 30 ? 125 * 10 + 140 * 10 + 160 * (w-30)
			: w > 20 ? 125 * 10 + 140 * (w-20)
			: w > 10 ? 125 * (w-10)
			: 0)));
	}
}

Measured memory_bytes: 0
// D - 11
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

#define MAX 100000
ll fac[MAX+1]; // 累乗 n!
ll inv[MAX+1]; // 逆元 1/n
ll finv[MAX+1]; // 逆元の累乗 (n^-1)! = (1/n)!

void init(int n, int p){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	rp(i, 2, n+1){
		fac[i] = fac[i-1] * i % p;
		inv[i] = p - inv[p%i] * (p/i) % p;
		finv[i] = finv[i-1] * inv[i] % p;
	}
}

ll nCk_mod(int n, int k, int m){
	if(n<k || n<0 || k<0) return 0;
	return fac[n] * (finv[n-k] * finv[k] % m) % m;
}

void solve(int N, vi &A){
	int d = 0;
	vi exist(N+1, -1);
	rp(i, 0, N+1){
		if(exist[A[i]] >= 0){
			d = i - exist[A[i]];
			break;
		}
		exist[A[i]] = i;
	}
	int MOD = 1000000007;
	init(N+1+1, MOD);
	rp(k, 1, N+2){
		ll ans = (nCk_mod(N+1, k, MOD) - nCk_mod(N-d, k-1, MOD)) % MOD;
		if(ans < 0) ans += MOD;
		cout<< ans <<endl;
	}
}

int main(){
	int N; cin>>N;
	vi A(N+1);
	rp(i, 0, N+1) cin>>A[i];
	solve(N, A);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
ll a[100005];
ll lc(ll a, ll b){
    ll g = __gcd(a,b);
    return (a*b)/g;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    ll m;
    cin>>m;
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    ll lcm = 1;
    for(int i=0;i<n;i++){

        lcm = lc(lcm,a[i]);
        if(lcm>5*m){
            cout<<0<<endl;
            return 0;
        }
    }
    for(int i=0;i<n;i++){
        if((lcm/a[i])%2==0){
            cout<<0<<endl;
                return 0;
        }
    }
    cout<<(m+lcm/2)/lcm<<endl;
    return 0;

}


Measured memory_bytes: 1024