akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
#include <sstream>
#include <algorithm>
#define fin(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int dx[4] = { -1,1,0,0 };
int dy[4] = { 0,0,-1,1 };

template <typename T> bool contains(vector<T> list, T value) {
	for (T tmp : list) if (tmp == value) return true;
	return false;
}

char map[1000][1000];
int depth[1000][1000];

int main()
{
	
	fin(i, 1000) fin(j, 1000) map[i][j] = 'x';
		
	int h, w; 
	cin >> h >> w;

	// 探索対象を保持するキュー
	queue<pair<int, int>> queue;
	
	fin(i, 1000) fin(j, 1000) depth[i][j] = -1;

	fin(i, h) {
		string tmp = "";
		cin >> tmp;
		fin(j, w) {
			if (tmp[j] == '#') {
				queue.push(make_pair(i, j));
				depth[i][j] = 0;
			}
			map[i][j] = tmp[j];
		}

	}

	// 探索開始
	while (queue.size() > 0) {
		pair<int, int> point = queue.front();
		queue.pop();
		// 今の深さ
		int dp = depth[point.first][point.second];

		fin(i, 4) {
			int x = point.first + dx[i];
			int y = point.second + dy[i];

			// 探索対象かどうか判定する
			if (x < 0 || x >= h || y < 0 || y >= w)
				continue;
			if (depth[x][y] != -1)
				continue;

			// 深さを保存＋キューに追加
			depth[x][y] = dp + 1;
			queue.push(make_pair(x, y));
		}
	}

	int mx = 0;
	fin(i, h) fin(j, w) mx = max(mx, depth[i][j]);
	cout << mx << endl;

	return 0;
}

Measured memory_bytes: 13328
/*
  Esteban Arango Medina
*/
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <tuple>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
using namespace std;

using ll=long long;
#define int ll

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<string,int> si;
typedef pair<int,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef vector <char> vc;
typedef vector <string> vs;
typedef map <string,vs> msvs;
typedef map <string,int> msi;
typedef map <char,int> mci;
typedef map <int,int> mii;
typedef map <string,string> mss;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define endl '\n' // Normal `cout << endl` flushes the output every time wich hit performance badly
#define INF 1000000000
#define deb(x) cout<<#x<<": "<<x<<endl;
#define printArray(arr) for(auto x: arr) { cout<<x<<", "; }
#define printMatrix(mat) for(auto x: mat) { cout<<" "; printArray(x); cout<<endl; }
#define printMap(mmap) for(auto p: mmap) { cout<< p.first<<": "<<p.second<<endl; }

signed main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); // Fast input
  #ifdef LOCAL_PROJECT
    freopen("in.in", "r", stdin);
    // freopen("out.out", "w", stdout);
  #endif

  int T = 1; //cin>>T;
  while(T--) {
    int n, k; cin>>n>>k;
    vi stones(n);
    rep(i,0, n) { cin>>stones[i]; }
    vi DP(n, 0);
    DP[0] = 0;
    DP[1] = abs(stones[0] - stones[1]);
    rep(i,2,n) {
      int minSteps = INT_MAX;
      int j = 1;
      while(j <= k && i - j >= 0) {
        minSteps = min(minSteps, DP[i-j] + abs(stones[i] - stones[i-j]));
        j++;
      }
      DP[i] = min(DP[i-2] + abs(stones[i] - stones[i-2]), DP[i-1] + abs(stones[i] - stones[i-1]));
      DP[i] = minSteps;
    }
    cout<<DP[n-1];
  }
  return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

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

		int n = sc.nextInt();
		int k = sc.nextInt();

		if (k <= (n + 1) / 2)
			System.out.println("YES");
		else
			System.out.println("NO");
	}

}


Measured memory_bytes: 23764
A,B,C=map(int,input().split())
K=int(input())

for i in range(0,K+1):
    for j in range(0,K+1-i):
        for k in range(0,K+1-i-j):
            #print('{},{},{}'.format(i,j,k))
            if(A*(2**i) < B*(2**j) and B*(2**j) < C*(2**k)):
                if(i==j==k==0):
                    pass
                else:
                    print('Yes')
                    exit()

print('No')


Measured memory_bytes: 81192
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin >> n;
    vector<int> a(n, 0), b(n, 0), c(n - 1, 0);

    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];
    for(int i = 0; i < n - 1; i++) cin >> c[i];

    int ans = b[a[0] - 1];
    for(int i = 1; i < n; i++) {
        ans += b[a[i] - 1] + (a[i] == a[i - 1] + 1 ? c[a[i] - 2] : 0);
    }

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

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

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

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

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



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



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



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

	LL H, W; cin >> H >> W;
	int N; cin >> N;
	VI a(N);
	FOR(i, 0, N) {
		cin >> a[i];
	}
	VVI ans(H, VI(W, 0));
	int idx = 0;
	FOR(i, 0, H) {
		if (i % 2 == 0) {
			FOR(j, 0, W) {
				if (a[idx])ans[i][j] = idx, a[idx]--;
				if (!a[idx])idx++;
			}
		}
		else {
			FORR(j, W - 1, 0 - 1) {
				if (a[idx])ans[i][j] = idx, a[idx]--;
				if (!a[idx])idx++;
			}
		}
	}
	FOR(i, 0, H) {
		FOR(j, 0, W) {
			cout << ans[i][j] + 1 << " \n"[j == W - 1];
		}
	}

	return 0;
}


Measured memory_bytes: 384
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
void solve(){
	char ch ;
	cin>> ch ;
	if(ch>='A' && ch<='Z')cout<<'A';
	else cout<<'a';
}
int main(){
	//mahakal(),fast;
	ll t=1;
	// cin>>t ;
	while(t--)solve();

	return 0;
}

Measured memory_bytes: 3576
#include<stdio.h>
int train[100]={},idx=0,num;
void pop(){
	printf("%d\n",train[idx-1]);
	idx--;
}
void push(){
	train[idx]=num;
	idx++;
}
int main(){
	while(scanf("%d",&num)!=EOF){
		if(num==0)	pop();
		else		push();
	}
	return 0;
}
 

Measured memory_bytes: 1788
n,k,s = map(int,input().split())
L = []
if s == 10**9:
  for i in range(k):
    L.append(10**9)
  for i in range(n-k):
    L.append(1)
else:
  for i in range(k):
    L.append(s)
  for i in range(n-k):
    L.append(10**9)
print(' '.join(map(str,L)))

Measured memory_bytes: 12056
n,x,y = map(int,input().split())
x -= 1
y -= 1
ansl = [0 for i in range(n-1)]

for i in range(n):
    for j in range(i+1, n):
        k = min(j-i, abs(x-i) + abs(y-j) + 1)
        ansl[k-1] += 1

for a in ansl:
    print(a)

Measured memory_bytes: 47196
n, m = list(map(int, input().split(' ')))
arr  = set()
for _ in range(m):
    x = int(input())
    arr.add(x)

MOD = int(1e9) + 7

w = [0 for _ in range(n + 1)]

if 0 not in arr:
    w[0] = 1

for i in range(n + 1):
    if i in arr:
        continue

    if i - 1 >= 0 and i - 1 not in arr:
        w[i] += w[i-1]

    if i - 2 >= 0 and i - 2 not in arr:
        w[i] += w[i-2]
    
    w[i] %= MOD


print(w[n])


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

int main() {
  int a, b, c, t = 0;
  scanf("%d %d %d", &a, &b, &c);
  set<int> r;
  while(r.find(t) == r.end()) {
    r.insert(t);
    t = (t + a) % b;
  }
  if(r.find(c) != r.end())
    printf("YES\n");
  else
    printf("NO\n");
}

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

public class Main {
    BufferedReader rd;

    Main() throws IOException {
        rd = new BufferedReader(new InputStreamReader(System.in));
        compute();
    }

    private void compute() throws IOException {
        int[] a = intarr();
        int n = a[0];
        int m = a[1];
        boolean[] from1ToMid = new boolean[n];
        boolean[] fromMidToN = new boolean[n];
        for(int i=0;i<m;i++) {
            a = intarr();
            if(a[0] == 1) {
                from1ToMid[a[1]-1] = true;
            }
            if(a[1] == n) {
                fromMidToN[a[0]-1] = true;
            }
        }
        boolean pos = false;
        for(int i=0;i<n;i++) {
            if(from1ToMid[i] && fromMidToN[i]) {
                pos = true;
                break;
            }
        }
        out(pos?"POSSIBLE":"IMPOSSIBLE");
    }

    private int[] intarr() throws IOException {
        return intarr(rd.readLine());
    }

    private int[] intarr(String s) {
        String[] q = split(s);
        int n = q.length;
        int[] a = new int[n];
        for(int i=0;i<n;i++) {
            a[i] = Integer.parseInt(q[i]);
        }
        return a;
    }

    private String[] split(String s) {
        if(s == null) {
            return new String[0];
        }
        int n = s.length();
        int start = -1;
        int end = 0;
        int sp = 0;
        boolean lastWhitespace = true;
        for(int i=0;i<n;i++) {
            char c = s.charAt(i);
            if(isWhitespace(c)) {
                lastWhitespace = true;
            } else {
                if(lastWhitespace) {
                    sp++;
                }
                if(start == -1) {
                    start = i;
                }
                end = i;
                lastWhitespace = false;
            }
        }
        if(start == -1) {
            return new String[0];
        }
        String[] res = new String[sp];
        int last = start;
        int x = 0;
        lastWhitespace = true;
        for(int i=start;i<=end;i++) {
            char c = s.charAt(i);
            boolean w = isWhitespace(c);
            if(w && !lastWhitespace) {
                res[x++] = s.substring(last,i);
            } else if(!w && lastWhitespace) {
                last = i;
            }
            lastWhitespace = w;
        }
        res[x] = s.substring(last,end+1);
        return res;
    }

    private boolean isWhitespace(char c) {
        return c==' ' || c=='\t';
    }

    private static void out(Object x) {
        System.out.println(x);
    }

    public static void main(String[] args) throws IOException {
        new Main();
    }
}


Measured memory_bytes: 48472
// g++ -std=gnu++14 -I ~/Documents/AtCoder -o test ~/Documents/AtCoder/test.cpp && ./test && rm test
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(v)    (v).begin(), (v).end()
#define in        ([]{int n; cin>>n; return n;}())
using namespace std;
using lint = int64_t;


int main() { cin.tie(0); ios::sync_with_stdio(false);
    int N=in, K=in;

    if( K==1 ) cout << 0 << endl;
    else cout << (N-K) << endl;
}


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


int main(){
  int N, M;
  cin >> N >> M;
  vector<int> X(M);
  for(auto& x : X){
    cin >> x;
  }
  sort(X.begin(), X.end());
  
  vector<int> D(M-1);
  for(int ii=0; ii<M-1; ii++){
    D[ii] = X[ii+1] - X[ii];
  }
  sort(D.begin(), D.end());
  
  int ans = 0;
  for(int ii=0; ii<M-N; ii++){
    ans += D[ii];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define w(t) int t;cin>>t;while(t--)
#define pb   push_back
#define mk   make_pair
#define u_s  unordered_set
#define endl "\n"
#define prDouble(x) cout<<fixed<<setprecision(10)<<x
#define ll long long int
#define ipair pair<int,int>
#define all(x) (x).begin(), (x).end()

const int mod=pow(10,9)+7;

bool compare(pair<int,int>p1,pair<int,int>p2){
    return p1.second<p2.first;
}
void open_file(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
}
void fast_io(){
    ios_base::sync_with_stdio(false); 
    cin.tie(nullptr); 
    cout.tie(nullptr);
      
}
/*
  ll C(ll n,ll k){
  
  if(k>n)return 0;
  
  ll ans=1;

  if(k>n-k)
    k=n-k;
  for(ll i=1;i<=k;i++)
    ans*=(n-i+1),ans/=i;

  return ans;
  }
  unsigned long long fact(long long a)
  {
  unsigned long long res=1;
  for(long long i=a;i>0;i--)
    res*=i;
  return res;
  }
  unsigned long long comb(long long a,long long b)
  {
  if((a-b)<b) b=a-b;
  if(a<=19) return fact(a)/(fact(a-b)*fact(b));
  if(a==b||b==0) return 1;
  if(b==1) return a;
  return comb(a-1,b-1)+comb(a-1,b);
  }
*/

ll dp[3005][3005];

ll game(vector<int>&A,int i,int j,int player){

   if(i>j)return 0;

   if(dp[i][j]!=-1)return dp[i][j];

   if(player==1){

      return dp[i][j]=max(A[i]+game(A,i+1,j,2),A[j]+game(A,i,j-1,2));
   }else
     return dp[i][j]=min(game(A,i+1,j,1),game(A,i,j-1,1));
}

void solve(){
   
   memset(dp,-1,sizeof dp);

   int n; cin>>n;
   ll sum=0;
   vector<int>A(n); for(int i=0;i<n;i++)cin>>A[i],sum+=A[i];

   ll X=game(A,0,n-1,1);
   ll Y=sum-X;

   cout<<X-Y;
}

int main(){

  //open_file();
  fast_io();
  
  solve();
  
  return 0;  
    
}


Measured memory_bytes: 74432
#include <iostream>
#include <fstream>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#define inf 3
#define MAX 200001
using namespace std;

//ifstream in("input.txt");
//ofstream out("output.txt");

int T;
int N, M, W;
int D[MAX];
vector <int> E[MAX];
priority_queue <int> q;

int main() {
	int u, v;
	int k = 1;
	cin >> N >> M;
	for (int i = 1; i <= N; ++i) D[i] = -1;
	for (int i = 0; i < M; ++i) {
		cin >> u >> v;
		E[u].push_back(v);
	}
	for (int i = 0; i < E[1].size(); ++i) {
		q.push(E[1][i]);
	}

	while (!q.empty()) {
		int node = q.top();
		q.pop();

		for (int i = 0; i < E[node].size(); ++i) {
			D[E[node][i]] = 1;
		}
	}

	if (D[N] == 1) cout << "POSSIBLE";
	else cout << "IMPOSSIBLE";
}

Measured memory_bytes: 9976
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n;
    cin >> n;
    int a[1<<n];
    rep(i,1<<n){
        scanf("%d", &a[i]);
    }
    sort(a,a+(1<<n),greater<int>());

    int b[1<<n];
    b[0] = a[0];
    int flag[1<<n] = {};
    flag[0] = 1;

    rep(i,n){
        int j = 0;
        int k = 0;
        while(j<(1<<i)){
            if(k==(1<<n))break;
            if(flag[k] == 0 && a[k] < b[j]){
                b[(1<<i) + j] = a[k];
                j++;
                flag[k] = 1;
            }
            k++;
        }
        if(j<(1<<i)){
            cout << "No" << endl;
            return 0;
        }
        sort(b,b+(1<<(i+1)),greater<int>());
    }



    cout << "Yes" << endl;
    return 0;
}
 
 


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

int main(){
    int n, ans = 0; string c; cin >> n >> c;
    priority_queue<int> r; vector<int> w;
    for (auto i = 0; i < n; i++) {
        if(c[i] == 'R') r.push(i);
        else w.push_back(i);
    }
    if(r.empty() or w.empty()) { cout << 0 << endl; return 0; }
    for (auto i = 0; i < (int)w.size(); i++) {
        if(r.top() > w[i]) {
            auto tmp = r.top(); r.pop();
            c[w[i]] = 'R'; c[tmp] = 'W';
            r.push(w[i]); w[i] = tmp; ans++;
        }
//        cout << c << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4780
use proconio::{input, fastout};

macro_rules! echo {
  ($val:expr) => {
    println!("{}", $val);
  }
}

#[fastout]
fn main() {
  input!{
    n: usize,
    mut aa: [i64; n]
  };
  aa.sort_unstable();
  
  let max = aa[n-1];
  let mut ans_a = aa[0];
  for a in &aa[0..n-1] {
    if (max - ans_a*2).abs() > (max - *a*2).abs() {
      ans_a = *a;
    }
  }
  println!("{} {}", max, ans_a);
}


Measured memory_bytes: 3668
n, q = map(int, input().split())
s = input()
flag = False
count = 0
li = []

for i in range(n):
    if s[i] == "A":
        flag = True
    elif s[i] == "C" and flag is True:
        count += 1
        flag = False
    else:
        flag = False
    li.append(count)

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


Measured memory_bytes: 6128
import sys
mod = pow(10, 9) + 7

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

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

NNN = (10**5)
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, NNN + 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 L in range(1, K+1):
    print(H(K - L, L)*H((N-K) - (L-1), L+1)%mod)


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

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

int main() {
  int n;
  cin >> n;
  int count = 0;
  for (int i = 2; i <= 55555; i++) {
    if (is_prime(i) && i % 5 == 1) {
      cout << i;
      count++;
      if (count == n) {
        cout << endl;
        break;
      }
      cout << " ";
    }
  }
  return 0;
}


Measured memory_bytes: 256
o=input()
e=input()
if len(o)==len(e):
    for i in range(len(e)):
        print(o[i],end='')
        print(e[i],end='')
else:
    for i in range(len(e)):
        print(o[i],end='')
        print(e[i],end='')
    print (o[len(e)],end='')
print()

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

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

	std::vector<int> input(n);
	for (int i = 0; i < n; i++)
	{
		std::cin >> input[i];
	}

	int numSwap = 0;
	int temp = 0;
	int bubble = 0;
	bool isContinue = true;
	while(isContinue)
	{
		isContinue = false;
		for (int j = n - 1; j > 0; j--)
		{
			if (input[j - 1] > input[j])
			{
				temp = input[j];
				input[j] = input[j - 1];
				input[j - 1] = temp;
				numSwap++;
				isContinue = true;
			}
		}
	}

	for (int i = 0; i < n; i++)
	{
		std::cout << input[i];
		if (i != n - 1)
		{
			std::cout << " ";
		}
	}
	std::cout << "\n" << numSwap << std::endl;
}

Measured memory_bytes: 3036
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define ANS(ans) cout<<(ans)<<endl;
typedef vector<int> VI;


//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)




int main() {

	string s;
	cin >> s;
	long long ans = 0;

	unsigned int maxPlus = 1 << 9;


	int n = s.length();
	VI v(n - 1);

	REP(k, 1 << n - 1) {

		for (int i = n - 2; i >= 0; i--) {
			v[n - 2 - i] = (k >> i) & 1;
		}

		string sushiki;
		sushiki= s[0];
		string plus;
		REP(i, n - 1) {
			if (v[i] == 1) {
				sushiki.push_back('+');
			}
			else {
				sushiki.push_back('#');
			}
			sushiki.push_back (s[i + 1]);
		}
		
		string str;
		//str += sushiki[0];
		REP(i, 2 * n - 1) {
			if (sushiki[i] == '#'){

			}
			else if (sushiki[i] == '+') {
				ans += stoll(str);
				str.clear();
			}
			else {
				str += sushiki[i];
			}
		}
		ans += stoll(str);
		
		
	}

	cout << ans << endl;




	return 0;
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys

N,K = map(int,input().split())

N += 1
MOD = 10**9+7
#%%
ans = 0
for i in range(K,N+1):
    p = (2*N-i-1)*i//2
    m = (i-1)*i//2
    ans += p-m+1
    ans %= MOD

print(ans)    

Measured memory_bytes: 9192
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        int pageNum = 0;

        Scanner scanner = new Scanner(System.in);
        String inputPageNum = scanner.nextLine();
        scanner.close();
        pageNum = Integer.parseInt(inputPageNum);

        int printOutPage = 0;
        if (pageNum % 2 == 0) {
            printOutPage = pageNum / 2;
        } else {
            printOutPage = pageNum / 2 + 1;
        }
        System.out.println(printOutPage);

    }
}

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

int done(int a){
  if(a==1){
  cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
  return 0;
}


int main(){
  int n; cin>>n;
  if(n==1) return done(1);
  
  vector<int> h(n);
  for(int i=0; i<n; i++){
    cin>>h[i];
  }
  
  for(int i=n-1;i>=1;i--){
    if(h[i]+1<h[i-1]){return done(0);}
    else if(h[i]+1==h[i-1]){
      h[i-1]--;
    }
  }
  
  done(1);
  
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <list>
#include <functional>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)


int main() {
	int N;
	map<int, int> a;

	scanf("%d", &N);
	rep(i, N) {
		int t;
		scanf("%d", &t);
		++a[t];
	}

	long long int ans = 0;
	for (auto aa : a) {
		if (aa.first < aa.second) ans += aa.second - aa.first;
		else if (aa.first > aa.second) ans += aa.second;
	}

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

	return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> food(m+1, 0);
    rep(i,n){
       int k; cin >> k;
       rep(j,k){
           int a; cin >> a;
           food[a]++;
       } 
    }
    int ans = 0;
    for(int i=1; i<=m; i++){
        if (food[i] == n) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

#define int long long
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

void shift()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
}
const int N = 2e5;


signed main()
{
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1; i <= n; ++i)
    {
        int k = i;
        int res = 0;
        while(k > 0)
        {
            ++res;
            k /= 10;
        }
        if (res & 1)
            ++ans;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
/*
 *    FileName:
 *      Source:
 *        Date:
 *      Author: Mew
 *	  Function:
 */
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iomanip>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<set>
#include<map>
#include<iterator>
#include<ctime>
using namespace std;
struct pnt{
	long long x,t;
};
pnt a[200005];
bool operator<(pnt a, pnt b){
	return a.x < b.x;
}
int main()
{
	long long w,h;
	cin>>w>>h;
	for(int i=1;i<=w;i++){
		cin>>a[i].x;
		a[i].t=0;
	}
	for(int i=w+1;i<=w+h;i++){
		cin>>a[i].x;
		a[i].t=1;
	}
	long long cnt[2];
	cnt[0] = w+1;
	cnt[1] = h+1;
	long long ans = 0;
	long long sumr = w * (h+1) + (w+1) * h;
	sort(a+1,a+w+h+1);
	for(int i=1;i<=w+h;i++){
		int t = a[i].t, nt = 1-t;
		ans += a[i].x *cnt[nt];
		cnt[t]--;
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define gcd __gcd
#define pcount __builtin_popcount
#define pcountll __builtin_popcountll
#define nxtperm next_permutation
//primitive roots: 998244353 - 3; 7340033 - 5
//#pragma 03
//#pragma GCC target ("sse4.2")

const ll mod = 1000000007;		const double PI = acos(-1.);
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef complex<double> cd;

struct custom_hash
{
    static uint64_t splitmix64(uint64_t x)
	{
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const
	{
        static const uint64_t kawaii = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + kawaii);
    }
};

int n; 
const int maxn = 1e5 + 100; 
int a[maxn][3], dp[maxn][3]; 

signed main()
{
//	freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);
// 	fast_cin();
	cin >> n; 
	for(int i=1;i<=n;i++) for(int j=0;j<3;j++) cin >> a[i][j]; 
	for(int i=1;i<=n;i++) 
	{
		for(int j=0;j<3;j++) 
		{
			for(int k=0;k<3;k++) 
			{
				if(k == j) continue; 
				dp[i][j] = max(dp[i][j], dp[i-1][k] + a[i][j]); 
			}
		}
	}
	int ans =0; 
	for(int i=0;i<3;i++) ans = max(ans, dp[n][i]); 
	cout << ans; 
}

/*
	Test input:
*/



Measured memory_bytes: 2560
def read_int():
    return int(input())

def read_int_map():
    return map(int,input().split(' '))

def read_int_list():
    return list(map(int,input().split(' ')))

def read_s_list_loop(n):
    return [input() for _ in range(n)]

N,K = read_int_map()
An = read_int_list()
memo = [0]*(N+1)
memo_indx = [0]*(N+1)
memo[1] = 1
memo_indx[1] = 0
seq_an = [1]
next_place = An[0]
for i in range(len(An)):
    if memo[next_place] == 0:
        seq_an.append(next_place)
        memo[next_place] = 1
        memo_indx[next_place] = i + 1
        next_place = An[next_place-1]
    else:
        break
loop_idx = memo_indx[next_place]
loop_list = seq_an[loop_idx:]
if K <= len(seq_an)-1:
    print(seq_an[K])
else:
    num = (K - len(seq_an)) % len(loop_list)
    print(loop_list[num])

Measured memory_bytes: 106980
require 'pp'

N = readline.to_i
hi = readline.split.map(&:to_i)

hmax = hi.max

def count_flip(arg)
  a = [false] + arg
  cnt = 0
  (1..a.size).each do |i|
    cnt += 1 if !(a[i-1]) and a[i]
  end
  cnt
end

sum = 0
(1..hmax).each do |h|
  a = hi.map {|x| x >= h }
  # pp a
  sum += count_flip(a)
end

puts sum


Measured memory_bytes: 2172
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	string a, b;
	cin >> a >> b;
	if (a.size() == b.size()) {
		if (a > b) {
			cout << "GREATER" << endl;
		}
		else if (a < b) {
			cout << "LESS" << endl;
		}
		else if (a == b) {
			cout << "EQUAL" << endl;
		}
	}
	else {
		cout << (a.size() > b.size() ? "GREATER" : "LESS") << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define rrep1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int A, B, M;
ll a[100010], b[100010], x[100010], y[100010], c[100010];

int main() {
    cin >> A >> B >> M;
    rep(i, A) cin >> a[i];
    rep(i, B) cin >> b[i];
    rep(i, M) cin >> x[i] >> y[i] >> c[i];
    rep(i, M) { x[i]--; y[i]--; }

    ll minA = LLINF, minB = LLINF;
    rep(i, A) chmin(minA, a[i]);
    rep(i, B) chmin(minB, b[i]);

    ll ans = minA + minB;
    rep(i, M) {
        ll cur = a[x[i]] + b[y[i]] - c[i];
        chmin(ans, cur);
    }
    cout << ans << endl;
}


Measured memory_bytes: 4224
H, W = map(int, input().split())
S = ['.' + input() + '.' for i in range(H)]
S.insert(0, '.' * (W + 2))
S.insert(len(S), '.' * (W + 2))
def mine(x):
    if x == '#':
        count.append(1)
for i in range(1, H+1):
    tmp = ''
    for j in range(1, W+1):
        if S[i][j] == '#':
            tmp += '#'
        else:
            count = []
            mine(S[i-1][j-1]); mine(S[i-1][j]); mine(S[i-1][j+1])
            mine(S[i][j-1]);                    mine(S[i][j+1])
            mine(S[i+1][j-1]); mine(S[i+1][j]); mine(S[i+1][j+1])
            tmp += str(sum(count))
    print(tmp)

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int n; cin >> n;
  vector<string> s(n);
  rep(i,n) cin >> s[i];

  map<string,int> mp;

  rep(i,n){
    mp[s[i]]++;      
  }
  vector<pair<int,string>> p(n);
  for(int i = 0;i<n;i++){
    string sec = s[i];
    int value = mp[s[i]];
    p[i] = make_pair(value,s[i]);
  }
  sort(p.begin(),p.end());
  reverse(p.begin(),p.end());
  
  int max = p[0].first;
  vector<string> ans(max);
  rep(i,n){
    int key = p[i].first;
    string st = p[i].second;
    if(max == key){
      ans.push_back(st);
    }
  }
  sort(ans.begin(),ans.end());
  ans.erase(unique(ans.begin(),ans.end()),ans.end());

  rep(i,ans.size()) cout << ans[i] << endl;
  
  return 0;
}


Measured memory_bytes: 41272
using System;

class Program
{
  static void Main(string[] args)
  {
    string s = Console.ReadLine();
    string[] s2 = s.Split(' ');

    int n = int.Parse(s2[0]);
    int k = int.Parse(s2[1]);

    if (k == 1)
      Console.WriteLine(n);
    else
      Console.WriteLine(n - k + 1);
  }
}

Measured memory_bytes: 11220
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)

function main()
	n = readline() |> parseInt
	a = readline() |> split |> parseMap
	b = readline() |> split |> parseMap
	if sum(b)>sum(a)
		println(-1)
	else
		c = Int[a[i]-b[i] for i in 1:n]
		c = sort(c,rev=true)
		k = 0
		x = 0
		for i in 1:n
			if c[i]<0
				k+=1
				x-=c[i]
			end
		end
		for i in 1:n
			if x<=0
				println(i-1+k)
				break
			else
				x-=c[i]
			end
		end
	end
end

main()

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

def solve(n):

    tmp = 0
    ans = 0
    if n > 0:
        b = bin(n)[2:]
        for i,c in enumerate(b):
            if (len(b)-i)%2 == 0:
                if int(c) == 1:
                    tmp += 11*10**(len(b)-i-1)
            else:
                tmp += int(c)*10**(len(b)-i-1)
    elif n < 0:
        b = bin(abs(n))[2:]
        for i,c in enumerate(b):
            if(len(b)-i)%2 == 1:
                if int(c) == 1:
                    tmp += 11*10**(len(b)-i-1)
            else:
                tmp += int(c)*10**(len(b)-i-1)

    tmp = str(tmp)
    while '2' in tmp:
        ans = 0
        for i,c in enumerate(tmp):
            o = len(tmp)-i-1
            if int(c) >= 2:
                if (ans//(10**(len(tmp)-i)))%10 > 0:
                    ans += (int(c)-2-10)*10**o
                else:
                    ans += (110+int(c)-2)*10**o
            else:
                ans += int(c)*10**(len(tmp)-i-1)
        
        tmp = str(ans)
    
    return tmp


print(solve(n))

Measured memory_bytes: 3064
//abc172_a.cpp
//Sat Jun 27 20:54:49 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	int ans = a+a*a+a*a*a;
	cout << ans << endl;
//	printf("%.4f\n",ans);
}

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

int main() {

  int N;
  cin >> N;

  vector<long long> a(N);
  long long sum = 0;

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

  long long answer = 1LL<<60;
  long long current = 0;

  for (int i = 0; i < N - 1; i++) {
    current += a[i];
    long long c_ = sum - current;
    answer = min(abs(current - c_), answer);
  }

  cout << answer << endl;

  return 0;

}

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

const int64_t MOD = 1000000007;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;


// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
      v[k][j] %= MOD;
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;


signed main() {
  ll a, b, c ,d;
  cin >> a >> b >> c >> d;
  
  // a --- b
  
  // ( a + (c-(a%c))%c )/c .... b/c
  // b/c - ( a + (c-(a%c))%c )/c + 1
  
  ll cCount = b/c - ( a + (c-(a%c))%c )/c + 1;
  ll dCount = b/d - ( a + (d-(a%d))%d )/d + 1;
  ll cd = lcm(c,d);
  ll cdCount = b/(cd) - ( a + (cd-(a%(cd)))%(cd) )/(cd) + 1;

  //cout << cCount << endl;
  //cout << dCount << endl;
  //cout << cdCount << endl;
  
  cout <<  b - a + 1 -  (cCount + dCount - cdCount) << endl;  
  return 0;
}



Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 2147483647
#include <math.h> /* M_PI */
//最短で行かないといけない。残っている白を通って。
int main()
{
    int h, w;
    cin >> h >> w;
    vector<vector<char>> data(h, vector<char>(w));
    ll count = 0;
    rep(i, h) rep(j, w)
    {
        char a;
        cin >> a;
        if (a == '#')
        {
            count += 1;
        }
        data[i][j] = a;
    }
    priority_queue<ll> py; //最短距離を返すもの。
    int i = 0;
    int j = 0;
    //スタートを全通り試して。
    queue<ll> que;
    vector<vector<int>> dist(h, vector<int>(w, -1)); //訪れたかどうかを判断
    //スタート地点を全部試して行く・
    que.push(i);
    que.push(j); //最初の場所を追加する。
    if (data[0][0] == '#' || data[h - 1][w - 1] == '#')
    {
        cout << -1 << endl;
    }
    else
    {
        dist[i][j] = 0; //初期条件
        while (que.empty() != 1)
        {
            int a = que.front();
            que.pop();
            int b = que.front();
            //この最初を考えて行く。
            if (a + 1 < h && dist[a + 1][b] == -1 && data[a + 1][b] != '#')
            {
                que.push(a + 1);
                que.push(b);
                dist[a + 1][b] = 1 + dist[a][b];
            }
            if (a - 1 > -1 && dist[a - 1][b] == -1 && data[a - 1][b] != '#')
            {
                que.push(a - 1);
                que.push(b);
                dist[a - 1][b] = 1 + dist[a][b];
            }
            if (b + 1 < w && dist[a][b + 1] == -1 && data[a][b + 1] != '#')
            {
                que.push(a);
                que.push(b + 1);
                dist[a][b + 1] = 1 + dist[a][b];
            }
            if (b - 1 > -1 && dist[a][b - 1] == -1 && data[a][b - 1] != '#')
            {
                que.push(a);
                que.push(b - 1);
                dist[a][b - 1] = 1 + dist[a][b];
            }
            que.pop();
        }
        //distance(20*20の配列の中からもっとも大きいものを手に入れたい。)

        ll dis = dist[h - 1][w - 1];

        if (dis == -1)
        {
            cout << dis;
        }
        else
        {
            cout << h * w - dis - count - 1 << endl;
        }
    }
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	input := scanner.Text()
	inputList := strings.Split(input, " ")
	a, _ := strconv.Atoi(inputList[0])
	b, _ := strconv.Atoi(inputList[1])

	if 1 <= a && a <= 9 && 1 <= b && b <= 9 {
		fmt.Println(a * b)
	} else {
		fmt.Println(-1)
	}
}


Measured memory_bytes: 640
import time
s__ = time.time()
limit = 1.9
#limit = 10

from numba import njit
import numpy as np

d = int(input())
cs = list(map(int, input().split()))
cs = np.array(cs, dtype=np.int64)
sm = [list(map(int, input().split())) for _ in range(d)]
sm = np.array(sm, dtype=np.int64)

@njit('i8(i8[:], i8)', cache=True)
def total_satisfaction(ts, d):
    ls = np.zeros(26, dtype=np.int64)
    s = 0
    for i in range(d):
        t = ts[i]
        t -= 1
        s += sm[i][t]
        ls[t] = i + 1

        dv = cs * ((i+1) - ls)
        s -= dv.sum()
    return s

@njit('i8[:]()', cache=True)
def greedy():
    ts = np.array([0] * d, dtype=np.int64)
    for i in range(d):
        mx = -1e10
        mxt = None
        for t in range(1, 26+1):
            ts[i] = t
            s = total_satisfaction(ts, i + 1)
            if s > mx:
                mx = s
                mxt = t
        ts[i] = mxt
    return ts

@njit('i8(i8, i8[:])', cache=True)
def loop(mxsc, ts):
    it = 50
    rdd = np.random.randint(1, d, (it,))
    rdq = np.random.randint(1, 26, (it,))
    for i in range(it):
        di = rdd[i]
        qi = rdq[i]

        bk = ts[di]
        ts[di] = qi
        sc = total_satisfaction(ts, d)

        if sc > mxsc:
            #print(mxsc, '->', sc)
            mxsc = sc
        else:
            # 最大値を更新しなかったら戻す
            ts[di] = bk
    return mxsc

ts = greedy()
mxsc = total_satisfaction(ts, d)
mxbk = mxsc

s_ = time.time()
mxsc = loop(mxsc, ts)
e_ = time.time()

consume = s_ - s__
elapsed = e_ - s_
#print('consume:', consume)
#print('elapsed:', elapsed)

if consume < limit:
    lp = int((limit - consume)/ elapsed)
    #print('loop', lp)
    for _ in range(lp):
        mxsc = loop(mxsc, ts)

for t in ts:    print(t)
#print(mxbk, mxsc)
#print(time.time() - s__)


Measured memory_bytes: 121540
#include <vector>
#include <iostream>
#include <stdio.h>

using namespace std;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<int> sizes;
    // vector<pair<int, int> > blockedEdges;

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        sizes = par;
        for(int i = 0; i < N; i++) {
            par[i] = i;
            sizes[i] = 1;
        }
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        sizes[ry] += sizes[rx];
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x) {
        // 同じrootであるものを数える
        int root_x = root(x);
        return sizes[root_x];
        // if(sizes[root_x] != 1) return sizes[root_x];

        // int counter = 0;
        // for(int i = 0; i < par.size(); i++) {
        //     if(same(root_x, i)) counter++;
        // }
        // sizes[root_x] = counter;

        // return counter;
    }
};



void solve(int N, int M, int K, std::vector<int> A, std::vector<int> B, std::vector<int> C, std::vector<int> D){
    // aとbが同じTreeに含まれるか
    // Union Find Treeを作成する
    // 全ての人が別々のグループとして初期化
    UnionFind friendsTree(N);

    // 友達関係からTreeを併合していく
    for(int i = 0; i < M; i++) {
        friendsTree.unite(A[i]-1, B[i]-1);
    }
    // ブロック関係からTreeを併合していく
    // for(int i = 0; i < K; i++) {
    //     friendsTree.unite(C[i], D[i]);
    // }

    // 含まれるときは
    // Tree.Size - (aに直接繋がっている、Nodeの数) - 1（自分のNode）
    // 間にブロック関係があると、友達候補にならない
    // それぞれの連結のsizeを求める

    // それぞれの直接繋がっている
    vector<int> answers(N);
    for(int i = 0; i < N; i++) {
        answers[i] = friendsTree.size(i);
    }
    // 友達関係に数字があるとき友達候補は減る
    for(int j = 0; j < M; j++) {
        answers[A[j]-1]--;
        answers[B[j]-1]--;
    }

    // 同じTreeかつブロック関係の時は１減らす
    for(int j = 0; j < K; j++) {
        if(friendsTree.same(C[j]-1, D[j]-1)) {
            answers[C[j]-1]--;
            answers[D[j]-1]--;
        }
    }

    for(int i = 0; i < N; i++) {
        if(i != 0) cout << " ";
        cout << answers[i] - 1;
    }
    cout << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    int N;
    scanf("%d",&N);
    int M;
    scanf("%d",&M);
    int K;
    scanf("%d",&K);
    std::vector<int> A(M);
    std::vector<int> B(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%d",&A[i]);
        scanf("%d",&B[i]);
    }
    std::vector<int> C(K);
    std::vector<int> D(K);
    for(int i = 0 ; i < K ; i++){
        scanf("%d",&C[i]);
        scanf("%d",&D[i]);
    }
    solve(N, M, K, std::move(A), std::move(B), std::move(C), std::move(D));
    return 0;
}


Measured memory_bytes: 3968
n = int(input())
robots = [list(map(int, input().split())) for _ in range(n)]

min_max = sorted([[list[0] - list[1], sum(list)] for list in robots], key=lambda val: val[1])
           
remove = 0
max_range = -1e9 - 1
for robot in min_max:
  if max_range <= robot[0]:
    max_range = robot[1]
  else:
    remove += 1
  
print(n - remove)

Measured memory_bytes: 43560
const lines: string[] = [];
const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});
reader.on("line", function (line: string) {
  lines.push(line);
});

reader.on("close", function () {
  const rule = lines.shift().split(" ").map(Number);
  const data: any = lines.map((line) => {
    return line.split(" ").map((int) => parseInt(int));
  });

  const dp = [];
  dp.push(data[0]);
  for (let i = 1; i < rule[0]; i++) {
    dp.push(new Array(3).fill(-1));
  }

  for (let i = 1; i < rule[0]; i++) {
    for (let j = 0; j < 3; j++) {
      for (let k = 0; k < 3; k++) {
        if (j !== k) {
          dp[i][k] = Math.max(dp[i][k], dp[i - 1][j] + data[i][k]);
        }
      }
    }
  }
  console.log(Math.max.apply(null, dp[rule[0] - 1]));
});


Measured memory_bytes: 57336
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <fstream>
#include <list>
#include <climits>

using namespace std;

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

	int n, m, arr[1000] = { 0 }, tmp, tmp2, tmp3, tmp4;

	cin >> n >> m;

	for (int i = 0; i < m; ++i)
	{
		cin >> tmp >> tmp2;

		if (tmp == 1 && tmp2 == 0)
		{
			if (n != 1)
				arr[0] = 1;

			for (int j = 1; j <= 999; ++j)
				arr[j] = 1;
		}
		else
		{
			for (int j = 0; j <= 999; ++j)
			{
				tmp4 = j;
				tmp3 = tmp;

				while (n != tmp3)
				{
					tmp4 /= 10;

					tmp3++;
				}

				if (tmp4 % 10 != tmp2)
					arr[j] = 1;
			}
		}
	}

	tmp = 0;

	if (n == 1 && arr[0] == 0)
	{
		cout << 0 << '\n';
		tmp = 1;
	}
	else
	{
		for (int i = 1; i <= 999; ++i)
		{
			int cnt = 0;
			tmp2 = i;

			while (tmp2)
			{
				tmp2 /= 10;
				cnt++;
			}

			if (cnt == n && !arr[i])
			{
				tmp = 1;
				cout << i << '\n';

				break;
			}
		}
	}

	if (!tmp)
		cout << -1 << '\n';

	return 0;
}

Measured memory_bytes: 384
#include <iostream>

void funcB() {
	long long int H, W, sum;
	std::cin >> H >> W;
	if (H == 1 || W == 1) sum = 1;
	else {
		sum = H * W / 2;
		if ((H*W) % 2 != 0) sum += 1;
	}
	std::cout << sum;
}

int main(void) {
	funcB();
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>

int main() {
	std::size_t n;
	std::cin >> n;

	std::vector<std::size_t> as;
	as.reserve(n);
	for (std::size_t i = 0; i < n; ++i) {
		std::size_t a;
		std::cin >> a;
		as.emplace_back(a);
	}

	std::sort(std::begin(as), std::end(as));

	std::size_t max_combined = 0;
	std::size_t count = 0;
	for (std::size_t a : as) {
		if (a > 2 * max_combined) {
			count = 0;
		}
		++count;
		max_combined += a;
	}
	std::cout << count << std::endl;
}


Measured memory_bytes: 1024