akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

struct cake{
    ll a;
    ll b;
    ll c;
};
ll N , M ;
vector<cake> lst;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> N >> M ;
    rep(i,N){
        cake inp;
        cin >> inp.a >> inp.b >> inp.c;
        lst.pb(inp);
    }

    ll ans  = 0 ;
    rep(i,2)rep(j,2)rep(k,2){
        ll ret = 0 ;
        
        ll a = i, b = j, c = k;
        if(a == 0 ) a = -1;
        if(b == 0 ) b = -1;
        if(c == 0 ) c = -1;
        
        vector<ll> v ;
        rep(si, lst.size()){
            ll value = a * lst[si].a + b * lst[si].b + c*lst[si].c;
            v.pb(value);
        }
        sort(rall(v));
        
        rep(si,M){
            ret+= v[si];
        }
        ans = max(ans, ret);
    }
    
    cout << ans << endl;
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl '\n'
#define rep(i,n) for(int i=0;i<n;i++) 
#define all(v) v.begin(),v.end()
#define F first
#define S second 
const ll MOD=1e9+7;
template<typename ForwardIterator,typename T>
ForwardIterator first_less_than(ForwardIterator first,ForwardIterator last,T val)
{
	auto it=lower_bound(first,last,val);
	return (it==first?first:it);
}
const ll N=10e5+7;
vector<ll> adj[N];
vector<ll> vis(N,false);
ll res=0;
void dfs(ll x)
{
	vis[x]=true;
	res++;
	for(auto y:adj[x])
	{
		if(!vis[y])
		{
			dfs(y);
		}
	}
	
}
void solve()
{
	ll n,m;
	cin>>n>>m;
	ll maxres=0;
	while(m--)
	{
		ll x,y;
		cin>>x>>y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	for(int i=1;i<=n;i++)
	{
		if(!vis[i])
		{
			dfs(i);
			maxres=max(maxres,res);
			res=0;
		}
	}
	cout<<maxres<<endl;
}

int main()
{
	ios_base::sync_with_stdio(false); 
  	 cin.tie(NULL);  
	int tt;
	tt=1;
	while(tt--)
	{
		solve();
	}
}


Measured memory_bytes: 46932
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
	if(n==1){
		cout << 1 << endl;
		return 0;
	}
	long long int a[100];
	a[0] = 2;
	a[1] = 1;
	for(int i=2;i<=n;i++){
		a[i] = a[i-1] + a[i-2];
	}
	cout << a[n] << endl;
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef string st;
typedef double db;
typedef vector<long long> vecll;
typedef vector<char> vechar;

int main(){
    ll r, g, b;
    cin >> r >> g >> b;
    ll card = 100 * r + 10 * g + b;
    if(card % 4 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
#include <utility>
typedef long long ll;
using namespace std;

int main(void){
  int h, w, i, j;
  int d, q;
  char c;
  bool b = 0;
  vector<int> alp;
  string buff;

  cin >> h >> w;
  q = (h/2) * (w/2);
  d = (h*w-4*q) / 2;

  alp.resize('z'-'a'+1,0);

  for(i=0;i<h;i++){
    cin >> buff;
    for(j=0;j<w;j++){
      ++alp[buff[j]-'a'];
    }
  }

  for(i=0;i<'z'-'a'+1;i++){
    q -= alp[i] / 4;
    alp[i] -= (alp[i]/4) * 4;

    d -= alp[i] / 2;
    alp[i] -= (alp[i]/2) * 2;

    if(alp[i]==1){
      if(b){
        cout << "No" << endl;
        return 0;
      }
      b=1;
    }
  }
  
  if(q>0){
    cout << "No" << endl;
    return 0;
  }
  else{
    cout << "Yes" << endl;
    return 0;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main() {
  long long int a, b, x;
  std::cin >> a >> b >> x;

  if ( a == 0 ) std::cout << b / x + 1 << std::endl;
  else if ( b == 0 ) std::cout << 1 << std::endl;
  else std::cout << b / x - (a - 1) / x << std::endl;

  return 0;
}


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

int x(int i,int r,int d,int xx){
	if(i==0){
		return xx;
	}
	else{
		return r*x(i-1,r,d,xx)-d;
	}
}

int main(){
	long long r,d,xx;
	cin>>r>>d>>xx;
	
	for(int j=1;j<=10;j++){
		cout<<x(j,r,d,xx)<<"\n";
	}
}

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

int main(){
  int n,a[110000],m=0,c[110000],ans=0;
  cin>>n;
  for(int i=0;i<n;i++) { cin>>a[i]; c[a[i]]++; }

  if(n==1) { cout<<"1"; return 0; }
  else if(n==2) {
      if(abs(a[0]-a[1])<=1) cout<<"2";
      else cout<<"1";
      return 0;
  }
  else {
    for(int i=2;i<n;i++)
      if(c[i-2]+c[i-1]+c[i]>ans) ans=c[i-2]+c[i-1]+c[i];
  }
  cout<<ans;




}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
    static void Main()
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Program().Solve();
        Console.Out.Flush();
    }
    Scanner cin = new Scanner();

    List<int>[] G;
    bool[] B;
    bool flag;
    void Solve()
    {
        int V = cin.Nextint, E = cin.Nextint;
        G = Enumerable.Range(0, V).Select(i => new List<int>()).ToArray();
        for (int i = 0; i < E; i++)
        {
            G[cin.Nextint].Add(cin.Nextint);
        }

        for (int i = 0; i < V; i++)
        {
            B = new bool[V];
            Dfs(i, i);
            if (flag) break;
        }
        Console.WriteLine((flag) ? 1 : 0);
    }
    void Dfs(int start, int now)
    {
        if (start == now && B[start])
        {
            flag = true;
            return;
        }
        if (B[now]) return;
        B[now] = true;
        foreach (var x in G[now])
        {
            Dfs(start, x);
        }
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] Scan { get { return Console.ReadLine().Split(); } }
    public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } }
    public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } }
    public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } }
    public string Next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return Next;
        }
    }
    public int Nextint { get { return int.Parse(Next); } }
    public long Nextlong { get { return long.Parse(Next); } }
    public double Nextdouble { get { return double.Parse(Next); } }
}

Measured memory_bytes: 9720
#include <iostream>

using namespace std;
long long w[105], v[105];
long long a[100005];
int main()
{
    long long n, i, j, m, maxi = 0;
    cin >> n >> m;
    for (i = 1; i <= n; i++)
        cin >> w[i] >> v[i];
    for (i = 1; i <= 100000; i++)
        a[i] = 1000000000005;
    for (i = 1; i <= n; i++)
    {
        for (j = maxi; j > 0; j--)
        {
            if (a[j] != 1000000000005)
            {
                a[j + v[i]] = min(a[j+v[i]], a[j] + w[i]);
                maxi = max(maxi, j + v[i]);
            }
        }
        maxi = max(v[i], maxi);
        a[v[i]] = min(a[v[i]], w[i]);
    }
    for (i = maxi; i > 0; i--)
    {
        if (a[i] <= m)
        {
            cout << i;
            i = 0;
        }
    }
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <string.h>

int main()
{
    int N;
    scanf("%d",&N);
    int H[N];
    for (int i=0; i<N; i++)
        scanf("%d",&H[i]);
    int count = 1;
    int a = 0;
    int idx=0;
    for (int i=1; i<N; i++)
    {

        if (H[idx]<=H[i])
        {
            count++;
            idx=i;
        }
    }
    printf("%d",count);

    return 0;
}


Measured memory_bytes: 128
#include <iostream>

int main()
{
    int r, g, b;
    std::cin >> r >> g >> b;

    if ((r * 100 + g * 10 + b) % 4 == 0) {
        std::cout << "YES" << std::endl;
    } else {
        std::cout << "NO" << std::endl;
    }
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

n,u,v = map(int, input().split())
adjacent_list = [[] for i in range(n+1)]
aoki = [0 for i in range(n+1)]
takahashi = [0 for i in range(n+1)]
for i in range(n-1):
    a,b = map(int ,input().split())
    adjacent_list[a].append(b)
    adjacent_list[b].append(a)

def dfs(node, count,li):
    li[node] = count
    finished.add(node)
    for i in adjacent_list[node]:
        if i not in finished:
            dfs(i, count + 1,li)
def dfs_par(node, count,li):
    global node_par
    li[node] = count
    finished.add(node)
    for i in adjacent_list[node]:
        if i not in finished:
            node_par[i] = node
            dfs_par(i, count + 1,li)
        
node_par = [0 for i in range(n+1)]

finished = set()
dfs(u,0,takahashi)

#辿って親保存しとく
finished = set()
dfs_par(v,0,aoki)

#さかのぼれるとこまで行く,startがさかのぼれる最大のノーど
par = u
start = u
while takahashi[par] < aoki[par]:
    start = par
    par = node_par[start]

ans_height = [0 for i in range(n+1)]
finished = set([node_par[start]])
dfs(start,0,ans_height)
print(max(ans_height) + aoki[start] - 1)



Measured memory_bytes: 109276
a = []
for i in range(6):
    a.append(int(input()))


f = 1

for j in range(len(a)-1):
    for k in range(1+j,5):



        if(a[k] - a[j] > a[5]):
            print(":(")
            f =  0
            break
    if(f ==0):
        break
if(f ==1):
    print("Yay!")



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

using namespace std;

#define pb push_back
#define mp make_pair
#define pi 2.0*acos(0.0)
#define INTM 1e18
#define mod 1e9+7
#define FOR(i,j,n)    for(ll i=j;i<n;i++)
#define RFOR(i,j,n)    for(ll i=j;i>=n;i--)

typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;

int main(){
    ll a,b;
    cin>>a>>b;
    ll gcd = __gcd(a,b);
    cout<<(a*b)/gcd<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,f,t) for(int i=f;i<t;i++)
#define ll long long int
using namespace std;

int pr[200010];
int sz[200010];

void make_set(){
	rep(i,0,200005){
		pr[i]=i;
		sz[i]=1;
	}
}

int find_set(int a){
	if(pr[a]==a)return a;
	return pr[a]=find_set(pr[a]);
}

void union_set(int a,int b){
	int p=find_set(a);
	int q=find_set(b);
	if(p!=q){
		if(sz[p]<sz[q])swap(p,q);
		sz[p]+=sz[q];
		pr[q]=p;
	}
}

int solve(){
	make_set();
	ll n,m;
    cin>>n>>m;
	rep(i,0,m){
		int a,b;
		cin>>a>>b;
		union_set(a,b);
	}
	int maxi=0;
	rep(i,1,n+1){
		maxi=max(maxi,sz[i]);
	}
	cout<<maxi<<endl;
	return 0;
}
int main(){
//    waste;
    int t;
    //cin>>t;
    t=1;
    while(t--){
       	solve();
    }
}


Measured memory_bytes: 5168
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n; rd(n);
  auto d=new int[](n);
  foreach(i; 0..n) rd(d[i]);

  int r=0;
  foreach(int i, int e; d){
    if(r<i*10){writeln("no"); return;}
    if(r<i*10+e) r=i*10+e;
  }

  reverse(d);
  r=0;
  foreach(int i, int e; d){
    if(r<i*10){writeln("no"); return;}
    if(r<i*10+e) r=i*10+e;
  }

  writeln("yes");
}

void chmax(T)(ref T x, T y){
  if(x<y) x=y;
}
void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}

Measured memory_bytes: 4512
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
  long long x, y;
  cin >> x >> y;

  int ans = 0;
  while (x <= y) {
    ans++;
    x *= 2;
  }
  cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const ll MOD2=998244353;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  string s;
  cin >> s;
  ll k=s.size();
  bool b=true;
  rep(i,k-1){
    FOR(j,i+1,k){
      if(s[i]==s[j]){
        b=false;
      }
    }
  }
  if(b){
    cout << "yes" << endl;
  }
  else{
    cout << "no" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N, X, T; cin >> N >> X >> T;
    cout << (N + X - 1) / X * T << endl;
}


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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 300005;

/* ...o(^-^)o... */

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

    vector<int> r, g;
    vector<bool> isb(n);
    rep(i, n) isb[i] = false;
    lint count_b = 0;

    rep(i, n){
        if(s[i] == 'R') r.push_back(i);
        else if(s[i] == 'G') g.push_back(i);
        else{ isb[i] = true; count_b++; }
    }

    if(r.size() == 0 || g.size() == 0 || count_b == 0){
        out(0); return 0;
    }

    lint ans = 0;
    rep(i_, r.size()) rep(j_, g.size()){
        int i = r[i_], j = g[j_];
        if(i > j) swap(i, j);

        vector<int> ng;
        ng.push_back(i*2-j); ng.push_back(j*2-i);
        if((j-i)%2 == 0) ng.push_back((i+j)/2);

        lint ngb = 0;
        rep(k, ng.size()){
            if(ng[k] < 0 || ng[k] >= n) continue;
            if(isb[ng[k]]) ngb++;
        }
        ans += count_b - ngb;
    }
    out(ans);
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define N 200100

struct query {
	int l,r,id;
}q[N];
int n,m,Q,ans;
int a[510][510],l[N],r[N],Ans[N];

bool cmp(query x,query y) {
	if (x.l==y.l) return x.r<y.r;
	return x.l<y.l;
}

int now;
int main()
{
	scanf("%d%d%d",&n,&m,&Q);
	for (int i=1;i<=m;i++) scanf("%d%d",&l[i],&r[i]),a[l[i]][r[i]]++;
	for (int i=1;i<=Q;i++) scanf("%d%d",&q[i].l,&q[i].r),q[i].id=i;
	sort(q+1,q+Q+1,cmp);
	for (int i=1;i<=Q;i++) {
		if (q[i].l==q[i-1].l && q[i].r==q[i-1].r) {
			Ans[q[i].id]=ans;
			continue;
		}
		if (q[i].l!=q[i-1].l) ans=a[q[i].l][q[i].l],now=q[i].l;
		while (now<q[i].r)
		{
			now++;
			for (int j=q[i].l;j<=now;j++) ans+=a[j][now];
		}
		Ans[q[i].id]=ans;
	}
	for (int i=1;i<=Q;i++) printf("%d\n",Ans[i]);
	return 0;
}

Measured memory_bytes: 5120
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <limits>
#include <functional>
#include <cassert>
#include <numeric>
#include <bitset>

#define FOR(x,n) for(int x = 0; x < n; x++)
#define INPUT(x) scanf("%d",&x);
#define PUT(x) cout << x << endl
#define DPUT(x) printf("%.15lf\n",x)
#define GET(x,y) std::get<x>(y)
#define CHMAX(x,y) x = std::max(x,y)
#define CHMIN(x,y) x = std::min(x,y)
#define SP_END (i != n - 1 ? ' ' : '\n') ;

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvpii = std::vector<vpii>;
using vch = std::vector<char>;
using vvch = std::vector<vch>;
using tiii = std::tuple<int, int, int>;

const ll mod197 = 1000000007LL;
const ll INF = 10000000000LL;

const double PI11 = 3.14159265359;

const int dis[5] = { 0,1,0,-1,0 };

const int disD[4] = { 0,1,1,0 };

int main(void)
{

	int n;

	cin >> n;

	pii m;

	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;

		if (m < pii(a, b)) {
			m = pii(a,b);
		}

	}

	cout << m.first + m.second << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;

public class Main {

  static double n;
  
  public static void main(String[] args) throws Exception {
    
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    String[] in = br.readLine().split(" ");
    n = Double.parseDouble(in[0]);

    br.close();

    System.out.println(2.0 * n * 3.141592);
  }
}

Measured memory_bytes: 33064
#include <iostream>
#include <vector>
#include <algorithm>
#define all(x) (x).begin(), (x).end()
using namespace std;

int main(void) {
    int N,M;cin>>N>>M;
    vector<string> flag;
    for (int i = 0; i < N; i++) {
        string s;cin>>s;
        flag.push_back(s);
    }
    int mi = 1e9;
    for (int white_index = 0; white_index <= N - 3; white_index++) {
        for (int blue_index = white_index+1; blue_index <= N - 2; blue_index++) {
            int tmp = 0;
            for (int i = 0; i <= white_index; i++) tmp += count(all(flag[i]), 'B') + count(all(flag[i]), 'R');
            for (int i = white_index+1; i <= blue_index; i++) tmp += count(all(flag[i]), 'W') + count(all(flag[i]), 'R');
            for (int i = blue_index+1; i <= N - 1; i++) tmp += count(all(flag[i]), 'W') + count(all(flag[i]), 'B');
            if (tmp < mi) mi = tmp;
        }
    }
    cout << mi << endl;
    return 0;
}


Measured memory_bytes: 3208
import java.util.*;
import java.util.stream.Collectors;
public class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        
        List<Integer> list = new ArrayList<>(N);
        for (int i = 0; i < N; i++) {
        	list.add(sc.nextInt());
        }
        
        list = list.stream().sorted().collect(Collectors.toList());
        
        int ans = 0;
        for (int i = 0; i < list.size(); i++) {
        	for (int j = i+1; j < list.size(); j++) {
        		for (int k = j+1; k < list.size(); k++) {
        			int a = list.get(i);
        			int b = list.get(j);
        			int c = list.get(k);
        			
        			if (a == 0 || b == 0 || c == 0) {
        				continue;
        			}
        			
        			if (a <= A && A+1 <= b && b <= B && B+1 <= c) {
        				list.set(i, 0);
        				list.set(j, 0);
        				list.set(k, 0);
        				ans++;
        			}
        		}
        	}
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 27088
#!/usr/bin/env python

def main(N, H):
    ans = 'Yes'

    min_val = H[0] -1
    for i in range(1, N):
        if min_val <= H[i] -1:
            min_val = H[i] -1
        elif min_val <= H[i]:
            min_val = H[i]
        else:
            ans = 'No'
            break
    return ans

if __name__ == '__main__':
    N = int(input())
    H = list(map(int, input().split()))
    print(main(N, H))


Measured memory_bytes: 63984
#include <stdio.h>

int main()
{
 int N;
 char s1[54];
 char s2[54];
 int i;
 long long ways=1;
 int start;

 scanf("%d",&N);
 scanf("%s",s1);
 scanf("%s",s2);


 if(s1[0]==s2[0]) 
 {
   ways=3;
   start=1;
 }else{
   ways=6;
   start=2;
 }

 for(i=start;i<N;i++)
 {
   if((s1[i]==s2[i])&(s1[i-1]==s2[i-1])) 
   {
     /*  ab
         ab */
     ways=ways*2;
     ways=ways%1000000007;
   }else if((s1[i]==s2[i])&(s1[i-1]!=s2[i-1]))
   {
     /* aab
        ccb  */
   }else if((s1[i]!=s2[i])&(s1[i-1]==s2[i-1]))
   {
     /* abb
        acc */
     ways=ways*2;
     ways=ways%1000000007;
     i++;
   }else{
    /*  aabb
        ccaa  */
    ways=ways*3;
     ways=ways%1000000007;
     i++;
   }
 }
 printf("%lld \n",ways); 
 return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define LIMIT(d_in, d_min, d_max) max(d_min, min(d_max, d_in))
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int H, A;
	cin >> H >> A;

	for (int i = 0; i < A; i++)
	{
		int tmp;
		cin >> tmp;
		H -= tmp;
	}
	if (H <= 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#define MAX 2010
#define Ai 10000
int A[MAX],B[MAX],C[Ai+10]={0},book[MAX];
int n;
void swap(int x,int y)
{
	int t=A[x];
	A[x]=A[y];
	A[y]=t;
	return;
}
void countingsort()
{
	int i;
	for(i=1;i<=n;i++)
		C[A[i]]++;
	for(i=1;i<=Ai;i++)
		C[i]=C[i]+C[i-1];
	for(i=n;i>=1;i--)
	{
		B[C[A[i]]]=A[i];
		book[i]=C[A[i]];
		C[A[i]]--;
	}
	return;
}
int circlecost(int start,int rn)//start是圆的起始点(可以是圆中的任意点),rn是圆中的点数
{
	if(rn==1)
		return 0;
	if(rn==2)
		return A[start]+A[book[start]];

	//初始化
	int min=start,minA=1,i,h,j,cnt1=0,cnt2=0,k;
	int a[MAX];
	for(i=1;i<=n;i++)
		a[i]=A[i];
	j=1;
	for(i=start;;i=book[i])
	{
		if(j>rn)
			break;
		if(A[min]>A[i])
			min=i;
		j++;
	}
	//情况1:不借元素
	j=1;
	for(i=start;j<=rn-1;i=book[i])
	{
		for(k=1;k<=n;k++)
			if(book[k]==min)
			{
				h=k;
				break;
			}
		swap(min,h);
		if(min!=h)
			cnt1=cnt1+A[min]+A[h];
		min=h;
		j++;
	}
	//还原
	for(i=1;i<=n;i++)
		A[i]=a[i];
	j=1;
	for(i=start;;i=book[i])
	{
		if(j>rn)
			break;
		if(A[min]>A[i])
			min=i;
		j++;
	}
	for(i=1;i<=n;i++)
		if(A[minA]>A[i])
			minA=i;
	//情况2:借整体最小元素
	if(min!=minA)
	{
		swap(min,minA);
		if(min!=minA)
			cnt2=cnt2+A[min]+A[minA];
		j=1;
		for(i=start;j<=rn-1;i=book[i])
		{
			for(k=1;k<=n;k++)
				if(book[k]==min)
				{
					h=k;
					break;
				}
			swap(min,h);
			if(min!=h)
				cnt2=cnt2+A[min]+A[h];
			min=h;
			j++;
		}
		swap(min,minA);
		if(min!=minA)
			cnt2=cnt2+A[min]+A[minA];
	}
	else
		cnt2=cnt1+1;
	//比较
	if(cnt1<cnt2)
		return cnt1;
	return cnt2;
}
int mincost()
{
	countingsort();


	int book2[MAX]={0},i,t,j,circlen,cnt=0;
	for(i=1;i<=n;i++)
		if(book2[i]==0)
		{
			circlen=1;
			for(j=i;;)
			{
				book2[j]=1;
				j=book[j];
				if(j==i)
					break;
				circlen++;
			}
			cnt+=circlecost(i,circlen);
		}
	return cnt;
}
int main()
{
	int i;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",&A[i]);
	printf("%d\n",mincost());
	return 0;
}


Measured memory_bytes: 2100
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i, MAT.size()){
    REP(j, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

template <typename CLASS1, typename CLASS2>
class HOGE{
  public:
    CLASS1 key;
    CLASS2 value;
    HOGE(void){
      return;
    };
    HOGE(CLASS1 key, CLASS2 value){
      this->key = key;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "key : " << key << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

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

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  cin >> N;
  ll ans;
  cin >> ans;
  REP(i, N-1){
    ll A;
    cin >> A;
    ans = gcd(ans, A);
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
string a,b,c;
int main(void){
    cin>>a>>b>>c;
    char A=a[0]-32,B=b[0]-32,C=c[0]-32;
    cout<<A<<B<<C<<endl;
    
}


Measured memory_bytes: 3632
import itertools
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def gcd(a,b):
    while b % a:
        a,b = b, a % b
    return a

N = I()
A = IL()

ans = gcd(A[0],A[1])
for i in A:
  if i%ans != 0:
    ans = gcd(ans,i)
  if ans == 1:
    break

print(ans)

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

namespace AtCoder.Question
{
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var n = ReadHelper.ReadValue<int>();
            Console.WriteLine(n % 1000 == 0 ? 0 : 1000 - n % 1000);
        }

        static class ReadHelper
        {
            internal static T ReadValue<T>()
            {
                return (T)Convert.ChangeType(Console.ReadLine(), typeof(T));
            }
            internal static (T1, T2) ReadValue<T1, T2>()
            {
                var input = Console.ReadLine().Split(' ');
                return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)));
            }
            internal static (T1, T2, T3) ReadValue<T1, T2, T3>()
            {
                var input = Console.ReadLine().Split(' ');
                return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)), (T3)Convert.ChangeType(input[2], typeof(T3)));
            }
            internal static (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>()
            {
                var input = Console.ReadLine().Split(' ');
                return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)), (T3)Convert.ChangeType(input[2], typeof(T3)), (T4)Convert.ChangeType(input[3], typeof(T4)));
            }
            internal static T[] ReadValues<T>()
            {
                var input = Console.ReadLine().Split(' ');
                return input.Select(x => (T)Convert.ChangeType(x, typeof(T))).ToArray();
            }
        }

        static class MathAlgorithm
        {
            internal static bool IsPrime(long n)
            {
                if (n == 2) return true;
                if (n < 2 || n % 2 == 0) return false;
                var sqrt = Math.Sqrt(n);
                for (int i = 3; i <= sqrt; i += 2) if (n % i == 0) return false;
                return true;
            }
            internal static IEnumerable<long> EnumeratePrimes(long n)
            {
                var i = 2L;
                while (i * i <= n)
                {
                    if (n % i == 0)
                    {
                        n /= i;
                        yield return i;
                    }
                    else
                    {
                        i += i == 2 ? 1 : 2;
                    }
                }
                if (n != 1) yield return n;
            }
        }
    }
}


Measured memory_bytes: 27568
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    int N;
    int s,f;
    cin>>a>>b>>N;
    int check=0;
    
    for(int i=0;i<N;i++){
        cin>>s>>f;
        if(a<f&&s<b)check++;
    }
    
    if(check==0)cout<<0<<endl;
    else cout<<1<<endl;
    
    return 0;
}



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

public static class Solution
{
    public static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var L = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

        int count = 0;
        for (int i = 0; i < N; i++)
        {
            for (int j = i + 1; j < N; j++)
            {
                for (int k = j + 1; k < N; k++)
                {
                    if (L[i] == L[j] || L[i] == L[k] || L[j] == L[k])
                    {
                        continue;
                    }

                    if (L[i] >= L[j] + L[k] || L[j] >= L[k] + L[i] || L[k] >= L[j] + L[i])
                    {
                        continue;
                    }

                    count++;
                }
            }
        }

        Console.WriteLine(count);
    }
}

Measured memory_bytes: 28236
main :: IO ()
main = do
  [a,b,x] <- map (read :: String -> Double) . words <$> getLine
  print $ ans a b x

ans :: Double -> Double -> Double -> Double
ans a b x
  | 2*x < a^2*b = atan(a*b^2/(2*x)) *180/pi
  | otherwise   = atan((2*a^2*b-2*x)/(a^3)) *180/pi

Measured memory_bytes: 508
// AtCoder Beginner Contest 172
// ABC A - Calc

#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <random>
#include <vector>
#include <chrono>

using namespace std;

int main()
{
	int a;

	cin >> a;
	
	cout << a + a*a + a*a*a << endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int MOD = 1000000007;
ll cnt =0,ans=0;

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

   ll v=7;
   for(int i=1;i<1000000;i++){
       if(v%k == 0){
           cout << i << endl;
           return 0;
       }

       else{
           v*=10;
           v+=7;
           v=v%k;
           
       } 
   }

   cout << -1 << endl;
}

Measured memory_bytes: 3580
int main(int argc ,const char *argv[])
{
    int x,y,d[2][3000],n=0;
    while(1){
        scanf("%d",&x);
        scanf("%d",&y);
        if(x==0&&y==0){
            break;
        }else{
            if(x>y){
                d[0][n]=y;d[1][n]=x;
            }else{
                d[0][n]=x;d[1][n]=y;
            }
            n++;
        }
    }
    for(int i=0;i<n;i++){
        printf("%d %d\n",d[0][i],d[1][i]);
    }
}


Measured memory_bytes: 2144
#include<bits/stdc++.h>
using namespace std;
int dp[100100];
int n,m;
vector<int> ga[100100];
int u,v;
int d(int x)
{
	if(dp[x]!=-1)
	{
		return dp[x];
	}
	int &res=dp[x];
	res=0;
	for(int i=0;i<ga[x].size();i++)
	{
		int y=ga[x][i];
		res=max(res,d(y)+1);
	}
	return res;
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		cin>>u>>v;
		ga[u].push_back(v);
	}
	int res=0;
	memset(dp,-1,sizeof(dp));
	for(int i=1;i<=n;i++)
	{
		res=max(res,d(i));
	}
	cout<<res;
	return 0;
}

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

int main() {
  int a,b; a=0; b=0;
  string s; cin >> s;
  rep(i,s.size()){
    if(s[i] == '0') a++;
    else b++;
  }
  
  cout << min(a,b)*2 << endl;
  
}

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


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

   int a,b,t; cin >> a >> b >> t;
   int f = t/a;
   int ans = f*b;
   cout << ans << endl;
}



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

int main() {
  int A, B, N, S;
  cin >> A >> B; 
  
  N = 0;
  S = 1;
  
  while (S < B) {
   S = S + A - 1;
   N = N + 1;
  }

  cout << N << endl;
  
}


Measured memory_bytes: 256
N,X=map(int,input().split())
A=[2**(i+2)-3 for i in range(0,N+1)]
pati=[2**(i+1)-1 for i in range(0,N+1)]
def function(num,level):
    if level==0:
        if num==1:
            return 1
        else:
            return 0
    elif num==1:
        return 0
    else:
        subslice=A[level-1]
        if subslice+1>=num:
            return function(num-1,level-1)
        elif num==subslice+2:
            return pati[level-1]+1
        elif A[level]-1>=num:
            return pati[level-1]+1+function(num-subslice-2,level-1)
        else:
            return pati[level]
print(function(X,N))


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

int main(){
  int n;
  cin >> n;
  vector<int> X(n);
  int ans =1<<20;
  for (int i=0;i<n;i++){
    cin >> X[i];
  }
  for (int i=0;i<100;i++){
    int tmp = 0;
    for(int j=0;j<n;j++){
      tmp += (X[j]-i)*(X[j]-i);
    }
    ans = ans>tmp?tmp:ans;
  }
  cout << ans << endl;
}

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

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

bool occ[1 << 17];

int main() {
	ll n;
	int x, m;
	scanf("%lld %d %d", &n, &x, &m);
	if (n <= 1e5) {
		ll ans = 0;
		rep(i, n) {
			ans += x;
			x = 1LL * x * x % m;
		}
		printf("%lld\n", ans);
		return 0;
	}
	vector <int> v;
	while (!occ[x]) {
		occ[x] = 1;
		v.pb(x);
		x = 1LL * x * x % m;
	}
	int o = 1;
	while (v[v.size() - o] != x) ++ o;
	ll s = 0;
	rep(i, o) s += v[v.size() - i - 1];
	ll ans = (n - v.size() + o) / o * s;
	rep(i, v.size() - o) ans += v[i];
	rep(i, (n - v.size() + o) % o) {
		ans += x;
		x = 1LL * x * x % m;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3976
/***
 * 1. b * b <= n
 * 2. n - s = (b - 1) * p
 */

#pragma GCC optimize(2)

#include <cstdio>
#include <iostream>

using namespace std;

typedef long long LL;

LL n, s;

LL f(LL b, LL n)
{
	if(n < b) return n;
	return f(b, n / b) + (n % b);
}

LL solve()
{
	if(n == s) return n + 1;
	for(LL b = 2; b * b <= n; ++b) if(f(b, n) == s) return b;
	if(n < s) return -1;
	LL res = (1LL << 61);
	for(LL i = 1; i * i < n; ++i)
	{
		if((n - s) % i) continue;
		LL b = (n - s) / i + 1LL;
		if(b <= n && f(b, n) == s) res = min(res, b);
	}
	return res != (1LL << 61) ? res : -1LL;
}

int main(void)
{
	scanf("%lld%lld", &n, &s);
	printf("%lld\n", solve());
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string>
#include<queue>
using namespace std;
int edge[10][10] = {};

int main() {
	int N, M, ans = 0;
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		edge[a][b] = 1;
		edge[b][a] = 1;
	}
	vector<int> v;
	for (int i = 2; i <= N; i++) {
		v.push_back(i);
	}

	do {
		int now_v = 1;
		bool flag = true;
		for (int i = 0; i < v.size(); i++) {
			if (edge[now_v][v[i]] == 1) {
				now_v = v[i];
			}
			else {
				flag = false;
				break;
			}
		}
		if (flag) ans++;
	} while (next_permutation(v.begin(), v.end()));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
# coding: utf-8
range = xrange
H, W = map(int, raw_input().split(' '))
S = [[c for c in raw_input()] for _ in range(H)]

answer = []
for h in range(H):
    row = []
    for w in range(W):
        if S[h][w] == '.':
            row.append([
                S[i][j]
                for i in range(max(h - 1, 0), min(H, h + 2))
                for j in range(max(w - 1, 0), min(W, w + 2))
            ].count('#'))
        else:
            row.append(S[h][w])
    answer.append(row)

for r in answer:
    print u''.join(map(unicode, r))


Measured memory_bytes: 2692
import java.util.*;
public class Main {
        static Scanner sc = new Scanner(System.in);
        static void myout(Object t){System.out.println(t);}//standard output
        static void myerr(Object t){System.err.println(t);}//standard error
        static String getStr(){return sc.next();}
        static int getInt(){return Integer.parseInt(getStr());}
        static long getLong(){return Long.parseLong(getStr());}
        static boolean hasNext(){return sc.hasNext();}
        static char[] mySplit(String str){return str.toCharArray();}
        public static void main(String[] args){
          long N = getLong();
          Long min = new Long("10000000000000007");
          while(hasNext()){
            min = Math.min(getLong(),min);
          }
          if(min >= N){
            myout(5);
          }else{
            long output = (N / min);
            if(N % min != 0){
              output++;
            }
            myout(output + 4);
          }
        }
        //Method addition frame start

        //Method addition frame end
}


Measured memory_bytes: 22996
#include<iostream>
#include <algorithm>

using namespace std;
// 算法思路：
// 遍历所有价格，维护当前利润的最大值和历史价格的最低值
// 当前利润的最大值 = max(当前价格 - 历史价格最小值， 上一次的利润最大值)
// 历史价格最低值 = min(当前价格， 上一次的历史价格最小值)
int main(){
    int maxv, minv;
    int n, m;
    int a, b;
    cin>>n>>a>>b;
    minv = min(a, b);
    maxv = b - a;
    for (int i = 2; i < n; i++){
        cin>>m;
        maxv = max(maxv, m -minv); // 保存当前利润的最大值
        minv = min(minv, m); // 更新历史价格最小值
    }

    cout<<maxv<<endl;
}


Measured memory_bytes: 3104
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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 long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<int, int> P;
ll ma = 1000000000 + 7;
ll h, w, n,k,m,r,d,x; string s,t;
char maze[60][60];
int dis[101][101]; int graph[52][52]; bool vis[52];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

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

int main() {
	cin >> r >> d >> x;
	int res = 0;
	for (int i = 1; i <= 10; i++) {
		res = r * x - d;
		cout << res << endl;
		x = res;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std; 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  ll n,k;
  cin>>n>>k;
  ll ans=0;
  ll mini[n+2]={0};
  ll maxi[n+2]={0};
  for(ll i=1;i<=n+1;i++)
  {
      mini[i]=mini[i-1]+i-1;
      maxi[i]=maxi[i-1]+n-(i-1);
    //  cout<<maxi[i]<<" "<<mini[i]<<endl;
  }
  ll p=1000000007;
  for(ll i=k;i<=n+1;i++)
  {
      ll z=maxi[i]-mini[i]+1;
      ans=(ans+z)%p;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 6776
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll > ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define sz(x) (ll)(x).size()
#define tr1(x) cerr << #x << ": " << x << endl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define tr4(x,y,z,w) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#w<<": "<<w<<endl
#define trv(a) cerr<<#a<<": ";for(ll zz=0;zz<sz(a);zz++) cerr<<a[zz]<<" ";cerr<<endl
#define trii(x) cerr<<#x<<": ("<<x.F<<","<<x.S<<")\n";
#define trvii(a) cerr<<#a<<": ";for(ll zz=0;zz<sz(a);zz++) cerr<<"("<<a[zz].F<<","<<a[zz].S<<") ";cerr<<nl
#define trset(s) cerr<<#s<<": ";for(auto &i:s) cerr<<i<<" ";cerr<<"\n"
#define trsetii(s) cerr<<#s<<": ";for(auto &i:s) trii(i);
#define epsilon 0.000000001L
#define mod 1000000007ll
#define inf 9999999999999999ll
#define nl endl
#define all(x) x.begin(), x.end()
#define r_all(x) x.rbegin(), x.rend()
#define fast()  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define modulo 998244353ll


int main()
{
    fast();
    string s;
    cin>>s;
    char c=s.back();
    if(c =='2'|| c=='4' || c=='5'|| c=='7'||c=='9' )
    {
        cout<<"hon\n";
    }
    else if(c=='0' || c=='1' || c=='6' || c=='8')
    {
        cout<<"pon\n";
    }
    else
    {
        cout<<"bon\n";
    }
}



Measured memory_bytes: 3644
import collections
n = int(input())
s_list = ["".join(sorted(input())) for _ in range(n)]
s_dict = {}
ans = 0
for s in s_list:
    if s in s_dict:
       ans += s_dict[s]
       s_dict[s] += 1
    else:
        s_dict[s] = 1
print(ans)

Measured memory_bytes: 19760
#include "bits/stdc++.h"

using namespace std;

//#define int long long

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FORR(i, a, b) for (int i = (a); i >= (b); i--)

#define pb push_back
#define VDEL(v, n) v.erase(v.begin() + (n))
#define ALL(v) v.begin(), v.end()

#define INTMAX 2147483647
#define INF 200000000
#define TINT(str) atoi(str.c_str())
#define TSTR(num) to_string(num)

typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<vector<int>> VII;

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

//the end of library



signed main()
{
    int N, A, B, C;
    cin >> N >> A >> B >> C;

    VI D(N);
    REP(i, N)
    {
        cin >> D[i];
    }

    sort(ALL(D));

    int ans = C / A;

    int calsum = 0;

    FORR(i, N - 1, 0)
    {
        calsum += D[i];
        if(ans <= (C + calsum) / (A + B * (N - i)))
        {
            ans = (C + calsum) / (A + B * (N - i));
        }
        else
        {
            break;
        }
    }
    cout << ans << endl;

    int max_ = 0;
    return 0;
}



Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> inline bool chmin(T&x,T y){if(x>y){x=y;return true;}return false;}
template<class T> inline bool chmax(T&x,T y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
 int n,f;
 f = 0;
 cin>>n;
 string s;
 cin>>s;
 char c;
 c = s[0];
 for(int i=1;i<(n);++i){
     if(c == s[i]){
         f += 1;
     }
     c = s[i];
 }
 cout<<n-f;
}

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

int main(void){
    
    int N,L;
    cin >> N >> L;
    
    string S[N];
    
    for(int i = 0; i < N; i ++)cin >> S[i];
    
    sort(S,S+N);
    
    for(int i = 0; i < N; i ++)cout << S[i];
    cout <<endl;
    
    
}


Measured memory_bytes: 256
#include <iostream>

/* ユークリッドの互除法 */
int _euclidean_algorithm(int a, int b)
{
    if (a % b == 0){
        return b;
    }
    return _euclidean_algorithm(b, a % b);
}

/* Greatest common divisor */
int gcd(int a, int b)
{
    return _euclidean_algorithm(a, b);
}

/* Least common multiple */
int lcm(int a, int b)
{
    return (a / gcd(a, b) * b);
}

int main(void)
{
    int a, b;
    
    while (std::cin >> a >> b){
        std::cout << gcd(a, b) << " " << lcm(a, b) << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>

int main(void)
{
	int x[15][20], n, b, f, r, v, a, c;
	for (a = 0; a < 15; a++)
	{
		for (c = 0; c < 20; c++)
		{
			x[a][c] = 0;
		}
	}

	scanf("%d", &n);
	for (a = 0; a < n; a++)
	{
		scanf("%d %d %d %d", &b, &f, &r, &v);
		x[(b - 1) * 4 + f-1][2*r-1] = x[(b - 1) * 4 + f-1][2*r-1] + v;
	}
	for (a = 0; a < 15; a++)
	{
		for (c = 0; c < 20; c++)
		{
			if (a%4==3)
			{			
					printf("#");			
			}
			else if (c % 2 == 0)
			{					
				printf(" ");				
			}
			else if (c % 2 == 1)
			{			
				printf("%d", x[a][c]);
			}
		}
		printf("\n");
	}
	
	return 0;
}


Measured memory_bytes: 2104
#include <stdio.h>
int n, s, count = 0, digits[10]; // n 個の整数の和がsになる
void dfs(int cur, int start) {              // cur = 0   {}
  if(cur == n) {               // cur = 1   {a}
      int sum = 0;             // cur = 2   {a, b}
      for(int i = 0; i < n; i++) { sum += digits[i]; }
      if(sum == s) { count++; }
      return;
  }
  for(int i = start; i < 10; i++) {
      digits[cur] = i; // FIXME: 重複を避ける
      dfs(cur+1, i+1);  
  }
}
int main(void){
    while(scanf("%d %d",&n,&s)!= EOF){
        if(n == 0 && s == 0){
            break;
        }
        count = 0;
        dfs(0, 0);
        printf("%d\n", count);
    }
  return 0;
}


Measured memory_bytes: 2036
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        
        //int x = stdIn.nextInt();
        int num[] = new int[n];
        //String s = stdIn.next();
        //String t = stdIn.next();
        //char c[] = s.toCharArray();
        //int sum = 0;
        //boolean flag = true;
        for(int i = 0; i < n; i++){
            num[i] = stdIn.nextInt();
        }
        
        int q = stdIn.nextInt();
        
        for(int i = 0; i < q; i++){
            int b = stdIn.nextInt();
            int e = stdIn.nextInt();
            int k = stdIn.nextInt();
            
            int count = 0;
            for(int j = b; j < e; j++){
                if(num[j] == k){
                    count++;
                }
            }
            System.out.println(count);
        }
        //System.out.println(sum);

        //System.out.println();
        //System.out.print();

        stdIn.close();
    }
}




Measured memory_bytes: 36720
k = int(input())

lists = [1, 2, 3, 4, 5, 6, 7, 8, 9]
i = 0
while len(lists) <= k:
    num = lists[i]
    lastnum = num % 10
    if lastnum == 0:
        lists.append(num * 10 + 0)
        lists.append(num * 10 + 1)
    elif lastnum == 9:
        lists.append(num * 10 + 8)
        lists.append(num * 10 + 9)
    else:
        lists.append(num * 10 + lastnum-1)
        lists.append(num * 10 + lastnum)
        lists.append(num * 10 + lastnum+1)
    i+=1
#print(lists)    
print(lists[k-1])

Measured memory_bytes: 7156