akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>
#include <sys/time.h>
#include <fstream>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define REP(i,n)  FOR(i,0,n)
#define each(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define deb(x) cerr << #x << " = " << (x) << " , ";
#define debl cerr << " (L" << __LINE__ << ")"<< endl;
#define sz(s) (int)((s).size())


#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(x,y) make_pair((x),(y))

double pi=3.14159265358979323846;

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template<typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& z){
	os << "[ ";
	REP(i,z.size())os << z[i] << ", " ;
	return ( os << "]" << endl);
}

template<typename T> std::ostream& operator<<(std::ostream& os, const set<T>& z){
	os << "set( ";
	EACH(p,z)os << (*p) << ", " ;
	return ( os << ")" << endl);
}

template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const map<T,U>& z){
	os << "{ ";
	EACH(p,z)os << (p->first) << ": " << (p->second) << ", " ;
	return ( os << "}" << endl);
}

template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const pair<T,U>& z){
	return ( os << "(" << z.first << ", " << z.second << ",)" );
}

double get_time(){
	struct timeval tv;
	gettimeofday(&tv, NULL);
	return tv.tv_sec + tv.tv_usec*1e-6;
}

typedef unsigned int uint32_t;
struct RND{
	uint32_t x;
	uint32_t y;
	uint32_t z;
	uint32_t w;
	RND(){
		x=123456789;
		y=362436069;
		z=521288629;
		w=88675123;
	}
	void init(int seed){
		x=123456789;
		y=362436069;
		z=521288629;
		w=seed+100;
		REP(i,10)get();
	}
	uint32_t get(){
		uint32_t t;
		t=x^(x<<11);
		x=y;y=z;z=w;
		w=(w^(w>>19))^(t^(t>>8));
		return w;
	}
};
RND rnd;

void _main(istream &inp){
	ll N, L;
	inp >> N >>L;
	vl a(N);
	rep(i,N) inp >> a[i];
	rep(i,N-1){
		if(a[i]+a[i+1]>=L){
			cout << "Possible" << endl;
			rep(k,i) cout << k+1 << endl;
			for(int k=N-2; k>=i+1; k--){
				cout << k+1<<endl;
			}
			cout << i+1 <<endl;
			return;
		}
	}
	cout << "Impossible" << endl;
	return;

}

int main(){
	if(0){
		ifstream ifs("test.txt");
		_main(ifs);
	}
	else{
		_main(cin);
	}
	return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f|=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int N=200005;
int n,a[N];
map <int,int> Map;
int main(){
	n=read();
	for (int i=1;i<=n;i++)
		a[i]=read();
	sort(a+1,a+n+1);
	Map.clear();
	for (int i=1;i<=n;i++)
		Map[a[i]]++;
	int ans=0;
	for (int i=n;i>=1;i--){
		if (Map[a[i]]>0){
			for (int t=1;t<=30;t++){
				if (Map[(1<<t)-a[i]]>0){
					if ((1<<t)-a[i]==a[i]&&Map[a[i]]<2)
						continue;
					Map[a[i]]--;
					Map[(1<<t)-a[i]]--;
					ans++;
					break;
				}
			}
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 290816
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int a,b; cin>>a>>b;
    if(a==0){
        if(b==100){
            cout<<101<<endl;
        }
        else cout<<b<<endl;
    }
    else if(a==1){
        if(b==100) cout<<10100<<endl;
        else cout<<b*100<<endl;
    }
    else{
        if(b==100) cout<<1010000<<endl;
        else cout<<10000*b<<endl;
    }
}

Measured memory_bytes: 256
from collections import deque
import sys

def input():
    return sys.stdin.readline().strip()

def main():
    H,W = map(int,input().split())
    Ch,Cw = map(int,input().split())
    Dh,Dw = map(int,input().split())
    S = [list(input()) for _ in range(H)]
    S[Ch-1][Cw-1] = 0

    def bfs(x,y):
        que = deque()
        que.append((x,y))

        while que:
            x,y = que.popleft()
            for dx,dy in ((-1,0),(1,0),(0,-1),(0,1)):
                sx = x + dx
                sy = y + dy
                if sx < 0 or sx >= W or sy < 0 or sy >= H:
                    continue
                if S[sy][sx] == '#':
                    continue
                if S[sy][sx] == '.':
                    S[sy][sx] = S[y][x]
                    que.appendleft((sx,sy))        
                else:
                    if S[sy][sx] > S[y][x]:
                        S[sy][sx] = S[y][x]
                        que.appendleft((sx,sy)) 
            for dx in range(-2,3):
                for dy in range(-2,3):
                    if (dx,dy) in ((-1,0),(1,0),(0,-1),(0,1),(0,0)):
                        continue
                    sx = x + dx
                    sy = y + dy
                    if sx < 0 or sx >= W or sy < 0 or sy >= H:
                        continue
                    if S[sy][sx] == '#':
                        continue
                    if S[sy][sx] == '.':
                        S[sy][sx] = S[y][x] + 1
                        que.append((sx,sy))
                    else:
                        if S[sy][sx] > S[y][x] + 1:
                            S[sy][sx] = S[y][x] + 1
                            que.append((sx,sy))     
    bfs(Cw-1,Ch-1)
    print(S[Dh-1][Dw-1] if S[Dh-1][Dw-1] != '.' else '-1')

if __name__ == "__main__":
    main()


Measured memory_bytes: 166416
n = int(input())
A = list(map(int,input().split()))
s = [0]

for i in A:
    s.append(i+s[-1])

M = 10000000000

for i in range(1,len(s)-1):
    dif = abs((s[-1]-s[i]) - s[i])
    M = min(M,dif)

print(M)

Measured memory_bytes: 26396
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int x = Integer.parseInt(sc.next());
        sc.close();

        double d = 0.0;
        if (a*a*b/2 > x) {
            d = 90.0-(Math.atan((double)x*2/b/a/b))*180/Math.PI;
        } else if (a*a*b/2 == x) {
            d = (Math.atan((double)a/b))*180/Math.PI;
        } else {
            d = (Math.atan((((double)a*a*b-x)/a/a/a*2)))*180/Math.PI;
        }
        System.out.println(d);
    }
}

Measured memory_bytes: 21972
/*
    In the name of
        "ALLAH"
    And say "AL-HAMD-U-LILLAH"
*/

#include<bits/stdc++.h>
#define   ll   long long
#define   llu  unsigned long long
#define   _    printf("\n")
int      take() {
    int n;
    scanf("%d",&n);
    return n;

}
double  ttake() {
    double n;
    scanf("%lf",&n);
    return n;
}
ll     takes() {
    ll n;
    scanf("%lld",&n);
    return n;

}

#define  Int            take()
#define  Dnt            ttake()
#define  LL             takes()
#define  done           {return 0;}
#define  fr(i,x,n,a)    for(int i=x;i<=n;i+=a)
#define  FR(a,b,x)      for(int i=(a);i<=(b);i+=(x))
#define  rfr(i,x,n,a)   for(int i=x;i>=n;i--)
int      cas;
#define  print          printf("Case %d:",++cas)
#define  vi             vector<int>
#define  vl              vector<ll>
#define  pb              push_back
#define  pii             pair<int,int>
#define  vii             vector<pii>
#define  pll             pair<ll,ll>
#define  pil             pair<int,ll>
#define  pli             pair<ll,int>
#define  mk              make_pair
#define  fill(x,v)       memset(x,v,sizeof x)

using    namespace      std;

bool     approximatelyEqual(float a, float b, float epsilon) {
    return fabs(a - b) <= ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool     essentiallyEqual(float a, float b, float epsilon) {
    return fabs(a - b) <= ( (fabs(a) > fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool     definitelyGreaterThan(float a, float b, float epsilon) {
    return (a - b) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool     definitelyLessThan(float a, float b, float epsilon) {
    return (b - a) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}
#define  STR            {struct info}
#define  dbg(x)         {cout<<"ekhane"<<x<<endl;}
#define  SS             second
#define  FF             first
#define  PQ             priority_queue
#define  great          greatest
#define  less           lesser
#define  mii            map<int,int>
#define  mil            map<int,ll>
#define  mll            map<ll,ll>
#define  msb            map<string,bool>
#define  V              vector
#define  M              100005
#define  pf             printf
#define  inf            INT_MAX
//////////////////////////////////////////

int main( ){
    int tc = 1 ;
    while( tc-- ){
        int a = Int , b = Int ;
        if( a < b ) swap( a , b ) ;
        bool nw[ 17 ] = { 0 } ;
        fr( i , 1 , 16 , 2 ){
            if( a )
            nw[ i ] = 1 ;
            else break ;
            a-- ;
        }
        fr( i ,2 , 16 , 2 ){
            if( b )
            nw[ i ] = 1 ;
            else break ;
            b-- ;
        }
        if( a || b ){
            pf(":(") ;
        }else{
            pf("Yay!") ;
        }
    }
    done ;
}



Measured memory_bytes: 256
n,q=gets.split.map(&:to_i)
arr=[]
n.times do |i|
  name,time=gets.split
  arr<<[name,time.to_i]
end
total=0
while !arr.empty?
  p,t=arr.shift
  if t<=q
    total+=t
    puts "#{p} #{total}"
  else
    t-=q
    total+=q
    arr<<[p,t]
  end
end

Measured memory_bytes: 13284
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B: Varied
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

int used[26];

/* subroutines */

/* main */

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

  bool ok = true;
  for (int i = 0; ok && i < s.size(); i++)
    ok = (++used[s[i] - 'a'] <= 1);

  if (ok) puts("yes");
  else puts("no");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
int n;
string s[110];
int main() {

	read(n);
	for (int i=1;i<=n;i++) cin>>s[i];
	for (int i=1;i<n;i++) if (s[i][(int)s[i].size()-1]!=s[i+1][0]) { printf("No\n"); return 0; }
	sort(s+1,s+n+1);
	for (int i=1;i<n;i++) if (s[i]==s[i+1]) { printf("No\n"); return 0; }
	printf("Yes\n");
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 3632
import re
str = input()
k1 = re.compile(".*keyence$")
k2 = re.compile("^k.*eyence$")
k3 = re.compile("^ke.*yence$")
k4 = re.compile("^key.*ence$")
k5 = re.compile("^keye.*nce$")
k6 = re.compile("^keyen.*ce$")
k7 = re.compile("^keyenc.*e$")
k8 = re.compile("^keyence.*")

if (re.match(k1, str) is not None) or (re.match(k2, str) is not None) or (re.match(k3, str) is not None) or (re.match(k4, str) is not None) or (re.match(k5, str) is not None) or (re.match(k6, str) is not None) or (re.match(k7, str) is not None) or (re.match(k8, str) is not None):
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main()
{
	int n,sum=0,d,e,f;
	vector<int> v1;
	vector<int>::iterator it;
	cin>>n;
	int a[n],b[n],c[n];
	for(int i=0;i<n;i++)
    cin>>a[i];
    for(int i=0;i<n;i++)
    cin>>b[i];
    for(int i=0;i<n-1;i++)
    cin>>c[i];
    for(int i=0;i<n;i++)
    {
    	d=a[i];
    	--d;
    	sum=0;
    	if(a[i+1]==++a[i])
    	{
    		sum=b[d]+c[d];
    		v1.push_back(sum);
		}
		else
		{sum=b[d];
		v1.push_back(sum); }    	
	}
	sum=0;
	for(it=v1.begin();it!=v1.end();it++)
	sum+=*it;
	cout<<sum;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) fixed << setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string S;
  string T;
  cin >> S >> T;
  ll ans = llINF;
  REP(i, S.size() - T.size() + 1) {
    ll score = 0;
    REP(j, T.size()) {
      if (S[i + j] != T[j])
        score++;
    }
    ans = min(ans, score);
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  int n;
  cin >>n;
  long long a[n];
  long long max,min;
  for(int i=0;i<n;i++){
    cin >>a[i];
    if(i==0){
      max=a[i];
      min=a[i];
    }else{
      if(max<a[i])max=a[i];
      else if(min>a[i])min=a[i];
    }
  }
  
  cout <<(max-min)<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
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;}


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

    for(int i = 0; i < s.size(); i++){
        s[i] += n;
        if(s[i] - 'A' >= 26){
            s[i] -= 26;
        }
    }

    cout << s << endl;

    return 0;
}

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

#define SIZE 100

int main(void)
{
    int N, M;
    string blue_cards[SIZE], red_cards[SIZE];

    cin >> N;
    for(int i = 0; i < N; i++) cin >> blue_cards[i];

    cin >> M;
    for(int i = 0; i < M; i++) cin >> red_cards[i];

    int max_num = -200;

    for(int i = 0; i < N; i++)
    {
        string str = blue_cards[i];
        int cnt = 1;
        if(str == "") continue;

        for(int j = i + 1; j < N; j++)
        {
            if(str == blue_cards[j]){
                cnt++;
                blue_cards[j] = "";
            }
        }

        for(int k = 0; k < M; k++)
        {
            if(str == red_cards[k]) cnt--;
        }

        max_num = max(max_num, cnt);
    }

    if(max_num < 0)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << max_num << endl;
    }
    
    return 0;
}

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

int main(){
    string S;
    cin >> S;
    int N = S.size();
    bool flag = true;
    for (int i=0; i<N/2; i++) {
        if (S.at(i) != S.at(N-1-i)) flag = false;
    }
    for (int i=0; i<((N-1)/2)/2; i++) {
        if (S.at(i) != S.at((N-1)/2-1-i)) flag = false;
        if (S.at(N-1-i) != S.at((N+3)/2-1+i)) flag = false;
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <chrono>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9

typedef long long ll;

using namespace std;

const int N = 1e5+1;
int cnt[N];
bool prime[N];

void sieve() {

    prime[0] = 1, prime[1] = 1;

    for (int i = 2; i < N; i++) {

        if (!prime[i]) {

            for (int j = i+i; j < N; j+=i) {

                prime[j] = 1;
            }
        }
    }

}

void solve () {

    for (int i = 3; i < N; i+=2) {

        if (!prime[i] && !prime[(i+1)/2]) cnt[i]++;
    }

    for (int i = 3; i < N; i++) {

        cnt[i]+=cnt[i-1];
    }
}
int main()

{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    sieve();
    solve();

    int q, l, r;

    cin >> q;

    while (q--) {

        cin >> l >> r;

        cout << cnt[r]-cnt[l-1] << "\n";
    }

    return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	string s;
	cin >> s;
	ll n = s.size();
	vector<vector<ll>> dp(n,vector<ll>(13,0));
	if (s[0] == '?'){
		for(int i = 0; i < 10; i++) {
			dp[0][i] = 1;
		}
	}
	else{
		dp[0][s[0] - '0'] = 1;
	}

	for(int i = 0; i < n - 1; i++) {
		if (s[i+ 1]  == '?'){
			for(int j = 0; j < 13; j++) {
				for(int k = 0; k < 10; k++) {
					dp[i+1][(j*10+k) % 13] += dp[i][j] % mod;
					dp[i+1][(j*10+k) % 13] %= mod;
				}
			}
		}
		else{
			for(int j = 0; j < 13; j++) {
					dp[i+1][(j * 10 + (s[i + 1] -'0')) % 13] += dp[i][j] % mod;
					dp[i+1][(j * 10 + (s[i + 1] -'0')) % 13] %= mod;
			}
		}
	}
	cout << dp[n - 1][5] << endl;
	return 0;
}

Measured memory_bytes: 13696
#include <stdio.h>

int main(){
  int w, res;
  while(scanf("%d", &w)  && w != -1){
    res = 1150;
    if(w > 30){ res += (w - 30) * 160; w = 30;}
    if(w > 20){ res += (w - 20) * 140; w = 20;}
    if(w > 10) res += (w - 10) * 125;

    printf("%d\n", 4280 - res);
  }
  return 0;
}

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

using namespace std;

int N,M;
int X[100005];
int SUB[100005];
int main(){
    scanf("%d %d",&N,&M);
    for(int i=0;i<M;i++){
        scanf("%d",&X[i]);
    }
    sort(X,X + M);
    for(int i = 0;i<M-1;i++){
        SUB[i] = abs(X[i]-X[i+1]);
    }
    sort(SUB,SUB+M-1);
    int ans = 0;
    for(int i=0;i<M-N;i++){
        ans += SUB[i];
    }
    printf("%d\n",ans);

}

Measured memory_bytes: 1024
#include<iostream>
#include<stdio.h>
#include<cmath>
 
using namespace std;
int main () {
    double a,b,C;
    cin >> a >> b >> C;
    printf("%.6f\n",a*b*sin(C*M_PI/180)/2);
    printf("%.6f\n",a+b+sqrt(a*a+b*b-2*a*b*cos(C*M_PI/180)));
    printf("%.6f\n",b*sin(C*M_PI/180));
}


Measured memory_bytes: 3536
main(){
	int x=0,y=0,dx,dy,tx=0,ty=0;
	scanf("%*d");
	for(;~scanf("%d%d",&dx,&dy);){
		x+=dx,y+=dy;
		if(x*x+y*y>tx*tx+ty*ty||x*x+y*y==tx*tx+ty*ty&&x>tx)
			tx=x,ty=y;
		if(dx==0&&dy==0){
			printf("%d %d\n",tx,ty);
			tx=ty=0;
		}
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<map>
using namespace std;

int main(){
    //input
    int N,M;
    map<string, int> jisho;
    int i;
    string s;
    cin >> N;
    for(i=0; i<N; i++){
        cin >> s;
        jisho[s]++;
    }
    cin >> M;
    for(i=0; i<M; i++){
        cin >> s;
        jisho[s]--;
    }

    //calc
    int ans=0;
    for(auto p: jisho){
        ans=max(ans,p.second);
    }


    //output
    cout << ans << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================

vector<bool> sosuu; // ←これをグローバル変数にして１度だけ実行する
void searchSosuu(ll N) {
	for (ll i = 0; i < N; i++) {
		sosuu.emplace_back(true);
	}
	sosuu[0] = false;
	sosuu[1] = false;
	for (ll i = 2; i < N; i++) {
		if (sosuu[i]) {
			for (ll j = 2; i * j < N; j++) {
				sosuu[i * j] = false;
			}
		}
	}
}



int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


	ll Q;
	cin >> Q;
	vll L(Q), R(Q);
	for (int i = 0; i < Q; i++)
	{
		cin >> L[i] >> R[i];
	}

	searchSosuu(1e5+10);


	vbool sim(1e5 + 10);
	sim[0] = false;
	for (int i = 1; i <= 1e5 + 5;i++)
	{
		if (sosuu[i]  && sosuu[((i + 1) / 2)])
		{
			sim[i] = true;
		}
	}


	vll ruiseki(1e5 + 5);
	for (int i = 1; i < 1e5 + 5;i ++)
	{
		ruiseki[i] = ruiseki[i - 1] + sim[i];
	}

	for (int i = 0; i < Q; i++)
	{
		cout << ruiseki[R[i]] - ruiseki[L[i] - 1] << endl;
	}




}





Measured memory_bytes: 3072
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
#include <list>

using namespace std;



int main() {
	int abc[3];
	for (int i = 0; i < 3; i++) {
		cin >> abc[i];
	}
	sort(abc, abc + 3);
	int count = 0;
	if (abc[2] % 2 == abc[1] % 2 && abc[2] % 2 == abc[0] % 2) {
		count = (abc[2] - abc[1]) / 2 + (abc[2] - abc[0]) / 2;
	}
	if (abc[2] % 2 != abc[1] % 2 && abc[2] % 2 != abc[0] % 2) {
		count++;
		abc[0]++;
		abc[1]++;
		count+= (abc[2] - abc[1]) / 2 + (abc[2] - abc[0]) / 2;
	}
	if (abc[2] % 2 == abc[1] % 2 && abc[2] % 2 != abc[0] % 2) {
		count++;
		abc[1]++;
		abc[2]++;
		count += (abc[2] - abc[1]) / 2 + (abc[2] - abc[0]) / 2;
	}
	if (abc[2] % 2 != abc[1] % 2 && abc[2] % 2 == abc[0] % 2) {
		count++;
		abc[2]++;
		abc[0]++;
		count += (abc[2] - abc[1]) / 2 + (abc[2] - abc[0]) / 2;
	}
	cout << count << endl;
	return 0;
}



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



int main() {

  int N;
  scanf("%d", &N);

  vector<long long> A(N);
  for (int i=0;i<N;i++){
    scanf("%lld", &A[i]);
  }


  
  sort(A.begin(), A.end(), greater<int>());

  priority_queue<long long> pq;
  pq.push(A[0]);

  long long S = 0;

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

    
    int X_MAX = pq.top();pq.pop();

    S += X_MAX;

    pq.push(A[i]);
    pq.push(A[i]);
    
  }

  printf("%lld\n", S);
  
  return 0;
}



Measured memory_bytes: 6920
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();

		ArrayList<Long> right = new ArrayList<>();
		ArrayList<Long> left = new ArrayList<>();

		for (int i = 0; i < N; i++) {
			long x = sc.nextLong();
			if (x>0) {
				right.add(x);
			} else if(x==0) {
				K--;
			} else {
				left.add(-x);
			}
		}
		right.add(0L);
		left.add(0L);

		Collections.sort(right);
		Collections.sort(left);

		long ans = Long.MAX_VALUE;

		for (int i = 0; i < right.size(); i++) {
			int j = K - i;
			if (j >= 0 && j < left.size()) {
				long min = Math.min(right.get(i), left.get(K-i));
				long max = Math.max(right.get(i), left.get(K-i));

				ans = Math.min(ans , min*2 + max);
			}
		}

		for (int i = 0; i < left.size(); i++) {
			int j = K - i;
			if (j >= 0 && j < right.size()) {
				long min = Math.min(left.get(i), right.get(K-i));
				long max = Math.max(left.get(i), right.get(K-i));

				ans = Math.min(ans, min*2 + max);
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 62920
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    string s;
    cin >>s;
    int ans = 0;
    for(int i = s.size()-1;i >=0;i--){
        s[i]-=48;
        if(s[i]>10-s[i]){
            if(i!=0){
                s[i-1]++;
                ans-=1;
            }
            ans+=(11-s[i]);
        }else if(s[i]==5){
            if(i!=0&&s[i-1]-48>=5){
                s[i-1]++;
                ans-=1;
                ans+=(11-s[i]);
            }else{
                ans +=(s[i]);
            }
        }
        else{
            ans +=(s[i]);
        }
    }
    cout << ans << endl;
}

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

#define mem( arr, i ) fill( arr, arr + sizeof (arr), i )
#define MEM( arr, i ) memset( arr, i, sizeof (arr) )
#define Push push_back
#define Pair make_pair
#define ALL(x) (x).begin(), (x).end()
#define X first
#define Y second
#define ACCEL ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
typedef unsigned long long ull;
typedef long long lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vcI;
typedef vector<lli> vcL;
typedef vector<pii> vPI;
typedef vector<pll> vPL;
typedef vector<vcL> vvL;
//typedef priority_queue<T> prior_S<T>;
//typedef priority_queue< T, vector<T>, greater<T> > prior_B<T>;
const double PI = 3.141592653589793;
const lli I_MAX = 1LL << 60;
      lli   mod = 1000000007;

/// templates ///

const lli maxN = 2E5;

vcL inv( maxN+5, 1 );
vcL fac( maxN+5, 1 );

void ADD(lli &x, lli y) {
	x += y;
	if ( x >= mod ) x -= mod;
	if ( x < 0 ) x += mod;
}

void MUL(lli &x, lli y) {
	x *= y;
	x = ( x%mod + mod ) % mod;
}

lli mypow(lli b, lli e) {
	lli ans = 1;
	while (e) {
		if ( e&1 ) MUL( ans, b );
		MUL( b, b );
		e >>= 1;
	}
	return ans;
}

lli modinv(lli n) {
	return mypow( n, mod-2 );
}

void calcInv(lli n) {
	for (int i = 2; i <= n; ++i) {
		inv[i] = (mod-mod/i) * inv[ mod%i ] % mod;
	}
}

void calcFac(lli n) {
	for (int i = 2; i <= n; ++i) {
		fac[i] = fac[ i-1 ] * i % mod;
	}
}

lli cm(lli a, lli b) {
	lli ans = 1;
	if ( a < b ) return 0;

	MUL( ans, inv[ fac[ a-b ] ] );
	MUL( ans, inv[ fac[b] ] );
	MUL( ans, fac[a] );

	return ans;
}

lli Lucas(lli n, lli m) {
	if ( m == 0 ) return 1;
	return cm( n%mod, m%mod ) * Lucas( n/mod, m/mod ) % mod;
}

lli doLucas(lli n, lli m) {
	calcInv(mod);
	calcFac(mod);
	return Lucas( n, m );
}

/// coding area ///

void precal() {

	return;
}

void solve() {
	lli n = 1, l, sum = 0, ans = 0, _min = 1000;
	string s;
	cin >> n >> l;

	for (int i = 0; i < n; ++i) {
		_min = min( _min, abs( l+i ) );
		sum += l+i;
	}
	
	if ( sum < 0 ) sum += _min;
	else sum -= _min;
	
	cout << sum << '\n';
}

int main() {
	precal();
	int t = 1;
	#ifdef LOCAL
		t = INT_MAX;
	#else
		ACCEL;
	#endif
//	cin >> t;
	for (int i = 1; i <= t; ++i) {
//		printf("Case #%d: ", i );
		solve();
	}
	return 0;
}




Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl
#define int ll
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
 
const int M = 1e9 + 7;
 
int qpow(int a, int b) {
	if(b == 0) return 1;
	int t = qpow(a, b / 2);;
	t = t * t % M;
	if(b&1) return t * a % M;
	else return t;
}
 
int inv[200005];
 
int C(int n, int k) {
	int ret = 1;
	for(int i=0;i<k;i++)
		ret = ret * (n - i) % M;
	for(int i=1;i<=k;i++)
		ret = ret * inv[i] % M;
	return ret;
}
 
signed main()
{
	IO_OP;
	inv[1] = 1;
	for(int i=2;i<200005;i++)
	    inv[i] = (M - M / i) * inv[M % i] % M;
	int n, a, b;
	cin >> n >> a >> b;
	int ans = (qpow(2, n) + M - 1) % M;
	ans += M - C(n, a);
	ans += M - C(n, b);
	ans %= M;
	cout << ans << endl;
	
}
 

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;
 
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;
 
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; }
 
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }
 
 
signed main()
{
  int n; cin>>n;
  reps(i,9){
    if(n%i==0){
      int a=n/i;
      if(a<10) {
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 256
/*
     Author:Raghav Bansal
     IIIT Una
                  */
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define BOLT ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define X first
#define Y second
#define endl "\n"
using namespace std;
int n;
vector<int> v;
int dp[20][2][10][2];
int dfs(int x, int tight, int digit, int sum) {
	if (x == n) {
		return sum > 0;
	}
	int &an = dp[x][tight][digit][sum > 0];
	if (an != -1) {
		return an;
	}
	an = 0;
	int range = (tight) ? v[x] : 9;
	if (sum == 0) {
		for (int i = 0; i <= range; i++) {
			int ntight = (v[x] == i) ? tight : 0;
			an += dfs(x + 1, ntight, i, sum + i);
		}
	} else {
		if (digit - 1 >= 0 and digit - 1 <= range) {
			int ntight = (v[x] == (digit - 1)) ? tight : 0;
			an += (dfs(x + 1, ntight, digit - 1, sum + digit - 1));
		}
		if (digit <= range) {
			int ntight = (v[x] == (digit)) ? tight : 0;
			an += (dfs(x + 1, ntight, digit, sum + digit));
		}
		if (digit + 1 <= range) {
			int ntight = (v[x] == (digit + 1)) ? tight : 0;
			an += (dfs(x + 1, ntight, digit + 1, sum + digit + 1));
		}
	}
	return an;
}
int solve(string s)
{
	v.clear();
	memset(dp, -1, sizeof(dp));
	for (int i = 0; i < s.length(); i++)
		v.pb(s[i] - '0');
	n = v.size();
	return dfs(0, 1, 0, 0);
}
void solve() {
	int k;
	cin >> k;
	int low = 1, high = 1e12;
	int ans;
	while (low <= high) {
		int mid = (low + high) / 2;
		int temp = solve(to_string(mid));
		if (temp < k) {
			low = mid + 1;
		} else {
			if (temp == k)
				ans = mid;
			high = mid - 1;
		}
	}
	cout << ans << endl;
}
int32_t main() {
	int t;
	t = 1;
	int cnt = 1;
	while (t--)
	{
		solve();
	}
}


Measured memory_bytes: 256
#include <cstdio>
#define MAX 200001
int main()
{
	char s[MAX];
	char t[MAX];


	int i;
	for (i = 0; i < MAX; i++) {
		s[i] = '\0';
		t[i] = '\0';
	}
	scanf("%s", s);
	scanf("%s", t);

	int count = 0;
	i = 0;
	while (s[i] != '\0') {
		if (s[i] != t[i])
			count++;

		i++;
	}
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 2120
#include <stdio.h>
 
int Partition(int* A,int p,int r);

int n;
 
main(){
  int i,p,A[100000];
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
 
  p = Partition(A,0,n-1);
 
  for(i=0;i<n;i++){
    if(p==i)printf("[%d]",A[i]);
    else printf("%d",A[i]);
if(i!=n-1) printf(" ");
  }
  printf("\n");
 
  return 0;
}
 
int Partition(int* A,int p, int r){
 
  int x, i,j, tmp;
 
  x = A[r];
  i = p-1;
  for(j=p; j<=r-1; j++){
 
    if(A[j] <= x){
      i++;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
 
  }
      tmp = A[i+1];
      A[i+1] = A[r];
      A[r] = tmp;
 
  return i+1;
 
}

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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<std::vector<char> > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<std::vector<double> > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

int main(void)
{
    ll n, k;
    cin >> n >> k; 
    
    v_int a(n);

    irep(i, n) { cin >> a[i]; }

    v_int s, t(n+1, -1);
    int c, l;

    {
        int v = 1;
        while(t[v] == -1) {
            t[v] = s.size();
            s.push_back(v);          
            v = a[v-1];
        }
        c = s.size() - t[v];
        l = t[v];
    }

    if(k < s.size()) {
        cout << s[k] << endl;
    } else {
        k -= l;
        k %= c;
        cout << s[l+k] << endl;
    }
    return 0;
}
/** atcoder **/


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

#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define MOD 1000000007

typedef long long ll;

using namespace std;
int main(){
    int N, M;
    cin >> N >> M;
    string A[N], B[M];
    string ans = "";
   	REP(i, N) {
    	cin >> A[i];
    }
    REP(i, M) {
    	cin >> B[i];
    }

    bool matching;
    REP(x, N - M + 1) {
    	REP(y, N - M + 1) {
    		matching = true;
    		REP(i, M) {
    			if (A[y + i].substr(x, M) == B[i]) {
    				continue;
    			}
    			else {
    				matching = false;
    				break;
    			}
    		}
    		if (matching) break;
    	}
    	if (matching) break;
    }

    ans = matching ? "Yes" : "No";
    cout << ans << endl;
}


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

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int N, M;

int dx[]={1,0};
int dy[]={0,1};
char maze[10][10];

void dfs(int x, int y) {
	maze[y][x] = '.';
	rep(2, i) {
		if (maze[y+dy[i]][x+dx[i]] == '#' && x < M && y < N) {
			dfs(x+dx[i], y+dy[i]);
			break;
		}
	}
}

void solve(void){

	cin >> N >> M;
	rep(N, i) rep(M, j) cin >> maze[i][j];
	dfs(0, 0);
	rep(N, i) rep(M, j) {
		if (maze[i][j] == '#') {
			cout << "Impossible" << endl;
			return;
		}
	}
	cout << "Possible" << endl;

}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define inf 1e+9
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

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

    int n,k,sum=0,c=1;
	cin >> n >> k;
	int l[n];
	rep(i,n){
		cin >> l[i];
		sum += l[i];
		if(k>=sum){
			c++;
		}
	}
	
	cout << c << endl;
}

Measured memory_bytes: 888
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on

void main()
{
    long N = lread();
    auto S = sread();
    auto E = new long[](N + 1);
    auto W = new long[](N + 1);
    foreach (i; 0 .. N)
    {
        E[i + 1] = E[i] + (S[i] == 'E');
        W[i + 1] = W[i] + (S[i] == 'W');
    }
    long ans = long.max;
    foreach (i; 0 .. N)
    {
        long cnt = W[i] + E[$ - 1] - E[i + 1];
        ans = ans.min(cnt);
    }
    writeln(ans);
}


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

int gcd(int a, int b) {
	int c;

	if (a < b) {
		a += b;
		b = a - b;
		a -= b;
	}

	while (b != 0) {
		c = a % b;
		a = b;
		b = c;
	}

	return a;
}

int main() {
	int N, K, A[100000], Gcd, Max;
	cin >> N >> K >> A[0];
	Gcd = A[0];
	Max = A[0];
	for (int i = 1; i < N; i++) {
		cin >> A[i];
		Gcd = gcd(Gcd, A[i]);
		if (Max < A[i]) Max = A[i];
	}
	if (K % Gcd == 0 && Max >= K) cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 640
import java.lang.Math.sqrt

data class Point(val x:Double, val y:Double){
    operator fun minus(that:Point):Vector = Vector(x - that.x, y - that.y)
    fun distantFrom(that:Point):Double = (this - that).let{(x, y) -> sqrt(x * x + y * y)}
    fun vectorTo(that:Point):Vector = (that - this).let{(x, y) -> Vector(x, y)}
}
data class Vector(val x:Double, val y:Double){
    fun length():Double = sqrt(x * x + y * y)
}
class Angle private constructor(val sin:Double, val cos:Double){
    fun isObtuse():Boolean = cos < 0
    fun isNarrowThan(that:Angle):Boolean = cos > that.cos
    companion object {
        fun angleFromCos(cos:Double):Angle = Angle(sqrt(1 - cos * cos), cos)
        fun angleFromSin(sin:Double):Angle = Angle(sin, sqrt(1 - sin * sin))
        fun angleBetweenVector(a:Vector, b:Vector):Angle = angleFromCos((a.x * b.x + a.y * b.y) / a.length() / b.length())
    }
}
data class Circle(val center:Point, val radius:Double)
class Seeker(val position:Point)
class Target(val position:Point)

fun isCoveredByCircle(seeker:Seeker, target: Target, circle: Circle):Boolean {
    return when{
        seeker.position.distantFrom(circle.center) < circle.radius &&
                target.position.distantFrom(circle.center) < circle.radius -> false
        seeker.position.distantFrom(circle.center) < circle.radius &&
                target.position.distantFrom(circle.center) > circle.radius -> true
        seeker.position.distantFrom(circle.center) > circle.radius &&
                target.position.distantFrom(circle.center) < circle.radius -> true
        else -> {
            val circleViewAngle = Angle.angleFromSin(circle.radius / seeker.position.distantFrom(circle.center))
            val targetViewAngle = Angle.angleBetweenVector(seeker.position.vectorTo(target.position), seeker.position.vectorTo(circle.center))
            when{
                circleViewAngle.isNarrowThan(targetViewAngle) -> false
                else ->{
                    val targetSeekerAngleFromCircle = Angle.angleBetweenVector(circle.center.vectorTo(seeker.position), circle.center.vectorTo(target.position))
                    targetSeekerAngleFromCircle.isObtuse()
                }
            }
        }
    }
}
fun solve(n:Int):Unit{
    if (n == 0) return
    val circles = (0 until n).map{
        val (x, y, r) = readLine()!!.split(' ').map(String::toDouble)
        Circle(Point(x, y), r)
    }
    for (d in 0 until readLine()!!.toInt()){
        val (tx, ty, sx, sy) = readLine()!!.split(' ').map(String::toDouble)
        val target = Target(Point(tx, ty))
        val seeker = Seeker(Point(sx, sy))
        println(when{
            circles.any{isCoveredByCircle(seeker, target, it)} -> "Safe"
            else -> "Danger"
        })
    }
    solve(readLine()!!.toInt())
}
fun main(args:Array<String>):Unit{
    solve(readLine()!!.toInt())
}


Measured memory_bytes: 36748
N = int(input())

a = []
for _ in range(N):
    a += [int(input())]

lst = [0] * N

flag = True
i = 0
count = 0
while flag:
    if lst[i] == 1:
        print (-1)
        exit()
    elif a[i] == 2:
        print (count + 1)
        exit()
    else:
        lst[i] = 1
        i = a[i] - 1
        count += 1


Measured memory_bytes: 7960
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

int main() {
    int n;
    cin >> n;
    
    vector<int64_t> a(n);


    for(int i=0; i<n; i++){
        cin >> a[i];
        if(a[i] == 0){
            cout << 0 << endl;
            return 0;
        }
    }

    uint64_t ans=1;

    uint64_t k = (uint64_t)pow(10,18);

    for(int i=0; i<n; i++) {
        if(log10(ans)+ log10(a[i]) > 18){
            cout << -1 << endl;
            return 0;
        }
        ans *= (uint64_t)a[i];
        if(ans > k) {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 4052
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			if (n == 0)
				break;
			int[] I = new int[n];
			int[] R = new int[n];
			for (int i = 0; i < n; i++)
				I[i] = sc.nextInt();
			int S = 0, A = 0, C = 0;
			double min = Double.MAX_VALUE;
			for (int s = 0; s < 16; s++)
				for (int a = 0; a < 16; a++)
					for (int c = 0; c < 16; c++) {
						int[] O = new int[256];
						R[0] = (a * s + c) % 256;
						O[(I[0] + R[0]) % 256]++;
						for (int i = 1; i < n; i++) {
							R[i] = (a * R[i - 1] + c) % 256;
							O[(I[i] + R[i]) % 256]++;
						}
						double H = 0;
						for (int i = 0; i < 256; i++)
							if (O[i] > 0)
								H -= O[i] / (double) n
										* Math.log(O[i] / (double) n);
						if (H + 1e-10 < min) {
							min = H;
							S = s;
							A = a;
							C = c;
						}
					}
			System.out.println(S + " " + A + " " + C);
		}
		sc.close();
	}
}

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

int N;
long long A[100010];

int main()
{
    scanf("%d",&N);
    for(int i = 0; i < N; i++)scanf("%d",A + i);

    long long ans = 0;
    long long sum = 0;
    for(int i = 0; i < N; i++)
    {
        if(A[i] == 0)
        {
            ans += sum / 2;
            sum = 0;
        }
        sum += A[i];
    }

    ans += sum / 2;

    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int tree[260];

int main(){
  int n;
  cin>>n;
  for(int i=1;i<=n;i++)cin>>tree[i];

  for(int i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,tree[i]);
    if(i!=1) printf("parent key = %d, ",tree[i/2]);
    if(i*2<=n)printf("left key = %d, ",tree[i*2]);
    if(i*2+1<=n)printf("right key = %d, ",tree[i*2+1]);
    cout <<endl;
  }
  return 0;
}

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

int main() {
  int N, K; cin >> N >> K;
  int ans = 0;
  vector<int> l(N);
  rep(i, N) {
    cin >> l[i];
  }
  sort(l.begin(), l.end());
  reverse(l.begin(), l.end());
  rep(i, K) {
    ans += l[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256