akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N >> K;
	double ans = 0.0;
	rep(i, N) {
		int s = i + 1;
		double p = 1;
		while (s < K) {
			s *= 2;
			p *= 0.5;
		}
		ans += 1.0 / N * p;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	N := nextInt()
	if N%1000 == 0 {
		fmt.Fprintf(out, "0\n")
	} else {
		fmt.Fprintf(out, "%d\n", 1000-N%1000)
	}
}


Measured memory_bytes: 1812
# -*- coding: utf-8 -*-
"""

"""



if __name__ == '__main__':
    n = int(input())
    nums = [int(x) for x in input().split(' ')]
    data = [nums[x]==x+1 for x in range(len(nums))]

    flipped = 0
    prev_d = data[0]
    for x, d in enumerate(data[1:], start=1):
        if d == True:
            if prev_d == True:
                data[x] = False
                data[x-1] = False
                flipped += 1
                prev_d = False
            else:
                prev_d = True
        else:
            prev_d = False
    flipped += data.count(True)
    print(flipped)


Measured memory_bytes: 13880
N = int(input())
dp = []
AL = 'abcdefghijklmn'
dp.append(['a'])
if N == 1:
    print('a')
else:
    for i in range(2, N+1):
        tmp = []
        for l in dp[-1]:  # l = [['a', 'a'], ['a', 'b']]
            n = len(set(l))
            for i in range(n+1):
                tmp.append(l + AL[i])
        dp.append(tmp)

    for s in dp[N-1]:
        print(s)


Measured memory_bytes: 56284
import java.util.Scanner;

public class Main {

    public static double Average(int[] S, int N){
        double Sum = 0.0;
        for(int i = 0; i < N; i++){
            Sum += S[i];
        }
        Sum /= N;
        return Sum;
    }

    public static void main(String[] args){
       Scanner sc = new Scanner(System.in);
       while(true){
        int n = sc.nextInt();
        if(n == 0){
            break;
        }
        int[] Score = new int[n];
        for(int i = 0; i < n; i++){
            Score[i] = sc.nextInt();
        }
        double Ave = Average(Score, n);
        double ScoreSum = 0.0;
        for(int i = 0; i < n; i++){
            ScoreSum += (Score[i] - Ave) * (Score[i] - Ave);
        }
        ScoreSum /= n;
        System.out.println(Math.sqrt(ScoreSum));
       }
       sc.close(); 
    }
}


Measured memory_bytes: 31308
#include<stdio.h>
#include<string.h>
#define LEN 4000000
#define NIL -1

int trance_command(char []);
void insert(int);
void print();
void inorder(int);
void preorder(int);

int P[LEN], L[LEN], R[LEN], Key[LEN];
int root=NIL;

int main()
{
  char command[10];
  int n, id;
  int z=0;
  int i, j, k;

  //intelization
  for(i=0; i<LEN; i++)
    {
      P[i]=NIL;
      L[i]=NIL;
      R[i]=NIL;
      Key[i]=NIL;
    }

  //read
  scanf("%d", &n);
  for(i=0; i<n; i++)
    {
      scanf("%s", command);
      if(trance_command(command)==0)
	{
	  scanf("%d", &id);
	  Key[z]=id;
	  insert(z);
	  z++;
	}
      else
	{
	  inorder(root);
	  printf("\n");
	  preorder(root);
	  printf("\n");
	}
    }

  return 0;
}


//-------------------------
int trance_command(char c[])
{
  if(strcmp(c, "insert")==0)return 0;
  else if(strcmp(c, "print"))return 1;
}

void insert(int z)
{
  int y=NIL;
  int x=root;

  while(x!=NIL)
    {
      y = x;
      if(Key[z]<Key[x])x = L[x];
      else x = R[x];
    }
  P[z]=y;

  if(y==NIL)root=z;
  else if(Key[z]<Key[y])L[y]=z;
  else R[y]=z;
}

void inorder(int t)
{
  if(t!=NIL)
    {
      inorder(L[t]);
      printf(" %d", Key[t]);
      inorder(R[t]);
    }
}

void preorder(int t)
{
  if(t!=NIL)
    {
      printf(" %d", Key[t]);
      preorder(L[t]);
      preorder(R[t]);
    }
}

Measured memory_bytes: 61000
l = input()
dpf = [0] * (len(l) + 2)
dpf[len(l)-1] = 3
mod = 1000000007
for i in range(len(l)-2, -1, -1):
    dpf[i] = (3 * dpf[i+1]) % mod
#print(dpf)
# def dfs(i):
#     if i == len(l)-1:
#         if l[i] == '1':
#             return 3
#         else:
#             return 1
#     if l[i] == '0':
#         return dfs(i+1)
#     return (dpf[i+1] + (dfs(i+1) * 2) % mod) % mod
#
# print(dfs(0))

dp = [0] * (len(l))
dp[-1] = 1
if l[-1] == '1':
    dp[-1] = 3
for i in range(len(l)-2, -1, -1):
    if l[i] == '0':
        dp[i] = dp[i+1]
    else:
        dp[i] = (dpf[i+1] + (dp[i+1]*2)%mod)%mod
print(dp[0])

Measured memory_bytes: 41424
/*
 *  Created on: 24-May-2019
 *      Author: ankur314
 */
#include<bits/stdc++.h>
#define lli long long int 
#define li long int
#define db double 
#define ldb long double
#define vr vector 
#define it iterator
#define fi(i,a,n) for(int i=a;i<n;i++)
#define fli(i,a,n) for(long int i=a;i<n;i++)
#define flli(i,a,n) for(long long int i=a;i<n;i++)
#define pb(n) push_back(n)
#define ppf() pop_front()
#define pii pair<int,int>
#define MOD 1000000007
 
#define debug1(x) cout<<x<<"\n"
#define debug2(x,y) cout<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define debug4(x,y,z,w) cout<<x<<" "<<y<<" "<<z<<" "<<w<<"\n"
 
using namespace std;
 
int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    /*freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);*/
    int n;cin>>n;
    db dp[n+1];
  	memset(dp,0,sizeof(dp));
    dp[0] = 1;
    for(int coin = 0; coin < n; ++coin) {
        double p_heads;
        cin>>p_heads;
        for(int i = coin + 1; i >= 0; --i) {
            dp[i] = (i == 0 ? 0 : dp[i-1] * p_heads) + dp[i] * (1 - p_heads);
        }
    }
    db ans=0;
    for(int heads = 0; heads <= n; ++heads) {
        int tails = n - heads;
        if(heads > tails) {
            ans += dp[heads];
        }
    }
    cout<<fixed<<setprecision(10)<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int n,A[50];

int solve(int i,int m){
	if(m==0) return 1;
	if(i>=n) return 0;
	int res=solve(i+1,m)||solve(i+1,m-A[i]);
	return res;
}

int main(){
	int q,M,i;
	scanf("%d",&n);
	for(i=0;i<n;i++) scanf("%d",&A[i]);
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d",&M);
		if(solve(0,M)) printf("yes\n");
		else printf("no\n");
	}
	return 0;
}



Measured memory_bytes: 2696
n,k = gets.split.map(&:to_i)
a = [1]
99.times{
  a << a[-1]*2
}

ans = 0
(1..n).each{|i|
  a.each.with_index{|x,j|
    if i*x >= k
      ans += 1.0/x/n
      break
    end
  }
}

p ans


Measured memory_bytes: 1916
#include<stdio.h>

int main() {
	int r,c,i,j;
	
	scanf("%d %d",&r,&c);
	int data[r+1][c+1];
	for(i = 0;i < r;i++) {
		for(j = 0;j < c; j++) {
			scanf("%d",&data[i][j]);
		}
	}
	for(i = 0;i < r;i++) {
		data[i][c] = 0;
		for(j = 0;j < c;j++) {
			data[i][c] += data[i][j];
		}
	}
	for(j = 0;j <= c;j++) {
		data[r][j] = 0;
		for(i = 0;i < r;i++) {
			data[r][j] += data[i][j];
		}
	}
	for(i = 0;i <= r;i++) {
		for(j = 0; j <= c;j++) {
			printf("%d",data[i][j]);
			if(j != c) {
				printf(" ");
			}
		}
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const long long int MAX_N = 100000;

int main(int argc, char const *argv[]) {
  long long int n;
  vector<long long int> vec(MAX_N,0);
  cin >> n;
  vec.resize(n);
  for (size_t i = 0; i < n; i++) cin >> vec[i];

  vector<long long int> ans, fans;

  sort(vec.begin(),vec.end());
  for (size_t i = 0; i < vec.size(); ) {
    vector<long long int>::iterator lb = lower_bound(vec.begin(), vec.end(), vec[i]), ub = upper_bound(vec.begin(), vec.end(),vec[i]);
    if ((ub-lb)>=4) fans.push_back(vec[i]);
    if ((ub-lb)>=2) ans.push_back(vec[i]);
    i = ub-vec.begin();
  }
  
  if (ans.size() >= 2 and fans.size() >0) cout << max(fans[fans.size()-1]*fans[fans.size()-1],ans[ans.size()-1]*ans[ans.size()-2]) << endl;
  else if (ans.size() >= 2 and fans.size()==0) cout << ans[ans.size()-1]*ans[ans.size()-2] << endl;
  else if (ans.size() < 2 and fans.size() > 0) cout << fans[fans.size()-1]*fans[fans.size()-1] << endl;
  else cout << 0 << endl;
  return 0;
}


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

long long cl(long long a,long long b,long long n){
  long long na=a+(b-a%b);
  if(na/b>n){
    na=n*b;
    return abs(a-na);
  }else{
    long long na2=a-a%b;
    if(na2==0) return abs(a-na);
    return min(abs(a-na),abs(a-na2));
  }
}


int main(){
  long long a,b,n;
  long long ans = 1e12;
  cin>>a>>b>>n;
  for(long long i=1;i*i<=b;i++){
    if(b%i) continue;
    if(b/i<=n){
      long long  c=cl(a,i,n);
      if(c<ans) ans=c;
    }
    if(b/(b/i)<=n){ 
      long long d=cl(a,b/i,n);
      if(d<ans) ans=d;
    }
  }
  cout<<ans<<endl;

  return 0;
}

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

#define INPUT freopen("input.txt", "r", stdin);

#define ll long long
#define ld long double

int main()
{
    //INPUT;

    ld n, x, t;
    cin >> n >> x >> t;

    ld tm = ceil(n / x);

    ll ans = tm * t;

    cout << ans << endl;
}

Measured memory_bytes: 3656
def colorful_transceivers(
        a: int, b: int, c: int, d: int) -> bool:
    return (abs(a-b) <= d and abs(b-c) <= d) or abs(a-c) <= d


if __name__ == "__main__":
    a, b, c, d = map(int, input().split())
    yes = colorful_transceivers(a, b, c, d)
    print('Yes' if yes else 'No')


Measured memory_bytes: 2940
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll

map<int, pair<int, int>>  mapping[2];
int tate[2][500];
int yoko[2][500];
int cross[2][2];

void solve() {
	int n, u, v, m;
	cin >> n >> u >> v >> m;
	REP(i, 2) {
		REP(q, n) {
			REP(j, n) {
				int a;
				cin >> a;
				mapping[i][a] = mp(q, j);
			}
		}
	}
	if (n == 1) {
		u *= 4;
		v *= 4;
	}
	REP(i, m) {
		int a;
		cin >> a;
		REP(q, 2) {
			if (mapping[q].find(a) == mapping[q].end()) continue;
			pair<int, int> now = mapping[q][a];
			tate[q][now.first]++;
			int down = 0;
			if (tate[q][now.first] == n) {
				down++;
			}
			yoko[q][now.second]++;
			if (yoko[q][now.second] == n) {
				down++;
			}
			if (now.first == now.second) {
				cross[q][0]++;
				if (cross[q][0] == n) {
					down++;
				}
			}
			if (now.first == n - now.second - 1) {
				cross[q][1]++;
				if (cross[q][1] == n) {
					down++;
				}
			}
			if (q == 0) {
				u -= down;
			}
			else {
				v -= down;
			}
		}
		if (u <= 0 && v <= 0) break;
		if (u <= 0) {
			cout << "USAGI" << endl;
			return;
		}
		else if(v <= 0){
			cout << "NEKO" << endl;
			return;
		}
	}
	cout << "DRAW" << endl;
}

#undef int
int main() {
	init();
	solve();
}


Measured memory_bytes: 21164
#include <bits/stdc++.h>
using namespace std;
#define go(i, a, n) for (ll i = a; i < n; i++)
#define gor(i, a, n) for (int i = n - 1; i >= a; i--)
#define show(x) cout << x << '\n'
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vpair vector<pair<ll, ll>>
#define vtuple vector<tuple<ll, ll, ll>>
#define ff first
#define ss second
#define mod 1000000007
#define memset(a, k) memset(a, k, sizeof(a))
#define answer(z, k) cout << "Case #" << z << ": " << k << endl;
auto t1 = chrono::high_resolution_clock::now();
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s, t;
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int sum = 0;
	// ones
	if (a and k)
	{
		if (k <= a)
		{
			show(k);
			exit(0);
		}
		sum += a;
		k -= a;
	}
	// zeroes
	if (b and k)
	{
		if (k <= b)
		{
			show(sum);
			exit(0);
		}
		k -= b;
	}
	// minus
	if (c and k)
	{
		if (k <= c)
		{
			show(sum - k);
			exit(0);
		}
		sum -= c;
		k -= c;
	}
	show(sum);
	auto t2 = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(t2 - t1).count();
	clog << "Time taken = " << duration * 1.0 / 1000 << " seconds" << endl;
	return 0;
}


Measured memory_bytes: 3644
#define _ 2<<17
n,i;A[_],B[_],T[_],F[_];long M,D[_],P[_],R[_];s(u,p,i,I){D[u]=1;for(i=F[u];I=B[i];i=T[i])I-p?s(I,u),D[u]=D[u]*-~D[I]%M:0;}S(u,x,p,i,I){for(m(i=F[u],p);I=B[i];I-p?S(I,R[i]*x%M+1,u),x=x*-~D[I]%M:0)i=T[i];P[u]=x%M;}m(i,p){i?m(T[i],p),R[i]=R[T[i]]*(B[i]-p?-~D[B[i]]:1)%M:0;}main(u,v){for(;~scanf("%d%d",&u,&v);)i++?A[i-1]=B[i]=u,B[i-1]=A[i++]=v:(n=u,M=v);for(;--i;F[A[i]]=i)T[i]=F[A[i]];s(*R=1,0);S(1,1,0);for(;i++<n;)printf("%d\n",P[i]);}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 14592
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;

int main() {
	ll N, M;
	cin >> N >> M;
	ll ans = min(N, M / 2);
	M -= ans * 2;
	ans += M / 4;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
	int n;
  	cin >> n;
  	int d[n];
  	for(int i = 0; i < n; i++){
    	cin >> d[i];
    }
  	sort(d, d+n);	
  	int mid = n/2;
  	int lb = d[mid-1];
  	int ub = d[mid];
  	int ans = ub - lb;
  	cout << ans << endl;
}

Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"math/big"
	"os"
	"strconv"
	"strings"
)

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

var sc = newScanner()

func scanInt() int64 {
	sc.Scan()
	v, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return v
}

func scanFloat64() float64 {
	sc.Scan()
	v, _ := strconv.ParseFloat(sc.Text(), 64)
	return v
}

func scanString() string {
	if sc.Scan() {
		return sc.Text()
	}
	panic(sc.Err())
}

func main() {
	a, b := scanInt(), scanString()
	answer := mul(a, b)
	fmt.Println(answer)
}

func debug(a ...interface{}) {
	//fmt.Println(a...)
}

func mul(a int64, b string) int64 {
	ai := big.NewInt(a)
	bMul100, _ := strconv.Atoi(strings.ReplaceAll(b, ".", ""))
	ai.Mul(ai, big.NewInt(int64(bMul100)))
	ai.Quo(ai, big.NewInt(100))
	return ai.Int64()
}


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

int main(){
    string s;
    cin>>s;
    if(s[0]==s[1] && s[2]==s[3] && s[0]!=s[2])cout<<"Yes"<<endl;
    else if(s[0]==s[2] && s[1]==s[3] && s[0]!=s[1])cout<<"Yes"<<endl;
    else if(s[0]==s[3] && s[2]==s[1] && s[0]!=s[1])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    int n;
    cin >> n;
    vi ans;
    int i = 1;
    int sum = 0;
    while(sum <= n) {
        sum += i;
        ans.push_back(i);
        ++i;
    }
    int num = sum-n;
    rep(j, ans.size()) {
        if(j == num-1) continue;
        cout << ans[j] << endl;
    }
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int sum = a + b;
		if (sum >= 10)
			System.out.println("error");
		else
			System.out.println(sum);
		sc.close();
	}
}

Measured memory_bytes: 22996
#include<cstdio>
using namespace std;
int i,n,l,r,s=0;
int main()
{
	scanf("%d",&n);
	for (i=1;i<=n;i++)
	{
		scanf("%d%d",&l,&r);
		s+=r-l+1;
	 } 
	 printf("%d\n",s);
}

Measured memory_bytes: 128
n = int(input())
a_input=list(map(int,input().split()))

rate_li=[0]*9
top_coder=0
for a in a_input:
    rate_li[min(a//400,8)]+=1
#print(rate_li)
min_ = sum(i!=0 for i in rate_li[:8])
print(max(min_,1),min_+rate_li[-1])

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define mp make_pair
#define F(i, a, n) for(int i=a;i<n;i++)
#define REP(i, n) F(i, 0, n)
#define REP1(i, n) for(int i=1;i<=n;i++)
#define PTR(it, x) for(auto it=x.begin();it!=x.end();++it)
#define MOD 1000000007

typedef long long ll;

const int MAX = 1e6 + 5;

int n;
ll h[MAX],dp[MAX],mx=0;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n;
	REP1(i, n){
		cin>>h[i];
	}
	h[0] = 10000000001;
	dp[0] = 0;
	REP1(i, n){
		if(i == 1)
			dp[i] = 0;
		else if(h[i] <= h[i-1]){
			dp[i] = dp[i-1] + 1;
		}
		else{
			dp[i] = 0;
		}
		if(dp[i] > mx)
			mx = dp[i];
	}
	cout<<mx;
	return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i < N; i++){
    cin >> A[i];
  }
  for(int x:A){
    if((x%2==0&&(x%3!=0&&x%5!=0))){
      cout << "DENIED";
      return 0;
    }
  }
  cout << "APPROVED";
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>

using namespace std;
#define MAX 1000000000

int main(){
    int N;
    vector<int> h;
    int ans = 0;

    cin >> N;
    for (int i = 0; i < N; i++){
        int temp;
        cin >> temp;
        h.push_back(temp);
    }
    while (true){
        vector<int>::iterator itr = find(h.begin(), h.end(), 0);
        while ((itr == h.begin())){
            if (0 == h.size()){
                break;
            }
            h.erase(h.begin());
            itr = find(h.begin(), h.end(), 0);
        }
        if (0 == h.size()){
            break;
        }
        int min = *min_element(h.begin(), itr);
        int dis = distance(h.begin(), itr);
        for (int i = 0; i < dis; i++){
            h[i] = h[i] - min;
        }
        ans += min;
    }
    cout << ans << "\n";
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
typedef long long ll;
typedef long double ld;
const long long INF = 1e18;
# define len(x) ((int)(x).size())
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++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 foreps(i, m, n) for(int i = m;i < n;i++)
# define ALL(x) (x).begin(), (x).end()
# define rall(x) (x).rbegin(), (x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    ll N, T, A; cin >> N >> T >> A;
    vector<ld> H(N);
    rep(i, N) cin >> H.at(i);

    map<ld, ld> ch;
    rep(i, N) ch[i] = abs(A - (T - (H.at(i) * 0.006)));

    ld res = 1e9, ans = 0;
    rep(i, N) {
        res = min(res, ch[i]);
        if (res == ch[i]) ans = i + 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3932
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}
template< int id > struct CompTupleBy
{
  template<class T> 
  bool operator()( const T& a, const T& b ) const {
    return std::get<id>(a) < std::get<id>(b);
  }
};

using namespace std;

int main(){
    ll n,m;
    cin >> n >> m;
    vector<ll> Height;
    Height.push_back(0);
    rep(i,n){
        ll h;
        cin >> h;
        Height.push_back(h);
    }
    vector<vector<ll>> vec;
    vector<ll> tmp;
    rep(i,n+1){
        vec.push_back(tmp);
    }
    rep(i,m){
        ll a,b;
        cin >> a >> b;
        vec[a].push_back(b);
        vec[b].push_back(a);
    }
    ll ans = 0;
    for (ll i=1;i<=n;i++){
        bool ok = true;
        ll height = Height[i];
        rep(j,vec[i].size()){
            if (height <= Height[vec.at(i).at(j)]){
                ok = false;
            }
        }
        if (ok) {
            ans += 1;
        }
    }
    cout << ans << endl;


        
}

Measured memory_bytes: 9864
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define PB push_back
#define ALL(c) c.begin(),c.end()

using namespace std;

int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N) {
    cin >> A[i];
  }
  sort(ALL(A));

  vector<int> v;
  int cnt = 1;
  REP(i, N - 1) {
    if (A[i] != A[i + 1]) {
      v.PB(cnt);
      cnt = 1;
    } else {
      cnt++;
    }
  }
  v.PB(cnt);
  sort(ALL(v));

  int num = 0;
  REP(i, v.size()) {
    if (v[i] >= 3) {
      if (v[i] % 2 == 1) {
        num += v[i] / 2;
        v[i] = 1;
      } else {
        num += v[i] / 2 - 1;
        v[i] = 2;
      }
    }
  }

  cnt = 0;
  REP(i, v.size()) {
    if (v[i] == 2) cnt++;
  }
  num += (cnt + 1) / 2;

  cout << N - 2*num << endl;

  return 0;
}

Measured memory_bytes: 1276
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<a.length;i+=2){if(op==='=='){if(s==a[i])return a[i+1]}else if(op==='>='){if(s>=a[i])return a[i+1]}else if(op==='<='){if(s<=a[i])return a[i+1]}else if(op==='>'){if(s>a[i])return a[i+1]}else if(op==='<'){if(s<a[i])return a[i+1]}}return a[a.length-1];};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};const maxindex=(...a)=>{return a.indexOf(Math.max.apply(null,a))};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const ceil=a=>{return Math.ceil(a)};const srin=s=>{const a:string[]=[];rep(s,()=>a.push(sin()));return a};let ssinteger=-1;const ssin=()=>{ssinteger++;return input[0][ssinteger]};
const main = ()=>{
  let [a,b,c]=nrin(3)
  out(a+b==c||a+c==b||b+c==a?'Yes':'No')
}
main()

Measured memory_bytes: 7372
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>

using namespace std;

int main(){
    int X;
    cin >> X;
    priority_queue<int> que;
    que.push(1);
    
    for(int i = 2; i <= X; i++){
        int temp = i * i;
        while(temp <= X){
            que.push(temp);
            temp *= i;
        }
    }
    
    int ans = que.top();
    cout << ans << endl;
}


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

int main() {
    int N;
    cin >> N;
    int h[N];
    for (int i=0; i<N; ++i) cin >> h[i];

    long long int dp[N];
    dp[0] = 0;
    dp[1] = abs(h[0] - h[1]);
    for (int i=0; i<N-2; ++i) dp[i+2] = min(dp[i+1]+abs(h[i+2]-h[i+1]), dp[i]+abs(h[i+2]-h[i]));

    cout << dp[N-1] << endl;

    return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>

int main(){
	int H,W,i,j,c=0;
	
	scanf("%d%d",&H,&W);
	int ans[H*W][4];
	int a[H][W];
	for(i=0;i<H;i++){
		for(j=0;j<W;j++)scanf("%d",&a[i][j]);
	}
	
	for(i=0;i<H;i++){
		for(j=0;j<W;j++){
			if(a[i][j]%2==0)continue;
			
			
			
			if(j<W-1){
				ans[c][0]=i;
				ans[c][1]=j;
				ans[c][2]=i;
				ans[c][3]=j+1;
				a[i][j]--;
				a[i][j+1]++;
				c++;
				continue;
			}
			
			if(i<H-1){
				ans[c][0]=i;
				ans[c][1]=j;
				ans[c][2]=i+1;
				ans[c][3]=j;
				a[i][j]--;
				a[i+1][j]++;
				c++;
				continue;
			}
		}
	}
	
	printf("%d\n",c);
	for(i=0;i<c;i++)printf("%d %d %d %d\n",ans[i][0]+1,ans[i][1]+1,ans[i][2]+1,ans[i][3]+1);
	return 0;
}


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

int main(){
  int a, b;
  cin>>a>>b;
  int ans = (b-1)/(a-1);
  if((b-1) % (a-1) != 0) ans++;
  if(b == 1) ans=0;
  cout << ans<<endl;
  
}

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

#define MOD 1000000007

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

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

    ll mod = pow(10, 9) + 7;

    string S;
    cin >> S;

    vector<ll> a(S.length());
    vector<ll> c(S.length());
    vector<ll> qa(S.length());
    vector<ll> qc(S.length());

    if(S[0] == 'A') a[0] = 1;
    else if(S[0] == '?') qa[0] = 1;

    if(S[S.length() - 1] ==  'C') c[S.length() - 1] = 1;
    else if(S[S.length() - 1] == '?') qc[S.length() - 1] = 1;

    for(int i = 1; i < S.length(); i++) {
        if(S[i] == 'A') a[i] = 1;
        else if(S[i] == '?') qa[i] = 1;
        a[i] += a[i - 1];
        qa[i] += qa[i - 1];
    }

    for(int i = S.length() - 2; i >= 0; i--) {
        if(S[i] == 'C') c[i] = 1;
        else if(S[i] == '?') qc[i] = 1;
        c[i] += c[i + 1];
        qc[i] += qc[i + 1];
    }

    ll ans = 0;

    for(int i = 1; i < S.length() - 1; i++) {

        if(S[i] != 'B' && S[i] != '?') continue;

        ll as = a[i - 1] * (modpow(3, qa[i - 1], mod) % mod);
        as %= mod;
        as += qa[i - 1] * (modpow(3, qa[i - 1] - 1LL, mod) % mod);
        as %= mod;

        ll cs = c[i + 1] * (modpow(3, qc[i + 1], mod) % mod);
        cs %= mod;
        cs += qc[i + 1] * (modpow(3, qc[i + 1] - 1LL, mod) % mod);
        cs %= mod;

        //cerr << c[i + 1] << endl;

        ans += (as * cs) % mod;
        ans %= mod;
    }

    cout << ans << endl;
}

Measured memory_bytes: 6612
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define get0(x)     (get<0>(x))
#define get1(x)     (get<1>(x))
#define get2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       9223372036854775807LL
#define LLMIN       -9223372036854775808LL
#define IMAX        2147483647
#define IMIN        -2147483648
typedef long long LL;
using namespace std;

class UnionFind
{
    vector<int> data;
    vector<int> scale;
    public:
    UnionFind(int n)
    {
        for(int i=0;i<n;i++)
        {
            data.push_back(i);
            scale.push_back(1);
        }
    }
    int root(int n)
    {
        if(data[n]==n)
            return n;
        else
            return data[n]=root(data[n]);
    }
    void set(int x,int y)
    {
        if(root(x)==root(y))
            return;
        scale[root(y)]+=scale[root(x)];
        scale[root(x)]=0;
        data[root(x)]=data[root(y)];
    }
    int size(int n)
    {
        return scale[root(n)];
    }
};


int N;
LL A[300][300];
LL B[300][300];

int check(){
    REP(k,N)
        REP(i,N){
            REP(j,N){
                if(A[i][k]+A[k][j] < A[i][j])
                    return false;
            }
        }
    return true;
}

int main(void){
    cin>>N;
    vector<tuple<LL,int,int> > ls;
    REP(i,N)REP(j,N){
        cin>>A[i][j];
        ls.pb(mt(A[i][j],i,j));
    }
    if(!check()){
        cout<<-1<<endl;
        return 0;
    }

    LL ans=0;
    sort(ALL(ls));
    REP(i,N)REP(j,N)if(i!=j)B[i][j]=1e12;
    REP(i,SZ(ls)){
        LL l=get0(ls[i]);
        int a=get1(ls[i]),b=get2(ls[i]);
        LL m=1e12;
        REP(j,N)
            m=min(m,B[a][j]+B[j][b]);
        B[a][b]=B[b][a]=m;
        if(l<m){
            B[a][b]=B[b][a]=l;
            ans+=l;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

#define int long long
#define INF 9223372036854775807
#define double long double

struct line{
    double a, b;
};

vector< line > convexHull;

double intersect(line a, line b){
    return (b.b-a.b)/(a.a-b.a);
}

int query(int a){
    int l = 0;
    int r = convexHull.size()-1;

    while(l < r){
        int mid = (l+r)/2;

        if(convexHull[mid].a*a+convexHull[mid].b < convexHull[mid+1].a*a+convexHull[mid+1].b){
            r = mid;
        }else{
            l = mid+1;
        }
    }

    return convexHull[l].a*a+convexHull[l].b;
}

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

    int n, c;
    cin >> n >> c;

    vector< int > h(n);

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

    vector< int > dp(n);

    dp[0] = 0;

    convexHull.push_back(line{-2*h[0], dp[0]+h[0]*h[0]});

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

        dp[i] = c+h[i]*h[i];

        dp[i] += query(h[i]);

        line d = line{-2*h[i],dp[i]+h[i]*h[i]};

        while(convexHull.size() >= 2 && intersect(convexHull[convexHull.size()-2],convexHull.back()) >= intersect(convexHull[convexHull.size()-2],d)){
            convexHull.pop_back();
        }

        convexHull.push_back(d);
    }

    cout << dp.back() << endl;
}


Measured memory_bytes: 13804
from collections import deque
h,w=map(int,input().split())
cx,cy=map(int,input().split())
cx+=1
cy+=1
dx,dy=map(int,input().split())
dx+=1
dy+=1
l=[]
l.append("#"*(w+4))
l.append("#"*(w+4))
for i in range(h):
    l.append("##"+input()+"##")
l.append("#"*(w+4))
l.append("#"*(w+4))
#input

"""
for i in l:
    print(*i)
"""

q=deque([[cx,cy]])
qq=deque([[cx,cy]])
s=[[-1 for i in j]for j in l]
s[cx][cy]=0

while len(qq)>0:
    while len(q)>0:
        x,y=q.popleft()
        for px,py in ((0,1),(0,-1),(1,0),(-1,0)):
            if l[x+px][py+y]=="." and s[x+px][y+py]==-1:
                s[x+px][y+py]=s[x][y]
                q.appendleft([x+px,y+py])
                qq.append([x+px,y+py])
    x,y=qq.popleft()
    for px in range(-2,3):
        for py in range(-2,3):
            if l[x+px][py+y]=="." and s[x+px][y+py]==-1:
                s[x+px][y+py]=s[x][y]+1
                q.append([x+px,y+py])
                qq.append([x+px,y+py])
"""
for i in s:
    print(*i)
"""

print(s[dx][dy])

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

char m[1000][1000];
int d[1000][1000];

int main(){

    int H,W;
    cin>>H>>W;
    int dx[4]={1,0,-1,0};
    int dy[4]={0,1,0,-1};


    queue<pair<int,int>> Q;
    for(int i=0;i<1000;i++){
        if(i<H){
            string S;
            cin>>S;
            for(int j=0;j<1000;j++){
                if(j<W) {
                    m[i][j]=S.at(j);
                    if(S.at(j)=='#') {Q.push(make_pair(i,j)); d[i][j]=1;}
                }
                else m[i][j]='#';
            }
        }
        else {
            for(int j=0;j<1000;j++) m[i][j]='#';
        }
    }

    int max=0;

    while(Q.size()>0){
        int y=Q.front().first;
        int x=Q.front().second;
        int t=d[y][x];
        if(t>max) max=t;
        for(int i=0;i<4;i++){
            int Y=y+dy[i], X=x+dx[i];
            if(d[Y][X]==0 && m[Y][X]=='.' && 0<=Y && Y<1000 && 0<=X && X<1000){
                Q.push(make_pair(Y,X));
                d[Y][X]=t+1;
            }
        }
        Q.pop();
    }

    cout<<max-1<<endl;
    


}

Measured memory_bytes: 13328
h, w = map(int, input().split())
s = []
for i in range(h) :
    s += [["-1"] + list(input()) + ["-1"]]
s = [["-1"] * (w + 2)] + s + [["-1"] * (w + 2)]
for i in range(1, h + 1) :
    for j in range(1, w + 1) :
        if s[i][j] == "#" :
            continue
        else :
            count = 0
            for k in range(-1,2) :
                if s[i-1][j+k] == "#" :
                    count += 1
                if s[i][j+k] == "#" :
                    count += 1
                if s[i+1][j+k] == "#" :
                    count += 1
            s[i][j] = str(count)
s = s[1:-1]
for i in range(h) :
    print("".join(s[i][1:-1]))

Measured memory_bytes: 3188
n, k = map(int, input().split())
A = [int(a) - 1 for a in input().split()]

V = [-1] * n
V[0] = 0

nv = A[0]
i = 1
while True:
    if V[nv] != -1:
        first_time = V[nv]
        cycle = i - first_time
        break
    V[nv] = i
    i += 1
    nv = A[nv]

if k <= first_time:
    for idx, v in enumerate(V):
        if k == v:
            ans = idx + 1
            print(ans)
else:
    k -= first_time
    for idx, v in enumerate(V):
        if first_time + (k % cycle) == v:
            ans = idx + 1
            print(ans)


Measured memory_bytes: 92460
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;

const int N=2005;
const int M=2e5+5;
const int mod=1e9+7;
int n,mx,x[M],y[M],C[N<<1][N<<1];
int fac[N<<3],infac[N<<3],inv[N<<3];

void init()
{
	int i;
	scanf("%d",&n);
	for(i=1;i<=n;++i)
	{
		scanf("%d%d",&x[i],&y[i]);
		mx=max(mx,x[i]),mx=max(mx,y[i]);
	}
//	cout<<mx<<"#######"<<endl;
	for(i=1;i<=n;++i) ++C[x[i]+mx][y[i]+mx];
//	cout<<C[4][3]<<"++++++++"<<endl;
}

void work()
{
	int i,j;
	for(i=2*mx;~i;--i)
		for(j=2*mx;~j;--j)
		{
			C[i][j]+=C[i+1][j];
			if(C[i][j]>=mod) C[i][j]-=mod;
			C[i][j]+=C[i][j+1];
			if(C[i][j]>=mod) C[i][j]-=mod;
		}
}

void prework()
{
	int i,mm=mx<<2,kk=mx<<1;
	fac[0]=1;for(i=1;i<=mm;++i) fac[i]=1LL*fac[i-1]*i%mod;
	inv[1]=1;for(i=2;i<=kk;++i) inv[i]=1LL*inv[mod%i]*(mod-mod/i)%mod;
	infac[0]=1;for(i=1;i<=kk;++i) infac[i]=1LL*infac[i-1]*inv[i]%mod;
}

int CC(int x,int y)
{
	return 1LL*fac[x]*infac[x-y]%mod*infac[y]%mod;
}

void calc()
{
	int i,ans=0;
	for(i=1;i<=n;++i)
	{
		ans-=CC(2*x[i]+2*y[i],x[i]+x[i]);
		if(ans<0) ans+=mod;
	}
	for(i=1;i<=n;++i)
	{
		ans+=1LL*C[-x[i]+mx][-y[i]+mx];
		if(ans>=mod) ans-=mod;
	}
	printf("%d\n",500000004LL*ans%mod);
}

int main()
{
	init();
	work();
	prework();
	calc();
	return 0;
}

Measured memory_bytes: 64640
#import re
#import heapq
#import bisect
#from collections import deque
import math
from functools import reduce

def main():
    n = int(input())
    ans = 0
    for i in range(n):
        for j in range(n):
            for k in range(n):
                ans += gcd_list((i+1, j+1, k+1))
    print(ans)

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
    
if __name__ == '__main__':
    main()


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

int main(){
 int H,W;
 while(true){
  cin >> H >> W;
  if(H == 0 && W == 0) break;
  
  for(int i=0;i<H;i++){
   if(i==0 || i==H-1)
    for(int j=0;j<W;j++) cout<< '#';
   else{
    for(int j=0;j<W;j++){
     if(j==0 || j==W-1) cout<<'#';
     else cout<<'.';
    }
   } 
   cout << "\n";
  }
  cout << "\n";
 }
}


Measured memory_bytes: 3092
#include <cstdio>
long long n, s, a[200005];
int main() {
	scanf("%lld%lld", &n, a);
	if(a[0]>0) return !puts("-1");
	for(long long i=1; i<n; i++) {
		scanf("%lld", a+i);
		if(a[i] - a[i-1] > 1) return !puts("-1");
		else if(a[i] == a[i-1]+1) s++;
		else s += a[i];
	}
	printf("%lld", s);
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <math.h>
using namespace std;

#define rep(i, o) for (ll i = 0; i < (o); ++i)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
#define NUM 1e5

typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int n, m, q;
vector<int> a, b, c, d;
int ans;

void dfs(vector<int> A) {
  if (A.size() == n+1)
  {
    /* code */
    int now = 0;
    rep(i, q) {
      if (A[b[i]]-A[a[i]] == c[i]) now += d[i];
    }
    ans = max(ans, now);
    return;
  }

  A.push_back(A.back());
  while (A.back() <= m)
  {
    /* code */
    dfs(A);
    A.back()++;
    // rep(i, A.size()) {
      // cout << A[i] << " ";
    // }
  }


}

int main() {
  cin >> n >> m >> q;
  a = b = c = d = vector<int>(q);

  // permutation library
  rep(i, q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }

  dfs(vector<int>(1,1));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3580
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<functional>
using namespace std;

int main() {
	int N;
	std::cin>>N;
	priority_queue<double,vector<double>, greater<double> > Q;

	for(int i=0;i<N;i++) {
		double temp;
		std::cin>>temp;
		Q.push(temp);
	}
	
	while(Q.size() != 1) {
		double i1 = Q.top();
		Q.pop();
		double i2 = Q.top();
		Q.pop();

		Q.push((i1 + i2) / 2);
	}

	std::cout<<Q.top()<<"\n";

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = Convert.ToInt32 (Console.ReadLine ());
            int[] Ai = Array.ConvertAll<string, int> (Console.ReadLine ().Split (), int.Parse);
            int[] answer = new int[Ai.Length + 2];
            for (var i = 0; i < Ai.Length; i++) {
                answer[Ai[i]]++;
            }
            var output = answer.ToList ();
            output.RemoveAt (0);
            foreach (var ans in output) {
                Console.WriteLine (ans);
            }
        }
    }
}


Measured memory_bytes: 44556
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<double,double> pd;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

template<int SZ> struct DSU {
    int par[SZ], sz[SZ];
    DSU() {
        F0R(i,SZ) par[i] = i, sz[i] = 1;
    }
    
    int get(int x) { // path compression
    	if (par[x] != x) par[x] = get(par[x]);
    	return par[x];
    }
    
    bool unite(int x, int y) { // union-by-rank
    	x = get(x), y = get(y);
    	if (x == y) return 0;
    	if (sz[x] < sz[y]) swap(x,y);
    	sz[x] += sz[y], par[y] = x;
    	return 1;
    }
};

vector<pair<int,pi>> edge;

DSU<1001> D;

ll kruskal(pair<int,pi> x) {
    D = DSU<1001>(); D.unite(x.s.f,x.s.s);
    ll ans = x.f;
	for (auto a: edge) if (D.unite(a.s.f,a.s.s)) ans += a.f; // edge is in MST	
	return ans;
}

ll mul(ll a, ll b) {
    if (a < 0) return 0;
    if (b < 0) return 0;
    return a*b%MOD;
}

ll po2(ll a) {
    ll b = 1;
    F0R(i,a) b = 2*b%MOD;
    return b;
}

int N,M,c[3];
ll X;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> M >> X;
    F0R(i,M) {
        int a,b,c; cin >> a >> b >> c;
        edge.pb({c,{a,b}});
    }
	sort(all(edge));
    for (auto a: edge) {
        ll z = kruskal(a);
        if (z < X) c[0] ++;
        else if (z == X) c[1] ++;
        else c[2] ++;
    }
    if (c[0] == 0) cout << mul(po2(c[1])-2,po2(c[2]));
    else cout << mul(mul(2,po2(c[1])-1),po2(c[2]));
}

// read the question correctly (is y a vowel?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)

Measured memory_bytes: 384
using System;

public class Hello
{
	public static void Main()
	{
		var n = int.Parse(Console.ReadLine().Trim());
		string[] line = Console.ReadLine().Trim().Split(' ');
		var a = Array.ConvertAll(line, int.Parse);
		var count = 0;
		for (int i = 1; i <= n - 2; i++)
			if (check(a[i - 1], a[i], a[i + 1])) count++;
		Console.WriteLine(count);
	}
	static bool check(int a, int b, int c)
	{
		var t = new int[3];
		t[0] = a; t[1] = b; t[2] = c;
		Array.Sort(t);
		return t[1] == b;
	}
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define N 100
using namespace std;
typedef complex<double> P;
typedef pair<P,P> L;
const double EPS = 1e-8;
double dot(P a, P b){ return real(conj(a)*b); }
double cross(P a, P b){ return imag(conj(a)*b); }

int ccw(P a, P b, P c){
  b -= a;
  c -= a;
  if(cross(b,c) > EPS) return 1;   // ????????????(b-a)????????´???????????????(c-a)????????¨?????????
  if(cross(b,c) < -EPS) return -1; // ????????????(b-a)????????´???????????????(c-a)????????¨?????????
  if(dot(b,c) < -EPS) return 2;
  if(norm(b) < norm(c)) return -2;
  return 0;
}

bool isIntersect(L s1, L s2){
  //ccw ??????????????????????????¨, ????????????????????´?????????????????¨??????????????????????????????
  if(max(real(s1.first), real(s1.second)) + EPS < min(real(s2.first), real(s2.second)) ||
     max(imag(s1.first), imag(s1.second)) + EPS < min(imag(s2.first), imag(s2.second)) ||
     max(real(s2.first), real(s2.second)) + EPS < min(real(s1.first), real(s1.second)) ||
     max(imag(s2.first), imag(s2.second)) + EPS < min(imag(s1.first), imag(s1.second))) return false;

  return ( ccw(s1.first,s1.second,s2.first) * ccw(s1.first,s1.second,s2.second) <= 0 &&
           ccw(s2.first,s2.second,s1.first) * ccw(s2.first,s2.second,s1.second) <= 0 );
}


vector<P> get_p(P a,double d,double r){
  vector<P> res(5);
  d=(d/360)*2*M_PI;
  P p=P(0,r)*P(cos(d),sin(d));
  res[0]=p+a;
  d=2*M_PI/5;
  for(int i=1;i<=4;i++){
    p=p*P(cos(d),sin(d));
    res[i]=p+a;
  }
  return res;
}
double getDistanceSP(L s, P p){
  if(dot(s.second - s.first, p - s.first) < -EPS) return abs(p - s.first);
  if(dot(s.first - s.second, p - s.second) < -EPS) return abs(p - s.second);
  return abs(cross(s.second - s.first, p - s.first) / abs(s.second - s.first));  }

double getDistanceSS(L s1, L s2){
  if(isIntersect(s1,s2)) return 0.0;
  return min( min(getDistanceSP(s1, s2.first), getDistanceSP(s1, s2.second)),
              min(getDistanceSP(s2, s1.first), getDistanceSP(s2, s1.second)));
}


double G[N][N],x[N],y[N],d[N],r[N];
double get_dis(int a,int b){
  vector<P> A=get_p(P(x[a],y[a]),d[a],r[a]);
  vector<P> B=get_p(P(x[b],y[b]),d[b],r[b]);
  double res=1e9;
  for(int i=0;i<5;i++)
    for(int j=0;j<5;j++)
      res=min(res,getDistanceSS(L(A[i],A[(i+2)%5]),L(B[j],B[(j+2)%5])));
  return res;
}

int main(){
  while(1){
  int n,s,g;
  cin>>n>>s>>g;
  if(!n&&!s&&!g)break;
  for(int i=0;i<n;i++)for(int j=0;j<n;j++)G[i][j]=1e9*(i!=j);
  for(int i=0;i<n;i++)cin>>x[i]>>y[i]>>d[i]>>r[i];
  
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)if(i!=j) G[i][j]=get_dis(i,j);
  
  for(int k=0;k<n;k++)
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
	G[i][j]=min(G[i][j],G[i][k]+G[k][j]);

  printf("%.20f\n",G[s-1][g-1]);
  }
  return 0;
}

Measured memory_bytes: 3536
#include <stdio.h>
int main(){

  int card,i,j,taroS=0,hanakoS=0;
  char taroC[101]={},hanakoC[101]={};

  scanf("%d",&card);

  for(i = 0; i < card; i++){

    j=0;
    scanf("%s %s",taroC,hanakoC);

    while(1){

      if(taroC[j] > hanakoC[j]){
   
	taroS += 3;
	break;
	
      } else if(taroC[j] < hanakoC[j]){
	
	hanakoS += 3;
	break;
	
      } else {
	
	if(taroC[j+1] == '\0' && hanakoC[j+1] == '\0'){
	  
	  taroS++;
	  hanakoS++;
	  break;
	  
	}

	j++;
	
      }
      
    }

  }

  printf("%d %d\n",taroS,hanakoS);

  return 0;

}

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

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int a,b;
  scanf("%d%d",&a,&b);
  printf("%d\n",(a-1)*(b-1));
}

int main(void){
  run();
  return 0;
}

Measured memory_bytes: 128
#!/usr/bin/python3
# -*- coding: utf-8 -*-

def solve(p, t, A, result):
    if A[p] == t:
        result[(p,t)] = True
        return True
    if p == len(A) - 1:
        return False
    if (p,t) in result:
        # print('Cache Hit')
        return result[(p,t)]
    if solve(p+1, t-A[p], A, result):
        result[(p,t)] = True
        return True
    if solve(p+1, t, A, result):
        result[(p,t)] = True
        return True
    result[(p,t)] = False 
    return False

import sys

n = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
num_q = int(sys.stdin.readline())
query = list(map(int, sys.stdin.readline().split()))
result = dict()

for m in query:
    if solve(0, m, A, result):
        print('yes')
    else:
        print('no')



Measured memory_bytes: 9476