akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define bit(k) (1LL<<(k))
#define SUM(v) accumulate(all(v), 0LL)

typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
struct fast_ios{ fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; }fast_ios_;

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; }

#define TOSTRING(x) string(#x)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os  << "["; for(auto _: v) os << _ << ", "; os << "]"; return os; };
template <typename T> ostream &operator<<(ostream &os, set<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair< T, U >& p){os << "{" <<p.first << ", " << p.second << "}";return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &mp){ os << "["; for(auto _: mp){ os << _ << ", "; } os << "]" << endl; return os; }

#define DUMPOUT cerr
void dump_func(){ DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); }

#ifdef DEBUG
#define dbg(...) dump_func(__VA_ARGS__)
#define dump(...) DUMPOUT << string(#__VA_ARGS__) << ": "; dump_func(__VA_ARGS__)
#else
#define dbg(...)
#define dump(...)
#endif

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const long double PI = acos(-1.0);

/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/


int main() {
    ll N;
    cin >> N;

    ll ans = 0;
    for(ll a = 1; a <= N; a++){
        if(N%a == 0){
            ans += N / a - 1;
        }
        else ans += N/a;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3648
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
using namespace std;
typedef long long ll;

int main(){
  int a, b, k;
  cin >> a >> b >> k;
  int abg = max(a, b);
  int abm = min(a, b);
  int currentOrder = 0;

  for(int i=abm;i>0;i--) {
    if(a%i == 0 && b%i == 0) {
      currentOrder++;
      if(currentOrder == k) {
        cout << i << endl;
        return 0;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 256
K, S = map(int, input().split())
c = 0
for x in range(K + 1):
    if x > S:
        break
    for y in range(S - x + 1):
        if y > K:
            break
        z = S - x - y
        if 0 <= z <= K:
            c += 1
print(c)

Measured memory_bytes: 8848
#include <iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<sstream>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define all(hoge) hoge.begin(),hoge.end()
const long long INF = 1LL << 60;


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;
}

class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size() - 1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min + (max - min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}

//約数求める //約数
void divisor(ll n, vector<ll> &ret) {
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(ret.begin(), ret.end());

}
//階乗
long long factorial(long long n, long long mod) {
	long long ret = 1;
	for (long long i = 1; i <= n; i++) {
		ret = (ret * i) % mod;
	}
	return ret;
}
//モジュラ逆数
long long inv_mod(long long n, long long mod) {
	long long a = n % mod, b = mod - 2, ret = 1;
	while (b > 0) {
		if (b & 1) ret = (ret * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ret;
}

long long nPr(long long n, long long r, long long mod) {
	long long ret = 1;
	for (long long i = n; i >= n - r + 1; i--) {
		ret = ret * (i % mod) % mod;
	}
	return ret;
}

long long nCr(long long n, long long r, long long mod) {
	return nPr(n, r, mod) * inv_mod(factorial(r, mod), mod) % mod;
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {//降順second
	if (a.second != b.second) {
		return a.second > b.second;
	}
	else {
		return a.first > b.first;
	}
}

bool compare_by_a(pair<ll, ll> a, pair<ll, ll> b) {//降順first
	if (a.first != b.first) {
		return a.first > b.first;
	}
	else {
		return a.second > b.second;
	}
}

ll gcd(ll m, ll n) {
	if (n == 0)return m;
	return gcd(n, m%n);
}//gcd

int p[10];
int main() {
	ll n, k;
	cin >> n >> k;
	vector<int> d(k);
	rep(i, k) {
		cin >> d[i];
		p[d[i]]++;
	}
	while (1) {
		ostringstream oss;
		oss << n;
		string temp = oss.str();
		int flag = 0;
		for (int i = 0; i < temp.size();i++) {
			if (p[temp[i]-'0'] == 1) {
				flag = 1;
				break;
			}
		}
		if (flag == 0) {
			cout << n;
			break;
		}
		n++;
	}
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;
 
int N;
vector<pair<int, int> > v1, v2;
int calc(int k1, int k2){
    if(k1 < 0 || k2 < 0)
      return INT_MAX;
    return ceil(N*1.0/2*1.0) - v1[k1].second + N/2 - v2[k2].second;
}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //freopen("eq_0.txt", "r", stdin);
  cin >> N;
  vector<int> v(N);
  for(int i=0; i<N; ++i) cin >> v[i];
  map<int, int> mp1, mp2;
  for(int i=0; i<N; i+=2){
    ++mp1[v[i]];
  }
  for(int i=1; i<N; i+=2){
    ++mp2[v[i]];
  }
  auto it = mp1.begin();
  while(it != mp1.end()){
    v1.push_back(make_pair(it->first, it->second));
    ++it;
  }
  it = mp2.begin();
  while(it != mp2.end()){
    v2.push_back(make_pair(it->first, it->second));
    ++it;
  }
  sort(all(v1), [&](const pair<int, int> &a, const pair<int, int > &b){
       return a.second > b.second;
      });
  sort(all(v2), [&](const pair<int, int> &a, const pair<int, int> &b){
       return a.second > b.second;
      });
  int k1 = 0, k2 = 0, res = 0, flag = 0;
  if(v1[k1].first == v2[k2].first){
    //fix k1
    //cout << "jkno:::\n";
    flag = 1;
    int p = k2;
    while(k2 < (int)v2.size() && (v1[k1].first == v2[k2].first))  ++k2;
    res = calc(k1, k2);
    while(k1 < (int)v1.size() && (v1[k1].first == v2[p].first)) ++k1;
    res = min(res, calc(k1, p));
  }
  if(k1 >= (int)v1.size()){
    cout << N/2 + N%2 << "\n";
  }
  else if(k2 >= int(v2.size())){
    cout << N/2 << "\n";
  }
  else{
    if(!flag) res = calc(k1, k2);
    cout << res << "\n";
  //  cout << min({calc(k1, k2-1), calc(k1-1, k2), calc(k1, k2)}) << "\n";
  }
 
  return 0;
}


Measured memory_bytes: 6524
#include <iostream>

using namespace std;

int main()
{
    int d;
    int Answer;

    while(cin >> d)
    {
        Answer = 0;
        for(int i = d; i < 600; i+=d)
        {
            Answer = Answer + i*i*d;
        }

        cout << Answer << endl;
    }

}

Measured memory_bytes: 2968
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define xrep(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define vl vector<long long>
#define vs vector<string>

int main() {
    ll a,b; cin >> a >> b;

    ll A = a,B = b;
    rep(i,b-1){
        A *= 10;
        A += a;
    }
    rep(i,a-1){
        B *= 10;
        B += b;
    }

    if(a<b) cout << A << endl;
    else cout << B << endl; 

}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
int main(){
  int N; cin>>N;
  vector<int> a(N);
  rep(i,N){
    int v; cin>>v; v--;
    a[i] = v;
  }
  int c = 0;
  rep(i,N){
    if(c == 1){
      cout<<i<<endl;
      return 0;
    }
    c = a[c];
  }
  cout<<-1<<endl;
  return 0;
}


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

signed main(){

vector<int> a(4);
vector<int> c(4);

for(int i=0;i<4;i++){ 
  cin >> a[i];
}

c[0] = a[0]*a[2];
c[1] = a[0]*a[3];
c[2] = a[1]*a[2];
c[3] = a[1]*a[3];

sort(c.begin(), c.end()); 

cout << c[3];

}

Measured memory_bytes: 3628
//逆ポーランド記法
#include<iostream>
#include<string>
#include<stack>
//atoiがある
#include <cstdlib>



using namespace std;

int main(){
  int n1,n2;
  string s;
  stack<int> p;
  //cout << s.size();
  while(cin >> s){
    //cout << s << endl;
    if(s=="\t"){

    }else if(s=="+"){
      n1=p.top();p.pop();n2=p.top();p.pop();
      p.push(n1+n2);
    }else if(s=="*"){
      n1=p.top();p.pop();n2=p.top();p.pop();
      p.push(n1*n2);
    }else if(s=="-"){
      n1=p.top();p.pop();n2=p.top();p.pop();
      p.push(n2-n1);
    }else{

      /*
      p.push((int)(s[i]));
      */
      p.push(stoi(s));
    }

  }

  /*
  for(size_t i=0;i<s.size();i++){
    if(s[i]=='\t'){
      continue;
    }else if(s[i]=='+'){
      n1=p.top();p.pop();n2=p.top();p.pop();
      p.push(n1+n2);
    }else if(s[i]=='*'){
      n1=p.top();p.pop();n2=p.top();p.pop();
      p.push(n1*n2);
    }else if(s[i]=='-'){
      n1=p.top();p.pop();n2=p.top();p.pop();
      p.push(n1-n2);
    }else{
      cout << (int)(s[i]) << endl;
      p.push((int)(s[i]));
      cout << atoi(s[i]) << endl;
      p.push(atoi(s[i]));
    }
  }
  */
  cout << p.top() << endl;
}



Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long
#define pb push_back 
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()
#define Uniq(v) v.erase(unique(All(v)),v.end())
typedef pair<int, int> Pii; 
typedef pair<int, Pii> Pip;
typedef pair<string, int> Psi;
const int INF = (1<<30);
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

string s;

ll func( ll sum, ll now, ll n )
{
  //cout << sum << " "  << now << " " << n << endl;
  if( n == s.size() ) return sum + now;
  ll ret = 0;
  ret = func(sum+now, s[n]-'0', n+1);
  ret += func(sum, now*10+(s[n]-'0'), n+1);
  
  return ret;
}

int main()
{
  cin >> s;
  ll ans = func(0, s[0]-'0', 1); 
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

using namespace std;

int main(){
	int r,c,sum,total_sum = 0;
	scanf("%d %d",&r,&c);
	int table[r+1][c+1];

	for(int i = 0; i < r+1; i++){
		for(int j = 0; j < c+1; j++){
			table[i][j] = 0;
		}
	}

	for(int i = 0; i < r; i++){
		sum = 0;
		for(int j = 0; j < c; j++){
			scanf("%d",&table[i][j]);
			sum += table[i][j];
			table[r][j] += table[i][j];
		}
		table[i][c] = sum;
		total_sum += sum;
	}
	table[r][c] = total_sum;

	for(int i = 0; i < r+1; i++){
		for(int j = 0; j < c; j++){
			printf("%d ",table[i][j]);
		}
		printf("%d\n",table[i][c]);
	}
}



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

int main(){
  int x;
  std::cin >> x;

  if(1800<=x)std::cout << "1" << '\n';
  else if(1600<=x)std::cout << "2" << '\n';
  else if(1400<=x)std::cout << "3" << '\n';
  else if(1200<=x)std::cout << "4" << '\n';
  else if(1000<=x)std::cout << "5" << '\n';
  else if(800<=x)std::cout << "6" << '\n';
  else if(600<=x)std::cout << "7" << '\n';
  else std::cout << "8" << '\n';

  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
using namespace __gnu_pbds;

typedef tree<pair<long long int,long long int>,null_type,less<pair<long long int,long long int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

void go()
{
    int ans=0;
    int n;
    cin>>n;
    int f[100000]={0};
    for(int i=1;i<100;i++)
    {
        for(int k=1;k<100;k++)
        {
            for(int j=1;j<100;j++)
            {
                f[i*i + j*j + k*k +i*j +i*k +k*j]++;
            }
        }
    }
    for(int z=1;z<=n;z++)
        cout<<f[z]<<endl;
}
int main()
{
    FIO;
//    int t;
//    cin>>t;
//    while(t--)
    go();
    return 0;
}


Measured memory_bytes: 4028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6+5;
const int mod = 1e9+7;
ll qpow(ll a,ll b){ll res=1;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

int a[maxn];
int cnt[maxn],divided[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i = 1;i <= n;++i)scanf("%d",&a[i]),cnt[a[i]]++;
    for(int i = 1;i <= maxn-5;++i){
        if(cnt[i]&&!divided[i]){
            for(int j = i+i;j <= maxn-5;j+=i){
                divided[j]=1;
            }
        }
    }
    int ans = 0;
    for(int i = 1;i <= n;++i){
        if((cnt[a[i]]==1)&&(!divided[a[i]]))ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 12248
#include<cstdio>
#include<cstring>
const int maxn=55;
int n,m,a,b,c,t;
int s[maxn];
struct matrix
{
    int mat[maxn][maxn];
};
matrix operator * (const matrix &A,const matrix &B)
{
    matrix C;
    memset(C.mat,0,sizeof(C.mat));
    for (int k=0;k<n;k++)
        for (int i=0;i<n;i++)
            if (A.mat[i][k])
                for (int j=0;j<n;j++)
                    C.mat[i][j]=(C.mat[i][j]+A.mat[i][k]*B.mat[k][j])%m;
    return C;
}
matrix v_pow(const matrix &A,int nn)
{
    matrix B,C;
    memset(C.mat,0,sizeof(C.mat));
    for (int i=0;i<n;i++) C.mat[i][i]=1;
    B=A;
    while (nn)
    {
        if (nn&1) C=C*B;
        B=B*B;
        nn>>=1;
    }
    return C;
}
int main()
{
    while (~scanf("%d%d%d%d%d%d",&n,&m,&a,&b,&c,&t)&&(n||m||a||b||c||t))
    {
        for (int i=0;i<n;i++) scanf("%d",&s[i]);
        matrix A;
        memset(A.mat,0,sizeof(A.mat));
        for (int i=0;i<n;i++)
        {
            if (i) A.mat[i][i-1]=a;
            A.mat[i][i]=b;
            if (i!=n-1) A.mat[i][i+1]=c;
        }
        A=v_pow(A,t);
        int f=0;
        for (int i=0;i<n;i++)
        {
            int ans=0;
            for (int j=0;j<n;j++) ans=(ans+A.mat[i][j]*s[j])%m;
            if (f) putchar(' ');
            else f=1;
            printf("%d",ans);
        }
        putchar('\n');
    }
    return 0;
}

Measured memory_bytes: 1096
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	//min(a,b)...a,bの小さいほう
	//max(a,b)...     大きいほう
	int a;
	int b;
	//int c;
	//int d;
	int e;
	std::cin >> a;
	std::cin >> b;
	if (a % 500 > b) {
		cout << "No" << "\n";
	}
	else {
		cout << "Yes" << "\n";
	}
	std::cin >> e;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read

#n = int(input)
#h,w = [int(i) for i in readline().split()]
h,w,n = [int(i) for i in read().split()]

a = max(h,w)

print((n+a-1)//a)



Measured memory_bytes: 3316
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define digit(a) to_string(a).size()
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

const long long MOD = 1e9 + 7;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<vector<ll>> a(2, vector<ll>(n));
    rep(i, 0, 2) rep(j, 0, n) cin >> a[i][j];
    vector<vector<ll>> cusum(2, vector<ll>(n + 1, 0));
    rep(i, 0, 2) rep(j, 0, n) cusum[i][j + 1] = cusum[i][j] + a[i][j];
    // rep(i, 0, 2)
    // {
    //     rep(j, 0, n + 1) cout << cusum[i][j] << " ";
    //         cout << endl;
    // }

    ll ans = 0;
    rep(i, 1, n + 1)
    {
        // cout << cusum[0][i] << " " << cusum[1][n] - cusum[1][i - 1] << endl;
        ans = max(ans, cusum[0][i] + cusum[1][n] - cusum[1][i - 1]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int closejudge(char tmp,char *c){
	int flag = 0;
	char wtmp, retmp;
	if(tmp == ')')
		wtmp = ']';
	else
		wtmp = ')';
	*c = getchar();
	while(*c != tmp && flag == 0){
		if(*c == '.' || *c == wtmp)
			flag = 1;
		else if(*c == '(' || *c == '['){
			if(*c == '(')
				retmp = ')';
			else
				retmp = ']';
			flag = closejudge(retmp,c);
		}
		if(*c != '.')
			*c = getchar();
	}
	return flag;
}
int main(void){
	char c,tmp;
	int flag;
	c = getchar();
	while(c != '.'){
		flag = 0;
		while(c != '.' && flag == 0){
			if(c == ')' || c == ']')
				flag = 1;
			if(c == '(' || c == '['){
				if(c == '(')
					tmp = ')';
				else
					tmp = ']';
				flag = closejudge(tmp,&c);
			}
			if(c != '.')
				c = getchar();
		}
		while(c != '\n')
			c = getchar();
		if(flag == 0)
			printf("yes\n");
		else
			printf("no\n");
		c = getchar();
	}
	return 0;
}

Measured memory_bytes: 916
#include<bits/stdc++.h>
#define ll unsigned long long
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl;
#define mod 1000000007
using namespace std;
int n;
int a[22][22],memo[2097155][22];
bitset<21>mask;
ll dp(int i,bitset<21>mask)
{
    if(i==n)
    {
        return 1;
    }
    if(memo[mask.to_ullong()][i]!=-1)
    {
        return memo[mask.to_ullong()][i];
    }
    ll way=0;
    for(int j=0;j<n;++j)
    {
        if(!mask.test(j)&&a[i][j])
        {
            mask.set(j);
            way=(way+dp(i+1,mask))%mod;
            mask.reset(j);
        }
    }
    return memo[mask.to_ullong()][i]=way;
}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;++i)
    {
        for(int j=0;j<n;++j)
        {
            scanf("%d",&a[i][j]);
        }
    }
    memset(memo,-1,sizeof memo);
    printf("%llu",dp(0,mask));
    return 0;
}




Measured memory_bytes: 180480
#include <bits/stdc++.h>
using namespace std;
int xx[90001];
int yy[90001];
int d[90001];
int main()
{
	int i,j,H,W,D,a,x,y,m;
	scanf("%d%d%d",&H,&W,&D);
	for(i=0;i<H;i++)
	{
		for(j=0;j<W;j++)
		{
			scanf("%d",&a);
			xx[a]=i;
			yy[a]=j;
		}
	}
	for(i=D+1;i<=H*W;i++)
		d[i]=d[i-D]+abs(xx[i]-xx[i-D])+abs(yy[i]-yy[i-D]);
	scanf("%d",&m);
	for(i=0;i<m;i++)
	{
		scanf("%d%d",&x,&y);
		printf("%d\n",d[y]-d[x]);
	}
	return 0;
}

Measured memory_bytes: 2176
//	-*- mode: C++ -*-
// Koch Curve
//	Write a program which reads an integer n and draws a Koch curve based on recursive calles of depth n.
//
//	The Koch curve is well known as a kind of fractals.
//
//	You can draw a Koch curve in the following algorithm:
//
//	Divide a given segment (p1, p2) into three equal segments.
//	Replace the middle segment by the two sides of an equilateral triangle (s, u, t) of the same length as the segment.
//	Repeat this procedure recursively for new segments (p1, s), (s, u), (u, t), (t, p2).
//
//	You should start (0, 0), (100, 0) as the first segment.
//
// Input
//	An integer n is given.
//
// Output
//	Print each point (x, y) of the Koch curve. Print a point in a line. You should start the point(0, 0), which is the endpoint of the first segment and end with the point (100, 0), the other endpoint so that you can draw the Koch curve as an unbroken line. Each solution should be given as a decimal with an arbitrary number of fractional digits, and with an absolute error of at most 10-4.
//
// Constraints
//	0 ≤ n ≤ 6
// Sample Input 1
//	1
// Sample Output 1
//	0.00000000 0.00000000
//	33.33333333 0.00000000
//	50.00000000 28.86751346
//	66.66666667 0.00000000
//	100.00000000 0.00000000
// Sample Input 2
//	2
// Sample Output 2
//	0.00000000 0.00000000
//	11.11111111 0.00000000
//	16.66666667 9.62250449
//	22.22222222 0.00000000
//	33.33333333 0.00000000
//	38.88888889 9.62250449
//	33.33333333 19.24500897
//	44.44444444 19.24500897
//	50.00000000 28.86751346
//	55.55555556 19.24500897
//	66.66666667 19.24500897
//	61.11111111 9.62250449
//	66.66666667 0.00000000
//	77.77777778 0.00000000
//	83.33333333 9.62250449
//	88.88888889 0.00000000
//	100.00000000 0.00000000

#include <iostream>
#include <cmath>

struct Point{
	double	X;
	double	Y;

	void	print(void);
};

void	Point::print(void)
{
	std::cout << X << " " << Y << std::endl;
}

void	koch(unsigned int	n,
			 Point			P1,
			 Point			P2)
{
	if(n == 0){
		return;
	}

	// P1, P2からs, t, uを計算
	Point	s;
	Point	t;
	Point	u;

	s.X	= (2 * P1.X + P2.X) / 3;
	s.Y	= (2 * P1.Y + P2.Y) / 3;
	t.X	= (P1.X + 2 * P2.X) / 3;
	t.Y	= (P1.Y + 2 * P2.Y) / 3;

	u.X	= (t.X - s.X) * std::cos(M_PI / 3) - (t.Y - s.Y) * std::sin(M_PI / 3) + s.X;
	u.Y = (t.X - s.X) * std::sin(M_PI / 3) + (t.Y - s.Y) * std::cos(M_PI / 3) + s.Y;

	koch(n - 1, P1, s);
	s.print();

	koch(n - 1, s, u);
	u.print();

	koch(n - 1, u, t);
	t.print();

	koch(n - 1, t, P2);
}

int	main(int	argc,
		 char*	argv[])
{
	Point	P1	= {0.0, 0.0};
	Point	P2	= {100.0, 0.0};

	unsigned int	n	{0};

	std::cin >> n;

	std::cout.setf(std::ios::fixed);
	std::cout.precision(10);
	P1.print();
	koch(n, P1, P2);
	P2.print();

	return 0;
}



Measured memory_bytes: 3288
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
typedef pair<int,int> P;
typedef vector<int> vi;

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; }

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

int k(int n){
    if(n%10==0) return n;
    else{
        int x=n/10;
        return 10*(x+1);
    }
}

int main(){
    ios::sync_with_stdio(false);
    int n[5];
    vector<int> am;
    rep(i,5){
        cin >> n[i];
        if(n[i]%10!=0){
            am.push_back(n[i]%10);
        }
    }
    int x=10;
    rep(i,am.size()){
        x=min(x,am[i]);
    }
    int a=n[0];
    int b=n[1];
    int c=n[2];
    int d=n[3];
    int e=n[4];
    if(x==a%10){
        cout << a+k(b)+k(c)+k(d)+k(e) << endl;
    } else if(x==b%10){
        cout << k(a)+b+k(c)+k(d)+k(e) << endl;
    } else if(x==c%10){
        cout << k(a)+k(b)+c+k(d)+k(e) << endl;
    } else if(x==d%10){
        cout << k(a)+k(b)+k(c)+d+k(e) << endl;
    } else{
        cout << k(a)+k(b)+k(c)+k(d)+e << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include "stdio.h"
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;

class Puzzle
{
public:
	vector<int> S;
	vector<int> T;

	void input()
	{
		int N, Q;
		int buf;

		cin >> N;
		for (int ni = 0; ni < N; ni++) {
			cin >> buf;
			S.push_back(buf);
		}
		cin >> Q;
		for (int ni = 0; ni < Q; ni++) {
			cin >> buf;
			T.push_back(buf);
		}

		sort(S.begin(), S.end());
		sort(T.begin(), T.end());

	}

	void play()
	{
		int cnt = 0;
		for (int ti = 0; ti < T.size(); ti++) {
			for (int si = 0; si < S.size(); si++) {
				if (S[si] == T[ti]) {
					cnt++;
					break;
				}
				if (S[si] > T[ti]) break;
			}
		}

		printf("%d\n", cnt);
	}
};


int main()
{
	Puzzle puz;

	puz.input();
	puz.play();

    return 0;
}




Measured memory_bytes: 3660
function Main(input) {
	var list = input.split("\n")[1].split(" ").map((list)=>Number(list));
  var end = parseInt(input.split("\n")[0].split(" ")[1]);
  var output = 1;
  var position = 0;
  for(var i = 1; i <= list.length; i++){
    position += list[i - 1];
    if(position > end){
       console.log(output);
      return;
    }
    output++;
  }
  console.log(output);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
n, m, q = map(int, input().split())
ABCD = [list(map(int, input().split())) for _ in range(q)]
ans = 0
for i1 in range(1, m+1):
    for i2 in range(i1, m+1):
        for i3 in range(i2, m+1):
            for i4 in range(i3, m+1):
                for i5 in range(i4, m+1):
                    for i6 in range(i5, m+1):
                        for i7 in range(i6, m+1):
                            for i8 in range(i7, m+1):
                                for i9 in range(i8, m+1):
                                    for i10 in range(i9, m+1):
                                        temp = 0
                                        A = [i1, i2, i3, i4, i5, i6, i7, i8, i9, i10]
                                        for a, b, c, d in ABCD:
                                            if A[b-1] - A[a-1] == c:
                                                temp += d
                                        ans = max(ans, temp)
print(ans)

Measured memory_bytes: 9196
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#define pai 3.1415926535

int main(void) {
	
	int N;
	scanf("%d", &N);
	int a[100000];
	for (int i = 0; i < N; i++) {
		scanf("%d", &a[i]);
	}

	int va;
	int count = 0;
	for (int i = 0; i < N; i++) {
		va = a[i];
		if (i + 1 == a[va-1]) {
			count++;
		}
	}

	printf("%d\n", count / 2);

	return 0;
}

Measured memory_bytes: 512
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x[ohara], y[ohara], z[ohara], sum, k,
    q;

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

  cin >> n >> m;
  rep(i, n) cin >> x[i] >> y[i] >> z[i];

  for (int bit = 0; bit < (1 << 3); bit++) {
    int dat[10] = {};
    rep(i, 3) {
      if (bit & (1 << i)) {
        dat[i] = 1;
      }
    }
    // 1で性
    P p[n + 10] = {};
    rep(i, n) {
      cnt = 0;
      if (dat[0]) {
        cnt += x[i];
      } else {
        cnt -= x[i];
      }
      if (dat[1]) {
        cnt += y[i];
      } else {
        cnt -= y[i];
      }
      if (dat[2]) {
        cnt += z[i];
      } else {
        cnt -= z[i];
      }
      p[i] = m_p(cnt, i);
    }
    sort(p, p + n);
    reverse(p, p + n);
    ll s_x = 0, s_y = 0, s_z = 0;
    rep(i, m) {
      s_x += x[p[i].se];
      s_y += y[p[i].se];
      s_z += z[p[i].se];
    }
    ans = max(ans, abs(s_x) + abs(s_y) + abs(s_z));
  }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 4352
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

int comp(const void *a, const void *b){return (*(int*)a>*(int*)b)-(*(int*)a<*(int*)b);}
int compr(const void *a, const void *b){return (*(int*)a<*(int*)b)-(*(int*)a>*(int*)b);}

uint32_t nextpint(void){ char c=getc_unlocked(stdin); while(c<'0'||'9'<c) c=getc_unlocked(stdin); uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getc_unlocked(stdin); } return x; }
uint64_t nextplong(void){ char c=getc_unlocked(stdin); while(c<'0'||'9'<c) c=getc_unlocked(stdin); uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getc_unlocked(stdin); } return x; }
uint32_t nextstr(char *s){ char c=getc_unlocked(stdin); while(c==' '||c=='\n') c=getc_unlocked(stdin); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getc_unlocked(stdin); } *s='\0'; return len; }

inline int max2(const int a, const int b){return a>b?a:b;}
inline int min2(const int a, const int b){return a>b?b:a;}
inline int dif2(const int a, const int b){return a>b?a-b:b-a;}
inline int abs2(const int a){return a>=0?a:-a;}

int a[100];
int main(void){
	int n=nextpint();
	int m=nextpint();
	int sum=0;
	for(int i=0; i<n; i++){
		sum+=a[i]=nextpint();
	}
	int ans=0;
	for(int i=0; i<n; i++){
		if(a[i]*m*4>=sum) ans++;
	}
	puts(ans>=m?"Yes":"No");
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
 
int main(){
	long long int N,L;
	cin >> N >> L;
	long long int a[N];
    for(int i=0;i<N;i++){
      cin >> a[i];
    }
    long long int c = N*(N-1)*(N-2) / 6;
    long double x = 0;
    long double y = 0;
    long double pi = 3.14159265358979323846264338327950288;
    for(int j=0;j<N-1;j++){
          for(int k=j+1;k<N;k++){
      x = x + (N - 2 * (k - j)) * cos(pi * (a[j] + a[k]) / L) / c;
      y = y + (N - 2 * (k - j)) * sin(pi * (a[j] + a[k]) / L) / c;
          }
    }

  	cout.precision(20);
	cout << x << " " << y <<endl;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstdlib>

using namespace std;

const int MAXN = 100000 + 10;

int n;
int p[MAXN];

void Work()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i ++)
	{
		scanf("%d", &p[i]);
		p[i] --;
	}
	int cnt = 0;
	for (int i = 0; i < n; i ++)
		if (p[i] == i)
		{
			cnt ++;
			if (i + 1 < n && p[i + 1] == i + 1)
				i ++;
		}
	printf("%d\n", cnt);
}

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


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

int main()
{
   int a,b,c;
   cin>>a>>b>>c;
   int p=(a+b+c)/2;
   cout<<sqrt(p*(p-a)*(p-b)*(p-c));
   return 0;
   
   
}

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

int main() {
    string S;
    cin >> S;
    reverse(S.begin(),S.end());
    S = S + string(1e+6+10,'0');
    
    vector<vector<int64_t>> dp(2,vector<int64_t>(1e+6+10,0));
    dp[0][0] = 0;
    dp[1][0] = 1 << 30;
    
    for ( int64_t i = 0; i < 1e+6+10; ++i){
        dp[0][i+1] = min( dp[0][i] + (S[i]-'0'), dp[1][i] + (S[i]-'0'+1) );
        dp[1][i+1] = min( dp[0][i] + 10 - (S[i]-'0'), dp[1][i] + 10 - (S[i]-'0'+1));
    }
    
    cout << dp[0][1e+6+5] << endl;
    
    return 0;
}


Measured memory_bytes: 28728
#include <stdio.h>

#define MAX 2000

int m_search(int,int);

int n, array[MAX];

int main(){

  int i, j, q, ans;
  int m_array[MAX];

  scanf("%d", &n);

  for( i=0; i<n; i++){
    scanf("%d", &array[i]);
  }

  scanf("%d", &q);

  for( i=0; i<q; i++){
    scanf("%d", &m_array[i]);
  }

  for( i=0; i<q; i++){
    ans = m_search(0,m_array[i]);

    if( ans == 0 )printf("yes\n");
    else printf("no\n");

  }

  return 0;
}

int m_search(int i, int m){
  int res;

  if( m == 0 ) return 0;

  if( i >= n ) return 1;

  res = m_search(i+1,m);
  if( res == 0 ) return res;

  res = m_search(i+1,m-array[i]);

  return res;
}

Measured memory_bytes: 592
using System;
class Program {
  static void Main(string[] args) {
    int n = int.Parse(Console.ReadLine());
    string[] input = Console.ReadLine().Split(' ');
    int[] x = new int[n];
    for (int i=0; i<n; i++) x[i] = int.Parse(input[i]);
    Array.Sort(x);
    int min = -1;
    for (int i=x[0]; i<=x[n-1]; i++) {
      int sum = 0;
      for (int j=0; j<n; j++) sum += (x[j]-i)*(x[j]-i);
      if (min == -1 || sum < min) min = sum;
    }
    Console.WriteLine(min);
  }
}

Measured memory_bytes: 13140
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<double, double> pdd;

ll slow(ll xa, ll ya, ll xb, ll yb, ll xc, ll yc) {
  ll ans = xa*yb+xb*yc+xc*ya-xa*yc-xb*ya-xc*yb;
  return abs(ans);
}

void solve() {
  ll a;
  cin >> a;
  if(a == 1000000000000000000) {
    cout << "0 0 1000000000 0 1000000000 1000000000\n";
    return;
  }
  ll k = a / 1000000000;
  ll xb = k;
  ll xc = (k+1);
  ll ya = a - k * 1000000000;

  ll check = slow(0, ya, xb, 0, xc, 1000000000);
  cerr << check << endl;

  cout << 0 << " " << ya << " " << xb << " " << 0 << " " << xc << " " << 1000000000 << "\n";
}

void casesolve() {
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << " ";
    solve();
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  // casesolve();
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  ll A[N], B[N];
  for(int i=0;i<N;++i) cin>>A[i];
  for(int i=0;i<N;++i) cin>>B[i];
  vector<int> arr(N);
  for(int i=0;i<N;++i) {
    arr[i] = A[i]-B[i];
  }
  sort(arr.begin(), arr.end());
  int ans = 0;
  ll sum = 0;
  for(int i=0;i<N;++i) {
    if(arr[i]<0) {
      ans++;
      sum += arr[i];
    }
  }
  for(int i=N-1;i>=0;--i) {
    if(sum>=0) break;
    if(arr[i]<=0) break;
    ans++;
    sum += arr[i];
  }
  if(sum>=0) cout<<ans<<endl;
  else cout<<-1<<endl;
}


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

#define int long long
#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define reps(i, n) for (int (i) = 1; (i) <= (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define bit(n) (1LL << (n))
typedef vector<int> vint;
typedef pair<int, int> pint;
constexpr double pi = 3.1415926535897932384626433832795028;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<typename T, typename U> inline bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> inline bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
struct SetUp {
    SetUp() {
        cout << fixed << setprecision(20);
        cerr << fixed << setprecision(20);
    };
} setUp;

string S;
signed main() {
    cin >> S;
    if (S == "Sunny") { cout << "Cloudy" << endl; }
    if (S == "Cloudy") { cout << "Rainy" << endl; }
    if (S == "Rainy") { cout << "Sunny" << endl; }
}

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

int main()
{
    int n;
    cin >> n;
    n--;
    ll ans = (ll)(n + 1) * n / 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    int A, B;
    string S;
    cin >> A >> B >> S;
    int l_cnt = 0, r_cnt = 0;
    
    bool flag = true;
    for(int i = 0; i < S.length(); i++){
        if(flag && S[i] != '-'){
            l_cnt++;
        }
        else if(flag && S[i] == '-'){
            flag = false;
        }
        else if(!flag && S[i] != '-'){
            r_cnt++;
        }
    }
    
    if(l_cnt == A && r_cnt == B){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ff        first
#define ss        second
#define ll        long long
#define int       long long
#define inf       ((ll)1e18)
#define mod       1000000007
#define double    long double
#define ull       unsigned long long
#define vi        vector<ll>
#define ppi       pair<int,int>
#define pii       pair<pair<int,int>,int>
#define pb        push_back
#define pi        2*acos(0.0)
#define rev       greater<int>()
#define pr(a,x,y) for(int i=x;i<y;i++){cout<<a[i]<<" ";}
#define ps(s)     for(auto i:s){cout<<i<<" ";}
#define sp(x,y)   fixed<<setprecision(y)<<x
#define w(x)      ll x; cin>>x; while(x--)
#define all(v)    v.begin(), v.end()
#define rall(v)   v.rbegin(), v.rend()
#define test      cout<<"This is test"<<endl;
#define str       string
#define endl      '\n'
#define e         cout<<'\n';
void kehsihba(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif*/
}
void solve(){
	ll n,m,k;cin>>n>>m>>k;
	ll a[n];
	int ans=0;
	for(int i=0;i<n;i++){cin>>a[i];if(i!=0){a[i]+=a[i-1];}if(a[i]<=k){ans=max(ans,i+1);}}
	int s=0,x;
	for(int i=0;i<m;i++){
		cin>>x;
		if(s<=k){ans=max(ans,i);}
		s+=x;
		if(s<=k){
			ll c=i+1+(upper_bound(a,a+n,k-s)-a);
			ans=max(ans,c);
		}
	}
	cout<<ans<<endl;
}
int32_t main(){
	kehsihba();
	//init();
	ll t=1;
	//cin>>t;
	for(int k=1;k<=t;k++){
		//cout<<"Case "<<k<<": ";
		solve();
		//e;
	}
}


Measured memory_bytes: 5160
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;

int main(){
    ll n,m; cin >> n >> m;
    bool flag [n];
    rep(i,n) flag[i] = 0;
    vector<pair<int,string>> a(m);
    rep(i,m) cin >> a[i].first >> a[i].second;
    int AC = 0;
    int WA = 0;
    int count_WA [n];
    rep(i,n) count_WA[i] = 0;

    rep(i,m){
        if(a[i].second == "WA" && !flag[a[i].first - 1]){
            count_WA[a[i].first - 1]++;
        }
        if(a[i].second == "AC" && !flag[a[i].first - 1]){
            AC++;
            flag[a[i].first - 1] = 1;
        }
    }
    rep(i,n) if(flag[i]) WA += count_WA[i];
    cout << AC << " " << WA << endl;
}

Measured memory_bytes: 7040
#include <iostream>

using namespace std;
string s;
int main()
{
    cin>>s;
    for (int i=0;i<s.length();i++)
    {
        if (s[i]=='7')
        {
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
    return 0;
}


Measured memory_bytes: 3636
import sys
sys.setrecursionlimit(10**9)
class UnionFind:
  def __init__(self, n):
    self.n = [-1]*n
    self.r = [0]*n
    self.siz = n

  def find_root(self, x):
    if self.n[x] < 0:
      return x
    else:
      self.n[x] = self.find_root(self.n[x])
      return self.n[x]

  def unite(self, x, y):
    x = self.find_root(x)
    y = self.find_root(y)
    if x == y:
      return
    elif self.r[x] > self.r[y]:
      self.n[x] += self.n[y]
      self.n[y] = x
    else:
      self.n[y] += self.n[x]
      self.n[x] = y
      if self.r[x] == self.r[y]:
        self.r[y] += 1
    self.siz -= 1

  def root_same(self, x, y):
    return self.find_root(x) == self.find_root(y)

  def count(self, x):
    return -self.n[self.find_root(x)]

  def size(self):
    return self.siz

n,m=map(int,input().split())
edges=[list(map(int,input().split()))for _ in range(m)]
ans=0
for i in range(m):
  u=UnionFind(n)
  for j in range(m):
    if j==i:continue
    a,b=edges[j]
    a-=1
    b-=1
    u.unite(a,b)
  if u.size()!=1:ans+=1
print(ans)
  

Measured memory_bytes: 9232
#define _USE_MATH_DEFINES

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

using namespace std;

int main() {

	vector<int> A(3);
	cin >> A[0] >> A[1] >> A[2];

	sort(A.begin(), A.end());

	cout << A[0] + A[1] << endl;

	return 0;

}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define int long long
using namespace std;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	string str;
	cin>>str;
	bool fl = true;
	for(int i=0;i<str.size();i++)
	{
		if((i+1)%2)
		{
			if(!(str[i] == 'R' || str[i] == 'U' || str[i] == 'D'))
				fl = false;
		}
		else if(!(str[i] == 'L' || str[i] == 'U' || str[i] == 'D'))
			fl = false;

	}
	if(fl) cout<<"Yes";
	else cout<<"No";

}

Measured memory_bytes: 256
mod = 1000000007
N = int(input())

dp = [ [[[0 for c3 in range(4)]  for c2 in range(4)]  for c1 in range(4)] for n in range(N+1)]

# 全部TのときはOK
dp[0][3][3][3] = 1

# 文字の数
for n in range(N):
  # 後ろから1文字目
  for c1 in range(4):
    # 後ろから2文字目
    for c2 in range(4):
      # 後ろから3文字目
      for c3 in range(4):
        # 該当するものがないとき
        if dp[n][c1][c2][c3] == 0: continue

        # 新しく追加する文字
        for a in range(4):
          # AGCに当てはまる文字
          if(c2 == 0 and c1 == 1 and a == 2): continue
          if(c2 == 0 and c1 == 2 and a == 1): continue
          if(c2 == 1 and c1 == 0 and a == 2): continue
          if(c3 == 0 and c1 == 1 and a == 2): continue
          if(c3 == 0 and c2 == 1 and a == 2): continue

          dp[n+1][a][c1][c2] += dp[n][c1][c2][c3]
          dp[n+1][a][c1][c2] %= mod

ans = 0
# 後ろから1文字目
for c1 in range(4):
  # 後ろから2文字目
  for c2 in range(4):
    # 後ろから3文字目
    for c3 in range(4):
      ans += dp[N][c1][c2][c3]
      ans %= mod

print(ans)

Measured memory_bytes: 3316
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

L=LI()
print(L.index(0)+1)


Measured memory_bytes: 9240
#include<stdio.h>

int n,m,K;
int a[35][35],ma[35][35],c[35][35];

int max(int a, int b)
{
    if(a<b)return b;
    return a;
}
void f(int x, int y)
{
    int i;
    for(i=x;i>=1;i--){
        a[i][y]=a[i-1][y];
    }
}
int g(int x, int y)
{
    int X=1,i,j,res=0,C,s,k;
    for(i=1;i<=n;i++){
        a[i][0]=-1;
        for(j=1;j<=m;j++)a[i][j]=ma[i][j],c[i][j]=0;
    }
    f(x,y);
    while(1){
        C=0;
        for(i=1;i<=n;i++){
            s=0;
            for(j=1;j<=m+1;j++){
                if((a[i][j]!=a[i][s])){
                    if(s<=j-K&&a[i][s]){
                        for(k=s;k<j;k++)c[i][k]=1;
                        C=1;
                    }
                    s=j;
                }
            }
        }
        for(i=1;i<=n;i++){
            for(j=1;j<=m;j++){
                if(c[i][j])res+=X*a[i][j],f(i,j);
                c[i][j]=0;
            }
        }
        if(C==0)break;
        X*=2;
    }
    return res;
}

int main()
{
    int i,j,res=0;
    scanf("%d %d %d", &n, &m, &K);
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            scanf(" %c", &a[i][j]);
            a[i][j]-='0';
            ma[i][j]=a[i][j];
        }
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            res=max(res,g(i,j));
        }
    }
    printf("%d\n", res);
    return 0;
}


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


namespace StartFinish
{
    class Program
    {   
        static void Main(string[] args)
        {
            int.Parse(Console.ReadLine());
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Sort(array);
        }

        static void Sort(int[] array)
        {
            for(int i = 0; i < array.Length-1; i++)
            {
                Console.Write("{0} ",array[i]);
            }
            Console.WriteLine("{0}", array[array.Length-1]);

            for(int i =1; i < array.Length; i++)
            {
                int tmp = array[i];
                int j = i-1;

                while (j >= 0 && array[j]>tmp)
                {
                    Swap(ref array[j], ref array[j + 1]);
                    j--;
                }
                array[j+1] = tmp;
                for(int k = 0; k < array.Length-1; k++)
                {
                    Console.Write("{0} ", array[k]);
                }
                Console.WriteLine(array[array.Length-1]);
            }
        }

        static void Swap(ref int a,ref int b)
        {
            int tmp = a;
            a = b;
            b = tmp;
        }

    }
}

Measured memory_bytes: 9792