akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC push_options
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include <xmmintrin.h>
#include <immintrin.h>
using namespace::std;
__attribute__((constructor))void init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// typedef mp::number<mp::cpp_dec_float<0>> cdouble;
// typedef mp::cpp_int cint;
template<typename T>using pbds=__gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T>using pbds_map=__gnu_pbds::tree<T,T,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T,typename E>using hash_map=__gnu_pbds::gp_hash_table<T,E>;
template<typename T>using pqueue =__gnu_pbds::priority_queue<T, greater<T>,__gnu_pbds::rc_binomial_heap_tag>;
typedef long long lint;
#define INF (1LL<<60)
#define IINF (1<<30)
#define EPS (1e-10)
#define endl ('\n')
//#define MOD 1000000007LL
#define MOD 998244353LL
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
template<typename T>inline void numout(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i<INF/2?i:"INF";f=1;}cout<<endl;}
template<typename T>inline void numout2(T t){for(auto i:t)numout(i);}
template<typename T>inline void output(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}
template<typename T>inline void output2(T t){for(auto i:t)output(i);}
template<typename T>inline void _output(T t){bool f=0;for(lint i=0;i<t.size();i++){cout<<f?"":" "<<t[i];f=1;}cout<<endl;}
template<typename T>inline void _output2(T t){for(lint i=0;i<t.size();i++)output(t[i]);}
#define rep(i,n) for(lint i=0;i<lint(n);++i)
#define repi(i,a,b) for(lint i=lint(a);i<(lint)(b);++i)
#define rrep(i,n) for(lint i=lint(n)-1;i>=0;--i)
#define rrepi(i,a,b) for(lint i=lint(b)-1;i>=lint(a);--i)
#define irep(i) for(lint i=0;;++i)
#define all(n) begin(n),end(n)
#define dist(a,b,c,d) sqrt(pow(a-c,2)+pow(b-d,2))
inline lint gcd(lint A,lint B){return B?gcd(B,A%B):A;}
inline lint lcm(lint A,lint B){return A/gcd(A,B)*B;}
// inline cint cgcd(cint A,cint B){return B?cgcd(B,A%B):A;}
// inline cint clcm(cint A,cint B){return A/cgcd(A,B)*B;}
inline bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
inline bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
const vector<lint> dx={1,0,-1,0,1,1,-1,-1};
const vector<lint> dy={0,1,0,-1,1,-1,1,-1};
#define SUM(v) accumulate(all(v),0LL)
auto call=[](auto f,auto... args){return f(f,args...);};

int main(){
    lint n,k;
    cin>>n>>k;
    cout<<min(n%k,k-n%k)<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>
#include<cmath>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int n, ans = 0;
    cin >> n;
    vector<int> w(n);
    for(int i = 0; i < n; i++){
        cin >> w[i];
    }
    w.push_back(0);
    partial_sum(begin(w), end(w), begin(w));
    ans = INF;
    for(int i = 0; i < n; i++){
        ans = min(ans, abs(w[i] - (w[n] - w[i])));
    }
    cout << ans << endl;
    return 0;
}


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

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int[] NumData = new int[3];
    int min;

    for(int i = 0; i < 3 ; i++){
      NumData[i] = scan.nextInt();
    }
    Arrays.sort(NumData);

    System.out.println(NumData[2] * 10 + NumData[1] + NumData[0]);

  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

const int MAX = 5e5;

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(ll n, ll k){
  if(n >= MAX){
    ll tmp = 1;
    rep(i,k){
      tmp *= (n-i);
      tmp %= MOD;
    }
    return tmp*finv[k]%MOD;
  }

  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll POW(ll x, ll n){
  ll ret = 1;
  while(0 < n){
    if(n%2 == 0){
      x = x*x%MOD;
      n = n >> 1;
    }
    else{
      ret = ret*x%MOD;
      n--;
    }
  }
  return ret;
}

ll dfs(string N, int k){
  int n = N.size();
  if(k == 0){
    return 1;
  }
  if(n == 0){
    return 0;
  }
  ll ret = 0;
  ll num = N[0] - '0';
  N.erase(N.begin());
  if(num == 0){
    ret += dfs(N,k);
  }
  else{
    ret += dfs(N,k-1) + COM(n-1, k)*POW(9LL, k) + (num-1)*COM(n-1, k-1)*POW(9LL, k-1);
  }

  return ret;
}

int main(){
  string N; int k; cin >> N >> k;
  COMinit();
  cout << dfs(N, k) << endl;
}


Measured memory_bytes: 11904
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <cmath>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<long long> a(n),b(n),c(n);
	long long ans = 0;
	REP(i,n){
		cin >> a[i] >> b[i];
		c[i] = (b[i] - a[i] % b[i]);
	}
	for(int i = n-1;i>=0;i--){
		if((ans + a[i])% b[i] != 0 ){
			ans = ceil((double)(ans-c[i])/b[i]) * b[i] + c[i];
		}
	}
	cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  std::string S;
  std::cin >> S;
  const i64 N = S.size();

  if (N % 2 == 1) goto FAILED;
  for (i64 i = 0; i < N; i += 2) {
    if (S[i] != 'h' || S[i + 1] != 'i') goto FAILED;
  }

  std::cout << "Yes" << std::endl;
  return 0;

FAILED:
  std::cout << "No" << std::endl;
  return 0;
}

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

MOD = 998244353
n, k = map(int, input().split())
s = list()
for i in range(k):
    s.append(tuple(map(int, input().split())))

dp = [0] + [0] * n
diff = [0] + [0] * n
dp[1] = 1
diff[2] = -1
for i in range(1, n):
    for j, k in s:
        if i + j > n:
            continue
        diff[i + j] += dp[i]
        if i + k + 1 > n:
            continue
        diff[i + k + 1] -= dp[i]
    #dp[i] = (dp[i - 1] + diff[i]) % MOD
    dp[i + 1] = (dp[i] + diff[i + 1]) % MOD
print(dp[n])


Measured memory_bytes: 79340
import math
from functools import reduce
import itertools
#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))





N=input1()
P=input_array()
Q=input_array()

nums=list(itertools.permutations(range(1,N+1)))


a=nums.index(tuple(P))
b=nums.index(tuple(Q))
print(abs(a-b))

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

#define mod 1000000007
#define all(x) (x).begin(), (x).end()

const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}

int main(){
    ll n, m;
    cin >> n >> m;
    if(n == m) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int M = int.Parse(str[1]);
		string s = Console.ReadLine();
		var list = new List<int>();
		for(var i=0;i<N+1;i++){
			if(s.Substring(i,1)=="0"){
				list.Add(i);
			}
		}
		int an = N;
		var ans = new List<int>();
		bool flag = true;
		while(an>0){
			int an2 = an-M;
			int min = 0;
			int max = list.Count-1;
			while(min<max){
				int m = (min+max)/2;
				if(list[m]<an2){
					min = m+1;
				} else {
					max = m;
				}
			}
			int an3 = list[min];
			if(an-an3<=0){
				flag = false;
				break;
			}
			ans.Add(an-an3);
          	an = an3;
		}
		if(flag){
			Console.Write(ans[ans.Count-1]);
			for(var i=ans.Count-2;i>=0;i--){
				Console.Write(" "+ans[i]);
			}
		} else {
			Console.WriteLine("-1");
		}
	}
}

Measured memory_bytes: 17752
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>
using namespace std;
using ll = long long;

int main(){
  int N;
  cin >> N;
  cout << (int)(floor(sqrt(N))*floor(sqrt(N))) << endl;
}

Measured memory_bytes: 3600
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<map>
#include<set>

using namespace std;

inline int read()
{
	int ans=0,f=1;
	char c=getchar();
	while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
	return ans*f;
}

int x,y,a,b;

int main()
{
	x=read();y=read();
	a=(y-2*x)/2;
	b=x-a;
	//printf("%d %d\n",a,b);
	if(a<0||b<0) printf("No\n");
	else
	{
		if(a+b==x&&2*b+4*a==y)
			printf("Yes\n");
		else
			printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 3024
#include <stdio.h>

int main(void){
  
  int H;
  int W;
  int h;
  int w;
  
  scanf("%d %d",&H,&W);
  scanf("%d %d",&h,&w);
  
  int K = H - h;
  int J = W - w;
  
  printf("%d",K * J);
  
  return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int N;

int main() {
    cin >> N;

    string S;
    cin >> S;

    int W = 0;
    vi nW(N + 1);
    for (int i = 0; i < N; i++) {
        if (S[i] == '.')
            W++;
        nW[i + 1] = W;
    }

    int ans = INF;
    int B = N - W;
    int rW, lB;
    for (int i = 0; i <= N; i++) {
        rW = W - nW[i];
        lB = i - nW[i];
        ans = min(ans, rW + lB);
    }

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


Measured memory_bytes: 1412
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;
ll kai[200001], inv[200001];
int n, k;
ll mod_pow(ll x, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * x % mod;
    }
    x = x * x % mod;
    n /= 2;
  }
  return res;
}
void init() {
  kai[0] = 1LL;
  for (ll i = 1LL; i <= 200000; i++) {
    kai[i] = kai[i - 1] * i;
    kai[i] %= MOD;
  }
  inv[200000] = mod_pow(kai[200000], MOD - 2LL, MOD);
  for (ll i = 199999; i >= 0; i--) {
    inv[i] = inv[i + 1] * (i + 1);
    inv[i] %= MOD;
  }
}

ll comb(ll r, ll c) {
  ll res;
  res = kai[r];
  res *= inv[c];
  res %= MOD;
  res *= inv[r - c];
  res %= MOD;
  return res;
}
int main() {
  int x[100000];
  ll y[100010], sum[100001] = {};
  ll ans = 0;
  scanf("%d", &n);
  init();
  for (int i = 0; i < n; i++) {
    scanf("%d", &x[i]);
  }
  for (ll i = 1; i < n; i++) {
    y[i] = mod_pow(i, MOD - 2LL, MOD);
    sum[i] = sum[i - 1] + y[i];
    sum[i] %= MOD;
  }
  for (int i = 1; i <= n; i++) {
    ll a = (x[i] - x[i - 1]);
    a %= MOD;
    a *= sum[i];
    a %= MOD;
    ans += a;
    ans %= MOD;
  }
  ans *= kai[n - 1];
  ans %= MOD;
  printf("%lld\n", ans);
}

Measured memory_bytes: 4480
function Main(input) {
    const lines = input.split("\n");

    const [A, B, M] = lines.shift().split(' ').map(Number);
    const aList = lines.shift().split(' ').map(Number);
    const bList = lines.shift().split(' ').map(Number);

    const minA = aList.reduce((acc, current) => Math.min(acc, current));
    const minB = bList.reduce((acc, current) => Math.min(acc, current));

    let minCost = minA + minB;

    for (let i = 0; i < M; i++) {
        const [x, y, c] = lines[i].split(' ').map(Number);
        minCost = Math.min(minCost, aList[x-1] + bList[y-1] - c);
    }

    console.log(minCost);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 53040
#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<string>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#define UP(i,l,h) for(int i=l;i<h;i++)
#define DOWN(i,h,l) for(int i=h-1;i>=l;i--)
#define W(a) while(a)
#define MEM(a,b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f3f3f3f3f
#define LL long long
#define MAXN 100010
#define SIZE 95
#define EPS 1e-10
#define MOD 1000000007

using namespace std;
char ch[150];

int main() {
    scanf("%s",ch);
    int len=strlen(ch);
    printf("%c%d%c\n",ch[0],len-2,ch[len-1]);
}


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

#define ll long long
#define p_q priority_queue
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

int main(){
    vector<ll> a(5);
    ll m,min=20,sum=0;
    for(int i=0;i<5;i++){
        cin>>a.at(i);
        m = a.at(i)%10;
        if(m>0){
            a.at(i) += 10-m;
        }
        if(min>m&&m!=0){
            min = m;
        }
        sum += a.at(i);
    }

    if(min==20){
        min = 10;
    }

    cout<<sum-(10-min)<<endl;

}



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

int main(){
	set<int> A;
	for(int i=0;i<3;i++){
		int a;
		cin >> a;
		A.insert(a);
	}
	if(A.size()==2){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

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

int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
    cin>>arr[i];
    
    
    ll dp[n+1][n+1];
    memset(dp,0,sizeof dp);
    
    for(int i = n-1;i>=0;i--){
        for(int j = i;j<n;j++){
            if( i == j)
            dp[i][j] = arr[i];
            else{
                dp[i][j] = max(arr[i] - dp[i+1][j], arr[j] - dp[i][j-1]);
                
            }
        }
    }
    cout<<dp[0][n-1];
}

Measured memory_bytes: 70656
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
      ArrayList<Integer> one = nextIntArray();
      int H = one.get(0) - 1;
      int W = one.get(1) - 1;
      myout(H * W);
	}
	//Method addition frame start



	//Method addition frame end
}


Measured memory_bytes: 32988
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

vector<int> prime(int N) {
    vector<int> pri;
    vector<bool> is_prime;
    is_prime    = vector<bool>(N + 1, true);
    is_prime[0] = is_prime[1] = false;
    FOR(i, 2, N + 1) {
        if (is_prime[i]) {
            pri.push_back(i);
            FORSTEP(j, 2 * i, N + 1, i) is_prime[j] = false;
        }
    }
    return pri;
}

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

    int N;
    cin >> N;

    auto pri = prime(55555);

    int cnt = 0;
    REP(i, pri.size()) {
        if (cnt == N)
            break;
        if (pri[i] % 5 == 1) {
            cout << pri[i] << " ";
            cnt++;
        }
    }
    cout << endl;

    return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<long>a(n);
	string ans;
	int count = 0, count4 = 0;
	for (int i = 0; i < n; ++i)cin >> a[i];
	for (int i = 0; i < n; ++i) {
		if (a[i] % 2 != 0)++count;
		if (a[i] % 4 == 0)++count4;
	}
	if (n % 2 == 0) {
		if (count <= count4)ans = "Yes";
		else ans = "No";
	}
	else {
		if (count <= count4 + 1)ans = "Yes";
		else ans = "No";
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
package main

import (
	"fmt"
	"math"
	"sort"
)

// solve N個からM個からの選ぶ組み合わせに対して和を取り最大和を返す
func solve(N int, M int, arr [][]int) int {
	var maxval int
	maxval = math.MinInt64
	for ix := -1; ix <= 1; ix += 2 {
		for iy := -1; iy <= 1; iy += 2 {
			for iz := -1; iz <= 1; iz += 2 {
				converted := make([]int, N)
				for i := 0; i < N; i++ {
					a := arr[i]
					converted[i] = a[0]*int(ix) + a[1]*int(iy) + a[2]*int(iz)
				}
				// sort(converted, func(i, j int) bool { return converted[i] > converted[j] })
				sort.Ints(converted)
				var val int
				val = 0
				for i := 0; i < M; i++ {
					val += converted[N-1-i]
				}
				// fmt.Println(converted[0:M])
				// fmt.Println(val)
				if maxval < val {
					maxval = val
				}
			}
		}
	}
	return maxval
}

func main() {
	var (
		N int
		M int
	)

	fmt.Scan(&N)
	fmt.Scan(&M)
	arr := make([][]int, N)
	for i := 0; i < int(N); i++ {
		arr[i] = make([]int, 3)
		fmt.Scan(&arr[i][0])
		fmt.Scan(&arr[i][1])
		fmt.Scan(&arr[i][2])
	}
	res := solve(N, M, arr)
	fmt.Println(res)
}


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

int main(){

	int n, d, x, a[100], max=0;
	cin >> n >> d >> x;
	for (int i = 0; i < n; i++) cin >> a[i];

	for (int i = 0; i < n; i++){
		
		for (int j = 0;j < 101; j++){
			int p = 1;
			p += a[i] * j;
			if (p > d) continue;
			max++;
		}
	}

	cout << x + max << endl;

	
	return 0;
}

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

#define N 100000
#define MAX 1000000000000000000

int main (void)
{
    unsigned long long n, a[N], ans = 1;
    unsigned long long i, j = 0, k = 0;
    unsigned long long ans_arry[N];

    scanf("%llu", &n);

    for (i = 0; i < n; i++) {
        scanf("%llu", &(a[i]));

        if (a[i] == 0) {
            puts("0");
            return 0;
        }
    }

    for (i = 0; i < n; i++) {
        if (ans > MAX / a[i]) {
            puts("-1");
            return 0;
        }

        ans *= a[i];
    }

    /*
    for (i = 0; i < n; i++) {
        if (a[i] > 1000000000000000000) {
            puts("-1");
        }

        if (a[i] > 1000000000) {
            ans_arry[j] = ans;
            j++;

            ans_arry[j] = a[i];
            j++;
            ans = 1;
        } else {
            ans = ans * a[i];
        }

        if (ans > 1000000000000000000) {
            puts("-1");
            return 0;
        }

        if (ans > 1000000000) {
            ans_arry[j] = ans;
            j++;
            ans = 1;
        }
    }

    if (ans != 1) {
        ans_arry[j] = ans;
        j++;
    }

    for (i = 0; i < j; i++) {
        if (ans_arry[i] > 1000000000) {
            k++;
        }

        if (k >= 2) {
            puts("-1");
            return 0;
        }
    }

    ans = 1;
    for (i = 0; i < j; i++) {
        ans *= ans_arry[i];

        if (ans > 1000000000000000000) {
            puts("-1");
            return 0;
        }
    }
    */

    printf("%llu", ans);

    return 0;
}


Measured memory_bytes: 2516
N = int(input())
A = list(map(int, input().split()))

money = 1000
stok = 0

for i in range(N-1):
  if A[i] < A[i+1]:
    stok += money//A[i]
    money -= (money//A[i])*A[i]
  elif A[i] > A[i+1]:
    money += stok * A[i]
    stok = 0
ans = money + stok*A[N-1]
print(ans)

Measured memory_bytes: 9080
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		
		int price = fs.nextInt();
		int mod = price % 1000;
		if(mod == 0) {
			System.out.println(0);
		}else {
			System.out.println(1000- mod);
		}
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


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

typedef long long ll;
typedef pair<ll, ll> P;


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


int main() {
    ll n; cin >> n;
    bool ok = true;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    ll ans = 1, num = 0; // 答え、列の数
    map<ll, ll> m; // 最後尾の数とその数
    
    rep(i, n) {
        if(a[i] == 0) {
            num++;
            if(m.count(0)) {
                m[0]++;
                if(m[0] > 3) {
                    ok = false;
                    break;
                }
            }
            else m[0] = 1;
        }
        else {
            ans = mtime(ans, m[a[i]-1], 1);
            m[a[i]-1]--;
            if(m[a[i]-1] < 0) {
                ok = false;
                break;
            }
            if(m.count(a[i])) {
                m[a[i]]++;
                if(m[a[i]]>3) {
                    ok = false;
                    break;
                }
            }
            else m[a[i]] = 1;
        }
    }

    if(num >= 4) {
        ok = false;
    }
    else if(num >= 2) {
        ans = mtime(ans, 6, 1);
    }
    else {
        ans = mtime(ans, 3, 1);
    }
    if(ok) cout << ans << endl;
    else cout << 0 << endl;

    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

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

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


Measured memory_bytes: 10316
#include<stdio.h>
#include<vector>
using namespace std;

int main(){
    int N;
    scanf("%d",&N);
    vector<int> A(N);
    for(int i=0;i<N;i++){
        scanf("%d",&A.at(i));
    }

    bool flg = true;
    int i = N-2;

    while(i >= 0){
        if(A.at(i)-A.at(i+1) == 1){
            A.at(i) = A.at(i) -1;
        }
        else if(A.at(i)-A.at(i+1) >= 2 ){
            flg = false;
            break;
        }
        i--;
    }

    if(flg == true){
        printf("%s\n","Yes");
    }else{
        printf("%s\n","No");
    }

    ///for(int i=0;i<N;i++){
        ///printf("%d ",A.at(i));
    ///}

    return 0;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
   void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int N;
vec<vec<int>> G;

void dfs(int pos, int par,int cost, vec<int> &dist) {
   dist[pos] = cost;
   for (int to : G[pos]) {
      if (to != par) {
         dfs(to, pos,cost+1, dist);
      }
   }
}

int main() {
   cin >> N;
   G = vec<vec<int>>(N);
   rep (i, N-1) {
      int a, b;
      cin >> a >> b;
      a--, b--;
      G[a].push_back(b);
      G[b].push_back(a);
   }
   vec<int> dist1(N), dist2(N);
   dfs(0, -1, 0, dist1); // 黒のフェネック
   dfs(N-1, -1, 0, dist2); // 白のすぬけ

   int black = 0, white = 0;
   rep (i, N) {
      // 距離が短いほうが塗りつぶす
      // 距離が同じ場合は、黒が塗りつぶす
      if (dist1[i] <= dist2[i]) {
         black++;
      } else {
         white++;
      }
   }

   // 黒と白が同じ場合、黒の手番で手が打てなくなるので、黒が負ける
   if (black > white) {
      puts("Fennec");
   } else {
      puts("Snuke");
   }

   return 0;
}

Measured memory_bytes: 12800
fun main(args: Array<String>) {
    val (N, M) = listOfLong()
    var ans = 1L
    var a = 1L
    while (a * a <= M) {
        if (M % a == 0L) {
            val b = M / a
            if (a * N <= M) ans = Math.max(ans, a)
            if (b * N <= M) ans = Math.max(ans, b)
        }
        a += 1
    }
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfLong() = listOfString().map { java.lang.Long.parseLong(it) }


Measured memory_bytes: 37924
import java.util.*;

public class Main{
  public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		if(N == M) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 35756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
// long double EPS=1E-8;
////////////////////////////////////////

bool comp(l_l a,l_l b){
    if(a.first<b.first)return true;
    else if(a.first==b.first&&a.second>b.second)return true;
    else return false;
}

bool comp2(l_l a,l_l b){
    if(a.second>b.second)return true;
    else return false;
}


int main() {
    ll n,k;cin>>n>>k;
    vector<l_l> a;
    rep(i,0,n-1){
        l_l aa;
        cin>>aa.first>>aa.second;
        a.pb(aa);
    }
    sort(a.begin(),a.end(),comp);
    vector<l_l>b,c;
    rep(i,0,n-1){
        if(i==0){
            b.pb(a[i]);
        }else if(a[i-1].first==a[i].first){
            c.pb(a[i]);
        }else{
            b.pb(a[i]);
        }
    }
    sort(b.begin(),b.end(),comp2);sort(c.begin(),c.end(),comp2);
    ll bs=b.size(),cs=c.size();
   // rep(i,0,bs-1)cout<<b[i].first<<" "<<b[i].second<<endl;cout<<endl;
   // rep(i,0,cs-1)cout<<c[i].first<<" "<<c[i].second<<endl;cout<<endl;
    ll x[bs],y[cs];
    if(b.size()){
        x[0]=b[0].second;
        rep(i,1,bs-1)x[i]=x[i-1]+b[i].second;
    }
    if(c.size()){
        y[0]=c[0].second;
        rep(i,1,cs-1)y[i]=y[i-1]+c[i].second;
    }
    ll ans=0;
  //  rep(i,0,bs-1)cout<<x[i]<<" ";cout<<endl;
  //  rep(i,0,cs-1)cout<<y[i]<<" ";cout<<endl;
    for(ll i=1;i<=bs&&i<=k;i++){
        if(i+cs<k)continue;
        ll sum=i*i;
        if(k-i-1<0)sum+=x[i-1];
        else sum+=x[i-1]+y[k-i-1];
    //cout<<i<<" "<<sum<<endl;
        Max(&ans,sum);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5488
import java.util.Scanner;

public class Main {

	static final int a0 = 1;
	static final int[] days = {0,31,28,31,30,31,30,31,31,30,31,30,31};

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.println(count(sc.nextLong(),sc.nextInt(),sc.nextInt(),sc.nextLong(),sc.nextInt(),sc.nextInt()));
	}

	public static long count(long y1,int m1,int d1,long y2,int m2,int d2) {
		long count400 = count(1,1,1,a0,400,12,31);
		d1--;
		if (d1 <= 0) {
			m1--;
			if(m1 <= 0) {
				y1--;
				m1 = 12;
			}
			d1 = days[m1];
		}
		long yy1 = (y1 - 1) / 400;
		long c1 = count400 * yy1 + count(yy1 * 400 + 1, 1, 1, a0, y1, m1, d1);
		long yy2 = (y2 - 1) / 400;
		long c2 = count400 * yy2 + count(yy2 * 400 + 1, 1, 1, a0, y2, m2, d2);
		return c2 - c1;
	}

	public static long count(long y1,int m1,int d1,int a,long y2,int m2,int d2) {
		long count = 0;
		while(true) {
			if (y1 > y2 || y1 == y2 && m1 > m2 || y1 == y2 && m1 == m2 && d1 > d2) {
				break;
			}
			if (d1 == 13 && a == 5) {
				count++;
			}
//			if (y1 == 2015 && m1 == 3 && d1 == 13) {
//				System.out.println(a);
//			}

			d1++;
			if (d1 > days[m1] + (m1 == 2 && isUruu(y1) ? 1 : 0)) {
				d1 = 1;
				m1++;
			}
			if (m1 > 12) {
				m1 = 1;
				y1++;
			}
			a = (a + 1) % 7;
		}
		return count;
	}

	public static boolean isUruu(long y) {
		if (y % 400 == 0) {
			return true;
		}else if(y % 100 == 0) {
			return false;
		}else{
			return y % 4 == 0;
		}
	}

}


Measured memory_bytes: 19304
#include <iostream>
using namespace std;
typedef long long  ll;

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

int main()
{
	ll N, M; cin >> N >> M;
	ll c[51][51] = {};
	rep(i, 0, M) {
		ll a, b;
		cin >> a >> b;
		c[a][b]++;
		c[b][a]++;
	}
	rep(i, 1, N + 1) {
		ll cnt = 0;
		rep(j, 1, N + 1) {
			cnt += c[i][j];
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll //9223372036854775807
#define pi acos(-1.0)
#define ms(a,b) memset(a,b,sizeof(a))
#define nl "\n"
#define FAST_IO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
typedef long long ll;
const int mod = 998244353;
ll qpow(ll x, ll y){ll s=1;while(y){if(y&1)s=s*x%mod;x=x*x%mod;y>>=1;}return s;}
//ll qpow(ll a, ll b){ll s=1;while(b>0){if(b%2==1)s=s*a;a=a*a;b=b>>1;}return s;
inline ll read(){ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();return x*f;}
ll inve(ll x){return x==1?1:(mod-mod/x)*inve(mod%x)%mod;}

const int N = 1e6+5;

int n;
ll a[N], b[N], c[N];

int main()
{
    ll s = 0;
    scanf("%d", &n);
    for(int i=1;i<=n;i++) a[i] = read();
    for(int i=1;i<=n;i++)
    {
        b[i] = read(); c[i] = b[i]-a[i];
        s += c[i];
    }
    if(s>0) return puts("-1"),0;
    sort(c+1,c+1+n);
    ll t = 0;
    int l = 1, ans = 0;
    for(int r=n; c[r]>0; r--)
    {
        while(l<r && t<c[r])
            t -= c[l++], ans++;
        t -= c[r];
        ans++;
    }
    cout<<ans<<nl;
    return 0;
}


Measured memory_bytes: 9344
#include<bits/stdc++.h>
using namespace std;
#define I inline int
#define V inline void
#define ll long long int
#define isnum(ch) ('0'<=ch&&ch<='9')
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define gc (_op==_ed&&(_ed=(_op=_buf)+fread(_buf,1,100000,stdin),_op==_ed)?EOF:*_op++)
char _buf[100000],*_op(_buf),*_ed(_buf);
I getint(){
	static const int flag[2]={1,-1};
	int _s=0,_f=1;char _ch=gc;
	while(!isnum(_ch))_f=flag[_ch=='-'],_ch=gc;
	while(isnum(_ch))_s=_s*10+_ch-48,_ch=gc;
	return _s*_f;
}
const int N=1e2+2;
char a[N][N];
int f[N][N],n,m,ans;
V input(){
	scanf("%d%d",&n,&m);
	FOR(i,1,n)scanf("%s",a[i]+1);
}
V init(){
	
}
V work(){
	FOR(i,1,n)FOR(j,1,m)f[i][j]=1000;
	f[1][1]=0;
	FOR(i,1,n)FOR(j,1,m){
		if(i!=n)f[i+1][j]=min(f[i+1][j],f[i][j]+(a[i][j]!=a[i+1][j]));
		if(j!=m)f[i][j+1]=min(f[i][j+1],f[i][j]+(a[i][j]!=a[i][j+1]));
	}
	cout<<(f[n][m]+1)/2+(a[1][1]==a[n][m]&&a[1][1]=='#');
}
int main(){
//	freopen("test.in","r",stdin);
	input();
	init();
	work();
	return 0;
}

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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (long long)1e18 + 1;

class UnionFind {
public:
    struct Node {
        long long parent, rank, weight;
        Node() = default;
        Node(const long long& _parent,
             const long long& _rank,
             const long long& _weight = 0) :
            parent(_parent),
            rank(_rank),
            weight(_weight) { }
    };

    std::vector<Node> node;

    UnionFind(const long long& num_node) :
        node(num_node) {
        for(long long i = 0; i < num_node; i++) {
            node[i].parent = i;
        }
    }

    long long searchAndZipRoot(const long long& x) {
        if(node[x].parent == x) {
            return x;
        }
        else {
            auto r = searchAndZipRoot(node[x].parent);
            node[x].weight += node[node[x].parent].weight;
            return node[x].parent = r;
        }
    }

    long long calcWeight(const long long& x) {
        searchAndZipRoot(x);
        return node[x].weight;
    }

    void unite(const long long& x,
               const long long& y,
               const long long& weight = 0) {
        auto rx = searchAndZipRoot(x);
        auto ry = searchAndZipRoot(y);
        if(rx != ry) {
            auto yw = weight + calcWeight(x) - calcWeight(y);
            if(node[rx].rank < node[ry].rank) {
                std::swap(rx, ry);
                yw *= -1;
            }
            node[ry].parent = rx;
            node[ry].weight = yw;
            if(node[rx].rank == node[ry].rank) {
                node[rx].rank++;
            }
        }
    }

    long long calcDiff(const long long& x,
                       const long long& y) {
        return std::abs(calcWeight(x) - calcWeight(y));
    }

    template<class... A>
    bool checkWhetherRootIsSame(const A&... nodes) {
        auto node_list = std::initializer_list<long long>{nodes...};
        if(node_list.size() < 2) return false;
        auto v = searchAndZipRoot(*node_list.begin());
        for(size_t i = 1; i < node_list.size(); i++) {
            if(v != searchAndZipRoot(*(node_list.begin() + i))) return false;
        }
        return true;
    }
};

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

    int N, M;
    std::cin >> N >> M;

    UnionFind tree(N);

    string ans = "Yes";
    REP(i, M) {
        int l, r, d;
        std::cin >> l >> r >> d;
        l--; r--;

        if(!tree.checkWhetherRootIsSame(l, r)) {
            tree.unite(l, r, d);
        }
        else {
            auto diff = tree.calcDiff(l, r);
            if(diff != d) {
                ans = "No";
                break;
            }
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 2560
a=int(input())
if 400<=a<=599:
        print('8')
if 600<=a<=799:
        print('7')
if 800<=a<=999:
        print('6')
if 1000<=a<=1199:
        print('5')
if 1200<=a<=1399:
        print('4')
if 1400<=a<=1599:
        print('3')
if 1600<=a<=1799:
        print('2')
if 1800<=a<=1999:
        print('1')    

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

int main()
{
	int n,k;
	int a[105]={0};
	cin>>n>>k;
	int sum=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if (a[i]<=k/2){
			sum+=2*a[i];
		}
		else
			sum+=2*(k-a[i]);
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
S = input()
counter = 1
anscount = 1
for i in S:
  if counter % 2 == 1:
    if i == 'R' or i == 'U' or i == 'D':
      anscount += 1
  if counter % 2 == 0:
    if i == 'L' or i == 'U' or i == 'D':
      anscount += 1
  counter += 1
if counter == anscount:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
 
using ull = unsigned long long int;
using ll = long long int;
using du = double;
using ld = long du;
using vi = vector<int>;
using vll = vector<ll>;
using vld = vector<ld>;
using vdu = vector<du>;
using vs = vector<string>;
using vc = vector<char>;
using si = set<int>;
using sll = set<ll>;
using sdu = set<du>;
using sld = set<ld>;
using pii = pair<int, int>;
using pll = pair<ll,ll>;
using pdu = pair<du,du>;
using pld = pair<ld,ld>;
using pis = pair<int,string>;
 
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define sp(x) setprecision(x)<<fixed
#define loop(i,n) for(int i=0;i<n;i++)
#define ff first
#define ss second
#define pi acos(-1)
#define meme(a,x) memset(a,x,sizeof(a))
#define all(a) a.begin(),a.end()
 
//debugger
 
#ifdef KAIZER
#include "debug.h"
#else
#define debug(x...)
#endif
//debugger
 
//functions
bool check_pow(ll a)
{
    if((a&(a-1))==0) return true;
    else return false;
}
ld my_pow(ld a,int b)
{
    ld ans=1;
    for(int i=0;i<b;i++) ans*=a;
    return ans;
}
ll digits(ll a)
{
    string line=to_string(a);
    return line.size();
}
bool prime_check(ll a)
{
    bool flag=true;
    for(ll i=2;i<=sqrt(a);i++)
    {
        if(a%i==0) {flag=false; break;}
    }
    return flag;
}
bool comp(const pair<int,int> &a , const pair<int,int> &b)
{
    if(a.ff!=b.ff) return a.ff>b.ff;
    else return a.ss<b.ss;
}
bool comp2(const ll &a, const ll &b)
{
     return a>b;
}

//functions


int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    FASTIO;
    ll t,a,b,x=0,y=0;
    cin>>t>>a>>b;
    string z;
    cin>>z;
    for(auto it: z)
    {
        if(it=='a'&&x<(a+b))
        {
            x++;
            cout<<"Yes"<<endl;
        }
        else if(it=='b'&&x<(a+b)&&y<b)
        {
            x++;
            y++;
            cout<<"Yes"<<endl;
        }
        else cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define For(i, j, k) for (int i = j; i <= k; i++)
using namespace std;
const int N = 2e5 + 10;
int n; int pa[N], fa[N], w[N]; int c0[N], c1[N];
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
struct Node { int o, x, y; bool operator < (const Node B) const { return 1ll * y * B.x > 1ll * x * B.y; } };
priority_queue<Node> q;
int main() {
	scanf("%d", &n);
	For(i, 2, n) scanf("%d", &pa[i]);
	For(i, 1, n) { scanf("%d", &w[i]), fa[i] = i; c0[i] = !w[i], c1[i] = w[i]; if (i > 1) q.push((Node){i, c0[i], c1[i]}); }
	long long ans = 0;
	while (!q.empty()) {
		Node s = q.top(); q.pop();
		int o = find(s.o); if (c0[o] != s.x || c1[o] != s.y) continue;
		int f = find(pa[o]); ans += 1ll * c1[f] * c0[o]; fa[o] = f, c0[f] += c0[o], c1[f] += c1[o];
		if (f != 1) q.push((Node){f, c0[f], c1[f]});
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 8816
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    int ans=1000000;
    for(int i=1;i<=n;i++){
        int sum1=0,sum2=0;
        for(int j=0;j<n;j++){
            if(j<=(i-1)){
                sum1+=v[j];
            }else{
                sum2+=v[j];
            }
        }
        ans = min(ans,abs(sum1-sum2));
    }
    cout<<ans;
}


Measured memory_bytes: 256