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

#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi > 
#define IOS ios_base::sync_with_stdio(false),cin.tie(NULL)
const int N=500003;
int a[N];
int main()
{
	int n,x;
	cin>>n;
	for(int i=2;i<=n;i++)
	{
		cin>>x;
		a[x]++;
	}
	for(int i=1;i<=n;i++) cout<<a[i]<<"\n";
	return 0;
}

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

int main()
{
    int n, i, dp[100009][2];
    string s;
    cin >> s;

    dp[0][0] = dp[0][1] = 0;

    for(i = 0; i < s.size(); i++)
    {
        dp[i+1][0] = dp[i][1] + (s[i] == '0');
        dp[i+1][1] = dp[i][0] + (s[i] == '1');
    }

    cout << min(dp[s.size()][0], dp[s.size()][1]);
}


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

int main( ){

    int n ;

    cin >> n ;

    int ac = 0, wa = 0 , tle = 0 , re = 0 ;

    for( int i = 0 ; i < n ; i ++ ){

        string s ;

        cin >> s ;

        if( s == "AC"){

            ac ++ ;

        }

        if( s == "TLE" ){

            tle ++ ;

        }

        if( s == "RE"){

            re ++ ;

        }

        if( s == "WA" ){

            wa ++ ;

        }

    }

    cout << "AC " << "x " << ac << endl ;

    cout << "WA "<<"x "<< wa << endl ;

    cout << "TLE "<<"x "<<tle<< endl ;

    cout <<"RE "<<"x "<< re << endl ;

}


Measured memory_bytes: 3608
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

sum = 0
counter = 0

list = [[A,A%10], [B,B%10], [C,C%10], [D,D%10], [E,E%10]]
list = sorted(list, key=lambda x:x[1])
for i in range(4):
    if list[i][1] == 0:
        sum += list[i][0]
        counter += 1
for i in range(len(list)-1,counter,-1):
    if list[i][0] % 10 != 0:
        sum += 10*(list[i][0] // 10 + 1)
    else:
        sum += list[i][0] 
sum += list[counter][0]
print(sum)

Measured memory_bytes: 3064
function main (input) {
  const N = parseInt(input.split('\n')[0]);
  const a = parseInt(input.split('\n')[1]);
 
  console.log(N % 500 <= a ? "Yes" : "No");
  Nperfh = N % 500;
}
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<pll> vpl;
typedef vector<int> vi;
ll modpow(ll b, ll e ,ll mod) {
	ll ans = 1;
	for (; e; b = b * b % mod, e /= 2)
		if (e & 1) ans = ans * b % mod;
	return ans;
}


int32_t main(){
	int n;
	cin >> n;
	if(n%10 == 3){
		cout <<"bon" << endl;
	}	
	else if(n%10 ==0 || n%10 ==1 || n %10 == 6 || n %10 == 8){
		cout<<"pon"<<endl;
	}
	else cout <<"hon" << endl;
}
  // clever stuff:
  // Math -> gcd it all
  // Did u check N=1? Did you switch N,M? io?  
  // overflow? ll x int


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int k,x; cin >> k >> x;
    if (500*k >= x) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

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

typedef long long ll;

ll A;
string B;
int main() {
  cin >> A >> B;
  assert(B[1] == '.');
  cout << A * ((B[0] - '0') * 100 + (B[2] - '0') * 10 + (B[3] - '0')) / 100
       << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define PI 3.14159265358979
typedef long long int ll;
const int inf=1001001001;
vector<ll>ans;
ll absc(ll a,ll b){return (a-b>0?a-b:b-a);
}
ll mini(ll a,ll b){return (a>b?b:a);}
int keta(ll a,int ketame){
	rep(i,ketame-1)a/=10;
	if(a)return a%10;
	else return -1;
}
void ume(ll i){
	if(i/3234566668)return ;
	ans.push_back(i);
	if(i%10==0){
		if(i)ume(i*10+0);
		if(i)ume(i*10+1);
	}
	else if(i%10==9){
		ume(i*10+8);
		ume(i*10+9);
	}
	else
	{
		ume(i*10+(i%10)+1);
		ume(i*10+(i%10));
		ume(i*10+(i%10)-1);
	}
}
int main()
{
    ll k;;string a[100010]={};
    cin>>k;
    for(int i=0;i<10;i++)
    {
    	ume(i);
    }
    sort(ans.begin(),ans.end());
    cout<<ans[k];
}


Measured memory_bytes: 2296
#include<cstdio>
#include<math.h>
#include<algorithm>
using namespace std;

int main(void)
{
	long long N, ans = 1E13;
	scanf("%lld", &N);
	for(long long i = 1, j = sqrt(N); i <= j; i++)
		if(N%i == 0)
				ans = min(ans, i+N/i-2);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
n, q = map(int, input().split())
 
tree = {i:[] for i in range(1, n + 1)}
for _ in range(1, n):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)
 
cnt = [0]*n
for _ in range(q):
    p, x = map(int, input().split())
    cnt[p-1] += x
 
check = [0]*n
 
tmp = [1]
while len(tmp) != 0:
    tmp2 = tmp
    tmp = []
    for oya in tmp2:
        check[int(oya)-1] = 1
        for ko in tree[oya]:
            if check[ko-1] == 0:
                cnt[ko-1] += cnt[oya-1]
                tmp.append(ko)
 
 
print(" ".join(map(str, cnt)))

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

int main() {
  int n,q; cin>>n>>q;
  string s; cin>>s;
  int a[n]={0};
  //rとlがわかった瞬間にその間のACの個数がわかるような配列をつくる
  //a[i]＝１番からi番目までの部分文字列にあるACの個数

     for(int i=0;i<n-1;i++){
       if(s[i]=='A'&&s[i+1]=='C') a[i + 1] = a[i] + 1; 
       else a[i+1]=a[i];
       //Aの個数を足してく
  
  }

  for(int i=0;i<q;i++){
    int ans=0;
     int l,r; cin>>l>>r;

     /* 実行時間制限over
     string str=s.substr(l-1,r-l+1);
     for(int j=0;j<str.size()-1;j++){
        if(str[j]=='A'&&str[j+1]=='C')ans++;
     }
     cout<<ans<<endl;
     */

   ans=a[r-1]-a[l-1];
   cout<<ans<<endl;

  }

}

Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#define N 100010
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
long long int a[205];
int main(){
  int n;
  int ans=0;
  cin>>n;
  for (int i=1;i<=n;i++)
    cin>>a[i];
for (int i=1;;i++){
    if (a[i]%2==0)
        a[i]=a[i]/2;
    else
        break;
    if (i%n==0)
        i=1,ans++;
}
cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class AAirConditioner {
        public void solve(int testNumber, FastReader s, PrintWriter out) {
            int x = s.nextInt();
            if (x >= 30) {
                out.println("Yes");
            } else {
                out.println("No");
            }
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 25544
// header {{{
using namespace std;

// C++
#include <algorithm>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>

#pragma GCC optimization_level 3

// util {{{
#define print(x)	        cout << (x)
#define printvec(x,y)       for(int i = 0;i < (y);i++)cout << (x).at(i) << " ";cout << endl
#define println(x)	        cout << (x) << endl
#define printn		        cout << endl
#define read(x)	            cin >> (x)
#define readvec(x,y)        for(int i = 0; i < (y);i++)cin >> (x).at(i)

#define rep(i, n)	        for(int i = 0; i < (int)(n); i++)
#define rep_1(i, n) 	    for(int i = 1; i <=(int)(n); i++)

#define all(x) 		        (x).begin(),(x).end()
#define vint                vector<int>
#define outif(x,y,z)        if(x) cout<<(y)<<endl; else cout<<(z)<<endl
#define loop 		        while(true)

// }}}

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

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

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

void solve() {
    vint vec(3);
    readvec(vec,3);
    sort(all(vec));
    print(vec.at(0));
    print(" ");
    print(vec.at(1));
    print(" ");
    print(vec.at(2));
    printn;
}

signed main() {
    solve();
    return 0;
}


Measured memory_bytes: 3184
package main

import "fmt"

func main() {
	var x, y int
	fmt.Scan(&x, &y)

	for i := 0; i <= x; i++ {
		crane := i * 4
		turtle := (x - i) * 2

		if crane+turtle == y {
			fmt.Println("Yes")
			return
		}
	}

	fmt.Println("No")
}


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

int main() {
    int d, n;
    cin >> d >> n;
    int div = pow(100, d);
    if(n % 100 == 0) n += n/100;
    int ans = n * div;
    cout << ans << endl;
    return 0;
}


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

using namespace std;

bool f(int A[], int n, int m)
{
    for(int32_t bits=(1 << n) -1; bits >= 0; bits--){
        int sum=0;
        for(int i=0; i<n; i++){
            if(bits & (1<<i)){
                sum+=A[i];
                if(sum==m){
                    return true;
                }
            }
        }
    }
    return false;
}

int main()
{
    int n, q;

    scanf("%d", &n);
    //cin >> n;
    int A[n];
    for(int i=0; i<n; i++){
        //cin >> A[i];
        scanf("%d", &A[i]);
    }

    //cin >> q;
    scanf("%d", &q);
    for(int i=0; i<q; i++){
        int m;
        //cin >> m;
        scanf("%d", &m);
        if(f(A, n, m)){
            cout << "yes" << endl;
        } else{
            cout << "no" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3224
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>


int main (void) {
int A,B,C;
scanf("%d %d %d",&A,&B,&C);
if ((A+B+C)>=22)printf("bust");
else printf("win");
return EXIT_SUCCESS;
}


Measured memory_bytes: 128
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int X = stdIn.nextInt();
		int d = X/100;
		int r = X%100;
		
		if(r <= 5*d) System.out.println(1);
		else System.out.println(0);

	}

}

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

int main(){
	int n, i = 0;
	int a[100];
	cin >> n;

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

	for (i = n - 1; i >= 0; i--){
		cout << a[i];
		if (i != 0)
			cout << " ";
	}
 
        cout << endl;

	return 0;
}

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

int arr[100001];
int n;

int dp[100001];

int main(){
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>arr[i];
        dp[i] = INT_MAX;
    }
    dp[0]=0;

    for(int i=0; i<n; i++){
        if(i+1 < n ){
            dp[i+1] = min(dp[i+1], dp[i] + min(dp[i+1], abs(arr[i+1]-arr[i])));
        }
        if(i+2 < n ){
            dp[i+2] = min(dp[i+2], dp[i] + min(dp[i+2], abs(arr[i+2]-arr[i])));
        }
    }

    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
	int A,B,C;
	scanf("%d %d %d",&A,&B,&C);
	if(A>=B&&A>=C) A=10*A;
	else if(B>=A&&B>=C) B=10*B;
	else C=10*C;
	printf("%d\n",A+B+C);
    return 0;
}

Measured memory_bytes: 128
/*
    WRITER:kakitamasziru
*/
#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 <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
//#include <unordered_map> // unordered_map
//#include <unordered_set> // unordered_set
#include <bitset> // bitset
//#include <cctype> // isupper, islower, isdigit, toupper, tolower
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1001001000;
const int MOD = 1000000007;
typedef pair<long,long> P;
//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}
long long nCr(long long n, long long r) {
    long long A = 1, B = 1;
    //Aが分子Bが1/r!
    //n!はi = 1;i<=nでする
    for (long long i = n-r+1; i <= n; i++) {
        A = A * i % MOD;
    }
    for (long long i = 1; i <= r; i++) {
        B = B * i % MOD;
    }
    B = mod_pow(B, MOD - 2);
    B %= MOD;
    //Bは割るのではなく掛ける
    return (A * B) % MOD;
}

int dp[514514];

int main() {
    int H,W;cin >> H >> W;
    int N;cin >> N;
    vector<vector<int>> G(H,vector<int>(W));
    vector<int> color(N);
    for(int i = 0;i<N;i++){
        cin >> color.at(i);
    }

    int colorCount = 1;
    int changeCount = 0;

    for(int i = 0;i<H;i++){
        for(int j = 0;j<W;j++){
            G.at(i).at(j) = colorCount;
            changeCount++;
            if(changeCount == color.at(colorCount-1)){
                colorCount++;
                changeCount = 0;
            }
        }
        i++;
        if(i >= H) break;
        for(int k = W-1;k>=0;k--){
            G.at(i).at(k) = colorCount;
            changeCount++;
            if(changeCount == color.at(colorCount-1)){
                colorCount++;
                changeCount = 0;
            }
        }
    }

    for(int i = 0;i<H;i++){
        for(int j = 0;j<W;j++) {
            if(j != W-1) cout << G.at(i).at(j) << " ";
            else cout << G.at(i).at(j);
        }
        cout << endl;
    }

    return 0;
    
    /*
    g++ abc.cpp
    ./a.out
    */
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
#include<vector>
#include<functional>
template<typename T>
struct dualsegtree{
	function<T(T,T)>lazycalcfn,updatefn;
	int n;
	T lazydefvalue;
	vector<T>dat,lazy;
	vector<bool>lazyflag;
	dualsegtree(int n_=0,T defvalue=0,
		function<T(T,T)>lazycalcfn_=[](T a,T b){return a+b;},
		function<T(T,T)>updatefn_=[](T a,T b){return a+b;},
		T lazydefvalue_=0
	):lazydefvalue(lazydefvalue_),
		lazycalcfn(lazycalcfn_),updatefn(updatefn_)
	{
		n=1;
		while(n<n_)n<<=1;
		dat.assign(n,defvalue);
		lazy.assign(n-1,lazydefvalue);
		lazyflag.assign(n-1,false);
	}
	void copy(const vector<T>&v)
	{
		for(int i=0;i<v.size();i++)dat[i]=v[i];
		lazy.assign(n-1,lazydefvalue);
		lazyflag.assign(n-1,false);
	}
	void update(int a,int b,T x,int k=0,int l=0,int r=-1)//[a,b)
	{
		if(r<0)r=n;
		if(b<=l||r<=a)return;
		else if(a<=l&&r<=b)
		{
			if(k<n-1)
			{
				lazy[k]=lazycalcfn(lazy[k],x);
				lazyflag[k]=true;
			}
			else dat[k-n+1]=updatefn(dat[k-n+1],x);
		}
		else
		{
			if(lazyflag[k])
			{
				update(0,n,lazy[k],k*2+1,l,(l+r)/2);
				update(0,n,lazy[k],k*2+2,(l+r)/2,r);
				lazy[k]=lazydefvalue;
				lazyflag[k]=false;
			}
			update(a,b,x,k*2+1,l,(l+r)/2);
			update(a,b,x,k*2+2,(l+r)/2,r);
		}
	}
	T query(int i)
	{
		T ret=dat[i];
		i+=n-1;
		while(i>0)
		{
			i=(i-1)/2;
			if(lazyflag[i])ret=updatefn(ret,lazy[i]);
		}
		return ret;
	}
};
main()
{
	int N,Q;
	cin>>N>>Q;
	dualsegtree<int>P(N,0,
		[](int a,int b){return a+b;},[](int a,int b){return a+b;});
	for(;Q--;)
	{
		int q;cin>>q;
		if(q==0)
		{
			int s,t,x;cin>>s>>t>>x;
			P.update(s-1,t,x);
		}
		else
		{
			int i;cin>>i;cout<<P.query(i-1)<<endl;
		}
	}
}



Measured memory_bytes: 3872
#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 main() {
   int n;
   cin >> n;
   cout << n / 3 << endl;

   return 0;
}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
while(true){
   var [n,d]=arr.shift().split(" ").map(Number);
   if(n==0 && d==0)break;
   var S=[];
   var C=[];
   for(var i=0;i<n;i++){
      var mc=arr[i].split(" ");
      mc.shift();
      var c=mc.map(Number).reverse();
      var sum= (c.length!=0)?c.reduce((a,b)=> a+b):0;
      S[i]=sum;
      C[i]=c;
   }
   while(true){ 
      var f=false;
      for(var i=0;i<S.length;i++){
         if(S[i]==0)continue;
         S[i] -= C[i][0];
         if(Math.max(...S) - Math.min(...S) <=d){
            C[i].shift();
            f=true;
            break;
         }else{
            S[i] +=C[i][0];
         }
      }
      if(f==false)break;
   }
   var sum=S.reduce((a,b)=> a+b);
   if(sum==0)console.log("Yes");
   else console.log("No");
   arr=arr.slice(n);
}


Measured memory_bytes: 25488
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		double x[] = new double[100];
		double y[] = new double[100];
		double p_1 = 0,p_2 = 0,p_3 = 0,p_infinity = -1;

		int n = scanner.nextInt();

		for(int i = 0; i < n; i++)x[i] = scanner.nextDouble();
		for(int i = 0; i < n; i++)y[i] = scanner.nextDouble();

		for(int i = 0; i < n; i++){
			p_1 += Math.abs(x[i]-y[i]);
			p_2 += (x[i]-y[i])*(x[i]-y[i]);
			p_3 += Math.abs((x[i]-y[i])*(x[i]-y[i])*(x[i]-y[i]));
			p_infinity = Math.max(p_infinity, Math.abs(x[i]-y[i]));
		}

		System.out.printf("%.10f\n", p_1);
		System.out.printf("%.10f\n", Math.sqrt(p_2));
		System.out.printf("%.10f\n", Math.cbrt(p_3));
		System.out.printf("%.10f\n", p_infinity);
	}
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

const int limit = 100010;
using edge = struct {int to; ll cost;}; // 重み付き木を作る場合の定石
vector<edge> tree[limit];
ll depth[limit];
void dfs(int v, int p, ll d) {
  depth[v] = d;
  for(auto &e : tree[v]) {
    if(e.to == p) continue; // 親しかいなくなった場合、探索終了
    dfs(e.to, v, d + e.cost);
  }
}

int main() {
  int N; cin >> N;
  for(int i = 0; i < N - 1; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    tree[a].push_back({b, c});
    tree[b].push_back({a, c});
  }
  int Q, K; cin >> Q >> K;
  vector<ll> x(Q), y(Q); REP(i, Q) cin >> x[i] >> y[i];

  dfs(K - 1, -1, 0);

  for(int i = 0; i < Q; ++i) {
    cout << depth[x[i] - 1] + depth[y[i] - 1] << endl;
  }
}

Measured memory_bytes: 15872
N, D = map(int, input().split())
X = [list(map(int, input().split())) for i in range(N)]
count = 0
for i in range(N-1):
    for j in range(i+1,N):
        length = 0
        for k in range(D):
            length += (X[i][k] - X[j][k])**2
        if((length**0.5).is_integer()): count += 1
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, Q;
  string S;
  cin >> N >> Q >> S;
  S += 'B';
  vector<int> vec(N+1); 
  vec.at(0) = 0;
  int ACcount = 0;
  for (int i = 1; i <= N; i++){
    if (S.at(i-1) == 'A' && S.at(i) == 'C'){
      ACcount++;
      vec.at(i) = ACcount;
    } else {
      vec.at(i) = ACcount;
    }

  }
  


  for (int i = 0; i < Q; i++){
    int l,r;
    int count = 0;
    cin >> l >> r;
    count = vec.at(r-1) - vec.at(l-1);
    cout << count << endl;   
  }

}



Measured memory_bytes: 1408
import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;
import std.uni, std.math, std.container, std.typecons, std.typetuple;
import core.bitop, std.datetime;

immutable long mod = 10^^9 + 7;
immutable long inf = mod;

void main(){
    long m, n;
    readVars(m, n);

    long ans = modpow(m, n, mod);

    writeln(ans);
}

T modpow(T)(T x, T y, T mod){
    return y ? modpow(x, y>>1, mod)^^2 % mod * x^^(y&1) % mod : 1;
}

void readVars(T...)(auto ref T args){
    auto line = readln.split;
    foreach(ref arg ; args){
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    if(!line.empty){
        throw new Exception("args num < input num");
    }
}

Measured memory_bytes: 2704
N=gets.to_i
array=gets.chomp.split(" ").map(&:to_i)
indexes=Array.new(N){|i|i}
rets=Array.new(N, nil)
N.downto(1) do |i|
    a = array[i-1]
    index=indexes.delete_at(a-1)
    if index == nil
        puts -1
        exit
    end
    rets[index]= a
end
rets.each do |r|
    puts r
end


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

int main() {
  int a,b;
  string x,y;
  
  cin >> a >> b;
  
  for (int i = 0; i < b; i++) {
    x += to_string(a);
  }
  
  for (int i = 0; i < a; i++) {
    y += to_string(b);
  }
  if (x < y) {
    cout << x << endl;
  }
  else 
    cout << y << endl;
}




Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <fstream>
using namespace std;
const long long inf=1e9+7;
const long long mod=1e9+7;
const int64_t CYCLES_PER_SEC=2800000000;
//
inline uint32_t Xor128(){
	static uint32_t x=123456789;
	static uint32_t y=362436069;
	static uint32_t z=521288629;
	static uint32_t w=88675123;
	uint32_t t=x^(x<<11);
	x=y;y=z;z=w;
	return w=(w^(w>>19))^(t^(t>>8));
}
struct Timer{
	int64_t start;
	Timer(){reset();}
	void reset(){start=getcycle();}
	void plus(double a){start-=(a*CYCLES_PER_SEC);}
	inline double get(){return (double)(getcycle()-start)/CYCLES_PER_SEC;}
	inline int64_t getcycle(){
		uint32_t low,high;
		__asm__ volatile ("rdtsc":"=a"(low),"=d"(high));
		return ((int64_t)low)|((int64_t)high<<32);
	}
};
//
int a[300000][10];
int b[300000][10];
int f[10][10][10];
int main(){
	int n;
	string s;
	cin>>n>>s;
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++){
			char c='0'+j;
			if(s[i]==c){
				a[i][j]=1;
			}
		}
	}
	for(int i=1;i<n;i++){
		for(int j=0;j<10;j++){
			a[i][j]|=a[i-1][j];
		}
	}
	for(int i=n-1;i>=0;i--){
		for(int j=0;j<10;j++){
			char c='0'+j;
			if(s[i]==c){
				b[i][j]=1;
			}
		}
	}
	for(int i=n-2;i>=0;i--){
		for(int j=0;j<10;j++){
			b[i][j]|=b[i+1][j];
		}
	}
	for(int i=1;i<n-1;i++){
		for(int j=0;j<10;j++){
			for(int k=0;k<10;k++){
				int num=s[i]-'0';
				if(a[i-1][j]&&b[i+1][k]){
					f[j][num][k]=1;
				}
			}
		}
	}
	int ans=0;
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			for(int k=0;k<10;k++){
				ans+=(f[i][j][k]?1:0);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5632
#include <stdio.h>

int main(void) {
  int a,b,c,x, count=0;
  scanf("%d%d%d%d",&a,&b,&c,&x);

  for (int i = 0; i <= a;i++) {
    for (int j = 0; j <= b;j++) {
      for (int k = 0; k <= c;k++) {
        if ((i * 500 + 100 * j + k * 50) == x) count++;
      }
    }
  }
  printf("%d",count);
}


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

int main() {
    int a, b, k;
    cin >> a >> b >> k;
    vector<int> v;
    for (int i = 1; i <= min(a, b); i++) {
        if (a % i == 0 && b % i == 0) {
            v.push_back(i);
        }
    }
    reverse(v.begin(), v.end());
    cout << v[k - 1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define make_unique(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define Sort(vec) sort(vec.begin(),vec.end())
#define RSort(vec) sort(vec.rbegin(),vec.rend())
#define endl "\n"
#define tr1(i) cout<<i<<endl;
#define tr2(i,j) cout<<i<<" "<<j<<endl;
#define tr3(i,j,k) cout<<i<<" "<<j<<" "<<k<<endl;
#define vvi vector<vector<int> > 
#define vvl vector<vector<ll> >
#define all(st) st.begin(),st.end()
#define vpl vector<pair<ll,ll> >
#define vpi vector<pair<int,int> >
#define pi pair<int,int>
#define pl pair<ll,ll>
#define al vector<list<int> >
#define vs vector<string>
#define vi vector<int>
#define vb vector<bool>
#define vl vector<ll>
#define vc vector<char>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repit(st) for(auto it=st.begin();it!=st.end();it++)
#define ull unsigned long long int
#define eb emplace_back
#define pb push_back
#define ll long long int
#define minf -(1e18)
#define inf 1e18
#define f first
#define se second
#define mod 1000000007
using namespace std;
ll mi(ll n,ll m){ll pw=n%m;ll ex=m-2;ll ans=1;while(ex){if(ex&1) ans = ans*pw%m;pw = pw*pw%m;ex>>=1;}return ans%mod;}
ll pw(ll a,ll n){ll pw=a%mod;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw%mod;pw = pw*pw%mod;ex>>=1;}return ans%mod;}
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
void show(ll x){cout<<x<<" ";}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
ll Abs(ll x){return x>0?x:(-x);}
ll Ceil(ll a,ll b){return a/b+(a%b!=0);}
#define bs binary_search
#define lb lower_bound
#define mkp make_pair
//#define d double
void solve(){
	int n,m;
	cin>>n>>m;
	priority_queue<ll> pq;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		pq.push(x);
	}
	while(m--){
		ll fi=pq.top();
		pq.pop();
		pq.push(fi/2);
	}
	ll ans=0;
	while(!pq.empty()){
		ll x=pq.top();
		ans+=x;
		pq.pop();
	}
	cout<<ans;
	
	
}
int32_t main(){
FIO;
int t=1;
//cin>>t;
while(t--){
	solve();
}
}

Measured memory_bytes: 1400
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    sum=0
    for i in range(1,n+1):
        if 1<=i<10 or 100<=i<1000 or 10000<=i<100000:
            sum+=1
    print(sum)
resolve()

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){

  int X,A,B;
  cin>>X>>A>>B;
  int time=A-B;
  if(time>=0){
  
    cout<<"delicious";
    return 0;
  }
  else if(time*-1<=X){
  
    cout<<"safe";
    return 0;
  }
  else{
  
    cout<<"dangerous";
    return 0;
  }
}

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

int main() {
    int k,a,b;cin >> k>>a>>b;
    string ans="NG";
    for (int i = a; i <=b; i++) {
        if(i%k==0){
            ans="OK";
        }
    }
    cout<<ans<<endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define ppb pop_back
#define INF 1e18
typedef long long ll;

using namespace std;

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

    ll n,weight;
    cin>>n>>weight;
    vector<ll> w(n),v(n);
    rep(i,n)
    cin>>w[i]>>v[i];
    vector<vector<ll> >dp(n+1, vector<ll>(1e5+1, INF));
    dp[0][0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= 1e5; j++) {
            dp[i][j] = min(dp[i][j], dp[i-1][j]);
            if (j-v[i-1] >= 0)
                dp[i][j] = min(dp[i][j], dp[i-1][j-v[i-1]]+w[i-1]);
        }
    }
    int ans = 0;
    rep(i, 1e5+1) {
        if (dp[n][i] <= weight)
            ans = i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 80256
import math

N = int(input())

min_move_count = float("inf")
for i in range(1, int(math.sqrt(N)) + 1):
    if (N / i).is_integer():
        move_count = i + (N // i) - 2
        if move_count < min_move_count:
            min_move_count = move_count

print(min_move_count)

Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
struct point{int x;int y;};
int i,j,count1=0,count2=0;

int main(void){
    vector<int> vec(3);
    cin>>vec[0]>>vec[1]>>vec[2];
    sort(vec.begin(),vec.end());
    int def1,def2,ans=0;
    def1=vec[2]-vec[1];
    def2=vec[2]-vec[0];
    if(def1%2==def2%2){
        def2-=def1;
        ans=def1+def2/2;
    }else{
        ans+=def1;
        ans+=(def2-def1+1)/2;
        ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
//Problem : Character - Ring by aiju
#include <bits/stdc++.h>
#include <iostream>
using namespace std;

int main() {
	string s, p;
	cin >> s >> p;
	string newS = s + s;
	int pLen = p.length();
	bool found = false;
	for(int i=0; i<newS.length()-pLen; i++)
	{
		if(newS.substr(i, pLen)==p)
		{
			found = true;
			break;
		}
	}
	cout << (found?"Yes" : "No") << "\n";
	return 0;
}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1e9;
int MOD = 1e9+7;
const int MAX_N = 100000;
struct UnionFind{
    int par[MAX_N];
    void init(int n){
        for(int i = 0;i < n;i++)par[i] = i;
    }
    int root(int x){
        if(par[x] == x)return x;
        else return par[x] = root(par[x]);
    }
    bool same(int x,int y){
        return root(x) == root(y);
    }
    void unite(int x,int y){
        x = root(x);
        y = root(y);
        if(x == y)return;
        par[y] = x;
    }
};
main(){
    int N,X[100000],Y[100000],sum = 0;
    vector<pair<int,int> >xx,yy;
    vector<pair<int,pair<int,int> > >edge;
    cin >> N;
    for(int i = 0;i < N;i++){
        cin >> X[i] >> Y[i];
        xx.push_back(make_pair(X[i],i));
        yy.push_back(make_pair(Y[i],i));
    }
    sort(xx.begin(),xx.end());
    sort(yy.begin(),yy.end());
/*    
    for(auto p:xx){
        cout << p.first << " " << p.second << endl;
    }
    for(auto p:yy){
        cout << p.first << " " << p.second << endl;
    }
*/
    for(int i = 0;i < N-1;i++){
        auto p = make_pair(xx[i+1].second,xx[i].second);
        edge.push_back(make_pair(xx[i+1].first-xx[i].first,p));
    }
    for(int i = 0;i < N-1;i++){
        auto p = make_pair(yy[i+1].second,yy[i].second);
        edge.push_back(make_pair(yy[i+1].first-yy[i].first,p));
    }
    sort(edge.begin(),edge.end());
    UnionFind uf;
    uf.init(N);
    for(auto e:edge){
        int cost = e.first;
        auto p = e.second;
        if(!uf.same(p.first,p.second)){
            sum += cost;
            uf.unite(p.first,p.second);
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 7784
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*************** using variables ***************/
int n;
/**********************************************/

int main(){
    cin >> n;
    printf("ABC%3d\n", n);
}


Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    val params = scala.io.StdIn.readLine().split(" ")
    val result = params(1) match {
      case "+" => params(0).toInt + params(2).toInt
      case "-" => params(0).toInt - params(2).toInt
    }

    println(result)
  }
}

Measured memory_bytes: 21416
//
//  main.cpp
//  A
//
//  Created by 曾憲揚 on 2020/8/19.
//  Copyright © 2020 曾憲揚. All rights reserved.
//

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

int main(int argc, const char * argv[]) {
    int n; cin>>n;
    cout<<fixed<<setprecision(5)<<n*2*3.14159265<<endl;
    return 0;
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define si size()
#define bk back()
#define popb pop_back()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define ump unordered_map
#define forl(i,a,n) for(int i=a;i<n;i++)
#define rfor(i,n,a) for(int i=n;i>=a;i--)
#define fore(i,a,n) for(int i=a;i<=n;i++)
#define len length()
const int N=1e9+7;

const int MAX=1e5+7;
ll mem[MAX];

//recursive solution
//extend same solution of a to this by simulating for k jumps
ll step(int pos,int k,int n,int arr[])
{
    if(pos==n-1) return 0;
    if(mem[pos]!=-1) return mem[pos];
    ll val=N;
    forl(i,1,k+1)
    {
        if(pos+i<=n-1)val=min(val,step(pos+i,k,n,arr)+abs(arr[pos]-arr[pos+i]));
        else break;
    }
    return mem[pos]=val;
   
}

//dp-- O(n*k)--- n dp states and for each dp state k possiblity
//recursion O(k^n) ---- for every i there are k posiblities


int main()
{
   int n,k;
   cin>>n>>k;
   int arr[n];
   forl(i,0,n) cin>>arr[i];
   memset(mem,-1,sizeof(mem));
   cout<<step(0,k,n,arr)<<endl;

// iterative approach

//    int dp[n];
//    //dp[i] means minimum cost to reach (0..i) from 0
//    forl(i,0,n) dp[i]=N;
//    dp[0]=0;
//    forl(i,1,n)
//    {
//        fore(j,1,2)
//        {
//            if(i-j>=0) dp[i]=min(dp[i],dp[i-j]+abs(arr[i]-arr[i-j]));
//        }
//    }
//    cout<<dp[n-1]<<endl;

}


Measured memory_bytes: 12672
#include<iostream>
using namespace std;
#define MAX 100000

int parent(int i){return i/2;}
int left(int i){return 2*i;}
int right(int i){return 2*i+1;}

int main(){
    int H,i,A[MAX+1];
    
    cin>>H;
    for(i=1;i<=H;i++)cin>>A[i];
    
    for(i=1;i<=H;i++){
        cout<<"node "<<i<< ": key = " <<A[i]<<", ";
        if(parent(i)>=1)cout<<"parent key = "<<A[parent(i)]<<", ";
        if(left(i)<=H)cout<<"left key = "<<A[left(i)]<<", ";
        if(right(i)<=H)cout<<"right key = "<<A[right(i)]<<", ";
        cout<<endl;
    }
    return 0;

}


Measured memory_bytes: 3136
unittest
{
	assert( [ "13 3 1" ].parse.expand.solve == 3 );
	assert( [ "12 3 1" ].parse.expand.solve == 2 );
	assert( [ "100000 1 1" ].parse.expand.solve == 49999 );
	assert( [ "64146 123 456" ].parse.expand.solve == 110 );
	assert( [ "64145 123 456" ].parse.expand.solve == 109 );
}



import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto xyz = input.front.split.to!( long[] );
	return tuple( xyz[ 0 ], xyz[ 1 ], xyz[ 2 ] );
}

auto solve( long x, long y, long z )
{
	return ( x - z ) / ( y + z );
}


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

#[allow(dead_code)]
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")
}

fn main() {
    let a: i32 = read();
    let b: i32 = read();
    let x: i32 = read();
    println!("{}", if a <= x && x <= a + b { "YES" } else { "NO" });
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<stdlib.h>


int main(){
  int a,b,c,d;
  scanf("%d %d %d %d",&a, &b, &c, &d);
  if(abs(a-c)<=d)
  printf("Yes");
  else{
    if(abs(a-b)<=d&&abs(b-c)<=d)
      printf("Yes");
      else
        printf("No");
  }
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

#define int long long

const int MOD = 998244353;
const int MAXN = 3e5 + 7;

int mul(int a, int b) {
    return (a * b) % MOD;
}

int add(int a, int b) {
    return (a + b) % MOD;
}

int binpow(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1) {
            res = mul(res, a);
        }
        a = mul(a, a);
        b >>= 1;
    }
    return res;
}

int fact[MAXN];

void init() {
    fact[0] = 1;
    for (int i = 1; i < MAXN; i++) {
        fact[i] = mul(i, fact[i - 1]);
    }
}

int C(int n, int k) {
    int up = fact[n];
    int dw = mul(fact[k], fact[n - k]);
    return mul(up, binpow(dw, MOD - 2));
}

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

    init();

    int n, a, b, k;
    cin >> n >> a >> b >> k;
    int ans = 0;
    for (int c1 = 0; c1 <= n; c1++) {
        int c2 = (k - c1 * a) / b;
        if (c2 < 0 || c2 > n || c1 * a + c2 * b != k) continue;
        ans = add(ans, mul(C(n, c1), C(n, c2)));
    }
    cout << ans << endl;
}   


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
vector<int> ed[100001];
int flag;
int an[100001];
pair<int,int> dfs(int node,int p){

int i,j;
int index=0;
vector<pair<int,int> > x;
for(i=0;i<ed[node].size();i++)
{
    int x1=ed[node][i];
    if(x1==p)
        continue;
        x.pb(dfs(x1,node));







}
int n=x.size();

if(n==0)
{
    return mp(an[node],0);
}
int z=an[node];
int ss[n+1][z+1];

for(j=0;j<=n;j++)
for(i=0;i<=z;i++)
    ss[j][i]=1e6;
    ss[0][0]=0;
    for(i=0;i<n;i++)
    {
         int x1,x2,y1,y2;
        x1=x[i].first;
         y1=x[i].second;
         x2=x[i].second;
         y2=x[i].first;


        for(j=0;j<=z;j++){

         int k=j+x1;
         if(k<=z)
            ss[i+1][k]=min(ss[i+1][k],ss[i][j]+x2);
          k=j+y1;
         if(k<=z)
            ss[i+1][k]=min(ss[i+1][k],ss[i][j]+y2);



        }



    }
    int ans=1e6;
    for(i=0;i<=z;i++)
        ans=min(ans,ss[n][i]);
        if(ans>=(1e6))
            flag=1;
    return mp(z,ans);



}
int main(){


int n;
cin>>n;
int i,j;
for(i=2;i<=n;i++){

    int x;
    cin>>x;
    ed[x].pb(i);
    }
    for(i=1;i<=n;i++)
        cin>>an[i];
        dfs(1,0);
if(flag)
    cout<<"IMPOSSIBLE"<<endl;
    else
        cout<<"POSSIBLE"<<endl;






return 0;}



Measured memory_bytes: 3584
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
 
typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PII;
static const int INF=1010000000000000017LL;
static const double eps=1e-12;
static const double pi=3.14159265358979323846;
static const int dx[4]={1,-1,0,0};
static const int dy[4]={0,0,1,-1};
static const int ddx[8]={1,-1,0,0,1,1,-1,-1};
static const int ddy[8]={0,0,1,-1,1,-1,1,-1};
 
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}

int N,M,L;
int Q;

int d[305][305];
int u[305][305];
int remain[305];

void init(){
    for(int i=0;i<305;++i)for(int j=0;j<305;++j){
        if(i==j)d[i][j]=0;
        else d[i][j]=INF;
        u[i][j]=INF;
    }
}

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

void warshall_floyd2(){
    for(int k=0;k<N;++k){
        for(int i=0;i<N;++i){
            for(int j=0;j<N;++j){
                chmin(u[i][j],u[i][k]+u[k][j]);
            }
        }
    }
}

signed main(){
    init();
    cin>>N>>M>>L;
    for(int i=0;i<M;++i){
        int a,b,c;
        cin>>a>>b>>c;
        a--,b--;
        d[a][b]=d[b][a]=c;
    }
    warshall_floyd1();
    for(int i=0;i<N;++i){
        for(int j=0;j<N;++j){
            if(L<d[i][j])continue;
            u[i][j]=1;
        }
    }
    warshall_floyd2();
    cin>>Q;
    while(Q--){
        int s,t;
        cin>>s>>t;
        s--,t--;
        int cost=u[s][t];
        if(cost==INF)cout<<-1<<endl;
        else cout<<cost-1<<endl;
    }
}


Measured memory_bytes: 5096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int main(){
    int n; string s;
    cin >> n >> s;
    map<char,int> mp;
    for(int i = 0; i < n; i++){
        mp[s[i]]++;
    }
    if(mp['R'] > mp['B']) cout << "Yes" << endl;
    else cout << "No" << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    int N; cin >> N;
    vec a(N); readvec(a);

    map<int, int> index, num;
    REP(i, N){
        if(num[a[i]] == 0) index[a[i]] = i;
        num[a[i]]++;
    }

    vector<Pii> P;
    for(auto p: num) P.push_back(Pii(p.first, p.second));
    SORT(P);
    REVERSE(P);
    P.push_back(Pii(0, INF));

    vec ans(N, 0);
    int m = INF;
    int n = 0;
    REP(i, P.size() - 1){
        m = min(m, index[P[i].first]);
        n += P[i].second;
        ans[m] += n * (P[i].first - P[i + 1].first);
    }

    REP(i, N) cout << ans[i] << endl;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 18160
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
const int MAX_A = 3e5 + 5;
int op(int a, int b) { return max(a, b); }
int e() { return 0; }

int main() {
	cin.tie(0)->sync_with_stdio(false);
	int n, k; cin >> n >> k;
	segtree<int, op, e> dp(MAX_A);
	int res = 0;
	while (n--) {
		int a; cin >> a;
		int l = max(0, a - k);
		int r = min(a + k + 1, MAX_A);
		int now = dp.prod(l, r) + 1;
		dp.set(a, now);
		res = max(res, now);
	}
	cout << dp.all_prod() << '\n';
	return 0;
}

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

int main() {
  int a,q=0;
  cin>>a;
  for(int i=0;i<a;i++){
    int A;
    cin>>A;
    if(A%2==0){
      if((A%3!=0)&&(A%5!=0)){
        
      q=1;
      break;
      }
    }
    
  }
  if(q==1){
    cout<<"DENIED";
  }
  else{
    cout<<"APPROVED";
  }
  
  
}


Measured memory_bytes: 256
abc=list(map(int,input().split()))
a,b,c=sorted(abc)

ans=0

#まず+1, +1を限界まで
b_plus=c-b
b+=b_plus
a+=b_plus
ans+=b_plus

#次に+2を限界まで
a_plus=(c-a)//2
a+=a_plus*2
ans+=a_plus

#微調整
if a!=b:
    ans+=2

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h> 
  
using namespace std; 
typedef long long ll;
 
int main()
{
  
    ll t=1,l;
     // cin>>t;
     l = t;

    while(t--)
    {
       ll x,a,b;
       cin>>x;
       cin>>a>>b;
       if(a/x==b/x)
       {
        if(a%x!=0&&b%x!=0)
          cout<<"NG"<<endl;
        else
          cout<<"OK"<<endl;
       }
       else
        cout<<"OK"<<endl;
    }
  return 0;
}



Measured memory_bytes: 3596