akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;


int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	long long int k;
	cin >> k;

		if((k % 2) == 0 || (k % 5) == 0)
		{
			return cout << "-1\n", 0;
			 
		}
		
		long long int cur = 7 % k;
		int cnt  = 1;		
		while(cur != 0)
		{
			cur = cur * 10 + 7;
			cur %= k;
			cnt++;
//			cout << cur << " ";
		}
		cout << cnt << "\n";
}

Measured memory_bytes: 3628
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        mut v: [usize; 3]
    }
    v.sort();
    println!("{}", if v == vec![5, 5, 7] {"YES"} else {"NO"});
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(void)
{
	string s;
	cin >> s;
	vector<int> ans(s.size());
	vector<int> dp(s.size());

	int minL = s.size() - 1;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'L') {
			if (minL > i) {
				minL = i;
			}
			dp[i] = minL;
		}
		else {
			minL = s.size() - 1;
		}
	}

	int maxR = 0;
	for (int i = s.size() - 1; i >= 0; i--) {
		if (s[i] == 'R') {
			if (maxR < i) {
				maxR = i;
			}
			dp[i] = maxR;
		}
		else {
			maxR = 0;
		}
	}

	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'R') {
			if ((dp[i] - i) % 2 == 1) {
				ans[dp[i] + 1]++;
			}
			else {
				ans[dp[i]]++;
			}
		}
		else {
			if ((i - dp[i]) % 2 == 1) {
				ans[dp[i] - 1]++;
			}
			else {
				ans[dp[i]]++;
			}
		}
	}
	
	/*
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'R') {
			int j = i + 1;
			for (; s[j] != 'L'; j++);
			if ((j - i) % 2 == 1) {
				ans[j - 1]++;
			}
			else {
				ans[j]++;
			}
		}
		else {
			int j = i - 1;
			for (; s[j] != 'R'; j--);
			if ((i - j) % 2 == 1) {
				ans[j + 1]++;
			}
			else {
				ans[j]++;
			}
		}
	}
	*/

	for (int i = 0; i < ans.size() - 1; i++) {
		printf("%d ",ans[i]);
	}
	printf("%d\n",ans[ans.size()-1]);

	return 0;
}

Measured memory_bytes: 1408
N = int(input())
S = input()

alpha = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']

ans =[]

for i in range(len(S)):
    for j in range(26):
        if S[i] == alpha[j]:
            ans.append(alpha[j+N])

for i in range(len(ans)):
    print(ans[i], end ="")

Measured memory_bytes: 4596
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_pbds;
template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;
const ll mod =998244353;
const int maxn = 200005;
#define endl '\n'
#define ld long double
#define int ll
#define all(x) (x).begin(),(x).end()


int32_t main()
{ 
  IOS

  int n, k;
  cin >> n >> k;
  vector<int> p(n+1),c(n+1),who(n+1);
  for(int i = 1;i<=n;i++){
    cin >> p[i];
  }
  for(int i = 1;i<=n;i++){
    cin >> c[i];
  }

  vector<vector<int>> cycles;
  
  vector<int> vis(n+1,0);
  
  for(int i = 1;i<=n;i++){
    if(vis[i]) continue;
    int x = i;
    vector<int> now ;
    while(!vis[x]){
      now.push_back(x);
      vis[x] = true;
      who[x] = cycles.size();
      x = p[x];
    }
    assert(now.size()>0);
    cycles.push_back(now);
  }

  int ans = -1e18;
  for(int i = 1;i<=n;i++){

    vector<int> now = cycles[who[i]];
    
    int sum = 0;
    
    for(auto x:now) sum += c[x];
    
    if(sum>0){
      
      int whole  = k/now.size();
      whole = max(0ll,whole-1);
      int temp = whole*sum;
      int rem = k - whole*now.size();
      assert(rem>0);
      int x = i;
      while(rem--){
        temp += c[p[x]];
        ans = max(ans,temp);
        x = p[x];
      }

    }
    else{
      int temp = 0;
      int rem = min(k,(ll)now.size());
      int x = i;
      while(rem--){
        temp += c[p[x]];
        ans = max(ans,temp);
        x = p[x];
      }
    }
  }

  cout << ans << endl;





  

  










  
    
} 



Measured memory_bytes: 3880
def isprime(x):
    if x == 2:
        return True
    elif x < 2 or x%2 == 0:
        return False
    i = 3
    while i <= pow(x,1/2):
        if x%i == 0:
            return False
        i = i + 2
    return True
count = 0
for s in range(int(input())):
    if isprime(int(input())):
        count += 1
print(count)

Measured memory_bytes: 7736
#include <stdio.h>

#define MAX 2000000

int H, A[MAX + 1];

void maxHeapity(int i){
	int l, r, largest;
	l = 2 * i;
	r = 2 * i + 1;
	
	if(l <= H && A[l] > A[i]) {largest = l;}
	else {largest = i;}
	if(r <= H && A[r] > A[largest]) {largest = r;}
	
	if(largest != i){
		int tmp=0;
		tmp=A[i];
		A[i]=A[largest];
		A[largest]=tmp;
		maxHeapity(largest);
	}
}

int main()
{
	scanf("%d", &H);
	
	for(int i = 1; i <= H; i++){
		scanf("%d", &A[i]);
	}
	
	for(int i = H/2; i>=1; i--){
		maxHeapity(i);
	}
	
	for(int i = 1; i <= H; i++){
		printf(" %d", A[i]);
	}
	printf("\n");
	
	return 0;
}



Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  if(n/10==9 || n%10==9) cout<<"Yes"<<'\n';
  else cout<<"No"<<'\n';
  return 0;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	for(int i=0;i<n;++i){
		char c; cin>>c;
		if(c=='Y'){
			cout<<"Four\n"s;
			return 0;
		}
	}
	cout<<"Three\n"s;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>



void solve_A() {
	int R;
	std::cin >> R;
	std::cout << 2 * acos(-1) * R << std::endl;
}

void solve_B() {
	int N, M;
	std::cin >> N >> M;
	//int A[1001];
	long long int sum = 0;
	for (int i = 0; i < M; i++) {
		int tmp;
		std::cin >> tmp;
		sum += tmp;
	}
	
	std::cout << (sum <= N ? N - sum : -1) << std::endl;

}

void solve_C() {
	int N;
	std::cin >> N;
	int A[200001];

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

	for (int i = 1; i < N; i++) {
		int tmp;
		std::cin >> tmp;
		A[tmp -1] += 1;
	}
	for (int i = 0; i < N; i++) {
		std::cout << A[i] << std::endl;
	}
}

int main()
{
	//solve_A();
	//solve_B();
	solve_C();
    return 0;
}

Measured memory_bytes: 4364
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        s: [String; n],
    }

    if s.contains(&"Y".to_string()) {
        println!("Four");
    } else {
        println!("Three");
    }
}



Measured memory_bytes: 4352
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

signed main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);  
     cout.tie(0);   
 #ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
 #endif
 
// -------------------------------------Code starts here---------------------------------------------------------------------     

   int n,m;
   cin>>n>>m;
   long double a[n+1];
   long double s=0;
   for(int i=1;i<=n;i++)
   {
      cin>>a[i];
      s+=a[i];
   }
   s/=(4*m);
   int cnt=0;
   for(int i=1;i<=n;i++)
   {
      if(a[i]>=s)
         cnt++;
   }

   if(cnt>=m)
   {
      cout<<"Yes";
   }
   else
   {
      cout<<"No";
   }
   
// -------------------------------------Code ends here------------------------------------------------------------------
     clock_t clk;
 	clk = clock();
 
    clk = clock() - clk;
 	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
 	return 0;
 }
 

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

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

}



Measured memory_bytes: 3084
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<n;i++)
int main(){
ll n;
cin>>n;
ll a[n];
  ll b[n];
REP(i,n){
cin>>a[i];
  b[i]=a[i]-i;
}
sort(b,b+n);
  ll ans=0;
  if(n%2==1){
    ll mid=b[n/2];
  REP(i,n){
  ans+=abs(b[i]-mid);
  }
  }
  else{
    ll ans1=0;
    ll ans2=0;
  ll mid1=b[n/2];
    ll mid2=b[(n/2)-1];
    REP(i,n){
  ans1+=abs(b[i]-mid1);
        ans2+=abs(b[i]-mid2);
  }
    if(ans1<ans2)
      ans=ans1;
    else
      ans=ans2;
  }
  cout<<ans<<endl;
return 0;
}


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

namespace cola2
{
    class Program
    {
        static void Main()
        {
            string[] s_num = Console.ReadLine().Trim().Split(' ');
            int[] num = new int[s_num.Length];
            for(int i = 0; i < s_num.Length; i++)
            {
                num[i] = int.Parse(s_num[i]);
            }

            Array.Sort(num);

            for(int i = 0; i < num.Length - 1; i++)
            {
                Console.Write(num[i] + " ");
            }
            Console.WriteLine(num[2]);
        }
    }
}

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

a, b, c, x, y = map(int, input().split())

# ABセットをi個購入したとき、Aをmax(0, x - i)個、Bをmax(0, y - i)個購入する必要がある
# 1 <= x, y <= 10^5なので、全探索して最小金額を求めればよい

inf = float("inf")
min_price = inf
max_i = 10 ** 5

for i in range(max_i + 1):
    rest_x, rest_y = max(0, x - i), max(0, y - i)
    price = 2 * c * i + a * rest_x + b * rest_y
    if price < min_price:
        min_price = price

print(min_price)


Measured memory_bytes: 39792
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.Comparator;
import java.util.Collections;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        EAllyoucaneat solver = new EAllyoucaneat();
        solver.solve(1, in, out);
        out.close();
    }

    static class EAllyoucaneat {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int t = in.nextInt();
            int[] a = new int[n + 1];
            int[] b = new int[n + 1];
            ArrayList<Pair> alp = new ArrayList<Pair>();
            alp.add(new Pair(0, 0));
            int[][] dp = new int[n + 1][t + 2]; // dp[i][j] -> maximum value from 1 to i, within j min
            for (int i = 1; i <= n; i++) {
                a[i] = in.nextInt();
                b[i] = in.nextInt();
                alp.add(new Pair(a[i], b[i]));
            }
            Collections.sort(alp, Comparator.comparing(x -> x.time));
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= t; j++) {
                    // dp[i][j] = dp[i-1][j-a[i]] -> Add or dp[i-1][j] NoAdd
                    if (j - alp.get(i).time >= 0) {
                        dp[i][j] = Math.max(dp[i - 1][j - alp.get(i).time] + alp.get(i).val, dp[i - 1][j]);
                    } else {
                        // Add -> cannot [i][j] = [i-1][j]
                        dp[i][j] = dp[i - 1][j];
                    }
                }
                dp[i][t + 1] = Math.max(dp[i - 1][t - 1] + alp.get(i).val, dp[i - 1][t + 1]);
            }
            out.println(dp[n][t + 1]);

        }

    }

    static class Pair {
        int time;
        int val;

        public Pair(int x, int y) {
            this.time = x;
            this.val = y;
        }

    }
}



Measured memory_bytes: 84284
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9+7;
const int MAX = 510000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
#define INT_MAX 1e9+7

int main(){
    ll n,a,b; cin >> n >> a >> b;
    ll c = a-b;
    vl h(n);
    rep(i,n) cin >> h[i];
    ll ok = 1e10;
    ll ng = -1;
    while(ok-ng>1){
        ll mid = (ok+ng)/2;
        vl hh(n);
        rep(i,n){
            hh[i] = h[i] - b*mid;
        }
        ll cnt = 0;
        rep(i,n){
            if(hh[i]<=0) continue;
            cnt += (hh[i]+c-1)/c;
        }
        if(cnt > mid) ng = mid;
        else ok = mid;
    }
    cout << ok << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
typedef long long ll;
typedef pair<ll,ll> P;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
#define MAX 100000


int main(){
    int n,k;
    ll ans=0;
    cin>>n>>k;
    vi p(n); 
    rep(i,n){
        cin>>p[i];
    }
    sort(p.begin(),p.end());

    rep(i,k)ans+=p[i];
    cout<<ans;
    return 0;
}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int a, b, n;
        cin >> a >> b >> n;
        int x = min(n, b - 1);
        int ans = (a * x) / b - a * (x / b);
        cout << ans << '\n';
        // ans = -INF;
        // for(int i = 1; i <= n; i++){
        //     ans = max(ans, (a * i) / b - a * (i / b));
        //     // cout << i << ' ' << (a * i) / b - a * (i / b) << '\n';
        // }
        // cout << ans << '\n';
    }
}

Measured memory_bytes: 34216
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr=limii()

cnt=0
for i in range(n):
    if arr[i]%2==1:
        cnt+=1

if cnt%2==1:
    print("NO")
else:
    print("YES")



Measured memory_bytes: 87532
#include<stdio.h>
#include<assert.h>

namespace beet{
  
  template<typename T>
  struct Vector{
    int sz,cap;
    T *data;
    Vector():sz(0),cap(1){
      data = new T[cap];
    }    
    Vector(int sz):sz(sz),cap(sz<<1){
      data = new T[cap];
    }
    Vector(int sz,T t):sz(sz),cap(sz<<1){
      data = new T[cap];
      for(int i=0;i<sz;i++) data[i]=t;
    }
    ~Vector(){
      delete[] data;
    }
    void resolve(){
      T *tmp = new T[cap];
      for(int i=0;i<sz;i++) tmp[i]=data[i];
      delete[] data;
      data=tmp;
    }
    void push_back(T x){
      if(sz>=cap){
        cap<<=1;
        assert(sz<cap);
        resolve();
      }      
      data[sz++]=x;
    }
    void pop_back(){
      sz--;
    }
    int size() const{
      return sz;
    }
    const T operator[](int x) const{
      return data[x];
    }
    T& operator[](int x){
      assert(0<=x&&x<sz);
      return data[x];
    }
  };

  template<typename T>
  void swap(T &a,T &b){
    T x=a;
    a=b;
    b=x;
  }

  template<typename T>
  struct PriorityQueue{

    Vector<T> heap;
    PriorityQueue():heap(1){}
    
    void push(T t){
      heap.push_back(t);
      int v=heap.size()-1;
      while(v>>1){
        int p=v>>1;
        if(heap[v]<heap[p]) swap(heap[v],heap[p]);
        v=p;
      }
    }

    T top() const{
      return heap[1];
    }

    void dfs(int v){
      int l=(v<<1)|0;
      int r=(v<<1)|1;
      
      int nx=v;
      if(l<heap.size()&&heap[l]<heap[nx]) nx=l;
      if(r<heap.size()&&heap[r]<heap[nx]) nx=r;
      
      if(nx==v) return;
      swap(heap[v],heap[nx]);
      dfs(nx);
    }
    
    void pop(){
      assert(heap.size()>1);
      swap(heap[1],heap[heap.size()-1]);
      heap.pop_back();
      dfs(1);
    }

    bool empty() const{
      assert(heap.size()>=1);
      return heap.size()==1;
    }
  };
}
using namespace beet;

const int INF = 1e9;  
struct Node{
  int v,cost;
  Node(){}
  Node(int v,int cost):v(v),cost(cost){}
  bool operator<(const Node &a)const{
    return cost<a.cost;
  }
};
struct Edge{
  int to,cost;
  Edge(){}
  Edge(int to,int cost):to(to),cost(cost){}
};
  
int main(){
  int V,E,r;
  scanf("%d %d %d",&V,&E,&r);
  
  Vector<Vector<Edge> > G(V);
  for(int i=0;i<E;i++){
    int s,t,d;
    scanf("%d %d %d",&s,&t,&d);
    G[s].push_back(Edge(t,d));
  }
  
  PriorityQueue<Node> pq;
  Vector<int> dist(V,INF);
  dist[r]=0;
  pq.push(Node(r,dist[r]));
  while(!pq.empty()){
    Node res=pq.top();pq.pop();
    int v=res.v;
    
    if(dist[v]<res.cost) continue;
    for(int i=0;i<G[v].size();i++){
      int u=G[v][i].to,d=G[v][i].cost;
      if(dist[v]+d>=dist[u]) continue;
      dist[u]=dist[v]+d;
      pq.push(Node(u,dist[u]));
    }
  }
  
  for(int i=0;i<V;i++){
    if(dist[i]<INF) printf("%d\n",dist[i]);
    else printf("INF\n");
  }
  
  return 0;
}



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

ll gcd(ll a,ll b){
  while(b!=0){
    a%=b;
    swap(a,b);
  }
  return a;
}

ll kaizyou(ll N){
  ll num=1;
  for(ll i=1;i<=N;i++){
  num*=i;
  }
  return num;
}

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

vector<int> ans;
vector<int> to[200005];

void dfs(int now,int next=-1){
  for(int x : to[now]){
    if(x==next)continue;
    ans[x]+=ans[now];
    dfs(x,now);
  }
}
 
int main(){
  int n,q;
  cin >> n >> q;
  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ans.resize(n);
  rep(i,q){
    int p,x;
    cin >> p >> x;
    p--;
    ans[p]+=x;
  }
  dfs(0);
  rep(i,n){
    cout << ans[i] << endl;
  }
}
      
  
  
  

Measured memory_bytes: 23552
/*
*         ****FOX****
*/
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <limits>
//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#include <utility>
#include <list>
#include <cstdio>
#include<forward_list>
#include<algorithm>
#include<string>
#define Omar_Hafez ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi 3.1415926536
#define ll long long
#define ull unsigned long long
#define lli long long int
using namespace std;
int main()
{
    Omar_Hafez
   int n; cin >> n;
    vector<int> v(n,0); 
    for (int i = 1; i < n; i++)
    {
        for (int j = 1; j < n; j++)
        {
            for (int z = 1; z < n; z++)
            {
                int res = (i * i) + (j * j) + (z * z) + (i * j) + (j * z) + (i * z);  
                if (res <= n)  v[--res]++;
                else break;
            }
        }
    }
    for (int i = 0; i< v.size(); i++) cout << v[i] << "\n";
    return 0;
}



Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
	int N;
	cin >>N;
	int R = 0;
	for (int i = 1; i < 10; i++) {
		if (N%i == 0 && N / i < 10) {
			R++;
		}
	}
	if (R == 0) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
s = input()

odd = 'R','U','D' 
even = 'L','U','D' 

odd_flg = True
even_flg = True

for i in range(len(s)):
    # odd
    S = s[i:i+1]
    if i%2 == 0:
        if S not in odd:
            odd_flg = False
    elif i%2 == 1:# even
        if S not in even:
            even_flg = False
if odd_flg == True and even_flg == True:
    print('Yes')
else:
    print('No')



Measured memory_bytes: 3060
#include <iostream>
#include <vector>
using namespace std;
int n,m;
int k[10],s[10][10];
int p[10];
int ans;
vector<int> S[11];
int main(){
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>k[i];
        for(int j=0;j<k[i];j++){
            cin>>s[i][j];
            S[s[i][j]-1].push_back(i);
        }
    }for(int i=0;i<m;i++)cin>>p[i];
    int x[10];
    for(int i=0;i<1<<n;i++){
        for(int j=0;j<m;j++)x[j]=0;
        for(int j=0;j<n;j++){
            if((i>>j)%2==0) continue;
            for(int k=0;k<S[j].size();k++){
                x[S[j][k]]++;
            }
        }
        for(int j=0;j<m;j++){
            if(x[j]%2!=p[j]) break;
            if(j==m-1) ans++;
        }
    }
    cout<<ans;
    return 0;
}

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



int main(){
    ll n;
    cin >> n;
    ll a[n];
    ll b[n];
    for(ll i=0;i<n;i++){
        cin >> a[i];
        b[i]=a[i];
    }
    sort(a,a+n);
    sort(b,b+n);
    reverse(b,b+n);
    ll res=0;
    ll count=0;
    if(n%2==0){
        for(ll i=0;i<(n-2)/2;i++){
            res+=b[i]*2;
            res-=a[i]*2;
        }
        res+=b[n/2-1];
        res-=b[n/2];
    }
    else{
        for(ll i=0;i<(n-2)/2;i++){
            res+=b[i]*2;
            count-=a[i]*2;
        }
        for(ll i=0;i<(n-1)/2;i++){
            res-=a[i]*2;
            count+=b[i]*2;
        }
        res+=(b[n/2]+b[n/2-1]);
        count-=(b[n/2]+b[n/2+1]);
    }
    cout << max(res,count) << endl;
    return 0;
}  


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

using namespace std;

#define Speed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define mod 1000000007
#define fr first
#define sc second
#define pb push_back
#define PI acos(-1.0)
#define print(num,ans) cout<<setprecision(num)<<fixed<<ans


int main()
{
    Speed;
    int i,a1,a2,a3;
    cin>>a1>>a2>>a3;
    if(a1+a2+a3 >= 22)cout<<"bust"<<endl;
    else cout<<"win"<<endl;
    return 0;
}


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

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

struct L {
  int a, b, c;
  L(int a=0, int b=0, int c=0): a(a), b(b), c(c) {}
};

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

int main() {
  int n, m;
  cin >> n >> m;
  map<int,int> mpX, mpY;
  mpX[0] = 0;
  mpY[0] = 0;

  vector<L> lh, lv;
  rep(i,n) {
    int a, b, c;
    cin >> a >> b >> c;
    mpX[a] = 0;
    mpX[b] = 0;
    mpY[c] = 0;
    lh.emplace_back(a,b,c);
  }
  rep(i,m) {
    int a, b, c;
    cin >> c >> a >> b;
    mpY[a] = 0;
    mpY[b] = 0;
    mpX[c] = 0;
    lv.emplace_back(a,b,c);
  }

  vector<int> xs, ys;
  for (auto& p : mpX) {
    p.second = xs.size();
    xs.push_back(p.first);
  }
  for (auto& p : mpY) {
    p.second = ys.size();
    ys.push_back(p.first);
  }

  int h = xs.size()*2;
  int w = ys.size()*2;

  vector<vector<int>> d(h, vector<int>(w));
  rep(i,n) {
    int a = mpX[lh[i].a]*2;
    int b = mpX[lh[i].b]*2;
    int c = mpY[lh[i].c]*2;
    for (int x = a; x <= b; ++x) d[x][c] = -1;
  }
  rep(i,m) {
    int a = mpY[lv[i].a]*2;
    int b = mpY[lv[i].b]*2;
    int c = mpX[lv[i].c]*2;
    for (int y = a; y <= b; ++y) d[c][y] = -1;
  }

  queue<P> q;
  int sx = mpX[0]*2, sy = mpY[0]*2;
  d[sx][sy] = 1;
  q.emplace(sx,sy);
  while (!q.empty()) {
    int x = q.front().first;
    int y = q.front().second;
    q.pop();
    rep(v,4) {
      int nx = x+dx[v], ny = y+dy[v];
      if (nx < 0 || nx >= h) continue;
      if (ny < 0 || ny >= w) continue;
      if (d[nx][ny] != 0) continue;
      d[nx][ny] = 1;
      q.emplace(nx,ny);
    }
  }

  ll ans = 0;
  rep(x,h)rep(y,w) {
    if (d[x][y] != 1) continue;
    if (x == 0 || x == h-1 || y == 0 || y == w-1) {
      cout << "INF" << endl;
      return 0;
    }
    if (x%2 == 0 || y%2 == 0) continue;
    ll ex = xs[x/2+1]-xs[x/2];
    ll ey = ys[y/2+1]-ys[y/2];
    ans += ex*ey;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 144516
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
// #include <numeric> // gcdとかlcmとか C++17から
#include <time.h> // time_t timer; time(&timer); でtimerに現在時刻が代入される．
#include <unistd.h> // sleep関数．引数は秒単位．
using namespace std;

typedef long long ll;


// sortの仕方
// 	■ string s の場合
// 	昇順: sort(s.begin(), s.end())
// 	降順: sort(s.rbegin(), s.rend())
//
// 	■ ll a[N] の場合
// 	昇順: sort(a, a+N)
// 	降順: 不明


// int alph2int(char character) {
//     int x = character - 'a';
//     return x;
// }


ll my_gcd(ll a, ll b){
	return (b==0) ? a : my_gcd(b, a%b);
}


//  ll my_lcm(ll a, ll b){
//  	return a*b / my_gcd(a,b);
//  }


// ll factorial(ll a){
// 	ll ans = 1;
// 	for(ll)i=a; i>0; i--){
// 		ans *= i;
// 	}
// 	return ans;
// }

int main(int argc, char *argv[]){
    ll N, X;
    cin >> N >> X;
    vector<ll> x(N);
    for (int i=0; i<N; i++) {
        cin >> x[i];
    }

    sort(x.begin(), x.end());
    ll ans = abs(x[0] - X);
    for (int i=0; i<N; i++) {
        int ans_tmp = my_gcd(ans, abs(x[i] - X));
        if (ans > ans_tmp) {
            ans = ans_tmp;
        }
    }

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

Measured memory_bytes: 1024
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll=long long;
constexpr ll MOD=1e9+7;

int main()
{
	int N;
	cin>>N;
	vector<int> A(N), cnt(100000,0);
	rep(i,N)cin>>A[i];

	ll res = count(A.begin(), A.end(), 0);
	if(res>3){
		cout<<0<<endl;
		return 0;
	}
	vector<int> base = {0,3,6,6};
	res = base[res];
	rep(i,N){
		if(A[i]>0){
			(res *= cnt[A[i]-1])%=MOD;
		}
		cnt[A[i]-1]--;
		cnt[A[i]]++;
	}
	cout<<res<<endl;
	return 0;
}


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

int main(){

    int N;
    cin >> N;

    int ans = 0;
    for(int i = 1; i <= N; i++){
        // 一番上の桁から見てそれが7, 5, 3以外だったらその桁数分スキップする
        string num = to_string(i);
        int seven = 0, five = 0, three = 0;
        for(int j = 0; j < num.length(); j++){
            if(num[j] == '7' || num[j] == '5' || num[j] == '3'){
                if(num[j] == '7') seven++;
                else if(num[j] == '5') five++;
                else if(num[j] == '3') three++;
                if(j == num.length() - 1 && seven > 0 && five > 0 && three > 0){
                    ans++;
                }
            }else{
                i += pow(10, num.length() - 1 - j);
                i--; 
                break;
            } 
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.*;

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

		try {
			while ((buf = br.readLine())!=null) {
				int n = Integer.parseInt(buf);
				int S = 1;
				for (int i=1;i<=n;i++) {
					S += i;
				}
				System.out.println((long)S);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

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

void solve()
{
	string s,t;
	cin>>s>>t;
	int ans = 0;
	for (int i = 0; i < s.length(); ++i)
	{
		if(s[i]!=t[i])
			ans++;
	}
	printf("%d\n", ans);
}

int main()
{
	ll t = 1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 3880
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#define fast ios_base::sync_with_stdio(false)
#define mxn (ll)1e5
#define mod (ll)(1e9+7)
#define mod1 (ll)(998244353)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
int main(){
	string s;cin>>s;
	if(s[2]==s[3]&&s[4]==s[5]) cout<<"Yes\n"; else cout<<"No\n";
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<numeric>
#include<list>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;


//最大公約数
template<class T> T gcd(T a, T b)
{
	while (true)
	{
		T r;
		if (a%b == 0) return b;
		else
		{
			r = a % b;
			a = b;
			b = r;
		}
	}
}
//最小公倍数
template<class T> T lcm(T a, T b)
{
	return a / gcd(a, b)*b;
}
//文字0~9をint型0~9に変換
int char_to_int(char c)
{
	if (c == '0') return 0;
	if (c == '1') return 1;
	if (c == '2') return 2;
	if (c == '3') return 3;
	if (c == '4') return 4;
	if (c == '5') return 5;
	if (c == '6') return 6;
	if (c == '7') return 7;
	if (c == '8') return 8;
	if (c == '9') return 9;
	else return -1;
}
//int型0~9を文字0~9に変換
char int_to_char(int c) {
	if (c == 0) return '0';
	if (c == 1) return '1';
	if (c == 2) return '2';
	if (c == 3) return '3';
	if (c == 4) return '4';
	if (c == 5) return '5';
	if (c == 6) return '6';
	if (c == 7) return '7';
	if (c == 8) return '8';
	if (c == 9) return '9';
	else return'x';
}
//a^b mod MODを計算
long long int ModPower(long long int a, long long int b, long long int MOD)
{
	if (b == 0) return 1;
	else if (b % 2 == 0)
	{
		long long int d = ModPower(a, b / 2, MOD);
		return (d*d) % MOD;
	}
	else
	{
		return (a*ModPower(a, b - 1, MOD)) % MOD;
	}
}
//nCr mod MODを計算
long long int ModCombi(long long int n, long long int r, long long int MOD)
{
	if (n == 0 || r == 0) return 1;

	long long int Kn = 1, Kr = 1, Knr = 1;

	long long int temp = 1;
	for (long long int i = 1; i <= n; i++)
	{
		temp *= i;
		temp %= MOD;
		if (i == n) Kn = temp;
		if (i == r) Kr = temp;
		if (i == n - r) Knr = temp;
	}

	long long int x = ModPower(Kr, MOD - 2, MOD);
	long long int y = ModPower(Knr, MOD - 2, MOD);

	long long int ans;
	ans = Kn * x;
	ans %= MOD;
	ans *= y;
	ans %= MOD;

	return ans;
}
//int型10進数をord桁のstring型2進数に変換する
string binary(int x, int ord)
{
	int y;
	string ans = "";
	for (int i = 0; i < ord; i++)
	{
		y = x / (int)pow(2, ord - 1 - i);
		y %= 2;
		if (y == 0) ans += "0";
		else ans += "1";
	}

	return ans;
}
//ord桁のstring型2進数をint型10進数に変換する
int rep_binary(string x, int ord)
{
	int res = 0;
	for (int i = 0; i < ord; i++)
	{
		if (x[i] == '1') res += (int)pow(2, ord - 1 - i);
	}
	return res;
}
//xとyのビットごとの排他的論理和
template<class T> T XOR(T x, T y)
{
	T n = 0;
	while (max(x, y) > pow(2, n)) n++;
	T ans=0;
	for (int i = 0; i <= n; i++)
	{
		T x1 = (x % (T)pow(2, i + 1)) / (T)pow(2, i);
		T y1 = (y % (T)pow(2, i + 1)) / (T)pow(2, i);
		if (x1 != y1) ans += (T)pow(2, i);
	}
	return ans;
}

/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/

int cut(double x)
{
	return (int)x;
}

int main()
{
	int A, B;
	cin >> A >> B;
	bool x = true;
	for (int i = 1; i < 1010; i++)
	{
		if (cut(i*0.08) == A && cut(i*0.1) == B)
		{
			cout << i << endl;
			x = false;
			break;
		}
	}
	if (x) cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 256
H,N=map(int,input().split())
A=[]
B=[]
for i in range(N):
    n,a=input().split()
    A.append(int(n))
    B.append(int(a))
def f(x):
    if x<=0:
        return 0
    else:
        mini=g(x-A[0])+B[0]
        for i in range (1,N):
            sub=g(x-A[i])+B[i]
            if sub<mini:
                mini=sub
        return mini
def g(x):
    if x<0:
        return 0
    else:
        return g_list[x]
g_list=[]
g_list.append(0)
for i in range(1,H+1):
    g_list.append(f(i))
print(g_list[-1])

Measured memory_bytes: 9392
// stdin
macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

// input
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// Test
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r"3
2 3 1
" => r"3 1 2",

r"5
1 2 3 4 5
" => r"1 2 3 4 5",

r"8
8 2 7 3 4 5 6 1
" => r"8 2 4 5 6 7 3 1"
}

fn solve(src: &str) -> String {
    input! {
        source=src,
        n:usize,
        a:[i32;n],
    }

    let a: Vec<i32> = a;
    let n: usize = n;
    let mut arr: [i32; 100_000] = [0; 100_000];


    for (i, arrival) in a.iter().enumerate() {
        arr[(*arrival -1) as usize] = (i + 1 )as i32;
    }

    let ans = &arr[..n];

    let ans = format!("{}", ans.into_iter().map(|n| n.to_string()).collect::<Vec<String>>().join(" "));
    format!("{}", ans)
}


fn main() {
    println!("{}", solve(&stdin!()));
}



Measured memory_bytes: 10876
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
using namespace std;
int main(){
	int n,a,i,j;
	int s[2][100];
	cin >> n;
	for (i=0 ; i < 2; i++) {
		for (j = 0; j < n; j++) {
			cin >> a;
			s[i][j] = a;
		}
	}
	int m = 0;
	int sum;
	for (i = 0; i < n; i++) {
		sum = 0;
		sum += s[0][i] + s[1][i];
		for (j = 0; j < n; j++) {
			if (j < i)sum += s[0][j];
			else if(j>i){
				sum += s[1][j];
			}
		}
		m = max(m, sum);
	}
	cout << m << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll long long
#define int long long
#define pb push_back
#define x first
#define ld long double
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) a.begin(),a.end()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector <int> used(10, 1);
    for (int i = 0; i < k; i++) {
        int x;
        cin >> x;
        used[x] = 0;
    }
    for (int i = n; ; i++) {
        bool ok = true;
        int x = i;
        while (x) {
            if (!used[x % 10]) ok = false;
            x /= 10;
        }
        if (ok) {
            cout << i << '\n';
            rr;
        }
    }
}


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

int main() {
  long long a, b, c; cin >> a >> b >> c;
  long long tmp = c - a - b;
  tmp *= tmp;
  long long tmp2 = 4 * a * b;
  if (tmp2 < tmp) {
    if (c - a - b > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  else cout << "No" << endl;
}

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

using ll = long long;

using namespace std;

int rui[20][1010] = {{0}};

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    for (int i=1; i<=h; i++) {
        for (int j=1; j<=w; j++) {
            char c; cin >> c;
            rui[i][j] = c - '0';
        }
    }
    for (int i=0; i<=h; i++) {
        for (int j=0; j<w; j++) {
            rui[i][j+1] += rui[i][j];
        }
    }
    for (int j=0; j<=w; j++) {
        for (int i=0; i<h; i++) {
            rui[i+1][j] += rui[i][j];
        }
    }
    int lim = (1 << (h-1));
    int ans = h + w;
    for (int b=0; b<lim; b++) {
        vector<int> ends;
        for (int i=0; i<h-1; i++) if (b & (1 << i)) ends.push_back(i);
        ends.push_back(h-1);
        int sj = 0, cnt = ends.size()-1;
        for (int j=0; j<w; j++) {
            int si = 0;
            for (auto &ei:ends) {
                int val = rui[ei+1][j+1] - rui[si][j+1] - rui[ei+1][sj] + rui[si][sj];
                if (val > k) {
                    if (sj == j) cnt = h + w;
                    sj = j;
                    cnt++;
                    break;
                } 
                si = ei+1;
            }
        }
        ans = min(ans, cnt);
        // cerr << cnt << ' ' << b << '\n';
    }
    cout << ans << '\n';
    return 0;
}

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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

int main(){
  int n;
  ll sum=0;
  cin>>n;
  ll a[n];
  ll b[n+1];
  int c[n];
  memset(b,0,sizeof(b));
  REP(i,n){
    cin>>a[i];
    b[a[i]]++;
  }
  REP(i,n){
    if(b[i+1]>1){
      if(b[i+1]%2==0){
        sum+=(b[i+1]/2)*(b[i+1]-1);
      }else{
        sum+=((b[i+1]-1)/2)*b[i+1];
      }
    }
  }
  REP(i,n){
    cout<<sum-(b[a[i]]-1)<<endl;
  }
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


//const int mod = 1000000007;
const int MAX = 1000005;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod/i) % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
}
long long COM(int n, int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

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

    COMinit();
    int N, K; cin >> N >> K;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];
    sort(a.begin(), a.end());

    ll ans = 0;
    rep(i, N){
        // max
        if (i>=K-1) { ans += a[i]*COM(i, K-1)%mod; chmod(ans); }
        // min
        if (N-1-i>=K-1) { ans -= a[i]*COM(N-1-i, K-1)%mod; chmod(ans); }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 24448
# 各ポイントから右回り(right)、左回り(left)の２通りで距離を計算する

K,N = map(int,input().split())
aList = [int(x) for x in input().split()]

minDist=pow(10,6)

for i in range(N-1):
    right=0
    left=0
    if i == 0:
        right = aList[N-1] - aList[0]
        left  = K - aList[1] + aList[0]
    elif i == N-1:
        right = K + aList[N-2] - aList[N-1]
        left  = aList[N-1] - a[0]
    else:
        right = K + aList[i-1] - aList[i]
        left  = K - aList[i+1] + aList[i]
    minDist =min(minDist,min(right,left))

print(minDist)


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

int main(){
	int n;
	int a[100];
	int min = 0;
	int max = 0;
	int over = 0;
	bool geta = 0;
	bool color[8] = {};



	cin >> n;

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

	for(int i = 0; i < n;++i){
		if((a[i] / 400) < 8)
			color[a[i] / 400] = true;
		else
			over++;
	}

	for(int i = 0;i < 8;++i){
		if(color[i])
			min++;
	}

	if(min == 0)
		geta =  1;


	
	max = min + over;



	cout << min + geta << " "<< max  << endl;
}

Measured memory_bytes: 256