akhauriyash/Code-Regression huggingface dataset:
n,m,s=map(int,input().split())
edge=[[]for _ in range(n)]
for _ in range(m):
  a,b,c=map(int,input().split())
  edge[a].append((b,c))
from heapq import heappop,heappush
ans=[10**20]*n
ans[s]=0
h=[[0,s]]
while h:
  c,v=heappop(h)
  if ans[v]<c:continue
  for u,t in edge[v]:
    if c+t<ans[u]:
      ans[u]=c+t
      heappush(h,[c+t,u])
for i in ans:
  if i==10**20:print("INF")
  else:print(i)


Measured memory_bytes: 91320
// 22
/****************************************************
https://searleser97.gitlab.io/algorithms/template.cpp
****************************************************/

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fors(_, x, n, s) for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fors(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define forrs(_, x, n, s) for (int _ = x; _ > n; _ -= s)
#define forrn(_, x, n) forrs(_, x, n, 1)
#define rrep(_, n) forrn(_, n - 1, -1)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#ifdef LOCAL
#define cerr(s) cerr << "\033[48;5;196m\033[38;5;15m" s << "\033[0m"
#else
#define cerr(s)
#endif
// typedef __int128_t lli;
typedef long long int li;
typedef long double ld;
const int mod = 1e9 + 7;
// 12
void _main(int tc) {
  int h, w;
  cin >> h >> w;
  vector<string> mat(h);
  rep(i, h) cin >> mat[i];
  vector<vector<int>> mem(h, vector<int>(w));
  mem[h - 1][w - 1] = 1;
  rrep(i, h) {
    rrep(j, w) {
      for (auto& mv : vector<pairii>{{0, 1}, {1, 0}}) {
        int new_i = i + mv.fi, new_j = j + mv.se;
        if (new_i < h && new_j < w && mat[i][j] == '.') {
          mem[i][j] += mem[new_i][new_j];
          if (mem[i][j] >= mod) mem[i][j] -= mod;
        }
      }
    }
  }
  cout << mem[0][0] << endl;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0);
  return 0;
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

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

int main() {
	int a, b;
	cin >> a >> b;
	if (a == b) {
		cout << "Draw" << endl;
		return 0;
	}
	if (a != 1 && b != 1) {
		if (a > b)
			cout << "Alice" << endl;
		else
			cout << "Bob" << endl;
	}
	else {
		if (a == 1)
			cout << "Alice" << endl;
		else
			cout << "Bob" << endl;
	}
	return 0;
}

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

int main(){
  int n,y;
  int a=-1,b=-1,c=-1;
  cin >> n >> y;
  
  for(int i=0; i <= n; i++){
    for(int j=0; j <= n-i; j++){
      if(10000*i+5000*j+1000*(n-i-j) == y){
        a = i;
        b = j;
        c = n-i-j;
        break;
      }
    }
  }
  cout << a << " " << b << " " << c << endl;
      
}

Measured memory_bytes: 256
n = int(input())
s = []
for i in range(n):
    a = list(input())
    a.sort()
    s.append(a)
s.sort()
s = [''.join(x) for x in s]
result = 0
j = 0
while j < n-1:
    i = 1
    count = 0
    while s[j] == s[j+i]:
        i += 1
        count += 1
        if j+i > n-1:
            break
    result += count*(count+1)/2
    j += i
print(int(result))


Measured memory_bytes: 31812
// while( !(succeed == try()) );

#include "bits/stdc++.h"
using namespace std;

// Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha


#define int long long int
#define loop(i,s,e) for(int i=s; i<e; i++)
#define endl '\n'
#define vii vector<int>
#define pii pair<int, int>
#define ff first
#define ss second
#define N 100001
#define pb push_back
#define INF LLONG_MAX
#define inf INT_MAX

void INP();

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define rtn                                       if(0)return;
template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { rtn cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{     rtn 
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

// Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha // Alpha


void alpha()
{	
	int a, b, n;
	cin>>a>>b>>n;

	int rem = n%b;

	int x1 = n-rem-1;
	x1 = max(x1, 0LL);

	int x2 = n;

	int t1 = floor(1.0*a*x1/b) - a*floor(1.0*x1/b);
	int t2 = floor(1.0*a*x2/b) - a*floor(1.0*x2/b);

	// bug(x1, x2, t1, t2);

	if(t1 >= t2)
	{
		cout<<t1<<endl;
		return;
	}
	else
	{
		cout<<t2<<endl;
	}
	


}

int32_t main(){

	ios_base:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	// INP();
    int t=1;
	//cin>>t;

  	while(t--) alpha();

	return 0;

}






















inline void INP()
{
      #ifndef ONLINE_JUDGE
          freopen("input.txt",  "r",  stdin);
          freopen("output.txt", "w", stdout);
      #endif
}
 
 

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;


int main(void) {
	int h, w, i, j, dp[1003][1003] = {};
	string a[1003];
	const int mod = 1e9 + 7;

	cin >> h >> w;
	for (i = 0; i < h; i++) {
		cin >> a[i];
	}

	dp[0][0] = 1;
	for (i = 0; i < h; i++) for (j = 0; j < w; j++) {
		if (i == 0 && j == 0) continue;
		if (a[i][j] == '.') {
			if (i > 0) dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
			if (j > 0) dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
		}
	}

	cout << dp[h - 1][w - 1] << endl;

	return 0;
}

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

using namespace std;

int N,C;
int A[410],B[410];
const int MOD = 1e9 + 7;
typedef long long LL;
LL f[410][410],S[410][410];//S[i][j] = \sum_{k=1}^i{k^j}

int main()
{
    scanf("%d%d",&N,&C);
    for (int i=1;i<=N;i++)scanf("%d",&A[i]);
    for (int i=1;i<=N;i++)scanf("%d",&B[i]);
    for (int i=1;i<=400;i++)S[i][0] = 1;
    for (int j=1;j<=400;j++)
        for (int i=1;i<=400;i++)S[i][j] = S[i][j-1] * 1LL * i % MOD;
    S[0][0] = 1;
    for (int i=1;i<=400;i++)
        for (int j=0;j<=400;j++)
        {
            S[i][j] += S[i-1][j];
            S[i][j] %= MOD;
        }
    f[0][0] = 1;
    for (int i=1;i<=N;i++)
        for (int j=0;j<=C;j++)
        {
            for (int k=0;k<=j;k++)
            {
                f[i][j] += f[i-1][j-k] * (S[B[i]][k] - S[A[i] - 1][k] + MOD);
                f[i][j] %= MOD;
            }
        }
    printf("%lld\n",f[N][C]);
}


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

#define INF 1001001001

using namespace std;

int main(void) {
  int n,w;
  cin >> n >> w;
  vector<long> W(n);
  vector<int> V(n);

  for(int i = 0;i < n;i++){
    cin >> W[i] >> V[i];
  }
  vector<vector<long>> dp(n + 1,vector<long>(100100,INF));
  dp[0][0] = 0;
  for(int i = 0;i < n;i++){
    for(int j = 0;j < 100100;j++){
      if(j - V[i] >= 0){
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - V[i]] + W[i]);
      }
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
    }
  }
  for(int i = 100001;i > 0;i--){
    if(dp[n][i] <= w){
      cout << i << endl;
      break;
    }
  }
  
  return 0;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(){
  string s,t;cin>>s>>t;
  cout <<t+s<<endl;

}
  


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

#define ll long long

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

    int n; cin>>n;
    vector<pair<int,ll> > adj[n+3];
    for (int i = 0; i < n-1; i++)
    {
        int x, y; cin>>x>>y;
        ll c; cin>>c;
        adj[x].push_back({y,c});
        adj[y].push_back({x,c});
    }

    ll dist[n+3] = {};
    stack<int> s;
    dist[1] = 1;
    s.push(1);
    while (!s.empty())
    {
        int x = s.top(); s.pop();
        for (auto y: adj[x])
        {
            if (!dist[y.first])
            {
                s.push(y.first);
                dist[y.first] = dist[x] + y.second;
            }
        }
    }

    cout<<0<<endl;
    for (int i = 2; i <= n; i++)
    {
        dist[i]--;
        if (dist[i] % 2) cout<<1<<endl;
        else cout<<0<<endl;
    }
}


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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    long double a, b, c;
    cin >> a >> b >> c;
    dump(a + b + 2 * sqrt(a * b) < c ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+8
#define EPS 1e-8
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < k; i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;

int main(){
	int t[10];
	int n[10];
	rep(i,4){
		scanf("%d%d",&t[i],&n[i]);
		if(t[i] == 1){
			printf("%d\n",n[i]*6000);
		}
		else if(t[i] == 2){
			printf("%d\n",n[i]*4000);
		}
		else if(t[i] == 3){
			printf("%d\n",n[i]*3000);
		}
		else{
			printf("%d\n",n[i]*2000);
		}
	}
	return 0;
}

Measured memory_bytes: 1188
#include<iostream>
using namespace std;
int main(){
   int a,b;
   char c;
   cin>>a>>c>>b;
   if(c=='+'){
   	cout<<a+b<<endl;
   }
   else if(c=='-'){
   	cout<<a-b<<endl;
   }
   /*
   if (a<b){
   cout<<"Better"<<endl;
   }
   else if (a>b){
   cout<<"Worse"<<endl;
   }
   */
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
const int N=102;
string mat[N];
int flag[N][N];
int main(){
	ios::sync_with_stdio(false);
	int n,m; cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>mat[i]; bool ok=1;
		for(int j=0;j<m;j++){
			if(mat[i][j]=='#'){ok=0; break;}
		}
		if(ok){
			for(int j=0;j<m;j++) flag[i][j]=1;
		}
	}
	for(int j=0;j<m;j++){
		bool ok=1;
		for(int i=0;i<n;i++){
			if(mat[i][j]=='#'){ok=0; break;}
		}
		if(ok){
			for(int i=0;i<n;i++) flag[i][j]=1;
		}
	}
	for(int i=0;i<n;i++){
		bool ok=1;
		for(int j=0;j<m;j++){
			if(!flag[i][j]){ok=0; cout<<mat[i][j];}
		}
		if(!ok) cout<<endl;
	}
return 0;
}

Measured memory_bytes: 384
fn solve(rs: Vec<(i32, i32, i32)>) -> String {
    for i in 0..rs.len() - 1 {
        let (t1, x1, y1) = rs[i];
        let (t2, x2, y2) = rs[i + 1];
        let t = t2 - t1;
        let dist = (x2 - x1).abs() + (y2 - y1).abs();

        if t % 2 != dist % 2 || t < dist {
            return "No".to_string();
        }
    }
    "Yes".to_string()
}

fn main() {
    let n = read_1();
    let mut rs = vec!((0, 0, 0));
    rs.append(&mut read_tup3_n(n));

    println!("{}", solve(rs));
}

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

fn read_tup3_n<T: std::str::FromStr + Copy>(n: usize) -> Vec<(T, T, T)> {
    let mut ss = String::new();
    for _ in 0..n {
        std::io::stdin().read_line(&mut ss).ok();
    }
    let mut v = ss.split("\n").collect::<Vec<&str>>();
    v.pop();
    v.iter()
        .map(
            |s| {
                let v = s.trim().split_whitespace()
                    .map(|c| c.parse().ok().unwrap())
                    .collect::<Vec<T>>();
                (v[0], v[1], v[2])
            }
        )
        .collect()
}


Measured memory_bytes: 6132
#include "bits/stdc++.h"
using namespace std;
#define debug(var) cout << #var << ": " << var << endl;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
using ll = long long;
using ull = unsigned long long;
using vvint = vector<vector<int>>;
constexpr ll mod = 1e9 + 7;

int main() {

  int N; cin >> N;
  vector<string> s(N);
  map<string, ull> m;
  rep(i, N) {
	cin >> s[i];
	sort(s[i].begin(), s[i].end());
	m[s[i]]++;
  }
  ull ans = 0;
  for (const auto& v : m) {
	if (v.second <= 1)continue;
	else {
	  ans += ((v.second * (v.second - 1)) / 2);
	}
  }
  if (ans < 0)ans = 0;
  cout << ans;

  return 0;
}

Measured memory_bytes: 18176
n = int(input())
A = [int(x) for x in input().split()]

flag = 1
i = 0
cnt = 0
while flag==1:
    flag = 0
    for j in range(i+1,n)[::-1]:
        #print(j)
        if A[j-1]>A[j]:
            A[j-1],A[j] = A[j],A[j-1]
            flag = 1
            cnt += 1
    i += 1
print(*A)
print(cnt)



Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
  int n;
  cin >> n;
  vector<int>h(n);
  rep(i,n) cin >> h[i];
  
  int res = 0;
  int max_hight = 0;
  
  rep(i,n){
    max_hight = max(max_hight, h[i]);
    if(h[i] >= max_hight) ++res;
  }
  
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    ll N;
    cin >> N;
    set<ll> S;
    rep(i, N)
    {
        ll a;
        cin >> a;
        if(S.find(a) == S.end())
        S.insert(a);
        else
        {
            S.erase(a);
        }
        
    }
    cout << S.size();
    return 0;
}

Measured memory_bytes: 4992
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll r,d,x;
    cin >> r>>d>>x;
    rep(i,10){
        x = x*r -d;
        cout << x << endl;;
    }


    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int gcd(long int, long int);

int main(){
    int N, i;
    long int A[100000], X[100000], max=0;

    scanf("%d", &N);

    for(i=0; i<N; i++)
        scanf("%ld", &A[i]);
    
    X[0] = 0;
    
    for(i=0; i<N; i++){
        X[i+1] = gcd(X[i], A[i]);
    }

    printf("%ld\n", X[i]);

    return 0;
}

int gcd(long int a, long int b){
    long int r, work;

    if((a == 0 && b != 0 ) || (a != 0 && b == 0)){
        if(a==0)
            return b;
        else
            return a;
    }

    if(a < b){
        work = a;
        a = b;
        b = work;
    }

    r = a % b;

    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

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

using namespace std;


int main(){
    char a[26] = {'A','B','C','D','E','F','G','H','I','J','K','L','M',
                  'N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};

    string s;
    int n;
    cin>>n>>s;

    int num;
    for(int i=0;i<s.size();i++){
        num=0;
        for(int j=0;j<26;j++){
            if(s.at(i)==a[j]){
                if(j+n<=25) {
                    s.at(i) = a[j + n];
                }else{
                    num = (j+n) - 26;
                    s.at(i) = a[num];
                }
                break;
            }else{
                continue;
            }
        }
    }

    cout<<s<<endl;




};


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int i, ans = 0, X[101] = {0}, a[3];
    cin >> a[0] >> a[1] >> a[2];
    X[a[0]]++;
    X[a[1]]++;
    X[a[2]]++;
    for(i=0;i<101;i++)
    {
        if(X[i]!=0)
        ans++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3560
import java.util.Arrays;
    import java.util.Scanner;
     
    public class Main {
    	public static void main (String[] args) {
    		Scanner in = new Scanner(System.in);
    		int h = in.nextInt();
    		int w = in.nextInt();
    		String[] a = new String[h];
    		for (int i = 0; i < h; i++) {
    			a[i] = in.next();
    		}
     
    		boolean[] row = new boolean[h];
    		Arrays.fill(row, false);
    		boolean[] col = new boolean[w];
    		Arrays.fill(col, false);
    		for (int i = 0; i < h; i++) {
    			for (int j = 0; j < w; j++) {
    				if (a[i].charAt(j) == '#') {
    					row[i] = true;
    					col[j] = true;
    				}
    			}
    		}
     
    		for (int i = 0; i < h; i++) {
    			if (row[i]) {
    				for (int j = 0; j < w; j++) {
    					if (col[j]) {
    						System.out.print(a[i].charAt(j));
    					}
    				}
    				System.out.println();
    			}
    		}
    	}
    }

Measured memory_bytes: 26424
#include <iostream>
#include <string.h>
using namespace std;
 
int main() {
    string s, p;
    cin >> s >> p;
    s += s ;
    if (s.find(p) != string::npos)
    {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 1192
# 2019/11/18

h,w=map(int,input().split())

g=[list('@'*(w+2))]
for i in range(h):
    g+=[list('@')+list(map(int,input().split()))+list('@')]
g+=[list('@'*(w+2))]

dir=[(0,1),(1,0)]

n=0
ans=[]
for i in range(1,h+1):
    for j in range(1,w+1):
        if g[i][j]%2==0:
            continue
        right=g[i][j+1]
        down=g[i+1][j]            
        if right!='@':
            g[i][j]-=1
            g[i][j+1]+=1
            ans.append((i,j,i,j+1))
        elif down!='@':
            g[i][j]-=1
            g[i+1][j]+=1
            ans.append((i,j,i+1,j))
        else:continue
        n+=1
print(n)
[print(*e) for e in ans]

Measured memory_bytes: 23292
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n, k = MAP()
d = set(S_LIST())
m = n
while True:
    if len(set(str(m)) & d) == 0:
        print(m)
        exit()
    m += 1


Measured memory_bytes: 61544
#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(){

    int n;
    cin >> n ;
    vector<int> p(n);
    rep(i,n){
        cin >> p[i];
    }

    int mi=n+1;
    int cnt=0;
    rep(i,n){
        mi=min(mi,p[i]);
        if(p[i]<=mi){
            cnt++;
        }
    }
    cout << cnt << endl;

    return 0;
}

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

using namespace std;

int n, a[100001], dp[100001];

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    dp[2] = abs(a[1] - a[2]);
    for (int i = 3; i <= n; i++) {
        dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
    }

    cout << dp[n];

    return 0;
}

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

int main() {
  int64_t N,X,Z=0;
  cin>>N>>X;
  vector<int64_t> p(N);
  for(int i=0;i<N;i++){
    cin>>p.at(i);
  }
  for(int i=1;i<N;i++){
    if(p.at(i-1)>X){
      Z+=p.at(i)+p.at(i-1)-X;
      p.at(i)=0;
    }
    else if(p.at(i)+p.at(i-1)>X){
      Z+=p.at(i)+p.at(i-1)-X;
      p.at(i)=X-p.at(i-1);
    }
  }
  cout<<Z<<endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

class Main {

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

        int W = scan.nextInt();
        int H = scan.nextInt();
        int x = scan.nextInt();
        int y = scan.nextInt();
        int r = scan.nextInt();
        
        if(W>=(r+x) && 0<=(x-r) && 0<=(y-r) && H>=(y+r)){
            System.out.println("Yes");
 }
        else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 26204
N = int(input())
A = list(map(int, input().split()))
a_sum = sum(A)
Q = int(input())

from collections import Counter
counter = Counter(A)

for q in range(Q):
  b, c = map(int, input().split())
  b_count = counter.get(b, 0)
  counter[c] = counter.get(c, 0) + b_count
  if b_count:
    del counter[b]
  b_sum = b * b_count
  c_sum = c * b_count
  a_sum = a_sum - b_sum + c_sum
  print(a_sum)

Measured memory_bytes: 24004
#include<stdio.h>

int main()
{
  char b;

  scanf("%c", &b);

  if(b=='A'){
    printf("T\n");
  }
  else if(b=='T'){
    printf("A\n");
  }
  else if(b=='C'){
    printf("G\n");
  }
  else if(b=='G'){
    printf("C\n");
  }

  return 0;
}


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

typedef complex<double> P;
const double EPS = 1e-8;
double norm(P a) { return a.real()*a.real()+a.imag()*a.imag(); }
double dot(P a, P b) { return a.real()*b.real() + a.imag()*b.imag(); }
double cross(P a, P b) { return a.real()*b.imag() - a.imag()*b.real(); }
int ccw(P p0, P a, P b) {
  a -= p0;
  b -= p0;
  if(cross(a, b) > EPS) return 1;
  if(cross(a, b) < -EPS) return -1;
  if(dot(a, b) < -EPS) return 2;
  if(norm(a) < norm(b)) return -2;
  return 0;
}

P getCrossP(P a1, P a2, P b1, P b2) {
  P a = a2 - a1;
  P b = b2 - b1;
  // cross Ã£ÂÂ®Ã§Â¬Â¦Ã¥ÂÂ·Ã©ÂÂ¢Ã¤Â¿ÂÃ£ÂÂÃ£ÂÂ
  return a1 + a * cross(b, b1 - a1)/cross(b, a);
}

vector<P> convex_cut(vector<P> ps, P l1, P l2, int dir = -1) {
  vector<P> v;
  for(int i = 0; i < ps.size(); ++i) {
    P a = ps[i];
    P b = ps[(i+1)%ps.size()];
    if(ccw(l1, l2, a) != dir) v.push_back(a);
    if(ccw(l1, l2, a)*ccw(l1, l2, b) < 0)
      v.push_back(getCrossP(a, b, l1, l2));
  }
  return v;
}

int solve(vector<P> &ps) {
  vector<P> v;
  v.push_back(P(-20000, -20000));
  v.push_back(P(20000, -20000));
  v.push_back(P(20000, 20000));
  v.push_back(P(-20000, 20000));

  for(int i = 0; i < ps.size(); ++i) {
    v = convex_cut(v, ps[i], ps[(i+1)%ps.size()]);
  }
  return v.empty() ? 0 : 1;
}

int main() {
  int n;
  while((cin >> n) && n) {
    vector<P> ps;
    for(int i = 0; i < n; ++i) {
      P p;
      cin >> p.real() >> p.imag();
      ps.push_back(p);
    }
    cout << solve(ps) << endl;
  }
  return 0;
}

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

using namespace std;

int main(){
	pair<double,double> p1,p2;
	cin >> p1.first >> p1.second;
	cin >> p2.first >> p2.second;
	double dis;
	dis=sqrt(pow(p2.first-p1.first,2.0)+pow(p2.second-p1.second,2.0));
	printf("%f\n",dis);
	return 0;
}

Measured memory_bytes: 3176
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int flag = 0;
        Monmo momo = new Monmo(7,k);
        
        for(int i=1;i<1000000;i++){ //19万回で処理が終わらない場合は存在しない可能性が高い
            if(momo.zero()){
                System.out.println(i);
                flag = 1;
                break;
            }
            momo.ten();
            momo.sho();
        }
        if(flag == 0){
            System.out.println("-1");
        }
    }
}

class Monmo {
    int n;
    int k;
    int rem;
    int verrem;
    
    Monmo(int n,int k){
        this.n=n;
        this.k=k;
        rem = n%k;
        verrem = n;
    }
    
    boolean zero(){
        if(rem == 0){
            return true;
        }else{
            return false;
        }
    }
    
    void ten(){
        verrem *= 10;
        verrem %= k;
        rem +=  verrem;
    }
    
    void sho(){
        rem %= k;
    }
    
}


Measured memory_bytes: 36116
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <list>
using namespace std;

const int NMAX = 1e5;
int cnt[NMAX] = {};

int main(){

    int n, q;
    cin >> n >> q;

    string s;
    cin >> s;

    int left[q], right[q];
    for(int i=0; i<q; i++){
        cin >> left[i] >> right[i];
    }

    int temp = 0;
    for(int i=1; i<n; i++){
        if(s[i-1] == 'A' && s[i] == 'C'){
            temp++;
            cnt[i] = temp;
        }
        else{
            cnt[i] = temp;
        }
    }

    for(int i=0; i<q; i++){
        cout << (cnt[right[i]-1] - cnt[left[i]-1]) << endl;
    }




    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll x,y;cin >> x >> y;
	if(x%y==0){
		cout << -1 << endl;
		return 0;
	}
	for(ll i=x;i<=1000000000000000000;i+=x){
		if(i%y!=0){
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef		long long       ll;
typedef         long double      dl;
typedef     unsigned long long  ull;
#define		pb              push_back
#define		PB              pop_back
#define		nn              "\n"
#define     O_O             ios_base::sync_with_stdio(false); cin.tie(NULL)
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define		ss              ' '
#define         arrsize(a)      (sizeof(a)/sizeof(a[0]))
//#define       arrsize(a)      (sizeof(a)/sizeof(*a))
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
#define		pi              acos(-1.0)
typedef        pair <int, int>   pii;
typedef       pair <ll, ll>      pll;
typedef      vector< pair <ll, ll> >      vpll;
typedef		vector<ll>      vll;
typedef		map<string,ll>      msl;
typedef		map<ll,ll>      mll;
#define yes cout << "YES\n"
#define no cout<<"NO\n"
//#define sort(x) sort(x.begin(), x.end())
//sort(a,a+n,greater<ll>())
//for (auto it = mp.begin(); it != mp.end(); ++it){}
#define MAX 1000005
#define mod 1000000007



int main()
{
 //O_O ;
   ll a,b,n;
   cin>>a>>b>>n;
   ll mi=min(n,b-1);
   ll ans=dl(floor((a*mi)/b))-a*floor(dl(mi/b));
   cout<<ans<<nn;



    return 0;
}


Measured memory_bytes: 3592
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e  2.718281828459045
#define eps 1.0e18
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define memset(x,y) memset(x,y,sizeof(x))
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
#define ll long long
using namespace std;
const int N = 200005;
double p[N];
int main(){
	ios::sync_with_stdio(false);
	double n,k;
	cin>>n>>k;
	double sum=0,maxn=0;
	for(int i=0;i<n;i++){
		cin>>p[i];
		if(i<k){
			sum=sum+p[i];
		}
		else{
			sum=sum-p[i-(int)k]+p[i];
		}
		maxn=max(sum,maxn);
	}
	printf("%lf",(maxn+k)/2.0);
//	cout<<(maxn+k)/2.0<<endl;	
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(i) begin(i), end(i)

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }

ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll pow_mod(ll n,ll k,ll m){ll r = 1;for(; k > 0;k >>= 1) {if (k & 1) r = (r * n) % m; n = (n * n) % m;}return r;}

//ここから。
int main(){
    int H1,M1,H2,M2,K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;
    int memo;
    if(M1 != 0){
        memo = -1*M1 + M2;
    }else{
        memo = M2;
    }
    cout << (H2 - H1)*60 + memo - K << endl;
}

Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
from operator import mul
import sys
from operator import itemgetter
# gcd
from fractions import gcd
# 切り上げ，切り捨て
from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
from collections import Counter
import math
from functools import reduce
# input関係の定義
# fin = open('in_2.txt', 'r')
# sys.stdin = fin
#
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


MOD = 1000000007  # type: int


def cmb(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


def H(n, r):
    if n == 0:
        return 1
    return cmb(n + r - 1, n)


def solve(N: int, K: int):
    for i in range(1, K + 1):
        if N - K - i + 1 < 0:
            print(0)
        else:
            print(cmb(K - 1, i - 1) * H(N - K - i + 1, i + 1) % MOD)


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
    K = int(next(tokens))  # type: int
    solve(N, K)


if __name__ == '__main__':
    main()


Measured memory_bytes: 70104
n,m = map(int,input().split())
a = [tuple(map(int,input().split())) for i in range(n)]
b = [tuple(map(int,input().split())) for i in range(m)]
inf = float("inf")
for ai,bi in a:
    d,num = inf,0
    for i in range(m):
        ci,di = b[i]
        x = abs(ai-ci)+abs(bi-di)
        if d > x:
            d = x
            num = i+1
    print(num)

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#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 PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(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 pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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; }

const ll INF = 1e15;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll ngcd(vector<ll> a) {
  ll res = a[0];
  for(ll i=1; i<a.size() && res!=1; i++) res = gcd(a[i], res);
  return res;
}
ll nlcm(vector<ll> a){
  ll res = a[0];
  for(ll i=1; i<a.size(); i++) res = lcm(a[i], res);
  return res;
}
bool is_prime(ll n) {
  if(n < 2) return false;
  for (ll i = 2; i * i <= n; i++) if (n % i == 0) return false;
  return true;
}
ll digsum(ll n) {
  ll res=0;
  while(n) res += n%10, n /= 10;
  return res;
}
ll digcnt(ll n){
  ll res=0;
  while(n) res++, n /= 10;
  return res;
}
vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i) res.push_back(n / i);
    }
  }
  sort(res.begin(), res.end());
  return res;
}
map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) ++res[i], n /= i;
  }
  if (n != 1) res[n] = 1;
  return res;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,k; cin>>n>>k;
  vll a(n);
  ll sum=0;
  rep(i,n){
    cin>>a[i];
    sum+=a[i];
  }
  
  auto v=divisor(sum);
  reverse(all(v));
  
  ll ans=1;
  for(auto e: v){
    vll b(n);
    rep(i,n) b[i]=a[i]%e;
    vsort(b);
    ll plus=0, minus=0;
    rep(i,n) plus+=e-b[i];
    rep(i,n){
      minus+=b[i];
      plus-=e-b[i];
      if(plus==minus){
        if(plus<=k) {
          chmax(ans,e);
        }
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(a,b) for(ll i=a;i<b;i++)
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

int main()
{   io

    ll n=0;
    cin>>n;
    ll h[n];
    ll dp[n];
    rep(0,n)
        cin>>h[i];

    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(ll i=1;i<n;i++)
    {
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }

    cout<<dp[n-1];
    return 0;
}


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

#define loop(i,n) for(int i=0;i<n;i++)
int dp[4002][4002];

int main(){
  string a,b;
  while(cin>>a>>b){
    int m=0;
    loop(i,a.size())loop(j,b.size()){
      if(a[i]==b[j]){
        if(i==0||j==0)dp[i][j]=1;
        else dp[i][j]=dp[i-1][j-1]+1;
      }else{
        dp[i][j]=0;
      }
      m=max(m,dp[i][j]);
    }
    cout<<m<<endl;
  }
  return 0;
}

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

long long combi(long long n) {
    return n*(n - 1) /2;
}

int main(){
  map<int,int> mball;
  int N,a;
  long long sum=0,bcombi,acombi;
  vector<int> vball;
  cin >> N;
  for(int i = 0;i < N;i++){
  	cin >> a;
    vball.push_back(a);
    mball[a] += 1;
  }
  for(auto itr = mball.begin(); itr != mball.end(); ++itr) {
        if(itr->second ==  1){
        }else{
        	sum += combi(itr->second);
        }
    }
  for(int i = 0;i < N;i++){
    bcombi=0,acombi=0;
	auto itr = mball.find(vball.at(i));
    if( itr != mball.end()) {
        bcombi = combi((itr->second));
      	acombi = combi((itr->second - 1));
      }
    cout << sum + acombi - bcombi<< endl;
  }
  
}


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

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  x--;
  y--;
  
  int ans[n] = {};
  int visited[n];
  queue<int> q;
  
  function<void(int)> bfs = [&](int curr){
    memset(&visited[0], 0, 4 * n);
    
    int steps(0);
    q.push(curr);
    
    while (!q.empty()) {
      int s = q.size();
      while (s--) {
        int c = q.front();
        q.pop();
        
        if (visited[c]) continue;
        visited[c] = 1;
        
        if (c > curr) ans[steps]++;
        
        if (c < n-1) q.push(c+1);
        if (c > 0) q.push(c-1);
        if (c == x) q.push(y);
      }
      steps++;
    }
  };
  for (int i = 0; i < n - 1; ++i) {
    bfs(i);
  }
  for (int i = 1; i < n; ++i) cout << ans[i] << '\n';
  return 0;
}

Measured memory_bytes: 384
use proconio::input;
use std::cmp::min;

fn main() {
    input! {
        n: usize,
        m: usize,
    }
    
    let ans = if n == 1 && m == 1 {
        1
    } else if n == 1 || m == 1 {
        n * m - 2
    } else {
        n * m + 4 - n * 2 - m * 2
    };

    println!("{}", ans);
}


Measured memory_bytes: 2140
import sys

n=sys.stdin.readline().rstrip()[::-1]
to=0

m=0
n+="0"
num=len(n)

for i in range(num):
    k=int(n[i])
    k+=m
    if k==5:
        if int(n[i+1])>=5:
            to+=10-k
            m=1
        else:
            to+=k
            m=0
    if k<5:
        to+=k
        m=0
    elif k>5:
        to+=10-k
        m=1
        
print(to+m)


Measured memory_bytes: 5492
#include <stdio.h>
int main(void)
{
	int n,max,tmp,count,cmax;
	scanf("%d\n",&n);
	max=1;
	for(int i=2;i<=n;++i)
	{
		count = 0;
		tmp = i;
		while(tmp%2==0)
		{
			tmp/=2;
			count++;
		}
		if(count>=cmax)
		{
			cmax=count;
			max=i;
		}
	}
	printf("%d\n",max);
}

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

using namespace std;
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
    isPrime[1]=false;
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}







/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
    ll n;
    cin>>n;
  vector<bool> isPrime=sieve_of_eratosthenes();
    vector<ll> v(100010);
    v[0]=0;
    for(ll i=1;i<100010;i++){
        if(isPrime[i] && isPrime[(i+1)/2]) v[i]=1;
        else v[i]=0;
    }
    vector<ll> sum(100010,0);
    rep(i,100009){
        sum[i+1]=sum[i]+v[i+1];
    }
    rep(i,n){
        ll a,b;cin>>a>>b;
        cout<<sum[b]-sum[a-1]<<endl;
    }
    
    
    
}


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

int main(){
 int a,b;
 char op;
 while(1){
   cin >> a >> op >> b;
   if( op == '?'){ 
      break;
   }else if (op == '+'){
    cout << a + b << endl;
   }else if (op == '-'){
    cout << a - b << endl;
   }else if (op == '*'){
    cout << a * b << endl;
   }else if (op == '/'){
    cout << a / b << endl;
   }
   }
 return 0;
}
 


Measured memory_bytes: 3072
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");

        int n = Integer.valueOf(arr01[0]);

        if (n % 2 == 0) {
            System.out.println(n / 2 - 1);
        } else {
            System.out.println(n / 2);

        }

    }

}

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

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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

const int mod = 1e9+7;




int main() {
    int n;
    cin >> n;
    vector<int> a(n+1, 0);
    rep (x, 1, 110) {
        rep (y, 1, 110) {
            rep (z, 1, 110) {
                int p = (x + y) * (x + y) + (y + z) * (y + z) + (z + x) * (z + x);
                if (p % 2 != 0) continue;
                p /= 2;
                if (1 <= p  && p <= n) {
                    a[p]++;
                }
            }
        }
    }
    rep (i, 1, n+1) {
        cout << a[i] << endl;
    }
}



Measured memory_bytes: 3668
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <limits>
#include <cmath>

using namespace std;

int main() {
  int n,d;
  cin >> n;
  
  int sum = 0;
  int p = 0;
  for (int i = 0; i < n; i++) {
    cin >> d;
    sum += d;
    p += d*d;
  }
  
  cout << (sum*sum-p)/2 << endl;
}

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

using namespace std;

typedef long long int ll;
#define inf 0x3f3f3f3f
#define endl '\n'
// #define case(i) "Case #" << i << ": "

int n, k;
vector<int> v;
int dp[100001];

int solve(int i) {
    if(i == 0) return 0;
    else {
        int mn = inf;
        for(int j = 1; j <= k && i - j >= 0; ++j) {
            if(dp[i-j] == -1) dp[i-j] = solve(i-j);
            mn = min(mn, abs(v[i] - v[i-j]) + dp[i-j]);
        }
        return mn;
    }
}

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

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

    cin >> n >> k;
    v.resize(n);

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

    cout << solve(n-1) << endl;
}

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

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

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

    double res = 0;
    for (int i = 0; i < n; ++i){
        res += 1.0/a[i];
    }
    printf("%.10f\n", 1/res);
}

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

using namespace std;

struct Node {
  int key;
  Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int key) {
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = key;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL) {
    y = x;
    if (z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;

  if (y == NIL) {
    root = z;
  } else {
    if (z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

Node * find(Node *node, int key) {
  while (node != NIL && key != node->key) {
    if (key < node->key) {
      node = node->left;
    } else if (key > node->key) {
      node = node->right;
    }
  }
  return node;
}

Node * treeMinimum(Node *x) {
  while (x->left != NIL) x = x->left;
  return x;
}

Node * treeSuccessor(Node *x) {
  if (x->right != NIL) return treeMinimum(x->right);
  Node *y = x->parent;
  while (y != NIL && x == y->right) {
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node *z) {
  Node *target; // 削除対象
  Node *target_child;

  if (z->left == NIL || z->right == NIL) target = z;
  else target = treeSuccessor(z);

  if (target->left != NIL) {
    target_child = target->left;
  } else {
    target_child = target->right;
  }

  if (target_child != NIL) {
    target_child->parent = target->parent;
  }

  if (target->parent == NIL) {
    root = target_child;
  } else {
    if (target == target->parent->left) {
      target->parent->left = target_child;
    } else {
      target->parent->right = target_child;
    }
  }

  if (target != z) {
    z->key = target->key;
  }

  free(target);
}

void inorder(Node *node) {
  if (node == NIL) return;
  inorder(node->left);
  printf(" %d", node->key);
  inorder(node->right);
}
void preorder(Node *node) {
  if (node == NIL) return;
  printf(" %d", node->key);
  preorder(node->left);
  preorder(node->right);
}


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

  for (int i = 0; i < n; i++) {
    string s; int key;
    cin >> s;
    if (s == "insert") {
      cin >> key;
      insert(key);
    } else if (s == "find") {
      cin >> key;
      Node *node = find(root, key);
      if (node != NIL) cout << "yes" << endl;
      else cout << "no" << endl;
    } else if (s == "print") {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if (s == "delete") {
      cin >> key;
      treeDelete(find(root, key));
    }
  }

  return 0;
}



Measured memory_bytes: 21984
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 200 + 5;
ll a[maxn] , n;
int main()
{
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 1 ; i <= n ; i++) cin >> a[i];
    ll ans = 0;
    ll now = 1000;
    a[0] = 1e9;
    for (int i = 1 ; i <= n ; i++){
        if (a[i] > a[i - 1]){
            ll g = now / a[i - 1];
            now -= g * a[i - 1];
            now += g * a[i];
        }
    }
    cout << now << endl;
    return 0;
}

Measured memory_bytes: 3584
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<functional>
using namespace std;
int p = 998244353;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(long long i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define V vector
#define Endl endl
#define veb vector<bool>
#define sq(a) (a)*(a)
int kai_size = 400001;
vel kai(kai_size, 1);
vel ink(kai_size, 1);
vel dist;
int RE() {
	vel v(3, 2);
	return v.at(4);
}
int ru(int a, int r) {
	if (r == 0) { return 1; }
	int ans = ru(a, r / 2);
	ans *= ans; ans %= p;
	if (r % 2 == 1) { ans *= a; }
	return ans % p;
}
int inv(int a) {
	return ru(a, p - 2);
}
void make_kai() {
	rep(i, kai_size) { kai[i + 1] = (kai[i] * (i + 1)) % p; }
	rep(i, kai_size) { ink[i] = inv(kai[i]); }
}
int com(int n, int r) {
	int ans = kai[n] * ink[r];
	ans %= p; ans *= ink[n - r]; ans %= p;
	return ans;
}
int per(int n, int r) {
	int ans = kai[n] * ink[n - r];
	ans %= p;
	return ans;
}
signed main() {
	string n; cin >> n;
	int sz = n.size();
	bool fl = true;
	for (int i = 1; i < sz; i++) {
		if (n[i] != '9') { fl = false; }
	}
	int ans = n[0] - '0';
	ans += (sz - 1) * 9;
	if (fl) { cout << ans << endl; }
	else {
		cout << ans - 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 6528
#include <stdio.h>
int main (){
  int w,h,x,y,r;
  scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
  if (x-r<0||x+r>w){
    printf("No\n");
  } 
  else if (y-r<0||y+r>h){
    printf("No\n");
  } else{
    printf("Yes\n");
  }
  return 0;
}

Measured memory_bytes: 584