akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;
using Q = std::tuple<int,int,int>;

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

std::vector<P> X, Y;
priority_queue<Q, std::vector<Q>, std::greater<Q>> pq;

template <int n>
struct UnionFind{
    UnionFind(){
        for(int i=0;i<n;i++){
            par[i] = i;
            rank[i] = 0;
        }
    }
    int find(int x){
        if(x == par[x])return x;
        return par[x] = find(par[x]);
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y){return;}
        
        if(rank[x] > rank[y]){
            par[y] = x;
        }else{
            par[x] = y;
            if(rank[x] == rank[y]){rank[y]++;}
        }
    }
    int rank[n], par[n];
};

UnionFind<100100> uf;

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

    int N;
    std::cin >> N;

    for(int i=0;i<N;++i){
        int x, y;
        std::cin >> x >> y;
        
        X.emplace_back(x, i);
        Y.emplace_back(y, i);
    }

    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());

    for(int i=0;i+1<X.size();++i){
        int v, a, v2, b;
        tie(v, a) = X[i];
        tie(v2, b) = X[i+1];
        pq.emplace(v2 - v, a, b);
    }

    for(int i=0;i+1<Y.size();++i){
        int v, a, v2, b;
        tie(v, a) = Y[i];
        tie(v2, b) = Y[i+1];
        pq.emplace(v2 - v, a, b);
    }

    ll res = 0ll;
    while(!pq.empty()){
        int cost, a, b;
        tie(cost, a, b) = pq.top();
        pq.pop();

        // std::cout << cost << ", " << a << ", " << b << std::endl;

        if(uf.same(a, b)){continue;}

        res += cost;
        uf.unite(a, b);
    }

    std::cout << res << std::endl;
}


Measured memory_bytes: 7912
n=gets.chomp.to_i
list=gets.chomp.split.map(&:to_i);
i=0
max=list[i]
bool="Yes"
while i < n-1 do
  if list[i] > list[i+1] 
    if list[i]-1 > list[i+1]
      bool="No"
    else
      if max < list[i]-1
       max=list[i]-1
      end
    end
  else
    if max < list[i]-1
      max=list[i]-1
    end
  end
  if max > list[i+1]
    bool="No"
  end
      
  i+=1
end

puts "#{bool}"


Measured memory_bytes: 12036
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    map<int, int> mp;
    rep(i, n) {
        int a;
        cin >> a;
        mp[a]++;
    }

    int res = 0;
    int num = 0;
    for (auto m : mp) {
        if (m.second % 2 == 1) res++;
        else {
            num++;
        }
    }

    if (num % 2 == 1) --res;

    cout << res + num << endl;

    return 0;
}

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

public class Main {
	static final int hashA = 97;
	static final int hashPeriod = 46;
	void run() throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		String[] alphabet = "abcdefghijklmnopqrstuvwxyz".split("");
		int[] cntAlpha = new int[alphabet.length];
		String txt = br.readLine();
		while( txt != null && ! "".equals(txt) ){
			for (int i = 0;i < txt.length();i++){
				txt = txt.toLowerCase();
				char ch = txt.charAt(i);
				int hash = String.valueOf(ch).hashCode();
				if(hash >= hashA && hash < hashA + alphabet.length){
					cntAlpha[hash - hashA]++;
				}
			}
			txt = br.readLine();
		}
		for(int i = 0;i < alphabet.length;i++){
			System.out.println(alphabet[i] + " : " + cntAlpha[i]);
		}
	}
	public static void main(String args[]) throws IOException{
		new Main().run();
	}
}

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

#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433L;

template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
std::vector<std::string> split(const std::string &str, const char delemiter) {std::vector<std::string> res;std::stringstream ss(str);std::string buffer; while( std::getline(ss, buffer, delemiter) ) res.push_back(buffer); return res;}
int msb(int x) {return x?31-__builtin_clz(x):-1;}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    ll K; cin >> K;
    ll x=7;
    for(int i = 1; i <= K; ++i){
        corner(x%K==0,i);
        x=(x*10+7)%K;
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
    int a,b,c,x,y;
    scanf("%d%d%d%d%d", &a,&b,&c,&x,&y);
    int combine = x > y ? y : x;
    int comb_cst = (a+b) < (2*c) ? (a+b) : (2*c);
    int cst = combine * comb_cst;
    if (combine == x ){
        int t = 2*c > b ? b : 2*c;
        cst+= (y-combine) * t;
    }
    else {
        int t = 2*c > a ? a : 2*c;
        cst += (x - combine) * t;
    }
    printf("%d\n", cst);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono; 
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> > 
#define pb push_back
#define f first
// #define s second
#define int long long
#define float long double
#define all(c) (c).begin(), (c).end()
#define endl '\n'



int32_t main()
{
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     cout.tie(0);
   	
//     int t;
//      cin >> t;

//      while(t--){



// }
     int a,b;
     cin >> a >> b;
     cout << a*b << endl;



return 0;
}




Measured memory_bytes: 3616
package main

import (
        "fmt"
)

func solution(s string) string {
        if s[0] != 'A' {
                return "WA"
        }

        c := 0
        for _, r := range s[2 : len(s)-1] {
                if r == 'C' {
                        c++
                }
        }
        if c != 1 {
                return "WA"
        }

        for i := range s {
                if s[i] == 'A' || s[i] == 'C' {
                        continue
                }
                if s[i]-'a' < 0 || 26 < s[i]-'a' {
                        return "WA"
                }
        }

        return "AC"
}

func main() {
        var s string
        fmt.Scan(&s)
        fmt.Println(solution(s))
}

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

using namespace std;

int A[15][15], C[15], U[15], B[15][15];
int n, m, x;

int mincost = 9999999;
bool done;
bool found = false;

void takeOrLeave(int book, int cost) {
	if (book > n) return;
	takeOrLeave(book + 1, cost);
	cost += C[book];
	for (int i = 1; i <= m; ++i) {
		B[book][i] = U[i];
		if (U[i] < x) {
			U[i] += A[book][i];
		}
	}
	takeOrLeave(book + 1, cost);
	done = true;
	for (int i = 1; i <= m; ++i) {
		if (U[i] < x) {
			done = false;
			break;
		}
	}
	if (done) {
		found = true;
		mincost = min(mincost, cost);
	}
	for (int i = 1; i <= m; ++i) {
		U[i] = B[book][i];
	}
	cost -= C[book];
}

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	cin >> n >> m >> x;
	int cost = 0;
	for (int i = 1; i <= n; ++i) {
		cin >> C[i];
		for (int j = 1; j <=m; ++j) {
			cin >> A[i][j];
		}
	}
	takeOrLeave(1, 0);
	if (found) cout << mincost << '\n';
	else cout << -1 << '\n';
	return 0;
}

Measured memory_bytes: 3624
// This file is a "Hello, world!" in C++ language by GCC for wandbox.#include <stdio.h>
#include <stdio.h>
int main(){
    int n;
    scanf("%d¥n", &n);
    
    if(n>=111 && n<= 999){
        if(n%10 == 1){
            n+=8;
        } else {
            n-=8;
        }
        
        if(n/10%10 == 1){
            n+=80;
        } else {
            n-=80;
        }
        
        if(n/100%10 == 1){
            n+=800;
        } else {
            n-=800;
        }
        
    }
    printf("%d", n);
    return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios::sync_with_stdio(false); cin.tie(NULL);
#ifndef LOCAL
#define dbg(...) ;
#define endl '\n'
#endif

const int inf = 1e15;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;

int a[11];
int n, m, q;
pair<pii, pii> p[55];
int ans = 0;

void solve(int prev, int pos) {
    if (pos == n + 1) {
        int c = 0;
        for (int i = 0; i < q; i++) {
            if (a[p[i].fi.se] - a[p[i].fi.fi] == p[i].se.fi) c += p[i].se.se;
        }
        ans = max(ans, c);
        return;
    }
    for (int i = prev; i <= m; i++) {
        a[pos] = i;
        solve(i, pos + 1);
    }
}

signed main(){
    IOS;
    cin >> n >> m >> q;
    for (int i = 0; i < q; i++) {
        cin >> p[i].fi.fi >> p[i].fi.se >> p[i].se.fi >> p[i].se.se;
    }
    solve(1, 1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = INF+7;
const ll LINF = 1e18;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define rrep(i,N) for(int (i)=(N-1);(i)>0;--i)
#define FOR(i,j,N) for(int (i)=(j);(i)<(N);++(i))
#define put(n) cout<<(n)<<endl;
#define VI vector<int>
#define VII vector<vector<int>>
#define all(v) (v.begin(),v.end())
#define MP make_pair
#define pb(n) push_back(n)


int main(){
    int N,C;
    cin>>N>>C;
    cout<<N*C<<endl;
}


Measured memory_bytes: 3100
import sys
 
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
mod = pow(10, 9)+7
zero = 0
plus = []
minus = []
for i in range(n):
  if a[i] == 0:
    zero += 1
  elif a[i] > 0:
    plus.append(a[i])
  else:
    minus.append(a[i])
 
P, M = len(plus), len(minus)
plus.sort(reverse=True)
minus.sort()
ans = 1
if n == k:
  for i in range(n):
    ans *= a[i]
    ans %= mod
elif P+M < k:
  ans = 0
elif P == 0 and k%2 ==1 :
  if zero >= 1:
    ans = 0
  else:
    minus.sort(reverse=True)
    for i in range(k):
      ans *= minus[i]
      ans %= mod
else:
  q = 0
  if k%2:
    ans *= plus[0]
    ans %= mod
    q = 1
  judge = []
  for i in range((len(plus)-q)//2):
    judge.append(plus[2*i+q]*plus[2*i+q+1])
  for i in range(len(minus)//2):
    judge.append(minus[2*i]*minus[2*i+1])
  judge.sort(reverse=True)
  for i in range(k//2):
    ans *= (judge[i]%mod)
    ans %= mod
 
print(ans)

Measured memory_bytes: 31604
#include <bits/stdc++.h>
using namespace std;
char sir[105];
int main()
{
    int i, n;
    cin>>sir;
    n=strlen(sir);
    i=0;
    while((i<n)&&(sir[i]!='C')) i++;
    if(i<n){
        //am gasit C
        while((i<n)&&(sir[i]!='F')) i++;
        if(i<n) cout<<"Yes";
        else cout<<"No";
    }
    else cout<<"No";
    return 0;
}


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

using namespace std;

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

typedef long long int ll;

int main(){
    int n;
    cin >> n;
    int a[100][100] = {0};
    rep(i,n){
        rep(k,n){
            scanf("%d",&a[k][i]);
        }
    }

    ll sum[100][100] = {0};
    rep(i,n){
        sum[0][i] = a[0][i];
        reep(k,1,n){
            sum[k][i] += sum[k-1][i] + a[k][i];
        }
    }

    rep(i,n){
        reep(k,1,n){
            sum[i][k] += sum[i][k-1];
        }
    }

    /*rep(i,n){
        rep(k,n){
            printf("%3d",sum[k][i]);
        }
        puts("");
    }*/

    ll ans = -10000000000000;
    rep(lx,n){
        rep(ty,n){
            reep(rx,lx,n){
                reep(uy,ty,n){
                    ll cou;
                    if(rx==lx){
                        if(ty==uy){
                            cou = sum[rx][uy];
                        }else{
                            cou = sum[rx][uy]-sum[rx][ty];
                        }
                    }else{
                        if(ty==uy){
                            cou = sum[rx][uy] - sum[lx][uy];
                        }else{
                            cou = (sum[rx][uy]-sum[rx][ty])-(sum[lx][uy]-sum[lx][ty]);
                        }
                    }
                    ans = max(cou,ans);
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1364
n = int(input())
a = list(map(int,input().split()))
for i in range(1,n):
    a[i] += a[i-1]
a_1 = a.copy()
ans = 0
k = 0
for i in range(n):
    if i%2==0 and a_1[i]+k<=0:
        tmp = -a_1[i]-k+1
        k += tmp
        ans += abs(tmp)
    elif i%2==1 and a_1[i]+k>=0:
        tmp = -a_1[i]-k-1
        k += tmp
        ans += abs(tmp)
ans_2 = 0
k = 0
for i in range(n):
    if i%2==1 and a[i]+k<=0:
        tmp = -a[i]-k+1
        k += tmp
        ans_2 += abs(tmp)
    elif i%2==0 and a[i]+k>=0:
        tmp = -a[i]-k-1
        k += tmp
        ans_2 += abs(tmp)
print(min(ans,ans_2))

Measured memory_bytes: 14212
import java.util.Scanner;

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

    private static final int DIVVAL = 1000000007;

    public Main() {
    }

    public void exec(String args[]) throws Exception {
    	//初期化読み込み
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	sc.nextLine();
    	String sT = sc.nextLine();
    	String sA = sc.nextLine();
    	boolean wrong = false;
    	int[] T = parseStringInt(sT, ' ', N);
    	int[] A = parseStringInt(sA, ' ', N);
    	int[] ans = new int[N];
    	int preval=0;
    	for(int i=0; i<T.length; i++) {
    		if(preval < T[i]) {
    			ans[i] = 1;
    			preval=T[i];
    		}else{
    			ans[i] = T[i];
    		}
    	}
    	preval=0;
    	for(int i=A.length - 1; i>=0; i--) {
    		if(preval < A[i]) {
    			if(ans[i] == 1 && T[i] != A[i]) {
    				wrong = true;
    				break;
    			}
    			if(ans[i] != 1 && ans[i] < A[i]) {
    				wrong = true;
    				break;
    			}
    			ans[i] = 1;
    			preval=A[i];
    		}else{
    			if(ans[i] == 1 && T[i] > A[i]) {
    				wrong = true;
    				break;
    			}
    			if(ans[i] != 1 && ans[i] > A[i]) {
        			ans[i] = A[i];
    			}
    		}
    	}
    	long ansval = 1;
    	if(!wrong) {
    		for(int i=0; i<ans.length; i++) {
    			if(ans[i]==1) continue;
    			ansval = (ansval * ans[i]) % DIVVAL;
    		}
    	}else{
    		ansval=0;
    	}
    	System.out.println(ansval);
	}


    public int[] parseStringInt(String s, char delim, int size) {
    	int[] ia = new int[size];
    	char[] ca = s.toCharArray();
    	int intval= 0;
    	for(int ii=0, ci=0; ci<ca.length && ii<size; ci++){
    		if(ca[ci]==delim) {
    			ia[ii] = intval;
    			ii++;
    			intval=0;
    		}else if ('0' <= ca[ci] && ca[ci] <= '9'){
    			intval = intval*10 + (ca[ci] - '0');
    		}
    	}
    	ia[size-1]=intval;
    	return ia;
    }
}

Measured memory_bytes: 38308
import java.util.Scanner;

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

	int W, H, x, y;
	W = sc.nextInt();
	H = sc.nextInt();
	x = sc.nextInt();
	y = sc.nextInt();

	int judge;
	if (x + x == W && y + y == H)
	    judge = 1;
	else
	    judge = 0;

	System.out.println((double)(((double)W * (double)H) / 2) + " " + judge);
    }
}

Measured memory_bytes: 22740
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))
n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(k, n):
    if a[i] > a[i - k]:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 33124
H,W,A,B = map(int,input().split(" "))
if H//2 < B or W//2 < A:
  print("No")
else:
  s = "0" * A + "1" * (W - A) 
  for i in range(B):
    print(s)
  s = list(s)
  
  for i in range(len(s)):
    if s[i] == "1":
      s[i] = "0"
    elif s[i] == "0":
      s[i] = "1"
  s = "".join(s)
  for i in range(B,H):
    print(s)
    

Measured memory_bytes: 4084
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <limits>
#include <functional>

using Pair = std::pair<int, int>;

struct Node {
	std::vector<Pair> edges;

	int minCost = std::numeric_limits<int>::max();
	bool done;
};

int main() {
	int n, k;

	while (std::cin >> n >> k, n + k != 0) {
		std::vector<Node> nodes(n);
		for (int i = 0; i < k; ++i) {
			int req;
			std::cin >> req;

			if (req == 1) {
				int c, d, e;
				std::cin >> c >> d >> e;

				nodes[c - 1].edges.push_back({ d - 1, e });
				nodes[d - 1].edges.push_back({ c - 1, e });
			}
			else {
				int a, b;
				std::cin >> a >> b;
				// first: cost, second: node
				std::priority_queue<Pair, std::vector<Pair>, std::greater<Pair>> que;
				que.push({ 0, a - 1 });

				while (!que.empty()) {
					const auto top = que.top();
					
					if (top.second == b - 1) {
						std::cout << top.first << std::endl;
						break;
					}

					que.pop();

					auto& now = nodes[top.second];
					if (now.done)
						continue;

					now.minCost = top.first;
					now.done = true;

					for (auto&& edge : now.edges)
						if (nodes[edge.first].done == false && nodes[edge.first].minCost > top.first + edge.second)
							que.push({ top.first + edge.second, edge.first });
				}

				if (que.empty())
					std::cout << -1 << std::endl;

				for (auto&& n : nodes) {
					n.done = false;
					n.minCost = std::numeric_limits<int>::max();
				}
			}
		}
	}
}

Measured memory_bytes: 3072
// Package main provides
//
// File:  c.go
// Author: ymiyamoto
//
// Created on Sat Jan 19 13:52:07 2019
//
package main

import (
	"fmt"
	"sort"
)

type pair struct {
	x, y int
}

type pairs []pair

func (ps pairs) Len() int {
	return len(ps)
}

func (ps pairs) Swap(i, j int) {
	ps[i], ps[j] = ps[j], ps[i]
}

func (ps pairs) Less(i, j int) bool {
	return ps[i].x < ps[j].x
}

func main() {
	var N, K int
	fmt.Scan(&N, &K)

	ps := make(pairs, N)
	for i := range ps {
		fmt.Scan(&ps[i].x, &ps[i].y)
	}
	sort.Sort(ps)

	for i := range ps {
		a, b := ps[i].x, ps[i].y
		if K-b <= 0 {
			fmt.Println(a)
			return
		}
		K -= b
	}
}


Measured memory_bytes: 6912
N = int(input())
A = [int(x) for x in input().split()]
#print(N,A)
flg = True
cnt = 0
for i in range(N):
  if (A[i] % 2) == 0:
    cnt += 1
    if (A[i] % 3) != 0 and (A[i] % 5) != 0:
      flg = False
      break
if cnt == 0 or flg:
  print('APPROVED')
else:
  print('DENIED')

Measured memory_bytes: 3060
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;

int main()
{
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	if(b <= c) swap(b, c);
	if(a <= b) swap(a, b);
	for(int i = 1; i <= k; i++) a *= 2;
	printf("%d\n", a + b + c);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(int argc, const char * argv[]) {
   
    int w = 0;
    int h = 0;
    int area = 0;
    int circle = 0;
    
    
    scanf("%d %d", &w, &h);
    area = w * h;
    circle = w * 2 + h * 2;
    printf("%d %d\n", area, circle);
    
    
   
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
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;
}

class UnionFind {
    std::vector<int> p;

public:
    UnionFind(int n) : p(n, -1) {}

    int root(int x) { return p[x] < 0 ? x : p[x] = root(p[x]); }

    bool same(int x, int y) { return root(x) == root(y); }

    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (p[y] < p[x]) std::swap(x, y);
        if (p[x] == p[y]) --p[x];
        p[y] = x;
        return true;
    }
};

void solve(long long N, long long M, std::vector<long long> A,
           std::vector<long long> B) {
    UnionFind uf(N);
    for (int i = 0; i < M; i++) {
        uf.unite(A[i] - 1, B[i] - 1);
    }
    map<int, int> cnt;
    for(int i = 0 ; i < N ; i++)
        cnt[uf.root(i)]++;

    int ans = 0;
    for( auto i : cnt ){
        ans = max(ans, i.second);
    }
    cout << ans << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    std::vector<long long> A(M);
    std::vector<long long> B(M);
    for (int i = 0; i < M; i++) {
        scanf("%lld", &A[i]);
        scanf("%lld", &B[i]);
    }
    solve(N, M, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 13460
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var nm = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var n = nm[0];
        var m = nm[1];
        var digits = new [] { 1, 0, 0 }.Take(n).ToArray();
        var fix = new bool[digits.Length];
        for (int i = 0; i < m; ++i)
        {
            var sc = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            var s = sc[0] - 1;
            var c = sc[1];
            
            if (fix[s] && digits[s] != c || digits.Length > 1 && s == 0 && c == 0)
            {
                Console.WriteLine("-1");
                return;
            }
            digits[s] = c;
            fix[s] = true;
        }

        if (digits.Length == 1 && !fix[0])
        {
            Console.WriteLine("0");
            return;
        }

        var str = new string(digits.Select(x => (char)(x + '0')).ToArray());
        Console.WriteLine(str);
    }
}


Measured memory_bytes: 13396
#include <iostream>

int main () {
  int x, cnt;
  cnt = 1;
  while(1){
    std::cin >> x;
  	if(x == 0) 
  	  break;
  	else
  	  std::cout << "Case " << cnt << ": " << x << std::endl;
  	  ++cnt;
  }
  return 0;
}

Measured memory_bytes: 3052
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000

void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b;
  cin>>a>>b;
  if( (a<=0&&b>=0) || (a>=0&&b<=0) )  cout<<"Zero"<<endl;
  else if(a==0 || b == 0) cout<<"Zero"<<endl;
  else if(a<0 && b<0 && abs( abs(a)-abs(b) ) % 2 ==0) cout<<"Negative"<<endl;
  else cout<<"Positive"<<endl;
}
int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
import math
l,r = list(map(int,input().split()))
MOD = 2019
res = 100000000000000000000000000000000
ans = []
for i in range(l,r+1):
    if res == 0:
        break
    for j in range(i+1,r+1):
        if res == 0:
            break
        if (i*j)%2019 < res:
            res = (i*j)%2019
print(res)


Measured memory_bytes: 39536
def main():
    n,a,b = map(int,input().split())
    MOD = 10**9 +7
    s = pow(2,n,MOD)-1
    P_ni = 1
    F_i = 1

    for i in range(1,b + 1):
        P_ni=P_ni*(n-i+1)%MOD
        F_i=F_i* i % MOD
        if i == a or i == b:
            s-=P_ni*pow(F_i,MOD-2,MOD)
    print(s%MOD)

if __name__=='__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv,  digitDP//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal ,RMQ, LCA//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q; ll A, B;
ll MOD = 1000000007; ll INF = 1LL << 60; ll ans = 0; ll z = 0, o = 1;
vl flag, D; vll path;
//***********//
int main() {
	string S;
	cin >> S;
	N = S.length();
	for (i = 0; i < N; i++) {
		if (i % 2 == 1) {
			if (S[i] == 'g') ans++;
		}
		else {
			if (S[i] == 'p') ans--;
		}
	}
	cout << ans << endl;
}

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

long long int knapsack(long long int W, long long int wt[], long long int val[], int n) 
{ 
   long long int i, w; 
   long long int K[n+1][W+1]; 
   for (i = 0; i <= n; i++) { 
       for (w = 0; w <= W; w++) { 
           if (i==0 || w==0) 
               K[i][w] = 0; 
           else if (wt[i-1] <= w) 
                 K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]); 
           else
                 K[i][w] = K[i-1][w]; 
       } 
   } 
  
   return K[n][W]; 
} 
  
int main() 
{ 
    int n;
    cin >> n;
    long long int W, wt[n], val[n];
    cin >> W;
    for( int i = 0; i < n; i++){
        cin >> wt[i] >> val[i];
    }
    cout << knapsack(W, wt, val, n); 
    return 0; 
}


Measured memory_bytes: 79104
import bisect
for e in iter(input,'0'):
    n=int(e)
    c=[sorted(int(input())for _ in[0]*n)]
    c+=[sorted(set(range(1,2*n+1))-set(c[0]))]
    t=f=0
    while 1:
        x=bisect.bisect(c[t],f)
        if not c[t]:break
        f=c[t].pop(x)if x<len(c[t])else 0
        t^=1
    print(len(c[1]))
    print(len(c[0]))


Measured memory_bytes: 5656
#include<stdio.h>
#define N 1201
  
int main(){
  char str[N];
  int i=0,j;
  int number[26];
  char Eng[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'};
  int num;
  for(j=0;j<26;j++){
    number[j]=0;
  }  
    
  while(1){
    if(scanf("%c",&str[i])==EOF)break;
    if('A'<=str[i]&&str[i]<='Z'){
      str[i]=str[i]+('a'-'A');
    }
    num=str[i] - 'a';
    number[num]++;
    i++;
  }
  
  for(i=0;i<26;i++){
    printf("%c : %d\n",Eng[i],number[i]);
  }
  
  return 0;
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

void solve(){
    i64 R,C,N;
    cin >> R >> C >> N;

    vector<pair<int,int>> ps[4];
    rep(i,0,N){
        int x[2],y[2];
        rep(j,0,2) cin >> x[j] >> y[j];
        if((0<x[0] and x[0]<R and 0<y[0] and y[0]<C) or (0<x[1] and x[1]<R and 0<y[1] and y[1]<C)) continue;
        rep(j,0,2){
            if(x[j]==0) ps[0].push_back(make_pair(y[j],i));
            else if(y[j]==C) ps[1].push_back(make_pair(x[j],i));
            else if(x[j]==R) ps[2].push_back(make_pair(y[j],i));
            else ps[3].push_back(make_pair(x[j],i));
        }
    }
    rep(i,0,2) sort(ps[i].begin(),ps[i].end());
    rep(i,2,4) sort(ps[i].rbegin(),ps[i].rend());

    stack<int> stk;
    rep(i,0,4){
        rep(j,0,ps[i].size()){
            if(stk.empty() or stk.top()!=ps[i][j].second) stk.push(ps[i][j].second);
            else stk.pop();
        }
    }
    if(stk.empty()) cout << "YES" << endl;
    else cout << "NO" << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 2520
N = int(input())
A = list(map(int,input().split()))

def insertion_sort(A):
    print(*A)
    for j in range(1,len(A)):
        key=A[j]
        i=j-1
        while i>=0 and A[i]>key:
            A[i+1]=A[i]
            i=i-1
        A[i+1]=key
        print(*A)
    return A

insertion_sort(A)




Measured memory_bytes: 5980
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>

using namespace std;
#define MAXN 200000
#define INF 0x3f3f3f3f
#define lc(x) (x<<1)
#define rc(x) (x<<1|1)
#define mn(x) t[x]
#define mid ((lef+rig)>>1)
#define rint register int
#define gc() getchar()
inline int read(rint ans = 0, rint sgn = ' ', rint ch = gc())
{
	for(; ch < '0' || ch > '9'; sgn = ch, ch = gc());
	for(; ch >='0' && ch <='9';(ans*=10)+=ch-'0', ch = gc());
	return sgn-'-'?ans:-ans;
}
struct SegmentTree
{
	int t[524289]; void BD(int p, int lef, int rig){lef^rig ? BD(lc(p),lef,mid), BD(rc(p),mid+1,rig), mn(p) = min(mn(lc(p)),mn(rc(p))) : mn(p) = !!lef*INF;}
	void ED(int p, int lef, int rig, int x, int v){lef^rig ? x<=mid ? ED(lc(p),lef,mid,x,v) : ED(rc(p),mid+1,rig,x,v), mn(p) = min(mn(lc(p)),mn(rc(p))) : mn(p) = v;}
	int QU(int p, int lef, int rig, int L, int R){return L^lef||R^rig ? min(L<=mid?QU(lc(p),lef,mid,L,min(mid,R)):INF,R>mid?QU(rc(p),mid+1,rig,max(mid+1,L),R):INF) : mn(p);}
}T[2]; int n, q, c[2][MAXN+5], Ans; struct S{int l,r; S(){} S(int _l, int _r){l=_l,r=_r;}}s[MAXN+5]; inline bool operator < (S a, S b){return a.l^b.l ? a.l<b.l : a.r<b.r;}
int main()
{
	n = read(); for(rint i = 1; i <= n; c[1][i] = c[1][i-1]+read(), c[0][i] = i-c[1][i], i++); Ans = c[1][n];
	q = read(); for(rint i = 1; i <= q; s[i].l = read(), s[i].r = read(), i++); sort(s+1,s+q+1); T[0].BD(1,0,n); T[1].BD(1,0,n);
	for(rint i = 1, f; i <= q; T[0].ED(1,0,n,s[i].r,f-c[0][s[i].r]), T[1].ED(1,0,n,s[i].r,f-c[1][s[i].r]), Ans = min(Ans,f+c[1][n]-c[1][s[i].r]), i++)
		f = min(T[0].QU(1,0,n,s[i].l,s[i].r)+c[0][s[i].r],T[1].QU(1,0,n,0,s[i].l-1)+c[0][s[i].r]-c[0][s[i].l-1]+c[1][s[i].l-1]); printf("%d\n",Ans); return 0;
}

Measured memory_bytes: 7552
package main

import (
	"fmt"
)

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)

	count := 0

	for a%2 == 0 && b%2 == 0 && c%2 == 0 {
		if a == b && b == c {
			count = -1
			break
		}
		aTemp := a
		bTemp := b
		cTemp := c
		a = bTemp/2 + cTemp/2
		b = aTemp/2 + cTemp/2
		c = aTemp/2 + bTemp/2
		count++
	}

	fmt.Println(count)
}


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

#define ll long long
#define mk make_pair
#define pb push_back
#define ff first
#define sc second
#define all(x) x.begin(), x.end();

ll gcd(ll a, ll b){
   if(b == 0) return a;
   
   return gcd(b, a % b);
}

ll sum(int n){
   if(n == 0){
      return n;
   }else{
      return sum(n/10) + n%10;
   }
}
using namespace std;


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

   string s; cin >> s;
   int cost = 0;
   for(char i : s){
      if(i != 'x') cost++;
   }
   cout << 700 + cost * 100;
   return 0;
}


Measured memory_bytes: 256
let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let ss = Array.init n @@ fun _ -> read_line ()

let count_ab str =
  let t = Str.global_replace (Str.regexp "AB") "." str in
  (String.length str) - (String.length t)

let f str = (count_ab str, str.[0] = 'B', str.[String.length str - 1] = 'A')

let () =
  let ss = Array.map f ss in
  let ab_count = Array.fold_left (fun sum (a, _, _) -> sum + a) 0 ss in
  let both, only_a, only_b = ref 0, ref 0, ref 0 in
  Array.iter (fun (_, x, y) ->
    if x && y then both := !both + 1
    else if x then only_a := !only_a + 1
    else if y then only_b := !only_b + 1
  ) ss;
  Printf.printf "%d\n" @@ ab_count +
    if !both = 0 then (min !only_a !only_b)
    else if !only_a = 0 && !only_b = 0 then !both - 1
    else !both + (min !only_a !only_b)


Measured memory_bytes: 6688
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//#define int long long


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

  if(s%2==0) {
  cout << s << endl;
  }
  
  else {
  cout << 2*s << endl;
  }
  
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll = long long;
const int INF = 10000000;

int main(){
    int n, ans = 0;
    cin >> n;
    vector<int> a(n), b(n), c(n-1);
    rep(i, n) cin >> a[i];
    rep(i, n){
        cin >> b[i];
        ans += b[i];
    }
    rep(i, n-1) cin >> c[i];

    for(int i = 1; i < n; ++i){
        if(a[i] - a[i-1] == 1){
            ans += c[a[i-1]-1];
        }
    }
    cout << ans << endl;

    return 0;
}


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

int size;
vector<long long> val;
vector<long long> lazy;
vector<long long> width;

void lazy_propagate(int p) {
    if (lazy[p] > 0) {
        val[p] += lazy[p] * width[p];
        if (p < size-1) {
            lazy[p*2+1] += lazy[p];
            lazy[p*2+2] += lazy[p];
        }
        lazy[p] = 0;
    }
}

void add(int wishl, int wishr, int watchl, int watchr, int k, int x) {
    if (wishr <= watchl || watchr <= wishl) {
        lazy_propagate(k);
        return;
    }
    if (wishl <= watchl && watchr <= wishr) {
        lazy[k] += x;
        lazy_propagate(k);
        return;
    }
    int mid = (watchl+watchr)/2;
    lazy_propagate(k);
    add(wishl, wishr, watchl, mid, k*2+1, x);
    add(wishl, wishr, mid, watchr, k*2+2, x);
    val[k] = val[k*2+1] + val[k*2+2];
}
void add(int wishl, int wishr, int x) {
    add(wishl, wishr, 0, size, 0, x);
}

long long getsum(int wishl, int wishr, int watchl, int watchr, int k) {
    if (wishr <= watchl || watchr <= wishl) {
        return 0;
    }
    if (wishl <= watchl && watchr <= wishr) {
        lazy_propagate(k);
        return val[k];
    }
    int mid = (watchl+watchr)/2;
    lazy_propagate(k);
    long long sl = getsum(wishl, wishr, watchl, mid, k*2+1);
    long long sr = getsum(wishl, wishr, mid, watchr, k*2+2);
    return sl + sr;
}
long long getsum(int wishl, int wishr) {
    return getsum(wishl, wishr, 0, size, 0);
}

signed main() {
    int n, q;
    cin >> n >> q;
    size = 1;
    while (size < n) size <<= 1;
    val = vector<long long>(size*2, 0);
    lazy = vector<long long>(size*2, 0);
    width = vector<long long>(size*2, 1);

    for (int i = size-2; i >= 0; i--) {
        width[i] = width[i*2+1] + width[i*2+2];
    }

    while (q--) {
        int type, l, r;
        cin >> type >> l >> r;
        if(type == 0) {
            int x;
            cin >> x;
            add(l-1, r, x);
        } else {
            cout << getsum(l-1, r) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 8828
import sys
from collections import defaultdict

bbn=1000000007
	
#+++++
#Reverse and Compare
#https://atcoder.jp/contests/agc019/tasks/agc019_b


def main():
	s = input()
	di = defaultdict(lambda : 0)
	for c in s:
		di[c] += 1
	
	total_s=len(s)
	ret=1
	
	for c in s:
		ret += total_s-1
		ret -= di[c]-1
		total_s -= 1
		di[c] -= 1
		
	print(ret)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 3876
#include<bits/stdc++.h>
#include<string>
#include<cmath>

using namespace std;

#define ll long long int
#define ld long double
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout<< #x << '=' << x <<endl
#define MOD 1000000007
ll n , ans;

void dfs(ll x){
    if(x > n){
        return;
    }
    string s = to_string(x);
    bool f3 = 0 , f5 = 0, f7 = 0;
    for(auto e : s){
        if(e == '3'){
            f3 = 1;
        }else if(e == '5'){
            f5 = 1;
        }else if(e == '7'){
            f7 = 1;
        }
    }
    if(f3 && f5 && f7){
        ans++;
    }
    dfs(x*10 + 3);
    dfs(x*10 + 5);
    dfs(x*10 + 7);
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n;
    dfs(3);
    dfs(5);
    dfs(7);
    cout<<ans;

}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
int cnt_digits(long long n){
  int digits=0;
  while(n){
    n/=10;
    digits++;
  }
  return digits;
}
int main()
{
  long long n;cin>>n;
  int ans=cnt_digits(n);
  long long j=0;
  for(long long i=1;i*i<=n;i++){
    if(n%i==0){
      j=n/i;
      ans=min(ans,cnt_digits(j));
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main(){
  int k;
  cin >> k;
  int r = 7 % k;
  int r0 = r;
  set<int> s;
  s.insert(r);
  int ans = 1;
  while(1){
    if(r == 0){
      cout << ans << endl;
      return 0;
    }
    r = (10*r+r0) % k;
    int sz = s.size();
    s.insert(r);
    if(int(s.size()) == sz) break;
    ans++;
  }
  cout << -1 << endl;
}
    

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

using namespace std;

typedef long long ll;

int main()
{
    int n,m,ans=0;
    cin >> n >> m;
    string s;
    for(int i=n; i<=m; i++)
    {
        s=to_string(i);
        if(s[0]==s[4]&&s[1]==s[3])
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3664
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <functional>

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



using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
const ll inf = (1LL << 60);
const ll mod = 1000000007;


ll N, M, K;


ll dp[2][1003];
ll sum[1003];

vector<ll> a;


ll A, B;

int main() {
	cin >> N >> A >> B;

	cout << MIN(A, B) << " " <<  MAX((A + B) - N, 0) << endl;





	return 0;
}

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

int main() {
	int n;
	cin >> n;
	int a[100010];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int now=1;
	for (int i = 0; i < n; i++) {
		now = a[now - 1];
		if (now == 2) {
			cout << i + 1 << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define pb push_back
#define mp make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define LLINF (1<<60)
#define MOD 1000000007
#define rep(i, n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;

int main() {
    string s, t;
    vector<char>check[200], c[200];
    cin >> s >> t;
    for (int i = 0; i < s.length(); i++) {
        if (check[(int)s[i]].size() == 0)check[(int)s[i]].pb(t[i]);
        else {
            if (check[(int)s[i]][0] != t[i]) {
                No;
                return 0;
            }
        }
    }
    for (int i = 0; i < t.length(); i++) {
        if (c[(int)t[i]].size() == 0)c[(int)t[i]].pb(s[i]);
        else {
            if (c[(int)t[i]][0] != s[i]) {
                No;
                return 0;
            }
        }
    }
    Yes;
    return 0;
    return 0;
}


Measured memory_bytes: 776
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < n; i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(a, b) for (int i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template <class T>inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}


int main()
{
    int n,r;
    cin >> n >> r;
    if(n>=10){
        cout << r << endl;
    }
    else{
        cout << r+100*(10-n) << endl; 
    }
}

Measured memory_bytes: 764
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

int main()
{

  int H,W,h,w; cin >> H >> W >> h >> w;
  cout << (H-h)*(W-w) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int H, W;
vector<vector<int>> A;

int main() {
  cin >> H >> W;
  A.resize(H, vector<int>(W));

  deque<pair<int, int>> que;
  for (int y = 0; y < H; ++y) {
    for (int x = 0; x < W; ++x) {
      char c; cin >> c;
      if (c == '#') {
        A[y][x] = 0;
        que.push_back({y, x});
      } else {
        A[y][x] = -1;
      }
    }
  }

  while (!que.empty()) {
    auto p = que.front(); que.pop_front();
    int y = p.first;
    int x = p.second;

    vector<pair<int, int>> ds = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
    for (auto dxy : ds) {
      int ny = y + dxy.first;
      int nx = x + dxy.second;
      if (nx < 0 || W <= nx || ny < 0 || H <= ny) continue;
      if (A[ny][nx] >= 0) continue;

      A[ny][nx] = A[y][x] + 1;
      que.push_back({ny, nx});
    }
  }


  int vmax = 0;
  for (int y = 0; y < H; ++y) {
    for (int x = 0; x < W; ++x) {
      vmax = max(A[y][x], vmax);
    }
  }
  cout << vmax << endl;
}


Measured memory_bytes: 12432
#include<stdio.h>

int main(void){
  
  int N,K,X,Y;
  int cost;
  
  scanf("%d",&N);
  scanf("%d",&K);
  scanf("%d",&X);
  scanf("%d",&Y);
  
  if(N>K){
    
    cost=K*X+(N-K)*Y;
    
  }else{
    
    cost=N*X;
    
  }
  
  printf("%d\n",cost);
  
  return 0;
  
}


Measured memory_bytes: 128
import sys,os,re
from collections import Counter,deque
from operator import itemgetter
from itertools import accumulate
sys.setrecursionlimit(10**6)

n,m=map(int,input().split())
A=[list(map(int,input().split())) for i in range(n)]
b=[int(input()) for i in range(m)]
c=[0 for i in range(n)]

for i in range(n):
    for j in range(m):
        c[i]+=A[i][j]*b[j]
    print(c[i])


Measured memory_bytes: 6920