akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	// 整数の入力
	int a = sc.nextInt();

	// 出力
	int count = 0;
	int x = 333;

	for (x = 333; x <= a; x = next753(x)){
	    if (is753(x)){
		count ++;
	    }
	}
	
	System.out.println(count);
    }

    private static int next753(int n){
	return next753_1(n, 0);
    }

    private static int next753_1(int n, int k){
    	int x = n;
    	int y = n;
	int z = 1;
    	for (int i = 1; i <= k; i++){
    	    y /= 10;
	    z *= 10;
    	}

    	if(y % 10 == 0){
    	    x += 3 * z;
    	}else if(y % 10 == 3){
    	    x += (5-3) * z;
    	}else if (y % 10 == 5){
    	    x += (7-5) * z;
    	}else{
    	    x += (3-7) * z;
    	    return next753_1(x, k +1);
    	}
    	return x;
    }

    private static boolean is753(int n){
	boolean has3 = false;
	boolean has5 = false;
	boolean has7 = false;
	for(int x = n; x > 0; x /= 10){
	    if(x % 10 == 3){
		has3 = true;
	    }else if(x % 10 == 5){
		has5 = true;
	    }else if(x % 10 == 7){
		has7 = true;
	    }
	    if(has3 && has5 && has7){
		return true;
	    }
	}
	return false;
    }
}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
#define Mod 1000000007
#define Val(x) ((((long long)x) % Mod + Mod) % Mod)
using namespace std;
int Pow(int a,int n) {
	int ret = 1 , base = a;
	while(n) {
		if(n&1)	ret = Val(ret * base);
		base = Val(base * base);
		n >>= 1;
	}
	return ret;
}
int C(int n,int a) {
	int ret = 1;
	for(int i=n-a+1;i<=n;i++)
		ret = Val(ret * i);
	for(int i=2;i<=a;i++)
		ret = Val(ret * Pow(i,Mod-2));
	return ret;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,a,b;
	cin >> n >> a >> b;
	cout << Val(Pow(2,n) - C(n,a) - C(n,b) - 1) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int a, b, c, d, e, k;
  
  scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &k);
  
  if((e - a) <= k){
    printf("Yay!\n");
  }
  else{
    printf(":(\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cmath>
const double PI=acos(-1);
int main() {
    int a,b,x;
    scanf("%d%d%d",&a,&b,&x);
    int v=a*a*b;
    if(x+x<=v) {
        double l=2.0*x/a/b;
        printf("%.10f",atan(b/l)*180/PI);
    }
    else {
        double l=b+b-2.0*x/a/a;
        printf("%.10f",(PI/2-atan(a/l))*180/PI);
    }
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

string color[8] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
string strength[8] = {"000000", "0000ff", "00ff00", "00ffff", "ff0000", "ff00ff", "ffff00", "ffffff"};

int toi(string s){
    int ret = 0;
    rep(i, s.size()){
        string t = s.substr(i, 1);
        if('0' <= t[0] && t[0] <= '9') ret += stoi(t);
        else ret += t[0]-'a'+10;
        if(i != s.size()-1) ret *= 16;
    }
    return ret;
}

vector<int> rgb(string s){
    vi ret;
    rep(i, 3){
        string t = s.substr(i*2, 2);
        ret.pb(toi(t));
    }
    return ret;
}

int main(){
    string  s;
    while(cin >> s, s!="0"){
        s = s.substr(1);
        vi c = rgb(s);
        double m = inf;
        int ans = 0;
        rep(i, 8){
            vi d = rgb(strength[i]);
            double ret = sqrt(pow(c[0]-d[0], 2)+pow(c[1]-d[1], 2)+pow(c[2]-d[2], 2));
            if(m > ret){ans = i; m = ret;}
        }
        cout << color[ans] << endl;
    }
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

ll beki(ll x, ll n, const ll &p) {
    ll ret = 1;
    while (n > 0) {
        if (n & 1) (ret *= x) %= p;
        (x *= x) %= p;
        n >>= 1;
    }
    return ret;
}

void solve() {
    ll k;
    cin >> k;
    int rem = 0;
    rep(i, k + 1) {
        rem = (rem + beki(10, i, k) * 7) % k;
        if (rem == 0) {
            cout << i + 1 << endl;
            return;
        }
    }
    cout << -1 << endl;
    return;
}

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

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int>P;//Pre val
#define fi first
#define se second
 
const int SIZE=16777216;
int dat[SIZE*2-1];
const int INF=LLONG_MAX/100;
void update(int k,int x){
    k+=SIZE-1;
    dat[k]=x;
    while(k){
        k=(k-1)/2;
        dat[k]=max(dat[k*2+1],dat[k*2+2]);
    }
}
 
int getMax(int a,int b,int k=0,int l=0,int r=SIZE){
    if(a<=l&&b>=r)return dat[k];
    if(r<=a||b<=l)return -INF;
 
    int m=(l+r)/2;
    int vl=getMax(a,b,k*2+1,l,m);
    int vr=getMax(a,b,k*2+2,m,r);
    return max(vl,vr);
}
 
int N,D;
int X[30],Y[30];
 
vector<P>A,B;
void Latte(int cur,int last,int val,int pre,bool after){
    if(cur==last){
        if(after)B.push_back(P(pre,val));
        else A.push_back(P(pre,val));
        return;
    }
 
    Latte(cur+1,last,val+X[cur],pre+Y[cur],after);
    Latte(cur+1,last,val-X[cur],pre-Y[cur],after);
    Latte(cur+1,last,val,pre,after);
}
 
 
signed main(){
    cin>>N>>D;
    for(int i=0;i<N;i++)cin>>Y[i]>>X[i];
 
    Latte(0,N/2,0,0,false);
    Latte(N/2,N,0,0,true);
 
    sort(A.rbegin(),A.rend());
    sort(B.begin(),B.end());
    fill_n(dat,SIZE*2-1,-INF);
    for(int i=0;i<B.size();i++){
        update(i,B[i].second);
    }
 
    int ans=-INF;
    int lb=0,ub=0;
    for(int i=0;i<A.size();i++){
        while(lb<B.size()&&-D-A[i].fi>B[lb].fi)lb++;
        while(ub<B.size()&&D-A[i].fi>=B[ub].fi)ub++;
        ans=max(ans,A[i].se+getMax(lb,ub));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 713308
//naveen mall
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb               push_back
#define sz(c)            (int)c.size()
#define len(c)           (int)c.length()
#define vec              vector
#define int              long long int
#define all(c)           c.begin(), c.end()
#define rall(c)          c.rbegin(), c.rend()
#define trav(a,i)        for(auto i: a)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define invect(v,n)       for(int i=0;i<n;i++ ){int arb;cin>>arb;v.pb(arb);}
#define inset(s,n)        fl(i,0,n){int aset;cin>>aset;s.insert(aset);}
#define display(c)        trav(c,i) cout<<i<<" ";cout<<"\n";
#define F                 first
#define S                 second
#define pii               pair<int,int>
#define PB                pop_back
#define endl              "\n"
#define what(x) cerr << #x << " is " << x << endl;
int sum() { return 0; }template<typename T,typename... Args>T sum(T a, Args... args) { return a + sum(args...); }
#define p   200005




void solve()
{  
  int k,n;
  cin>>k>>n;
  int a[n+1];
  rep(i,0,n)
    cin>>a[i];
  
    vec<int> v;

    rep(i,1,n)
      v.pb(a[i]-a[i-1]);
      v.pb(abs(k-a[n-1]+a[0]));
      //display(v)
      int s=0;
     sort(all(v));
        for(int i=0;i<sz(v)-1;i++)
            s+=v[i];
          cout<<s;



  




   
 }

  

signed main()
{fast
  int t;
  //cin>>t;
  t=1;
  while(t--)
    {solve();}
  
}












Measured memory_bytes: 3956
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, A;
    cin >> H >> A;
    cout << (H + A - 1) / A << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 101
#define X 298
 
void init(int [N][X]);
 
int main(void) {
    int n, x, tbl[N][X] = {};
    init(tbl);
    while(scanf("%d %d", &n, &x), n || x) {
        printf("%d\n", 0 < x && x < X ? tbl[n][x] : 0);
    }
    return 0;
}
 
void init(int tbl[N][X]) {
    int i, j, k;
    double v;
    for(i = 3; i < N; i++) {
        v = 1;
        for(j = i + 3; j <= ~-i * 3; j++) {
            for(k = i; k < N; k++) {
                tbl[k][j] += (int)v;
            }
            if(j < i * 2) {
                v += 0.5;
            } else {
                v -= 0.5;
            }
        }
    }
}

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

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

int desc(const void *a, const void *b) {
    return *(int*)b - *(int*)a;
}
int main() {
    int n, k;
    scanf("%d %d", &n, &k);
    int *h = malloc(sizeof(int) * n);
    for (int i = 0; i < n; i++) {
        scanf("%d ", &h[i]);
    }

    qsort(h, n, sizeof(int), desc);
    long long result = 0;
    for (int i = MIN(k, n); i < n; i++) {
        result += h[i];
    }
    printf("%lld", result);
    return 0;
}

Measured memory_bytes: 1788
global x
def get(left,right):
    if(x[left]*x[right]<0):
        return min([2*abs(x[left]) +x[right], 2*abs(x[right]) + abs(x[left])])

    else:
        return max([abs(x[left]),x[right]])


n,k=map(int,input().split())
x=list(map(int,input().split()))


tmp_min=get(0,k-1)
for i in range(1,n):
    if(i+k-1 >=n):
        break
    tmp_min=min([tmp_min ,get(i,i+k-1)])
    if(x[i]>=0):
        break
    

print(tmp_min)

Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (int)(s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
constexpr long long INF = 1e18;
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a=b;return true;}return false;}

int A,B,C,D,E,F,G,X,Y,Z,N,M,W;
string s,t;

signed main(){
	string s[] = {"Sunny","Cloudy","Rainy"};
	string t;
	cin >> t;
	REP(i,3){
		if(t==s[i]){
			cout<<s[(i+1)%3]<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <sstream>
#include <map>
#include <cstring>
#include <vector>
#include <queue>
#include <iomanip>

using namespace std;
typedef long long ll;

ll ans, mx, sum, mn = 1e8, cnt;

string c[200001];
ll idx;
int main(){
	ll n;
	cin>>n;
	map<string,ll> mp;
	for(ll i=0; i<n; i++){
		string s;
		cin>>s;
		mp[s]++;
	}
	for(auto i : mp){
		mx = max(mx,i.second);
	}
	for(auto i : mp){
		if(i.second==mx) c[idx++]=i.first;
	}
	sort(c,c+idx);
	for(ll i=0; i<idx; i++){ 
		cout<<c[i]<<endl;
	}
	
}

Measured memory_bytes: 25480
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author dauom
 */
public class Main {
  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    CTsundoku solver = new CTsundoku();
    solver.solve(1, in, out);
    out.close();
  }

  static class CTsundoku {
    public final void solve(int testNumber, InputReader in, PrintWriter out) {
      int n = in.nextInt();
      int m = in.nextInt();
      int k = in.nextInt();
      int[] a = in.nextIntArray(n);
      int[] b = in.nextIntArray(m);
      long sumb = 0;
      int j = 0;
      for (; j < m; j++) {
        int x = b[j];
        if (x + sumb > k) {
          break;
        }
        sumb += x;
      }
      --j;

      int max = j + 1;
      long suma = 0;
      for (int i = 0; i < n; i++) {
        suma += a[i];
        while (j >= 0 && suma + sumb > k) {
          sumb -= b[j--];
        }
        if (suma + sumb > k) {
          break;
        }
        max = Math.max(max, j + 1 + i + 1);
      }

      out.print(max);
    }
  }

  static final class InputReader {
    private final InputStream stream;
    private final byte[] buf = new byte[1 << 16];
    private int curChar;
    private int numChars;

    public InputReader() {
      this.stream = System.in;
    }

    public InputReader(final InputStream stream) {
      this.stream = stream;
    }

    private final int read() {
      if (this.numChars == -1) {
        throw new UnknownError();
      } else {
        if (this.curChar >= this.numChars) {
          this.curChar = 0;

          try {
            this.numChars = this.stream.read(this.buf);
          } catch (IOException ex) {
            throw new InputMismatchException();
          }

          if (this.numChars <= 0) {
            return -1;
          }
        }

        return this.buf[this.curChar++];
      }
    }

    public final int nextInt() {
      int c;
      for (c = this.read(); isSpaceChar(c); c = this.read()) {}

      byte sgn = 1;
      if (c == 45) { // 45 == '-'
        sgn = -1;
        c = this.read();
      }

      int res = 0;

      while (c >= 48 && c <= 57) { // 48 == '0', 57 == '9'
        res *= 10;
        res += c - 48; // 48 == '0'
        c = this.read();
        if (isSpaceChar(c)) {
          return res * sgn;
        }
      }

      throw new InputMismatchException();
    }

    private static final boolean isSpaceChar(final int c) {
      return c == 32 || c == 10 || c == 13 || c == 9
          || c == -1; // 32 == ' ', 10 == '\n', 13 == '\r', 9 == '\t'
    }

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


Measured memory_bytes: 35588
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps DBL_EPSILON
#define mod (ll)1000000007
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
signed main() {
	int m, d;
	cin >> m >> d;
	int ans = 0;
	REP(i, m) {
		REP(j, d) {
			if (j < 10)continue;
			if ((j / 10) * (j % 10) == i && j / 10 >= 2 && j % 10 >= 2)ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define F first
#define S second
#define SHN 1e9
#define lSHN 1e18
using namespace std;
ll a[100010];
ll b[100010];
ll c[100010];
ll d[100010];
int n;
ll res=0;
int main()
{
	cin >>n;
	for (int i=0;i<n;i++) cin >>c[i];
	for (int i=0;i<n;i++) cin >>b[i];
	for (int i=0;i<n;i++) cin >>a[i];
	sort(a,a+n);
	sort(b,b+n);
	sort(c,c+n);
	for (int i=0;i<n;i++)
	{
		d[i]=lower_bound(c,c+n,b[i])-c; 
		if (i) d[i]+=d[i-1];
	}
	for (int i=0;i<n;i++)
	{
		ll t=lower_bound(b,b+n,a[i])-b;
		//cout <<t<<" ##\n";
		if (t) res+=d[t-1];
	}
	cout <<res;
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
using namespace std;
int ans = 0;


int main(void) {
    // insert code here...
    char a;
    for(int i = 0; i <4; i++){
        cin >> a;
        if(a=='+'){
            ans++;
        }else{
            ans--;
        }
    }
    
    cout << ans << endl;
}


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

typedef long long ll;

int main()
{
  ll n,x,ans,y;

  cin>>n>>x;

  ans+=n;
  y=n-x;

  while(1){
    ans+=(y/x)*2*x;
    if(y%x==0){
      ans-=x;
      break;
    }
    ll tmp1=x,tmp2=y;
    y=tmp1;
    x=tmp2%tmp1;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(input())
a1 = [int(i) for i in input().split()]
a2 = [int(i) for i in input().split()]

ans = 0
tmp = 0
for i in range(n):
    tmp = sum(a1[0:i+1]) + sum(a2[i:n])
    #print(sum(a1[0:i+1]))
    #print(sum(a2[i:n]))
    if ans < tmp:
        ans = tmp
print(ans)


Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
n = int(input())
A = [int(i) for i in readline().split()]

for a in A:
    if a % 2 == 0 and a % 3 != 0 and a % 5 != 0:
        print('DENIED')
        break
else:
    print('APPROVED')


Measured memory_bytes: 2940
N,M=map(int,input().split())
d=[[float('inf') for x in range(N)] for y in range(N)]
for i in range(N):
  d[i][i]=0
ans=[]
for i in range(M):
  a,b,c=map(int,input().split())
  d[a-1][b-1]=c
  d[b-1][a-1]=c
  ans.append([a-1,b-1,c])

for k in range(N):
  for i in range(N):
    for j in range(N):
      if d[i][j]>d[i][k]+d[k][j]:
        d[i][j]=d[i][k]+d[k][j]

res=0
for a,b,c in ans:
  if d[a][b]!=c:
    res+=1

print(res)

Measured memory_bytes: 3696
n, k = map(int, input().split())
a = list(map(int, input().split()))
dist = [-1] * n

i = 0
dist[0] = 0
while True:
    nxt = a[i] - 1
    if dist[nxt] >= 0:
        if k > dist[nxt]:
            k -= dist[nxt]
            k %= dist[i] - dist[nxt] + 1
            k += dist[nxt]
        print(dist.index(k) + 1)
        break
    dist[nxt] = dist[i] + 1
    i = nxt

Measured memory_bytes: 32332
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

#define REPS(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	int N;
	cin >> N;
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		int num;
		cin >> num;
		while (num % 2 == 0) {
			num /= 2;
			ans++;
		}
	}
	cout << ans;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
//#pragma warning disable

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;

public class Test
{
    public static void Main()
    {
        var line1 = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        var N = line1[0];
        var M = line1[1];

        var a = new long[M];
        var b = new long[M];

        for (var i = 0; i < M; i++)
        {
            var line2 = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            a[i] = line2[0];
            b[i] = line2[1];
        }

        var count = new long[N];

        foreach (var toshi in a.Concat(b))
        {
            count[toshi - 1]++;
        }

        foreach (var c in count)
        {
            Console.WriteLine(c);
        }
    }
}

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

int main(){
  ll N,D;
  cin>>N>>D;
  ll ans=0;
  for(ll i=0;i<N;i++){
    ll X,Y;
    cin>>X>>Y;
    if(X*X+Y*Y<=D*D)ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll unsigned long long
#define maxn 500005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 1e9 + 7;
#define int long long

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int k ,n;
    cin >> k >> n;
    vector<int>v(n);
    vector<int>d(n);
    for (auto &i : v) {
        cin >> i;
    }
    f(n) {
        d.pb((v[(i + 1)% n] - v[i] + k)%k);
    }
    sort(all(d));
    cout << k - d.back() << '\n';
}


Measured memory_bytes: 7424
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] a = new int[2 * m][2];
        for(int i = 0;i < m;i++) {
            a[i][0] = sc.nextInt() - 1;
            a[2 * m - 1 - i][1] = a[i][0];
            a[i][1] = sc.nextInt() - 1;
            a[2 * m - 1 - i][0] = a[i][1];
        }

        System.out.println(dfs(n, m, a, new boolean[n], 0, 0));
    }

    private static int dfs(int n, int m, int[][] a, boolean[] footprints, int here, int count) {
        if(footprints[here]) return 0;

        footprints[here] = true;
        boolean hasConquered = true;
        for(int i = 0;i < footprints.length;i++) {
            if(!footprints[i]) {
                hasConquered = false;
                break;
            }
        }
        if(hasConquered) return 1;

        int tmpCount = count;
        for(int i = 0;i < 2 * m;i++) {
            if(a[i][0] == here && !footprints[a[i][1]]) {
                tmpCount += dfs(n, m, a, footprints, a[i][1], count);
                footprints[a[i][1]] = false;
            }
        }

        return tmpCount;
    }

}


Measured memory_bytes: 21844
while True :
    x, op, y = input().split()
    x, y = int(x), int(y)
    if op=="?" :
        break
    if op=="+" :
        print( x+y)
    elif op=="-" :
        print( x-y)
    elif op=="*" :
        print(x*y)
    elif op=="/" :
        print(x//y)
#    op(x, op, y)


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

char encrypt(char x, int a, int b){
    return (char)(((x-'a') * a + b)%26 + 'a');
}

int main(){
    int n;
    scanf("%d\n", &n);

    string str, copy;
    for(int i = 0; i < n; i++){
        getline(cin, str);
        int a, b;
        bool found = false;
        for(a = 1; !found ; a++){
            if(a % 2 == 0 || a % 13 == 0)    continue;
            for(b = 1; b <= 26; b++){
                copy = str;
                for(int k = 0; k < str.length(); k++){
                    if(str[k] != ' ')   copy[k] = encrypt(str[k], a, b);
                }
                if(copy.find("this") != -1 || copy.find("that") != -1){
                    cout << copy << endl;
                    found = true;
                    break;
                }
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3216
#include <stdio.h>
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<complex>
#include<vector>

using namespace std;

int nx[]={0,1,0,-1};
int ny[]={0,1,0,-1};
//*****************************************


int main(void){

    int a,b,c;
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);

    if((a>c && b<c) || (a<c && b>c))
    {

        cout << "Yes"<<endl;
    }
    else
    {
        cout << "No"<<endl;
    }


    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
    int n;
    int v[51];
    int c[51];
    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> v[i];
    }
    for (int i=0; i<n; i++) {
        cin >> c[i];
    }
    int s = 0;
    for (int i=0; i< n; i++) {
        int diff = v[i] - c[i];
        if (diff > 0) {
            s += diff;
        }
    }
    cout << s << endl;
    return 0;
}

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

int main() {
  int n, i;
  cin >> n;
  
  vector<long> a(n), b;
  for(i = 0; i < n; i++){
    cin >> a.at(i);
  }
  
  if(n % 2 == 1){
    for(i = n - 1; i >= 0; i -= 2){
      b.push_back(a.at(i));
    }
    for(i = 1; i <= n - 1; i += 2){
      b.push_back(a.at(i));
    }
  }
  
  else{
    for(i = n - 1; i >= 0; i -= 2){
      b.push_back(a.at(i));
    }
    for(i = 0; i <= n - 1; i += 2){
      b.push_back(a.at(i));
    }
  }
  
  for(i = 0; i < n; i++){
    cout << b.at(i) << endl;
  }
}


Measured memory_bytes: 5488
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int n,a[N],k;
int cal(int m)
{
	int s=0;
	for(int i=1;i<=n;i++)
	{
		s+=(a[i]+m-1)/m-1;
		if(s>k)
			return 0;
	}
	return 1;
}
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int l=0,r=1e9;
	while(r-l>1)
	{
		int m=l+r>>1;
		if(cal(m))
			r=m;
		else
			l=m;
	}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 4588
#include <stdio.h>

int main(void)
{
	int omori[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};
	int flag[10];
	int g;
	int i;
	int f;
	
	while (scanf("%d", &g) != EOF){
		for (i = 0; i < 10; i++){
			flag[i] = 0;
		}
		
		for (i = 9; i >= 0; i--){
			if (g >= omori[i]){
				flag[i] = 1;
				g -= omori[i];
			}
		}
		
		f = 0;
		for (i = 0; i < 10; i++){
			if (flag[i] == 1){
				if (f == 1){
					printf(" ");
				}
				printf("%d", omori[i]);
				if (f == 0){
					f = 1;
				}
			}
		}
		printf("\n");
		
	}
		return (0);
}

Measured memory_bytes: 596
m, d = map(int, input().split())

cnt = 0
if m < 4 or d < 22:
  pass
else:
  for i in range(22, d+1):
    if (i // 10) >= 2 and (i % 10) >= 2:
      if (i // 10) * (i % 10) <= m:
        cnt += 1
        
        
print(cnt)

Measured memory_bytes: 3060
#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;
 
/*******  All Required define Pre-Processors and typedef Constants *******/
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, k) for (int i = 0; i < k; i++)
#define repA(i, a, n) for (int i = a; i <= (n); ++i)
#define repD(i, a, n) for (int i = a; i >= (n); --i)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define INF 1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define LLINF 1e14
#define sz(a) int(a.size())
#define ff first
#define ss second
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vp;
typedef vector<vp> vvp;

const int N = 2 * 100 * 1000 + 5;
vvi G(N, vi(0));
int V[N];
int cnt[N];
void dfs(int u, int p){
	V[u] = 1;
	if(p != -1) cnt[u] += cnt[p];
	rep(i, sz(G[u])){
		int v = G[u][i];
		if(!V[v]) dfs(v, u);
	}
}
int main(int argc, char const *argv[])
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int n, q; cin >> n >> q;
        rep(i, n - 1){
        	int x, y; cin >> x >> y;
        	G[x].pb(y); G[y].pb(x);
        }

        rep(i, q){
        	int x, y; cin >> x >> y;
        	cnt[x] += y;
        }

        repA(i, 1, n){
        	if(!V[i]) dfs(i, -1);
        }

        repA(i, 1, n) cout << cnt[i] << ' '; cout << endl;
		return 0;    
}

Measured memory_bytes: 24320
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 998244353LL;
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
template <class T>
void chmin(T &a, T b) { a = min(a, b); }
template <class T>
void chmax(T &a, T b) { a = max(a, b); }
void debug() { cerr << "ok" << endl; }
template <class T>
void printv(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    int sum = 0;
    for (int i = 0; i < m; i++) {
        int a;
        cin >> a;
        sum += a;
    }
    if (sum > n) {
        cout << -1 << '\n';
    } else {
        cout << n - sum << '\n';
    }
}


Measured memory_bytes: 3604
n=int(input())
location=list(map(str,[input() for i in range(n)]))
fail=0
for j in range(n):
    if j==0:
        a=[0,0,0]
    else:
        a=list(map(int, location[j-1].split()))
    b=list(map(int,location[j].split()))
    x=abs(a[1]-b[1])
    y=abs(a[2]-b[2])
    t=b[0]-a[0]
    if x+y<=t:
        if (x+y)%2==t%2:
            pass
        else:
            fail+=1
    else:
        fail+=1
if fail==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 16832
object Main extends App {
  val N = scala.io.StdIn.readLine().toInt
  val workerList = scala.io.StdIn.readLine().split(' ').map(_.toInt)
  val bossesMap = workerList.groupBy(i => i)

  (1 to N).foreach(i => {
    println(
      bossesMap.get(i) match{
        case Some(w) =>  w.length
        case _ => 0
      }
    )
  })
}


Measured memory_bytes: 114116
#include <bits/stdc++.h>
using namespace std;
using LL  = long long;
using VI  = vector<LL>;
using VVI = vector<VI>;
using VB  = vector<bool>;
using VS  = vector<string>;
using PII = pair<LL, LL>;
using VP  = vector<PII>;
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first < y.first;});
#define FRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first > y.first;});
#define SSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second < y.second;});
#define SRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second > y.second;});
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define $(x) {cout << #x << " = " << (x) << endl;}

int main() {
    LL N;
    cin >> N;
    VI plus, minus;
    REP(i, N) {
        LL a;
        cin >> a;
        if (a < 0) minus.PB(a);
        else plus.PB(a);
    }
    SORT(plus);
    RSORT(minus);

    VP trace;
    LL x, y;
    LL ans;
    LL mi = 0, pi = 0;
    if (SZ(minus) == 0) {
        trace.PB(MP(plus[0], plus[1]));
        ans = plus[0] - plus[1];
        if (N > 2) {
            for (LL i = 2; i < N - 1; ++i) {
                trace.PB(MP(ans, plus[i]));
                ans -= plus[i];
            }
            trace.PB(MP(plus[N - 1], ans));
            ans = plus[N - 1] - ans;
        }
    } else if (SZ(plus) == 0) {
        trace.PB(MP(minus[0], minus[1]));
        ans = minus[0] - minus[1];
        for (LL i = 2; i < N; ++i) {
            trace.PB(MP(ans, minus[i]));
            ans -= minus[i];
        }
    } else {
        ans = minus[0];
        for (LL i = 0; i < SZ(plus) - 1; ++i) {
            trace.PB(MP(ans, plus[i]));
            ans -= plus[i];
        }
        trace.PB(MP(plus[SZ(plus) - 1], ans));
        ans = plus[SZ(plus) - 1] - ans;
        for (LL i = 1; i < SZ(minus); ++i) {
            trace.PB(MP(ans, minus[i]));
            ans -= minus[i];
        }
    }

    cout << ans << endl;
    EACH(t, trace) {
        cout << t.first << " " << t.second << endl;
    }
	
    return 0;
}


Measured memory_bytes: 5224
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define cer(x) cerr << x <<endl
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
#define pb push_back
#define MOD 1e9+7
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
template<class T>inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<class T>inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

int main()
{
	string s; cin >> s;
	string t = s;
	reverse(ALL(t));
	int ans = 0;
	rep(i, SZ(s))
	{
		if (t[i] != s[i])ans++;
	}
	ans /= 2;
	co(ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <algorithm>
#include <cstdio>

#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; i++)

using namespace std;


int main() {
  int a, b;
  ios::sync_with_stdio(false);
  while (cin >> a >> b) {
    cout << (a + b) % 24 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#ABC154-E Almost Everywhere Zero

#桁DP

"""
問題：
n以下の0以外の数字の数が丁度k個である整数の個数を求めよ。

解法：
桁DP
以下の条件があったら桁DPを疑うべし
・桁に関している
・制約が大きい
・整数nがある範囲を動くときの、〜〜〜の最大値を求めよ
・整数nがある範囲を動くときの、〜〜〜という条件を満たすものは何通りあるか←今回はコッチ

考え方：
桁DPでは上位桁から条件を絞っていって、下位桁にクエリを出すという再帰方法で解く。この時、何回もこの再帰をやっていると
下位桁が全く同じ条件になることが出現するので、それをメモ化、呼び出しして動的に解く。
そのためのdpテーブルは３次元で、各階層に対応するのは以下のようなデータ。

dp[i][j][k] = (上から)i桁まで見た,j個Kを使った,k=0:制約ありk=1:自由     の時の条件を満たす場合の個数(value)

問題により多少dpテーブルの内容や順番は異なるが、i桁目まで見た、と、自由度kについての制約は必ずテーブルの中に入る。
もうひとつ、今回で言えばjのテーブルは、kをいくつ使ったか、全桁の合計がD以下であるみたいな問題はいま合計はいくらか
みたいなデータになる。
"""

n = input() #桁DPの場合、nはstr型で取る
m = len(n)
K = int(input()) #DPテーブルのkとかぶって紛らわしいので、大文字にする

dp = [[[0]*2 for j in range(4)] for i in range(105)]
dp[0][0][0] = 1
for i in range(m): #m=桁数
    for j in range(4): #0以外の数はj回使っている
        for k in range(2): #制約,自由の2通り(制約がかかってから気にするんじゃなくて、
            #最初から全桁に制約がかかってるもんだと思って全部計算する)
            nd = int(n[i]) #その桁の数字(制約ありの時に使う)
            for d in range(10): #下位桁に対して10回(0~9まで)まわす
                ni = i+1 #下位桁に
                nj = j #0以外を使った回数はj回
                nk = k #制約か自由か
                if d != 0: nj += 1 #その桁を0だと仮定して場合、現在までの0の個数+=1
                if nj > K: continue #0の個数がKを超えていたら条件を満たさない
                if k == 0: #制約ありの場合
                    if d > nd:continue #その桁の制約を超えていたら飛ばす
                    if d < nd:nk = 1 #逆にd未満ならば、下位桁は自由になるので、k=1:自由にしてやる
                #この下位桁に対するforループを全て満たした時、dpテーブルを更新
                dp[ni][nj][nk] += dp[i][j][k]

ans = dp[m][K][0] + dp[m][K][1] #制約ありでもなしでも良いので、両方足す

print(ans)



Measured memory_bytes: 41072
#include<bits/stdc++.h>
using namespace std;
#define vrep(i,a,b) for(__typeof(b) i=a-(a>b);i!=b-(a>b);i+=1-2*(a>b))
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=n-1;i>=a;i--)
#define SZ(x) ((int)(x).size())
#define all(a) begin(a), end(a)

#define eb emplace_back
#define mt make_tuple
#define pb push_back
#define f first
#define s second

typedef  pair<int, int>   pii;
typedef   vector<int>     vi;
typedef    long long      ll;
//for debug
#define debug(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define rangei(a,L,R) {vrep(i,L,R) cout << a[i] <<' '; cout<<endl;}
#define range(a) rangei(a,0,a.size())
#define rangei_2d(a,L,R){vrep(j,L,R) cout<<a[i][j]<<' '; cout<<endl;}
#define range_2d(a) { rep(i,0,SZ(a)){rangei_2d(a,0,SZ(a[0]));} }

const int mod=1e9+7;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int r,c;
	cin>>r>>c;

	char x;
	vector<vi> in(r,vi(c,1));
	for(int i=0;i<r;i++)
		for(int j=0;j<c;j++){
			cin>>x;
			if(x=='#')in[i][j]=0;
		}

	vector<vi> v(2,vi(c+1,0));
	v[1][1]=1;
	rep(i,1,r+1){
		// memset(&v[i&1],0,sizeof(v[0])*SZ(v));
		if(i!=1)fill(v[i&1].begin(),v[i&1].end(),0);
		rep(j,1,c+1){
			if(in[i-1][j-1])
				v[i&1][j]+= (v[(i-1)&1][j] + v[i&1][j-1])%mod;
		}
	}
	cout<<v[r&1][c]<<endl;

	return 0;
}

Measured memory_bytes: 7580
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(1,n):
    if a[i-1]>a[i]:
#        print("i=",i)
        ans+=a[i-1]-a[i]
        a[i]+=a[i-1]-a[i]
print(ans)


Measured memory_bytes: 32360
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

int main(){
	int N,K; cin >> N >> K;
	vector<int> a(N);
	cinf(N,a);
	int m=-1;
	for(int i=0;i<N;i++){
		if(a[i]==1){
			m=i+1;
			break;
		}
	}
	int left=m-1;
	int right=N-m;
	int cnt=0;
    if((N-1)%(K-1)==0){
     cout << (N-1)/(K-1) << endl;
     return 0;
   }
     else{
     cout << (N-1)/(K-1)+1<< endl;
     return 0;
   }
}

Measured memory_bytes: 640
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
using namespace std;

int main(){
    int x[5],dx[5],k;
    bool b=true;
    for(int i=0;i<5;++i)cin>>x[i];
    cin>>k;
   if(x[4]-x[0]<=k)cout<<"Yay!"<<endl;
   else cout<<":("<<endl;
   return 0;
}

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

int main(void){
    int n = 0, m = 0, x = 0;
    int a[101]; 
    int ans = 0;
    int cost = 0;

    scanf("%d%d%d", &n, &m, &x);

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

    for(int i = 1; i <= m; i++){
        int tmp = 0;
        scanf("%d", &tmp);
        a[tmp] = 1;
    }

    // 0 をゴールとする時
    for(int i = x - 1; i > 0; i--){
        cost += a[i];
    }
    ans = cost;
    cost = 0;

    // N をゴールとする時
    for(int i = x + 1; i < n; i++){
        cost += a[i];
    }
    if(ans > cost){
        ans = cost;
    }

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

    return 0;

} 


Measured memory_bytes: 256
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <map>
#include <stdio.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = (a); i < (int)(b); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll mod = 998244353;
pint dx[4] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1}};

vector<ll> A;
ll L;

ll dpl[2 * 100005][2], dpr[2 * 100005][2], sum[2*100005];

int main() {
	cin >> L;
	A.resize(L);

	
	rep(i, L) {
		cin >> A[i];
		if (i == 0) {
			sum[i] = A[i];
		}
		else
			sum[i] = sum[i - 1] + A[i];

	}

	if (A[0] != 0) {
		dpl[0][0] = A[0] % 2;
		dpl[0][1] = 1 - A[0] % 2;
	}
	else {
		dpl[0][0] = 0;
		dpl[0][1] = 1;
	}

	

	for (int i = 1; i < L; i++) {

		if (A[i] != 0 || A[L-i] != 0) {
			dpl[i][0] = dpl[i - 1][0] + A[i] % 2;
			dpl[i][1] = min(dpl[i - 1][0] + (1 - A[i] % 2), dpl[i - 1][1] + (1 - A[i] % 2));
			dpr[L - i - 1][0] = dpr[L - i][0] + (A[L - i] % 2);
			dpr[L - i - 1][1] = min(dpr[L - i][0] + (1 - A[L-i] % 2), dpr[L - i][1] + (1 - A[L-i] % 2));
		}
		if(A[i] == 0) {
			dpl[i][0] = min(sum[i], 2 + dpl[i - 1][0]);
			dpl[i][1] = min(1 + dpl[i - 1][0], 1 + dpl[i - 1][1]);
		}

		if (A[L - i] == 0) {
			dpr[L - i - 1][0] = min(sum[L - 1] - sum[L - i - 1], 2 + dpr[L - i][0]);
			dpr[L - i - 1][1] = min(1 + dpr[L - i][0], dpr[L - i][1] + 1);

		}

	}

	ll ans = inf;

	rep(i, L) {
		ans = min(ans, min(dpl[i][0] + dpr[i][0], dpl[i][0] + dpr[i][1]));
		ans = min(ans, dpr[i][0] + dpl[i][1]);
	}

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

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  ll n;
  cin >> n;
  ll a[n];
  REP(i, n) cin >> a[i];

  SORT(a, n);

  cout << a[n - 1] - a[0] << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class F
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		map = new int[n + 1].Select(_ => new List<int>()).ToArray();
		foreach (var r in new int[n - 1].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()))
		{
			map[r[0]].Add(r[1]);
			map[r[1]].Add(r[0]);
		}

		tour = new int[n + 1].Select(_ => new List<int>()).ToArray();
		Dfs(1, 0);

		MInt bSum = 0, m2 = 2, all = m2.Pow(n - 1);
		foreach (var l in tour.Skip(1))
		{
			if (l.Count < 2)
				bSum += all - 1;
			else
				foreach (var c in Subtrees(l, n - 1))
					bSum += m2.Pow(c) - 1;
		}
		Console.WriteLine(((n - (n + bSum) / all) / 2).V);
	}

	static List<int>[] map;
	static List<int>[] tour;
	static int c;
	static void Dfs(int p, int p0)
	{
		foreach (var x in map[p])
		{
			if (x == p0) continue;
			tour[x].Add(++c);
			Dfs(x, p);
			tour[p].Add(++c);
		}
	}

	static IEnumerable<int> Subtrees(List<int> l, int m)
	{
		for (int i = 0; i < l.Count; i++)
			yield return ((l[(i + 1) % l.Count] - l[i]) / 2 + m) % m;
	}
}

struct MInt
{
	const int M = 1000000007;
	public long V;
	public MInt(long v) { V = (v %= M) < 0 ? v + M : v; }

	public static implicit operator MInt(long v) => new MInt(v);
	public static MInt operator +(MInt x) => x;
	public static MInt operator -(MInt x) => -x.V;
	public static MInt operator +(MInt x, MInt y) => x.V + y.V;
	public static MInt operator -(MInt x, MInt y) => x.V - y.V;
	public static MInt operator *(MInt x, MInt y) => x.V * y.V;
	public static MInt operator /(MInt x, MInt y) => x * y.Inv();

	public MInt Pow(int i) => MPow(V, i);
	public MInt Inv() => MPow(V, M - 2);

	static long MPow(long b, int i)
	{
		for (var r = 1L; ; b = b * b % M)
		{
			if (i % 2 > 0) r = r * b % M;
			if ((i /= 2) < 1) return r;
		}
	}
}


Measured memory_bytes: 75036
/*Author: Gautam*/
 
 
#include<bits/stdc++.h>
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
#define MOD 1000000007
#define ull unsigned long long int
#define newline cout<<endl
 
 
/* TYPE DEFINITIONS */
typedef     long long int        ll;
typedef     vector<ll>     vi;
typedef     pair<int,int>   pi;
 
 
 
/* MATH */
bool isPrime(ull n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ull i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
 
ll pow(ll a,ll b)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)res=(res*a);
        a=(a*a);
        b>>=1;
    }
    return res;
}

  
//
/* MACROS */
 
#define  all(A)         (A).begin() , (A).end()
#define  arrall(A,n)    (A),((A)+(n))
#define  rall(A)        (A).rbegin() , (A).rend()
#define  sz(A)          (int)(A).size()
#define  pb             push_back
#define  ppb            pop_back
#define  mp             make_pair
#define  ln(X)          (int)(X).length()
#define  square(X)      ((X)*(X))
#define  cube(X)        ((X)*(X)*(X))
#define  forn(i, n)  for (int i = 0; i < int(n); i++)
#define  forr(i, n)  for (int i = int(n - 1); i >= 0; i--)
#define  fora(i, a, b)  for (int i = int(a); i <= int(b); i++)
#define  forb(i, a, b)  for (int i = int(a); i >= int(b); i--)
#define  fore(it, a)    for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++) 
void solve()
{
    ll n;
    cin>>n;
    ll ans=1e13;
    for (int i=1; i<=sqrt(n); i++) 
    { 
        if (n%i == 0) 
        { 
            if (n/i == i) 
                ans=min(ans,(abs(i-1)+abs(n/i-1)));
            else 
            {
                //printf("%d %d ", i, n/i); 
                ans=min(ans,(abs(i-1)+abs(n/i-1)));
                ll a=n/i;
                ans=min(ans,(abs(a-1)+abs(n/a-1)));
            }
        } 
    }
    cout<<ans<<endl;
}  
int main()
{
 
    FastIO;
    ll t=1;
   // cin>>t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
int main(){
  int n,a,b;
  cin >> n >> a >> b;
  long long ans=1,x=1;
  long long c= n/20;
  int d=n%20;
  for(int i=0;i<c;i++){
    ans = (ans*1048576)%1000000007;
  }
  for(int i=0;i<d;i++)x*=2;
  ans = (ans*x)%1000000007;
  long long f=1,l=1;
  for(int i=0;i<a;i++){
    f*=(n-i);
    f%=1000000007;
    f*=modinv(i+1,1000000007);
    f%=1000000007;
  }
  for(int i=0;i<b;i++){
    l*=(n-i);
    l%=1000000007;
    l*=modinv(i+1,1000000007);
    l%=1000000007;
  }
  if(ans-f<0)ans+=1000000007;
  ans=(ans-f)%1000000007;
  if(ans-l<0)ans+=1000000007;
  ans=(ans-l)%1000000007;
  cout << ans-1 << endl;
}

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

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

const int N = 105;
const int K = 1e5 + 5;

int a[N];
bool dp[K];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
	int n, k;
	cin >> n >> k;
	for (int i=1; i<=n; i++) cin >> a[i];
	dp[0] = 0;
	for (int i=1; i<=k; i++) {
		dp[i] = 0;
		for (int j=1; j<=n; j++) {
			if (i - a[j] >= 0 && !dp[i - a[j]]) {
				dp[i] = 1;
				break;
			}
		}
	}
	if (dp[k]) cout << "First\n";
	else cout << "Second\n";
    return 0;
}


Measured memory_bytes: 384
#define _USE_MATH_DEFINES

#include <iostream>	//cin, cout
#include <vector>	//vector
#include <algorithm> //sort,min,max,count
#include <string>	//string,getline
#include <ios>		//fixed
#include <iomanip>	//setprecision
#include <utility> //swap
#include <cstdlib>	//abs(int)
#include <cmath>	//sqrt
#include <sstream>	//stringstream,getline
#include <cmath>	//ceil,M_PI
#include <numeric>	//gcd
#include <deque>	//deque

using namespace std;

int main() {

	int N;
	cin >> N;

	cout << N * N * N << endl;

	return 0;

}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
const int Nmax=200010;
 
int main() {
	ll N,price=0;
	int A[Nmax];;
	cin >> N;
	A[0]=0;
	A[N+1]=0;
	for(int i=1;i <= N;i++){
		cin >> A[i];
		price += abs(A[i-1]-A[i]);
	}
	price += abs(A[N]-0);
	for(int i=1;i <= N;i++){
		//A[i]を抜く！
		if((A[i]<A[i+1] && A[i-1] < A[i])||(A[i]>A[i+1] && A[i-1]>A[i])) cout << price << endl;
		else cout << price - abs(A[i-1]-A[i]) - abs(A[i]-A[i+1]) + abs(A[i-1]-A[i+1]) << endl;
	}
	return 0;
}

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

def count_attack(hp):
    count = 0        
    if hp == 2 or hp == 3:
        return 3
    else:
        # calculate new hp
        count += 1
        hp_child = hp //2
        count += 2 * count_attack(hp_child)
        return count

if n == 1:
    print(1)
else:
    print(count_attack(n))

Measured memory_bytes: 2940
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;
int a[200005];
int n,eve=0;
bool zero=false;
ll min(ll a,ll b)
{
    if(a>b)return b;
    else return a;
}
int main()
{
    ll ans=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]==0)zero=true;
        if(a[i]<0)eve++;
        ans+=abs(a[i]);
    }
    if(zero==true||eve%2==0){
         cout<<ans<<endl;
    }else{
        ll minm=10000000000;
        for(int i=0;i<n;i++)
        {
            minm=min(abs(a[i]),minm);
        }
        cout<<ans-2*minm<<endl;
    }
    
}

Measured memory_bytes: 640