akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;

int main() {
    int n;
    cin >> n;
    lli a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    lli s[n];
    for (int i = 0; i < n; i++) {
        s[i] = a[i] - (i + 1);
    }
    sort(s, s+n);
    lli b = s[int(n/2)];
    lli sum = 0;
    for (int i = 0; i < n; i++) {
        sum += abs(a[i]-(b+i+1));
    }
    cout << sum << endl;
    return 0;
}

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

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

  vector<int> P(N);
  vector<int> Q(N);

  for(int i=0;i<N;i++) {
    cin >> P.at(i);
  }

  for(int i=0;i<N;i++) {
    cin >> Q.at(i);
  }

  int p=0, q=0;
  while(next_permutation(P.begin(), P.end())) p++;
  while(next_permutation(Q.begin(), Q.end())) q++;

  cout << abs(p-q) << endl;

  return (0);
}


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

int binarySearch(int n,int q,int S[],int flag) {
	int left = 0;
	int right = n;
	int mid;
	while (left < right) {
		mid = (left + right) / 2;
		if (S[mid] == flag) return 1;
		else if (S[mid] > flag) right = mid;
		else if (S[mid] < flag) left = mid + 1;

	}
	return 0;

}
int main() {

	int S[100000],T,n,q,i,c=0;

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

	for (i = 0; i < q; i++) {
		cin >> T;

		if (binarySearch(n, q, S, T)) c++;
	}

	cout << c<<endl;


	
}

Measured memory_bytes: 3432
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a%b) : a; }
long long lcm(long long a, long long b) {
	return a / gcd(a, b) * b;
}
signed main()
{
	int n, t, a;
	cin >> n >> t >> a;
	double risou = (double)(t - a) / 0.006;
	int ans = INT_MAX/2;
	int ansnum;
	int tmp;
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		double tmp2 = tmp;
		double tmp3=tmp-risou;
		if (tmp3 < 0)tmp3 = -tmp3;
		double tmp4 = ans - risou;
		if (tmp4 < 0)tmp4 = -tmp4;
		if ( tmp3<tmp4 ) { ans = tmp; ansnum = i + 1; }
	}
	cout << ansnum;
}

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

long long fac(int k){long long sum = 1;for(int i=1;i<=k;++i)sum *= i;return sum;}
long long per(int n,int r){long long nn,rr;nn=fac(n);rr=fac(r)*fac(n-r);return nn/rr;}

int main(){
    int a,b;
    cin >> a >> b;
    if(b<a)cout << a-1 << endl;
    else cout << a << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

int main() {
  int N;
  while(cin >> N && N) {
    vector<string> vec[30];
    string s[30];
    for(int ii=0; ii<N; ii++) {
      cin >> s[ii];
      int m, d; cin >> m;
      for(int i=0; i<m; i++) {
	cin >> d;
	vec[d].push_back(s[ii]);
      }
    }
    
    map<string, int> score;
    
    for(int i=0; i<N; i++) {
      score[s[i]] = 0;
    }
    
    for(int i=0; i<30; i++)
      for(int j=0; j<(int)vec[i].size(); j++)
	score[vec[i][j]] += N-vec[i].size()+1;
    
    vector<pair<int, string> > ans;
    map<string, int>::iterator it = score.begin();
    for(;it!=score.end(); it++) {
      ans.push_back(make_pair(it->second, it->first));
    }
    sort(ans.begin(), ans.end());
    cout << ans[0].first << ' ' << ans[0].second << endl;
  }
  return 0;
}

Measured memory_bytes: 1236
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))


ans=9999
diff=9999

x,n=nm()
p=set(nl())

for i in range(102):
  if i not in p:
    if abs(x-i)==diff:
      if i<ans:
        ans=i
    elif abs(x-i)<diff:
      diff = abs(x-i)
      ans = i

print(ans)



Measured memory_bytes: 9196
num = int(input())
pattern = {"AC":0, "WA":1, "TLE":2, "RE":3}
result = [0, 0, 0, 0]
for i in range(num):
  si = input()
  result[pattern[si]] += 1

print("AC x {0}".format(result[0]))
print("WA x {0}".format(result[1]))
print("TLE x {0}".format(result[2]))
print("RE x {0}".format(result[3]))

Measured memory_bytes: 9208
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    long ans = 0;
    for (int i = 1; i <= n; i++){
      if (i%3==0 || i%5 == 0){
        continue;
      }else{
        ans = ans + i;
      }
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 35592
#include <bits/stdc++.h>
using std::cerr;using std::cin;using std::cout;using std::abs;using std::min;using std::max;using std::swap;using std::map;using std::unordered_map;using std::unordered_set;using std::bitset;using std::pair;using std::set;using std::string;using std::vector;using std::sort;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);std::iostream::sync_with_stdio(0);cout<<std::fixed<<std::setprecision(10);cerr<<std::fixed<<std::setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}


const int N=1e5+5;

int32_t main(){
    int n,k,s;
    cin>>n>>k>>s;
    int nes=1000000000;
    if(s==nes)nes--;
    forn(i,k)cout<<s<<' ';
    forn(i,n-k)cout<<nes<<' ';
    cout<<'\n';

    return 0;
}


Measured memory_bytes: 1280
N = int(input())

if (N <= 3):
    ans = 'No'
else:
    mod_7 = N // 7
    
    ans = 'No'
    
    for i in range(mod_7 + 1):
        n = N
        n -= 7 * i
        
        if (n % 4 == 0):
            ans = 'Yes'
            break


print(ans)

Measured memory_bytes: 2940
#include<stdio.h>
#include<string.h>
    char s[105][105];
    int n,l,i,j;
    char a[105];
    int main()
    {
    while(~scanf("%d%d",&n,&l))
       {
       for(i=0;i<n;i++)
          scanf("%s",s[i]);
       for(i=0;i<n-1;i++)
          for(j=0;j<n-1-i;j++)
             if(strcmp(s[j],s[j+1])>0)
                {
                strcpy(a,s[j]);
                strcpy(s[j],s[j+1]);
                strcpy(s[j+1],a);
                }
       for(i=0;i<n;i++)
       printf("%s",s[i]);
       printf("\n");
    }
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size()
#define bgn begin()
#define en end()
#define pb(a) push_back(a)
#define pp() pop_back()
#define V vector
#define P pair
#define V2(a,b,c) V<V<int>> a(b,V<int>(c))
#define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d))
#define incin(a) int a; cin>>a
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())

signed main(){
  string s;
  cin>>s;
  int a=0;
  int b=0;
  int c=s.size();
  for(int i=0; i<c; i++){
    if(i%2==0){
      if(s[i]=='0')
        a++;
    }
    else{
      if(s[i]=='1')
        a++;
    }
  }
  for(int i=0; i<c;i++){
    if(i%2==1){
      if(s[i]=='0')
        b++;
    }
    else{
      if(s[i]=='1')
        b++;
    }
  }
  cout<<min(a,b)<<endl;
}



Measured memory_bytes: 512
( N, X ) = gets.split(' ').map(&:to_i)
b = gets.split(' ').map(&:to_i)
a = [0]
N.times { |i| a.push(a[i] + b[i]) }
ret = 0
a.each_with_index { |x, i| 
  if X >= x
    ret = i + 1
  else
    break
  end
}
puts ret

Measured memory_bytes: 1788
import static java.util.Arrays.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	void solve() {
		int n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			solve2();
		}
	}

	void solve2() {
		char[] s = sc.next().toCharArray();
		sort(s);
		long min = Long.parseLong(new String(s), 10);
		rev(s, 0, s.length);
		long max = Long.parseLong(new String(s), 10);
		System.out.println(max - min);
	}

	static void swap(char[] is, int i, int j) {
		char t = is[i]; is[i] = is[j]; is[j] = t;
	}

	static void rev(char[] is, int s, int t) {
		while (s < --t) swap(is, s++, t);
	}

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

	MyScanner sc = null;
	PrintWriter out = null;
	public void run() throws Exception {
		sc = new MyScanner(System.in);
		out = new PrintWriter(System.out);
		for (;sc.hasNext();) {
			solve();
			out.flush();
		}
		out.close();
	}

	class MyScanner {
		String line;
		BufferedReader reader;
		StringTokenizer tokenizer;

		public MyScanner(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}
		public void eat() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					line = reader.readLine();
					if (line == null) {
						tokenizer = null;
						return;
					}
					tokenizer = new StringTokenizer(line);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
		public String next() {
			eat();
			return tokenizer.nextToken();
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		public boolean hasNext() {
			eat();
			return (tokenizer != null && tokenizer.hasMoreElements());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
	}
}

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

#define N (LL)1e9+5
typedef long long LL;

void fastIO_test(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

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

void solve(void)
{
    LL a, b, c, d;
    cin >> a >> b >> c >> d;
    LL max_pro = LLONG_MIN;
    LL p1 = a*c;
    max_pro = max(max_pro, p1);
    LL p2 = a*d;
    max_pro = max(max_pro, p2);
    LL p3 = b*c;
    max_pro = max(max_pro, p3);
    LL p4 = b*d;
    max_pro = max(max_pro, p4);
    cout << max_pro << "\n";
}

int main()
{
    fastIO_test();

    LL t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

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

void sieve(ll n, vector<ll>& ps, vector<bool>& is_prime){
	ps = vector<ll>();
	is_prime = vector<bool>(n + 1, true);

	is_prime[0] = is_prime[1] = false;
	for(ll i = 2; i <= n; i++){
		if(is_prime[i]){
			ps.push_back(i);
			for(ll j = 2 * i; j <= n; j += i){
				is_prime[j] = false;
			}
		}
	}
}

int a[100010];
int s[100010];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	vector<ll> ps;
	vector<bool> prime;
	sieve(200000, ps, prime);

	for(int i = 2; i < 100010; i++){
		if(i % 2 && prime[i] && prime[(i + 1) / 2]){
			a[i] = 1;
		}
		s[i + 1] = s[i] + a[i];
	}

	int Q;
	cin >> Q;
	while(Q--){
		int l, r;
		cin >> l >> r;
		cout << s[r + 1] - s[l] << endl;
	}
}


Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	char a, b;
	cin >> a >> b;

	if (a == b)
	{
		cout << "H";
	}
	else
	{
		cout << "D";
	}
	cout << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    string s;
    cin >> s;
    int cnt=0;
    rep(i,s.size()){
        if(s[i]=='g'){
            cnt++;
        }else{
            cnt--;
        }
    }
    cout << cnt/2 << endl;
    return 0;
}


Measured memory_bytes: 512
/*
@author: sharrad99
*/
#include<bits/stdc++.h>
using namespace std;
const int64_t mod = 998244353;
const int64_t oo = 2000000000;
int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int64_t n;
	cin >> n;
	vector<pair<int64_t, int64_t>> robot(n + 1);
	vector<int64_t> dp(n + 1);

	for(int64_t i = 0; i < n; i++) {
		cin >> robot[i].first >> robot[i].second;
	}

	robot[n] = make_pair(oo, oo);
	sort(robot.begin(), robot.end());

	dp[n] = 1;
	stack<int64_t> s;
	s.push(n);

	for(int64_t i = n - 1; i >= 0; i--) {
		int64_t g = robot[i].first + robot[i].second;
		while(!s.empty() and robot[s.top()].first < g) {
			s.pop();
		}

		dp[i] = (dp[i] + dp[i + 1] + dp[s.top()]) % mod;
		s.push(i);
	}

	cout << dp[0];
}

Measured memory_bytes: 5760
#include<vector>
#include<cmath>
#include<algorithm>

const double INF = 1e9;
const double EPS = 1e-9;

struct Point {
    Point() :x(INF), y(INF) {}
    Point(double x, double y) :x(x), y(y) {}
    bool operator==(const Point& p) const {return x == p.x && y == p.y;}
    double x, y;
};
struct Compare {
    bool f;
    Compare(bool f = false) :f(f) {}
    bool operator()(const Point& lhs, const Point& rhs) const {return f ? lhs.y < rhs.y : lhs.x < rhs.x;}
};
double distance(const Point& lhs, const Point& rhs) {return std::hypot(lhs.x - rhs.x, lhs.y - rhs.y);}

struct Result {
    double d;
    Point p1, p2;
    Result() :d(INF) {}
    Result(double d, const Point p1, const Point p2) :d(d), p1(p1), p2(p2) {}
};
bool operator<(const Result& lhs, const Result& rhs) {return lhs.d < rhs.d;}

Result closest_pair_recursion(const std::vector<Point>::const_iterator& begin, const std::vector<Point>::const_iterator& end) {
    int size = end - begin;
    if(size <= 1) return Result();

    auto mid = begin + size / 2;
    Result r = std::min(closest_pair_recursion(begin, mid), closest_pair_recursion(mid, end));

    auto left = std::lower_bound(begin, end, Point(mid->x - r.d - EPS, mid->y), Compare());
    auto right = std::upper_bound(left, end, Point(mid->x + r.d + EPS, mid->y), Compare());
    std::vector<Point> y_sorted(left, right);
    std::sort(y_sorted.begin(), y_sorted.end(), Compare(true));

//     for(auto i = y_sorted.begin(); i != y_sorted.end(); ++i) {
//         auto top = std::upper_bound(i + 1, y_sorted.end(), Point(i->x, i->y + r.d + EPS), Compare(true));
//         for(auto j = i + 1; j != top; ++j) {
//             if(distance(*i, *j) >= r.d) continue;
//             r = Result(distance(*i, *j), *i, *j);
//         }
//     }
    for(auto i = y_sorted.begin(); i != y_sorted.end(); ++i) {
        for(auto j = i + 1; j != y_sorted.end(); ++j) {
            if(j->y - i->y >= r.d) break;
            if(distance(*i, *j) >= r.d) continue;
            r = Result(distance(*i, *j), *i, *j);
        }
    }
    return r;
}
Result closest_pair(std::vector<Point> point) {
    std::sort(point.begin(), point.end(), Compare());
    return closest_pair_recursion(point.begin(), point.end());
}

////////////////////////////////////////////////////////////////////////////////
#include<iostream>
#include<iomanip>
using namespace std;

int main() {
    int n;
    vector<Point> v;
    for(cin >> n; n > 0; --n) {
        double x, y;
        cin >> x >> y;
        v.push_back(Point(x, y));
    }
    auto res = closest_pair(v);
    cout <<setprecision(12) << fixed << res.d << endl;
}

Measured memory_bytes: 5768
#include <stdio.h>
#include <string.h>
int main()
{
  char s[100];
  scanf("%s",s);
  size_t len = strlen(s);
  int ilen = (int)len;
  int bad=0;
  for (int i = 0;i<ilen;i+=2) {
    if (s[i] == 'L') {
      bad=1;
      break;
    }
  }
  for (int i = 1;i<ilen;i+=2) {
    if (s[i] == 'R') {
      bad=1;
      break;
    }
  }
  if (bad == 1) {
    puts("No");
  } else {
    puts("Yes");
  }
  return 0;
}

Measured memory_bytes: 1660
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    ll k;
    string s;
    cin >> k >> s;
    if(k<s.size()){
        cout <<  s.substr(0,k)+"...";
    }else cout << s;
    return 0;
}


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

int main()
{
    int a,b,c,k;
    cin >> a >>b >> c >> k;
    while ( b <= a && k > 0 )
    {
        b = b*2 ;
        k--;
    }
    c = c * pow(2,k);
    
    if (  b <= a || c <= b )
        cout <<"No";
    else cout << "Yes";
    return 0;
}


Measured memory_bytes: 4024
import java.util.*
import kotlin.math.min

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    val c = sc.nextInt()
    var k = sc.nextInt()

    val useA = min(a, k)
    k -= useA
    val useB = min(b, k)
    k -= useB
    val useC = min(c, k)
    k -= useC

    println(useA - useC)
}

Measured memory_bytes: 36440
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1000000000;

int main()
{
   int n;
   cin >> n;
   cout<<(n+1)/2<<endl;
   return 0;
}

Measured memory_bytes: 256
from collections import Counter

#https://qiita.com/snow67675476/items/e87ddb9285e27ea555f8

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

N = int(input())
mod = 10**9+7
counter = Counter()
for n in range(1,N+1):
    fs = factorization(n)
    for f in fs:
        counter[f[0]] += f[1]

counts = counter.most_common()
ans = 1
for count in counts:
    if count[0] != 1:
        ans *= (count[1]+1)
        ans %= mod
print(ans)

Measured memory_bytes: 3316
N=int(input())
a=list(map(int,input().split()))
b=[0 for i in range(N)]
c=[]
A=0
B=0
for i in range(N):
    s=N//(N-i)
    p=1
    while p<=s:
      if b[(N-i)*p-1]==1:
        A+=1
      p+=1
    p=1
    if (A-a[N-1-i])%2==0:
      b[N-1-i]=0
    elif (A-a[N-1-i])%2==1:
      b[N-1-i]=1
    A=0
for i in range(N):
  if b[i]==1:
    B+=1
    c+=[i+1]
c=[c]
print(B)
print(*c[0])

Measured memory_bytes: 14140
import sys
input = sys.stdin.readline
 
H, W = [int(x) for x in input().split()]
s = []
W_count = 0
for _ in range(H):
    tmp = list(input().rstrip())
    s.append(tmp)
    W_count += tmp.count('.')

from collections import deque
D = [[-1] * W for _ in range(H)]

def bfs():
    queue = deque([(0, 0, 0, 0)])
    D[0][0] = 0
    while queue and D[-1][-1] < 0:
        u = queue.popleft()
        x = u[0]
        y = u[1]
        D[x][y] = D[u[2]][u[3]] + 1
        for i in [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]:
            if 0 <= i[0] < H and 0 <= i[1] < W and D[i[0]][i[1]] < 0 and s[i[0]][i[1]] == ".":
                queue.append((i[0], i[1], x, y))
                s[i[0]][i[1]] = "#"
    return D

D = bfs()
if D[-1][-1] == -1:
    print(-1)
    sys.exit()
print(W_count - D[-1][-1])




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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};



int main(){
  
  string s;
  cin >> s;
  if(s[0] == '9' || s[1] == '9')cout << "Yes" << endl;
  else cout << "No" << endl;
  
  


  

  return 0;
}

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

using namespace std;
int main(int argc, char* argv[])
{
	string s;
	long long K;
	cin>>s;
	cin>>K;
	int len=s.length();
	long long k=K;
	int d;
	int i=0;
	while(i<len){
		if (s[i]!='a'){
			d = 'z'-s[i]+1;
			if (d<=k){
				s[i]='a';
				k -= d;
			}
		}
		i++;			
	}
	s[len-1] = s[len-1]+k%26;
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cmath>
using namespace std;
int main() {
	int n, d;
	cin >> n >> d;
	d = d * 2 + 1;
	if (n / d <= 0) {
		cout << 1 << endl;
		return 0;
	}
	if (n % d == 0) {
		cout << n / d << endl;
		return 0;
	}
	else {
		n = n + d;
		cout << n / d << endl;
		return 0;
	}
}

Measured memory_bytes: 256
import re

N,K = map(int, input().split())
S = str(input())
s1 = list(S)
right = 0
count_0 = 0
ans = 0

for left in range(N):
  while right<N and count_0 <=K:
    if s1[0] == "0" and right == 0:
      count_0 += 1
    elif s1[right] == "0" and s1[right-1] == "1":
      count_0 += 1
    right += 1
    
    if count_0 <= K:
      #print(right,left,count_0)
      ans = max(ans, right-left)
  if left != N-1:
    if s1[left] == "0" and s1[left+1] =="1":
      count_0 -= 1
    
print(ans)


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

int main() {
  int a,b,c,d;
  cin >>a>>b>>c>>d;
  if((a+b)>(c+d)){
    cout << "Left" << endl;
  }
  if((a+b)==(c+d)){
    cout << "Balanced" << endl;
  }
  if((a+b)<(c+d)){
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
// ░░░░░░░▄▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▄░░░░░░
// ░░░░░░█░░▄▀▀▀▀▀▀▀▀▀▀▀▀▀▄░░█░░░░░
// ░░░░░░█░█░▀░░░░░▀░░▀░░░░█░█░░░░░
// ░░░░░░█░█░░░░░░░░▄▀▀▄░▀░█░█▄▀▀▄░
// █▀▀█▄░█░█░░▀░░░░░█░░░▀▄▄█▄▀░░░█░
// ▀▄▄░▀██░█▄░▀░░░▄▄▀░░░░░░░░░░░░▀▄
// ░░▀█▄▄█░█░░░░▄░░█░░░▄█░░░▄░▄█░░█
// ░░░░░▀█░▀▄▀░░░░░█░██░▄░░▄░░▄░███
// ░░░░░▄█▄░░▀▀▀▀▀▀▀▀▄░░▀▀▀▀▀▀▀░▄▀░
// ░░░░█░░▄█▀█▀▀█▀▀▀▀▀▀█▀▀█▀█▀▀█░░░
// ░░░░▀▀▀▀░░▀▀▀░░░░░░░░▀▀▀░░▀▀░░░░
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
int main(int argc, char const *argv[])
{
	ll n;cin >> n;
	ll ans =1e18;
	for(ll i=1;i*i<=n;i++)
	{
		if(n%i==0)
		ans=min(ans,i+n/i);
	}cout <<ans-2;
	return 0;
}

Measured memory_bytes: 256
N=int(input())
A=[int(i) for i in input().split()]
flag=1
for i in range(N):
    if A[i]%2==0:
        if A[i]%3==0 or A[i]%5==0:
            pass
        else:
            flag=0
            break
if flag==0:
    print("DENIED")
else:
    print("APPROVED")


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int r; cin >> r;
  cout << 3 * r * r << '\n';
}

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

using namespace std;

#define int long long

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

int P[100010], A[100010], B[100010], C[100010];
int imos[100010];

signed main()
{
    int N, M; cin >> N >> M;

    rep(i, M) {
        cin >> P[i];
    }

    rep(i, N - 1) {
        cin >> A[i] >> B[i] >> C[i];
    }

    rep(i, M - 1) {
        if (P[i] < P[i + 1]) {
            imos[P[i]]++;
            imos[P[i + 1]]--;
        } else {
            imos[P[i + 1]]++;
            imos[P[i]]--;
        }
    }

    rep(i, N) imos[i + 1] += imos[i];

    int ans = 0;

    rep(i, N) {
        ans += min(A[i] * imos[i + 1], C[i] + B[i] * imos[i + 1]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 6944
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A[] = new int[N];
        for (int i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        int ans = 0;
        for (int i = 0;i<N;i++){
            if(A[A[i]-1] == i+1){
                ans++;
            }
        }
        System.out.println(ans/2);
    }
}

Measured memory_bytes: 51868
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
    int N;cin >> N;
    ll ans = 0LL;
    for (int i = 0; i < N; ++i) {
        ll a; cin >> a;
        ans += a - 1LL;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
/*************************************************\
           In the name of almighty ALLAH
                 MD.Faysal Hasan
                Comilla Univesity
\*************************************************/

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

#define     ikarus_101  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef     long long             ll;
typedef     long double           ld;
typedef     unsigned long long    ull;
typedef     vector<ll>            vll;
typedef     pair<ll,ll>           pll;
typedef     vector<pll>           vpl;
typedef     map<ll,ll>            mll;
typedef     multiset<ll>          msl;
typedef     multimap<ll,ll>       Mll;
using pqboro=priority_queue<ll,vll,less<ll>>;
using pqchoto=priority_queue<ll,vll,greater<ll>>;

#define    all(str)       str.begin(),str.end()
#define    sajo(str)      sort(str.begin(),str.end())
#define    rev(str)       reverse(str.begin(),str.end())
#define    usajo(str)     sort(str.rbegin(),str.rend())
#define    vin(a)         for(auto &it : a) cin>>it
#define    vout(a)        for(auto it:a) cout<<it<<' ';cout<<nn
#define    pb             push_back
#define    eb             emplace_back
#define    mkp(x,y)       make_pair(x,y)
#define    F              first
#define    S              second
#define    yes            cout<<"YES"<<nn
#define    no             cout<<"NO"<<nn
#define    nn             "\n" ///endl
#define    rep(i,n)       for (i=0;i<n;++i )
#define    rep1(i,n)      for (i=1;i<=n;++i )

#define    min3(a,b,c)    min(a,min(b,c))
#define    max3(a,b,c)    max(a,max(b,c))
#define    sqr(x)         ((x)*(x))
#define    pi             2*acos(0.0)
#define    gcd(a,b)       __gcd(a,b)
#define    lcm(a,b)       (a/gcd(a,b))*b
#define    mem(a,b)       memset(a,b,sizeof (a))
#define    dec(x)         cout<<fixed<<setprecision(x)
#define    none(n)         __builtin_popcountll(n)

template < typename T > string toString ( T Number ) { stringstream ss ; ss << Number ; return ss.str() ; }
template < typename T > ll toll ( T str ) { stringstream ss ; ss << str ; ll num ; ss >> num ; return num ; }
ll power(ll n , ll k) { if(k == 0) return 1 ; if(k&1) return n*sqr(power(n,k/2)) ; else return sqr(power(n,k/2)); }

const   int  N   =   2e5+7;
const   int  M   =   1e9+7;
const   ll  inf  =   0x7f7f7f7f7f7f7f7f;
const   int dx[] =   {+1,+2,+2,+1,-1,-2,-2,-1};
const   int dy[] =   {-2,-1,+1,+2,+2,+1,-1,-2};

int main() {ikarus_101

    ll n,m,i,j,k,x;

    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout << max( a*b , c*d ) << endl;
























    return 0;
}


Measured memory_bytes: 3632
N = int(input())

S = input()

count = 0
count_list = []
for i in range(N):
    if S[i]=="(":
        count-=1
    if S[i]==")":
        count+=1
    count_list.append(count)

mr=max(count_list)

count = 0
count_list = []
for i in range(N):
    if S[N-i-1]=="(":
        count+=1
    if S[N-i-1]==")":
        count-=1
    count_list.append(count)


ml=max(count_list)

for _ in range(ml):
    S+=")"
for _ in range(mr):
    S="(" + S
    
print(S)

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


set<ll> prime_factor(ll n) {
  set<ll> ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret.insert(i);
      n /= i;
    }
  }
  if(n != 1) ret.insert(n);
  return ret;
}

ll disjoint_set_of_common_divisors(ll a, ll b) {
  set<ll> aa = prime_factor(a);
  set<ll> bb = prime_factor(b);
  set<ll> merged;
  set_intersection(aa.begin(), aa.end(), bb.begin(), bb.end(), inserter(merged, merged.end()));
  return merged.size() + 1;
}

int main() {
  ll a, b;
  cin >> a >> b;
  cout << disjoint_set_of_common_divisors(a, b);
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <istream>
#include <ostream>

#include <cstdlib>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i,n) for(ll i=0; i < (n); ++i)
#define rrep(i,n) for(ll i=((n)-1); i >= 0; --i)

#define OPLT(T) bool operator<(const T & lop_, const T & rop_)
#define OPEQ(T) bool operator==(const T & lop_, const T & rop_)

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

istream& operator>>(istream& istr, __float128& obj) { double d; istr >> d; obj = d; return istr; };
ostream& operator<<(ostream& ostr, __float128& obj) { ostr << static_cast<double>(obj); return ostr; };

bool dp[100100];

int main() {
	dp[0] = true;
	int N;cin >> N;
	rep(i,N) {
		int s;
		cin >> s;
		for(int j = 100000; j >= 0; j--) {
			if(j-s >= 0 && dp[j-s])
				dp[j] = true;
		}
	}
	int res = 0;
	for(int j = 100000; j >= 0; j--) {
		if(dp[j] && j % 10) {
			res = j;
			break;
		}
	}
	cout << res << endl;
	return 0;
}


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

int main() {
    string s,t;
    cin>>s;
    int n,ans=0;
    cin>>n;
    while(n--) {
        cin>>t;
        t += t;
        for(int i=0; i<t.length()-s.length(); ++i) {
            if(t.substr(i,s.length()) == s) {
                ans++;
                goto NEXT;
            }
        }
    NEXT:;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 0
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    m = [tuple(input().split()) for _ in range(n)]
    btc_to_jpy = 380000
    ans = 0
    for price, kind in m:
        if kind == 'JPY':
            ans += int(price)
        else:
            ans += btc_to_jpy * float(price)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9088
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)

print(ans)

Measured memory_bytes: 47376
// 02/01/29 // 4:25 AM //
// O(n)

#include <iostream>

using namespace std;

#define MAXN 100010

int n;
int value[MAXN][10];
int memo[5][5];

int solve(){  // ant = 0, 1, 2


    for(int i=1; i<=n; i++)
        for(int k=0; k<3; k++)
            for(int j=0; j<3; j++)
                if(j!=k)
                   memo[i&1][k] = max(memo[i&1][k], memo[~i&1][j] + value[i][k]);


    return max(memo[n&1][0], max(memo[n&1][1], memo[n&1][2]));
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;

    for(int i=1; i<=n; i++)
        cin >> value[i][0] >> value[i][1] >> value[i][2];

    cout << solve() << "\n";

    return 0;
}



Measured memory_bytes: 4224
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);    
    int N; cin >> N;
    
    int M; cin >> M;
    
    ll P; cin >> P;
    vector<vpl > graph(N);
    vector<vi > graph2(N);
    F0R(i, M) {
		int A, B, C; cin >> A >> B >> C; A--; B--; C-=P;
		graph[A].pb(mp(B, C)); 
		graph2[B].pb(A);
	}
	
	bool foundEnd[N]; F0R(i, N) foundEnd[i] = false;
	queue<int> q;
	q.push(N-1);
	foundEnd[N-1] = true;
	while (!q.empty()) {
		int cur = q.front(); q.pop();
		F0R(i, sz(graph2[cur])) {
			int nxt = graph2[cur][i];
			if (!foundEnd[nxt]) {
				foundEnd[nxt] = true;
				q.push(nxt);
			}
		}
	}
	
	ll dist[N];
	F0R(i, N) {
		dist[i] = -1000000000000;
	}
	dist[0] = 0;
	
	bool found[N]; F0R(i, N) found[i] = false;
	
	found[0] = true;
	
	F0R(i, N) {
		F0R(j, N) {
			if (dist[j] == -1000000000000) continue;
			F0R(k, sz(graph[j])) {
				int nxt = graph[j][k].f;
				found[nxt] = true;
				if (dist[nxt] < dist[j] + graph[j][k].s) {
					dist[nxt] = dist[j]+graph[j][k].s;
				}
			
			}
		}
	}
	
	/*F0R(i, N) {
		cout << dist[i] << " ";
	} cout << endl;*/
	
	F0R(i, N) {
		F0R(j, sz(graph[i])) {
		
			int k = graph[i][j].f;
			if (dist[k] == -1000000000000 || dist[i] == -1000000000000) continue;
			if (dist[k] < dist[i] + graph[i][j].s && foundEnd[k]) {
				cout << -1 << endl; return 0;
			}
		}
	}
	
	cout << max(0LL, dist[N-1]) << endl;
	
    return 0;
}

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

/*define*/
double N;
double t_sum, f_sum, b_sum, fb_sum;

int main(){
    /*inpus*/
    std::cin >> N;

    /*syori*/
    t_sum = (N+1)*N/2;
    f_sum = floor(N/3)*(3 + floor(N/3)*3)/2;
    b_sum = floor(N/5)*(5 + floor(N/5)*5)/2;
    fb_sum = floor(N/15)*(15 + floor(N/15)*15)/2;
    t_sum = t_sum - f_sum - b_sum + fb_sum;
    std::cout << (int64_t)t_sum;
}    


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

static const int AMAX = 100000;
int64_t cnt[AMAX + 1];

int main(void){
    int n;
    int64_t k;
    cin >> n >> k;

    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        cnt[a] += b;
    }
    
    for (int ans = 1; ans <= AMAX; ans++) {
        if (k <= cnt[ans]) {
            cout << ans << "\n";
            break;
        }
        k -= cnt[ans];
    }
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define int long long

signed main(){
    int n, k;
    cin >> n >> k;
    long double ans = 0;
    reps(i,1,n){
        long double chance = 1.0/n;
        int p = i;
        while(p < k){
            p *= 2;
            chance *= 0.5;
        }
        ans += chance;
    }
    printf("%.12Lf\n",ans);
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        System.out.println(Math.max(Math.max(Math.abs(a-b), Math.abs(b-c)), Math.abs(a-c)));
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
using namespace std;
int main() {
    int i,j,n,a,b,c,x;
    int flag=0;
    int count=0;
    int sum=0;
    int souwa=0;
    int temp;
    cin>>n>>a>>b;
    for(i=0; i<=n; ++i){
        temp=i;
        do{
          sum=sum+(temp%10);
          temp=temp/10;
        }while(temp!=0);
        if(sum>=a&&sum<=b){souwa=souwa+i;}
        sum=0;
    }
cout<<souwa;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
print(*A)

for i in range(1,N):
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    print(*A)


Measured memory_bytes: 5980
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
using namespace std;
int main(){
    int cnt =0;
    string S;
    cin >> S;
    int min,max;
    int size = S.size();
    REP(i,size){
        if(S[i]=='A'){
            min = i;
            break;
        }
    }
    for(int i=size;i>0;i--){
        if(S[i]=='Z'){
            max=i;
            break;
        }
    }

    cout << max-min+1 << endl;
}

Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<pair<int, int>> as(N);
  F0R(i, N) {
    as[i].first = i;
    cin >> as[i].second;
  }
  sort(rng(as), [](const pair<int, int>& l, const pair<int, int>& r) {
    return l.second < r.second;
    });

  F0R(i, N) {
    cout << (as[i].first + 1) << ' ';
  }
}
#endif


Measured memory_bytes: 1664
# import math
# import decimal
# import queue
# import bisect
# import heapq
# import time
# import itertools

mod = int(1e9+7)

def main():
    h,n = map(int,input().split())
    a = [0] * n
    b = [0] * n
    for i in range(n):
        a[i],b[i] = map(int,input().split())
    dp = [int(1e9)] * (h + max(a) + 10)
    dp[0] = 0
    for i in range(n):
        for j in range(1,h+max(a)):
            if a[i] <= j:
                dp[j] = min(dp[j - a[i]] + b[i],dp[j])
    ans = int(1e9)
    for i in range(h,h+max(a)):
        ans = min(ans,dp[i])
    print(ans)
    return

if __name__=='__main__':
    main()

Measured memory_bytes: 41692
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))

int main() {

	int M, D;
	scanf("%d %d", &M, &D);
	int count = 0;
	for (int m = 4; m <= M; m++) {
		for (int d = 22; d <= D; d++) {
			if (d % 10 > 1 && d / 10 > 1) {
				int multi = (d % 10) * (d / 10);
				if (multi == m)count++;
			}
		}
	}
	printf("%d", count);
	return 0;
}

Measured memory_bytes: 128
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    A, B, C = map(int, input().split())
    if (A==B and B==C) or (A!=B and B!=C and C!=A):
        print("No")
    else:
        print("Yes")


if __name__ == '__main__':
    main()

Measured memory_bytes: 66028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
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 long long INF = 1LL << 60;

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

    int cnt=0;
    REP(n, 999+1){
        int c[3]={n/100, (n/10)%10, n%10};
        int f=0;
        REP(i, N){
            if(S[i]==c[f]+'0') f++;
            if(f==3) break;
        }
        if(f==3) cnt++;
    }

    cout << cnt << endl;   

    return 0;
}

Measured memory_bytes: 256
using System;

namespace ITP1_5_B
{
    class Program
    {
        static void Main(string[] args)
        {
            while(true)
            {
                string str = Console.ReadLine();
                string[] parseStr = str.Split((char[])null);
                int H, W;
                H = int.Parse(parseStr[0]);
                W = int.Parse(parseStr[1]);
                if (H == 0 && W == 0)
                    Environment.Exit(0);

                string[,] square = new string[H, W];

                for (int i = 0; i < H; i++)
                {              
                    for (int j = 0; j < W; j++)
                    {
                        if (i == 0 || j == 0 || i == H - 1 || j == W - 1)
                            Console.Write("#");
                        else
                            Console.Write(".");
                    }
                    Console.Write("\n");
                }
                Console.Write("\n");
            }
        }
    }
}


Measured memory_bytes: 14208
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <utility>
#include <climits>
#include <iomanip>
using namespace std;
#define MAXSIZE 100005
#define MAXL 100
#define MOD 998244353
typedef long long int lli;

int main(){
    int r;
    cin >> r;
    cout << r * r << endl;
    return 0;
}

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

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

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

int main(void){

    string a, b;
    cin >> a >> b;

    b.pop_back();

    if(a == b) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<deque>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
using ll=long long;

int n,m;

ll gcl(ll x,ll y){
    if(x<y) swap(x,y);
    while(y>0){
        ll t=x%y;
        x=y;
        y=t;
    }
    return x;
}

int main(){
    cin>>n;
    deque<int> b;
    int reverse=1;
    rep(i,0,n){
        int a;cin>>a;
        if(reverse==1) b.push_back(a);
        else b.push_front(a);
        reverse*=(-1);
    }

    if(reverse==1){
        rep(i,0,b.size()) cout<<b[i]<<' ';
    }else{
        rep(i,0,b.size()) cout<<b[b.size()-1-i]<<' ';
    }
}

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

using namespace std;

#define vit vector<int>::iterator
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fr first
#define sc second
#define skip continue
#define PI 3.14159265

typedef unsigned long long ull;
typedef long long ll;
typedef unsigned int ui;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const ll MAXN = 3e5 + 3;
const int  M   =   1e9+7;

void faster(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

bool cmp(const string& a, const string& b) {
    return (a + b) < (b + a);
}

void solve(){
    int n, a, b;
    cin >> n >> a >> b;
    ll arr[n], cnt = 0;
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    for(int i = 1; i < n; i++){
        if((arr[i] - arr[i-1]) * a >= b) cnt += b;
        else cnt += (arr[i] - arr[i-1]) * a;
    }
    cout << cnt;
}


int main(){
    //freopen("slalom.in","r",stdin);
    //freopen("slalom.out","w",stdout);
    //faster();
    int n = 1;
    //cin >> n;
    while(n--){
        solve();
        cout << endl;
    }
    //fclose(stdout);
}


Measured memory_bytes: 4380
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define F(i,a,n) for(int i=a; i<n; i++)

int main(){
    int tmp,n;
    scanf("%d",&n);
    int sum=0;
    F(i,0,n){
        scanf("%d",&tmp);
        sum+=tmp-1;
    }
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD (ll) (1e9+7)
int main()
{




 string a,b;
 cin>>a>>b;
 int cnt=0;
 for(int i=0;i<min(a.size(),b.size());i++)
 {

     if(a[i]!=b[i])
     {

         cnt++;
     }
 }
 cout<<cnt<<endl;


}


Measured memory_bytes: 3920
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define FAST ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int32_t main(){ 
    FAST
    int l,r,d;cin>>l>>r>>d;
    int ans=r/d;
    ans-=((l-1)/d);
    cout<<ans<<"\n";

    return 0;
}

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

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

int main() {
    ll n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;
    ll p = lcm(n, m);
    vector<ll> s_index;
    vector<ll> t_index;
    for (ll i = 0; i < n; i+=p/m) {
        s_index.push_back(i);
    }
    for (int i = 0; i < m; i+=p/n) {
        t_index.push_back(i);
    }
    bool ok = true;
    rep(i,s_index.size()) {
        if (s[s_index[i]] != t[t_index[i]]) {
            ok = false;
        }
    }
    ll ans;
    if (ok) ans = p;
    else ans = -1;
    cout << ans << endl;
}

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

int opts[] = {111,222,333,444,555,666,777,888,999};

int main(void){
	int n;
	cin>>n;
	for(int i = 0; ;i++){
		if(opts[i] >= n) {
			cout<<opts[i]<<'\n';
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 256