akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>

int search(int *s, int n, int t){
    int ret = 0;
    if(t==s[n/2])ret = 1;
    else if(n<=1)ret = 0;
    else if(t<s[n/2])ret = search(s, n/2, t);
    else ret = search(s+n/2, (n+1)/2, t);
    return ret;
}

int main(){
    int i, n, q, t;
    int c = 0;
    scanf("%d",&n);
    int s[n];
    for(i=0;i<n;i++){
        scanf("%d",s+i);
    }
    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d",&t);
        c += search(s, n, t);
    }
    printf("%d\n",c);
    return 0;
}




Measured memory_bytes: 2960
n,xstart=map(int,input().split())
x=map(int,input().split())
z=[];za=z.append
for i in x:
  za(abs(xstart-i))
import fractions;g=fractions.gcd
a=z[0]
for i in range(n-1):
  a=g(a,z[i+1])
print(a)

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

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
const int MAX = 510000;

// https://drken1215.hatenablog.com/entry/2018/06/08/210000
ll fac[MAX], finv[MAX], inv[MAX];
void combinationInit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

ll combination(ll n, ll k) {
  if (n < k) {
    return 0;
  } else if (n < 0 || k < 0) {
    return 0;
  }
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<pair<ll, ll>> primeFactorize(ll n) {
  vector<pair<ll, ll>> r;
  for (int i = 2; i * i <= n; i++) {
    if (n % i != 0) {
      continue;
    }
    int ex = 0;
    while (n % i == 0) {
      ex++;
      n /= i;
    }
    r.push_back({i, ex});
  }
  if (n > 1) {
    r.push_back({n, 1});
  }
  return r;
}

int main() {
  ll n, m;
  cin >> n >> m;
  auto res = primeFactorize(m);
  ll v = 1;
  combinationInit();
  for (ll i = 0; i < res.size(); i++) {
    v *= combination(res[i].second + n - 1, n - 1);
    v %= MOD;
  }

  cout << v << endl;
}


Measured memory_bytes: 15556
//ITP1_1_B
#include <iostream>
#include <cmath>

class ITP1_1_B
{
public:
    static void cubeNumber()
    {
        int num;
        std::cin >> num;
        std::cout << num * num * num << std::endl;
    }
};

class ITP1_1_C
{
public:
    int length;
    int breadth;
    int area;
    int perimeter;

    ITP1_1_C(int l, int b)
    {
        this->length = l;
        this->breadth = b;
        this->area = length * breadth;
        this->perimeter = 2 * (length + breadth);
    }
};

class ITP1_1_D
{
public:
    int originSecond;
    int hour;
    int minute;
    int second;

    ITP1_1_D(int s)
    {
        originSecond = s;
        hour = (originSecond / 60) / 60;
        minute = (originSecond - 60 * 60 * hour) / 60;
        second = originSecond - 60 * 60 * hour - 60 * minute;
    }
};

int main()
{
    int n;
    std::cin>>n;
    ITP1_1_D second(n);
    std::cout<<second.hour<<":"<<second.minute<<":"<<second.second<<std::endl;
}



Measured memory_bytes: 3084
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
using namespace std;
int n,q;
string str[1001];
int e[1001],w[1001];

int main(void){
	while(1){
		scanf("%d %d",&n,&q);
		if(n+q==0)break;
		for(int i=0;i<n;i++){
			cin >> str[i] >> e[i] >> w[i];
		}
		for(int i=0;i<q;i++){
			int y;
			scanf("%d",&y);
			int j;
			for(j=0;j<n;j++){
				if(w[j]-e[j]<y && y<=w[j]){
					cout << str[j] << " " << y-(w[j]-e[j]) << endl;
					break;
				}
			}
			if(j==n)cout << "Unknown" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1356
import java.util.*;

public class Main{
	public static void main(String[] args){
        
  		Scanner sc = new Scanner(System.in);
        
        String[] line = sc.nextLine().split(" ");
        int length = Integer.parseInt(line[0]);
        double maxItemNum = Double.parseDouble(line[1]);
        
        String[] tempArr = sc.nextLine().split(" ");
        double[] arr = new double[length];

        for(int i = 0;i < length;i++){
            arr[i] = Double.parseDouble(tempArr[i]);
        }

        Arrays.sort(arr);

        int index = 0;
        int result = 0;
        while(index < length) {
            
            if (index == length -1){
                if (maxItemNum == arr[index]){
                    result++;
                }
                break;
            }

          	if (maxItemNum >= arr[index]){
                maxItemNum -= arr[index];
                result++;
            }else{
                break;
            }

            index++;
        }

        System.out.println(result);
    }

}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007 //S.size() 配列名.Length()
using namespace std;
typedef unsigned long long ll;


int main(void){
	int a,b;
	cin >> a >> b;
	cout << max({a + b,a - b, a * b});
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
def input():
    return sys.stdin.readline()[:-1]

def main():
    N = int(input())
    H = int(input())
    W = int(input())

    h = N - H + 1
    w = N - W + 1
    print(h * w)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61868
from collections import deque
rev = False
S = deque(list(input().strip()))

Q = int(input())

for _ in range(Q):
    q = input().split()
    if len(q) == 3 and q[1] == '1':
        if not rev:
            S.appendleft(q[2])
        else:
            S.append(q[2])
    elif len(q) == 3 and q[1] == '2':
        if rev:
            S.appendleft(q[2])
        else:
            S.append(q[2])
    else:
        rev = not rev
if not rev:
    print(''.join(list(S)))
else:
    print(''.join(list(S))[::-1])


Measured memory_bytes: 8420
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<set>
#include<stack>
#include<queue>

#define reps(i,j,k) for(int i=(j);i<(k);i++)
#define rep(i,j) reps(i,0,j)
#define fs first
#define sc second
#define pb push_back
#define mk make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

template<class S,class T>
ostream &operator<<(ostream &out, const pair<S,T> p){
	return out << "(" << p.fs << ", " << p.sc << ")";
}

template<class T>
ostream &operator<<(ostream &out, const vector<T> &v){
	out << "{";
	rep(i,v.size()) out << v[i] << ", ";
	return out << "}" << endl;
}
#define N 100
#define C 20
#define INF (1<<25)
ll d[C][N][N];
ll v[N][N];
int main(){
	int n,m,c,s,g;
	while(cin >> n >> m >> c >> s >> g, n){
		s--; g--;
		rep(i,c) rep(j,n) rep(k,n) d[i][j][k] = INF * (j!=k);
		rep(i,m){
			ll x,y,ci,di;
			cin >> x >> y >> di >> ci;
			x--; y--; ci--;
			d[ci][x][y] = d[ci][y][x] = min(d[ci][x][y], di);
		}

		rep(l,c) rep(k,n) rep(i,n) rep(j,n) d[l][i][j] = min(d[l][i][j], d[l][i][k] + d[l][k][j]);
		vi p(c);
		rep(i, c) cin >> p[i];
		vi q[C], r[C];
		rep(i, c){
			q[i].resize(p[i]-1);
			r[i].resize(p[i]);
			rep(j, p[i]-1) cin >> q[i][j];
			rep(j, p[i]) cin >> r[i][j];
		}

		rep(i,n) rep(j,n) v[i][j] = INF * (i!=j);
		rep(i,c) rep(j,n) rep(k,n){
			ll t = 0, pos=0, ind=0;
			int dst = d[i][j][k];
			while(ind<p[i]-1 && dst > q[i][ind]){
				t += (q[i][ind] - pos) * r[i][ind];
				pos = q[i][ind];
				ind++;
			}
			t += (dst - pos) * r[i][ind];
			v[j][k] = min(v[j][k], t);
		}

		rep(k,n) rep(i,n) rep(j,n) v[i][j] = min(v[i][j], v[i][k] + v[k][j]);
		if (v[s][g] >= INF) cout << -1 << endl;
		else cout << v[s][g] <<endl;
	}
	return 0;
}

Measured memory_bytes: 4724
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,x,t;
    cin>>n>>x>>t;
    if(n%x==0)
    {
        cout<<(n/x)*t;
    }
    else
        cout<<((n/x)+1)*t;

}

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

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<pair<int,int>> h(n+1,pair<int,int>(0, 0));//index=展望台i,first=展望台の標高,second=良い(0)良くない(-1)
  for(int i = 1; i <= n; i++) cin >> h[i].first;
  for(int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    if(h[a].first == h[b].first) h[a].second = h[b].second = -1;
    else if(h[a].first > h[b].first) h[b].second = -1;
    else h[a].second = -1;
  }
  int cnt = 0;
  for(int i = 1; i <= n; i++) {
    if(h[i].second == 0) cnt++;
  }
  cout << cnt;
}

Measured memory_bytes: 4008
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100;
const long long MOD = 1000000007;
typedef pair<long long,long long> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}

int main() {
    int N;cin >> N;
    vector<long long> retu(N);
    for(int i = 0;i<N;i++)cin >> retu.at(i);
    vector<P> guuki;
    for(int i = 0;i<N;i++){
        guuki.push_back(make_pair(retu.at(i),i%2));
    }
    sort(retu.begin(),retu.end());
    sort(guuki.begin(),guuki.end());
    int ans = 0;
    for(int i = 0;i<N;i++){
        if(guuki.at(i).second != i%2) ans++;
    }
    cout << ans/2 << endl;
}


Measured memory_bytes: 3188
import java.util.List;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Scanner;


public class Main {

	public static int cnt=0;
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		
		Scanner scan =new Scanner(System.in);
		int n=scan.nextInt();
		int[] arr=new int[n];
		for(int i=0;i<n;i++){
			arr[i]=scan.nextInt();
		}
		//insertsort(arr,n);
		//bubblesort(arr,n);
		//selectSort(arr, n);
		shellSort(arr,n);
	}

	//输出超时 我也不知道为什么
	private static void shellSort(int[] arr, int n) {
		// TODO Auto-generated method stub
		ArrayList<Integer> list=new ArrayList<>();
		
		int h=1;
		while(true){
			if(h>n) break;
			list.add(h);
			h=h*3+1;
			
		}
		
		Collections.reverse(list);
	   // Integer[] g=(Integer[])list.toArray();
		int m=list.size();
		for(int i=0;i<m;i++){
			shellinsert(arr,n,list.get(i));
		}
		StringBuilder builder=new StringBuilder();
		builder.append(m);
		builder.append("\n");
		builder.append(list.get(0));
		for(int i=1;i<m;i++){
			builder.append(" ");
			builder.append(list.get(i));
		}
		builder.append('\n');
		builder.append(cnt).append('\n');
		for(int i=0;i<n;i++){
			builder.append(arr[i]).append('\n');
		}
		System.out.println(builder);	
//		System.out.println(m);
//		for(int i=0;i<m-1;i++)
//			System.out.print(list.get(i)+" ");
//		System.out.println(list.get(m-1));
//		System.out.println(cnt);
//		for(int i=0;i<n-1;i++)
//			System.out.println(arr[i]+" ");
//		System.out.println(arr[n-1]);
	}

	private static void shellinsert(int[] arr, int n, int gi) {
		// TODO Auto-generated method stub
		for(int i=gi;i<n;i++){
			int v=arr[i];
			int j=i-gi;
			while(j>=0&&arr[j]>v){
				arr[j+gi]=arr[j];
				j=j-gi;
				cnt++;
			}
			arr[j+gi]=v;
		}
	}

	public  static  void selectSort(int[] arr,int n){
		int sum=0;
		for(int i=0;i<n;i++){
			int min=i;
			for(int j=i+1;j<n;j++){
				if(arr[min]>arr[j])
					min=j;
			}
			
			if(min!=i){
				swap(arr,min,i);
				sum++;
			}
				
		}
		arrPrint(arr);
		System.out.println(sum);
	}
	private static void swap(int[] arr, int i,int j) {
		// TODO Auto-generated method stub
		int tmp=arr[i];
		arr[i]=arr[j];
		arr[j]=tmp;
	}

	public  static void insertsort(int[] arr,int n){
		arrPrint(arr);
		for(int i=1;i<n;i++){
			int tmp=arr[i];//必须要使用tmp把这个值存起来，因为后面可能会有变动
			int j=i-1;
			while(j>=0&&arr[j]>tmp){
				arr[j+1]=arr[j];
				j--;
			}
			arr[j+1]=tmp;
			arrPrint(arr);
		}
	}
	
	public static void bubblesort(int[] arr,int n){
		int res=0;
		for(int i=0;i<n;i++){
			boolean flag=false;
			for(int j=n-1;j>i;j--){
				if(arr[j]<arr[j-1]){
					int tmp=arr[j];
					arr[j]=arr[j-1];
					arr[j-1]=tmp;
					flag=true;
					res++;
				}
				
			}
			if(flag==false)
				break;
		}
		arrPrint(arr);
		System.out.println(res);
	}
	
	
	public static void arrPrint(int[] arr){
		int i=0;
		for(i=0;i<arr.length-1;i++)
			System.out.print(arr[i]+" ");
		System.out.println(arr[i]);
	}
}



Measured memory_bytes: 297752
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  string str = a==b ? "=="
  : a>b ? ">"
  : "<";
  cout << "a " << str << " b" << endl;

  return 0;
}



Measured memory_bytes: 3156
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);

        int n = stdIn.nextInt();
        int m = stdIn.nextInt();

        System.out.println(n * (n-1) / 2 + m * (m-1) / 2);
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<iomanip>
using namespace std;
char map[3][3]={'A','B','C','D','E','F','G','H','I'};
double dp[16][3][3];
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
int main(){
	int n;
	char s,t,d;
	while(true){
	cin>>n;
	if(n==0)break;
	cin>>s>>t>>d;
	for(int i=0;i<=n;i++)for(int f=0;f<3;f++)for(int g=0;g<3;g++)dp[i][f][g]=0.0;
	for(int i=0;i<3;i++)for(int j=0;j<3;j++)if(map[i][j]==s)dp[0][i][j]=1.0;
	for(int i=0;i<n;i++){
		for(int f=0;f<3;f++){
			for(int g=0;g<3;g++){
				for(int j=0;j<4;j++){
					bool move=false;
					if(f+dy[j]>=0&&f+dy[j]<3&&g+dx[j]>=0&&g+dx[j]<3){if(map[f+dy[j]][g+dx[j]]!=d)move=true;}
					if(move)dp[i+1][f+dy[j]][g+dx[j]]+=dp[i][f][g]/4.0;
					else dp[i+1][f][g]+=dp[i][f][g]/4.0;
				}
			}
		}
	}
	for(int i=0;i<3;i++)for(int j=0;j<3;j++)if(map[i][j]==t)cout<<fixed<<setprecision(10)<<dp[n][i][j]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1232
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>
using namespace std;

typedef long long int ll;

ll max_and_fill(int p, vector<int> &visited, const vector<ll> &hs, const vector< vector<int> > &as) {
    if (visited[p]) {
        return 0;
    }
    visited[p] = 1;
    ll max_val = hs[p];
    for (int i = 0; i < (int)as[p].size(); i++) {
        int next = as[p][i];
        if (visited[next]) { continue; }
        ll tmp = max_and_fill(next, visited, hs, as);
        max_val = max(tmp, max_val);
    }
    return max_val;
}

ll max_cnt(int p, ll target, vector<int> &visited, const vector<ll> &hs, const vector< vector<int> > &as) {
    if (visited[p]) {
        return 0;
    }
    visited[p] = 1;
    ll ret = 0;
    if (hs[p] == target) {
        ret += 1;
    }
    for (int i = 0; i < (int)as[p].size(); i++) {
        int next = as[p][i];
        if (visited[next]) { continue; }
        ret += max_cnt(next, target, visited, hs, as);
    }
    return ret;
}

int main () {
    int n, m;
    cin >> n >> m;
    vector<ll> hs(n, 0);
    vector< vector<int> > as(n, vector<int>(0));

    for (int i = 0; i < n; i++) {
        cin >> hs[i];
    }
    for (int i = 0; i < m; i++) {
        int a1, a2;
        cin >> a1 >> a2;
        a1--; a2--;
        as[a1].push_back(a2);
        as[a2].push_back(a1);
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        bool flg = true;
        for (int j = 0; j < (int)as[i].size(); j++) {
            int next = as[i][j];
            if (hs[next] >= hs[i]) {
                flg = false;
            }
        }
        if (flg) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8596
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Wed Aug 28 19:11:18 2019
//
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	arr := make([]float64, n)
	for i := range arr {
		fmt.Scan(&arr[i])
	}

	sort.Float64s(arr)
	if len(arr) == 1 {
		fmt.Println(arr[0])
		return
	}

	total := 0.0
	for i := range arr {
		if i != 1 {
			total /= 2.0
		}
		total += arr[i] / 2.0
	}
	fmt.Println(total)
}


Measured memory_bytes: 512
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int32_t, int32_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int32_t H, W;
  cin >> H >> W;
  vector<int32_t> histgram_row(H);
  vector<int32_t> histgram_column(W);
  vector<vector<bool>> grid(H, vector<bool>(W));
  for (int32_t row = 0; row < H; ++row) {
    string s;
    cin >> s;
    for (int32_t column = 0; column < W; ++column) {
      const char ch = s.c_str()[column];
      if (ch == '#') {
        ++histgram_row[row];
        ++histgram_column[column];
        grid[row][column] = true;
      } else {
        grid[row][column] = false;
      }
    }
  }
  for (int32_t row = 0; row < H; ++row) {
    if (histgram_row[row] > 0) {
      for (int32_t column = 0; column < W; ++column) {
        if (histgram_column[column] > 0) {
          if (grid[row][column]) {
            cout << "#";
          } else {
            cout << ".";
          }
        }
      }
      cout << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
char a[1000],b[1000];
int main()
{
cin>>a>>b;
int i,ii;
i=ii=0;
bool now=0;
for(;i<strlen(a)||ii<strlen(b);)
{
	if(now==0) {if (a[i]!='/0') cout<<a[i];i++;now=!now;}
	else {if (b[ii]!='/0') cout<<b[ii];ii++;now=!now;}
}
cout<<endl;
} 

Measured memory_bytes: 256
#include<cstdio>
#include<stack>
using namespace std;
int main(){
	stack<int> ans;
	char c=getchar();
	while(c!='A') c=getchar();
	while(c!=EOF){
		while(c!=EOF&&(c<'A'||c>'Z')) c=getchar();
		if(c==EOF) break;
		ans.push(c-'A');
		c=getchar();
	}
	while(ans.top()!=25) ans.pop();
	printf("%d",ans.size());
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
#define int long long
#define rep(i,a,n) for (int (i)=(a);(i)<(n);(i)++)
using namespace std;
#define hash hush
typedef long long ll;
typedef long double ld;
int n, a[8];
signed  main() {
	cin >> n;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		int b;
		cin >> b;
		if (b < 400)
			a[0]++;
		else if (b < 800)
			a[1]++;
		else if (b < 1200)
			a[2]++;
		else if (b < 1600)
			a[3]++;
		else if (b < 2000)
			a[4]++;
		else if (b < 2400)
			a[5]++;
		else if (b < 2800)
			a[6]++;
		else if (b < 3200)
			a[7]++;
		else
			sum++;
	}
	int ans = 0;
	for (int i = 0; i < 8; i++) {
		if (a[i] > 0)
			ans++;
	}
	if (sum == 0)
		cout << ans << " " << ans << endl;
	else
		cout << max(ans,1LL) << " " << ans + sum << endl;
	getchar(); getchar();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 2e7 + 9, M = 1e7, OO = 0x3f3f3f3f;
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0);
int main()
{
int a,b,c,counter1=0,counter2=0;
cin>>a>>b>>c;
if(a==5){
    counter1++;
}
if(b==5)
    counter1++;
if(c==5){
    counter1++;
}
if(a==7){
    counter2++;
}
if(b==7)
    counter2++;
if(c==7){
    counter2++;
}
if(counter1==2&&counter2==1){
    printf("YES\n");
}
else{
    printf("NO\n");
}




    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <numeric>
#include <climits>

using ll = long long;
#define REP(i,x) for(long long i=0;i<(long long)(x);i++)
#define REPS(i,x) for(long long i=1;i<=(long long)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
const ll mod = 1000000007;
long long N;
using namespace std;
long long gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
int main() {
	cin >> N;
	vector<ll> v(N);
	REP(i, N) cin >> v[i];
	reverse(v.begin(), v.end());
	ll ans = v[0];
	REPS(i, N-1) {
		ans = ans/ gcd(ans, v[i]) * v[i] ;
	}
	cout << ans << endl;
	return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

const ll INF = 1e18;
ll ans = INF;

void f(map<int, vector<P>> X, int d1, int d2, int diag){
    for(auto [x, mp] : X) {
        sort(all(mp));
        ll tmp = INF;
        for(auto [y, d] : mp){
            if(d == d1) tmp = y;
            if(tmp == INF) continue;
            if(d == d2) {
                tmp = y - tmp;
                ans = min(ans, tmp * diag);
                tmp = INF;
            }
        }
    }
    return;
}

void Main() {
    int n; cin >> n;
    map<int, vector<P>> X, Y, YpX, YmX;
    
    rep(i, n){
        int x, y; char u; cin >> x >> y >> u;
        int d;
        if(u == 'U') d = 0;
        else if(u == 'R') d = 1;
        else if(u == 'D') d = 2;
        else if(u == 'L') d = 3;
    
        X[x].eb(y, d);
        Y[y].eb(x, d);
        YpX[y+x].eb(y, d);
        YmX[y-x].eb(y, d);
    }

    f(X, 0, 2, 1);
    f(Y, 1, 3, 1);    
    f(YpX, 0, 1, 2);
    f(YpX, 3, 2, 2);
    f(YmX, 0, 3, 2);    
    f(YmX, 1, 2, 2);    

    if(ans == INF) cout << "SAFE" << endl;
    else cout << ans * 5 << endl;
    return;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 91428
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    static int[] w = new int[100010];
    static int[] v = new int[100010];
    static int[][] dp = new int[110][100010];
    static int k;

    static int chmin(int a, int b) {
        if (a > b) {
            a = b;
            return a;
        }
        return a;
    }

    static int chmax(int a, int b) {
        if (a < b) {
            a = b;
            return a;
        }
        return a;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] in = sc.next().toCharArray();
        in[3] = '8';
        System.out.println(new String(in));
    }
}


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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

int main() {
    int n,A,B;cin>>n>>A>>B;
    string s;cin>>s;
    int cnta=0,cntb=0;

    rep(i,n){
        if(s[i]=='c'){
            cout<<"No"<<endl;
        }
        else if(s[i]=='a'){
            if(cnta+cntb<A+B){
                cout<<"Yes"<<endl;
                cnta++;
            }
            else {
                cout<<"No"<<endl;
            }
        }
        else{
            if(cntb<B&&cnta+cntb<A+B){
                cout<<"Yes"<<endl;
                cntb++;
            }
            else {
                cout<<"No"<<endl;
            }

        }
    }
}


Measured memory_bytes: 896
n, m = map(int, input().split(" "))
a = map(int, input().split(" "))

mods = {}
mods[0] = 1
sum = 0
ans = 0
for i in a:
    sum += i
    mod = sum % m
    # print("sum/mod  %d/%d" % (sum, mod))

    if mod in mods.keys():
        mods[mod] = mods[mod] + 1
    else:
        mods[mod] = 1

for mod, count in mods.items():
    # print("mod,count = %d,%d" % (mod, count))
    if count < 2:
        continue
    else:
        ans += (count * (count - 1) / 2)

print(int(ans))


Measured memory_bytes: 16100
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
using namespace std;

int main(){
    int n, m, c;
    int b[21];
    int a[21][21];

    cin >> n >> m >> c;
    for (int i = 0; i < m; ++i) cin >> b[i];
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            cin >> a[i][j];

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        int sum = 0;
        for (int j = 0; j < m; ++j) {
            sum += a[i][j] * b[j] ;
        }
        sum += c;
        if (sum > 0) ans++;
    }

    cout << ans;
    return 0;
}



Measured memory_bytes: 256
#include<algorithm>//sort(all(変数),greater<型名>())で降順に、*max_element(all(変数))で最大値を獲得
#include<bits/stdc++.h>
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric>
// xとyのgcdは__gcd(x,y),xとyのlcmは(x*y)/__gcd、accumulate(all(変数),0)で要素の全加算
#include<queue>//priority_queue<型名> 変数
#include<set>
#include<stack>
#include<string>//変数.substr(どこから,いくつ)
#include<vector>
#define rep(i,n)  for(ll i=0; i<n; i++)
#define rrep(i,n) for(ll i=n-1; 0<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e9
using ll = long long;
using namespace std;
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; }

int main(){
  int h,w; cin >> h >> w;
  vector<vector<char> > a(h,vector<char>(w));
  rep(i,h) rep(j,w) cin >> a[i][j];
  set<int> tate,yoko;
  rep(i,h){
    rep(j,w){
      if(a[i][j] == '#'){
        tate.insert(i);
        yoko.insert(j);
      }
    }
  }
  for(auto y : tate){
    for(auto x : yoko){
      cout << a[y][x];
    }
    cout << "\n";
  }
  cout << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long int w, h, x, y;
	cin >> w >> h >> x >> y;
	cout << (double)w * h / 2 << ' ';
	if (x == (double)w / 2 && y == (double)h / 2)
		cout << 1;
	else
		cout << 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(clippy::many_single_char_names)]
#![allow(clippy::suspicious_arithmetic_impl)]

// using Rust(1.42.0)
// My Library Repo is at "https://github.com/Loptall/prcn_lib"
// check available crates on AtCoder at "https://atcoder.jp/contests/language-test-202001"

/*
    AtCoder Language Update 2020204 お疲れ様でした! 有難いです
*/

// Dep crates are...
use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque};
use std::mem::swap;
use std::ops::*;
use std::{i128, i16, i32, i64, i8, isize, u128, u16, u32, u64, u8, usize};

use itertools::*;
use itertools_num::*;
use lazy_static::lazy_static;
use maplit::{btreemap, btreeset, hashmap, hashset};
use num_bigint::{BigInt, BigUint};
use num_integer::{binomial, gcd, lcm, Integer};
use permutohedron::Heap;
use proconio::{fastout, input, is_stdin_empty, marker::*};
use rand::random;

// code...
fn main() {
    input! {
        s: usize, w: usize,
    }
    println!("{}", if w >= s { "unsafe" } else {"safe"});
}


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

int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a+b>c+d)cout<<"Left"<<endl;
  else if(a+b==c+d)cout<<"Balanced"<<endl;
  else cout<<"Right"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL){
    x=x->left;
  }
  return x;

}

Node treeMaximum(Node x){
  while(x->right!=NIL){
    x=x->right;
  }
  return x;
}

Node treeSearch(Node u, int k){
  if(u==NIL||k==u->key){
    return u;
  }
  if(k<u->key){
    return treeSearch(u->left,k);
  }else{
    return treeSearch(u->right,k);
  }
}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x!=NIL){
    y=x;
    if(z->key<x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }else if(z->key<y->key){
    y->left=z;
  }else{
    y->right=z;
  }
}

void inorder(Node u){
  if(u==NIL){
    return;
  }
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL){
    return ;
  }
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20536
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N;
    cin >> N;
    ld x[N];
    string s[N];
    ld bit = 380000;
    ld ans = 0;
    rep(i, N){
        cin >> x[i] >> s[i];
        if(s[i] == "JPY") ans += x[i];
        else ans += x[i]*bit;
    }
    cout << setprecision(15) << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] inputA = new int[N];
		int[] inputB = new int[N];
		int[] inputC = new int[N];
		for (int i = 0; i < N; i++) {
			inputA[i] = sc.nextInt();
			inputB[i] = sc.nextInt();
			inputC[i] = sc.nextInt();
		}
		long[][] dp = new long[3][N];
		dp[0][0] = inputA[0];
		dp[1][0] = inputB[0];
		dp[2][0] = inputC[0];
		for (int i = 1; i < N; i++) {
			dp[0][i] = Math.max(dp[1][i - 1] + inputA[i], dp[2][i - 1] + inputA[i]);
			dp[1][i] = Math.max(dp[0][i - 1] + inputB[i], dp[2][i - 1] + inputB[i]);
			dp[2][i] = Math.max(dp[0][i - 1] + inputC[i], dp[1][i - 1] + inputC[i]);
		}
		System.out.print(Math.max(Math.max(dp[0][N - 1], dp[1][N - 1]), dp[2][N - 1]));
	}
}

Measured memory_bytes: 93928
N,Q=map(int,input().split())
S=[i for i in input()]
t=[0]*(N+1)
for i in range(N-1):
  t[i+1]=t[i]+(1 if S[i]=='A' and S[i+1]=='C' else 0)
for i in range(Q):
  l,r=map(int, input().split())
  print(t[r-1]-t[l-1])

Measured memory_bytes: 8440
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;

int main(){
    int n;  cin >> n;
    vector<ll> a(n);
    for(int i=0; i<n; i++)  cin >> a.at(i);
    sort(a.begin(), a.end());
    ll ml=a.back()/2, mr=ml+a.back()%2, obj=-1;
    
    for(int i=0; i<n-1; i++)
        if(abs(ml-a[i])<abs(ml-obj) || abs(mr-a[i])<abs(mr-obj)) obj=a[i];
    
    cout << a.back() << ' ' << obj << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const ll MOD = 1e9+7;


#define REP(i, N) for (ll i = 0; i < (N); i++)
#define REPP(i, a, b) for (ll i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((ll)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<ll>>

using namespace std;

ll sumRow(ll a, ll b){
    return ((b-a+1)*(a+b)/2);
}

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

    ll n,k;
    cin >> n >> k;
    ll ans = 0;
    ll start = sumRow(0,k-1);
    ll end = sumRow(n-k+1,n);
    for(ll i = k; i < n+1+1;i++){
        ans += (end-start+1)%MOD;
        start += i;
        end += n-i;
    }

    cout << ans%MOD << endl;



    return 0;
}

Measured memory_bytes: 3196
### constant

MAX_X = MAX_Y = 10000.0
DELTA = 1e-8

CNRS = [[0.0, 0.0], [MAX_X, 0.0], [MAX_X, MAX_Y], [0.0, MAX_Y]]

### subroutines

def get_line(x0, y0, x1, y1)
  cx = (x0 + x1) / 2
  cy = (y0 + y1) / 2
  vx = -(y1 - y0)
  vy =  (x1 - x0)
  [cx, cy, vx, vy]
end

def i_prod(vx0, vy0, vx1, vy1)
  vx0 * vx1 + vy0 * vy1
end

def o_prod(vx0, vy0, vx1, vy1)
  vx0 * vy1 - vx1 * vy0
end

# x = vx0*s+cx0 = vx1*t+cx1
# y = vy0*s+cy0 = vy1*t+cy1
# |vx0 -vx1| |s| = |cx1-cx0|
# |vy0 -vy1| |t|   |cy1-cy0|
# |s| = 1/(vx0*vy1-vx1*vy0)|vy1 -vx1||cx1-cx0|
# |t|                      |vy0 -vx0||cy1-cy0|

def cross(cx0, cy0, vx0, vy0, cx1, cy1, vx1, vy1)
  d = o_prod(vx0, vy0, vx1, vy1)
  return nil if d == 0.0
  s = (vy1 * (cx1 - cx0) - vx1 * (cy1 - cy0)) / d
  [vx0 * s + cx0, vy0 * s + cy0]
end

def triangle(x0, y0, x1, y1, x2, y2)
  o_prod(x1 - x0, y1 - y0, x2 - x0, y2 - y0).abs / 2
end

def dist2(x0, y0, x1, y1)
  (x1 - x0) ** 2 + (y1 - y0) ** 2
end

def div_border(ix, iy, px, py, ax, ay, lip, lia)
  ptsi = 4.times.map{|i| [CNRS[i]]}
  $bls.each_with_index do |bl, i|
    for l in [lip, lia]
      pt = cross(*l, *bl)
      if pt &&
         pt[0] >= 0.0 && pt[0] <= MAX_X && pt[1] >= 0.0 && pt[1] <= MAX_Y
        ptsi[i] << pt
      end
    end
  end

  ptsi.each{|pts| pts.sort!}
  ptsi[2].reverse!
  ptsi[3].reverse!
  pts = ptsi.flatten(1).uniq

  nrsts = pts.map do |pt|
    d2i = dist2(ix, iy, *pt)
    d2p = dist2(px, py, *pt)
    d2a = dist2(ax, ay, *pt)
    (d2i <= d2p + DELTA && d2i <= d2a + DELTA)
  end

  [pts, nrsts]
end

### main

$bls = 4.times.map do |i|
  j = (i + 1) % 4
  vx = CNRS[j][0] - CNRS[i][0]
  vy = CNRS[j][1] - CNRS[i][1]
  [*CNRS[i], vx, vy]
end
#p $bls

seq = 0

loop do
  ix, iy, px, py, ax, ay = gets.split.map(&:to_f)
  break if ix == 0 && iy == 0 && px == 0 && py == 0 && ax == 0 && ay == 0

  lip = get_line(ix, iy, px, py)
  lia = get_line(ix, iy, ax, ay)

  ar = 0.0
  
  ci = cross(*lip, *lia)

  pts, nrsts = div_border(ix, iy, px, py, ax, ay, lip, lia)
  npts = pts.length
  #p ci
  #p pts
  #p nrsts
  
  if ci && ci[0] >= 0.0 && ci[0] <= MAX_X && ci[1] >= 0.0 && ci[1] <= MAX_Y
    for i in (0...npts)
      j = (i + 1) % npts
      if nrsts[i] && nrsts[j]
        ar += triangle(*ci, *pts[i], *pts[j])
      end
    end
  else
    while ! nrsts.first || nrsts.last
      pts.rotate!
      nrsts.rotate!
    end
    #p pts
    #p nrsts

    ply = (0...npts).select{|i| nrsts[i]}.map{|i| pts[i]}
    pt0 = ply.shift
    ply.each_cons(2) do |pt1, pt2|
      ar += triangle(*pt0, *pt1, *pt2)
    end
  end

  seq += 1
  puts [seq, "%.5f" % (ar / (MAX_X * MAX_Y))].join(' ')
end

Measured memory_bytes: 6212
import Control.Applicative ((<$>))

solve a b b' c
  | a == b && b' == c = "YES"
  | otherwise = "NO"

main = do
  [a, b, c] <- words <$> getLine
  let a' = last a
      bhead = head b
      blast = last b
      c' = head c in
    putStrLn (solve a' bhead blast c')


Measured memory_bytes: 380
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main(){
  string s;
  cin>>s;
  int ans=0;
  rep(i,s.size()-1){
    if(s[i]!=s[i+1])++ans;
  }
  cout<<ans<<endl;
}

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

int main(){
    int N;
    cin >> N;
    int count[9];
    fill(count,count+9,0);
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        if(0<=a&&a<=399) count[0]++;
        else if(400<=a&&a<=799) count[1]++;
        else if(800<=a&&a<=1199) count[2]++;
        else if(1200<=a&&a<=1599) count[3]++;
        else if(1600<=a&&a<=1999) count[4]++;
        else if(2000<=a&&a<=2399) count[5]++;
        else if(2400<=a&&a<=2799) count[6]++;
        else if(2800<=a&&a<=3199) count[7]++;
        else count[8]++;
    }
    int temp=0;
    int ansmin=1,ansmax=0;
    for(int i=0;i<9;i++){
        if(count[i]>0&&i<8) temp++;
    }
    if(temp!=0) ansmin=temp;
    ansmax=temp+count[8];
    cout << ansmin << " " << ansmax << endl;
    return 0;
}


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

bool fin(bool ok){
    cout << (ok ? "Yes" : "No") << endl;
    exit(0);
}

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    map<int, int> mp;
    for(int a : A) mp[a]++;
    if(N%3){
        fin(mp.size() == 1);
    }else{
        vector<int> c;
        for(auto& p : mp) for(int i=0; i<3*p.second/N; i++) c.push_back(p.first);
        fin(c.size() == 3 && ((c[0]^c[1]^c[2]) == 0));
    }
    return 0;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
long long int a[100010],b[100010];
int main()
{
	long long int n,i,ans=0;
	scanf("%lld",&n);
	for(i=1;i<=n+1;i++)
	{
		scanf("%lld",&a[i]);
	}
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&b[i]);
	}
	for(i=1;i<=n;i++)
	{
		ans += min(a[i],b[i]);
		b[i] -= min(a[i],b[i]);
		if(b[i]>0)
		{
			ans += min(a[i+1],b[i]);
			a[i+1] = (long long int)max(0,int(a[i+1]-b[i]));
		}
	}
	printf("%lld",ans);
}

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

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;
 
public:
  u64 a;
 
  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=998244353,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k,q;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
ll f[ohara],fr[ohara];
ll dep[ohara];
    
//------ Believe yourself as a genius!!!!!! ------

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

    using mint=modint<MOD>;

    cin>>n;
    rep(i,n)cin>>a[i],dep[a[i]]++;
    if(a[0]!=0){
        Cout(0);
        return 0;
    }
    rrep(i,1,n){
        if(a[i]==0){
            Cout(0);
            return 0;
        }
    }
    mint ans=mint(1);
    rrep(i,1,n){
        rep(j,dep[i])ans*=dep[i-1];
    }
    Cout(ans.value());
    return 0;
}


Measured memory_bytes: 3072
/*********************
*  Author: xuziyuan  * 
*********************/
 
#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair
 
using namespace std;
 
const LL MOD=1e9+7;

string s,t,u;
int a,b;

int main()
{
	cin>>s>>t>>a>>b>>u;
	if(s==u) a--;
	else b--;
	cout<<a<<' '<<b<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--) 
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que) priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int>> Matrix;
const int MOD = 1e9 + 7;
const int MAX = 1e7;
const int INF = numeric_limits<int>::max();

int main(){
 int a,b,c,k,t=0,res=0; cin>>a>>b>>c>>k;
 res=a+b+c+max({a,b,c})*pow(2,k)-max({a,b,c});
 cout<<res<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<string> str(N);
    for(int i = 0; i < N; ++i){
        cin >> str[i];
    }
bool is_ok = true;
for(int i = 0; i < N - 1; ++i){
if(str[i].back() != str[i + 1].front())is_ok = false;
for(int i = 0; i < N; ++i){
    for(int j = i + 1; j < N; ++j){
        if(str[i] == str[j]){
            is_ok = false;
        }
    }
}

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

}


Measured memory_bytes: 256
n, m = map(int, input().split())

aList = []
bList = []
aListSlice = []
answer = 'No'

for i in range(n):
    aList = aList + list(input())

for j in range(m):
    bList = bList + list(input())

for right in range(n-m+1):
    for down in range(n-m+1):
        for k in range(m):
            idx = n*(k+down)+right
            aListSlice = aListSlice + aList[idx:idx+m]
        if bList == aListSlice:
            answer = 'Yes'
            break
        aListSlice = []
    if answer == 'Yes':
        break

print(answer)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int count=13;
		int d[]=new int[count];
		int h[] =new int[count];
		int s[]=new int[count];
		int c[]=new int[count];
		int ds=0;
		int hs=0;
		int ss=0;
		int cc=0;
		for(int i=0;i<n;i++) {
			String mark=sc.next();
			if(mark.equals("S")) {
				s[ss]=sc.nextInt();
				ss++;
			}else if(mark.equals("D")) {
				d[ds]=sc.nextInt();
				ds++;
			}else if(mark.equals("C")) {
				c[cc]=sc.nextInt();
				cc++;
			}else {
				h[hs]=sc.nextInt();
				hs++;
			}
		}
		for(int i=1;i<=13;i++) {
			int check=0;
			for(int j=0;j<s.length;j++) {
				if(i==s[j]) {
					check++;
				}
			}
			if(check==0) {
				System.out.println("S "+i);
			}
		}
		for(int i=1;i<=13;i++) {
			int check=0;
			for(int j=0;j<h.length;j++) {
				if(i==h[j]) {
					check++;
				}
			}
			if(check==0) {
				System.out.println("H "+i);
			}
		}
		for(int i=1;i<=13;i++) {
			int check=0;
			for(int j=0;j<c.length;j++) {
				if(i==c[j]) {
					check++;
				}
			}
			if(check==0) {
				System.out.println("C "+i);
			}
		}
		for(int i=1;i<=13;i++) {
			int check=0;
			for(int j=0;j<d.length;j++) {
				if(i==d[j]) {
					check++;
				}
			}
			if(check==0) {
				System.out.println("D "+i);
			}
		}
	}
}


Measured memory_bytes: 26184
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

#include<bits/stdc++.h>
using namespace std;

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=2e5+5;
const int mod=1e9+7;

signed main(){
    FastIO;
    int x;
    cin>>x;
    rep(i,-2000,2000) rep(j,i+1,2000){
        long long unsigned int a=1ull*i*i*i*i*i;
        long long unsigned int b=1ull*j*j*j*j*j;
        if(b-a==x) return cout<<j<<' '<<i,0;
    }
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>

using namespace std;


int main(){
	int mon = 100000;
	int r = 5;
	int n;
	cin >> n;

	for (int i=0 ; i< n ; i++){
		mon += mon * r / 100;
		if((mon-1)/1000 == mon/1000){
			mon = mon/1000;
			mon++;
			mon = mon * 1000;
		}
	}

	cout << mon << endl;
	return 0;
}

Measured memory_bytes: 1160
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const s = args[0]
	console.log(`${s[0][0]}${s[1][0]}${s[2][0]}`.toUpperCase())
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

lli n;

lli cnt;
map<string,bool> vis;
void func(string s,lli flag){
    if(vis[s])return;
    if(s.size() > to_string(n).size())return;
    if(s.size() == to_string(n).size() && s>to_string(n))return;

    vis[s]=true;
    if(flag == (1LL<<3)-1)cnt++;

    string t="3",f="5",ss="7";
    func(s+t,flag|(1LL<<0));
    func(s+f,flag|(1LL<<1));
    func(s+ss,flag|(1LL<<2));
}

int main(){
    // cout << fixed << setprecision(5);

    cin>>n;

    func("",0);

    cout<<cnt<<endl;
    
    return 0;
}


Measured memory_bytes: 10368