akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	var k int64
	fmt.Fscan(r, &n, &m, &k)
	a := make([]int64, n+1)
	b := make([]int64, m+1)
	for i := 0; i < n; i++ {
		var tmp int64
		fmt.Fscan(r, &tmp)
		a[i+1] = a[i] + tmp
	}
	for i := 0; i < m; i++ {
		var tmp int64
		fmt.Fscan(r, &tmp)
		b[i+1] = b[i] + tmp
	}
	var ans int
	for i := 0; i <= n; i++ {
		if a[i] > k {
			continue
		}
		j := sort.Search(len(b), func(j int) bool { return a[i]+b[j] > k })
		if i+j-1 > ans {
			ans = i + j - 1
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 8516
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	cout << a+b+c - max(a,max(b,c)) << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.math.abs
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val n = readInteger()
    val count = readIntegerList()
        .groupingBy { it }
        .eachCount()
    val ans = count.map {
        count.getOrDefault(it.key - 1, 0) +
                count.getOrDefault(it.key, 0) +
                count.getOrDefault(it.key + 1, 0)
    }.max()
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 58856
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<numeric>

/*
3|hまたは3|wのとき0.
h=3t±1とおく。
[1](t±1)*wを分割する
残りは等分にできるのでw.
[2]t*wを分割する
i)2|wのとき
残りを等分してw/2.
ii)otherwise
残りは(2t±1)*(w±1)/2（二番目の複号の両方）である。
これらの間の差は2t±1となる。
twとの差が大きい方は複号が一致する場合で差は(2t±1+w)/2であり、
[1]より[2]が小さくなるという条件では2t±1より大きい。
（また、これはw/2より大きいので無条件で採用してよい。）
*/

using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h, w;
	cin >> h >> w;
	int ans = min(h, w);
	ans = min(ans, (w - (w + 1) / 3+h)/2);
	ans = min(ans, (h - (h + 1) / 3+w)/2);
	if ((h % 2) == 0) ans = min(ans, h/2);
	if ((w % 2) == 0) ans = min(ans, w/2);
	if ((h % 3)*(w % 3) == 0) ans = 0;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int N;
  int p[50];
  int tigau = 0;

  cin >> N;

  for(int i = 0;i < N;i++){
    cin >> p[i];
  }

  for(int i = 0;i < N;i++){
    if(p[i] != i+1){
      tigau++;
    }
  }

  if(tigau <= 2){
    cout << "YES";
  }else{
    cout << "NO";
  }
  
}

Measured memory_bytes: 256
A,B,C=input().split()
A=int(A)
B=int(B)
C=int(C)

if A==B and A!=C:
	print("Yes")
    
elif B==C and A!=B:
	print("Yes")
    
elif A==C and A!=B:
	print("Yes")
    
else:
	print("No")

Measured memory_bytes: 3060
#include<stdio.h>
#define N 500000
 
int A[N],n,n1,number,count;
 
int searchNumber(int);
 
int main(){
 
  int i,j,T[N];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
 
  scanf("%d",&n1);

  for(i=0;i<n1;i++){
    scanf("%d",&T[i]);
    number = searchNumber(T[i]);
    if( number != -1 ){
      count++;
    }
  }
 
  printf("%d\n",count);
  return 0;
}

int searchNumber(int key){
  int left,right,mid;
  left = 0;
  right = n;
  while(left < right){
    mid = (left + right) / 2;
    if(A[mid] == key){
      return A[mid];
    }
    else if(key < A[mid]){
      right = mid;
    }
    else{
      left = mid + 1;
    }
  }
  return -1;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;

int main(){
	int n;
	cin>>n;
	vector<int>x(n);
	for(int i=0;i<n;i++)cin>>x[i];
	int ans=1e9;
	for(int i=0;i<=100;i++){
		int tmp=0;
		for(int j=0;j<n;j++){
			tmp+=(x[j]-i)*(x[j]-i);
		}
		if(tmp<ans)ans=tmp;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    s=input()
    x=len(s)//2
    l1=[1,0]*x+[1]
    l2=[0,1]*x+[0]
    cnt1=0
    cnt2=0
    for i in range(len(s)):
        if s[i]!=str(l1[i]):
            cnt1+=1
        if s[i]!=str(l2[i]):
            cnt2+=1
    print(min(cnt1,cnt2))
resolve()

Measured memory_bytes: 5476
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D - Megalomania
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

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

/* global variables */

pii ps[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++)
    scanf("%d%d", &(ps[i].second), &(ps[i].first));
  sort(ps, ps + n);

  ll sum = 0;
  for (int i = 0; i < n; i++) {
    sum += ps[i].second;
    if (sum > ps[i].first) {
      puts("No");
      return 0;
    }
  }

  puts("Yes");
  return 0;
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

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

#define DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	string s;
	getline(cin, s);
	rep(i, s.size())
	{
		if(s[i] >= 'a' && s[i] <= 'z')
			s[i] -= abs('A' - 'a');
		else if(s[i] >= 'A' && s[i] <= 'Z')
			s[i] += abs('A' - 'a');
	}
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 3184
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def make_adjlist_d(n, edges):
    res = [[] for _ in range(n+1)]
    for edge in edges:
        res[edge[0]].append(edge[1])
    return res


def main():
    N, M = NMI()
    edges = [NLI() for _ in range(M)]
    S, T = NMI()

    tree = [[] for _ in range(3*N+1)]
    for e in edges:
        tree[e[0]].append(e[1]+N)
        tree[e[0]+N].append(e[1]+2*N)
        tree[e[0]+2*N].append(e[1])

    stack = deque()
    stack.append(S)
    seen = [-1] * (3*N+1)
    seen[S] = 0
    while stack:
        now = stack.popleft()
        now_step = seen[now]
        for goto in tree[now]:
            if seen[goto] >= 0:
                continue

            stack.append(goto)
            seen[goto] = now_step + 1

    print(seen[T]//3)



if __name__ == "__main__":
    main()

Measured memory_bytes: 126304
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;
}

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


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  string t;
  cin >> t;

  int ans = 100000;

  rep(i, 26) {
    char ch = 'a' + i;
    string s = t;
    do {
      bool f = true;
      rep(j, s.size()) if (s[j] != ch) f = false;
      if (f) ans = min(ans, (int)(t.size() - s.size()));

      string tmp = "";
      rep(j, s.size() - 1) {
        if (s[j] == ch || s[j + 1] == ch)
          tmp += ch;
        else
          tmp += '-';
      }
      s = tmp;
    } while (s.size());
  }

  cout << ans << endl;
}


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

#define rep(x, y) for (int i = (x); i < (y); i++)

typedef long long ll;

using namespace std;

int main() {
    ll a, b, k;
    cin >> a >> b >> k;

    if (k <= a) {
        cout << (a - k) << " " << b << endl;
    } else if (k <= (a + b)) {
        cout << 0 << " " << (b - (k - a)) << endl;
    } else {
        cout << 0 << " " << 0 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
from statistics import mean, median,variance,stdev
import sys
import math
import fractions

def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())

n = ip()                              #入力整数1つ
#t,x= (int(i) for i in input().split())      #入力整数横2つ
#x,y,z = (int(i) for i in input().split())    #入力整数横3つ
#n,m,x,y= (int(i) for i in input().split())  #入力整数横4つ
a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列

#jの変数はしようできないので注意

a.sort()
if max(a) < sum(a)-max(a): j(1)
else: j(0)

Measured memory_bytes: 5660
n,m=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(n)]
b=[list(map(int,input().split())) for _ in range(m)]

for i in range(n):
  c=10**10
  e=0
  for j in range(m):
    d=abs(a[i][0]-b[j][0])+abs(a[i][1]-b[j][1])
    if d<c:
      c=d
      e=j
  print(e+1)

Measured memory_bytes: 9112
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
using namespace std;
int ans=0;
int main(){
    ios::sync_with_stdio(false);
    ll a,b;
    cin >> a >> b;
    b--;
    while(b > 0){
        b -= a-1;
        ans++;
    }
    cout << ans;
    
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define abs(x) ((x)>0?(x):-(x))
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define inf 2000000000
#define ll long long
//#define file
using namespace std;

int a[20011][4],ls[2011],g[2011],X[2001],Y[2001],c[2001],d[1000001],n,i,j,k,l,len,st,ed,h,t;
ll f[2011],ans;
bool bz[2011];

void NEW(int x,int y,int z,int w) {++len;a[len][0]=y;a[len][1]=ls[x];ls[x]=len;a[len][2]=z;a[len][3]=w;}
void New(int x,int y,int z,int w) {NEW(x,y,z,w),NEW(y,x,0,-w);}

int main()
{
	#ifdef file
	freopen("agc034d.in","r",stdin);
	#endif
	
	scanf("%d",&n);st=n*2+1,ed=n*2+2;len=1;
	fo(i,1,n*2) scanf("%d%d%d",&X[i],&Y[i],&c[i]);
	fo(i,1,n) New(st,i,c[i],0),New(i,ed+1,c[i],X[i]+Y[i]),New(i,ed+2,c[i],X[i]-Y[i]),New(i,ed+3,c[i],-X[i]+Y[i]),New(i,ed+4,c[i],-X[i]-Y[i]);
	fo(i,n+1,n+n) New(i,ed,c[i],0),New(ed+1,i,c[i],-(X[i]+Y[i])),New(ed+2,i,c[i],-(X[i]-Y[i])),New(ed+3,i,c[i],-(-X[i]+Y[i])),New(ed+4,i,c[i],-(-X[i]-Y[i]));
	
	while (1)
	{
		memset(f,128,sizeof(f));
		h=0;t=1;
		d[1]=st;f[st]=0;bz[st]=1;
		while (h<t)
		{
			for (i=ls[d[++h]]; i; i=a[i][1])
			if (a[i][2] && f[d[h]]+a[i][3]>f[a[i][0]])
			{
				f[a[i][0]]=f[d[h]]+a[i][3],g[a[i][0]]=i;
				if (!bz[a[i][0]]) d[++t]=a[i][0],bz[a[i][0]]=1;
			}
			bz[d[h]]=0;
		}
		
		if (f[ed]<-1152921504606846976ll) break;
		l=inf;
		for (i=ed; i!=st; i=a[g[i]^1][0]) l=min(l,a[g[i]][2]);
		ans+=f[ed]*l;
		for (i=ed; i!=st; i=a[g[i]^1][0]) a[g[i]][2]-=l,a[g[i]^1][2]+=l;
	}
	printf("%lld\n",ans);
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}

Measured memory_bytes: 4164
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j,key;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
  
  for(i=1;i<=n;i++){
  key=A[i];
  j=i-1;
  
  while(j>=0&&A[j]>key){
  A[j+1]=A[j];
  j--;
  A[j+1]=key;
  }
  trace(A, n);
  
  }
 
  return 0;
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
#include <fstream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

//#define _debug
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sc(x) scanf("%d",&x)
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORd(i,a,b) for(int i=a;i>b;i--)
#define ff first
#define ss second
#define sz(x) x.size()
#define pb push_back
//#define _online_judge

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, //data type
        null_type, //
        less<int>, //
        rb_tree_tag, //red-black tree
        tree_order_statistics_node_update> new_data_set;

typedef pair<int,int> pii;
typedef vector<pii> vii;
const int con = static_cast<const int>(1e5 + 2);
const int MOD = 1000000007;

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

}


int main (){
	FASTIO
#ifdef _online_judge
	freopen("input.txt" , "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif

    int a,b,c;cin >> a >> b >> c;
    if(a > b) swap(a,b);
    if(a < c && c < b){
        cout << "Yes";
        return 0;
    }
    cout << "No";
    return 0;
}


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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;

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

    bool flag = false;
    rep(i, N) {
        rep(j, N) {
            if ((4 * i) + (7 * j) == N) {
                flag = true;
            }
        }
        if (flag) break;
    }

    if (flag) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
void Say(bool say, string a = "Yes", string b = "No"){cout << (say ? a : b) << endl;};

int main(){

    ll A, B;
    cin >> A >> B;
    ll tmp = 1;
    ll ans = 0;
    while(tmp < B){
        ans++;
        tmp += (A - 1);
    }
    cout << ans << endl;

    return 0;
}

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

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

    long long tmp = n;

    long long ans = 0;
    long long tt = 0;
    long long d = 1;
    while(tmp > 9){
        ans += 9;
        d *= 10;
        tt = tt*10 + 9;
        tmp /= 10;
    }

    for(int i = 1;i<=9;i++){
        if(tt + i*d <= n){
            ans++;
        }
    }

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




Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        int N = int.Parse(str[0]);
        long W = int.Parse(str[1]);
        str = Console.ReadLine().Split(' ');
        long w1 = int.Parse(str[0]);
        List<long>[] v = new List<long>[4];
        for(int i=0;i<4;i++){
            v[i] = new List<long>();
        }
        v[0].Add(int.Parse(str[1]));
        for(int i=1;i<N;i++){
            str = Console.ReadLine().Split(' ');
            v[int.Parse(str[0])-w1].Add(int.Parse(str[1]));
        }
        long[][] V = new long[4][];
        for(int i=0;i<4;i++){
            V[i] = v[i].ToArray();
            Array.Sort(V[i],(a,b)=>(a>b ? -1 : (a<b ? 1 : 0)));
        }
        long count = 0;
        long sum1 = 0;
        long nw1 = 0;
        for(int i=0;i<=V[0].Length;i++){
            if(nw1 > W){
                break;
            }
            long sum2 = sum1;
            long nw2 = nw1;
            for(int j=0;j<=V[1].Length;j++){
                if(nw2 > W){
                    break;
                }
                long sum3 = sum2;
                long nw3 = nw2;
                for(int k=0;k<=V[2].Length;k++){
                    if(nw3 > W){
                        break;
                    }
                    long sum4 = sum3;
                    long nw4 = nw3;
                    for(int l=0;l<=V[3].Length;l++){
                        if(nw4 > W){
                            break;
                        }
                        count = Math.Max(count,sum4);
                        if(l != V[3].Length){
                            sum4 += V[3][l];
                            nw4 += w1+3;
                        }
                    }
                    if(k != V[2].Length){
                        sum3 += V[2][k];
                        nw3 += w1+2;
                    }
                }
                if(j != V[1].Length){
                    sum2 += V[1][j];
                    nw2 += w1+1;
                }
            }
            if(i != V[0].Length){
                sum1 += V[0][i];
                nw1 += w1;
            }
        }
        sb.Append(count+"\n");
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
using ll = int_fast64_t;
using ull = uint_fast64_t;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vull = vector<ull>;
#define rep(i, n) for (ull i = 0; i < n; ++i)
#define rep1(i, n) for (ull i = 1; i < n; ++i)
#define iter(it, v) for (auto it = v.begin(); it != v.end(); ++it)
#define pb push_back
#define fi first
#define se second
#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }
template <typename T> void vecout(const T &v) {
  for (auto it = v.begin(); it != v.end();
       ++it, cout << (it != v.end() ? " " : "\n")) {
    cout << *it;
  }
}

void solve() {
  // input
  ll n,m; cin>>n>>m;
  vll keys(m),costs(m);
  ll a,b,c,key;
  rep(i,m) {
    cin>>a>>b;
    costs[i]=a;
    key=0;
    rep(_,b) {
      cin>>c;
      c--;
      key|=(1<<c);
    }
    keys[i]=key;
  }
  // dynamic programing
  vll dp(1<<n,INF);
  dp[0]=0;
  rep(k,1<<n) rep(i,m) {
    dp[k|keys[i]]=min(dp[k|keys[i]],dp[k]+costs[i]);
  }
  cout<<(dp[(1<<n)-1]!=INF?dp[(1<<n)-1]:-1)<<endl;
}

int main() {
  cout << fixed << setprecision(12);
  solve();
  return 0;
}


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

int main() {
    string s;
    cin >> s;
    int count = 1;
    int L_start = 0;
    bool flag = true;
    int a[s.length()];

    for(int i = 0; i < s.length(); i++) {
        a[i] = 0;
    }

    for(int i = 0; i < s.length(); i++) {
        if(s[i] == 'R') {
            if(s[i+1] == 'R') {
                count++;
            } else {
                for(int j = 0; j < count; j++) {
                    if(j % 2 == 0) {
                        a[i]++;
                    } else {
                        a[i+1]++;
                    }
                }
                count = 1;
            }
        } else if(s[i] == 'L') {
            if(flag) {
                L_start = i;
                flag = false;
            }
            if(i == s.length()-1) {
                for(int j = 0; j < count; j++) {
                    if(j % 2 == 0) {
                        a[L_start]++;
                    } else {
                        a[L_start-1]++;
                    }  
                }
                count = 1;
                flag = true;
            } else if(s[i+1] == 'R') {
                for(int j = 0; j < count; j++) {
                    if(j % 2 == 0) {
                        a[L_start]++;
                    } else {
                        a[L_start-1]++;
                    }  
                }
                count = 1;
                flag = true;
            } else {
                count++;
            }
        }
    }

    for(int i = 0; i < s.length(); i++) {
        cout << a[i] << " ";
    }
}


Measured memory_bytes: 1024
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = 99999999;
const ll linf = 999999999999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////



int main(){
	int x,t;
	cin >> x >> t;
	P(max(x-t,0));

	return  0;
}

Measured memory_bytes: 256
N = int(input())
if N>=1 and 1000>=N:
    print(1000-N)
elif N>=1001 and 2000>=N:
    print(2000-N)
elif N>=2001 and 3000>=N:
    print(3000-N)
elif N>=3001 and 4000>=N:
    print(4000-N)
elif N>=4001 and 5000>=N:
    print(5000-N)
elif N>=5001 and 6000>=N:
    print(6000-N)
elif N>=6001 and 7000>=N:
    print(7000-N)
elif N>=7001 and 8000>=N:
    print(8000-N)
elif N>=8001 and 9000>=N:
    print(9000-N)
elif N>=9001 and 10000>=N:
    print(10000-N)

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

int main(){
    int N;
    cin>>N;
    vector<int> V(N);
    vector<int> C(N);
    vector<int> A(N);
    for(int i=0;i<N;i++) cin>>V.at(i);
    for(int i=0;i<N;i++){
         cin>>C.at(i);
         A.at(i)=V.at(i)-C.at(i);
    }

    int sum=0;
    for(int i=0;i<N;i++){
        if(A.at(i)>0) sum+=A.at(i);
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <deque>
#include <numeric>
#include <map>
#include <stack>
#include <iomanip>
#include <math.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF 100000
 
using namespace std;
 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
double PI = atan2(0, -1);
 
int main () {
	int N, M;
	cin >> N >> M;
	ll sum = 0;
	ll discount = 0;
	priority_queue<int> pq;
	int tmp;
	rep(i,N) {
		cin >> tmp;
		pq.push(tmp);
		sum += tmp;
	}
	rep(i,M) {
		int cur = pq.top();
		pq.pop();
		discount += cur - cur/2;
		pq.push(cur/2);
	}
	cout << sum - discount << endl;
    return 0;
}

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

const int N=1e5;
int act[N][3];
long long dp[N][3];
int n;

long long solve(int idx, int opt){
    if(idx==n)
        return 0;
    // if(opt > 2) opt=0;
    long long &ret= dp[idx][opt];
    if(~ret) return ret;
    ret=0;
    if(opt==0)
        ret +=max(solve(idx+1, 1)+act[idx][1],solve(idx+1,2)+act[idx][2]);

    if(opt==1)
        ret +=max(solve(idx+1, 0)+act[idx][0],solve(idx+1,2)+act[idx][2]);

    if(opt==2)
        ret +=max(solve(idx+1, 1)+act[idx][1],solve(idx+1,0)+act[idx][0]);

    return ret;
}

int main(){
    // freopen("out.txt","wt",stdout);
    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d %d %d", &act[i][0], &act[i][1], &act[i][2]);
    }
    memset(dp,-1,sizeof dp);
    long long sol = max(solve(0, 0),max(solve(0, 1),solve(0, 2)));
    printf("%lld\n", sol);
    return 0;
}

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

#define rep(i, s, n) for (Int i = s; i < (Int)(n); i++)
#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
double EPS = 1e-10;
Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    Int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    if (c * 2 > a + b) {
        Int res = min(x, y) * (a + b);
        Int sub = min(x, y);
        x -= sub;
        y -= sub;
        if (c * 2 > a) {
            res += x * a;
        } else {
            res += x * c * 2;
        }
        if (c * 2 > b) {
            res += y * b;
        } else {
            res += y * c * 2;
        }
        dump(res);
        return 0;
    } else {
        Int res = min(x, y) * c * 2;
        Int sub = min(x, y);
        x -= sub;
        y -= sub;
        if (c * 2 > a) {
            res += x * a;
        } else {
            res += x * c * 2;
        }
        if (c * 2 > b) {
            res += y * b;
        } else {
            res += y * c * 2;
        }
        dump(res);
        return 0;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

int pow_mod(int x, int n, int mod) {
  if (n == 0) return 1;
  int res = pow_mod(x*x%mod,n/2,mod);
  if (n & 1) res = res*x%mod;
  return res;
}

// 拡張gcd
int ext_gcd(int a, int b, int &x, int &y) {
  if (b == 0) {
    x = 1; y = 0; return a;
  }
  int q = a/b;
  int g = ext_gcd(b,a-q*b,x,y);
  int z = x-q*y;
  x = y; y = z;
  return g;
}

// 逆元 | a と m は互いに素
int inv_mod(int a, int m) {
  int x,y;
  ext_gcd(a,m,x,y);
  x %= m;
  if (x < 0) x += m;
  return x;
}

// 逆元(配列) | N! と MOD が互いに素
int fac[1000010], invfac[1000010], inv[1000010];
void init(int n) {
  fac[0] = 1;
  for (int i = 1; i < n; i++) fac[i] = fac[i-1]*i%MOD;
  invfac[n-1] = inv_mod(fac[n-1],MOD);
  for (int i = n-2; i >= 0; i--) invfac[i] = invfac[i+1]*(i+1)%MOD;
  for (int i = 1; i < n; i++) inv[i] = invfac[i]*fac[i-1]%MOD;
}

// 二項係数 | MOD は素数
int nCk(int n, int k) {
  if (!(0 <= k && k <= n)) return 0;
  return (((fac[n] * invfac[k]) % MOD) * invfac[n-k]) % MOD;
}

int N,A,B,C;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  cin >> N >> A >> B >> C;
  init(300000);
  int ans = 0;
  REP(i,N) {
    int tmp = nCk(N-1+i,i)*pow_mod(B,i,MOD)%MOD*pow_mod(A,N,MOD)%MOD*100%MOD*(N+i)%MOD*pow_mod(100-C,N-1-i,MOD)%MOD;
    (tmp += nCk(N-1+i,i)*pow_mod(A,i,MOD)%MOD*pow_mod(B,N,MOD)%MOD*100%MOD*(N+i)%MOD*pow_mod(100-C,N-1-i,MOD)%MOD) %= MOD;
    ans = (ans+tmp)%MOD;
  }
  ans = ans*inv_mod(pow_mod(100-C,2*N,MOD),MOD)%MOD;
  cout << ans << endl;

  return 0;
}

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

int n;
string s;
set<string> NoDup_s;

void solve(){
  for(int i = 0; i < n; i++){
    cin >> s;
    NoDup_s.insert(s);
  }
}

int main()
{
  cin >> n;
  solve();
  cout << NoDup_s.size() << endl;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}
ll ans = 0;
string S;

ll solve(int idx=0) {
    ll res = 0;
    if (idx >= S.size()) {
        S += "+";
        //cout << S << endl;
        string tmp = "";
        rep(i, S.size()) {
            if (S[i] != '+') tmp += S[i];
            else if (S[i] == '+') {
                res += stol(tmp);
                tmp = "";
            }
        }
        //res += stol(tmp);
        S.pop_back();
        return res;
    }

    if (idx+1 < S.size()) {
        string tmp = S;
        S = S.substr(0, idx+1) + "+" + S.substr(idx+1, S.size()-idx-1);
        res += solve(idx+2);
        S = tmp;
    }
    res += solve(idx+1);

    return res;
}

int main() {
    cin >> S;
    cout << solve() << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int ans = LONG_MAX;
int w[20000];
int s = 0, ps = 0, n = 0;
signed main(){
	cin >> n;
	for(int i = 1 ; i <= n ; i ++){
		cin >> w[i];
		s += w[i];
	}
	for(int i = 1 ; i <= n ; i ++){
		ps += w[i];
		ans = min(ans, abs(2*ps - s));
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i,j,k) for(int i=j;i<=k;++i)
using namespace std;
int read(){
    int x=0,l=1; char ch=getchar();
    while(!isdigit(ch)) {if (ch=='-') l=-1; ch=getchar();}
    while(isdigit(ch)) x=x*10+(ch^48),ch=getchar();
    return x*l;
}
int main(){
    int n=read(),k=read(),x,y; long long ans=0;
    For(i,k+1,n){
        x=n/i; y=n%i; ans+=(long long)x*(i-k);
        if (y>=k){
            ans+=y-k; if (k) ++ans;
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
n=i1()
a=i2()
c=[0 for i in range(n)]


for i in range(n):
 if i: c[i]+=c[i-1]
 c[i]+=a[i]

l=0
r=2
f=float("inf")
for i in range(1,n-1):
 while abs(c[l]-(c[i]-c[l]))>abs(c[l+1]-(c[i]-c[l+1])):
   l+=1
 while abs(c[r]-c[i]-(c[n-1]-c[r]))>abs(c[r+1]-c[i]-(c[n-1]-c[r+1])):
   r+=1
 e=[c[l],c[i]-c[l],c[r]-c[i],c[n-1]-c[r]]
 f=min(f,max(e)-min(e))
print(f)

Measured memory_bytes: 95608
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <cstdlib>
#define EVAL 1
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 1048576
#define PI 3.1415926535
int grid[3][3] = {};
int main() {
	REP(i, 3) {
		REP(q, 3) {
			cin >> grid[i][q];
		}
	}
	for (int i = 0;i < 3;++i) {
		for (int q = 1;q < 3;++q) {
			if (grid[i][q] - grid[i][q - 1] != grid[0][q] - grid[0][q - 1]) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	for (int i = 0;i < 3;++i) {
		for (int q = 1;q < 3;++q) {
			if (grid[q][i] - grid[q - 1][i] != grid[q][0] - grid[q-1][0]) {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}


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

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

    int x, y;
    cin >> x >> y;

    if(x%y == 0) {
        cout << -1 << endl;
        return 0;
    }

    int base = 2;
    while(1){
        int res = x*base;
        if(res % y){
            cout << res << endl;
            return 0;
        }
        ++base;
    }


    return 0;
}

Measured memory_bytes: 256
"""
index = j を満たすもののうち最大のものを消していく
→消した番号の逆順が答え
"""
n = int(input())
b = list(map(int, input().split()))

ans = []

while len(b) != 0:
    index = -1
    for j in range(len(b)):
        if j+1 == b[j]:
            index = j

    if index == -1:
        print(-1)
        exit()
    else:
        ans.append(b.pop(index))

for _ans in ans[::-1]:
    print(_ans)


Measured memory_bytes: 3060
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long

using namespace std;

int main(){

  string N;
  cin >> N;

  for (int i = 0; i < 3; i++) {
    if(N[i] == '7'){
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;

  return 0;
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  int n, k;
  cin >> n >> k;
  vector<int> vl(n);
  for (int i = 0; i < n; ++i) {
    cin >> vl[i];
  }

  sort(vl.begin(), vl.end(), greater<int>());

  int ans = 0;
  for (int i = 0; i < k; ++i) {
    ans += vl[i];
  }

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i,s,e) for (int64_t i=s; i<e; i++)
#define pi 3.14159265358979323846264338327950L
using namespace std;

int main() {
  int N, S, T, U, H;
  cin >> N;
  long int O=0;
  vector<int> x(N);
  vector<int> y(N);
  vector<int> h(N);
  rep(i,0,N) {
    cin >> x[i] >> y[i] >> h[i];
  }
  rep(i,0,N) {
    if (h[i]>0) {
      S=x[i];
      T=y[i];
      U=h[i];
      break;
    }
  }
  rep(X,0,101) {
    rep(Y,0,101) {
      H=U+abs(X-S)+abs(Y-T);
      int K=0;
      rep(i,0,N) {
        if (h[i]==max((H-abs(x[i]-X)-abs(y[i]-Y)),O)) {
          K++;
        }
      }
      if (K==N) {
        cout << X << " " << Y << " " << H << endl;
      }
    }
  }
}

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

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)
#define Float(x) OUTN(fixed, setprecision(x));

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// IN
void IN() {}
template <class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

// OUTS
void OUTS() {}
template <class Head, class... Tail>
void OUTS(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  OUTS(forward<Tail>(tail)...);
}

template <class T>
void OUTS(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void OUTS(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// OUTL
void OUTL() {}
template <class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

template <class T>
void OUTL(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// OUTN
void OUTN() {}
template <class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}

template <class T>
void OUTN(vector<T> &vec) { for (auto &e : vec) cout << e; }
// }}} End

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  vector<int> value(2);
  rep(i, 2) IN(value[i]);
  sort(all(value), greater<>());
  OUTL(value[0] + max(value[0] - 1, value[1]));
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <tuple>
#include <utility>
#include <functional>
#include <sys/time.h>
#include <iomanip>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(i, m, n) for(int i = (m); i < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
void setp(const int n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

constexpr int SZ = 26;
constexpr int D = 365;
array<int, SZ> C;
array<array<int, SZ>, D> S;

int main(void){
	int tmp;
	cin >> tmp;
	rep(i, SZ) cin >> C[i];
	rep(i, D) rep(j, SZ) cin >> S[i][j];

	array<int, SZ> last;
	rep(i, SZ) last[i] = 0;

	for (int d = 1; d <= D; ++d){
		int max = 0, ans = 0;
		rep(i, SZ) if (chmax(max, C[i] * (d - 1 - last[i]))) ans = i;
		cout << ans + 1 << endl;
		last[ans] = d;
	}

	return 0;
}


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

using namespace std;
using ll = long long;

int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  for(int i=0; i<n; i++) cin >> a[i];
  vector<ll> s(n+1, 0);

  for(int i=0; i<n; i++){
    s[i+1] = s[i] + a[i];
  }
  
  
  ll ans = 1001001001001001001;
  for(int i=1; i<n; i++){
    ll x = s[i];
    ll y = s[n]-s[i];
    ans = min(ans, abs(y-x));
  }
  
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 6360
from math import atan,degrees
a, b, x = map(int,input().split())
 
if x >= a**2 * b/2:
    print(degrees(atan(2*(a**2*b-x)/a**3) ))

elif x < a**2 * b/2:
    print(degrees(atan(b**2*a/(2*x))))

Measured memory_bytes: 3060
using System;
using System.Linq;

class Program {
    static void Main(string[] args) {
        int N = Cin.Ni();
        int K = Cin.Ni();
        int answer = 1;

        for (int i = 0; i < N; i++) {
            answer = Math.Min(answer * 2, answer + K);
        }
        Console.WriteLine(answer);
    }
}


public class Cin {
    private static string[] s = new string[0];
    private static int i = 0;

    private static char[] cs = new char[] { ' ' };

    public static string Next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return Next();
    }

    public static int Ni() {
        return int.Parse(Next());
    }

    public static long NextLong() {
        return long.Parse(Next());
    }

    public static double NextDouble() {
        return double.Parse(Next());
    }

}


Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

const int MAX = 8368791;

void solve(int& M, int& N){
  vector<bool> data(MAX, true);
  int cnt = 0, i = M - 1;
  while(cnt != N){
    i++;
    if(!data[i]) continue;
    if(data[i]) {
      for(int j = i; j < MAX; j += i) {
	data[j] = false;
      }
    }
    cnt++;
  }
  
  for(int i = M; i < MAX; i++){
    if(data[i]) {
      cout <<  i << endl;
      return ;
    }
  }
}

int main(){
  int n, m;
  while(cin >> m >> n) {
    if(m == 0 && n == 0) break;
    solve(m, n);
  }
  return 0;
}



Measured memory_bytes: 4104
S = gets.chomp.chars.map(&:to_i)
def dfs(i, n, acc)
  if i == S.size - 1
    m = S[i]
    return acc + n + m
  end
  m = S[i]
  a = dfs(i + 1, 0, acc + n + m)
  b = dfs(i + 1, (n + m) * 10, acc)
  a + b
end
ans = dfs(0, 0, 0)
puts ans


Measured memory_bytes: 1788
n,m,*L=map(int,open(0).read().split())
A=L[:n];B=L[n:]
cnta=cntb=0
inA=[0]*(n*m+1);inB=[0]*(n*m+1)
mod=10**9+7
ans=1
for a in A:inA[a]=1
for b in B:inB[b]=1
for i,(x,y) in enumerate(zip(inA[:0:-1],inB[:0:-1])):
	if x and y:
		cnta+=1
		cntb+=1
	elif x:
		ans*=cntb
		cnta+=1
	elif y:
		ans*=cnta
		cntb+=1
	else:
		ans*=(cnta*cntb-i)
	ans%=mod
print(ans)

Measured memory_bytes: 34420
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	long long a[n], ans = 1, INF = 1e18;
	for(int i = 0; i < n; ++i){
		cin >> a[i];
		if(a[i] == 0){
			cout << 0 << endl;
			return 0;
		}
	}
	for(int i = 0; i < n; ++i){
		if(ans > INF / a[i]){
			cout << "-1\n";
			return 0;
		}
		ans *= a[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 4428
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>

using namespace std;

int main()
{
	long long n, m;
	long long input, num;
	map<long long, long long> val;
	map<long long, long long>::iterator it, ret;
	long long sum = 0;
	long long i, add, cnt = 0;

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

	for (i = 0; i < n; i++)
	{
		scanf("%lld", &input);

		it = val.find(input);

		if (it == val.end())
		{
			val[input] = 1;
		}

		else
		{
			it->second++;
		}
	}

	for (i = 0; i < m; i++)
	{
		scanf("%lld %lld", &num, &input);

		it = val.find(input);

		if (it == val.end())
		{
			val[input] = num;
		}

		else
		{
			it->second += num;
		}
	}

	it = val.end();

	while (it--!=val.begin())
	{
		add = n - cnt < it->second ? n - cnt : it->second;

		sum += add*it->first;

		cnt += add;

		if (cnt == n)
		{
			break;
		}
	}

	printf("%lld\n", sum);

	return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n, ans;
set<int> S; 
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n; 
    rep(i, 0, n) {
        int x; cin >> x;
        S.insert(x);
    }
    if (S.size() % 2 == 0) cout << S.size() - 1 << endl;
    else cout << S.size() << endl;
    return 0;
}


Measured memory_bytes: 4992
/*input
1
2
4
8
9
15
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}




int main()
{
	IOS;
	int a[5];
	REP(i,5) cin>>a[i];
	int tmp;
	cin>>tmp;
	if(a[4]-a[0]<=tmp) cout<<"Yay!\n";
	else cout<<":(\n";



	return 0;
}


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

using namespace std;

void Main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int ans = min(A, B) + min(C, D);
    cout << ans << endl;
}

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


Measured memory_bytes: 3604