akhauriyash/Code-Regression huggingface dataset:
package main

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

/*-----------Main-----------*/

func main() {
	s, w := readI(), readI()

	if w >= s {
		fmt.Println("unsafe")
		return
	}
	fmt.Println("safe")
}

/*-----------Utilities-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if len(os.Args) >= 2 {
		if os.Args[1] == "debug" {
			debug()
		}
	}
	const maxBuf = 200100
	var buf []byte = make([]byte, maxBuf)
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBuf)
}

func debug() {
	testFile, err := os.Open("./test/sample-1.in")
	if err != nil {
		fmt.Fprintln(os.Stderr, "Error : There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

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

func readSs(a int) []string {
	b := make([]string, a)
	for i := 0; i < a; i++ {
		b[i] = readS()
	}
	return b
}

func readI() int {
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())
	return r
}

func readIs(a int) []int {
	b := make([]int, a)
	for i := 0; i < a; i++ {
		b[i] = readI()
	}
	return b
}

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

func readFs(a int) []float64 {
	b := make([]float64, a)
	for i := 0; i < a; i++ {
		b[i] = readF()
	}
	return b
}

func max(a []int) int {
	l := len(a)
	m := a[0]
	for i := 1; i < l; i++ {
		if a[i] > m {
			m = a[i]
		}
	}
	return m
}

func min(a []int) int {
	l := len(a)
	m := a[0]
	for i := 1; i < l; i++ {
		if a[i] < m {
			m = a[i]
		}
	}
	return m
}

func sortI(a []int) []int {
	sort.Ints(a)
	return a
}

func reverse(a []int) []int {
	l := len(a)
	r := make([]int, l)
	for i := 0; i < l; i++ {
		r[i] = a[l-i-1]
	}
	return r
}

func countI(a []int, b int) int {
	l := len(a)
	var c int
	for i := 0; i < l; i++ {
		if a[i] == b {
			c++
		}
	}
	return c
}


Measured memory_bytes: 1784
import heapq
N,M = map(int,input().split())
l = [tuple(map(int,input().split())) for _ in range(N)]
l = sorted(l,reverse=True)
heap = []
ans = 0
for i in range(1,M+1):
        while l and l[-1][0] == i:
            heapq.heappush(heap, (l.pop()[1]*(-1)))
        if heap :
            ans -= (heapq.heappop(heap))
print(ans)


Measured memory_bytes: 73176
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef int Weight;
struct Edge {
  int src, dest;
  Weight weight;
  Edge(int src, int dest, Weight weight): src(src), dest(dest), weight(weight) {;}
  bool operator<(const Edge &rhs) const {
    return weight < rhs.weight;
  }
};

struct UnionFind {
  int parent[100];
  UnionFind() {
    memset(parent, -1, sizeof(parent));
  }

  bool unite(int x, int y) 
  {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (parent[y] < parent[x]) { swap(x, y); }
    parent[x] += parent[y];
    parent[y] = x;
    return true;
  }

  bool find(int x, int y) 
  {
    return root(x) == root(y);
  }

  int root(int x) 
  {
    return parent[x] < 0 ? x : parent[x] = root(parent[x]);
  }
};

int M, N;
vector<Edge> es;
void Solve() 
{
  sort(es.begin(), es.end());
  UnionFind uf;
  int res = 0;
  for (int i = 0; i < M; i++) {
    Edge e = es[i];
    if (!uf.find(e.src, e.dest)) {
      uf.unite(e.src, e.dest);
      res += (int)(e.weight / 100) - 1;
    }
  
  }
  cout << res << endl;
}

int main() 
{
  int u, v, w;
  while (cin >> N && N) {
    cin >> M;
    es.clear();
    for (int i = 0; i < M; i++) {
      scanf("%d,%d,%d", &u, &v, &w);
      es.push_back(Edge(u, v, w));
    }

    Solve();
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
  int N, total = 0, i;
  cin >> N;
  int L[N];
  for (i = 0; i < N; i++)
    cin >> L[i];
  sort(L, L + N);
  for(i = 0; i < N - 1; i++)
    total += L[i];
  if (L[N - 1] < total)
    cout << "Yes";
  else
    cout << "No";
  
  return 0;
}

Measured memory_bytes: 256
n = int(input())
dat_a = map(int, input().split())
dat_a = list(dat_a)
l = [0] * n
r = [0] * n
res = [0] * n
import fractions

l[0] = 0
r[n-1] = 0
for i in range(1, n):
    l[i] = fractions.gcd(l[i-1], dat_a[i-1])

for i in range(n-2, -1, -1):
    r[i] = fractions.gcd(r[i+1], dat_a[i+1])
for i in range(n):
    res[i] = fractions.gcd(l[i], r[i])

print(max(res))


Measured memory_bytes: 85856
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#include<map>
#include<iostream>
#include<cmath>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;


int main(){
   int x , y;
   cin >> x >> y;
   int count = 0;
   bool flag = false;
   while(count < 51){
      if(2*count == 4*x - y){
         flag = true;
         break;
      }
      count++;
   }
   cout << (flag ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3632
n,c = map(int, input().split())
d = []
for _ in range(c):
    a = list(map(int, input().split()))
    d.append(a)

grid = [[0 for j in range(c+1)] for i in range(3)]
for i in range(n):
    for j,cc in enumerate(map(int, input().split())):
        k = j
        grid[(i+j)%3][cc] += 1

ans = float('INF')

for i in range(1,c+1):
    for j in range(1,c+1):
        if i == j:
            continue
        for k in range(1,c+1):
            if i == k or j == k:
                continue
            cost = 0
            for a in range(1,c+1):
                # print(int(d[a-1][i-1]), grid[0][a], int(d[a-1][j-1]), grid[1][a], int(d[a-1][k-1]), grid[2][a])
                cost += d[a-1][i-1] * grid[0][a] + d[a-1][j-1] * grid[1][a] + d[a-1][k-1] * grid[2][a]
            
            if cost < ans:
                # print(i,j,k,cost)
                ans = cost

print(int(ans))


Measured memory_bytes: 45164
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;

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

    long long n, m;
    cin >> n >> m;
    vector<P> A(n);
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        A[i] = {a, -b};
    }

    sort(A.begin(), A.end());

    long long cnt = 0, d = 0;
    for(int i = 0; i < n; i++){
        P p = A[i];
        if(cnt + (-1 * p.second) >= m){
            d += (m - cnt) * p.first;
            break;
        }else{
            cnt += -p.second;
            d += p.first * -p.second;
        }
    }

    cout << d << endl;

    return 0;
}

Measured memory_bytes: 1792
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int main(){
  int X, Y, Z; cin >> X >> Y >> Z;
  swap(X, Y); swap(X, Z);
  cout << X << " " << Y << " " << Z << endl;

  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = sorted(list(map(int, input().split())))
B = list(map(int, input().split()))
C = sorted(list(map(int, input().split())))

def BinaryIndexSearch_floor(p, SL):
	"""
	search the minimum number among the larger numbers than the ginven nymber "n". 
	return the index of it under the list sorted.
	"""
	#SL = sorted(L)
	l = 0
	r = len(SL) - 1

	while True:
		if l == r:
			if SL[l] > p:
				return l
			else:
				return -1
		elif r-l == 1:
			if SL[l] > p:
				return l
			elif SL[r] > p:
				return r
			else:
				return -1

		center = l + ((r-l) // 2)

		if SL[center] <= p:
			l = center + 1
			continue

		else:
			r = center
			continue

def BinaryIndexSearch_ceil(p, SL):
	#SL = sorted(L)
	l = 0
	r = len(SL) - 1

	while True:
		if l == r:
			if SL[l] < p:
				return l
			else:
				return -1
		elif r-l == 1:
			if SL[r] < p:
				return r
			elif SL[l] < p:
				return l
			else:
				return -1
		center = l + ((r-l) // 2)

		if SL[center] < p:
			l = center 
			continue

		else:
			r = center - 1
			continue

min_A = A[0]
max_C = C[-1]
ans = 0
for b in B:
	if not (min_A < b < max_C):
		continue

	a = BinaryIndexSearch_ceil(b,A)
	c = BinaryIndexSearch_floor(b,C)

	ans += (a+1) * (N-c)

print(ans)

Measured memory_bytes: 23348
import sys
from pprint import pprint

def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

  
def mod_inv(a,m):
    if a == 0:
        return 0
    x = extgcd(a,m)[0]
    return (m+x%m)%m


def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

if __name__ == '__main__':
    mod = 10**9 + 7
    n, a, b = map(int, sys.stdin.readline().strip().split(" "))
    # print(n, a, b, mod)

    denominator = 1
    numerator = 1
    for i in range(1, a+1):
        # print(n-i+1, i)
        numerator *= (n-i+1)
        numerator %= mod
        denominator *= i
        denominator %= mod
    # print(numerator, denominator)
    cmb_a = numerator * mod_inv(denominator, mod)
        
    denominator = 1
    numerator = 1
    for i in range(1, b+1):
        # print(n-i+1, i)
        numerator *= (n-i+1)
        numerator %= mod
        denominator *= i
        denominator %= mod
    # print(numerator, denominator)
    cmb_b = numerator * mod_inv(denominator, mod)
        
    # print(pow(2, n, mod) - 1, cmb_a, cmb_b)
    ans = pow(2, n, mod) - 1 - cmb_a - cmb_b
    print(ans % mod)

Measured memory_bytes: 39152
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    N = int(input())
    
    def rec(n, maxchr, ans):
        if n==N:
            print(ans)
        else:
            for i in range(maxchr):
                rec(n+1, maxchr, ans+chr(i+97))
            rec(n+1, maxchr+1, ans+chr(maxchr+97))

    rec(0, 0, '')

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 4412
k = int(input())
a = list(map(int,input().split()))

upper,lower = 2,2

for ai in a[::-1]:
    lower = (1+(lower-1)//ai)*ai
    upper = (1 + upper//ai)*ai -1
    if(upper < lower):
        print(-1)
        exit()
    # print(lower,upper)

print(' '.join(map(str,[lower,upper])))

Measured memory_bytes: 85652
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
using namespace std;
int main() {
	long long l, r;
	int min = 1000000009;
	cin >> l >> r;
	if (min > (l % 2019)* (r % 2019) % 2019) {
		min = (l % 2019) * (r % 2019) % 2019;
	}
	if (r > l + 4038) {
		r = l + 4038;
	}
	for (int i = l; i < r-1; i++) {
		for (int j = i + 1; j <= r; j++) {
			if ((i % 2019) * (j % 2019) % 2019 == 0) {
				cout << "0" << endl;
				return 0;
			}
			if (min > (i % 2019)* (j % 2019) % 2019) {
				min = (i % 2019) * (j % 2019) % 2019;
			}
		}
	}
	cout << min << endl;
	return 0;
}

Measured memory_bytes: 256
//
#include <vector>
#include <set>
#include <array>
#include <iostream>
//
#include <cstdio>
#include <cstdint>
//
using ll = long long;
using namespace std;
//
void yes(bool cond) { cond ? puts("Yes") : puts("No"); }

//
class Init
{
public:
    Init()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    }
}init;

//
int main()
{
    //
    ll w, h, k;
    cin >> h;
    cin >> w;
    cin >> k;
    vector<bool> table;
    for (int32_t i = 0; i < h; ++i)
    {
        for (int32_t j = 0; j < w; ++j)
        {
            char ch;
            cin >> ch;
            table.push_back((ch == '#'));
        }
    }

    const auto checkTable = [&](ll xb, ll yb)
    {
        ll cnt = 0;
        for (int32_t y = 0; y < h; ++y)
        {
            for (int32_t x = 0; x < w; ++x)
            {
                if (((xb >> x) % 2) && ((yb >> y) % 2))
                {
                    cnt += table[x + y * w] ? 1 : 0;
                }
            }
        }
        return cnt == k;
    };

    // 全探索
    ll ybm = (1 << h);
    ll xbm = (1 << w);
    ll okay = 0;
    for (ll yb=0;yb<ybm;++yb)
    {
        for (ll xb = 0; xb < xbm; ++xb)
        {
            if (checkTable(xb, yb))
            {
                ++okay;
            }
        }
    }
    cout << okay;
}

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

int main()
{
    int n,q,b,m,e;
    cin>>n;
    vector<int>a(n);
    REP(i,n)cin>>a[i];
    cin>>q;
    REP(i,q)
    {
        cin>>b>>m>>e;
        auto bb=a.begin(),mm=a.begin(),ee=a.begin();
        bb+=b;mm+=m;ee+=e;
        rotate(bb,mm,ee);
    }
    REP(i,n)
    {
        if(i!=0)cout<<" ";
        cout<<a[i];
    }cout<<endl;
}


Measured memory_bytes: 3152
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		//a, b, hを標準出力
		Scanner sc = new Scanner (System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int h =sc.nextInt();
		sc.close();

			System.out.println((a+b)*h/2);
		
	//1≤a≤100
//		1≤b≤100
//		1≤h≤100
//		入力で与えられる値はすべて整数
//		h は偶数

		
		
	}
	
	
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;


int main() {
//    cout << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    ll n, m;
    cin >> n >> m;
    int maxi = pow(2, n);
    ll cost[m];
    vector<ll> boxes[m];
    for (ll i = 0; i < m; i++) {
        ll b;
        cin >> cost[i] >> b;
        while (b--) {
            ll u;
            cin >> u;
            u--;
            boxes[i].pb(u);
        }
    }

    ll dp[m][(ll) pow(2, n)];
    for (ll i = 0; i < m; i++) {
        for (ll j = 0; j < pow(2, n); j++) {
            dp[i][j] = INT_MAX;
        }
    }

    for (int i = 0; i < m; i++) {
        dp[i][0] = 0;
    }

    for (ll mask = 1; mask < pow(2, n); mask++) {
        bool cs = true;
        for (ll j = 0; j < n; j++) {
            if (mask & (1 << j)) {
                if (find(boxes[0].begin(), boxes[0].end(), j) != boxes[0].end()) {

                }

                else {
                    cs = false;
                    break;
                }
            }
        }

        if (cs) {
            dp[0][mask] = cost[0];
        }

        else {
            dp[0][mask] = INT_MAX;
        }
    }

    for (ll i = 1; i < m; i++) {
        dp[i][0] = 0;
        for (ll mask = 1; mask < pow(2, n); mask++) {
            dp[i][mask] = dp[i - 1][mask];
            ll msk = mask;
            for (ll bits : boxes[i]) {
                if (msk & (1 << bits)) {
                    msk ^= (1 << bits);
                }
            }
            dp[i][mask] = min(dp[i][mask], cost[i] + dp[i - 1][msk]);
        }
    }

//    cout << dp[0][6];

    cout << (dp[m - 1][(ll) pow(2, n) - 1] >= INT_MAX ? -1 : dp[m - 1][(ll) pow(2, n) - 1]);
}

Measured memory_bytes: 32384
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    N, K = i_map()
    D = i_list()

    for i in range(N,10*N+1):
        t = str(i)
        flg = True
        for j in D:
            if str(j) in t:
                flg = False
        if flg == True:
            print(i)
            exit()


if __name__=="__main__":
    main()

    

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

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;

struct int_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

struct pair_hash {
    size_t operator()(pair<int, int> x) const {
        return int_hash{}(x.first) ^ (int_hash{}(x.second) << 16);
    }
};

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
const int MX = 100001; //check the limits, dummy

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll h, n; cin >> h >> n;
    vector<ll> a(n);
    vector<int> b(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        cin >> b[i];
    }

    vector<ll> dp(h + 1, inf + 1);
    dp[0] = 0;
    for(int i = 0; i < n; i++)
        for(int j = 0; j <= h; j++)
            dp[j] = min(dp[j], b[i] + dp[max(0LL, j - a[i])]);

    cout << dp[h] << endl;
}

Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <bitset>
#include <ctime>
#include <queue>
#include <stack>
#include <set>
#include <map>
#define F first
#define S second
#define qq queue
#define dq deque
#define vc vector
#define INF (1e9)
#define in cin >>
#define LINF (1e18)
#define out cout <<
#define ln  << endl
#define pb push_back
#define mp make_pair
#define ll long long
#define _tp template
#define _tyn typename
#define pf push_front
#define itor iterator
#define sint short int
#define ull unsigned ll
#define pq priority_queue
#define pii pair<int,int>
#define uint unsigned int
#define B out "BreakPoint\n";
#define read(_num) scanf("%d",&_num)
#define ms(_data) memset(_data,0,sizeof(_data))
#define fin(_filename) freopen(_filename,"r",stdin)
#define fout(_filename) freopen(_filename,"w",stdout)
#define read2(_num1,_num2) scanf("%d %d",&_num1,&_num2)
#define msn(_data,_num) memset(_data,_num,sizeof(_data))
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define read3(_num1,_num2,_num3) scanf("%d %d %d",&_num1,&_num2,&_num3)
using namespace std;
_tp<_tyn T>void mymax( T &_a , T _b ){ if( _a < _b ) _a = _b; }
_tp<_tyn T>void mymin( T &_a , T _b ){ if( _a > _b ) _a = _b; }
_tp<_tyn T>void print(T _x){for(auto _it=_x.begin();_it!=_x.end();_it++)cout<<*_it<<" ";cout ln;}
void print(int _x){printf("%d ",_x);}
void print(ll _x){printf("%lld ",_x);}

#define MAXN 100100

int n;
ll data[MAXN];

int main(){
	read( n );
	for( int i = 1 ; i <= n ; i++ )
		scanf("%lld",&data[i]);
	
	int canmod2 = 0 , cannotmod = 0 , canmod4 = 0;
	for( int i = 1 ; i <= n ; i++ ){
		if( data[i] % 4 == 0 ) canmod4++;
		else if( data[i] % 2 == 0 ) canmod2++;
		else cannotmod++;
	}
	if( canmod2 ) cannotmod++;
	
	if( cannotmod <= canmod4 + 1 ) printf("Yes\n");
	else printf("No\n");
	
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

void _126() {
    string s;
    cin >> s;
    int first = atoi(s.substr(0, 2).c_str());
    int second = atoi(s.substr(2, 2).c_str());

    if (first > 0 && first <= 12 && second > 0 && second <= 12)
        cout << "AMBIGUOUS" << endl;
    else if (first > 0 && first <= 12)
        cout << "MMYY" << endl;
    else if (second > 0 && second <= 12)
        cout << "YYMM" << endl;
    else
        cout << "NA" << endl;
}

void _127() {
    int r, d, x;
    cin >> r >> d >> x;
    for (int i = 0; i < 10; ++i) {
        x = r * x - d;
        cout << x << endl;
    }
}

void _128() {
    int n;
    cin >> n;

    string  cities[100];
    int score;
    string name;
    vector<pair<pair<string, int>, int> > stores;

    for (int i = 0; i < n; ++i) {
        cin >> name >> score;
        stores.push_back(make_pair(make_pair(name, -score), i + 1));
    }

    sort(stores.begin(), stores.end());

    for (auto itr = stores.begin(); itr != stores.end(); ++itr) {
        cout << itr->second << endl;
    }

    // for (int i = 0; i < n; ++i) {
    //     cout << cities[i] << " " << scores[i] << endl;
    // }

}

void _129() {
    int n;
    int w[100];
    cin >> n;
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> w[i];
        sum += w[i];
    }

    int sum_before, sum_after;
    sum_before = 0;
    sum_after = sum;
    int min_diff = sum;
    for (int i = 0; i < n; ++i) {
        sum_before += w[i];
        sum_after -= w[i];
        min_diff = min(min_diff, abs(sum_after - sum_before));
    }
    cout << min_diff << endl;
}

int main()
{
    _129();
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);

    long a = scan.nextLong();
    long b = scan.nextLong();
    long c = scan.nextLong();
    long k = scan.nextLong();

    if (k <= a) {
      System.out.println(k);
      return;
    } else {
      if (k - a <= b) {
        System.out.println(a);
        return;
      } else {
        System.out.println(2 * a + b - k);
        return;
      }
    }

  }

}

Measured memory_bytes: 35800
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int dp[110][4],a[110];
inline int get_val(int pos,int idx){
	if(idx==0) return a[pos-1];
	if(idx==1) return a[pos];
	if(idx==2) return a[pos+1];
	return -1;
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",a+i);
	memset(dp,0x3f,sizeof dp);
	dp[1][0]=dp[1][2]=dp[1][3]=1;
	dp[1][1]=0;
	for(int i=2;i<=n;i++)
		for(int j=0;j<4;j++)
			for(int k=0;k<4;k++)
				if(get_val(i-1,j)!=get_val(i,k) || get_val(i,k)==-1)
					dp[i][k]=min(dp[i][k],dp[i-1][j]+(k!=1));
	int ans=0x3f3f3f3f;
	for(int i=0;i<4;i++)
		ans=min(ans,dp[n][i]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
N,M,K=map(int,input().split())
P=1000000007
import math
ans=0
for A in [N,M]:
    for i in range(1,A):
        ans = (ans+(N^M^A)**2*i*(i+1)//2)%P
print(ans*math.factorial(N*M-2)*pow(math.factorial(K-2),P-2,P)*pow(math.factorial(N*M-K),P-2,P)%P)


Measured memory_bytes: 101432
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll, ll> lltpl;



/******************************************************************************************/


const ll MOD = 1e9 + 7;



template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


int dp[20][100005];//dp[i][j]:=j番目の頂点から2^i日以内に到達できる最右のホテル

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

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

	int L, Q;
	cin >> L >> Q;
	
	for (int i = 0; i < n; i++)
	{
		dp[0][i] = upper_bound(x.begin(), x.end(), x[i] + L) - x.begin() - 1;
	}


	for (int i = 0; i < 19; i++)
	{
		for (int j = 0; j < n; j++)
		{
			dp[i + 1][j] = dp[i][dp[i][j]];
		}
	}

	for (int i = 0; i < Q; i++)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		if (a > b) {
			swap(a, b);
		}

		int ans = 0;
		for (int i = 19; i >= 0; i--)
		{
			if (dp[i][a] < b) {
				a = dp[i][a];
				ans += 1 << i;
			}
		}
		ans++;
		cout << ans << endl;
	}




	return 0;
}


Measured memory_bytes: 9088
void main()
{
    int[] ab = readln.split.to!(int[]);
    int k = ab[2];
    ab.popBack;

    foreach (i; 0 .. k)
    {
        ab[i%2] /= 2;
        ab[(i+1)%2] += ab[i%2];
    }

    ab.to!(string[]).join(" ").writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

const ll INF = (ll)1e18 + 5;


ll a[2001001];

bool OK(ll i, ll j, ll x){
	return a[i]*a[j] >= x;
}

bool OK2(ll i, ll j, ll x){
	return a[i]*a[j] < x;
}

bool OK3(ll m, ll k, function<ll(ll)> f){
  	return f(m) < k;
}

ll nibutan(ll ltemp, ll rtemp, ll i, ll x, function<bool(ll, ll, ll)> OK){
  	ll l = ltemp, r = rtemp;
  	while(l+1!=r){
  		ll m = (l+r)/2;
      	if(OK(i, m, x)) r = m;
      	else l = m;
    }  	
  	return r;
}

ll nibutan2(ll ltemp, ll rtemp, ll k, function<bool(ll,ll,function<ll(ll)>)> OK3, function<ll(ll)> f){
  	ll l = ltemp, r = rtemp;
  	while(l+1!=r){
  		ll m = (l+r)/2;
      	if(OK3(m,k,f)) r = m;
      	else l = m;
    }  	
  	return l;
}

void Main(){
  	ll n, k;	
	cin >> n >> k;
	rep(i,n) cin >> a[i];
	sort(a, a+n);
	  	  
	auto f = [&](ll x){
		// a[] * a[] のテーブル上で product が x 以上になるペアの個数を数える
		ll res = 0;
      	ll dif;
      	rep(i,n){
			// a[i] >= 0 のときと a[i] < 0 のときで場合分け
			if(a[i]>=0) dif = n - nibutan(-1,n,i,x,OK);
			else if(a[i]<0) dif = nibutan(-1,n,i,x,OK2);            
           	if(OK(i,i,x)) dif--;
			res += dif;
        }
      	return res/2;
	};
		  
  	//*
	// f は単調減少
	// 下から k 番目が欲しい
	// f(x+1) < k, f(x) >= k なら x を出力
	k = n*(n-1)/2 - k + 1;
  
  	ll ans = nibutan2(-INF, INF, k, OK3, f);
	cout << ans << endl;
	
	return;  	
}

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


Measured memory_bytes: 1792
from collections import deque

N = int(input())
Edge = [[]for _ in range(N)]
for i in range(N-1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    Edge[a].append((b, c))
    Edge[b].append((a, c))

Q, K = map(int, input().split())
K -= 1
DP = [-1] * N
DP[K] = 0
A = deque()
A.append((0,K))
while len(A) > 0:
    fatigue, now = A.pop()
    for next, cost in Edge[now]:
        if DP[next] > 0:
            continue
        else:
            DP[next] = fatigue + cost
            A.append((fatigue+cost, next))

for i in range(Q):
    x, y = map(int, input().split())
    print(DP[x-1] + DP[y-1])


Measured memory_bytes: 83360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(a) cout<<#a<<":"<<a<<endl;
const int INF=0x3f3f3f3f;
const int N=1e6+7;
const int mod=1e9+7;
int maxn,minn;
int T,n,m;
vector<int>mp[N];
int du[N];
int dp[N];


int main(){
	queue<int>que;
	int u,v;
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		scanf("%d%d",&u,&v);
		mp[u].push_back(v);
		du[v]++;
	}
	for(int i=1;i<=n;i++){
		if(du[i]==0){
			que.push(i);
		}
	}
	while(!que.empty()){
		int i=que.front();
//		cout<<i<<endl; 
		que.pop();
		for(int j=0;j<mp[i].size();j++){
			du[mp[i][j]]--;
			dp[mp[i][j]]=max(dp[mp[i][j]],dp[i]+1);
			if(du[mp[i][j]]==0){
				que.push(mp[i][j]);
			}
		}
	}
	maxn=0;
	for(int i=1;i<=n;i++){
		maxn=max(dp[i],maxn);
	}
	cout<<maxn<<endl;
	

	return 0;
}





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

int J, Y;

void rec(int j, int y, string s) {
	if (j == J && y == Y) {
		cout << s << endl;
		return;
	}

	if (j == 5 && y == 5) { return; }
	if (j <= 3 && y == 5) { return; }
	if (j == 5 && y <= 3) { return; }

	if (j + 1 <= J) { rec(j + 1, y, s + 'A'); }
	if (y + 1 <= Y) { rec(j, y + 1, s + 'B'); }
}

int main() {
	cin >> J >> Y;

	rec(0, 0, "");
}

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

using namespace std;

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    string s;
    cin >> n >> s;

    if (n < 3200) cout << "red";
    else cout << s;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>

using namespace std;

int main()
{
	string o, e;
	cin >> o >> e;

	for (int i = 0; i < o.size() + e.size(); i++) {
		if (i % 2 == 0) {
			cout << o[i / 2];
		}
		else {
			cout << e[i / 2];
		}
	}
	cout << endl;
	return (0);
}

Measured memory_bytes: 256
#include <stdio.h>
char s[11];
int i;
void insert_01(char);
void back_s(char);

int main()
{
    char ch;
    while ((ch = getchar()) != EOF)
    {
        if (ch == 'B')
            back_s(ch);
        else
            insert_01(ch);
    }
    printf("%s\n", s);
    return 0;
}

void insert_01(char ch)
{
    s[i++] = ch;
}

void back_s(char ch)
{
    if (i == 0)
        return;
    s[i--] = '\0';
}

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

void solve(string S) {
	bool alpha[27] = { };
	for(auto itr = S.begin(); itr != S.end(); itr++) {
		alpha[int(*itr) - int('a')] = true;
	}
	int i;
	for(i = 0; i < 26; i++) {
		if(alpha[i] == false) break;
	}
	if(i == 26) printf("None");
	else printf("%c", 'a' + i);
}

int main() {
	string S;
	cin >> S;
	solve(S);
	return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<list>
#include<set>
#include<numeric>

#define MOD 1000000007

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int H, W, N;
int d[1010][1010];
char field[1010][1010];

int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

int bfs(char s, char g) {
	queue<P> que;
	fill(d[0], d[1010], -1);
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (field[i][j] == s) {
				que.push(P(i, j));
				d[i][j] = 0;
			}
		}
	}

	while (!que.empty()) {
		P p = que.front(); que.pop();
		if (field[p.first][p.second] == g)return d[p.first][p.second];

		for (int i = 0; i < 4; i++) {
			int ny = p.first + dy[i], nx = p.second + dx[i];
			if (0 <= nx && nx < W && 0 <= ny && ny < H && field[ny][nx] != 'X' &&
				d[ny][nx] == -1) {
				que.push(P(ny, nx));
				d[ny][nx] = d[p.first][p.second] + 1;
			}
		}
	}
	return -1;
}
int main()
{
	cin >> H >> W >> N;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> field[i][j];
		}
	}
	int ans = bfs('S','1');
	for (int i = 1; i < N; i++)
		ans += bfs(i + '0', i + 1 + '0');
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8000
# -*- coding: utf-8 -*-

# for文を3つ回すと間に合わない
# a + b + c = s が決まるとき a, b, s が決まれば c が決まる

k, s = map(int, input().split())

cnt = 0

for x in range(k + 1):
    for y in range(k + 1):
        z = s - x - y
        if 0 <= z <= k:
            cnt = cnt + 1

print(cnt)

Measured memory_bytes: 9108
mod=1777777777
n,ma,mb=map(int,input().split())
d=[[mod for j in range(100)] for i in range(100)]
for i in range(n):
    a,b,c=map(int,input().split())
    x=a
    y=b
    for j in range(100-a-1,0,-1):
        for k in range(100-b-1,0,-1):
            if d[j][k]!=mod:
                d[j+a][k+b]=min(d[j+a][k+b],d[j][k]+c)
    d[x][y]=min(d[x][y],c)
ans=mod
for i in range(100):
    if i%ma==0 and mb*i//ma<100:
        ans=min(ans,d[i][mb*i//ma])

print([ans,-1][ans==mod])

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

typedef long long ll;

int main() {
    int N, K;
    ll ans = 1e18;
    cin >> N >> K;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    rep(i, 1 << (N - 1)) {
        int c = 1, h = a[0];
        ll s = 0;
        rep(j, N - 1) {
            if ((i >> j) & 1) {
                if (a[j + 1] > h) {
                    h = a[j + 1];
                    c++;
                }
                continue;
            }
            h = max(h + 1, a[j + 1]);
            s += h - a[j + 1];
            c++;
        }
        if (c < K) continue;
        ans = min(ans, s);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  auto args=readln.split.to!(int[]);

  if((args[2]-args[1])&1){
    writeln("Borys");
  }else{
    writeln("Alice");
  }
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}
void wr(T...)(T x){
  import std.stdio;
  foreach(e; x) write(e, " ");
  writeln();
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


n, a, b = li()

print(b if b < a*n else a*n)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

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

int main() {
  int n, m;
  cin >> n >> m;
  pair<int,int> v[n];
  rep(i,n) {
    int a, b;
    cin >> a >> b;
    v[i] = make_pair(a, b);
  }
  sort(v, v+n);
  
  priority_queue<int> q; 
  int i = 0, s = 0;
  rep(j,m) {
    while(v[i].first == j+1) q.push(v[i].second), i++;
    if(!q.empty()) s += q.top(), q.pop();
  }
  cout << s << endl;
  return 0;
}

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

int main() {
    string s;
    int s1,s2;
    cin >> s;
    s1 = stoi(s.substr(0,2));
    s2 = stoi(s.substr(2,2));
    bool MMYY = ((s1 >= 1 && s1 <= 12) ? true : false);
    bool YYMM = ((s2 >= 1 && s2 <= 12) ? true : false);
    if(MMYY && YYMM){
        cout << "AMBIGUOUS" << endl;
    }else if(!MMYY && YYMM){
        cout << "YYMM" << endl;
    }else if(MMYY && !YYMM){
        cout << "MMYY" << endl;
    }else{
        cout << "NA" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/
 
 


#define NO "NO"
#define YES "YES"
int N, H;
int L[101010], R[101010];
int in[505], ou[505];
int used[505];
//---------------------------------------------------------------------------------------------------
vector<int> E[505];
int vis[505];
void dfs(int cu) {
    vis[cu] = 1;
    fore(to, E[cu]) if(!vis[to]) {
        dfs(to);
    }
}
//---------------------------------------------------------------------------------------------------
string solve() {
    cin >> N >> H;

    // make_edge
    rep(i, 0, N) {
        int a, b, c, d; cin >> a >> b >> c >> d;

        int l;
        if (0 < c) l = -c;
        else l = a;

        int r;
        if (0 < d) r = d;
        else r = -b;

        l += 250, r += 250;

        L[i] = l, R[i] = r;
    }

    // in/out check
    rep(i, 0, N) {
        int l = L[i], r = R[i];
        ou[l]++; in[r]++;
    }
    rep(i, 0, 505) {
        int x = i - 250;
        if (0 < x) if (ou[i] < in[i]) return NO;
        if (x < 0) if (in[i] < ou[i]) return NO;
    }

    // cycle check
    rep(i, 0, N) {
        int l = L[i], r = R[i];
        used[l] = used[r] = 1;
        E[l].push_back(r);
    }

    rep(i, 0, 505) {
        int x = i - 250;
        if (0 < x) if (ou[i] > in[i]) if (!vis[i]) dfs(i);
    }
    rep(i, 0, 505) if (used[i]) if (!vis[i]) return NO;

    return YES;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cout << solve() << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
typedef long long ll;
typedef pair<ll,ll> PP;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false

class segmenttree{
    /*
    Copyright (c) 2020 0214sh7
    https://github.com/0214sh7/library/
    */
    private:
    int n;
    long long identity = -INF;//単位元
    std::vector<long long> dat;
    public:
    
    void init(int N){
        n=1;
        while(n<N)n*=2;
        dat.clear();
        for(int i=0;i<2*n-1;++i){
            dat.push_back(identity);
        }
    }
    
    long long calc();
    
    void update(int k,long long a){
        k+=n-1;
        dat[k]=a;
        while(k>0){
            k=(k-1)/2;
            dat[k]=calc(dat[2*k+1],dat[2*k+2]);
        }
    }
    
    long long query(long long a,long long b){
        a+=n;
        b+=n;
        long long R=0;
        while(a < b){
            if(a % 2 == 1){
                R = calc(R, dat[a - 1]);
                a += 1;
            }
            a /= 2;
            if(b % 2 == 1){
                b -= 1;
                R = calc(R, dat[b - 1]);
            }
            b /= 2;
        }
        return R;
    }
    
    long long calc(long long a,long long b){
        //your monoid here
        return max(a,b);
    }
    
};

signed main(void){
    int N,a;
    vector<int> h,A;
    cin >> N;
    REP(i,N){cin >> a;h.push_back(a);}
    REP(i,N){cin >> a;A.push_back(a);}
    
    segmenttree seg;
    seg.init(N+1);
    seg.update(0,0);
    
    
    int Ans=0;
    REP(i,N){
        int num=seg.query(0,h[i]);
        seg.update(h[i],num+A[i]);
        //cout << h[i] MM num+A[i] << endl;
    }
    
    Ans=seg.query(0,N+1);
    cout << Ans << endl;
    return 0;
}



Measured memory_bytes: 9456
#![allow(unused_imports)]

use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::{i32, i64, i128, u32, u64, u128, f64};
use std::io::{stdout, Write, BufWriter};
use std::mem::{swap};
use proconio::marker::{Isize1, Usize1, Bytes, Chars};

#[proconio::fastout]
fn main() {
    proconio::input!{
        mut n: i64,
    }
    let mut ans = String::new();
    let mut k = 0;
    for i in 0.. {
        if 26i64.pow(i) <= 25*n + 1 && 25*n + 1 < 26i64.pow(i + 1) {
            k = i;
            n -= (26i64.pow(k) - 1) / 25;
            break;
        }
    }
    for i in (0..k).rev() {
        let q = (n / 26i64.pow(i)) as u8;
        ans.push(char::from(q + b'a'));
        n %= 26i64.pow(i);
    }
    println!("{}", ans);
}


Measured memory_bytes: 2200
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		int[] V = new int[N];
		for (int i=0;i<N;i++) {
			V[i] = sc.nextInt();
		}

		int[] C = new int[N];
		for (int i=0;i<N;i++) {
			C[i] = sc.nextInt();
		}

		int MAX=0;
		for (int i=0;i<N;i++) {
			if(V[i]>C[i]) {
				MAX += V[i]-C[i];
			}
		}

		System.out.println(MAX);

	}
}

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

int a,b,c;
int i,n;
scanf("%d",&n);
for(i=0;i<n;i++){
	scanf("%d %d %d",&a,&b,&c);
	if(a*a+b*b==c*c||a*a+c*c==b*b||b*b+c*c==a*a) printf("YES\n");
	else printf("NO\n");
}
	
return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <functional>
#include <queue>
#include <cmath>

using namespace std;

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

int N, M;
int a[100010];

int gcd(int a, int b)
{
	return b == 0 ? a : gcd(b, a % b);
}

int lcm(int a, int b)
{
	return a / gcd(a,b) * b;
}

int f(int a)
{
	int counter = 0;

	while (a % 2 == 0) a /= 2, counter++;

	return counter;
}


signed main()
{
	cin >> N >> M;

	rep(i, N) cin >> a[i], a[i] /= 2;

	int cur = f(a[0]);

	rep(i, N) {
		if (cur != f(a[i])) {
			cout << 0 << endl;
			return 0;
		}
	}

	int A = 1;

	rep(i, N) {
		A = lcm(A, a[i]);
		if (A > M) {
			cout << 0 << endl;
			return 0;
		}
	}

	// A <= M
	int l = 0, r = 500000005;

	while (r - l > 1) {
		int m = (l + r) / 2;

		if (A * (2 * m + 1) <= M) {
			l = m;
		} else {
			r = m;
		}
	}

	cout << l + 1 << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   long long int n,k;
   cin>>n>>k;
   int count=0;
   while(n--){
   	 double a,b;
   	 cin>>a>>b;
   	 a=a*a;
   	 b=b*b;
   	 a=a+b;
   	 double p=sqrt(a);
   	 if(p<=k){
   	 	count++;
	}
   }
   cout<<count<<"\n";
}

Measured memory_bytes: 3856
#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>
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 1 << 21;
using pii = std::pair<int, int>;
#define SORT(v) std::sort(v.begin(), v.end())


int main(void) {
	long long N,M;
	std::cin >> N >> M;
	if (N >= M) {
		std::cout << M/2;
	}
	else {
		if((M / 2 - N) % 2==0) N += (M / 2 - N) / 2;
		else N += (M / 2 - N-1) / 2;
		std::cout << N <<std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 500005
ll arr[N] , bit[N] ,ans[N] ,vis[N];

struct kj {
  ll l,r,id;
};

bool comp(kj & a,kj & b){
   return (a.r < b.r);
}

void update(ll id,ll val,ll n){
  while(id<=n){
    bit[id]+=val;
    id+=(id&-id);
  }
}

ll ask(ll id){
  ll s=0;
  while(id>0){
    s+=bit[id];
    id-=(id &-id);
  }
  return s;
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  ll n,k ,i,j;
  cin>>n>>k;
  for(i=0;i<n;i++)cin>>arr[i];
  kj query[k];

  for(i=0;i<k;i++){
    cin>>query[i].l >> query[i].r;
    query[i].id =i;
  }
  sort(query,query+k,comp);
     
  memset(vis,-1,sizeof(vis));

  ll cnt=0;
  for(i=0;i<n;i++){
    if(vis[arr[i]]!=-1)
     update(vis[arr[i]]+1 ,-1,n);
    
    vis[arr[i]]=i;
    update(i+1,1,n);

    while(cnt<k && query[cnt].r-1==i){
      ans[query[cnt].id] = ask( query[cnt].r) -ask( query[cnt].l-1);
      cnt++;
    }

  }

  for(i=0;i<k;i++)cout<<ans[i]<<"\n";

}   

Measured memory_bytes: 31088
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using static System.Math;
using System.Linq;
using static System.Array;

namespace ConsoleApp2
{
    class Program
    {
    

        static void Main(string[] args)
        {
            //N = long.Parse(Console.ReadLine());
            //var c = Console.ReadLine();
            var ABN = Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray();
            var A = ABN[0];
            var B = ABN[1];
            var N = ABN[2];

            //for (int i = 1; i <= N; i++)
            //{
            //    Console.WriteLine(Floor((A*i/B))-A*Floor(i/B));
            //}
            Console.WriteLine(Floor((A * Min(N,B-1) / B)));
        }



    }

}


Measured memory_bytes: 28148
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    string s;
    cin >> s;
    int len = s.length();
    int ct = 0;
    int cf = 0;

    bool flg = true;
    int lastl = 0;
    int lastr = 0;

    int a[len];
    REP(i, len)
    {
        a[i] = 0;
    }

    for (int i = 0; i < len; i++)
    {
        if (s[i] == 'R')
        {
            lastl = 0;
            lastr = i;

            if (flg)
            {
                ct++;
                flg = false;
            }
            else
            {
                cf++;
                flg = true;
            }
        }
        else if (lastl == 0)
        {
            if (flg)
            {
                a[i] = ct + 1;
                a[i - 1] = cf;
            }
            else
            {
                a[i] = cf + 1;
                a[i - 1] = ct;
            }
            ct = 0;
            cf = 0;
            lastl = 1;
        }
        else
        {
            lastl++;
            if (lastl % 2 == 0)
            {
                a[lastr]++;
            }
            else
            {
                a[lastr + 1]++;
            }
        }
    }
    for (int i = 0; i < len; i++)
    {
        if (i != 0)
        {
            cout << " " << a[i];
        }
        else
        {
            cout << a[i];
        }
    }
    cout << endl;
}

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

const int mN = 105;
int d[mN];
int cnt[mN];

int main() {
    int n, k;
    cin >> n >> k;
    for (int i=1; i<=k; i++) {
        cin >> d[i];
        for (int j=1,a; j<=d[i]; j++) 
            cin >> a, cnt[a]++;
    }
    int ans = 0;
    for (int i=1; i<=n; i++) ans += (cnt[i] == 0);
    cout << ans;
    return 0;
}


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

class union_find{
public:
    union_find(int N){
        parent = vector<int>(N);
        for(int i = 0; i < N; i++){
            parent[i] = i;
        }
        rank = vector<int>(N, 0);
    }

    int root(int x){
        if(parent[x] == x) return x;
        else return parent[x] = root(parent[x]);
    }

    void unite(int x, int y);
    bool same(int x, int y){
        return root(x) == root(y);
    }
private:
    vector<int> parent;
    vector<int> rank;
};

void union_find::unite(int x, int y){
    x = root(x);
    y = root(y);
    if(rank[x] < rank[y]){
        parent[x] = y;
    }else{
        parent[y] = x;
        if(rank[x] == rank[y]) rank[x]++;
    }
}

int main(){
    int n, m, k;
    cin >> n >> m >> k;
    union_find data(n+1);
    vector<int> ans(n+1, 0);
    vector<int> friendsnum(n+1, 0);
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        data.unite(a, b);
        friendsnum[a]++;
        friendsnum[b]++;
    }
    for(int i = 1; i <= n; i++){
        ans[data.root(i)]++;
    }
    for(int i = 1; i <= n; i++){
        ans[i] = ans[data.root(i)];
    }
    for(int i = 1; i <= n; i++){
        ans[i] -= friendsnum[i]+1;
    }
    for(int i = 0; i < k; i++){
        int a, b;
        cin >> a >> b;
        if(data.root(a) == data.root(b)){
            ans[a]--;
            ans[b]--;
        }
    }

    for(int i = 1; i <= n; i++){
        cout << ans[i];
        if(i == n) cout << endl;
        else cout << " ";
    }
    return 0;
}

Measured memory_bytes: 2432