akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>

int main(){
  int N;
  scanf("%d",&N);
  //std::vector<std::pair<std::string, int> > moji;
  std::map<std::string, int > moji;
  std::string S;
  for (int i=0; i<N; i++){
    std::cin >> S;
    int count = moji[S];
    moji[S] = count + 1;
  }
  int maxcount = 0;
  for (auto const& entry: moji){
    maxcount = std::max(maxcount, entry.second);
  }
  for (auto const& entry: moji){
    if (entry.second==maxcount){
      std::cout << entry.first << std::endl;
    }
  }
  return 0;
}


Measured memory_bytes: 17664
using System;
using System.Reflection;
using System.Linq.Expressions;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder {
    public class Program {
        static int[] getKeys(char delimiter) {
            var Keys = Console.ReadLine().Split(' ');
            int[] Ns = new int[Keys.Length];
            for (int i = 0; i < Keys.Length; i++) {
                Ns[i] = int.Parse(Keys[i]);
            }
            return Ns;
        }
        static void Show<T>(T[,] map) {
            int H = map.GetLength(0);
            int W = map.GetLength(1);
            Console.WriteLine("-------------------------");
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    Console.Write(map[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine("-------------------------");
        }
        static void Show<T>(IEnumerable<T> ts) {
            foreach (var item in ts) {
                Console.Write(item + " ");
            }
            Console.WriteLine();
        }
        static void Main() {
            int N = int.Parse(Console.ReadLine());
            int[,] Route = new int[N, N];
            bool[,] hasDirectRoute = new bool[N, N];
            for (int i = 0; i < N; i++) {
                var Key = getKeys(' ');
                for (int j = i + 1; j < N; j++) {
                    Route[i, j] = Key[j];
                    Route[j, i] = Key[j];
                    hasDirectRoute[i, j] = true;
                    hasDirectRoute[j, i] = true;
                }
            }
            for (int from = 0; from < N; from++) {
                for (int to = from + 1; to < N; to++) {
                    for (int i = 0; i < N; i++) {//経由地を1つ選ぶ。
                        if (i != from && i != to) {//始点・終点とも違うところ。
                            if (Route[from, to] == Route[from, i] + Route[i, to]) {
                                hasDirectRoute[from, to] = false;
                                hasDirectRoute[to, from] = false;
                            }
                            if (Route[from, to] > Route[from, i] + Route[i, to]) {
                                hasDirectRoute[from, to] = false;
                                hasDirectRoute[to, from] = false;
                                Console.WriteLine(-1);
                                return;
                            }
                        }
                    }
                }
            }
            long Sum = 0;
            for (int i = 0; i < N; i++) {
                for (int j = i + 1; j < N; j++) {
                    if (hasDirectRoute[i, j]) Sum += Route[i, j];
                }
            }
            Console.WriteLine(Sum);
        }
    }
}


Measured memory_bytes: 19036
#include <cstdio>
#include <algorithm>    
#include <iostream>
#include <vector>
#include <queue>
// #include <map>
#include <iomanip>
#include <cstring>
#include <cmath>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int uii;
typedef pair<int,int> pii;
typedef unsigned long long uLL; 
typedef vector<int> vii; 

double d[333][333][333];
int a[5];

int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; ++i){
		int x;
		scanf("%d", &x);
		a[x]++;
	}
	for(int i = 0; i <= n; ++i){
		for(int j = 0; i + j <= n; ++j){
			for(int k = 0; i + j + k <= n; ++k){
				if(i == 0 && j == 0 && k == 0){
					continue;
				}
				double R = 0;
				if(i) R += d[i - 1][j + 1][k] * i / n;
				if(j) R += d[i][j - 1][k + 1] * j / n;
				if(k) R += d[i][j][k - 1] * k / n;
				d[i][j][k] = 1. * n / (i + j + k) * (R + 1);
			}
		}
	}
	printf("%.15f\n", d[a[3]][a[2]][a[1]]);
	return 0;
}

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

char s[200][200];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	int h=100,w=100;
	int cnt=0;
	rep(i,h/2)rep(j,w){
		if(i%2&&j%2&&cnt<a-1){
			s[i][j]='.';cnt++;
		}
		else s[i][j]='#';
	}
	cnt=0;
	rep(i,h/2)rep(j,w){
		if(i%2&&j%2&&cnt<b-1){
			s[i+h/2][j]='#';cnt++;
		}
		else s[i+h/2][j]='.';
	}
	cout<<h<<' '<<w<<endl;
	rep(i,h)printf("%s\n",s[i]);
}

Measured memory_bytes: 256
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
q = int(input())
counter = Counter(a)
sum_res = sum(a)
for _ in range(q):
    before, after = map(int, input().split())
    sum_res -= before * counter[before]#合計を減らす
    sum_res += after * counter[before]#合計を増やす
    counter[after] += counter[before]
    counter[before] = 0
    print(sum_res)


Measured memory_bytes: 94036
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()
J = 0
B = 0
for _ in range(N):
    x, u  = map(str, input().split())
    if u == 'JPY':
        J += int(x)
    else:
        B += float(x)
ans = J + 380000*B
print(ans)

Measured memory_bytes: 93116
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

 
int main() {
  	cin.tie(0); 
  	ios::sync_with_stdio(false);
  	int count = 0;
  	int arr_num = 0;
	int n;
  	cin >> n;
  	vector<unsigned long long> input(n);
  	
  	for(int i = 0; i < n; i++){
    	cin >> input.at(i);
      	
      	if(input.at(i) % 2 == 0){
        	while(input.at(i) % 2 == 0 && input.at(i) > 0){
            	input.at(i) /= 2;
              	count++;
            }
        }
    }
  
  	cout << count << endl;
  	
    return 0;
}

Measured memory_bytes: 3680
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <math.h>

using namespace std;

typedef long long ll;

int main() {
	int w, h;
	while ( cin >> h >> w, h || w ) {
		for (int y = 0; y < h; ++y) {
			for (int x = 0; x < w; ++x) {
				cout << '#';
			}
			cout << endl;
		}
		cout << endl;
	}
}

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

int main()
{
    int n,h[100002];
    cin>>n;
    for (int i = 0; i < n; i++)
    {
        cin>>h[i];
    }
    bool ans=true;
    int b=h[0]-1;
    for (int i = 1; i < n; i++)
    {
        if(h[i]==b){
            b=h[i];
        }else if(h[i]<b){
            ans=false;
            break;
        }else{
            b=h[i]-1;
        }
    }
    if(ans){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 768
from itertools import permutations
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]


pattern = list(permutations(range(n)))

ans = 0
for p in pattern:
    tmp = 0
    for i in range(n - 1):
        tmp += ((xy[p[i + 1]][0] - xy[p[i]][0])**2 +
                (xy[p[i + 1]][1] - xy[p[i]][1])**2)**0.5
    ans += tmp

print(ans / len(pattern))

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


int main()
{
	int H, W;
	cin >> H >> W;

	while (H != 0 || W != 0){
		for (int i = 0; i < H; i++){
			for (int j = 0; j < W; j++){
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
		cin >> H >> W;
	}
	
	return 0;
}


Measured memory_bytes: 3100
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N, K = MAP()
a = LIST()

dp = [0]*(K+1)

for i in range(K+1):
	for x in a:
		if 0 <= i-x and dp[i-x] == 0:
			dp[i] = 1

if dp[K]:
	print("First")
else:
	print("Second")

Measured memory_bytes: 11092
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);


int main(){
  FAST_IO  
  
  int a, b, c, x, cnt = 0; cin >> a >> b >> c >> x;

  for(int o = 0; o <= a; ++o){
    for(int t = 0; t <= b; ++t){
      int cur = o * 500 + t * 100;
      int req = x - cur;
      if(req < 0) continue;
      req /= 50;
      cnt += (req <= c);
    }
  }

  cout << cnt << "\n";

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
        int m,f,r;
        Scanner s = new Scanner(System.in);
        while(true){
            m = s.nextInt();
            f = s.nextInt();
            r = s.nextInt();
            if(m==-1&&f==-1&&r==-1)break;
            if(m==-1||f==-1)System.out.println("F");
            else if(m+f>=80)System.out.println("A");
            else if(m+f>=65)System.out.println("B");
            else if(m+f>=50)System.out.println("C");
            else if(m+f>=30){
                if(r>=50)System.out.println("C");
                else System.out.println("D");
            }
            else System.out.println("F");
 
 
        }
    }
}



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

using namespace std;

typedef long long int ll;

const ll mod = 1e9 + 7;
const ll MAXN = 1e5 + 5;

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

  ll n;
  cin >> n;
  vector < ll > cnt(n + 1, 0);
  for(int i = 0; i < n - 1; i++){
    ll a;
    cin >> a;
    cnt[a]++;
  }
  for(int i = 1; i <= n; i++) cout << cnt[i] << endl;
}


Measured memory_bytes: 4784
#include <iostream>

void solve() {
    int n, m;
    std::cin >> n >> m;
    std::cout << (n == m ? "Yes" : "No") << std::endl;
}

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

    solve();

    return 0;
}


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

int main() {
    int n;
    cin>>n;
    set<string> st;
    string w;
    cin>>w;
    st.insert(w);
    int f=1;
    for (int i=0;i<n-1;i++) {
        string pre=w;
        cin>>w;
        f&=pre.back()==w[0];
        st.insert(w);
    }
    if (f&&st.size()==n)
        puts("Yes");
    else
        puts("No");
    return 0;
}

Measured memory_bytes: 256
n = int(input())
nums = []
for _ in range(n):
    nums.append(int(input()))
nums.sort()
ans = sum(nums)
if ans % 10 != 0:
    print(ans)
else:
    for num in nums:
        t = ans - num
        if t % 10 != 0:
            print(t)
            break
    else:
        print(0)

Measured memory_bytes: 38456
while n=gets
	n=n.to_i
	break if n==0
	sa=0
	sb=0
	n.times{
		a,b=gets.chomp.split(" ").map{|s| s.to_i}
		if a>b then
			sa+=(a+b)
		elsif a<b then
			sb+=(a+b)
		else
			sa+=a
			sb+=b
		end		
	}
	puts [sa,sb].join(" ")
end


Measured memory_bytes: 6844
#include <iostream>
#include <string>
using namespace std;
int main(void){
    
    int a;string c,d;
    cin >> c >> d;
    c+=d;a=stoi(c);
    int i=1;
    while(i*i<=a){
        if(i*i==a){
            cout << "Yes" << endl;
            return 0;
        }
        i+=1;
    }
    cout << "No" << endl;
    return 0;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<numeric>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
//scanf("%d", &a); '\n'; cout << fixed << setprecision(10);

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, a, b,sum;
	cin >> n >> a >> b;
	sum = n / (a + b);
	cout << sum * a + min(a, n - sum * (a + b));
}

Measured memory_bytes: 256
package main

import (
	"math/rand"
	"time"
	"os"
	"bufio"
	"fmt"
	"strconv"
)

var(
	inf = 10000000071000000
	stdin = bufio.NewReader(os.Stdin)
	mod = 1000000007
	mod9 = 1000000009
	//////////////////////////////////
	stack []byte
)

func init()  {
	rand.Seed(time.Now().UnixNano())
}


func main() {
	n := goint()
	a := intLine(n,0)
	count := countInt(a)
	check := 0
	for _,v:=range count{
		check += v - 1
	}
	if check % 2 == 0{
		fmt.Println(n - check)
	} else {
		fmt.Println(n - check - 1)
	}
}

//要素の個数を数える
func countInt(ls []int) map[int]int {
	counter := make(map[int]int)
	for _,v := range ls{
		if _, ok := counter[v]; ok {
			counter[v] ++
		} else {
			counter[v] = 1
		}
	}
	return counter
}

func solv(s []byte) {

}

//||||||||||||||||||||||||||入力|||||||||||||||||||||||||||||||||||||||

//次のスペースか改行まで読み込む
func gostring() string {
	byte_ls := make([]byte,0)
	for  {
		b, _ := stdin.ReadByte()
		if b == 32 || b == 10 || b == 0{
			return string(byte_ls)
		} else if b == 13 {
			continue
		} else {
			byte_ls = append(byte_ls,b)
		}
	}
}

//上の関数のintバージョン
func goint() int {
	n,_ := strconv.Atoi(gostring())
	return n
}

//数字一行
func intLine(n ,a int) []int {
	ls := make([]int,n)
	for i,_ := range ls{
		ls[i] = goint() + a
	}
	return ls
}

//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

func sum(a ...int) int {
	ans := 0
	for i:=0;i<len(a);i++{
		ans += a[i]
	}
	return ans
}

func min(a ...int) int {
	ans := a[0]
	for i:=1;i<len(a);i++{
		if ans > a[i]{
			ans = a[i]
		}
	}
	return ans
}

func abs(n int) int {
	if n >= 0{
		return n
	} else {
		return -n
	}
}

func max(a ...int) int {
	ans := a[0]
	for i:=1;i<len(a);i++{
		if ans < a[i]{
			ans = a[i]
		}
	}
	return ans
}

func intList(n,k int) []int {
	ls := make([]int,n)
	for i:=0;i<n;i++{
		ls[i] = k
	}
	return ls
}

Measured memory_bytes: 7040
#include <iostream>
#include <string>
using namespace std;
string shuffle(string, int);
int main()
{
  while(1)
  {
    string s;
    cin>>s;
    if(s=="-") break;
    int m;
    cin>>m;
    for(int i=0;i<m;i++)
    {
      int n;
      cin>>n;
      s=shuffle(s,n);
    }
    cout<<s<<endl;
  }
}

string shuffle(string s, int n)
{
  int l=s.length();
  s=s+s;
  s=s.substr(n,l);
  return s;
}

Measured memory_bytes: 3152
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>
#define len length()
#define sz size()
#define rng(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) rng(i, 0, n)
#define srt(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define vi(a, n) vector<int> a(n)
#define vs(a, n) vector<string> a(n)
#define vc(a, n) vector<char> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define erc(S, i) S.erase(S.begin() + i)
#define ers(S, i, j) S.erase(S.begin() + i, S.begin() + j)
#define sp(n) cout << setprecision(n) << fixed
#define fst(s) s.at(0)
#define lst(s) s.at(s.len - 1)
using namespace std;

int main(){
    int N;
    cin >> N;
    rng(i, N, 1000){
        if(i%111==0){
            cout << i << endl;
            return 0;
        }

    }
    
}

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

int main(){
	int n,ans=0;
	cin>>n;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		if(a%2 != 0 && i%2 == 0){
			ans++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3620
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<iomanip>
#include<map>
#include<stack>
const int maxn = 1e5+10;
#define INF 1e9+10
using namespace std;
char ch;
stack<int>A,B,C;
bool p = false;
bool pA()
{
    if(A.empty())return true;
    ch = A.top();
    A.pop();
   // cout <<ch <<endl;
    return false;
}
bool pB()
{
    if(B.empty())return true;
    ch = B.top();
    B.pop();
   // cout <<ch <<endl;
    return false;
}
bool pC()
{
    if(C.empty())return true;
    ch = C.top();
    C.pop();
   // cout <<ch <<endl;
    return false;
}
int main()
{
    string a,b,c;
    cin >> a >> b >> c;
    for(int i = a.length()-1; i>=0; i --)
    {
        A.push(a[i]);
        //cout << "a:" << a[i] << endl;
    }
    for(int i = b.length()-1; i>=0; i --)
    {
        B.push(b[i]);
    }
    for(int i = c.length()-1; i>=0; i --)
    {
        C.push(c[i]);
    }
    ch = a[0];
    A.pop();
    do
    {
        if(ch == 'a')p=pA();
        if(ch == 'b')p=pB();
        if(ch == 'c')p=pC();

    }while(!p);
    //cout <<ch <<endl;
    cout << (char)(ch-'a'+'A') << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n, m;
  cin >> n >> m;
  string s;
  cin >> s;
  vector<ll> ans;
  ans.push_back(n);
  ll cur = n;
  while (cur > 0) {
    bool ok = false;
    IFOR(i, 1, m + 1) {
      ll nxt = cur - i;
      if (nxt < 0) continue;
      if (s[nxt] == '1') continue;
      ok = true;
      ans.push_back(nxt);
      cur = nxt;
      break;
    }
    if (ok) continue;
    cout << -1 << endl;
    return 0;
  }

  reverse(ALL(ans));
  ll l = SZ(ans);
  REP(i, l - 1) { cout << ans[i + 1] - ans[i] << " \n"[i == l - 2]; }
}

Measured memory_bytes: 1528
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

vector<int> as;
vector<int> bs;
vector<int> cs;
vector<int> ds;

int calc(const vector<int> &acc, const int N, const int Q) {
#ifdef DEBUG
    printf("calc for: ");
    for (auto x : acc) {
        cout << x << " ";
    }
    cout << endl;
#endif

    int ans = 0;
    for (int q = 0; q < Q; q++) {
        int a = as[q], b = bs[q], c = cs[q], d = ds[q];
        if (acc[b] - acc[a] == c) {
            ans += d;
        }
    }
#ifdef DEBUG
    printf("ans: %d\n", ans);
#endif
    return ans;
}

int f(int pos, vector<int> &acc, const int N, const int M, const int Q) {
    if ((int) acc.size() == N) {
        return calc(acc, N, Q);
    }

    if (pos > M) {
        return 0;
    }

    int ans = 0;
    for (int i = pos; i <= M; i++) {
        acc.push_back(i);
        chmax(ans, f(i, acc, N, M, Q));
        acc.pop_back();
    }
    return ans;
}

int solve(const int N, const int M, const int Q) {
    vector<int> acc;
    return f(1, acc, N, M, Q);
}

int main(void) {
    int N, M, Q;
    cin >> N >> M >> Q;

    as.resize(Q);
    bs.resize(Q);
    cs.resize(Q);
    ds.resize(Q);
    for (int i = 0; i < Q; i++) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        a--;
        b--;
        as[i] = a;
        bs[i] = b;
        cs[i] = c;
        ds[i] = d;
    }

    cout << solve(N, M, Q) << endl;

    return 0;
}


Measured memory_bytes: 3640
#include <stdio.h>

int main(void){ 

int i,kazu; 

long sum=0,a,min=1000001,max=-1000001; 

scanf("%d",&kazu);  

for(i=0;i<kazu;i++){ 

scanf("%ld",&a); 

if(a<=min){ 

min=a; 

} 

if(a>=max){ 

max=a; 

} 

sum=sum+a; 

} 

printf("%d %d %ld\n",min,max,sum); 

return 0;

}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

int main(){
  int n,W;
    cin >> n >> W;
    vector<vector<int> > dp(n+1,vector<int> (W+1,0));
    vector<int> v(n),w(n);
    REP(i,n) cin >> v[i] >> w[i];

    
        REP(j,W+1){
REP(i,n){
            if(j<w[i]) dp[i+1][j]=dp[i][j];
            else dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
        }
    }

    int max=0;
    REP(j,W+1){
        if(dp[n][j]>max) max=dp[n][j];
    }
    cout << max << endl;
  return 0;
}

Measured memory_bytes: 4956
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;

int main(){
  int x, y, z, w;
  cin >> x >> y >> z >> w;
  cout << y - w + z << ' ' << w+z-x << ' ' << y-w+x << ' ' << y+z-x <<endl;
  return 0;
}


Measured memory_bytes: 888
import java.util.Scanner;
import java.lang.Math;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		double r = scanner.nextDouble();
		double x = Math.PI;
		double s = 0;
		double l = 0;
		s = r * r * x;
		l = 2 * r * x;

		String ss = String.format("%1$.6f", s);
		String ls = String.format("%1$.6f", l);
		System.out.println (ss + " " + ls);
	}
}



Measured memory_bytes: 28260
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define alll(v) v.begin(),v.end()
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}cout<<endl;}

vector<ll> divv(ll n);
int main() {
    ll n;

    cin>>n;
    ll sum = 0;
    auto v = divv(n);
    for(auto it:v){
        // pr(it);
        ll alp = it;
        ll m = n / alp;
        m--;
        if(m>0 && m > alp) {
            sum += m;
        }
    }
    pr(sum);
    
    return 0;
}

vector<ll> divv(ll n) {
  vector<ll> v;
  for(ll i = 1; i*i <= n; i++) {
    if(n%i == 0) {
      v.push_back(i);
      if(i*i != n){
          v.push_back(n/i);
      }
    }
  }
  sort(alll(v));
  return v;
}

class UF { // union find from https://github.com/kartikkukreja/blog-codes (MIT)
    // [usage]
    // auto uf = new UF(n);
    // uf->merge(a, b);
    // ...
public:
    int *id; // inner id
    int cnt; // number of all vartices
    int *sz; // sz[i] means size of i's set
    UF(int N)   {
        cnt = N;
        id = new int[N];
        sz = new int[N];
        for(int i=0; i<N; i++) {
            id[i] = i;
            sz[i] = 1;
        }
    }
    ~UF() {
        delete [] id;
        delete [] sz;
    }
    int find(int p) {
        int root = p;
        while (root != id[root]) root = id[root];
        while (p != root) {
            int newp = id[p];
            id[p] = root;
            p = newp;
        }
        return root;
    }
    void merge(int x, int y) {
        int i = find(x);
        int j = find(y);
        if (i == j) return;
        
        if (sz[i] < sz[j]) {
            id[i] = j;
            sz[j] += sz[i];
        } else {
            id[j] = i;
            sz[i] += sz[j];
        }
        cnt--;
    }
    bool connected(int x, int y) {
        return find(x) == find(y);
    }
    int count() {
        return cnt;
    }
};

Measured memory_bytes: 384
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n+1) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
  
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;}
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n),cnt(3);
	int zero = 0;
	int ans = 1;
	rep(i,n){
		cin >> a[i];
		int c = 0;
		bool flg = true;
		rep(j,3){
			if(cnt[j] == a[i]){
				++c;
				if(flg){
					cnt[j]++;
					flg = false;
				}
			}
		}
		(ans *= c) %= mod;
	}
	cout << ans << '\n';
	return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main()
{
    int k;
    cin >> k;
    vector<ll> v;

    for (int i = 1; i <= 9; i++)
        v.push_back(i);

    while (1)
    {
        if (k <= v.size())
        {
            OP(v[k - 1]);
            break;
        }
        k -= v.size();
        vector<ll> old;
        swap(old, v);
        for (auto x : old)
        {
            for (int i = -1; i <= 1; i++)
            {
                int d = x % 10 + i;
                if (d < 0 || d > 9)
                    continue;
                v.push_back(x * 10 + d);
            }
        }
    }

    return 0;
}

Measured memory_bytes: 1712
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int num = scan.nextInt();
        int ones = num % 10;
        if (ones==2 || ones==4 || ones==5 || ones==7 || ones==9){
			System.out.println("hon");} 
        else if(ones==0 || ones==6 || ones==1 || ones==8){
			System.out.println("pon");}
        else if(ones==3){
            System.out.println("bon");}
        scan.close();
    }
}



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

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  int W,H,w,h;
  cin >> W >> H >> w >> h;
  cout << (W - w) * (H - h) << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll int64_t
#define f first
#define sec second
#define pb push_back
#define pf push_front
#define pbb pop_back
#define vi vector<ll>
#define vii vector< pair<ll,ll> >
#define pi pair<ll,ll>
#define map map<ll,ll>
#define set set<ll>
const int m=1e9+7;
int main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    int p=max(n,m);
    int q=min(n,m);
    string str="";
    for(int i=0;i<p;i++){
        str+=q+'0';
    }
    cout<<str<<endl;
}
  
   

Measured memory_bytes: 256
N, = map(int, input().split())
xs = list(map(int, input().split()))
r = 0
for k in range(1, N):
    a = (N-1) % k
    for _ in range(1+(N-1-a)//k):
        b = a - k
        n = (N-1-a)//k
        if a <= b or a <= k:
            a += k
            continue
        if a%(a-b) == 0:
            if a <= (a-b)*n:
                a += k
                continue
    if a >= N-1:
        continue
    s1 = a
    s2 = n * (a-b)
    t = xs[s1]
    for i in range(n):
        s1 += a-b
        t += xs[s2]
        t = max(t,0)
        t += xs[s1]
        s2 -= a-b
    r = max(r, t)
print(r)


Measured memory_bytes: 63216
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int sum = 0;
    int min = 10;
    int[] a = new int[5];
    for(int i = 0; i < 5; i++){
      a[i] = sc.nextInt();
      if(a[i] % 10 != 0){
        min = Math.min(min, a[i] % 10);
        sum += (a[i] / 10 + 1) * 10;
      }else{
        sum += a[i];
      }
    }
    sum -= 10 - min;
    System.out.println(sum);
  }
}

Measured memory_bytes: 23124
a,b,c=map(int,input().split())

if (a==1 and b==0) or (a==0 and b==1):
    print("Close")
elif a==1 and b==1:
    print("Open")
elif a==0 and b==0 and c==1:
    print("Open")
else:
    print("Close")
    


Measured memory_bytes: 5596
m,n = map(int,input().split())
X = list(map(int,input().split()))
Y = list(map(int,input().split()))
MOD = 1000000007
sum_x = 0
sum_y = 0
for k in range(m):
  sum_x += (2*k +1 -m)*X[k]
sum_x %= MOD
for l in range(n):
  sum_y += (2*l + 1 - n)*Y[l]
sum_y %= MOD
Answer = (sum_x*sum_y) % MOD
print(Answer)

Measured memory_bytes: 18556
N = input()

res = 0
for i in range(1, N + 1):
	if i % 2 == 0:
		continue
	c = 0
	for j in range(1, i + 1):
		if i % j == 0:
			c += 1
		if c == 8:
			res += 1
print(res)
	


Measured memory_bytes: 2568
#include<bits/stdc++.h>
using namespace std ;
#define ll long long int 
#define pb push_back 
#define mp make_pair 
#define pii pair <int , int > 
#define pll pair < ll , ll >
ll fun(ll a , ll b , ll c){
	ll x ;
	if(a % c == 0){
		x = a/c ;
		x-- ;
	}
	else {
		x = a/c ;
	}
	ll y = b/c ;
	return y - x ;
}
int main(){
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;
	ll a , b , c ,d ;
	cin >> a >> b >> c >> d ;
	ll x = fun(min(a, b) , max(a, b) , c) ;
	ll y = fun(min(a, b) , max(a, b) , d) ;
	ll z = fun(min(a, b) , max(a, b) , (c*d)/(__gcd(c, d))) ;
	// cout << x << " " << y << " " << z ;
	cout << max(a, b) - min(a, b) + 1  -( x + y - z) ;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.StringTokenizer;
import java.util.Arrays;

class Point {
	int x;
	int y;
	Point(int x,int y) {
		this.x = x;
		this.y = y;
	}
}

class Main {
	public static void main(String args[]) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String buf;

		try {
			while (!(buf = br.readLine()).equals("0 0")) {
				StringTokenizer st = new StringTokenizer(buf);
				int H = Integer.parseInt(st.nextToken());
				int W = Integer.parseInt(st.nextToken());
				int field[][] = new int[H][W];
				boolean check[][] = new boolean[H][W];
				if (H==0||W==0) {
					System.out.println(0);
					continue;
				}
				for (int i=0;i<H;i++) {
					Arrays.fill(check[i],false);
					buf = br.readLine();
					for (int j=0;j<W;j++) {
						if (buf.charAt(j)=='@') {
							field[i][j] = 0;
						} else if (buf.charAt(j)=='#') {
							field[i][j] = 1;
						} else {
							field[i][j] = 2;
						}
					}
				}
				int count = 0;
				Point queue[] = new Point[H*W];
				for (int i=0;i<H;i++) {
					for (int j=0;j<W;j++) {
						if (!check[i][j]) {
							int q = 0;
							queue[q++] = new Point(i,j);
							while (q>0) {
								Point t = queue[--q];
								if (!check[t.x][t.y]) {
									check[t.x][t.y] = true;
									if (t.x+1<H) {
										if (!check[t.x+1][t.y]&&field[t.x][t.y]==field[t.x+1][t.y]) queue[q++] = new Point(t.x+1,t.y);
									}
									if (t.x-1>=0) {
										if (!check[t.x-1][t.y]&&field[t.x][t.y]==field[t.x-1][t.y]) queue[q++] = new Point(t.x-1,t.y);
									}
									if (t.y+1<W) {
										if (!check[t.x][t.y+1]&&field[t.x][t.y]==field[t.x][t.y+1]) queue[q++] = new Point(t.x,t.y+1);
									}
									if (t.y-1>=0) {
										if (!check[t.x][t.y-1]&&field[t.x][t.y]==field[t.x][t.y-1]) queue[q++] = new Point(t.x,t.y-1);
									}
								}
							}
							count++;
						}
					}
				}
				//printField(field,H,W);
				//printField(check,H,W);
				System.out.println(count);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void printField(int[][] a,int H,int W) {
		for (int i=0;i<H;i++) {
			for (int j=0;j<W;j++) System.out.print(a[i][j]);
			System.out.println();
		}
	}
}

Measured memory_bytes: 26328
#include<stdio.h>

static const int N = 1000;




void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main() 
{
  int i,j,v,n;
  int A[N+1];

  scanf("%d", &n);
  
  for ( i = 1; i <= n; i++ ){
    if(scanf("%d", &A[i])==EOF)break;
    
  }  
  trace(A,n);
  for(i=2;i<=n;i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
	A[j+1]=A[j];
	j=j-1;	
	A[j+1]=v;
	//	trace(A,n);
      }
    trace(A,n);

  }//trace(A,n);
  return 0;
}

Measured memory_bytes: 604
#include<iostream>
#include<algorithm>
#define INF (1<<26)
using namespace std;
 
int n,ans;
int checkA(int);
int checkB(int);
int checkC(int);
 
int main(){
  while(cin>>n){
    if(n==0)break;
 
    ans=INF;
 
    for(int i=0;i<100;i++){
      for(int j=0;j<100;j++){
    for(int k=0;k<100;k++){
      //if(i==5&&j==0&&k==0)cout<<checkA(i)<<' '<<checkB(j)<<' '<<checkC(k)<<endl;
      if( i*200+j*300+k*500 == n){
        ans=min(ans,checkA(i)+checkB(j)+checkC(k));
      }
 
    }
      }
    }    
    cout<<ans<<endl;
  }
  return 0;
}
int checkA(int cnt){
 
  int x = cnt - (cnt % 5), y = cnt % 5;
  return x*304 + y*380;
}
 
int checkB(int cnt){
 
  int x = cnt - (cnt % 4), y = cnt % 4;
  x/=4;
  return x*1870 + y*550;
}
 
int checkC(int cnt){
 
  int x = cnt - (cnt % 3), y = cnt % 3;
  return x*748 + y*850;
}


Measured memory_bytes: 3056
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;
ll const MAX_N = 510000;
ll const MOD = 1000000007;

int main() {
    ll A, B, K;
    cin >> A >> B >> K;

    if (B - A + 1 <= 2 * K) {
        reps(i, A, B + 1) { cout << i << endl; }
        return 0;
    }

    rep(i, K) { cout << A + i << endl; }

    for (ll i = K - 1; i >= 0; i--) {
        cout << B - i << endl;
    }
    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<string,ll> P;
ll dp[55][105]={0};
int main(){
  int n,kk;
  cin>>n>>kk;
  ll array[55]={0};
  ll kkk=0;
  for(int i=1;i<=n;i++){
    cin>>array[i];
    if(array[i]>0) kkk+=i;
  }
  ll ans=0;
  for(int b=0;b<=n+1;b++){
    for(int i=0;i<=kk;i++){
      ll lcos=0;
      for(int j=1;j<=i;j++){
        priority_queue<ll,vector<ll>,greater<ll>> lque;
        ll kcos=0;
        for(int k=1;k<=j;k++){
          if(k>=b) break;
          kcos+=array[k];
          lque.push(array[k]);
          if(k>=n) break;
          if(k>=b) break;
        }
        for(int k=0;k<i-j;k++){
          if(lque.empty()) break;
          if(lque.top()>0) break;
          kcos-=lque.top();
          lque.pop();
        }
        lcos=max(kcos,lcos);
      }

      ll rcos=0;
      for(int j=1;j<=kk-i;j++){
        priority_queue<ll,vector<ll>,greater<ll>> rque;
        ll kcos=0;
        for(int k=1;k<=j;k++){
          if(n-k+1<=b+1) break;
          kcos+=array[n-k+1];
          rque.push(array[n-k+1]);
          if(n-k+1<=1) break;
          if(n-k+1<=b+1) break;
        }
        for(int k=0;k<kk-(i+j);k++){
          if(rque.empty()) break;
          if(rque.top()>0) break;
          kcos-=rque.top();
          rque.pop();
        }
        rcos=max(kcos,rcos);
      }
      //cout<<lcos<<" "<<rcos<<endl;
      ans=max(ans,lcos+rcos);
    }
  }
  //cout<<kkk<<endl;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import math
from collections import defaultdict

def main():
    n = int(input())
    nums = list(map(int, input().split()))
    nums.sort()

    nums_cnt = defaultdict(int)
    for num in nums:
        nums_cnt[num] += 1

    cnt = 0
    for num in reversed(nums):
        if nums_cnt[num] <= 0:
            continue

        power_of_2 = 1 << math.ceil(math.log2(num))
        pair = power_of_2 - num

        if pair != 0 and nums_cnt[pair] > 0:
            nums_cnt[pair] -= 1
            nums_cnt[num] -= 1
            cnt += 1
        elif pair == 0 and nums_cnt[num] >= 2:
            nums_cnt[num] -= 2
            cnt += 1

    print(cnt)
    return

main()

Measured memory_bytes: 55988
h, w = map(int, input().split())

def cl(sx, sy, m):
    Z = -1
    dist = [[Z for i in range(w)] for j in range(h)]
    for i in range(h):
        for j in range(w):
            if m[i][j] == '#':
                dist[i][j] = -1

    def bfs():
        q = []
        q.insert(0, (sx, sy))
        dist[sy][sx] = 0
        while len(q):
            x, y = q.pop()
            for i in range(0, 4):
                nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]
                if (0 <= nx < w and 0 <= ny < h and m[ny][nx] != '#' and dist[ny][nx] == Z):
                    q.insert(0, (nx, ny))
                    dist[ny][nx] = dist[y][x] + 1
        return dist
    return bfs()

S = [list(input()) for _ in range(h)]
ans = 0
for y in range(h):
    for x in range(w):
        e = S[y][x]
        if e != '#':
            num = cl(x, y, S)
            for k in range(h):
                ans = max(ans, max(num[k]))
print(ans)


Measured memory_bytes: 49116
#include<iostream>
using namespace std;
int main(void)
{
	int x;
	cin>>x;
	for(int i=1;i<=x;i++)
	{
		int p=i;
		if(p%3==0)
		{
			cout<<" "<<i;
		}

		else if(p%10==3)
			{
				cout<<" "<<i;
			}
		else
		{
			while(p/=10)
			{
				if(p%10==3)
				{
					cout<<" "<<i;
					break;
				}
			}
		}
	}
cout<<endl;
return 0;
}




Measured memory_bytes: 3080
#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <functional>

#define N 100000

using namespace std;

// int pq[2*N+1] = {};
// int q_max = 0;

int parent(int i){return((i-1)/2);}
int lchild(int i){return(2*i+1);}
int rchild(int i){return(2*i+2);}

void display_queue(int *pq, int *q_max){
  int j = 0;
  int b = 0;
  for (int i=0;i < *q_max;i++) {
    cout << pq[i] << " ";
    if (j==0 || j==(1<<b)) {
      cout << endl;
      b++;
      j=0;
    }
    j++;
  }
  cout << endl;
}

bool gt(long long x, long long y){
  return(x > y);
}

bool lt(long long x, long long y){
  return(x < y);
}

void push(long long x, long long *pq, long long *q_max, function<bool(long long, long long)> f){
  pq[*q_max] = x;
  int idx = *q_max;
  (*q_max)++;
  while (idx > 0) {
    if (f(pq[idx], pq[parent(idx)])) {
      int tmp = pq[parent(idx)];
      pq[parent(idx)] = pq[idx];
      pq[idx] = tmp;
      idx = parent(idx);
    } else {
      return;
    }
  }
}

long long pop(long long *pq, long long *q_max, function<bool(long long, long long)> f){
  if (*q_max < 0) {
    cerr << "queue is empty." << endl;
    return 0;
  }
  int result = pq[0];
  pq[0] = pq[--(*q_max)];
  int idx = 0;
  while (lchild(idx) < *q_max) {
    if (f(pq[idx], pq[lchild(idx)]) && f(pq[idx], pq[rchild(idx)])) {
      return(result);
    }
    if (f(pq[lchild(idx)], pq[rchild(idx)])) {
      int tmp = pq[lchild(idx)];
      pq[lchild(idx)] = pq[idx];
      pq[idx] = tmp;
      idx = lchild(idx);
    } else {
      int tmp = pq[rchild(idx)];
      pq[rchild(idx)] = pq[idx];
      pq[idx] = tmp;
      idx = rchild(idx);
    } 
  }
  return(result);
}


int main(){
  long long n;
  long long a1_pq[N+1], a2[N+1], a3_pq[N+1];
  long long a1_pq_max = 0;
  long long a3_pq_max = 0;
  long long a1_max[N+1], a3_min[N+1];
  cin >> n;
  a1_max[0] = 0;
  a3_min[n] = 0;
  for (int i=0;i<n;i++) {
    long long a;
    cin >> a;
    push(a, a1_pq, &a1_pq_max, lt);
    a1_max[0] += a;
  }
  for (int i=0;i<n;i++) {
    long long a;
    cin >> a;
    a2[i] = a;
  }
  for (int i=0;i<n;i++) {
    int a;
    cin >> a;
    push(a, a3_pq, &a3_pq_max, gt);
    a3_min[n] += a;
  }
  for (int i=0;i<n;i++) {
    if (a1_pq[0] < a2[i]) {
      a1_max[i+1] += a2[i] - a1_pq[0] + a1_max[i];
      pop(a1_pq, &a1_pq_max, lt);
      push(a2[i], a1_pq, &a1_pq_max, lt);
    } else {
      a1_max[i+1] = a1_max[i];
    }
  }
  for (int i=n;i>0;i--) {
    if (a3_pq[0] > a2[i-1]) {
      a3_min[i-1] += a2[i-1] - a3_pq[0] + a3_min[i];
      pop(a3_pq, &a3_pq_max, gt);
      push(a2[i-1], a3_pq, &a3_pq_max, gt);
    } else {
      a3_min[i-1] = a3_min[i];
    }
  }
  long long result = LLONG_MIN;
  for (int i=0;i<=n;i++) {
    if (a1_max[i] - a3_min[i] > result) {
      result = a1_max[i] - a3_min[i];
    }
  }
  cout << result << endl;  
}


Measured memory_bytes: 4224
#include <stdio.h>
#include <limits.h>
long FindMaxCrossingSubarray(long R[], long low, long mid, long high);
long FindMaxSubarray(long R[], long low, long high);
int main(){
  char line[100];				/* コマンドラインからの入力 */
  long n;						/* データの総数 */
  long i;						/* 添字 */
  long N[200000];
  long R[200000];
 /* 総数の入力 */
  fgets(line, sizeof(line), stdin);
  sscanf(line, "%ld", &n);
  /* データの入力 */
  for(i=0; i<n; ++i){
	fgets(line, sizeof(line), stdin);
	sscanf(line, "%ld", &N[i]);
  }
  for(i=0; i<(n-1); ++i){
	R[i]=N[i+1]-N[i];
}
  long max;
  /* for(i=0; i<n; ++i){ */
  /* 	printf("%ld\n", R[i]); */
  /* } */
  max=FindMaxSubarray(R, 0, n-2);
  printf("%ld\n", max);
  return 0;
}
long FindMaxCrossingSubarray(long R[], long low, long mid, long high){

  long leftsum=LONG_MIN, rightsum=LONG_MIN;
  long sum=0;
  // long maxleft, maxright;
  long i;
  for(i=mid; i>=low; --i){
	sum+=R[i];
	if(sum>leftsum)
	  leftsum=sum;
  }
  sum=0;
  for(i=(mid+1); i<=high; ++i){
	sum+=R[i];
	if(sum>rightsum)
	  rightsum=sum;
  }
  return (leftsum+rightsum);
}
long FindMaxSubarray(long R[], long low, long high){
  if(low==high)
	return R[low];
  else{
	long mid=(low+high)/2;
	long leftsum, rightsum, crosssum;
	leftsum=FindMaxSubarray(R, low, mid);
	rightsum=FindMaxSubarray(R, mid+1, high);
	crosssum=FindMaxCrossingSubarray(R, low, mid, high);
	if((leftsum>=rightsum)&&(leftsum>=crosssum))
	  return leftsum;
	else if((rightsum>=leftsum)&&(rightsum>=crosssum))
	  return rightsum;
	else 
	  return crosssum;
  }
}



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

#define MOD 1000000007;

long long dp[105][100005];
long long a[105], s[100005];

int main() {
    int n, k;
    cin >> n >> k;
	for (int i = 0; i < n; i++) 
        cin >> a[i];
    for (int i = 0; i <= n; i++)
        dp[i][0] = 1;
    for (int i = 0; i <= k; i++)
        dp[0][i] = 0;
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++) {
        s[0] = 0;
		for (int j = 1; j <= k + 1; j++)
            s[j] = s[j - 1] + dp[i - 1][j - 1];
		for (int j = 1; j <= k; j++) {
			dp[i][j] = (s[j+1] - s[max(0ll, j-a[i-1])]) % MOD;
		}
	}
    cout << dp[n][k];
}



Measured memory_bytes: 80128
import java.io.*;
import java.util.*;

public class Main{
	static void main() throws Exception{
		int n=sc.nextInt();long k=sc.nextLong();
		int[]in=new int[n+1];
		for(int i=0;i<n;i++) {
			in[i]=sc.nextInt()-1;
		}
		int[]time=new int[n];
		int timer=0;
		int cur=0;
		Arrays.fill(time, -1);
		while(time[cur]==-1) {
			time[cur]=timer++;
			cur=in[cur];
			k--;
			if(k==0) {
				pw.println(cur+1);
				return;
			}
		}
		int lenCycle=timer-time[cur];
		k=k%lenCycle;
		while(k-->0) {
			cur=in[cur];
		}
		pw.println(cur+1);
	}
	public static void main(String[] args) throws Exception{
		pw=new PrintWriter(System.out);
		sc = new MScanner(System.in);
		int tc=1;
		while(tc-->0) main();
		pw.flush();
	}
	static PrintWriter pw;
	static MScanner  sc;
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
	static void shuffle(int[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			int tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
	static void shuffle(long[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			long tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
}

Measured memory_bytes: 54816