akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N; cin>>N;
    ll sum=0,ans=INF;
    vector<ll> A(N);
    rep(i,N){
        cin>>A[i];
        sum+=A[i];
    }
    ll tmp=0;
    rep1(i,N-1){
        tmp+=A[i-1];
        chmin(ans,abs(sum-tmp*2));
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4836
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<algorithm>
#define int long long
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define REP(u) for(int i=hd[u],v;v=e[i].v,i;i=e[i].n)
#define REQ(u) for(int i=Hd[u],v;v=E[i].v,i;i=E[i].n)
using namespace std;
const int N=400400,M=N<<1,P=1e9+7;
struct edge{int n,v;}e[M],E[M];
int n,m,u,v,fl,Fl,T,ans;
int hd[N],in[N],vi[N],a[N],b[N],f[N],fa[N],du[N],sz[N],Hd[N];
int iv[N],fc[N],vf[N];
vector<int>ve;
queue<int>q;
void add(int u,int v){e[++fl]=(edge){hd[u],v};hd[u]=fl;du[v]++;}
void Add(int u,int v){E[++Fl]=(edge){Hd[u],v};Hd[u]=Fl;}
void dfs0(int u){
	ve.push_back(u);
	REP(u)if(in[v] && v!=fa[u]) fa[v]=u,dfs0(v);
}
void dfs1(int u){
	vi[u]=1;a[++T]=u;ve.push_back(u);
	REP(u) if(!vi[v]) dfs1(v);else if(in[v]) dfs0(v);
}
void dfs2(int u,int ff){
	REP(u)if(in[v] && v!=fa[u]){
		dfs2(v,u);
		if(ff>v) Add(u,v),b[v]=1;
	}
}
int dfs3(int u){
	int ret=1;sz[u]=f[u]=1;
	REQ(u) dfs3(v),f[u]=1ll*f[v]*f[u]%P,sz[u]+=sz[v];
	f[u]=1ll*f[u]*iv[sz[u]]%P;
}
int sol(){
	int ret=1;
	for(int u:ve) Hd[u]=b[u]=0;Fl=0;
	FOR(j,1,T)if(a[j-1]>a[j+1]) Add(a[j],a[j+1]),b[a[j+1]]=1;
	//for(int u:ve){cout<<u<<':';REQ(u) cout<<v<<' ';cout<<'\n';}
	FOR(j,1,T) dfs2(a[j],a[j-1]);
	for(int u:ve)if(!b[u]) dfs3(u),ret=1ll*ret*f[u]%P;
	return ret;
}
int work(int u){
	int ret=0;
	T=0;ve.clear();dfs1(u);
	//FOR(i,1,T) cout<<a[i]<<' ';cout<<'\n';
	a[0]=a[T];a[T+1]=a[1];
	(ret+=sol())%=P;
	reverse(a,a+T+2);
	(ret+=sol())%=P;
	return ret;
}
signed main(){
	//freopen("robot.in","r",stdin);
	//freopen("robot.out","w",stdout);
	scanf("%d",&n);m=2*n;
	iv[1]=fc[0]=vf[0]=1;
	FOR(i,2,m) iv[i]=1ll*(P-P/i)*iv[P%i]%P;
	FOR(i,1,m) fc[i]=1ll*fc[i-1]*i%P,vf[i]=1ll*vf[i-1]*iv[i]%P;
	FOR(i,1,m) scanf("%d%d",&u,&v),add(u,v+n),add(v+n,u);
	FOR(i,1,m) if(!du[i]) return puts("0"),0;
	FOR(i,1,m) if(du[i]==1) vi[i]=in[i]=1,q.push(i);
	while(q.size()){
		u=q.front();q.pop();
		REP(u)if(!vi[v] && (--du[v])==1) vi[v]=in[v]=1,q.push(v); 
	}
	ans=1;
	FOR(i,1,m)if(!vi[i]) ans=1ll*ans*work(i)%P;
	printf("%lld\n",1ll*fc[m]*ans%P);
}/*
4
1 1
1 2
2 1
2 2
3 3
3 4
4 3
4 4
*/

Measured memory_bytes: 55156
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String[] tokens = in.nextLine().split(" ");
		int N = Integer.parseInt(tokens[0]);
		int M = Integer.parseInt(tokens[1]);
		int X = Integer.parseInt(tokens[2]);
		int Y = Integer.parseInt(tokens[3]);
		List<Integer> x = new ArrayList<>(N);
		tokens = in.nextLine().split(" ");
		for (int i = 0; i < N; ++i) {
			x.add(Integer.parseInt(tokens[i]));
		}
		List<Integer> y = new ArrayList<>(M);
		tokens = in.nextLine().split(" ");
		for (int i = 0; i < M; ++i) {
			y.add(Integer.parseInt(tokens[i]));
		}

		Collections.sort(x);
		Collections.sort(y);
		int xMax = Math.max(x.get(x.size() - 1), X);
		int yMin = Math.min(y.get(0), Y);
		if (yMin - xMax >= 1) {
			System.out.println("No War");
		} else {
			System.out.println("War");
		}
		in.close();
	}
}

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

using namespace std;


int main(){
    
    int N;
    cin >> N;
    string s[N];
    for (int i = 0; i < N; i++) {
        
        string sss[10];
        string ss;
        cin >> ss;
        
        for (int i = 0; i < 10; i++) {
            sss[i] = ss[i];
        }
        
        sort(sss, sss+10);
        
        ss = sss[0];
        for (int i = 1; i < 10; i++) {
            ss += sss[i];
        }
        s[i] = ss;
        
    }
    
    
    sort(s, s+N);
    
    
    long int ans = 0;
    string bigin;
    long int bii;
    int k = 0;
    
    while (k < N-1) {
        bigin = s[k];
        bii = 1;
        k += 1;
        while (bigin == s[k]) {
            bii += 1;
            k += 1;
            if (k == N) {
                break;
            }
        }
        if (bii > 1) {
            ans += bii*(bii-1)/2;
        }
        
        
        
    }
    
    cout << ans << endl;
    
    
    
}



Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
int n,s,r,ans;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>s>>r;
        ans+=r-s+1;
    }
    cout<<ans;

	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); }
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second
#define all(c) c.begin(),c.end()

const int N = 3005;
string s, t;
int dp[N][N];

int solve(int i, int j) {
  if (i == s.size() || j == t.size()) return 0;
  if (dp[i][j] == -1) {
    dp[i][j] = max(solve(i+1, j), solve(i, j+1));
    if (s[i] == t[j]) {
      dp[i][j] = max(dp[i][j], solve(i+1, j+1)+1);
    }
  }
  return dp[i][j];
}

string recov() {
  int i = 0, j = 0;
  string ans;
  while(i < s.size() && j < t.size()) {
    if (s[i] == t[j]) {
      ans += s[i];
      i++, j++;
    } else {
      if (solve(i+1, j) > solve(i, j+1)) {
        i++;
      } else {
        j++;
      }
    }
  }
  return ans;
}

int main() { // Emily <3
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  cin >> s >> t;
  memset(dp, -1, sizeof dp);
  cerr << solve(0, 0) << nl;
  cout << recov() << nl;

  return 0;
}



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

char c[21][21];
int w, h;
int sy, sx;
int dy[4] = {1, -1, 0, 0};
int dx[4] = {0, 0, 1, -1};
bool f[21][21];
int ans = 0;

bool contain(int y, int x){
    return (0 <= y && y < h && 0 <= x && x < w);
}

void dfs(int y, int x){
    f[y][x] = true;
    ans++;
    for(int i = 0; i < 4; i++){
        int ny = y + dy[i];
        int nx = x + dx[i];
        if(contain(ny, nx) == true && f[ny][nx] == false && c[ny][nx] != '#'){
            dfs(ny, nx);
        }
    }
    return;
}

int main(){
    while(cin >> w >> h, w, h){
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                cin >> c[i][j];
                if(c[i][j] == '@'){
                    sy = i;
                    sx = j;
                }
                f[i][j] = false;
            }
        }
        ans = 0;
        dfs(sy, sx);
        cout << ans << endl;
    }
}

Measured memory_bytes: 3044
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n;cin >> n;
    vl a(n);rep(i,n)cin >> a[i];
    if(n%2==0){
        vvl dp(n,vl(2,-INF));
        dp[0][0]=a[0];dp[1][1]=a[1];
        rep(i,n-2){
            if(i!=n-3)chmax(dp[i+3][1],dp[i][0]+a[i+3]);
            chmax(dp[i+2][1],dp[i][1]+a[i+2]);
            chmax(dp[i+2][0],dp[i][0]+a[i+2]);
        }
        cout << max(dp[n-1][1],dp[n-2][0]);
    }
    else{
        vvl dp(n,vl(3,-INF));
        dp[0][0]=a[0];dp[1][1]=a[1];dp[2][2]=a[2];
        rep(i,n-2){
            if(i<n-4)chmax(dp[i+4][2],dp[i][0]+a[i+4]);
            if(i!=n-3)chmax(dp[i+3][2],dp[i][1]+a[i+3]);
            if(i!=n-3)chmax(dp[i+3][1],dp[i][0]+a[i+3]);
            chmax(dp[i+2][2],dp[i][2]+a[i+2]);
            chmax(dp[i+2][1],dp[i][1]+a[i+2]);
            chmax(dp[i+2][0],dp[i][0]+a[i+2]);
        }
        cout << max(max(dp[n-1][2],dp[n-2][1]),dp[n-3][0]) <<endl;
    }
}   

Measured memory_bytes: 15676
#include <iostream>

using namespace std;

int main()
{
    int h,n;
    cin>>h>>n;
    int a[n];
    int c=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        c+=a[i];
    }
    if(c>=h)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


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

const ll INF=1e18;
ll dp[105][100010];

int main(){
    int n,x;
    cin>>n>>x;
    vector<int>w(n),v(n);
    rep(i,n)cin>>w[i]>>v[i];
    rep(i,105)rep(j,100010)dp[i][j]=INF;
    rep(i,105)dp[i][0]=0;
    rep(i,n){
        for(int j=0; j<=100010; ++j){
            if(j-v[i]>=0){
                dp[i+1][j]=min(dp[i][j],dp[i][j-v[i]]+w[i]);
            }
            else{
                dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
            }
        }
    }
    int ans=0;
    rep(i,100010){
        if(dp[n][i]<=x)ans=i;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 85688
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
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++)

using LL = long long;
using PII = pair<int, int>;
using VI = vector<int>;

int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }

int main() {
	int a = 0, b, n;
	cin >> n;
	REP(i, n) { cin >> b; a = gcd(a, b); }
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 256
import sys, fractions

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))

lcm = 1
for a in A:
    lcm = (lcm * a) // fractions.gcd(lcm, a)

lcm -= 1
res = 0
for a in A:
    res += lcm % a

print(res)


Measured memory_bytes: 5344
a, b, m = map(int, input().split())
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))
ans = min(aaa) + min(bbb)
for _ in range(m):
    x, y, c = map(int, input().split())
    x -= 1
    y -= 1
    tmp = aaa[x] + bbb[y] - c
    ans = min(ans, tmp)
print(ans)


Measured memory_bytes: 18736
N,M,K = list(map(int,input().split()))


if M>1:
    mod = 998244353
    comb = [1]
    c = 1
    for i in range(N-1):
        c *= N-1-i
        c *= pow(i+1,mod-2,mod)
        c %= mod
        comb.append(c)
    #print(comb)
    M1 = [1]
    m = 1
    for i in range(N):
        m*=M-1
        m%=mod
        M1.append(m)
    #print(M1)
    ans = 0
    #print((M1[N]*M)%mod)
    for i in range(K+1):
        ans += M1[N-1-i]*comb[i]
        ans %= mod
    ans *= M
    ans %= mod
    print(ans)
else:
    if N==K+1:
        print(1)
    else:
        print(0)

Measured memory_bytes: 100752
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    map<string, int> m;
    int n;
    cin >> n;
    rep(i, n) {
        string enter;
        cin >> enter;
        m[enter]++;
    }
    cout << "AC x " << m["AC"] << endl;
    cout << "WA x " << m["WA"] << endl;
    cout << "TLE x " << m["TLE"] << endl;
    cout << "RE x " << m["RE"] << endl;
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int dp[100001],k;
int ans(int a[],int n)
{if(n==0) return dp[0];
 if(n==1) return dp[1];
 if(dp[n]!=-1) return dp[n];
 int min=INT_MAX;
 for(int i=n;i>n-k&&i>0;i--)
 {   int temp=ans(a,i-1)+abs(a[n]-a[i-1]);
     if(temp<min) min=temp;
 }
 dp[n]=min;
 return dp[n];
}
int main()
{   
    int n;
    cin>>n>>k;
    int a[n];
    int i;
    for(i=0;i<n;i++) cin>>a[i];
    memset(dp,-1, sizeof(dp));
    dp[0]=0;dp[1]=abs(a[1]-a[0]);
    cout<<ans(a,n-1)<<endl;
    return 0;
} 


Measured memory_bytes: 8832
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;

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

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

	vector<pair<int, int>> r(n);
	vector<pair<int, int>> b(n);

	for(int i = 0; i < n; i++){
		int a, b;
		cin >> a >> b;
		r[i].first = a;
		r[i].second = b;
	}

	for(int i = 0; i < n; i++){
		int c, d;
		cin >> c >> d;
		b[i].first = c;
		b[i].second = d;
	}

	sort(r.begin(), r.end(), greaterSecond);
	sort(b.begin(), b.end());

	int bestX, bestY;

	int ans = 0;
	vector<int> usedIndexR;
	vector<int> usedIndexB;
	for(int i = 0; i < b.size(); i++){
		for(int j = 0; j < r.size(); j++){
			
			int ok = true;
			for(int x = 0; x < usedIndexB.size(); x++){
				for(int y = 0; y < usedIndexR.size(); y++){
					if(i == usedIndexB[x] || j == usedIndexR[y]){
						ok = false;
						break;
					}
				}
				if(!ok)break;
			}

			if(!ok)continue;

			if(b[i].first > r[j].first && b[i].second > r[j].second){
				ans++;
				usedIndexB.push_back(i);
				usedIndexR.push_back(j);
				break;
			}
		}
	}

	cout << ans << endl;


}


Measured memory_bytes: 256
#ifdef __GNUC__ 
#include <bits/stdc++.h>
//#pragma GCC optimize ("O3") 
//#pragma GCC target ("avx")

#endif
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/dynamic_bitset.hpp>
using namespace std;


int main() {
	int h, w;
	string s;
	cin >> h >> w;
	vector< boost::dynamic_bitset<> > buf[2];
	buf[0].resize(h); buf[1].resize(h);
	for (auto &v : buf) {
		for (auto & v2 : v) {
			v2.resize(w);
		}
	}
	int line= 0, n = 0;
	int col = 0;
	for (int i = 0; i < h; ++i) {
		cin >> s;
      	n=0;
		for (auto c : s) {
			if (c == '#') {
				buf[0][line].set(n);
			}
			++n;
		}
		++line;
	}
	n = 0;
	//int lastresult = w * h;
	int bufindex = 0;

	while (1) {
		int count = 0;
		for (const auto & v : buf[bufindex]) { count += 1 * v.all(); }
		if (count == h)break;
		for (int l = 0; l < h; ++l) {
          	//cout << l << " ";
			buf[bufindex ^ 1][l] = buf[bufindex][l];
			if (l != 0)buf[bufindex ^ 1][l] |= buf[bufindex][l-1];
			if (l != h-1)buf[bufindex ^ 1][l] |= buf[bufindex][l+1];
			buf[bufindex ^ 1][l] |= (buf[bufindex ][l]<<1)| (buf[bufindex ][l] >> 1);
		}
		bufindex ^= 1;
		++n;
	}
	cout << n << endl;
}


Measured memory_bytes: 640
str = gets.chomp
gets.to_i.times do
  line = gets.chomp.split
  cm = line[0]
  s = line[1].to_i
  e = line[2].to_i
  if cm == "print"
    puts str[s..e]
  elsif cm == "reverse"
    if s == 0
      str = str[s..e].reverse + str[(e+1)..-1]
    else
      str = str[0..(s-1)] + str[s..e].reverse + str[(e+1)..-1]
    end
  else
    p = line[3]
    str[s..e] = p
  end
end



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

int main(){
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    
    if ((x >= r) && (x <= W - r) && (y >= r) && (y <= H - r)){
        cout << "Yes" << endl;
    }
    
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3108
#include "bits/stdc++.h"
typedef long long ll;
using namespace std;

int main() {
    int n, a, b;
    cin >> n;
    if (n == 1) {
        cout << "Hello World";
    } else {
        cin >> a >> b;
        cout << a + b;
    }
    return 0;
}


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

using namespace std;

int main(void){
	int N;
	cin>>N;
	int a[N+1],i;
	for(i = 1; i < N+1; i++){
		cin>>a[i];
	}
	int ans = 0;
	int j = 1;
	for(i = 1; i < N+1;i++){
		if(a[i] == j){
			j++;
		}
		else{
			a[i] = -1;
			ans++;
		}
	}
	j = 1;
	for(i = 1; i < N+1; i++){
		if(a[i] != -1 && a[i] != j){
			cout<<"-1"<<endl;
			return 0;
		}
		else if(a[i] == j){
			j++;
		}
	}
	if(j == 1){
		cout<<"-1"<<endl;
		return 0;
	}
	cout<<ans<<endl;
	return 0;
}




Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int main()
{

    int n;
    cin >> n;
    VI v(n);
    VI num(1010101, 0);
    VI divnum(1010101, 0);
    rep(i, n)
    {
        cin >> v[i];
        num[v[i]]++;
        if (num[v[i]] == 1)
        {
            int j = 1;
            while (j * v[i] < 1010101)
            {
                divnum[j * v[i]]++;
                j++;
            }
        }
    }
    int ans = n;
    rep(i, n)
    {
        if (num[v[i]] != 1)
        {
            ans--;
        }
        else if (divnum[v[i]] != 1)
        {
            ans--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11968
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) begin(v), end(v)
#define allg(v) begin(v), end(v), greater<int>()



int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  string s;
  cin >> s;
  int n = s.size();
  
  bool ans = true;
  
  rep(i, 0, (n-1)/4) {
    if(s.at(i) != s.at((n-1)/2 -i-1)) {
      ans = false;
      break;
    }
  }
  
  rep(i, 0, n/2) {
    if(s.at(i) != s.at(n -i-1)) {
      ans = false;
      break;
    }
  }
  
  rep(i, (n+3)/2, (n-(n+3)/2 )/2) {
    if(s.at(i) != s.at((n+3)/2 -i -1)) {
      ans = false;
      break;
    }
  }
  
  cout << (ans ?"Yes" :"No") << "\n";

}


Measured memory_bytes: 256
n = $<.gets.to_i
r = n.times.map {$<.gets.to_i}

min_r = r.first
max = -Float::INFINITY
(n - 1).times do |i|
  a = r[i + 1]
  dif = a - min_r
  max = dif if dif > max
  min_r = a if a < min_r
end
puts max


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

int main() {

	int i = 0;

	int w, h;

	int nums[2][3000];

	while (true) {
		cin >> h >> w;

		if (w == 0 && h == 0) break;

		nums[0][i] = h;
		nums[1][i] = w;

		i++;
	}

	for (int j = 0; j < i; j++) {
		for (int y = 0; y < nums[0][j]; y++) {
			for (int x = 0; x < nums[1][j]; x++) {
				if (y == 0 || y == nums[0][j] - 1)
					cout << "#";
				else if (x == 0 || x == nums[1][j] - 1)
					cout << "#";
				else
					cout << ".";
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    int c;
    if(b <= 9) c = a * 10 + b;
    else if(b <= 99) c = a * 100 + b;
    else c = a * 1000 + b;
    bool ok = false;
    for(int i = 0; i <= 1000; i++) {
        if(i * i == c) ok = true;
    }
    if(ok) Yes(); else No();
}

Measured memory_bytes: 3592
qqq,qqq2 = list(map(int,input().split()))

x = input()
y = input()

if len(x) < len(y):
	x, y = y, x

lx = len(x)
ly = len(y)
lxy = lx * ly
r = lx % ly
while r != 0:
	lx = ly
	ly = r
	r = lx % ly

lcm = int(lxy / ly)
ret = lcm

lx = len(x)
ly = len(y)
stepX = int(lcm / lx)
stepY = int(lcm / ly)

dic = {}
i = 0
for s in x:
	dic[i] = s
	i = i + stepX

i = 0
for s in y:
	if i in dic:
		if dic[i] != s:
			ret = -1
			break
	i = i + stepY

print(ret)

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

int main() {
	int n;
	cin >> n;

	int* ip;
	ip = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> ip[i];
	}

	int min = ip[0];
	int result = 1;
	for (int i = 1; i < n; i++) {
		if (ip[i] < min) {
			result++;
			min = ip[i];
		}
		if (min == 1) {
			break;
		}
	}

	cout << result << "\n";

	return 0;
}

Measured memory_bytes: 1024
using System;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(' ');
        bool isSame = true;
        for(var i = 0; i < 2; i++)
        {
            isSame = input[i].Substring(input[i].Length - 1, 1) == input[i + 1].Substring(0, 1) ? true : false;
            if (!isSame) break;
        }
        var result = isSame ? "YES" : "NO";
        Console.WriteLine(result);
    }
}

Measured memory_bytes: 11092
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
const int N=55;
int T,n,du[N],foo,bar,fa1[N],fa2[N],mrk[N],vis[N],ans;
vector<int>E1[N],E2[N],G[N];
queue<int>Q;
void dfs2(int u,int f){
	fa2[u]=f;
	for(int v:E2[u])
		if(v!=f)
			dfs2(v,u);
}
void dfs1(int u,int f){
	fa1[u]=f;mrk[u]=mrk[f]&(fa1[u]==fa2[u]);
	for(int v:E1[u])
		if(v!=f&&(u!=foo||v!=bar)&&(v!=foo||u!=bar))
			dfs1(v,u);
}
int calc(int rt){
	dfs2(rt,0);mrk[0]=1;dfs1(rt,0);
	for(int i=1;i<=n;++i)G[i].clear(),vis[i]=0;
	int res=0,tmp=0;
	for(int i=1;i<=n;++i)
		if(!mrk[i]){
			++res;
			if(!mrk[fa1[i]])
				G[i].push_back(fa1[i]),++vis[fa1[i]];
			if(!mrk[fa2[i]])
				G[fa2[i]].push_back(i),++vis[i];
		}
	while(!Q.empty())Q.pop();
	for(int i=1;i<=n;++i)
		if(!mrk[i]&&!vis[i])
			Q.push(i);
	while(!Q.empty()){
		int u=Q.front();Q.pop();
		++tmp;
		for(int v:G[u])
			if(!--vis[v])
				Q.push(v);
	}
	return tmp==res?res:1<<30;
}
int main(){
	scanf("%d",&T);while(T--){
		scanf("%d",&n);
		for(int i=1;i<=n;++i)E1[i].clear(),E2[i].clear(),du[i]=0;
		for(int i=1,x,y;i<n;++i){
			scanf("%d%d",&x,&y);
			E1[x].push_back(y);
			E1[y].push_back(x);
			++du[x];++du[y];
		}
		for(int i=1,x,y;i<n;++i){
			scanf("%d%d",&x,&y);
			E2[x].push_back(y);
			E2[y].push_back(x);
		}
		foo=bar=0;ans=calc(1);
		for(int i=1;i<=n;++i)
			if(du[i]==1){
				int j=E1[i][0];
				foo=i;bar=j;
				for(int k=1;k<=n;++k)
					if(k!=i&&k!=j){
						E1[i].push_back(k);
						E1[k].push_back(i);
						ans=min(ans,calc(i)+1);
						E1[i].pop_back();
						E1[k].pop_back();
					}
			}
		printf("%d\n",ans==1<<30?-1:ans);
	}
	return 0;
}


Measured memory_bytes: 384
// inputに入力データ全体が入る
function Main(input) {
  // 改行コード削除
  input = input.replace(/\r?\n/g, '');
  
  var num = input.split(' ');

  // console.log(num);

  // 降順ソート
  num.sort(function (a, b) {
    return b - a;
  })

  console.log('%d', parseInt(num[0]) * 10 + parseInt(num[1]) + parseInt(num[2]));

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 7372
nums = list(map(int, input().split()))
num5 = 0
num7 = 0
for i in nums:
  if i == 5:
    num5 += 1
  elif i == 7:
    num7 += 1
  else:
    print("NO")
    
if num5 == 2 and num7 == 1:
  print("YES")
else:
  print("NO")

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

#define pii  pair<int, int>
#define vi vector<int >
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (x).size()
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal

#define ll long long
#define ld long double

const ld EPS = 10e-9;
const int INF = 1e9 + 5;
const long long INFLL = (ll)INF * (ll)INF;
const ll MOD = 1e9 + 7;
const ld PI = 3.14159265358979323846;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "[";
    for (int i = 0; i < (int)v.size(); ++i) {
        os << v[i];
        if (i != (int)v.size() - 1)
            os << ", ";
    }
    os << "]\n";
    return os;
}

template <typename T>
ostream& operator<<(ostream& os, const set<T>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it;
        if (it != *v.rbegin())
            os << ", ";
    }
    os << "}\n";
    return os;
}

template <typename T>
ostream& operator<<(ostream& os, const unordered_set<T>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it;
        if (it != *v.rbegin())
            os << ", ";
    }
    os << "}\n";
    return os;
}

template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it.first << " : "
           << it.second;

        if( it != *v.rbegin())
            os  << ", ";
    }

    os << "}\n";
    return os;
}

template <typename T, typename S>
ostream& operator<<(ostream& os, const unordered_map<T, S>& v)
{
    os << "{";
    for (const auto& it : v) {
        os << it.first << " : "
           << it.second;

        if( it != *v.rbegin())
            os  << ", ";
    }

    os << "}\n";
    return os;
}

template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v)
{
    os << "(";
    os << v.first << ", "
       << v.second << ")";
    os << "\n";
    return os;
}

#define DEBUG

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define debug(...)
#endif


// __gcd(x, y)

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

    int a, b;
    cin >> a >> b;

    cout << a*b << endl;


    return 0;
}


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

int main()
{
  int n;
  for(;cin>>n,n;)
    {
      int ans[3]={0,0,0};
      int sum[3]={0,0,0};
      for(int i=0;i<n;i++)
	{
	  int hh,mm,m;
	  char buf;
	  cin>>hh>>buf>>mm>>m;
	  //cout<<hh<<" "<<mm<<" "<<m<<endl;
	  int time=hh*60+mm;
	  int m_time;
	  if(mm<=m)
	    m_time=m-mm;
	  else
	    m_time=(60-mm)+m;

	  if(time>=11*60 && time<=14*60+59)
	    {
	      sum[0]++;
	      if(m_time<9)
		ans[0]++;
	    }
	  if(time>=18*60 && time<=20*60+59)
	    {
	      sum[1]++;
	      if(m_time<9)
		ans[1]++;
	    }
	  if((time>=21*60 && time<=23*60+59) ||( time>=0 && time<=1*60+59))
	    {
	      sum[2]++;
	      if(m_time<9)
		ans[2]++;
	    }
	}
      string s[3]={"lunch","dinner","midnight"};
      for(int i=0;i<3;i++)
	{
	  cout<<s[i]<<" ";
	  if(sum[i]>0)
	    cout<<(int)(((double)ans[i]/sum[i])*100)<<endl;
	  else
	    cout<<"no guest"<<endl;
	}
    }


}

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


int main(void){
    ll n;
    cin>>n;
    if(n%2==1)cout<<0<<endl;
    else{
        ll x=n/2;
        ll power=5;
        ll ans=0;
        while(x>=power){
            ans+=x/power;
            power=5*power;
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

int main() {
  int MOD = 1000000007;
  int N; cin >> N;
  vector<long long> T(N), A(N);
  for (int i = 0; i < N; i++) cin >> T.at(i);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  // 最高が更新された地点の記録
  vector<bool> TB(N), AB(N);
  int tmp_t = -1, tmp_a = -1;
  for (int i = 0; i < N; i++) {
    if (T.at(i) != tmp_t) TB.at(i) = true;
    tmp_t = T.at(i);
    if (A.at(N-1-i) != tmp_a) AB.at(N-1-i) = true;
    tmp_a = A.at(N-1-i);
  }
  // 整合性のチェック
  for (int i = 0; i < N; i++) {
    if (TB.at(i) && AB.at(i)) {
      if (T.at(i) != A.at(i)) { cout << 0 << endl; return 0; }
    }
    else if (TB.at(i)) {
      if (T.at(i) > A.at(i)) { cout << 0 << endl; return 0; }
    }
    else if (AB.at(i)) {
      if (A.at(i) > T.at(i)) { cout << 0 << endl; return 0; }
    }
  }
  long long ans = 1;
  for (int i = 0; i < N; i++) {
    if (TB.at(i) || AB.at(i)) continue;
    else ans = ans * min(T.at(i), A.at(i)) % MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
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; }
typedef long long ll;

using namespace std;


int N, M;
vector<vector<int>> G;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N >> M;
  G.assign(N, vector<int>());
  int indeg[N] = {};
  REP(i,M){
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    G[x].push_back(y);
    indeg[y]++;
  }
  queue<int> que;
  int d[N];
  REP(i,N){
    if(indeg[i] == 0){
      que.push(i);
      d[i] = 0;
    }else d[i] = -1;
  }
  while(!que.empty()){
    int tmp = que.front();
    que.pop();
    for(auto nv:G[tmp]){
      chmax(d[nv],d[tmp] + 1);
      indeg[nv]--;
      if(indeg[nv] == 0) que.push(nv);
    }
  }
  int ans = 0;
  REP(i, N) chmax(ans,d[i]);
  cout << ans << endl;

  }

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

int ans = 0;

void dfs(ll now, ll MX) {
    if (now > MX) return;
    string S  = to_string(now);
    bool has3 = S.find("3") != string::npos;
    bool has5 = S.find("5") != string::npos;
    bool has7 = S.find("7") != string::npos;
    if (has3 && has5 && has7) ans++;
    dfs(now * 10 + 3, MX);
    dfs(now * 10 + 5, MX);
    dfs(now * 10 + 7, MX);
}

int main() {
    ll N;
    cin >> N;
    dfs(0, N);
    cout << ans << endl;
}

Measured memory_bytes: 256
X = int(input())
if X >=400 and X<= 599:
  print('8')
elif X >= 600 and X <= 799:
  print('7')
elif X >= 800 and X <= 999:
  print('6')
elif X >= 1000 and X <= 1199:
  print('5')
elif X >= 1200 and X <= 1399:
  print('4')
elif X >= 1400 and X <= 1599:
  print('3')
elif X >= 1600 and X <= 1799:
  print('2')
elif X >= 1800 and X <= 1999:
  print('1')



Measured memory_bytes: 9188
N,X=map(int,input().split())
G=list(map(int,input().split()))

S=[0]
for g in G:
    S.append(S[-1]+g)

ANS=1<<60

def length(x):
    if x==1:
        return 5
    else:
        return 2*x+1

for rep in range(1,N+1):
    score=X*N+X*rep
    count=1
    
    for i in range(N,0,-rep):
        score+=(S[i]-S[max(0,i-rep)])*length(count)
        count+=1
        
    ANS=min(ANS,score)
    
print(ANS)

Measured memory_bytes: 98128
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,n;
    cin>>x>>n;
    vector<int>minas;
    vector<int>plus;
    bool zero=true;
    for(int i=0;i<n;i++){
        int current;
        cin>>current;
        if(current-x<0)
        {
            minas.push_back(current-x);
        }
        else if(current-x>0)
        {
            plus.push_back(current-x);
        }
        else{
            zero=false;
        }
        
    }
    sort(minas.begin(),minas.end());
    reverse(minas.begin(),minas.end());
    sort(plus.begin(),plus.end());
 
    if(zero)
    {
        cout<<x<<endl;
    }
    else if(minas.size()==0)
    {
      cout<<x-1<<endl;
    }
    else
    {
         for(int i=1;true;i++)
        {
             if(i==minas.size()+1||-i!=minas.at(i-1))
            {  
                cout<<x-i<<endl;
                break;
            }
            if(i==plus.size()+1||i!=plus.at(i-1))
            {  
                cout<<x+i<<endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 3612
#include <iostream>                                  
#include <cmath>                                     
using namespace std;                                 
                                                     
int main(void){                                      
 long long int n,a,b,c,d,e,min,group,count = 0;      
  cin >> n;                                          
  cin >> a;min = a;                                  
  cin >> b;if(b < min) min =b;                       
  cin >> c;if(c < min) min = c;                      
  cin >> d;if(d < min) min = d;                      
  cin >> e;if(e < min) min = e;                      
  cout << 4+(n+min-1)/min <<endl;                    
  return 0;                                          
}                                                    
                                                     

Measured memory_bytes: 256
#include <iostream>                                                                                                                                                                                         
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
using namespace std;

int main(){
    int N;
    long long W;
    cin >> N >> W;
    long long w[N+1],v[N+1];
    cin >> w[0] >> v[0];
    // create a dictionary
    map<long long, vector<long long>> mp;
    vector<long long> g1, g2, g3, g4;
    mp[w[0]] = g1; 
    mp[w[0]+1] = g2;
    mp[w[0]+2] = g3;
    mp[w[0]+3] = g4;
    mp[w[0]].push_back(v[0]);
    for(int i=1;i<N;i++){
        cin >> w[i] >> v[i];
        mp[w[i]].push_back(v[i]);
    }   

    sort(mp[w[0]].begin(),mp[w[0]].end(),greater<int>());
    sort(mp[w[0]+1].begin(),mp[w[0]+1].end(),greater<int>());
    sort(mp[w[0]+2].begin(),mp[w[0]+2].end(),greater<int>());
    sort(mp[w[0]+3].begin(),mp[w[0]+3].end(),greater<int>());

    long long temp = 0;
    long long a, b, c, d;
    for(int i=0;i<=mp[w[0]].size();i++){
        for(int j=0; j<=mp[w[0]+1].size();j++){  
            for(int k=0; k<=mp[w[0]+2].size();k++){
                for(int l=0; l<=mp[w[0]+3].size();l++){
                     if(i*w[0]+j*(w[0]+1)+k*(w[0]+2)+l*(w[0]+3) > W) break;  
                     a = accumulate(mp[w[0]].begin(),mp[w[0]].begin()+i,0);
                     b = accumulate(mp[w[0]+1].begin(),mp[w[0]+1].begin()+j,0);
                     c = accumulate(mp[w[0]+2].begin(),mp[w[0]+2].begin()+k,0);
                     d = accumulate(mp[w[0]+3].begin(),mp[w[0]+3].begin()+l,0);
                     if(a+b+c+d > temp){
                         temp = a+b+c+d;
                     }
                }
            }
        }
    }

    cout << temp << endl;
    return 0;
}

Measured memory_bytes: 888
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
int a[200020];
int main()
{
    int n,m,s=0,mn,x;
    scanf("%d",&n);
    mn=n+5;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&x);
        if(x<mn)
        {
            mn=x;
            s++;
        }
    }
    printf("%d\n",s);
    return 0;
}





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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

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


int main(void){

	string s; cin >> s;

  ll N = s[0] - '0';
	REP(i,s.length()-1){
		N *= 10;
		N += 9;
	}

	int ans = 0;
	if(stol(s) == N){
		ans = s[0] - '0' + 9 * (s.length()-1);
	}else{
		ans = s[0] - '0' + 9 * (s.length()-1) - 1;
	}

	cout << ans << endl;

	


	return 0;

}


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

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

class Magatro
{
    private int N;
    private long[] A;
    private void Scan()
    {
        N = int.Parse(Console.ReadLine());
        A = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
    }

    public void Solve()
    {
        Scan();
        long sum = A.Sum();
        long sunke = 0;
        long ans = long.MaxValue;
        for(int i = 0; i < N - 1; i++)
        {
            sunke += A[i];
            sum -= A[i];
            ans = Math.Min(ans, Math.Abs(sunke - sum));
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 34372
#include<iostream>
#include<string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int i;
	int ans = 0;
	vector<int> A;
	vector<int> B;
	for (i = 0; i < 5; i++) {
		int a;
		cin >> a;
		A.push_back(a);
		if (A.at(i) % 10 == 0) {
			B.push_back(0);
		}
		else {
			B.push_back(10 - A.at(i) % 10);
		}
	}
	sort(B.begin(), B.end());
	for (i = 0; i < 5; i++) {
		ans += A.at(i);
		ans += B.at(i);
	}
	ans -= B.at(4);
	cout << ans;
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for(int i=0;i<int(n);i++)
#define rrep(w, n) for(int i=int(n)-1; i>=0; i--)

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

int main(){
	int n;
	cin>>n;
	vi v(n),x(n),y(n);
	rep(i,n)cin>>x[i]>>y[i];
	rep(i,n)v[i]=i;

	int cnt=0;
	double sum=0;
	do{
		cnt++;
		rep(i,n-1){
			sum+=hypot(x[v[i]]-x[v[i+1]],y[v[i]]-y[v[i+1]]);
		}
	}while(next_permutation(all(v)));

	sum/=cnt;
	cout<<fixed<<setprecision(9)<<sum<<endl;

	return 0;
}
	


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	string s;
	cin>>s;
	int mini,maxi;
	for(int i=0;i<s.length();i++){
		if (s[i] == 'A'){
			mini = i;
			break;
		}

	}
	for(int i=s.length()-1;i>=0;i--){
		if (s[i] == 'Z'){
			maxi = i;
			break;
		}
	}
	cout<<maxi-mini+1<<endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<stack>

using namespace std;

int main() {
	
	int n;
	cin >> n;
	int n2;
	cin >> n2;
	
	int choice;
	int temp, temp2;	
	stack<int> stack[n];
	
	for(int i=0;i<n2;i++) {		
		cin >> choice;
		switch(choice) {
			case 0:
				cin >> temp >> temp2;
				stack[temp].push(temp2);
				break;
			case 1:
				cin >> temp;
				if( stack[temp].size() == 0)
					break;
				else
				cout << stack[temp].top() << "\n";
				break;
			case 2:
				cin >> temp;
				if( stack[temp].size() == 0)
					break;
				stack[temp].pop();
				break;
		}
	}
	
	return 0;
}


Measured memory_bytes: 4356
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
import sys
gcd = math.gcd
co = collections.Counter()
n = ni()
mod=10**9+7
for i in range(n):
    a,b = ma()
    d = gcd(a,b)
    if d!=0:
        a//=d
        b//=d
    elif abs(a)>0 or abs(b)>0:
        l = max(abs(a), abs(b))
        a//=l
        b//=l
    co[(a,b)]+=1
d = collections.defaultdict(lambda:False)
ans=1
for t,cnt in co.items():
    a,b = t
    if t==(0,0) or d[t]:
        continue
    d[(a,b)]=True;d[(-a,-b)]=True;d[(b,-a)]=True;d[(-b,a)]=True
    l1 = co[(a,b)]+co[(-a,-b)]
    l2 = co[(b,-a)]+co[(-b,a)]
    ans=ans*(pow(2,l1,mod)+pow(2,l2,mod) -1)%mod
    ans%=mod
print((ans-1 +co[(0,0)])%mod)


Measured memory_bytes: 217936
d, g = map(int, input().split())
questions = [list(map(int, input().split())) for _ in range(d)]
ans = 10 ** 9 

for i in range(2 ** d):
    score = 0
    problems = 0
    index = -1
    for j in range(d):
        if i >> j & 1:
            score += 100 * (j+1) * questions[j][0] + questions[j][1]
            problems += questions[j][0]
        else:
            index = j
    if g <= score:
        ans = min(ans, problems)
    elif 0 <= index and  g <= score + questions[index][0] * (index+1)*100:
        problems += -(-(g-score) // ((index+1)*100))
        ans = min(ans, problems)
print(ans)


Measured memory_bytes: 40944
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int[] value = new int[n];
		for (int i = 0; i < value.length; i++) {
			value[i] = sc.nextInt();
		}

		new Main().execute(n, value);
	}

	private void execute(int n, int[] value) {
		long money = 1000;
		long kabu = 0;
		for (int i = 0; i < value.length - 1; i++) {
			int todayVal = value[i];
			int tommorowVal = value[i + 1];
			if (todayVal < tommorowVal) {
				// 買う
				kabu += money / todayVal;
				money = money % todayVal;
			} else if (todayVal > tommorowVal && kabu > 0) {
				// 売る
				money += todayVal * kabu;
				kabu = 0;
			}
		}
		// 最終日
		money += value[value.length - 1] * kabu;
		System.out.println(money);
	}
}

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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
// constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

template <class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

struct Edge {
    ll to, rev;
    long double cap;
    Edge(ll _to, long double _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph &G, ll from, ll to, long double cap, bool revFlag,
              long double revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    ll n;
    cin >> n;
    vec<ll> f(10101, 0);
    rep(x, 1, 101) {
        rep(y, 1, 101) {
            rep(z, 1, 101) {
                if(x * x + y * y + z * z + x * y + y * z + z * x > n)
                    continue;
                f[x * x + y * y + z * z + x * y + y * z + z * x]++;
            }
        }
    }
    rep(i, 1, n + 1) {
        cout << f[i] << en;
    }
}

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

    solve();
    // ll t;cin>>t;REP(i,t) solve();

    return 0;
}


Measured memory_bytes: 3732