akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<array>
#include<algorithm>
#include<deque>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<list>

int main(void) {
	using namespace std;
	/*int N, A,res;
	cin >> N >> A;
	res = N * N - A;
	cout << res << endl;*/

	/*int a, b,c;
	cin >> a >> b;
	c = a * b;
	c = c % 2;
	if (c == 0) {
		cout << "Even" << endl;
	}
	else if(c == 1){
		cout << "Odd" << endl;
	}*/

	int A, B, a, b, c;
	cin >> A >> B;
	a = A + B;
	b = A - B;
	c = A * B;
	if (a >= b && a >= c) {
		cout << a << endl;
	}
	else if (b >= a && b >= c) {
		cout << b << endl;
	}
	else if (c >= a && c >= b) {
		cout << c << endl;
	}

	/*int K, S,res = 0;
	cin >> K >> S;
	for (int X = 0; X <= K;X++) {
		for (int Y = 0; Y <= K; Y++) {
			for (int Z = 0; Z <= K; Z++) {
				if (X + Y + Z == S) {
					res += 1;
				}

			}
		}
	}
	cout << res << endl;*/

	/*int N,a;
	cin >> N;
	set<int>s;
	for (int i = 0; i < N;i++) {
		cin >> a;
		s.insert(a);
	}
	cout << s.size() << endl;*/

	/*int N, a, res;
	vector<int>vec;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a;
		vec.push_back(a);
	}
	sort(vec.begin(), vec.end());
	res = vec[vec.size() - 1] - vec[0];
	cout << res << endl;*/

	/*int Alice = 0, Bob = 0,a,N;
	deque<int>dec;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a;
		dec.push_back(a);
	}
	sort(dec.rbegin(), dec.rend());
	for (int i = 0; i < N;i++) {
		if (i % 2 == 0) {
			Alice += dec[0];
			dec.pop_front();
		}
		else if (i % 2 == 1) {
			Bob += dec[0];
			dec.pop_front();
		}
	}
	cout << Alice - Bob << endl;*/
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
  int n,k;
  int ans =0;
  cin >> n >> k;
  for (int i=0; i<n; i++) {
    int h;
    cin >> h;
    if (h >= k) ans++;
  }

  cout << ans << endl;
}

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

int main(void){
  int n,A,B,C,xbe,xaf,cnt,flag,y;

  while(1){

    cnt = 0; flag = 0;

    cin >> n >> A >> B >> C >> xbe;

    if( n == 0 && A == 0 && B == 0 && C == 0 && xbe == 0 ) break;

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

      cin >> y;

      if(flag==1)continue;

      while(1){

	if(xbe == y){

	  xaf = ( A * xbe + B ) % C;
	  xbe = xaf;
	  cnt++;
	  break;

	}

	xaf = ( A * xbe + B ) % C;
	xbe = xaf;
	cnt++;

	if( cnt > 10000 ){

	  cout << "-1" << endl;
	  flag = 1;
	  break;

	}
      }
      
    }
    
    if( flag==0 ) cout << cnt-1 << endl;
    
  }
  
  return 0;
  
}

Measured memory_bytes: 1160
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>

#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,n) for(int i=0;i<(n); i++)

using namespace std;
typedef long long ll;
const int MAX_N = 100000;
const int MAX_W = 1000000000;
static const int INF = 1<<29;
string s,t,ans;
int dp[3001][3001];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0); //この2行はより速度を向上させる
    // 追加２, 以降 cin の入力元が 'input.txt' になる
    //提出時に消す！！
    cin >> s >> t;
    for(int i=1;i<=s.size();i++){
        for(int j=1;j<=t.size();j++){
            if(s[i-1]==t[j-1]){
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else{
                dp[i][j]=max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
    //LCSの対応は後ろから遡る
    int i=s.size(),j=t.size();
    int a=dp[i][j];
    while(a!=0){
        if(a>dp[i-1][j]&&a>dp[i][j-1]){
            ans += s[i-1];
            i--;
            j--;
            a=dp[i][j]; //対角線移動
            continue;
        }
        else{
            if(a==dp[i-1][j]){
                i--;
                a=dp[i][j];
                continue;
            }
            else{
                j--;
                a=dp[i][j];
                continue;
            }
        }
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;
    return 0;
}


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

int main(){

    ll n;
    cin >> n;
    vector<ll> a(n);
    ll ans=0;
    rep(i,n){
        cin >> a[i];
    }
    vector<ll> cnt(n+1);
    for(ll i=0;i<n;i++){
        if(a[i]>n){
            ans++;
        }else{
            cnt[a[i]]++;
        }
    }

    for(ll i=0;i<n+1;i++){
        if(cnt[i]==0) ;
        else if(cnt[i]>i){
            ans+=cnt[i]-i;
        }else if(cnt[i]<i){
            ans+=cnt[i];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
n = int(input())
s=[input() for _ in range(n)]
m = int(input())
t=[input() for _ in range(m)]

from collections import defaultdict
d=defaultdict(int)
for plus_word in s:
    d[plus_word]+=1
for minus_word in t:
    d[minus_word]-=1

print(max(max(d.values()), 0))

Measured memory_bytes: 3316
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>

using namespace std;



int main(){
    int n;
    cin >> n;
    string a;
    cin >> a;
    int cnt=1;
    char now = a[0];
    for(int i=1;i<a.length();i++){
        if(a[i] != now){
            now = a[i];
            cnt++;
        }
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
ll a,b,c,k;
int main(){
	scanf("%lld%lld%lld%lld",&a,&b,&c,&k);
	if(k&1) printf("%lld",b-a);
	else printf("%lld",a-b);
	return 0;
} 

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

using namespace std;

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

  int n;
  cin >> n;
  vector<int> w(n);
  for (int i = 0; i < n; i++) {
    cin >> w[i];
  }
  vector<int> s(n + 1);
  s[0] = 0;
  for (int i = 0; i < n; i++) {
    s[i + 1] = w[i] + s[i];
  }
  int ans = 10000;
  for (int i = 0; i < n; i++) {
    int s1 = s[i];
    int s2 = s[n] - s1;
    ans = min(ans, abs(s1 - s2));
  }
  cout << ans << endl;
  return 0;
}


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

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

    vector<long long int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }

    int memo = -1;
    for(int i=0; i+1<n; i++){
        if(a[i] + a[i+1] >= l) memo = i+1;
    }

    if(memo == -1){
        cout << "Impossible" << endl;
        return 0;
    }

    cout << "Possible" << endl;
    for(int i=1; i<memo; i++) cout << i << endl;
    for(int i=n-1; i>memo; i--) cout << i << endl;
    cout << memo << endl;
    return 0;
}

Measured memory_bytes: 4036
import collections

N,K=input().split(" ")
N = int(N)
K = int(K)
A = input().split(" ")
#temp_list = list(set(A))

test = collections.Counter(A)
test_key = list(test.keys())
#print(type(test_key))
temp = []
for i in test_key:
    temp.append(int(test[str(i)]))
tyouka = K - len(temp)
temp = sorted(temp)
#print(temp)
ans = 0 
if tyouka >=0:
    print(0)
else:
    tyouka = -tyouka
    for i in range(tyouka):
        ans += int(temp[i])
    print(ans)

Measured memory_bytes: 35996
# coding: utf-8
# Your code here!
import sys
import math

A, B, H, M = map(int, input().split())

h_ras = (30 * H) + (M/2)
m_ras = 6 * M
h_m_ras = abs(h_ras - m_ras)
if h_m_ras == 0:
    print(abs(A-B))
    sys.exit()
ans = A * A + B * B - ((2* A * B * math.cos(math.radians(h_m_ras))))
print(math.sqrt(ans))


Measured memory_bytes: 9572
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;

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

  int n = s.size();
  vector<int> c(26, -1);
  rep(i, n) {
    int xs = s[i] - 'a', xt = t[i] - 'a';
    if (c[xs] == -1) c[xs] = xt;
    else {
      if (c[xs] != xt) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  vector<int> cr(26, -1);
  rep(i, n) {
    int xs = s[i] - 'a', xt = t[i] - 'a';
    if (cr[xt] == -1) cr[xt] = xs;
    else {
      if (cr[xt] != xs) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  


  
  return 0;
}

Measured memory_bytes: 776
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	int n, a, b;
	cin >> n >> a >> b;
	if ((a + b) % 2 == 0) {
		cout << "Alice" << endl;
	}
	else {
		cout << "Borys" << endl;
	}
	return 0;
}


Measured memory_bytes: 3632
n,k = map(int, input().split())
mod = 10**9+7

dp = [[1] + [0 for i in range(k)] for j in range(n+1)]
for i in range(1,n+1):
    for j in range(1,k+1):
        dp[i][j] = dp[i-1][j] + dp[i-1][j-1]

for i in range(k):
    print(dp[n-k+1][i+1]*dp[k-1][i]%mod)

Measured memory_bytes: 356488
s = input()
t = input()

ls = len(s)
lt = len(t)

ans=0

for i in range(0, ls-lt+1):
    cnt = 0 
  
    for j in range(lt):
        if s[i+j] == t[j]:
            cnt+=1 
    ans = max(ans, cnt)
    
print(lt-ans)
   

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

const int mod = 998244353;

long long pow_mod(int a, int b) {
  long long r = 1;
  if ( b == 0 ) { return 1; }
  for ( int i = 0; i < b; i++ ) {
    r *= a;
    r %= mod;
  }
  return r;
}

int main() {
  int n;
  cin >> n;
  int d[n];
  int dp[n];
  for ( int i = 0; i < n; i++ ) {
    cin >> d[i];
    dp[i] = 0;
  }
  for ( int i = 0; i < n; i++ ) {
    dp[d[i]]++;
  }
  long long ans = 1;
  if ( dp[0] != 1 || d[0] != 0 ) {
    cout << 0 << endl; return 0;
  }
  for ( int i = 1; i < n-1; i++ ) {
    long long t = pow_mod(dp[i], dp[i+1]);
    ans *= t;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}
template<typename T> inline int Log2(T& x) {int k; for(k=0; (T(1)<<k)<=x; ++k); return k;} // number of binary digits


int main() {
  ll K, N; cin >> K >> N;
  Vll A(N);
  rep(i, N) cin >> A[i];

  Vll dif(N);
  rep(i, N-1) dif[i] = A[i+1] - A[i];
  dif[N-1] = A[0] - A[N-1] + K;

  sort(all(dif));
  ll ans = 0;
  rep(i, N-1) ans += dif[i];

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


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

int main(void)
{
  int W,H,x,y,r;
  cin >> W >> H >> x >> y >> r;
  if (0+r <= x && x <= W-r && 0+r <= y && y <= H-r)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

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

ans = []
for i in range(2**n):
  pat = [0] * n
  r = [0] * m
  money = 0
  for j in range(n):
    if ((i>>j)&1):
      pat[n-1-j] = 1
  for x in range(len(pat)):
    if pat[x] == 1:
      money += a[x][0]
      for y in range(m):
        r[y] += a[x][y+1]
  flag = True
  for z in range(m):
    if r[z] < X: 
      flag = False
      break
  if flag: 
    ans.append(money)
print(min(ans) if ans else -1)     

Measured memory_bytes: 9252
#include<bits/stdc++.h>
using namespace std;
int W,n;
long long arr[101][2];
long long dp[1000001][101];
long long max_val(int cap_left,int i)
{
    if(i == n)
        return 0;
    if(cap_left == 0)
        return 0;

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

    dp[cap_left][i] = max((cap_left-arr[i][0] >= 0 ) ? (max_val(cap_left-arr[i][0],i+1)+arr[i][1] ): 0, max_val(cap_left,i+1));
    return dp[cap_left][i];

}
int main()
{
    cin>>n>>W;
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<n;i++)
        cin>>arr[i][0]>>arr[i][1];
    cout<<max_val(W,0);
    return 0;
}


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

int main(){
  string S; cin >> S;
  map<char,int>mp;
  for(int i=0;i<S.size();i++){
    mp[S.at(i)]++;
  }
  for(auto itr = mp.begin();itr != mp.end();itr++){
    if(itr->second != 2){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for (int i = a; i <= (b); i++)
#define ROF(i, a, b) for (int i = a; i >= (b); i--)

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<ll>; using vvll = vector<vll>;

int main() {
    string s; cin >> s;
    int ans = 0;
    for (char i : s) if (i == '1') ans++;
    cout << ans << endl;
}

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

using namespace std;


int main(){
  int S;
  
  cin >> S;
  
  int a = S%10;
  S = S/10;
  
  for(int i=0; i<3; i++){
    if(a==(S%10)){
      cout << "Bad" << endl;
      return 0;
    }
    
    a = S%10;
    S = S/10;
    
  }
  
  cout << "Good" << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define EACH(begin, end) for(auto itr = (begin); itr != (end); itr++)

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;



ll N = 0;
ll ret = 0;
ll a, b, c;

void input() {
  IN(a);
  IN(b);
  IN(c);
}

void solve() {
  ll ret = max((int)(c-a+b), 0);
  PRINT(ret);
}

int main(void){
  input();
  solve();
}


Measured memory_bytes: 256
from __future__ import division, print_function, unicode_literals
from future_builtins import *

N = int(raw_input())
A = list(map(int, raw_input().split()))

print(" ".join(map(str, A)))
for i in xrange(1,N):
    j, p = i-1, A[i]
    while j >= 0 and A[j] > p:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = p
    print(" ".join(map(str, A)))

Measured memory_bytes: 6488
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

H, N = LI()
ab = []
for i in range(N):
    ab.append(LI())

dp = [[mod for i in range(H + 2)] for i in range(N + 2)]
for i in range(N):
    dp[i][0] = 0

for n in range(N):
    A,B = ab[n]
    for h in range(H + 2):
        dp[n + 1][h] = min(dp[n][h], dp[n + 1][max(0, h - A)] + B)
# print(dp)
print(dp[-2][H])


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

card = [A, B, C]
cardnumber = [1, 0, -1]

sum = 0
for i in range(0, 3):
	if card[i] > K:
		sum += K*cardnumber[i]
		break
	else:
		sum += card[i]*cardnumber[i]
		K -= card[i]

print(sum)

Measured memory_bytes: 79884
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let ab: Vec<_> = (0..n).map(|_| {
        let a: u64 = sc.cin();
        let b: u64 = sc.cin();
        (a, b)
    }).collect();
    let mut ans = 0;
    let mut base = 0;
    for i in (0..n).rev() {
        let (a, b) = ab[i];
        let c = if (a + base) % b == 0 {
            0
        } else {
            b - (a + base) % b
        };
        ans += c;
        base += c;
        // trace!(c);
    }
    put!(ans);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


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

using namespace std;
const int maxn = 2e5 + 4;
int cnt[maxn];

void _accepcted_by_one_hit_()
{
    #ifdef NTMA
        freopen("abc.inp", "r", stdin);
        freopen("abc.out", "w", stdout);
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
}
int main()
{	
	_accepcted_by_one_hit_();
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n+1, 0), b(m+1, 0);
    for(int i=1; i<=n; ++i) cin >> a[i];
    for(int i=1; i<=m; ++i) cin >> b[i];
    int ans = 1e9 + 7;
    while (k--){
        int u, v, c; cin >> u >> v >> c;
        ans = min(ans, a[u] + b[v] - c);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    ans = min(ans, a[1] + b[1]);
    cout << ans;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define maxn 1000005

ll power(ll x, ll y, ll p) 
{ 
    ll res = 1; // Initialize result 
  
    // Update x if it is more than or 
    // equal to p 
    x = x % p;  
  
    while (y > 0) { 
        // If y is odd, multiply x with the result 
        if (y & 1) 
            res = (res * x) % p; 
  
        // y must be even now 
        y = y >> 1; // y = y/2 
        x = (x * x) % p; 
    } 
    return res-y; 
} 


ll fastpower (ll b , ll p){
    ll k= p%2 ? b : 1 ;
    return p==0 ? 1 : k*(fastpower(b*b,p/2));
}

//int v1[105],v2[105];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t=1;
	//cin>>t;
	while(t--){
		int n;
		cin>>n;
		int a=7%n;
		for(int i=0;i<=20000000;i++){
			if(a==0){
				cout<<i+1<<"\n";
				return 0;
			}
			else a=((a*10)+7)%n;
		}
		cout<<-1<<"\n";
	}
}

Measured memory_bytes: 3608
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;//keyを格納
  struct node *next;//次のキューの位置を格納（先頭の場合はnil）
  struct node *prev;//前のキューの位置を格納（末尾の場合はnil）
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  /* your code */
  int i=0;
  NodePointer x,y=NULL;
  for(x=nil->prev;;x=x->next){
  	if(x->key==key) y=x;
  	if(x->next==nil) break;
  }
  //printf("%d\n",y->key);
  return y;
}

void init(){//キューの先頭と末尾の位置を格納
  nil = malloc(sizeof(struct node));
  nil->next = nil;//first
  nil->prev = nil;//last
  nil->key = -1;
}

void printList(int n){//キューに格納されているkeyを出力
  NodePointer cur = nil->prev;
  int i = 1,p;
  int box[n];
  int next[n],prev[n];
  for(i=0;;i++){
    box[i]=cur->key;
    next[i]=cur->next->key;
    prev[i]=cur->prev->key;
    if ( nil == cur->next ) break;
    cur = cur->next;
  }
  p=i;
  for(;i>-1;i--){
  	printf("%d",box[i]);
  	if(i!=0) printf(" ");
  }
  printf("\n");
}

void deleteNode(NodePointer t){//削除するキューの位置によって処理を分岐
  if(t->next==nil){//先頭の場合
    t->prev->next=nil;
    nil->next=t->prev;
    if(t->prev==nil) nil->prev=nil;
  }else if(t->prev==nil){//末尾の場合
  	nil->prev=t->next;
  	t->next->prev=nil;
  }else{//それ以外
  	t->prev->next=t->next;
    t->next->prev=t->prev;
  }
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
   NodePointer t=nil->prev;
   if ( t == nil ) return;
   deleteNode(t);}

void delete(int key){
  NodePointer t;
  t=listSearch(key);
  if(t!=NULL) deleteNode(t);
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  if(nil->prev==nil){
  	nil->prev=x;
  	x->prev=nil;
  }else{
  	x->prev=nil->next;
  	x->prev->next=x;
  }
  x->next=nil;
  nil->next=x;
}

int main(){
  int key, n, i;
  int size = 0;//scanfした命令数
  char com[20];
  scanf("%d", &n);
  init();  
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ) {scanf("%d",&key);insert(key);}//insert
    else if ( com[0] == 'd' ) {//deretegroup
      if (strlen(com) > 6){//deletefirst or delete last
		if ( com[6] == 'F' ) {;deleteFirst();}
		else if ( com[6] == 'L' ) {deleteLast();}
      	}else {
      		scanf("%d",&key);
			delete(key);// delete x
      	}
    }
  }

  printList(n);
  return 0;
}


Measured memory_bytes: 38460
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

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;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
#define int long long

signed main() {
    int n;
    cin >> n;
    priority_queue<int> q;
    q.push(0);
    q.push(0);
    int a;
    vector<bool> check(1e9 + 1);
    rep(i, n) {
        cin >> a;
        if (check[a]) {
            q.push(a);
            check[a] = false;
        }
        else
            check[a] = true;
    }
    int res = q.top();
    q.pop();
    cout << res * q.top() << endl;
    return 0;
}

Measured memory_bytes: 125836
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>

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

   std::vector<long long> a (N);


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

   std::cout << sum - N << std::endl;
}

   

   


Measured memory_bytes: 256
// https://abc042.contest.atcoder.jp/tasks/arc058_b
#include <iostream>
#include <vector>
     
using namespace std;
     
typedef long long ll;
typedef vector<ll> vll;
     
const ll MOD = 1000000007;
     
ll pow(ll a, ll b) {
	ll x = 1, y = a;
	while(b > 0) {
		if(b % 2) x = (x * y) % MOD;
		y = (y * y) % MOD;
		b /= 2;
	}
	return x;
}
         
ll inv(ll n) {
	return pow(n, MOD - 2);
}
     
ll f(ll n) {
	ll k = 1;
	for (ll i = 1; i <= n; i++) k = (k * i) % MOD;
	return k;
}
     
int main() {
	ll h, w, a, b;
	cin >> h >> w >> a >> b;
	ll s = 0;
	ll p1, p2;
	vll p3(w - b);
	vll p4(w - b);
	p3[w - b - 1] = f((a - 1));
	p4[w - b - 1] = p3[w - b - 1];
	for (int i = w - 2; i >= b; i--) {
		p3[i - b] = (p3[i - b + 1] * (a - 1 + w - i - 1)) % MOD;
		p4[i - b] = (p4[i - b + 1] * (w - i - 1)) % MOD;
	}
	for (int i = b; i < w; i++) {
		if (i == b) {
			p1 = f((h - a - 1) + i);
			p2 = (f(h - a - 1) * f(i)) % MOD;
		} else {
			p1 = (p1 * (h - a - 1 + i)) % MOD;
			p2 = (p2 * i) % MOD;
		}
		ll s1 = (p1 * inv(p2)) % MOD;
		ll s2 = (p3[i - b] * inv(p4[i - b])) % MOD;
		s1 = (s1 * s2) % MOD;
		if (s1 < 0) s1 += MOD;
		s = (s + s1) % MOD;
	}
	cout << s << endl;
}


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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> s(H);
    for (int i = 0; i < H; i++) {
        cin >> s[i];
    }

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

    auto isOK = [&](int x, int y) {
        return (0 <= x && x < W && 0 <= y && y < H && s[y][x] == '.');
    };
    
    vector<vector<int>> distance(H, vector<int>(W, INT_MAX));
    vector<vector<pair<int, int>>> pre(H, vector<pair<int, int>>(W, { -1, -1 }));

    priority_queue<pair<int, pair<int, int>>> pq;
    pq.push({ 0, {0, 0,} });
    distance[0][0] = 0;
    while (!pq.empty()) {
        auto curr = pq.top();
        pq.pop();
        int d = curr.first;
        int x = curr.second.first;
        int y = curr.second.second;
        if (distance[y][x] < d) {
            continue;
        }

        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (isOK(nx, ny) && distance[ny][nx] > (d + 1)) {
                distance[ny][nx] = d + 1;
                pre[ny][nx] = { x, y };
                pq.push({ d + 1, {nx, ny} });
            }
        }
    }

    if (distance[H - 1][W - 1] == INT_MAX) {
        cout << -1 << endl;
        return 0;
    }

    for (pair<int, int> p = { W - 1, H - 1 }; p.first != -1; p = pre[p.second][p.first]) {
        s[p.second][p.first] = '+';
    }

    int ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (s[i][j] == '.') {
                ans++;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i,n) for(int (i) = 0; (i) < (int)(n); (i)++)
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int n;
    cin >> n;
    cout << n*n*n << endl;
}

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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    REP(i, n) cin >> p[i];
    sort(p.begin(), p.end());

    int sum = 0;
    REP(i, k) sum += p[i];

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

Measured memory_bytes: 3680
N, M = map(int, input().split())

time = (N-M)*100 + M*1900

ans = 0
k = 1
while True:
    value = k*time*((1-(0.5**M))**(k-1))*(0.5**M)
    if value == 0:
        break
    ans += value
    k += 1

print(round(ans))


Measured memory_bytes: 3060
#!/usr/bin/env python3
import sys


def solve(N: int):
    ans = []
    for i in range(1, N+1):
        if i % 3 == 0 or i % 5 == 0:
            continue
        ans.append(i)
    print(sum(ans))
    return


# 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)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 30000
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
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;}

////////// 二分探索 //////////

vector<ll> A;

// index が条件を満たすかどうか
bool isOK(ll index,ll key) {
  if(A[index]>=key) return true;
  else return false;
}

// 汎用的な二分探索のテンプレ
ll binary_search(ll key) {
  ll ng=-1; //「index = 0」が条件を満たすこともあるので、初期値は -1
  ll ok=(ll)A.size(); // 「index=a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
  while(abs(ok-ng)>1){
    ll mid=(ok+ng)/2;
    if(isOK(mid,key)) ok=mid;
    else ng=mid;
  }
  return ok;
}

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

int main(){
  ll N,M;
  cin>>N>>M;
  REP(i,N){
    ll a;
    cin>>a;
    A.PB(-a);
  }
  SORT(A);
  
  ll SUM[N+1];
  SUM[0]=0;
  REP(i,N) SUM[i+1]=SUM[i]-A[i];
  
  ll ye=INF,no=0; // Ax+Ayとして取れる値
  while(ye-no>1){
    ll mid=(ye+no)/2,cnt=0;
    REP(i,N){
      ll it=binary_search(-mid-A[i]+1);
      cnt+=it;
    }
    if(cnt<=M) ye=mid;
    else no=mid;
  }
  
  ll X=ye-1,ans=0,count=0;
  REP(i,N){
    ll it=binary_search(-X-A[i]+1);
    count+=it;
    ans+=SUM[it]-it*A[i];
  }
  ans-=(count-M)*X;
  co(ans);
  return 0;
}

Measured memory_bytes: 4836
import math

n = list(map(int,input().split()))

kaku = n[2] * 30 + n[3] * 0.5 - 6 *n[3]

if kaku >= 180:
    kaku = 360 - kaku

x = n[0]**2 + n[1]**2 - 2*n[0]*n[1] * math.cos(math.radians(kaku))
hen = math.sqrt(x)
#print(kaku)
print(hen)

Measured memory_bytes: 62496
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
using data=pair<ll,ll>;

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll euclidean_gcd(ll a, ll b) {
  if(a<b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

void printmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  For(i,0,H+2){
    For(j,0,W+2){cout<<a[i*(W+2)+j];}
    cout<<endl;
  }
}
void inputmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  string ss;
  For(i,1,H+1){
    cin>>ss;
    For(j,1,W+1){
      if(ss[j-1]=='#'){
        a[i*(W+2)+j]=1;
      }else{
        a[i*(W+2)+j]=0;
      }
    }
  }
}

void dijkstra(vector<vector<data>>& tree,vector<ll>& d,ll start){
  ll i,K=tree[start].size(),N=d.size(),cnt=1;
  data x;
  d[start]=0;
  priority_queue<data,vector<data>,greater<data>> que;
  rep(i,K){
    que.push(data(tree[start][i].second,tree[start][i].first));
  }
  while(cnt<N){
    x=que.top();que.pop();
    if(d[x.second]>0)continue;
    d[x.second]=x.first;
    cnt++;
    K=tree[x.second].size();
    rep(i,K){
      if(d[tree[x.second][i].first]<0){
        que.push(data(d[x.second]+tree[x.second][i].second,tree[x.second][i].first));
      }
    }
  }
}


int main(){
  ll i,N,K,ans=0,term,p;
  cin>>N>>K;
  if(K==0){cout<<N*N<<endl;return 0;}
  For(i,K+1,N+1){
    term=N/i;
    ans+=term*(i-K);
    p=N%i;
    if(p>=K)ans+=p-K+1;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define WHOLE(v) v.begin(), v.end()
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<int> d(N);
    for(int i = 0; i < N; i++) {
        cin >> d[i];
    }
    sort(WHOLE(d));
    if(N % 2 != 0) {
        cout << 0 << endl;
    } else {
        cout << d[(N - 1) / 2 + 1] - d[(N - 1) / 2] << endl;
    }
    return 0;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.Map.Entry;
import java.util.TreeMap;

public class Main {

	/* several useful subroutines */
	private static BufferedReader brStdin = new BufferedReader(new InputStreamReader(System.in));
	private static String[] readBuf = null;
	private static int readPtr = 0;
	private static String getString() throws IOException {
		while ( readBuf == null || readPtr >= readBuf.length ) {
			readBuf = brStdin.readLine().split(" ");
			readPtr = 0;
		}
		return readBuf[readPtr++];
	}
	private static int getInt() throws IOException {
		return Integer.parseInt(getString());
	}
	private static long getLong() throws IOException {
		return Long.parseLong(getString());
	}
	private static BigDecimal getBD() throws IOException {
		return new BigDecimal(getString());
	}
	@SuppressWarnings("unused")
	private static String[] getStringArray(int size) throws IOException {
		String stringArray[] = new String[size];
		for (int i = 0; i < stringArray.length; i++) {
			stringArray[i] = getString();
		}
		return stringArray;
	}
	@SuppressWarnings("unused")
	private static int[] getIntArray(int size) throws IOException {
		int intArray[] = new int[size];
		for (int i = 0; i < intArray.length; i++) {
			intArray[i] = getInt();
		}
		return intArray;
	}
	@SuppressWarnings("unused")
	private static long[] getLongArray(int size) throws IOException {
		long longArray[] = new long[size];
		for (int i = 0; i < longArray.length; i++) {
			longArray[i] = getLong();
		}
		return longArray;
	}
	@SuppressWarnings("unused")
	private static BigDecimal[] getBDArray(int size) throws IOException {
		BigDecimal bdArray[] = new BigDecimal[size];
		for (int i = 0; i < bdArray.length; i++) {
			bdArray[i] = getBD();
		}
		return bdArray;
	}

	
	/* main routine */
	public static void main(String args[]) throws IOException {
		int n = getInt();
		int m = getInt();
		TreeMap<Long, Long> tm = new TreeMap<Long, Long>();
		for ( int i= 0 ; i < n ; i++ ) {
			long a = getLong();
			long v = 1;
			if ( tm.containsKey(a) ) {
				v = tm.get(a)+1;
			}
			tm.put(a,v);
		}
		for ( int i = 0 ; i < m ; i++ ) {
			Entry<Long, Long> e = tm.pollLastEntry();
			long k = e.getKey() ;
			long v = e.getValue() ;
			if ( v > 1 ) {
				tm.put(k, --v);
			}
			k /= 2;
			v = 1;
			if ( tm.containsKey(k) ) {
				v = tm.get(k)+1;
			}
			tm.put(k,v);
		}
		long sum = 0L;
		for ( long k : tm.keySet() ) {
			sum += k * tm.get(k);
		}
		System.out.println( sum );
	}
}


Measured memory_bytes: 56144
#include<iostream>   
#include<cstdio>  
#include<algorithm>
#include<queue>
#include<map>
#include<string>
using namespace std;
const int row = 4;
const int maxx = 16;
const int LIMIT = 100;
struct Puzzle {
	int f[maxx], space, MD;
};

const int dx[4] = { 0, -1, 0, 1 };
const int dy[4] = { 1, 0, -1 ,0 };
const char dir[4] = { 'r','u','l','d' };
int MDT[maxx][maxx];

Puzzle state;
int limit;
int path[LIMIT];

int getAllMD(Puzzle pz) {
	int sum = 0;
	for (int i = 0; i < maxx; i++) {
		if (pz.f[i] != maxx)
			sum += MDT[i][pz.f[i] - 1];
	}
	return sum;
}

bool isSolved() {
	for (int i = 0; i < maxx; i++)
		if (state.f[i] != i + 1)
			return false;
	return true;
}

bool dfs(int depth, int prev) {

	if (state.MD == 0)
		return true;

	// 如果当前的深度加上启发值超过了限制，则进行剪枝
	if (depth + state.MD > limit)
		return false;

	int sx = state.space / row;
	int sy = state.space % row;

	Puzzle tmp;
	for (int r = 0; r < 4; r++) {
		int tx = sx + dx[r];
		int ty = sy + dy[r];
		if (tx < 0 || ty < 0 || tx >= row || ty >= row)
			continue;
		if (max(prev, r) - min(prev, r) == 2)
			continue;
		tmp = state;
		// 计算曼哈顿距离的差值，同时交换拼图
		state.MD -= MDT[tx * row + ty][state.f[tx * row + ty] - 1];
		state.MD += MDT[sx * row + sy][state.f[tx * row + ty] - 1];
		swap(state.f[tx * row + ty], state.f[sx * row + sy]);
		state.space = tx * row + ty;
		if (dfs(depth + 1, r)) {
			path[depth] = r;
			return true;
		}
		state = tmp;
	}
	return false;
}

string iterative_deepening(Puzzle in) {
	// 初始状态的曼哈顿距离
	in.MD = getAllMD(in);
	for (limit = in.MD; limit <= LIMIT; limit++) {
		state = in;
		if (dfs(0, -100)) {
			string ans = "";
			for (int i = 0; i < limit; i++)
				ans += dir[path[i]];
			return ans;
		}
	}
	return "unsolvable";
}

int main()
{
	for (int i = 0; i < maxx; i++) {
		for (int j = 0; j < maxx; j++) {
			MDT[i][j] = abs(i / row - j / row) + abs(i % row - j % row);
		}
	}
	Puzzle in;
	for (int i = 0; i < maxx; i++) {
		cin >> in.f[i];
		if (in.f[i] == 0) {
			in.f[i] = maxx;
			in.space = i;
		}
	}
	string ans = iterative_deepening(in);
	printf("%d\n", ans.size());
	return 0;
}


Measured memory_bytes: 3336
#include<stdio.h>
int main()
{
 int i,j,N,a=0;
 scanf("%d",&N);
 for(i=1;i<=9;i++)
 {
	 for(j=1;j<=9;j++)
	 {
		 if(i*j==N)
			 a++;
	 }
 }
  
 if(a>0)
	 printf("Yes\n");
 else
	 printf("No\n");

	return 0;}


Measured memory_bytes: 128
#include <iostream>
#include <stack>
#include <queue>
#include <string>
#include <regex>

using namespace std;

queue<char> convert(string formula){
  queue<char> qu;
  stack<char> st;
  stack<char> m_rp;
  
  bool b_minus = false;
  for(char c : formula){
    switch(c){
      case '(':
        if(b_minus == true) {
          m_rp.push('-');
          b_minus = false;
        }
        m_rp.push('(');
        break;
      case '0': case '1': case '2': case 'P': case 'Q': case 'R':
        qu.push(c);
        if(b_minus == true){
          qu.push('-');
          b_minus = false;
        }
        break;
      case '*': case '+':
        st.push(c);
        break;
      case '-':
           b_minus = true;
        break;
      case ')':
        qu.push(st.top());
        st.pop();
        m_rp.pop();
        if(!m_rp.empty() && m_rp.top() == '-'){
          qu.push(m_rp.top());
          m_rp.pop();
        }
        break;
      }
  }
  return qu;
}

int lAnd(int a, int b){
  if(a == 0 || b == 0) return 0;
  else if(a == 2 && b == 2) return 2;
  else return 1;
}

int lOr(int a, int b){
  if(a == 2 || b == 2) return 2;
  else if(a == 0 && b == 0) return 0;
  else return 1;
}

int lNot(int a){
  if(a == 0) return 2;
  else if(a == 1) return 1;
  else return 0;
}

int cal(queue<char> quc, int p, int q, int r){
  stack<int> stc;
  int a,b;
  while(!quc.empty()){
    char c = quc.front();
    quc.pop();
    switch(c){
      case '0':
      case '1':
      case '2':
        stc.push(c-'0');
        break;
      case 'P':
        stc.push(p);
        break;
      case 'Q':
        stc.push(q);
        break;
      case 'R':
        stc.push(r);
        break;
      case '+':
        b = stc.top(); stc.pop();
        a = stc.top(); stc.pop();
        stc.push(lOr(a,b));
        break;
      case '*':
        b = stc.top(); stc.pop();
        a = stc.top(); stc.pop();
        stc.push(lAnd(a,b));
        break;
      case '-':
        a = stc.top(); stc.pop();
        stc.push(lNot(a));
        break;
    }
  }
  return stc.top();
}

int main(void){
  string d = "";
  int ans;
  while(true){
    cin >> d;
    if(d == ".") break;
    d = regex_replace(d, std::regex("(--)"), "");
    
    queue<char> t = convert(d);
    ans = 0;
    for(int i=0;i<=2;i++){
      for(int j=0;j<=2;j++){
        for(int k=0;k<=2;k++){
          if(cal(t,i,j,k) == 2) ans++;
        }
      }
    }
    cout << ans << endl;

    // while(!t.empty()){
    //   cout << t.front();
    //   t.pop();
    // }
    // cout << endl;
  }
}


Measured memory_bytes: 3308
// problem: "https://atcoder.jp/contests/abc129/tasks/abc129_a"

import java.util.Scanner;

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

        int p,q,r;

        p = in.nextInt();
        q = in.nextInt();
        r = in.nextInt();

        int ans = 0;
        if(p<=q && p<=r)
        {
            if(q<=r)
                ans = p+q;

            else
                ans = p+r;
        }
        else if(q<=p && q<=r)
        {
            if(p<=r)
                ans = q+p;
            else
                ans = q+r;
        }
        else
        {
            if(q<=p)
                ans = r+q;
            else
                ans = r+p;
        }

        System.out.print(ans);
    }
}


Measured memory_bytes: 22996
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
if sum(a)+sum(b)<k:
    ans=m+n
else:
    numa=[0]
    numb=[0]
    for i in range(n):
        numa.append(numa[-1]+a[i])
    for j in range(m):
        numb.append(numb[-1]+b[j])
    ans=0
    for i in range(n+1):
        if numa[i]>k:
            break
        while numb[m]>k-numa[i]:
            m-=1
        ans=max(ans,i+m)
print(ans)


Measured memory_bytes: 47496
import heapq
n,m=map(int,input().split())
lis=[[] for i in range(m)]
for i in range(n):
  a,b=map(int,input().split())
  if a-1<m:
    lis[a-1].append(-b)
l=list()
v=0
for i in range(m):
  for j in lis[i]:
    heapq.heappush(l,j)
  if l:
    v+=heapq.heappop(l)*(-1)
print(v)

Measured memory_bytes: 17604
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;
 
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; }
 
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; }
 
const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
 
inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}
 
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
 
int h,w;
vector<string> g(25);
 
int bfs(int y, int x){
  int cost[25][25];
  rep(i,h) rep(j,w) cost[i][j]=INF;
  cost[y][x]=0;
  queue<pii> q;
  q.push(pii(y,x));
  int res=0;
  while(!q.empty()){
    pii now=q.front();
    q.pop();
    rep(i,4){
      int ny=now.first+dy[i];
      int nx=now.second+dx[i];
      if(inside(ny,nx,h,w) && g[ny][nx]=='.' && cost[ny][nx]>=cost[now.first][now.second] && cost[ny][nx] > cost[now.first][now.second]+1){
        q.push(pii(ny,nx));
        cost[ny][nx]=cost[now.first][now.second]+1;
        chmax(res,cost[ny][nx]);
      }
    }
  }
  return res;
}
 
signed main()
{
  cin>>h>>w;
  rep(i,h) cin>>g[i];
  
  int ans=0;
  rep(i,h){
    rep(j,w){
      if(g[i][j]=='#')continue;
      chmax(ans,bfs(i,j));
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256