akhauriyash/Code-Regression huggingface dataset:
// Created by ...
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'

#define vll vector< ll >
#define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= b; ++i)
#define fo(i,a,b) for(int i = a; i<= b; ++i)
#define pii pair<ll,ll> 
#define vec(a) vector<a >
#define all(a) a.begin(),a.end()
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;
using ll = long long;
ll md=MD;

ll exp(ll a,ll b){ll r=1ll;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b>>=1;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll Min(ll a,ll b){if(a<b)return a; return b;}
ll Max(ll a,ll b){if(a>b)return a; return b;}
int32_t main() {
    IOS;

        ll n;
        cin>>n;
        vll a(n),b(n);
        rep(i,0,n-1) cin>>a[i]>>b[i];
        sort(all(a));sort(all(b));
        int minx,maxx;
        if(n&1)
        {
        	maxx=b[n/2];
        	minx=a[n/2];
        }
        else
        {
        	maxx=b[n/2]+b[n/2-1];
        	minx=a[n/2]+a[n/2-1];
        }
        cout<<maxx-minx+1;



        cout<<'\n';
    return 0;
}

Measured memory_bytes: 6368
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	long long n,m,k;
	cin>>n>>m>>k;
	bool check=false;
	rep(i,n+1){
		rep(j,m+1){
			if(j*n+i*m-i*j*2==k)check=true;
		}
	}	
	cout<<((check)?"Yes":"No")<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
constexpr int OFFSET = 12'720;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, x, d;
    cin >> n >> x >> d;
    if (d == 0) {
        cout << (x != 0 ? n + 1 : 1) << endl;
        return 0;
    }
    int g = __gcd(x, d);
    x /= g;
    d /= g;
    if (d < 0) {
        d = -d;
        x = -x;
    }
    long long ans = 0;
    auto sum = [&](int a, int b) {
        return 1LL * (a + a + b - 1) * b / 2;
    };
    for (int i = 0; i < d; ++i) {
        set<pair<long long, long long>> s;
        for (int j = i; j <= n; j += d)
            s.emplace(1LL * j / d * x + sum(0, j), 1LL * j / d * x + sum(n - j, j) + 1);
        long long r = -1E18;
        for (auto p : s) {
            ans += max(0LL, p.second - max(r, p.first));
            r = max(r, p.second);
        }
    }
    cout << ans << endl;
    return 0;
}

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


int main(){
  int N, M, C;
  vector<int> B(20);
  vector<vector<int>> A(20, vector<int>(20));

  cin >> N >> M >> C;
  for(int i=0; i<M; i++) cin >> B[i];
  for(int i=0; i<N; i++){
    for(int j=0; j<M; j++) cin >> A[i][j];
  }

  int ans = 0;
  for(int i=0; i<N;i++){
    int x = C;
    for(int j=0; j<M; j++) x +=  A[i][j]*B[j];
    if(x > 0) ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define DEBUG_MODE
#define endl '\n'
#ifdef DEBUG_MODE
#define DEBUG(...) debug_func_mult(split_names(#__VA_ARGS__), __VA_ARGS__)
#define DEBUG_ENDL endl << flush
#define DEBUG_SEPARATOR_LINE cout<<"=================\n"
#else
#define DEBUG(...) 0
#define DEBUG_ENDL 0
#define DEBUG_SEPARATOR_LINE 0
#endif
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
#define DEBUG_ENDL_S(S) ((S).size() ? "\n" : "") << flush;

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }

string to_string(const string &s) { return s; }

template <typename T, typename U>
string to_string(const P<T, U> &p) {
    string ret = "(";
    ret += to_string(p.first);
    ret += ", ";
    ret += to_string(p.second);
    ret += ")";
    return move(ret);
}

template <typename T>
string to_string(const V<T> &v) {
    string ret = "{";
    for(const T &t : v) {
        ret += to_string(t);
        ret += ", ";
    }
    ret += "}";
    return move(ret);
}

template <typename T>
void debug_func(const T &t, const string &s = "") {
    if(s.size()) cout << s << " = ";
    cout << to_string(t) << DEBUG_ENDL_S(s);
}

template <typename T>
void debug_func_mult(int idx, const V<string> &names, const T &t) {
    debug_func(t, names[idx]);
}

template <typename T>
void debug_func_mult(const V<string> &names, const T &t) {
    debug_func(t, names[0]);
}

template <typename Head, typename... Tail>
void debug_func_mult(int idx, const V<string> &names, const Head &head, const Tail&... args) {
    debug_func(head, names[idx]);
    debug_func_mult(idx + 1, names, args...);
}

template <typename Head, typename... Tail>
void debug_func_mult(const V<string> &names, const Head &head, const Tail&... args) {
    debug_func(head, names[0]);
    debug_func_mult(1, names, args...);
}

V<string> split_names(string &&s) {
    replace(ALL(s), ' ', ',');
    V<string> ret;
    istringstream ss(s);
    string t;
    while(getline(ss, t, ',')) if(t.size()) ret.push_back(move(t));
    return move(ret);
}

inline void init_io() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(30);
}

int main() {
    init_io();
    ll a, b, c;
    cin >> a >> b >> c;
    cout << (a == b && b == c && c == a ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
x = sorted(list(map(int, input().split())))
a, b, c = x

cnt = 0
while a <= b-2:
    a += 2
    cnt += 1

while a <= c-1 or b <= c-1:
    a += 1
    b += 1
    cnt += 1

if a == b == c:
    print(cnt)
else:
    print(cnt + 1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){long long int h,w,i,j,m=1000000007;
cin>>h>>w;
long long int dp[h+1][w+1];
memset(dp,0,sizeof(dp));
int g[h+1][w+1];
char ch;
for(i=1;i<=h;i++){
    for(j=1;j<=w;j++){
    cin>>ch;
    if(ch=='#'){
        g[i][j]=1;
    }
       else{g[i][j]=0;} 
    }}
    dp[1][1]=1;
    for(i=1;i<=h;i++){
        for(j=1;j<=w;j++){
            
            dp[i][j]=dp[i][j-1]+dp[i-1][j];
            dp[i][j]=dp[i][j]%m;
            if(g[i][j]){dp[i][j]=0;}
            if(i==1&&j==1){dp[i][j]=1;}
        }
    }
    cout<<dp[h][w];
    return 0;}

Measured memory_bytes: 12032
const main = (lines: string) => {
  const data = lines.split("\n");
  const N = parseInt(data[0]);
  const weights = data[1].split(" ").map(str => parseInt(str));
  let S1, S2;
  let ans;


  for (let i = 1; i < N; i++) {
    let temp;
    S1 = weights.slice(0, i).reduce((a, x) => a+=x, 0)
    S2 = weights.slice(i, N).reduce((a, x) => a+=x, 0)

    temp = Math.abs(S1 - S2);

    if (ans === undefined || ans > temp) {
      ans = temp
    }
  }

  console.log(ans)
};

main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define MAX 1e9
#define MIN -1e9
#define mod 1000000007
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define mxn 300005
using namespace std;

int main()
{
    FLASH
    int n;
    cin >> n;
    int ans = 0;
    int cnt = 0;
    for(int i = 1; i <= n; i++){
        int x;
        cin >> x;
        cnt += (i % 2 && x % 2);
    }
    cout << cnt;
    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = long long;
using u32 = unsigned long long;
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using vi32 = vector<i32>;
using vu32 = vector<u32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf64 = vector<f64>;
using vstr = vector<string>;
using vvi32 = vector<vi32>;
using vvu32 = vector<vu32>;
using vvi64 = vector<vi64>;
using vvu64 = vector<vu64>;
using vvf64 = vector<vf64>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

i64 dp[110][100010];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  int n, W;
  cin >> n >> W;
  vi32 v(n), w(n);
  rep(i, n) cin >> w[i] >> v[i];
  rep(i, 110) rep(j, 100010) dp[i][j] = -1e9;
  dp[0][0] = 0;
  rep(i, n) rep(j, W + 1) {
    if (dp[i][j] == -1e9) continue;
    amax(dp[i + 1][j], dp[i][j]);
    if (j + w[i] > W) continue;
    amax(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
  }
  i64 ans = 0;
  rep(i, W + 1) amax(ans, dp[n][i]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 86272
#include<bits/stdc++.h>
#define endl "\n"
#define ll long long int
#define N (ll)(1e9+7)
#define T int
#define P pair<T,T>
#define umap unordered_map<T,T>
#define uset unordered_set<T>
#define rep(i,n) for(i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define print(v) for(auto x:v) cout<<x<< " "
#define pb push_back
using namespace std;
#define _USE_MATH_DEFINES

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    double r;
    cin>>r;
    cout<<2*M_PI*r<<endl;


    return 0;
}


Measured memory_bytes: 3796
import java.util.Scanner;
 
public class Main {
    private static int n;
    private static int q;
    private static int[] p;
    private static int[] rank;
 
    private static boolean same(int x, int y) {
        return findSet(x) == findSet(y);
    }
 
    private static void unite(int x, int y) {
        int i = findSet(x);
        int j = findSet(y);
 
        if (i == j) return;

        if (rank[i] > rank[j]){
            p[j] = p[i];
        }
        else {
            p[i] = p[j];
            rank[j]++;

        }	
    }
 
    private static int findSet(int i) {
        while (i != p[i]){
            p[i] = p[p[i]];
            i = p[i];
        }
        return i;
    }
 
    private static void DisjointSet() {
        p = new int[n];
        rank = new int[n];
 
        for (int i = 0; i < n; i++) {
            p[i] = i;
            rank[i] = 0;
        }
    }
 
 
    public static void main (String[] args){
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        q = scanner.nextInt();
 
        DisjointSet();
        for (int i = 0; i < q; i++) {
            int com = scanner.nextInt();
            int x = scanner.nextInt();
            int y = scanner.nextInt();
 
            if (com == 0){
                unite(x, y);
            }
            if (com == 1){
                if (same(x, y)){
                    System.out.println(1);
                }else{
                    System.out.println(0);
		}
            }
        }
    }
}

Measured memory_bytes: 102456
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
#define LL long long
using namespace std;
const int N=1e5+10;
int n,x[N],m,a[N],di[N],top,stk[N],pos[N],vis[N];
LL k,ans[N];
template<typename I> inline void read(I &ot){
	I ch=getchar(), x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();	}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();	}
	ot=x*f;}
template<typename I, typename... U> inline void read(I &x,U&... y){read(x); read(y...);}
template<typename I>inline void swp(I&a,I&b){a^=b; b^=a; a^=b;}
int main()
{
	//freopen("Rabbit Exercise.in","r",stdin);
	read(n);
	for(RG int i=1;i<=n;i++) read(x[i]), di[i]=x[i]-x[i-1], pos[i]=i;
	read(m,k);
	for(RG int i=1;i<=m;i++) read(a[i]), swp(pos[a[i]],pos[a[i]+1]);
	for(RG int i=1;i<=n;i++)
	 if(!vis[i])
	 {
		top=0;
		for(RG int j=i;!vis[j];j=pos[j]) stk[++top]=j, vis[j]=1;
		for(RG int j=1;j<=top;j++) ans[stk[j]]=di[stk[(LL)(j+k-1)%top+1]];
	 }
	for(RG int i=1;i<=n;i++) printf("%lld\n",ans[i]+=ans[i-1]);
	return 0;
}

Measured memory_bytes: 4352
{-# LANGUAGE BangPatterns #-}
import Data.List
import Control.Applicative

listsumcut :: [Int]->[Int]->[Int]
listsumcut [x] accum =accum
listsumcut !(x:xs) !(a:accum) = listsumcut xs $ (a+2*x):a:accum

solver (x:y:[]) = abs (x-y)
solver (x:xs) = minimum $ map abs $ listsumcut xs [x-(sum xs)]


main :: IO ()
main = do
    -- スペース区切り整数の入力
    getLine
    list <- map read . words <$> getLine
    -- 出力
    putStrLn $ show $ solver list



Measured memory_bytes: 111996
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int n;

int main()
{
	scanf("%d",&n);
    if(n==0){
        cout << "1\n";
    }else if(n==1){
        cout << "2\n";
    }else if(n==2){
        cout << "1\n";
    }else{
        cout << "0\n";
    }
	return 0;
}

Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = (ll)1e9 + 7;
  
int main(){
  ll n,k;
  cin >> n >> k;
  auto a = vector<int>(n,0);
  
  for (int i = 0; i < n; i++)
  {
      cin >> a[i];
  }

  ll ans = 0;
  for (int i = 0; i < n; i++)
  {
      for (int j = 0; j < n; j++)
      {
       		if (a[i] <= a[j]) continue;
			ans += k * (k - 1) / 2;
			if (i < j) ans += k;
			ans %= MOD;
      }
    }
    cout << ans;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
using namespace std;
typedef long long LL;
const int MAXN = 100005;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

namespace ModCalculator {
	const int MOD = 998244353;
	inline void Inc(int &x, int y) {
		x += y; if (x >= MOD) x -= MOD;
	}
	inline void Dec(int &x, int y) {
		x -= y; if (x < 0) x += MOD;
	}
	inline int Add(int x, int y) {
		Inc(x, y); return x;
	}
	inline int Sub(int x, int y) {
		Dec(x, y); return x;
	}
	inline int Mul(int x, int y) {
		return 1LL * x * y % MOD;
	}
}
using namespace ModCalculator;
 
inline int ksm(int x, int k) {
    int ret = 1;
   	for (; k; k >>= 1) {
        if (k & 1) ret = Mul(ret, x);
        x = Mul(x, x);
    }
    return ret;
}

int n, tim, vis[MAXN], pw[MAXN];

struct Graph {
	vector<int> e[MAXN];
	int m, sg[MAXN], mxsg, sum[MAXN];
	
	void build() {
		read(m);
		for (int i = 1, u, v; i <= m; ++i) {
			read(u); read(v);
			e[min(u, v)].push_back(max(u, v));
		}
		for (int u = n; u >= 1; --u) {
			++tim;
			for (auto v : e[u]) {
				vis[sg[v]] = tim;
			}
			while (vis[sg[u]] == tim) {
				++sg[u];
			}
			Inc(sum[sg[u]], pw[u]);
			mxsg = max(mxsg, sg[u]);
		}
	}
} g1, g2, g3;

void init() {
	read(n);
	int p18 = ksm(10, 18);
	pw[0] = 1;
	for (int i = 1; i <= n; ++i) {
		pw[i] = Mul(pw[i - 1], p18);
	}
	g1.build();
	g2.build();
	g3.build();
}

void solve() {
	int ans = 0;
	for (int i = 0; i <= g1.mxsg; ++i) {
		for (int j = 0; j <= g2.mxsg; ++j) {
			Inc(ans, Mul(Mul(g1.sum[i], g2.sum[j]), g3.sum[i ^ j]));
		}
	}
	printf("%d\n", ans);
}

int main() {
	init();
	solve();
	return 0;
}


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

int main(){
    int N, Y;
    cin >> N >> Y;
    vector<int64_t> A(2*N), S(2*N+1);
    for(int i=0; i<N; i++){
        cin >> A[i];
        A[i+N] = A[i];
    }
    for(int i=0; i<2*N; i++){
        S[i+1] = S[i] + A[i];
    }
    int64_t L = accumulate(A.begin(), A.end(), 0LL) / 10 - Y;
    int64_t ans = 0;
    for(int s=N; s>=0; s--){
        int t = s+N;
        int64_t dp[601][6] = {0};
        dp[s][0] = 1;
        for(int i=s; i<t; i++) for(int j=i+1; j<=t; j++) if(S[j] - S[i] >= L) for(int k=0; k<5; k++){
            if(k == 0 && j <= N) continue;
            dp[j][k+1] += dp[i][k];
        }
        ans += dp[t][5];
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3144
def solve(n, arr):
    # Firstly sort the array to reduce amount of calculation
    arr.sort()

    ans = 0

    for (i, _) in enumerate(arr):
        for j in range(i + 1, len(arr)):
            for k in range(j + 1, len(arr)):
                if arr[i] != arr[j] and arr[i] != arr[k] and arr[j] != arr[k]:
                    if arr[i] + arr[j] > arr[k]:
                        ans += 1
    return ans


if __name__ == "__main__":
    n = int(input())
    arr = list(map(int, input().split(' ')))
    print(solve(n, arr))

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

for i in range(0, n):
    if a[i] == 0:
        print(0)
        exit(0)

ans = 1
for i in range(0, n):
    ans = ans * a[i]
    if ans > 10 ** 18:
        print(-1)
        exit(0)

print(ans)


Measured memory_bytes: 21684
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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; }

__int128 read_int128() {
  string s; cin >> s;
  __int128 res = 0;
  for(char c : s) {
    res = res * 10 + int(c - '0');
  }
  return res;
}

//ミョ(-ω- ?)
int main() {
    auto n = read_int128();
    vector<__int128> a(n,0);
    bool b = false;
    rep(i,n){
      a[i] = read_int128();
      if(a[i] == 0)b = true;
    }
    sort(a.begin(),a.end());
    if(b){
        cout << 0 << endl;
    }else{
        __int128 pro = 1;
        for(auto i : a){
            pro *= i;
            if(pro > 1000000000000000000){
                cout << -1 << endl;
                return 0;
            }
        }
        cout << (long long)pro << endl;
    }
    return 0;
}

Measured memory_bytes: 4812
import collections
import itertools
import sys
import time

def getint(): return int(input())
def getints(): return list(map(int, input().split()))

s = input()
n = len(s)
place_pos = n - 1


def eval_expr(expr):
    expr = expr.split("+")
    res = 0
    for s in expr:
        res += int(s)
    return res

res = 0
for h in range(1 << place_pos):
    expr = s[0]
    for i in range(place_pos):
        if h >> i & 1:
            expr = expr + "+"
        expr += s[i + 1]
    res += eval_expr(expr)

print(res)


Measured memory_bytes: 3316
n, k = map(int, input().split())
tds = []
for i in range(n):
    t, d = map(int, input().split())
    tds.append((d,t))
tds.sort(reverse=True)
cnt = k
hand = []
hand_throw = []
hs = {}
subs = []
rs = {}
v_t = {}
res = 0
for i in range(n):
    if cnt > 0:
        if tds[i][1] in hs:
            hs[tds[i][1]] += 1
            hand_throw.append(tds[i][0])
        else:
            hs[tds[i][1]] = 1
            hand.append(tds[i][0])
        cnt -= 1
        res += tds[i][0]
    else:
        if not tds[i][1] in rs and not tds[i][1] in hs:
            rs[tds[i][1]] = 1
            subs.append(tds[i][0])
    if not tds[i][1] in v_t:
        v_t[tds[i][1]] = 1
subs.sort()
v_hs = len(hs)
v_t = len(v_t)
res += pow(v_hs,2)
final_res = res
while v_hs+1 <= k and v_hs+1 <= v_t:
    res += subs.pop() - hand_throw.pop() - pow(v_hs,2) + pow(v_hs+1,2)
    final_res = max(final_res,res)
    v_hs += 1
print(final_res)

Measured memory_bytes: 35396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
ll n,a[maxn],tree[maxn*2],pre[maxn*2],l,r;
void add(int x,ll v){
	for(int i=x;i<=2*maxn;i+=i&-i)
    	tree[i]+=v;
}
ll ask(int x){
    ll ans=0;
    for(int i=x;i>0;i-=i&-i)
    	ans+=tree[i];
    return ans;
}
bool check(int mid){
	memset(tree,0,sizeof(tree));
	pre[0]=0;
	ll ans=0;
	for(int i=1;i<=n;++i)
		pre[i]=pre[i-1]+(a[i]>=mid?1:-1);
	for(int i=0;i<=n;++i){
		ans+=ask(pre[i]+maxn); 
		add(pre[i]+maxn,1);
	}
	return ans>=n*(n+1)/4;
}
int main(){
	cin>>n;
	for(int i=1;i<=n;++i){
	 	cin>>a[i];
	 	r=max(r,a[i]);
    }
    while(l<=r){
    	int mid=(l+r)>>1; 
    	if(check(mid))l=mid+1;
		else r=mid-1; 
    }
    cout<<r;
	return 0;
} 


Measured memory_bytes: 3328
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for (int i = -1000; i <= 1000; i++) {
            for (int j = -1000; j <= 1000; j++) {
                long tmp = i;
                for (int k = 0; k < 4; k++) {
                    tmp *= i;
                }
                long tmp2 = j;
                for (int k = 0; k < 4; k++) {
                    tmp2 *= j;
                }
                
                if (tmp - tmp2 == n) {
                    // System.out.println(tmp);
                    // System.out.println(tmp2);
                    System.out.println(i + " " + j);
                    return;
                }
            }
        }
    }
}


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

MOD = 1000000007


def main():
    n, m = [int(i) for i in input().split()]
    a = {int(input()) for _ in range(m)}
    steps = [0] * (n + 1)
    steps[0] = 1

    for now in range(n):
        for next_ in range(now + 1, min(now + 2, n) + 1):
            if next_ not in a:
                steps[next_] += steps[now] % MOD
                steps[next_] %= MOD
    print(steps[-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 47192
n = int(input())
a = list(map(lambda x: int(x)+1, input().split()))
MOD = 1000000007

up = [0] * (n+1)
up[0] = 3
p = 1
for i in a:
    if up[i - 1] < up[i]:
        print(0)
        exit()
    p = (p * (up[i - 1] - up[i]) % MOD)
    up[i] += 1

print(p % MOD)


Measured memory_bytes: 52844
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int n;
  string s;
  cin >> n;
  int m = n;
  int count = 0;
  for(int i=0; i<m; i++) {
    s = to_string(n);
    if(s.size()%2 == 1) count++;
    n--;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3696
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


LL powmod(LL x, LL y){
	LL a = 1;
	while(y){
		if(y & 1){ a = a * x % MOD; }
		y >>= 1;
		x = x * x % MOD;
	}
	return a;
}

LL solve(LL n, LL k){
	vector<LL> divs;
	if(n & 1){
		for(LL i = 1; i * i <= n; i += 2){
			if(n % i == 0){
				divs.push_back(i);
				LL t = n / i;
				if(i != t && t & 1){ divs.push_back(t); }
			}
		}
	}
	else{
		LL m = n / 2;
		for(LL i = 1; i * i <= m; ++i){
			if(m % i == 0){
				divs.push_back(i);
				if(i * i != m){ divs.push_back(m / i); }
			}
		}
	}
	sort(ALL(divs));
	int sz = divs.size();
	vector<LL> cnt(sz);
	LL ans = 0;
	for(int i = 0; i < sz; ++i){
		LL x = cnt[i] % MOD;
		LL y;
		if(n & 1){
			y = powmod(k, (divs[i] + 1) / 2);
		}
		else{
			y = powmod(k, divs[i]);
		}
		x = (x + y + MOD) % MOD;
		cnt[i] = x;
		ans = (ans + divs[i] * x) % MOD;
		
		for(int j = i + 1; j < sz; ++j){
			if(divs[j] % divs[i] == 0){
				cnt[j] -= x;
			}
		}
	}
	return ans;
}

void mainmain(){
	LL n, k;
	cin >> n >> k;
	LL ans = (solve(n, k) % MOD + MOD) % MOD;
	cout << ans << endl;
}



}
int main() try{
//	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


Measured memory_bytes: 256
//Mahir Ratanpara (DA-IICT)
#include<bits/stdc++.h>
using namespace std;
#define Ff(i,a,n) for(i=a;i<n;i++)
#define Fr(i,a,n) for(i=a;i>n;i--)
#define ll long long
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef pair<ll, ll>	pa;
typedef vector<ll>		vc;
typedef vector<pa>		vp;
typedef vector<vc>		vvc;
int mpow(int base, int exp); 
void ipgraph(ll n,ll m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vc g[N];

int main() {
    FAST;
    ll t, i, j, k, p, q,l,r, x, y, u, v, n, m;
    cin>>n;
    ll a[n][3];
    Ff(i,0,n)
    cin>>a[i][0]>>a[i][1]>>a[i][2];

    ll dp[n][3];
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    Ff(i,1,n)
    {
        dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=a[i][2]+max(dp[i-1][0],dp[i-1][1]);
    }

    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(ll n, ll m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=1000000007;

int N,M;
int X[111111],Y[111111];

int calc(int n,int x[]){
    int ret=0;
    int sum=0;
    for(int i=0;i<n;i++){
        ret=(ret+i*x[i]-sum+mod)%mod;
        sum=(sum+x[i])%mod;
    }
    return ret;
}

signed main(){
    cin>>N>>M;
    rep(i,N)cin>>X[i];
    rep(i,M)cin>>Y[i];

    int sumX=calc(N,X);
    int sumY=calc(M,Y);

    cout<<sumX*sumY%mod<<endl;
    return 0;
}


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

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

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> x_s(n);
    for (auto i = 0; i < n; i++)
    {
        cin >> x_s[i];
    }
    vector<int> sub(n);
    for (auto i = 0; i < n; i++)
    {
        sub[i] = abs(x_s[i] - x);
    }
    int ans;
    for (auto i = 0; i < n; i++)
    {
        if (i==0) {
            ans = sub[i];
        }
        else
        {
            ans = gcd(ans, sub[i]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4036
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()


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

    int n=s.size();
    set<string> st;
    rep(i,n){
        for(int j=1;j<=min(n-i,k);j++){
            string t=s.substr(i,j);
            st.insert(t);
        }
    }

    int num=1;
    for(auto e : st){
        if(num==k){
            cout<<e<<endl;
            return 0;
        }
        num++;
    }

}



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

using namespace std;
using ll = long long;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount


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

    ll ans = 1e15;
    for (int to_a = 0; to_a < n; ++to_a) {
        for (int to_b = 0; to_b < n; ++to_b) {
            if(to_a==to_b)continue;
            for (int to_c = 0; to_c < n; ++to_c) {
                if(to_a==to_c || to_b==to_c)continue;
                vector<int> kouho;
                for(int i = 0;i<n;i++){
                    if(i!=to_a&&i!=to_b&&i!=to_c)kouho.push_back(len[i]);
                }

                for(int i=0;i<(1<<(2*(n-3)));i++) {
                    ll pa = len[to_a], pb = len[to_b], pc = len[to_c];
                    ll used_mp = 0;
                    for (int j = 0; j < n - 3; j++) {
                        if ((i >> (2 * j)) % 4 == 1) {
                            pa += kouho[j];
                            used_mp+=10;
                        } else if ((i >> (2 * j)) % 4 == 2) {
                            pb += kouho[j];
                            used_mp+=10;
                        } else if ((i >> (2 * j)) % 4 == 3) {
                            pc += kouho[j];
                            used_mp+=10;
                        }
                    }
                    ans = min(ans, abs(a - pa) + abs(b - pb) + abs(c - pc)+used_mp);
                }
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

typedef unsigned long long UL;
typedef long long LL;
#define LP(i, a, b) for (int i = int(a); i < int(b); i++)
#define LPE(i, a, b) for (int i = int(a); i <= int(b); i++)
typedef pair<int, int> PII;
typedef vector<vector<PII> > WAL;
typedef vector<vector<int> > SAL;
#define Ep 1e-7

#define INF 1e16

/*
 */

int const MaxSize = 1e5 + 10;
int n, m;
LL x[MaxSize], y[MaxSize];

int main() {

	ios_base::sync_with_stdio(false);
	//freopen("/Users/george/A_1.in", "r", stdin);
	cin >> n >> m;
	LP(i, 0, n)
	{
		cin >> x[i];
	}
	sort(x, x + n);

	LL MOD = 1e9 + 7;
	LL xSum = 0;
	LP(i, 0, n)
	{
		xSum += (2 * i - n + 1) * x[i];
		xSum %= MOD;
	}

	LP(i, 0, m)
		cin >> y[i];

	sort(y, y + m);

	LL ySum = 0;
	LP(i, 0, m)
	{
		ySum += (2 * i - m + 1) * y[i];
		ySum %= MOD;
	}

	LL ans = xSum * ySum;
	ans %= MOD;

	cout << (ans + MOD) % MOD << endl;

	return 0;
}


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

namespace TYC
{
	const int N = 55, INF = 0x3f3f3f3f;

	int n, ans, FA[N], FB[N], Deg[N];
	vector<int> A[N], B[N], E[N];

	inline int read()
	{
		int x = 0, f = 0, ch = getchar();
		while (!isdigit(ch))
			f |= (ch == '-'), ch = getchar();
		while (isdigit(ch))
			x = x * 10 + ch - '0', ch = getchar();
		return f ? -x : x;
	}

	void dfs(const int u, const int f, vector<int> *T, int *fa)
	{
		fa[u] = f;
		for (int v : T[u])
			if (v != f)
				dfs(v, u, T, fa);
	}

	bool toposort(int tot)
	{
		static queue<int> q;
		for (int i = 1; i <= n; i++)
			if (FA[i] != FB[i] && !Deg[i])
				q.push(i);
		while (!q.empty())
		{
			int u = q.front();
			q.pop();
			tot--;
			for (int v : E[u])
				if (!--Deg[v])
					q.push(v);
		}
		return !tot;
	}

	inline int count(const int u, const int f)
	{
		int c = 1;
		for (int v : A[u])
			if (v != f && FB[v] == u)
				c += count(v, u);
		return c;
	}

	int solve(const int o)
	{
		dfs(o, 0, A, FA);
		dfs(o, 0, B, FB);
		for (int i = 1; i <= n; i++)
			E[i].clear(), Deg[i] = 0;
		int cnt = 0;
		for (int i = 1, a, b; i <= n; i++)
			if ((a = FA[i]) != (b = FB[i]))
			{
				cnt++;
				if (FA[a] != FB[a])
					E[i].push_back(a), Deg[a]++;
				if (FA[b] != FB[b])
					E[b].push_back(i), Deg[i]++;
			}
		return count(o, 0) == n - cnt && toposort(cnt) ? cnt : INF;  
	}

	void work()
	{
		int T = read();
		while (T--)
		{
			n = read();
			for (int i = 1; i < n; i++)
			{
				int u = read(), v = read();
				A[u].push_back(v);
				A[v].push_back(u);
			}
			for (int i = 1; i < n; i++)
			{
				int u = read(), v = read();
				B[u].push_back(v);
				B[v].push_back(u);
			}
			ans = INF;
			for (int i = 1; i <= n; i++)
				ans = min(ans, solve(i));
			for (int u = 1; u <= n; u++)
				if (int(A[u].size()) == 1)
				{
					int v = A[u][0];
					A[u].pop_back();
					A[v].erase(find(A[v].begin(), A[v].end(), u));
					for (int p = 1; p <= n; p++)
						if (p != u && p != v)
						{
							A[u].push_back(p);
							A[p].push_back(u);
							ans = min(ans, solve(u) + 1);
							A[u].pop_back();
							A[p].pop_back();
						}
					A[u].push_back(v);
					A[v].push_back(u);
				}
			printf("%d\n", ans == INF ? -1 : ans);
			for (int i = 1; i <= n; i++)
				A[i].clear(), B[i].clear();
		}
	}
}

int main()
{
	TYC::work();
	return 0;
}

Measured memory_bytes: 256
let n = read_int ()
let ar = Array.init n (fun _ -> read_int ())
let () = Array.fast_sort compare ar

let sum  = 
  let rec f i tmp =
    if i >= n then tmp else f (succ i) (ar.(i) + tmp)
  in
  f 0 0 

let rec solve i =
  if i >= n then 0
  else
    let sum' = sum - ar.(i) in
    if sum' mod 10 = 0 then solve (succ i) else sum'

let () =
  (if sum mod 10 = 0 then solve 0 else sum)
  |> Printf.printf "%d\n"

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
  long double H,W,h,w; cin>>H>>W>>h>>w;
  cout<<fixed<<setprecision(10)<<H*W/2.0<<" "<<fixed<<setprecision(0)<<(H/2==h&&W/2==w? 1:0)<<endl;
}

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

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}

template <i64 mod = MOD>
struct ModInt{
    i64 p;

    ModInt() : p(0){}
    ModInt(i64 x){p = x >= 0 ? x % mod : x + (-x + mod - 1) / mod * mod;}

    ModInt& operator+=(const ModInt& y){p = p + *y - ((p + *y) >= mod ? mod : 0); return *this;}
    ModInt& operator-=(const ModInt& y){p = p - *y + (p - *y < 0 ? mod : 0); return *this;}
    ModInt& operator*=(const ModInt& y){p = (p * *y) % mod; return *this;}
    ModInt& operator%=(const ModInt& y){if(y)p %= *y; return *this;}

    ModInt operator+(const ModInt& y) const{ModInt x = *this; return x += y;}
    ModInt operator-(const ModInt& y) const{ModInt x = *this; return x -= y;}
    ModInt operator*(const ModInt& y) const{ModInt x = *this; return x *= y;}
    ModInt operator%(const ModInt& y) const{ModInt x = *this; return x %= y;}

    friend ostream& operator<<(ostream& stream, const ModInt<mod>& x){
        stream << *x;
        return stream;
    }

    friend ostream& operator>>(ostream& stream, const ModInt<mod>& x){
        stream >> *x;
        return stream;
    }

    ModInt& operator++(){p = (p + 1) % mod; return *this;}
    ModInt& operator--(){p = (p - 1 + mod) % mod; return *this;}

    bool operator==(const ModInt& y) const{return p == *y;}
    bool operator!=(const ModInt& y) const{return p != *y;}

    const i64& operator*() const{return p;}
    i64& operator*(){return p;}

};

using mint = ModInt<>;


signed main(){

    int h, w, k;
    cin >> h >> w >> k;

    vector<vector<int>> pat;
    for(int i = 0; i < (1 << (w - 1)); ++i){
        vector<int> iot(w);
        iota(iot.begin(), iot.end(), 0);
        bool fl = true;
        for(int j = 0; j < w; ++j){
            if(i & (1 << j)){
                swap(iot[j], iot[j + 1]);
                if(i & (1 << (j + 1)))
                    fl = false;
            }
        }
        if(fl){
            pat.emplace_back(move(iot));
        }
    }

    vector<vector<mint>> dp(h + 1, vector<mint>(w, 0));
    dp[0][0] = 1;
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            for(auto& p : pat){
                dp[i + 1][p[j]] += dp[i][j];
            }
        }
    }
    cout << dp.back()[k - 1] << endl;

    return 0;
}


Measured memory_bytes: 3504
use std::env;
use std::io::prelude::*;
use std::io;
use std::fs::File;
use std::str::FromStr;
use std::io::BufReader;
fn buf_read() -> io::Result<(Vec<String>)> {
    let args: Vec<_> = env::args().collect();
    if args.len() >= 2 {
        let f = try!(File::open("input.txt"));
        let input_lines: Vec<_> = BufReader::new(f).lines().collect();
        let lines: Vec<String> = input_lines.into_iter().map(|e| e.unwrap()).collect();
        Ok((lines))
    } else {
        let stdin = io::stdin();
        let input_lines: Vec<_> = stdin.lock().lines().collect();
        let lines: Vec<String> = input_lines.into_iter().map(|e| e.unwrap()).collect();
        Ok((lines))
    }
}

fn main() {
    type Element = usize;
    let input = buf_read().unwrap();
    let mut input_vectors: Vec<Vec<Element>> = vec![];
    for input_line in input {
        let input_str: Vec<String> = input_line.split(' ').map(String::from).collect();
        let mut input_vector: Vec<Element> = vec![];
        for input_elem_str in input_str {
            let elem: Element = Element::from_str(input_elem_str.as_str()).unwrap();
            input_vector.push(elem);
        }
        input_vectors.push(input_vector);
    }
    let x_len = input_vectors[0][0];
    let y_len = input_vectors[0][1];
    let mut area: Vec<Vec<Element>> = vec![vec![0; x_len]; y_len];
    for i in 1..input_vectors[0][2] + 1 {
        match input_vectors[i][2] {
            1 => {
                for y in 0..y_len {
                    for x in 0..input_vectors[i][0] {
                        area[y][x] = 1;
                    }
                }
            }
            2 => {
                for y in 0..y_len {
                    for x in input_vectors[i][0]..x_len {
                        area[y][x] = 1;
                    }
                }
            }
            3 => {
                for x in 0..x_len {
                    for y in 0..input_vectors[i][1] {
                        area[y][x] = 1;
                    }
                }
            }
            _ => {
                for x in 0..x_len {
                    for y in input_vectors[i][1]..y_len {
                        area[y][x] = 1;
                    }
                }
            }
        }
    }
    let black_sum: usize = area.iter()
                               .fold(0, |acc, ref x| acc + x.iter().fold(0, |sum, acc| sum + acc));
    println!{"{:?}", x_len * y_len - black_sum}
}


Measured memory_bytes: 508
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<cmath>
#include<numeric>
#include<queue>
using namespace std;

long long int mod = 1000000007;

int main(void) {

  int l, n;
  cin >> l >> n;
  int t = 0;
  for(int i=0; i<n; i++){
    int x, w;
    cin >> x >> w;
    t += x * w;
  }
  if( t == 0 ){
    cout << 0 << endl;
    return 0;
  }
  cout << 1 << endl;
  cout << (t > 0 ? -1 : 1) << " " << abs(t) << endl;

  return 0;
}


//

Measured memory_bytes: 3088
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int N, A, B, ans; cin >> N >> A >> B;
    ans = min(N*A, B);
    cout << ans << endl;
}

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

vector<int> dx = {0,0,1,-1};
vector<int> dy = {1,-1,0,0};
 
int main(){
        int h,w;
        cin >> h >> w;
        int ans = 0;
        vector<string> maze(h);
        rep(i,h) cin >> maze[i];
        rep(s_y,h)rep(s_x,w)rep(g_y,h)rep(g_x,w){
                if(maze[s_y][s_x] =='#' || maze[g_y][g_x] =='#') continue;
                queue<P> q;
                vector<vector<int>> visited(h,vector<int>(w,-1));
                q.push(P(s_y,s_x));
                visited[s_y][s_x] = 0;
                while(!q.empty()){
                        int y = q.front().first;
                        int x = q.front().second;
                        q.pop();
                        rep(i,4){
                                  int new_y = y + dy[i];
                                  int new_x = x + dx[i];
                                  if(0<= new_y && new_y < h && 0  <= new_x && new_x < w){
                                       if(visited[new_y][new_x] >= 0 || maze[new_y][new_x] =='#') continue;
                                       visited[new_y][new_x] = visited[y][x] + 1;
                                       q.push(P(new_y,new_x));
                                  }
                         }
                        
                }
                ans = max(ans,visited[g_y][g_x]);
        }
        cout << ans << endl;

        return 0;
}






Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main{
    public static void main(String args[]) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String s = new String(in.readLine());
        String[] s2 = s.split(" ",0);
        int n = Integer.parseInt(s2[0]);
        int a = Integer.parseInt(s2[1]);
        int b = Integer.parseInt(s2[2]);

        int c;
        if(a > b){
            c=b;
        }else{
            c=a;
        }

        int d;
        d = a+b-n;
        if(d < 0){
            d = 0;
        }
        System.out.print( c + " " + d );
  }
}

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

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

typedef pair<int,int> pii;
typedef long long int ll;

void gen_sosuu(int sosuu[]){
  REP(i,100010){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(100000)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<=100000;j++){
      //printf("%d %d %d\n",i*j,i,j);
      sosuu[i*j] =false;
    }
  }
}

int n,m;
int cnt[60]={0};
int a,b;

int main(){
  scanf("%d %d",&n,&m);
  REP(i,m){
    scanf("%d %d",&a,&b);
    cnt[a]++;
    cnt[b]++;
  }
  FOR(i,1,n+1){
    printf("%d\n",cnt[i]);
  }
}


Measured memory_bytes: 256
n = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
from itertools import accumulate
cs = [a-b for a,b in zip(As,Bs)]
cs.sort(reverse=True)
#負の数を埋めるのに、正の数を何個使うか
p = [0]+[c for c in cs if c > 0]
m = [c for c in cs if c < 0]


ans = 0

m_all = sum(m)
acc = list(accumulate(p))
ans += len(m)
for i,p in enumerate(acc):
    if p >= -m_all:
        break
ans += i


if sum(As) < sum(Bs):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 18484
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

s = input()

print(s[::2])


Measured memory_bytes: 5472
#include<iostream>
#include<cmath>

using namespace std;

const long long MOD = 998244353;

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main()
{
    int N,a[110000],key;
    cin >> N;
    for (int i=0; i<N; ++i)
    {
        cin >> key;
        ++a[key];
        if (i==0 && key != 0)
        {
            cout << 0 << endl;
            return 0;
        } 
    }

    if(a[0] != 1)
    {
        cout << 0 << endl;
        return 0;
    }

    // long long ans = 1;
    // int sum = 0;
    // for (int i=1; i<N; ++i)
    // {
    //     if(a[i-1]==0 && a[i]>0)
    //     {
    //         cout << 0 << endl;
    //         return 0;
    //     }
    //     if(a[i-1]>0 && a[i]==0)
    //     {
    //         for(int j=i; j<N; ++j)
    //         {
    //             sum += a[j];            
    //         }
    //         if(sum != 0)
    //         {
    //             cout << 0 << endl;
    //             return 0;
    //         }
    //         else
    //         {
    //             cout << ans << endl;
    //             return 0;
    //         }
    //     }
    //     long long tmp = (long long)pow(a[i-1],a[i]) % MOD;
    //     ans *= tmp;
    //     ans %= MOD; //取り忘れ 
    // }

    long long ans = 1;
    int sum = 0;
    for (int i=0; i<N; ++i)
    {
        // long long tmp = (long long)pow(a[i],a[i+1]) % MOD;
        long long tmp = modpow(a[i],a[i+1],MOD); //modpowの取り方がだめだった
        ans *= tmp;
        ans %= MOD; //取り忘れ
        sum += a[i]; 
        if(a[i+1]==0) break;
    }
    if(sum != N) cout << 0 << endl;
    else cout << ans << endl;
    // cout << sum << endl;
    return 0;
}

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

int main(void){
    int n, y;
    cin >> n >> y;
    
    int i, j;
    for(i = 0; i <= n; i++){
        for(j = 0; i + j <= n; j++){
            if(10000 * i + 5000 * j + 1000 * (n - i - j) == y){
                printf("%d %d %d\n", i, j, n - i - j);
                return 0;
            }
        }
    }
    
    cout << "-1 -1 -1" << endl;
    
    return 0;
}


Measured memory_bytes: 256