akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include<stdio.h>
#include<vector>
#pragma GCC optimize(2)
typedef long long ll;
typedef unsigned long long ull;
const int mod=1000;
const int maxn=1e5+5;
const ll INF=100000000000005;
using namespace std;
ll n,m,p;
ll qpow(ll a,ll b){ll ans=1;while(b){if(b&1) ans=(ans*a)%mod;b/=2;a=(a*a)%mod;}return ans;}
ll dp[maxn];
ll num[maxn];
int main()
{
    scanf("%lld",&n);
    for(int i=1;i<=n;i++) scanf("%lld",&num[i]);
    dp[1]=0;dp[2]=abs(num[2]-num[1]);
    for(int i=3;i<=n;i++)
        dp[i]=min(dp[i-1]+abs(num[i]-num[i-1]),dp[i-2]+abs(num[i]-num[i-2]));
    printf("%lld\n",dp[n]);
    return 0;
}


Measured memory_bytes: 1792
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::collections::HashMap;

fn main() {
    let n: usize = read();
    let mut ans = 0;

    for i in 1..n + 1 {
        let k = n / i;
        ans += i * (k * (k + 1) / 2);
    }
    println!("{}", ans);
}


Measured memory_bytes: 2140
#include<vector>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#define pb push_back
#define nc getchar
using namespace std;
inline void read(int &x) {
	char b = nc(); x = 0;
	for (; !isdigit(b); b = nc());
	for (; isdigit(b); b = nc()) x = x * 10 + b - '0';
}
struct Node {
	int x, y, id;	
	inline bool operator<(const Node &o) const {
		return x < o.x || (x == o.x && y < o.y);
	}
} a[100005];
int n, s, t, D, f[100005], fa[100005];
int find(int x) {return fa[x] == x ? x : fa[x] = find(fa[x]);}
long long ans;
bitset < 100005 > vis;
inline int ABS(int x) {return x > 0 ? x : -x;}
inline void ae(int u, int v) {
	if ((u = find(u)) != (v = find(v))) fa[v] = u;
}
void build(int k) {
	sort(a + 1, a + 1 + n); int i, j, l, r;
	for (i = j = l = r = 1; i <= n; ++i) {
		while (a[l].x < a[i].x - D || (a[l].x == a[i].x - D && a[i].y - a[l].y > k)) ++l;
		while (a[r].x < a[i].x - D || (a[r].x == a[i].x - D && a[r].y - a[i].y <= k)) ++r;
		f[a[i].id] += r - l; j = max(j, l); if (j < r) ae(a[i].id, a[j].id);
		for (; j + 1 < r; ++j) ae(a[j].id, a[j+1].id);
	}
}
int main() {
	read(n); read(s); read(t);
	for (int i = 1; i <= n; ++i) fa[i] = i;
	for (int x, y, i = 1; i <= n; ++i)
		read(x), read(y), a[i] = (Node){x + y, x - y, i};
	D = max(ABS(a[s].x - a[t].x), ABS(a[s].y - a[t].y));
	build(D);
	for (int i = 1; i <= n; ++i) swap(a[i].x, a[i].y);
	build(D-1);
	for (int i = 1; i <= n; ++i)
		if (find(i) == find(s)) ans += f[i];
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;


int main(){
    int N, P, tmp;
    int a=0;
    cout << setprecision(32);
    cin >> N >> P;
    for(int i=0;i<N;i++){
        cin >> tmp;
        if(tmp%2 != 0) a++;
    }
    if(P == 1 && a < 1) cout << 0 << endl;
    else if(P == 0 && a < 1) cout << pow(2,N) << endl;
    else{ 
        cout <<  pow(2,N - 1) << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, l, r) for(register int i = l; i < r; i++)
#define hrp(i, l, r) for(register int i = l; i <= r; i++)
#define rev(i, r, l) for(register int i = r; i >= l; i--)
#ifdef LOCAL
#define D(x) cout<<"D: "<<#x<<'='<<x<<endl;
#define R(x, l) cout<<"R: Array "<<#x<<endl; rep(i, 0, l) cout<<' '<<i<<':'<<*(x+i)<<endl;
#else
#define D(x)
#define R(X, l)
#endif
#define pb push_back
#define int ll
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn> inline tn next(void);
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v);
inline int _max(int cnt, ...);
inline int _min(int cnt, ...);
signed main(void)
{
	#ifdef LOCAL
//		freopen("C:\\Users\\Joeon\\Desktop\\IN.txt", "r", stdin);
//		freopen("C:\\Users\\Joeon\\Desktop\\OUT.txt", "w", stdout);
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n = next<int>(), ans = 0;
	hrp(i, 1, n) if(!(i%3 == 0 || i%5 == 0)) ans += i;
	cout<<ans<<endl;
	return 0;
}
template<typename tn> inline tn next(void)
{
	tn k;
	cin>>k;
	return k;
}
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v)
{
	rep(i, 0, v.size()) os<<v[i]<<' ';
	return os;
}
inline int _max(int cnt, ...)
{
	int mx = -1e18;
	va_list l;
	va_start(l, cnt);
	while(cnt--) mx = max(mx, va_arg(l, int));
	va_end(l);
	return mx;
}
inline int _min(int cnt, ...)
{
	int mn = 1e18;
	va_list l;
	va_start(l, cnt);
	while(cnt--) mn = min(mn, va_arg(l, int));
	va_end(l);
	return mn;
}


Measured memory_bytes: 3660
#include "bits/stdc++.h"

using namespace std;

const char en = '\n';
using  ll =          long long;
using ull = unsigned long long;


int main(){
	ios::sync_with_stdio(false);cin.tie();
	
	ll n,m,distance[114514],result=0;
	cin>>n>>m;
	distance[0]=0;
	for(int i=1;i<n;i++){
		cin>>distance[i];
		distance[i]+=distance[i-1];
		//cout<<distance[i]<<en;
	}

	int in,pos=0;
	for(int i=0;i<m;i++){
		cin>>in;
		result+=abs(distance[pos+in]-distance[pos]);
		pos+=in;
		result%=100000;
	}
	cout<<result<<en;

	return 0;
}

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

using namespace std;

unordered_map<long long,long long> mp;
long long sol(long long x){
	if(x==0) return 0;
	if(mp.find(x)!=mp.end()) return mp[x];
	
	long long res=sol(x/2)*2+1;
	mp[x]=res;
	return res;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	long long x;
	cin >> x;
	cout << sol(x) << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
using namespace std;

#define INF 1e18
#define int long long

static const int MOD = 1000000007;

int n;
char s[100005];
int dp[100005][13];

int solve() {
    int i, j, k, res = 0;

    scanf("%s", s);
    n = strlen(s);

    dp[0][0] = 1;
    for(i = 0; i < n; i++) {
        int c;
        if(s[i] == '?') c = -1;
        else c = s[i] - '0';

        for(j = 0; j < 10; j++) {
            if(c != -1 && c != j) continue;
            for(k = 0; k < 13; k++) {
                dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
            }
        }
        for(j = 0; j < 13; j++) dp[i + 1][j] %= MOD;
    }
    res = dp[n][5];

    printf("%lli\n", res);
    return 0;
}

signed main() {
    solve();
}


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

int main() {
	int k, t;
	cin >> k >> t;
	vector<int> a(t);
	for(int i = 0; i < t; i++){
		cin >> a[i];
	}
	
	sort(a.begin(), a.end());
	
	for(int i = 0; i < t-1; i++){
		a[t-1] -= a[i];
	}
	a[t-1]--;
	
	if(a[t-1] < 0){
		cout << 0 << endl;
	}else{
		cout << a[t-1] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <map>
#define REP(i,n) for(int i = 0; i < (int)n; i++)
using namespace std;

int main(){
  int n;
  cin >> n;
  map<long,bool> mp;
  REP(i,n){
    long a;
    cin >> a;
    mp[a] = !mp[a];
  }
  int ans = 0;
  for(auto x: mp){
    if(x.second==true) ans++;
  }
  cout << ans << endl;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

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

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    vector<ll> A(N);

    ll sum = 0;
    map<ll, ll> M;
    REP(i, N){
        cin >> A[i];
        sum += A[i];
        M[A[i]]++;
    }

    ll Q;
    cin >> Q;

    REP(i, Q){
        ll b, c;
        cin >> b >> c;

        ll temp;
        if(!M.count(b)) M[b] = 0;
        if(!M.count(c)) M[c] = 0;

        sum -= M[b]*b;
        temp = M[b];
        M[b] = 0;

        sum += temp*c;
        M[c] += temp;
        
        cout << sum << endl;

    }

    return 0;
}

Measured memory_bytes: 9956
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
   
//#include <x86intrin.h>
#include <bits/stdc++.h>   
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
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>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, r, st;
vector <int> g[N];

void dfs (int v, int pr = 0, int lvl = 0) {
   if (r < lvl) r = lvl, st = v;
   for (auto to : g[v])
      if (to != pr)
         dfs (to, v, lvl + 1);

}

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   cin >> n;
   for (int i = 1; i < n; i ++) {
      int x, y;
      cin >> x >> y;
      g[x].pb (y);
      g[y].pb (x);
   }
   dfs (1);
   r = 0;
   dfs (st);
   cout << (r % 3 == 1 ? "Second" : "First");
}

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}
                          

Measured memory_bytes: 22912
arr = [int(x) for x in input().split()]
max_item = max(arr)
max_index = arr.index(max_item)
del arr[max_index]
diff1 = max_item - arr[0]
diff2 = max_item - arr[1]
diff = diff1 + diff2
if diff % 2 == 0:
    print(int(diff/2))
else:
    print(int((diff + 1)/2) + 1)
    
    

Measured memory_bytes: 3060
import java.util.*;
class Main {
    public static void main (String[] args) throws java.lang.Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        for(int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if('a' <= c && c <= 'z') System.out.print((char)(c - 32));
            else if('A' <= c && c <= 'Z') System.out.print((char)(c + 32));
            else System.out.print(c);
        }
        System.out.println();
    }
}


Measured memory_bytes: 26644
#include <bits/stdc++.h>
#define X first
#define Y second
#define mp make_pair
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
const int N = 200010;
bitset<N> s,tmp;
char S[N];
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	scanf("%s",S);

	for(int i=0;i<n;i++){
		if(S[i]=='A') s.set(i);
	}
	int i,j,t;
	for(i = 0,j = 0,t = 0;i<k && j<n;i++){
			//if((j&1) && t==0) s.flip(j),t^=1;
			if(s[j]==0){
				j++;
				if(j<n && (j&1)) s.flip(j);
				t=0;
			} else{
				s.flip(j);
			}
	}
	//cout<<s<<endl;
	tmp = s;
	s.reset();
	if(j<n) s[0]=tmp[j]; else {
		if((n&1) && ((k-i)%2)==0) s.set(0);
	}
	for(int i=j+1;i<n;i++){
		if((j&1)^(tmp[i]==1)) s.set(i-j);
	}
	//cout<<s<<endl;
	for(int i=max(n,j+1);i<j+n;i++){
		if((n&1)^((i-j)&1)) s.set(i-j);
		//if((n-i+j+1)&1) s.set(i-j);
	}
	for(int i=0;i<n;i++)if(s[i]==0) putchar('B'); else putchar('A');
	puts("");
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> vec(n);
  for(int i = 0; i < n; i++){
    cin >> vec[i];
  }
  int count = 1;
  int min = vec[0];
  for(int i = 0; i < n; i++){
    if(min > vec[i]){
      min = vec[i];
      count ++;
    }
  }
  cout << count;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<cassert>
using namespace std;
#define INF (1<<24)

bool isNum(char ch){return ('0'<=ch&&ch<='9');}

struct calcStr{
  string s;
  int pos,len;

  void init(){ pos=0;len=s.size();}

  int head2Num(){
    if(s[pos]=='('){pos++;return getAns();}
    
    bool f=false;
    if(s[pos]=='-'){f=true;pos++;}
    int res=0;
    while(pos<len){
      if(isNum(s[pos])){
	res*=10;
	res+=(s[pos]-'0');
	pos++;
      }else break;
    }
    if(f)res*=-1;
    return res;
  }
  
  int getNum(){
    int res=head2Num(),num;
    char ch;
    while(s[pos]=='*'||s[pos]=='/'){
      ch=s[pos++];
      num=head2Num();
      if(ch=='*')res*=num;
      else if(ch=='/')res/=num;
    }
    return res;
  }
  
  int getAns(){
    int res=getNum(),num;
    while(1){
      if(s[pos]==')'){pos++;break;}
      if(s[pos]=='=')break;
      char ch=s[pos++];
      num=getNum();
      if(ch=='+')res+=num;
      else if(ch=='-')res-=num;
      else assert(0);
    }
    return res;
  }
};

int main(){
  int Tc;cin>>Tc;
  calcStr a;
  while(Tc--){
    cin>>a.s;
    a.init();
    cout<<a.getAns()<<endl;
  }
  return 0;
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
int main()
{
  
int dp[3005][3005]={};
  string s,t;
  int n,m;
  stack<char> str;

  cin>>s>>t;
  n=s.size();
  m=t.size();

  dp[0][0]=0;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      if(s[i-1]==t[j-1]){
	dp[i][j]=dp[i-1][j-1]+1;
      }else{
	dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
      }
    }
  }

  int i=n,j=m;
  while(i!=0 && j!=0){
    if(s[i-1]==t[j-1]){
      str.push(s[i-1]);
      i--;
      j--;
    }else{
      if(dp[i-1][j]>=dp[i][j-1]){
	i--;
      }else{
	j--;
      }
    }
  }

  int r=str.size();
  for(int i=0;i<r;i++){
    cout<<str.top();
    str.pop();
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 35584
#include<bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ll long long
#define all(a) a.begin(),a.end()
#define endl '\n'
#define int ll

using namespace std;

const int N = 3e5 + 3;
const int inf = 1e9 + 3;
const int md = 1e9 + 7;

string s;

bool pal(int l, int r) {
    for(int i = 0; i <= r - l; ++i) {
        if(s[l + i] != s[r - i]) return false;
    }
    return true;
}

bool f(string s) {
    int len = s.size();
    return pal(0, s.size() - 1) && pal(0, (len - 1) / 2 - 1) && pal((len + 3) / 2 - 1, s.size() - 1);
}

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

    cin >> s;
    cout << (f(s) ? "Yes" : "No");

}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int n = N;
    int sum = 0;
    while (n != 0) {
      sum += n%10;
      n /= 10;
    }
    
    System.out.println(N % sum == 0 ? "Yes" : "No");
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    int sum=0;
    for(int i=0;i<n;i++) sum+=a[i];
    bool answer=true;
    for(int i=0;i<n;i++){
        if(sum-a[i]<=a[i]){
            answer=false;
            break;
        }
    }
    if(answer) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.lang.*;
public class Main {
	PrintWriter out;
    StringTokenizer st;
    BufferedReader br;
 	
 	class Pair implements Comparable<Pair>
	{
	    int f;
	    int s;
 
	    Pair(int t, int r) {
	       f = t;
	       s = r;
	    }
	    public int compareTo(Pair p)
	    {
	    	if(this.f!=p.f)
	    		return this.f-p.f;
 
	    	return this.s-p.s;
	    }
 	}
 // 	class Sort implements Comparator<String> 
	// { 
	//     public int compare(String a, String b) 
	//     { 
	//     	return (a+b).compareTo(b+a);
	//     } 
	// }
 
	String ns() {
        while (st == null || !st.hasMoreElements()) {
 
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }
 
    String nextLine() throws Exception {
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            throw new Exception(e.toString());
        }
        return str;
    }
 
    int nextInt() {
        return Integer.parseInt(ns());
    }
 
    long nextLong() {
        return Long.parseLong(ns());
    }
 
    double nextDouble() {
        return Double.parseDouble(ns());
    }
	
	int upperBound(long a[],long key)
	{
		int l=0,r=a.length-1;
		int i=-1;
 
		while(l<=r)
		{
			int mid=(l+r)/2;
 
			if(a[mid]<key)
				l=mid+1;
 
			else{
				i=mid;	
				r=mid-1;
			}
			
		}
		return i;
	}
	int lowerBound(Pair[] a , long key)
	{
		int l = 0, r = a.length- 1;
		int i = -1;
 	
		while(l<=r)
		{
			int mid=(l+r)/2;
 
			if(a[mid].f<key)
			{
				i=mid;
				l=mid+1;	
			}
 
			else
				r=mid-1;
			
		}
		return i;
	}
 
	long power(long x,long y)
	{
	    long ans=1;
	    
	    while(y!=0)
	    {
	        if(y%2==1) ans=(ans*x)%mod;
	        x=(x*x)%mod;
	        y/=2;
	    }
	    return ans%mod;
	}
	
 
	int mod= 1000000007;
	long gcd(long x ,long y)
	{
		if(y==0)
			return x;
		return gcd(y,x%y);
	}
 
	// ArrayList a[];
	// int vis[],cnt=0;
	// void dfs(int ver)
	// {
	// 	ArrayList<Integer> l=a[ver];
	// 	if(l.size()==1)
	// 		cnt++;
	// 	for(int v:l)
	// 	{
	// 		if(vis[v]==0){
	// 			vis[v]=vis[ver]+1;
	// 			dfs(v);
	// 		}
	// 	}
	// }
 
 	int countSetBits(long n) 
    { 
        int count = 0; 
        while (n > 0) { 
            n &= (n - 1); 
            count++; 
        } 
        return count; 
    }

	void solve() throws IOException{
		int n = nextInt();
		int r = n % 1000;
		if(r == 0)
			out.println(0);
		else
			out.println(1000 - r);
		
	}
 	
    void run() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
		solve();
		out.flush();
 
		out.close();
	}
 
	public static void main(String args[]) throws IOException {
		new Main().run();
	}
  
}


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

ll func(ll b, ll n) {
    if (n < b) return n;
    else return func(b, floor(n/b)) + n%b;
}

int main() {
    ll n, s;
    cin >> n >> s;

    if (n == s) {
        cout << n+1 << endl;
        return 0;
    }
    else if (s > n) {
        cout << -1 << endl;
        return 0;
    }

    int sz = (int)sqrt(n) + 1;
    for (int b=2; b<=sz; ++b) {
        if (s == func(b, n)) {
            cout << b << endl;
            return 0;
        }
    }

    for (int p=sz; p>=1; --p) {
        ll b = (n - s) / p + 1;
        if (p < b and b > sqrt(n) and b <= n and func(b, n) == s) {
            cout << b << endl;
            return 0;
        }
    }

    cout << -1 << endl;
    return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
	ll A, B, C, X, Y;
	ll ans = 0;
	vector<ll> v;

	cin >> A >> B >> C >> X >> Y;

	v.push_back(max(X, Y)*C * 2);
	v.push_back(X*A + Y * B);
	if (X > Y) {
		ll sa = X - Y;
		v.push_back(sa*C * 2 + Y * B + A * X);
		v.push_back(A*sa + 2 * C * Y);

		//cout << "sa" <<  X  << endl;
	}
	else {
		ll sa = Y - X;
		v.push_back(sa*C * 2 + X * A + B * Y);
		v.push_back(B*sa + 2 * C*X);
	}

	/*for (auto it = v.begin();it != v.end();it++) {
		cout << "aa" << *it << endl;
	}*/

	cout << *min_element(v.begin(), v.end()) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail){
  std::cerr << " " << head;
  debug_impl(tail...);
}
#ifdef STOPIT
#define debug(...) 0
#else
#define debug(...)\
do {\
  std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
  debug_impl(__VA_ARGS__);\
  std::cerr << std::noboolalpha;\
} while (false)
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n; std::cin >> n;
  std::vector< std::pair< int, int > > graph(n);
  std::vector< int > ckd(n,false);
  rep(i,0,n) {
    int id, x, y;
    std::cin >> id >> x >> y;
    if (x!=-1) ckd.at(x) = true;
    if (y!=-1) ckd.at(y) = true;
    graph.at(id) = {x,y};
  }
  int root = std::find(all(ckd),false) - ckd.begin();
  std::vector< int > a,b,c;
  auto dfs = [&](auto&& dfs, int i) -> void {
    int x,y; std::tie(x,y) = graph.at(i);
    a.emplace_back(i);
    if (x!=-1) dfs(dfs,x);
    b.emplace_back(i);
    if (y!=-1) dfs(dfs,y);
    c.emplace_back(i);
  };
  dfs(dfs, root);
  std::cout << "Preorder" << std::endl;
  for (int i : a) std::cout << " " << i;
  std::cout << std::endl;
  std::cout << "Inorder" << std::endl;
  for (int i : b) std::cout << " " << i;
  std::cout << std::endl;
  std::cout << "Postorder" << std::endl;
  for (int i : c) std::cout << " " << i;
  std::cout << std::endl;
  return 0;
}



Measured memory_bytes: 3244
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
const int inf = 1000000000; //10^9
const ll MOD = 1e9 + 7;
//加算代入演算子は+=！！！！！
//int 2^31 10^9まで
//intは10桁、long longは18桁、doubleは308桁、long double は4932桁
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a <= c and c <= b) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#include<functional>

using namespace std;

#define PII pair<int,int>

int main(void){
	int n;
	
	while(scanf("%d", &n) && n != 0){
		vector<PII> a;
		vector<PII> b;
		int num,km,KM;
		
		for(int i = 0; i < n; i++){
			scanf("%d%d%d", &num, &km, &KM);
			a.push_back(PII(km+KM,num));
		}
		
		sort(a.begin(),a.end(), greater<PII>() );
		
		printf("%d %d\n",a[0].second,a[0].first);
		
	}
	return 0;
}

Measured memory_bytes: 0
while True:
    H, W = map(int, raw_input().split())
    if H == W == 0: break

    tiles = [list(raw_input()) for _ in range(H)]
    x = y = 0
    while True:
        drct = tiles[y][x]
        tiles[y][x] = "x"
        if drct == ".":
            print x,y
            break
        elif drct == "^":
            y -= 1
        elif drct == "v":
            y += 1
        elif drct == ">":
            x += 1
        elif drct == "<":
            x -= 1
        else:
            print "LOOP"
            break

Measured memory_bytes: 4400
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define IN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long ll;
//////////////////////////////////////////////////////
int main(){
	ll A,B,C,K;
	scanf("%lld %lld %lld %lld",&A,&B,&C,&K);
	if (K % 2 == 0){
		PRINTLLD(A-B);
	}else{
		PRINTLLD(B-A);
	}
	
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
typedef long long llong;
using namespace std;

int n,k;
llong T[100000];

int check(llong P)
{

    int i=0;
    for(int j=0;j<k;j++)
    {   llong sum=0;
        while(sum+T[i]<=P)
        {
            sum+=T[i];
            i++;
            if(i==n) return n;
        }
    }
    return i;
}

int solve()
{
    llong left=0;
    llong right=100000*10000;
    llong mid;
    while(right-left>1)
    {
        mid=(left+right)/2;
        int v=check(mid);
        if(v>=n) right=mid;
        else left=mid;
    }
    return right;
}

int main()
{
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>T[i];
    llong ans=solve();
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3868
s = input()
AKlist = ["AKIHABARA","AKIHABAR","AKIHABRA","AKIHABR","AKIHBARA","AKIHBAR","AKIHBRA","AKIHBR","KIHABARA","KIHABAR","KIHABRA","KIHABR","KIHBARA","KIHBAR","KIHBRA","KIHBR",]
if s in AKlist:
         print("YES")
else:
         print("NO")


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
                
int main() {    
    int x, y, d, r = 0;
    double f = 0.0;
                
    std::cin >> x >> y;
    d = x / y;  
    r = x % y;  
    f = (double)x / (double) y;
                
    printf("%d %d %f\n", d, r, f);
    return 0;   
}

Measured memory_bytes: 1184
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    long long n;
    cin >> n;

    int b = -2;
    int ab = abs(b);

    string res;
    if (n == 0) {
        res = "0";
    }
    while (n != 0) {
        int d = n % b;
        if (d < 0) {
            d += ab;
        }
        res += (char)('0' + d);
        n -= d;
        n /= b;
        // cout << d << " " << n << endl;
    }

    reverse(res.begin(), res.end());

    cout << res << '\n';
    return 0;
}

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

typedef vector< ll > 	vi;
typedef vector< vi > 	vvi;
typedef pair< ll,ll > 	ii;
#define pb 		push_back
#define all(c) 		(c).begin(),(c).end()
#define tr(c,i) 	for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) 	((c).find(x) != (c).end())

#define MOD 	1000000007
#define INF 	(int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))

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

	string s;
	cin>>s;
	ll a=s.size(); ll b=s.size();
	ll i=0,j=b-1;
	ll count=0;
	for(i=0, j=b-1 ; i<=a/2 && j>=a/2 ; i++ , j--)
	{
		if(s[i]!=s[j])
			count++;
	}
	cout<<count;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ll a,b,k,abigger,bbigger,part2=0;
    cin>>a>>b>>k;
   if(a>0){
            if(a>=k){
                a -= k;
                k = 0;
               }
            else
            {
                k -= a;
                a = 0;

            }
   }
   if(k>0 && b>0){
         if(b<=k)
            b = 0;
         else
         {
             b = b - k;
         }
   }

   cout<<a<<" "<<b<<endl;

}


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

#define ll long long 
#define mkp make_pair 
#define fi first 
#define se second

using namespace std ;

int z , e , q , k;

int main ( ) {
	
	int n ;
	cin >> n ;

	int a[n] ;
	for(int i = 0 ; i < n ; i ++ ){
		cin >> a[i] ;
		if ( ( a[i] % 2 == 0 && a[i] % 3 == 0 ) || ( a[i] % 2 == 0 && a[i] % 5 == 0 )){
			z++ ;
		}
		if( a[i] % 2 == 0 ){
			q ++ ;
		}
	}

	if( q == z ){
		cout << "APPROVED" << endl ;
	}
	else{
		cout << "DENIED" << endl ;
	}

}

Measured memory_bytes: 256
N = int(input())
lst = [int(input()) for i in range(5)]
div_lst = []

for i in range(5):
  if N//lst[i] == 0:
    div_lst.append(1)
  elif N % lst[i] == 0:
    div_lst.append(N//lst[i])
  else:
    div_lst.append(N//lst[i]+1)

ans = max(div_lst) + 4
    
#print(div_lst)
print(ans)


Measured memory_bytes: 3060
<?php
/**
 * ABC131
 * A - Security
 */

// $s = trim(fgets(STDIN));
// fscanf(STDIN, "%d %d", $a, $b);
// $n = array_map('intval', explode(' ', trim(fgets(STDIN))));

$s = trim(fgets(STDIN));

for ($i = 1; $i < 4; $i++) {
    if ($s[$i] === $s[$i - 1]) {
        echo 'Bad', PHP_EOL;
        exit;
    }
}

echo 'Good', PHP_EOL;


Measured memory_bytes: 4728
#include <iostream>
using namespace std;
int main() {
	int i;
	cin >> i;
	long long int a[i-1], s,ma,mi;
	s = 0;
	for (int j = 0; j < i ; j++ ) {
		cin >> a[j] ;
		s = s + a[j];
	}
	mi = a[0];
 	ma = a[0];
	for (int j = 0; j < i; j++) {
		if (ma <  a[j] ) {
			ma = a[j];
		}
		else if (mi > a[j] ) {
			mi = a[j];
		}
	}
	cout << mi << " " << ma << " " << s << endl;
}		

Measured memory_bytes: 1244
/**
 * Counting Sort
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_A&lang=ja
 */

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

/**
CountingSort(A, B, k)
    for i = 0 to k
        C[i] = 0

    // C[i] に i の出現数を記録する
    for j = 1 to n
        C[A[j]]++

    // C[i] に i 以下の数の出現数を記録する
    for i = 1 to k
        C[i] = C[i] + C[i-1]

    for j = n downto 1
        B[C[A[j]]] = A[j]
        C[A[j]]--
*/

// 入力の最初の行に、数列 A の長さを表す整数 n が与えられます。
int n;

void printVector(vector<int> &A) {
  for (int i = 0; i < A.size(); i++) {
    if (i > 0) {
      cout << ' ';
    }
    cout << A.at(i);
  }
  cout << endl;
}

void countingSort(vector<int> &A, vector<int> &B, int k) {
  // C[i] に i の出現数を記録する
  vector<int> C(k + 1, 0);
  for (int i = 0; i < n; i++) {
    C.at( A.at(i) )++;
  }

  // C[i] に i 以下の数の出現数を記録する
  for (int i = 1; i <= k; i++) {
    C.at(i) = C.at(i) + C.at(i-1);
  }

  // printVector(C);
  for (int i = n - 1; i >= 0; i--) {
      // 配列の要素の位置に換算するため、1を引く必要がある
      B.at( C.at( A.at(i) ) - 1 ) = A.at(i);
      C.at( A.at(i) )--;
  }
}

int main() {
  // 1行目にカードの枚数 n が与えられます。
  cin >> n;

  // ２行目に、n 個の整数が空白区切りで与えられます。 
  vector<int> A(n);
  int maxA = 0;
  for (int i = 0; i < n; i++) {
    cin >> A.at(i);
    maxA = max(maxA, A.at(i));
  }

  vector<int> B = A;
  countingSort(A, B, maxA);

  // 結果の出力
  printVector(B);
}



Measured memory_bytes: 18444
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;
 
void Main()
{
	int X;
  
  	cin >> X;
  
  int A;
  
  A = (X / 500) * 1000 + (X % 500) / 5 * 5;
  
  printf("%d", A);
	
	
}
 
int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 256
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

case class Station(c: Int, s: Int, f: Int)

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val n = in.readLine().toInt
    val stations = Array.fill(n - 1) {
      in.readLine().split("\\s+").map(_.toInt) match {
        case Array(c, s, f) => Station(c, s, f)
      }
    }

    for(i <- 0 until n) {
      var t = 0
      for(j <- i until (n - 1)) {
        val station = stations(j)
        val d = if (station.s >= t) {
          station.s
        } else {
          station.s + station.f * Math.ceil(1.0 * (t - station.s) / station.f).toInt
        }
        t = d + station.c
      }
      out.println(t)
    }

    out.flush()
  }
}


Measured memory_bytes: 27172
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
short ctos(char a) {
	return (int)(a - '0');
}
#define int long long
const long long Inf = 4523372036854775807;
const int inf = 15000000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
int n;
int a[200001];
signed main() {
	cin >> n;
	bool l = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (a[i] - a[i - 1] > 1) l = 1;
	}
	if (l || a[1]) {
		cout << -1 << endl;
		return 0;
	}
	int ans = 0;
	for (int i = n; i > 0; ) {
		int j = i;
		while (j > 1 && a[j] == a[j - 1] + 1) {
			j--;
		}
		ans += (i - j) + a[j];
		i = j - 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 2424
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

ll gcd(ll x,ll y){
  return y==0?x:gcd(y,x%y);
}

int main(){
  int t;
  cin>>t;

  for(int i=0;i<t;i++){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a<b||d<b) cout<<"No"<<endl;
    else{
      ll x=(a-c-1)/b+1;
      if(a-b*x<0) cout<<"No"<<endl;
      else if(b==d) cout<<"Yes"<<endl;
      else{
        ll y=gcd(b,d);
        ll z=y-(c-(a-b*x))%y;
        ll next=z+c;
        if(next-b<0) cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
      }
    }


  }

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
    import static java.lang.System.*;

public class Main {

  public static void main(String[] args){
            Scanner sc = new Scanner(in);
            String s=sc.next();
            s=s.replace("9","-");
            s=s.replace("1","9");
            s=s.replace("-","1");
            out.println(s);
        }
    }

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

int main(){

  int n,x;
  cin >>n>>x;
  int l[n];
  for(int i=0; i<n; i++) cin >> l[i];
  
  int sum=0,count=1;
  
  for(int i=0; i<n; i++){
    sum+=l[i];
    if(sum>x) break;
  	count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll P[N];
    ll ans = 0;
    ll minnum = inf;
    REP(i, 0, N) {
        cin >> P[i];
        if (P[i] < minnum) {
            ans++;
            minnum = P[i];
        }
    }
    cout << ans << endl;
}


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

int main()
{
  int A,B,M;  
  cin >> A >> B >> M;
  vector<int> a(A);
  vector<int> b(B);
  vector<int> x(M);
  vector<int> y(M);
  vector<int> c(M);
  int Amin=100000;
  int Bmin=100000;
  int saishou=100000;
  
  for(int i=0;i<A;i++){
   cin >> a.at(i);
  }
  for(int i=0;i<B;i++){
   cin >> b.at(i);
  }
  for(int i=0;i<M;i++){
   cin >> x.at(i);
   cin >> y.at(i);
   cin >> c.at(i);
  }
//----------------------
  for(int i=0;i<A;i++){
      Amin = min(Amin,a.at(i));
    }  

   for(int j=0;j<B;j++){
      Bmin = min(Bmin,b.at(j));
    } 

//------------------------  
  saishou = Amin + Bmin;    
  for(int i=0;i<M;i++){
    int num;
    num = a.at(x.at(i)-1) + b.at(y.at(i)-1) - c.at(i);
    saishou = min(saishou,num);
}  
  cout << saishou << endl;
}



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

int main() {
   int d,g;
   cin >> d >> g;
   vector<int> p(d);
   vector<int> c(d);
   for(int i=0;i<d;i++){
       cin >> p[i] >> c[i];
   }
   int nin = 1e9;
    //----- bit 全探索 ------
    //ここで2^d-1個のbit列を列挙
    for (int bit = 0; bit < (1 << d); ++bit) {
        int score=0;
        int solve=0;
        //配列のコピー
        vector<int> copy_p = p;
        //ここで、列の各位が1かをみる
        for (int i = 0; i < d; ++i) {
            if (bit & (1 << i)) {
            // 1のところのボーナスポイントを取る
                copy_p[i] = 0;
                solve+=p[i];
                score+=p[i]*100*(i+1);
                score+=c[i];
            }
        }
        if(score>=g){
            nin = min(nin,solve);
        }
        else{
            for(int i=d-1;i>=0;i--){
                // 既に選んでいればbreak;
                while(copy_p[i]>0){
                    if(score>=g) {
                        nin = min(nin,solve);
                        break;
                    }
                    solve++;
                    score+=(i+1)*100;
                    copy_p[i]--;
                    if(copy_p[i]==0) score+=c[i];
                }
                if(score>=g) break;
            }
        }
        
    }
    cout << nin << endl;
}

Measured memory_bytes: 256
# ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
 
BUFSIZE = 8192
 
 
class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
 
# ------------------- fast io --------------------
from math import gcd, ceil
 
def pre(s):
    n = len(s)
    pi = [0] * n
    for i in range(1, n):
        j = pi[i - 1]
        while j and s[i] != s[j]:
            j = pi[j - 1]
        if s[i] == s[j]:
            j += 1
        pi[i] = j
    return pi
 
 
def prod(a):
    ans = 1
    for each in a:
        ans = (ans * each)
    return ans
 
def lcm(a, b): return a * b // gcd(a, b)
 
 
def binary(x, length=16):
    y = bin(x)[2:]
    return y if len(y) >= length else "0" * (length - len(y)) + y

K = int(input())
s = input()

print(s if len(s) <= K else s[:K]+'...')


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

int main() {
    int n;
    cin>>n;

    vector<int> f(n,0);
    rep(i,1,100){
        rep(j,1,100){
            rep(k,1,100){
                int v=i*i+j*j+k*k+i*j+j*k+k*i;
                if(v<=n){
                    f[v-1]++;
                }
            }
        }
    }

    rep(i,0,n){
        cout<<f[i]<<endl;
    }
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define Khela_Sesh ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
//const int sz=1e5+100;
int main()
{
    Khela_Sesh
    int i,j,k,q,p,x,y,sum,ct,ct1,m,l,r,len,x1,y1,mn,t,mx,W,n;
    char ch;
    double d;
    string str1,str2;
    bool bl,bl1;
    while(cin>>n>>W)
    {
        ll ara[W+2][n+2];
        int w[n+2],val[n+2];
        for(i=1;i<=n;i++)
        {
            cin>>w[i]>>val[i];
        }

        for(i=0;i<=W;i++){
            for(j=0;j<=n;j++){
                if(i==0 || j==0) ara[i][j]=0ll;
                else if(i-w[j]>=0) ara[i][j]=max(ara[i][j-1],val[j]+ara[i-w[j]][j-1]);
                else ara[i][j]=ara[i][j-1];
            }
        }
        pf("%lld\n",ara[W][n]);
    }

}



Measured memory_bytes: 80000
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
    long answer = 0;

    answer += nums[0];
    for(int i = 1; i < n; i++)
    {
      if(nums[i] > nums[i-1])
      {
        answer += nums[i] - nums[i-1];
      }
    }
    
    
		Console.WriteLine(answer);
	}
}

Measured memory_bytes: 13140
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N, Q = map(int, input().split())
D = N.bit_length()

edge = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b, c, d = map(int, input().split())
    a -= 1
    b -= 1
    edge[a].append((b, c, d))
    edge[b].append((a, c, d))
query = tuple(tuple(map(int, input().split())) for _ in range(Q))

par = [[-1] * N for _ in range(D)]
dep = [0] * N
dist = [0] * N
node = [0]
while node:
    s = node.pop()
    for t, _, d in edge[s]:
        if par[0][s] == t:
            continue
        par[0][t] = s
        dep[t] = dep[s] + 1
        dist[t] = dist[s] + d
        node.append(t)

for d in range(D - 1):
    for i in range(N):
        par[d + 1][i] = par[d][par[d][i]]


def LCA(x, y):
    if dep[x] < dep[y]:
        x, y = y, x
    h = dep[x] - dep[y]
    for d in reversed(range(D)):
        if h >= 1 << d:
            x = par[d][x]
            h -= 1 << d
    if x == y:
        return x
    for d in reversed(range(D)):
        if par[d][x] != par[d][y]:
            x = par[d][x]
            y = par[d][y]
    return par[0][x]


memo = [[] for _ in range(N)]
ans = [0] * Q

for i, (x, y, u, v) in enumerate(query):
    u -= 1
    v -= 1
    c = LCA(u, v)
    ans[i] = dist[u] + dist[v] - 2 * dist[c]
    memo[u].append((x, y, i))
    memo[v].append((x, y, i))
    memo[c].append((x, y, ~i))


c_len = [0] * (N + 1)
c_cnt = [0] * (N + 1)


def dfs(s, p=-1):
    for c, val, i in memo[s]:
        if i >= 0:
            ans[i] -= c_len[c]
            ans[i] += c_cnt[c] * val
        else:
            ans[~i] += c_len[c] * 2
            ans[~i] -= c_cnt[c] * val * 2
    for t, c, d in edge[s]:
        if t == p:
            continue
        c_len[c] += d
        c_cnt[c] += 1
        dfs(t, s)
        c_len[c] -= d
        c_cnt[c] -= 1


dfs(0)
print(*ans, sep="\n")

Measured memory_bytes: 209920
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
 
int main(){
  int N,K;
  cin >> N >> K;
  vector<int> vec(N,0);
  for(int i=0;i<N;i++){
    int a;
    cin >> a;
    vec.at(a-1)++;
  }
  sort(vec.begin(),vec.end(),greater<int>());
  int count=0;
  for(int i=0;i<K;i++){
    count+=vec.at(i);
  }
  cout<< N-count <<endl;
  return 0;
}

Measured memory_bytes: 1024