akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <climits>
#include <algorithm>

int main()
{
	int n,m;
	std::cin >> n >> m;
	std::vector<long> score(n);
	std::vector<std::vector<long>> data(n,std::vector<long>(3));
	long ans = LONG_MIN,temp=0;
	for (int i = 0; i < n; i++) {
		std::cin >> data[i][0] >> data[i][1] >> data[i][2];
	}
	for (int i = 0; i < 2; i++)
		for (int j = 0; j < 2; j++)
			for (int k = 0; k < 2; k++) {
				for (int l = 0; l < n; l++) {
					score[l] = i ? data[l][0]: -data[l][0];
					score[l] += j ? data[l][1] : -data[l][1];
					score[l] += k ? data[l][2] : -data[l][2];
				}
				std::sort(score.begin(), score.end(),std::greater<long>());
				temp = 0;
				for (int ii = 0; ii < m; ii++) {
					temp += score[ii];	
				}
				ans = std::max(ans, temp);
			}
	std::cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
// template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE


typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define Mod 1000000007
#define MAX 5002

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll h,w,a,b;cin>>h>>w>>a>>b;
	ll ans[h][w];
	For(i,0,h){
		For(j,0,w){
			if(i<b)
				ans[i][j] = 1;
			else
				ans[i][j] = 0;
		}
	}
	For(j,0,a){
		For(i,0,h){
			ans[i][j] = !ans[i][j];
		}
	}
	For(i,0,h){
		For(j,0,w){
			cout<<ans[i][j];
		}
		cout<<endl;
	}































	
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define md 1000000007
int main()
{
    int n,m; cin >> n >> m;
    if(n == 1 && m == 2) cout << 3 ;
         if(n == 1 && m == 3) cout << 2 ;
     if(n == 2 && m == 3) cout << 1 ;
      if(n == 2 && m == 1) cout << 3 ;
      if(n == 3 && m == 2) cout << 1 ;
      if(n == 3 && m == 1) cout << 2 ;
    
}


Measured memory_bytes: 256
# coding: utf-8
from functools import lru_cache


@lru_cache(maxsize=1000)
def test2(n):
    if n == 0:
        return 2
    elif n == 1:
        return 1
    else:
        return test2(n-1) + test2(n-2)


if __name__ == "__main__":
    n = int(input())
    dict = {0:2, 1:1}
    print(test2(n))

Measured memory_bytes: 3940
import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n, k = map(int, input().split())
    dp = [0] * (k + 1)
    dp[0] = 1
    for a in map(int, input().split()):
        # accumulate dp
        S = [0] * (k + 2)
        for i in range(k + 1):
            S[i + 1] = S[i] + dp[i]
            if S[i + 1] >= MOD:
                S[i + 1] -= MOD
        # ndp[i] = dp[i - a] + ... + dp[i]
        dp = [(S[i + 1] - S[max(0, i - a)]) % MOD for i in range(k + 1)]

    print(dp[k])
resolve()

Measured memory_bytes: 133812
import java.util.*;

public class Main {
	 public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
         for(;;){
            int n = sc.nextInt();
            if(n==0) break;
            
            int ba =0;
            int []te = new int[n];
            String s = sc.next();
            for(int i=0; i<100; i++){
            	if(s.charAt(i)=='M'){
            		te[i%n]++;
            	}else if(s.charAt(i)=='S'){
            		ba += te[i%n] +1;
            		te[i%n]=0;
            	}else{
            		te[i%n] += ba +1;
            		ba = 0;
            	}
            }
            Arrays.sort(te);
            for(int i=0; i<n; i++) System.out.print(te[i] + " ");
            System.out.println(ba);
            		
            }
          }
}

Measured memory_bytes: 21816
#include <bits/stdc++.h>
#define db(a) cout << a << endl
#define db2(a,b) cout << a << " " << b << endl
#define dbd(a) cout << #a << ": " << a << endl
#define dbd2(a,b) cout << #a << ": " << a << ", " << #b << ": " << b << endl 
#define dbp(a) cout << a.first << " " << a.second << endl
#define adb(a) for(auto _i:a) cout << _i << " "; cout << endl
#define adbp(a) for(auto _i:a) cout << _i.first << " " << _i.second << endl;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 998244353
#define N 10000010
#define M 100010
using namespace std;

int main()
{
    fastIO;
    long long n, x;
    cin >> x >> n;

    if(n == 0)
    {
        cout << x << endl;
        return 0;
    }

    long long a[n], i;
    set<long long> st;
    for(i=0;i<n;i++)
    {
        cin >> a[i];
        st.insert(a[i]);
    } 

    long long cl = 0, diff = 110;
    for(i=0;i<105;i++)
    {
        if(!st.count(i) && abs(i-x) < diff)
        {
            diff = abs(i-x);
            cl = i;
        }
    }

    cout << cl << endl;
    return 0;
}

Measured memory_bytes: 3620
def main():
    l = input().split()
    k, x = int(l[0]), int(l[1])
    min_x = x - (k - 1)
    max_x = x + (k - 1)
    all = list(range(min_x, max_x+1))
    asn = " ".join([str(s) for s in all])
    print(asn) 
    
if __name__=="__main__":
    main()


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

#define int long long
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()

signed main(){
    string s[3];
    rep(i,3) cin >> s[i];
    rep(i,3) cout << (char)(s[i][0]-'a'+'A');
    cout << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static boolean visited[][];
	public static String[][] map;
	static int numberOfBlack;
	
	public static void CheckBlackTiles(int a, int b,int w,int h) {
		numberOfBlack++;
		visited[a][b] = true;
		if(a+1<h && map[a+1][b].equals(".")&& visited[a+1][b]==false) {
			CheckBlackTiles(a+1,b,w,h);
		}
		if(a-1>=0 && map[a-1][b].equals(".")&& visited[a-1][b]==false) {
			CheckBlackTiles(a-1,b,w,h);
		}
		if(b+1<w && map[a][b+1].equals(".") && visited[a][b+1]==false) {
			CheckBlackTiles(a,b+1,w,h);
		}
		if(b-1>=0 && map[a][b-1].equals(".") && visited[a][b-1]==false) {
			CheckBlackTiles(a,b-1,w,h);
		}
	}
	
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int w;
		int h;
		
		while(true) {
			w = in.nextInt();
			h = in.nextInt();
			if(w==0||h==0) {
				break;
			}
			
			numberOfBlack=0;
			map = new String[h][w];
			visited = new boolean[h][w];

			
			for(int i=0; i<h;i++){    
                String buffer=in.next();
                //文字列格納後に1文字ずつ分離
                for(int l=0; l<buffer.length();l++) {
                	map[i][l]= String.valueOf(buffer.charAt(l));
                	visited[i][l]= false;
                }
			}

			for(int i=0; i<h;i++){
                for(int k=0; k<w;k++){
                	if(map [i][k].equals("@")&&visited[i][k]==false){
                		CheckBlackTiles(i,k,w,h);
                    }
                }      
			}
			System.out.println(numberOfBlack);
		}
		in.close();
	}
}

Measured memory_bytes: 12000
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
	cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	cout << head;
	if (sizeof...(tail) != 0) cout << " ";
	print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
	for (auto& a : vec) {
		cout << a;
		if (&a != &vec.back()) cout << " ";
	}
	cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
	for (auto& vec : df) {
		print(vec);
	}
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	auto N = IN();
	auto D = IN();
	auto X = IN();
	i64 ans = X;
	REP(i, N)
	{
		i64 a;
		cin >> a;
		ans += D / a;
		if (D % a != 0)
			ans++;
	}
	print(ans);
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


Measured memory_bytes: 256
import sys
n=int(input())
t,a = map(int, input().split())
h = list(map(int, input().split()))
tt = [abs(a - (t-h[i]*0.006)) for i in range(n)]
ans = 1000000000
for i in range(n):
  ans = min(ans, tt[i])
for i in range(n):
  if tt[i] == ans:
    print(i+1)
    sys.exit()

Measured memory_bytes: 3064
// D - Road to Millionaire
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(int)(s);i<(int)(e);++i)

int main(){
	int N; cin>>N;
	vector<int> A(N+1);
	rp(i, 0, N) cin>>A[i];
	int64_t yen = 1000, kabu_yen, kabu_n = kabu_yen = 0;
	rp(i, 1, N+1){
		if(A[i-1] < A[i]){ // buy
			int64_t m = yen / A[i-1];
			int64_t cost = (int64_t)m * A[i-1];
			yen -= cost;
			kabu_yen += cost;
			kabu_n += m;
		}
		else if(A[i-1] > A[i]){ // sell
			yen += kabu_n * A[i-1];
			kabu_yen = kabu_n = 0;
		}
	}
	cout<< yen <<endl;
}


Measured memory_bytes: 3624
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();// 几个500
		int B = sc.nextInt();// 几个100
		int C = sc.nextInt();// 几个50
		int X = sc.nextInt();
		int ans = 0;
		int i,j,k;
		for (i = 0; i <= A; i++) {
			for (j = 0; j <= B; j++) {
				for (k = 0; k <= C; k++) {
					if (500 * i + 100 * j + 50 * k == X)
						ans+=1;
				}
			}
		}
		System.out.println(ans);

		
	}
}


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

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

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976

ll dp[100100][3];

int main()
{
    int n; cin >> n;
    ll a[n][3];
    rep(i,n) rep(j,3) cin >> a[i][j];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(j == k) continue;
                if(dp[i+1][k] < dp[i][j] + a[i][k]){
                    dp[i+1][k] = (dp[i][j] + a[i][k]);
                }
            }
        }
    }
    ll ans = 0;
    rep(i,3) ans = max(ans,dp[n][i]);
    cout << ans << endl;
}

Measured memory_bytes: 4992
def main():
    N = int(input())
    X = list(map(int, input().split(" ")))

    nums = sorted(X)
    center = len(nums)//2

    dic = {}
    for i,x in enumerate(nums):
        if x not in dic:
            dic[x] = i

    if len(nums)%2 == 0:
        is_even = True
    else:
        is_even = False

    for x in X:
        i = dic[x]
        if is_even:
            if i < center:
                print(nums[center])
            else:
                print(nums[center-1])
        else:
            print(nums[center+1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 39940
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll dp[102][100005];
int main()
{
	ll n,W;
	cin>>n>>W;
	ll va[n+1],wt[n+1];
	for(int i=1;i<=n;i++)
	cin>>wt[i]>>va[i];
	for(int i=0;i<=n;i++)
	for(int j=1;j<=100000;j++)
	dp[i][j]=INT_MAX;
	ll ans=0;
	for(int i=1;i<=n;i++)
	{
		for(ll j=1;j<=100000;j++)
		{
			if(j<va[i])
			{
				dp[i][j]=dp[i-1][j];
				continue;
			}
			dp[i][j]=min(dp[i-1][j-va[i]]+wt[i],dp[i][j]);
			dp[i][j]=min(dp[i][j],dp[i-1][j]);
			if(dp[i][j]<=W)
			ans=max(ans,j);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 79232
#include <iostream>
#include <vector>

using namespace std;


template<typename T>
ostream& operator<<(ostream& out, const vector<T> &v) {
    for(auto it=v.begin();it != v.end();it++) {
        cout << *it << " ";
    }
    cout << endl;
    return out;
}

const int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<int> c(n, 0);
    vector<int> prev(n, -1); // prev[i]はj<iでc[j]=c[i]になる最大のj（なければ-1）
    vector<int> last(200001, -1);
    for(int i=0;i<n;i++) {
        cin >> c[i];
        if (last[c[i]] != -1) {
            prev[i] = last[c[i]];
        }
        last[c[i]] = i;
    }
    vector<int> dp(n, 0);
    dp[0] = 1;
    for(int i=1;i<n;i++) {
        dp[i] += dp[i-1];
        if (prev[i] != -1 && prev[i] != i-1) {
            dp[i] = (dp[i] + dp[prev[i]]) % MOD;
        }
    }
    //cout << prev;
    //cout << dp;
    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 3328
N = int(input())
A = list(map(int, input().split()))

cnt = 0
flag = 1

#  バブルソート
while flag:
    flag = 0

    for j in range(N-1, 0, -1):
        if A[j] < A[j-1]:
            A[j], A[j-1] = A[j-1], A[j]
            flag = 1
            cnt += 1

print(*A)
print(cnt)



Measured memory_bytes: 5612
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 LN             PIC X(60).
01 N              PIC 9(19).
01 A              PIC 9(19).
01 B              PIC 9(19).
01 dv             PIC 9(19).
01 rm             PIC 9(19).
01 ans            PIC 9(19).
01 ZS             PIC Z(18)9.

PROCEDURE DIVISION.
  ACCEPT LN.
  UNSTRING LN DELIMITED BY SPACE INTO N A B.
  COMPUTE dv = N / (A + B).
  COMPUTE rm = N - dv * (A + B).
  COMPUTE ans = A * dv + FUNCTION MIN(A, rm).
  MOVE ans TO ZS.
  DISPLAY ZS.
  STOP RUN.


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define dmp(x) cerr<<#x<<":"<<x<<endl
#define FOR(i,a,b) for(int i=(int)a,c=(int)b;i<c;++i)
#define rep(i,b) FOR(i,0,b)
#define ROF(i,a,b) for(int i=b-1,c=(int)a;i>=c;--i)
#define per(i,b) ROF(i,0,b)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

vector<int> g[111111];
int used[111111]; 

void dfs(int v){
  if(used[v])return;
  used[v]=1;
  rep(i,sz(g[v]))dfs(g[v][i]);
}

signed main(){
  int n,m;
  cin>>n>>m;
  rep(i,m){
    int x,y,z;
    cin>>x>>y>>z;
    x--,y--;
    g[x].pb(y);
    g[y].pb(x);
  }
  int ans=0;
  rep(i,n){
    if(used[i])continue;
    ans++;
    dfs(i);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 9856
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

N,K=map(int,input().split())
for i in range(1,K+1):
 print((cmb(N-K+1, i, mod)*cmb(K-1, i-1, mod))%(10**9+7))


Measured memory_bytes: 4584
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n; cin >> n;
  vector<int> p(n * n); REP(i, n * n) cin >> p[i], --p[i];
  int ans = 0;
  vector dep(n, vector(n, 0));
  REP(i, n) REP(j, n) dep[i][j] = min({i, n - 1 - i, j, n - 1 - j});
  vector exist(n, vector(n, true));
  REP(idx, n * n) {
    int y = p[idx] / n, x = p[idx] % n;
    ans += dep[y][x];
    --dep[y][x];
    exist[y][x] = false;
    deque<pair<int, int>> que;
    que.emplace_back(y, x);
    while (!que.empty()) {
      auto [i, j] = que.front(); que.pop_front();
      REP(k, 4) {
        int ny = i + dy[k], nx = j + dx[k];
        if (0 <= ny && ny < n && 0 <= nx && nx < n) {
          if (exist[ny][nx]) {
            if (dep[ny][nx] > dep[i][j] + 1) {
              dep[ny][nx] = dep[i][j] + 1;
              que.emplace_back(ny, nx);
            }
          } else {
            if (dep[ny][nx] > dep[i][j]) {
              dep[ny][nx] = dep[i][j];
              que.emplace_front(ny, nx);
            }
          }
        }
      }
    }
    // REP(i, n) REP(j, n) cout << dep[i][j] << " \n"[j + 1 == n];
    // cout << '\n';
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 6328
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>

using namespace std;
using llong = long long;
const int MOD=1000000007;

int main(int argc, char**argv){
    int a, b, c;
    cin >> a >> b >> c;
    int sum = a + b + c;
    int max_val = max(max(a, b), c);

    bool is_even = (sum % 2) == 0;

    if (is_even){
        if (max_val % 2 != 0){
            max_val++;
        }
        cout << (max_val*3 - sum) / 2 << endl;
        return 0;
    }else{
        if (max_val % 2 == 0){
            max_val++;
        }
        cout << (max_val*3 - sum) / 2 << endl;
        return 0;
    }

    return 0;
}





Measured memory_bytes: 256
#include <stdio.h>

int main( void ){
    int n, x, i, min, maxv;

    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d", &x);
        if(i == 0){
            min = x;
        }
        else if(i == 1){
            maxv = x - min;
            if(x < min){
                min = x;
            }
        }
        else{
            if(maxv < x - min){
                maxv = x - min;
            }
            if(x < min){
                min = x;
            }
        }
    }
    printf("%d\n", maxv);
    return 0;
}



Measured memory_bytes: 2100
#include<iostream>
#include <algorithm>
#include <vector>
#include <deque>
using namespace std;
using ll = long long;
ll gcd(ll a, ll b){
    if (a%b == 0){
        return b;
    }else{
        return gcd(b,a%b);
    }
}


int main()
{
    // 整数の入力
    long long  N,M,i,max,core;
    string S,T;
    cin >> N >> M;
    cin >> S >> T;
    core = gcd(N,M);
    max = N*M /core;
    ll Ndiff = max/N;
    ll Mdiff = max/M;
    ll Xdiff = max/core;

    for(i = 0;i < max;i = i+ Xdiff ){
        if (S[i/Ndiff] != T[i/Mdiff]){
            max = -1;
        }
    }
    cout << max << endl;


    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
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; }






int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;cin >> n >> m;
	if(m == 0){
		cout << "Yes" << endl;
		return 0;
	}
	vector<int> l(m), r(m), d(m);
	vector<vector<pii>> g(n);
	rep(i,m){
		cin >> l.at(i) >> r.at(i) >> d.at(i);
		l.at(i)--;
		r.at(i)--;
		g[l.at(i)].pb(mp(r.at(i),d.at(i)));
		g[r.at(i)].pb(mp(l.at(i),-d.at(i)));
	}
	vector<int> x(n);
	queue<int> q;
	vector<bool> visited(n);
	bool ok = true;
	rep(j,n){
		if(visited.at(j)) continue;
		visited.at(j) = true;
		q.push(j);
		while(!q.empty()){
			int cur = q.front();q.pop();
			rep(i,g[cur].size()){
				int next = g[cur][i].first, t = g[cur][i].second;
				if(visited.at(next)){
					if(x[next] - x[cur] != t) ok = false;
				}
				else{
					visited.at(next) = true;
					x.at(next) = x.at(cur) + t;
					q.push(next);
				}
			}
		}
	}
	if(ok) cout << "Yes" << endl;
	else cout << "No" << endl;
}


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int n; cin >> n;
  int i = 1;
  while ((i * 2) <= n) i *= 2;
  cout << i << '\n';
}


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


int main(void){
    char s[4];
    int i,count=1,ans=0,j;
    scanf("%s",&s);
    for(i=1;i<=3;i++){
        if(s[0]==s[i]){
            count +=1;
            j=i;
        }
    }
    if(count==2){
        if(j==1){
            if(s[2]==s[3]){
                printf("Yes\n");
                ans=1;
            }
        }else if(j==2){
            if(s[1]==s[3]){
                printf("Yes\n");
                ans=1;
            }
        }else{
            if(s[1]==s[2]){
                printf("Yes\n");
                ans=1;
            }
        }
    }
    if(ans==0){
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

char S[55],T[55]="AKIHABARA";

int main()
{
  scanf ("%s",S);
  int i=0,j=0;
  while (S[i]||T[j]){
if (S[i] == T[j]) i++, j++;
    else if ('A' == T[j]) j++;
    else{
      S[i] = 'a';
      break;
    }
  }
  puts(S[i]?"NO":"YES");
return 0;
}


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

int recursive(int n) {
  if (n < 10) {
    return n;
  }
  return recursive(n / 10) + (n % 10);
}

int main() {
  int N;
  cin >> N;
  int num = recursive(N);
  cout << (N % num == 0 ? "Yes" : "No") << endl;
  return 0;
}

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

#ifdef LOCAL
	#define D(a) cerr << #a << " = " << a << endl
#else
	#define D(a)
	#define cerr false && cerr
#endif
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define dforn(i,n) dforsn(i,0,n)
#define forn(i,n) forsn(i,0,n)
#define all(a) a.begin(),a.end()
#define si(a) int((a).size())
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first
#define endl '\n'
using pii = pair<int,int>;
using vi = vector<int>;
using ll = long long;

int main() {
	fastio;
	
    int n; cin >> n;
    vi v(2*n); for (int &x : v) cin >> x;

    sort(all(v));

    int sum = 0;
    forn(i, n) sum += min(v[2*i], v[2*i + 1]);

    cout << sum << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <vector>
#include <climits>
#include <queue>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
template<typename T1, typename T2>
inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2>
inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
const ll MOD = 1000000007;
const ll INF = 1LL << 60;



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

	vector<ll> a(n);
	rep(i, n) cin >> a[i];

	ll temp = 1;
	bool zero = false;
	bool over = false;
	rep(i, n) {
		if (a[i] == 0) zero = true;
		if ((long double)1000000000000000000.0 / (long double)a[i] < (long double)temp)
			over = true;


		temp *= a[i];

		if (temp > 1000000000000000000)
			over = true;

	}

	if (zero)
		cout << 0;
	else if (over)
		cout << -1;
	else
		cout << temp;


}




Measured memory_bytes: 4048
#include<cstdio>
#include<algorithm>
#define MN 510000
using namespace std;

const int MOD=1e9+7;
int n,k,a[1100000],w=0,ans=1e9;
inline int min(int x,int y){return x>y?y:x;}
int main(){
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++) if (scanf("%d",&a[i]),a[i]<=0) w=i;
	
	if (n-w>=k&&ans>a[w+k]) ans=a[w+k];
	if (w-k+1>0) ans=min(ans,-a[w-k+1]);
	for (int i=max(w-k+2,1);i<=w;i++)
	if (n>=k+i-1) ans=min(min(a[k+i-1],-a[i])+a[i+k-1]-a[i],ans);
	printf("%d\n",ans);
}

Measured memory_bytes: 512
# -*- coding utf-8 -*-
s=list(str(input()))

s1 = [i  for (i,x) in enumerate(s) if x =='A' ]
s2 = [i  for (i,x) in enumerate(s) if x =='Z' ]

x=min(s1)
y=max(s2)
print(y-x+1)


Measured memory_bytes: 12804
package main

import (
  "fmt"
  "strings"
)



func main() {
  var n int
  var s string
  fmt.Scanf("%v", &n)
  fmt.Scanf("%s", &s)
  ss := strings.Split(s, "")

  var count_ [26]int
  for _, v := range ss {
    i := v[0] - 'a'
    count_[i] += 1
  }

  sum := 1
  for _, v := range count_ {
    sum = sum * (1+v)
    if sum > 1000000007 {sum = sum%1000000007}
  }
  sum -= 1
  fmt.Print(sum)
}


Measured memory_bytes: 4196
#include <bits/stdc++.h>
#define SORT(c) sort((c).begin(),(c).end())
#define db(x) cout<<#x<<"="<<x<<endl
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define reprs(i, m, n) for(int i = n; i >= m; i--)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;

int main(){

  int N;
  cin >> N;
  cout << 3*N*N <<endl;
  return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
ans = 0
ss = []
for i in range(m):
    k, *s = map(int, input().split())
    ss.append(s)
ps = list(map(int, input().split()))
for i in range(2**n):
    status = format(i, 'b').zfill(n)
    areAllLit = True
    for j in range(m):
        amount = 0
        for k in ss[j]:
            if status[k-1] == '1':
                amount += 1
        if amount % 2 != ps[j]:
            areAllLit = False
    if areAllLit:
        ans += 1
print(ans)

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

template <class T>
class SegTree {
	int n;                       // 葉の数
	vector<T> data;              // データを格納するvector
	T def;                       // 初期値かつ単位元
	function<T(T, T)> operation; // 区間クエリで使う処理
	function<T(T, T)> update;    // 点更新で使う処理

	// 区間[a,b)の総和。ノードk=[l,r)に着目している。
	T _query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) return def; // 交差しない
		if (a <= l && r <= b)
			return data[k]; // a,l,r,bの順で完全に含まれる
		else {
			T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子
			T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子
			return operation(c1, c2);
		}
	}

public:
	// _n:必要サイズ, _def:初期値かつ単位元, _operation:クエリ関数,
	// _update:更新関数
	SegTree(size_t _n, T _def, function<T(T, T)> _operation,
		function<T(T, T)> _update)
		: def(_def), operation(_operation), update(_update) {
		n = 1;
		while (n < _n) {
			n *= 2;
		}
		data = vector<T>(2 * n - 1, def);
	}

	// 場所i(0-indexed)の値をxで更新
	void change(int i, T x) {
		i += n - 1;
		data[i] = update(data[i], x);
		while (i > 0) {
			i = (i - 1) / 2;
			data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
		}
	}

	// [a, b)の区間クエリを実行
	T query(int a, int b) {
		return _query(a, b, 0, 0, n);
	}

	// 添字でアクセス
	T operator[](int i) {
		return data[i + n - 1];
	}
};

int main() {
	int N, Q;
	cin >> N >> Q;
	SegTree<long long> st(N, (1LL << 31) - 1,
					[](long long a, long long b) {return min(a, b); },
					[](long long a, long long b) {return b; });
	REP(q, Q) {
		int c, x, y;
		cin >> c >> x >> y;
		if (c == 0)st.change(x, y);
		else cout << st.query(x, y + 1) << endl;
	}
	return 0;


}


Measured memory_bytes: 4888
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <set>

using namespace std;

#pragma GCC oprimize("Ofast")
#define rep(i,a,b) for(__typeof(b)i=a;i<b;++i)
#define fs first
#define sc second
#define pb emplace_back

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vl2;
typedef pair<ll,ll> pl;

const ll inf = ~((ll)1<<(ll)63);

ll mem[100010];
set<ll> no;
ll n,m;

ll dp(ll at)
{
    if(at>n)return 0;
    if(at==n)return 1;
    if(mem[at]!=-1)return mem[at];
    ll ans = 0;
    if(no.find(at+1)==no.end())ans+=dp(at+1)%1000000007;
    if(no.find(at+2)==no.end())ans+=dp(at+2)%1000000007;
    return mem[at] = ans%1000000007;
}

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

	memset(mem,-1,sizeof(mem));

    cin >> n >> m;
    rep(i,0,m)
    {
        ll tmp;
        cin >> tmp;
        no.insert(tmp);
    }
    cout << dp(0);

	return 0;
}


Measured memory_bytes: 5760
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define int long long

signed main() {
  string s;
  cin >> s;
  if(s[0] != 'A') {
    cout << "WA" << endl;
    return 0;
  }
  if (s[1] < 'a' || s[1] > 'z') {
    cout << "WA" << endl;
    return 0;
  }
  int count = 0;
  for (int i = 2; i < s.size() - 1; i++) {
    if (s[i] == 'C') count++;
    else if (s[i] < 'a' || s[i] > 'z') {
      cout << "WA" << endl;
      return 0;
    }
  }
  if (s[s.size() - 1] < 'a' || s[s.size() - 1] > 'z') {
    cout << "WA" << endl;
    return 0;
  }
  if (count == 1) {
    cout << "AC" << endl;
  } else {
    cout << "WA" << endl;
  }
  return 0;
}


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

using ll = long long;
const ll amari = 1e9+7;
const char BC = 'A' - 'a';
#define ben(a) a.begin(),a.end()
#define pb(a,b) a.push_back(b)
//fixed << setprecision(20)

int main(){
	int n;
	cin >> n;
	int w[n];
	int sum = 0;
	for(int i = 0; i < n; i++){
		cin >> w[i];
		sum += w[i];
	}
	int ans = 99999999;
	int left = 0;
	for(int i = 0; i < n; i++){
		left += w[i];
		ans = min(ans,abs((sum-left)-left));
	}
	cout << ans << endl;
	return 0; 
}

Measured memory_bytes: 256
n=int(input())


ac=0
wa=0
tle=0
re=0
for i in range(n) :
    s=str(input())
    if s=="AC" :
        ac=ac+1
    elif s=="WA" :
        wa=wa+1
    elif s=="TLE" :
        tle=tle+1
    else :
        re=re+1


print("AC x",ac)
print("WA x",wa)
print("TLE x",tle)
print("RE x",re)

Measured memory_bytes: 9208
#include <iostream>
#include <complex>
#include <cmath>
#include <stdio.h>

using namespace std;
typedef complex<double> xy_t;
xy_t P[110];
int main() {
	int N=0;
	double x,y;
	while (scanf("%lf,%lf", &x, &y) != EOF){
		P[N++] = xy_t(x,y);
	}
	double sum=0.0;
	for (int i=0; i+2<N; i++){
		xy_t a=P[0], b=P[i+1], c=P[i+2];
		xy_t vec1 = b-a, vec2 = c-a;
		sum += ((conj(vec1)*vec2).imag()) / 2;
	}
	printf("%.6f\n", abs(sum));
}

Measured memory_bytes: 3164
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn input_vec() -> Vec<u64> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn main() {
    let vals = input_vec();
    let k: u32 = input();
    let mut max_val = 0u64;
    let mut max_idx = 0;
    for i in 0..3usize {
        if vals[i] > max_val {
            max_val = vals[i];
            max_idx = i;
        }
    }
    let mut ans = 0;
    for i in 0..3 {
        // println!("{}", ans);
        if i == max_idx {
            ans += 2u64.pow(k) * max_val;
        } else {
            ans += vals[i];
        }
    }
    println!("{}", ans);
}


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

int main()
{
	int n;
	long a;
	long all = 0;
	long min = 1000000;
	long max = -1000000;

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> a;
		if (a < min)
		{
			min = a;
		}
		if (a >= max)
		{
			max = a;
		}
		all = all + a;
	}

	cout << min <<" "<< max <<" "<< all << "\n";

	return 0;
}

Measured memory_bytes: 3100
#include <stdio.h>

#define Mod 1000000007

int main()
{	
	int N, M;
	scanf("%d %d", &N, &M);
	
	int i, j, k;
	long long dp[302][302] = {}, tmp;
	for (k = 1, dp[1][1] = 1; k <= M; k++) {
		for (i = k; i >= 1; i--) {
			for (j = i; j >= 1; j--) {
				tmp = dp[i][j] % Mod;
				dp[i][j] = 0;
				dp[i+1][j] += tmp * (N - i);
				dp[i][i] += tmp * j;
				dp[i][j] += tmp * (i - j);
			}
		}
	}
	
	printf("%lld\n", dp[N][N] % Mod);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 2408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 100100100100100;
const ll mod = 1000000007;
typedef pair<int,int> P;
#define fi first
#define se second
#define pb push_back
int main(){
   int a,b,c,d,e,f;
   cin>>a>>b>>c>>d>>e>>f;
   vector<int> wat;
for(int i=0;a*100*i<=f;i++){
    for(int j=0;a*100*i+j*b*100<=f;j++){
        if(i==0&&j==0)continue;
        int x=a*100*i+b*j*100;
        wat.pb(x);
    }
}
double ans=0.0;int sug=0,sum=0;
for(int i=0;i<wat.size();i++){
      int x=wat.at(i);
      for(int j=0;x+c*j<=f;j++){
          for(int k=0;x+c*j+d*k<=f;k++){
              if(x/100*e<c*j+d*k)break;
            double rec=double(c*j+d*k)/(double)(x+c*j+d*k);
            if(ans<=rec){
                   sum=x+c*j+d*k;
                   sug=c*j+d*k;
                   ans=rec;
            }
          }
      }
}
cout<<sum<<" "<<sug<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

void solve(long long k, long long q, std::vector<long long> d, std::vector<long long> n, std::vector<long long> x, std::vector<long long> m){
  vector<ll> sumd(k);
  sumd[0]=d[0];
  REP(d.size()-1){
    sumd[i+1]=sumd[i]+d[i+1];
  }
  For(times,q){
    const ll mod=m[times];
    ll nn=n[times]-1;
    ll zcnt=0;
    ll xx=x[times]%mod;
    vector<ll> dd(k),sumdd(k);
    REP(k){
      dd[i]=d[i]%mod;
      if(dd[i]==0)++zcnt;
    }
    sumdd[0]=dd[0];
    REP(k-1){
      sumdd[i+1]=sumdd[i]+dd[i+1];
    }
    ll lasta=xx+sumdd.back()*(nn/k)+(nn%k>0?sumdd[nn%k-1]:0);
    ll ans=nn-(nn/k)*zcnt;
    dump(ans);
    dump(lasta);
    REP(nn%k){
      if(dd[i]==0)--ans;
    }
    dump(zcnt);
    cout<<ans-lasta/mod<<endl;
  }
}

int main(){
  cout<<setprecision(1000);
  cin.tie(0);
  ios::sync_with_stdio(false);
    long long k;
    scanf("%lld",&k);
    long long q;
    scanf("%lld",&q);
    std::vector<long long> d(k-1-0+1);
    for(int i = 0 ; i < k-1-0+1 ; i++){
        scanf("%lld",&d[i]);
    }
    std::vector<long long> n(q);
    std::vector<long long> x(q);
    std::vector<long long> m(q);
    for(int i = 0 ; i < q ; i++){
        scanf("%lld",&n[i]);
        scanf("%lld",&x[i]);
        scanf("%lld",&m[i]);
    }
    solve(k, q, std::move(d), std::move(n), std::move(x), std::move(m));
    return 0;
}


Measured memory_bytes: 640
#include"bits/stdc++.h"
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> & l, const pair<T1, T2> & r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> & l, const pair<T1, T2> & r) { return make_pair(l.first - r.first, l.second - r.second); }
lint N, K, a, f;
vector<lint> A, F;

bool check(lint val) {
	lint rest = K;
	REP(i, N) {
		lint y = ((A[i] * F[i] - val - 1) / F[i] + 1);
		if ((A[i] * F[i] - val) <= 0) {
			y = 0ll;
		}
		lint x = max(0ll, y);
		rest -= x;
	}
	return rest < 0 ? true : false;
}

int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> N >> K;
	REP(i, N) {
		cin >> a;
		A.push_back(a);
	}	
	REP(i, N) {
		cin >> f;
		F.push_back(f);
	}
	sort(ALL(A));
	sort(ALL(F));
	reverse(ALL(F));
	lint lb = -1, ub = 1e12+1;
	while (ub - lb > 1) {
		lint mid = (lb + ub) / 2;
		if (check(mid)) lb = mid;
		else ub = mid;
	}
	cout << ub;
}


Measured memory_bytes: 4848
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
using namespace std;

typedef long long ll;
ll MOD = 1e9+7;

ll dp[100001][3];
ll a[100000][3];

int main()
{
	int n;
	int ans=0;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i][0]>>a[i][1]>>a[i][2];
	fill(dp[0],dp[3],0);
	
	for(int i=1;i<n+1;i++)
	{
		dp[i][0]=a[i-1][0]+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=a[i-1][1]+max(dp[i-1][0],dp[i-1][2]);
		dp[i][2]=a[i-1][2]+max(dp[i-1][0],dp[i-1][1]);
	}
	cout<<max({dp[n][0],dp[n][1],dp[n][2]})<<endl;
	return 0;
}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String SA = sc.next();
        String SB = sc.next();
        String SC = sc.next();

        int iA = 0;
        int iB = 0;
        int iC = 0;
        char player = 'a';
        while (player == 'a' && iA < SA.length() || player == 'b' && iB < SB.length()
                || player == 'c' && iC < SC.length()) {
            // System.out.println(String.format("%c : %d %d %d", player, iA, iB, iC));
            switch (player) {
            case 'a':
                player = SA.charAt(iA);
                iA += 1;
                break;
            case 'b':
                player = SB.charAt(iB);
                iB += 1;
                break;
            case 'c':
                player = SC.charAt(iC);
                iC += 1;
                break;
            }
        }
        System.out.println(String.valueOf(player).toUpperCase());
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
const int MAXN=2e5+10;
int N;
pii Pos[MAXN],MaxPos[4]={pii(-1e9+1,-1e9+1),pii(-1e9+1,-1e9+1),pii(-1e9+1,-1e9+1),pii(-1e9+1,-1e9+1)};
inline ll ans(){
    int dx[]={1,1,-1,-1},dy[]={1,-1,-1,1};
    for(int i=1;i<=N;i++)
        for(int j=0;j<4;j++){
            pii Tmp=pii(Pos[i].first*dx[j],Pos[i].second*dy[j]);
            if(Tmp.first+Tmp.second>MaxPos[j].first+MaxPos[j].second)
                MaxPos[j]=Tmp;
        }
    return max( MaxPos[0].first+MaxPos[0].second+MaxPos[2].first+MaxPos[2].second , MaxPos[1].first+MaxPos[1].second+MaxPos[3].first+MaxPos[3].second );
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>N;
    for(int i=1;i<=N;i++) cin>>Pos[i].first>>Pos[i].second;
    cout<<ans()<<endl;
    return 0;
}

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

int main(){
  vector<int> a(3);
  int k;
  
  for(int i = 0; i < 3; i++){
    cin >> a[i];
  }

  cin >> k;
  
  sort(a.begin(), a.end());
 
  cout << a[0] + a[1] + a[2] * pow(2, k) << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()

{
    int a;
    scanf("%d",&a);
    switch(a){
        case 22:
        printf("Christmas Eve Eve Eve\n");
        break;
        case 23:
        printf("Christmas Eve Eve\n");
        break;
        case 24:
        printf("Christmas Eve\n");
        break;
        default:
        printf("Christmas\n");



    }



return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;

const int maxn = 1e5 + 10;
ll n , m , a[maxn] , b[maxn];
const int mod = 1e9 + 7;


int main()
{
	ios_base::sync_with_stdio(0); cin.tie(NULL);
	cin >> n >> m;
	for(int i=0;i<n;i++) cin >> a[i];
	for(int i=0;i<m;i++) cin >> b[i];		
	ll one = a[1] - a[0];
	ll last = one;
	for(int i=2;i<n;i++)
	{
		last = ((a[i] - a[i-1]) * i) + last;
		one += last;
	}
	ll two = b[1] - b[0];
	last = two;
	for(int i=2;i<m;i++)
	{
		last = ((b[i] - b[i-1]) * i) + last;
		two += last;
	}
	one %= mod;
	two %= mod;
	cout << one * two % mod;
}

Measured memory_bytes: 1792
#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 MAX_N = 100005;
ll a[MAX_N],B[100000];

ll mygcd(ll a, ll b)
{
	if (b == 0) return a;
	else return mygcd(b,a%b);
}

ll lcm(ll a, ll b)
{
	return a / mygcd(a,b) * b;
}

int main()
{
	ll N,M;
	cin >> N >> M;
	rep(i,N)
	{
		cin >> a[i];
		a[i] /= 2;
	}
	ll temp = a[0];
	int p = 0;
	while (temp % 2 == 0)
	{
		p++;
		temp /= 2;
	}
	rep(i,N-1)
	{
		temp = a[i+1];
		int pp = 0;
		while(temp % 2 == 0)
		{
			pp++;
			temp /= 2;
		}
		if (pp != p)
		{
			cout << "0" << endl;
			return 0;
		}
	}

	ll L = a[0];
	rep(i,N-1)
	{
		L = lcm(L,a[i+1]);
		//cout << L << endl;
		if (L > M)
		{
			cout << "0" << endl;
			return 0;
		}
	}
	cout << M/L - M/(L*2) << endl;
	return 0;
}

Measured memory_bytes: 4404
import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] ar = new int[200001];
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < N; i++) {
            int Ai = sc.nextInt();
            ar[Ai]++;
            set.add(Ai);
        }
        Arrays.sort(ar);
        int dir = set.size()-K;
        int count = 0;
        for (int a : ar) {
            if (a == 0) {
                continue;
            } else {
                if (dir <= 0) {
                    break;
                }
                count += a;
                dir--;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 101656
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
int main() {
  int n;
  cin >> n;
  while (n) {
    if (n % 10 == 7) {
      cout << "Yes" << endl;
      return 0;
    }
    n /= 10;
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <cmath>
#include <algorithm>

using namespace std;

int main(void) {
	while(1) {
		string str;
		bool balance = true;
		stack<char> sbracket;

		getline(cin, str);
		if(str == ".") break;
		for(int i = 0; str[i] != '.'; i++) {
			if(str[i] == '(' || str[i] == '[') {
				sbracket.push(str[i]);
			}
			if(str[i] == ')') {
				if(sbracket.size() == 0 || sbracket.top() != '(') {
					balance = false;
					break;
				}
				sbracket.pop();
			}
			if(str[i] == ']') {
				if(sbracket.size() == 0 || sbracket.top() != '[') {
					balance = false;
					break;
				}
				sbracket.pop();
			}
		}
		if(sbracket.size() > 0) balance = false;
		printf(balance ? "yes\n" : "no\n");
	}
	return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define wh(t) while(t--)
#define fi(n) for(long long i = 0; i < n; i++)
#define fj(n) for(long long j = 0; j < n; j++)
#define fu(i,s,e) for(ll i = s; i <=e; i++)
#define fd(i,s,e) for(ll i = s; i >=e; i--)
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define sll stack<ll>
#define qll queue<ll>
using namespace std;
const ll M = 1e9+7;
//const ll M = 998244353;

ll pmp(ll x,ll n){
	ll a = 1;
	while(n > 0){
		if(n & 1) a = (a * x)%M;
		x = (x * x) % M;
		n = n>>1;
	}
	return a;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t;
	t = 1;
	// cin >> t;
	wh(t){
		ll n,k;
		cin >> n >> k;
		vi v(n,0);
		fi(k){
			ll d;
			cin >> d;
			fi(d){
				ll x;
				cin >> x;
				v[x-1] = 1;
			}
		}
		ll sum=0;
		fi(n){
			sum+=v[i];
		}
		cout << n-sum;
	}
	return 0;
}

Measured memory_bytes: 3664