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

using namespace std;

int main()
{
    int N, count, num, num_boll = 0;
    cin >> N;
    vector<int> array(N + 1), bolls(N + 1);
    for (int i = 1; i < N + 1; i++)
    {
        cin >> array.at(i);
    }

    for (int i = N; i > 0; i--)
    {
        count = 2;
        num = 0;
        for (int j = i * count; j < N + 1; ++count, j = i * count)
        {
            num += bolls.at(j);
        }
        bolls.at(i) = !(num % 2 == array.at(i));
        num_boll += !(num % 2 == array.at(i));
    }

    count = 0;

    cout << num_boll << endl;
    for (int i = 1; i < N + 1; i++)
    {
        if (count)
            cout << " ";
        if (bolls.at(i))
        {
            cout << i;
            ++count;
        }
    }
    if (count)
        cout << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lowb lower_bound
#define upb upper_bound
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
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;};



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

	int ans1 = 0, ans2 = 0;
	int a, b, c;
	while(scanf("%lld,%lld,%lld", &a, &b, &c) != EOF) {
		if(a * a + b * b == c * c) ans1++;
		if(a == b) ans2++;
	}
	cout << ans1 << endl;
	cout << ans2 << endl;
	return 0;
}


Measured memory_bytes: 3168
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner scan = new Scanner(System.in);
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		int n = si();
		while(n-->0){
			char[] mozi = scan.next().toCharArray();
			Arrays.sort(mozi);
			String min = "",max = "";
			for (int i = 0; i < mozi.length; i++){
				min+=mozi[i];
				max=mozi[i]+max;
			}
			out.println(Integer.parseInt(max)-Integer.parseInt(min));
		}
		out.flush();
	}

	static int si() {
		return Integer.parseInt(scan.next());
	}
}

Measured memory_bytes: 17168
import sys
from itertools import accumulate
input=sys.stdin.buffer.readline
def main():
    n,k=map(int,input().split())
    a=[*map(int,input().split())]
    for _ in range(min(k,41)):
        b=[0]*n
        for i,t in enumerate(a):
            if i>t:b[i-t]+=1
            else:b[0]+=1
            j=i-~t
            if j<n:b[j]-=1
        a=[*accumulate(b)]
    print(' '.join(map(str,a)))
main()

Measured memory_bytes: 35596
import sys
readline = sys.stdin.readline

def solve():
    N = int(readline())
    A = list(map(int, readline().split()))

    ans = 0
    for i, a in enumerate(A):
        if (i + 1) % 2 == 1 and a % 2 == 1:
            ans += 1
    
    print(ans)


solve()

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

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


Measured memory_bytes: 512
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, M, Q, L, R;
int DP[501][501], Sum[501][501];

int main(){
  scanf("%d%d%d", &N, &M, &Q);
  for (int i = 0; i < M; i++){
    scanf("%d%d", &L, &R);
    DP[L][R]++;
  }

  for (int i = 1; i <= N; i++){
    for (int j = 1; j <= N; j++){
      Sum[i][j] = Sum[i-1][j] + Sum[i][j-1] - Sum[i-1][j-1];
      Sum[i][j] += DP[i][j];
    }
  }
  
  for (int i = 0; i < Q; i++){
    int p, q; scanf("%d%d", &p, &q);
    printf("%d\n", Sum[q][q] - Sum[p-1][q] - Sum[q][p-1] + Sum[p-1][p-1]);
  }
  
  return 0;
}


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

int main() {
		int A, B;
		cin >> A >> B;
		int sum = A;
		int count = 1;
		while(sum < B){
				count += 1;
				sum = A + (A-1) * (count - 1);
		}
		if(B == 1){
				cout << 0 << endl;
		} else {
				cout << count << endl;
		}
}
		


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

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}

using Graph = vector<vector<int>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}

typedef pair<int,int> P;

bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}
int factorial(int a){
  int res = 1;
  while(a){
    res *= a;
    a--;
  }
  return res;
}

int main(){
  int A,B;
  cin >> A >> B;
  if(A%3 == 0 || B%3 == 0 || (A+B)%3 == 0) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
 }

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a1 = new int[n];
        int[] a2 = new int[n];
        
        for (int i = 0; i < n; i++) {
            a1[i] = sc.nextInt();
        }
        
        int sum = a1[0];
        for (int i = 0; i < n; i++) {
            a2[i] = sc.nextInt();
            sum += a2[i];
        }
        
        int max = sum;
        
        for (int i = 1; i < n; i++) {
            sum = sum + a1[i] - a2[i - 1];
            max = Math.max(max, sum);
        }
        System.out.println(max);
    }
}

Measured memory_bytes: 21844
#include<iostream>
using namespace std;
int main(){
    int a,b,c,i,sum;
    sum=0;
    cin >>a >>b >>c;
    for(i=a;i<=b;i++){
        if(c%i==0){
            sum++;
        }
        else{
            continue;
        }
    }
    cout << sum <<endl;
    return 0;
}


Measured memory_bytes: 3108
#include<cstdio>
#include<queue>
#include<iostream>
#define ll long long
using namespace std;
ll res[4][2]={-1,0,0,1,0,-1,1,0};
char map1[60][60];
ll step[60][60];
ll n,m;
ll bfs()
{
	map1[0][0]='#';
	step[0][0]=0;
	queue<ll>qu;
	qu.push(0);
	qu.push(0);
	while(!qu.empty())
	{
		ll x=qu.front();qu.pop();
		ll y=qu.front();qu.pop();
		if(x==n-1&&m-1==y)return step[x][y];
		for(int i=0;i<4;++i)
		{
			ll dx=x+res[i][0];
			ll dy=y+res[i][1];
			if(dx>=0&&dx<n&&dy>=0&&dy<m&&map1[dx][dy]=='.')
			{
				map1[dx][dy]='#';
				step[dx][dy]=1+step[x][y];
				qu.push(dx);
				qu.push(dy);
			}
		}
	}
	return -1;
}
int main()
{
	while(cin>>n>>m)
	{
		for(ll i=0;i<n;++i)
		    cin>>map1[i];
		ll sum=0;
		for(ll i=0;i<n;++i)
		{
			for(int j=0;j<m;++j)
			    if(map1[i][j]=='.')
			        sum++;
		}
		ll ss=bfs();
		if(ss==-1)puts("-1");
		else printf("%lld\n",sum-ss-1);
	}
	return 0;
}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const char nl = '\n';

// INT VS LL

int win(char c){
	if (c=='r') return 2;
	if (c=='p') return 1;
	return 0;
}

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

    int n,k;
    cin>>n>>k;
    int a[3], ans=0;
    cin>>a[0]>>a[1]>>a[2];
    string t;
    cin>>t;
    vector<int> w(n);
    for (int i=0; i<n; ++i){
    	// cout<<win(t[i])<<nl;
    	int cur=win(t[i]);
    	if (i-k<0){
    		ans+=a[cur];
    		w[i]=cur;
    	}
    	else{
    		if (cur!=w[i-k]){
    			ans+=a[cur];
    			w[i]=cur;
    		}
    		else w[i]=-1;
    	}
    }
    cout<<ans<<nl;

    return 0;
}

Measured memory_bytes: 3832
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := readInt()
	type station struct{ c, s, f int }
	st := make([]station, n-1)
	for i := range st {
		c, s, f := readInt(), readInt(), readInt()
		st[i] = station{c, s, f}
	}

	var wr = bufio.NewWriter(os.Stdout)
	for i := range st {
		ans := 0
		for j := i; j < n-1; j++ {
			if ans <= st[j].s {
				ans = st[j].s
			} else {
				d := (ans - st[j].s + st[j].f - 1) / st[j].f
				ans = d*st[j].f + st[j].s
			}
			ans += st[j].c
		}
		wr.WriteString(strconv.Itoa(ans) + "\n")
	}
	wr.WriteString(strconv.Itoa(0) + "\n")
	wr.Flush()
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std ;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define ll long long
typedef long double ld ;
typedef vector<int> vi ;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define fre(i,a,b) for(int i=a;i<=b;i++)
#define rpe(i,a,b) for(i=a-1;i>=b;i--)
#define rp(i,n) rep(i,0,n)
#define fr(i,n) fre(i,1,n)
#define trav(a, x) for (auto& a : x)
#define pb push_back
#define F first
#define S second
#define pb push_back
#define prec(n) fixed<<setprecision(n)
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define mod 1e9+7

int32_t main(){

    IOS ;
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    int n, k ;
    cin >> n >> k ;

    rep(i,k-n+1,k+n)
    {
        cout << i << " " ;
    }cout << endl ;

return 0;}
///.... -dASH


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

int q,ans[100005],sum[100005],l,r;

int verificare(int x){
    if(x==1 || x==7) return 0;
    if(x==3 || x==5) return 1;
    int y=0;
    for(int i=2;i<=ceil(sqrt(x));i++){
        if(x%i==0) y++;
    }
    int z=(x+1)/2;
    if(z!=2) for(int i=2;i<=ceil(sqrt(z))+1;i++) if(z%i==0) y++;
    if(y==0) return 1; else return 0;
}


int main()
{
    ios_base::sync_with_stdio(0);cin.tie();cout.tie();
    cin >> q;
    for(int i=3 ;i<=100000 ;i++)  sum[i]=sum[i-1]+verificare(i);
    for(int i=1 ;i<=q ;i++){
        cin >> l >> r;
        ans[i]=sum[r]-sum[l-1];
    }
    for(int i=1 ;i<=q ;i++)   cout << ans[i] << "\n";
    
}

Measured memory_bytes: 1408
import sys
import time
import math
def inpl():
    return list(map(int, input().split()))
st = time.perf_counter()
# ------------------------------

N = int(input())
for i in range(N, 1000):
	if i//100==(i//10)%10:
		if i//100==i%10:
			print(i)
			sys.exit()

# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)


Measured memory_bytes: 8972
n = gets.to_i
alphabets = ('a'..'z').to_a
array = [n]
while array.last > 26
  div, mod = (array.last).divmod(26)
  if mod == 0
    array[-1] = 26
    array << div - 1
  else
    array[-1] = mod
    array << div
  end
end
puts array.reverse.map { |i| alphabets[i - 1] }.join


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

int main()
{
	int h, w;
	cin >> h >> w;
	auto s = vector<string>(h + 2);
	s[0] = s[h + 1] = string(w + 2, '#');
	for(auto i = 1; i <= h; ++i){
		string t;
		cin >> t;
		s[i] = '#' + t + '#';
	}
	auto c = vector<vector<int>>(h + 2, vector<int>(w + 2));
	auto r = c;
	for(auto j = 1; j <= w; ++j){
		int cnt = 0;
		for(auto i = 1; i <= h + 1; ++i){
			if(s[i][j] == '#'){
				c[i - 1][j] = cnt;
				cnt = 0;
			}else{
				++cnt;
			}
		}
		for(auto i = h; i >= 0; --i){
			if(s[i][j] == '#') continue;
			c[i][j] = max(c[i][j], c[i + 1][j]);
		}
	}
	for(auto i = 1; i <= h; ++i){
		int cnt = 0;
		for(auto j = 1; j <= w + 1; ++j){
			if(s[i][j] == '#'){
				r[i][j - 1] = cnt;
				cnt = 0;
			} else{
				++cnt;
			}
		}
		for(auto j = w; j >= 0; --j){
			if(s[i][j] == '#') continue;
			r[i][j] = max(r[i][j], r[i][j + 1]);
		}
	}
	int ans = 0;
	for(auto i = 1; i <= h; ++i){
		for(auto j = 1; j <= w; ++j){
			if(s[i][j] == '#') continue;
			ans = max(ans, c[i][j] + r[i][j] - 1);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 39552
#include <stdio.h>

typedef struct {
  char suit;
  int num;
  int idx;
} Card;

void BubbleSort(Card C[], int N);
void SelectionSort(Card C[], int N);

int main() {
  int N;
  Card C1[36], C2[36];
  int i;

  scanf("%d", &N);
  for(i = 0; i < N; ++i) {
    scanf(" %c%d", &C1[i].suit, &C1[i].num);
    C1[i].idx = i;
    C2[i] = C1[i];
  }

  BubbleSort(C1, N);
  SelectionSort(C2, N);

  return 0;
}

void BubbleSort(Card C[], int N) {
  Card tmp;
  int stable;
  int i, j;
  for(i = 0; i < N-1; ++i) {
    for(j = N-1; j > i; --j) {
      if(C[j].num < C[j-1].num) {
        tmp = C[j];
        C[j] = C[j-1];
        C[j-1] = tmp;
      }
    }
  }
  stable = 1;
  for(i = 0; i < N; ++i) {
    printf("%c%d%c", C[i].suit, C[i].num, " \n"[i==N-1]);
    if(i > 0 && C[i].num == C[i-1].num && C[i].idx < C[i-1].idx) stable = 0;
  }
  puts((stable ? "Stable" : "Not stable"));
}

void SelectionSort(Card C[], int N) {
    Card tmp;
    int minj;
    int stable;
    int i, j;
    for(i = 0; i < N; ++i) {
      minj = i;
      for(j = i; j < N; ++j) {
        if(C[j].num < C[minj].num) minj = j;
      }
      tmp = C[i];
      C[i] = C[minj];
      C[minj] = tmp;
    }
    stable = 1;
    for(i = 0; i < N; ++i) {
      printf("%c%d%c", C[i].suit, C[i].num, " \n"[i==N-1]);
      if(i > 0 && C[i].num == C[i-1].num && C[i].idx < C[i-1].idx) stable = 0;
    }
    puts((stable ? "Stable" : "Not stable"));
}
    


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

int main()
{
    int n;
    cin >> n;
    int height = 0;
    int temp = 0;
    int longest = 0;
    for (size_t i = 0; i < n; i++)
    {
        int h;
        cin >> h;
        if (h <= height)
        {
            temp++;
        }
        else
        {
            temp = 0;
        }
        height = h;
        if (temp > longest)
        {
            longest = temp;
        }
    }
    cout << longest << endl;

    return 0;
}

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

using namespace std;

int main()
{
	constexpr double PI = 3.141592653589793;

	double r;
	cin >> r;

	cout << setiosflags(ios::fixed) << setprecision(10) << r * r * PI << " " << r * PI * 2 << endl;


	return 0;
}

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

int main(){
  double mountain;
  double min=100000.0;
  double max=0;
  while(scanf("%lf",&mountain)!=EOF){

    if(min>mountain)min=mountain;
    if(max<mountain)max=mountain;
  }
  printf("%.1f\n",max-min);

}

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

using namespace std;
using ll = long long;

#pragma region Macros
#define FOR(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0, n)

template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

template <class T> string join(const T &v, const string delim = ",")
{
    if (v.empty())
        return "";

    ostringstream res;
    res << v[0];
    for (int i = 1; i < v.size(); i++)
    {
        res << delim << v[i];
    }
    return res.str();
}

#pragma endregion Macros

// N以下で、bで割った余りがK以上のものの個数
ll f(ll b, ll N, ll K){
    if(b<=K) return 0;

    ll res = 0;

    // 周期的な部分の個数
    res += (N / b) * (b - K);

    // 半端な部分
    res += max((N % b) - max((K-1),(ll)0), (ll)0);

//    cerr << b << "," << res << endl;

    return res;
}

int main() {
    ll N, K;
    cin >> N >> K;

    ll ans = 0;
    for (int b = 1; b <= N; b++) {
        ans += f(b, N, K);
    }

    cout << ans << endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;

int main() {
    ll n;
    cin >> n;
    vector<ll> h(n);
    rep(i,n) cin >> h[i];
    ll ans = 0;
    for (ll i = 0; i < n;) {
        ll t = 0, j = i+1;
        for(; j < n; j++) {
            if (h[j-1] < h[j]) break;
            ++t;
        }
        ans = max(ans, t);
        i += t+1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3972
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder out = new StringBuilder();
		while (true) {
			String cards = (String)sc.next();
			if (cards.equals("-"))
				break;
			int m = sc.nextInt();
			for (int i = 0; i < m; ++i) {
				int h = sc.nextInt();
				cards =	cards.substring(h) + cards.substring(0, h); 
			}
			out.append(cards + "\n");
		}
		System.out.print(out);
	}
}


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

int main(){
  int N;
  int a[100];
  cin >> N;
  int max=-100,min=100;
  for(int i=0; i < N; i++){
    cin >> a[i];
    if(a[i]>=max){
      max=a[i];
    }
    if(a[i]<=min){
      min=a[i];
    }
  }
  int min_ans=10000000,S,j;
  for(int i=min;i<=max;i++){
    for(S=0,j=0;j<N;j++){
      S+=(a[j]-i)*(a[j]-i);
    }
    if(min_ans>=S){
      min_ans=S;
    }
  }
  cout << min_ans <<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	int i;
	int h[100005];
	for (i = 0; i < n; i++)
		scanf("%d", &h[i]);
	int v[100005];
	for (i = 0; i < n; i++)
		v[i] = 1;
	int a, b;
	for (i = 0; i < m; i++)
	{
		scanf("%d %d", &a, &b);
		if (h[a - 1] >= h[b - 1])
			v[b - 1] = 0;
		if (h[a - 1] <= h[b - 1])
			v[a - 1] = 0;
	}
	int ans = 0;
	for (i = 0; i < n; i++)
		if (v[i] > 0)
			ans++;
	printf("%d\n", ans);
	return 0;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    i64 N; cin >> N;
    vector<i64> A(N);
    i64 d = 0;
    REP(i, N) {
        i64 a, b; cin >> a >> b;
        d -= b;
        A[i] = a + b;
    }
    sort(A.rbegin(), A.rend());

    REP(i, N) {
        if (i % 2 == 0) {
            d += A[i];
        }
    }

    cout << d << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //ATTENTION: <a> must be sorted in advance

lng power(lng b, lng n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n

const int MOD = 1000000007; //10^9+7


/*********** variables ************/
int x, y;
/**********************************/

int check(int z) {
    if(z == 2) return 0;
    if(z <=7 && z&1 || z>=8 && !(z&1)) return 1;
    return 2;
}

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

    if(check(x) == check(y)) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

void pre(){
      unordered_map<int, int> height;
    unordered_set<int> g;


   
    for (int i = 1; i <= b; ++i) {
        int tmp;

        cin >> tmp;
        height[i] = tmp;
        g.insert(i);
    }

  
    while (r--) {
        int ob1, ob2;
        cin >> ob1 >> ob2;

        if (height[ob1] <= height[ob2])
            g.erase(ob1);
        if (height[ob2] <= height[ob1])
            g.erase(ob2);
    }

    cout << g.size() << endl;

    
    
}

int main() {

    cin >> b >> r;
  pre();
    
    return 0;
}

Measured memory_bytes: 11388
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
#define ll long long
ll ans;
int par[100005];
int root(int p)
{
	if (par[p] == p)return p;
	return par[p] = root(par[p]);
}
void uni(int a, int b) {
	a = root(a); b = root(b);
	par[a] = b;
}
bool sameuni(int a, int b) {
	a = root(a); b = root(b);
	return (a == b);
}
struct point {
	int x, y, idx;
	point(int a, int b, int c) {
		x = a, y = b, idx = c;
	}
};
vector<point> v, v2;
bool cmpx(point a, point b)
{
	if (a.x != b.x)return a.x < b.x;
	if (a.y != b.y)return a.y < b.y;
	return a.idx < b.idx;
}
bool cmpy(point a, point b)
{
	if (a.y != b.y)return a.y < b.y;
	if (a.x != b.x)return a.x < b.x;
	return a.idx < b.idx;
}
struct Edge {
	int n1, n2, cost;
	Edge(int a, int b, int c) {
		n1 = a, n2 = b, cost = c;
	}
	bool operator<(const Edge &i)const {
		if (cost != i.cost)return cost < i.cost;
		return n1 < i.n1;
	}
};
vector<Edge> E;
int n;
int main() {
	scanf("%d", &n);
	for (int x, y, i = 1; i <= n; i++) {
		par[i] = i;
		scanf("%d %d", &x, &y);
		v.push_back(point(x, y, i));
		v2.push_back(point(x, y, i));
	}
	sort(v.begin(), v.end(), cmpx);
	sort(v2.begin(), v2.end(), cmpy);
	for (int i = 1; i < v.size(); i++) {
		int cc = min(abs(v[i - 1].x - v[i].x), abs(v[i - 1].y - v[i].y));
		E.push_back(Edge(v[i - 1].idx, v[i].idx, cc));
		cc = min(abs(v2[i - 1].x - v2[i].x), abs(v2[i - 1].y- v2[i].y));
		E.push_back(Edge(v2[i - 1].idx, v2[i].idx, cc));
	}
	sort(E.begin(), E.end());
	for (int i = 0; i < E.size(); i++) {
		if (sameuni(E[i].n1, E[i].n2))continue;
		uni(E[i].n1, E[i].n2);
		ans += E[i].cost;
	}
	printf("%I64d", ans);
}

Measured memory_bytes: 7724
#include <stdio.h>
#include <utility>

using namespace std; 

int main() {
    int w, n;
    scanf("%d%d", &w, &n);
    int num[w];
    for (int i = 0; i < w; i++) {
        num[i] = i+1;
    }
    while (n--) {
        int i, j;
        scanf("%d,%d", &i, &j);
        swap(num[i-1], num[j-1]);
    }
    for (int i = 0; i < w; i++) {
        printf("%d\n", num[i]);
    }
}


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

int N, M, R;
int rs[100], d[300][300];
int dp[30][1<<10];

int rec(int cur, int state){
    if(state + 1 == (1 << R)){
        return 0;
    }
    if(dp[cur][state] != -1){
        return dp[cur][state];
    }

    int res = 1001001001;
    for(int i=0;i<R;++i){
        if(state >> i & 1){continue;}
        res = min(res, d[rs[cur]][rs[i]] + rec(i, state | (1 << i)));
    }

    return dp[cur][state] = res;
}

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

    std::cin >> N >> M >> R;

    for(int i=0;i<R;++i){
        std::cin >> rs[i];
        --rs[i];
    }

    fill(&d[0][0], &d[0][0]+300*300, 1001001001);

    for(int i=0;i<N;++i){
        d[i][i] = 0;
    }
    
    for(int i=0;i<M;++i){
        int a, b, c;
        std::cin >> a >> b >> c;
        --a; --b;
        
        d[a][b] = min(d[a][b], c);
        d[b][a] = min(d[b][a], c);        
    }

    for(int k=0;k<N;++k){
        for(int i=0;i<N;++i){
            for(int j=0;j<N;++j){
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    memset(dp, -1, sizeof(dp));
    
    int res = 1001001001;
    for(int i=0;i<R;++i){
        res = min(res, rec(i, 1 << i));
    }

    std::cout << res << std::endl;
                                    
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define ll  long long
#define endl '\n'
#define pi 3.14159265
int main()
{       
    IOS;
    string s1;
    cin>>s1;
    ll n=s1.length();
    stack<char> s;
    s.push(s1[0]);
    ll ans=0;
    for(ll i=1;i<n;i++)
    {
        if(s.size()==1)
        {
            s.push(s1[i]);
            continue;
        }
        while(s.size()>1)
        {
            char curr=s.top();
            s.pop();
            char last=s.top();
            s.pop();
            if(last!=s1[i])
            {
                ans++;
                s.push(last);
            }
        }
        s.push(s1[i]);
    }
    if(ans%2==0)
        cout<<"Second";
    else
        cout<<"First";
}   

Measured memory_bytes: 512
/*
  数の10新表現を数学を並び替えることで別の数をつくり、数列を作って、その周期を調べる
*/

#include <stdio.h>
#define MAX_L 6 // 最大の桁数

#define SHOJUN 1 // 昇順
#define KOJUN 0 // 降順

#define MAX_I (20+1) // 問題で提示された周期の上限+1

/* バブルソート: type==SHOJUNで小さい順、type==KOJUNで大きい順 */
void bubble_sort(int *num, int size, int type) { // 配列、配列の大きさ、並べ方の種類
  int i, j;

  /* 前後の数の大小を比較して交換を繰り返すことで整列する */
  for (i=1; i<=size-1; i++) { 
    for (j=0; j<=size-1-i; j++) {
      if ((num[j] > num[j+1] && type == SHOJUN) // 指定された並び方にしたがい
	  || (num[j] < num[j+1] && type == KOJUN)) {
	int tmp = num[j]; // 値を交換する
	num[j] = num[j+1];
	num[j+1] = tmp;
      }
    }
  }
}


/* 配列をコピー */
void copy_array(int *from, int *to, int size) { // コピー元、コピー先、配列の大きさ
  int i;
  
  for (i=0; i<size; i++)
    to[i] = from[i];
}

/* 各桁の数字が入った配列を整数にして返す（1の桁が0番目の要素） */
int array_to_int(int *num, int size) { // 配列、 配列の大きさ
  int i;
  int sum=0; 

  /* 最上位の桁から、桁の値を加算し10倍するのを繰り返すことで、配列が表す整数を求める */
  for (i=size-1; i>0; i--) {
    sum += num[i];
    sum *= 10;
  }
  sum += num[0]; // 最後に1の桁の値を加える

  return sum;
}

int main(void) {
  int a_0; // 最初の整数
  int L; // 桁数

  int a[MAX_I]; // 得られた数列
  int a_n[MAX_L]; // 数列の一つの数を配列で表見したもの

  int max_array[MAX_L], max; // 数字を並び替えたときの最大の数と配列表現
  int min_array[MAX_L], min; // 数字を並び替えたときの最小の数と配列表現

  int result;
  int i;
  int count; // 数列の番号
  
  while (scanf("%d %d", &a_0, &L) != EOF) { // 数字と桁数を読み込む
    if (a_0 == 0 && L == 0) // 終了判定
      break;

    a[0] = a_0; // 数列の0番目は読み込んだ値
    result = a_0; 
    
    /* 一つまえの数列の並び替え、その最大と最小の値の差を求めて次の数にし、その数列の周期を求める */
    for (count=1; count<MAX_I; count++) {
      /* 読み込んだ値を配列表現にする */
      for (i=0; i<L; i++) {  
	a_n[i] = result % 10; // 1の桁から順番に、桁の数字を配列に格納
	result /= 10; 
      }

      /* 数列の桁ごとの値を配列に入れ、並び替えて、最大と最小を求める */
      /* 最大の数を求める */
      copy_array(a_n, max_array, L); 
      bubble_sort(max_array, L, SHOJUN);
      max = array_to_int(max_array, L);

      /* 最小の数を求める */
      copy_array(a_n, min_array, L);
      bubble_sort(min_array, L, KOJUN);      
      min = array_to_int(min_array, L);
      
      result = max - min; // 差を求める

      /* 今までの数列に今求めた新しい数列の値があるか調べる */
      for (i=0; i<count; i++)
	if (a[i] == result)
	  break; // 見つかったら i < count, 見つからなかったらi==countになっている

      if (i != count) { // 今までの数列に今求めた新しい数列の値があったら、表示してループを抜ける 
	printf("%d %d %d\n", i, result, count-i);
	break;
      } else { // なかったら、数列を表す配列に値を代入
	a[count] = result;
      }
    }
  }
	   
  return 0;
}

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

int main(void){
  int n;
  string s, t;
  cin >> n >> s >> t;
  string ans;
  rep(i,n){
    ans+=s[i];
    ans+=t[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
const int N = 2e6 + 10;
char s[N];
int n, k;
ll fac[N], inv[N];
ll power(ll a, int x) {
	ll ans = 1;
	while (x) {
		if (x & 1) ans = (ans * a) % mod;
		a = (a * a) % mod;
		x >>= 1;
	}
	return ans;
}
void init() {
	fac[0] = 1;
	for (int i = 1; i < N; i++) {
		fac[i] = fac[i - 1] * i %mod;
	}
	inv[N - 1] = power(fac[N - 1], mod - 2);
	for (int i = N - 2; i >= 0; i--) {
		inv[i] = inv[i + 1] * (i + 1) % mod;
	}
}
ll C(int n, int k) {
	return fac[n] * inv[k] % mod*inv[n - k] % mod;
}
int main() {
	scanf("%d", &k);
	scanf("%s", s);
	n = strlen(s);
	init();
	ll ans = 0;
	for (int i = 0; i <= k; i++) {
		ans = (ans + power(26, i)*C(n + k - i - 1, n - 1) % mod*power(25, k - i) % mod) % mod;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 35988
from sys import stdin
input = stdin.readline

N, K = map(int, input().split())
d = []
A = [[]] * K
sunuke = [0] * N

for k in range(K):
	d.append(int(input()))
	A[k] = map(int, input().split())
	for a in A[k]:
		sunuke[a-1] += 1

print(sunuke.count(0))


Measured memory_bytes: 9164
import sys
from heapq import heappop, heappush, heapify

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
A = lr()
A = [-x for x in A]
heapify(A)

def discount(A):
    a = heappop(A)
    heappush(A, a/2)
    return A

for _ in range(M):
    A = discount(A)

total = sum(int(-x) for x in A)
print(total)


Measured memory_bytes: 14184
#include <iostream>
using namespace std;
int main(void){
    int n, count = 1;
    
    cin >> n;
    
    int a[n];
    
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    
    for(int i = 0; i < n; i++){
        if(a[i] == count){
            count++;
        }
    }
 
    if(count == 1){
        count = -1;
    }else{
        count = n - count + 1;
    }
 
    cout << count << endl;
    
    return 0;
}


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

#define MAX 100000
int dp[MAX];
int minsteps(int h[], int n, int i)
{
    if (i < 0)
    {
        return INT_MAX;
    }
    if (i == 0)
    {
        return dp[0];
    }
    if (dp[i] != -1)
    {
        return dp[i];
    }
    dp[i] = min(minsteps(h, n, i - 1) + abs(h[i] - h[i - 1]), minsteps(h, n, i - 2) + abs(h[i] - h[i - 2]));
    return dp[i];
}

int main()
{
    int n;
    cin >> n;
    int h[n];
    for (int i = 0; i < n; i++)
    {
        cin >> h[i];
    }
    memset(dp, -1, sizeof(dp));
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    cout << minsteps(h, n, n - 1) << endl;
}

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

using namespace std;
typedef long long ll;

int main()
{
	char a[256];
	scanf("%s", a);
	a[0] += 1;
	
	printf("%c\n", a[0]);
	
	return 0;
}

Measured memory_bytes: 128
from sys import stdin
import sys

[c11, c12, c13] = list(map(int, stdin.readline().rstrip().split()))
[c21, c22, c23] = list(map(int, stdin.readline().rstrip().split()))
[c31, c32, c33] = list(map(int, stdin.readline().rstrip().split()))

#print("%d %d %d" % (c11, c12, c13))
#print("%d %d %d" % (c21, c22, c23))
#print("%d %d %d" % (c31, c32, c33))

## Horizontal
# 3*a1 + b1 + b2 + b3
# 3*a2 + b1 + b2 + b3
# 3*a3 + b1 + b2 + b3
# => 3 の倍数

## Vertical
# 3*b1 + a1 + a2 + a3
# 3*b2 + a1 + a2 + a3
# 3*b3 + a1 + a2 + a3
# => 3 の倍数

if ((c11 + c12 + c13) - (c21 + c22 + c23)) % 3 != 0 or ((c21 + c22 + c23) - (c31 + c32 + c33)) % 3 != 0 or ((c31 + c32 + c33) - (c11 + c12 + c13)) % 3 != 0:
    print("No")

elif ((c11 + c21 + c31) - (c12 + c22 + c32)) % 3 != 0 or ((c12 + c22 + c32) - (c13 + c23 + c33)) % 3 != 0 or ((c13 + c23 + c33) - (c11 + c21 + c31)) % 3 != 0:
    print("No")

else:
    print("Yes")



Measured memory_bytes: 3064
s = input().split()
n, k = int(s[0]), int(s[1])
l = input().split()
l = [int(i) for i in l]
#l = [17,13,13,12,15,20,10,13,17,11]
x = [(i+1)/2 for i in l]
#print(sum(p[-4:]))
#print(x)
#print(len(x))
p = []
p.append(x[0])
prev=0
for i in x[1:]:
    curr = p[prev]+i
    p.append(curr)
    prev += 1
#print(p)
#print(len(p))
#k=4
maxi = p[k-1]
for i in range(k,len(p)):
    maxi = max(maxi, p[i]-p[i-k])
print('%.9f'%maxi)

Measured memory_bytes: 26184
#include<stdio.h>

void swap(int *a, int *b, int *c)
{
	int temp;
	
	temp = *a;
	*a = *b;
	*b = *c;
	*c = temp;
	
	return;
}

int check(int a, int b, int c)
{
	int i;
	
	for(i = 0; i < 3; ++i)
	{
		if((a * a) == (b * b) + (c * c))
		{
			return 1;
		}
		swap(&a, &b, &c);
	}

	return 2;
}

void triangle(int *a, int *b, int *c, int datanum)
{
	int i;
	int result;

	for(i = 0; i < datanum; ++i)
	{
		result = check(a[i], b[i], c[i]);
		if(result == 1)
		{
			printf("YES\n");
		}
		else
		{
			printf("NO\n");
		}
	}
	
	return;
}

int main(void)
{
	int *a, *b, *c;
	int datanum;
	int i;

	scanf("%d", &datanum);

	a = (int *)malloc(sizeof(int) * datanum);
	b = (int *)malloc(sizeof(int) * datanum);
	c = (int *)malloc(sizeof(int) * datanum);

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

	triangle(a, b, c, datanum);
	
	return 0;
}

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

using namespace std;

int n;
string s, a, b;

int main(){
    cin >> n >> s;
    for(int i = 0; i < s.size(); i++){
        if(i <= n / 2 - 1){
            a += s[i];
        }
        else b += s[i];
    }
    if(a == b) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int N, M;
int k[11], s[11][11], p[11], k_flag[11];
int ans = 0;

void judge() {
  rep(i, M) {
    int cnt = 0;
    rep(j, k[i]) cnt += k_flag[s[i][j]-1];

    if (cnt % 2 != p[i]) return;
  }

  ans++;
}


void rec(int next_i, int flag_i) {
  k_flag[next_i] = flag_i;
  if (next_i == N-1) {
    judge();
  } else {
    next_i++;
    rec(next_i, 0);
    rec(next_i, 1);
  }
}

int main() {
  cin >> N >> M;
  rep(i, M) {
    cin >> k[i];
    rep(j, k[i]) {
      cin >> s[i][j];
    }
  }

  rep(i, M) cin >> p[i];

  rec(0, 0);
  rec(0, 1);

  cout << ans << endl;

  return 0;

}

Measured memory_bytes: 256
<?php
fscanf(STDIN, '%d', $n);
$numbers = fgets(STDIN);
$exploded_numbers = explode(' ', trim($numbers));

$reciprocal_sum = 0;
foreach ($exploded_numbers as $number) {
  $reciprocal_sum += 1/$number;
}
echo 1 / $reciprocal_sum;

Measured memory_bytes: 4856
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

R,r=range,raw_input
N,K=map(int,r().split())
L=K+1
P,Q=R(K),R(L)
D=[L*[0]for i in Q]
a=b=0
for i in R(N):
 x,y,c=r().split()
 x,y=int(x),int(y)
 p=(x/K+y/K+ord(c))%2
 D[y%K+1][x%K+1]+=1-2*p
 b+=p
for i in P:
 for j in Q:D[i+1][j]+=D[i][j]
for i in Q:
 for j in P:D[i][j+1]+=D[i][j]
for i in Q:
 for j in Q:
  S=D[i][K]+D[K][j]-D[i][j]*2
  a=max(a,S,D[K][K]-S)
print a+b

Measured memory_bytes: 23268
using System;
class Program
{
	static void Main(string[] args)
	{
		string[] input = Console.ReadLine().Split(' ');
		int A = int.Parse(input[0]);
		int B = int.Parse(input[1]);
		if (B % A == 0)
        {
			Console.WriteLine(A + B);
        }
      	else
        {
      		Console.WriteLine(B - A);
        }
	}
}

Measured memory_bytes: 11092
# -*- coding: utf-8 -*-
from sys import stdin

# import numpy as np
from itertools import accumulate
from bisect import bisect_right

# import sys
# sys.setrecursionlimit(10**4)


def _li():
    return list(map(int, stdin.readline().split()))


def _li_():
    return list(map(lambda x: int(x) - 1, stdin.readline().split()))


def _lf():
    return list(map(float, stdin.readline().split()))


def _ls():
    return stdin.readline().split()


def _i():
    return int(stdin.readline())


def _f():
    return float(stdin.readline())


def _s():
    return stdin.readline()[:-1]


def search(cum1, cum2, iter_max, limit):
    ans = 0
    for (i,) in range(iter_max):
        if cum1[i] > limit:
            cur = 0
        else:
            cur = i
        cand = bisect_right(cum2, limit - cum1[i])
        ans = max(cur + cand, ans)
    return ans


N, M, K = _li()
A_list = _li()
B_list = _li()

cum_a = [0] + list(accumulate(A_list))
cum_b = list(accumulate(B_list))

ans = 0
for i, a in enumerate(cum_a):
    if a > K:
        cur = 0
    else:
        cur = i
    cand = bisect_right(cum_b, K - a)
    ans = max(cur + cand, ans)

print(ans)


Measured memory_bytes: 48648
#!/usr/bin/env python3

N = int(input())
A = list(map(int, input().split()))
A_even = [i for i in A if i % 2 == 0]

if all(i%3 == 0 or i%5 == 0 for i in A_even):
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3060
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n;
const int maxN = 2e5 + 10;
ll a[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n;
    ll sm = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        sm += a[i];
    }
    ll best = 1e18;
    ll f = 0;
    for (int i = 1; i <= n - 1; i++) {
        f += a[i];
        best = min(best, abs(sm - 2 * f));
    }
    cout << best;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std ; 
#define ll long long 
signed main()
{
	ll g[3],b[3],s[3],cnt=0,n; 
	cin >> n ; 
	cin >> g[1] >> s[1] >> b[1] ; 
	cin >> g[2] >> s[2] >> b[2] ; 
	ll p1 = 0 , p2 = 0 , p3 = 0 ; 
	p1 ^= ( g[1] >= g[2] ) ;
	p2 ^= ( s[1] >= s[2] ) ; 
	p3 ^= ( b[1] >= b[2] ) ;
	if ( p1 == 0 && p2 == 0 && p3 == 0 ) {
		for ( int i = 0 ; i <= n/g[1] ; i++ ) {
			for ( int j = 0 ; j <= (n-i*g[1])/s[1] ; j++ ) {
				int k = (n - i*g[1] - j*s[1])/b[1] ; 
				cnt= max(cnt,i*(g[2]-g[1])+j*(s[2]-s[1])+k*(b[2]-b[1])) ; 
			}
		}
		n += cnt ; 
	}
	else if ( p1 && p2 && p3 ) {
		for ( int i = 0 ; i <= n/g[2] ; i++ ) {
			for ( int j = 0 ; j <= (n-i*g[2])/s[2] ; j++ ) {
				int k = (n-i*g[2]-j*s[2])/b[2] ; 
				cnt = max(cnt,i*(g[1]-g[2])+j*(s[1]-s[2])+k*(b[1]-b[2])) ;
			}
		}
		n += cnt ; 
	}
	else if ( p1 && p2 )
	{	
		n += n/b[1]*(b[2]-b[1]) ; 
		for ( int i = 0 ; i <= n/g[2] ; i++ ) {
			int k = (n-i*g[2])/s[2] ; 
			cnt = max(cnt,i*(g[1]-g[2])+k*(s[1]-s[2])) ; 
		}
		n += cnt ; 
	}		
 	else if ( p2 && p3 ) {
 		n += n/g[1]*(g[2]-g[1]) ; 
 		for ( int i = 0 ; i <= n/s[2] ; i++ ) {
			int k = (n-i*s[2])/b[2] ; 
			cnt = max(cnt,i*(s[1]-s[2])+k*(b[1]-b[2])) ; 
		}
		n += cnt ; 
 	}
	else if ( p1 && p3 ) {
		n += n/s[1]*(s[2]-s[1]) ;
		for ( int i = 0 ; i <= n/g[2] ; i++ ) {
			int k = (n-i*g[2])/b[2] ; 
			cnt = max(cnt,i*(g[1]-g[2])+k*(b[1]-b[2])) ; 
		}
		n += cnt ;
	}
	else if ( p1 ) {
		for ( int i = 0 ; i <= n/s[1] ; i++ ) {
			int k = (n-i*s[1])/b[1] ; 
			cnt = max(cnt,i*(s[2]-s[1])+k*(b[2]-b[1])) ; 
		}
		n += cnt ;
		n += n/g[2]*(g[1]-g[2]) ;
	}
	else if ( p2 ) {
		for ( int i = 0 ; i <= n/g[1] ; i++ ) {
			int k = (n-i*g[1])/b[1] ; 
			cnt = max(cnt,i*(g[2]-g[1])+k*(b[2]-b[1])) ; 
		}
		n += cnt ; 
		n += n/s[2]*(s[1]-s[2]) ;
	}
	else if ( p3 ) {
		for ( int i = 0 ; i <= n/g[1] ; i++ ) {
			 int  k = (n-i*g[1])/s[1] ; 
			cnt = max(cnt,i*(g[2]-g[1])+k*(s[2]-s[1])) ; 
		}
		n += cnt ; 
		n += n/b[2]*(b[1]-b[2]) ;
	}
	cout << n ; 
}

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

using namespace std;

int main() {
    int N, L;
    cin >> N >> L;

    int sum, min;
    min = L;

    for (int i = 0; i < N; i++) {
        sum += L + i;
        if (abs(L+i) < abs(min)) {
            min = L+i;
        }
    }

    int result = sum - min;
    cout << result << endl;
}

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


struct P
{
    //string r;
    int x,y,z;

   /* bool operator<(const P &a)const{
       // if(y!=a.y)
       // return y>a.y;
              return y>a.y;
    }*/
};


vector<int> v[111];
//bitset<4001000> b;
int a,c,i,b,k,n,d,m;//dy[15]={0,1,0,-1,-1,1,-1,1},dx[15]={1,0,-1,0,1,1,-1,-1};//
int l[1112];

int o[55];
int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,-1,1,-1,1},dz[10]={0,0,0,0,1,-1};

int e;
#define PI 3.14159265
long long x,y,mod=1000000007;
long long z[11];
P j[400];
P u[10];
stack<int> s;
queue<int> q;
//set<int> s;
//priority_queue<int> q;
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p;
//list<int> l;
string r1,r;
//char r[5][111][111];
//deque<int> de;

//20921
bool as(P a,P b)
{
    return a.x<b.x;
}

bool qw(int a,int b)
{
    return a%2<b%2;
}

int main()
{
    //scanf("%d %d %d",&o[],&b,&c);
    for(int t=0;t<3;t++)
        scanf("%d",&o[t]);
    sort(o,o+3,qw);
    if(o[0]%2==o[2]%2)
    {
       k=(max(o[0],max(o[1],o[2]))*3-(o[1]+o[0]+o[2]))/2;
    }
    else
    {
        k++;
        if(o[0]%2==o[1]%2)
        {
            o[0]++;
            o[1]++;
        }
        else
        {
            o[1]++;
            o[2]++;
        }
        k+=(max(o[0],max(o[1],o[2]))*3-(o[1]+o[0]+o[2]))/2;
    }
    printf("%d",k);
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	static int dset;
	static int[] balls = new int[10];

	public static boolean dfs(int l,int r,int d){	//lは左に入っている一番上の球の番号、dは深さ

		if(d==10)
			return true;

		if(balls[d]>l) return dfs(balls[d],r,d+1);

		if(balls[d]>r) return dfs(l,balls[d],d+1);

		return false;
	}

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		dset =scan.nextInt();
		boolean[] result = new boolean[dset];
		for(int i=0;i<dset;i++){
			for(int j=0;j<10;j++){
				balls[j]=scan.nextInt();
			}
			result[i] = dfs(0,0,0);
		}

		for(int i=0;i<dset;i++){
			if(result[i])
				System.out.println("YES");
			else
				System.out.println("NO");
		}



	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int INF = 1010101;

struct MaxSegTree{
    int n; vector<ll> dat;
    // 初期化
    MaxSegTree(int _n){
        n=1;
        while(n<_n) n*=2;
        dat=vector<ll>(2*n-1,0);
    }
    // k番目(0-indexed)の値をaに変更
    void update(int k, ll a){
        k+=n-1;
        dat[k]=a;
        //更新
        while(k>0){
            k=(k-1)/2;
            dat[k]=max(dat[2*k+1],dat[2*k+2]);
        }
    }
    // 内部的に投げられるクエリ
    ll _query(int a, int b, int k, int l, int r){
        if(r<=a || b<=l) return 0;
        if(a<=l && r<=b) return dat[k];

        ll vl=_query(a,b,2*k+1,l,(l+r)/2);
        ll vr=_query(a,b,2*k+2,(l+r)/2,r);
        return max(vl,vr);
    }
    // [a,b)
    ll query(int a, int b){
        return _query(a,b,0,0,n);
    }
};

using pi = pair<int,int>;

int main(){
    int n;
    scanf(" %d", &n);
    vector<int> a(n);
    rep(i,n) scanf(" %d", &a[i]);

    vector<int> x(n);
    vector<int> dp(n+2, INF);
    dp[0] = -1;
    rep(i,n){
        int idx = lower_bound(all(dp), a[i]) - dp.begin();
        dp[idx] = a[i];
        x[i] = idx;
    }

    int L = 0;
    while(dp[L]<INF) ++L;
    --L;

    vector<vector<int>> v(L+1);
    rep(i,n) v[x[i]].pb(i);

    MaxSegTree st(n);

    unordered_map<int,ll> pre;
    rep(i,n)if(x[i]==1) pre[i] = a[i];
    for(int i=2; i<=L; ++i){
        vector<pi> p;
        for(int j:v[i-1]) p.pb({a[j],j});
        sort(all(p));

        int P = p.size();
        int pidx = 0;

        vector<pi> now;
        unordered_map<int,ll> nx;
        for(int j:v[i]) now.pb({a[j],j});
        sort(all(now));

        for(const auto &pp:now){
            int idx = pp.se;
            while(pidx<P && p[pidx].fi<pp.fi){
                st.update(p[pidx].se, pre[p[pidx].se]);
                ++pidx;
            }

            ll val = st.query(0,idx);
            nx[idx] = val+a[idx];
        }

        for(const auto &pp:p) st.update(pp.se, 0);

        pre = nx;
    }

    ll ans = 0;
    for(const auto &pp:pre) ans = max(ans, pp.se);
    printf("%lld\n", ans);
    return 0;
}



Measured memory_bytes: 11500
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int ans = 0;
        if(a == b && b == c){
            if(a % 2 == 0) ans = -1;
            else ans = 0;
        }else{
            while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0){
                ans++;
                int tmpa = (b + c) /2;
                int tmpb = (c + a) /2;
                int tmpc = (a + b) /2;
                a = tmpa;
                b = tmpb;
                c = tmpc;
            }
        }
        System.out.println(ans);
        sc.close();
    }

}


Measured memory_bytes: 23892
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(n)]
cnt=0
k=[]
for i in l:
  k=[]
  for t in range(m):
    k.append(i[t]*b[t])
  if(sum(k)+c>0):
    cnt+=1
print(cnt)

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

int main() {
	int h, w, k;
	cin >> h >> w >> k;
	char c[h][w];
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin >> c[i][j];
		}
	}
	//bit全探索
	char c1[h][w], c2[h][w];
	

	int ans = 0;
	for (int bit = 0; bit < (1<<h); ++bit){
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				c1[i][j] = c[i][j];
			}
		}
		for(int row = 0; row < h; ++row){
			if(bit & (1<<row)) {
				for(int j = 0; j< w; j++) c1[row][j] = 'R';
			}
		}
		for(int bit2 = 0; bit2 < (1<<w); ++bit2){
			for(int i=0;i<h;i++){
				for(int j=0;j<w;j++){
					c2[i][j] = c1[i][j];
				}
			}
			for(int row2 = 0; row2 < w; ++row2){
				if(bit2 & (1<<row2)) {
					for(int i = 0; i< h; i++) c2[i][row2] = 'R';
				}
			}
			int count = 0;
			for(int i=0; i<h;i++){
				for(int j=0; j<w;j++){
					if(c2[i][j]=='#') count++;
				}
			}
			if(count==k){
				ans++;
			}

		}

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


Measured memory_bytes: 3624