akhauriyash/Code-Regression huggingface dataset:
// abc149_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

map<ll, int> factorize(ll n){
    ll tmp = n;
    map<ll, int> res;
    for (ll a = 2; a * a <= n; a++) { int cnt = 0; while (tmp % a == 0){ cnt++; tmp /= a; } if (cnt > 0) res[a] = cnt; }
    if (tmp > 1) res[tmp] = 1;
    return res;
}

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;

    int ans = 0;
    REPN(n, 1, N+1){
        if (n %2 == 0) continue;

        auto res = factorize(n);
        int num = 1;
        for (auto e: res){
            num *= (e.second+1);
        }
        if (num == 8){
            ans++;
        }
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 256
from sys import stdin
num=int(stdin.readline().rstrip())
ans="No"
if num%7==0 or num%4==0:
	ans="Yes"
if num-7>0 and (num-7)%4==0:
	ans="Yes"
if num-14>0 and (num-14)%4==0:
	ans="Yes"
if num-21>0 and (num-21)%4==0:
	ans="Yes"
print(ans)


Measured memory_bytes: 3060
def abc069_d():
    h, w = map(int, input().split())
    n = int(input())
    a = list(map(int, input().split()))
    s = []
    for i in range(n):
        s.extend([str(i + 1)] * a[i])

    for i in range(h):
        if i % 2 == 0:
            print(" ".join(s[i * w:(i + 1) * w]))
        else:
            print(" ".join(s[i * w:(i + 1) * w][::-1]))


abc069_d()

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

int main(void)
{
    int x, y, z;
    cin >> x >> y >> z;

    int tmp = x;
    x = y;
    y = tmp;
    tmp = x;
    x = z;
    z = tmp;

    cout << x << ' ' << y << ' ' << z << endl;
    return 0;
    
}

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

typedef long long int ll;
#define mamba() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int main()
{
	mamba()
      ll n,k,res=0;cin>>k>>n;
  		vector<ll> a(n),b(n);
  for(auto & v : a)
  {
  	cin>>v;
  }
  ll max=0;
  
  for(int i=0;i<n-1;i++)
  {
    if(max<abs(a[i+1]-a[i]))
      max=a[i+1]-a[i];
  }
  if(max<abs(k+a[0]-a.back()))
    	max=abs(k+a[0]-a.back());
  cout<<k-max;
}

Measured memory_bytes: 3328
#include<iostream>
#include<math.h>

using namespace std;

int main(int argc, char const *argv[]) {
  int n;
  long long min;
  long long sun=0, arai=0;
  cin >> n;
  long long* num = new long long[n];

  for (int i = 0; i < n; i++) {
    cin >>num[i];
  }
  for (int i = 0; i < n; i++) {
    arai += num[i];
  }
  sun += num[0];
  arai -= num[0];
  min = abs(sun-arai);

  for (int i = 1; i < n-1; i++) {
    sun += num[i];
    arai -= num[i];
    if(abs(sun-arai)<min){
      min = abs(sun-arai);
    }
  }
  cout << min <<endl;
  return 0;
}


Measured memory_bytes: 1792
'use strict'

function main(input) {

  // 最大数が1e100なので、文字列として比較

  input = input.split('\n')
  const A = input[0]
  const B = input[1]

  const G = 'GREATER'
  const L = 'LESS'
  const E = 'EQUAL'

  //桁のチェック
  if (A.length > B.length) {
    console.log(G)
    return
  } else if (A.length < B.length) {
    console.log(L)
    return
  } else {

    //桁は同じなので先頭の数字から比較
    for (let i = 0; i < A.length; i++) {
      let tmpA = ~~A[i]
      let tmpB = ~~B[i]
      if (tmpA > tmpB) {
        console.log(G)
        return
      } else if (tmpA < tmpB) {
        console.log(L)
        return
      }
    }
  }

  console.log(E)

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


Measured memory_bytes: 7372
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int a[17];
int main()
{
    int n;
    scanf("%d",&n);
    long long sum=0; long long cnt=0;
    for(int i=1;i<=n;i++)
    {
         scanf("%d",&a[i]);
         if(a[i]%2==0)
           cnt++;
    }
    sum=pow(3,n)-pow(2,cnt);
    printf("%lld\n",sum);
    return 0;


}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	static int mod = 1000000007;

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[in.nextInt()]++;
		}
		long ans = 1;
		if (N % 2 == 0 && A[0] == 0) {
			for (int i = 1; i < N; i += 2) {
				if (A[i] != 2) {
					ans = 0;
					break;
				}
				ans = (long) ans * 2 % mod;
			}
		} else if (N % 2 != 0 && A[0] == 1) {
			for (int i = 2; i < N; i += 2) {
				if (A[i] != 2) {
					ans = 0;
					break;
				}
				ans = (long) ans * 2 % mod;
			}
		} else {
			ans = 0;
		}
		System.out.println(ans);
		in.close();
	}
}

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

using namespace std;

template<class T> inline bool chmax(T &a, T b){
  if(a < b){
    a = b;
    return true;
  }
  return false;
}

int dp[3010][3010];

int main(void){
  for(int i=0;i<3010;i++){
    for(int j=0;j<3010;j++){
      dp[i][j] = 0;
    }
  }
  string s,t;
  cin >> s >> t;
  for(int i=1;i<=s.length();i++){
    for(int j=1;j<=t.length();j++){
      if(s[i-1] == t[j-1]){
        dp[i][j] = dp[i-1][j-1] + 1;
      }else{
        chmax(dp[i][j],dp[i-1][j]);
        chmax(dp[i][j],dp[i][j-1]);
      }
    }
  }

  // for debug
  // for(int i=0;i<=s.length();i++){
  //   for(int j=0;j<=t.length();j++){
  //     cout << dp[i][j] << ", ";
  //   }
  //   cout << endl;
  // }

  string ans ="";
  size_t slen=s.length(), tlen=t.length();
  while(slen>0 && tlen >0){
    if(s[slen-1]==t[tlen-1]){
      ans+=s[slen-1];
      slen--;
      tlen--;
    }else{
      if(dp[slen-1][tlen]>dp[slen][tlen-1]) slen--;
      else tlen--;
      if(ans.size()==dp[s.size()][t.size()]) break;
    }
  }

  reverse(ans.begin(), ans.end());
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 35712
#include <stdio.h>

int main(void)
{
	int n,m;
	int pairs;		//Answer.

	scanf("%d%d", &n, &m);

	//Only M pattarn.
	pairs = 0;
	while(m != 0)
	{
		pairs += m - 1;
		m--;
	}

	//Only N pattarn.
	while(n != 0)
	{
		pairs += n - 1;
		n--;
	}

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

	return(0);
}


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

using namespace std;

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

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << min(a, b) + min(c, d) << endl;

	return 0;
}


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

bool isprime(int n)
{
	if(n<=3)return true;
	if(n%2==0 || n%3 ==0 )return false;
	
	for(int i=5;i*i<=n;i+=6)
	{
		if(n%i==0 || n%(i+2)==0)return false;
	}
	
	return true;
	
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin>>n;
	
	for(int i=n;;i++)
	{
		if(isprime(i))
		{
			cout << i << endl;
			break;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>

void solve()
{
    using namespace std;
    string s;
    cin >> s;

    int price = accumulate(s.cbegin(), s.cend(), 700,
        [](int init, char c)
    { 
        return init + (c == 'o' ? 100 : 0);
    });

    cout << price << endl;

}

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

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

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define for1(i, a, b) for (int i = (int)a; i < (int)(b); ++i)
#define rfor1(i, a, b) for (int i=(int)b-1;i>=(int)a;i--)
#define for2(i, a, b) for (int i = (int)a; i <= (int)(b); ++i)
#define for3(i, a, b) for (int i = (int)a; i < (int)(b); i=i+2)
#define for4(i, a, b) for (int i = (int)a; i <= (int)(b); i=i+2)
#define tc(t) int t; cin>>t; while(t--)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    cout << (e - a <= k ? "Yay!" : ":(") << endl;
}









Measured memory_bytes: 3624
#include <iostream>
#include <vector>
using namespace std;
long long const mod = 1000000007;
long long mod_fact(int x){
    static vector<long long> fact = {1, 1};
    if(x < 0)return 0; //
    if(x < fact.size())return fact[x];
    for(int i = fact.size(); i <= x; i++){
        fact.push_back((fact[i-1] * i) % mod);
    }
    return fact[x];
}

long long mod_pow(long long a, long long b){
    long long res = 1;
    a %= mod;
    while(b > 0){
        if(b%2 == 1) res = (res * a) % mod;
        a = (a * a) % mod;
        b /= 2;
    }
    return res;
}

long long mod_div(long long a){
    return mod_pow(a, mod-2);
}

long long mod_comb(int a, int b){
    if(b < 0 || a < b)return 0;
    if(b > a/2)return mod_comb(a, a-b);
    return (((mod_fact(a) * mod_div(mod_fact(a-b))) % mod) * mod_div(mod_fact(b))) % mod;
}

long long f(int a){
    return (long long) a*(a+1)/2 % mod;
}
long long g(int a, int b){
    if(a <= 0 || b <= 0)return 0;
    long long res = a*f(b) + b*f(a);
    return res%mod;
}
int main(void){
    int n, m, k, nm;
    long long ans = 0;
    cin >> n >> m >> k;
    nm = n*m;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            long long t = f(i) + f(j) + f(n-1-i) + f(m-1-j);
            t += g(i, j);
            t += g(i, m-1-j);
            t += g(n-1-i, j);
            t += g(n-1-i, m-1-j);
            t %= mod;
            ans += t * mod_comb(nm-2, k-2);
            ans %= mod;
            
        }
    }
    cout << ans * mod_div(2) % mod<< endl;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x)  x.begin(),x.end()
#define vi vector<int>
#define print(x) for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<'\n';
#define in(x,n) for(int e=0;e<n;e++){int y;cin>>y;x.pb(y);}
#define lower(sl)  transform(sl.begin(), sl.end(), sl.begin(), ::tolower); 
//Available in Snips
#define fi(i, x, y)   for (__typeof(x) i = x; i < y; i ++)
#define fir(i, x, y)  for (__typeof(x) i = x; i > y; i --)
#define fv(x)   for (auto itr = x.begin(); itr != x.end(); itr ++)
#define fvr(x)  for (auto itr = x.end() - 1; itr != x.begin() - 1; itr --)

map<ll,ll>check,str;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//code here
	vi a(3,0);
	cin >> a[0];
	cin >> a[1];
	cin >> a[2];
	sort(a.begin(),a.end());
	cout << a[0]+a[1];
	return 0;
	
}


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

public class Main {

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

		String str;
		String[] arrStr;
		StringBuilder sb = new StringBuilder();
		try {

			final String sharp = "#";

			while (true) {
				str = br.readLine();
				arrStr = str.split(" ");

				int h = Integer.parseInt(arrStr[0]);
				int w = Integer.parseInt(arrStr[1]);
				if(h == 0 && w == 0){
					break;
				}
				for (int i = 0; i<h; i++) {
					for (int j = 0; j < w; j++) {
						sb.append(sharp);
					}
					sb.append("\n");
				}
				System.out.println(sb.toString());
				sb.setLength(0);
			}

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

Measured memory_bytes: 21020
#include<bits/stdc++.h>
using namespace std;
int n,C[501],S[501],F[501];
int main()
{
	cin>>n;
	for(int i=1;i<n;++i)
	cin>>C[i]>>S[i]>>F[i];
	for(int i=1;i<n;++i)
	{
		int t=0;
		for(int j=i;j<n;++j)
		{
			int tim=0;
			while(t>S[j]+F[j]*tim) ++tim;
			t=S[j]+F[j]*tim;
			t+=C[j];
		}
		cout<<t<<endl;
	}
	cout<<"0"<<endl;
	return 0;
}

Measured memory_bytes: 256
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;


int main() {
ll x;
cin>>x;
ll ans=(x/11)*2;
x%=11;
if(x==0){
  
}
else if(x<=6){
  ans++;

}
else{
  ans+=2;
}
cout<<ans<<endl;

return 0;
}

Measured memory_bytes: 3584
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    N = Scanner.int()
    A = Scanner.map_int()
    S = sum(A)
    X = [0 for _ in range(N)]

    for i in range(1, N, 2):
        X[0] -= 2 * A[i]
    X[0] += S

    for i in range(1, N):
        X[i] = 2 * A[i - 1] - X[i - 1]
    print(*X)


def main():
    # sys.setrecursionlimit(1000000)
    # sys.stdin = open("sample.txt")
    # T = Scanner.int()
    # for _ in range(T):
    #     solve()
    # print('YNeos'[not solve()::2])
    solve()


if __name__ == "__main__":
    main()


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

typedef long long ll;
typedef long double ld;
using namespace std;
mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());
//mt19937_64 mrand(42);
#define ii for(int i=1;i<=n;++i)
#define ji for(int j=1;j<=n;++j)
#define jj for(int j=1;j<=m;++j)
#define ij for(int i=1;i<=m;++i)
#define sz(x) ((ll)x.size())
#define all(x) x.begin(),x.end()
#define al(x) x+1,x+1+n
#define asd cout<<"ok"<<endl;
#define asdd cout<<"okok"<<endl;
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define pr(v) for(auto i:v) cout<<i<<" ";cout<<endl
#define prt(a, l, r) for(auto i=l;i<=r;++i) cout<<a[i]<<" ";cout<<endl;
#define pc(x) __builtin_popcount(x)
#define pb push_back

const ll maxn = 1e18;
int main() {
    int n;
    cin>>n;
    __int128 ans=1;
    int f=0;
    for(int i=1;i<=n;++i) {
        ll x;
        cin>>x;
        if(!x) return cout<<0<<endl,0;
        ans=ans*x;
        if(ans>maxn) f=1;
    }
    if(f) cout<<-1<<endl;
    else cout<<(ll)ans<<endl;
}

Measured memory_bytes: 3616
import java.util.*;
import java.io.*;
 
import static java.lang.System.in;
 
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long P = sc.nextLong();
        if(n==1){
            System.out.println(P);
            System.exit(0);
        }
        long upper = (long) Math.sqrt(P)+1;
        long ans=1;
        for(long i=2;i<=upper&&i<=P;i++){
            if(P%i!=0) continue;
            long cnt=0;
            while(P%i==0){
                cnt++;
                P = P/i;
            }
            long now = cnt/n;
            ans*=(long) Math.pow(i,now);
        }
        PrintWriter out = new PrintWriter(System.out);
        out.println(ans);
        out.flush();
    }
}

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

int main(){
  int N, M, C;
  cin >> N >> M >> C;
  int B[M];
  int A[N][M];
  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 code = C;
    for(int j=0; j<M; j++) code+= A[i][j]*B[j];
    if(code>0) ans++;
  }
  cout << ans << endl;  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

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

    int n;
    cin >> n;
    vector<int> a(n + 1);
    REP(i, 1, n + 1) cin >> a[i];

    vector<int> b(n + 1, 0);
    vector<int> ans;

    for (int i = n; i > 0; --i) {
        int sum = 0;
        for (int j = i; j <= n; j+=i) {
            sum += b[j];
        }

        if (sum % 2 != a[i]) {
            b[i] = 1;
            ans.push_back(i);
        }
    }

    reverse(ans.begin(), ans.end());

    cout << ans.size() << endl;
    for (auto v : ans) cout << v << endl;

    return 0;
}

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

int main(void){
    int x;
    cin>>x;
    int n=0;
    while(n*(n+1)/2<x) n++;
    cout<<n<<endl;
}

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

int main(int argc, char const *argv[]) {
    int a, b;
    cin >> a >> b;

    if (a == b) cout << 0 << endl;
    else {
        if ((a+b)%2 == 0) cout << (a+b)/2 << endl;
        else cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}


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

int main(){
  string n;
  cin >>n;
  bool can = false;
  if(n[0]==n[1] && n[1]==n[2]) can = true;
  if(n[1]==n[2] && n[2]==n[3]) can = true;
  if(can) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define BMAX 1000

int max(int a,int b){
 if(a > b)return a;
 return b;
}

int min(int a,int b){
 if(a > b)return b;
 return a;
}

int main(){
 int n,q;
 int i,j,k;
 int an,vn,x;
 int maxi;
 int *A;
 int B[BMAX];
 int b,L,R;
 int idx;

 scanf("%d %d",&n,&q);
 b=floor(sqrt(n));
 A=(int *)malloc(sizeof(int) * 1000001);

 for(i=0;i<n;i++){
  A[i]=0;
 }
 for(i=0;i<BMAX;i++){
  B[i]=0;
 }

 for(i=0;i<q;i++){

  /*update*/
   scanf("%d %d",&an,&vn);
   x=an-1;
   A[x]+=vn;
   maxi=A[(x/b)*b];
   R=min((x/b+1)*b-1,n-1);
   for(j=(x/b)*b+1;j<=R;j++)maxi=max(maxi,A[j]);
   B[x/b]=maxi;

  /*find*/
   maxi=-1;
   for(j=0;j<=(n-1)/b;j++){
     if(B[j] > maxi){
       maxi=B[j];
       idx=j;
     }
    }

   for(k=b*idx;k<b*(idx+1);k++){
     if(A[k]==maxi){
       printf("%d %d\n",k+1,maxi);
       break;
     }
   }

 }

return 0;
}
    


Measured memory_bytes: 5676
#include "bits/stdc++.h"
using namespace std;
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	string n;
	string ans = "";
	cin >> n;
	ans = ans+"2018";
	for (int i = 4; i < n.size(); i++) {
		ans = ans + n[i];
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	int k;
	cin >> s >> k;
	auto cal = [&](char c) {
		int p = c - 'a';
		return 25 - p + 1;
	};
	int n = s.size();
	rep(i, n) {
		if (s[i] == 'a') continue;
		if (cal(s[i]) <= k) {
			k -= cal(s[i]);
			s[i] = 'a';
		}
	}
	k %= 26;
	int np = s[n - 1] - 'a';
	np += k;
	s[n - 1] = char(np + 'a');
	cout << s << endl;
	return 0;
}

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

using namespace std;

template <class T> inline bool chmax(T &a, T b) { /* {{{ */
  if (a < b) {
    a = b;
    return true;
  }
  return false;
} /* }}} */

int N, W;
int WS[105], VS[105];
int dp[105][105][305];

int main() {
  cin >> N >> W;
  for (int i = 0; i < N; i++) {
    cin >> WS[i] >> VS[i];
  }
  for (int i = 0; i < 105; i++) {
    for (int j = 0; j < 105; j++) {
      for (int k = 0; k < 305; k++) {
        dp[i][j][k] = -1;
      }
    }
  }
  dp[0][0][0] = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      for (int k = 0; k < 305; k++) {
        if (dp[i][j][k] == -1) continue;
        int w = WS[i] - WS[0];
        chmax(dp[i + 1][j][k], dp[i][j][k]);
        chmax(dp[i + 1][j + 1][k + w], dp[i][j][k] + VS[i]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j < 305; j++) {
      long long w = (long long)WS[0] * i + j;
      if (w <= W) chmax(ans, dp[N][i][j]);
    }
  }
  cout << ans << endl;

  return 0;
}
/* vim:set fdm=marker: */


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

int main() {
    int N; cin >> N;
    int ans=0;int cnt=0;
    while(N>cnt){
        ans++;
        cnt+=ans;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        String s = sc.next();
        sc.close();
        if (a >= 3200) {
            System.out.println(s);
        } else {
            System.out.println("red");
        }
    }
}


Measured memory_bytes: 23764
if __name__ == '__main__':
    a = int(input())
    b = input()

    counts = []
    for i in range(1, a):
        count = 0
        b_1 = b[0:i]
        b_1 = list(set(list(b_1)))
        b_2 = b[i:a]
        b_2 = list(set(list(b_2)))
        for x in range(0, len(b_1)):
            for y in range(0, len(b_2)):
                if b_1[x] == b_2[y]:
                    count = count + 1

            counts.append(count)

    print(max(counts))

Measured memory_bytes: 3064
N, X = map(int, input().split())

a, p = [1], [1]
for i in range(N):
  a.append(a[i] * 2 + 3)
  p.append(p[i] * 2 + 1)

def f(N, X):
  if N == 0:
    return 0 if X <= 0 else 1
  elif X <= 1 + a[N-1]:
    return f(N-1, X-1)
  else:
    return p[N-1] + 1 + f(N-1, X-2-a[N-1])
  
print(f(N, X))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define reg register
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define inf 0x3f3f3f3f
#define eps 1e-8
#define pi acos(-1.0)
#define e exp(1.0)
#define ios ios::sync_with_stdio(false)
#define rep(i,l,r) for(int i=(l);i<(r);i++)
using namespace std;

const int maxn = 2e5 + 10;
const ll mod = 1e9 + 7;

ll qpow(ll a, ll b)
{
   ll res = 1;
   while(b){
      if(b & 1)  res = res * a % mod;
      a = a * a % mod;
      b >>= 1;
   }
   return res;
}
ll f[2005][2005];
int main()
{  
   
   for(int i = 1;i <= 2000;++i){
      f[1][i] = 1;
   }
   for(int i = 2;i <= 2000;++i){
      for(int j = 1;j <= 2000;++j){
         f[i][j] = (f[i][j-1] + f[i-1][j]) % mod; 
      }
   }

   int n;
   cin >>n;
   int cnt = n / 3;
   ll res = 1;
   if(n < 3) res = 0;
   for(int i = 1;i < cnt;++i){
      for(int j = 0;j <= n - 3 * (i+1);++j){
         res = (res + f[i][j+1]) % mod;
      }
   }
   cout<<res<<endl;

   return 0;
}

Measured memory_bytes: 34956
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

int E[5001], n[5001], C[5001], H[2501];
bool vis[2501];
void dfs(int v) {
	vis[v] = true;
	for (int p = H[v]; p; p = n[p]) {
		int to = E[p];
		if (!vis[to]) dfs(to);
	}
}

inline unsigned long long rdtsc() {
 
#ifdef __amd64
	unsigned long long a, d;
	__asm__ volatile ("rdtsc" : "=a" (a), "=d" (d));
	return (d << 32) | a;
#elif __i386
	unsigned long long x;
	__asm__ volatile ("rdtsc" : "=A" (x));
	return x;
#endif
	return 0;
}
 
ll gettime() {
	return rdtsc() / 2800000;
}

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


	int N, M, P;
	cin >> N >> M >> P;
	rep1(i, M) {
		int a;
		cin >> a >> E[i] >> C[i];
		n[i] = H[a];
		H[a] = i;
	}
	int D[2501];
	rep1(i, N) D[i] = -1e9;
	D[1] = 0;
	int q[2501] = {};
	q[1] = 1;

	//こんな明らかに正しくない提出をさらに繰り返して何をしたいというのか
	//結果さえ良ければ手段は何でもいいのかこのごみくずめ！なんの実りもないな！

	ll st = gettime();
	int cnt[2501] = {};
	bool ganbaru;
	rep1(k, N) {
		ganbaru = (gettime() < st + 16);
		rep1(i, N) {
			if (q[i] == k) {
				for (int p = H[i]; p; p = n[p]) {
					int to = E[p];
					int d = D[i] + C[p] - P;
					if (D[to] < d && (ganbaru || cnt[to] < 100)) {
						D[to] = d;
						q[to] = k + 1;
						cnt[to]++;
					}
				}
			}
		}
	}

	rep1(i, N) {
		if ((q[i] == N + 1 || (!ganbaru && cnt[i] >= 100)) && !vis[i]) dfs(i);
	}

	if (vis[N]) co(-1);
	else co(max(0, D[N]));

	Would you please return 0;
}

Measured memory_bytes: 512
//	ZapZu's code hohoho
//	#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define dfs_black 1
#define dfs_white -1
#define pr pair
#define vt vector
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef double db;
typedef long long li;
typedef long double ld;

typedef pr<int, int> ii;
typedef pr<ld,ld> dd;

typedef vt<int> vi;
typedef vt<li> vli;
typedef vt<ld> vld;
typedef vt<ii> vii;

typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<int, char> mic;

typedef set<int> s_i;
typedef set<char> s_c;

const int MOD = 1e9+7;
const li INF = 1e18;
const ld PI = 4*atan((ld)1);
vi v[2];
signed main()
{
//	freopen(".inp", "r", stdin);
//	freopen(".out", "w", stdout);
	int n;
	cin>>n;
	int a[n+1], dp[n+1], xs[n+1];
	dp[0]=xs[0]=0;
	for(int i=1; i<=n; i++)
	{
		cin>>a[i];
		dp[i]=dp[i-1]+a[i];
		xs[i]=xs[i-1]^a[i];
	}
	int p=1;
	li ans=0;
	for(int i=1; i<=n; i++)
	{
		while(p+1<=i and dp[i]-dp[p-1]!=(xs[i]^xs[p-1])) p++;
//		cout<<p<<endl;
		ans+=i-p+1;
	}
	cout<<ans;
}




Measured memory_bytes: 4992
import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M, *AB = map(int, read().split())
    G = [[] for _ in range(N)]
    for a, b in zip(*[iter(AB)] * 2):
        G[a - 1].append(b - 1)

    ans = []
    for i in range(N):
        queue = deque([i])
        dist = [-1] * N
        dist[i] = 0
        prev = [-1] * N
        while queue:
            v = queue.popleft()
            for nv in G[v]:
                if dist[nv] == -1:
                    dist[nv] = dist[v] + 1
                    prev[nv] = v
                    queue.append(nv)
        for j in range(N):
            if i == j or dist[j] == -1 or i not in G[j]:
                continue
            tmp = []
            k = j
            while k != -1:
                tmp.append(k)
                k = prev[k]

            if not ans or len(ans) > len(tmp):
                ans = tmp

    if ans:
        print(len(ans))
        for v in ans:
            print(v + 1)
    else:
        print(-1)

    return


if __name__ == '__main__':
    main()


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

using namespace std;

set<pair<int, int>> s;

int hcnt[300100], wcnt[300100];
int maxh, maxw;
vector<int> posh, posw;

int main()
{
    int H, W, m;
    scanf("%d%d%d", &H, &W, &m);
    for(int i = 1; i <= m; ++i)
    {
        int h, w;
        scanf("%d%d", &h, &w);
        hcnt[h]++;
        wcnt[w]++;
        maxh = max(maxh, hcnt[h]);
        maxw = max(maxw, wcnt[w]);
        s.insert({h, w});
    }
    for(int h = 1; h <= H; ++h)
        if(maxh == hcnt[h]) posh.push_back(h);
    for(int w = 1; w <= W; ++w)
        if(maxw == wcnt[w]) posw.push_back(w);
    for(int h : posh)
        for(int w : posw)
            if(!s.count({h, w}))
            {
                printf("%d\n", maxh + maxw);
                return 0;
            }
     printf("%d\n", maxh+maxw-1);
}


Measured memory_bytes: 23760
#include <iostream>
#include <string>
#include <algorithm>
 
int main(){
   int a;
   int b;
   std::cin >> a >> b;
   int r;
   if (a <= 5){
      r = 0;
   }else if (a <= 12){
      r = b /2;
   }else{
      r = b;
   }
   std::cout << r << std::endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int T[2000000];
int size;


int parent(int i)
{
  return i/2;
}
int left(int i)
{
  return 2*i;
}
int right(int i)
{
  return 2*i+1;
}

void maxHeapify(int i)
{
  int l,r,tmp,max;
  l=left(i);
  r=right(i);
  if(l<=size&&T[l]>T[i])
    {
      max=l;
    }
  else
    {
      max=i;
    }
  if(r<=size&&T[r]>T[max])
    {
      max=r;
    }
  if(max!=i)
    {
      tmp=T[i];
      T[i]=T[max];
      T[max]=tmp;
      maxHeapify(max);
    }
}

void heapIncreaseKey(int i,int key)
{
  int tmp;
  if(key<T[i])
    {
      return;
    }
  T[i]=key;
  while(i>1&&T[parent(i)]<T[i])
    {
      tmp=T[i];
      T[i]=T[parent(i)];
      T[parent(i)]=tmp;
      i=parent(i);
    }
}

void maxHeapInsert(int key)
{
  size=size+1;
  T[size]=-2000000000;
  heapIncreaseKey(size,key);
}


int heapExtractMax(void)
{
  int max;
  if(size<1)
    {
      return 0;
    }
  max=T[1];
  T[1]=T[size];
  size=size-1;
  maxHeapify(1);
  return max;
}





main()
{
  char command[10];
  int key;
  while(1)
    {
      scanf("%s",command);
      if(strcmp(command,"end")==0)
	{
	  break;
	}
      else if(strcmp(command,"insert")==0)
	{
	  scanf("%d",&key);
	  maxHeapInsert(key);
	}
      else if(strcmp(command,"extract")==0)
	{
	  printf("%d\n",heapExtractMax());
	}
    }
  return 0;
}

Measured memory_bytes: 4696
#include <bits/stdc++.h>
		using namespace std;
		#define pll pair<ll,ll>
		typedef long long ll;
		#define mod 1000000007
		#define fi first
		#define se second
		#define mp make_pair
		#define pb push_back
		#define INF 1e15
		
		long long binpow(long long a, long long b, long long m) {
			a %= m;
			long long res = 1;
			while (b > 0) {
				if (b & 1)
					res = res * a % m;
			a = a * a % m;
			b >>= 1;
			}
		return res;
		}
		ll modinverse(int A,int M)
		{
			return binpow(A,M-2,M);
		}
		
		int main()
		{
			ll n,k;
			cin>>n>>k;
			ll fac[100050];
			fac[0]=1;
			ll v[100050];
			for(ll i=1;i<=n;i++)
				{fac[i]=fac[i-1]*i;
				fac[i]%=mod;}
			ll ncr[100050]={0};
			for(ll i=0;i<=n;i++)
			{
				if(i>=(k-2)){
				ncr[i]=(fac[i]*modinverse(fac[k-2],mod))%mod;
				ncr[i]*=modinverse(fac[i-(k-2)],mod);
				ncr[i]%=mod;
				}
			}
		
			for(ll i=1;i<=n;i++)
			{
				ncr[i]+=ncr[i-1];
				ncr[i]%=mod;
			}
			for(ll i=0;i<n;i++)
			{
				cin>>v[i];
			}
			if(k==1)
			{
				cout<<0;
				exit(0);
			}
			
			sort(v,v+n);
		
			ll ans=0;
			for(ll i=0;i<n;i++)
			{
				if(i>(k-2))
				{
					ans+=(ncr[i-1]*v[i])%mod;
					ans%=mod;
					
				
				}
				if(i<=(n-2))
				{
					ans=(ans-(ncr[n-2-i]*v[i])%mod+mod)%mod;
				}
			//	cout<<ans<<endl;
			}
			cout<<ans;
			
		}


Measured memory_bytes: 2560
n,m=map(int,input().split())
a=[]
for i in range(n):
    a.append(list(map(int,input().split())))

num_drink=0
price=0
a.sort()
for i in a:

    if num_drink+i[1]<m:
        
        num_drink+=i[1]
        price+=i[1]*i[0]

    else:
        price+=(m-num_drink)*i[0]

        break
    
print(price)

Measured memory_bytes: 27760
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



//Dinic

#define SIZE 505


//辺を表す構造体(行先、容量、逆辺のインデックス)
struct Edge{
	Edge(int arg_to,int arg_capacity,int arg_rev_index){
		to = arg_to;
		capacity = arg_capacity;
		rev_index = arg_rev_index;
	}
	int to,capacity,rev_index;
};

struct Info{

	int a,b,cost;
};

int V,E;

vector<Edge> G[SIZE]; //グラフの隣接リスト表現
int dist[SIZE]; //sourceからの距離
int cheked_index[SIZE]; //どこまで調べ終わったか
int A[SIZE];
char buf[SIZE];
Info info[1005];


//fromからtoへ向かう容量capacityの辺をグラフに追加する
void add_edge(int from,int to,int capacity){
	G[from].push_back(Edge(to,capacity,G[to].size()));
	G[to].push_back(Edge(from,0,G[from].size()-1)); //逆辺の、初期容量は0
}

//sourceからの最短距離をBFSで計算する
void bfs(int source){
	for(int i = 0; i < V; i++)dist[i] = -1;
	queue<int> Q;
	dist[source] = 0;
	Q.push(source);

	while(!Q.empty()){
		int node_id = Q.front();
		Q.pop();
		for(int i = 0; i < G[node_id].size(); i++){
			Edge &e = G[node_id][i];
			if(e.capacity > 0 && dist[e.to] < 0){ //辺の容量が正で、かつエッジの行先に未訪問の場合
				dist[e.to] = dist[node_id]+1;
				Q.push(e.to);
			}
		}
	}
}

//増加パスをDFSで探す
int dfs(int node_id,int sink,int flow){
	if(node_id == sink)return flow; //終点についたらflowをreturn

	for(int &i = cheked_index[node_id]; i < G[node_id].size(); i++){ //node_idから出ているエッジを調査
		Edge &e = G[node_id][i];
		if(e.capacity > 0 && dist[node_id] < dist[e.to]){ //流せる余裕があり、かつsourceからの距離が増加する方法である場合
			int tmp_flow = dfs(e.to,sink,min(flow,e.capacity)); //流せるだけ流す
			if(tmp_flow > 0){ //流せた場合
				e.capacity -= tmp_flow; //流した分、エッジの容量を削減する
				G[e.to][e.rev_index].capacity += tmp_flow; //逆辺の容量を、流した分だけ増加させる
				return tmp_flow;
			}
		}
	}
	return 0;
}


//sourceからsinkへの最大流を求める
int max_flow(int source,int sink){ //source:始点 sink:終点
	int flow = 0,add;
	while(true){ //増加パスが存在する限り、流量を追加し続ける
		bfs(source);
		if(dist[sink] < 0)break; //sourceからsinkへと辿り着く残余グラフがない、つまり増加パスが無くなった場合、break
		for(int i = 0; i < V; i++)cheked_index[i] = 0;
		while((add = dfs(source,sink,BIG_NUM)) > 0){ //増加パスが見つかる間、加算
			flow += add;
		}
	}
	return flow;
}


int main(){

	int N,M;
	scanf("%d %d",&N,&M);
	V = N+2;

	scanf("%s",buf);

	for(int i = 0; i < N; i++){

		scanf("%d",&A[i]);
	}

	for(int i = 0; i < M; i++){

		scanf("%d %d %d",&info[i].a,&info[i].b,&info[i].cost);
		info[i].a--;
		info[i].b--;

		if(info[i].a > info[i].b){

			swap(info[i].a,info[i].b);
		}
	}

	int source = N,sink = N+1;

	for(int i = 0; i < N; i++){

		if(buf[i] == 'L'){

			add_edge(source,i,A[i]);
			add_edge(i,sink,0);

		}else{

			add_edge(source,i,0);
			add_edge(i,sink,A[i]);
		}
	}

	for(int i = 0; i < M; i++){

		add_edge(info[i].b,info[i].a,info[i].cost);
	}


	printf("%d\n",max_flow(source,sink));

	return 0;
}



Measured memory_bytes: 3300
private fun readInts() = readLine()!!.split(" ").map { it.toInt() }

fun main(args: Array<String>) {
    val (K, S) = readInts()

    var c = 0
    for (x in 0..K) {
        for (y in 0..K) {
            val z = S - x - y
            if (!(z < 0 || K < z) && x + y + z == S) c++
        }
    }

    println(c)
}

Measured memory_bytes: 36004
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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; }

ll MOD;
ll mod_pow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;  // n の最下位bitが 1 ならば x^(2^i) をかける
        x = x * x % MOD;
        n >>= 1;  // n を1bit 左にずらす
    }
    return ret;
}

int main() 
{
  cin>>MOD;
  ll sum=0;
  rep(i,1000000){
    sum+=7*mod_pow(10,i);
    sum%=MOD;
    if(sum==0) {cout<<i+1<<endl; return 0;}
  }
  cout<<-1<<endl;
  return 0;
}

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

int main() {
    int n;
    string s;

    cin >> n >> s;
    
    if (s.size() <= n) {
        cout << s << endl;
    }
    else {
        string new_s = "";
        rep(i, n) {
            new_s += s.at(i);
        }
        cout << new_s << "..." << endl;
    }

}

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

#define     bip(a)         __builtin_popcount(a)
#define     ull            unsigned long long
#define     ll             long long
#define     u              unsigned
#define     pb             push_back
#define     pf             push_front ///for list
#define     mp             make_pair
#define     is             insert
#define     ff             first
#define     ss             second
#define     vi             vector<int>
#define     vl             vector<ll>
#define     si             set<int>
#define     sl             set<ll>
#define     li             list<int>
#define     pii            pair<int,int>
#define     pll            pair<ll,ll>
#define     mii            map<int,int>
#define     mll            map<ll,ll>
#define     ma             INT_MAX
#define     mi             INT_MIN
#define     mod            1000000007
#define     pi             3.14159265359
#define     e              2.71828182846
#define     inf            1000000000000000LL
#define     all(x)         x.begin(), x.end()
#define     lb(a,b,c)      lower_bound(a,a+b,c)-a
#define     ub(a,b,c)      upper_bound(a,a+b,c)-a
#define     lbv(a,c)       lower_bound(all(a),c)-a.begin()
#define     ubv(a,c)       upper_bound(all(a),c)-a.begin()
#define     srt1(a,b)      sort(a,a+b)
#define     srt2(a,b)      sort(a,a+b,greater<int>())
#define     gcd(a,b)       __gcd(a,b)
#define     lcm(a,b)       (a*(b/gcd(a,b)))
#define     harmonic(n)    0.57721566490153286l+log(n)
#define     mem(a, b)      memset(a, b, sizeof(a))

///s.lower_bound(a),s.upper_bound(a), for set
///nCr(x, y) = nCr(x-1, y-1) + nCr(x-1, y)
///factorial digit   ((n * log10(n / e) +log10(2 * pi * n) /2.0));


int main()
{
    ll n;
    cin>>n;
    int c2=0;
    while(n%2==0){
        n/=2;
        c2++;
    }
    int a=1,ans=0;
    for(int i=1; i<=40; i++){
        if(c2>=a){
            c2-=a;
            ans++;
            a++;
        }
        else break;
    }
    for(ll i=3; i<=sqrt(n); i+=2){
        if(n%i==0){
            int cnt=0;
            while(n%i==0){
                n/=i;
                cnt++;
            }
            int b=1;
            for(int i=1; i<=40; i++){
                if(cnt>=b){
                    cnt-=b;
                    ans++;
                    b++;
                }
                else break;
            }
        }
    }
    if(n>2 && ans==0)cout<<1<<endl;
    else if(ans!=0 && n>2)cout<<ans+1<<endl;
    else cout<<ans<<endl;
}



Measured memory_bytes: 3700
def solve():
    n, m = map(int, input().split())
    ab = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: x[0])
    count, spend = 0, 0
    for a, b in ab:
        if count + b > m:
            spend += a * (m - count)
            break
        else:
            spend += a * b
            count += b
    return spend


if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 29792
#include<cstdio>
#include<algorithm>
#include<vector>
#define pb push_back
#define forall(x,i) for (int i=0,_t=x.size();i<_t;i++)
using namespace std;

int n;
vector<int> A[55],B[55],C[55],D[55];
int fat_B[55],fat_C[55]; int tot[55];
void dfs0(int x,int f){
	fat_B[x]=f;
	forall(B[x],i){
		int v=B[x][i];
		if (v==f) continue;
		dfs0(v,x);
	}
}
void dfs1(int x,int f){
	fat_C[x]=f; tot[x]=fat_C[x]==fat_B[x];
	forall(C[x],i){
		int v=C[x][i];
		if (v==f) continue;
		dfs1(v,x);
		tot[x]+=tot[v];
	}
}
int work(int x,int y){
	//printf("work %d %d\n",x,y);
	for (int i=1;i<=n;i++) vector<int>().swap(C[i]);
	for (int i=1;i<=n;i++)
		forall(A[i],j){
			int v=A[i][j];
			if (i!=x&&v!=x) C[i].pb(v);
		}
	C[x].pb(y); C[y].pb(x);
	dfs0(x,0); dfs1(x,0);
	//puts("test");
	//for (int i=1;i<=n;i++) printf("fat %d: B %d C %d\n",i,fat_B[i],fat_C[i]);
	for (int i=1;i<=n;i++) if (tot[i]&&fat_C[i]!=fat_B[i]) return 1e9;
	//puts("valid test A passed");
	for (int i=1;i<=n;i++) vector<int>().swap(D[i]);
	int S=0;
	for (int i=1;i<=n;i++)
		if (fat_C[i]!=fat_B[i]){
			S++;
			forall(C[i],j){
				int v=C[i][j];
				if (v==fat_C[i]) continue;
				D[v].pb(i);
			}
			int v=fat_B[i];
			if (fat_C[v]!=fat_B[v]) D[v].pb(i);
		}
	//printf("S %d\n",S);
	static int que[55],hd,tl,deg[55]; hd=tl=0;
	for (int i=1;i<=n;i++) deg[i]=0;
	for (int i=1;i<=n;i++)
		forall(D[i],j) ++deg[D[i][j]];
	for (int i=1;i<=n;i++) if (fat_C[i]!=fat_B[i]&&!deg[i]) que[++tl]=i;
	while (hd<tl){
		int u=que[++hd],v;
		forall(D[u],i){
			v=D[u][i];
			if (!--deg[v]) que[++tl]=v;
		}
	}
	if (tl!=S) return 1e9;
	//puts("valid test B passed");
	return S;
}
int deg[55];
void init(){}
void solve(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		vector<int>().swap(A[i]),
		vector<int>().swap(B[i]),
		deg[i]=0;
	for (int i=1;i<n;i++){
		int u,v; scanf("%d%d",&u,&v);
		A[u].pb(v); A[v].pb(u);
		deg[u]++,deg[v]++;
	}
	for (int i=1;i<n;i++){
		int u,v; scanf("%d%d",&u,&v);
		B[u].pb(v); B[v].pb(u);
	}
	bool flg=1;
	for (int i=1;i<=n;i++){
		sort(A[i].begin(),A[i].end());
		sort(B[i].begin(),B[i].end());
		if (A[i]!=B[i]) flg=0;
	}
	if (flg) return puts("0"),void();
	int ans=1e9;
	for (int i=1;i<=n;i++) if (deg[i]==1)
		for (int j=1;j<=n;j++) if (i^j)
			ans=min(ans,work(i,j)+1);
	if (ans==1e9) puts("-1");
	else printf("%d\n",ans);
}
int main()
{
	int T;
	scanf("%d",&T);
	while (T--) init(),solve();
	return 0;
}

Measured memory_bytes: 3252
import bisect
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    i = bisect.bisect_left(A, 0)
    j = bisect.bisect_right(A, 0)
    if i % 2 == 0:
        print(sum([abs(i) for i in A]))
    else:
        if i != j:
            print(sum([abs(i) for i in A]))
        elif i == N:
            print(sum([abs(i) for i in A]) - 2 * abs(A[-1]))
        else:
            if abs(A[i-1]) > A[i]:
                print(sum([abs(i) for i in A]) - 2 * abs(A[i]))
            else:
                print(sum([abs(i) for i in A]) - 2 * abs(A[i-1]))
main()


Measured memory_bytes: 14496
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <tuple>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
using namespace std;

#define ll int64_t
const long MOD = 1e9 + 7;


int main()
{
  int n;

  cin >> n;

  bool ans=false;
  for (int i = 0; i <= 100; ++i)
  {
    for(int j=0;j<=100-i;j++){
      if (i+j>0)if (4*i + 7*j==n)ans =true;
    }
  }
  

  if (ans == true) {
    cout << "Yes";
  } else {
    cout << "No";
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>
#include <fstream>
#include <cassert>
using namespace std;

//common

typedef int  i32;
typedef long long i64,ll;
typedef long double ld;

#define BR "\n"
#define ALL(c) (c).begin(),(c).end()
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,r) for(int i=(int)l;i<(int)(r);++i)
#define EACH(it,o) for(auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l,v,r) ((l)<=(v) && (v)<(r))

//config
//#define NDEBUG
//#define INF 1<<30
//#define EPS 1e-8
//const ll MOD =100000007;

//debug
#ifdef NDEBUG
#define DUMP(x)
#define DUMPLN(x)
#define DEBUG(x)
#define DEBUGLN(x)
#define LINE()
#define LINELN()
#define CHECK(exp,act)
#define STOP(e)
#else
#define DUMP(x)  cerr << #x << " = " << (x)
#define DUMPLN(x)  DUMP(x) <<endl
#define DEBUG(x) DUMP(x) << LINE() << " " << __FILE__
#define DEBUGLN(x) DEBUG(x)<<endl
#define LINE()    cerr<< " (L" << __LINE__ << ")"
#define LINELN()    LINE()<<endl
#define CHECK(exp,act)  if(exp!=act){DUMPLN(exp);DEBUGLN(act);}
#define STOP(e)  CHECK(e,true);if(!(e)) exit(1);
#endif

template<class T> inline string toString(const vector<T>& x) {
	stringstream ss;
	REP(i,x.size()){
		if(i!=0)ss<<" ";
		ss<< x[i];
	}
	return ss.str();
}

template<class T> inline string toString(const vector<vector<T> >& map) {
	stringstream ss;
	REP(i,map.size()){
		if(i!=0)ss<<BR;
		ss<< toString(map[i]);
	}
	return ss.str();
}
template<class K,class V>  string toString(map<K,V>& x) {
	string res;stringstream ss;
	for(auto& p:x)ss<< p.first<<":" << p.second<<" ";
	return ss.str();
}

string BITtoString(int bit){
    stringstream ss;
    while(bit!=0){ss<<(bit%2);bit/=2;}
    string res=ss.str();reverse(ALL(res));
    return res;
}

template<typename T> inline T pmod(T v,T MOD){
	return (v%MOD+MOD)%MOD;
}
#define nextInt(n) scanf("%d",&n)
#define defInt(n) int n;nextInt(n)
#define nextLong(n) scanf("%lld",&n)
#define defLong(n) ll n;nextLong(n)
#define nextDouble(n) scanf("%lf",&n)

class Main{
public:

        int N;
        bool input(){
            //   ifstream cin("in");
            //  ofstream cout( "out" );
            nextInt(N);
            return N!=0;
        }

        void run(){
            while(input()){
            	N=1000-N;
            	ll res=0;
            	res+=N/500;N%=500;
            	res+=N/100;N%=100;
            	res+=N/50;N%=50;
            	res+=N/10;N%=10;
            	res+=N/5;N%=5;
            	res+=N/1;N%=1;

            	cout << res<<endl;
            }
        }
};

int main(){
	//cout <<fixed<<setprecision(3);	
	//ios::sync_with_stdio(false);
	Main().run();
	return 0;
}

Measured memory_bytes: 1200