akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <iostream>
#include <vector>
using namespace std;
void reverseStringInPlace(std::string &stringToReverse)
{
    int numCharacters = stringToReverse.length();
    for (int i=0; i<numCharacters/2; i++)
    { std::swap(stringToReverse[i], stringToReverse[numCharacters-i-1]); }
}

string lcs(string s,string t) {
    vector<vector<int>> x(s.size()+1,vector<int>(t.size()+1));
    for (int i=0;i<=s.size();i++){
        x[i][0]=0;
    }
    for (int i=0;i<=t.size();i++){
        x[0][i]=0;
    }
    for (int i=1;i<=s.size();i++){
        for(int j=1;j<=t.size();j++){
            int diagonal = 0;
            int upleft = max(x[i-1][j],x[i][j-1]);
            if (s[i-1]==t[j-1]) {
             diagonal = x[i-1][j-1]+1;
            }
            x[i][j]=max(diagonal,upleft);
        }
    }
    string answer = "";
    int i = s.size();
    int j = t.size();
    int value = x[i][j];
    while (value!=0){
        if (i>0 && x[i-1][j]==value){
            i--;
        }
        else if (j>0 && x[i][j-1]==value)
        {
            j--;
        }
        else{
            i--;
            j--;
            answer.push_back(s[i]);
            value--;
        }
        
    }
    reverseStringInPlace(answer);
    return answer;
}


int main() 
{
    string s;
    string t;
    cin >> s;
    cin >> t;
    cout << lcs(s,t);
    return 0;
}


Measured memory_bytes: 35584
#include<stdio.h>

int nextInt();
int med3(int x, int y, int z);
void quickSort(int a[], int left, int right);
void sort(int a[], int size);
int lower_bound(int A[], int N, int K);


int N, q, i;
int A[100005];
int vt[100005];
int dp[100005];
long long int X[100005];

int main() {
	N = nextInt();
	q = nextInt();
	for(i=0; i<N;i++){
		A[i] = nextInt();
	}
	sort(A, N);

	int r = N/2;
	int l = 1;
	if(N%2){l--;}
	int cnt=0;
	long long int sum = 0;
	for(i=r; i<N; i++){
		sum += A[i];
	}
	while(l<r){
		dp[cnt++] = (A[l]+A[r])/2;
		X[cnt-1] = sum;
		sum -= A[r];
		sum += A[l];
		l+=2;
		r++;
	}
	X[cnt] = sum;
	while(q--){
		int a = nextInt();
		int idx = lower_bound(dp, cnt, a);
		printf("%lld\n", X[idx]);
	}
	return 0;
}

int nextInt(){
	int f=0; char c=getchar();
	while((c<'0')||('9'<c)){c=getchar();}
	while((c>='0')&&(c<='9')){f=f*10+(c-'0'); c=getchar();}
	return f;
}

int med3(int x, int y, int z){
	if(x < y){
		if (y < z){return y;}else if(z < x){return x;}else{return z;}
	} else {
		if (z < y){return y;}else if(x < z){return x;}else{return z;}
	}
}

void quickSort(int a[], int left, int right){
	if(left >= right){return;}
	int pivot = med3(a[left], a[left+(right-left)/2], a[right]);
	int l=left, r=right;
	while(1){
		while (a[l] < pivot){l++;}
		while (pivot < a[r]){r--;}
		if(l>=r){break;}
		int t=a[l]; a[l]=a[r]; a[r]=t;
		l++; r--;
	}
	quickSort(a, left, l-1);
	quickSort(a, r+1, right);
}

void sort(int a[], int size){
	quickSort(a, 0, size-1);
}

int lower_bound(int A[], int N, int K){
	int lb = -1;
	int ub = N;
	while(lb+1 < ub){
		int mid = lb+(ub-lb)/2;
		if(A[mid] >= K){
			ub = mid;
		}else{
			lb = mid;
		}
	}
	return ub;
}


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

int n, m;
int edge[9][9];
bool visited[9];

int dfs(int now) {
	bool flag = true;
	for (int i = 1; i <= n; i++) {
		if (!visited[i]) {
			flag = false;
		}
	}
	if (flag) {
		return 1;
	}

	int res = 0;
	for (int i = 1; i <= n; i++) {
		if (edge[now][i] && !visited[i]) {
			visited[i] = true;
			res += dfs(i);
			visited[i] = false;
		}
	}
	return res;
}

int main() {
	for (int i = 0; i < 9; i++) {
		for (int j = 0; j < 9; j++) {
			edge[i][j] = 0;
		}
	}

	for (int i = 0; i < 9; i++) {
		visited[i] = false;
	}

	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		edge[a][b] = 1;
		edge[b][a] = 1;
	}
	
	visited[1] = true;
	int ans = dfs(1);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import sys

def dp(i, xy, l):
    if l[i] >= 0:
        return l[i]
    l[i] = t = max(dp(j, xy, l) for j in xy[i]) + 1
    return t

def main():
    sys.setrecursionlimit(10 ** 6)
    N, M = map(int, input().split())
    xy = [set() for _ in range(N)]
    for _ in range(M):
        xi, yi = map(int, input().split())
        xy[xi - 1].add(yi - 1)
    l = [0 if not i else -1 for i in xy]
    m = 0
    for i in range(N):
        m = max(m, dp(i, xy, l))
    print(m)


main()


Measured memory_bytes: 133400
#include <bits/stdc++.h>
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using namespace std;
using pii=pair<int,int>;

int pa[100001],n;
vector<pii> xp,yp;

struct edge{
    int u,v,w;
    edge() {}
    edge(int u,int v,int w):u(u),v(v),w(w) {}
    bool operator<(const edge &rhs)const {
        return w<rhs.w;
    }
};
vector<edge> ev;

void add(vector<pii> &arr) {
    for(int i=0;i<sz(arr)-1;i++) ev.push_back(edge(arr[i].se,arr[i+1].se,arr[i+1].fi-arr[i].fi));
}
int find(int cur) {return cur==pa[cur] ? cur : pa[cur]=find(pa[cur]);}
bool merge(int u,int v) {
    u=find(u); v=find(v);
    if(u==v) return false;

    pa[v]=u;
    return true;
}

int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++) {
        int x,y;
        scanf("%d%d",&x,&y);
        xp.push_back(pii(x,i));
        yp.push_back(pii(y,i));
    }
    sort(xp.begin(),xp.end());
    sort(yp.begin(),yp.end());

    add(xp);
    add(yp);

    sort(ev.begin(),ev.end());
    
    long long ans=0;
    for(int i=0;i<n;i++) pa[i] =i;
    for(auto &e:ev) {
        if(merge(e.u,e.v)) {
            ans += e.w;
        }
    }
    printf("%lld\n",ans);

    return 0;
}


Measured memory_bytes: 7144
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations, accumulate
from operator import add, mul, sub, itemgetter, attrgetter


import sys
# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 1 << 60


def read_int():
    return int(readline())


def read_int_n():
    return list(map(int, readline().split()))


def read_float():
    return float(readline())


def read_float_n():
    return list(map(float, readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def ep(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.perf_counter()
        ret = f(*args, **kwargs)
        e = time.perf_counter()

        ep(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, X, M):
    ans = 0
    x = X
    x %= M
    # if math.gcd(X, M) != 1:
    if False:
        for _ in range(N):
            ans += x
            x *= x
            x %= M
            if x == 0:
                break
        return ans
    else:
        x = X
        s = [X]
        u = set()
        while True:
            x *= x
            x %= M
            s.append(x)
            if x in u:
                break
            u.add(x)

        i = s.index(s[-1])
        if i + 1 >= N:
            return sum(s[:N]) % M

        N -= i
        ans += sum(s[:i])

        s = s[i:]
        s.pop()
        ss = sum(s)
        ans += (N // len(s)) * ss
        ans += sum(s[:N%len(s)])
        return ans


def main():
    N, X, M = read_int_n()
    print(slv(N, X, M))

    # N = 10**10
    # X = random.randint(1, 10**5)
    # M = random.randint(1, 10**5)
    # N, X, M = 10000000000, 82162, 79872
    # print(N, X, M)
    # print(slv(N, X, M))

if __name__ == '__main__':
    main()


Measured memory_bytes: 88824
#include <stdio.h>
#define MAX 46

typedef struct{
  int stuff;
  int jud;
}Fin;

Fin F[MAX];

int fibonacci(int );
int main(){
  int in;
  F[0].stuff=1;
  F[1].stuff=1;
  scanf("%d",&in);
  fibonacci(in);
  printf("%d\n",F[in]);
  return 0;
}



int fibonacci(int n){
  if(n==0 || n==1){
    return F[n].stuff=1;
  }
  if(F[n].jud==1){
    return F[n].stuff;
  }
  F[n].jud=1;
  return F[n].stuff=fibonacci(n-2)+fibonacci(n-1);
}



Measured memory_bytes: 2112
import sys, re
import math
import numpy as np
from decimal import Decimal
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul	# 
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd	# 最大公約数
from heapq import heappush, heappop

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.maxsize = 10 ** 15
sys.setrecursionlimit(10 ** 9 + 7)
INF = float('inf')
MOD = 10 ** 9 + 7

# -*- coding: utf-8 -*-

n = input()
if n[-1] == "s":
    print(n + "es")
else:
    print(n + "s")

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define endl '\n'
#define w(t) int t;cin>>t;while(t--)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define rep(i,a,b) for(int i=a; i<b; ++i)
#define repl(i,a,b) for(ll i=a; i<b; ++i)


int main(){
	IOS

	int k;
  	cin>>k;
	string s;
	cin>>s;
	int sz = s.size();
	if(sz>k){
		rep(i,0,k)
			cout<<s[i];
		cout<<"..."<<endl;
	}
	else
		cout<<s<<endl;
}

Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;
using vec=vector<int>;
using mat=vector<vec>;
int mod=1e9+7;
mat mul(mat &a,mat &b)
{
  mat res(a.size(),vec(b[0].size(),0));
  for(int i=0;i<a.size();i++)
  {
    for(int k=0;k<b.size();k++)
    {
      for(int j=0;j<b[0].size();j++)
      {
        res[i][j]+=(ll)a[i][k]*b[k][j]%mod;
        res[i][j]%=mod;
      }
    }
  }
  return res;
}

mat pow(mat &a,ll n)
{
  mat b(a.size(),vec(a.size(),0));
  for(int i=0;i<a.size();i++)
  {
    b[i][i]=1;
  }
  while(n>0)
  {
    if(n&1)b=mul(b,a);
    a=mul(a,a);
    n>>=1;
  }
  return b;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k;
  cin>>n>>k;
  mat p(n,vector<int>(n,0));
  rep(i,n)rep(j,n)cin>>p[i][j];
  mat x(n,vector<int>(1,1));
  auto q=pow(p,k);
  mul(q,x);
  int res=0;
  rep(i,n)rep(j,n){res+=q[i][j];res%=mod;}
  cout<<res<<endl;




  return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>

int main(int argc, char** argv)
{
	int N, M, num, ans;
	std::pair<int, int> ABM;
	std::vector<std::pair<int,bool>> H;
	std::cin >> N >> M;
	for (int i = 0; i < N; i++)
	{
		std::cin >> num;
		H.push_back(std::pair<int,bool>(num,true));
	}
	for (int i = 0; i < M; i++)
	{
		std::cin >> ABM.first >> ABM.second;
		ABM.first --;
		ABM.second--;
		if (H[ABM.first].first <= H[ABM.second].first)
		{
			H[ABM.first].second = false;
		}
		if (H[ABM.first].first >= H[ABM.second].first)
		{
			H[ABM.second].second = false;
		}
	}
	ans = 0;
	for (std::pair<int, bool> x : H)
	{
		if (x.second) ans++;
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 4316
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    int n;
    double t,a;
    cin >> n;
    cin >> t >> a;
    vector<double> vec(n);

    int pos=1;
    double h;
    
    rep(i,n){
        cin >> h;
        vec[i] = t - h*0.006;
    }
    double tmp = vec[0];

    reps(i,1,n){
        if(abs(a-tmp) > abs(a-vec[i])){
            pos = i+1;
            tmp = vec[i];
        }
    }

    cout << pos << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int x,y,flgx,flgy;
  cin >>x;
  cin >>y;
  int g1[7]={1,3,5,7,8,10,12};
  int g2[4]={4,6,9,11};
  for(int i = 0; i < 7; i++){
    if(x == g1[i]) flgx = 1;
    if(y == g1[i]) flgy = 1;
  }
  for(int i = 0; i < 4; i++){
    if(x == g2[i]) flgx = 2;
    if(y == g2[i]) flgy = 2;
  }
    if(x == 2) flgx = 3;
    if(y == 2) flgy = 3;
    if(flgx == flgy){
      cout << "Yes" <<endl;

    }else{
      cout << "No" << endl;
    }
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var ABCD = ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
        var (A, B, C, D) = (ABCD[0], ABCD[1], ABCD[2], ABCD[3]);

        if (C > D)
            (C, D) = (D, C);

        var Lcm = GcdLcm.Lcm(C, D);

        var ACO = MathExt.DivideAndRoundUp(A, C);
        var ACX = A - ACO;
        var ADO = MathExt.DivideAndRoundUp(A, D);
        var ALcmO = MathExt.DivideAndRoundUp(A, Lcm);
        var ACDX = ACX - ADO + ALcmO;

        var BCO = MathExt.DivideAndRoundUp(B + 1, C);
        var BCX = B + 1 - BCO;
        var BDO = MathExt.DivideAndRoundUp(B + 1, D);
        var BLcmO = MathExt.DivideAndRoundUp(B + 1, Lcm);
        var BCDX = BCX - BDO + BLcmO;

        var ans = BCDX - ACDX;

        WriteLine(ans);
    }
}
static class GcdLcm
{
    public static long Gcd(long a, long b) => (b != 0) ? Gcd(b, a % b) : a;
    public static long Lcm(long a, long b) => a / Gcd(a, b) * b;
}
static class MathExt
{
    public static int DivideAndRoundUp(int x, int y) => (x + y - 1) / y; // (int)Math.Ceiling((double)x / (double)y);
    public static long DivideAndRoundUp(long x, long y) => (x + y - 1) / y;
}


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

using ll = long long;
//typedef long long ll;

#define INF ((1LL << 31) - 1)
#define MOD int(1e9+7)
#define repi(i,j,n) for(it i = (j), i < (n); ++i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()

inline void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int a, b, c;

int main() {
    cin >> a >> b >> c;
    if (a == b) cout << c << endl;
    else if (a == c) cout << b << endl;
    else if (b == c) cout << a << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int cmp(const void *lhs, const void *rhs) {
    return *(int*)lhs - *(int*)rhs;
}

int main () {
    int data[3];

    scanf("%d", &data[0]);

    while(scanf("%d %d %d", &data[0], &data[1], &data[2]) != EOF ) {
        qsort(data, 3, sizeof(int), cmp);
        if ( data[0] * data[0] + data[1] * data[1] == data[2] * data[2] )
            printf("YES\n");
        else
            printf("NO\n");
    }

    return 0;
}

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

int main()
{
    int n;
    cin>>n;
    int h[n];
    int dp[n];

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

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

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

Measured memory_bytes: 1024
#coding:utf-8

n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))

#各地点と平均気温aとの差の絶対値を格納するリスト
diff = [0] * n
for i in range(0,n):
    diff[i] = abs(a - (t - h[i] * 0.006))

#差が最小の要素のインデックスを抽出
print(diff.index(min(diff)) + 1)

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

int main() {
  int N;
  cin >> N;
  
  vector<int> A(N);
  vector<int> number(N);
  
  for(int i = 0; i < N; i++) {
    cin >> A.at(i);
    number.at(A.at(i) - 1) = i + 1;
  }
  
  for(int i = 0; i < N; i++) cout << number.at(i) << ' ';
    
}

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

int main()
{
    string s;
    int k;
    cin >> s >> k;
    int n = s.size();
    set<string> st;
    for (int i = 0; i < n; i++)
    {
        for (int j = 1; j <= 5; j++)
        {
            st.emplace(s.substr(i, j));
        }
    }
    int count = 0;
    for (auto &t : st)
    {
        if (++count == k)
        {
            cout << t << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 100
string s[N];
int a[N];

int main(){
	int n; cin >> n;
	REP(i, n){
		cin >> s[i] >> a[i];
	}
	string x; cin >> x;
	REP(i, n){
		if(s[i] == x){
			int ans = 0;
			FOR(j, i+1, n) ans += a[j];
			cout << ans << endl;
		}
	}
}


Measured memory_bytes: 256
from collections import deque

n, q = map(int, input().split())
que = deque([])
for i in range(n):
    name, time = input().split()
    que.append({'name': name, 'time': int(time)})

past = 0
while len(que) > 0:
    np = que.popleft()
    if q < np['time']:
        np['time'] = np['time'] - q
        que.append(np)
        past += q
    else:
        past += np['time']
        print(np['name'], past)


Measured memory_bytes: 21408
import bisect
import itertools

A, B, Q = map(int, input().split())
INF = 10 ** 15
S = [-INF] + [int(input()) for _ in range(A)] + [INF]
T = [-INF] + [int(input()) for _ in range(B)] + [INF]

for _ in range(Q):
    answer = INF
    x = int(input())
    si = bisect.bisect_left(S, x)    
    ti = bisect.bisect_left(T, x)
    for s, t in itertools.product(S[si-1:si+1], T[ti-1:ti+1]):
        d = min(abs(s-x), abs(t-x)) + abs(t-s)            
        answer = min(answer, d)
    print(answer)

Measured memory_bytes: 12824
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for (ll i = 0; i < (n); ++i)

int n, k;
int p[1000];

int main() {
    cin >> n >> k;

    rep(i,n) cin >> p[i];

    sort(p,p+n);

    int sum = 0;
    rep(i,k) sum += p[i];

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define X real()
#define Y imag()
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const double EPS = 1e-8;
const double INF = 1e12;
const double PI = acos(-1);
typedef complex<double> P;
typedef complex<double> point;
namespace std {
	bool operator < (const P& a, const P& b) {
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
}
double cross(const P& a, const P& b) {
	return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
	return real(conj(a)*b);
}

struct L : public vector<P> {
	L(const P &a, const P &b) {
		push_back(a); push_back(b);
	}
};

typedef vector<P> G;
typedef vector<P> polygon;

struct C {
	P p; double r;
	C(const P &p, double r) : p(p), r(r) { }
};
//??????????????????
int ccw(P a, P b, P c) {
	b -= a; c -= a;
	if (cross(b, c) > 0)   return +1;       // counter clockwise
	if (cross(b, c) < 0)   return -1;       // clockwise
	if (dot(b, c) < 0)     return +2;       // c--a--b on line
	if (norm(b) < norm(c)) return -2;       // a--b--c on line
	return 0;
}

double getArea(const polygon& pol) {
	int n = pol.size();
	double s = 0.0;
	for(int i = 0; i < n; i++) {
		int now = i, nxt = (i + 1) % n;
		s += (pol[now].X - pol[nxt].X) * (pol[now].Y + pol[nxt].Y);
	}
	return abs(s/2.0);
}

int main(){
	int n;
	while(cin >> n && n > 0) {
		vector<P> ps;
		rep(i, n) {
			double x, y;
			cin >> x >> y;
			ps.pb({x, y});
		}
		double S = 0.0;
		S = getArea(ps);
		G rect;
		double l = INF, r = -INF, u = -INF, d = INF;
		rep(i, 4) {
			double x, y;
			cin >> x >> y;
			rect.pb({x, y});
			l = min(l, x);
			r = max(r, x);
			u = max(u, y);
			d = min(d, y);
		}
		G pp;
		rep(i, n) {
			double x, y;
			if(ps[i].X > r) x = r;
			else if(ps[i].X < l) x = l;
			else x = ps[i].X;
			if(ps[i].Y > u) y = u;
			else if(ps[i].Y < d) y = d;
			else y = ps[i].Y;
			pp.pb({x, y});
		}
		double s = 0.0;
		s = getArea(pp);
		printf("%d\n", (int)(abs(S) - abs(s) + EPS));
		//cout << S <<" " << s << endl;
	}
}

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

int main(){
    int n,a;
    int _max=0, _min=INT_MAX;
    cin >> n;

    for(int i=0; i<n; i++){
        cin >> a;
        _max=max(_max,a);
        _min=min(_min,a);
    }

    cout << abs(_max-_min) << endl;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

vector<vector<pair<int, int>>> g;

vector<int> ans;

void dfs(int n, int par = -1) {
    for (auto t : g[n]) {
        if (ans[t.first] != -1) continue;
        if (t.first == par) continue;

        if (t.second % 2 == 0) {
            ans[t.first] = ans[n];
        } else {
            ans[t.first] = 1 - ans[n];
        }

        dfs(t.first, n);
    }
}

int main() {

    int n; cin >> n;

    ans.resize(n);
    for (int i = 0; i < n; ++i) {
        ans[i] = -1;
    }

    g.resize(n);
    for (int i = 0; i < n-1; ++i) {
        int u, v, w; cin >> u >> v >> w;
        --u; --v;

        g[u].push_back(make_pair(v, w));
        g[v].push_back(make_pair(u, w));
    }

    ans[0] = 0;
    dfs(0);

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

Measured memory_bytes: 8960
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		for (int n = 1; n <= a; n++){
			int c1 = n % 10;
			int c2 = (n / 10) % 10;
			int c3 = (n / 100) % 10;
			int c4 = (n / 1000);
			if (n%3==0||c1==3||c2==3||c3==3||c4==3){
				System.out.print(" " + n);
			}
		}
		System.out.println("");
		
		sc.close();
	}
}



Measured memory_bytes: 28872
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		//Input
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());

		int[] A = new int[N];
		for(int i = 0 ; i < N ; i++ ) {
			A[i] = Integer.parseInt(sc.next());
		}

		//Logic
		long answer = 0;
		long minusNum = 0;
		long minNum = 1000000001;
		for(int i = 0 ; i < N ; i++) {
			answer += Math.abs(A[i]);
			if(A[i] < 0) {
				minusNum += 1;
			}
			minNum = Math.min(minNum, Math.abs(A[i]));
		}

		//Output
		if(minusNum % 2 != 0) {
			answer = answer - (2 * minNum);
		}
		System.out.println(answer);

	}

}


Measured memory_bytes: 48572
fn main() {
    let v = read_vec::<i32>();
    let a = v[0];
    let b = v[1];
    let c = v[2];
    yn(c >= a && c <= b);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

typedef long long ll;
typedef double db;
typedef long double ld;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vector<int>>  vvi ;
typedef vector<vc> vvc;
typedef pair<int,int> pi;
typedef vector<pair<int,int>> vpi ;

#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define rall(x) x.rbegin(), x.rend()
#define F first 
#define S second
#define pb push_back 
#define mp make_pair
#define ar array
#define lb lower_bound
#define ub upper_bound
#define FIO freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define mem(X,val) memset(X, val, sizeof((X)))
#define FOR(i, n) for(int i = 0 ; i < (int) n ; ++i)
#define UNQ(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define P(x) cout << x <<'\n';
#define W(x) cout << x;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const db PI = acos(-1);
const ll mod = 1e9+7;
template <typename A, typename B>istream& operator>>(istream& input,pair<A,B>& x) {input>>x.F>>x.S;return input;}
template <typename A>istream& operator>>(istream& input,vector<A>& x) {for(auto& i:x)input>>i;return input;}
template<typename A>ostream& operator<<(ostream& output,vector<A>& x) {for(auto& i:x)output<<i<<' ';return output;}
template<class T> void _R(T &x) { cin >> x; } void R() {}template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...);}
template <class T>void smax(T& x,T y){ if(x<y)x=y;}
template <class T>void smin(T& x,T y){ if(x>y)x=y;}
template<typename T1, typename T2> T1 powz(T1 A, T2 B);
template <typename T1, typename T2>T1 ADD(T1,T2);
template <typename T1, typename T2>void ADDZ(T1&,T2);
template<class T1, class T2> T1 mul(T1 A, T2 B);
template<typename T1, typename T2> T1 GCD(T1 A,T2 B);
template<typename T1> T1 MOD(T1 A){return (A%mod + mod)%mod;}
/***************************************************main code**************************************************************/
const int MXN=1e6+5;
const ll INF = 9e18+200;
const int inf = 1e9+100;
const int mxn = 2e5+20;

void test_case()
{
	ll n,a,b;
	R(n,a,b);
	ll x = n/(a+b);
	ll y = n%(a+b);
	x*=a;
	if(y>=a)x+=a;
	else x+=y;
	W(x);
	
	
	
}

/*************----------------------------******************/
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	int Tests = 1;
	//cin >> Tests;
	
	for(int tc = 1; tc <= Tests; ++tc){
		//cout <<"Case #"<<tc<<": ";
		test_case();
		cout<<'\n';
	}
		
}
template <typename T1, typename T2> 
T1 ADD(T1 A, T2 B)
{
	ll res = (A+B)%mod;
	if(res<0)res+=mod;
	return res;
}
template <typename T1, typename T2> 
void ADDZ(T1& A, T2 B)
{
	ll res = (A+B)%mod;
	if(res<0)res+=mod;
	A = res;
}
template<typename T1, typename T2>
T1 powz(T1 X,T2 B)
{
	ll A = X;
	ll res=1;
		A%=mod; 
		assert(B>=0); 
	for( ; B ; B>>=1){
		if(B&1)res=res*A%mod;
		A= A*A%mod;
	}
	return res;
}
template<typename T1, typename T2> 
T1 GCD(T1 A,T2 B)
{
	 return B?GCD(B,A%B):A;
}
template <class T1 , class T2> 
T1 mul(T1 A, T2 B)
{
	ll res = 1;
	res = (1LL * A%mod * B%mod )%mod;
	return res;
}


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

#define MOD 1000000007
#define INF 1000000001

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


template <class T>
ostream &operator<<(ostream &o, const vector<T>&obj) {
    o << "["; for (int i = 0; i < (int)obj.size(); ++i) o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U>&obj) {
    o << "(" << obj.first << ", " << obj.second << ")"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const set<T>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const queue<T>&obj) {
    queue<T> obj_cp = obj;
    bool first = true;
    o << "{";
    while (!obj_cp.empty()) { o << (!first ? ", " : "") << obj_cp.front(); obj_cp.pop(); first = false; }
    o << "}"; return o;
}

void print() {
    cout << "\n";
}
template<class Head, class... Body>
void print(Head head, Body... body) {
    cout << head << " ";
    print(body...);
}


int main(int argc, char const *argv[]) {
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    for (int i = 0; i < N; ++i) {
        cin >> h[i];
    }

    vector<int> dp(N, INF);
    dp[0] = 0;
    for (int i = 1; i < N; ++i) {
        for (int k = 1; k <= min(K, i); ++k) {
            dp[i] = min(dp[i], dp[i-k] + abs(h[i] - h[i-k]));
        }
    }
    cout << dp[N-1] << endl;

    return 0;
}


Measured memory_bytes: 1024
import sys


class Plain:
    def __init__(self, mat):
        self.plain = mat

    def show(self):
        for i in range(8):
            print self.plain[i]

    def shift(self):
        while all_zero(self.plain[0]):
             shift_lis(self.plain)
        while all_zero(map(lambda x: x[0], self.plain)):
            map(shift_lis, self.plain)
        return self

    def match_figure(self, figs):
        for (name, fig) in figs:
            if self.match(fig):
                return  name

    def match(self, fig):
        lx = len(fig[0])
        ly = len(fig)
        result = True
        for y in range(ly):
            for x in range(lx):
                if not fig[y][x] == self.plain[y][x]:
                    result = False
        return result


def all_zero(lis):
    return sum(lis) == 0 

def shift_lis(lis):
    a = lis.pop(0)
    lis.append(a)
    return lis

A = [[1,1],[1,1]]
B = [[1],[1],[1],[1]]
C = [[1,1,1,1]]
D = [[0,1],[1,1],[1,0]]
E = [[1,1,0],[0,1,1]]
F = [[1,0],[1,1],[0,1]]
G = [[0,1,1],[1,1,0]]

figures = zip("ABCDEFG", [A,B,C,D,E,F,G])

while True:
    try:
        p = []
        for i in range(8):
            p.append(map(int, list(raw_input())))
        plain = Plain(p)
        plain.shift()
        print plain.match_figure(figures)
        raw_input()
    except:
        exit()

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

typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()
#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en
#define le length()
#define mp make_pair
#define mt make_tuple
#define acc(v) accumulate(all(v), 0)
#define F first
#define S second
#define INF lli(1e19)

#define forz(i, n) for (lli i = 0; i < n; i++)
#define fore(i, m, n) for (lli i = m; i < n; i++)
#define rforz(i, n) for (lli i = n - 1; i >= 0; i--)
#define rfore(i, m, n) for (lli i = n - 1; i >= m; i--)
#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define highll(n) __builtin_popcountll(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)
#define lb lower_bound
#define ub upper_bound
#define er equal_range
#define maxe *max_element
#define mine *min_element
#define mod 1000000007
#define mod2 998244353
#define gcd __gcd
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define newline cout<<endl;
//#define endl "\n"



inline lli power(lli x, lli y, lli p = mod)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

inline lli modadd(lli a, lli b, lli m = mod)
{
    a += b;
    if (a >= m)
        a -= m;
    return a;
}

inline lli modmul(lli a, lli b, lli m = mod)
{
    return ((a % m) * (b % m)) % m;
}

inline lli modi(lli a, lli m = mod) { return power(a, m - 2, m); }
inline lli md(lli x) {if(x>=0)return x; return -x;}
///////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
lli n,m,k,r;
//lli u, v;
//bool vis[3030];
//vector<lli> adj[3030];
//void init()
//{
//    forz(i,n) vis[i]=0, adj[i].clear();
//}


int32_t main()
{
    kira;

    lli T=1;
    //cin>>T;

    while(T--)
    {
        cin>>n;
        lli a[n];
        r = 0;
        forz(i,n)
        {
            cin>>a[i];
        }
        for(int i = 1; i<n; ++i) if(a[i]<a[i-1]) r+= a[i-1]-a[i], a[i]=a[i-1];
        cout<<r<<endl;

    }

    return 0;

}


Measured memory_bytes: 5216
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
int main()
{
    string temp;
    cin >> temp;
    vector <int> number;
    int i;
    for(i = 0;i < temp.size();++i){
        number.push_back(temp.at(temp.size() - i - 1) - '0');
    }
    i = 0;
    ll ans = 0;
    while(true){
        if(i == number.size()){
            break;
        }
        if(number.at(i) <= 4){
            ans += number.at(i);
        }else{
            if(i != number.size()-1){
                if(number.at(i) >= 6){
                    ans += 10 - number.at(i);
                    ++number.at(i+1);
                }else if(number.at(i) == 5){
                    if(number.at(i+1) >= 5){
                        ans += 5;
                        ++number.at(i+1);
                    }else{
                        ans += 5;
                    }
                }
            }else{
                if(number.at(i) >= 6){
                    ans += 1;
                    ans += 10 - number.at(i);
                }else{
                    ans += 5;
                }
            }
        }
        ++i;
    }
    cout << ans << endl;
    return 0;
}

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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (int i=0; i<n; i++)
#define	Rep1(i, n)	for (int i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)
// while (getline(cin, S)) {}

// #include <cstdio>
// int a; ll B;
// scanf("%d %lld", &a, &B);
// printf("%d\n", a);
//
// for (int i=0; i<n; ++i)
// 	scanf("%d", &a[i]);
//
// char c;
// scanf(" %c", &c);
//
// cout << "\n";

// cout <<fixed <<setprecision(10)

// priority_queue<int> q;
// priority_queue<int, vector<int>, less<int>> q; // Default: vector, less
// priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

//
// Notes
//
// When specified less than N, try full scan.
// RE: empty vector
// Check Qs
// long/int
// xor -> count each bit
// Check values
// 	1,000,000 -> Loop
// 	100,000	-> vector(int:400KB, long:800KB) 

/*
ll	myPow(ll x, ll n) {
	if (0==n)
		return 1;
	if (0==n%2)
		return myPow(x*x%MOD, n/2);
	else
		return x*myPow(x, n-1)%MOD;
}
*/
ll	myPow(ll x, ll n) {
	ll r=1;
	while(n>0)
		if (0==n%2) {
			x *=x;
			x %=MOD;
			n /=2;
		} else {
			r *=x;
			r %=MOD;
			n--;
		}
	return r;
}

int	main() {
	ll N, M;
	cin >>N >>M;
	vector<ll> A(M, 0);
	Rep0(i, M)
		cin >>A.at(i);
	for (auto AA: A)
		N -=AA;
	if (N<0)
		cout <<-1 <<endl;
	else
		cout <<N <<endl;
	return 0;
}



Measured memory_bytes: 3632
n,d = map(int, input().split())
a = [list(map(int,input().split())) for _ in range(n)]
cnt = 0
for i in range(n-1):
    for j in range(i+1,n):
        s = 0
        for k in range(d):
            s+=(abs(a[i][k]-a[j][k]))**2
        if s**0.5==int(s**0.5):
            cnt+=1
print(cnt)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define lli long long int
using namespace std;
int main()
{
    lli n,m;
    cin>>n>>m;
    vector<lli>v;
    lli total=0;
    for(lli i=0;i<n;i++)
    {
        lli x;
        cin>>x;
        total+=x;
        v.push_back(x);
    }
    lli x=(total+4*m-1)/(4*m);
    sort(v.rbegin(),v.rend());
    lli cnt=0;
    for(lli i=0;i<m;i++)
    {
        if(v[i]>=x)
            cnt++;
    }
    if(cnt==m)
    {
        cout<<"Yes";
    }
    else
        cout<<"No";
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll solve(ll l,ll r,ll div)
{
    return r/div - (l-1)/div;
}
int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll gcm = c*d/__gcd(c,d);
    cout<<(b-a+1)-(solve(a,b,c)+solve(a,b,d)-solve(a,b,gcm));
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 1145141919
#define ll long long
//#define scanf scanf_s
bool p[260000];
int s[260000];

int main()
{
	REP(i, 260000) p[i] = true;
	p[0] = p[1] = false;
	for (int i = 2; i*i <= 250000; i++)
	{
		if (p[i] == true)
		{
			for (int j = 2; j*i <= 250000; j++)
			{
				p[i*j] = false;
			}
		}
	}
	s[1] = 0;
	FOR(i,2, 250000)
	{
		if (p[i] == true) s[i] = s[i - 1] + 1;
		else s[i] = s[i - 1];
	}
	int n;
	while (cin >> n,n)
	{
		cout << s[2*n]-s[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 2392
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<55)+1e9; // ~ 3.6 * 1e16
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> &a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
template<class T>void prArr(T a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  Int n, x;
  cin>>n>>x;
  vector<Int> A(n);
  cin>>A;
  sort(A.begin(), A.end());

  Int ans = 0;
  for(Int i=0;i<n;i++){
    if(x - A[i] >= 0) ans ++;
    x -= A[i];
  }
  if(ans == n && x > 0) ans--; 
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import os, sys, re, math

x1,y1,x2,y2 = map(int,input().split(' '))

v = (x2 - x1, y2 - y1)
x3,y3 = x2 - v[1], y2 + v[0]
x4,y4 = x3 - v[0], y3 - v[1]
print(x3,y3,x4,y4)


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

int main() {
	int n, k;
	cin >> n >> k;

	set<int> s;
	for (int i = 1; i <= n; i++) 
		s.insert(i);

	for (int i = 0; i < k; i++) {
		int d;
		cin >> d;

		for (int i = 0; i < d; i++) {
			int snuke;
			cin >> snuke;
			s.erase(snuke);
		}
	}

	cout << s.size() << endl;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define REP(N) for(int i = 0; i < N; i++)
using namespace std;

double dist(vector<int>& a, vector<int>& b){
  int sum = 0;
  for(int i = 0; i < a.size(); i++) sum += (a[i] - b[i]) * (a[i] - b[i]);
  return sqrt(sum);
}

int main(){
  int N, D; cin >>N >>D;
  vector< vector<int> > v(N, vector<int>(D));
  for(int i = 0; i < N; i++) for(int j = 0; j < D; j++) cin >>v[i][j];
  int cnt = 0;
  for(int i = 0; i < N; i++){
    for(int j = i + 1; j < N; j++){
      double d = dist(v[i], v[j]);
      if(d == int(d)) cnt++;
    }
  }
  cout <<cnt <<endl;
  return 0;
}


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

vector<int> v[100005];
int vis[100005];
int fans[100005];

int dfs(int n)
{
    if(fans[n]!=-1)
        return fans[n];
    int ans = 0;
    for(int i = 0 ; i<v[n].size() ; i++)
    {
        ans = max(ans , 1 + dfs(v[n][i]));
    }
    return fans[n] = ans;
}

int main()
{
    int node , edge;

    cin >> node >> edge;

    for(int i = 1 ; i<=node ; i++)
        fans[i] = -1;

    for(int i = 1 ; i<=edge ; i++)
    {
        int x , y;

        cin >> x >> y;

        v[x].push_back(y);
    }

    int ans = 0;

    for(int i = 1 ; i<=node ; i++)
    {
        ans = max(ans , dfs(i));
    }

    cout << ans;


    return 0;
}


Measured memory_bytes: 8192
fun main(args: Array<String>) {
    val input = readLine()!!.split(" ").map { it.toInt() }
    val playerNumber = input[0]
    val defaultPoint = input[1]
    val correctAnswer = input[2]
    val who = mutableListOf<Int>()
    repeat(correctAnswer) {
        who.add(readLine()!!.toInt())
    }
    abc141c(playerNumber, defaultPoint, who).forEach { println(it) }
}

fun abc141c(playerNumber: Int, startPoint: Int, answerPlayer: MutableList<Int>): List<String> {
    val playerScore = mutableListOf<Int>()
    repeat(playerNumber) {
        playerScore.add(startPoint)
    }

    for (element in answerPlayer) {
        playerScore[element - 1] += 1
    }

    val whoGoNextRound = mutableListOf<String>()
    for (i in playerScore) {
        when {
            i > answerPlayer.size -> whoGoNextRound.add("Yes")
            else -> whoGoNextRound.add("No")
        }
    }

    return whoGoNextRound
}

Measured memory_bytes: 48436
#include<stdio.h>
int main()
{
    int a,b,c,s;
    scanf("%d %d %d",&a,&b,&c);
    if((a-b)<c)
        {s=c-(a-b);
    printf("%d\n",s);}
    else
        {printf("0\n");}
    return 0;
}

Measured memory_bytes: 128
import java.util.*;

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        int m = sc.nextInt();

        int reizouko[] = new int[a];
        int densirenji[] = new int[b];

        int minReizouko = Integer.MAX_VALUE;
        int minDensirenji = Integer.MAX_VALUE;

        for (int i = 0; i < a; i++) {
            reizouko[i] = sc.nextInt();
            if (minReizouko > reizouko[i] ) {
                minReizouko = reizouko[i];
            }
        }

        for (int i = 0; i < b; i++) {
            densirenji[i] = sc.nextInt();
            if (minDensirenji > densirenji[i] ) {
                minDensirenji = densirenji[i];
            }
        }

        int minValue = minReizouko + minDensirenji;

        for (int i = 0; i < m; i++) {
            int value = reizouko[sc.nextInt() - 1] + densirenji[sc.nextInt() - 1] - sc.nextInt();
            if (value < minValue) {
                minValue = value;
            }
        }

        System.out.println(minValue);

    }


}

Measured memory_bytes: 132444
ls = 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
K = int(input())
print(ls[K-1])

Measured memory_bytes: 3068
temparr = input()
temparr = temparr.split()
a = abs(int(temparr[0]))
b = int(temparr[1])
c = int(temparr[2])
rem = a // c 

if rem > b :
    print(a - b * c)

else:
    a -=  rem * c 
    b -= rem 
    v1 = a - c 
    v2 = v1 + c 
    if b & 1 :
        print(abs(v1) )
    else:
        print(abs(v2))

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

int main() {
  int n;
  cin >> n;

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

  vector<int> visited(n + 1, 0);
  int ans = 0;
  int cur = 1;
  while(true) {
    if(visited[cur]) {
      ans = -1;
      break;
    }
    if(cur == 2) break;
    visited[cur] = true;
    cur = a[cur];
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

int solve(const vector<int> &xp, const vector<int> &xn, int K) {
	int res = (int)1e+10;

	if(xp.size() >= K) {
		res = xp[K-1];
	}
	for(int i = 0; i < min((int)xp.size(), K - 1); ++i) {
		if(i + 1 + xn.size() < K) {
			continue;
		}
		res = min(res, xp[i] * 2 + xn[K - i - 2]);
	}

	return res;
}

signed main(){
	int N, K;
	cin >> N >> K;
	vector<int> x(N);
	for(int i = 0; i < N; ++i) {
		cin >> x[i];
	}
	vector<int> xp, xn;
	for(int i = 0; i < N; ++i) {
		if (x[i] < 0) {
			xn.push_back(abs(x[i]));
		} else if(x[i] > 0) {
			xp.push_back(x[i]);
		} else {
			--K;
		}
	}
	reverse(ALL(xn));
	if (K <= 0) {
		cout << 0 << endl;
		return 0;
	}
	cout << min(solve(xn, xp, K), solve(xp, xn, K)) << endl;
	return 0;
}


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

namespace V0011{
    public class Program{
        public static void Main(string[] args){
            var seq = Enumerable.Range(1, int.Parse(Console.ReadLine())).ToArray();
            var n = int.Parse(Console.ReadLine());

            for(var i = 0; i < n; i++){
                var input = Console.ReadLine().Split(',');
                var a = int.Parse(input[0]);
                var b = int.Parse(input[1]);

                var tmp = seq[a - 1];
                seq[a - 1] = seq[b - 1];
                seq[b - 1] = tmp;
            }

            Array.ForEach(seq, Console.WriteLine);
        }
    }
}

Measured memory_bytes: 9384
// 2012/01/06 Tazoe

#include <iostream>
using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;

	int s[100000];
	for(int i=1; i<n; i++)
		cin >> s[i];

	int sum = 0;
	int x = 1;
	for(int i=0; i<m; i++){
		int a;
		cin >> a;

		if(a>0){
			for(int j=0; j<a; j++){
				sum += s[x];
				x++;
			}
		}
		else{
			a = -a;
			for(int j=0; j<a; j++){
				x--;
				sum += s[x];
			}
		}

		sum %= 100000;
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 1228
def main():
    s = list(input())
    t = list(input())

    min_v = len(t)
    
    for i in range(len(s)-len(t)+1):
        cnt = 0
        for x, y in zip(s[i:i+len(t)], t): 
            if not(x == y):
                cnt += 1
            
        if min_v > cnt:
            min_v = cnt

    print(min_v)
        
if __name__ == '__main__':
    main()


Measured memory_bytes: 67952
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] h = new int[n];
        
        for(int i = 0; i < n; i++){
            h[i] = Integer.parseInt(sc.next());
        }
        
        int res = 1;
        
        int max = h[0];
        
        for(int i = 1; i < n; i++){
            if(max <= h[i]){
                res++;
                max = h[i];
            }
        }
        
        System.out.println(res);
    }
}


Measured memory_bytes: 22740