akhauriyash/Code-Regression huggingface dataset:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

def gcd(m, n):
    # 入力を m, n (m ≧ n) とする。
    tmp = max(m,n)
    n = min(m,n)
    m = tmp
    # n = 0 なら、 m を出力してアルゴリズムを終了する。
    if n == 0:
        return m
    # m を n で割った余りを新たに n とし、更に 元のnを新たにm とし 2. に戻る。
    return gcd(n, m % n)

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

a,b = get_nums_l()

_gcd = gcd(a,b)

if(_gcd == 1):
    print(1)
    exit()

print(len(factorization(_gcd))+1)

Measured memory_bytes: 38512
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
const int mod=998244353;
int main(){
    ll n,z,w;
    cin>>n>>z>>w;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    if(n==1){
        cout<<abs(a[0]-w)<<endl;
        return 0;
    }
    cout<<max(abs(a[n-1]-a[n-2]),abs(a[n-1]-w))<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <cassert>
#include <unordered_set>
#include <set>
#include <bitset>
#include <memory.h>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <queue>

using namespace std;
 
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
 
const int MOD = (int) 1e9 + 7;
const int MAGIC = 400;

long long binPow(long long a, long long b) {
    if (b == 0)
        return 1;

    long long ans = binPow(a, b / 2);
    ans = ans * ans % MOD;

    if (b % 2)
        ans = ans * a % MOD;

    return ans;
}

int main() {
    // freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;

    vector<long long> a(n);
    long long right = 0, left = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];

        right += a[i];
    }

    long long ans = (long long) 1e18;
    for (int i = 0; i + 1 < n; ++i) {
        left += a[i];
        right -= a[i];

        ans = min(ans, abs(right - left));

        // cout << left << " " << right << "\n";
    }

    cout << ans << "\n";
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main(){
  int x,a,b;
  cin >> x >> a >> b;
  cout << (x - a) % b << endl;
}


Measured memory_bytes: 256
N = int(input())
S = input()
total = (2**N-1)%(10**9+7)
dicta = {}
for i in range(N):
    if S[i] not in dicta:
        dicta[S[i]] = 1
    else:
        dicta[S[i]] += 1
dup = [v for v in dicta.values()]
dc = 1
for i in dup:
    dc *= i+1
print((dc -1)%(10**9+7))

Measured memory_bytes: 3188
import java.util.MissingResourceException;
import java.util.Scanner;

public class Main {
    public static void main(String[] arg){
        Scanner sc = new Scanner(System.in);
        try{
            while(true){
                String line = sc.next();
                if(line.equals("-")) {
                    break;
                }
                int m = sc.nextInt();
                for(int i=0;i<m;i++){
                    int h =sc.nextInt();
                    line = line.substring(h)+line.substring(0, h);
                }
                System.out.println(line);
            }
        }catch(MissingResourceException e){
            System.out.println(e);
        }
        sc.close();
    }
}


Measured memory_bytes: 26368
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>


#ifdef _DEBUG
#define typeof(X) std::identity<decltype(X)>::type //C++0x (for vs2010)
#else
#define typeof(X) __typeof__(X) // for gcc
#endif

#define sz(a)  int((a).size())
#define FOREACH(it, c) for (typeof((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define FOR(i,count) for (int i = 0; i < (int)(count); i++)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
const int MODULO = 100000 ;
const int INF = 100000000; //1e8

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef complex<double> Cd;

using namespace std;

int main()
{
	double a,b;
	while(~scanf("%lf %lf",&a,&b)){
		static double t5[] = {35.5,37.5,40,43,50,55,70};
		static double t10[] = {71,77,83,89,105,116,148};
		static string s[] = {"AAA","AA","A","B","C","D","E","NA"};
		int t5_r = upper_bound(t5,t5+7,a) - t5;
		int t10_r = upper_bound(t10,t10+7,b) - t10;

		int mx = max(t5_r,t10_r);
		cout << s[mx] << endl;
	}

	return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll llINF=1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
 
int main() {
  int x,y;
  cin>>x>>y;
  if(y%2==0&&y<=x*4&&y>=x*2){
    cout<<"Yes"<<endl;
    return 0;
  }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 3624
let f s = Str.split (Str.regexp " ") s
          |> List.map int_of_string
          |> List.fold_left (+) 0
;;

let () =
  let a = read_line () |> f and
      b = read_line () |> f in
  Printf.printf "%d\n" (if a < b then b else a)
;;

Measured memory_bytes: 2300
#include<iostream>

void rotate(char ptn[8][8]);

int main()
{
	char pattern[8][8];
	char buf[10];
	for(int i=0;i<8;i++)
	{
		std::cin.getline(buf,10);
		for(int j=0;j<8;j++)
		{
			pattern[i][j]=buf[j];
		}
	}
	for(int i=1;i<=3;i++)
	{
		std::cout<<90*i<<std::endl;
		rotate(pattern);
		for(int j=0;j<8;j++)
		{
			for(int k=0;k<8;k++)
			{
				std::cout<<pattern[j][k];
			}
			std::cout<<std::endl;
		}
	}
	return 0;
}

void rotate(char ptn[8][8])
{
	char temp[8][8];
	for(int i=0;i<8;i++)
	{
		for(int j=0;j<8;j++)
		{
			temp[i][j]=ptn[7-j][i];
		}
	}
	for(int i=0;i<8;i++)
	{
		for(int j=0;j<8;j++)
		{
			ptn[i][j]=temp[i][j];
		}
	}
}

Measured memory_bytes: 1128
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>

#define in std::cin
#define out std::cout

int32_t N;
std::pair<float,int> A[100000];
int res[100000] = {};

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);

	in >> N;
	for (int i = 0; i < N; i++)
	{
		in >> A[i].first;
		A[i].second = i;
	}
	std::sort(A, A + N);
	for (int i = 0; i < N; i++)
	{
		auto index = A[i].second;
		auto up = std::upper_bound(A, A + N, std::pair<float, int>{A[i].first, 100001});
		auto lower = std::lower_bound(A, A + N, std::pair<float, int>{A[i].first, -1});
		res[index] += 3*(lower - A);//?????????
		res[index] += (up - lower - 1);//????????????
	}

	for (int i = 0; i < N; i++)
	{
		out << res[i] << endl;
	}

	return 0;
}
#endif

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }


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

    vector<int> a(3);
    rep(i, 3) cin >> a[i];
    sort(all(a));
    if (a[0] == a[1] && a[0] == 5 && a[2] == 7) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/

#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0LL, sizeof(x))
#define mm(x) memset((x), -1LL, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define Bit(n) (1LL << (n))
#define Bitset(a, b) (a) |= (1LL << (b))
#define Bitunset(a, b) (a) &= ~(1LL << (b))
#define Bitcheck(a, b) ((((a) >> (b)) & 1LL) == 1LL)
#define Bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
constexpr int INF = (int)1e18;
constexpr int MOD = (int)1e9 + 7;
constexpr double PI = (double)acos(-1);
constexpr double EPS = (double)1e-10;
constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

signed main() {
  int N, M;
  cin >> N >> M;
  vector<int> v(N, 1);
  v[0] *= -1;

  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    if (v[x] == 0) {
      continue;
    } else if (v[x] > 0) {
      v[x]--;
      if (v[y] < 0) {
        v[y]--;
      } else {
        v[y]++;
      }
    } else if (v[x] < 0) {
      v[x]++;
      if (v[y] < 0) {
        v[y]--;
      } else {
        v[y]++;
        v[y] *= -1;
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (v[i] < 0) ans++;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
s = input()
l = len(s)

while s:
    if s.rfind('dream') == l-len('dream'): #文字列の背後から'dream'をさがす
        s = s[:l-len('dream')] #末尾の'dream'を削除する（スライス）
    
    elif s.rfind('dreamer') == l-len('dreamer'):
        s = s[:l-len('dreamer')]

    elif s.rfind('erase') == l-len('erase'):
        s = s[:l-len('erase')]
    
    elif s.rfind('eraser') == l-len('eraser'):
        s = s[:l-len('eraser')]

    else:
        break #文字列がなくなるか、指定の文字が探せなくなったらbreak

    l = len(s)

if s:
    print('NO')
else:
    print('YES')

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

using namespace std;

#define ll long long

void solve() {
	int n;
	cin >> n;
	vector<int> v;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		v.push_back(a);
	}
	sort(v.rbegin(), v.rend());
	
	int j = 0;
	ll x = 1;
	for (int i = 0; i < n; i++) {
		if (v[i] == v[i+1]) {
			x *= v[i];
			j++;
			i++;
			if (j == 2) {
				break;
			}
		}
	}
	if (j < 2) {
		x = 0;
	}
	cout << x << "\n";
}

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

	int t = 1, i = 1;
	//cin >> t;
	while(t--) {
		//cout << "Case #" << i << ": ";
		solve();
		//i++;
	}
	return 0;
}



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

	int t[2], tp[2][4];

	for (int i = 0; i < 2; i++){
		t[i] = 0;
		for (int j = 0; j < 4; j++){
			cin >> tp[i][j];
			t[i] += tp[i][j];
		}
	}
	if (t[0]>=t[1]) cout << t[0] << endl;
	else cout << t[1] << endl;

}

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

#define ll long long
#define mod 1000000007


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

    pair<int,int>p[n];

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

    long double re=0;

    for(int j=0;j<n-1;j++)
    {

    long double x=p[j].first,y=p[j].second;

    for(int i=j+1;i<n;i++)
    {
        long double xx=p[i].first,yy=p[i].second;

        long double dis=(xx-x)*(xx-x)+(yy-y)*(yy-y);

        re+=sqrt(dis);
    }
    }

    re=re*2.00;



    printf("%.8Lf\n",re/n);

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main() {
	int a, b, c, d;
	scanf("%d %d %d %d",&a, &b, &c, &d);
	if (a < 1 || a>10 * 10 * 10 * 10) {
		printf("Error");
	}
	if (b < 1 || b>10 * 10 * 10 * 10) {
		printf("Error");
	}
	if (c < 1 || c>10 * 10 * 10 * 10) {
		printf("Error");
	}
	if (d < 1 || d>10 * 10 * 10 * 10) {
		printf("Error");
	}
	int x1;
	int x2;
	x1 = a*b;
	x2 = c*d;
	if (x1 > x2) {
		printf("%d", x1);
	}
	if (x1 < x2) {
		printf("%d", x2);
	}
	if (x1 == x2) {
		printf("%d", x1);
	}



}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

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

  int res = 0, lol = 1;
  while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
    if(lol == 1e6 + 1) {
      cout << -1 << endl;
      return 0;
    }

    int tmpa = a / 2;
    int tmpb = b / 2;
    int tmpc = c / 2;

    a = tmpb + tmpc;
    b = tmpa + tmpc;
    c = tmpa + tmpb;

    res++;
    lol++;
  }

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<bool> vb;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sq(x) ((x)*(x))
#define fo(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<n;i++)
#define Fo(i,n) for(int i=1;i<=n;i++)
#define all(x) x.begin(),x.end()
#define deb(x) cout<<#x<<"="<<x<<"\n"
#define deb2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<"\n"
#define fi first
#define se second
const double pi = 3.14159265358979323846;
#define uni(c) (c).resize(unique(all(c))-(c).begin())
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
//pair <int, int> w[4] = {mp(-1, 0), mp(0, -1), mp(1, 0), mp(0, 1)};   // for matrix movement:
void cp()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}
ll n, w;
ll wt[200015];
ll val[200015];
ll dp[105][200015];
void solve()
{
	cin >> n >> w;
	fo(i, n)cin >> wt[i] >> val[i];
	//fo(i, n)cin >> wt[i];
	memset(dp, 0, sizeof(dp));
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= w; j++)
		{
			if (j < wt[i - 1])
			{
				dp[i][j] = dp[i - 1][j];
			}
			else
			{
				dp[i][j] = max(val[i - 1] + dp[i - 1][j - wt[i - 1]], dp[i - 1][j]);
			}
		}
	}
	cout << dp[n][w] << "\n";


}
int main()
{
	fast;
	//cp();
	ll t = 1;
	//cin >> t;
	while (t--)
		solve();


	return 0;
}

Measured memory_bytes: 167728
N, M, K = gets.chomp.split.map(&:to_i)
A = gets.chomp.split.map(&:to_i)
B = gets.chomp.split.map(&:to_i)

a = [0]
b = [0]

A.size.times{ |i| a << A[i] + a.last }
B.size.times{ |i| b << B[i] + b.last }

i = 0
j = B.size
max = 0
while i < a.size && j >= 0
  if a[i] + b[j] <= K
    max = i+j if max < i+j
    i += 1
  else
    j -= 1
  end
end

puts max


Measured memory_bytes: 49428
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    int m1,d1,m2,d2;
    cin>>m1>>d1>>m2>>d2;
    if( m1 == m2 )cout<<0<<endl;
    else cout<<1<<endl;
    return 0;
}


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

#define ll long long
using namespace std;

vector<int> p;
vector<int> a[10];
vector<int> used(10);

int main() {
    int n,m;
    cin >> n >> m;
    for(int i = 1; i <= m; i++)
    {
        int x,y;
        cin >> x >> y;
        a[x].push_back(y);
        a[y].push_back(x);
    }
    for (int i = 1; i <= n; i++)
        p.push_back(i);
    ll answ = 0;
    do
    {
        if (p[0] != 1) break;
        bool f = true;
        for (int i = 0; i < p.size()-1; i++)
        {
            bool f1 = false;
            for (auto j = a[p[i]].begin(); j != a[p[i]].end(); j++)
                if (*j == p[i+1]) f1 = true;
            if (!f1) {f = false; break;}
        }
        if (f) answ++;
    }while (next_permutation(p.begin(),p.end()));
        cout << answ << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
class UnionFind{
    public:
        vector<ll> par;
        vector<ll> siz;
        UnionFind(ll sz_): par(sz_),siz(sz_,1LL){
            rep(0,i,sz_)par[i]=i;
        }
        void init(ll sz_){
            par.resize(sz_);
            siz.assign(sz_,1LL);
            rep(0,i,sz_)par[i]=i;
        }
        ll root(ll x){
            while(x!=par[x]){
                x=par[x]=par[par[x]];
            }
            return x;
        }
        bool merge(ll x,ll y){
            x=root(x);
            y=root(y);
            if(x==y)return false;
            if(siz[x]<siz[y])swap(x,y);
            siz[x]+=siz[y];
            par[y]=x;
            return true;
        }
        bool issame(ll x,ll y){
            return root(x)==root(y);
        }
        ll size(ll x){
            return siz[root(x)];
        }
};
int main(void){
    ll n,m,k;
    cin>>n>>m>>k;
    vector<ll> c(n);
    c.assign(n,1LL);
    UnionFind a(n);
    rep(0,i,m){
        ll x,y;
        cin>>x>>y;
        --x,--y;
        a.merge(x,y);
        ++c[x];
        ++c[y];
    }
    rep(0,i,k){
        ll x,y;
        cin>>x>>y;
        --x,--y;
        if(a.issame(x,y)){
            ++c[x];
            ++c[y];
        }
    }
    rep(0,i,n){
        cout<<a.size(i)-c[i];
        if(i!=n-1)cout<<" ";
        else cout<<endl;
    }
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

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

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 0x3fffffff;
const ll MOD = 1e9+7;


int main(){
	//ios_base::sync_with_stdio(0);
	ll N, M, ans=0;
	ll x[100005], y[100005];

	cin >> N >> M;
	rep(i,N) cin >> x[i];
	rep(i,M) cin >> y[i];

	ll sum_x = 0, tmp_b = 0;
	rep(i,N-1){
		ll tmp = (x[i+1] - x[i])*(ll)(i+1);
		tmp %= MOD;
		tmp += tmp_b;
		tmp %= MOD;
		sum_x += tmp;
		sum_x %= MOD;
		tmp_b = tmp;
	}

	ll sum_y = 0;
	tmp_b = 0;
	rep(i,M-1){
		ll tmp = (y[i+1] - y[i])*(ll)(i+1);
		tmp %= MOD;
		tmp += tmp_b;
		tmp %= MOD;
		sum_y += tmp;
		sum_y %= MOD;
		tmp_b = tmp;
	}

	ans = (sum_x * sum_y) % MOD;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
int main(void){
    int A,B,C,D,X=0;
    scanf("%d\n%d\n%d\n%d",&A,&B,&C,&D);
    if(A<B){
        X+=A;
    }else{
        X+=B;
    }
    if(C<D){
        X+=C;
    }else{
        X+=D;
    }
    printf("%d\n",X);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;


vector<int>  dx = {1,-1,0,0};
vector<int>  dy = {0,0,1,-1};


int main() {
	int A,B,K; cin >> A >> B >> K;

	set<int> s;
	if (B - A + 1 < K) {
		K = B - A + 1;
	}
	for (int i = A; i < A + K; i++) {
		s.insert(i);
	}
	for (int i = B - K + 1; i <= B; i++) {
		s.insert(i);
	}

	for(auto x: s) {
		cout << x << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

ll mod_pow(ll x, ll n, ll mod = MOD) {
  ll res = 1;

  while (n > 0) {
    if (n & 1) {
      res = res * x % mod;
    }

    x = x * x % mod;
    n >>= 1;
  }

  return res;
}

ll mod_inverse(ll x, ll mod = MOD) {
  return mod_pow(x, mod - 2, mod);
}

const int MAX_N = 5001;
int dp[MAX_N][MAX_N];

int main() {
  int N;
  string S;

  cin >> N;
  cin >> S;

  int L = S.size();
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 1;

  for (int i = 0; i < N; ++i){
    for (int j = 0; j < N; ++j) {
      if (j > 0) {
        dp[i + 1][j - 1] += dp[i][j];
        dp[i + 1][j - 1] %= MOD;
      } else {
        dp[i + 1][j] += dp[i][j];
        dp[i + 1][j] %= MOD;
      }

      dp[i + 1][j + 1] += 2 * dp[i][j];
      dp[i + 1][j + 1] %= MOD;
    }
  }

  ll m = mod_pow(2, L);
  cout << (dp[N][L] * mod_inverse(m)) % MOD << endl;

  return 0;
}


Measured memory_bytes: 98048
#include<bits/stdc++.h>
using namespace std;
const long long M =1e5+7,MOD=1e9+7;
typedef long long ll;
#define pb push_back
#define Y printf("YES\n")
#define N printf("NO\n")
#define O printf("-1\n")
bool f_2=false,vis[M]= {false},f=false;
vector<ll>v,v_1,v_2,v_3,v_4,v_5;
string s,p,q,ok,ch;
map<ll,ll>mp,mp_2;
set<ll>st,st_1;
ll arr[M],ar[M]= {0};
ll cnt=0,cost=0,mx=0,NODE,t;
deque<ll>Q;
//vector< pair<ll,ll > >v,v_1;
struct node
{
    ll pa,ran,visit;

};
//node X[M];

int main()
{
    ios::sync_with_stdio(false);//ISHWAR
    cin.tie(0);//Tourist_Twin
    ll a,b,c=1,n,sum=0,mx=0,l,x,y,i=0,j=0,result=0,e,sum_2,ans=0,d,k;
    cin>>t>>a>>b;
    d=t-a;
    c=b-d;
    if(c<0)
        c=0;
    cout<<c<<endl;


        return 0;
    }


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int n;
    cin>>n;
    if(n==1)
    {
        cout<<"Hello World"<<endl;
    }
    else
    {
        int a,b;
        cin>>a>>b;
        cout<<a+b<<endl;
    }
 
    return 0;
}

Measured memory_bytes: 256
def main():
  n = int(raw_input())
  tasks = map(int, raw_input().split())
  m = int(raw_input())
  for _ in xrange(m):
    p, x = map(int, raw_input().split())
    total_time = sum(tasks) - tasks[p-1] + x
    print(total_time)

main()

Measured memory_bytes: 2568
S = str(input())

count = 0
if S[0] == 'R':
    count += 1
    if S[1] == 'R':
        count += 1
        if S[2] == 'R':
            count += 1
elif S[1] == 'R':
    count += 1
    if S[2] == 'R':
        count += 1
elif S[2] == 'R':
    count += 1

print(count)

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

int main() {
    int N; cin >> N;
    vector<int> s(N);

    int ans = 0;
    for (int i = 0; i < N; i++) {
        cin >> s[i];
        ans += s[i];
    }
    
    sort(s.begin(), s.end());

    if (ans % 10 == 0) {
        int tmp = -1;

        for (int i = 0; i < N; i++) {
            if (s[i] % 10 != 0) {
                tmp = s[i];
                break;
            }
        }

        if (tmp == -1) {
            ans = 0;
        }
        else {
            ans -= tmp;
        }
    }
            
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <queue>
#include <sstream>
#include <cmath>
#include <functional>
#include <climits>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define all(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cerr << __FILE__ << ":" << __LINE__ << endl;
#define INF 2147483647

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
        // setw(6) << setfill('0')
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const map<_K, _V>& v) {
    ostr << "{";
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << (*iter).first << ": " << (*iter).second << ", ";
    }
    ostr << "}";
    return ostr;
}

template <typename _K>
ostream& operator << (ostream& ostr, const set<_K>& v) {
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << *iter << (iter != v.end() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const pair<_K, _V>& v) {
    ostr << v.first << " " << v.second;
    return ostr;
}

int64 powmod(int64 n, int64 count, int64 mod) {
    if (count == 0) return 1;
    if (count % 2 == 0) {
        int64 t = powmod(n, count / 2, mod);
        return t * t % mod;
    }
    return n * powmod(n, count - 1, mod) % mod;
}

int64 ncr(int64 n, int64 r, int64 mod) {
    int64 a;
    if (n < r) a = min(n, r - n);
    else a = min(n - r, r);

    int64 res = 1;
    rep(i, a) {
        res = res * (n - i) % mod;
        res = res * powmod(i + 1, mod - 2, mod) % mod;
    }

    return res;
}

int main() {
    int64 N, M, X; cin >> N >> M >> X;
    vector<vector<int64>> L(N, vector<int64>(M+1));
    rep(i, N) rep(j, M+1) {
        cin >> L[i][j];
    }

    int64 ans = LLONG_MAX;
    rep(i, 1 << N) {
        vector<int> v;
        rep(j, N) {
            if ((i >> j) & 1) {
                v.push_back(j);
            }
        }

        int64 tmp = 0;
        vector<int64> D(M);
        rep(j, v.size()) {
            tmp += L[v[j]][0];
            reps(1, k, M+1) {
                D[k-1] += L[v[j]][k];
            }
        }

        bool f = true;
        rep(j, M) {
            if (D[j] < X) {
                f = false;
                break;
            }
        }

        // cout << "----" << endl;
        // cout << v << endl;
        // cout << D << endl;

        if (!f) continue;

        ans = min(ans, tmp);
    }

    if (ans == LLONG_MAX) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
}


Measured memory_bytes: 3664
// template version 1.12
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

// varibable settings
#define infile "../test/sample-1.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

int solve(){
  int n;cin>>n;
  vector<int> w(n);
  rep(i, n) {
    cin>>w[i];
  }
  dump(w);
  int s = accumulate(all(w), 0LL);

  int now = 0;
  int ans = s;
  rep(i, n){
    now += w[i];
    chmin(ans, abs(now-(s-now)));
  }
  cout << ans << endl;
  
  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <random>
#include <tuple>
#include <cstdint>

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

using namespace std;
typedef long long ll;

const int INF = 1 << 30;
const int MOD = 1e9 + 7;

vector<int> to[2505];
vector<int> rto[2505];
bool reachableFrom1[2505];
bool reachableToN[2505];
bool ok[2505];

void dfs(int v) {
    if (reachableFrom1[v]) return;
    reachableFrom1[v] = true;
    for (int nv: to[v]) {
        dfs(nv);
    }
}

void rdfs(int v) {
    if (reachableToN[v]) return;
    reachableToN[v] = true;
    for (int nv: rto[v]) {
        rdfs(nv);
    }
}


int main() {
    int n, m, p; cin >> n >> m >> p;
    vector<tuple<int, int, int>> g;
    rep(i, m) {
        int a, b, c; cin >> a >> b >> c;
        a--; b--;
        g.emplace_back(a, b, -(c-p));
        to[a].push_back(b);
        rto[b].push_back(a);
    }

    rep(i, n) {
        reachableFrom1[i] = false;
        reachableToN[i] = false;
    }

    dfs(0);
    rdfs(n-1);

    rep(i, n) {
        ok[i] = reachableToN[i] & reachableFrom1[i];
    }

    vector<int> dist(n, INF);
    dist[0] = 0;
    bool update = true;
    int iter = 0;
    while (update) {
        update = false;
        rep(i, m) {
            int a, b, c;
            tie(a, b, c) = g[i];
            if (!ok[a]) continue;
            if (!ok[b]) continue;
            int newdist = dist[a] + c;
            if (dist[b] > newdist) {
                update = true;
                dist[b] = newdist;
            }
        }
        iter++;
        if (iter > n) {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << max(0, -dist[n-1]) << endl;

    return 0;
}

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

int main() {
	int N, M; cin >> N >> M;
	int a[55], b[55], c[55], d[55];
	for(int i=0; i<N; ++i) cin >> a[i] >> b[i];
	for(int i=0; i<M; ++i) cin >> c[i] >> d[i];
	for(int i=0; i<N; ++i){
	    int P=abs(a[i]-c[0])+abs(b[i]-d[0]), Q=0;
	    for(int j=1; j<M; ++j){
	        int K=abs(a[i]-c[j])+abs(b[i]-d[j]);
	        if(P>K){
	            P=K;
	            Q=j;
	        }
	    }
	    cout << Q+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#define MOD 1000000007
#define mp make_pair
#define pb push_back
using namespace std; 
typedef long long ll; 
int lst[200005], to[200005], pre[200005], tot; 
int dep[200005], fa[200005][25], vfa[200005];
int dfn[200005], t, st[200005], n; 
vector<int> vec[200005]; 
ll dp0[200005], dp1[200005], ans; 
inline void add_edge(int u, int v)
{
	to[tot] = v; 
	pre[tot] = lst[u]; 
	lst[u] = tot++; 
}
void dfs(int u)
{
	dfn[u] = t++; 
	for (int i = 1; i < 20; i++)
		fa[u][i] = fa[u][i - 1] == -1 ? -1 : fa[fa[u][i - 1]][i - 1]; 
	vec[dep[u]].pb(u); 
	for (int i = lst[u]; ~i; i = pre[i])
	{
		dep[to[i]] = dep[u] + 1; 
		fa[to[i]][0] = u; 
		dfs(to[i]); 
	}
}
inline int lca(int u, int v)
{
	if (dep[u] > dep[v])
		swap(u, v); 
	for (int i = 0; i < 20; i++)
	{
		if (dep[v] - dep[u] & (1 << i))
			v = fa[v][i]; 
	}
	if (u == v)
		return u; 
	for (int i = 19; i >= 0; i--)
	{
		if (fa[u][i] != fa[v][i])
		{
			u = fa[u][i]; 
			v = fa[v][i]; 
		}
	}
	return fa[u][0]; 
}
inline ll quick_pow(ll a, int n)
{
	ll res = 1; 
	while (n)
	{
		if (n & 1)
			res = res * a % MOD; 
		a = a * a % MOD; 
		n >>= 1; 
	}
	return res; 
}
void upd(int u)
{
	if (-1 == lst[u])
		return; 
	ll sum = 1, prod = 1; 
	for (int i = lst[u]; ~i; i = pre[i])
	{
		upd(to[i]);
		sum = sum * (dp0[to[i]] + dp1[to[i]]) % MOD; 
		prod = prod * dp0[to[i]] % MOD; 
	}
	for (int i = lst[u]; ~i; i = pre[i])
		dp1[u] = (dp1[u] + prod * quick_pow(dp0[to[i]], MOD - 2) % MOD * dp1[to[i]]) % MOD; 
	dp0[u] = (sum - dp1[u] + MOD) % MOD; 
}
inline bool comp(int u, int v)
{
	return dfn[u] < dfn[v]; 
}
void work(vector<int> vec)
{
	if (!vec.size())
		return; 
	vector<int> nodes; 
	for (int i = 0; i < vec.size(); i++)
		nodes.pb(vec[i]); 
	int tp = 0; 
	for (int i = 0; i < vec.size(); i++)
	{
		if (!tp)
		{
			st[++tp] = vec[i]; 
			vfa[vec[i]] = -1; 
			continue; 
		}
		int x = lca(vec[i], st[tp]);  
		while (dep[st[tp]] > dep[x])
		{
			if (dep[st[tp - 1]] <= dep[x])
				vfa[st[tp]] = x; 
			tp--; 
		}
		if (st[tp] != x)
		{
			nodes.pb(x); 
			vfa[x] = st[tp]; 
			st[++tp] = x; 
		}
		st[++tp] = vec[i]; 
		vfa[vec[i]] = x; 
	}
	sort(nodes.begin(), nodes.end(), comp); 
	for (int i = 0; i < nodes.size(); i++)
	{
		lst[nodes[i]] = -1; 
		dp0[nodes[i]] = dp1[nodes[i]] = 0; 
	}
	for (int i = 0; i < vec.size(); i++)
		dp0[vec[i]] = dp1[vec[i]] = 1; 
	tot = 0; 
	for (int i = 1; i < nodes.size(); i++)
	{
		int u = nodes[i], v = vfa[u]; 
		add_edge(v, u); 
	}
	upd(nodes[0]); 
	ans = (ans + dp1[nodes[0]] * quick_pow(2, n + 1 - vec.size())) % MOD; 
}
int main()
{
	// freopen("ARC086-E.in", "r", stdin); 
	memset(lst, -1, sizeof(lst)); 
	scanf("%d", &n); 
	for (int i = 1; i <= n; i++)
	{
		int x; 
		scanf("%d", &x); 
		add_edge(x, i); 
	}
	fa[0][0] = -1; 
	dfs(0); 
	st[0] = -1; 
	for (int i = 0; i <= n; i++)
		work(vec[i]); 
	printf("%lld\n", ans);
	return 0; 
}


Measured memory_bytes: 45568
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<numeric>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;


//最大公約数
template<class T> T gcd(T a, T b)
{
	while (true)
	{
		T r;
		if (a%b == 0) return b;
		else
		{
			r = a % b;
			a = b;
			b = r;
		}
	}
}
//最小公倍数
template<class T> T lcm(T a, T b)
{
	return a / gcd(a, b)*b;
}
//文字0~9をint型0~9に変換
int char_to_int(char c)
{
	if (c == '0') return 0;
	if (c == '1') return 1;
	if (c == '2') return 2;
	if (c == '3') return 3;
	if (c == '4') return 4;
	if (c == '5') return 5;
	if (c == '6') return 6;
	if (c == '7') return 7;
	if (c == '8') return 8;
	if (c == '9') return 9;
	else return -1;
}
//a^b mod MODを計算
long long int ModPower(long long int a, long long int b, long long int MOD)
{
	if (b == 0) return 1;
	else if (b % 2 == 0)
	{
		long long int d = ModPower(a, b / 2, MOD);
		return (d*d) % MOD;
	}
	else
	{
		return (a*ModPower(a, b - 1, MOD)) % MOD;
	}
}
//nCr mod MODを計算
long long int ModCombi(long long int n, long long int r, long long int MOD)
{
	if (n == 0 || r == 0) return 1;

	long long int Kn = 1, Kr = 1, Knr = 1;

	long long int temp = 1;
	for (long long int i = 1; i <= n; i++)
	{
		temp *= i;
		temp %= MOD;
		if (i == n) Kn = temp;
		if (i == r) Kr = temp;
		if (i == n - r) Knr = temp;
	}

	long long int x = ModPower(Kr, MOD - 2, MOD);
	long long int y = ModPower(Knr, MOD - 2, MOD);

	long long int ans;
	ans = Kn * x;
	ans %= MOD;
	ans *= y;
	ans %= MOD;

	return ans;
}
//int型10進数をord桁のstring型2進数に変換する
string binary(int x,int ord)
{
	int y;
	string ans = "";
	for (int i = 0; i < ord; i++)
	{
		y = x / pow(2, ord - 1 - i);
		y %= 2;
		if (y == 0) ans += "0";
		else ans += "1";
	}

	return ans;
}


/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/


int main()
{
	int n, m;
	int c[20];
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		cin >> c[i];
	}

	int ans[50000];
	ans[0] = 0, ans[1] = 1;

	for (int i = 2; i <= n; i++)
	{
		int x = 100000;
		for (int j = 0; j < m; j++)
		{
			if(i >= c[j])
				x = min(x, 1 + ans[i - c[j]]);
		}
		ans[i] = x;
	}

	cout << ans[n] << endl;

	return 0;
}



Measured memory_bytes: 3296
<?php
fscanf(STDIN, "%d", $need_tomari);
fscanf(STDIN, "%d", $waribiki_day);
fscanf(STDIN, "%d", $normal_pay);
fscanf(STDIN, "%d", $waribiki_pay);


if (($need_tomari < 1 || 10000 < $need_tomari)
    || ($waribiki_day < 1 || 10000 < $waribiki_day)
    || ($normal_pay < 1 || 10000 < $normal_pay)
    || ($waribiki_pay < 1 || 10000 < $waribiki_pay)
    || ($normal_pay < $waribiki_pay)
) {
    exit;
}

$pay = $need_tomari * $normal_pay;
$waribiki = ($need_tomari - $waribiki_day) * ($normal_pay - $waribiki_pay);

if ($need_tomari > $waribiki_day) {
    echo $pay - $waribiki;
} else {
    echo $pay;
}

exit;

?>

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

typedef long long ll;
char s[1000000];
ll a[1000000];
int n;

int main()
{
	cin>>n;
	ll x,pre=0,ans=0;
	cin>>pre;
	for(int i=2;i<=n;i++)
	{
		cin>>x;
		if(pre>x) ans+=pre-x;
		pre=max(pre,x);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3732
from sys import stdin
import numpy as np
N,M=[int(x) for x in stdin.readline().rstrip().split()]
data=[int(x) for x in stdin.readline().rstrip().split()]
if N >= M:
    ans=0
else:
    data=np.array(sorted(data))
    diff=sorted(np.diff(data))
    ans=sum(diff[0:len(diff)-N+1])
print(ans)

Measured memory_bytes: 23028
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i,n) for(int i = 1; i < n+1 ;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 INF 2e9
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    //COMinit();
    int a,b,c;
    cin >> a >> b >> c;
    if(a+b+c>=22){
        cout << "bust" << endl;

    }
    else{
        cout << "win" << endl;
    }
}


Measured memory_bytes: 256
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/* 
 * File:   main.c
 * Author: Ivan
 *
 * Created on July 3, 2018, 12:26 PM
 */

#include <stdio.h>
#include <stdlib.h>

typedef struct{
    char s;
    int v;
}Poker;
/*
 * 
 */
int charCompare(Poker a[], Poker b[], int n);
void bubbleSort(Poker a[], int n);
void selectionSort(Poker A[], int N);

int main(int argc, char** argv) {
    int n;
    
    scanf("%d", &n);
    Poker A[1900], B[1432];
    for (int i = 0; i < n; i++)
    {
        scanf(" %c %d", &A[i].s, &A[i].v);
        B[i] = A[i];
//        printf("%c%d\n", B[i].s, B[i].v);
    }
    bubbleSort(A, n);
    selectionSort(B, n);
    
    for (int k = 0; k < n; ++k) 
    {
        if (k) printf(" ");
        printf("%c%d", A[k].s, A[k].v);
    }
    printf("\nStable\n");
    
    for (int kx = 0; kx < n; ++kx) 
    {        
        if (kx) printf(" ");
        printf("%c%d", B[kx].s, B[kx].v);
    }
    if (charCompare(A, B, n)) printf("\nStable\n");
    else printf("\nNot stable\n");
    
    return (EXIT_SUCCESS);
}

int charCompare(Poker a[], Poker b[], int n)
{
    for (int i = 0; i < n; ++i) if (a[i].s != b[i].s) return 0;    
    return 1;
}

void bubbleSort(Poker a[], int n)
{
    for( int i = 0; i < n; i++ )
	{
            for( int j = n-1; j >= i; j-- )
            {
                if( a[j].v < a[j-1].v )
                {
                    Poker copy;
                    copy = a[j];
                    a[j] = a[j-1];
                    a[j-1] = copy;
                }
            }
	}
}

void selectionSort(Poker A[], int N)
{
    int i, j, minj;
    Poker t;
    for (i = 0; i < N; i++)
    {
        minj = i;
        for (j = i; j < N; j++) if (A[j].v < A[minj].v) minj = j;
        t = A[i]; A[i] = A[minj]; A[minj] = t;
//        if (i != minj) sw++;
    }
}



Measured memory_bytes: 2112
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int number = in.nextInt(); 
		int h = number / 3600;
		int min = number % 3600 / 60;
		int  s = (number % 3600) % 60;
		System.out.println(h+":"+min+":"+s);
	}
}

Measured memory_bytes: 26068
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll a, b; cin >> a >> b;
  cout << a*b - a - b + 1 << endl;
}

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

using namespace std;
int d[26];

int main(){
	int h, w;string s;
	cin >> h >> w;
	getline(cin, s);
	for(int i = 0; i < h; i++){
		getline(cin, s);
		for(int j = 0; j < w; j++){
			d[s[j] - 'a']++;
		}
	}
	int d4 = 0, even = 0, odd = 0;
	for(int i = 0; i < 26; i++){
		if(d[i] % 4 == 0)
			d4++;
		else if(d[i] % 2 == 0)
			even++;
		else
			odd++;
	}
	if((h & 1) && (w & 1)){
		if(odd == 1 && even < (h + w) / 2)
			cout << "Yes";
		else
			cout << "No";
	}
	else if((h & 1) || (w & 1)){
		if(odd == 0 && even <= (h & 1) * w / 2 + (w & 1) * h / 2)
			cout << "Yes";
		else
			cout << "No";
	}
	else{
		if(odd == 0 && even == 0)
			cout << "Yes";
		else
			cout << "No";		
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i ++)
using ll = long long;
const ll INF = 1ll<<55;
int N;
int A[100001][3];
ll dp[100001][3];

int main() {
    cin >> N;
    rep(i, N) cin >> A[i][0] >> A[i][1] >> A[i][2];
    dp[0][0] = dp[0][1] = dp[0][2] = 0;
    for (int i = 1; i <= N; i ++) {
        for (int j = 0; j < 3; j ++) {
            dp[i][j] = max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3]) + A[i-1][j];
        }
    }
    cout << max(max(dp[N][0], dp[N][1]), dp[N][2]) << endl;
    return 0;
}

Measured memory_bytes: 7120
n,m = (int(i) for i in input().split())
y,z,ans = [[] for i in range(n+1)],[None for i in range(n+1)],"Yes"
for num in range(m):
	i,j,k = (int(i) for i in input().split())
	y[i].append([j,k])
	y[j].append([i,-k])
for i in range(1,n+1):
	if z[i] == None:
		z[i],q = 0,[i]
		while q:
			p = q.pop()
			for j,k in y[p]:
				if z[j] == None:
					q.append(j)
					z[j] = z[p]+k
for i in range(1,n+1):
	for j,k in y[i]:
		if z[i]+k != z[j]: ans = "No"
print(ans)

Measured memory_bytes: 77616
#include<iostream>
#define INF 1e9
using namespace std ;
int main(){
int X , Y , A,C,B,best=INF ;
scanf("%d %d %d %d %d",&A,&B,&C,&X,&Y);
for(int i=0 ;i<100001 ; i++){

   best =min(best, 2*C*i+max(0, X-i)*A+ max(0 , Y-i)*B) ;

}
printf("%d",best) ;



return 0 ;
}


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

const double EPS = 1e-10;

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    int bestIndex;
    double bestBMI = 1e10;
    while (n--) {
      int i, h, w;
      cin >> i >> h >> w;
      
      double bmi = w / ((h/100.0)*(h/100.0));
      if (abs(22.0-bestBMI) - abs(22.0-bmi) > EPS) {
	bestBMI = bmi;
	bestIndex = i;
      } else if (abs(22.0-bmi) - abs(22.0-bestBMI) < EPS) {
	bestIndex = min(bestIndex, i);
      }
    }
    cout << bestIndex << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

typedef long long ll;

char buf[100][100];


const int DI[4] = {1, 0, -1, 0};
const int DJ[4] = {0, 1, 0, -1};

int main(void) {
  int nRow, nCol;
  cin >> nRow >> nCol;
  REP(i, nRow) {
    cin >> buf[i];
  }

  REP(i, nRow) {
    REP(j, nCol) {
      if(buf[i][j] == '.') {
        continue;
      }
      bool ok = false;
      REP(d, 4) {
        int ni = i + DI[d];
        int nj = j + DJ[d];
        if(ni >= 0 && nj >= 0 && ni < nRow && nj < nCol) {
          if(buf[ni][nj] == '#') {
            ok = true;
            break;
          }
        }
      }
      if(!ok) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 384
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int>a(M);
    for (int i = 0; i < M; i++)cin >> a[i];

    vector<int>v(N + 2, 0);
    v[0] = 0;
    v[1] = 1;
    for (int i = 2; i <= N+1; i++) {
        if (binary_search(a.begin(), a.end(), i-1))continue;
        else {
            v[i] = (v[i - 1] + v[i - 2])% 1000000007;
        }
    }

    cout << v[N + 1] << endl;
}

Measured memory_bytes: 1024