akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;struct edge{int to,next,rem;}e[1000005];
queue<int> q;pair<int,int> p[100005];vector<int> bel[100005];
int tot=1,s,t,n,last[1000005],dep[1000005],nxt[1000005],lst[1000005];
inline void adde(int u,int v,int d) {e[++tot]=(edge){v,last[u],d},last[u]=tot;return;}
inline void inse(int u,int v) {return adde(u,v,1),adde(v,u,0);}
inline bool bfs(void) {
	memset(dep,0,sizeof dep),dep[s]=1;
	while (!q.empty()) q.pop();q.push(s);
	while (!q.empty()) {int cur=q.front();q.pop();
		for (int i=last[cur];i;i=e[i].next) {int ot=e[i].to;
			if (e[i].rem&&!dep[ot]) dep[ot]=dep[cur]+1,q.push(ot);
		}
	}return dep[t];
}int dfs(int u,int lim) {int rtv=0,d;if (u==t) return lim;
	for (int&i=lst[u];i&&rtv<lim;i=e[i].next) {int ot=e[i].to;
		if (e[i].rem&&dep[ot]==dep[u]+1) {
			d=dfs(ot,min(e[i].rem,lim-rtv));
			e[i].rem-=d,e[i^1].rem+=d,rtv+=d;
		}
	}if (!rtv) dep[u]=0;return rtv;
}inline int prt(void) {int cnt=n;
	for (int i=1;i<n;++i) for (int j=last[i];j;j=e[j].next) {
		int ot=e[j].to;if (ot&&!e[j].rem) nxt[i]=ot-n;
	}while (!q.empty()) q.pop();q.push(n);
	while (!q.empty()) {int cur=q.front();q.pop(),--cnt;
		for (int i:bel[cur]) if (nxt[i])
			p[i]=make_pair(cur,nxt[i]),q.push(nxt[i]),nxt[i]=0;
	}return cnt;
}int main() {int m,u,fl=0;scanf("%d",&n),s=0,t=n<<1;
	for (int i=1;i<n;++i) inse(s,i),inse(n+i,t);
	for (int i=1;i<n;++i) {scanf("%d",&m);
		while (m--) {scanf("%d",&u);
			if (u^n) inse(i,n+u);bel[u].push_back(i);
		}
	}while (bfs()) memcpy(lst,last,sizeof last),fl+=dfs(s,0x3f3f3f3f);
	if (fl^(n-1)) return 0*puts("-1");if (prt()) return 0*puts("-1");
	for (int i=1;i<n;++i) printf("%d %d\n",p[i].first,p[i].second);return 0;
}

Measured memory_bytes: 28616
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>

using namespace std;

#define x first
#define y second

int getArea(int x1, int y1, int x2, int y2, int x3, int y3) {
    return abs((x1-x2)*(y3-y2)-(x3-x2)*(y1-y2));
}

int main() {
    ios::sync_with_stdio(false);

    int n;
    while (cin >> n, n) {
        map<int, bool> has;

        vector<pair<int,int> > co(n);
        for (int i=0; i<n; ++i) {
            cin >> co[i].x >> co[i].y;
            has[co[i].x+10000*co[i].y] = true;
        }
        sort(co.begin(), co.end());

        int area = 0, mxhyp = 0;
        for (int i=0; i<(int)co.size(); ++i) {
            for (int j=i+1; j<(int)co.size(); ++j) {
                int dx, dy, x3, y3, x4, y4;
                dx = co[j].x - co[i].x;
                dy = co[j].y - co[i].y;
                x3 = co[j].x - dy;
                y3 = co[j].y + dx;
                x4 = co[i].x - dy;
                y4 = co[i].y + dx;
                int hyp = dx * dx + dy * dy;
                if (mxhyp < hyp && has.count(x3+10000*y3) && has.count(x4+10000*y4)) {
                    area = max(area, getArea(co[i].x, co[i].y, co[j].x, co[j].y, x3, y3));
                    mxhyp = hyp;
                }
            }
        }
        cout << area << endl;
    }
    return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,sum=0;
	cin >> n;
	vll v(n);
	rep(i,n){
		cin >> v[i];
		sum+=v[i];
	}
	cout << minvec(v) << " " << maxvec(v) << " " << sum << endl;
	return 0;
}


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

#define x first
#define y second
#define y1 Y1
#define y2 Y2
#define mp make_pair
#define pb push_back
#define DEBUG(x) cout << #x << " = " << x << endl;

using namespace std;

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

template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; }
template <typename T> inline T read ()
{
	T sum = 0, fl = 1; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
	return sum * fl;
}

inline void proc_status ()
{
	ifstream t ("/proc/self/status");
	cerr << string (istreambuf_iterator <char> (t), istreambuf_iterator <char> ()) << endl;
}

const int Maxn = 2e5 + 100;
const int Maxm = 20 + 5;
const int Maxs = (1 << 20) + 100;

int N, V, Log;
int A[Maxn];

int L[Maxm][Maxn], R[Maxm][Maxn];
int Next[Maxn];

inline void get_seg ()
{
	for (int i = 0; i <= Log; ++i)
	{
		int v = V >> i;
//		DEBUG (v);
		for (int j = N; j >= 1; --j)
		{
			int p = upper_bound (A + 1, A + N + 1, A[j] + v) - A - 1;
			Next[j] = 0;
			Next[j] = max (Next[p], j);
		}
		for (int l = 1, r = 0; l <= N; l = r + 1)
		{
			r = Next[l];
			L[i][++L[i][0]] = l, R[i][++R[i][0]] = r;
		}
	}
}

int f[Maxs], g[Maxs];

inline void get_f ()
{
	int ALL = (1 << Log) - 1;
	for (int i = 0; i <= ALL; ++i)
	{
		int preR = f[i];
		for (int j = 1; j <= Log; ++j)
		{
			if (i & (1 << (j - 1))) continue;
			int x = upper_bound (L[j] + 1, L[j] + L[j][0] + 1, preR + 1) - L[j] - 1;
			int nowR = max (preR, R[j][x]);
			Chkmax (f[i | (1 << (j - 1))], nowR);
		}
	}
}

inline void get_g ()
{
	int ALL = (1 << Log) - 1;
	for (int i = 0; i <= ALL; ++i) g[i] = N + 1;
	for (int i = 0; i <= ALL; ++i)
	{
		int preL = g[i];
		for (int j = 1; j <= Log; ++j)
		{
			if (i & (1 << (j - 1))) continue;
			int x = lower_bound (R[j] + 1, R[j] + R[j][0] + 1, preL - 1) - R[j];
			int nowL = min (preL, L[j][x]);
			Chkmin (g[i | (1 << (j - 1))], nowL);
		}
	}
}

inline void Solve ()
{
	get_seg ();
	get_f ();
	get_g ();

	if (L[0][0] > Log + 3) { for (int i = 1; i <= N; ++i) puts("Impossible"); return ; }

	int ALL = (1 << Log) - 1;
	for (int i = 1; i <= L[0][0]; ++i)
	{
		int l = L[0][i], r = R[0][i], fl = 0;
		for (int j = 0; j <= ALL; ++j)
			if (l - 1 <= f[j] && g[ALL ^ j] <= r + 1)
			{
				fl = 1;
				break;
			}
		if (fl) for (int j = l; j <= r; ++j) puts("Possible");
		else for (int j = l; j <= r; ++j) puts("Impossible");
	}
}

inline void Input ()
{
	N = read<int>(), V = read<int>(), Log = log2(V) + 1;
	for (int i = 1; i <= N; ++i) A[i] = read<int>();
}

int main()
{

#ifdef hk_cnyali
	freopen("E.in", "r", stdin);
	freopen("E.out", "w", stdout);
#endif

	Input ();
	Solve ();

	return 0;
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
#define reps(i,n) for(ll i=1;i<=(n);++i)
using ll = long long;
using str = string;
constexpr long long INF = (1LL<<60);
constexpr long long MOD = (1e9+7);
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}

main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout<<fixed<<setprecision(10);
  
  ll n,k,q;
  cin>>n>>k>>q;
  vector<ll> a(q);
  cin>>a;

  vector<ll> b(n,k-q);
  rep(i,q){
    a[i]--;
    b[a[i]]++;
  }

  rep(i,n){
    if(b[i]>0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }


}


Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int main(){
  while(1){
    int n, m;
    cin >> n >> m;
    if(!n) break;

    vector<int> taro(n);
    vector<int> hanako(m);

    for(auto itr = taro.begin(); itr != taro.end(); itr++){
      cin >> *itr;
    }
    for(auto itr = hanako.begin(); itr != hanako.end(); itr++){
      cin >> *itr;
    }

    sort(taro.begin(), taro.end());
    sort(hanako.begin(), hanako.end());

    int diff = accumulate(taro.begin(), taro.end(), 0) - accumulate(hanako.begin(), hanako.end(), 0);

    if(diff % 2){
      cout << -1 << endl;
      continue;
    }

    bool flag = false;
    for(int t_val : taro){
      for(int h_val : hanako){
        if(t_val - h_val == diff/2){
          cout << t_val << " " << h_val << endl;
          flag = true;
          break;
        }
      }
      if(flag) break;
    }

    if(flag){
      continue;
    }
    else{
      cout << -1 << endl;
      continue;
    }
  }

  return 0;
}

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

int main() {
	int a,b;cin>>a>>b;
	if(a+b==15){
		cout<<'+'<<endl;
	}else if(a*b==15){
		cout<<'*'<<endl;
	}else{
		cout<<'x'<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
N, D = [int(x) for x in input().strip().split(" ")]

cnt = 0

dist = pow(D, 2)
for _ in range(N):
    X, Y = [int(x) for x in input().strip().split(" ")]
    if dist >= pow(X, 2) + pow(Y, 2):
        cnt += 1
print(cnt)

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

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		String s = stdIn.next();
		
		if(Character.isUpperCase(s.charAt(0))) {
			System.out.println("A");
		}else {
			System.out.println("a");
		}
		
		
		
		
		
	}

}


Measured memory_bytes: 35660
#include<stdio.h>
int main()
{
    int x,y[10000],i,sum=0;
    scanf("%d",&x);
    for(i=0;i<x;i++)
    {
        scanf("%d",&y[i]);
        sum=sum+y[i];
    }
    int max;
    max=y[0];
    for(i=1;i<x;i++)
    {
        if(max<y[i])
            max=y[i];
    }
    printf("%d\n",sum-(max/2));


    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, s, n) for(int i = s; i < n; i++)
#define rRep(i, n) for(int i = n - 1; i >= 0; i--)
#define pi pair<int, int>
#define vi vector<int>
#define endl "\n"
const double PI = 3.141592653589793238;

int32_t main() {
    FAST
    int n, m;
    cin >> n >> m;
    vi vec(m);
    int sum = 0;
    REP(i, 0, m) {
        int x;
        cin >> x;
        sum += x;
    }
    int val = n - sum;
    if(val < 0)
        cout << -1 << endl;
    else
        cout << val << endl;

}

Measured memory_bytes: 3732
import java.util.Scanner;

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

    int n = sc.nextInt();
    int m = sc.nextInt();

    int total = 0;
    for (int i = 0; i < m; i++ ) {
      total += sc.nextInt();
    }

    int rest = n - total;
    System.out.println(rest >= 0 ? rest : -1);
  }
}


Measured memory_bytes: 39320
#include<iostream>
#include<vector>
#include<map>

int main(void){
    std::vector<long long > a(26);
    long long n;
    std::cin >> n;
    std::map<std::vector<long long >, long long> mp;
    for(int i = 0; i < n; i++){
        std::string s;
        std::cin >> s;
        for(int j = 0; j < 10; j++){
            long long cur = s[j] - 'a';
            a[cur]++;
        }
        mp[a]++;
        for(int j = 0; j < 26; j++){
            a[j] = 0;
        }
    }
    long long ans = 0;
    for(auto i = mp.begin(); i != mp.end(); i++){
            ans += (i->second) * (i->second - 1) / 2;
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 33264
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <cctype>

using namespace std;

using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)
const int inf = 1e+9;



int main() {
	int n, k;
	cin >> n >> k;
	vector<int> ps(n);
	rep(i, n) {
		cin >> ps[i];
	}
	sort(ps.begin(), ps.end());

	int ans = 0;
	rep(i, k) {
		ans += ps[i];
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <numeric>
#include <climits>
#include <math.h>
#include <memory.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int N, M;
int cnt = 0;
int ans = 0;
int i_index;
int tmp;
bool Rok = true;
bool Uok = true;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};
string board[64];
int main(){
    int H, W;
    cin >> H >> W;
    rep(i, H) cin >> board[i];
    rep(i, H) rep(j, W){
        if(board[i][j] == '#')
            cnt++;
    }
    if(cnt == H + W - 1)
        cout << "Possible" << endl;
    else
        cout << "Impossible" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
	int N;
	int a;
	cin >> N;
	for (int i = 0; i < 100; i++) {
		if (N < pow(2, i)) break;
		a = (int)pow(2, i);
		}
	cout << a<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())

home =[[[0]*10 for i in range(3)]for i in range(4)]

for i in range(n):
    b,f,r,v = map(int,input().split())
    home[b-1][f-1][r-1] += v

for i in range(4):
    for j in range(3):
        print("",*home[i][j])
    if i < 3 :
        print("#"*20)


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

using namespace std;

int N, K;
int arr[15][15];

int main(){
    cin >> N >> K;
    int ans = 0;
    for(int i = 1; i<=N; i++){
        for(int k = 1; k<=K; k++){
            cin >> arr[i][k];
        }
        for(int j = 1; j<i; j++){
            int tot = 0;
            for(int k = 1; k<=K; k++){
                tot += (arr[i][k]-arr[j][k])*(arr[i][k]-arr[j][k]);
            }
            int s = (int) sqrt(tot);
            if(s*s == tot){
                ans++;
            }
        }
    }
    cout << ans << endl;
}


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

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

    static class BProductMax {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int a = Integer.parseInt(in.next());
            int b = Integer.parseInt(in.next());
            int c = Integer.parseInt(in.next());
            int d = Integer.parseInt(in.next());
            long ans = 0;

            if (b <= 0 && d <= 0) {
                ans = (long) a * (long) c;
            } else if (a >= 0 && c >= 0) {
                ans = (long) b * (long) d;
            } else if ((a < 0 && b <= 0 && c < 0 && d <= 0) || (a < 0 && b < 0 && c < 0 && d > 0)) {
                ans = (long) a * (long) c;
            } else if ((a >= 0 && b > 0 && c >= 0 && d > 0) || (a > 0 && b > 0 && c < 0 && d > 0)) {
                ans = (long) b * (long) d;
            } else if (a < 0 && b > 0 && c < 0 && d > 0) {
                ans = Math.max((long) b * (long) d, (long) a * (long) c);
            } else if (a < 0 && b > 0 && c > 0 && d > 0) {
                ans = (long) b * (long) d;
            } else if (a < 0 && b < 0 && c > 0 && d > 0) {
                ans = (long) b * (long) c;
            } else if (a > 0 && b > 0 && c < 0 && d < 0) {
                ans = (long) a * (long) d;
            } else if (a < 0 && b > 0 && c < 0 && d < 0) {
                ans = (long) a * (long) c;
            } else if (b <= 0 && c >= 0) {
                ans = (long) b * (long) c;
            } else if (a >= 0 && d <= 0) {
                ans = (long) a * (long) d;
            }

            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 35580
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

typedef long long ll;
using namespace std;

int main() {
    int a = 0, b = 0, q = 0;
    cin >> a >> b >> q;
    vector<ll> s(a), t(b), x(q);
    for (int i=0; i<a; i++) cin >> s.at(i);
    for (int i=0; i<b; i++) cin >> t.at(i);
    for (int i=0; i<q; i++) cin >> x.at(i);
    for (int i=0; i<q; i++) {
        ll start = x.at(i);
        int s_where = upper_bound(s.begin(), s.end(), start) - s.begin();
        int t_where = upper_bound(t.begin(), t.end(), start) - t.begin();
        ll s_big, s_small, t_big, t_small;
        s_big = s_small = t_big = t_small = 1000000000000;
        if (start < s.at(0)) s_big = s.at(0);
        else if (start > s.at(s.size()-1)) s_small = s.at(s.size()-1);
        else {
            s_big = s.at(s_where);
            s_small = s.at(s_where-1);
        }
        if (start < t.at(0)) t_big = t.at(0);
        else if (start > t.at(t.size()-1)) t_small = t.at(t.size()-1);
        else {
            t_big = t.at(t_where);
            t_small = t.at(t_where-1);
        }
        cout << min(min(max(abs(t_big-start), abs(s_big-start)), max(abs(t_small-start), abs(s_small-start))), min(abs(t_big-s_small)+min(abs(t_big-start), abs(s_small-start)), abs(t_small-s_big)+min(abs(t_small-start), abs(s_big-start)))) << endl;
    }
    return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e5+1;


int n,fa[N],tot[N],fr[N],a[N],b[N],c[N],cnt,head[N];

struct nd{int ne,to;}e[N];

void in(int x,int y){e[++cnt].to=y;e[cnt].ne=head[x];head[x]=cnt;}
int w1[5001],q[N];
void dfs(int x)
{
	for(int i=head[x];i;i=e[i].ne)dfs(e[i].to);
	if(!fr[x])return;
	q[0]=0;
	int ret=tot[x],tot1=0;
	for(int i=head[x];i;i=e[i].ne)
	{
		ret-=min(a[e[i].to],b[e[i].to]);
		q[++q[0]]=abs(a[e[i].to]-b[e[i].to]);
		tot1+=a[e[i].to]+b[e[i].to];
	}
	if(ret<0){cout<<"IMPOSSIBLE";exit(0);}
	memset(w1,0,sizeof(w1));
	w1[0]=1;
	for(int i=1;i<=q[0];++i)
	for(int t=5000;t>=q[i];--t)
	if(w1[t-q[i]]==1)w1[t]=1;
	for(int i=ret;i>=0;--i)
	if(w1[i]==1){ret-=i;break;}
	a[x]=tot[x];b[x]=tot1+ret-a[x];
	return;
}

int main()
{
	scanf("%d",&n);
	for(int i=2;i<=n;++i)
	scanf("%d",&fa[i]),in(fa[i],i),fr[fa[i]]++;
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&tot[i]);
		if(!fr[i])a[i]=tot[i],b[i]=0;
	}
	dfs(1);
	cout<<"POSSIBLE";


}

Measured memory_bytes: 14592
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

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

	int s = 0;
	for (int i = n; i > 0; i /= 10)
	{
		s += i % 10;
	}

	cout << (n % s == 0 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#define INF (1<<21)
using namespace std;

int main(){
  int i,j,n,k,c,a,b,G[101][101],d[101],f[101],yen,p,min,s,g;
  while(1){
    cin >> n >> k;
    if(n == 0 && k == 0) break;

    for(i=0;i<=n;i++){
      for(j=0;j<=n;j++){
	G[i][j] = INF;
      }
    }

    for(i=0;i<k;i++){
      cin >> c;
      if(c == 1){
	cin >> a >> b >> yen;
	if(G[a][b] > yen) G[a][b] = G[b][a] = yen;
      }

      else if(c == 0){
	for(j=0;j<=n;j++){
	  d[j] = INF;
	  f[j] = 0;
	}
	cin >> s >> g;

	d[s] = 0;
	while(1){
	  min = INF;
	  for(j=0;j<=n;j++){
	    if(d[j]<min && f[j] == 0){
	      min = d[j];
	      p = j;
	    }
	  }
	  if(min == INF) break;
	  f[p] = 1;
	  for(j=0;j<=n;j++){
	    if(f[j] == 1) continue;
	    if(G[p][j] + d[p] < d[j]) d[j] = G[p][j] + d[p];
	  }
	}

	if(d[g] == INF) cout << "-1" << endl;
	else cout << d[g] << endl;
      }
    }
  }
  return 0;
}

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

#define rep(i,a,b) for(int (i) = (a) ; (i) < (b) ; (i) ++)
#define scin(a) scanf("%d",&a);
#define scdo(a) scanf("%lf",&a);
#define scch(a) scanf("%s",a);
#define anin(a) printf("%d\n",a);
#define ando(a) printf("%lf\n",a);
#define anch(a) printf("%s\n",a);

int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

int main(void){
	int N,K,ans(0);
	scin(N)
	scin(K)
	int h[N];
	rep(i,0,N){
		scin(h[i])
		if(h[i] >=  K) ans++;
	}
	anin(ans)
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>

int main () 
{
  int i;
  char n[4];
  
  scanf("%s",n);

  if ( n[0] == '7' || n[1]=='7' || n[2]=='7' )
  {
  printf("Yes");
    return 0;
  }
 
  printf("No");
  return 0;
}

Measured memory_bytes: 2128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n;
  cin >> n;
  vec a(n);
  vec b(n);
  for(ll i=0;i<n;i++) cin >> a[i];
  for(ll i=0;i<n;i++) cin >> b[i];
  for(ll i=0;i<n-1;i++) a[i+1]+=a[i];
  for(ll i=n-1;i;i--) b[i-1]+=b[i];
  ll ans=0;
  for(ll i=0;i<n;i++) {
    ans=max(ans,a[i]+b[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,1,-1,1,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}
ll modpow(long long a, long long n, long long mod2) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod2;
        a = a * a % mod2;
        n >>= 1;
    }
    return res;
}

int main() {
    ll n,ans = 1;
    cin >> n;
    vector<ll> d(n);
    ll tmp,mx = 0;
    for (int i = 0; i < n; ++i) {
        cin >> tmp;
        mx = max(mx,tmp);
        if(i == 0 && tmp != 0){
            cout << 0 << endl;
            return 0; // 自分が0じゃない
        }
        d[tmp]++;
    }
    if(d[0] != 1){
        cout << 0 << endl;
        return 0; // 自分複数でもng
    }
    for (int i = 1; i <= mx; ++i) {
        if(d[i] == 0) {
            cout << 0 << endl;
            return 0; // 途中が途切れる
        }

        ans *= modpow(d[i-1],d[i],mod2);
        ans %= mod2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
##https://beta.atcoder.jp/contests/abc102/submissions/2779056
n = int(input())
a = list(map(int, input().split()))
s = [a[0]]
for i in range(n-1):
    s.append(s[i] + a[i+1])
ans = s[n-1]

##i,j,kは左側の区間の右端
##iは1からN-3まで
j = 0
k = 2             
for i in range(1, (n - 3) + 1):
    ##BC(i)DE
    ##BCの区間[0, i]: 最低でも2要素→0,1を取るのでi=1から
    ##DEの区間[i+1, N-1]: 最低でも2要素→N-2, N-1を取るので、i+1=N-2よりi=N-3まで

    ##B(j)C(i)DE
    #Bの区間[0, j]
    #Cの区間[j+1, i]
    ##sumB = s[j]
    ##sumC = s[i] - s[j]
    while abs(s[i] - 2 * s[j]) > abs(s[i] - 2 * s[j+1]):
        j += 1

    ##B(j)C(i)D(k)E
    #Dの区間[i+1, k]
    #Eの区間[k+1, N-1]
    ##sumD = s[k] - s[i]
    ##sumE = s[N-1] - s[k]
    while abs(s[n-1] - 2 * s[k] + s[i]) > abs(s[n-1] - 2 * s[k+1] + s[i]):
        k += 1
             
    pqrs = list((s[j],s[i]-s[j],s[k]-s[i],s[n-1]-s[k]))
    ans = min(ans, max(pqrs) - min(pqrs))
print(ans)

Measured memory_bytes: 24684
#include <iostream>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <iomanip>
#include <vector>
#include <functional>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <cstdlib>
#include <unordered_map>
#include <string.h>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll X;
    cin >> X;
    for (ll i = -150; i <= 150; i++)
    {
        for (ll j = -150; j <= 150; j++)
        {
            if (i * i * i * i * i - j * j * j * j * j == X)
            {
                cout << i << ' ' << j << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3652
#!/usr/bin/env python3


def solve(n, m, x):

    if m <= n:
        return 0

    x.sort()
    total = x[-1] - x[0]

    if n == 1:
        return total

    px = x[0]
    y = []
    for xi in x[1:]:
        y.append(xi - px)
        px = xi

    y.sort(reverse = True)
    r = sum(y[:n - 1])

    return total - r

def main():
    n, m = input().split()
    n = int(n)
    m = int(m)
    x = list(map(int, input().split()))

    print(solve(n, m, x))


if __name__ == '__main__':
    main()



Measured memory_bytes: 13968
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

int main() {
    ll n, m;
    cin >> n >> m;
    vel h(n), a(m), b(m);
    rep(i, n) {
        cin >> h[i];
    }
    rep(i, m) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    vector<bool> ans(n, true);
    ll cnt = 0;
    rep(i, m) {
       if(h[a[i]] > h[b[i]]) {
           ans[b[i]] = false;
       }
       else if(h[a[i]] < h[b[i]]) {
           ans[a[i]] = false;
       }
       else {
           ans[a[i]] = false;
           ans[b[i]] = false;
       }
    }
    rep(i, n) {
        if(ans[i]) {
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 5648
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define uni(q) unique(all(q)),q.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

bool from1[2505];
bool fromN[2505];
bool ok[2505];
vector<vl> G(2505);
vector<vl> rG(2505);



int main(){
    ll n; cin >> n;
    string a,b,c; cin >> a >> b >> c;
    ll ans = 0;
    rep(i,n){
        if(a[i] != b[i] && b[i]!=c[i] && a[i]!=c[i]) ans+=2;
        else if(a[i] == b[i] && b[i] == c[i]) ans = ans;
        else ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
import scala.io.Source.stdin

object Main extends App {
  var b = new StringBuilder

  def integral(i:Int,s:Int,d:Int):Unit = if(i*d >= 600-d) b.append((s + i*i*d*d*d)+"\n") else integral (i+1, s + i*i*d*d*d, d)

  for(i<-stdin.getLines)
    integral(0,0,i.toInt)

  print(b.result)
}

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

const long N=100001;

typedef struct{
	long parent;
	long left; //1????????????
	long right_sib; //??????????????????(????????????????????¬?????????????????¨?????????)
}Node;

long n, d[N];
Node t[N];

void print(long a){
	printf("node %ld: parent = %ld, depth = %ld, ", a, t[a].parent, d[a]);
	
	if(t[a].parent==-1) printf("root, ");
	else if(t[a].left==-1) printf("leaf, ");
	else printf("internal node, ");
	
	long c=t[a].left;
	printf("[");
	if(c!=-1){
		while(true){
			if(t[c].right_sib==-1){
				printf("%ld", c);
				break;	
			}
			printf("%ld, ", c);	
			c=t[c].right_sib;
		}
	}
	printf("]\n");
}

void setDepth(long u, long a){
	d[u]=a;
	if(t[u].right_sib != -1) setDepth(t[u].right_sib, a);
	if(t[u].left != -1) setDepth(t[u].left, a+1);
}

int main(){
	scanf(" %ld", &n);
	
	for(long i=0; i<n; ++i) 
	t[i].parent=t[i].left=t[i].right_sib=-1;
	
	for(long i=0; i<n; ++i){
		long x, k;
		scanf(" %ld %ld", &x, &k);
		
		long now;
		for(long j=0; j<k; ++j){
			long y;
			scanf(" %ld", &y);
			
			if(j==0) t[x].left=y;
			else t[now].right_sib=y;	
			
			t[y].parent=x;
			now=y;
		}	
		
	}
	
	long root;
	for(long i=0; i<n; ++i){
		if(t[i].parent==-1) root=i;
	}
	
	setDepth(root, 0);
	
	for(long i=0; i<n; ++i) print(i);
}


Measured memory_bytes: 9464
#include<iostream>
#include<algorithm>
#include<math.h>

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

int main() {
    int N; cin >> N;
    int K; cin >> K;
    int l[110]; rep(i, N) cin >> l[i];

    sort(l, l+N, greater<int>());

    int res = 0;
    rep(i, K) res += l[i];

    cout << res << endl;
    return 0;
}


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

int main(){
  int N,M;
  cin >>N>>M;
  int X[M];
  
  for(int i=0;i<M;i++){
      cin >>X[i];
  }
  
  if(N>=M){
    cout<<0;
  }
  else{
    sort(X,X+M);
    /*
    int flag=1;
    int tmp=0;
    
    while(flag==1){
      flag=0;
      for(int i=0;i<M-1;i++){
        if(X[i]>X[i+1]){
          tmp = X[i+1];
          X[i+1] = X[i];
          X[i] = tmp;
          flag=1;
        }
      }
    }
    */
    

    //差分取得
    int dif[M-1];
    for(int i=0;i<M-1;i++){
      dif[i] = X[i+1] - X[i];
      //cout << dif[i];
    }
    
    /*
    flag=1;
    tmp=0;
    
    //Xソート
    while(flag==1){
      flag=0;
      for(int i=0;i<M-2;i++){
        if(dif[i]>dif[i+1]){
          tmp = dif[i+1];
          dif[i+1] = dif[i];
          dif[i] = tmp;
          flag=1;
        }
      }
    }
    */
    
    sort(dif,dif+M-1);
    int answer = 0;
    for(int i=0;i<M-N;i++){
      answer += dif[i];
    }
    
    cout << answer;
   
  }
  return 0;
}


Measured memory_bytes: 1024
H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
B = [None] * (H*W)
C = [0] * (H*W)
for h, aa in enumerate(A):
    for w, a in enumerate(aa):
        B[a-1] = h, w
for i in range(H*W-D):
    C[i+D] = C[i] + abs(B[i][0]-B[i+D][0]) + abs(B[i][1]-B[i+D][1])
for _ in range(int(input())):
    L, R = map(int, input().split())
    print(C[R-1]-C[L-1])

Measured memory_bytes: 17976
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define inf 1e+9
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

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

    ll n,k,ans,min=inf,mod=2019;
	cin >> n >> k;
	if(n/mod!=k/mod){
		min = 0;
		cout << min << endl;
		return 0;
	}
		n=n%mod;
	k=k%mod;
	for(int i=n;i<k;i++){
		for(int j=i+1;j<=k;j++){
			if(min>(i*j)%mod){
				min = (i*j)%mod;
			}
			if(min==0){
				break;
			}
		}
		if(min==0){
			break;
		}
	}

	cout << min << endl;
}

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

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T>
inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T>
inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T>
T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); }
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

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

	cout << (f - 30) / 2 << endl;
}


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

using namespace std;

int main()
{
	char b;
	cin >> b;

	if (b == 'A')
		cout << "T" << endl;
	if (b == 'T')
		cout << "A" << endl;
	if (b == 'C')
		cout << "G" << endl;
	if (b == 'G')
		cout << "C" << endl;

	return 0;
}


Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.array, std.algorithm,
    std.numeric, std.math, std.range;

void main()
{
    long n;
    readf("%d\n", &n);
    auto hs = readln.strip.split.to!(long[]);

    foreach_reverse (i; 1 .. hs.length)
    {
        if (hs[i] < hs[i - 1])
        {
            if (hs[i] + 1 == hs[i - 1])
            {
                hs[i - 1]--;
            }
            else
            {
                writeln("No");
                return;
            }
        }
    }
    writeln("Yes");
}


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

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

using namespace std;

int main(){
	string s;
	int w; cin>>s>>w;

	for(int i=0;i<s.length();i+=w) putchar(s[i]);
	puts("");

	return 0;
}


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

void Main() {
  int N, M;
  cin >> N >> M;
  int a[M], b[M], c[M];
  for (int i = 0; i < M; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--; b[i]--;
  }

  // warshall floyd
  const int INF = 100000000;
  int dist[N][N];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i == j) dist[i][j] = 0;
      else dist[i][j] = INF;
    }
  }

  for (int i = 0; i < M; i++) {
    dist[a[i]][b[i]] = min(dist[a[i]][b[i]], c[i]);
    dist[b[i]][a[i]] = min(dist[b[i]][a[i]], c[i]);
  }

  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }

  int ans = M;
  for (int i = 0; i < M; i++) {
    bool shortest = false;
    for (int j = 0; j < N; j++) {
      if (dist[j][a[i]] + c[i] == dist[j][b[i]]) shortest = true;
    }

    if (shortest) ans--;
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}



Measured memory_bytes: 256
from collections import deque

def main():
    S = list(input().strip())
    Q = int(input())

    d = deque(S)
    mode = True

    for _ in range(Q):
        query = input().split()

        if query[0] == "1":
            mode = not mode
        elif query[0] == "2":
            F, C = query[1], query[2]
            if F == "1":
                if mode:
                    d.appendleft(C)
                else:
                    d.append(C)
            elif F == "2":
                if mode:
                    d.append(C)
                else:
                    d.appendleft(C)

    s = list(d)
    if not mode:
        s = s[::-1]

    print(''.join(s))

if __name__ == "__main__":
    main()

Measured memory_bytes: 10868
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<math.h>

#define DIV 1000000007
using namespace std;
using ll = long long;

int main(void) {
	string s;
	cin >> s;

	reverse(s.begin(), s.end());
	int N = s.size();
	vector<vector<ll>> dp(N, vector<ll>(13));
	int temp = 1;

	if (s[0] == '?') {
		for (int d = 0; d <= 9; d++) {
			dp[0][d] = 1;
		}
	}
	else {
		dp[0][s[0] - '0'] = 1;
	}
	for (int i = 0; i < N - 1; i++) {
		temp *= 10;
		temp %= 13;
		for (int j = 0; j <13; j++) {
			if (s[i+1] == '?') {
				for (int d = 0; d <= 9; d++) {
					dp[i + 1][(j + temp * d) % 13] += dp[i][j];
					dp[i + 1][(j + temp * d) % 13] %= DIV;
				}
			}

			else {
				dp[i + 1][(j + temp * (s[i+1] - '0')) % 13] += dp[i][j];
				dp[i + 1][(j + temp * (s[i+1] - '0')) % 13] %= DIV;
			}
		}

		
	}
	/*
	for (int i = 0; i < N; i++) {
		for (int d = 0; d < 13; d++) {
			printf("dp[%d][%d]=", i, d);
			cout << dp[i][d] << " ";
		}
		cout << endl;
	}
	*/
	cout << dp[N - 1][5] << endl;
}

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

int main(){
  string N;
  cin >> N;
  int L=N.size();
  int f=0;
  for(int i=0; i<L; i++){
    string A="";
    A.push_back(N.at(i));
    f+=stoi(A);
  }
  if(stoi(N)%f==0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

int main()
{
  long long n,a,b;cin>>n>>a>>b;
if ((b-a)%2 == 0) cout << b-((a+b)/2) << endl;
	else cout << min(a-1, n-b) + 1 + (b-a-1)/2 << endl;
}


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

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

Measured memory_bytes: 256
Var n,rem,i,sum:Int64;
Begin
    Readln(n);
    If odd(n) then sum:=0
    ELse begin
        i:=10;
        While i<=n do begin
            sum:=sum+n div i;
            i:=i*5;
        End;
    End;
    Writeln(sum);
End.

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

    int n1=0;
    int n2=0;
    int n3=0;
    int h;
    while(cin >> h){
        int tmp;
        if(h>n3) n3=h;
        if(n3>n2){
            tmp=n2;
            n2=n3;
            n3=tmp;
        }
        if(n2>n1){
            tmp=n1;
            n1=n2;
            n2=tmp;
        }
    }
    
    cout << n1 << endl;
    cout << n2 << endl;
    cout << n3 << endl;
    
    return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include<cstdio>
typedef long long ll;
using namespace std;

int a[55];
int sum[55];
ll dp[55][2505];

int main()
{
    int n,A;
    scanf("%d%d",&n,&A);
    for(int i=1;i<=n;i++) {scanf("%d",&a[i]); sum[i]=sum[i-1]+a[i];}
    dp[0][0]=1;
    for(int k=1;k<=n;k++){
        for(int i=k;i>=1;i--){
            for(int j=sum[k];j>=a[k];j--){
                dp[i][j]+=dp[i-1][j-a[k]];
            }
        }
    }
    ll ans=0;
    for(int i=1;i<=n;i++) ans+=dp[i][i*A];
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1280
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define MAX 300000
typedef long long ll;

int main(){
  ll N,a,ans=0,count=0,mina=1000000000;
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>a;
    if(a<0) count++;
    mina=min(mina,abs(a));
    ans+=abs(a);
  }
  if(count%2==0) cout<<ans<<endl;
  else cout<<ans-mina*2<<endl;
}


Measured memory_bytes: 256
package main

import "fmt"

var (
	burgers = make([]string, 51)
	sizes   = make([]uint64, 51)
	dp      = make([]map[uint64]uint64, 51)
)

func init() {
	for i := 0; i < 51; i++ {
		dp[i] = make(map[uint64]uint64)
	}
}

func bSize(n uint64) uint64 {
	if n == 0 {
		return 1
	}
	if sizes[n] != 0 {
		return sizes[n]
	}
	sizes[n] = bSize(n-1)*2 + 3
	return sizes[n]
}

func count(n, x uint64) uint64 {
	if dp[n][x] != 0 {
		return dp[n][x]
	}

	s := bSize(n)
	if s == 1 {
		return 1
	}

	if x == 1 {
		return 0
	}

	center := s/2 + 1

	r := uint64(0)
	if x < center {
		r = count(n-1, x-1)
	} else if x == center {
		r = count(n-1, center-2) + 1
	} else {
		r = count(n-1, center-2) + 1 + count(n-1, x-center)
	}
	dp[n][x] = r
	return r
}

func main() {
	var n, x uint64
	fmt.Scan(&n, &x)
	fmt.Println(count(n, x))
}

Measured memory_bytes: 640
/*
無向グラフに対して使う

G=vector<int>を引数にすることを前提にしている
edgeなどを使う場合には、eの所をe.toにする必要がある

O(V+E)

verify:
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_A&lang=ja
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_B
参考:
https://ei1333.github.io/luzhiled/snippets/graph/lowlink.html
http://hos.ac/slides/20110504_graph.pdf
*/

#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
template<class T,class U>constexpr bool chmin(T&a,const U b){if(a<=b)return false;a=b;return true;}
template<class T,class U>constexpr bool chmax(T&a,const U b){if(a>=b)return false;a=b;return true;}
typedef pair<int,int> pii;

using Graph=vector<vector<int>>;


template<typename G>
struct LowLink{
    const G &g;
    int sz;
    vector<int> ord,low;
    vector<bool> used;
    vector<int> articulation;
    vector<pii> bridge;
    int k;

    void dfs(int idx,int par){
        used[idx]=true;
        ord[idx]=k++;
        low[idx]=ord[idx];
        bool is_articulation=false;
        int cnt=0;
        for(auto &e:g[idx]){
            if(!used[e]){
                cnt++;
                dfs(e,idx);
                chmin(low[idx],low[e]);
                if(ord[idx]<low[e]) bridge.emplace_back(minmax(idx,e));
                is_articulation |=(par!=-1 && ord[idx]<=low[e]);
            }else if(e!=par){
                chmin(low[idx],ord[e]);
            }
        }
        is_articulation |= (par==-1 && cnt>=2);
        if(is_articulation) articulation.push_back(idx);

    }

    LowLink(const G &g):g(g){
        sz=g.size();
        used.assign(sz,false);
        ord.assign(sz,0);
        low.assign(sz,0);
        k=0;
        for(int i=0;i<sz;i++){
            if(!used[i]) dfs(i,-1);
        }
    }


};

signed main(){
    /*int v,e;
    cin>>v>>e;
    vector<vector<int>> g(v);
    for(int i=0;i<e;i++){
        int s,t;
        cin>>s>>t;
        g[s].push_back(t);
        g[t].push_back(s);
    }
    LowLink<int> l(g);
    vector<int> buri=l.articulation;
    sort(buri.begin(),buri.end());
    for(int i:buri){
        cout<<i<<endl;
    }*/

    int v,e;
    cin>>v>>e;
    Graph g(v);
    for(int i=0;i<e;i++){
        int s,t;
        cin>>s>>t;
        g[s].push_back(t);
        g[t].push_back(s);
    }
    LowLink<Graph> l(g);
    vector<pii> buri=l.bridge;
    sort(buri.begin(),buri.end());
    for(auto i:buri){
        cout<<i.first<<" "<<i.second<<endl;
    }

}


Measured memory_bytes: 4564
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    int from,to,value;
    Edge(int a,int b,int c){
        from = a;
        to = b;
        value = c;
    }
    Edge(int a,int b){
        from = a;
        to = b;
    }
};

int main(){
    string s;cin >> s;
    int ans = 0;
    COUT(ans+count(ALL(s),'+')-count(ALL(s),'-'));
    return 0;
}


Measured memory_bytes: 768
n = input()
ax = ay = x = y = mx = 0
while n > 0:
	dx,dy = map(int,raw_input().split())
	if dx == dy == 0:
		print ax,ay
		n -= 1
		ax = ay = x = y = mx = 0
		continue
	x += dx; y += dy
	if x*x + y*y > mx:
		mx = x**2 + y**2
		ax,ay = x,y
	elif x*x + y*y == mx:
		if x > ax:
			ax,ay = x,y

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

int main() {

    int N,M;
    cin >> N >> M;
    
    cout << (N * (N - 1) / 2) + (M * (M - 1) / 2) << endl;
    
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

#define PI 3.14159265359
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repz(i,n) rep(i,0,n)


int main() {
	string s, t, u;
	int a, b;
	cin >> s >> t >> a >> b >> u;
	if (u == s)cout << (a - 1)<< " " << b << endl;
	else cout <<a << " " << (b - 1) << endl;

	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        double B = sc.nextDouble();
        sc.close();

        long hyakubaiB = (long) (Math.round(B * 100));

        System.out.println((A * hyakubaiB) / 100);
    }
}


Measured memory_bytes: 36788
s=input()
n=len(s)
ans = [0]*n

c=0
for i in range(n-1):
    if s[i]=='R':
        c+=1
        if s[i+1]=='L':
            ans[i]+=c//2 + (c&1)
            ans[i+1]+=c//2
            c=0

c=0
for i in range(n-1,0,-1):
    if s[i]=='L':
        c+=1
        if s[i-1]=='R':
            ans[i]+=c//2 + (c&1)
            ans[i-1]+=c//2
            c=0

print(*ans)

Measured memory_bytes: 47684
N = int(input())
A = list(map(int,input().split()))

B = [0]
b = 0

mod = 10**9 + 7

for i in range(N):
    b+=A[i]
    b%=mod
    B.append(b)

ans = 0

for i in range(N):
    ans += (mod+B[N]-B[i+1])*A[i]
    ans %= mod

print(ans)

Measured memory_bytes: 105288
N = int(input())

heights = [int(s) for s in input().split()]

def cost(i, j):
  return abs(heights[i] - heights[j])

dp = [0 for _ in range(N)]
dp[0] = 0
dp[1] = cost(0, 1)

if N > 3:
  for k in range(2, N):
    dp[k] = min(dp[k-1] + cost(k, k-1),
                dp[k-2] + cost(k, k-2))
print(dp[N-1])

Measured memory_bytes: 20456