akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		while(true){
			String tmp = br.readLine();
			
			if(tmp == null){
				break;
			}
			
			String[] tmpArray = tmp.split(",");
			
			int[] distance = new int[10];
			int sum = 0;
			for(int i = 0; i < 10 ; i++){
				distance[i] = Integer.parseInt(tmpArray[i]);
				sum += distance[i];
			}
			int v1 = Integer.parseInt(tmpArray[10]);
			int v2 = Integer.parseInt(tmpArray[11]);
			
			double conflictPoint = (double)sum*v1/(v1+v2);
			
			for(int i = 0; i < 10 ; i++){
				conflictPoint -= distance[i];
				if(conflictPoint <= 0){
					System.out.println(i + 1);
					break;
				}
			}
		}
	}

}

Measured memory_bytes: 24180
#include <iostream>
#include <algorithm>
#define llint long long

using namespace std;

llint n, Q, L, R;
llint a[200005];
llint q[200005], x[200005], s[200005], t[200005];

bool check(llint m)
{
	if(m >= n) return true;
	m = a[m];
	for(int i = 0; i < Q; i++){
		if(q[i] == 1){
			if(m >= x[i]) m = (m+s[i])*t[i];
		}
		else{
			if(m <= x[i]) m = (m-s[i])/t[i];
		}
	}
	return m >= R;
}

bool check2(llint m)
{
	if(m < 0) return true;
	m = a[m];
	for(int i = 0; i < Q; i++){
		if(q[i] == 1){
			if(m >= x[i]) m = (m+s[i])*t[i];
		}
		else{
			if(m <= x[i]) m = (m-s[i])/t[i];
		}
	}
	return m <= L;
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> Q >> L >> R;
	L--, R++;
	for(int i = 0; i < n; i++) cin >> a[i];
	sort(a, a+n);
	for(int i = 0; i < Q; i++) cin >> q[i] >> x[i] >> s[i] >> t[i];
	
	llint ub = n, lb = -1, mid, ans = 0;
	while(ub-lb>1){
		mid = (ub+lb)/2;
		if(check(mid)) ub = mid;
		else lb = mid;
	}
	ans += n - ub;
	
	//cout << ub << endl;
	
	ub = n, lb = -1;
	while(ub-lb>1){
		mid = (ub+lb)/2;
		if(check2(mid)) lb = mid;
		else ub = mid;
	}
	ans += lb+1;
	
	//cout << lb << endl;
	
	cout << n - ans << endl;
	
	return 0;
}



Measured memory_bytes: 10756
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

vector< vector<bool> > done;
vector<string> m;

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

    int H, W;
    cin >> H >> W;
    done.resize(H, vector<bool>(W, false));
    m.resize(H);
    rep (i, H) cin >> m[i];

    queue< pair<int, int> > q;
    rep (i, H)
    {
        rep (j, W)
        {
            if (m[i][j] == '#')
            {
                q.push(make_pair(i, j));
                done[i][j] = true;
            }
        }
    }

    int ans = 0;
    while (!q.empty())
    {
        ++ans;
        int s = q.size();
        rep (i, s)
        {
            int xx = q.front().first;
            int yy = q.front().second;
            q.pop();
            if (xx + 1 < H && !done[xx + 1][yy]) { done[xx + 1][yy] = true; q.push(make_pair(xx + 1, yy)); }
            if (xx - 1 >= 0 && !done[xx  - 1][yy]) { done[xx - 1][yy] = true; q.push(make_pair(xx - 1, yy)); }
            if (yy + 1 < W && !done[xx][yy + 1]) { done[xx][yy + 1] = true; q.push(make_pair(xx, yy + 1)); }
            if (yy - 1 >= 0 && !done[xx][yy - 1]) { done[xx][yy - 1] = true; q.push(make_pair(xx, yy - 1)); }
        }
    }
    cout << ans - 1 << "\n";
    return 0;
}



Measured memory_bytes: 9744
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    int N,ans=0;
    cin>>N;
    REP(i,N){
        int r,l;
        cin>>r>>l;
        ans+=l-r+1;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define X first
#define Y second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define ini(x, y) memset(x, y, sizeof(x))
#define endl '\n'
#define fastio cin.sync_with_stdio(false); cin.tie(nullptr)
using namespace std;

using ll = long long;
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int dx[] = { -1, 0, 1, 0, -1, 1, 1, -1 };
const int dy[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

int main() {
	fastio;
	int bo[3][3];
	for (int i = 0; i < 3; ++i)
		for (int j = 0; j < 3; ++j)
			cin >> bo[i][j];

	int N;
	cin >> N;

	for (int v, i = 0; i < N; ++i) {
		cin >> v;
		for (int j = 0; j < 3; ++j) {
			for (int k = 0; k < 3; ++k) {
				if (bo[j][k] == v) {
					bo[j][k] = -1;
				}
			}
		}
	}

	int cnt = 0;
	for (int i = 0; i < 3; ++i) {
		cnt += bo[i][0] + bo[i][1] + bo[i][2] == -3;
		cnt += bo[0][i] + bo[1][i] + bo[2][i] == -3;
	}
	cnt += bo[0][0] + bo[1][1] + bo[2][2] == -3;
	cnt += bo[2][0] + bo[1][1] + bo[0][2] == -3;

	if (cnt) cout << "Yes";
	else cout << "No";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)
#define loop(i,N,M) for(int i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

//変数
ll N;
vector<ll> vec;

//解法
void solve() {

	vec.emplace_back(N);
	bool flag = true;

	while (flag) {

		ll val = 0;
		if (vec[vec.size() - 1] % 2 == 0) {
			val = vec[vec.size() - 1] / 2;
		}
		else {
			val = 3 * vec[vec.size() - 1] + 1;
		}
		vec.emplace_back(val);

		rep(j, vec.size() - 1) {
			if (vec[vec.size() - 1] == vec[j]) {
				cout << vec.size();
				flag = false;
				break;
			}
		}

	}

	return;
}

int main() {
	//入力

	cin >> N;

	solve();
	//cout << endl;
	return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/02/24  Problem: ABC 119 A / Link: http://abc119.contest.atcoder.jp/tasks/abc119_a  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL ans = 0LL;

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

	int y, m, d;
	scanf("%d/%d/%d", &y, &m, &d);
	if (y > 2019 || (y == 2019 && m > 4) || (y == 2019 && m == 4 && d > 30)) {
		cout << "TBD" << endl;
	}
	else {
		cout << "Heisei" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
N = gets.to_i

list = N.times.collect{
	gets.strip.split(/ /).collect{|n| n.to_i}
}

i = -1
st_a = list.collect{|a, b|
	i += 1
	[a + b, a, i]
}.sort.reverse

i = -1
st_b = list.collect{|a, b|
	i += 1
	[a + b, b, i]
}.sort.reverse

count = N
index_a = 0
index_b = 0
used = {}
sum_a = 0
sum_b = 0
N.times{|i|
	if i % 2 == 0
		while true
			sum, a, n = st_a[index_a]
			unless used[n]
				sum_a += a
				used[n] = true
				break
			end
			index_a += 1
		end
	else
		while true
			sum, b, n = st_b[index_b]
			unless used[n]
				sum_b += b
				used[n] = true
				break
			end
			index_b += 1
		end
	end
}
puts sum_a - sum_b


Measured memory_bytes: 26352
#include<cstring>
#include <cstdio> 
#include <iostream>
#include <cmath>
#include<algorithm>
using namespace std;
#define pi 3.1415926 
#include<iostream>
using namespace std;
int main()
{
	int x;
	cin>>x;
	if(x>=30)
	{
		printf("Yes");
	 } 
	else
	{
		printf("No");
	}
}

Measured memory_bytes: 3756
import java.util.Scanner;
public class Main {
    static int max_depth=1;
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        while(true) {
            max_depth=1;
            int m = sc.nextInt();
            int n = sc.nextInt();
            if(m==0 && n==0) break;
            int[][] table = new int[m + 2][n + 2];
            for (int i = 0; i < m + 2; i++) {
                for (int j = 0; j < n + 2; j++) {
                    table[i][j] = 0;
                }
            }
            for (int i = 1; i < m + 1; i++) {
                for (int j = 1; j < n + 1; j++) {
                    table[i][j] = sc.nextInt();
                }
            }
            for (int i = 1; i < m + 1; i++) {
                for (int j = 1; j < n + 1; j++) {
                    if (table[i][j] == 1) hakuhyo(table, i, j, 1);
                }
            }
            System.out.println(max_depth);
        }
    }
    public static void hakuhyo(int[][] table,int x,int y,int depth){
        if(table[x-1][y]==0 && table[x][y-1]==0 && table[x][y+1]==0 && table[x+1][y]==0) {
            if (depth > max_depth) max_depth = depth;
            return;
        }
        table[x][y]=0;
        if(table[x-1][y]==1){
            hakuhyo(table,x-1,y,depth+1);
        }
        if(table[x][y-1]==1){
            hakuhyo(table,x,y-1,depth+1);
        }
        if(table[x][y+1]==1){
            hakuhyo(table,x,y+1,depth+1);
        }
        if(table[x+1][y]==1){
            hakuhyo(table,x+1,y,depth+1);
        }
        table[x][y]=1; //割った氷を元に戻す
    }
}



Measured memory_bytes: 39232
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a,b;
		while(sc.hasNext()) {
			a = sc.nextInt();
			b = sc.nextInt();
			if(a == 0 && b == 0) 
				break;
			else {
				int sum = a+b;
				a = Math.min(a,b);
				b = sum-a;
			}
			System.out.println(a+" "+b);
		}
	}
}



Measured memory_bytes: 35640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0 ; i<(n) ;i++)
ll solve(ll a, ll b ,ll c, ll x){
	ll count = 0;
	for(int i=0; i <= a; i++){
		for(int j=0; j<=b ;j++){
			for(int k=0; k<=c;k++){
				if(i*500 + j*100 + k*50 == x) count++;
			}
		}
	}
	return count;
}

int main(){
	ll a,b,c,x; cin >> a >> b >> c >>x;
	ll ans = solve(a,b,c,x);
	cout << ans << endl;
	return 0;
}

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

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

    while(1){
        c  -= b;
        if(c <= 0) { cout << "Yes" << endl; break;}
        a  -= d;
        if(a <= 0) { cout << "No" << endl; break;}
    }

    return 0;
}

Measured memory_bytes: 3128
#include<bits/stdc++.h>
#define FO(i, a, b) for (int i = a; i <= b; i++)
#define FE(i, a, b) for (int i = a; i < b; i++)
#define R(i) i = read()
using namespace std;

typedef long long ll;

const int N = 100005;
const int MOD = 1e9 + 7;

int read() {
	int x = 0; char c = getchar();
	while((c != '-') && (c < 48 || c > 57)) c = getchar();
	if(c == '-') {c = getchar(); while(c >= 48 && c <= 57) x = x * 10 - c + 48, c = getchar();}
	else while(c >= 48 && c <= 57) x = x * 10 + c - 48, c = getchar();
	return x; 
}

struct Point {
	int x, y, v;
}P[N];

int fy[N], fx[N], cy[N], cx[N], min1[N], min2[N];

inline bool cmp_x(Point x, Point y) {
	return x.x < y.x;
}

inline bool cmp_y(Point x, Point y) {
	return x.y < y.y;
}

int pd;

inline int find_y(int x) {
	if(fy[x] == x) return x;
	int tmp = fy[x];
	fy[x] = find_y(tmp);
	cy[x] += cy[tmp];
	return fy[x];
}

inline int find_x(int x) {
	if(fx[x] == x) return x;
	int tmp = fx[x];
	fx[x] = find_x(fx[x]);
	cx[x] += cx[tmp];
	return fx[x];
}

inline void Link_y(int a, int b, int c) {
	int fa = find_y(a), fb = find_y(b);
	if(fa == fb) {
		if(cy[a] - cy[b] != c) 
			pd= 1;
	}
	else {
		fy[fa] = fb;
		cy[fa] = c + cy[b] - cy[a];
	}
}

inline void Link_x(int a, int b, int c) {
	int fa = find_x(a), fb = find_x(b);
	if(fa == fb) {
		if(cx[a] - cx[b] != c)
			pd = 1;
	}
	else {
		fx[fa] = fb;
		cx[fa] = c + cx[b] - cx[a];
	}
}

int T, R, C, n;

int main() {
//	freopen("then.in", "r", stdin);
//	freopen("then.out", "w", stdout);
//	R(T);
	T = 1;
	while(T--) {
		pd = 0;
		R(R), R(C);
		memset(cx, 0, sizeof(cx));
		memset(cy, 0, sizeof(cy));
		FO(i, 1, R) fx[i] = i;
		FO(i, 1, C) fy[i] = i;
		R(n);
		FO(i, 1, n)
			R(P[i].x), R(P[i].y), R(P[i].v), pd = P[i].v < 0 ? 1 : 0;
//		sort(P + 1, P + n + 1, cmp_x);
//		FE(i, 1, n)
//			if(P[i].x == P[i + 1].x)
//				Link_y(P[i].y, P[i + 1].y, P[i + 1].v - P[i].v);
		sort(P + 1, P + n + 1, cmp_y);
		FE(i, 1, n)
			if(P[i].y == P[i + 1].y)
				Link_x(P[i].x, P[i + 1].x, P[i + 1].v - P[i].v);
		if(pd) {
			printf("No\n");
			continue;
		}
		memset(min1, 127/2, sizeof(min1));
		memset(min2, 127/2, sizeof(min2));
		FO(i, 1, n) {
			int t = P[i].x;
			int f = find_x(t);
			min1[f] = min(min1[f], P[i].v + cx[t]);
		}
		FO(i, 1, R) {
			int f = find_x(i);
			min2[i] = min(min2[i], min1[f] - cx[i]);
		}
		FO(i, 1, R) {
			if(min2[i] < 0)
				pd = 1;
		}
		if(pd) printf("No\n");
		else printf("Yes\n");
	}
}

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

#define int long long

int32_t main(){
	int n ;
	cin >> n ;
	int a[n] ;
	int k = 1 ;
	for(int i = 0 ; i < n ; i++) cin >> a[i] ;
	for(int i = 0 ; i < n ; i++){
		k += k == a[i] ;
	}
	if(k == 1) {
		cout << -1 ;
	}else {
		cout << n - k + 1 ;
	}return 0 ;
}



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

/* #include<cstdio>*/
int main(){
	int a, b;
	char op;
	while (1){
		cin >> a >> op >> b;
		if (op == '?')break;
		if (op == '+'){
			cout << a + b << endl;
			continue;
		}
		else if (op == '-'){
			cout << a - b << endl;
			continue;
		}
		else if (op == '/'){
			cout << a / b << endl ;
			continue;
		}
		else {
			cout << a * b << endl;
			continue;
		}

	}
	return 0; 
}




Measured memory_bytes: 3100
X,Y,Z,K = map(int,input().split())
#A = np.empty(X,dtype=int)
#B = np.empty(Y,dtype=int)
#C = np.empty(Z,dtype=int)
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)

AB = [ a+b for a in A for b in B]
AB = sorted(AB, reverse=True)
AB = AB[:3000]
ABC = [ab+c for ab in AB for c in C]
ABCs = sorted(ABC, reverse=True)[:K]
for i in range(K):
  print(ABCs[i])
  

Measured memory_bytes: 186124
#include "bits/stdc++.h"

using namespace std;

long long N, A, B;
vector<long long> X;

void Main() {
    cin >> N >> A >> B;
    X = vector<long long>(N, 0);
    for (long long i = 0; i < N; ++i) {
        cin >> X[i];
    }

    long long ans = 0LL;
    for (long long i = 0; i < N - 1; ++i) {
        long long dist = X[i + 1] - X[i];
        ans += min(dist * A, B);
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3964
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <tuple>

template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr r, l;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

class union_find {
private:
  int component;
  std::vector<int> parent;

public:
  union_find() = default;
  union_find(int size_) { init(size_); }

  void init(int size_) {
    component = size_;
    parent.assign(size_, -1);
  }

  int count_components() const { 
    return component; 
  }
  int component_size(int i) { 
    return -parent[find_parent(i)]; 
  }
  bool same_component(int i, int j) { 
    return find_parent(i) == find_parent(j); 
  }

  int find_parent(int i) {
    if (parent[i] < 0) {
      return i;
    }
    else {
      return parent[i] = find_parent(parent[i]);
    }
  }

  bool unite(int i, int j) {
    i = find_parent(i);
    j = find_parent(j);
    if (i == j) {
      return false;
    }
    if (parent[i] > parent[j]) {
      std::swap(i, j);
    }
    parent[i] += parent[j];
    parent[j] = i;
    --component;
    return true;
  }

};

int main() {
  int N, M, K;
  std::cin >> N >> M >> K;
  std::vector<int> degree(N);
  std::vector<std::vector<int>> block(N);
  union_find dsu(N);
  for (int i: range(0, M)) {
    int a, b;
    std::cin >> a >> b;
    --a; --b;
    dsu.unite(a, b);
    ++degree[a];
    ++degree[b];
  }
  for (int i: range(0, K)) {
    int a, b;
    std::cin >> a >> b;
    --a; --b;
    block[a].push_back(b);
    block[b].push_back(a);
  }
  for (int i: range(0, N)) {
    int ans = dsu.component_size(i) - degree[i] - 1;
    for (int u: block[i]) {
      if (dsu.same_component(i, u)) {
        --ans;
      }
    }
    std::cout << ans << (i + 1 == N ? '\n' : ' ');
  }
  return 0;
}


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Graph;
const int MOD = 1e9 + 7;
const ll INF = 1e9;
const int MAX_V = 1e5 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

long long fac[MAX_N], finv[MAX_N], inv[MAX_N];
// テーブルを作る前処理 from: https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX_N; 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;
}

struct mint {
    // Preparation: MOD is already defined.
    ll x;

    mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint pow(mint m) const {
        return pow(m.x);
    }

    mint inv() const {
        ll a = x, b = MOD, u = 1, v = 0;
        while (b) {
            ll t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        u %= MOD;
        return u;
    }

    mint &operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint &operator-=(const mint a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint &operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

int main() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    COMinit();
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end(), greater<ll>());
    mint sum = 0;
    rep(i, n - k + 1) {
        mint diff = COM(n - 1 - i, k - 1);
        mint ma = (diff * a[i]);
        sum += ma;
    }
    rep(i, n - k + 1) {
        mint diff = COM(n - 1 - i, k - 1);
        mint mi = (diff * a[n - i - 1]);
        sum -= mi;
    }
    out(sum.x);
    return 0;
}


Measured memory_bytes: 3328
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
const LL MOD = 1000000007LL;
LL dp[41][1 << 16];
int main() {
	int N, X, Y, Z;
	cin >> N >> X >> Y >> Z;
	int mask = (1 << (X + Y + Z - 1)) - 1;
	int xyz = (1 << (X + Y + Z - 1)) | (1 << (Y + Z - 1)) | (1 << (Z - 1));
	dp[0][0] = 1;
	for (int i = 0; i < N; i++) {
		for (int bit = 0; bit < (1 << (X + Y + Z - 1)); bit++) {
			for (int j = 1; j <= 10; j++) {
				int nbit = bit << j | (1 << (j - 1));
				if ((nbit&xyz) == xyz) continue;
				(dp[i + 1][nbit&mask] += dp[i][bit]) %= MOD;
			}
		}
	}
	LL ans = 1;
	for (int i = 0; i < N; i++) (ans *= 10) %= MOD;
	for (int bit = 0; bit < (1 << (X + Y + Z - 1)); bit++) {
		ans = (ans - dp[N][bit] + MOD) % MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 20736
#include <stdio.h>
#include <stdlib.h>

int main(){
        int n, data = 1, i, j, num, nump = 0, flag;

        scanf("%d", &n);

        while(data <= n){
                scanf("%d", &num);
                flag = 0;
                for(i = 2 ; i * i <= num ; i += 2){
                        if(i == 2){
                                if(num % i == 0){
                                        flag = 1;
                                        break;
                                }else{
                                        i++;
                                }
                        }
                        if(num % i == 0){
                                flag = 1;
                                break;
                        }
                }
                if(flag != 1)nump++;
                data++;
        }

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

        return 0;
}



Measured memory_bytes: 2104
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

const double eps = 1e-6;
const ll MOD = 1000000007;
const ll INF = 1e15;

int main() {
	ll N, K;
	cin >> N >> K;
	vector<ll> A(N);
	for (int i = 0;i < N;i++)
		cin >> A[i];
	ll mini = INF;
	for (int i = 0;i < N;i++)
		mini = min(mini, A[i]);
	vector<ll> v(1, -1);
	for (int i = 0;i < N;i++)
		if (A[i] == mini)
			v.push_back(i);
	v.push_back(N);
	ll ans = 0;
	ll ok = -1;
	for (int i = 0;i < v.size() - 1;i++) {
		if (v[i + 1] - 1 <= ok)
			continue;
		v[i] = max(v[i], ok);
		ll length = v[i + 1] - v[i] - 1;
		if (length <= 0)
			continue;
		ll now = (length + K - 2) / (K - 1);
		ans += now;
		ok = v[i] + now * (K - 1) + 1;
	}

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


Measured memory_bytes: 1272
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,a[5][14];
	cin>>n;
	for(int e=1;e<=4;e++){
		for(int c=1;c<=13;c++){
			a[e][c]=0;
		}
	}
	for(int i=1;i<=n;i++){
		char egr;
		int eg,crs;
		cin>>egr>>crs;
		if(egr=='S'){
			eg=1;
		}
		else if(egr=='H'){
			eg=2;
		}
		else if(egr=='C'){
			eg=3;
		}
		else if(egr=='D'){
			eg=4;
		}
		a[eg][crs]=1;
	}
	for(int e=1;e<=4;e++){
		for(int c=1;c<=13;c++){
			if(a[e][c]==0){
				char egr;
				if(e==1){
					egr='S';
				}
				else if(e==2){
					egr='H';
				}
				else if(e==3){
					egr='C';
				}
				else if(e==4){
					egr='D';
				}
				cout<<egr<<" "<<c<<endl;
			}
		}
	}
}



Measured memory_bytes: 3084
#include<cstdio>
#include<cstring>

#define MAXN 1000

int main(){
    char c;
    bool N=0,S=0,E=0,W=0;
    do{
        c=getchar();
        N|=c=='N',S|=c=='S',E|=c=='E',W|=c=='W';
    }while(c!='\n');
    if(N==S&&E==W) puts("Yes");
    else puts("No");
}


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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

int	main() {
	int N;
	cin >>N;
	vector<int> A(N, 0);
	for (int i=0; i<N; i++)
		cin >>A.at(i);
	int S0=1;
	int S1=1;
	for (int i=0; i<N; i++) {
		S0 *=3;
		if (0==A.at(i)%2)
			S1 *=2;
	}
	cout <<S0-S1 <<endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct edge{int t,d,c;};
struct st{
  int p,d,c,a;
  st(int p,int d,int c,int a):p(p),d(d),c(c),a(a){}
  bool operator<(const st& s)const{
    return a>s.a;
  }
};
int n,m,c,s,g;
int p[30];
int q[105][55],r[105][55];
int cost[30][30000];
int dp[105];
int e[105][105];
vector<edge> v[105];

void calc(){
  int i,j,k;
  for(k=0;k<n;k++){
    bool used[105];
    //cout << "k:" << k << endl;
    for(j=0;j<c;j++){
      //cout << "j:" << j << endl;
      memset(used,0,sizeof(used));
      priority_queue<st> qu;
      qu.push(st(k,0,j,0));
      while(!qu.empty()){
	st ss=qu.top();qu.pop();
	if(used[ss.p]) continue;
	used[ss.p]=true;	
	//cout <<ss.p<<":"<<ss.c<<":"<<ss.d<<":"<<ss.a<<endl;
	if(!~e[k][ss.p]||e[k][ss.p]>ss.a) e[k][ss.p]=ss.a;
	for(i=0;i<v[ss.p].size();i++){
	  if(v[ss.p][i].c==ss.c){
	    qu.push(st(v[ss.p][i].t,ss.d+v[ss.p][i].d,v[ss.p][i].c,
		       ss.a+cost[v[ss.p][i].c][ss.d+v[ss.p][i].d]
		       -cost[v[ss.p][i].c][ss.d]));
	  }
	}
      }
    }
  }
}

int main(){
  while(cin>>n>>m>>c>>s>>g,n){
    s--;g--;
    int i,j,k,inf=1<<28;
    int x,y,a,b;
    for(i=0;i<105;i++) v[i].clear();
    memset(e,-1,sizeof(e));
    for(i=0;i<m;i++){
      cin>>x>>y>>a>>b;
      x--;y--;b--;
      v[x].push_back((edge){y,a,b});
      v[y].push_back((edge){x,a,b});
    }

    memset(p,0,sizeof(p));
    memset(q,0,sizeof(q));
    memset(r,0,sizeof(r));
    for(i=0;i<c;i++) cin>>p[i];
    for(i=0;i<c;i++){
      for(j=1;j<p[i];j++) cin>>q[i][j];
      q[i][p[i]]=inf;
      for(j=0;j<p[i];j++) cin>>r[i][j];
    }
    memset(cost,0,sizeof(cost));
    for(i=0;i<c;i++){
      k=0;
      for(j=0;j<30000-1;j++){
	if(q[i][k]<=j) k++;
	cost[i][j+1]=cost[i][j]+r[i][k-1];
      }
    }
    
    calc();
    
    memset(dp,-1,sizeof(dp));
    typedef pair<int,int> P;
    priority_queue<P> q;
    q.push(P(0,s));
    while(!q.empty()){
      P p=q.top();q.pop();
      //cout << p.first << ":" << p.second << endl;
      if(~dp[p.second]&&dp[p.second]<=p.first) continue;
      dp[p.second]=p.first;
      for(i=0;i<n;i++){
	if(e[p.second][i]>0&&(!~dp[i]||p.first+e[p.second][i]<dp[i]))
	  q.push(P(p.first+e[p.second][i],i));
      }
    }
    cout << dp[g] << endl;
  }
  return 0;
}

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

int main(){
	int H , W , K;
  cin >> H >> W >> K;
  
  vector<string>c(H);
  for(int i = 0 ; i < H ; i++)cin>>c[i];
  int ans = 0;
  
  for(int i = 0 ; i < (1<<H) ; i++){
  	for(int j = 0 ; j < (1<<W) ; j++){
    int cnt = 0;
      for(int h = 0 ; h<H ; h++){
      	for(int w = 0 ; w < W ; w++){
        	if(i&(1<<h) || j&(1<<w))continue;
          	if(c[h][w]=='#')cnt++;
        }
      }
    
      if(cnt==K)ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    int h[N];
    for (int i=0; i<N; ++i) cin >> h[i];
 
    long long int dp[N];
    dp[0] = 0;
    dp[1] = abs(h[0] - h[1]);
    for(long long i(2);i<N;i++){
    	dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
  	}
 
 
    cout << dp[N-1] << endl;
 
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const int MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n,q;
  cin >> n >> q;
  vector<tuple<int,int,int>> stx(n);
  rep(i,n){
    cin >> get<1>(stx[i]) >> get<2>(stx[i]) >> get<0>(stx[i]);
  }
  sort(stx.begin(),stx.end());
  
  set<P> st;
  rep(i,q){
    int x;
    cin >> x;
    st.emplace(x,i);
  }
  
  vector<int> ans(q,-1);
  rep(i,n){
    int s = get<1>(stx[i]);
    int t = get<2>(stx[i]);
    int x = get<0>(stx[i]);
    //xの昇順で考えてぶつかったら，その人をerase
    auto first = st.lower_bound(P(s-x,0));//引っかかる人
    auto end = st.upper_bound(P(t-x-1,q));//引っかからない人
    
    for(auto it = first; it !=end; ++it) ans[it->second] = x;
    
    st.erase(first,end);
  }
  
  rep(i,q) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 18752
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
inline void write(int x)
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int n=read(),L=read(),sum=n*(n-1)/2+L*n,mn=999999,ans=0;
    for(int i=1;i<=n;i++)
    {
    	int ul=abs(i+L-1);
    	if(ul<mn)mn=ul,ans=sum-i-L+1;
    }pr2(ans);
   	return 0;
}

Measured memory_bytes: 128
def solve():
    n, m, k = map(int, input().split())
    for i in range(n + 1):
        selected = m * i
        for j in range(m + 1):
            if selected + (n - i * 2) * j == k:
                print("Yes")
                return
    print("No")

if __name__=="__main__":
    solve()

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

int main()
{
  int N, K;
  std::cin >> N >> K;
  int l[N];
  for ( int i = 0; i < N; i++ ) std::cin >> l[i];
  std::sort(l, l+N, std::greater<int>());
  
  int sum = 0;
  for ( int i = 0; i < K; i++ ) sum += l[i];
  std::cout << sum << std::endl;
  return 0;
}


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

# define REP(i,n) for (int i=0;i<(n);++i)
# define PER(i,n) for (int i=(N-1);i>=0;--i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

const int MAX = 510000;
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;
}

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

// 素因数分解　O(√n)
map<ll, ll> prime_factor(ll n){
    map<ll, ll> res;
    for(ll i = 2; i * i <= n; i++){
        while(n % i == 0){
            ++res[i];
            n %= i;
        }
    }
    if (n != 1) res[n] = 1;
    return res;
}

long long int gcd(long long int a,long long int b){
    if(a<b){
        long long int tmp=a;
        a=b;
        b=tmp;
    }

    long long int r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

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

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

    ll p = gcd(A, B);

    auto m1 = prime_factorize(p);

    cout << m1.size() + 1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int top, s[1000];

void push(int x)
{
    /*top?????????????????????????????????????????\*/
    s[++top] = x;
}

int pop() 
{
    top--;
    /*top??????????????????????´?????????????*/
    return s[top + 1];
    
}


int main(void) 
{
    int a, b;
    top = 0;
    char s[100];
    
    while( scanf("%s", s) != EOF){
        if ( s[0] == '+'){
            a = pop();
            b = pop();
            push(a + b);
            
        } else if ( s[0] == '-') {
            b = pop();
            a = pop();
            push(a - b);
            
        } else if ( s[0] == '*') {
            a = pop();
            b = pop();
            push(a * b);
            
        } else {
            push(atoi(s));
            
        }
        
    }
    printf("%d\n", pop());
    return 0;
    
}

Measured memory_bytes: 548
#include <stdio.h>

int main() {

  int i, n;

  for(i	= 1; i <= 10000;	i++) {
    scanf("%d",	&n);
    if(n == 0)
      break;
    else
      printf("Case %d: %d\n", i, n);
  }

  return 0;
}

Measured memory_bytes: 596
#クエリにO(1)で返すためのテーブルを用意
import numpy as np
MAX = int(10e5+1)
List = list(range(2,MAX))
P = []
while len(List) > 0:
    p = List[0]
    if p >= np.sqrt(MAX): break
    P.append(p)
    List = [x for x in List if x % p != 0]
P = set(P+List)

Ans = [0] * MAX
cnt = 0
for i in range(1,MAX):
    if i in P and (i+1)//2 in P:
        cnt += 1
    Ans[i] = cnt

q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    print(Ans[r]-Ans[l-1])

Measured memory_bytes: 70380
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var cin = new Scanner();
			int n = cin.Int();
			int k = cin.Int();
			var x = cin.ArrayLong(n);

			long ans = long.MaxValue;
			for (int i = 0; i <= n - k; i++) {
				long l = x[i];
				long r = x[i + k - 1];

				long temp1 = Math.Abs(l) + Math.Abs(r - l);
				long temp2 = Math.Abs(r - l) + Math.Abs(r);
				ans = Math.Min(ans, temp1);
				ans = Math.Min(ans, temp2);
			}

			Console.WriteLine(ans);
		}
	}

	public class Scanner
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private string[] buf_;
		private int index_;

		public Scanner()
		{
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = Console.ReadLine();
			while (st == "") {
				st = Console.ReadLine();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 20960
// ABC108
// A - Pair
#include<bits/stdc++.h>

using namespace std;

int main(){
    int k;
    cin >> k;
    if(k%2==0) cout << (k/2)*(k/2) << endl;
    else cout << (k/2)*(k/2+1) << endl;
    return 0;
}


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


int main() {
	int a1,a2,a3;
	cin >> a1>>a2>>a3;

	if (a1+a2+a3>=22) {
		cout << "bust" << endl;
	}
	else if (a1 + a2 + a3 <= 21) {
		cout << "win" << endl;
	}
}

Measured memory_bytes: 256
from math import gcd

n = int(input())
ration = dict()
used = dict()
for _ in range(n):
    a, b = map(int, input().split())
    if a == 0 or b == 0:
        if a == b == 0:
            r = '0'
        elif a == 0:
            r = '0a'
        else:
            r = '0b'
    else:
        s = '-' if (a < 0) ^ (b < 0) else '+'
        a = abs(a)
        b = abs(b)
        g = gcd(a, b)
        r = f'{s} {a//g} {b//g}'
    ration[r] = ration.get(r, 0) + 1
    used[r] = 0

res = 1
mod = 10**9+7
add = 0
for k, v in ration.items():
    if used[k]:
        continue
    if k == '0':
        add += v
        used[k] = 1
    elif k == '0a' or k == '0b':
        res *= 2**ration.get('0a', 0) + 2**ration.get('0b', 0) - 1
        used['0a'] = used['0b'] = 1
    else:
        r = k.split()
        l = f'{"-" if r[0]=="+" else "+"} {r[2]} {r[1]}'
        res *= 2**v + 2**ration.get(l, 0) - 1
        used[k] = used[l] = 1
    res %= mod

res += add
res -= 1
if res < 0:
    res += mod
print(res)


Measured memory_bytes: 83244
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define to_ll(b) stoll(b)
#define MOD 1000000007
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	string s; cin>>s;
	map<int,int> mp;
	int a=0;
	rep(i,0,s.size()){
		if(s[i]=='A'){
			a=i;
			break;
		}
	}
	rep(i,0,s.size()){
		if(s[i]=='Z') mp[2]=i;
	}
	int cnt=0;
	rep(i,a,mp[2]+1){
		cnt++;
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 640
//BISMILLAHIR RAHMANIR RAHIM
//ALLAH HU AKABR
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
int a[6];
for(int i=0;i<5;i++)
{
     cin>>a[i];
}
int ans=0;
for(int i=0;i<5;i++)
{
     if(a[i]==0)
     {
          ans=i+1;
          break;
     }
}
cout<<ans<<endl;
}

Measured memory_bytes: 3532
#include<stdio.h>
int main()
{
	int d=0,t=0,e=0,a,b,c,A,B,C,h;
	while(1){
		scanf("%d%d%d",&a,&b,&c);
		if(a>b&&a>c){
			C=a;
			A=b;
			B=c;
		}else if(b>a&&b>c){
			B=c;
			C=b;
			A=a;
		}else{
			A=a;
			B=b;
			C=c;
		}
		if(A+B<=C){
			printf("%d %d %d %d\n",d+t+e,t,e,d);
			break;
		}
		h=A*A+B*B-C*C;
		if(h>0){
			e++;
		}else if(h<0){
			d++;
		}else{
			t++;
		}
	}
	return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main {
	public static void main(String[] args){

		//????????£????????????
		Scanner sc = new  Scanner(System.in);

		//??? ??? ?????????
		int  n = sc.nextInt();
		//m ??? ?????????
		int m = sc.nextInt();
		//????????????
		int l = sc.nextInt();
		//??????
		int [][] A = new int[n][m];
		//B??????
		int [][] B = new int[m][l];
		//C??????????´?
		long [][] C = new long[n][l];
		//A??????
		//A??????
		for(int i =0;i<n;i++){
			//A??????
			for(int j =0; j<m;j++){
				//A??????i ??????
				A [i][j]  = sc.nextInt();
			}
		}
		//B?????? ???
		for(int j=0; j<m;j++){
			//B?????? ???
			for(int k =0;k<l; k++){
				B[j][k]=sc.nextInt();
			}
		}
		//C????¨???????
		for(int i =0; i<n;i++){
			for(int j=0; j<m;j++){
				for(int k =0; k<l;k++){
					C[i][k] += A[i][j] *B[j][k];
				}
			}
		}
		//C???????????????
		for(int i =0;i<n;i++){
			for(int k =0; k<l;k++){
				System.out.print(C[i][k]);
				if(k != (l-1)){
					System.out.print(" ");
				}
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 55044
#include<bits/stdc++.h>
using namespace std;
#define inf 100000000000000000
#define ll long long int
#define pb push_back
#define f first
#define s second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}

int main(){
	//mahakal();fast;
	ll n , x;
	cin>>n;
	ll ans = 0 ,mn=10000000000;
	ll arr[n];
	for(ll i=0;i<n;i++)cin>>arr[i];
	for(ll i=1 ;i<=1000 ;i++){
		ll ans =0 ;
		for(ll j=0;j<n;j++){
			ans = ans +abs(i-arr[j])*abs(i-arr[j]);
		}
		mn=min(mn , ans );
	}
	cout<<mn;

	return 0;
}

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

int main(){
	int N, K, S=0;
	cin >> N >> K;
	int l[N];
	for(int i=0; i<N; i++) cin >> l[i];
	sort(l, l+N, greater<int>());
	for(int i=0; i<K; i++) S += l[i];
	cout << S << endl;
}

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

int main()
{
    int n;
    std::cin >> n;
    std::vector<long long> h(n);
    std::priority_queue<long long> q;
    for (int i = 0; i < n; i++) {
        std::cin >> h[i];
    }

    int c = 0;
    for (int i = n - 1; i >= 1; i--) {
        if (h[i] <= h[i - 1]) {
            c++;
            continue;
        }
        q.push(c);
        c = 0;
    }
        q.push(c);

    std::cout << q.top() << std::endl;
    return 0;
}


Measured memory_bytes: 2168
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def main():
    N = int(input())
    s = input().split()
    
    for i in s:
        if i == "Y":
            print("Four")
            sys.exit()
            
    print("Three")
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll N,P;
    cin >> N >> P;
    ll A[N];

    bool even = true;
    for(int i = 0;i<N;i++){
        cin >> A[i];
        if(!(even && A[i]%2 == 0)) even = false;
    }
    ll ans = pow(2,N-1);
    if(even && P == 1) ans = 0;
    else if(even && P == 0) ans = pow(2,N);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <cassert>

using namespace std;

typedef long long ll;
typedef ll li;
typedef pair<int,int> PI;
#define EPS (1e-10L)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
void pkuassert(bool t){t=1/t;};
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};

ll dp[2][256];
int C[16];
int x[20000];
int N,M;

void solve(){
  rep(i,M) cin >> C[i];
  rep(i,N) cin >> x[i];
  memset(dp,-1,sizeof(dp));
  dp[0][128]=0;
  rep(i,N){
    int cu=i&1;
    int ne=(i+1)&1;

    rep(j,256){
      if(dp[cu][j]==-1) continue;
      //cout << i << ' ' << dp[cu][j] << endl;
      rep(k,M){
        int nx=j+C[k];
        nx=min(nx,255);
        nx=max(nx,0);
        int di=nx-x[i];
        if(dp[ne][nx]==-1 || dp[ne][nx]>dp[cu][j]+di*di)
          dp[ne][nx]=dp[cu][j]+di*di;
      }
      dp[cu][j]=-1;
    }
  }
  
  ll ans=1LL<<50LL;
  rep(i,256) if(dp[N&1][i]!=-1) ans=min(ans,dp[N&1][i]);
  cout << ans << endl;
}

int main(int argc, char *argv[])
{
  while(cin >> N >> M && N && M) solve();
  return 0;
}

Measured memory_bytes: 1236
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int N; cin >> N;
    vector<int> W(N, 0);
    for (int i = 0; i < N; ++i) cin >> W[i];
    int a = 0, b = 0, i = 0, j = N - 1;
    while (i <= j) {
        if (a <= b) {
            a += W[i], i++;
        }
        else {
            b += W[j], j--;
        }
    }
    printf("%d\n", abs(a - b));
}


Measured memory_bytes: 3728
n, m = map(int, input().split())
a = list(map(int, input().split()))

sumList = [0] * (n + 1)
sumList[0] = 0
number = {}
number[0] = 0

for i in range(1, n + 1):
    sumList[i] = (sumList[i - 1] + a[i - 1]) % m
    number[sumList[i]] = 0

for i in range(n + 1):
    number[sumList[i]] += 1

ans = 0

for key, value in number.items():
    ans += value * (value - 1) // 2

print(ans)


Measured memory_bytes: 15444
N = int(input())
XL = [tuple(map(int, input().split())) for _ in range(N)]
XL.sort(key=lambda x: x[0] + x[1])

ans = 0
current = float('-inf')
for x, l in XL:
    if current <= x - l:
        current = x + l
        ans += 1
print(ans)



Measured memory_bytes: 63748