akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long a = sc.nextLong();
    long b = sc.nextLong();
    long ans = modPow(2, n) - 1;
    ans = minus(ans,cmb(n,a));
    ans = minus(ans,cmb(n,b));

    System.out.println(ans);
  }
  private static final long MOD = 1000000007;
  private static final long MOD5 = 1000000005;

  private static long modPow(long a, long n) {
    if (n == 1) return a % MOD;
    if (n % 2 == 1) return (a * modPow(a, n - 1)) % MOD;
    long t = modPow(a, n / 2);
    return (t * t) % MOD;
  }

	private static long minus(long a, long b) {
      while (a<b) {
        a+=MOD;
      }
      return (a-b) % MOD;
    }
    private static long cmb(long n, long r) {
        if (n-r<r) {
            r = n - r;
        }
        long x = 1;
        long y = 1;
        for (long i=0;i<r;i++) {
            x = x * (n - i) % MOD;
            y = y * (i + 1) % MOD;            
        }
        return x * modPow(y, MOD5);
    }

}



Measured memory_bytes: 23252
def main():
  N = int(input())
  H = [int(_) for _ in input().split()]
  a = [0] * N
  a[0] = H[0]
  for i in range(N-1):
    if H[i+1] > H[i]:
      a[i+1] += a[i] + H[i+1] - H[i]
    else:
      a[i+1] = a[i]
  print(a[N-1])
  return

if __name__ == '__main__':
  main()

Measured memory_bytes: 3060
//INCLUDE
//------------------------------------------
#include <iostream>
#include <functional>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <string>
#include <cstring>
#include <vector>
//DEFINE
//------------------------------------------
#define ll long long
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
using namespace std;
//-------------------------------------------

int main(void){
  string S;cin>>S;
  ll Q;cin>>Q;cin.ignore();
  string buf,F="",B="";
  bool isRev=false;
  REP(i,Q){
    getline(cin,buf);
    if(buf[0]=='1'){
      isRev=!isRev;
    }else{
      if( (buf[2]=='1')==!isRev){//F
	    F+=buf[4];
      }else{
	    B+=buf[4];
      }
    }
  }
  reverse(ALLv(F));
  if(isRev){
  	reverse(ALLv(F));
  	reverse(ALLv(B));
  	reverse(ALLv(S));
  	S=B+S+F;
  }else{
  	S=F+S+B;
  }
  cout<<S<<endl;
  return 0;
}


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


void solve(long long a){
    printf("%lld\n", (long long)(a+pow(a,2)+pow(a,3)));
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long a;
    scanf("%lld",&a);
    solve(a);
    return 0;
}


Measured memory_bytes: 4188
#include<bits/stdc++.h>
using namespace std; 
 
int main()
{
  string s ; 
  
  cin>>s; 
  
  if(s[s.size() -1] == 's') 
  {
    s+= "es";
  }
  else 
  {
    s += 's';
  }
  
  cout<<s; 
}

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

using namespace std;

// 最小のAと最大のBを出す必要がある 

int main(void)
{
    int A = 0, B = 0;

    cin >> A >> B; 

    bool isOk = false;
    int ans = 0;

    const int max = 1009;

    // 1~max円まで全探索する 
    for(; ans < max; ans++){
        // Aについて税抜き価格の範囲に該当
        int a_x = ans * 0.08;
        int b_x = ans * 0.1;

        if((a_x == A) && (b_x == B )){
            isOk = true;
            break;
        }
    }

    if (isOk){
        cout << ans << endl;
    }else{
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const  ll INF = 1e18;
const  ll MOD = 1e9 + 7;
#define repi(i,n,init) for(ll i=init;i<(n);i++)

int main()
{
    int n;
    cin >> n;
    int a[n];
    ll y = 0;
    repi(i,n,0){
        cin >> a[i];
        y += a[i];
    }
    ll x = 0;
    ll ans = INF;
    repi(i,n-1,0){
        x += a[i];
        y -= a[i];
        ans = min(ans,abs(x-y));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

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

    string s, t;
    for (int i = 0; i < b; ++i) {
        s += '0' + a;
    }
    for (int i = 0; i < a; ++i) {
        t += '0' + b;
    }
    cout << min(s, t) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <list>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;

int main() {
    int q, x;
    char cmd[20];
    list<int> v;
    scanf("%d",&q);
    for (int i=0; i<q; i++) {
        scanf("%s",cmd);
        if (strcmp(cmd,"insert")==0) {
            scanf("%d",&x);
            v.push_front(x);
        } else if (strcmp(cmd,"deleteLast")==0) {
            v.pop_back();
        } else if (strcmp(cmd,"deleteFirst")==0) {
            v.pop_front();
        } else if (strcmp(cmd,"delete")==0) {
            scanf("%d",&x);
            list<int>::iterator it;
            for (it=v.begin(); it!=v.end(); it++)  {
                if (*it==x) {
                    v.erase(it);
                    break;
                }
            }
        }
    }
    int i=0;
    list<int>::iterator it;
    for (it=v.begin(); it!=v.end(); it++) {
        if (i++) {
            printf(" ");
        }
        printf("%d",*it);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 34360
#include <bits/stdc++.h>
using namespace std;
  
int main() {
  int N,M;
  cin >> N >> M;
  
  vector<long long>A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  
  vector<pair<long long, int>> a(M);
  for (int i = 0; i < M; i++) {
    cin >> a.at(i).second >> a.at(i).first;
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  
  vector<long long>B(N);
  int L = 0;
  for (int i = 0; i < M; i++) {
    if (L >= N){
        break;
    }
    for (int j = 0; j < a.at(i).second; j++) {
      B.at(L) = a.at(i).first;
      L++;
      if (L >= N){
        break;
      }
    }
  }
  
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    A.at(i) = max(B.at(i),A.at(i));
    sum += A.at(i);
  }
  cout << sum << endl;
}
  
  
    

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define debugbit(x, n)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

class SegmentTree {
    vector<int> nodes_;
    int size_;
    inline static constexpr int INIT = 0;

    int query (const int left, const int right, const int index, const int l, const int r) const {
        if (r <= left || right <= l) return INIT;
        if (left <= l && r <= right) return nodes_[index];

        return query(left, right, 2 * index + 1, l, (l + r) / 2) +
                query(left, right, 2 * index + 2, (l + r) / 2, r);
    }

public:
    SegmentTree(const int maxSize) {
        size_ = 1;
        while (size_ < maxSize) size_ *= 2;
        nodes_ = vector<int> (2 * size_, INIT);
    };

    void update (int index, const int value) {
        index += size_ - 1;
        nodes_[index] += value;
        while (index > 0) {
            index = (index - 1) / 2;
            nodes_[index] = nodes_[2 * index + 1] + nodes_[2 * index + 2];
        }
    }

    // get value in [left, right)
    int get (const int left, const int right) const {
        return query(left, right, 0, 0, size_);
    }
};

void solve(long long N, long long Q, vector<ll> c, std::vector<long long> l, std::vector<long long> r){
    vector<int> posOfLast(N+1, -1);
    vector<int> answer(Q);
    vector<vector<int>> queries(N+1);
    rep(i,0,Q) {
        queries[r[i]].push_back(i);
    }
    SegmentTree seg(N+1);
    rep(i,0,N) {
        if (posOfLast[c[i]] != -1) seg.update(posOfLast[c[i]], -1);
        posOfLast[c[i]] = i+1;
        seg.update(posOfLast[c[i]], 1);

        for (auto j : queries[i+1]) {
            answer[j] += seg.get(l[j], r[j]);
        }
    }
    rep(i,0,Q) cout << answer[i]+1 << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    long long Q;
    scanf("%lld",&Q);
    vector<ll> c(N);
    for(int i = 0 ; i < N ; i++){
        cin >> c[i];
    }
    std::vector<long long> l(Q);
    std::vector<long long> r(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&l[i]);
        scanf("%lld",&r[i]);
    }
    solve(N, Q, move(c), std::move(l), std::move(r));
    return 0;
}


Measured memory_bytes: 44168
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace ConsoleApp5
{
    class Program
    {
        int n;
        int inf = 1050000000;
        int result;
        int summ;
       
        int m,k,f;
        bool[,] pairs;
        int[,] g;
        List<int> tank;
        string a, b;
        char tmp;
        List<string> used;
        Dictionary<char, List<int>> tank1;
        int ans;

        public void Run()
        {
                var Elems = Console.ReadLine().Split().Select(int.Parse).ToArray();
                n = Elems[0];
                m = Elems[1];
            SortedDictionary<int, string>[] kek = new SortedDictionary<int, string>[n+1];
            SortedDictionary<int, string>[] lel = new SortedDictionary<int, string>[n + 1];
            for (int i = 1; i <= n; i++)
            {
                kek[i] = new SortedDictionary<int, string>();
                lel[i] = new SortedDictionary<int, string>();
            }
            List<string> list = new List<string>();
            for (int i = 0; i<m; i++)
            {
                list.Add(Console.ReadLine());
            }
            int[] pup;
            foreach (var e in list)
            {
                pup = e.Split().Select(int.Parse).ToArray();
                kek[pup[0]][pup[1]] = "";
                lel[pup[0]][pup[1]] = "";
            }
            int counter;
            for(int i = 1; i<=n; i++)
            {
                counter = 1;
                foreach (var e in kek[i])
                {
                    for (int j = 0; j < 6 - i.ToString().Length; j++)
                        lel[i][e.Key] += '0';
                    lel[i][e.Key] += i.ToString();
                    for (int j = 0; j < 6 - counter.ToString().Length; j++)
                        lel[i][e.Key] += '0';
                    lel[i][e.Key] += counter.ToString();
                    counter++;
                }
            }
                foreach (var e in list)
            {
                pup = e.Split().Select(int.Parse).ToArray();
                Console.WriteLine(lel[pup[0]][pup[1]]);
            }
        }

        
       
        void GoS(int i)
        {
        }

        /* string Kek(int i)
        {
            if (i == 1) return dp[1].ToString() + "+"+n;
            return "(" + Kek(i - 1) + ")" + dp[i].ToString() +"+"+ (n - i + 1).ToString();
        }
*/
        static void Main(string[] args)
        {
                    new Program().Run();
        }
    }
}


Measured memory_bytes: 67088
#include <iostream>
#include <vector>
#include <stdint.h>
#include <utility>
using namespace std;
int main() {
	int64_t A;
	cin >> A;

	vector<pair<int64_t, int64_t>>v;
	for (int64_t i = 1; i*i <= A; i++) {
		if (A%i==0 ) {
			v.push_back(pair<int64_t, int64_t>(i, A / i));
		}
	}

	int64_t min=1e12;
	int64_t tmp = 0;
	for (int64_t j = 0; j < v.size(); j++) {
		tmp = v[j].first + v[j].second - 2;
		if (tmp < min) min = tmp;
	}
	cout << min << endl;
	return 0;
}

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

int main(){

    string s, ans;
    char c0, c1;
    int i, s_num, correct;

    cin >> s;

    s_num = s.size();

    for (i = 2; i<s_num; i += 2){
        c0 = s.at(i);
        c1 = s.at(i+1);

        if (c0 != c1){
            ans = "No";
            break;
        }
    }

    if (ans == "No"){
        cout << ans << endl;
    }
    else{
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
    
class Combinatorics:
    def __init__(self, N, mod):
        '''
        Preprocess for calculating binomial coefficients nCr (0 <= r <= n, 0 <= n <= N)
        over the finite field Z/(mod)Z.
        Input:
            N (int): maximum n
            mod (int): a prime number. The order of the field Z/(mod)Z over which nCr is calculated.
        '''
        self.mod = mod
        self.fact = {i: None for i in range(N+1)}         # n!
        self.inverse = {i: None for i in range(1, N+1)}   # inverse of n in the field Z/(MOD)Z
        self.fact_inverse = {i: None for i in range(N+1)} # inverse of n! in the field Z/(MOD)Z
        
        # preprocess
        self.fact[0] = self.fact[1] = 1
        self.fact_inverse[0] = self.fact_inverse[1] = 1
        self.inverse[1] = 1
        for i in range(2, N+1):
            self.fact[i] = i * self.fact[i-1] % self.mod
            q, r = divmod(self.mod, i)
            self.inverse[i] = (- (q % self.mod) * self.inverse[r]) % self.mod
            self.fact_inverse[i] = self.inverse[i] * self.fact_inverse[i-1] % self.mod
    
    def perm(self, n, r):
        '''
        Calculate nPr = n! / (n-r)! % mod
        '''
        if n < r or n < 0 or r < 0:
            return 0
        else:
            return (self.fact[n] * self.fact_inverse[n-r]) % self.mod
    
    def binom(self, n, r):
        '''
        Calculate nCr = n! /(r! (n-r)!) % mod
        '''
        if n < r or n < 0 or r < 0:
            return 0
        else:
            return self.fact[n] * (self.fact_inverse[r] * self.fact_inverse[n-r] % self.mod) % self.mod
        
    def hom(self, n, r):
        '''
        Calculate nHr = {n+r-1}Cr % mod.
        Assign r objects to one of n classes.
        Arrangement of r circles and n-1 partitions:
            o o o | o o | | | o | | | o o | | o
        '''
        if n == 0 and r > 0:
            return 0
        if n >= 0 and r == 0:
            return 1
        return self.binom(n + r - 1, r)
    
n, k = map(int, input().split())
MOD = 10**9 + 7
com = Combinatorics(k, MOD)
ans = 0
for i in range(k):
    if i % 2 == 0:
        ans = (ans + com.binom(k, i) * pow(k - i, n, MOD)) % MOD
    else:
        ans = (ans - com.binom(k, i) * pow(k - i, n, MOD)) % MOD
print(ans)


Measured memory_bytes: 6276
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> L(M), R(M);
  map<int, int> mp;
  rep(i, M) cin >> L[i] >> R[i];
  int begin = 0;
  int end = N;
  rep(i, M) {
    begin = max(L[i], begin);
    end = min(R[i], end);
  }
  cout << max(end-begin+1, 0) << endl;
  return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

		while (true) {

			String first_line = input.readLine();

			// ????????°??¨?????°
			int student_num = Integer.parseInt(first_line);

			if (student_num == 0) {

				break;

			}

			// ????????\?????¨?????°
			String secound_lines = input.readLine();

			String[] score_arrays = secound_lines.split(" ");

			// ?????°???????¨???¨?????°
			double score_sum = 0;

			//n???????????????????????????????????°?????????
			for (int score_spot = 0; score_spot < score_arrays.length; score_spot++) {

				int score = Integer.parseInt(score_arrays[score_spot]);

				score_sum += score;

			}

			//???????????????
			double average = score_sum / student_num;

			//??°???a???2???
			double sequence_a_square = 0;

			//??°???a???2??????????????????
			for (int sequence_spot = 0; sequence_spot < score_arrays.length; sequence_spot++) {

				double score = Double.parseDouble(score_arrays[sequence_spot]);


				sequence_a_square += Math.pow(score - average, 2);

			}

			double distributed_a_square = sequence_a_square / student_num;

			//??°???a????????????
			double square_a = Math.sqrt(distributed_a_square);

			System.out.println(square_a);
		}

	}

}

Measured memory_bytes: 26100
import sys

def solve():
    N = int(input())
    D = dict()
    for i in range(1, N + 1):
        front = i % 10
        back = i
        while back >= 10: back //= 10
        if front > 0:
            if (front, back) in D: D[(front, back)] += 1
            else: D[(front, back)] = 1
    Ans = 0
    for i in range(1, N + 1):
        back = i % 10
        if back > 0:
            front = i
            while front >= 10: front //= 10
            if (front, back) in D: Ans += D[(front, back)]
    print(Ans)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	string s, t;
	cin >> s >> t;
	map<char, vector<int>> sm, tm;
	for (int i = 0; i < s.size(); i++) {
		sm[s[i]].push_back(i);
		tm[t[i]].push_back(i);
	}
	vector<string> ss;
	for (auto e : sm) {
		string tmp;
		for (auto f : e.second) {
			tmp.append(" ");
			tmp.append(to_string(f));
		}
		ss.push_back(tmp);
	}
	vector<string> ts;
	for (auto e : tm) {
		string tmp;
		for (auto f : e.second) {
			tmp.append(" ");
			tmp.append(to_string(f));
		}
		ts.push_back(tmp);
	}
	sort(ss.begin(), ss.end());
	sort(ts.begin(), ts.end());

	
	if (ss.size() != ts.size()) {
		cout << "No" << endl;
		return 0;
	}

	for (int i = 0; i < ss.size(); i++) {
		if (ss[i] != ts[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 9244
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  vector<long> h(n);
  for(int i=0;i<n;i++) cin>>h[i];
  sort(h.begin(),h.end());
  long count=0;
  if(n>k){
    for(int i=0;i<n-k;i++)
    count+=h[i];
  }
  cout<<count<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
//#define LOCAL
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define forn(i,a,b) for(int i=a;i<b;i++)
#define ft first
#define sd second
#define sz size()
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<string,int> psi;
typedef pair<char,char> pcc;
typedef pair<double,double> pdd;
typedef pair<long long,long long> pll;
//cout << fixed << setprecision(12) <<x<<endl;

int main(){
fastIO;
#ifdef LOCAL
     freopen("in.txt", "r", stdin);
#endif

short t,c=0;
cin>>t;
while(t--){
    short x,y;
    cin>>x>>y;
    if(x==y){
        c++;
    }else{
        c=0;
    }
    if(c==3) break;
}
if(c==3){
    cout<<"Yes"<<endl;
}else{
    cout<<"No"<<endl;
}
}



Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n,mx;
	cin>>n;
	vector < int > c(3),prev(3);
	cin>>c[0]>>c[1]>>c[2];
	for(int i = 0 ; i < n-1 ; i++) {
		prev = c;
		cin>>c[0]>>c[1]>>c[2];
		for(int j = 0 ; j < 3 ; j++) {
			mx=0;
			for(int k = 0 ; k < 3 ; k++) {
				if(j!=k) {
					mx = max(c[j]+prev[k],mx);
				}
			}
			c[j] = mx;
		}
	}
	cout<<max({c[0],c[1],c[2]});
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
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; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    ll res = 0;
    char a[3];
    a[0]='R';
    a[1]='G';
    a[2]='B';
    sort(a,a+3);
    do{
        vector<ll> r(4005,0);
        vector<ll> rg(4005,0);
        vector<ll> rgb(4005,0);
        for(int i=1;i<=n;i++){
            if(s[i-1]==a[0])r[i]=r[i-1]+1;
            else r[i]=r[i-1];
        }
        for(int i=1;i<=n;i++){
            if(s[i-1]==a[1])rg[i]=rg[i-1]+r[i-1];
            else rg[i]=rg[i-1];
        }
        for(int i=1;i<=n;i++){
            if(s[i-1]==a[2])rgb[i]=rgb[i-1]+rg[i-1];
            else rgb[i]=rgb[i-1];
        }
        ll ans = rgb[n];
        vector<int> rp;
        rep(i,n)if(s[i]==a[0])rp.push_back(i);
        rep(i,n){
            if(s[i]==a[1]){
                for(auto p:rp){
                    if(p>i)break;
                    else if(((2*i-p)<n)&&(s[2*i-p]==a[2]))ans--;
                }
            }
        }
        res += ans;
    }while(next_permutation(a,a+3));
    cout << res << endl;
}

Measured memory_bytes: 3692
#include <iostream>
#include <numeric>

int main(int argc, char **argv)
{
    int K;
    std::cin >> K;

    long sum = 0;
    for(int i = 1; i <= K; i++){
        for(int j = 1; j <= K; j++){
            for(int k = 1; k <= K; k++){
                sum += std::gcd<int,int>(std::gcd<int,int>(i, j), k);
            }
        }
    }
    std::cout << sum << std::endl;
    
}


Measured memory_bytes: 3628
#include<stdio.h>

int main()
{
	int n, m, a, i;
	int work = 0;
	scanf("%d%d", &n, &m);
	for (i = 0; i < m; i++) {
		scanf("%d", &a);
		work += a;
	}
	if (n < work)
		printf("%d", -1);
	else
		printf("%d", n - work);
}

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

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

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

const int mxn = 2e5 + 5;
int n, K, q;
int x[mxn];
int l[mxn], r[mxn];
int idl[mxn], idr[mxn];
int mx[mxn];
ll sum[mxn];
int jmp[mxn][20];
ll s[mxn][20];

bool cmpl(int a, int b) {
	return l[a] > l[b];
}

bool cmpr(int a, int b) {
	return r[a] < r[b];
}

int main() {
	scanf("%d %d", &n, &K);
	rep(i, n) scanf("%d", &x[i]);
	scanf("%d", &q);
	rep(i, q) {
		scanf("%d %d", &l[i], &r[i]);
		-- l[i], -- r[i];
		idl[i] = idr[i] = i;
	}
	sort(idl, idl + q, cmpl);
	sort(idr, idr + q, cmpr);
	int i = 0;
	rep(R, n) {
		jmp[R][0] = upper_bound(x, x + n, x[R] - K) - x - 1;
		s[R][0] = R + 1;
		for (int j = 1; j < 20; ++ j) {
			jmp[R][j] = jmp[R][j - 1] == -1 ? -1 : jmp[jmp[R][j - 1]][j - 1];
			s[R][j] = s[R][j - 1] + (jmp[R][j - 1] == -1 ? 0 : s[jmp[R][j - 1]][j - 1]);
		}
		while (i < q && r[idr[i]] == R) {
			int L = l[idr[i]];
			int cnt = 1, cur = R;
			for (int j = 20 - 1; ~j; -- j) {
				if (jmp[cur][j] >= L) {
					cnt += 1 << j;
					cur = jmp[cur][j];
				}
			}
			mx[idr[i]] = cnt;
			++ i;
		}
	}
	i = 0;
	rep(R, n) {
		while (i < q && r[idr[i]] == R) {
			int L = l[idr[i]];
			ll &S = sum[idr[i]];
			int cur = R;
			for (int j = 20 - 1; ~j; -- j) {
				if (jmp[cur][j] >= L) {
					S += s[cur][j];
					cur = jmp[cur][j];
				}
			}
			S += cur + 1;
			S -= 1LL * mx[idr[i]] * L;
			++ i;
		}
	}
	i = 0;
	for (int L = n - 1; ~L; -- L) {
		jmp[L][0] = lower_bound(x, x + n, x[L] + K) - x;
		s[L][0] = L - 1;
		for (int j = 1; j < 20; ++ j) {
			jmp[L][j] = jmp[L][j - 1] == n ? n : jmp[jmp[L][j - 1]][j - 1];
			s[L][j] = s[L][j - 1] + (jmp[L][j - 1] == n ? 0 : s[jmp[L][j - 1]][j - 1]);
		}
		while (i < q && l[idl[i]] == L) {
			int R = r[idl[i]];
			ll &S = sum[idl[i]];
			int cur = L;
			for (int j = 20 - 1; ~j; -- j) {
				if (jmp[cur][j] <= R) {
					S -= s[cur][j];
					cur = jmp[cur][j];
				}
			}
			S -= cur - 1;
			S += 1LL * mx[idl[i]] * R;
			++ i;
		}
	}
	rep(i, q) {
		ll ans = sum[i] - (r[i] - l[i] + 1) - 1LL * (mx[i] - 1) * (r[i] - l[i] + 1);
		printf("%lld\n", ans);
	}
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    int h[n];
    bool flg = true;
    int max = 0;
    for(int i=0;i<n;i++){
        cin >> h[i];
        if(h[i] > max) max = h[i];
        if(max - h[i] > 1) flg = false;
    }
    if(flg){
        cout << "Yes";
        return 0;
    }
     cout << "No";
}

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

using namespace std;

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

    int f[n+1];
    f[0] = 0;
    int nf = 1;

    int s = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        s = (s + a) % m;
        f[nf++] = s;
    }
    sort(f, f + nf);

    long long int r = 0;
    int c = 0;
    for (int i = 1; i < nf; i++) {
        if (f[i] == f[i - 1]) {
            c++;
        } else {
            c = 0;
        }
        r += c;
    }

    cout << r << endl;
    
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  int T[N+1];
  for (int i=1; i<=N; i++) cin >> T[i];
  int M;
  cin >> M;
  int P[M], X[M];
  for (int i=0; i<M; i++) cin >> P[i] >> X[i];

  int sum=0;
  for (int i=1; i<=N; i++) sum += T[i];
  for (int i=0; i<M; i++) {
    if (T[P[i]] < X[i]) {
      cout << sum + (X[i] - T[P[i]]) << endl;
    } else {
      cout << sum - (T[P[i]] - X[i]) << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void strprint(T e){ cout << to_string(e) << endl; }
template<typename T> void strprint(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void strprint(const vector<vector<T>>& vv){ for(const auto& v : vv){ strprint(v); } }
template<typename Iter> void strprint(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
const ll DVSR = 1e9+7;


int main(int argc, char const *argv[])
{
  ll N, K; cin >> N >> K;
  vector<ll> XS(N);
  REP(i, N) cin >> XS[i];
  ll res = 1e15;
  if (N == 1) {
    cout << abs(XS[0]) << endl;
    return 0;
  }
  REP(i, N-K+1) {
    auto width = XS[i+K-1] - XS[i];
    if (XS[i] >= 0) {
      width += abs(XS[i]);
    } else if (XS[i+K-1] <= 0) {
      width += abs(XS[i+K-1]);
    } else {
      width += min(abs(XS[i+K-1]), abs(XS[i]));
    }
    res = min(res, width);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class ASumOfInteriorAngles {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            out.println((n - 2) * 180);
        }

    }

    static class InputReader implements AutoCloseable {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public void close() {
        }

    }
}



Measured memory_bytes: 21460
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())
face='Yay!'
dlist=[e-d,e-c,e-b,e-a,d-c,d-b,d-a,c-b,c-a,b-a]
for i in range(0,10):
  if dlist[i]>k:
    face=':('
    break
  else:
    pass
print(face)

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

const int N = 1e5 + 10;
pair<int, int> a[N];

bool cmp(pair<int, int> a, pair<int, int> b) {
	return a.first - a.second > b.first - b.second;
}

int main() {
  	int n;
  	cin >> n;
  	for (int i = 0; i < n; i++) 
    	cin >> a[i].first;
  	for (int i = 0; i < n; i++)
      	cin >> a[i].second;
 	long long cnt1 = 0, cnt2 = 0;
  	for (int i = 0; i < n; i++) {
      	cnt1 += a[i].first;
      	cnt2 += a[i].second;
	}
	if (cnt1 < cnt2) 
      	cout << -1 << endl;
  	else {
    	sort(a, a + n, cmp);
		int st = 0, en = n - 1, ans = 0;
      	bool flag = true, flag2 = true;
      	while (st < en) {
        	if (a[en].first < a[en].second) {
        		if (flag2) {
                  	ans++;
                  	flag2 = false;
                }
              	if (flag) {
                  	ans++;
                	flag = false;
                }
              	if (a[en].second - a[en].first < a[st].first - a[st].second) {
                	a[st].first -= a[en].second - a[en].first;
                 	a[en].first = a[en].second;
                }
              	else {
                	a[en].first += a[st].first - a[st].second;
                  	a[st].first = a[st].second;
                }
              	if (a[st].first == a[st].second) {
                	st++;
                	flag = true;
                }
              	if (a[en].first == a[en].second) {
                  	en--;
                	flag2 = true;
                }
         	}
          	else
              	break;
        }
		cout << ans << endl;
    }
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i=0; i<N; i++) cin >> a[i];

    int now = a[0];
    int count = 0;

    for(;;){
        if(now == 2){
            count++;
            cout << count << endl;
            break;
        }
        if(count > N){
            cout << -1 << endl;
            break;
        }
        count++;
        now = a[now-1];
    }

    return 0;
}

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

void solve(string s){
    int n=s.size();
    int bit=1<<(n-1);
    ll ans =0;
    rep(i,bit){
        ll ret=0,pos=s[0]-'0';
        rep(j,n-1){
            if((i)&1<<j){
                ret+=pos;
                pos=s[j+1]-'0';
            }
            else{
                pos=10*pos+(s[j+1]-'0');
            }
        }
        ret+=pos;
        ans+=ret;
    }
    cout<<ans<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    string S;cin>>S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
#define ll long long 
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define REP(i,n) for (int i=0; i<(n); i++)
#define RREP(i,n) for (int i=(n-1); i>=0; i--)
#define ALL(x) x.begin(),x.end()
#define SZ(x) x.size()
#define MNTO(a,b) a = min(a,(__typeof__(a))(b))
#define MXTO(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define debug(x) cerr<<#x<<" is "<<x<<endl  
using namespace std;

// #define int ll

const int maxn = 3e5+5;
const int iinf = 1<<29;
const ll inf = 1ll<<60;
const ll mod = 1e9+7;


void GG(){cout<<"-1\n"; exit(0);}

ll inv (int b){
	if (b==1) return 1;
	return inv(mod%b) * (mod - mod/b) %mod;
}

ll pow(ll a, ll n, ll mod = 1e9+7){ 
	ll re=1;
	while (n>0){
		if (n&1) re = re*a % mod;
		a = a*a %mod;
		n>>=1;
	}
	return re;
}


main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n, m; cin>>n>>m;
    int c = (n-1)*(n-2)/2;
    if (m>c) GG();
    vector<pii> re;
    REP(i,n-1){
        re.pb({i+1, n});
    }
    REP(i, n-1){
        REP(j, i){
            if (c>m) {
                re.pb({i+1, j+1}); c--;
            }
        }
    }
    cout<<re.size()<<'\n';
    for (pii x : re){
        cout<<x.f<<' '<<x.s<<'\n';
    }

}	

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e14;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);

    ll A, B, Q;
    cin >> A >> B >> Q;

    vector<ll> S(A+2);
    vector<ll> T(B+2);
    vector<ll> X(Q);

    REP(i, A){
        cin >> S[i+1];
    }
    S[0] = -LINF;
    S[A+1] = LINF;
    REP(i, B){
        cin >> T[i+1];
    }
    T[0] = -LINF;
    T[B+1] = LINF;
    REP(i, Q){
        cin >> X[i];
    }

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

    REP(i, Q){
        vector<ll>::iterator iter_lower_S;
        iter_lower_S = lower_bound(S.begin(), S.end(),X[i]);
        ll idx_lower_S = distance(S.begin(), iter_lower_S); 
        ll SL, SR;
        if(S[idx_lower_S] == X[i]){
            SL = 0;
            SR = 0;
        }
        else{
            SL = S[idx_lower_S-1];
            SR = S[idx_lower_S];
        }

        vector<ll>::iterator iter_lower_T;
        iter_lower_T = lower_bound(T.begin(), T.end(),X[i]);
        ll idx_lower_T = distance(T.begin(), iter_lower_T); 
        ll TL, TR;
        if(T[idx_lower_T] == X[i]){
            TL = 0;
            TR = 0;
        }
        else{
            TL = T[idx_lower_T-1];
            TR = T[idx_lower_T];
        }

        ll ans1, ans2, ans3, ans4;
        ans1 = max(abs(SL-X[i]), abs(TL-X[i]));
        ans2 = max(abs(SR-X[i]), abs(TR-X[i]));
        ans3 = min(abs(SL-X[i]), abs(TR-X[i]))*2 + max(abs(SL-X[i]), abs(TR-X[i]));
        ans4 = min(abs(SR-X[i]), abs(TL-X[i]))*2 + max(abs(SR-X[i]), abs(TL-X[i]));

        cout << min(min(ans1, ans2), min(ans3, ans4)) << endl;
    }
    return 0;
}

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

signed main(){
    string s;
    int res = 0 , ans = 0 , carry = 1 , num[2019] = {} ;
    cin >> s;
    
    num[0] = 1;
    for(int i = s.size()-1 ;i >= 0 ;i-- ){
        res = (res + (s[i] - '0') * carry) % 2019;
        carry = (10 * carry) % 2019;
        ans += num[res];
        num[res]++;
    }
    
    cout << ans << endl;
    
    return(0);
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
long long x;
int main() {
    cin >> x;
    long long ccnt = x/11;
    long long ans = 2*ccnt;
    long long rest = x - (ccnt*11);
    if(rest <= 6 && rest > 0) {
        ans++;
    }else if(rest > 6 && rest < 11) {
        ans += 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
s=list(input())
X,Y=map(int,input().split())

if "T" in s:
    pass
else:
    if X==len(s) and Y==0:
        print("Yes")
    else:
        print("No")
    exit()


way=[[],[]]

switch=0
judge=True

lx=[]
ly=[0]
temp=0
for item in s:
    if item == "T":
        if judge:
            judge=False
            lx.append(temp)
        else:
            way[switch].append(temp)
        temp=0
        switch^=1
    else:
        temp+=1
way[switch].append(temp)

#print(lx)

for x in way[0]:
    temp_x=[]
    for item in lx:
        temp_x.append(item+x)
        temp_x.append(item-x)
    lx=temp_x[:]
    lx=list(set(lx))
#print(lx)

for y in way[1]:
    temp_y=[]
    for item in ly:
        temp_y.append(item+y)
        temp_y.append(item-y)
    ly=temp_y[:]
    ly=list(set(ly))
#print(ly)

if (X in lx) and (Y in ly):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 4148
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val Array(n, m) = in.readLine().split("\\s+").map(_.toInt)

    val cities = Array.ofDim[Int](n)

    for(_ <- 0 until m) {
      val Array(a, b) = in.readLine().split("\\s+").map(_.toInt)
      cities(a - 1) += 1
      cities(b - 1) += 1
    }

    for(i <- 0 until n) {
      out.println(cities(i))
    }

    out.flush()
  }
}


Measured memory_bytes: 27460
m = lambda: map(int,input().split())
N,M = m()
l = [tuple(m()) for _ in range(M)]
ans = []
l.sort(key=lambda x: x[1])
for i in range(M):
    if not ans or ans[-1]<l[i][0]:
        ans.append(l[i][1]-1)
print(len(ans))

Measured memory_bytes: 18244
#include<bits/stdc++.h>
using namespace std;
int v[55],c[55];
int main() {
	int n,zd=0,f=0;
	cin>>n;
	for(int i=0; i<n; i++) cin>>v[i];
	for(int i=0; i<n; i++) cin>>c[i];
	for(int i=0; i<n; i++) {
		if(v[i]-c[i]>0)
			zd+=v[i]-c[i];
	}
	cout<<zd;

	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from collections import defaultdict


def solve(N: int, S: "List[str]", P: "List[int]"):
    d = defaultdict(list)

    for i,(s,p) in enumerate(zip(S,P)):
        d[s].append((i,p))
    d = sorted(d.items())

    for k,v in d:
        v.sort(key=lambda x:x[1],reverse = True)
        for vv in v:
            print(vv[0]+1)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = [str()] * (N)  # type: "List[str]" 
    P = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        S[i] = next(tokens)
        P[i] = int(next(tokens))
    solve(N, S, P)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#include <bits/stdc++.h> 
using namespace std;  
long INF=1000000000000000;
int main() {
    long a,b,c,d;
    cin>>a>>b>>c>>d;
    
    if((abs(a-b)<=d && abs(b-c)<=d) || abs(a-c)<=d) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize, x: i64,
        l: [i64; n],
    }
    let mut c = 0;
    let mut acc = 0;
    for i in 0..n + 1 {
        if acc <= x {
            c += 1;
        }
        if i < n {
            acc += l[i];
        }
    }
    puts!("{}\n", c);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#include <stdio.h>

int main(void){
  int a,b,c,a1,b1,c1;
  scanf("%d %d %d",&a,&b,&c);
  a1=a;
  b1=b;
  c1=c;
  if(1<=a && a<=10000 && 1<=b && b<=10000 && 1<=c && c<=10000){
      if(a1<=b1 && a1<=c1 && c1<=b1){
          b=c1;
          c=b1;
      }
      if(b1<=a1 && b1<=c1){
          a=b1;
          if(a1<=c1){
              b=a1;
          }else{
              b=c1;
              c=a1;
          }
      }
      if(c1<=b1 && c1<=a1){
          a=c1;
          if(a1<=b1){
              b=a1;
              c=b1;
          }else{
              c=a1;
          }
      }
  }
  printf("%d %d %d\n",a,b,c);
  return 0;
}

Measured memory_bytes: 596
import sys
input = sys.stdin.buffer.readline

def main():
    n, c = map(int, input().split())
    D = [list(map(int, input().split())) for _ in range(c)]
    C_ = [list(map(int, input().split())) for _ in range(n)]
    C = [0]*n
    for i, c_ in enumerate(C_):
        c_ = [x-1 for x in c_]
        C[i] = c_

    X = [[0]*c for _ in range(3)]
    for i in range(n):
        for j in range(n):
            m = (i+j)%3
            X[m][C[i][j]] += 1

    #print(C)
    import itertools
    ans = 10**18
    for p in itertools.permutations(range(c), 3):
        temp = 0
        for i in range(3):
            for j in range(c):
                temp += D[j][p[i]]*X[i][j]
        ans = min(ans, temp)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9460
#include <cstdio>

int main(void)
{
	int n,hensai=100000;

	std::scanf("%d",&n);
	for (int i=0;i<n;++i){
		hensai = hensai*1.05;
		if (hensai%1000){
			hensai -= hensai%1000;
			hensai += 1000;
		}
	}

	std::printf("%d\n",hensai);
}

Measured memory_bytes: 2612
using System;

class Program
{
	static void Main(string[] args)
	{
		string[] strInput = Console.ReadLine().Split(' ');
		Int64 a = Int64.Parse(strInput[0]);
		Int64 b = Int64.Parse(strInput[1].Remove(1,1));

		Int64 result = a * b;

		String strResult = result.ToString();
		String strResult2;
		if (result >= 100) {
			strResult2 = strResult.Substring(0, strResult.Length - 2);
		}
		else
		{
			strResult2 = "0";
		}


		Console.WriteLine(strResult2);
		return;
	}
}

Measured memory_bytes: 27528
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<62)-1
#define MAX 1000000000
signed main(){
    int N,K; cin>>N>>K;
    int ans=0;
    REP(i,K,N+1){
        int X=(i-1)*i/2,Y=(2*N-i+1)*i/2;
        ans+=Y-X+1;
        ans%=MOD;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdlib>

int main()
{
    int N;
    
    std::cin >> N;
    
    int arr[10];
    
    int total = 0;
    
    for(int i = 0; i < N; i++)
    {
        std::cin >> arr[i];
        total += arr[i];
    }
    
    bool correct = true;
    
    for(int i = 0; i < N && correct; i++)
    {
        if(arr[i] >= total - arr[i])
            correct = false;
    }
    
    if(correct)
        std::cout << "Yes";
    else
        std::cout << "No";
}

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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

// これはAC。いちおう解説動画見る
int main() {
    int n;
    cin >> n;
    int a[26] = {0};
    for(int i = 0; i < 26; i++) {
        a[i] = 1e6;
    }

    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < 26; j++) {
            a[j] = min((int)a[j], (int)count(s.begin(), s.end(), j+'a'));
        }
    }

    string ans;
    for (int i = 0; i < 26; i++) {
        ans += string(a[i], i+'a');
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REP1(i, n) for (ll i = 1; i <= n; i++)
#define RREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define RREP1(i, n) for (ll i = n; i >= 1; i--)
#define FOR(i, a, b, c) for (ll i = a; i <= b; i += c)
#define RFOR(i, a, b, c) for (ll i = a; i >= b; i -= c)
#define MAX(a, b) (a > b ? a : b)
#define MIN(a, b) (a < b ? a : b)
#define INF 1145141919
typedef long long ll;

int main() {
    int n;
    scanf("%d", &n); getchar();
    int x = 0, max = 0;
    REP(i, n) {
        if (getchar() == 'I') x++;
        else x--;
        max = MAX(x, max);
    }
    printf("%d\n", max);
    return 0;
}

Measured memory_bytes: 128
n = int(input())
a = list(map(int, input().split()))
q = int(input())

asum = sum(a)
adic = {}

for i in a:
  if i in adic:
    adic[i] += 1
  else:
    adic[i] = 1


for i in range(q):
  b, c = map(int, input().split())
  if b in adic:
    if c not in adic:
      adic[c] = 0
    cnt = adic.pop(b)
    adic[c] += cnt
    asum += (c-b) * cnt
  print(asum)

Measured memory_bytes: 20872