akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;

const ll linf = 1LL << 62;
const int inf = 99999999;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };
const ll atcoder = 1e9 + 7;

#define Endl endl
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pb push_back
#define pr(x) cout << x << endl
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define rep(i,n) for(int i= 0;i<n;i++)
#define FOR(i,a,b) for(int i = a;i<b;i++)

template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

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

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

int main() {

	int a, b ,c;
	cin >> a >> b >> c;
	if (a + b >= c)pr("Yes");
	else pr("No");

	//system("pause");
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
#define asn ans
using namespace std;
template <typename T> istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;

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

int main() {
	int n, k; CI n >> k;
	if (n%k) CO 1 EN;
	else CO 0 EN;
	return 0;
}

Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n,k = readInts()
    A = [int(input()) for _ in range(n)]
    A = sorted(A)
    min_ = float('inf')
    for i in range(n-k+1):
        min_ = min(min_,abs(A[i] - A[i+k-1]))
    print(min_)



if __name__ == '__main__':
  main()


Measured memory_bytes: 8280
#include <stdio.h>
#include <string.h>
 
char str [100005];
char dr[10]="dream";
char er[10]="erase";
 
int main()
{
    while (scanf("%s",&str)!=EOF)
    {
        int len = strlen (str);
        int i,ok=1;
        for (i=0;i<len;i++)//dreameraser
        {
            if (str[i]=='d')
            {
                int j;
                for (j=i;j<=i+4;j++)
                {
                    if (j>=len||dr[j-i]!=str[j])
                    {
                        ok=0;
                        break;
                    }
                }
                if (j==i+5)//是dream
                {
                    i=j-1;
                    if (str[j]=='e'&&str[j+1]=='r'&&str[j+2]!='a')
                    {
                        i=j+1;
                    }
                }
            }
            else if (str[i]=='e')
            {
                int j;
                for (j=i;j<=i+4;j++)
                {
                    if (j>=len||er[j-i]!=str[j])
                    {
                        ok=0;
                        break;
                    }
                }
                if (j==i+5) //是erase
                {
                    i=j-1;
                    if (str[j]=='r') i=j;
                    else i=j-1;
                }
            }
            else ok=0;
            if (ok==0) break;
        }
        if (ok==1)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 256
def nc2(n):
	return (n*(n-1))//2
n=int(input())
arr=[int(x) for x in input().split()]
cnt={}
for x in arr:
	if x in cnt:
		cnt[x]+=1
	else:
		cnt[x]=1
ans=0
for x in cnt:
	ans+=nc2(cnt[x])
for x in arr:
	print(ans+nc2(cnt[x]-1)-nc2(cnt[x]))

Measured memory_bytes: 25764
import sys

n = int(input())
a = list(map(int,input().split()))

for i in range(n):
	if a[i] % 2 == 0:
		if a[i] % 3 != 0 and a[i] % 5 != 0:
			print('DENIED')
			sys.exit()

print('APPROVED')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100005
typedef long long LL;

LL pre[MAXN], cur[MAXN];

int main()
{
	int n, w, wei, val;
	cin >> n >> w;
	
	fill(pre+1, pre+w+1, -LLONG_MAX);
	
	for (int i = 1; i <= n; i++)
	{
		cin >> wei >> val;
		
		//copy(pre, pre+w+1, cur);
		
		for (int j = wei; j <= w; j++)
		{
			cur[j] = max(pre[j], pre[j-wei]+val);
		}
		
		copy(cur, cur+w+1, pre);
	}
	
	cout << *max_element(cur+1, cur+w+1) << "\n";
}

Measured memory_bytes: 1792
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

func getStirlingType2(n, k, p int) [][]int {
	table := make([][]int, n+1)
	table[1] = make([]int, k+1)
	table[1][1] = 1
	for i := 2; i <= n; i++ {
		table[i] = make([]int, k+1)
		for j := 1; j <= k; j++ {
			table[i][j] = (table[i-1][j-1] + j*table[i-1][j]) % p
		}
	}
	return table
}

func main() {
	scanner.Split(bufio.ScanWords)

	prime := 1000000000 + 7

	nBalls := nextInt()
	nBoxes := nextInt()

	if nBalls < nBoxes {
		fmt.Println(0)
	} else {
		table := getStirlingType2(nBalls, nBoxes, prime)
		nCombinations := table[nBalls][nBoxes]
		for i := 1; i <= nBoxes; i++ {
			nCombinations = (nCombinations * i) % prime
		}
		fmt.Println(nCombinations)
	}
}



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

int main() {

	int x; cin >> x;
	int ans = 0;
	for (int y = x; y  >= 1; y--) {
		for (int b = 1; b <= 100; b++) {
			for (int p = 2; p <= 5; p++) {
				if (y == pow(b, p)) {
					ans = max(ans, y);
				}
			}			
		}
	}
	cout << ans << endl;
	return 0;
	
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
using namespace std;
int h,w,c[1400][1400],dp[1401][1401],max_width;

int main(){
    cin>>h>>w;
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            cin>>c[i][j];
        }
    }

    for(int i=1;i<=h;++i){
        for(int j=1;j<=w;++j){
            if(c[i-1][j-1]==0){
                dp[i][j]=1+min(dp[i-1][j],min(dp[i-1][j-1],dp[i][j-1]));
                max_width=max(max_width,dp[i][j]);
            }
        }
    }

    cout<<max_width*max_width<<endl;

}


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

int cnt1[26], cnt2[26];

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

	for (auto i : s) cnt1[i - 'a']++;
	for (auto i : t) cnt2[i - 'a']++;

	sort(cnt1, cnt1 + 26); sort(cnt2, cnt2 + 26);

	for (int i = 0;i < 26;i++) {
		if (cnt1[i] != cnt2[i]) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
    return 0;
}



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

int main(){
    int a;
    int b;
    int c;
    cin >> a >> b >> c;
    if(a<b && b<c){
        cout << "Yes" << endl;
    }else if(a>b || b>c || a==b || b==c){
        cout << "No" << endl;
    }
    return 0;
}
    


Measured memory_bytes: 3068
#include <climits>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

template<class T> inline void chmin(T& a, T b) { if(b < a) a = b; }

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

struct node {
	int x, y, d;
	node(int x, int y, int d):x(x), y(y), d(d) {}

	bool operator>(const node& o) const {
		return d > o.d;
	}
};

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

	int w, h;
	cin >> w >> h;

	vector<string> field(h);
	for(int i = 0; i < h; ++i)
		cin >> field[i];

	int gx, gy;
	vector<vector<int> > label(h, vector<int>(w, 0));
	for(int i = 0; i < h; ++i) {
		for(int j = 0; j < w; ++j) {
			if(field[i][j] == '#')
				label[i][j] = INT_MAX;

			else if(field[i][j] == 't') {
				gx = j;
				gy = i;
			}
		}
	}

	int n;
	cin >> n;

	for(int i = 1; i <= n; ++i) {
		int x, y;
		cin >> x >> y;
		chmin(label[y][x], i);
	}

	vector<vector<int> > dist(h, vector<int>(w, INT_MAX));
	dist[0][0] = 0;

	priority_queue<node, vector<node>, greater<node> > que;
	que.push(node(0, 0, 0));

	while(!que.empty()) {
		node n = que.top();
		que.pop();

		for(int i = 0; i < 4; ++i) {
			int x = n.x + dx[i];
			int y = n.y + dy[i];

			if(x < 0 || y < 0 || x >= w || y >= h || dist[y][x] == label[y][x])
				continue;

			if(dist[y][x] > max(n.d, label[y][x])) {
				dist[y][x] = max(n.d, label[y][x]);
				que.push(node(x, y, dist[y][x]));
			}
				
		}
	}

	cout << (dist[gy][gx] == INT_MAX ? -1 : dist[gy][gx]) << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 17668
#include<bits/stdc++.h>
#define ll long long
const int N=100005;
using namespace std;
ll n,r,g,b;
string s;
int main(){
	cin>>n>>s;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='R') r++;
		if(s[i]=='G') g++;
		if(s[i]=='B') b++;
	}
	ll ans=r*g*b,x=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			int k=j+(j-i);
			if(k>=n) break;
			if(s[i]!=s[k]&&s[j]!=s[k]&&s[i]!=s[j]) x++;
		}
	}
	cout<<ans-x;
    return 0;
}

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

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

using namespace std;

using ll = long long int;

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec)
{
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> s(n);
  rep(i, n) {
    cin >> s[i];
  }
  vector<int> cul(n);
  rep(i, n){
    if (i == 0) cul[i] = s[i];
    else cul[i] = cul[i-1]+s[i];
  }
  ll val = 10000000;
  rep(i, n){
    int tmp = abs(cul[i] - (cul[n-1] - cul[i]));
    if(tmp < val) {
      val = tmp;
    }
  }
  cout << val << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>

typedef  long long ll;
#define mop 1000000007
#define mop2 998244353

using namespace std;

int main() {
	ll h1, h2, m1, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	cout << 60 * (h2 - h1) + (m2 - m1) - k << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;

int main()
{

	ios_base:: sync_with_stdio(false); cin.tie(0);
	int n; cin>>n;
	int m= n%1000;
	int ans=(1000-m)%1000;
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 3636
// AOJ 2456: Usoperanto
// 2018.4.17 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// マイナス値の入力に対応
//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	if (c == '-') { c = getchar_unlocked();
		do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

#define MAX 1000002
int  N;
int  m[MAX];
int  *base, bsz;
int  hi[MAX], *to[MAX];
int  que[MAX], top;
int  a[MAX];
long long s[MAX], b[MAX], dp[MAX];

int cmp(long long *a, long long *b)
{
	if (*a == *b) return 0;
	if (*a < *b) return 1;
	return -1;
}

void calc(int u)
{
	int i, v, sz;

	sz = 0, s[u] = m[u], dp[u] = 0;
	for (i = 0; i < hi[u]; i++) {
		v = to[u][i];
		b[sz++] = s[v], s[u] += s[v], dp[u] += dp[v];
	}
	qsort(b, sz, sizeof(long long), cmp);
	for (i = 0; i < sz; i++) dp[u] += b[i]*i;
}

int main()
{
	int i, l, t;
	long long ans;
	int *memo;

	N = in();
	memo = malloc(N<<2);
	for (i = 0; i < N; i++) {
		m[i] = in(), memo[i] = l = in();
		if (l == -1) bsz++;
		else hi[l]++;
	}
	base = malloc(bsz<<2);
	for (i = 0; i < N; i++) if (hi[i]) to[i] = malloc(hi[i]<<2);
	bsz = 0, memset(hi, 0, N<<2);

	for (i = 0; i < N; i++) {
		l = memo[i];
		if (l == -1) base[bsz++] = i;
		else to[l][hi[l]++] = i;
	}

	ans = 0;
	for (i = 0; i < bsz; i++) {
		que[1] = base[i], top = 1;
		while (top) {
			t = que[top];
			if (a[t] < hi[t]) que[++top] = to[t][a[t]++];
			else calc(t), top--;
		}
		ans += dp[base[i]];
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 75940
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <algorithm>
using namespace std;
int n,m,k,f[5005][5005],qz[5005][5005];
const int MOD=1e9+7;
int main()
{
	cin>>n>>m>>k;
	f[0][0]=1;
	#define qzz(c) \
	qz[c][0]=f[c][0];\
	for(int r=1;r<=n;++r)\
		qz[c][r]=(qz[c][r-1]+f[c][r])%MOD;
	qzz(0)
	int ml=(n+m-1)/(k-1),ans=0;
	for(int i=1;i<=ml;++i)
	{
		for(int j=0;j<=n;++j)
		{
			int l=max(j-(k-1),0);
			f[i][j]=qz[i-1][j];
			if(l) f[i][j]-=qz[i-1][l-1];
			f[i][j]%=MOD;
		}
		qzz(i)
		for(int j=1;j<=n;++j)
		{
			int fn=f[i][j]-f[i-1][j]; fn%=MOD;
			if(j%(k-1)==n%(k-1)&&(k-1)*i-j<m)
				(ans+=fn)%=MOD;
		}
	}
	ans=(ans%MOD+MOD)%MOD;
	printf("%d\n",ans);
}


Measured memory_bytes: 159232
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <iomanip>
#include <cstring>
#include <math.h>
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
using namespace std;

int swap(int &a,int &b){
	int c;
	c=a;
	a=b;
	b=c;

	return 0;
}



int main(){
	while(1){
	char op;
	int a,b;
	cin>>a>>op>>b;
	switch(op){
		case '+':
			cout<<a+b<<endl;
			break;
		case '-':
			cout<<a-b<<endl;
			break;
		case '/':
			cout<<a/b<<endl;
			break;
		case '*':
			cout<<a*b<<endl;
			break;
		default:
			break;
	}
	if(op=='?')
		break;
	}
	return 0;
}

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

int main() {
    ll a,b,x;
    cin >> a >> b >> x;
    ll ans;
    if (a>0) ans=b/x-((a-1)/x);
    else ans=b/x+1;
    cout << ans << endl;
}

Measured memory_bytes: 256
N,M = map(int,input().split(" "))
List = [0]*M
for i in range(N):
    LIst = [int(i)-1 for i in input().split(" ")]
    for l in LIst[1:]:
        List[l]+=1
count = 0
for i in List:
    if i==N:
        count+=1
print(count)

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>

int main(void)
{
    char c[2];
    char aiueo[] = "aiueo";
    int i;
    scanf("%s", c);
    for(i = 0; i < strlen(aiueo); i++){
        if (c[0] == aiueo[i]) {
            printf("vowel\n");
            break ;
        }
        if (i == strlen(aiueo)-1) {
            printf("consonant\n");
        }
    }

    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define MOD 1000000007
typedef long long ll;

int main(){
	char str[5];
	scanf("%s", str);
	if((str[0] == str[1]) && (str[1] == str[2])) printf("No");
	else printf("Yes");
	return 0;
}


Measured memory_bytes: 128
//A
#include <bits/stdc++.h>
#define reg register

using namespace std;

typedef long long ll;
const int maxn = 100005;

inline ll read() {
    reg ll s = 0, t = 0; reg char ch = getchar();
    while (!isdigit(ch)) t |= ch == '-', ch = getchar();
    while (isdigit(ch)) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return t ? -s : s;
}

int main() {
    int n; cin >> n;
    reg int res = n / 2;
    if (n % 2) cout << (double)(res + 1) / (double)n << endl;
    else cout << (double)res / (double)n << endl;
    return 0;
}


Measured memory_bytes: 256
import math
import sys

def insertion_sort(a, n, g):
    ct = 0
    for i in range(g,n):
        v = a[i]
        j = i-g
        while j >= 0 and a[j] > v:
            a[j+g] = a[j]
            j = j-g
            ct += 1
        a[j+g] = v
    return ct

n = int(input())
a = list(map(int, sys.stdin.readlines()))
m = 0
b = 0
ct= 0
g = []
while True:
    b = math.ceil(2.25*b+1)
    if b > n:
        break
    g.append(b)
    m += 1
g = g[::-1]

for i in g:
    ct += insertion_sort(a, n, i)

print(m)
print(*g, sep=" ")
print(ct)
print(*a, sep="\n")

Measured memory_bytes: 118544
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

class Main {

	public static void main(String[] args) throws Exception {

		try {

			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

			int N = Integer.parseInt(br.readLine());

			int result = getSum(N);
			
			System.out.println(result);
			
		} catch (IOException | NumberFormatException e) {
			e.printStackTrace();
			System.exit(0);
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(0);
		}

	}
	
	public static int getSum(int N) {
		int sum = 0;
		for(int i = 1; i <= N; i++) {
			sum += i;
		}
		
		return sum;
	}
}

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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353
#define Graph vector<vector<int>>

int main() {
    vector<int> X(3);
    for (int i = 0; i < 3; i++) cin >> X.at(i);
    sort(X.begin(), X.end());
    int &A = X.at(0), &B = X.at(1), &C = X.at(2);
    int ans = 0;
    while (A != B || B != C || C != A) {
        if (A < C && B < C) {
            A++;
            B++;
            ans++;
        }
        else if (A < C && B >= C) {
            A += 2;
            ans++;
        }
        else if (A >= C && B < C) {
            B += 2;
            ans++;
        }
        sort(X.begin(), X.end());
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF pow(10, 9) + 7
#define rep(i, N) for(ll i = 0; i < N; i++)
#define rep2(i, j, k) for(ll i = j; i < k; i++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define chmax(x, y) x = max(x, y)
#define print(x) cout << x << "\n"
#define printv(vec) rep(i, vec.size()) cout << vec[i] << " "
#define ALL(v) v.begin(), v.end()
#define SUM(v) accumulate(ALL(v), 0)
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
typedef long long ll;
using namespace std;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;
using vvs = vector<vector<string>>;

void solve(){
	
	ll N;
	cin >> N;
	vl A(N);
	rep(i, N) cin >> A[i];
	
	vl acc(N + 5);
	rep(i, N) acc[i + 1] = acc[i] + A[i];
	ll ans = 0;
	map<ll, ll> mp;
	rep(i, N + 1){
		ans += mp[acc[i]];
		mp[acc[i]] += 1;
	}
	
	print(ans);

}	

int main(){
    
    fastio;
	solve();
    
	return 0;
	
}


Measured memory_bytes: 18644
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int f(ll a,ll b){
  if(b==0){return 1;}
  if(b%2==0){return (f(a*a%2019,b/2));}
  if(b%2==1){return (a*f(a,b-1)%2019);}
}
int main() {
  string s;
  cin>>s;
  ll N=s.size(),ans=0;
  vector<ll> sum(N+1),vec(2019);
  sum.at(0)=0;
  for(ll i=1;i<=N;i++){
    sum.at(i)=(sum.at(i-1)+f(10,i-1)*(int)(s.at(N-i)-'0'))%2019;
  }
  for(ll i=0;i<=N;i++){
    vec.at(sum.at(i))++;
  }
  for(ll i=0;i<2019;i++){
    if(vec.at(i)>=2){
      ans+=vec.at(i)*(vec.at(i)-1)/2;
    }
  }
  cout<<ans<<endl;
}


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

int main(void){
  char str[10000];
  int JOI,IOI,JOI_check,IOI_check;
  while((scanf("%s",str))!=EOF){
    JOI=0; IOI=0; JOI_check=0; IOI_check=0;

    for(int i=0;i<strlen(str);i++){
      if(str[i]=='J'){ JOI_check=1; }
      else if(str[i]=='O' && JOI_check==1){ JOI_check=2; }
      else if(str[i]=='I' && JOI_check==2){ JOI_check=0; JOI++; }
      else{ JOI_check=0; }
    }

    for(int i=0;i<strlen(str);i++){
      if(str[i]=='I'){
        if(IOI_check==2){ IOI++; }
        IOI_check=1;
       }
      else if(str[i]=='O' && IOI_check==1){ IOI_check=2; }
      else{ IOI_check=0; }
    }
    printf("%d\n%d\n",JOI,IOI);
    str[0]='\0';
  }
  return 0;
}



Measured memory_bytes: 2056
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------
int N,M,Q;
vector<int> a(55),b(55),c(55),d(55);
vector<int> vec;
int mx = 0;


void dfs(int k){
    if(vec.size() == N){
        int sum = 0;
        for(int i=0; i<Q; i++){
            if(vec[b[i]]-vec[a[i]] == c[i]){
                sum += d[i];
            }
        }
        chmax(mx,sum);
        return;
    }
    for(int i=k; i<=M; i++){
        vec.push_back(i);
        dfs(i);
        vec.pop_back();
    }
    return;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> M >> Q;
    for(int i=0; i<Q; i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
    }
    dfs(1);
    cout << mx << enld;
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
using namespace std;
string smallchange(string a){
  for(int i = 0;i < a.length();i++){
    if(a[i] >= 'A' && a[i] <= 'Z'){
      a[i] = a[i] + 0x20;
    }
  }
  return a;
}
int main(){
  int count = 0;
  std::string w;
  std::string t;
  cin >> w;
  w = smallchange(w);
  while(cin >> t){
    if(t == "END_OF_TEXT"){
      break;
    }else{
      t = smallchange(t);
      if(t == w){
        count++;
      }
    }
  }

  cout << count << endl;
}

Measured memory_bytes: 3064
#include<stdio.h>

int main(void)
{

int num[5];
int W,H,x,y,r;
int i;

for(i=0;i<5;i++){
scanf("%d",&num[i]);
}
W=num[0];
H=num[1];
x=num[2];
y=num[3];
r=num[4];

if(x-r<0||x+r>W||y-r<0||y+r>H){
printf("No\n");
}
else if(x-r>=0&&x+r<=W&&y-r>=0&&y+r<=H){
printf("Yes\n");
}

return 0;
}

Measured memory_bytes: 1012
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int A,B,C,D; cin >> A >> B >> C >> D;
    cout << max(0, min(B,D) - max(A,C)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<stdio.h>
#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<map>
#include<utility>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
int main()
{
    ll a,b,h,m;
    cin>>a>>b>>h>>m;
    double pi=acos(-1.0);
    double f=abs(h*30+(m/60.0)*30-m*6)*pi/180.0;
    f=sqrt(a*a+b*b-2*a*b*cos(f));
    cout<<fixed<<setprecision(20);
    cout<<f;


}




Measured memory_bytes: 4168
N,M=map(int,input().split())

AC=[0]*N
WA=[0]*N
ac=0
wa=0

for i in range(M):
    p,s=map(str,input().split())
    P=int(p)
    if s=="AC":
        if AC[P-1]!=P:
            AC[P-1]+=P
            ac+=1
            wa+=WA[P-1]
    else:
        if AC[P-1]!=P:
            WA[P-1]+=1

print(ac,wa)

Measured memory_bytes: 7704
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    ll N;
    string s;
    cin >> N >> s;
    if(N%2==0&&s.substr(0,N/2)==s.substr(N/2,N/2))cout <<"Yes";else cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)



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

	string S;
	cin >> S;
	if (S == "Sunny")puts("Cloudy");
	else if (S == "Cloudy")puts("Rainy");
	else puts("Sunny");

	return 0;
}

Measured memory_bytes: 256
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
#define dcml(n) fixed<<setprecision(n)
//CONST
//------------------------------------------
const ll INF=1010000000000000017LL;
const ll MOD=1000000007LL;
const ld EPS=1e-12;
const ld PI=3.14159265358979323846;
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define  FORS(i,m,n) for(ll (i)=(m);   (i)<=(n); (i)++)
#define  RFOR(i,m,n) for(ll (i)=(n)-1; (i)>=(n); (i)--)
#define RFORS(i,m,n) for(ll (i)=(n);   (i)>(n);  (i)--)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
#define WREPS(i,in,j,jn) REPS(i,in)REPS(j,jn)
//-----------------------------------------
//namespace
using namespace std;
//ライブラリはここに
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

//-----------------------------------------
int main(void){
    vector<ll> x(5);
    REP(i,5)cin>>x[i];
    REP(i,5){
        if(x[i]==0)cout<<i+1;
    }
    cout<<"\n";
}

Measured memory_bytes: 3600
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
  public static void main(String[] args) {
	  FastReader sc = new FastReader();
	  String s = sc.next();
	  String t = sc.next();
	  s += s;
	  
	  if (s.indexOf(t) == -1) {
		  System.out.println("No");
	  } else {
		  System.out.println("Yes");
	  }
  }
  
  static class FastReader {
    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }
  
    String next() { 
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException  e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

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

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() { 
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
        try{
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
      }
  }
}


Measured memory_bytes: 21332
N=int(input())
W=[]
S1=0
min=100000
W=list(map(int, input().split(" ")))
for i in range(len(W)-1):
    S1+=W[i]
    S2=0
    for j in range(i+1,len(W)):
        S2+=W[j]
    if abs(S1-S2)<min:
        min=abs(S1-S2)
print(min)

Measured memory_bytes: 3064
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n,t[60],i,ans,k=0;
  string s[60],x;
  scanf("%d\n",&n);
  for(i=0;i<n;i++){
    cin >> s[i] >> t[i];
  }
  cin >> x;
  for(i=0;i<n;i++){
    if(s[i]==x){
      k=1;
    }
    else{
      if(k==1){
        ans=ans+t[i];
      }
    }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 256
class UnionFind(object):
    def __init__(self, N):
        self.parent = [-1] * N #parent[i] は(i+1)番目の要素が含まれる要素数の(-1)倍
    #要素が負-->その数を親とするグループに属する要素の数×(-1)
    #要素が正-->親のindex

    #Aがどのグループに属しているかを調べる
    def root(self, A):
        if self.parent[A-1] < 0: #負の数-->その数は親
            return A
        self.parent[A-1] = self.root(self.parent[A-1]) #負では無い時、親の場所が入っているから、親が属しているグループを、自分自身に入れる(一度確認したところは直接親を見れるようにする)
        return self.parent[A-1] #親の位置を返す

    #Aが含まれているグループに属している数を返す
    def size(self, A):
        return -1 * self.parent[self.root(A)-1]

    #AとBをくっ付ける
    def connect(self, A, B):
        A = self.root(A) #Aを含むグループの親を返す
        B = self.root(B) #Bを含むグループの親を返す
        if A == B: #親が同じならなにもしない
            return False
        
        #大きい方(A)に小さい方(B)をつなぎたい
        if self.size(A) < self.size(B): #大小関係が逆の時は入れ替える
            A, B = B, A
        
        self.parent[A-1] += self.parent[B-1] #大きい方に小さい方を加える　（負の数＋負の数 = 新しいグループに含まれる数×(-1)）
        self.parent[B-1] = A #加えられた親の値を、加えた先の親の位置に書き変える
        return True
    
    def same(self, A, B):
        if self.root(A) == self.root(B):
            return True
        else:
            return False
            
# N, Q = map(int, input().split())
# uni = UnionFind(N)
# for _ in range(Q):
#     P, A, B = map(int, input().split())
#     if P == 1:
#         if uni.root(A) == uni.root(B): #親が同じかどうか
#             print ('Yes')
#         else:
#             print ('No')
#     else:
#         uni.connect(A, B)

N, M = map(int, input().split())
uni = UnionFind(N)
ans = N
for _ in range(M):
    x, y, z = map(int, input().split())
    x -= 1
    y -= 1
    if uni.root(x) == uni.root(y): #親が同じ時
        pass
    else:
        ans -= 1
        uni.connect(x, y)

print (ans)


Measured memory_bytes: 5376
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.12f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 1010101;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; 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;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[8] = { 1,-1,0,0,1,1,-1,-1 };
ll dy[8] = { 0,0,1,-1,1,-1,1,-1 };
ll d[110][2];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n;
	cin >> n;
	vector<ll>a(n);
	ll ans;
	rep(i, n) {
		cin >> a[i];
		if (i == 0)ans = a[i];
		else {
			ans = gcd(ans, a[i]);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4000
N=int(input())
A=input()
B=input()
C=input()
#print(A[1])
count=0

for i in range(0,N):
    if A[i]==B[i]==C[i]:
        count=count+0
    elif A[i]!=B[i] and B[i]!=C[i] and A[i]!=C[i]:
        count=count+2
    else:
        count=count+1

print(count)        

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

ll MOD;

inline void add(ll &x, ll y) { x += y; if (x >= MOD) x -= MOD; }

ll solve1(int N, int K) {
	vector<vector<ll>> dp(N + 1, vector<ll>(N + 1));

	dp[0][0] = 1;

	rep(i, N) {
		for (int j = 0; j <= min(i, K); ++j) {
			add(dp[i + 1][0], dp[i][j]);
			if (j + 1 <= K) add(dp[i + 1][j + 1], dp[i][j]);
		}
	}

	ll res = 0;

	for (int j = 0; j <= K; ++j) add(res, dp[N][j]);

		return res;
}

const int maxn = 160;

ll dp[2][maxn][maxn][maxn]; //j < k : rightmost excluded elements, l : limitation (0 means none)

ll solve(int N, int K) { // K : odd
	memset(dp, 0, sizeof(dp));

	//handle as 0 and 1 already skipped and start from 2 to N + 1
	int c = 0, f = 1;
	dp[c][0][1][0] = 1;

	++N;

	for (int i = 2; i <= N; ++i) {
		//init
		for (int j = 0; j <= i; ++j) {
			for (int k = j; k <= i; ++k) {
				for (int l = 0; l <= N; ++l) {
					dp[f][j][k][l] = 0;
				}
			}
		}

		for (int j = i % 2; j < i; j += 2) {
			for (int k = j - 1; k >= 0; k -= 2) { //parity : i = j != k, k < j < i
				bool can = (j + K + 2 <= N && i - K - 2 >= k); //a cycle can be formed or not
				//include i and a new constraint (note that constraint is determinied by j), on k side
				add(dp[f][k][j][can ? j + K + 2 : 0], dp[c][k][j][0]);

				//include i
				for (int l = i + 1; l <= N; ++l) {
					add(dp[f][k][j][l], dp[c][k][j][l]);
				}

				//exclude i
				for (int l = 0; l <= N; ++l) {
					add(dp[f][k][i][l], dp[c][k][j][l]);
				}
			}

			for (int k = j + 1; k < i; ++k) { //parity : i = j != k, j < k < i
				//include i
				add(dp[f][j][k][0], dp[c][j][k][0]);

				for (int l = i + 1; l <= N; ++l) {
					add(dp[f][j][k][l], dp[c][j][k][l]);
				}

				//exclude i
				for (int l = 0; l <= N; ++l) {
					add(dp[f][k][i][0], dp[c][j][k][l]);
				}
			}
		}
		swap(c, f);
	}
	ll ans = 0;
	for (int j = 0; j <= N; ++j) {
		for (int k = 0; k <= N; ++k) {
			for (int l = 0; l <= N; ++l) {
				add(ans, dp[c][j][k][l]);
			}
		}
	}
	return ans;
}

int main() {
	int N, K, M; cin >> N >> K >> M;
	MOD = M;

	if (K % 2 == 0) {
		ll ans = solve1(N / 2, K / 2) * solve1((N + 1) / 2, K / 2) % MOD;
		cout << ans << endl;
	} else if (K == 1) {
		ll ans = solve1(N, 2);
		cout << ans << endl;
	} else {
		ll ans = solve(N, K);
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 64384
using System;
using System.Collections.Generic;
using System.Linq;
class Ho{
  static void Main(){
    var aho = Console.ReadLine();
    if(aho == "AAA" || aho == "BBB"){
		Console.WriteLine("No");
    }
    else{
      Console.WriteLine("Yes");
    }
  }
}
 

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

public class Main {
    static final int MX = 100_000;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int num[] = new int[MX + 1];
        Arrays.fill(num, 0);

        int n = in.nextInt();
        int a[] = new int[n];
        long total = 0;
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            num[a[i]]++;
            total += a[i];
        }

        int q = in.nextInt();
        for (int i = 0; i < q; i++) {
            int b = in.nextInt();
            int c = in.nextInt();

            total += (num[b] * (c - b));
            num[c] += num[b];
            num[b] = 0;
            System.out.println(total);
        }        
    }
}

Measured memory_bytes: 61004
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
int main() {
	string s;
	std::cin >> s;
	
	for (int i = 0; i < 3; i++) {
	    if(s[i]==s[i+1]) {
	        std::cout << "Bad" << std::endl;
	        return 0;
	    }
	}
	std::cout << "Good" << std::endl;
	return 0;
}

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

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            var result = Volume0.ListOfTop3Hills();
            System.Diagnostics.Trace.WriteLine(result);
            Console.WriteLine(result);
        }
    }

    public static class Volume0
    {
        public static string ListOfTop3Hills()
        {
            var input = Console.ReadLine();
            var hills = new List<int>();
            while (!string.IsNullOrEmpty(input))
            {
                hills.Add(int.Parse(input));
                input = Console.ReadLine();
            }

            return string.Join("\n", hills.OrderByDescending(x => x).Select(x => x.ToString()).Take(3).ToArray());
        }
    }
}

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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n);
  vector<int> b(m);
  vector<ll> aSum(n + 1, 0);
  vector<ll> bSum(m + 1, 0);
  rep(i, n) {
    cin >> a.at(i);
    aSum.at(i + 1) = (ll) a.at(i) + aSum.at(i);
  }
  rep(i, m) {
    cin >> b.at(i);
    bSum.at(i + 1) = (ll) b.at(i) + bSum.at(i);
  }
  int res = 0;
  for (int ac = 0; ac <= n; ac++) {
    ll xSumV = aSum.at(ac);
    if (xSumV > k) {
      continue;
    }
    auto itB = upper_bound(bSum.begin(), bSum.end(), (ll) k - xSumV);
    int bc = (ll) distance(bSum.begin() + 1, itB);
    res = max(res, ac + bc);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 7964
#include <bits/stdc++.h>
#include <cmath>
#include <set>
#include <cstdio>
#include <vector>
#include <iostream>
#include <utility>

#define fir first
#define sec second
#define pb push_back
#define get(n) scanf("%d",&n);
#define gets(s) string s;cin >> (s);
#define prfi(n) printf("%d", &n);
#define prfd(n) printf("%lf", &n);
#define All(s) (s).begin(), (s).end()
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);
#define rep(i, j) for (int (i)=0;(i)<(j);(i)++)
#define repk(i, j, k) for(int (i)=(j);(i)<(k);(i)++)
#define repdown(i, j, k) for(int (i)=(j);(i)>=(j);(i)--)
#define dump(x)  std::cout << #x << " = " << (x) << std::endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using ll = long long;
using vi = std::vector<int> ;
using vvi = std::vector<vi> ;
using vd = std::vector<double> ;
using vvd = std::vector<vd> ;
using qi = std::queue<int> ;
using namespace std;

const int Mod = 1e9 + 7;
const int max_n = 3 * 1e5 + 1;
const int max_m = 83 * 1e5 + 1;
const ll INF = 10241024;
long double INFD = 100100100;

//_________template______________
inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

//_____________________array calc____________________________________//
/*
vvi mul(vvi &A, vvi &B){
  vvi C(A.size(), vi(B.size()))
  rep(i,A.size()){
    rep(j,B.size()){
      rep(k,B[0].size()){
        C[i][j] = (C[i][j] A[i][k] + B[k][j]) % Mod;
      }
    }
  }

  return C;
}

vvi pow(vvi A, ll n){
  vvi B(A.size(), vi(A.size()));
  rep(i=0;i<A.size();i++){
    B[i][i] = 1;
  }

  while (n >0){
    if (n & 1) B = mul(B, A);
    A = mul(A, A);
    n = n >> 1;
  }
  return B;
}
*/
//_____________________Bynary Indexed Tree __________________________//
/*
const max_st = (1 << 15) - 1;
int bit[max_st];
int sum (int i){
  int s = 0;
  while(i > 0){
    s += bit[i];
    i -= i & -i;
  }
  return s;
}

void add(int i, int x){
  while(i <= n){
    bit[i] += x;
    i += i & -i;
  }
}
*/
//_____________________　following sorce code_________________________//
ll n;
void input(){
  IN(n);
}

void solve(){
  input();
  if(n == 1ll)
  {
    OUT(0);
    return ;
  }

  ll sum = 0;
  for(ll i=1ll;i<n;i++){
    sum += i;
  }
  

  OUT(sum);
}

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





Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

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

        // input
        String input = scan.next();
        char[] board = input.toCharArray();

        // search
        int count = 0;
        char temp = board[0];
        for(int i = 1; i < board.length; i++){
            if(temp != board[i]){
                count++;
                temp = board[i];
            }
        }

        // answer
        System.out.println(count);

    }
}

Measured memory_bytes: 27052
//参考：https://qiita.com/DaikiSuyama/items/9dba963ba74396b9b7fd
//インクルード(アルファベット順)
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define FIR first    //pairの一つ目の要素
#define SEC second   //pairの二つ目の要素

signed main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll N;
    cin >> N;

    vector<ll> A(N);
    REP(i, N)
    {
        cin >> A[i];
    }

    //降順にソートした順番で挿入するのが最適解の一つ
    sort(ALL(A), greater<ll>());

    //1番大きい数を1回、それ以外を大きい順に2回ずつ足していくのが最大
    ll ans = A[0];
    FOR(i, 2, N - 1)
    {
        ans += A[i / 2];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4440
#include <bits/stdc++.h>
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;

ll dp[405][405];
int dpi[405][405];
ll S[405];

int A[405];

int N;

int main() {
	ios::sync_with_stdio(false);

	cin >> N;
	for(int i = 1; i <= N; i++) {
		cin >> A[i];
		S[i] = S[i-1] + A[i];
		dp[i][i+1] = 0;
		dpi[i][i+1] = i+1;
	}

	for(int l = 2; l <= N; l++) {
		for(int s = 1, e = l+1; e <= N+1; s++, e++) {
			ll &ret = dp[s][e]; ret = INFLL;
			int &v = dpi[s][e];
			for(int k = dpi[s][e-1], ke = dpi[s+1][e]; k <= ke; k++) {
				ll t = dp[s][k] + dp[k][e] + S[e-1] - S[s-1];
				if(ret <= t) continue;
				ret = t; v = k;
			}
		}
	}

	cout << dp[1][N+1] << endl;
	return 0;
}

Measured memory_bytes: 2176
using System;
using System.Collections.Generic;

namespace ABC065B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var a = new Dictionary<int, int>();
            for(var i = 1; i <= N; i++)
            {
                a[i] = int.Parse(Console.ReadLine());
            }

            var btn = 1;
            var cnt = 0;
            while (true)
            {
                if (btn == 2)
                {
                    Console.WriteLine(cnt);
                    return;
                }
                else if (a.ContainsKey(btn))
                {
                    var next = a[btn];
                    a.Remove(btn);
                    btn = next;
                    cnt++;
                }
                else
                {
                    Console.WriteLine(-1);
                    return;
                }
            }
        }
    }
}


Measured memory_bytes: 35148
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
 
const int MAXN = 1000 + 10;
const int MOD = 20071027;
 
int n;
int L[MAXN];
 
int main() {
    while (scanf("%d", &n) != EOF) {
        for (int i = 0; i < n * 2; ++i) {
            scanf("%d", &L[i]);
        }
        sort(L, L + 2 * n);
        int ans = 0;
        for (int i = 2 * n - 1; i >= 0; i -= 2) {
            ans += min(L[i], L[i - 1]);
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
node = Array.new(n)
parent = Array.new(n,-1)
sibling = Array.new(n,-1)
degree = Array.new(n,0)
depth = Array.new(n)
height = Array.new(n)

n.times do
  l = gets.split.map(&:to_i)
  node[l[0]] =  l[1,2]
end
n.times do |i|
  a, b = node[i]
  parent[a] = i if a != -1
  parent[b] = i if b != -1
  sibling[a] = b if a != -1 && b != -1
  sibling[b] = a if a != -1 && b != -1
  degree[i] = 2 - [a,b].count(-1)
end
depth[p = parent.index(-1)] = 0
cnt = 0
while depth.any?{|v| v.nil?}
  n.times do |i|
    if depth[i] == cnt
      a, b = node[i]
      depth[a] = cnt + 1 if a != -1
      depth[b] = cnt + 1 if b != -1
    end
  end
  cnt += 1
end
n.times{ |i| height[i] = 0 if degree[i] == 0 }
cnt = 0
while true
  f = false
  n.times do |i|
    if height[i] == cnt 
      next if parent[i] == -1 
      height[parent[i]] = cnt + 1
      f = true
    end
  end
  break unless f 
  cnt += 1
end
type = Array.new(n)
n.times{|i| type[i] = parent[i] == -1 ? "root" : node[i].count(-1) == 2 ? "leaf" : "internal node"}
n.times{|i| puts "node #{i}: parent = #{parent[i]}, sibling = #{sibling[i]}, degree = #{degree[i]}, depth = #{depth[i]}, height = #{height[i]}, #{type[i]}"}

Measured memory_bytes: 8756