akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
typedef unsigned long long int ull;

using namespace std;

int main(){
   ull N, A, B;
   cin >> N >> A >> B;
   ull c1 = N / (A + B);
   ull c2 = N % (A + B);
   // cout << c1 << " " << c2 << endl;

   if(A==0){
      cout << 0 << endl;
   }
   else if(A >= N){
      cout << N << endl;
   }
   else{
      cout << ull(c1*A+min(c2, A)) << endl;
   }


   return 0;
}


Measured memory_bytes: 256
def main():
    n, sum = list(map(int,input().split()))
    x_max = sum // 10000
    for x in reversed(range(0, x_max + 1)):
        y_max = (sum - x * 10000) // 5000
        for y in reversed(range(0, min(n - x + 1, y_max + 1))):
            z = n - x - y
            if 10000 * x + 5000 * y + 1000 * z == sum:
                    print(x, y, z)
                    return 0
    print('-1 -1 -1')
    return 0

main()

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

#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)


int main(void){
  int x;
  cin>>x;

  if(x==7 ||x==5 || x==3)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;



return 0;}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  int x,n; cin >> x >> n;
  int m[110],val,dist= 1000,idx = 0;
  for (int i=0; i<=102; i++) m[i] = 0;
  for (int i=0; i<n; i++) {
    cin >> val;
    m[val]++;
  }
  for (int i=0; i<=103; i++) {
    if ( !m[i] && abs(x-i) < dist) {
      dist = abs(x-i);
      idx = i;
    }
  }
  cout << idx << endl;
}

Measured memory_bytes: 3196
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuffer sb = new StringBuffer();
		
		int count = Integer.parseInt(br.readLine());
		int[][][] list = new int[4][3][10];
		
		for (int i = 0; i < count; i++) {
			String[] str = br.readLine().split(" ");
			int num01 = Integer.parseInt(str[0]) - 1;
			int num02 = Integer.parseInt(str[1]) - 1;
			int num03 = Integer.parseInt(str[2]) - 1;
			int human = Integer.parseInt(str[3]);
			list[num01][num02][num03] += human;
		}
		
		for (int i = 0; i < list.length; i++) {
			if (!(i == 0)) {
				sb.append("####################");
				sb.append('\n');
			}
			for (int j = 0; j < list[i].length; j++) {
				for (int k = 0; k < list[i][j].length; k++) {
					sb.append(" " + list[i][j][k]);
					if(k == 9){
						sb.append('\n');
					}
					if (k == list[i][j].length - 1) {
						sb.append("");
					}
				}
			}
		}
		System.out.print(sb.toString());
	}
}

Measured memory_bytes: 24636
from sys import stdin
import sys

# A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
N, M = [int(x) for x in stdin.readline().rstrip().split()]
# U = input().split()
# A, B = [str(x) for x in stdin.readline().rstrip().split()]

A = list(map(int, input().split()))
if N-sum(A) >= 0:
    print(N-sum(A))
else:
    print("-1")


Measured memory_bytes: 10052
import numpy as np

N, K, Q = map(int, input().split())
A_list = np.array([0] * N)
i = 0
while i < Q:
  A_list[int(input()) - 1] += 1
  i += 1

N_list = np.array([K] * N)
N_list = N_list + A_list - Q

for N in N_list:
  if N <= 0:
    print("No")
  else:
    print("Yes")
    

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

int main(void) {
	int num, b, i, ans = 0;
	long long sum = 0;
	cin >> num;
	vector<int> c(num);
	for (i = 0; i < num; i++)
		scanf("%d", &c[i]);
	for (i = 0; i < num; i++){
		scanf("%d", &b);
		c[i] -= b;
	}
	sort(c.begin(), c.end());
	i = 0;
	while (i < num && c[i] < 0) {
		sum += c[i++];
		ans++;
	}
	for (i = num - 1; c[i] > 0; i--) {
		if (sum >= 0)
			break;
		sum += c[i];
		ans++;
	}
	if (sum < 0)
		printf("-1\n");
	else
		printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<cmath>
#include<stdio.h>
using namespace std;

double ans=0.0,x[1000],y[1000];
int id;
char ch;

double S3(double ,double,double,double,double,double);
double f(double,double,double,double);
int main(){
  id=0;
  while(cin>>x[id]>>ch>>y[id]){
    if(id>=2){
      ans+=S3(x[0],y[0],x[id-1],y[id-1],x[id],y[id]);
    }
    id++;   
  }
  //  cout<<ans<<endl;
  printf("%.6f\n",ans);
  return 0;
  
}


double S3(double x1,double y1,double x2,double y2,double x3,double y3){
  double a=f(x1,y1,x2,y2),b=f(x2,y2,x3,y3),c=f(x3,y3,x1,y1);
  double z=(a+b+c)/2.0;
  return sqrt(z*(z-a)*(z-b)*(z-c));
}


double f(double x1,double y1,double x2,double y2){
  return sqrt(pow(x1-x2,2.0)+pow(y1-y2,2.0));

}

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


using namespace std;

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


int main() {
	int n, k;
	cin >> n >> k;
	vector<ll> imos(n + 1);
	imos[0] = 0;


	for (int i = 0; i < n; i++) {
		ll a;
		cin >> a; 
		imos[i + 1] = imos[i] + a;
		//cout << i + 1 << " " << imos[i + 1] << endl;
	}
	ll max_v = 0;

	for (int i = 0; i + k < n + 1; i++) {
		max_v = max(imos[i + k] - imos[i], max_v);
		//cout << i << " max_v" <<  max_v << endl;
	}
	//cout << max_v << endl;
	double ans = ((double) max_v  + (double) k) / 2.0 ;
	cout << fixed << setprecision(8) << ans <<  endl;
	
	return 0;
}

Measured memory_bytes: 1792
import java.io.IOException;
import java.math.BigInteger;
import java.util.Scanner;

/**
 * Created on 2017/09/30 21:17.
 */
public class Main {
    /**
     * p/qの分数を通分して返します。
     *
     * @param p 分子
     * @param q 分母
     * @return long[]{分子, 分母}
     */
    static long[] reduce(long p, long q) {
        BigInteger[] res = reduce(new BigInteger(Long.toString(p)), new BigInteger(Long.toString(q)));
        return new long[]{res[0].longValue(), res[1].longValue()};
    }

    /**
     * p/qの分数を通分して返します。
     *
     * @param p 分子
     * @param q 分母
     * @return BigInteger[]{分子, 分母}
     */
    static BigInteger[] reduce(BigInteger p, BigInteger q) {
        BigInteger gcd = p.gcd(q);
        p = p.divide(gcd);
        q = q.divide(gcd);
        return new BigInteger[]{p, q};
    }

    public static void main(String[] args) throws IOException {
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Scanner sc = new Scanner(System.in);

        while (sc.hasNextLong()) {
            long N = sc.nextLong();
            long hAns = -1;
            long nAns = -1;
            long wAns = -1;

            for (long h = 1; hAns == -1 && h <= 3500; h++) {
                for (long n = h; n <= 3500; n++) {
                    long p = 4 * h * n - N * n - N * h;
                    if (p <= 0) {
                        continue;
                    }

                    long q = N * h * n;
                    long[] r = reduce(p, q);
                    if (r[0] == 1) {
                        hAns = h;
                        nAns = n;
                        wAns = r[1];
                        break;
                    }
                }
            }

            System.out.println(hAns + " " + nAns + " " + wAns);
        }
    }
}

Measured memory_bytes: 23764
import itertools

N, M = map(int, input().split())
Lines = [set(map(int, input().split())) for _ in range(M)]

count = 0
for p in itertools.permutations(range(1, N+1)):
    if p[0] != 1:
        continue

    flag = True
    for i in range(N - 1):
        if not {p[i], p[i+1]} in Lines:
            flag = False
            break

    if flag:
        count += 1

print(count)

Measured memory_bytes: 3064
//Author : Vivek Dubey
#include <bits/stdc++.h>
using namespace std;

// debug start
	template <typename A, typename B>
	string to_string(pair<A, B> p);
	 
	template <typename A, typename B, typename C>
	string to_string(tuple<A, B, C> p);
	 
	template <typename A, typename B, typename C, typename D>
	string to_string(tuple<A, B, C, D> p);
	 
	string to_string(const string& s) {
	  return '"' + s + '"';
	}
	 
	string to_string(const char* s) {
	  return to_string((string) s);
	}
	 
	string to_string(bool b) {
	  return (b ? "true" : "false");
	}
	 
	string to_string(vector<bool> v) {
	  bool first = true;
	  string res = "{";
	  for (int i = 0; i < static_cast<int>(v.size()); i++) {
	    if (!first) {
	      res += ", ";
	    }
	    first = false;
	    res += to_string(v[i]);
	  }
	  res += "}";
	  return res;
	}
	 
	template <size_t N>
	string to_string(bitset<N> v) {
	  string res = "";
	  for (size_t i = 0; i < N; i++) {
	    res += static_cast<char>('0' + v[i]);
	  }
	  return res;
	}
	 
	template <typename A>
	string to_string(A v) {
	  bool first = true;
	  string res = "{";
	  for (const auto &x : v) {
	    if (!first) {
	      res += ", ";
	    }
	    first = false;
	    res += to_string(x);
	  }
	  res += "}";
	  return res;
	}
	 
	template <typename A, typename B>
	string to_string(pair<A, B> p) {
	  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
	}
	 
	template <typename A, typename B, typename C>
	string to_string(tuple<A, B, C> p) {
	  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
	}
	 
	template <typename A, typename B, typename C, typename D>
	string to_string(tuple<A, B, C, D> p) {
	  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
	}
	 
	void debug_out() { cerr << endl; }
	 
	template <typename Head, typename... Tail>
	void debug_out(Head H, Tail... T) {
	  cerr << " " << to_string(H);
	  debug_out(T...);
	}
	 
	#ifndef ONLINE_JUDGE
	#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
	#else
	#define debug(...) 42
	#endif
// end debug

	#define int long long

const int mxN = 3e5 + 1;

int n, k;
int a[mxN];

void solve() {
	cin >> n;
	vector<int> x(n), y(n);
	int res = 0;
	for(int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
	}
	for(int p:{1, -1}) {
		for(int q:{1, -1}) {
			int smallest = p * x[0] + q * y[0];
			for(int i = 1; i < n; i++) {
				int curr = p * x[i] + q * y[i];
				res = max(res, curr - smallest);
				smallest = min(smallest, curr);
			}
		}
	}
	cout << res;
}

int32_t main() {
	#ifndef ONLINE_JUDGE
	    // for getting input from input.txt
		freopen("input.txt", "r", stdin);
	    // for writing output to output.txt
	    //this can be opted out if you want to print the output to the sublime console
		freopen("output.txt", "w", stdout);
	#endif

	// for fast i/o
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL); 
	cout.tie(NULL);

	// test cases
	int t = 1;
	// cin >> t;
	while(t--) {
		solve();
	}

	return 0;
}

Measured memory_bytes: 6360
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    public static void Main()
    {
        int A = NextInt();
        string s = NextString();
        Console.WriteLine((s.Count(v => v == 'R') > s.Count(v => v == 'B') ?"Yes":"No"));

    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


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

void swap(int& x, int& y){
	int tmp = x;
	x=y;
	y=tmp;
}

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if(a>b) swap(a,b);
	if(b>c) swap(b,c);
	if(a>b) swap(a,b);

	cout << a << " " << b << " "  << c << endl;
}


Measured memory_bytes: 3116
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF ((1<<25)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()


int N;
int X[200000];
int Y[200000];
char U[200000];


int dir(char c) {
	return c == 'U' ? 0 : c == 'R' ? 1 : c == 'D' ? 2 : 3;
}

int near(int v, const set<int> &s) {
	int ret = INF;
	auto it = s.lower_bound(v);
	if (it != s.end()) {
		ret = min(ret, *it - v);
	}

	return ret;
}


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


	int ans = INF;

	cin >> N;
	rep(i, N)cin >> X[i] >> Y[i] >> U[i];


	{
		unordered_map<int, array<set<int>, 4>> d;
		rep(i, N) {
			int a = X[i];
			d[a][dir(U[i])].insert(Y[i]);
		}
		// U, D
		for (const auto& p : d) {
			const auto& layer = p.second;
			for (int y : layer[dir('U')]) {

				ans = min(ans, near(y, layer[dir('D')]) * 5);
 			}
		}
	}
	{
		unordered_map<int, array<set<int>, 4>> d;
		rep(i, N) {
			int a = Y[i];
			d[a][dir(U[i])].insert(X[i]);
		}
		// L, R
		for (const auto& p : d) {
			const auto& layer = p.second;
			for (int y : layer[dir('R')]) {
				ans = min(ans, near(y, layer[dir('L')]) * 5);
			}
		}
	}


	{
		unordered_map<int, array<set<int>, 4>> d;
		rep(i, N) {
			int a = X[i] + Y[i];
			d[a][dir(U[i])].insert(Y[i]);
		}

		// R, U
		for (const auto& p : d) {
			const auto& layer = p.second;
			for (int y : layer[dir('U')]) {
				ans = min(ans, near(y, layer[dir('R')]) * 10);
			}
		}
		// D, L
		for (const auto& p : d) {
			const auto& layer = p.second;
			for (int y : layer[dir('L')]) {
				ans = min(ans, near(y, layer[dir('D')]) * 10);
			}
		}
	}
	

	{
		unordered_map<int, array<set<int>, 4>> d;
		rep(i, N) {
			int a = X[i] - Y[i] + 200000;
			d[a][dir(U[i])].insert(Y[i]);
		}

		// L, U
		for (const auto& p : d) {
			const auto& layer = p.second;
			for (int y : layer[dir('U')]) {
				ans = min(ans, near(y, layer[dir('L')]) * 10);
			}
		}
		// D, R
		for (const auto& p : d) {
			const auto& layer = p.second;
			for (int y : layer[dir('R')]) {
				ans = min(ans, near(y, layer[dir('D')]) * 10);
			}
		}
	}

	if (ans == INF)cout << "SAFE" << endl;
	else cout << ans << endl;

	return 0;
}


Measured memory_bytes: 59928
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Iterator;

public class Main
{

  public static void main
  (
    String[] args
  )
  {
    BufferedReader in_stream;
    String         in_str;
    String[]       in_str_split;

    int        in_H;
    int        in_W;
    String[][] in_a;

    int     cnt_h;
    int     cnt_w;
    boolean not_skip_h[];
    boolean not_skip_w[];
    int     ans;

    try
    {
      in_stream = new BufferedReader(new InputStreamReader(System.in));

      /*----------------
       * 引数
       *----------------*/
      in_str       = new String(in_stream.readLine());
      in_str_split = in_str.split(" ");
      in_H         = Integer.parseInt(in_str_split[0]);
      in_W         = Integer.parseInt(in_str_split[1]);


      in_a       = new String[in_H][in_W];
      not_skip_h = new boolean[in_H]; /* init value = false(スキップあり) */
      not_skip_w = new boolean[in_W]; /* init value = false(スキップあり) */

      for(cnt_h=0; cnt_h<in_H; cnt_h++)
      {
        in_str = new String(in_stream.readLine());
        for(cnt_w=0; cnt_w<in_W; cnt_w++)
        {
          in_a[cnt_h][cnt_w] = in_str.substring(cnt_w, cnt_w+1);

          if("#".equals(in_a[cnt_h][cnt_w]))
          {
            not_skip_h[cnt_h] = true; /* スキップなしに設定 */
            not_skip_w[cnt_w] = true; /* スキップなしに設定 */
          }
        }
      }

      /*----------------
       * 出力
       *----------------*/
      for(cnt_h=0; cnt_h<in_H; cnt_h++)
      {
        if(not_skip_h[cnt_h])
        {
          for(cnt_w=0; cnt_w<in_W; cnt_w++)
          {
            if(not_skip_w[cnt_w])
            {
              System.out.print(in_a[cnt_h][cnt_w]);
            }
          }
          System.out.print("\n");
        }
      }

    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
  }
}


Measured memory_bytes: 24148
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        HashMap<Integer, Integer> mapping = new HashMap<>();
        mapping.put(1,1);
        mapping.put(3,1);
        mapping.put(5,1);
        mapping.put(7,1);
        mapping.put(8,1);
        mapping.put(10,1);
        mapping.put(12,1);
        mapping.put(4,2);
        mapping.put(6,2);
        mapping.put(9,2);
        mapping.put(11,2);
        mapping.put(2,3);
        int x = scan.nextInt();
        int y = scan.nextInt();
        boolean answer = mapping.get(x) == mapping.get(y);
        System.out.println(answer ? "Yes" : "No");
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT false

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<class T> void DEBUG(string str, T e){if(DEBUG_OUT == false)return;std::cout <<str << ">>" << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == 1)return;for(const auto& v : vv){ DEBUG(v); } }
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T> void SORT_(vector<int>& v,bool GREATER = 0){if(GREATER == 0)sort(v.begin(),v.end());else{sort(v.begin(),v.end(),std::greater<T>());}}


void solve(void)
{
  int N;
  cin>>N;
  int MIN_A = 0;
  int MIN_X;
  for (int i = 0; i < N; i++)
  {
    int A,B;
    cin>>A>>B;
    if(chmax(MIN_A,A)) MIN_X = B;
  }

  cout<<MIN_A + MIN_X<<endl;
  
  
  
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}

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

using namespace std;

double sq(double a)
{
  return a*a;
}

int N, M;
double L[22], a[22], b[22];

double dfs(vector<int>& idx, int n)
{
  if(idx.size() == M){
    double ret = 0.0;
    for(int i = 0; i < idx.size(); i++){
      for(int j = i+1; j < idx.size(); j++){
	ret += sq(L[idx[i]]-L[idx[j]]) + sq(a[idx[i]]-a[idx[j]]) + sq(b[idx[i]]-b[idx[j]]);
      }
    }
    return ret;
  }
  if(n >= N) return 0.0;
  double res = 0.0;
  vector<int> tmp1 = idx;
  vector<int> tmp2 = idx;
  tmp1.push_back(n);
  res = max(dfs(tmp1, n+1), dfs(tmp2, n+1));
  return res;
}

int main()
{
  cin >> N >> M;
  for(int i = 0; i < N; i++) cin >> L[i] >> a[i] >> b[i];
  vector<int> idx;
  printf("%.10f\n", dfs(idx, 0));
  return 0;
}

Measured memory_bytes: 1276
N = int(input())
one = two = 0
A = []
for i in range(N):
    a = int(input())
    if a >= one:
        one,two = a,one
    elif a >= two:
        two = a
    A.append(a)

for i in range(N):
    if A[i] == one:
        print(two)
    else:
        print(one)


Measured memory_bytes: 12568
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, 0, n) {
        cin >> a[i];
    }
    sort(a.rbegin(), a.rend());
    int Al = 0, Bo = 0;
    rep(i, 0, n) {
        if (i % 2 == 0) {
            Al += a[i];
        } else {
            Bo += a[i];
        }
    }
    cout << Al - Bo << endl;
}

Measured memory_bytes: 256
import sys
li=[0]*101
sc=[False]*31
ra=[0]*31
while True:
    (n,s)=map(int,raw_input().split(","))
    if (n,s)==(0,0):break
    sc[s]=True
    li[n]=s
r=1
for i in xrange(30,-1,-1):
    if sc[i]:
        ra[i]=r
        r+=1
for line in sys.stdin.readlines():
    print ra[li[int(line.strip())]]

Measured memory_bytes: 6560
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    map <char,int>  l, r ; 
    int n; cin >> n; 
    string s; cin >> s;
    for (int i=0;i<n;i++) r[s[i]]++;
    int ans=0;
    for (int i=0;i<n-1;i++){
        r[s[i]]--; l[s[i]]++;
        int cnt=0;
        for (char c='a';c<='z';c++){
            if (l[c] and r[c]) cnt++;
        }
        ans=max(ans,cnt);
    }
    cout << ans << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3624
import sys
import re
import math
import collections
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===

def disLR(a, idx):
    small = a[max(0, idx - 1)]
    large = a[min(len(a) - 1, idx)]
    return small, large


def main():
    a, b, q = ns()
    s = [ni() for _ in range(a)]
    t = [ni() for _ in range(b)]

    for _ in range(q):
        ans = INF

        x = ni()
        tmpans = [0] * 4

        idxs = bisect.bisect_left(s, x)
        sml, lrg = disLR(s, idxs)
        tmpans[0] += abs(x - sml)
        tmpans[1] += abs(x - lrg)
        idxsml = bisect.bisect_left(t, sml)
        tmpans[0] += min([abs(sml - i) for i in disLR(t, idxsml)])
        idxlrg = bisect.bisect_left(t, lrg)
        tmpans[1] += min([abs(lrg - i) for i in disLR(t, idxlrg)])

        idxt = bisect.bisect_left(t, x)
        sml, lrg = disLR(t, idxt)
        tmpans[2] += abs(x - sml)
        tmpans[3] += abs(x - lrg)
        idxsml = bisect.bisect_left(s, sml)
        tmpans[2] += min([abs(sml - i) for i in disLR(s, idxsml)])
        idxlrg = bisect.bisect_left(s, lrg)
        tmpans[3] += min([abs(lrg - i) for i in disLR(s, idxlrg)])
        ans = min(ans, min(tmpans))
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 93204
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N;
  cin>>N;
  
  if(N<2){
    cout<<1<<endl;
  }
  else if(N<4){
    cout<<2<<endl;
  }
  else if(N<8){
    cout<<4<<endl;
  }
  else if(N<16){
    cout<<8<<endl;
  }
  else if(N<32){
    cout<<16<<endl;
  }
  else if(N<64){
    cout<<32<<endl;
  }
  else{
    cout<<64<<endl;
  }
}

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

int main() {
    while (true) {
        int n, arr[1010];
        cin >> n;
        if (n == 0) { break; }
        int ret = 1 << 30;
        for (int j = 0; j < n; ++j) {
            cin >> arr[j];
        }
        sort(arr, arr+n);
        for (int j = 0; j < n-1; ++j) {
            ret = min(ret, arr[j+1]-arr[j]);
        }
        cout << ret << endl;
    }
    return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
using namespace std;

#define LL long long
int n, num;
int cnt1, cnt4, cnt2;

int main() {
    #ifdef LOCAL
    freopen("test.txt", "r", stdin);
    #endif // LOCAL

    while(scanf("%d", &n) != EOF) {
        cnt1 = cnt4 = cnt2 = 0;
        for(int i = 0; i < n; ++i) {
            scanf("%d", &num);
            if(num % 4 == 0) {
                ++cnt4;
            } else if(num % 2 == 0) {
                ++cnt2;
            } else {
                ++cnt1;
            }
        }
        if(cnt4 >= cnt1) {
            printf("Yes\n");
        } else if(cnt1 - cnt4 == 1 && cnt2 == 0) {
            printf("Yes\n");
        } else {
            printf("No\n");
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <utility>

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

int main() {
	int N, M;
	for(;;) {
		scanf("%d%d", &N, &M);
		if(N==0 && M==0) return 0;
		vector<vector<pair<int, int> > > h(M);
		int r;
		scanf("%d", &r);
		rep(i, r) {
			int t, n, m, s;
			scanf("%d%d%d%d", &t, &n, &m, &s);
			h[m-1].push_back(make_pair(t, s));
		}
		int q;
		scanf("%d", &q);
		rep(i, q) {
			int t1, t2, m;
			scanf("%d%d%d", &t1, &t2, &m);
			int l=0;
			int ts=-1;
			int t=0;
			rep(j, h[m-1].size()) {
				if(h[m-1][j].first>t2) {
					if(l) t += t2-ts;
					break;
				}
				if(h[m-1][j].second) {
					if(l==0) ts=max(t1, h[m-1][j].first);
					l++;
				}
				else {
					l--;
					if(l==0) {
						if(h[m-1][j].first>ts) t += h[m-1][j].first-ts;
					}
				}
			}
			printf("%d\n", t);
		}
	}
}

Measured memory_bytes: 0
#include<stdio.h>
#include<limits.h>
int main(){
    int N,i,j,Min=INT_MAX,Max=INT_MIN;
	scanf("%d",&N);
	int A[N];
	for(i=0;i<N;i++){
		scanf("%d",&A[i]);
	}
	/*Max check*/
	for(i=0;i<N;i++){
			if(Max<A[i]-Min)Max=A[i]-Min;
			if(Min>A[i])Min=A[i];
	}
	printf("%d\n",Max);
    return 0;
}


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

signed main() {
    int s, p, q;
    int i, j;

    while (cin >> p >> q >> s) {
        int ans = 0;
        if (!s) break;

        //zeinuki de rekkyo.
        for (i = 1; i < s; i++) {
            for (j = 1; j < s; j++) {
                if (i*(100+p)/100 + j*(100+p)/100 != s) {
                    continue;
                }
                ans = max(ans, i*(100+q)/100 + j*(100+q)/100);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	c := next()
	fmt.Println(string(c[0]+1))
}

Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>

using namespace std;

#define rep(i,n) for(int i=0;i<int(n);i++)
#define reps(i,n) for(int i=1;i<=int(n);i++)
#define sint(i) scanf("%d",&i);
#define sintt(i,j) scanf("%d%d",&i,&j);
#define sinttt(i,j,k) scanf("%d%d%d",&i,&j,&k);
#define sintttt(i,j,k,m) scanf("%d%d%d%d",&i,&j,&k,&m);

#define INF 1010000000
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


char sosu[1000001];
char can[1000001];

int main(){
	rep(i,1000001){
		sosu[i]=0;
	}
	
	sosu[0]=1;
	sosu[1]=1;
	
	rep(i,1000001){
		if(sosu[i]==1)continue;
		for(int j=i+i;j<1000001;j+=i){
			sosu[j]=1;
		}
	}
	
	while(1){
		int n,m;
		sintt(n,m);
		if(n==0)break;
		
		rep(i,1000001){
			can[i]=0;
		}
		
		int sina[31];
		rep(i,n){
			sint(sina[i]);
		}
		
		can[0]=1;
		reps(i,m){
			rep(j,n){
				if(i-sina[j]<0){
					continue;
				}
				if(can[i-sina[j]]==1){
					can[i]=1;
				}
			}
		}
		
		int ans=-1;
		for(int i=m;i>=0;i--){
			if(!sosu[i]&can[i]==1){
				ans=i;
				break;
			}
		}
		
		if(ans==-1){
			puts("NA");
		}else{
			printf("%d\n",ans);
		}
	}
}

Measured memory_bytes: 2832
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;

signed main(){
    ll n,m;
    cin>>n>>m;
    if(n==m) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;

template<int MOD>
struct ModInt {
    using M = ModInt;
    long long val;
    ModInt(long long v = 0) {
        set_val(v % MOD + MOD);
    }
    M& set_val(unsigned int v) {
        val = v<MOD ? v : v - MOD;
        return *this;
    }
    explicit operator bool() const {return val != 0;}
    M operator-() const {return M() - *this;}
    M operator+(const M& r) const {return M().set_val(val + r.val);}
    M operator-(const M& r) const {return M().set_val(val + MOD - r.val);}
    M operator*(const M& r) const {return M().set_val(val * r.val % MOD);}
    M operator/(const M& r) const {return *this * r.inverse();}
    M& operator+=(const M& r) {return *this = *this + r;}
    M& operator-=(const M& r) {return *this = *this - r;}
    M& operator*=(const M& r) {return *this = *this * r;}
    M& operator/=(const M& r) {return *this = *this / r;}
    bool operator==(const M& r) const {return val == r.val;}
    M pow(long long n) const {
        M x = *this, r = 1;
        while(n>0) {
            if(n & 1) r *= x;
            x *= x;
            n >> 1;
        }
        return r;
    }
    M inverse() const {
        int a = val, b = MOD, u = 1, v = 0, t;
        while(b>0) {
            t = a/b;
            swap(a-=t*b, b);
            swap(u-=t*v, v);
        }
        return ModInt(u);
    }
    friend istream& operator<<(istream& i, const M& r) {
        long long tmp; i >> tmp;
        r = M(i);
        return i;
    }
    friend ostream& operator<<(ostream& os, const M& r) {
        return os << r.val;
    }
};

template<typename M>
struct BinomialCoefficients {
    vector<M> fact, finv, inv;
    BinomialCoefficients() {};
    BinomialCoefficients(int n) : fact(n+1,1), finv(n+1,1), inv(n+1,1) {
        init(n);
    }
    void init(int n) {
        fact[0] = finv[n] = inv[0] = 1;
        for(int i = 1; i <= n; ++i) fact[i] = fact[i-1] * i;
        finv[n] /= fact[n];
        for(int i = n-1; i >= 0; --i) finv[i] = finv[i+1] * (i+1);
        for(int i = 1; i<= n; ++i) inv[i] = finv[i]*fact[i-1];
    }
    M C(int n, int k) {
        if(n<k || k<0) return 0;
        return fact[n]*finv[n-k]*finv[k];
    }
    M P(int n, int k) {
        if(n<k || k<0) return 0;
        return fact[n]*finv[n-k];
    }
    M H(int n, int k) {
        if(n<0 || k<0) return 0;
        return k == 0 ? 1 : C(n+k-1,k);
    }
};

template<typename T>
map<T, T> primeFactor(T n) {
    map<T,T> res;
    for(T i = 2; i*i<=n; ++i) {
        while(n%i==0) {
            res[i] ++;
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m; cin >> n >> m;
    using mint = ModInt<MOD>;
    BinomialCoefficients<mint> bc(n+100);
    mint ans = 1;
    for(auto x : primeFactor(m)) {
        ans *= bc.C(x.second+n-1, n-1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
int main(void){
  int x,y,i,j;
  
  scanf("%d %d",&x,&y);
  
  
  if(x<y){
    j = x;
    x = y;
    y = j;
  }
  
  
  i = x%y;
  while(i!=0){
    x = y;
    y = i;
    i = x%y;
  }
  printf("%d\n",y);
  return 0;
}



Measured memory_bytes: 2048
<?php

[$n, $m, $x] = explode(' ', trim(fgets(STDIN)));

$bookPrices = [];	// 本の価格[本]
$usLevels = [];		// 理解度[アルゴリズム][本]

for($i = 0; $i < $n; $i++)
{
  $t = explode(' ', trim(fgets(STDIN)));
  $bookPrices[] = $t[0];
  for($j = 0; $j < $m; $j++)
  {
    $usLevels[$j][] = $t[$j + 1];
  }
}

$lowestPrice = INF;
$MAX = 1 << $n;
for($i = 0; $i < $MAX; $i++)
{
  $pattern = [];
  for($j = 0; $j < $n; $j++)
  {
    if($i & (1 << $j)) $pattern[] = $j;
  }
  if(($totalPrice = total($pattern)) !== false)
  {
  	$lowestPrice = min($lowestPrice, $totalPrice);
  }
}

if($lowestPrice === INF) $lowestPrice = -1;
echo $lowestPrice . "\n";

function total($pattern)
{
  global $usLevels;
  global $bookPrices;
  global $m;
  global $x;

  $totalPrice = 0;
  $tLevels = array_fill(0, $m, 0);
  foreach($pattern as $book)
  {
    for($i = 0; $i < $m; $i++)
    {
      $tLevels[$i] += $usLevels[$i][$book];
    }
    $totalPrice += $bookPrices[$book];
  }
  
  foreach($tLevels as $tLevel)
  {
    if($tLevel < $x) return false;
  }
  
  return $totalPrice;
}

Measured memory_bytes: 16260
N, M = map(int,input().split())
L = [list(map(int,input().split())) for k in range(M)]
l = 0
r = N+1
for k in range(M):
    l = max(L[k][0],l)
    r = min(L[k][1],r)
print(max(0,r-l+1))


Measured memory_bytes: 27336
using LIB;
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

class Program
{
    public static IO IO = new IO();
    static void Main(string[] args)
    {
        int[] m = IO.INT(' ');
        if (m[0] == m[1] + m[2] || m[0] + m[1] == m[2] || m[0] + m[2] == m[1]) { IO.WRITE("Yes"); } else { IO.WRITE("No"); }
        IO.FLUSH();
    }
}

namespace LIB
{
    public class IO
    {
        private const int WMAX = 1000;
        private StringBuilder S = new StringBuilder();
        private T R<T>(Func<string, T> f) { return f(Console.ReadLine()); }
        private T[] R<T>(Func<string, T> f, char c) { return STRING().Split(c).Select(f).ToArray(); }
        private T[] R<T>(Func<string, T> f, int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = R(f); } return r; }
        private T[][] R<T>(Func<string, T> f, int l, char c) { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = R<T>(f, c); } return r; }
        private void W<T>(Func<T, string> f, T v, bool lf = true) { S.Append(f(v)); if (lf) { S.Append('\n'); } if (S.Length >= WMAX) { FLUSH(); } }
        public string STRING() { return R(s => s); }
        public string[] STRING(char c) { return R(s => s, c); }
        public string[] STRING(int l) { return R(s => s, l); }
        public string[][] STRING(int l, char c) { return R(s => s, l, c); }
        public int INT() { return R(int.Parse); }
        public int[] INT(char c) { return R(int.Parse, c); }
        public int[] INT(int l) { return R(int.Parse, l); }
        public int[][] INT(int l, char c) { return R(int.Parse, l, c); }
        public long LONG() { return R(long.Parse); }
        public long[] LONG(char c) { return R(long.Parse, c); }
        public long[] LONG(int l) { return R(long.Parse, l); }
        public long[][] LONG(int l, char c) { return R(long.Parse, l, c); }
        public double DOUBLE() { return R(double.Parse); }
        public double[] DOUBLE(char c) { return R(double.Parse, c); }
        public double[] DOUBLE(int l) { return R(double.Parse, l); }
        public double[][] DOUBLE(int l, char c) { return R(double.Parse, l, c); }
        public void WRITE(object s, bool lf = true) { W(v => v.ToString(), s, lf); }
        public void FLUSH() { Console.Write(S); S.Length = 0; }
    }
}

Measured memory_bytes: 2904
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
#endif
int N,count=0;long long D;
cin>>N>>D;

vector<long long> X(N),Y(N);


for(int i=0;i<N;i++)
{
    cin>>X[i]>>Y[i];
}
D*=D;
for(int i=0;i<N;i++)
{
    if((X[i]*X[i] + Y[i]*Y[i]) <= D)
    count++;
}
cout<<count<<endl;
return 0;
}

Measured memory_bytes: 6364
#define _CRT_SECURE_NO_WARNINGS
#include <array>
#include <algorithm>
#include <cstdio>

using namespace std;

const int MAXN = 1e5;
const int MAXD = 10;
const int MAXM = 2 * MAXN;

int N, M, Q;

int v, d;

int bt = -1;

array<int, MAXN> b;
array<int, MAXM> nxt, to;

array<array<int, MAXN>, MAXD + 1> f;
array<int, MAXN> c;

template<class T> void gc(T &x)
{
    int k, s = 0;
    x = 0;

    k = getchar_unlocked();

    if (k == '-') s = 1;
    else if ('0' <= k && k <= '9')  x = k - '0';

    while (true)
    {
        k = getchar_unlocked();

        if (k < '0' || k > '9') break;
        x = x * 10 + k - '0';
    }

    if (s) x = -x;
}

void add(int x, int y) {
    nxt[++bt] = b[x];

    b[x] = bt;
    to[bt] = y;

    nxt[++bt] = b[y];

    b[y] = bt;
    to[bt] = x;
}

int main()
{
    gc(N);
    gc(M);

    b.fill(-1);
    nxt.fill(-1);
    to.fill(-1);

    for (int i = 0; i <= MAXD; i++) f[i].fill(-1);

    for (int i = 0; i < M; i++)
    {
        int tmpx, tmpy;
        gc(tmpx);
        gc(tmpy);
        tmpx--;
        tmpy--;
        add(tmpx, tmpy);
    }

    gc(Q);

    // Q
    // v0 d0 c0
    for (int i = 0; i < Q; i++)
    {
        gc(v);
        gc(d);
        gc(c[i]);

        f[d][v - 1] = max(f[d][v - 1], i);
    }

    // i = distance
    // i + 1 <= MAXD
    for (int i = MAXD - 1; i >= 0; i--)
    {
        // j = vertex
        for (int j = 0; j < N; j++)
        {
            f[i][j] = max(f[i][j], f[i + 1][j]);

            for (int k = b[j]; 0 <= k; k = nxt[k])
            {
                f[i][j] = max(f[i][j], f[i + 1][to[k]]);
            }
        }
    }

    for (int i = 0; i < N; i++)
        printf("%d\n", f[0][i] == -1 ? 0 : c[f[0][i]]);

    return 0;
}


Measured memory_bytes: 7168
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
using namespace std;

int main()
{
	int h, w;
	for (int i = 0; i < 100000000; i++) {
		cin >> h >> w;
		if (h == 0 && w == 0) break;
		for (int j = 0; j < h; j++) {
			for (int t = 0; t < w; t++) {
				if (((j % 2 == 0 && t % 2 == 0)) || (j % 2 != 0 && t % 2 != 0)) {
					cout << "#";
				}
				else {
					cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3084
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

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

using namespace std;

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

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

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

	vector<int> a;
	inputVector(a, n);

	int cnt1 = 0;
	{
		int sum = 0;
		vector<int> b = a;
		rep(i, n) {
			sum += b[i];

			if (i % 2) {
				int dif = max(0LL, 1 - sum);
				b[i] += dif;
				sum += dif;
				cnt1 += dif;
			} else {
				int dif = max(0LL, 1 + sum);
				b[i] -= dif;
				sum -= dif;
				cnt1 += dif;
			}
		}
	}

	int cnt2 = 0;
	{
		int sum = 0;
		vector<int> b = a;
		rep(i, n) {
			sum += b[i];

			if (i % 2 == 0) {
				int dif = max(0LL, 1 - sum);
				b[i] += dif;
				sum += dif;
				cnt2 += dif;
			} else {
				int dif = max(0LL, 1 + sum);
				b[i] -= dif;
				sum -= dif;
				cnt2 += dif;
			}
		}
	}

	cout << min(cnt1, cnt2) << endl;

    return 0;
}


Measured memory_bytes: 1804
'''
Created on 2020/08/21

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N=int(pin())
  a=list(map(int,pin().split()))
  ave=sum(a)
  ans=0
  now=100*N
  for i in range(N):
    if abs(N*a[i]-ave)<now:
      now=abs(N*a[i]-ave)
      ans=i 
  print(ans)
  return 
main()

Measured memory_bytes: 9152
a, b = map(int, input().split())

A = []

for i in range(a):
    c= list(map(int, input().split()))
    A.append(c)

ans = 0

A.sort(key=lambda x:x[0])


for j in range(a+1):
    if(b - A[j][1] >=0):
        ans += A[j][0] * A[j][1]
        b -= A[j][1]
    else:
        ans += A[j][0] * b
        b = 0
    if(b == 0):
        break
    
print(ans)

Measured memory_bytes: 29024
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cassert>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<utility>
using namespace std;

int n,m,ns[200],ms[200];
int nsum,msum;

/*
input data
*/

void init(){
	nsum=msum=0;
}

bool input(){
	cin>>n>>m;
	if(n==0&&m==0){
		return false;
	}
	for(int i=0; i<n; i++){
		cin>>ns[i];
	}
	for(int i=0; i<m; i++){
		cin>>ms[i];
	}
	return true;
}

void make_sum(){
	int i;

	for(i=0; i<n; i++){
		nsum+=ns[i];
	}
	for(i=0; i<m; i++){
		msum+=ms[i];
	}
}

int exchange(int i,int j){
	int a,b;
		
	a=nsum-ns[i]+ms[j];
	b=msum+ns[i]-ms[j];
	if(a==b){
		return ns[i]+ms[j];
	}
	return -1;
}

void search_exchange(){
	int ansi,ansj;
	int min=200;
	int tmp;

	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			tmp=exchange(i,j);
			if(tmp!=-1&&tmp<min){
				ansi=i;
				ansj=j;
				min=tmp;
			}
		}
	}
	if(min==200){
		cout<<"-1"<<endl;
	}else{
		cout<<ns[ansi]<<" "<<ms[ansj]<<endl;
	}
}


void solve(){
	int i;

	sort(ns,ns+n);
	sort(ms,ms+m);
	make_sum();
	search_exchange();
}


int main(){
  while(init(),input()){
	solve();
  }
  return 0;
}

Measured memory_bytes: 1180
#include <iomanip>
#include <iostream>
#include <set>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;

  multiset<int> mapA;
  rep(i, N) {
    int A;
    cin >> A;
    auto itr = mapA.lower_bound(A);
    if (itr != mapA.begin()) {
      --itr;
      mapA.erase(itr);
    }
    mapA.emplace(A);
  }

  cout << mapA.size() << endl;
  return 0;
}


Measured memory_bytes: 4992
s=input()
n=len(s)
a="".join(["0" if i%2==0 else "1" for i in range(n)])
b="".join(["1" if i%2==0 else "0" for i in range(n)])
tmp1=0
tmp2=0
for i,j,k in zip(s,a,b):
  if i!=j:
    tmp1+=1
  if i!=k:
    tmp2+=1
print(min(tmp1,tmp2))

Measured memory_bytes: 4068
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,K=MI()
    A=LI()
    Lp=[]
    Lm=[]
    Lz=[]
    for i in range(N):
        if A[i]==0:
            Lz.append(0)
        elif A[i]>0:
            Lp.append(A[i])
        else:
            Lm.append(A[i])
            
    Lp.sort(reverse=True)
    Lm.sort()
    
    Np=len(Lp)
    Nm=len(Lm)
    
    if len(Lp)+len(Lm)<K:#どうしても0が入る
        print(0)
        exit()
    if K==1:
        print(max(A))
        exit()
    if max(A)<=0:#正数がない
        if K%2==0:
            A.sort()
        else:
            A.sort(reverse=True)
        ans=1
        for i in range(K):
            ans=(ans*A[i])%mod
        print(ans)
        exit()
    if K==N:
        ans=1
        for i in range(N):
            ans=(ans*A[i])%mod
        print(ans)
        exit()
    
    Lp.append(0)
    Lp.append(0)
    Lp.append(0)
    Lm.append(0)
    Lm.append(0)
    nowp=0
    nowm=0
    
    ans=1
    if K%2==0:
        for i in range(K//2):
            a=Lp[nowp]*Lp[nowp+1]
            b=Lm[nowm]*Lm[nowm+1]
            if a>=b:
                ans=(ans*a)%mod
                nowp+=2
            else:
                ans=(ans*b)%mod
                nowm+=2
    else:
        ans=Lp[0]
        nowp+=1
        for i in range(K//2):
            a=Lp[nowp]*Lp[nowp+1]
            b=Lm[nowm]*Lm[nowm+1]
            if a>=b:
                ans=(ans*a)%mod
                nowp+=2
            else:
                ans=(ans*b)%mod
                nowm+=2
    print(ans)
        
            

        
 
    
            
            

main()


Measured memory_bytes: 107280
n,m=map(int,input().split())
#TLEの対策1. a in listと比べて a in setはめちゃんこ速い!!
a=set([int(input()) for _ in range(m)])

#TLEの対策2.配列ではなく変数を使う(対策1と比べると対して効果なし).
p,q=0,1

for i in range(1,n+1):
    #最新のp,q以前の値は捨てて良い.つまり配列を使用する必要なし.
    p,q=q,(p+q)%(10**9+7)*(not i in a) #n*Trueは1, n*Falseは0を表す.
print(q)

Measured memory_bytes: 13216
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repm(i, m, n) for (int i = (m); i < (int)(n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define all(vec) vec.begin(), vec.end()
using namespace std;

int main(){
  int a, b, c; cin >> a >> b >> c;

  //int ans;
  string ans;
  if (a < b && b < c) ans = "Yes";
  else ans = "No";

  cout << ans << endl;
}


Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define clr(a) memset(a,0,sizeof(a))
#define reset(a) memset(a,-1,sizeof(a))
#define mod 1000000007
#define pi acos(-1)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);

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


int main()
{
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif

    fastio
    
    int n,c=0;
    cin>>n;
    for(int i=1; i<n; i++){
        for(int j=1; j<=(n/i); j++){
            if(n - (i*j) > 0)c++;
        }
    }
    cout << c << "\n";

    return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>

#define MAX 100
#define INFTY 100000000
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[MAX][MAX];

int Prim(void);

int main()
{
  int i, j, a;
  
  scanf("%d", &n);

  for( i = 0 ; i < n ; i++ ){
    for( j = 0 ; j < n ; j++ ){
      scanf("%d", &a);
      if( a == -1 ) M[i][j] = INFTY;
      else M[i][j] = a;
    }
  }

  printf("%d\n", Prim());

  return 0;
}

int Prim()
{
  int i, u, v, min, res=0;
  int color[MAX], d[MAX], p[MAX];
  
  for( i = 0 ; i < n ; i++ ){
    color[i] = WHITE;
    d[i] = INFTY;
    p[i] = -1;
  }
  
  d[0] = 0;
  
  while( 1 ){
    min = INFTY;
    u = -1;
    for( i = 0 ; i < n ; i++ ){
      if( color[i] != BLACK && min > d[i] ){
	u = i;
	min = d[i];
      }
    }
    if( min == INFTY ) break;
    color[u] = BLACK;
    for( v = 0 ; v < n ; v++ ){
      if( color[v] != BLACK && M[u][v] != INFTY ){
	if( M[u][v] < d[v] ){
	  d[v] = M[u][v];
	  p[v] = u;
	  color[v] = GRAY;
	}
      }
    }
  }
  
  for( i = 0 ; i < n ; i++ ) if( p[i] != -1 ) res += M[i][p[i]];
  
  return res;
}

Measured memory_bytes: 636