akhauriyash/Code-Regression huggingface dataset:
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    static PrintWriter out;
    static Scanner sc;

    static void solve() {
        int n = nextInt();
        int[] a = nextIntArray(n);
        int[] aDelta = new int[n + 1];
        for (int i = 0; i <= n; i++) {
            if (i == 0) {
                aDelta[i] = Math.abs(a[0]);
            } else if (i == n) {
                aDelta[i] = Math.abs(a[n - 1]);
            } else {
                aDelta[i] = Math.abs(a[i] - a[i - 1]);
            }
        }

        int total = 0;
        for (int i = 0; i <= n; i++) {
            total += aDelta[i];
        }

        for (int i = 0; i < n; i++) {
            int ans = total;
            ans -= (aDelta[i] + aDelta[i + 1]);
            if (i == 0) {
                ans += Math.abs(a[1]);
            } else if (i == n - 1) {
                ans += Math.abs(a[n - 2]);
            } else {
                ans += Math.abs(a[i + 1] - a[i - 1]);
            }
            out.println(ans);
        }
    }

    static int nextInt() {
        return Integer.parseInt(sc.next());
    }

    static long nextLong() {
        return Long.parseLong(sc.next());
    }

    static String nextString() {
        return sc.next();
    }

    static int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    static List<Integer> nextIntList(int n) {
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(nextInt());
        }
        return list;
    }

    static List<Long> nextLongList(int n) {
        List<Long> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(nextLong());
        }
        return list;
    }

    static <T extends Comparable<? super T>> void sort(List<T> list) {
        Collections.sort(list);
    }

    // greatest common divisor
    static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    // baseのn乗を計算を返す
    static int pow(int base, int n) {
        int ret = 1;
        for (int i = 0; i < n; i++) {
            ret *= base;
        }
        return ret;
    }

    // intをlength桁のbit文字列に変換
    static String toBinaryString(int input, int length) {
        return toBinaryString(input).substring(29 - length);
    }

    // intを29桁のbit文字列に変換
    static String toBinaryString(int input) {
        String ret = "";
        int max = 0x10000000;
        for (int i = 0; i < 29; i++) {
            int tmp = input / max;
            ret += tmp;
            input %= max;
            max /= 2;
        }
        return ret;
    }

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

        solve();

        out.flush();
        sc.close();
    }

}


Measured memory_bytes: 48436
#include <iostream>
#include <limits.h>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(void){
    string s, t, ans[55];
    int ans_idx = 0;
    cin >> s;
    cin >> t;
    
    for (int i = 0; i < s.size() - t.size() + 1; i++) {
        bool am = true;
        for (int j = 0; j < t.size(); j++) {
            if (s[i + j] != '?' && s[i + j] != t[j]) am = false;
        }
        if (am) {
            for (int j = 0; j < i; j++) {
                if (s[j] == '?') ans[ans_idx] = ans[ans_idx] + "a";
                else ans[ans_idx] = ans[ans_idx] + s[j];
            }
            ans[ans_idx] = ans[ans_idx] + t;
            for (int j = i + t.size(); j < s.size(); j++) {
                if (s[j] == '?') ans[ans_idx] = ans[ans_idx] + "a";
                else ans[ans_idx] = ans[ans_idx] + s[j];
            }
            ans_idx++;
        }
    }
    
    sort(ans, ans + ans_idx);
    if (ans_idx > 0) cout << ans[0] << endl;
    else cout << "UNRESTORABLE" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
	double n;
	while(scanf("%lf",&n)!=EOF){
	for(int i=1;i<=10009;i++){
	int y=i*5-5;
	double t=sqrt((double)y/4.9);
	if(t*9.8>=n){cout<<i<<endl;break;}
	}
	}
	return 0;
}

Measured memory_bytes: 1232
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL << 60;

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

    deque<char> q;
    for(char c: s) q.push_back(c);
    bool flip = false;
    int Q;
    cin >> Q;
    rep(qi,Q){
        int ty;
        cin >> ty;
        if(ty == 1){
            flip = !flip;
        }
        else{
            int f;
            char c;
            cin >> f >> c;
            if(flip) f = 3-f;
            if(f == 1){
                q.push_front(c);
            }else{
                q.push_back(c);
            }
        }
    }
    if(flip) reverse(q.begin(),q.end());
    string ans;
    for(char c : q){
        ans+=c;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1412
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		String[] a = new String[n];
		String[] b = new String[m];
		for(int i = 0;i<n;i++) {
			a[i] = sc.next();
		}
		for(int i=0;i<m;i++) {
			b[i] = sc.next();
		}
		
		for(int i=0;i<n-m+1;i++) {
			for(int k=0;k<n-m+1;k++) {
				boolean flag = true;
				for(int x=0;x<m;x++) {
					for(int y=0;y<m;y++) {
						if(a[i+x].charAt(k+y) != b[x].charAt(y)) {
							flag=false;
						}
					}
				}
				if(flag) {
					System.out.println("Yes");
					return;
				}
			}
		}
		System.out.println("No");
	}
}

Measured memory_bytes: 23764
#include <cstdio>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>

using u4t = std::uint32_t;
using i4t = std::int32_t;
using u8t = std::uint64_t;
using i8t = std::int64_t;

void factorize(const i8t number, std::vector<i8t>& result){
  result.clear();
  i8t t = number;
  if (t == 1) {result.push_back(1);return;}
  if((t % 2)==0){
    do{result.push_back(2);t /= 2;}while((t % 2)==0);
    if(t == 1){return;}
  }
  i8t limit = (i8t)std::sqrt((double)t);
  for(i8t i=3; i<=limit; i+=2){
    if((t % i)==0){
      do{result.push_back(i);t /= i;}while((t % i)==0);
      if(t == 1){return;}
      limit = (i8t)sqrt((double)t);
    }
  }
  result.push_back(t);
}

u8t ipow(u8t b, u8t i){return i == 0?1:b*ipow(b,i-1);}
u8t keta = UINT64_MAX;
void check(std::vector<i8t> const& v, int index, u8t a, u8t b) {
  u8t m = a>b?a:b;
  u8t keta1 = 1 + (int) std::log10((double) m);
  if (keta1 >= keta) return;
  if (index==v.size()) {
    keta = keta1;
    return;
  }

  int value = v[index];
  int iend = index+1;
  while(iend <v.size() && v[iend] == value) iend++;
  for(int i = 0,n=iend -index;i<=n;i++)
    check(v,index+n, a * ipow(value,i), b * ipow(value,n-i));
}

int main() {
  i8t N;
  std::cin >> N;
  std::vector<i8t> fac;
  factorize(N, fac);
  {
    u8t a =1;u8t b=1;
    for (i4t i = fac.size() - 1; i>= 0; i--) {(a < b? a: b) *= fac[i];}
    u8t m = a>b?a:b;
    keta = 1 + (int) std::log10((double) m);
  }

  check(fac,0,1,1);

  //std::cout << std::min(keta1, keta2) << std::endl;
  std::cout << keta << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int N;
    cin >> N;
    int A[N];
    for(int i=0;i<N;i++) cin >> A[i];
    int kari1 = 0 , kari2 = 0;
    for(int i=0;i<36;i++){
      for(int j=0;j<N;j++){
        if(A[j]%2 == 1){
          kari2 = 1;
          break;
        }
        else A[j] = A[j]/2;
      }
      if(kari2 == 1) break;
      kari1++;
    }
    cout << kari1;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;


int main() {
int N, C, K; cin >> N >> C >> K;
VI T(N); rep(i, 0, N) scanf("%d", &T[i]);

sort(ALL(T));

int bus=0, pass, leavetime;

for(int i = 0; i < N;){
    pass = 0;
    leavetime= T[i] + K;
    while (i < N && pass < C && T[i] <= leavetime) {
        ++pass;
        ++i;
    }
    ++bus;
}

cout << bus << "\n";

return 0;
}

// 境界，出力文字列 チェック
// int は ± 2*10⁹.


Measured memory_bytes: 640
#!/usr/bin/python3

import math
import sys


DEBUG = False


def inp():
    return sys.stdin.readline().rstrip()


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


def run(N, A, loc, i):
    for c, d in A:
        if i in loc[c]:
            if d == 'L':
                i -= 1
                if i < 0:
                    return -1
            else:
                i += 1
                if i >= N:
                    return N
    return i


def solve(N, Q, S, A):
    loc = {a: set() for a in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'}
    for i, c in enumerate(S):
        loc[c].add(i)

    p0 = run(N, A, loc, 0)
    plast = run(N, A, loc, N - 1)

    if plast == -1:
        return 0
    if p0 == N:
        return 0

    lcnt = 0
    if p0 == -1:
        lb = 0
        ub = N - 1
        while ub - lb > 1:
            mid = (lb + ub) // 2
            p = run(N, A, loc, mid)
            dprint(lb, ub, mid, '=>', p)
            if p == -1:
                lb = mid
            else:
                ub = mid
        dprint(lb, ub)
        lcnt = ub

    rcnt = 0
    if plast == N:
        lb = 0
        ub = N - 1
        while ub - lb > 1:
            mid = (lb + ub) // 2
            p = run(N, A, loc, mid)
            dprint(lb, ub, mid, '=>', p)
            if p == N:
                ub = mid
            else:
                lb = mid
        dprint(lb, ub)
        rcnt = N - ub

    return N - lcnt - rcnt


def main():
    N, Q = [int(e) for e in inp().split()]
    S = inp()
    A = [inp().split() for _ in range(Q)]
    print(solve(N, Q, S, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 60468
import numpy as np

h, w, k = map(int, input().split())
c = np.array([list(input()) for _ in range(h)])
ans = 0
for i in range(2 ** (h+w)):
    cnt = 0
    c_ = c.copy()
    #print(bin(i))
    for j in range(h+w):
        if i >> j & 1:
            if j < h:
                c_[j] = 'x'
            else:
                c_.T[j-h] = 'x'
    for y in range(h):
        for x in range(w):
            if c_[y][x] == '#':
                cnt += 1
    if cnt == k:
        ans += 1
print(ans)

Measured memory_bytes: 26720
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

const ll INF = 1e9;

int main() {
	#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
	#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	ll n, m; cin >> n >> m;
	vvl path(n);
	REP(i, m) {
		ll a, b; cin >> a >> b;
		a--; b--;
		path[a].push_back(b);
		path[b].push_back(a);
	}
	ll q; cin >> q;
	vl v(q), d(q), c(q);
	REP(i, q) {
		cin >> v[i] >> d[i] >> c[i];
		v[i]--;
	}
	vl ans(n, -1), ansd(n, -1);
	for (int i = q - 1; i >= 0; --i) {
		using P = tuple<ll, ll, ll>;
		deque<P> q; q.push_back(P(v[i], -1, d[i]));
		if (ans[v[i]] != -1) {
			if (ansd[v[i]] >= d[i]) continue;
		} else {
			ans[v[i]] = c[i];
		}
		ansd[v[i]] = d[i];

		while (!q.empty()) {
			ll cur, prev, curd;
			tie(cur, prev, curd) = q.front(); q.pop_front();
			if (curd != 0) {
				for (auto next : path[cur]) if (next != prev) {
					if (ans[next] == -1) {
						q.push_back(P(next, cur, curd - 1));
						ans[next] = c[i];
						ansd[v[i]] = curd - 1;
					} else if (ansd[next] < curd - 1) {
						ansd[next] = curd - 1;
						q.push_back(P(next, cur, curd - 1));
					}
				}
			}
		}
	}
	REP(i, n) cout << (ans[i] == -1 ? 0 : ans[i]) << "\n";
	cout << flush;
}

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

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

int main() {
    int N, R;
    cin >> N >> R;

    if (N >= 10) {
        cout << R << endl;
    } else
    {
        R = R + (100 * (10 - N));
        cout << R << endl;
    }

    return 0;
}

Measured memory_bytes: 3576
#include<stdio.h>

int main(){
	int judgment,point,point_sum=0,point_max=0,point_min=1000,i;

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

		for(i=0;i<judgment;i++){
			scanf("%d",&point);
			point_sum+=point;
			if(point>point_max)
				point_max=point;
			if(point<point_min)
				point_min=point;
		}
		point_sum=point_sum-point_max-point_min;

		printf("%d\n",point_sum/(judgment-2));
		point_sum=0;
		point_max=0;
		point_min=1000;
	}

	return 0;
}

Measured memory_bytes: 600
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> a(M), b(M);
    rep(i, M) {
        cin >> a.at(i);
        cin >> b.at(i);
    }

    vector<int> ans(N);
    rep(i, N) {
        int count = 0;
        rep(j, M) {
            if (a.at(j) == (i + 1) || b.at(j) == (i + 1)) {
                count++;
            }
        }
        ans.at(i) = count;
    }

    rep(i, N) {
        cout << ans.at(i) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

#include <vector>
#include <cmath>
#include <cstring>

const double EPS = 1e-10;
#define equals(a,b) (fabs((a) - (b)) < EPS)
struct Point{
	double x,y;
	Point(double x = 0.0,double y =0.0):x(x),y(y){}
	Point operator + (Point& p){ return Point(x+p.x,y+p.y);	}
	Point operator - (Point& p){ return Point(x-p.x,y-p.y); }
	Point operator * (double k){ return Point(x*k,y*k);	}
	Point operator / (double k){ return Point(x/k,y/k); }

	double norm(){return x*x+y*y;}
	double abs(){return sqrt(norm());}

	bool operator < (const Point& p) const {
		return x != p.x ? x < p.x : y < p.y;
	}
	bool operator == (const Point &p) const{
		return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
	}
};
typedef Point Vector;

double dot(Vector a, Vector b){
	return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b){
	return a.x*b.y - a.y*b.x;
}


struct Segment{
	Point p1,p2;
};

typedef Segment Line;
class Circle{
public:
	Point c;
	double r;
	Circle(Point c = Point(), double r = 0.0): c(c),r(r){}
};
typedef vector<Point> Polygon;

bool isOrthgonal(Vector a, Vector b){
	return equals(dot(a,b),0.0);
}

bool isOrthgonal(Point a1, Point a2, Point b1, Point b2){
	return isOrthgonal(a1-a2,b1-b2);
}

bool isOrthgonal(Segment s1, Segment s2){
	return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1),0.0);
}

bool isParallel(Vector a,Vector b){
	return equals(cross(a,b),0.0);
}

bool isParallel(Point a1, Point a2, Point b1, Point b2){
	return isParallel(a1-a2,b1-b2);
}

bool isParallel(Segment s1, Segment s2){
	return equals(cross(s1.p2 - s1.p1,s2.p2-s2.p1),0.0);
}



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int n;cin>>n;
	REP(i,n){
		int a,b,c,d,e,f,g,h;
		cin>>a>>b>>c>>d>>e>>f>>g>>h;
		Vector v1(c-a,d-b),v2(g-e,h-f);
		if(isParallel(v1,v2))cout << 2 << endl;
		else if(isOrthgonal(v1,v2))cout << 1 << endl;
		else cout << 0 << endl;
	}
  return 0;
}

Measured memory_bytes: 3168
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
  int A, B, s = 0, c = 2;
  cin >> A >> B;
  while(c != 0) {
    if(A > B) {
      s += A;
      --A;
    } else {s += B; --B;}
    --c; 
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
<?php
for ($i  = 0; $i < 3; $i++) {
    $a[] = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $check[] = [false, false, false];
}
fscanf(STDIN, '%d', $n);
for ($i  = 0; $i < $n; $i++) {
    fscanf(STDIN, '%d', $b);
    for ($j  = 0; $j < 3; $j++) {
        for ($k = 0; $k < count($a); $k++) {
            if ($a[$j][$k] == $b) {
                $check[$j][$k] = true;
            }
        }
    }
}

$ans = 'No';

for ($i = 0; $i < count($check); $i++) {
    $flag = true;
    for ($j = 0; $j < count($check[$i]); $j++) {
        if ($check[$i][$j] == false) {
            $flag = false;
            break;
        }
    }
    if ($flag) {
        $ans = 'Yes';
    }
}

for ($j = 0; $j < count($check); $j++) {
    $flag = true;
    for ($i = 0; $i < count($check); $i++) {
        if ($check[$i][$j] == false) {
            $flag = false;
            break;
        }
    }
    if ($flag) {
        $ans = 'Yes';
    }
}

$flag = true;
for ($i = 0; $i < count($check); $i++) {
    if ($check[$i][$i] == false) {
        $flag = false;
        break;
    }
}
if ($flag) {
    $ans = 'Yes';
}

$flag = true;
for ($i = 0; $i < count($check); $i++) {
    if ($check[count($check) - 1 - $i][$i] == false) {
        $flag = false;
        break;
    }
}
if ($flag) {
    $ans = 'Yes';
}

echo $ans . PHP_EOL;

Measured memory_bytes: 4604
N = int(input())
H = list(map(int, input().split()))

ans = 'Yes'
RH = list(reversed(H))
for i in range(N - 1):
    if RH[i] >= RH[i + 1]:
        continue
    if RH[i] == RH[i + 1] - 1:
        RH[i + 1] -= 1
        continue
    ans = 'No'

print(ans)


Measured memory_bytes: 14252
#include <iostream>
using namespace std;
int a[100005],b[100005];
int main(int argc, char** argv) {
	int n,m,c;
	cin >> n >> m >> c;
	for(int i=1;i<=m;i++)
		cin >> a[i];
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		int x=0,s=0;
		for(int j=1;j<=m;j++)
		{
			cin >> x;
			s+=x*a[j];
		}
		s+=c;
		if(s>0) ++ans;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner s = new Scanner(System.in);
		String str = s.nextLine();
		char[] strKeyence = { 'k', 'e', 'y', 'e', 'n', 'c', 'e' };

		int backEnd = -1;
		for (int i = 0; i < strKeyence.length; i++) {
			if (strKeyence[i] != str.charAt(i)) {
				backEnd = i;
				break;
			}
			if (i == strKeyence.length - 1) {
				System.out.println("YES");
				return;
			}
		}

		boolean checkKeyence = true;
		for (int j = strKeyence.length - 1; j >= backEnd; j--) {
			int backId = str.length() - 1 + j - (strKeyence.length - 1);
			if (strKeyence[j] != str.charAt(backId))
				checkKeyence = false;
		}

		if (checkKeyence)
			System.out.println("YES");
		else
			System.out.println("NO");
	}
}


Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
#define test ll t;cin>>t;while(t--)
#define f first
#define s second
#define pb push_back
#define pop pop_back
#define int long long int

int arr[3007];
int dp[3007][3007]={0};
int maxmargin(int i,int j)
{
    if(i>j)
        return 0;

        if(dp[i][j]!=0)
        return dp[i][j];

        int x = min(maxmargin(i+2,j),maxmargin(i+1,j-1));
        int y = min(maxmargin(i,j-2),maxmargin(i+1,j-1));

        int ans=max(arr[i]+x,arr[j]+y);

    return dp[i][j] = ans;
}

int32_t main()
{
	fast;
	int n;
    cin>>n;
    int sum=0;
    for(int i=0;i<n;i++)
    {
       cin>>arr[i];
       sum+=arr[i];
    }
    int score = maxmargin(0,n-1);
    int d = sum-score;
    cout<<score-d<<"\n";

	return 0;
}


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

ll inf=1ll<<60;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ll n,m,i,j,a[50],b[50],c[50],d[50],t1,t;
	cin>>n>>m;
	for (i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	for (i=0;i<m;i++){
		cin>>c[i]>>d[i];
	}
	for (i=0;i<n;i++){
		t1=inf;
		for (j=0;j<m;j++){
			if (t1>abs(c[j]-a[i])+abs(d[j]-b[i])){
				t=j+1;
				t1=abs(c[j]-a[i])+abs(d[j]-b[i]);
			}
		}
		cout<<t<<"\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	
	int a,b,c;
	
	scanf("%d %d %d",&a,&b,&c);
	
	int sum1=a+b;
	int sum2=a+c;
	int sum3=b+c;
	
	if(sum1<=sum2 && sum1<=sum3){
		printf("%d\n",sum1);
	}
	else if(sum2<=sum1 && sum2<=sum3){
		printf("%d\n",sum2);
	}
	else if(sum3<=sum1 && sum3<=sum2){
		printf("%d\n",sum3);
	}
	
	
	return 0;
}

Measured memory_bytes: 128
n=input()
h=list(map(int,input().split()))
p=0
n=int(n)
a="Yes"
for k in range(n):
  if h[k]>=p:
    p=h[k]
  elif p-h[k]==1:
    p=h[k]+1
  else:
    a="No"
    break
print(a)  

Measured memory_bytes: 14252
N = int(input())
A_list = list(map(int, input().split()))
A_list.sort(reverse=True)
n = 1
for i in A_list:
  if A_list[-1] == 0:
    print(0)
    break
  n = n * i
  if n > 1000000000000000000:
    print(-1)
    break
else:
  print(n)

Measured memory_bytes: 21644
s = input()
front = []
back = []
isflip = False

# flipがFalseの時は、F=1ならfront[0]に、f=2ならback[-1]に来るように付ける
# flipがtrueの時は、F=1ならback[-1]に、F=2ならfront[0]に来るように付ける
# ∴常にappendすればOK.最後にfrontにreversedを掛けて出力.
a = int(input())
for i in range(a):
    query = input()
    if(int(query[0]) == 1):
        isflip = not isflip
    else:
        t, f, c = query.split()
        if(int(f) == 2):
            if(isflip):
                front.append(c)
            else:
                back.append(c)
        else:
            if(not isflip):
                front.append(c)
            else:
                back.append(c)

if(isflip):
    print("".join(str(e) for e in reversed(back)) + "".join(str(e) for e in reversed(s)) + "".join(str(e) for e in front))
else:
    print("".join(str(e) for e in reversed(front)) + s + "".join(str(e) for e in back))


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

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer cur = nil->next;
  while(cur!=nil&&cur->key!=key){
    cur=cur->next;
  }
  return cur;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer t = nil->prev;
  if(t==nil) return;
  deleteNode(t);
}

void delete(int key){
   NodePointer t = listSearch(key);
  if(t==nil) return;
  deleteNode(t);
}

void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev=nil;

}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}



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

int main() {
    int n;
    int k;
    cin >> n >> k;
    int p[n];
    for (int i = 0; i < n; i++) {
        int num;
        cin >> num;
        p[i] = num;
    }

    int sum = 0;
    sort(p, p + n);
    for (int i = 0; i < k; i++) {
        sum += p[i];
    }
    cout << sum;
}

Measured memory_bytes: 3560
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; i++)
#define REP(i,x,n) for (int i=x; i<n; i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;

int determine(vi &vec, string s, int i, int k){
  if (s.at(i) == s.at(i-k) && vec.at(i - k) == 0){
    vec.at(i) = 1;
    return true;
  }
  else {
    return false;
  }
}

int main(){
  int n, k, r, s, p;
  cin >> n >> k >> r >> s >> p;
  string S;
  cin >> S;
  vi vec((int)S.size());
  int ans = 0;
  rep(i,(int)S.size()){
    //cout << ans << endl;
    if (i<k){
      ans += S.at(i)=='s'? r : (S.at(i)=='p'? s : p);
      continue;
    }
    if (determine(vec, S, i, k)){
      continue;
    }
    ans += S.at(i)=='s'? r : (S.at(i)=='p'? s : p);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3832
#include<bits/stdc++.h>
using namespace std;
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout<<'\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
LL inf=2147483647;const long long ll =9223372036854775807,ninf=1000000000;const double eps = 1e-6; const long long nll =1000000000000000000;
#define sz size()
#define len(X) strlen(X)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ULL unsigned long long
#define de cout<<"test"<<endl;
#define st system("pause");
#define F first
#define S second
class MagicNumberThree
{

    public:
int countSubsequences(string s)
{

}

};

int vis[100005]={};

int sum[100005]={};
int main()
{
    vis[1]=1;
    vis[0]=1;
    for(int i=2;i<100005;i++){
        if(!vis[i]){
        for(int j=i+i;j<100005;j+=i){
        vis[j]=1;
        }
        }
    }
    
        
    for(int i=1;i<100005;i++){
        sum[i]=sum[i-1];
        if(!vis[i]&&!vis[ (i+1)/2]){
            sum[i]++;
        }
    }
  int a;
  while(cin>>a){
        for(int i=0;i<a;i++){
    int l,r;
    cin>>l>>r;
cout<<sum[r]-sum[l-1]<<endl;
        }
    
    
    
    
    
    
    
  }

    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = vector<T>;
using vvi = vector<vector<int>>;

void svtr(vector<int> &a){
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
}

int main() {
  int a,b;
  cin >> a >> b;
  if(a>12)
    cout << b;

  else if(a<6)
    cout << 0;

  else
    cout << b/2;
  return 0;
}


Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template< typename T > istream &operator>>(istream &is, vector< T > &v) { for(T &in : v) is >> in; return is; }

bool ng=false;
vec posi;

void dfs(pvvec &G,int now){
    for(auto p:G[now]){
        int next,dist;
        tie(next,dist)=p;
        if(posi[next]==INF){ // 未訪問
            posi[next]=posi[now]+dist;
            dfs(G,next);
        }
        else{ // 訪問済みならチェック
            if(posi[next]!=posi[now]+dist){
                ng=true;
                return;
            }
        }
    }
    return;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n,m;
    cin>>n>>m;
    posi.assign(n,INF);

    pvvec G(n);
    rep(i,m){
        int a,b,c;cin>>a>>b>>c;a--;b--;
        G[a].eb(b,c);
        G[b].eb(a,-c);
    }

    rep(i,n){
        if(posi[i]==INF){ // 新しい始まりなら0に初期化
            posi[i]=0;
            dfs(G,i);
        }
    }

    if(ng){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }
    
}

Measured memory_bytes: 16512
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;
#define p(a,b) (b-a)*(b-a)
#define rep(i,n) for(int i = 0 ; i < n ; i++)

int compute(int a,int b,int c,int d){
  int e[4] = {a,b,c,d};
  int res = (1<<29);

  rep(i,4){
    rep(j,4){
      if(i == j) continue;
      rep(k,4){
	if(i == k || j == k) continue;
	rep(l,4){
	  if(i == l || j == l || k == l) continue;
	  res = min(res,p(e[j],e[i])+p(e[k],e[j])+p(e[l],e[k]));
	}
      }
    }
  }
 
  return res;
}

int main(){
  int a,b;

  while(cin >> a >> b , a | b){
    vector<P> c,d;
    for(int i = 1 ; i*i <= a ; i++){
      if(a % i == 0){
	c.push_back(P(i,a/i));
      }      
    }

    for(int i = 1 ; i*i <= b ; i++){
      if(b % i == 0){
	d.push_back(P(i,b/i));
      }
    }

    int ans = (1<<29);
    rep(i,(int)c.size()){
      rep(j,(int)d.size()){
	ans = min(ans,compute(c[i].first,c[i].second,d[j].first,d[j].second));
      }
    }

    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1204
use proconio::{
   fastout, input,
   marker::{Bytes, Chars, Isize1, Usize1},
};

fn main() {
   input! {
      x:i128
   }
   let mut table = vec![];
   for i in -10000..=10000_i128 {
      table.push(i.pow(5_u32));
   }
   let mut ic = -10000;
   for &i in &table {
      let mut jc = -10000;
      for &j in &table {
         if i - j == x {
            println!("{} {}", ic, jc);
            return;
         }
         jc += 1;
      }
      ic += 1;
   }
}


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

#define SIZE 200000

using namespace std;
long long int A[SIZE],A1[SIZE],A2[SIZE];


bool comparaison(long long int i, long long int j)
{
    return ((i-A[i]) < (j-A[j]));
}


int main() {
    long long int i,j,k,N,M,K,Q,X;
  //  long long int A[100][100];

   cin >> N;

  long long int actuel,e;
long encore;

  // on cherche d'abord les solutions positifs ;

  long long s,s2,s3;
  s = 0;

  for (i=0;i<N;i++) {
    cin >> A[i];
    A1[i] = i-A[i];
    A2[i] = i+A[i];
  }

      sort(A1,A1 + N);
      sort(A2,A2 + N);

/*
      for (i=0;i<N;i++)
        cerr << i << " " << pos[i]-A[pos[i]] << endl;
        */

long long int a,b,c;
  i = 0; j = 0;
  while ((i<N) && (j<N)) {
    if (A1[i]==A2[j]) {
      k = j+1;
      encore = 1;
      s2 = 1;
      while ((k<N) && encore) {
        if (A1[i] == A2[k]) {
          s2++; // s2 compte le nombre de collisions
        }
        else encore = 0;
        k++;
      }
      encore = 1;
      s3 = 1;
      i++;
      while ((i<N) && encore) {
        if (A1[i] == A1[i-1]) {
          s3++;
          i++;
        }
        else encore = 0;
      }
      s += (s2*s3);
    }
    else if (A1[i] < A2[j])
      i++;
    else
      j++;
  }

  cout << s << endl;
  return 0;
}


Measured memory_bytes: 8280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
 
int main(){
  int n;
  cin >> n;
  ll a[n];
  for(int i = 0; i < n; i++)  cin >> a[i];
  ll ans = 0;
  for(int i = 0; i < 61; i++){
    ll cnt = 0;
    for(int j = 0; j < n; j++)  cnt += ((a[j]>>i)&1);
    ans += (1ll<<i)%mod * cnt % mod * (n-cnt);
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}

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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  char A;
  cin >> A;
  if(isupper(A)){
    cout << "A" <<endl;
  } else{
    cout << "a" <<endl;
  }
}

Measured memory_bytes: 3644
import sys
pin=sys.stdin.readline

N=int(pin())
A=list(map(int,pin().split()))
B=list(map(int,pin().split()))
C=list(reversed(B))

for i in range(N):
  if A[i]==C[i]:
    break
else:
  print("Yes")
  for k in C:
    sys.stdout.write(f"{k} ")
  print()
  sys.exit()
D=B[N//2:]+B[:N//2]
for j in range(N):
  if A[j]==D[j]:
    print("No")
    break
else:
  print("Yes")
  for l in D:
    sys.stdout.write(f"{l} ")
  print()
  sys.exit()


Measured memory_bytes: 41448
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define MOD 1000000007
#define f(i,a,n) for(lli i = a; i < n; i++)
#define fb(i,a,n) for(lli i=n-1;i>=a;i--)
 
#define p64 pair<lli,lli>
#define v64 vector<lli>
#define p32 pair<int,int>
#define v32 vector<int>
#define vp64 vector<pair<lli , lli >>
#define vp32 vector<pair<int , int>>
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mem(x,y) memset(x,y,sizeof(x))
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    //cin>>t;
    while(t--){
        int h,a; cin>>h>>a;
        lli ans = 0;
        for(int i=0;i<a;i++){
            lli b; cin>>b;
            ans+=b;
        }
        // cout<<ans<<endl;
        if(ans>=h){
            cout<<"Yes"<<endl;
        }else
        {
            cout<<"No"<<endl;
        }
        
}
return 0;
}

Measured memory_bytes: 384
import math

def is_integer(n):
    try:
        float(n)
    except ValueError:
        return False
    else:
        return float(n).is_integer()

n,d = map(int,input().split())
x = []
for i in range(n):
    x.append([int(j) for j in input().split()])
c = 0
for i in range(n-1):
    for j in range(i+1,n):
        dist = 0
        for a in range(d):
            dist += (x[i][a] - x[j][a]) * (x[i][a] - x[j][a])
        if is_integer(math.sqrt(dist)):
            c += 1
print(c)

Measured memory_bytes: 3064
char out[100000];outsz;
char c[10];
main()
{
	int N,X,Y;
	scanf("%d%d%d",&N,&X,&Y);
	int loop=Y-X+1;
	for(int k=1;k<N;k++)
	{
		int ans=0;
		int z=X<k?X-1:k-1;
		if(k-z<=loop/2)
		{
			int t=2*k-loop-1>0?2*k-loop-1:0;
			ans+=(z-t/2)*2;
			ans-=!(loop&1)&&loop/2<k&&k-loop/2<X;
		}
		z=N-Y<k-1?N-Y:k-1;
		if(k-z<=loop/2)
		{
			int t=2*k-loop-1>0?2*k-loop-1:0;
			ans+=(z-t/2)*2;
			ans-=!(loop&1)&&loop/2<k&&k-loop/2<N+1-Y;
		}
		if(N+1+X-Y>k)ans+=N+1+X-Y-k;
		if(k==1)ans--;
		else
		{
			ans-=X>=k;
			ans-=N-Y>=k-1;
		}
		if(k*2<loop)ans+=loop;
		else if(k*2==loop)ans+=loop/2;
		int sz=10;
		do{
			c[--sz]=ans%10+'0';
		}while(ans/=10);
		for(;sz<10;)out[outsz++]=c[sz++];
		out[outsz++]='\n';
	}
	write(1,out,outsz);
}


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

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int main(){
	int w, h, n;
	cin >> w >> h >> n;
	int a = 0, b = 0, ans = 0;
	rep(i, n){
		int p; cin >> p;
		if(p == 0) a++;
		else b++;
		
		if(b < w - 1 && a == b ||
			w - 2 <= b && b <= w - 2 + h - 3 && a - w == b - w + 2 ||
			w - 2 + h - 3 <= b && b - (w - 2 + h - 3) == a - (w - 1) - h)
		ans++;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

bool t = false ;

int n ;

void solve(int sum)
{
    if(sum > n)
        return ;
    if(sum == n)
    {
        t = true ;
        return ;
    }
    solve(sum + 4);
    solve(sum + 7);
}

int main()
{
    cin>>n ;
    solve(0);
    if(t)
        cout<<"Yes";
    else
        cout<<"No";
    return 0 ;
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
#define Size(n) (n).size()

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//long long int kaizyo(long long int hh){
  //  cmp=1;
    //while(hh>1){
      //  cmp=(cmp*hh)%MOD;
        //hh--;
    //}
    //return cmp;
//}
//long long int ruizyo(long long int aa, long long int bb){
  //  if(aa==0){
    //    return 1;
    //}
    //else if(aa%2==0){
      //  long long int tt=ruizyo(aa/2,bb);
        //return (tt*tt)%MOD;
    //}
    //else{
      //  return (ruizyo(aa-1,bb)*bb)%MOD;
    //}
//}フェルマ－のア


//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

//visited=vector<vector<bool>>(10,vector<bool>(10,false));アを全部falseに


long long int n,cnt=0,ans=0,a[10000000],b,c,cmp[10000000],cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;

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

       cin>>n;
       rep(i,n){cin>>a[i];
       if(a[i]%10!=0){
           fl=false;
       }
       if(i==0){
           sum=a[i];
       }
       else{
           sum+=a[i];
       }
       }
       sort(a,a+n);
       if(!fl){
       if(sum%10==0){
         rep(i,n){
             if(a[i]%10==0){
                 continue;
             }
             else{
                 sum-=a[i];
                 if(sum%10!=0){
                     Cout(sum);
                     return 0;
                 }
             }
         }
       }
       else{
           Cout(sum);
       }
       }
       else{
           Cout(0);
       }
return 0;
}


Measured memory_bytes: 2304
use List::Util qw(min);
sub doit {
	my @hs = @_;
    return 0 if scalar(@hs) == 0;
    my $m = min(@hs);
	my @left;
    my @right = map { $_ - $m } @hs;
    while (my $h = shift(@right)) {
		push(@left, $h);
    }
    return doit(@left) + doit(@right) + $m;
}

my $line;
$line = <STDIN>;
my @hs = split(' ', ($line = <STDIN>));
print doit(@hs);

Measured memory_bytes: 1152
#include<iostream>
#include<bitset>

using namespace std;

int main() {
    int n;
    cin >> n;
    bitset<64> mask[n];
    for (int i = 0; i < n; i++) {
        int k, b;
        cin >> k;
        while (k-- > 0) {
            cin >> b;
            mask[i].set(b);
        }
    }
    bitset<64> bs;
    int q, op, m;
    cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> op >> m;
        if (op == 0) cout << bs[m] << endl;
        if (op == 1) bs |= mask[m];
        if (op == 2) bs &= ~mask[m];
        if (op == 3) bs ^= mask[m];
        if (op == 4) cout << ((bs & mask[m]) == mask[m]) << endl;
        if (op == 5) cout << (bs & mask[m]).any() << endl;
        if (op == 6) cout << (bs & mask[m]).none() << endl;
        if (op == 7) cout << (bs & mask[m]).count() << endl;
        if (op == 8) cout << (bs & mask[m]).to_ullong() << endl;
    }
    return 0;
}


Measured memory_bytes: 3108
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const long long MOD = 998244353;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
#define RSORT(v) std::sort(v.rbegin(), v.rend())
constexpr auto PI = 3.14159265358979323846264338327950L;


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

    cin >> N >>M;
    vector<int> H(N),m(N);
    for (int i = 0; i < N; ++i) {
        cin >> H[i];
        m[i] = 0;
    }
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        m[a] = max(m[a], H[b]);
        m[b] = max(m[b], H[a]);
    }
    int ans = 0;
    for (int i = 0; i < N; ++i) {
        ans += H[i] > m[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3980
#include "bits/stdc++.h"
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr_inv(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define rep(i,n) repr(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define MOD 1000000007
#define PI 3.1415926535
using namespace std;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	int x, a, b, temp;

	cin>>x>>a>>b;

	temp=(x-a)/b;

	cout<<x-a-b*temp<<endl;
}

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

using namespace std;

deque<int> path;
int n, m, a, b;
vector<int> adj[100005];
bool onPath[100005];

int main() {
    cin >> n >> m;
    memset(onPath, 0, sizeof(bool) * (n+1));
    for (int i = 0; i < m; i++) {
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    path.push_front(1);
    onPath[1] = true;
    bool good = false;
    while (!good) {
        good = true;
        int front = path.front();
        for (int i : adj[front]) {
            if (!onPath[i]) {
                path.push_front(i);
                onPath[i] = true;
                good = false;
                break;
            }
        }
        int back = path.back();
        for (int i : adj[back]) {
            if (!onPath[i]) {
                path.push_back(i);
                onPath[i] = true;
                good = false;
                break;
            }
        }
    }
    cout << path.size() << endl;
    while (!path.empty()) {
        int front = path.front();
        path.pop_front();
        cout << front << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 6740
// 以下のライブラリを使ってみる.
// dr_ken氏.
// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=1455855#1
#include <bits/stdc++.h>
using namespace std;
#define MAX_V 100001
const long long INF = 1LL<<60;

static int V, E, r;
static vector<pair<int, long long> > graph[MAX_V];
static long long dist[MAX_V];

void bfs(){
    
    // 1. 初期化.
    priority_queue<pair<long long,int>, vector<pair<long long,int> >, greater<pair<long long, int> > > pq;
    for(int i = 0; i < MAX_V; ++i) dist[i] = INF;
    
    // 2. 始点設定.
    dist[r] = 0;
    pq.push(make_pair(0, r));
    
    // 3. 始点から各ノードについて, 最短経路上の辺の重みの総和を保存.
    while(!pq.empty()){
        long long cD = pq.top().first;
        int cV = pq.top().second;
        pq.pop();
        
        if(dist[cV] < cD) continue;

        for(int i = 0; i < graph[cV].size(); ++i){
            int nV = graph[cV][i].first;
            long long nD = cD + graph[cV][i].second;
            if(dist[nV] > nD){
                dist[nV] = nD;
                pq.push(make_pair(nD, nV));
            }
        }
    }
}

int main(){

    // 1. 入力情報.
    scanf("%d %d %d", &V, &E, &r);
    
    // 2. グラフ作成.
    for(int i = 0; i < E; ++i){
        int s, t; long long w;
        scanf("%d %d %lld", &s, &t, &w);
        graph[s].push_back(make_pair(t, w));
    }
    
    // 3. 単一始点最短経路の重み計算.
    bfs();
    
    // 4. 出力.
    for(int i = 0; i < V; ++i){
        if(dist[i] < INF) printf("%lld\n", dist[i]);
        else              printf("%s\n", "INF");
    }
    return 0;

}


Measured memory_bytes: 19476
N = int(input())
A = list(map(int, input().split()))
xor = 0
for a in A:
    xor ^= a
ans = [0]*N
for i in range(31):
    bit = 2**i
    if xor&bit:
        for j in range(N):
            if not A[j]&bit: ans[j] += bit
    else:
        for j in range(N):
            if A[j]&bit: ans[j] += bit
print(*ans)


Measured memory_bytes: 31444
/*  ex9_1
    pptenshi  */

#include<stdio.h>
#include<stdlib.h>
#define SIZE 11

typedef struct stack {
    char elem;
    struct stack *next;
}stack;


void push(stack **first, char elem)  {
    stack *new = calloc(1, sizeof(stack));
    if (new == NULL) exit(1);

    new->elem = elem;
    new->next = *first;
    *first = new;
}


char pop(stack **first) {
    char elem;
    stack *tmp = *first;

    if (tmp == NULL) {
        exit(1);
    }

    elem = tmp->elem;
    *first = tmp->next;
    free(tmp);
    return elem;
}


// 出力
void print_string(stack *first) {
    stack *stack_prt = NULL;
    char elem;

    // stack_ptrに入れなおして出力
    while (first != NULL) {
        elem = pop(&first);
        push(&stack_prt, elem);
    }
    while (stack_prt != NULL) {
        elem = pop(&stack_prt);
        putchar(elem);
    }
    putchar('\n');
}


int main(void) {
    char string[SIZE];      // s
    char *p_str;            // sのポインタ
    stack *first = NULL;    // 文字列を入れるスタック

    // input
    scanf("%s", string);
    p_str = string;

    
    while(*p_str) {
        switch (*p_str)
        {
        case '0': case '1':
            push(&first, *p_str);
            break;
        case 'B':
            if (first != NULL) {
                pop(&first);
            }
            break;
        }
        p_str++;
    }


    // output
    print_string(first);


    return 0;
}

Measured memory_bytes: 1628
h, w = map(int, input().split())
s = ['-' * (w + 2)]
for i in range(h):
    s.append('-' + input() + '-')
s.append('-' * (w + 2))

def search(i, j):
    global s
    count = 0
    for l in range(-1, 2):
        for m in range(-1, 2):
            if s[i+l][j+m] == '#':
                count += 1
    return str(count)

for i in range(h + 2):
    for j in range(w + 2):
        if s[i][j] == '.':
            s[i] = s[i].replace('.', search(i, j), 1)
for i in range(1, h + 1):
    print(s[i][1:-1])


Measured memory_bytes: 3064