akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stdlib.h>
#include <map>
#include <cmath>
#define MOD_P 1000000007
#define MOD_Q 998244353
#define PI 3.14159265358979
#define ll long long
using namespace std;



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

	printf("%s%s", t.c_str(), s.c_str());

	return 0;
}



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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

ll solve(ll n) {
    if (n < 10) {
        return n;
    }
    if (n % 10 == 9) {
        return 9 + solve(n / 10);
    } else {
        return 9 + solve((n / 10) - 1);
    }
}

int main() {
source:
    ll n;
    cin >> n;
    ll ans = solve(n);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3552
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

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

const ll M = 1e9+7;
const ll INF = 1e9+7;

ll n;
ll a[220000], b[220000];

int main() {
  cin >> n;

  for (ll i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  
  sort(a, a+n);
  sort(b, b+n);
  
  if (n % 2) {
    cout << b[n/2] - a[n/2] + 1 << endl;
  } else {
    cout << b[n/2-1] + b[n/2] - a[n/2-1] - a[n/2] + 1 << endl;
  }  
  
  return 0;
}

Measured memory_bytes: 6772
#include<iostream>
#include <bits/stdc++.h>
#include <cstdio>
#include<set>
using namespace std;
typedef long long int64;

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;


int N, M, L, Q;
map<int, int> m[512];

/////////////////////////////////////////
#define MAX_V 512
#define INF (1e9*500) // * 100000000LL)

struct edge{int to, cost;};
typedef pair<int, int> P;

int V;
vector<edge> G[MAX_V];
ll d[MAX_V][MAX_V], d2[MAX_V][MAX_V];


void warshal_floyd(ll d[MAX_V][MAX_V]){
    for (int k = 0; k < V; k++)
        for (int i = 0; i < V; i++)
            for (int j = 0; j < V; j++)
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    return;
}


int main() {
    
    cin >> N >> M >> L;
    V = N;
    vector<ll> A(M), B(M), C(M);
    for (int i = 0; i < M; i++){
        cin >> A[i] >> B[i] >> C[i];
    }
    cin >> Q;
    vector<int> S(Q), T(Q);
    for (int i = 0; i < Q; i++){
        cin >> S[i] >> T[i];
        S[i]--; T[i]--;
    }
    for (int i = 0; i < N; i++){
        for (int i2 = 0; i2 < N; i2++){
            d[i][i2] = INF;
            d2[i][i2] = INF;
        }
    }
    for (int i = 0; i < M; i++){
        d[A[i] - 1][B[i] - 1] = C[i];
        d[B[i] - 1][A[i] - 1] = C[i];
    }
    // �S�_�ԍŏ�����(Warshall-Floyd)
    warshal_floyd(d);
    
    for (int i = 0; i < N; i++){
        for (int i2 = 0; i2 < N; i2++){
            //fprintf(stderr, "%d, %d, %d\n", i, i2, d[i][i2]);
            if (i == i2){
                d2[i][i2] = 0;
            } else if (d[i][i2] <= L){
                d2[i][i2] = 1;
            } else {
                d2[i][i2] = INF;
            }
        }
    }
    //exit(1);
    warshal_floyd(d2);
    for (int i = 0; i < Q; i++){
        //fprintf(stderr, "%d, %d\n", S[i], T[i]);
        if (d2[S[i]][T[i]] < INF){
            cout << d2[S[i]][T[i]] - 1 << endl;
        } else {
            cout << - 1 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

ll x;

ll lcm(ll a, ll b){
    return a / __gcd(a, b) * b;
}
bool leapyear(int n){
	if(n % 400 == 0 ) {
		return true;
	}
	if(n%4 == 0 && n%100 != 0){
		return true;
	}
	return false;
}


int main(){
    ios_base::sync_with_stdio(0);
    ll n,k;
    cin >> n >> k;
    ll cnt = 0;
    while (n > 0) {
		n /= k;
		cnt++;
	}
	cout << cnt ;
  
}











Measured memory_bytes: 256
H,W,K=map(int,input().split())
S=[input() for i in range(H)]
r=[[0]*W for i in range(H)]
c=0
x=0
B=[]
for i in range(H):
    if '#' not in S[i]:
        B.append(i)
        continue
    f=0
    c+=1
    for j in range(W):
        if S[i][j]=='#':
            if c==1:
                x=i
            if f==0:
                for k in range(j-1):
                    r[i][k]=c
                f=1
            elif f==1:
                c+=1
        r[i][j]=c
for b in B:
    if b<x:
        r[b]=r[x]
    else:
        r[b]=r[b-1]
for l in r:
    print(*l)

Measured memory_bytes: 7568
#include <iostream>
#include <algorithm>

int N;
long long T;
int main(){
  std::cin>>N>>T;
  long long before=0;
  long long t;
  long long ans=0;
  for(int i=0;i<N;++i){
    std::cin>>t;
    ans+=std::min(T,t-before);
    before=t;
  }
  
  std::cout<<ans+T<<std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef string str;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define pb(x) pop_back(x)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define sum(x) accumulate(all(x),0)
#define pc(x) __builtin_popcount(x)
#define gll greater<ll>()

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

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


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

using namespace std;

int main(){
  int N; cin >> N;
  int dp[101][101];
  fill((int*)dp, (int*)dp+101*101, 1234567890);

  vector<int> r(N), c(N);
  for(int i=0;i<N;++i){
	cin >> r[i] >> c[i];
	dp[i][i+1] = 0;
  }
  
  for(int l=2;l<=N;++l){
	for(int i=0;i+l<=N;++i){
	  for(int j=i+1;j<i+l;++j){
		dp[i][i+l] = min(dp[i][j] + dp[j][i+l] + r[i]*c[i+l-1]*r[j], dp[i][i+l]);
	  }
	}
  }
  cout << dp[0][N] << endl;
  
  return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,mx=0,mn=1001;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
    	int k;
    	cin>>k;
    	if(k>mx)mx=k;
    	if(k<mn)mn=k;
	}
	cout<<mx-mn<<endl;
    return 0;
} 

Measured memory_bytes: 256
//test
#include<bits/stdc++.h>
using namespace std;
const int tot=26+26+10;
char enc(int t){
	if(t<10)return '0'+t;
	t-=10;
	if(t<26)return 'a'+t;
	t-=26;
	return 'A'+t;
}
 
string s[tot];
int sum=tot;
int ttm=0;
int query(string s){
	if(s.length()>128)return 0x3f3f3f3f;
	++ttm;
	if(ttm>=850)while(1);
	cout << "?" << " " << s << endl;
	fflush(stdout);
	int ans=0;
	cin >> ans;
	return ans;
}
 
 
int len=0x3f3f3f3f;
int q[tot];
 
string merge(string a,string b){
	int i=0,j=0;
	int la=a.length(),lb=b.length();
	string fir=string();
	while(i<la&&j<lb){
		string qr=fir;
		qr+=a[i];
		for(int k=j;k<lb;k++){
			qr+=b[k];
		}
		if(query(qr)+qr.length()==len){
			fir+=a[i++];
		}else {
			fir+=b[j++];
		}
	}
	while(i<la)fir+=a[i++];
	while(j<lb)fir+=b[j++];
	return fir;
}
 
int main()
{
	for(int i=0;i<tot;i++){
		s[i]+=enc(i);
		q[i]=query(s[i])+1;
		len=min(len,q[i]);
	}
	for(int i=0;i<tot;i++){
		if(q[i]==len){
			while(query(s[i]+enc(i))+s[i].length()+1==len)s[i]+=enc(i);
		}else s[i]=string();
	}
	while(1){
    	for(int i=0;i<tot;i++)for(int j=i+1;j<tot;j++)if(s[i].length()>s[j].length())swap(s[i],s[j]);
		int t=0;
		while(!s[t].length())++t;
		if(t+1==tot)break ;
		string nw=merge(s[t],s[t+1]);
		s[t+1]=nw;
		s[t]=string();
	}
	assert(query(s[tot-1])==0);
	cout << "! "<< s[tot-1] << endl;
	fflush(stdout);
}

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

int main()
{
    ll X,Y;
    cin >> X >> Y;
    
    ll tmp = X;
    ll ans = 0;
    ll key = 0;
    while ( X <= Y )
    {
        X *= 2;
        ans++;
    }
    cout << ans << endl;




}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import deque

h,w = map(int,input().split())
s = []
for i in range(h):
  q = input().rstrip()
  s.append(q)

chk = [[0]*(w-1) for i in range(h-1)]
for i in range(w-1):
  for j in range(h-1):
    chk[j][i] = 1-int((s[j][i]=='#')^(s[j+1][i]=='#')^(s[j][i+1]=='#')^(s[j+1][i+1]=='#'))

def f(a):
  a += [0]
  stack = deque()
  ans = -1
  for i in range(w):
    if stack == deque():
        stack.append((a[i], i))
    elif stack[-1][0] < a[i]:
        stack.append((a[i], i))
    elif stack[-1][0] > a[i]:
      while stack and stack[-1][0] >= a[i]:
        x, y = stack.pop()
        ans = max((x+1)*(i-y+1), ans)
      stack.append((a[i], y))
  return ans
  
dp = [[0]*(w-1) for i in range(h-1)]
for i in range(w-1):
  dp[0][i] = chk[0][i]
  
for i in range(1,h-1):
  for j in range(w-1):
    if chk[i][j]:
      dp[i][j] = dp[i-1][j]+1

ans=max(h,w)
for i in range(h-1):
    ans=max(ans,f(dp[i]))
    
print(ans)

Measured memory_bytes: 178392
open System
open System.Collections.Generic

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f

    let readChars() = read string |> Seq.toArray
    let readInts() =
        readChars()
        |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

[<AutoOpen>]
module Cout =
    let writer = new IO.StreamWriter(new IO.BufferedStream(Console.OpenStandardOutput()))
    let print (s: string) = writer.Write s
    let println (s: string) = writer.WriteLine s
    let inline puts (s: ^a) = s |> string |> println

[<AutoOpen>]
module Util =
    let strRev (s: string): string =
        s
        |> Seq.rev
        |> Seq.map string
        |> String.concat ""

    let inline roundup (x: ^a) (y: ^a): ^a =
        let one = LanguagePrimitives.GenericOne
        (x + y - one) / y

    let inline sameParity (x: ^a) (y: ^a): bool =
        let one = LanguagePrimitives.GenericOne
        (x &&& one) = (y &&& one)

let f n = n * (n+1) / 2

let solve() =
    let s = readChars()

    let len = Array.length s
    let left = Array.zeroCreate (len+1)
    for i in 0..len-1 do
        if s.[i] = '<' then
            left.[i+1] <- left.[i] + 1L
        else
            left.[i+1] <- 0L
    let right = Array.zeroCreate (len+1)
    for i in len-1..-1..0 do
        if s.[i] = '>' then
            right.[i] <- right.[i+1] + 1L
        else
            right.[i] <- 0L

    seq {
        for i in 0..len do
            yield max left.[i] right.[i]
    }
    |> Seq.sum
    |> puts
    ()

[<EntryPoint>]
let main _ =
    solve()
    writer.Close()
    0 // return an integer exit code


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

p, sx, sy = 0, 0, 0
for i in range(n):
    t, x, y = map(int, input().split())
    d, dx, dy = t - p, abs(x - sx), abs(y - sy)
    if (dx + dy) > d or (dx + dy - d) % 2 == 1:
        print("No")
        exit()
    p, sx, sy = t, x, y
else:
    print("Yes")

Measured memory_bytes: 46184
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <math.h>

/*
4
1 0
0 0
2 0
3 0
*/

double calc_dist(double x1, double y1, double x2, double y2)
{
    double dx = x1 - x2;
    double dy = y1 - y2;
    double dist = pow(dx * dx + dy * dy, 0.5);
    return dist;
}

int main()
{
    int N;
    std::cin >> N;
    std::vector<int> x(N);
    std::vector<int> y(N);
    std::vector<int> iter_array(N);
    double N_fact = 1;
    for (int i = 0; i < N; i++)
    {
        std::cin >> x[i] >> y[i];  // 入力
        iter_array[i] = i;         // 順列生成用配列
        N_fact *= i + 1;           // 階乗値
    }

    // solve
    double dist_sum = 0;
    do
    {
        for (int i = 0; i < iter_array.size() - 1; i++)
        {
            int ind = iter_array[i];
            int ind2 = iter_array[i + 1];
            double dist = calc_dist(x[ind], y[ind], x[ind2], y[ind2]);
            dist_sum += dist;
        }
    }
    while(next_permutation(iter_array.begin(), iter_array.end()));

    double ans = dist_sum / N_fact;
    std::cout << std::fixed << std::setprecision(10) << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)
#define rrep(i,a,b) for(int (i)=int(a);(i)>=int(b);(i)--)

#define put(a) cout << (a) << endl
#define puts(a) cout << (a) << " "

#define llint long long int

#define INF (long long)1e9+1
#define MOD (long long)1e9+7
#define INF64 (long long)1e18+1

#define F first
#define S second

#define Pii  pair<int,int>
#define Pll  pair<long long,long long>
#define Piii pair<int,pair<int,int>>
#define Plll pair<long long,pair<long long,long long>>

#define Vll(a,b,c)    vector<vector<long long>> (a)((b),vector<long long>((c))
#define Vlll(a,b,c,d) vector<vector<vector<long long>>> (a)((b),vector<vector<long long>>((c),vector<long long>((d)))

#define MAX_N 1000000

int main (void)
{
	//INPUT
	llint N;
	cin >> N;
	vector<string> s(N);
	rep(i,0,N) {
		cin >> s[i];
	}

	//SOLVE
	vector<vector<char> > c(N,vector<char>(10));
	rep(i,0,N) {
		rep(j,0,10) {
			c[i][j] = s[i][j];
		}
	}
	rep(i,0,N) {
		sort(c[i].begin(),c[i].end());
	}
	sort(c.begin(),c.end());

	vector<char> buf_c(10);
	llint same_ct;

	llint ans=0;

	for(int i=0;i<N;) {
		buf_c = c[i];
		auto itl = upper_bound(c.begin()+i,c.end(),buf_c);
		same_ct = itl - (c.begin()+i);
		ans += same_ct * (same_ct-1) / 2;
		i += same_ct;
	}

	//OUTPUT

	cout << ans << endl;



	return 0;
}


Measured memory_bytes: 12800
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

int main() {
    int n = 0;
    cin >> n;
    vector<ll> a(n);
    for (int i=0; i<n; i++) {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    int cnt = 1;
    int buf = 0;
    bool flag = false;
    for (int i=1; i<n; i++) {
        if (a.at(i) == a.at(i-1)) { 
            cnt++;
        }
        else {
            if (cnt >= 4) {
                if (flag) {
                    cout << buf*a.at(i-1) << endl;
                    return 0;
                }
                else {
                    cout << a.at(i-1)*a.at(i-1) << endl;
                    return 0;
                }
            }
            else if (cnt >= 2) {
                if (flag) {
                    cout << buf*a.at(i-1) << endl;
                    return 0;
                }
                else {
                    buf = a.at(i-1);
                    flag = true;
                }
            }
            cnt = 1;
        }
    }
    if (cnt >= 4) {
        if (flag) {
            cout << buf*a.at(n-1) << endl;
            return 0;
        }
        else {
            cout << a.at(n-1)*a.at(n-1) << endl;
            return 0;
        }
    }
    else if (cnt >= 2) {
        if (flag) {
            cout << buf*a.at(n-1) << endl;
            return 0;
        }
        else {
            buf = a.at(n-1);
            flag = true;
        }
    }
    cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  string s;
  while(cin>>s) {
    string ans;
    REP(i,s.length()) {
      if (s[i]=='@') {
        REP(j,s[i+1]-'0')
          ans += s[i+2];
        i += 2;
      } else {
        ans += s[i];
      }
    }
    cout << ans << endl;
  }
}

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

signed main(void)
{
	vector<int> x(3);
	rep(i, 3) cin >> x.at(i);
	sort(x.begin(), x.end());
	cout << x[0] + x[1] << endl;
	return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        mut k: usize,
    }

    let mut rem = 7;
    for i in 1..=k {
        if rem % k == 0 {
            println!("{}", i);
            return;
        }
        rem = (rem * 10 + 7) % k;
    }
    println!("-1");
}


Measured memory_bytes: 2144
#include <iostream>
#include <string>

bool is_good(const std::string& s) {
    return s[0] != s[1] && s[1] != s[2] && s[2] != s[3];
}

int main() {
    std::string s;
    std::cin >> s;
    std::cout << (is_good(s) ? "Good" : "Bad") << std::endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;

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

int main()
{
  int a, b, c;
  int n;
  cin >> n >> a >> b >> c;
  vector<int> m;
  rep(i,n) {
    int tmp;
    cin >> tmp;
    m.push_back(tmp);
  }
  int result = INF;
  rep(i,pow(4,m.size())) {
    int ma = 0, mb = 0, mc= 0;
    int maCount = 0, mbCount = 0, mcCount = 0;
    rep(j,m.size()) {
      int type = (i >> (j * 2)) & 3;
      if (type == 0) {
        /*pass through*/
      } else if (type == 1) {
        ma += m[j];
        maCount++;
      } else if (type == 2) {
        mb += m[j];
        mbCount++;
      } else {
        mc += m[j];
        mcCount++;
      }
    }
    if (ma == 0 || mb == 0 || mc == 0) continue;
    int totalCost = (--maCount + --mbCount + --mcCount) * 10 + abs(ma-a) + abs(mb-b) + abs(mc-c);
    result = min(result, totalCost);
  }
  cout << result << endl;
}


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

int main() {

    ll x; cin >> x;
    ll ans_a;
    ll ans_b;
    for (ll a = -1000; a <= 1000; a++) {
        for (ll b = -1000; b <= 1000; b++) {
            ll tmpa = a * a * a * a * a;
            ll tmpb = b * b * b * b * b;
            if (tmpa - tmpb == x) {
                ans_a = a;
                ans_b = b;
            }
        }
    }
    cout << ans_a << " " << ans_b << endl;
    return 0;
}

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

using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b;
	c = b;
	for (size_t i = 1;; i++)
	{
		if (a / c >= 1) {
			c *= b;
		}
		else {
			cout << i << endl;
			break;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
#include <ctype.h>
#include <sstream>
using namespace std;
using Graph = vector<vector<int>>;
#define  itn int
using ll=int64_t;
#define rep(i,n) for (int i = 0; i < (int) (n); i++)
using vi = vector<int>;
using vll = vector<ll>;
//GCD
long long gcd(long long a, long long b)
{if(a<b) swap(a,b);
   if (a%b == 0){return(b);}
   else{return(gcd(b, a%b));}
}
//lcm
long long lcm(long long a, long long b)
{return a * b / gcd(a, b);}

long long bikkuri(long long k){
    long long sum = 1;
    for (long long i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}
int main() {
int x,y;
cin>>x>>y;
  vi a(y);
if(y!=0){
for(int i =0; i<y;i++){cin>>a.at(i);}
sort(a.begin(),a.end());

for(int i =0; i<100;i++){
  bool aru1=true;
  bool aru2=true;
  int o=x-i;
  int p=x+i;
  for(int j =0; j<y;j++){
  if(a.at(j)==x-i){
    aru1=false;}
  if(a.at(j)==x+i){
    aru2=false;}
}
if(aru1){cout<<o;break;}
else if (aru2){cout<<p;break;}
  else{continue;}
}
}
else cout<<x;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;
int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  std::vector<int> v;
  cin >> n;
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    int t;
    cin >> t;
    v.push_back(t);
    sum += t;
  }
  int target = (int)(round(sum / (float)n)); //四捨五入

  int ans = 0 ;
  for (int i = 0; i < n; ++i) {
    ans += (v[i] - target) * (v[i] - target) ;
  }


  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 512
N,x=map(int,input().split(" "))
A=list(map(int,input().split(" ")))

A=sorted(A)

ans=0
for i in range(len(A)):
    x=x-A[i]
    if x>=0 and i!=len(A)-1:
        ans+=1
    elif x==0 and i==len(A)-1:
        ans+=1
    else:
        break

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    int n;
    string s;
    cin >> n >> s;
    ll res = 0;
    repp(i,1000,2000){
        string str = to_string(i).substr(1);
        int ind = 0;
        bool b = false;
        rep(j,s.length()){
            if(str[ind] == s[j])ind++;
            if(ind == 3){
                b = true;
                break;
            }
        }
        if(b)res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <complex>
#include <cassert>
#include <random>
#include <cstring>
#include <numeric>
#define ll long long
#define ld long double
#define null NULL
#define all(a) a.begin(), a.end()
#define forn(i, n) for (int i = 0; i < n; ++i)
#define sz(a) (int)a.size()
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
template<class T> int gmax(T &a, T b) { if (b > a) { a = b; return 1; } return 0; }
template<class T> int gmin(T &a, T b) { if (b < a) { a = b; return 1; } return 0; }
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const int MAXN = 1e5 + 5;
vector<int> vc[MAXN];
// int A[MAXN], B[MAXN];

int main() {
    int n, m;
    while(~scanf("%d %d", &n, &m)) {
        for(int i = 0; i < MAXN; ++i) vc[i].clear();
        for(int i = 0; i < n; ++i) {
            int a, b;
            scanf("%d %d", &a, &b);
            vc[a].push_back(b);
            // scanf("%d %d", &A[i], &B[i]);
        }
        multiset<int> st;
        ll sum = 0;
        for(int i = 1; i <= m; ++i) {
            for(auto it : vc[i]) {
                st.insert(it);
            }
            if(st.empty()) continue;
            auto it = --st.end();
            sum += *it;
            st.erase(it);
        }
        printf("%lld\n", sum);
    }
    return 0;
}

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

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

  ll H; cin >> H;
  ll W; cin >> W;
  ll K; cin >> K;
  vector<vector<ll>> cells(H, vector<ll>(W, 0));
  for (ll h = 0; h < H; h++) {
    string s; cin >> s;
    for (ll w = 0; w < W; w++) {
      if (s[w] == '#') cells[h][w] = 1;
    }
  }

  ll MAX_H = (1 << H);
  ll MAX_W = (1 << W);
  ll ans = 0;
  for (ll i = 0; i < MAX_H; i++) {
    for (ll j = 0; j < MAX_W; j++) {
      vector<vector<ll>> temp = cells;
      for (ll h = 0; h < H; h++) {
        for (ll w = 0; w < W; w++) {
          if ((i & (1<<h)) || (j & (1<<w))) {
            temp[h][w] = 0;
          }
        }
      }
      ll cnt = 0;
      for (ll h = 0; h < H; h++) {
        for (ll w = 0; w < W; w++) {
          if (temp[h][w] == 1) {
            cnt++;
          }
        }
      }
      if (cnt == K) ans++;
      // if (cnt == K) {
      //   cout << i << ' ' << j << '\n';
      // }
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3624
function Main(input) {
  input = input.split("\n");
  const changeInt = (n) => {
    return parseInt(n, 10);
  };
  const [N,W] = input[0].split(' ').map(changeInt);
  const wv = [];
  let w_max = 0;
  let v_max = 0;
  for (var i = 0; i < N; i++) {
    wv.push(input[i + 1].split(' ').map(changeInt));
    w_max += wv[i][0];
    v_max += wv[i][1];
  }
 console.log(knapsack(N,W,wv,w_max,v_max));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

function knapsack(N,W,wv,w_max,v_max) {
  let ans = 0;
  const dp = Array(N+1).fill(0).map((n, i) => {
    if (i === 0) {
        return Array(v_max+1).fill(0);
    } else {
        return Array(v_max+1).fill(0).fill(w_max,1);
    }
  });
  for (let i = N; i > 0; i--) {
    for (let v = v_max; v > 0; v--) {
      if (v >= wv[i-1][1]) {
        dp[i-1][v] = Math.min(dp[i][v - wv[i-1][1]] + wv[i-1][0],dp[i][v]);
      } else {
        dp[i-1][v] = dp[i][v];
      }
    }
  }
  for (let i = 0; i < N; i++) {
   for (let v = 0; v <= v_max; v++) {
     if (dp[i][v] <= W) {
       ans = Math.max(v,ans);
     }
   }
 }
 return ans;
}


Measured memory_bytes: 126612
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
import numpy as np
def main():
    n, *a = map(int, read().split())

    p = np.array(a)
    minp = np.minimum.accumulate(p)
    r = 0
    for i1, ae in enumerate(a):
        r += minp[i1] >= ae

    print(r)

if __name__ == '__main__':
    main()


Measured memory_bytes: 50536
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF 1e9+7
#define LLINF 1e18
// #define int ll
using namespace std;
const int MOD = 1e9 +7;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,a[100010],ans=0;
    cin>>n;
    rep(i,n) cin>>a[i];
    sort(a,a+n);
    ll p=*lb(a,a+n,a[n-1]/2);
    if(a[n-1] %2==1){
        if(p ==a[n-1]/2 || p==a[n-1]/2+1) ans=p;
        else{
            ll q=*(lb(a,a+n,a[n-1]/2)-1);
            if(a[n-1]/2-q > p-a[n-1]/2-1 && p!=a[n-1]) ans=p;
            else ans=q;
        }
    }
    else{
        if(p==a[n-1]/2) ans=p;
        else{
            ll q=*(lb(a,a+n,a[n-1]/2)-1);
            if(a[n-1]/2-q > p-a[n-1]/2 && p != a[n-1]) ans=p;
            else ans=q;
        }
    }
    cout<<a[n-1]<<" "<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j,k;
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    vector<vi> v(100,vi(100));
    rep(i,100)rep(j,100)
      if(i==j)v[i][j]=0;
      else v[i][j]=INF;
    rep(i,n){
      int a,b,c;
      cin>>a>>b>>c;
      v[a][b]=c;
      v[b][a]=c;
    }
    rep(k,100)rep(i,100)rep(j,100)
      v[i][j]=min(v[i][j],v[i][k]+v[k][j]);
    int ans=INF;
    int num;
    rep(i,100)
      if(v[i][0]==INF)break;
    n=i;
    rep(i,n){
      int sum=0;
      rep(j,n)
        sum+=v[i][j];
      if(ans>sum){
        ans=sum;
        num=i;
      }
    }
    cout<<num<<" "<<ans<<endl;
  }
}

Measured memory_bytes: 3052
#include<iostream>
#include<math.h>
using namespace std;
int main(){
long long int n,s;
cin>>n>>s;
if(s==n){cout<<n+1<<endl;return 0;}
if(s>n){cout<<"-1"<<endl;return 0;}
if(n<=10000){
    long ans=n+1;

for(long i=2;i<=n;i++){
    long long int p=n;long long e=0;
            while(p!=0){e=e+p%i;p=p/i;}
            if(e==s&&i<ans){ans=i;}
}if(ans==n+1){cout<<"-1"<<endl;return 0;}
cout<<ans<<endl;return 0;
}
long long h=sqrt(n);
long long ans=n+1;
if(s==1){ans=n;}
long long q;

for(long long  i=2;i*i<n;i++){
    long long o=n/i;o++;long long r=i-1;
    long long w=i-1+n%o;
    if(s<=w){
        long long df=w-s;
        long long d=q/r;

        if(df%r==0){
            long long h=o+df/r;
            long long int p=n;long long e=0;
            while(p!=0){e=e+p%h;p=p/h;}
            if(e==s&&h<ans){ans=h;}

        }}
        o--;
        long long int p=n;long long e=0;
            while(p!=0){e=e+p%o;p=p/o;}
            if(e==s&&o<ans){ans=o;}
            q=o;
}

        for(long i=2;i<=q+1;i++){
            long long int p=n;long long e=0;
            while(p!=0){e=e+p%i;p=p/i;}
            if(e==s&&i<ans){ans=i;}
        }
        if(ans==n+1){cout<<"-1"<<endl;}
        else cout<<ans<<endl;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

string s;
ll k;
int main() {
    cin>>s>>k;
    ll idx=0;
    bool flag=false;

    while(k>0){
        if(s[idx]!='1'){
            cout<<s[idx]<<endl;
            flag=true;
            break;
        }
        k--;
        idx++;
    }
    if(!flag) cout<<s[idx-1]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
    int n,k;cin>>n>>k;
    if(k%2==0){
        ll a=n/k;
        ll b=(n+(k/2))/k;
        cout<<a*a*a+b*b*b<<endl;
    }
    else{
        ll a=n/k;
        cout<<a*a*a<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
N=int(input())
l=list(map(int,input().split()))
lcm=l[0]
ans=0
def gcd(a,b):
  while b:
    a,b=b,a%b
  return a

for i in range(1,N):
  lcm=lcm*l[i]//gcd(lcm,l[i])

for i in range(N):
  ans+=(lcm-1)%l[i]
  
print(ans)

Measured memory_bytes: 3316
<?php

function parsenums($str) {
    return array_map(function ($a) {
        return intval($a);
    }, preg_split("/ /", $str));
}

$hm = parsenums(fgets(STDIN));

foreach(range(0, $hm[0] - 1) as $i) {
    $map[$i] = str_split(rtrim(fgets(STDIN)));
}

// ゴールへの最短距離を求める
// 到達不可能の場合-1を返す
function shortest_dist($map, $goalx, $goaly) {
    global $hm;

    $openlist = [];

    array_push($openlist,
               array('v' => $map[0][0], 'x' => 0, 'y' => 0, 'cnt' => 1));
    while(true) {
        $next = array_shift($openlist);

        if($next == NULL) {
            return -1;
        }

        if($next['x'] == $goalx && $next['y'] == $goaly) {
            return $next['cnt'];
        }

        $x = $next['x'];
        $y = $next['y'];
        // はじっこはだめだぞ
        if(($hm[1] - 1) > $x &&
            $map[$y][$x + 1] != '#' &&
            !isset($visited[$y][$x + 1])) {
            array_push($openlist,
                array(
                    'v' => $map[$y][$x + 1],
                    'x' => $x + 1,
                    'y' => $y,
                    'cnt' => $next['cnt'] + 1
                )
            );
            $visited[$y][$x + 1] = true;
        }
        if(($hm[0] - 1) > $y &&
            $map[$y + 1][$x] != '#' &&
            !isset($visited[$y + 1][$x])) {
            array_push($openlist,
                array(
                    'v' => $map[$y + 1][$x],
                    'x' => $x,
                    'y' => $y + 1,
                    'cnt' => $next['cnt'] + 1
                )
            );
            $visited[$y + 1][$x] = true;
        }
        if(0 < $x &&
            $map[$y][$x - 1] != '#' &&
            !isset($visited[$y][$x - 1])) {
            array_push($openlist,
                array(
                    'v' => $map[$y][$x - 1],
                    'x' => $x - 1,
                    'y' => $y,
                    'cnt' => $next['cnt'] + 1
                )
            );
            $visited[$y][$x - 1] = true;
        }
        if(0 < $y &&
            $map[$y - 1][$x] != '#' &&
            !isset($visited[$y - 1][$x])) {
            array_push($openlist,
                array(
                    'v' => $map[$y - 1][$x],
                    'x' => $x,
                    'y' => $y - 1,
                    'cnt' => $next['cnt'] + 1
                )
            );
            $visited[$y - 1][$x] = true;
        }
    }
}

$dist = shortest_dist($map, $hm[1] - 1, $hm[0] - 1);
if($dist == -1) {
    echo "-1\n";
    return;
}

$black = 0;
foreach($map as $line) {
    foreach($line as $cell) {
        if ($cell == '#') {
            $black++;
        }
    }
}

$result = $hm[0] * $hm[1] - $black - $dist;
echo "$result\n";


Measured memory_bytes: 5240
import copy

h, w, k = map(int, input().split())
s = [[0] * w for _ in range(h)]
for i in range(h):
    inp = input()
    for j in range(w):
        s[i][j] = int(inp[j])

# 最終的に出力する操作回数の最小値
ans = h + w - 2

for i in range(2 ** (h-1)):
    # bit全探索によるcutの仕方
    cutIdx = [0] * (h-1)
    for j in range(h-1):
        cutIdx[j] = (i >> j) & 1
    #print('cI : ', cutIdx)

    # cutする場所を示したリスト
    div = []
    cut_row_begin, cut_row_end = 0, 1
    for j in range(h-1):
        if cutIdx[j] == 0:
            # cutしない
            cut_row_end += 1
        else:
            # cutする
            div.append((cut_row_begin, cut_row_end))
            cut_row_begin = cut_row_end
            cut_row_end += 1
    div.append((cut_row_begin, cut_row_end))
    #print('div: ', div)

    # 既にここまででcutされている回数
    cnt = sum(cutIdx)
    #print(cnt)

    # divごとのホワイトチョコの数をカウント
    whiteCnt = [0] * len(div)

    # まずは1列目をチェック
    for a in range(len(div)):
        cal = 0
        for b in range(div[a][0], div[a][1]):
            cal += s[b][0]
        whiteCnt[a] = cal
    #print('wC : ', whiteCnt)

    # もしこの時点でwhiteCntの要素でkを超えるものがあるとき
    # その横の切り方は不可能なのでbreak
    if max(whiteCnt) > k:
        continue

    # Wが1ならそこで終わり
    if w == 1:
        ans = min(ans, cnt)

    # 次行のホワイトチョコ数を保持
    search = [0] * len(div)

    # 2列目以降を同様にチェックしていく
    for a in range(1, w):
        # その次行のホワイトチョコの数
        for b in range(len(div)):
            cal = 0
            for c in range(div[b][0], div[b][1]):
                cal += s[c][a]
            search[b] = cal

        # その行単体でmax値とkを比べる
        # オーバーしていればcut不可
        if max(search) > k:
            break

        # greedy
        for b in range(len(div)):
            if whiteCnt[b] + search[b] > k:
                # cut対象
                cnt += 1
                whiteCnt = copy.copy(search)
                break
            else:
                whiteCnt[b] += search[b]
    #print('cnt: ', cnt)
    ans = min(ans, cnt)

print(ans)

Measured memory_bytes: 48476
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int sum=0;
	int maxn=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
	
		int a;
		cin>>a;
		sum+=a;
		maxn=max(maxn,a); 
	}	 
	sum-=maxn/2;
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<stdlib.h>
using namespace std;
int main() {
    string s;
    string op;
    int tmp;
    int cnt = 0;
    int result;
    while (cin >> s) {
        if (s == "=") {
            cout << result << endl;
            return 0;
        }
        if (s == "+" || s == "-" || s == "*" || s == "/") {
            op = s;
        } else {
            tmp = atoi(s.c_str());
            if (!cnt) {
                result = tmp;
                cnt++;
            } else {
                if (op == "+") {
                    result += tmp;
                } else if (op == "-") {
                    result -= tmp;
                } else if (op == "*") {
                    result *= tmp;
                } else {
                    result /= tmp;
                }
            }
        }
    }
}



Measured memory_bytes: 3180
// package app;

import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);

        final String N = sc.next();
        // final int N = sc.nextInt();
        // final int A = sc.nextInt();
        // final int N = sc.nextInt();
        // final int D = sc.nextInt();
        // System.out.println();

        System.out.println(N.contains("9") ? "Yes" : "No");

        // System.out.println(A <= X && A + B >= X ? "YES" : "NO");

    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <climits>

using namespace std;

int jagde( int *book, int ix, int n, int m )
{
	int sum;
	int j;

	sum = 0;
	j = 0;
	for( int i = 0;i < n;i++ ){
		sum += book[i];
		if( sum > ix ){
			j++;
			i--;
			sum = 0;
		}
	}
	if( j >= m ) return -1;

	ix--;

	sum = 0;
	j = 0;
	for( int i = 0;i < n;i++ ){
		sum += book[i];
		if( book[i] > ix ) return 0;
		if( sum > ix ){
			j++;
			i--;
			sum = 0;
		}
	}
	if( j >= m ) return 0;
	return 1;
}


int answer( int m, int n, int *book )
{
	int low,high;
	int sum[101];

	sum[0] = book[0];
	low = book[0];
	for( int i = 1;i < n;i++ ){
		if( low < book[i] ) low = book[i];
		sum[i] = sum[i - 1] + book[i];
	}

	high = sum[n - 1];

	while( true ){
		int ix = (low + high) / 2;
		int answer = jagde( book, ix, n, m );

		if( answer == -1 ){
			low = ix + 1;
		} else if( answer == 0 ) {
			return ix;
		} else if( answer == 1 ) {
			high = ix - 1;
		}
	}

}

int main(int argc, char const* argv[])
{
	int m,n;
	int book[101];

	while( cin >> m >> n && m != 0 ){
		for( int i = 0;i < n;i++ ) cin >> book[i];

		cout << answer( m, n, book ) << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
int main() {
  string s;
  cin >> s;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '?')
      s[i] = 'D';
  }
  cout << s << endl;
}

Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define qrep(i, q) for(auto i : q)
#define sz(a) (int)a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int maxn = 100005;
const int inf = 0x3f3f3f3f;

int main()
{
	//std::ios::sync_with_stdio(false);
    //std::cin.tie(0);
	int k;
	int a,b;
	cin >> k >> a >> b;
	rep(i,a,b+1){
		if(i%k == 0) return cout << "OK" << endl, 0;
	}
	cout << "NG" << endl;
	return 0;
}


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

int main(){
  int N;
  cin >> N;
  if(N % 10 == 0){
    cout << "10" << endl;
    return 0;
  }

  int min = 100000;
  for(int i = 0; i <= N; i++){
    int num1 = i;
    int num2 = N - i;
    int sum = 0;
    while(num1 != 0 | num2 != 0 ){
      sum += (num1 % 10 + num2 % 10);
      num1 /= 10;
      num2 /= 10;
    }
    if(min > sum){
      min = sum;
    }
  }
  cout << min << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s, t;
	cin >> s >> t;
	bool flag = false;
	int from;
	for(int i = 0; i < s.length() - t.length() + 1; i++){
		bool sub_flag = true;
		for(int j = 0; j < t.length(); j++){
			if(s[i + j] != t[j] && s[i + j] != '?') sub_flag = false;
			else continue;
		}
		if(sub_flag == true){
			flag = true;
			from = i;
		}
	}
	if(flag){
		for(int i = 0; i < t.length(); i++){
			s[from + i] = t[i];
		}
		for(int i = 0; i < s.length(); i++){
			if(s[i] == '?') s[i] = 'a';
		}
		cout << s << endl;
	}
	else cout << "UNRESTORABLE" << endl;
	return 0;
}


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

#define POS(i,j) ((i)*(w+1)+(j))

void run(void){
  const int mod=1000000007;
  int h,w;
  scanf("%d%d",&h,&w);
  char *board=(char *)calloc((h+1)*(w+1),sizeof(char));
  int i,j;
  for(i=0;i<h;i++) scanf("%s",board+POS(i,0));
  int *dp=(int *)calloc((h+1)*(w+1),sizeof(int));
  dp[POS(h-1,w-1)]=1;
  i=h-1;
  for(j=w-2;j>=0;j--){
    if(board[POS(i,j)]=='#') continue;
    dp[POS(i,j)]=dp[POS(i,j+1)];
  }
  for(i=h-2;i>=0;i--){
    for(j=w-1;j>=0;j--){
      if(board[POS(i,j)]=='#') continue;
      dp[POS(i,j)]=(dp[POS(i,j+1)]+dp[POS(i+1,j)])%mod;
    }
  }
  printf("%d\n",dp[POS(0,0)]);
}

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


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

long long N, M;
long long A[200005];
long long NUM[200005];
long long X[200005];
long long Y[200005];
long long paint[200005];

int main(){
	cin >> N >> M;
	for(long long i = 0; i < N; i++){
		cin >> A[i];
		NUM[A[i]]++;
	}
	for(long long i = 0; i < M; i++){
		cin >> X[i] >> Y[i];
	}

	long long ans = 0;

	for(long long j = N; j >= 0; j--){
		if(j != N && paint[j] <= 0){
			ans++;
		}
		if(NUM[j] > 0){
			for(long long k = 0; k < NUM[j]; k++){
				if(j - 1 - k >= 0){
					paint[j - 1 - k]++;
				}
			}
		}
	}


	for(long long i = 0; i < M; i++){
		long long from = A[X[i] - 1];
		long long to = Y[i];
		//cout << from << " -> " << to << endl;

		//f
		if(from - NUM[from] >= 0){
			paint[from - NUM[from]]--;
		}
		if(from - NUM[from] >= 0 && paint[from - NUM[from]] == 0){
			//cout << "ans++" << endl;
			ans++;
		}
		NUM[from]--;
		NUM[to]++;
		if(to - NUM[to] >= 0 && paint[to - NUM[to]] == 0){
			//cout << "ans--" << endl;
			ans--;
		}
		if(to - NUM[to] >= 0){
			paint[to - NUM[to]]++;
		}

		A[X[i] - 1] = to;

		cout << ans << endl;
	}
}


Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fr first
#define sc second
#define MAX ((ll)(1e9+100))
#define ARRS ((ll)(1e5+100))
#define pb push_back

vector<ll> v[ARRS];

ll dx[2][ARRS];
pair<ll,ll> dp[ARRS];
ll w[ARRS];

void go(ll x){
   for(auto y:v[x]){
      go(y);
   }
   ll P=0,N=1;
   for(int i=0; i<6005; i++)
      dx[P][i]=MAX;
   dx[P][0]=0;
   for(auto y:v[x]){
      for(int i=0; i<6004; i++){
         dx[N][i]=MAX;
      }
      for(int i=0; i<=5000; i++){

         if(i+dp[y].fr<=5000)
            dx[N][i+dp[y].fr]=min(dx[N][i+dp[y].fr],dx[P][i]+dp[y].sc);
         
         if(i+dp[y].fr<=5000)
            dx[N][i+dp[y].sc]=min(dx[N][i+dp[y].sc],dx[P][i]+dp[y].fr);

      }
      swap(N,P);
   }
   dp[x]={w[x],MAX};
   for(int i=0; i<=w[x]; i++){
      dp[x]=min(dp[x],{w[x],dx[P][i]});
   }
   if(dp[x].sc==MAX){
      cout<<"IMPOSSIBLE";
      exit(0);
   }
   //cout<<x<<" "<<dp[x].fr<<" "<<dp[x].sc<<endl;
}


int main(){
   ll n,k;
   cin>>n;
   for(int i=2; i<=n; i++){
      cin>>k;
      v[k].pb(i);
   }
   for(int i=1; i<=n; i++){
      cin>>w[i];
   }
   go(1);
   cout<<"POSSIBLE";
   
   return 0;
}


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

int main(){
  int n,s[10001],q;
  int ans=0,b;

  cin>>n;
  for(int i=0;i<n;i++) cin>>s[i];
  cin>>q;

  while(q>0){
    cin>>b;
    int i=0;
    q--;
    while(i<n&&s[i]!=b){
      i++;
    }
    if(i<n) ans++;
  }
  cout <<ans<<endl;
  return 0;
}



Measured memory_bytes: 3104
// Created by Kshitij Anand NSIT
#include <bits/stdc++.h>
//#include <ext/numeric>
//using namespace __gnu_cxx;


using namespace std;


#define int long long
#define pb push_back
#define P pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define mp(a, b) make_pair(a, b)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define fill(arr,val) memset(arr,val,sizeof(arr))
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define db(x)  cout<<#x<<" : "<<x<<endl


const int N = 1000000007;

void solve(){

    int n,a,b,c, ans=0, count=0, sum=0;
    cin>>n;
    ans = 1000 - n%1000;

    if(ans == 1000) ans = 0;

    cout<<ans<<endl;  
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    
  //  int t; cin>>t; while(t--)
    {     
      solve();
    }

  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
	int a, b, d, r;
	double f;
	cin >> a >> b;
	d = a/b;
	r = a%b;
	f = double(a)/double(b);
	printf("%d %d %.5f\n",d,r,f);
	return 0;
}


Measured memory_bytes: 3232
def find(A,x):
    p = A[x]
    if p == x:
        return x
    a = find(A,p)
    A[x] = a
    return a
 
def union(A, x, y):
#    bx, by = sorted([find(A,x), find(A,y)]) # bx, by = find(A,x), find(A,y)だと無限ループ。
    if find(A,x) > find(A,y):
        bx, by = find(A,y), find(A,x)
    else:
        bx, by = find(A,x), find(A,y)
    A[y] = bx
    A[by] = bx

#import sys
#input = sys.stdin.readline
import heapq
def main():
    N, M = map( int, input().split())
    A = list( map( int, input().split()))
    V = [ i for i in range(N)]
    q = []
    for _ in range(M):
        x, y = map( int, input().split())
        union(V, x, y)
    C = [0]*N
    T = [ [] for _ in range(N)]
    for i in range(N):
        C[find(V,i)] += 1
        heapq.heappush(T[find(V,i)], A[i])
    ans = 0
    if M == 0 and N == 1:
        print(0)
        return
    if M == 0:
        print("Impossible")
        return
    s = 0
    for i in range(N):
        if C[i] >= 2:
            if s == 0:
                q = T[i]
                heapq.heapify(q)
                s = 1
                continue
            if q:
                ans += heapq.heappop(q)
                ans += heapq.heappop(T[i])
                for a in T[i]:
                    heapq.heappush(q, a)
            else:
                print("Impossible")
                return
    for i in range(N):
        if C[i] == 1:
            if q:
                ans += heapq.heappop(q)
                ans += T[i][0]
            else:
                print("Impossible")
                return
    print(ans)
            
if __name__ == '__main__':
    main()


Measured memory_bytes: 23596