akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using _TYPE = int;
typedef tree< _TYPE, null_type, less< _TYPE >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

int n;
const int MAX = 3002;
double inp[MAX];
bool vis[MAX][MAX];
double dp[MAX][MAX];
//dp[i][j]: maximum probability from beginning until index i(inclusive) and having heads more than tails

double solve(int index, int headCount) {
    //We finished processing all the given coins
    if(index == n) {
        /*If number of head coins we have so far is more than the number of tail coins, return 1,
        as we multiply this probability by 1, so not affect overall probability */
        if(headCount > n - headCount)
            return 1.0;
        /*Else, this means head count is less than or equal to the number of tail coins we have, 
        so this path is incorrect and w don't consider it, so return 0 to decrease the probability
        of this path*/
        return 0.0;
    }
    /*
    We want to take heads as much as possible to have theit count more than the tails.
    We have two options:
        1-The input given us probability of having the coi at index (i) to be head, So, we 
        will try leaving the current coin as it is, (leave it head) and go to next coin,
        so leaving this coin as it is will increase the headCount by 1.

        2-We will have a tail at this coin, so this means headCount will NOT increase as now we are trying to 
        make the current coin as a tail, ans the total probability will be multiplied by (1 - prob[index])
        as this is the probability of making this coin as a tail.
    */
    if(vis[index][headCount])
        return dp[index][headCount];
    vis[index][headCount] = true;
    double &rt = dp[index][headCount];
    //Option 1
    rt = solve(index + 1, headCount + 1) * inp[index];
    //Option 2
    rt += solve(index + 1, headCount) * (1.0 - inp[index]);
    return rt;
}

int main() {
    IO;
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> inp[i];
    cout << fixed << setprecision(10) << solve(0, 0);
    return 0;
}

Measured memory_bytes: 77952
from sys import stdin
n = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0

a.sort(reverse = True)

for x in range(n):
   if x % 2 == 0:
      ans += a[x]
   else:
      ans -= a[x]

print(ans)

Measured memory_bytes: 9188
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>//pair
#include<cmath>//abs,sqrt
#include<cstring>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
const int INF=1e+9;
const ll INFLL=1e+17;
int main(){
  int n;cin>>n;
  int a[110];
  rep(i,n) cin>>a[i];
  bool f[8];
  fill(f,0);
  int cnt=0,cnt2=0;
  rep(i,n){
    if(a[i]<400&&!f[0]){
      cnt++;
      f[0]=true;
    }
    else if(400<=a[i]&&a[i]<800&&!f[1]){
      cnt++;
      f[1]=true;
    }
    else if(800<=a[i]&&a[i]<1200&&!f[2]){
      cnt++;
      f[2]=true;
    }
    else if(1200<=a[i]&&a[i]<1600&&!f[3]){
      cnt++;
      f[3]=true;
    }
    else if(1600<=a[i]&&a[i]<2000&&!f[4]){
      cnt++;
      f[4]=true;
    }
    else if(2000<=a[i]&&a[i]<2400&&!f[5]){
      cnt++;
      f[5]=true;
    }
    else if(2400<=a[i]&&a[i]<2800&&!f[6]){
      cnt++;
      f[6]=true;
    }
    else if(2800<=a[i]&&a[i]<3200&&!f[7]){
      cnt++;
      f[7]=true;
    }
    else if(3200<=a[i]) cnt2++;
  }
  if(cnt==0) prin2(1,cnt2); 
  else prin2(cnt,cnt+cnt2);


    
  

  return 0;
}


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

using namespace std;
long long a[100010],sum = 0,ans = 1;
int main(){
	int i,n;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a[i];
		sum += a[i];
	}
	sort(a,a+n);
	for(i=n-1;i>=0;i--){
		sum -= a[i];
		if(2*sum>=a[i]) ans++;
		else break;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
///*
#include<iostream>
using namespace std;

int main() {
	int antennas[5], limit;
	int distance;
	bool connect = true;

	//===input
	for (int number = 0; number < sizeof(antennas) / sizeof(int); number++) {
		cin >> antennas[number];
	}
	cin >> limit;

	//===process

	if(antennas[0] + limit < antennas[sizeof(antennas) / sizeof(int) - 1]){
		connect = false;
	}

	//===output

	connect ? cout << "Yay!" << endl : cout << ":(" << endl;
	return 0;
}
//*/

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

int main(){
	int N, i, j, k;
	scanf("%d", &N);
	vector<vector<int>> S(N, vector<int>(N, 0));
	for(i = 0; i < N; i++){
		for(j = 0; j < N; j++){
			scanf("%1d", &S[i][j]);
		}
	}
	int ans = -1;
	for(k = 0; k < N; k++){
//		printf("k = %d\n", k);
		vector<vector<int>> V(N, vector<int>(0));
		V[0].push_back(k);
		vector<int> used(N, 0);
		used[k] = 1;
		int l = 0;
		while(1){
//			printf("l = %d\n", l);
			int f = 1;
			for(i = 0; i < N; i++){
				if(used[i] == 0){
					f = 0;
				}
			}
			if(f == 1){
				break;
			}
			for(i = 0; i < V[l].size(); i++){
				for(j = 0; j < N; j++){
					if(S[V[l][i]][j] == 1 && used[j] == 0){
						V[l + 1].push_back(j);
						used[j] = 1;
					}
				}
			}
			l++;
		}
		vector<int> id(N);
		for(i = 0; i <= l; i++){
			for(j = 0; j < V[i].size(); j++){
				id[V[i][j]] = i;
			}
		}
/*		for(i = 0; i < N; i++){
			printf("id[%d] = %d\n", i, id[i]);
		}
*/		int f2 = 1;
		for(i = 0; i < N; i++){
			for(j = 0; j < N; j++){
				if(S[i][j] == 1){
					if(abs(id[i] - id[j]) != 1){
						f2 = 0;
					}
				}
			}
		}
		if(f2 == 1){
			ans = max(ans, l + 1);
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 384
fun main(args: Array<String>) {
    val alphabets = arrayOf("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z")
    println(alphabets[alphabets.indexOf(readLine()!!)+1])
}

Measured memory_bytes: 32232
import sys
sys.setrecursionlimit(10**7)

n=int(input())
A=[[] for i in range(n)]
for i in range(n-1):
  a,b = map(int,input().split())
  a,b = a-1,b-1
  A[a].append([b,i])
    
ans = [0]*(n-1)

def col(now,color):
  c=1
  for (b,j) in A[now]:
    if c==color:
      c+=1
    ans[j]=c
    col(b,c)
    c+=1
col(0,0)
print(max(ans))
for a in ans:
  print(a)

Measured memory_bytes: 71000
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

// #define DEBUG

void printarray(int n, int a[])
{
    for (int i = 1; i < n + 1; i++)
    {
        cout << a[i];
        if (i != n)
            cout << " ";
    }
    cout << endl;
}

int cycleanalysis(int n, int a[])
{
    int pos, ret, next;
    pos = 0, ret = 0;
    for (int i = 1; i < n + 1; i++)
    {
        pos = i;
        while (a[pos] != pos)
        {
            ret += (a[pos] + a[a[pos]]);
            next = a[pos];
            swap(a[pos], a[a[pos]]);
            pos = next;
        }
    }

    return ret;
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int q, op, x;
    string key;
    cin >> q;
    map<string, int> mp;
    for (int i = 0; i < q; i++)
    {
        cin >> op >> key;
        if (op == 0)
        {
            cin >> x;
            if (mp.count(key))
                mp[key] = x;
            else
                mp.insert(make_pair(key, x));
        }
        else if (op == 1)
        {
            cout << (mp.count(key) ? mp.at(key) : 0) << endl;
        }
        else if (op == 2)
        {
            mp.erase(key);
        }
    }

    return 0;
}

// getline(cin,s);
// a = strtok(s, ",");  ","で分解
// for (int i = 0; i < n; i++)


Measured memory_bytes: 27804
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
	int n;
	bool c=false;
	cin>>n;
	int a[n+1],b[n+1];
	cin>>a[1]>>b[1]>>a[2]>>b[2];
	for(int i=3;i<=n;i++){
		cin>>a[i]>>b[i];
		if(a[i-2]==b[i-2]&&a[i-1]==b[i-1]&&a[i]==b[i]) {
			c=true;
		}
	}
	if(c){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}

	return 0;
}


Measured memory_bytes: 3636
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = Integer.parseInt(sc.next());
        }
        
        Integer[] l = new Integer[n];
        l[0] = a[0];
        int length = 1;
        for(int i = 1; i < n; i++){
            if(l[length-1] < a[i]){
                l[length] = a[i];
                length++;
            }else{
                int j = lowerBound(l, 0, length, a[i]);
                l[j] = a[i];
            }
        }
        System.out.println(length);
    }
    
    static int lowerBound(Integer[] a, int from, int to, int key){
        return ~Arrays.binarySearch(a, from, to, key, (x, y) -> (x.compareTo(y) >= 0) ? 1 : -1);
    }
}


Measured memory_bytes: 72820
<?php

fscanf(STDIN, "%d %d", $n, $q);
$G = [];
for ($i = 0; $i < $n - 1; ++$i) {
    fscanf(STDIN, "%d %d", $a, $b);
    --$a;
    --$b;
    $G[$a][] = $b;
    $G[$b][] = $a;
}

$ans = array_fill(0, $n, 0);
for ($i = 0; $i < $q; ++$i) {
    fscanf(STDIN, "%d %d", $a, $b);
    --$a;
    $ans[$a] += $b;
}

function dfs($v, $p = -1) {
    global $G;
    global $ans;

    foreach ($G[$v] as $next_v) {
        if ($next_v === $p) continue;
        $ans[$next_v] += $ans[$v];
        dfs($next_v, $v);
    }
}

dfs(0);

echo implode(' ', $ans);


Measured memory_bytes: 154104
//* AuThOr GaRyMr *//
#include<bits/stdc++.h>
#define rb(a,b,c) for(LL a=b;a<=c;++a)
#define rl(a,b,c) for(LL a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB(a) push_back(a)
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int main(){
	int l,r;
	cin>>l>>r;
	if(r-l+1>=2019){
		cout<<0;
		return 0;
	}
	int tot=r-l;
	LL sum=INF;
	rb(i,l,r){
		rb(j,i+1,r){
			sum=min(sum,(i*j)%2019);
		}
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 384
#include <cmath>
#include <cstdio>
#include <vector>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int N, M, Q, a[100009], b[100009], v[100009], p[100009], x[100009], y[100009], ans[100009]; long long z[100009], ss[400009], offset[100009][333];
int cqx[100009], cqy[100009], cvx[100009], cvy[100009], cs[400009], as[400009];
int main() {
	scanf("%d %d %d", &N, &M, &Q);
	vector<int> cp(2 * (M + Q));
	for (int i = 0; i < M; i++) {
		scanf("%d %d %d", &a[i], &b[i], &v[i]), p[i] = i;
		cp[i * 2] = --a[i];
		cp[i * 2 + 1] = b[i];
	}
	for (int i = 0; i < Q; i++) {
		scanf("%d %d %lld", &x[i], &y[i], &z[i]), z[i]--, ans[i] = -1;
		cp[(i + M) * 2] = --x[i];
		cp[(i + M) * 2 + 1] = y[i];
	}
	sort(cp.begin(), cp.end());
	cp.erase(unique(cp.begin(), cp.end()), cp.end());
	sort(p, p + M, [](int i, int j) { return v[i] < v[j]; });
	for (int i = 0; i < Q; i++) {
		cqx[i] = lower_bound(cp.begin(), cp.end(), x[i]) - cp.begin();
		cqy[i] = lower_bound(cp.begin(), cp.end(), y[i]) - cp.begin();
	}
	int C = cp.size() - 1, B = sqrt(M);
	for (int i = 0; i < B; i++) {
		int pl = i * M / B, pr = (i + 1) * M / B;
		for (int j = pl; j < pr; j++) {
			as[lower_bound(cp.begin(), cp.end(), a[p[j]]) - cp.begin()]++;
			as[lower_bound(cp.begin(), cp.end(), b[p[j]]) - cp.begin()]--;
		}
		cs[0] = as[0];
		for (int j = 0; j < C; j++) cs[j + 1] = cs[j] + as[j + 1];
		for (int j = 0; j < C; j++) ss[j + 1] = ss[j] + 1LL * cs[j] * (cp[j + 1] - cp[j]);
		for (int j = 0; j < Q; j++) offset[j][i + 1] = ss[cqy[j]] - ss[cqx[j]];
	}
	for (int i = 0; i < B; i++) {
		int pl = i * M / B, pr = (i + 1) * M / B;
		vector<int> scp(2 * (pr - pl) + 2); scp[1] = N;
		for (int j = pl; j < pr; j++) {
			scp[(j - pl) * 2 + 2] = a[p[j]];
			scp[(j - pl) * 2 + 3] = b[p[j]];
		}
		sort(scp.begin(), scp.end());
		scp.erase(unique(scp.begin(), scp.end()), scp.end());
		int sc = scp.size() - 1;
		fill(cs, cs + sc + 1, 0);
		vector<int> vs;
		for (int j = 0; j < Q; j++) {
			if (offset[j][i] <= z[j] && z[j] < offset[j][i + 1]) {
				vs.push_back(j);
			}
		}
		int vc = vs.size();
		for (int j = 0; j < vc; j++) {
			cvx[j] = lower_bound(scp.begin(), scp.end(), x[vs[j]] + 1) - scp.begin() - 1;
			cvy[j] = lower_bound(scp.begin(), scp.end(), y[vs[j]] + 1) - scp.begin() - 1;
		}
		for (int j = pl; j < pr; j++) {
			int ptl = lower_bound(scp.begin(), scp.end(), a[p[j]]) - scp.begin();
			int ptr = lower_bound(scp.begin(), scp.end(), b[p[j]]) - scp.begin();
			for (int k = ptl; k < ptr; k++) cs[k]++;
			for (int k = 0; k < sc; k++) ss[k + 1] = ss[k] + 1LL * cs[k] * (scp[k + 1] - scp[k]);
			for (int k = 0; k < vc; k++) {
				long long val = 1LL * cs[cvx[k]] * (scp[cvx[k] + 1] - x[vs[k]]) + 1LL * cs[cvy[k]] * (y[vs[k]] - scp[cvy[k]]) + ss[cvy[k]] - ss[cvx[k] + 1];
				if (cvx[k] == cvy[k]) val = 1LL * cs[cvx[k]] * (y[vs[k]] - x[vs[k]]);
				if (val + offset[vs[k]][i] > z[vs[k]] && ans[vs[k]] == -1) ans[vs[k]] = v[p[j]];
			}
		}
	}
	for (int i = 0; i < Q; i++) printf("%d\n", ans[i]);
	return 0;
}

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

#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())
using namespace std;

int main() {
	long int x,mo=100;
	cin >> x;
	int y=0;
	while (mo < x) {
		mo *= 1.01;
		y++;
	}
	cout << y;

}

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

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

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <climits>
using namespace std;

int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a>b?a:b;}
int mv[4][2]={{0,-1},{1,0},{0,1},{-1,0}};
int map[100][100],n,m,N,M;
bool B[100][100];
int q[15000][2];
//unsigned 
int dis[100][100];
void fill(){
    int l=0,r=0;
    q[0][0]=1;q[0][1]=1;B[1][1]=true;
    dis[1][1]=2;
    while(l<=r){
        int x=q[l][0],y=q[l][1];
        int z=dis[x][y];
        for(int i=0;i<4;i++){
            int xx=x+mv[i][0],yy=y+mv[i][1];
            if(map[xx][yy]==-1)continue;
            if(dis[xx][yy]>z+1){
                dis[xx][yy]=z+1;
                if(!B[xx][yy]){
                    B[xx][yy]=true;
                    r++;
                    q[r][0]=xx;
                    q[r][1]=yy;
                }
            }
        }
        l++;
        B[x][y]=false;
    }
}
int main(){
    while(scanf("%d %d",&m,&n),n*m){
        N=2*n+1;M=2*m+1;
        /*
        memset(B,0,sizeof(bool)*10000);
        memset(map,0,sizeof(int)*10000);
        memset(dis,127,sizeof(unsigned int)*10000);
        */
        for(int i=0;i<100;i++)
            for(int j=0;j<100;j++){
                B[i][j]=0;
                map[i][j]=0;
                dis[i][j]=100000;
            }
        for(int i=0;i<N;i++){
            map[i][0]=-1;
            map[i][M-1]=-1;
        }
        for(int i=0;i<M;i++){
            map[0][i]=-1;
            map[N-1][i]=-1;
        }
        int x=1;
        for(int i=0;i<n;i++){
            int y=1;
            if(i){
                for(int j=0;j<m;j++,y+=2){
                    int z;
                    scanf("%d",&z);
                    map[x][y]=-z;
                }
                x++; 
            }
            y=2;
            for(int j=0;j<m-1;j++,y+=2){
                int z;
                scanf("%d",&z);
                map[x][y]=-z;
            }
            x++;
        }
        for(int i=0;i<n;i++)
            for(int j=0;j<m;j++)
                map[i*2][j*2]=-1;
        fill();
        int ans=dis[N-2][M-2]/2;
        if(ans>=50000)ans=0;
        printf("%d\n",ans);
/*        
        printf("%d %d\n",N,M);
        for(int i=0;i<N;i++){
            for(int j=0;j<M;j++){
                //if(dis[i][j]>=20000)dis[i][j]=0;
                //printf("%d ",dis[i][j]);
                printf("%d ",map[i][j]*-1);
            }
            printf("\n");
        }
*/ 
    }
    return 0;
}

Measured memory_bytes: 1136
import java.util.Scanner;

public class Main {
	
	static Scanner scan = new Scanner(System.in);
	
	public static void main(String[] args) {
		int k  = scan.nextInt();
		int x = scan.nextInt();
		
		
		for(int i = x-k+1; i < x+k; i++) {
			System.out.print(i);
			if(i < x+k) {
				System.out.print(" ");
			}
		}
		
	}

}


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


char GetChar(int i) {
   return (char)(i+97);
}

int main(void) {
   ll N;
   cin>>N;
   vector<int> b(N);
   rep(i,N) cin>>b[i];
   vector<int> ans;
   while(1) {
      ll len = b.size();
      if (!len) break;
      bool flag = false;
      for (int i = len-1;i>=0;i--) {
         if (b[i] == i+1) {
            auto itr = b.begin()+i;
            itr = b.erase(itr);
            ans.push_back(i+1);
            flag = true;
            break;
         }
      }
      if (!flag) break;
   }
   if (b.size()) cout<<"-1"<<endl;
   else {
      for(int i = ans.size()-1;i>=0;i--) {
         cout<<ans[i]<<endl;
      }
   }





   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>

int main() {
  int N;
  std::cin >> N;
  std::vector<std::string> S(N);
  for(auto &s:S)
    std::cin >> s;
  int start_b = 0;
  int end_a = 0;
  int start_b_end_a = 0;
  int include_ab = 0;
  for(auto &s:S){
    std::string ss = s;
    while(true) {
      int pos=ss.find("AB");
      if(pos==std::string::npos)break;
      ss = ss.substr(pos+2,ss.size()-pos-2);
      include_ab++;
    }
    if(s[0]=='B' && s[s.size()-1]=='A')
      start_b_end_a++;
    else if(s[0]=='B')
      start_b++;
    else if(s[s.size()-1]=='A')
      end_a++;

  }
  int ans = include_ab;
  if(start_b_end_a >0 && start_b == 0 && end_a == 0)
    ans += start_b_end_a - 1;
  else
    ans += start_b_end_a + std::min(start_b, end_a);
  std::cout << ans << std::endl;
  return 0;
}

/*
9
BEWPVCRWH
ZZNQYIJX
BAVREA
PA
HJMYITEOX
BCJHMRMNK
BP
QVFABZ
PRGKSPUNA
4
*/

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    string S;
    cin >> S;
    if(S[2] == S[3] && S[4] == S[5]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
def g_longest_path(N, M, Edges):
    """
    N頂点M辺の有向グラフGが与えられる。Gは有向閉路を含まない。
    Gの有向パスのうち、最長のものについてその長さを求めよ。
    有向パスの長さとは、有向パスに含まれる辺の本数のことをいう。
    """
    import sys
    sys.setrecursionlimit(10**6)

    # 隣接リストでグラフを持つ(0-based)
    graph = [[] for _ in range(N)]
    for x, y in Edges:
        graph[x - 1].append(y - 1)

    # メモ化再帰
    # ある頂点vから辿っていけるパスの長さは、vに着くまでにどのようにパスを
    # 辿ってきたかと無関係(有向閉路がないため)なので、この方法が使える
    def memorized_recursive(v):
        if dp[v] != -1:
            return dp[v]  # 頂点vはすでに更新済み

        ret = 0
        # 頂点vから1つ辺を通って行ける頂点の集合に対して同じ計算を行う
        for nv in graph[v]:
            ret = max(ret, memorized_recursive(nv) + 1)
        dp[v] = ret  # メモに追加
        return ret

    ans = 0
    dp = [-1] * N  # dp[v]: ノードvを始点としたときの、Gの有効パスの長さの最大値
    # 各頂点に対して調べる
    for v in range(N):
        ans = max(ans, memorized_recursive(v))
    return ans

N, M = [int(i) for i in input().split()]
Edges = [[int(i) for i in input().split()] for j in range(M)]
print(g_longest_path(N, M, Edges))

Measured memory_bytes: 85272
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#define fast ios_base::sync_with_stdio(false)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n,c) v.clear(),v.resize(n,c)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
vi a,f;ll n,k;
int check(ll x){
	ll i,c=0;
	for(i=0;i<n;i++){
		if(a[i]*f[i]>x){
			ll b=x/f[i];
			if(a[i]<b) return 0;
			c+=a[i]-b;
		}
	}if(c<=k) return 1;
	return 0;
}
int main(){
	ll l=0,r=1e12+5,i,m,c=0;
	cin>>n>>k;
	a.resize(n),f.resize(n);
	for(i=0;i<n;i++) cin>>a[i];
	for(i=0;i<n;i++) cin>>f[i];
	sort(all(a));sort(rall(f));
	while(c++<60){
		m=(l+r)/2;
		if(check(m)){
			if(!check(m-1)) break;
			r=m;
		}else l=m;
	}cout<<m<<endl;
}


Measured memory_bytes: 3328
package main

import "fmt"

func main() {
	var (
		a, b int
		s    string
	)
	fmt.Scan(&a, &b, &s)

	for _, r := range s[:a] {
		if r == '-' {
			fmt.Println("No")
			return
		}
	}
	if s[a] != '-' {
		fmt.Println("No")
		return
	}
	for _, r := range s[a+1:] {
		if r == '-' {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define vl vector<ll>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
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; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.first+a.second > b.first+b.second; }
int a[100001];

signed main() {
  SS(int,n);
  ll sum=0;
  rep(i,n){
      SS(int,A);
      a[A]++;
        sum+=A;
  }
  SS(int,q);
  rep(i,q){
      SS(int,b,c);
      sum+=(c-b)*a[b];
      p(sum);
      a[c]+=a[b];
      a[b]=0;
  }
}

Measured memory_bytes: 3928
using System;

namespace rensyuu1
{

    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            string[] vs = str.Split(new char[] { ' ' });
            int a = int.Parse(vs[0]);
            int b = int.Parse(vs[1]);
            if (b > a)
            {
                Console.WriteLine("a < b");
            }
            else if (a > b)
            {
                Console.WriteLine("a > b");
            }
            else
            {
                Console.WriteLine("a == b");
            }
        }
    }
}


Measured memory_bytes: 15940
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<60;
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; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;
const int MOD = 1000000007;

const int max_v = 2*100000;

int main(){
    int N; cin >> N;
    string X; cin >> X;
    vector<int> x(N);
    rep(i,N) x[i] = X[i] - '0';
    int pop_count = 0;
    rep(i,N) pop_count += x[i];

    vector<int> ans(N);
    rep(b,2){
        int now_pop_count = pop_count;
        if (b == 0) now_pop_count++; else now_pop_count--;
        if (now_pop_count == 0) continue;
        int total = 0;
        rep(i,N){
            total = (total*2)%now_pop_count;
            total += x[i];
        }
        int now_val = 1;
        for (int i = N-1; i >= 0; i--){
            if (x[i] == b){
                int count = 0;
                int t = total;
                if (b == 0){
                    t = (t+now_val)%now_pop_count;
                }
                else{
                    t = (t-now_val+now_pop_count)%now_pop_count;
                }
                count++;
                while (t > 0){
                    t = t % __builtin_popcount(t);
                    count++;        
                }
                ans[i] = count;
            }
            now_val = (now_val*2)%now_pop_count;
        }
    }

    rep(i,N) cout << ans[i] << endl;

}


Measured memory_bytes: 5200
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int hum[1000001];

int main()
{	
	memset(hum,0,sizeof(hum));
	int count = 1;
	REP(i,1,1000001)
	{
		int temp = i;
		while(temp != 1)
		{
			if(temp%2 == 0) temp /= 2;
			else if(temp%3 == 0) temp /= 3;
			else if(temp%5 == 0) temp /= 5;
			else break;
		}

		if(temp == 1)
		{
			hum[i] = count;
			count++;
		}
		else
		{
			hum[i] = hum[i-1];
		}
	}
	
	int n,m;
	while(cin >> n && n)
	{
		cin >> m;	
		cout << hum[m] - hum[n-1]<< endl;
	}
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define vi vector<int>

int main()
{
	int l, r;
	cin >> l >> r;
	int m=2019;
	int ans=2019;
	rep(i, m)rep(j, m)
	{
		if(l+i<r-j)
		{
			ans=min(ans, (l+i)%m*((r-j+m)%m)%m);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define int long long int
#define float double
#define pb push_back
#define FF first
#define SS second
#define N 100005
#define MOD 1000000007
#define fn(i,n) for(int i=0;i<n;i++)
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define pii pair<int,int>
#define mp make_pair
#define INF 9223372036854775807
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

int n,m;
vector<int> adj[N];
int dp[N];
int ans=0;

int dfs(int node)
{
    if(dp[node]!=-1) return dp[node];
    dp[node]=0;
    for(auto child:adj[node]) dp[node]=max(dfs(child)+1,dp[node]);
    ans=max(ans,dp[node]);
    return dp[node];
}


signed main() 
{
    speed;
    //freopen("input.tXt","r",stdin);
    //freopen("output.tXt","w",stdout);

    cin>>n>>m;
    memset(dp,-1,sizeof(dp));
    fn(i,m)
    {
        int u,v;
        cin>>u>>v;
        adj[u].pb(v);
    }

    for(int i=1;i<=n;i++)
    {
        if(dp[i]==-1) dfs(i);
    }
    cout<<ans<<endl;
}   

Measured memory_bytes: 11868
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int top,S[1000];

void push(int x){
	
	S[++top]=x;
}
int pop(){
	top--;
	return S[top+1];

}
int main(void)
{
	int a,b;
	top=0;
	char s[100];
	while(scanf("%s",s)!=EOF){
		if(s[0]=='+'){
			a=pop();
			b=pop();
			push(a+b);
		}
		else if(s[0]=='-'){
			b=pop();
			a=pop();
			push(a-b);
		}
		else if(s[0]=='*'){
			a=pop();
			b=pop();
			push(a*b);
		}
			else{push(atoi(s));}
	}
	printf("%d\n",pop());
	return 0;
}


Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
long long n,i,c[200009],d[200009],e[200009];
int main()
{
    for(d[0]=1,scanf("%lld",&n); n--; ++i,scanf("%lld",c+i),c[i]==c[i-1]?--i:e[c[i]]=d[i]=(d[i-1]+d[i]+e[c[i]])%1000000007);
    printf("%lld\n",d[i]),exit(0);
}

Measured memory_bytes: 4992
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;
ll MOD = 1000000007;

// a^p
// 2^3 = 2 * 2^2
// 2^2 = 2 * (2^1)
// 2^1 = 2
ll modpow(ll a, ll p, ll mod) {
  if (p == 0) return 1;

  if (p % 2 == 0) {
    ll half = modpow(a, p / 2, mod) % mod;
    return half * half % mod;
  } else {
    return a * modpow(a, p - 1, mod) % mod;
  }
}

// nCa を求める
ll modCombination(ll n, ll a, ll mod) {
  if (n - a < a) {
    return modCombination(n, n - a, mod);
  }

  ll denominator = 1;  // 分母
  ll numerator = 1;    // 分子

  for (ll i = 0; i < a; i++) {
    denominator *= a - i;
    numerator *= n - i;
    denominator %= mod;
    numerator %= mod;
  }

  return numerator * modpow(denominator, mod - 2, mod) % mod;
}

int main() {
  ll X, Y;
  cin >> X >> Y;

  ll ans = 0;
  // X = a + 2b;
  // Y = 2a + b;
  // (i + 1, j + 2) という動き方を全探索
  for (ll a = 0; a < X + 1; a++) {
    // 連立方程式を解く
    if ((X - a) % 2 != 0) continue;
    if ((Y - 2 * a) != ((X - a) / 2)) continue;

    ll b = Y - 2 * a;
    ans += modCombination(a + b, a, MOD);
  }

  cout << ans % MOD << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;


int main(){
    int h, w;
    cin >> h >> w;
    string s[h];
    rep(i, h) cin >> s[i];
    bool flag = true;
    rep(y, h){
        rep(x, w){
            bool u = true, d = true, l = true, r = true;
            if (s[y][x] == '#'){
                if (x > 0 && s[y][x - 1] == '.') l = false;
                if (x < w - 1 && s[y][x + 1] == '.') r = false;
                if (y > 0 && s[y - 1][x] == '.') u = false;
                if (y < h - 1 && s[y + 1][x] == '.') d = false;
            }
            flag &= (u || d || l || r);
        }
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

using namespace std;

#define int 		long long
#define endl 		"\n"
#define mod 		1000000007
#define inf 		1e18
#define IOS 		ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

int32_t main() {

	IOS;

	int n;
	cin >> n;

	vector<int> dp(n + 1, 1);
	dp[0] = dp[1] = dp[2] = 0;

	for (int i = 3; i <= n; i++) {
		for (int j = i - 3; j >= 3; j--) {
			dp[i] = (dp[i] + dp[j]) % mod;
		}
	}

	cout << dp[n];

	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000

//using namespace atcoder;
using namespace std;

int main(void){
  ll a, b, x;
  cin >> a >> b >> x;
  
  if (x >= a && x <= a + b)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
    

  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int n,mp[16][16];

void saiki(int x,int y,int num){
  if(num>n*n)return;

  if(y>=n)saiki(x,0,num);
  else if(x<0) saiki(n-1,y,num);
  else if(x>=n)saiki(0,y,num);
  else if(mp[y][x]!=0)saiki(x-1,y+1,num); 
  else mp[y][x]=num,saiki(x+1,y+1,num+1);
}

int main(){
  while(cin>>n,n){
    memset(mp,0,sizeof(mp));
    saiki(n/2,n/2+1,1);

    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++)printf("%4d",mp[i][j]);
      cout <<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define MOD (int)1e9+(int)7
#define INF 2147483647
typedef long long ll;
typedef unsigned long long ull;
//dark power
//#define int ll
//define Error、大抵は、セミコロン忘れとか、Defineは関係ない
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
        int n=0;cin>>n;
        int a,b=0;
        cin>>a;
        rep(i,n-1){
            cin>>b;
            a=__gcd(a,b);
        }
        cout<<a<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

const ll mod = 1e9+7;
const ld error = 2e-6;
const ld PI = acosl(-1); //const ld PI = acosl(-1)

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define eq(x, y) (fabs((x)-(y))<error)
#define bt(i) (1LL<<(i))

#define debug(x) cerr<<#x<<" = "<<(x)<<"\n"
#define hoise cerr<<"hoise - "<<__LINE__<<"\n"
#define tham getchar()
mt19937 rng((unsigned)chrono::system_clock::now().time_since_epoch().count()); //mt199937_64 for ll
//mt19937 rng(199);

inline ll MOD(ll x, ll m = mod){
    ll y = x % m;
    return (y >= 0) ? y: y+m;
}

const int inf = 1e9;
const ll infl = 1061109567;
const int nmax = 1e5+10;

#define contents(T, c) ostream_iterator<T>(cerr, c)
///===========================================  template  =======================================================

vector<int> adj[nmax];
ll val[nmax];

bool ok = true;
ll dfs(int root, int par){
    if(adj[root].size() == 1){
        ll ret = val[root];
        val[root] = 0;
        return ret;
    }
    ll below = 0;
    ll maxbelow = 0;
    for(int u : adj[root]){
        if(u == par) continue;
        ll open = dfs(u, root);
        below += open;
        maxbelow = max(maxbelow, open);
    }

    ll maxuse = ((maxbelow > below/2)? below - maxbelow : below/2);
    ll used = below - val[root];

//    tham;
//    debug(root);
//    debug(used);
//    debug(maxuse);
//    debug(below);
//    debug(maxbelow);


    if(used < 0 || used > maxuse) ok = false;

    return val[root] - used;
}

int main(){
    FASTIO;

    int n;
    cin>>n;
    for(int i = 1; i<= n; i++) cin>>val[i];
    for(int i = 1; i<n; i++){
        int u, v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    if(n == 2){
        if(val[1] == val[2]){
            cout<<"YES\n";
        }
        else{
            cout<<"NO\n";
        }
        return 0;
    }

    int root = 0;
    for(int i = 1; i<=n; i++){
        if(adj[i].size() != 1) root = i;
    }

    ll open = dfs(root, -1);
    ok &= (open == 0);

    if(ok){
        cout<<"YES\n";
    }
    else{
        cout<<"NO\n";
    }

    return 0;
}
/*
5
1 2 1 1 2
2 4
5 2
3 2
1 3
*/


Measured memory_bytes: 17004
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>

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

    if(s[2]==s[3]&&s[4]==s[5]){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
ll rand_int(ll l, ll r) //[l, r]
{
    static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
    return uniform_int_distribution<ll>(l, r)(gen);
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
int main()
{
    int n;
    cin>>n;
    if(n==1)
    {
        cout<<"1\n0\n";
    }
    else if(n==2)
    {
        cout<<2<<'\n'<<0<<'\n'<<"11\n";
    }
    else{
        cout<<n-1<<'\n';
        cout<<"00\n";
        for(int i=1;i<=n-2;i++)
        {
            cout<<'0';
            for(int j=0;j<i;j++) cout<<'1';
            cout<<'0';
            cout<<'\n';
        }
    }
}


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

using namespace std;

int main()
{
	string c1, c2;
	cin >> c1;
	cin >> c2;
	reverse(c1.begin(), c1.end());
	if (c1 == c2) {
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    int a[n],b[n];
    for(int i=0;i<n;i++)
        cin >> a[i];
    for(int i=0;i<n;i++)
        b[a[i]-1]=i+1;
    for(int i=0;i<n;i++)
        cout << b[i] << " ";
}


Measured memory_bytes: 1536
import sys
def fastio():
    from io import StringIO
    from atexit import register
    global input
    sys.stdin = StringIO(sys.stdin.read())
    input = lambda : sys.stdin.readline().rstrip('\r\n')
    sys.stdout = StringIO()
    register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

INF = 10**20
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
# from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br

n, = I()
print((n / 3) ** 3)

Measured memory_bytes: 3316
#include <iostream>

typedef long long ll;

using namespace std;

int main(){
    ll X, Y;
    int cnt = 1;
    ll tmp;
    cin >> X >> Y;
    tmp = X;
    while(true){
        X *= 2;
        if(X > Y) break;
        cnt++;
    }
    cout << cnt << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <functional>
#include <set>
#define DB cerr<<"D"<<endl
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<double,int>;
const ll M = 1e9+7;
void add(ll& x, ll y) {x+=y; x%=M;}
void chmax(ll& x, ll y) {if (x<y) x=y;}
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}

int main() {
  int n,x; cin>>n>>x;
  int l[n]; for(int i=0;i<n;i++) cin>>l[i];
  int an=0, nw=0;
  for(int i=0;i<=n;i++) {
    if (nw <= x) {
      an++;
      if (i<n)nw+=l[i];
    } else{
      break;
    }
  }
  cout<<an<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}
signed main(signed argc, char* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    const int MOD = 1000000007;
	string s;
	cin>>s;
	const int n=s.size();
	vector<int> memo(n+1,0);
	rep(i,n){
		int it=s[i]-'0';
		memo[i+1]=(memo[i]*10+it)%2019;
	}
	vector<int> memo2(2019,0);
	memo2[0]=1;
	int ans=0;
	rep(i,1,1+n){
		vector<int> memo2_(2019,0);
		rep(j,2019)memo2_[j]=memo2[j];
		rep(j,2019){
			int next=(j*10)%2019;
			memo2[next]=memo2_[j];
		}
		ans+=memo2[memo[i]];
		memo2[memo[i]]++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 5032
import java.util.*;

public class Main{
    Scanner in = new Scanner(System.in);

    ArrayList<String> select(String[] ary){
        ArrayList<String> list = new ArrayList<>();
        String[] name = new String[ary.length];
        int[] price = new int[ary.length];
        Arrays.fill(name, "NONE");
        for(String s : ary){
            String[] sp = s.split(" ");
            int idx = 0;
            while(!name[idx].equals(sp[0]) && !name[idx].equals("NONE")){
                idx++;
            }
            name[idx] = sp[0];
            price[idx] += Integer.parseInt(sp[1]) * Integer.parseInt(sp[2]);
        }
        for(int i = 0; i < price.length; i++){
            if(name[i].equals("NONE")){
                break;
            }
            if(price[i] >= 1000000){
                list.add(name[i]);
            }
        }
        if(list.size() == 0){
            list.add("NA");
        }
        return list;
    }

    void solve(){
        int n = Integer.parseInt(in.nextLine());
        while(n != 0){
            String[] a = new String[n];
            for(int i = 0; i < n; i++){
                a[i] = in.nextLine();
            }
            ArrayList<String> names = select(a);
            names.forEach(System.out::println);
            n = Integer.parseInt(in.nextLine());
        }
    }
    
    public static void main(String[] args){
        new Main().solve();    
    }
}

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

int main(){
  
  int n, a, b;
  
  cin >> n >> a >> b;
  
  if (n * a >= b){
    
    cout << b << endl;
    
  }else{
    
    cout << n * a << endl;
    
  }
  
}

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

using namespace std;

int main(){
    int l, r, d;
    cin >> l >> r >> d;
    
    int counter = 0;
    
    for (int i = l; i <= r; ++i) {
        if (i % d == 0) ++counter;
        else continue;
    }
    
    cout << counter << "\n";
    
    return 0;
}


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

int main(){

  int N, cnt = 0;
  long long A[100000], num;
  
  cin >> N;

  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
  for(int i = 0; i < N; i++){
    cin >> num;
    A[i] -= num;
  }

  std::sort(A, A+N);
  num = 0;
  for(int i = 0; i < N; i++){
    if(A[i] < 0){
      num += A[i];
      cnt++;
    }
    else{
      break;
    }
  }
  if(num == 0){
    cout << cnt << "\n";
    return 0;
  }
  
  for(int i = N-1; i >= 0; i--){
    num += A[i];
    cnt++;
    if(num >= 0){
      cout << cnt << "\n";
      return 0;
    }
  }

  cout << "-1\n";
  
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007


int main() {
  
  int N,Q;
  string S;
  cin >> N >> Q >> S;

  vector<int> p(0);
  for(int i = 0;i < N-1;i++) {
    if(S.at(i) == 'A' && S.at(i+1) == 'C') {
      p.push_back(i+1);
    }
  }

  
  for(int i = 0;i < Q;i++) {
    int l,r;
    cin >> l >> r;
    auto itL = lower_bound(p.begin(),p.end(),l);
    auto itR = lower_bound(p.begin(),p.end(),r);
    
    cout << distance(itL,itR) << endl;
  }


}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
int MIN=9999;
string S;
void solve(int n,int m,int now){
 	if(m == 3){
      MIN = min(MIN,abs(753-now));
      return;
    }
  	if(n == S.size())
      return;
  	solve(n+1,m+1,10*now+(S[n]-'0'));
}
int main(){
    int N,h[101],res=0;
    cin >> N;
    for(int i=0;i<N;i++)
        cin>> h[i];
    h[N] = 0;
    N++;
    while(1){
        int flag = 0;
        for(int i=0;i<N;i++)
            if(h[i] != 0)
                flag = 1;
        if(flag == 0)
            break;
        int f=0;
        for(int i=0;i<N;i++){
            if(h[i] >= 1){
                f = 1;
                h[i]--;
            }else{
                res += f;
                f = 0;
            }
        }
    }
  cout << (res) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int a[100];
int min_vector(int, int);

int main(){
	int n, ans;

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

	ans = min_vector(0, n-1);
	printf("%d\n", ans);
}

int min_vector(int left, int right){
	if(left > right){
		return 0;
	}

	int min_val = a[left], min_index = left;
	for(int i = left + 1; i <= right; i++){
		if(a[i] < min_val){
			min_val = a[i];
			min_index = i;
		}
	}
	
	for(int i = left; i <= right; i++){
		a[i] -= min_val;
	}
	int ret = min_val;
	ret += min_vector(left, min_index - 1) + 
		min_vector(min_index + 1, right);

	return ret;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <vector>
#include <queue>
#include <functional>
#include <utility>
#include <limits.h>
#include <string.h>

#define MAX_N 5000

using namespace std;

struct edge { int to, cost; };

vector<edge> graph[MAX_N];
vector<int> simpg[MAX_N];
bool bfsflag[MAX_N];
int dist[MAX_N];
int n, k;
int c[MAX_N], r[MAX_N];

using P = pair<int, int>;

void dijkstra(int start)
{
	for (int a = 0; a < n; ++a)dist[a] = INT_MAX - 100000;
	dist[start] = 0;
	priority_queue<P, vector<P>, greater<P>>que;
	que.push(P(0,start));
	while (!que.empty())
	{
		P p = que.top(); que.pop();
		if (dist[p.second] < p.first)continue;
		for (edge e : graph[p.second])
		{
			if (dist[e.to] > dist[p.second] + e.cost)
			{
				dist[e.to] = dist[p.second] + e.cost;
				que.push(P(dist[e.to],e.to));
			}
		}
	}
}


int main()
{
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; ++i)
	{
		scanf("%d %d", &c[i], &r[i]);
	}
	for (int j = 0; j < k; ++j)
	{
		int a, b;
		scanf("%d %d", &a, &b);
		simpg[a - 1].push_back(b - 1);
		simpg[b - 1].push_back(a - 1);
	}
	for (int i = 0; i < n; ++i)
	{
		memset(bfsflag,false,sizeof(bfsflag));
		bfsflag[i] = true;
		queue<int> bfs;
		bfs.push(i);
		for (int j = 0; j < r[i]; ++j)//?
		{
			queue<int>bfs2;
			while (!bfs.empty())
			{
				int v = bfs.front(); bfs.pop();
				for (int cv : simpg[v])
				{
					if (!bfsflag[cv])
					{
						bfsflag[cv] = true;
						bfs2.push(cv);
						graph[i].push_back({ cv, c[i] });
					}
				}
			}
			bfs = bfs2;
		}
	}
	dijkstra(0);
	printf("%d\n", dist[n - 1]);
}

Measured memory_bytes: 127212
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	cin >> n >> k;
	vector<long long int> a(n+2);
	long long int sum;
	for (long long int t = k; t < n+2; ++t)
	{
		a.at(t)=-t*t+n*t+t+1;
		sum = sum+a.at(t);
	}
  long long int ans;
  ans = sum%1000000007;
    
  
	cout << ans << endl;
}


Measured memory_bytes: 4788
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s;
    long long k;
    while(cin>>s>>k)
    {
        char ch='1';
        int pos=-1;
        for(int i=0;i<s.length();i++)
        {
            if(s[i]!='1') 
            {
                ch=s[i];
                pos=i+1;
                break;
            }
        }
        if(k>=pos) cout<<ch<<endl;
        else cout<<1<<endl;
    }
}

Measured memory_bytes: 256