akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority queue
#include<deque>//double_ended queue
using namespace std;
int main()
{ 
    int m1,d1,m2,d2;
    cin>>m1>>d1>>m2>>d2;
    if(m2==m1+1&&d2==1){cout<<1<<endl;}
    else{cout<<0<<endl;}
    return 0;
}

Measured memory_bytes: 256
n = int(input())
s_list = list(input().split())
# print(s_list)

l = []
for s in s_list:
    # print(s)
    if not s in l:
        l.append(s)
# print(l)
if len(l) == 4:
    print("Four")
else:
    print("Three")

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

int main(){
    int Input[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;
    cin >> K;

    cout << Input[K-1] << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        boolean xp = false;
        boolean xm = false;
        boolean yp = false;
        boolean ym = false;
        String s = scan.next();
        for(int i = 0; i < s.length(); i++){
            if(s.charAt(i) == 'N') yp = true;
            else if(s.charAt(i) == 'E') xp = true;
            else if(s.charAt(i) == 'S') ym = true;
            else xm = true;
        }
        if(yp == true && ym == false || xp == true && xm == false){
            System.out.println("No");
        }else if(ym == true && yp == false || xm == true && xp == false){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
    }
    
    public static void main(String[] args){
        new Main().solve();
    }
}


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

using namespace std;

#define pb push_back
#define fs first
#define sc second
#define sz size
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define forni(i, n) for (ll i = 2; i <= (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using ll = long long;
const ll inf = 1e9+7; 

const double PI =  3.141592653589793;

int main(){
	IO;
	ll n;
	cin>>n;
	(n>999)?cout<<"ABD\n":cout<<"ABC\n";
	return 0;
}

// _   .-')                .-. .-')                 .-')                                               
//( '.( OO )_              \  ( OO )               ( OO ).                                             
// ,--.   ,--.).-'),-----. ,--. ,--.  .-'),-----. (_)---\_) ,--. ,--.     .-----.  ,-.-')  .-'),-----. 
// |   `.'   |( OO'  .-.  '|  .'   / ( OO'  .-.  '/    _ |  |  | |  |    '  .--./  |  |OO)( OO'  .-.  '
// |         |/   |  | |  ||      /, /   |  | |  |\  :` `.  |  | | .-')  |  |('-.  |  |  \/   |  | |  |
// |  |'.'|  |\_) |  |\|  ||     ' _)\_) |  |\|  | '..`''.) |  |_|( OO )/_) |OO  ) |  |(_/\_) |  |\|  |
// |  |   |  |  \ |  | |  ||  .   \    \ |  | |  |.-._)   \ |  | | `-' /||  |`-'| ,|  |_.'  \ |  | |  |
// |  |   |  |   `'  '-'  '|  |\   \    `'  '-'  '\       /('  '-'(_.-'(_'  '--'\(_|  |      `'  '-'  '
// """    """     """""""" """  """"      """""""  """""""  """"""""      """"""   """         """""""


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define se second
#define fi first

bool used[26];
signed main()
{
    //freopen("inp.txt","r",stdin);
    string s;
    cin>>s;
    int n = s.length();
    for(int i=0;i<n;i++)
        used[s[i]-'a'] = 1;
    for(int i=0;i<26;i++)
    {
        if(!used[i])
        {
            char ch = 'a'+i;
            cout<<s<<ch;
            return 0;
        }
    }
    if(s=="zyxwvutsrqponmlkjihgfedcba")
        cout<<-1;
    else
    {
        while(1)
        {
            for(int j=(s[n-1]-'a'+1);j<26;j++)
            {
                if(!used[j])
                {
                    s[n-1] = char('a'+j);
                    cout<<s;
                    return 0;
                }
            }
            used[s[n-1]-'a'] = 0;
            s.pop_back();
            n--;
        }
    }
    return 0;
}

Measured memory_bytes: 256
<?php
    $n = intval(trim(fgets(STDIN)));
    $a = explode(" ", trim(fgets(STDIN)));
    $c = 0;

    for ($i = 0; $i < $n; $i++) {
        $minj = $i; 
        $j = $i + 1;
    
        while ($j < $n) {
            if ($a[$minj] > $a[$j]) {
                $minj = $j; 
            }   
            $j++;
        }   
        if ($minj != $i) {
            $t = $a[$i];
            $a[$i] = $a[$minj];
            $a[$minj] = $t; 
            $c++;
        }   
    }   

    $s = implode(" ", $a);
    echo $s . "\n";
    echo $c . "\n";

?>


Measured memory_bytes: 9252
#include<cstdio>
#include<cmath>
#include<algorithm>
#define MAXN 200+5

typedef long long ll;

const int INF=0x7fffffff;

using namespace std;

int h,w;
ll c[10][10]; 
int a[MAXN][MAXN];



void Floyd(){
	for(int k=0;k<=9;k++){
		for(int i=0;i<=9;i++){
			for(int j=0;j<=9;j++){
				c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
			}
		}
	}	
}

ll cnt(){
	ll ans=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(a[i][j]==-1||a[i][j]==1)
				continue;
			ans+=c[a[i][j]][1];
		}
	}
	return ans;
}

int main() {
	
	scanf("%d %d",&h,&w);
	for(int i=0;i<=9;i++){
		for(int j=0;j<=9;j++){
			scanf("%lld",&c[i][j]);
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			scanf("%d",&a[i][j]);
		}
	}
	Floyd();
	printf("%lld", cnt() );
	return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws NumberFormatException 
	 */
	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		
		int[][] matrix = new int[n+1][n+1];
		
		for(int i = 0; i <= n; i++){
			Arrays.fill(matrix[i], 0);
		}
		for(int i = 1 ; i <= n; i++){
			String[] tmpArray = br.readLine().split(" ");
			
			for(int j = 2 ; j < tmpArray.length ; j++){
				int tmp = Integer.parseInt(tmpArray[j]);
				matrix[i][tmp] = 1;
			}
		}
		
		int[] visited = new int[n + 1];
		int[] finished = new int[n + 1];
		Arrays.fill(visited, 0);
		Arrays.fill(finished, 0);
		
		int time = 0;
		for(int i = 1; i <= n ; i++){
			if(visited[i] <= 0){
				time = dfs(matrix, visited, finished, i, time);
			}
		}
		
		for(int i = 1; i <= n ; i++){
			System.out.println(i + " " + visited[i] + " " + finished[i]);
		}
		/*
		for(int i = 1; i <= n; i++){
			for(int j = 1 ; j <= n ; j++){
				if(j == 1){
					System.out.print(matrix[i][j]);
				}
				else {
					System.out.print(" "+matrix[i][j]);
				}
			}
			System.out.println();
		}*/
		
		
	}
	
	static int dfs (int[][] matrix, int[] visited, int[] finished, int v, int time){
		//System.out.println("current vertex is "+v);
		time++;
		visited[v] = time;
		
		int tmpTime = time;
		for(int i = 1; i <= matrix[v].length - 1 ; i++){
			if(matrix[v][i] == 1 && visited[i] <= 0){
				tmpTime = dfs(matrix, visited, finished, i, tmpTime);
			}
		}
		
		finished[v] = tmpTime + 1;
		
		return tmpTime + 1;
	}

}

Measured memory_bytes: 24472
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a+b<c+d){
		cout<<"Right"<<endl;
	}else if(a+b>c+d){
		cout<<"Left"<<endl;
	}else if(a+b==c+d){
		cout<<"Balanced"<<endl;
}
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{
  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
    String s;
    String sl[];

    s = r.readLine();
    sl = s.split(" ");

    int n = Integer.parseInt(sl[0]);
    long k = Long.parseLong(sl[1]);

    int a[][] = new int[200001][63];

    s = r.readLine();
    sl = s.split(" ");
    for(int i = 1; i <= n; i++)
    {
      a[i][0] = Integer.parseInt(sl[i - 1]);
    }

    for(int i = 1; i < 63; i++)
    {
      for(int j = 1; j <= n; j++)
      {
        a[j][i] = a[a[j][i - 1]][i - 1];
      }
    }

    int v = 1;
    for(int i = 0; i < 63; i++)
    {
      if(((1L << i) & k) > 0)
      {
        v = a[v][i];
      }
    }

    System.out.println(v);

  }

}

Measured memory_bytes: 135912
eval'N,C,*D='+`dd`.split*?,
r=*0...C
s,t,u=*(0...N*N).group_by{(_1/N+_1%N)%3}.map{|_,v|r.map{|t|v.sum{D[~-D[~_1]*C+t]}}},0,0
p r.permutation(3).map{s[_1]+t[_2]+u[_3]}.min

Measured memory_bytes: 58376
#include <iostream>
#include <limits.h>
using namespace std;

//3
int main(int argc, const char * argv[]) {
    int N = 0;
    int M = 0;
    
    cin >> N;
    cin >> M;

    int min = INT_MAX;
    int max = 0;
    int tmp = 0;
    for(int i = 0; i < M; i++){
        cin >> tmp;
        if(max < tmp){
            max = tmp;
        }
        cin >> tmp;
        if(min > tmp){
            min = tmp;
        }
    }

    int out = min - max + 1;
    if(out < 0) out = 0;

    cout << out << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    int n, k; cin>>n>>k;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin>>a[i];

    int need=0;

    bool ldp[n+1][k+1];
    memset(ldp, 0, sizeof(ldp));
    ldp[0][0] = true;
    for(int i=0; i<n; i++){
        for(int j=0; j<=k; j++){
            if(j - a[i] >= 0) ldp[i+1][j] |= ldp[i][j-a[i]];
            ldp[i+1][j] |= ldp[i][j];
        }
    }

    bool rdp[n+1][k+1];
    memset(rdp, 0, sizeof(rdp));
    rdp[0][0] = true;
    for(int i=0; i<n; i++){
        for(int j=0; j<=k; j++){
            if(j - a[(n-1)-i] >= 0) rdp[i+1][j] |= rdp[i][j-a[(n-1)-i]];
            rdp[i+1][j] |= rdp[i][j];
        }
    }

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

        vector<int> l, r;
        for(int j=0; j<=k; j++){
            if(ldp[i][j]) l.eb(j);
            if(rdp[n-1-i][j]) r.eb(j);
        }

        for(int j=0; j<l.size(); j++){
            if(lower_bound(r.begin(), r.end(), k-l[j]) - lower_bound(r.begin(), r.end(), k-a[i]-l[j])){
                need++;
                break;
            }
        }
    }

    cout << n - need << endl;
}

Measured memory_bytes: 49152
/*
	Created by : imay_10
	" It won't be EASY, but I'll make it "
*/

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

typedef long long int ll;
const int mod = 1e9+7;
const ll inf = 1e18;
const double pi = 3.1415926535897932384626;

// Utility for fast exponentiation
ll mpow(ll a,ll b,ll m){
    ll res=1;
    //a%=m;
    while(b){
    	if(b%2) res=res*a%m;
		a=a*a%m;
		b/=2;
	}
	return res;
}

// Utility for GCD Calculation
ll gcd(ll a,ll b){
	if(b==0) return a;
	return gcd(b,a%b);
}

void solve(){
	//code
	ll x,count=0;
	double d,p,q;
	cin>>x>>d;
	while(x--){
		cin>>p>>q;
		if((sqrt(p*p+q*q)<=d))
			count++;
	}
	cout<<count;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	solve();
 	return 0;
}


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

int main() {

    int n, m, c;
    cin >> n >> m >> c;
    int b[m];
    int count = 0;
    for (int i=0; i<m; i++) cin >> b[i];
    for (int i=0; i<n; i++) {
        int a;
        int sm = 0;
        for (int j=0; j<m; j++) {
            cin >> a;
            sm += a * b[j];
        }
        if (sm + c > 0) {
            count++;
        }
    }
    cout << count;

}

Measured memory_bytes: 256
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**7)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,k = na()

N = 300000

# N: 処理する区間の長さ
N0 = 2**(N-1).bit_length()
INF = 2**31-1
data = [INF]*(2*N0)
# a_k の値を x に更新
def update(k, x):
    k += N0-1
    data[k] = x
    while k >= 0:
        k = (k - 1) // 2
        data[k] = min(data[2*k+1], data[2*k+2])
# 区間[l, r)の最小値
def query(l, r):
    L = l + N0; R = r + N0
    s = INF
    while L < R:
        if R & 1:
            R -= 1
            s = min(s, data[R-1])

        if L & 1:
            s = min(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s


for i in range(n):
    a = ni()
    s = a-k if a-k > 0 else 0
    e = a+k+1 if a+k+1 < 300001 else 300001
    update(a, min(query(s,e)-1, -1))


print(-query(0,300000))


Measured memory_bytes: 109660
#include<stdio.h>

int main(){
  int num;
  int i,l,k,j;
  int arrayP[101];
  int arrayM[101][101];

  scanf("%d",&num);

  for(i = 1;i <= num;i++){
    scanf("%d %d",&arrayP[i-1],&arrayP[i]);
  }

  for(i = 1;i <= num;i++){
    arrayM[i][i] = 0;
  }

  for(l = 2;l <= num;l++){
    for(i = 1;i <= num - l + 1;i++){
      j = i + l - 1;
      arrayM[i][j] = (1 << 21);

      for(k = i;k <= j - 1;k++){
        if(arrayM[i][j] < arrayM[i][k] + arrayM[k + 1][j] + arrayP[i - 1] * arrayP[k] * arrayP[j]){
        arrayM[i][j] = arrayM[i][j];
      }
      else if(arrayM[i][j] > arrayM[i][k] + arrayM[k + 1][j] + arrayP[i - 1] * arrayP[k] * arrayP[j]){
        arrayM[i][j] = arrayM[i][k] + arrayM[k + 1][j] + arrayP[i - 1] * arrayP[k] * arrayP[j];
      }
      }
    }
  }
  printf("%d\n",arrayM[1][num]);
}



Measured memory_bytes: 2108
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define nmax_def 2200
#define Cmax_def 2200
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;

int main() {
	int H, W;
	cin >> H >> W;
	vector<vb> obs;
	vector<vi> LR;
	vector<vi> UD;
	vector<vi> sum;
	LR.resize(H);
	UD.resize(H);
	sum.resize(H);
	rep(i, H) {
		LR[i].resize(W);
		UD[i].resize(W);
		sum[i].resize(W);
		string S;
		vb obstmp;
		cin >> S;
		rep(j, W) {
			if (S[j] == '#')
				obstmp.push_back(1);
			else
				obstmp.push_back(0);
		}
		obs.push_back(obstmp);
	}
	rep(i, H) {
		int j_obs = -1;
		while (1) {
			int j_obs_nxt = j_obs + 1;
			while (1) {
				if (j_obs_nxt >= W)
					break;
				if (obs[i][j_obs_nxt])
					break;
				j_obs_nxt++;
			}
			for (int j = j_obs + 1; j < j_obs_nxt; j++) {
				LR[i][j] = j_obs_nxt - j_obs - 1;
			}
			if (j_obs_nxt >= W)
				break;
			j_obs = j_obs_nxt;
		}
	}
	rep(j, W) {
		int i_obs = -1;
		while (1) {
			int i_obs_nxt = i_obs + 1;
			while (1) {
				if (i_obs_nxt >= H)
					break;
				if (obs[i_obs_nxt][j])
					break;
				i_obs_nxt++;
			}
			for (int i = i_obs + 1; i < i_obs_nxt; i++) {
				UD[i][j] = i_obs_nxt - i_obs - 1;
			}
			if (i_obs_nxt >= H)
				break;
			i_obs = i_obs_nxt;
		}
	}

	int ans = 0;
	rep(i, H) {
		rep(j, W) {
			sum[i][j] = LR[i][j] + UD[i][j] - 1;
			ans = max(ans, sum[i][j]);
		}
	}
	cout << ans << endl;
	return 0;
}

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

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

typedef long long ll;

signed main()
{
    int R,G,B,N; cin >> R >> G >> B >> N;

    ll ans = 0;
    for (int r = 0; r*R <= N; ++r){
        int remain = N - r*R;
        for (int g = 0; g*G <= N; ++g){
            int remain2 = remain - g*G;
            if (remain2 < 0) continue;
            if (remain2 % B == 0) ++ans;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define MAX_R 100000
using namespace std;
int main(void) {
  int q;
  cin >> q;
  vector<int> l(q), r(q);
  for (int i = 0; i < q; i++) {
    cin >> l[i] >> r[i];
  }
  vector<bool> prime(MAX_R + 1, 1);
  vector<int> count(MAX_R + 1, 0);
  prime[0] = prime[1] = 0;
  for (int i = 2; i * i <= MAX_R; i++) {
    if (prime[i]) {
      for (int j = i * i; j <= MAX_R; j += i) {
        prime[j] = 0;
      }
    }
  }
  for (int i = 3; i <= MAX_R; i++) {
    if (prime[i] && prime[(i + 1) / 2]) {
      count[i] = count[i - 1] + 1;
    } else {
      count[i] = count[i - 1];
    }
  }
  for (int i = 0; i < q; i++) {
    cout << count[r[i]] - count[l[i] - 1] << endl;
  }
  return 0;
}

Measured memory_bytes: 4532
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll N,d,h=0,MOD=998244353,ans=1; cin>>N>>d;
  if(d!=0){cout<<0<<endl; return 0;}
  vector<ll>D(N);
  for(int i=1; i<N; i++){cin>>d; D[d]++; h=max(h,d);}
  if(D[0]!=0){cout<<0<<endl; return 0;}
  for(int i=1; i<h; i++){
    for(int j=0; j<D[i+1]; j++){ans*=D[i]; ans%=MOD;}
  }
  cout<<ans%MOD<<endl;
}

Measured memory_bytes: 1024
import Data.List
import Data.Ord
 
main = interact $ show . sol . get

get = map (map read . words) . lines

sol [[n],as] = if check n (sortBy (flip compare) as) then pow2 (n`div`2) else 0

check n []          = n==0
check n [a]         = n==1 && a==0
check n (a0:a1:as)  = a0==n-1 && a1==n-1 && check (n-2) as

p = 10^9+7 :: Int

pow2 n
  | n == 0    = 1
  | odd n     = 2*r `mod` p
  | otherwise = r
  where
  q = pow2 (n `div` 2)
  r = q*q `mod` p

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

int minof(long int x, long int y)
{
    if (x < y)
        return (x);
    else
        return (y);
}

int main(){
  int n,i;
  long int h,w,m;
  scanf("%d %ld %ld",&n,&h,&w);
    
  m=0;
  
  long int a[n],b[n];
  for (i=0;i<n;i++){
    scanf("%ld %ld",&a[i],&b[i]);
    m=m+minof(a[i]/h,b[i]/w);
  }
  

  printf("%ld",m);
 
}

Measured memory_bytes: 128
import java.util.Scanner;

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

		scan.close();

		int ans = i / 2;
		if (i % 2 == 1) {
			ans += 1;
		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
#define pi 3.141592654
#define EPS 1e-9
#define forr(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a,b) for(int i=a; i<=b;i++)
#define clr(x, val) memset(x, val, sizeof(x))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
const long long modl=1000000007;

//STLS
/*
stack <int > si;
queue < int > qi;
deque <int> dqi;
multiset<int> msi;
set < pair<int, string> > sp;
set < int > s;
map <int, string> m;
iterator;
*/

//map < ll, ll > farr;
int farr[2000000];
int prea[100002];
int preb[100002];
int cuma[2000000];
int cumb[2000000];

//functions
unsigned long long poow(int base, int po);
void swaap(int *a, int *b);

int main()
{
     cin.tie(0);
     cin.sync_with_stdio(0);
    // s :: itr it;
    int n;

    cin >> n;

    signed int arr[n];
    arr[0]=0;

    signed int mini=INT_MAX, maxi=INT_MIN;

    fore(i,1,n)
    {
        cin >> arr[i];
        mini=min(mini,arr[i]);
        maxi=max(maxi,arr[i]);
    }

    int res=INT_MAX;

    for(int i=mini; i <= maxi; i++)
    {
        int sum=0;

        fore(j,1,n)
        {
            sum+=( (arr[j]-i)*(arr[j]-i) );
        }

        res=min(res,sum);
    }

    cout << res;

     return 0;
}

unsigned long long poow(int base, int po)
{
    // take modelus of base in main
    if(po == 0)
        return 1;
    if(po == 1)
        return base;

    unsigned long long ans = poow(base, po/2);
    ans = (ans * ans) /* % modl */;

    if(po & 1)
       return (ans * base) /* % modl */ ;

    return ans  ;
}

void swaap(int *a, int *b)
{
	//send addresses from the main
	int temp;
	temp = *a;
	*a = *b;
	*b = temp;
}


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

const long long MAX_N = 100001;

long long prime[MAX_N]; // i番目の素数
bool is_prime[MAX_N + 1]; // is_prime[i]がtrueならiは素数
long long like[MAX_N + 1]; // i以下のlike numberの数

// n以下の素数の数を返す
long long sieve(long long n) {
	long long p = 0;
	for (long long i = 0; i <= n; i++) is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;
	for (long long i = 2; i <= n; i++) {
		if (is_prime[i]) {
			prime[p++] = i;
			for (long long j = 2 * i; j <= n; j += i) is_prime[j] = false;
		}
	}
	return p;
}
int main(){	
	long long N;
	scanf("%lld",&N);
	sieve(55555*5);
	vector<long long> res(N);
	int count = 0;
	for (long long i = 2; i <= 55555*5; i++) {
		if (is_prime[i]) {
			if (i%5 == 1) {
				res[count] = i;
				count++;
			}
		}
		if (count == N) break;
	}

	for (int i=0; i<N-1; i++) {
		cout << res[i] << " ";
	}
	cout << res[N-1] << endl;
	return 0;
}



Measured memory_bytes: 896
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int a, b, i, c;
	
	while(cin >> a >> b){
	
	i = 0;

	c = a + b;
	
	while(c > 0){
		
		c /= 10;
		
		i++;
	}
		cout << i << endl;
	}
	
    return 0;
}

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

typedef long long int llint;

int main()
{
  int n[4];
  cin>> n[0] >> n[1] >> n[2];

  sort(n, n + 3);

  int sum = 0;
  for(int i = 1; i < 3; i++) sum += abs(n[i] - n[i - 1]);

  cout<< sum <<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define NL            "\n"
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    string s;
    cin>>s;
    s[3]='8';
    cout<<s<<NL;
    return 0;
}


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

using namespace std;

void debug_out() { cerr << endl; }
template <typename H, typename... T> void debug_out(H h, T... t) {  cerr << " " << (h);  debug_out(t...); }
void read() {}
template <typename H, typename... T> void read(H &h, T&... t) { cin >> h; read(t...) ;}

#ifndef LOCAL
#define endl '\n'
#define debug(...) //
#else
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#endif


void solve() {
  int n, a;
  read(n, a);
  while (n >= 500) {
    n -= 500;
  }
  puts(n <= a ? "Yes" : "No");
}

int main() {
#ifndef LOCAL
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif
  //int tc; cin >> tc;
  //while (tc--)
    solve();
  return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define rn return
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;


int main(){
    int A,B; cin >> A >> B;
    cout << (A*B%2 == 0? "No":"Yes");
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    ll N;
    cin >> N;
    vector<ll> a(3 * N);
    rep(i, 3 * N) cin >> a[i];
    vector<ll> pre(N + 1), suf(N + 1);
    priority_queue<ll, vector<ll>, greater<ll>> pq1;
    priority_queue<ll> pq2;

    ll pre_sum = 0;
    ll suf_sum = 0;

    rep(i, N) {
        pre_sum += a[i];
        pq1.push(a[i]);
    }
    pre[0] = pre_sum;
    for(int i = N; i < 2 * N; i++) {
        pre_sum += a[i];
        pq1.push(a[i]);
        pre_sum -= pq1.top();
        pq1.pop();
        pre[i - N + 1] = pre_sum;
    }

    for(int i = 3 * N - 1; i >= 2 * N; i--) {
        suf_sum += a[i];
        pq2.push(a[i]);
    }
    suf[N] = suf_sum;
    for(int i = 2 * N - 1; i >= N; i--) {
        suf_sum += a[i];
        pq2.push(a[i]);
        suf_sum -= pq2.top();
        pq2.pop();
        suf[i - N] = suf_sum;
    }
    ll res = -LINF;
    rep(i, N + 1) { res = max(res, pre[i] - suf[i]); }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 6516
#include<stdio.h>
#include<string.h>
int main(){
	char str[101]="";
	char in[100];
	int i;
	while(~scanf("%s",in)){
		int len=strlen(in);
		str[0]='\0';
		for(i=0;i<len;i++){
			if(in[i]!='@'){
				char cat[2]="a";
				cat[0]=in[i];
				strcat(str,cat);
			}else{
				int j;
				char cat[50]="";
				for(j=0;j<in[i+1]-'0';j++){
					cat[j]=in[i+2];
				}
				cat[in[i+1]]='\0';
				strcat(str,cat);
				i+=2;
			}
		}
		puts(str);
	}
	
	return 0;
}

Measured memory_bytes: 532
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<cmath>
#include<ctime>
#include<locale>
using namespace std;
long a[51];
long long S;
long long fx(long long a)
{
    long long c=a,b=1;
    for(long i=1;i<=a;i++)b*=i;
    return b;
}
long long C(long long n,long long m)
{
    long long b[51];for(long i=0;i<=50;i++)b[i]=i;
    for(long long i=1;i<=min(m,n-m);i++)
    {
        for(long long j=n-min(m,n-m)+1;j<=n;j++)
        if(b[j]%b[i]==0){b[j]/=b[i];b[i]=1;break;}
    }
    long long S=1;
    for(long i=n-min(m,n-m)+1;i<=n;i++)S*=b[i];
    for(long i=1;i<=min(m,n-m);i++)S/=b[i];
    return S;
}
int main()
{
    long long n,p;
    long long x1=0,x0=0;
    cin>>n>>p;
    for(long long i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]%2==0)x0++;
        if(a[i]%2==1)x1++;
    }
    long long b=pow(2,x0);
    S=0;
    //cout<<x1<<' '<<x0<<endl;
    for(long long i=p;i<=x1;i+=2)
    {
        S+=C(x1,i);
        //cout<<C(x1,i)<<endl;
    }
    //cout<<S<<' '<<b<<endl;
    cout<<(long long)S*(long long)b;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;

int main(){
  int a, b, c, k;
  cin >> a >> b >> c >> k;

  int cnt = 0;
  while(a >= b){
    b *= 2;
    cnt++;
  }
  while(b >= c){
    c *= 2;
    cnt++;
  }

  cout << (cnt <= k ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 3620
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define EPS 1e-10
using namespace std;
typedef long long llong;
int main() {
	int n;
	while (cin >> n, n) {
		for (int j = 0; j < n; j++) {
			vector<int>a(4), b(4), c(4);
			for (int i = 0; i < 4; i++)cin >> a[i];
			for (int i = 0; i < 4; i++)cin >> b[i];
			c[0] = a[0] * b[0] - a[1] * b[1] - a[2] * b[2] - a[3] * b[3];
			c[1] = a[0] * b[1] + a[1] * b[0] + a[2] * b[3] - a[3] * b[2];
			c[2] = a[0] * b[2] - a[1] * b[3] + a[2] * b[0] + a[3] * b[1];
			c[3] = a[0] * b[3] + a[1] * b[2] - a[2] * b[1] + a[3] * b[0];
			for (int i = 0; i < 4; i++) {
				if (i)cout << " ";

				cout << c[i];
			}
			cout << endl;
		}
	}
	return 0;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n, 0);
    REP(i, n)
    {
        cin >> a[i];
    }

    sort(a.begin(), a.end());
    int ansN = a[n - 1];
    int diff = ansN;
    int ansR;
    REP(i, n - 1)
    {
        if (diff >= abs(ansN - 2 * a[i]))
        {
            diff = abs(ansN - 2 * a[i]);
            ansR = a[i];
        }
        else
        {
            break;
        }
    }

    cout << ansN << " " << ansR << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, Q; cin >> N >> Q;
    string str; cin >> str;

    // 累積和
    vector<int> s(N+1, 0);
    for (int i = 0; i < N; ++i) {
        if (i+1 < N && str[i] == 'A' && str[i+1] == 'C') s[i+1] = s[i] + 1;
        else s[i+1] = s[i];
    }

    // クエリ
    for (int q = 0; q < Q; q++) {
        int l, r; cin >> l >> r;
        --l, --r;
        cout << s[r] - s[l] << endl;
    }
    return 0;
}


Measured memory_bytes: 1488
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

#define fo(i,j,l) for(int i=j;i<=l;i++)
#define fd(i,j,l) for(int i=j;i>=l;i--)

using namespace std;
typedef long long ll;
typedef double db;
const ll N=66e4,maxn=1e12;
ll a[N],b[N],f[N],g[N],h[N],t[N],dd[N];
int top,n,m,j,k,l,i,c; 
ll F[N],G[N],d[N],bb;

double xl(ll a,ll b)
{return (F[a]-F[b])/(a-b*1.0);}

double xx(ll a,ll b)
{return (G[a]-G[b])/(a-b*1.0);}

ll max(ll a,ll b)
{return a>b?a:b;}

void ef(int l,int r,int f)
{
	if(l==r)return;
	int k=0,mid=(l+r)/2;
	fo(i,mid+1,r){
    	while(k-1&&xx(d[k],i)>=xx(d[k-1],d[k]))k--;
    	d[++k]=i;
	}
	t[l-1]=-maxn;
	fo(i,l,mid){
		while(k-1&&xx(d[k-1],d[k])<=i)k--;
		t[i]=max(t[i-1],F[i]+G[d[k]]-i*d[k]);
	}
	if(f==0)fo(i,l,mid)h[i]=max(h[i],t[i-1]);
	else fo(i,l,mid)h[n-i+1]=max(h[n-i+1],t[i-1]);
	ef(l,mid,f); ef(mid+1,r,f);
}

int main()
{
	cin>>n;
	fo(i,1,n)scanf("%lld",&a[i]),b[i]=b[i-1]+a[i];
	int t;
	d[t=1]=0;
	fo(i,1,n){
		while(t-1&&xl(d[t-1],d[t])<i)t--;
		f[i]=max(f[i-1],f[d[t]]+(ll)(i-d[t])*(i-d[t]+1)/2-b[i]+b[d[t]]);
		F[i]=f[i]+(ll)(i-1)*(ll)i/2+b[i];
		while(t-1&&xl(d[t],i)>=xl(d[t-1],d[t]))t--;
		d[++t]=i;
	}
	d[t=1]=0;
	fo(i,1,n)b[i]=b[i-1]+a[n-i+1];
	fo(i,1,n){
		while(t-1&&xl(d[t-1],d[t])<=i)t--;
		g[i]=max(g[i-1],g[d[t]]+(ll)(i-d[t])*(i-d[t]+1)/2-b[i]+b[d[t]]);
		F[i]=g[i]+(ll)(i-1)*(ll)i/2+b[i];
		while(t-1&&xl(d[t],i)>=xl(d[t-1],d[t]))t--;
		d[++t]=i;
	}
	fo(i,1,n/2)swap(g[i],g[n-i+1]);
	fo(i,1,n+1)dd[i]=f[i-1]+g[i+1],b[i]=b[i-1]+a[i];
	fo(i,0,n+1)F[i]=f[i]+(ll)i*(i+1)/2+b[i],G[i]=g[i]+(ll)i*(i-1)/2-b[i-1];
	fo(i,1,n)h[i]=-maxn;
	ef(0,n+1,0);
	fo(i,1,n+1)swap(f[i],g[i]),b[i]=b[i-1]+a[n-i+1];
	fo(i,1,n/2)swap(f[i],f[n-i+1]),swap(g[i],g[n-i+1]);
	fo(i,0,n+1)F[i]=f[i]+(ll)i*(i+1)/2+b[i],G[i]=g[i]+(ll)i*(i-1)/2-b[i-1];
	ef(0,n+1,1); 
	cin>>m;
	fo(i,1,m){
		scanf("%d%lld",&c,&bb);
		ll ans=max(dd[c],h[c]-(bb-a[c]));
		printf("%lld\n",ans);
	}
}

Measured memory_bytes: 39424
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

	Integer n = null;
	String a = null;
	String b = null;
	String c = null;
	boolean err = false;
    Scanner scan = new Scanner(System.in);

	try {
		n = Integer.parseInt(scan.nextLine());
		a = scan.nextLine();
		b = scan.nextLine();
		c = scan.nextLine();
	}
	catch (Exception e) {
		System.out.println("不正な入力が含まれています。");
		err = true;
	}

	if (n != a.length() || n != b.length() || n != c.length()) {
		System.out.println("入力が不正です。");
		err = true;
	}

	if (err == false) {
		// 3つの配列の比較
		int max = n * 2;
		String[] arrayA = a.split("");
		String[] arrayB = b.split("");
		String[] arrayC = c.split("");

		for(int i = 0; i < n; i++) {
			if (arrayA[i].equals(arrayB[i]) && arrayA[i].equals(arrayC[i])) {
				max = max - 2;
			}
			else if (arrayA[i].equals(arrayB[i])){
				max = max - 1;
			}
			else if (arrayA[i].equals(arrayC[i])){
				max = max - 1;
			}
			else if(arrayB[i].equals(arrayC[i])){
				max = max - 1;
			}
		}

		System.out.println(max);

	}

	}
}


Measured memory_bytes: 23764
import sys
input=sys.stdin.readline
n=int(input())
ab=[list(map(int,input().split())) for _ in range(n)]
for i in range(n):
    ab[i].append(ab[i][0]+ab[i][1])
ab.sort(key=lambda x:x[2],reverse=True)
ta=0
ao=0
for i in range(n):
    if i%2==0:
        ta+=ab[i][0]
    else:
        ao+=ab[i][1]

print(ta-ao)


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

#define ll long long
#define fr(i,n) for(i=0;i<n;i++)
#define frs(i,a,n) for(i=a;i<n;i++)
#define frv(i,n) for(i=n-1;i>=0;i--)

#define ne cout<<"\n";
#define cas(i) cout<<"Case #"<<i<<": "

#define vpi vector <pair <int,int> >
#define vpin(v,a,b) v.push_back(make_pair(a,b))
#define vsort(v) sort(v.begin(),v.end());
#define siz 1000005
bool prm[siz+5];
ll lis[siz+5];
ll pr=0;
void sieve()
{
    ll i,n,j;
    pr=0;
    memset(prm,true,sizeof(prm));

    for(i=2;i*i<=siz;i++)
    {
        if(prm[i])
        {
            for(j=i*i;j<siz;j+=i)
                prm[j] = false;
        }
    }
    for(i=2;i<siz;i++){
        if(prm[i]) {
                lis[pr++]=i;

        }
    }

}
ll lisi[100];
void gen()
{
    ll i,n,x=0,r=0;
    for(i=0;x<=40;i++)
    {
        x+=(++r);
        lisi[i]=x;
//        cout<<i<<" "<<lisi[i]<<"\n";
    }
}
int dis(int a, int b)
{
    if(a-b<0) return b-a;
    return a-b;
}
ll sol(ll n)
{
    ll j,i,pp,x,cnt=0,an=0;
    pp=0;
    for(i=lis[pp];i*i<=n;)
    {
        if(n%i==0)
        {
            cnt=0;
            while(n%i==0&&n>1)
            {
                n/=i;
                cnt++;
            }
            for(j=0;j<9;j++)
            {
                if(cnt==lisi[j]) {
                        an+=(j+1);
                        break;
                }
                else if(cnt<lisi[j]) {
                        an+=j;
                        break;
                }
            }
        }
        i=lis[pp++];
      	if(pp>=pr) break;
    }
    if(n>1) an++;
    return an;
}
int main()
{
    sieve();
    gen();
    ll n;
    cin>>n;
    cout<<sol(n)<<"\n";

    return 0;
}


Measured memory_bytes: 5228
n,m,k = map(int,input().split())
mod = 998244353
fact = [1]*(n+1)
for i in range(1,n+1):
    fact[i] = fact[i-1]*i
    fact[i] %= mod
    
fact_inv = [1]*(n+1)
fact_inv[-1] = pow(fact[-1],mod-2,mod)
for i in range(n,0,-1):
    fact_inv[i-1] = fact_inv[i]*i
    fact_inv[i-1] %= mod
    
ans = 0
for i in range(k+1):
    ans += m*pow(m-1,n-1-i,mod)*fact[n-1]*fact_inv[n-1-i]*fact_inv[i]
    ans %= mod

print(ans)

Measured memory_bytes: 24712
#include <bits/stdc++.h>		
using namespace std;
typedef long long int lli;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


int main()
{
   fastio
   double s;
   cin>>s;
   double length = s/3;
   s-=length; 
   double breadth = s/2; 
   double height = s - breadth; 
   double ans = length * breadth * height;
   cout <<fixed;
   cout <<setprecision(10);
   cout<<ans<<'\n';
   return 0;
}





Measured memory_bytes: 256
N = int(input())
max_item = 0
sum_item = 0
i = 0

while N > i:                  
    c = int(input())                
    sum_item += c                   
    max_item = max(c, max_item)     
    i += 1

sum_item -= max_item // 2           
print(sum_item)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define enld endl

int main() {
	lint A, B;
	while (cin >> A >> B) {
		cout << A + B << endl;
	}
}


Measured memory_bytes: 2996
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };



int n, m;
int dpru(int* c, int* v)
{
	int dp[333][333];
	CLEAR(dp, 0);
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j <= m; ++j)
		{
			dp[i + 1][j] = dp[i][j];
			if (j >= c[i])
				max_swap(dp[i + 1][j], dp[i + 1][j - c[i]] + v[i]);
		}
	}
	return dp[n][m];
}
int main()
{
	while (cin >> n >> m)
	{
		int c[333], v[3][333];
		rep (i, n)
		{
			string s;
			int t;
			getline(cin, s);
			getline(cin, s);
			cin >> t;
			c[i] = t;
			rep (j, 3)
				cin >> v[j][i];
		}
		int res = 0;
		rep (i, 3)
			max_swap(res, dpru(c, v[i]));
		cout << res << endl;
	}
}

Measured memory_bytes: 1364
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define max_v(v) *max_element(all(v));
#define min_v(v) *min_element(all(v));
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl
template <typename T> istream& operator >> (istream& is, vector<T>& vec) {
    for(T& x : vec) is >> x;
    return is;
}
template<typename T> ostream& operator << (ostream& os, vector<T>& vec) {
    for(int i = 0; i < vec.size(); i++) {
        os << vec.at(i) << (i + 1 == vec.size() ? "" : " ");
    }
    return os;
}

int main() {
    int x, cnt;

    rep(i, 5) {
        cin >> x;
        if (x == 0) cnt = i + 1;
    }
    

    cout << cnt << endl;
}

Measured memory_bytes: 3624
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();
    int[] a = new int[n];
    double sum = 0;
    for(int i = 0 ; i < n ; i++){
      a[i] = sc.nextInt();
      sum += a[i];
    }
      double min = sum / (4 * m);
      int num = n;
      for(int i = 0 ; i < n ; i++){
        if(a[i] < min)
          num--;
    }
    
      
	
	System.out.println(num >= m ? "Yes" : "No");
	}
}

Measured memory_bytes: 35716
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
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; }
 
const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
 
inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}
 
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int N,A,B,C;
vi L;
int rec(int i, int a, int b, int c){
  if(i==N){
    if(!a||!b||!c) return INF;
    return abs(A-a)+abs(B-b)+abs(C-c);
  }
  int res=rec(i+1,a,b,c);
  
  chmin(res,rec(i+1,a+L[i],b,c)+(a?10:0));
  chmin(res,rec(i+1,a,b+L[i],c)+(b?10:0));
  chmin(res,rec(i+1,a,b,c+L[i])+(c?10:0));
  
  return res;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  int k,s; cin>>k>>s;
  int ans=0;
  rep(i,k+1){
    rep(j,k+1){
      int z=s-i-j;
      if(z>=0&&z<=k) ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 384
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


from collections import defaultdict
n,m = map(int, input().split())
ns = defaultdict(set)
es = set()
for _ in range(m):
    u,v = map(int, input().split())
    u -= 1
    v -= 1
    ns[u].add(v)
    es.add((u,v))

### サイクル検出 cycle detection

seen = [False] * n
done = [False] * n
hist = []
def dfs(u, pos):
    # uからdfs
    seen[u] = True
    hist.append(u)
    for v in ns[u]:
        if done[v]:
            continue
        elif seen[v]:
            # サイクルを検出
            pos = v
            return pos
        else:
            pos = dfs(v, pos)
            if pos>=0:
                return pos
    done[u] = True
    hist.pop()
    return pos

# サイクル復元
def cycle(hist, pos):
    for i, u in enumerate(hist):
        if u==pos:
            break
    return hist[i:]
# 極小サイクルを復元
def sub(hist):
    s = set(hist)
    ss = set((hist[i],hist[i+1]) for i in range(len(hist)-1))
    ss.add((hist[len(hist)-1], hist[0]))
    l = None
    for u,v in es:
        if u in s and v in s and (u,v) not in ss:
            l = []
            for i,k in enumerate(hist):
                if k==v:
                    break
            for j in range(i,len(hist)):
                l.append(hist[j])
                if hist[j]==u:
                    break
            else:
                for j in range(len(hist)):
                    l.append(hist[j])
                    if hist[j]==u:
                        break
#     print(hist, l, i, u,v,ss)
    if l is None or len(l)==len(hist):
        return hist
    else:
        return sub(l)
ans = None
for u in range(n):
    pos = dfs(u, -1)
    if pos>=0:
        hist = cycle(hist, pos)
        ans = sub(hist)
        break
if ans is None:
    print(-1)
else:
    print(len(ans))
    write("\n".join(map(lambda x: str(x+1), ans)))

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    cin >> N;
    
    vec A = {1, 6, 6*6, 6*6*6, 6*6*6*6, 6*6*6*6*6, 6*6*6*6*6*6, 9, 9*9, 9*9*9, 9*9*9*9, 9*9*9*9*9};
    vec dp(N+1, INF);
    dp[0] = 0;
    REP(i,1,N+1) {
        REP(j,0,SZ(A)) {
            if(i >= A[j]) dp[i] = MIN(dp[i],dp[i-A[j]]+1);
        }
    }
    PR(dp[N]);

    return 0;
}

/*



*/

Measured memory_bytes: 3972
var dx = [1,1,1,0,0,-1,-1,-1];
var dy = [1,0,-1,1,-1,1,0,-1];

function judge(s,turn,ii,jj){
    var sum = 0;
    for(var i = 0;i < 8;i++){
        var su = 0;
        var x = jj + dx[i],y = ii + dy[i];
        while(x > 0 && x < 9 && y > 0 && y < 9){
            if(s[y][x] == turn){sum += su;break;}
            else if(s[y][x] == turn * (-1))su++;
            else
                break;
            x += dx[i];y += dy[i];
        }
    }
    return sum;
}

function put(s,turn,ii,jj){
    for(var i = 0;i < 8;i++){
        var su = 0;
        var x = jj + dx[i],y = ii + dy[i];
        var flag = false;
        while(x > 0 && x < 9 && y > 0 && y < 9){
            if(s[y][x] == turn){flag = true;break;}
            else if(s[y][x] == turn * (-1))su++;
            else
                break;
            x += dx[i];y += dy[i];
        }
        if(flag){
            var x = jj + dx[i],y = ii + dy[i];
            for(var j = 0;j < su;j++){
                s[y][x] = turn;
                x += dx[i];y += dy[i];
            }
        }
    }
    s[ii][jj] = turn;
}



function Main(input){
    input = input.split("\n");
    var s = [];
    for(var i = 1;i <= 8;i++){
        s[i] = [];
    }

    var fin = 0;

    for(var i = 1;i <= 8;i++){
        for(var j = 1;j <= 8;j++){
            if(input[i - 1][j - 1] == 'o'){
                fin++;
                s[i][j] = 1;
            }
            else if (input[i - 1][j - 1] == 'x'){
                fin++;
                s[i][j] = -1;
            }
            else
                s[i][j] = 0;
        }
    }

    var turn = 1;var aaa = false;

    while(fin < 64){
        var maxi = 0,imax = -1,jmax = -1;
        if(turn == 1){
            for(var i = 1;i <= 8;i++){
                for(var j = 1;j <= 8;j++){
                    if(s[i][j] == 0){
                        var a = judge(s,turn,i,j);
                        if(a > maxi){
                            maxi = a;imax = i;jmax = j;
                        }
                    }
                }
            }
        }else{
            for(var i = 1;i <= 8;i++){
                for(var j = 1;j <= 8;j++){
                    if(s[i][j] == 0){
                        var a = judge(s,turn,i,j);
                        if(a >= maxi){
                            maxi = a;imax = i;jmax = j;
                        }
                    }
                }
            }
        }

        if(maxi > 0){
            aaa = false;
            fin++;
            put(s,turn,imax,jmax);
        }else{
            if(aaa)
                break;
            aaa = true;
        }
        turn *= (-1);
    }

    for(var i = 1;i <= 8;i++){
        var ans = "";
        for(var j = 1;j <= 8;j++){
            if(s[i][j] == 1)
                ans += 'o';
            else if(s[i][j] == (-1))
                ans += 'x';
            else
                ans += '.';
        }
        console.log(ans);
    }
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 15864
#include <stdio.h>
#include <math.h>

double cal(double q, double x);

int main(void) {
	double q;
	while (1) {
		scanf("%lf", &q);
		if (q == -1.0)
			break;
		printf("%lf\n", cal(q, q/2.0));
	}

	return 0;
}

double cal(double q, double x) {
	x = x - (x*x*x-q)/(3*x*x);
	if (fabs(x*x*x-q) >= 0.00001*q)
		x = cal(q, x);
	return x;
}

Measured memory_bytes: 648