akhauriyash/Code-Regression huggingface dataset:
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int gcd(int a, int b){
	if(a==0 || b==0) return a==0?b:a;
	int d=0;
	while(1){
		if((a&1)!=0){
			if((b&1)!=0){
				if(a<b) b-=a;
				else if(a>b) a-=b;
				else break;
			}else{
				while((b&1)==0) b>>=1;
			}
		}else{
			if((b&1)!=0){
				while((a&1)==0) a>>=1;
			}else{
				a>>=1; b>>=1; d++;
			}
		}
	}
	return a<<d;
}

int main(void){
	int n, i;
	int a[100001];
	int l[100002], r[100002];
	scanf("%d", &n);
	for(i=1; i<=n; i++){
		scanf("%d", a+i);
	}
	l[0]=0;
	for(i=1; i<=n; i++){
		l[i] = gcd(l[i-1], a[i]);
	}
	r[n+1]=0;
	for(i=n; i>0; i--){
		r[i] = gcd(r[i+1], a[i]);
	}
	int max=0;
	for(i=1; i<=n; i++){
		int now=gcd(l[i-1], r[i+1]);
		if(now>max) max=now;
	}
	printf("%d\n", max);
}


Measured memory_bytes: 1280
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque 

cnt = 0
def include(x):
    global cnt
    s = str(x)
    if ('3' in s) and ('5' in s) and ('7' in s):
        cnt += 1  
     
def main():
    n = int(readline())
    dq = deque()
    dq.append(0)
    cnd = [0]
    dd = (3, 5, 7)
    while len(dq)>0:
        v = dq.popleft()
        for i in dd:
            if v*10+i>n:
                continue
            dq.append(v*10+i)
            cnd.append(v*10+i)
            include(v*10+i)
        if cnd[-1] > n:
            break
    print(cnt)
if __name__ == '__main__':
    main()


Measured memory_bytes: 5472
#include <stdio.h>

int main(){
	int i,cnt,price;
	int coin[6] = {500,100,50,10,5,1};

	while(1){
		scanf("%d",&price);
		if(price == 0){
			break;
		}

		price = 1000-price;

		cnt = 0;
		for(i = 0;i < 6;i++){
			cnt += price/coin[i];
			price %= coin[i];
		}

		printf("%d\n",cnt);
	}

	return 0;
}

Measured memory_bytes: 600
#include<cstdio>
#include<cstdlib>
bool check(bool);
bool p[1000][1000];
int C, N, l, f;

int main(void){
	char buf[1000];
	int i, j, ans=0;
	scanf("%d %d", &C, &N);
	--C;
	for(i=0; i<N; ++i){
		scanf("%s", buf);
		for(j=0; j<N; ++j){ p[i][j]=(buf[j]=='1')?true:false; }
	}
	if(check(true)){ ++ans; }
	for(i=0; i<C; ++i){
		if(check(false)){ ans++; }
	}
	printf("%d\n", ans);
	return(0);
}

bool check(bool isFirst){
	bool isSym=true;
	int D, r, c, i, j;
	if(isFirst){
		for(i=0; (i<N/2)&&(isSym); ++i){
			for(j=0; (j<N/2)&&(isSym); ++j){
				if(!((p[i][j]==p[N-i-1][j])&&(p[i][j]==p[i][N-j-1])&&(p[i][j]==p[N-i-1][N-j-1]))){ isSym=false; }
			}
		}
		
	}
	else{
		scanf("%d", &D);
		for(i=0; i<D; ++i){
			scanf("%d %d", &r, &c);
			--r; --c;
			p[r][c]=!p[r][c];
		}
		for(i=0; (i<N/2)&&(isSym); ++i){
			for(j=0; (j<N/2)&&(isSym); ++j){
				if(!((p[i][j]==p[N-i-1][j])&&(p[i][j]==p[i][N-j-1])&&(p[i][j]==p[N-i-1][N-j-1]))){ isSym=false; }
			}
		}

	}
	return(isSym);
}


Measured memory_bytes: 3728
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	int N, D;
	int con = 0;
	
	cin >> N >> D;
	
	for(int i = 0; i < N; i++){
		int X, Y;
		
		cin>>X>>Y;
		
		if(X * X + Y * Y <= D * D) {
			con++;
		}
	}
	
	cout<<con<<endl;
	
	return 0;
}

Measured memory_bytes: 3664
import string

w = raw_input()
d = dict.fromkeys(string.ascii_lowercase, 0)
for i in range(len(w)):
    d[w[i]] += 1

    
finalprint = "Yes"    

for key, value in d.iteritems():
    bool = value % 2
    if bool == 0:
        continue
    else:
        finalprint = "No"
        break

print finalprint

Measured memory_bytes: 2692
#include <stdio.h>

long long n, ans;
int main() {
  scanf("%lld", &n);
  if (n == 1)
    return puts("0") & 0;
  for (long long i = 1; i * i <= n; ++ i) {
    if (n % i) continue;
    long long now = n / i;
    if (now - 1 > n / (now - 1))
      ans += now - 1;
  }
  printf("%lld\n", ans);
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = Integer.parseInt(in.nextLine());
		if (N == 1) {
			System.out.println("Hello World");
		} else {
			int A = Integer.parseInt(in.nextLine());
			int B = Integer.parseInt(in.nextLine());
			System.out.println(A + B);
		}
		in.close();

	}

}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define inf 0x3f3f3f3f
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout);
using namespace std;

const int N=2005,M=100005,mod=1e9+7;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
inline void ch(int &x,int y){x=(x+y)%mod;}
template<class T>inline void read(T &x){
	x=0;char ch=getchar(),rev=0;
	while(ch>'9'||ch<'0') rev=(ch=='-'),ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	x=rev?-x:x;
}
template<class T>inline void print(T x,const char c){
	if(!x){putchar('0');putchar(c);return;}
	if(x<0) putchar('-'),x=-x;
	int m=0,a[10];
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');
	putchar(c);
}
inline int exp(int x,int y){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int n,a[N],du[N];
vi g[N],b;
bool vis[N];
priority_queue<pii> q;

void merge(vi &a,const vi b){
	vi tmp;tmp.clear();
	int n=a.size(),m=b.size();
	int x=0,y=0;
	while(x<n&&y<m)
		if(a[x]>b[y]) tmp.pb(a[x++]); else tmp.pb(b[y++]);
	while(x<n) tmp.pb(a[x++]);
	while(y<m) tmp.pb(b[y++]);
	a=tmp;
}

void dfs(int x,vi &b){
	b.clear();
	vis[x]=1;
	vi tmp,tmp2;tmp.clear();
	for(int i=0;i<g[x].size();i++){
		int y=g[x][i];
		if(vis[y]) continue;
		dfs(y,tmp2);merge(tmp,tmp2);
	}
	b.pb(a[x]);
	for(int i=0;i<tmp.size();i++)
		b.pb(tmp[i]);
}

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
#endif
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			if(__gcd(a[i],a[j])>1) g[i].pb(j),g[j].pb(i);
	for(int i=1;i<=n;i++)
		sort(g[i].begin(),g[i].end());
	for(int i=1;i<=n;i++)
		if(!vis[i]){
			vi ans;ans.clear();
			dfs(i,ans);
			merge(b,ans);
		}
	for(int i=0;i<n;i++) print(b[i],' ');puts("");
	return 0;
}

Measured memory_bytes: 17920
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000;

int main(){
    ll h, w;
    cin >> h >> w;
    ll a;
    if (h == 1 || w == 1) {
        cout << 1 << endl;
        return 0;
    }

    else if (h % 2 == 0 || w % 2 == 0) {
        a = h * w / 2;
        cout << a << endl;
        return 0;
    }

    else {
        a = (h * w + 1) / 2;
        cout << a << endl;
        return 0;
    }

    return 0;
} 

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


/*  
    
*/


int nn;
struct segTree{
    segTree *leftSeg;
    segTree *rightSeg;
    int push;
    int from , till;

    segTree(int l, int r){
        from = l;
        till = r;
        push = -1;
        if(l == r)
            return;
        int mid = ( l + r)/2;
        leftSeg = new segTree(l, mid);
        rightSeg = new segTree(mid+1, r);
    }

    void update(int l, int r, int curr){
        if(from != till && push != -1){
            leftSeg->push = push;
            rightSeg->push = push;
            push = -1;
        }

        if( l > till || r < from )
            return;

        if(from >= l && till <= r){
            push = curr;
            return;
        }

        leftSeg->update(l, r, curr);
        rightSeg->update(l, r, curr);
    }

    int get(int ind){
        if(from == till){
            if(push != -1)
                return push;
            return nn;
        }
        if(push != -1){
            leftSeg->push = push;
            rightSeg->push = push;
            push = -1;
        }
        if(ind <= leftSeg->till)
            return leftSeg->get(ind);
        else
            return rightSeg->get(ind);

    }


};


void test_case(){
    //int n; cin >> n;
    
    int n, q;
    cin >> n >> q;
    nn = n-1;
    segTree vertical = segTree(0, n-1);
    segTree horizontal = segTree(0, n-1);
    
    ll res = n-2;
    res *= res;
    while(q--){
        int type, x; cin >> type >> x;
        x--;
        if(type == 1){
            int bottom = horizontal.get(x);
            int already = vertical.get(bottom);
            if( already  > x ){
                vertical.update(0, bottom, x);
            }
            res -= (bottom-1);
        }
        else{
            int right = vertical.get(x);
            int already = horizontal.get(right);
            if( already > x ){
                horizontal.update(0, right, x);
            }
            res -= (right-1);
        }
    }
    
    cout << res << endl;
    
    
}

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

    int t; t = 1;
    //cin >> t;
    while(t--)
        test_case();
    return 0;
}


Measured memory_bytes: 41112
fun main(args: Array<String>) {
  val (n, k) = readLine()!!.split(" ").map { it.toInt() }
  val cList = readLine()!!.map { it }

  var inCnt = 0
  var outCnt = 0
  var happyCnt = 0
  for (i in 1 until n) {
    val l = cList[i - 1]
    val r = cList[i]
    if (l == 'L' && r == 'R') outCnt++
    if (l == 'R' && r == 'L') inCnt++
    if (l == 'L' && r == 'L') happyCnt++
    if (l == 'R' && r == 'R') happyCnt++
  }

  var swap2 = Math.min(inCnt, outCnt)
  var swap1 = Math.max(inCnt, outCnt) - swap2

  for (i in 0 until k) {
    if (swap2 > 0) {
      happyCnt += 2
      swap2--
    } else if (swap1 > 0) {
      happyCnt++
      swap1--
    }
  }

  println(happyCnt)
}



Measured memory_bytes: 41576
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    a = collections.Counter(a).most_common()
    if len(a) == 1:
        if a[0][0] == 0:
            print("Yes")
        else:
            print("No")
    elif len(a) == 2:
        if a[1][0] == 0 and a[0][1] == a[1][1] * 2:
            print("Yes")
        else:
            print("No")
    elif len(a) == 3:
        if a[0][0] ^ a[1][0] ^ a[2][0] == 0:
            if a[0][1] == a[1][1] == a[2][1]:
                print("Yes")
            else:
                print("No")
        else:
            print("No")
    else:
        print("No")


if __name__ == '__main__':
    solve()


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

int main() { 
    int n, w;
    cin >> n >> w;
    int a[n][w];
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < w; ++j) cin >> a[i][j];
    }
    vector<tuple<int, int, int, int>> tu;
    for(int i = 0; i < n; ++i) {
        if(i%2 == 0) {
            for(int j = 0; j < w; ++j) {
                if(j == w-1) {
                   if(a[i][j]%2 == 1 && i != n-1) {
                        a[i+1][j] += a[i][j];
                        tu.push_back(make_tuple(i+1, j+1, i+2, j+1));
                    } 
                } else {
                    if(a[i][j]%2 == 1) {
                        a[i][j+1] += a[i][j];
                        tu.push_back(make_tuple(i+1, j+1, i+1, j+2));
                    }
                }
            }
        } else {
            for(int j = w - 1; j >= 0; --j) {
                if(j == 0) {
                   if(a[i][j]%2 == 1 && i != n-1) {
                        a[i+1][j] += a[i][j];
                        tu.push_back(make_tuple(i+1, j+1, i+2, j+1));
                    } 
                } else {
                    if(a[i][j]%2 == 1) {
                        a[i][j-1] += a[i][j];
                        tu.push_back(make_tuple(i+1, j+1, i+1, j));
                    }
                }
            }
        }
    }

    cout << tu.size() << '\n';
    for(int i = 0; i < tu.size(); ++i) {
        cout << get<0>(tu[i]) << " " << get<1>(tu[i]) << " " << get<2>(tu[i]) << " "<< get<3>(tu[i]) << '\n';
    }

    return 0;
}


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

int main(){
	int N, K, i, j;
	scanf("%d%d", &N, &K);
	vector<int> A(N + 2);
	for(i = 1; i <= N; i++){
		scanf("%d", &A[i]);
	}
	vector<int> sub(N + 2);
	for(i = 0; i < K && i < 100; i++){
		for(j = 0; j <= N + 1; j++){
			sub[j] = 0;
		}
		for(j = 1; j <= N; j++){
			sub[max(1, j - A[j])]++;
			sub[min(N + 1, j + A[j] + 1)]--;
		}
		for(j = 1; j <= N + 1; j++){
			sub[j] += sub[j - 1];
		}
		for(j = 0; j <= N + 1; j++){
			A[j] = sub[j];
		}
	}
	for(i = 1; i <= N; i++){
		printf("%d ", A[i]);
	}
	printf("\n");
	return 0;
}

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

int main() {
    int w,h,x,y; cin >> w >> h >> x >> y;
    // (x,y)が中央にあれば縦横どちらに分割しても等しくなる
    int ans = w == x*2 && h == y*2;
    // どんなw,hについても中央での分割が最も大きい面積となる
    double area = (double)w*h/2;
    cout << area << " " << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll N,M; cin>>N>>M;
  for(int i=0; i<M; i++){
    ll A; cin>>A;
    N-=A;
  }
  if(N<0) N=-1;
  cout<<N<<endl;
}

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

using namespace std;
using i64 = long long;

int main(){
    i64 n,high,ans{};
    cin>>n;
    cin>>high;
    for(i64 i=1;i<n;i++){
        i64 a;
        cin>>a;
        if(high <= a){
            high = a;
        }
        else {
            ans+= high - a;
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int n; cin >> n;
    vector <int> a;

    for(int i = 0; i < n; i++){
        int b; cin >> b;
        a.push_back(b);
    }

    int count = 0;
    for(int i = 1; i < n-1; i++){
        if(a[i-1]  < a[i] && a[i] < a[i + 1]){
            count++;
        }
        else if(a[i-1]  > a[i] && a[i] > a[i + 1]){
            count++;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int N, K, X, Y, price = 0;
	scanf("%d", &N);
	scanf("%d", &K);
	scanf("%d", &X);
	scanf("%d", &Y);
	if(N - K >= 0){
		price = X*K;
		price += Y*(N-K);
	}else{
		price = X*N;
	}
	printf("%d\n", price);
	return 0;
}

Measured memory_bytes: 128
n, m = map(int, input().split())
a = set(map(int, [input() for _ in range(m)]))

dp = [0] * (n+1)
# 0段目と1段目は1通り（但し、１段目が壊れていない場合）（0 段目は「なにもしない」という から1 通り）
dp[:2] = 1, 1 if 1 not in a else 0 

for i in range(2, n+1):
    if i in a:
        continue
    else:
        dp[i] = (dp[i-1] + dp[i-2])

print(dp[-1] % (10**9+7))


Measured memory_bytes: 460020
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <numeric>
#include <functional>
#include <stack>
#include <map>

int main() {
	int n;

	std::cin >> n;

	std::vector<long long> v(n + 1);

	for (size_t i = 1; i <= n; i++)
	{
		std::cin >> v[i];
		v[i] += v[i - 1];
	}

	std::sort(v.begin(), v.end());

	long long count = 0;

	std::map <long long , long long > m;

	for (size_t i = 0; i < n + 1; i++)
	{
		m[v[i]]++;
	}

	for (auto&& i : m) {
		count += (i.second * (i.second - 1)) / 2;
	}

	std::cout << count << std::endl;

	return 0;
}

Measured memory_bytes: 14336
n=int(input())
h=list(map(int,input().split()))
ans="Yes"
minh=h[n-1]

for i in range(n-1,-1,-1):
  #  print((h[i+1:]),minh)
    minh=min(minh,h[i])
    if h[i]-minh>1.1:
        ans="No"
        break
    
print(ans)    

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main(){
    int n;
    cin >> n;
    vi b(n-1);
    rep(i, n-1) cin >> b[i];
    vi a(n, INF);
    rep(i, n-1) {
        a[i] = min(a[i], b[i]);
        a[i+1] = min(a[i+1], b[i]);
    }
    int ans = 0;
    rep(i, n) ans += a[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
 
using namespace std;
 
int main()
{
  int N;
  cin >> N;

  vector<int> A(N);
  vector<int> num(N);

  for(int i = 0; i < N-1; i++){
    cin >> A[i];
    num[A[i] - 1]++;
  }

  for(int i = 0; i < N; i++){
    cout << num[i]<<endl;
  }

  
  return 0;
}

Measured memory_bytes: 4840
import sys
a,b = input().split()
int_a,int_b = int(a),int(b)
moji_a = a
moji_b = b
for _ in range(int_b - 1) :
    moji_a += a

for _ in range(int_a - 1) :
    moji_b += b

for i in range(min(len(moji_a),len(moji_b))) :
    if int(moji_a[i]) < int(moji_b[i]) :
        print(moji_a)
        sys.exit()
    elif int(moji_a[i]) > int(moji_b[i]):
        print(moji_b)
        sys.exit()

if len(moji_a) < len(moji_b) :
    print(moji_a)
else :
    print(moji_b)


Measured memory_bytes: 3064
import java.util.Scanner;


public class Main {
	
	Scanner sc = new Scanner(System.in);
	
	void run() {
		
		int w = sc.nextInt();
		int n = sc.nextInt();
		
		int[][] h = new int [n][2];
		
		String[] s;
		int[] ans = new int [w];
		
		for (int i=0;i<n;i++) {
			s = sc.next().split(",");
			
			h[i][0] = Integer.parseInt(s[0]);
			h[i][1] = Integer.parseInt(s[1]);
			
		}
		
		for (int i=1;i<=w;i++) {
			
			int state = i;
			
			for (int j=0;j<n;j++) {
				
				if ( h[j][0] == state )
					state = h[j][1];
				else if ( h[j][1] == state )
					state = h[j][0];	
				
				
			}
			ans[state-1] = i;
		}
		for (int i=0;i<w;i++) {
			System.out.println(ans[i]);
		}
		
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

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

using namespace std;
  
int main(){
    int N, W;
    cin >> N >> W;

    int w[N+1];
    int v[N+1];
    for(int i=1; i<=N; i++){
        cin >> w[i] >> v[i];
    }

    long long int dp[N+1][W+1];
    memset(dp, 0, sizeof(dp));

    for(int i=1; i<=N; i++){
        for (int j=1; j<=W; j++){
            if(w[i] <= j){
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]] + v[i]);
            }else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }

    cout << dp[N][W] << "\n";

    return 0; 
} 

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

long long n,k,q,bil[100001],a;

int main(){
    cin>>n>>k>>q;
    for(int h=1;h<=n;h++){
    bil[h]=k-q;
    }
    for(int i=1;i<=q;i++){
        cin>>a;
        bil[a]++;
    }
    for(int i=1;i<=n;i++){
        if(bil[i]<=0){
            cout<<"No"<<endl;
        }else{
            cout<<"Yes"<<endl;
        }
    }
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#pragma warning (disable : 4996)
using namespace std;
int main()
{
	int d, n;
	int mul = 1;
	scanf("%d %d", &d, &n);
	for (int i = 1; i <= d; i++) mul *= 100;
	if (n == 100) n++;
	return !printf("%d\n", mul*n);
}

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

#define int long long
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define fr(i,j,k) for(i = j; i < (k); i++)
#define all(x) x.begin(), x.end()
#define el '\n'
#define remax(a,b) a = max(a, b)
#define remin(a,b) a = min(a, b)
#define sz(x) int32_t(x.size())

typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpi;
// --------------------------------------------------------------------

const pii dxy[] = { {-1, 0}, {1, 0}, {0, 1}, {0, -1} };
const int mod = 1e9 + 7;
const int INF = 2e18;
const ld EPS = 1e-9;
const int NN = 1e5 + 2;

int a[100][100];

void solve() {
      int i = 0, j = 0, k = 0, n = 0, m = 0; 
      int x; cin >> n >> m >> x;
      vi c(n);
      int ans = INF;
      fr(i, 0, n) {
            cin >> c[i];
            fr(j, 0, m) cin >> a[i][j];
      }

      for(int b = 0; b < (1 << n); b++) {
            vi g(m, 0);
            int cost = 0;
            fr(i, 0, n) {
                  if( ( (1<<i) & b) == 0 ) continue;
                  fr(j, 0, m) {
                        g[j] += a[i][j];
                  }
                  cost += c[i];
            }

            bool d = 1;
            fr(j, 0, m) {
                  if(g[j] < x) {
                        d = 0;
                  }
            }
            if(d) remin(ans, cost);
      }
      cout << (ans < INF ? ans : -1) << el;
}

int32_t main() {
      ios::sync_with_stdio(false); cin.tie(0); 
      int T = 1; 
      // cin >> T;
      for(int tc = 1; tc <= T; tc++) {
            solve();
       }
      return 0;
}

Measured memory_bytes: 3656
#include<iostream>
#include<stdio.h>
using namespace std;
#define MAX 500000
#define S 2000000000

int L[MAX/2+2],R[MAX/2+2];
int cnt;

void merg(int a[],int n,int le,int mid,int ri){
    int n1=mid-le;
    int n2=ri-mid;
    for(int i=0;i<n1;i++)L[i]=a[le+i];
    for(int i=0;i<n2;i++)R[i]=a[mid+i];
    L[n1]=R[n2]=S;
    int i=0,j=0;
    for(int k=le;k<ri;k++){
        cnt++;
        if(L[i]<=R[j]){
            a[k]=L[i++];
        }else{
            a[k]=R[j++];
        }
    }
}

void mergesort(int a[],int n,int le,int ri){
    if(le+1<ri){
        int mid=(le+ri)/2;
        mergesort(a,n,le,mid);
        mergesort(a,n,mid,ri);
        merg(a,n,le,mid,ri);
    }
}

int main(){
    int a[MAX],n,i;
    cnt=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    mergesort(a,n,0,n);
    for(int i=0;i<n;i++){
            if(i){cout<<" ";}
            cout<<a[i];
    }
    cout<<endl;
    cout<<cnt<<endl;
return 0;}

Measured memory_bytes: 6972
#include <stdio.h>
#define MAX 5000000
int heap[MAX];
int n;

void getmax(int i){
  int l=2*i;
  int r=2*i+1;
  int m,p;

  if(l<=n && heap[i]< heap[l]){
    m=l;
    }
    else {
      m=i;
    }
    if(heap[r] > heap[m] && r<=n){
      m=r;
    }
    if(m!=i){
      p=heap[i];
      heap[i]=heap[m];
      heap[m]=p;
      getmax(m);
    }
}
void build(void){
  int i;
  for(i=(n/2);i>=1;i--){
  getmax(i);
  }
}
int main(){
  int i;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&heap[i]);
  }
  build();
  for(i = 1;i <= n;i++){
    printf(" %d",heap[i]);
  }
  printf("\n");

  return 0;

}

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

int main(){
    int h, w ;
    cin >> h >> w ;
    vector<vector<string>> s(h,vector<string>(w));
    for(int i= 0 ; i < h ; i ++){
        for(int j = 0 ; j < w ; j++){
            cin >> s[i][j];
            if(s[i][j]=="snuke"){
                char c = 'A'+j;
                cout << c << i+1 << endl;
            }
        }
    }
}

Measured memory_bytes: 256
var input= require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=input.split("\n");
var arr=(Arr[1]).split(" ").map(Number);
var min=arr.reduce(function(a,b){return Math.min(a,b);});
var max=arr.reduce(function(a,b){return Math.max(a,b);});
var sum=arr.reduce(function(a,b){return a+b;});
console.log(min+" "+max+" "+sum);

Measured memory_bytes: 9892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forn for(int i=0;i<n;i++)
#define pb push_back
#define pob pop.back()
int main()
{
   int x,y;
   cin>>x>>y;
   cout<<x+y/2;
   return 0;
    
    
}

Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in) 
  val n = sc.nextInt()
  val d = sc.nextInt()
  val x = sc.nextInt()  
  val ret = for (i <- 1 to n) yield {
    calc(0, sc.nextInt(), List()).length
  }
  println(ret.sum + x)
  
  def calc(i: Int, a: Int, acc: List[Int]): List[Int] = {
    if (!acc.isEmpty && d < i*a+1) {
      acc
    } else {
      calc(i+1, a, acc:+(i*a+1))
    }
  }
}


Measured memory_bytes: 55396
a, b, c, x = int(input()), int(input()), int(input()), int(input())
ans = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if(500*i + 100*j + 50*k == x):
                ans += 1
                break
            elif(500*i + 100*j + 50*k > x):
                break
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>

int main() {
	int n, x, c = 0;
	while (scanf("%d %d", &n, &x) && (n != 0 || x != 0)) {
		for (int i = 1; i <= n; i++) {
			for (int j = i + 1; j <= n; j++) {
				for (int k = j + 1; k <= n; k++) {
					if (i + j + k == x) c++;
				}
			}
		}
		printf("%d\n", c);
		c = 0;
	}
	return 0;
}





Measured memory_bytes: 2720
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

multiset<lint> decomp(lint N){
    multiset<lint> res;
    for(int i=2;i<=1100000;i++){
        while(N%i==0) N/=i,res.insert(i);
        if(N==1) break;
        if(i==1100000) res.insert(N);
    }
    return res; 
}

int main(void){
    lint N;
    cin >> N;
    multiset<lint> ans=decomp(N);
    lint ans2=0;
    while(!ans.empty()){
        auto itr=ans.begin();
        lint num=ans.count(*itr);
        lint cnt=1;
        while(cnt<=num){
            ans2++;
            num-=cnt;
            cnt++;
        }
        ans.erase(*itr);
    }
    cout << ans2 << endl;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

int H,W;
string S[2010];
int L[2010][2010],R[2010][2010],D[2010][2010],U[2010][2010];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  cin >> H >> W;
  REP(i,H) cin >> S[i];
  REP(i,H) {
    int sum = 0;
    for (int j = 0; j < W; j++) {
      L[i][j] = sum;
      if (S[i][j] == '#') sum = 0;
      else sum++;
    }
  }
  REP(i,H) {
    int sum = 0;
    for (int j = W-1; j >= 0; j--) {
      R[i][j] = sum;
      if (S[i][j] == '#') sum = 0;
      else sum++;
    }
  }
  REP(j,W) {
    int sum = 0;
    for (int i = 0; i < H; i++) {
      U[i][j] = sum;
      if (S[i][j] == '#') sum = 0;
      else sum++;
    }
  }
  REP(j,W) {
    int sum = 0;
    for (int i = H-1; i >= 0; i--) {
      D[i][j] = sum;
      if (S[i][j] == '#') sum = 0;
      else sum++;
    }
  }
  int ans = 0;
  REP(i,H) REP(j,W) if (S[i][j] == '.') {
    CHMAX(ans, L[i][j]+R[i][j]+D[i][j]+U[i][j]+1);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 130688
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

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

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

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

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func grouping(h, w int, s []string, group [][]int) int {
	di := []int{0, 1, 0, -1}
	dj := []int{1, 0, -1, 0}
	bfs := func(i, j, id int) {
		que := make([][2]int, 0)
		que = append(que, [2]int{i, j})
		for len(que) > 0 {
			I, J := que[0][0], que[0][1]
			que = que[1:]
			for k := 0; k < 4; k++ {
				nextI, nextJ := I+di[k], J+dj[k]
				if nextI < 0 || h <= nextI || nextJ < 0 || w <= nextJ {
					continue
				}
				if group[nextI][nextJ] > 0 {
					continue
				}
				if s[I][J] == '#' && s[nextI][nextJ] == '.' {

				}
			}
		}
	}
	id := 0
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if group[i][j] == 0 {
				id++
				bfs(i, j, id)
			}
		}
	}
	return id
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	h, w := nextInt(), nextInt()
	s := make([]string, h)
	for i := range s {
		s[i] = next()
	}

	// group := make([][]int, h)
	// for i := range group {
	// 	group[i] = make([]int, w)
	// }
	// maxID := grouping(h, w, s, group)

	checked := make([][]bool, h)
	for i := range checked {
		checked[i] = make([]bool, w)
	}
	di := []int{0, 1, 0, -1}
	dj := []int{1, 0, -1, 0}
	ans := 0
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if checked[i][j] {
				continue
			}

			black, white := 0, 0
			// BFS
			que := make([][2]int, 0)
			que = append(que, [2]int{i, j})
			for len(que) > 0 {
				I, J := que[0][0], que[0][1]
				que = que[1:]
				if checked[I][J] {
					continue
				}
				checked[I][J] = true
				if s[I][J] == '#' {
					black++
				} else {
					white++
				}
				for k := 0; k < 4; k++ {
					nextI, nextJ := I+di[k], J+dj[k]
					if nextI < 0 || h <= nextI || nextJ < 0 || w <= nextJ {
						continue
					}
					if checked[nextI][nextJ] {
						continue
					}
					if s[I][J] != s[nextI][nextJ] {
						que = append(que, [2]int{nextI, nextJ})
					}
				}
			}

			ans += black * white
		}
	}

	puts(ans)
}


Measured memory_bytes: 6160
import numpy as np

n, k = map(int, input().split())
num_list = [int(i) for i in input().split()]
num_list = np.array(num_list)
num_list.sort()

neg = num_list[num_list < 0]
pos = num_list[num_list > 0]
zero =  num_list[num_list == 0]

def count(x):
    ans = 0
    if x >= 0:
        ans += len(zero) * n
    ans += np.searchsorted(num_list, x // pos, side="right").sum()
    ans += n * len(neg) - np.searchsorted(num_list, -(-x // neg), side="left").sum()
    ans -= np.count_nonzero(num_list * num_list <= x)
    return ans // 2

left = -(10 ** 18)
right = 10 ** 18

while left + 1 < right:
    mid = (left + right) // 2
    if count(mid) >= k:
        right = mid
    else:
        left = mid

print(right)

Measured memory_bytes: 32272
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
// #include <string>
using namespace std;

vector<string> split(string s, string delimiter)
{
    int pos_start = 0, pos_end, delim_len = delimiter.length();
    string token;
    vector<string> res;

    while ((pos_end = s.find(delimiter, pos_start)) != string::npos)
    {
        token = s.substr(pos_start, pos_end - pos_start);
        pos_start = pos_end + delim_len;
        res.push_back(token);
    }

    res.push_back(s.substr(pos_start));
    return res;
}

vector<int> dijkstra(int n, vector<vector<int>> adj_matrix)
{
    vector<int> d(n, 1e9);
    vector<int> prev(n);
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> Q;

    d[0] = 0;
    for (int i = 0; i < n; i++)
    {
        Q.push(make_pair(d[i], i));
    }

    while (!Q.empty())
    {
        int u = Q.top().second;
        // int c = Q.top().first;
        Q.pop();

        for (int i = 0; i < n; i++)
        {
            if (adj_matrix[u][i] > 0)
            {
                int tmp = d[u] + adj_matrix[u][i];
                if (tmp < d[i])
                {
                    d[i] = tmp;
                    prev[i] = u;
                    Q.push(make_pair(d[i], i));
                }
            }
        }
    }

    return d;
}

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

    int n;
    cin >> n;
    cin.ignore();
    vector<vector<int>> adj_matrix;
    adj_matrix.resize(n);
    for (int i = 0; i < adj_matrix.size(); i++)
    {
        adj_matrix[i].resize(n);
    }

    for (int i = 0; i < n; i++)
    {
        string s;
        getline(cin, s);
        vector<string> tmp = split(s, " ");
        int u = stoi(tmp[0]);
        int k = stoi(tmp[1]);

        for (int j = 2; j < tmp.size(); j += 2)
        {
            int v = stoi(tmp[j]);
            adj_matrix[u][v] = stoi(tmp[j + 1]);
        }
    }

    vector<int> ans = dijkstra(n, adj_matrix);
    for (int i = 0; i < n; i++)
    {
        cout << i << " " << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2")
int main()
{
	int a,b,c,k;
	cin>>a>>b>>c>>k;//c>b>a;
	if(c>b && b>a)	cout<<"Yes";
	else
	{
		bool c1=0;
		for(int i=1; i<=k; i++)
		{
		//	cout<<a<<" "<<b<<" "<<c<<endl;
			if(b>=c)
			{
				c*=2;
				continue;
			}
			if(a>=b)
			{
				b*=2;
				continue;
			}
			
			cout<<"Yes";
			c1=1;
			break;
		}
		if(c>b&&b>a && c1==0)	cout<<"Yes";
		else if(c1==0)
			cout<<"No";
	}
	return 0;
 }

Measured memory_bytes: 3636
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;*/
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define fb1(i,n) for(ll i=n;i>0;i--)
#define endd cout<<'\n';
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define all(x) x.begin(), x.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<ll>
#define pii pair<ll,ll>
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
//*X.find_by_order()
//X.order_of_key()
bool cmp(pair<ll,ll> a,pair<ll,ll> b){
    if(a.F!=b.F)
        return a.F<b.F;
    else
        return a.S>b.S;
}
ll mod=1000000007;
const ll N=200005;
int main()
{
fast;
    string s;
    cin>>s;
    ll n=s.size();
    ll sum=0;
    f(i,n)
    {
        sum+=(s[i]-'0');
    }
    if(sum%9!=0)
        cout<<"No";
    else
        cout<<"Yes";
    return 0;
}

Measured memory_bytes: 3768
using namespace std;

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <limits>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <numeric>
typedef long long ll;
typedef pair<int,int> p;

int main()
{
  int n,a,b;
  cin >> n >> a >> b;
  int res = 0;
  for (int i = 1; i <= n; i++){
    int tmp = i;
    int sum = 0;
    for (int j = 4; j >= 0; j--){
      sum += (tmp / int(pow(10, j)));
      tmp %= int(pow(10,j));
    }
    if (sum >= a && sum <= b) {
      res += i;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>

#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>

#include <algorithm>

using namespace std;
const int mod = 1000000007;
	

int main(int argc, char *argv[]) {
	
	vector<int> pos, neg;
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		if (t >= 0)
			pos.push_back(t);
		else
			neg.push_back(-t);
	}
	reverse(neg.begin(), neg.end());
	int res = 0x3f3f3f3f;
	for (int i = 0; i <= k; i++) {
		if (i == 0) {
			if (pos.size() >= k)
				res = min(res, pos[k - 1]);
		}
		else if (i == k) {
			if (neg.size() >= k)
				res = min(res, neg[k - 1]);
		}
		else {
			if (i <= pos.size() && k - i <= neg.size())
				res = min(res, pos[i - 1] + neg[k - i - 1] + min(pos[i - 1], neg[k - i - 1]));
		}
	}
	cout << res << endl;
}














Measured memory_bytes: 1020
(defun split (line)
  (with-input-from-string (stream line)
    (loop for obj = (read stream nil)
          while obj
          collect obj)))

(let* ((n (read))
       (ab (split (read-line)))
       (a (car ab))
       (b (cadr ab))
       (p (split (read-line))))
  (princ (min (count-if (lambda (x) (<= x a)) p)
              (count-if (lambda (x) (and (> x a) (<= x b))) p)
              (count-if (lambda (x) (>  x b)) p))))

Measured memory_bytes: 14820
(defun factorial (n)
  (if (zerop n)
      1
      (* n (factorial (1- n)))))

(defun all-permutations (list)
  (cond ((null list) nil)
        ((null (cdr list)) (list list))
        (t (loop for element in list
                 append (mapcar (lambda (l) (cons element l))
                                (all-permutations (remove element list)))))))

(defun distance-of-permutation (perm)
  (loop for (xy . rest) on perm
        while rest
        sum (destructuring-bind (x1 . y1) xy
              (destructuring-bind (x2 . y2) (first rest)
                (sqrt (+ (expt (- x2 x1) 2d0)
                         (expt (- y2 y1) 2d0)))))))

(defun distance-of-permutations (n permutations)
  (/ (loop for perm in permutations
           sum (distance-of-permutation perm))
     (factorial n)))

(defun solve (n points)
  (distance-of-permutations n (all-permutations points)))

#-swank
(let* ((n (read))
       (points (loop repeat n collect (cons (read) (read))))
       (*read-default-float-format* 'double-float))
  (format t "~A~%" (solve n points)))


Measured memory_bytes: 65760
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

using namespace std;
using ll = long long;

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 dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};


//////////////////////////////////////////////////


int main() {
    double n; cin >> n;
    vector<double> a(n);
    double sum = 0;
    rep(i, n) cin >> a[i], sum+=a[i];

    double avg = sum/n;

    int ans = 0;
    repf(i, 1, n) {
        if (abs(a[i]-avg) < abs(a[ans]-avg)) ans = i;
    }
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <limits.h>
#include <assert.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <bitset>
#include <vector>
using namespace std;

#define LL long long

#define fi first
#define se second
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(a,b) (((a)+(b))>>1)
#define maxx(a,b) ((a)<(b)?(b):(a))
#define minx(a,b) ((a)<(b)?(a):(b))
#define absx(a) ((a)<0?-(a):(a))
#define mk(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define itr iterator
#define lowbit(x) ((x)&-(x))

typedef unsigned LL ULL;
typedef unsigned uint;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;

template< typename T > inline void read(T &x) {
    bool f; char ch; f=0; x=0; ch=getchar();
    while(ch<'0' || ch>'9') {if(ch=='-') f=1; ch=getchar();}
    while(ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
    if(f) x=-x;
}

template< typename T > inline void Max(T &a, T b) {if(a<b) a=b;}
template< typename T > inline void Min(T &a, T b) {if(b<a) a=b;}
template< typename T > inline T Abs(T a) {if(a<0) return -a; else return a;}

const double pi=(double) acos(-1.0);
const int MOD=(int) 1e9+7;
const int INF=(int) 0x3f3f3f3f;
const LL  LINF=(LL) INF<<32|INF;
const int SINF=(uint) ~0>>1;
const LL  SLINF=(ULL) (-1)>>1;
const double DINF=(double) 1e50;
const double eps=(double) 1e-8;
const int maxn=(int) 2000+20;
const int maxm=(int) 1e5+20;
const int maxk=(int) 5e2+20;

inline int sig(double x) {return x<-eps?-1:x>eps;}

//--------------start------------------

int n;
int a[maxn];
int dp[maxn][2];
int X,Y;

int DP(int i,int t,int x,int y)
{
    if(i==n+1) return Abs(x-y);
    if(dp[i][t]!=-1) return dp[i][t];

    if(t)
    {
        int mx=-SINF;
        for(int j=i;j<=n;j++) Max(mx,DP(j+1,!t,a[j],y));
        return dp[i][t]=mx;
    }
    else
    {
        int mn=SINF;
        for(int j=i;j<=n;j++) Min(mn,DP(j+1,!t,x,a[j]));
        return dp[i][t]=mn;
    }
}

void work()
{
    read(n), read(X), read(Y);
    for(int i=1;i<=n;i++) read(a[i]);

    memset(dp,-1,sizeof(dp));
    printf("%d\n",DP(1,1,X,Y));

}

//--------------end--------------------

int main()
{
#ifdef yukihana0416
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif // yukihana0416
    work();
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long int
#define IOS ios_base::sync_with_stdio(false), cin.tie(NULL);
#define fr(i,a,b)  for(int i=a;i<=b;i++)
#define rf(j,b,a)  for(int j=b;j>=a;j--)
#define frr(k,a,b) for(int k=a;k<=b;k++)
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define ss second
#define ff first

using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
#define E 2000 
bool sortinrev(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
     if(a.first==b.first)
     {
     return (a.second < b.second); 
     }
     else
     {
       return (a.first > b.first); 
     }
     
} 
bool sortin(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
     return (a.second < b.second);   
} 
signed main()
{   
  IOS


int n,W;
cin>>n>>W;
int w[n+1],v[n+1];
int dp[n+1][W+1];
for(int i=1;i<=n;i++)
{
  cin>>w[i]>>v[i];
}
for(int i=0;i<=n;i++)
{
  for (int j = 0; j<=W ; j++)
  {
  if(i==0||j==0)
  {
    dp[i][j]=0;
  }
  else if(w[i]<=j)
  {
  dp[i][j]=max(v[i]+dp[i-1][j-w[i]],dp[i-1][j]); 
  }
  else
  {
    dp[i][j]=dp[i-1][j];
  }
  }

}
cout<<dp[n][W]<<endl;
}




 

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

using namespace std;

#define rep(i, j, k) for (int i = j; i < (int)k; i++)
#define pb push_back
#define mt make_tuple
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef complex<ld> point;
typedef vector<int> vi;

inline void fileIO(string s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}

template <class T, class S>
inline bool smin(T &a, S b) {
  return (T)b < a ? a = b, 1 : 0;
}
template <class T, class S>
inline bool smax(T &a, S b) {
  return a < (T)b ? a = b, 1 : 0;
}

constexpr int MOD = 998244353;
constexpr int N = 5e3 + 10;

template <typename T>
inline T mod(T &v) {
  return v = (v % MOD + MOD) % MOD;
}
template <typename S, typename T>
inline S add(S &l, T r) {
  return mod(l += r);
}
ll po(ll v, ll u) {
  return u ? po(v * v % MOD, u >> 1) * (u & 1 ? v : 1) % MOD : 1;
}

ll n, A, B, p[N], q[N], dp[N][N], psum[N][N];

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

#ifndef LOCAL
  // fileIO("superposition");
#endif

  cin >> n >> A >> B;
  rep(i, 0, n) {
    cin >> p[i];
    rep(j, p[i] + 1, n + 1) psum[j][i]++;
    q[p[i]] = i;
  }

  rep(i, 1, n + 1) partial_sum(psum[i], psum[i] + n + 1, psum[i]);

  for (int i = n - 1; ~i; i--)
    for (int j = n; j; j--) {
      if (q[j] < i)
        dp[i][j] = dp[i][j + 1];
      else
        dp[i][j] = min(dp[q[j] + 1][j + 1] +
                           (q[j] - i - (psum[j][q[j]] - psum[j][i - 1])) * A,
                       dp[i][j + 1] + B);
    }
  cout << dp[0][1] << endl;
  return 0;
}


Measured memory_bytes: 392064
# https://atcoder.jp/contests/abc163/tasks/abc163_c
N=int(input())
A=[0,0]
A[2:]=[int(x) for x in input().split()]
dict1={}
for i in range(2,N+1):
    tmp=str(A[i])
    if (not tmp in dict1):
        dict1[tmp]=1
    else:
        dict1[tmp]+=1
for i in range(1,N+1):
    if (str(i) in dict1):
        print(dict1[str(i)])
    else:
        print(0)

Measured memory_bytes: 45600
#include<stdio.h>

// 線形探索
int search(int A[], int n, int key) {
  int i = 0;
  A[n] = key;
  while ( A[i] != key ) i++;
  return i != n;
}

int main() {
  int i, n, A[10000+1], q, key, sum = 0;

  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) scanf("%d", &A[i]);

  scanf("%d", &q);
  for ( i = 0; i < q; i++ ) {
    scanf("%d", &key);
    if ( search(A, n, key) ) sum++;
  }
  printf("%d\n", sum);

  return 0;
}


Measured memory_bytes: 2712
n = int(input())
r1 = int(input())
r2 = int(input())
m = r1 if r1 < r2 else r2
d = r2 - r1
for i in range(n-2):
    r = int(input())
    if r - m > d:
        d = r - m
    if r < m:
        m = r
print(d)


Measured memory_bytes: 5612