akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define ull unsigned long long
#define db double
#define pb push_back
#define ppb pop_back
#define all(x) (x).begin(), (x).end()

template <typename T>
using pr = array <T, 2>;

template <typename T>
using ord_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll INF = 1e18;

int d(ll x, ll y) {
	int res = 0;
	if (x > y) {
		while (y < x) {
			y *= 4;
			res++;
		}
	}	else {
		while (x * 4 <= y) {
			x *= 4;
			res--;
		}
	}
	return res;
}

vector <ll> get(vector <ll> & v) {
	int n = v.size();
	vector <ll> c(n - 1), f(n);
	for (int i = 0; i < n - 1; i++) {
		c[i] = d(v[i], v[i + 1]);
	}
	stack <pr <ll>> st;
	st.push({n - 1, INF});
	for (int i = n - 2; i >= 0; i--) {
		f[i] = f[i + 1];
		if (c[i] < 0) {
			st.push({i, -c[i]});
		}	else {
			int x = c[i];
			while (x--) {
				f[i] += st.top()[0] - i;
				st.top()[1]--;
				if (!st.top()[1]) {
					st.pop();
				}
			}
		}
	}
	return f;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	int n;
	cin >> n;
	vector <ll> a(n);
	for (auto & i : a) {
		cin >> i;
	}
	vector <ll> suf = get(a);
	reverse(all(a));
	vector <ll> pref = get(a);
	reverse(all(pref));
	ll res = min(2 * pref[n - 1] + n, 2 * suf[0]);
	for (int i = 0; i < n - 1; i++) {
		res = min(res, 2 * (pref[i] + suf[i + 1]) + (i + 1));
	}
	cout << res;
}


Measured memory_bytes: 6500
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
#include <map>
using namespace std;


#define prec(i) cout << fixed << setprecision(i)

const long long int MOD = 1000000007;


int ctoi(char c) {
	if (c >= '0' && c <= '9')
		return c - '0';
	else
		return -1;
}


void output_yn(bool b) {
	if (b)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


int main()
{
	long long int n, sum = 0;

	cin >> n;

	vector<int> a(n);
	vector<int> b(n);
	vector<int> c(n - 1);

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

	for (int i = 0; i < n; i++) {
		sum += b[a[i] - 1];
	}

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

	cout << sum << endl;

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (b)-1; i >= (a); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
const ld EPS = 1e-12L;
const ld PI = 3.1415926535897932385L;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ull x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

const int MAX_V = 400;
ll d[MAX_V][MAX_V]; // 隣接行列

// ワーシャル-フロイド法　O(V^3)
// 隣接行列でd[i][i] == 0, 辺がないときd[i][j] == INFである
void Warshall_Floyd(ll l, ll r){
    for(ll k = l; k < r; k++)
        for(ll i = l; i < r; i++)
            for(ll j = l; j < r; j++)
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    vvll a(n, vll(n));
    ll ans = 0;
    rep(i, n)rep(j, n){
        cin >> a[i][j];
        d[i][j] = a[i][j];
        if(i < j) ans += a[i][j];
        if(i != j && a[i][j] == 0) d[i][j] = INF;
    }
    Warshall_Floyd(0, n);
    rep(i, n)rep(j, n){
        if(d[i][j] < a[i][j]){
            cout << -1 << endl;
            return 0;
        }
    }
    rep(i, n)repr(j, i+1, n)rep(k, n){
        if(i != k && j != k && d[i][j] == d[i][k] + d[k][j]){
            ans -= a[i][j];
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


int main() {
	int N;
	cin >> N;
	vector<vector<int> > plan(3, vector<int>(N));
	for (int i = 0; i < N; i++)cin >> plan[0][i] >> plan[1][i] >> plan[2][i];
	vector<vector<int> > dp(3, vector<int>(N, 0)); //i前日した行動 j何日目
	dp[0][0] = plan[0][0]; dp[1][0] = plan[1][0]; dp[2][0] = plan[2][0];
	for (int i = 1; i < N; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (k == j)continue;
				dp[k][i] = max(dp[j][i - 1] + plan[k][i], dp[k][i]);
			}
		}
	}
	cout << max(dp[0][N - 1], max(dp[1][N - 1], dp[2][N - 1])) << endl;
	return 0;
}

Measured memory_bytes: 2940
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        int s = (int)(Math.sqrt((double)n));
        for(int i = s;i >= 1;i--){
            if(n%i==0){
                System.out.println(i+n/i-2);
                break;
            }
        }
    }
}

Measured memory_bytes: 25300
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
   int n;cin>>n;
   int ac=0;
   int wa = 0;
   int tle = 0;
   int re = 0;
   for(int i = 0;i<n;i++){
    string s;cin>>s;
    if(s == "AC") ac+=1;
    else if(s == "WA") wa += 1;
    else if (s=="TLE") tle += 1;
    else re += 1;
   }
   cout<<"AC"<<" "<<"x"<<" "<<ac<<endl;
   cout<<"WA"<<" "<<"x"<<" "<<wa<<endl;
    cout<<"TLE"<<" "<<"x"<<" "<<tle<<endl;
    cout<<"RE"<<" "<<"x"<<" "<<re<<endl;
  
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const ll MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,M;
  cin>>N>>M;
  vector<ll>dp(N+1,0);
  for(int i=0;i<M;i++){
    int a;
    cin>>a;
    dp[a]=-1;
  }
  dp[0]=1;

  for(int i=0;i<N;i++){
    if(dp[i]==-1)continue;
    if(dp[i+1]!=-1)dp[i+1]+=dp[i];
    if(i+2<=N && dp[i+2]!=-1)dp[i+2]+=dp[i];
    dp[i+1]%=MOD;
    dp[i+2]%=MOD;
  }
  cout<<dp[N]%MOD<<endl;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main {
	public static void main(String[] args){
    	int x=0;
        int y;
    	Scanner sc = new Scanner(System.in);
    	String a = sc.next();
      		for(int i= 0; i < a.length(); i++){
      			if(a.charAt(i)=='o'){
        			x=x+1;
      			}
    		}
        y = 700 + 100*x;
    System.out.println(y);
    }
}

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

const long double PI = acos(-1);
constexpr long double EPS = 1e-15;
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

template<class T>
void maxi(T &a, const T &b){
  if(a < b) a = b;
}

int n,m;
int va[112];

void solve() {
  int vs = 0;
  for(int i = 1; i <= m; ++i){
    vs += va[i];
  }
  cout << vs << endl;
}

int main(int argc, char *argv[]){

  /*Regular*/
  // if (argc > 1 && stoi(argv[1])) cin >> case_num;
  // REP(case_no, case_num) {
  //   cerr << endl << "case " << case_no + 1 << endl;
  //   solve();
  // }

  /*ICPC*/
  while (cin >> n >> m, n && m) {
    REP(i, n){
      int d, v;
      cin >> d >> v;
      maxi(va[d], v);
    }
    solve();
    for(int i = 1; i <= m; ++i) va[i] = 0;
  }

  return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

void solve(){
    string today;
    cin >> today;
    string tomorrow;
    if(today == "Sunny") tomorrow = "Cloudy";
    else if(today == "Cloudy") tomorrow = "Rainy";
    else tomorrow = "Sunny";
    cout << tomorrow << endl;
}


int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n>=400 && n<=599)cout<<"8"<<endl;
    else if(n>=600 && n<=799)cout<<"7"<<endl;
    else if(n>=800 && n<=999)cout<<"6"<<endl;
    else if(n>=1000 && n<=1199)cout<<"5"<<endl;
    else if(n>=1200 && n<=1399)cout<<"4"<<endl;
    else if(n>=1400 && n<=1599)cout<<"3"<<endl;
    else if(n>=1600 && n<=1799)cout<<"2"<<endl;
    else if(n>=1800 && n<=1999)cout<<"1"<<endl;
    return 0;
}


Measured memory_bytes: 3588
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));		
		String s = br.readLine(); //.toCharArray();
		String t = br.readLine(); //.toCharArray();
		br.close();

		int row = t.length();
		int col = s.length();
		int tb[][] = new int[row + 1][col + 1];

		for ( int r = 0; r < row; r++ ) {
			for ( int c = 0; c < col; c++ ) {
				if ( t.charAt(r) == s.charAt(c) ) {
					tb[r + 1][c + 1] = tb[r][c] + 1;
				} else {
					tb[r + 1][c + 1] = Math.max(tb[r + 1][c], tb[r][c + 1]);
				}
			}
		}

		int r = row;
		int c = col;
		ArrayDeque<Character> stack = new ArrayDeque<Character>();
		stack.add(' ');
		while ( tb[r][c] != 0 ) {

			// 左上に行けるとき
			if ( tb[r - 1][c - 1] == tb[r][c] ) {
				r -= 1;
				c -= 1;
			} else
			// 上
			if ( tb[r - 1][c] == tb[r][c] ) {
				r -= 1;
			} else
			// 左
			if ( tb[r][c - 1] == tb[r][c] ) {
				c -= 1;
			} else
			// 行き止まり
			{
				stack.add((Character) s.charAt(c - 1));
				r -= 1;
				c -= 1;
			}
		}

		StringBuilder sb = new StringBuilder();
		while ( stack.size() > 0 ) {
			sb.append(stack.pollLast());
		}
		System.out.println(sb);
	}
}


Measured memory_bytes: 79952
#include<bits/stdc++.h>
using namespace std;
int main()
{  string a,b;
   cin>>a>>b;
   if(a.length()==b.length())
     {  
       for(int i=0;i<a.length();i++)cout<<a[i]<<b[i];
       cout<<endl;
	 }
   if(a.length()==b.length()+1)
     {  for(int i=0;i<b.length();i++)cout<<a[i]<<b[i];
        cout<<a[a.length()-1]<<endl;
	 }
   return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;
long long int MOD = 1000000007;

#define MAX_V 1000

struct edge{
	long long int to, cap, cost, rev; // 行き先、容量、逆辺
};

vector<edge> G[MAX_V] = {};
long long int dist[MAX_V]; // 最短距離
int prevv[MAX_V], preve[MAX_V]; // 直前の頂点と辺

// from から to へ向かう容量 cap の辺を張る
void add_edge(long long int from, long long int to, long long int cap, long long int cost){
	G[from].push_back((edge){to, cap, cost, G[to].size()});
	G[to].push_back((edge){from, 0, -cost, G[from].size() - 1}); // 有向辺
}

// s から t への流量 f の最小費用流を求める( V は頂点数)
long long int min_cost_flow(int s, int t, int f, int V){
	
	long long int res = 0;
	
	while(f > 0){
		
		fill(dist, dist + V, INF);
		dist[s] = 0;
		bool update = true;
		while(update){
			update = false;
			for(int v = 0; v < V; v++){
				if(dist[v] == INF){
					continue;
				}
				for(int i = 0; i < G[v].size(); i++){
					edge &e = G[v][i];
					if(e.cap > 0 && dist[e.to] > dist[v] + e.cost){
						dist[e.to] = dist[v] + e.cost;
						prevv[e.to] = v;
						preve[e.to] = i;
						update = true;
					}
				}
			}
		}
		if(dist[t] == INF){
			return -1;
		}
		
		long long int d = f;
		for(int v = t; v != s; v = prevv[v]){
			d = min(d, G[prevv[v]][preve[v]].cap);
		}
		f -= d;
		res += d * dist[t];
		for(int v = t; v != s; v = prevv[v]){
			edge &e = G[prevv[v]][preve[v]];
			e.cap -= d;
			G[v][e.rev].cap += d;
		}
	}
	return res;
}

int main(){
	
	int V = 365, E, F = 2;
	
	while(true){
		
		cin >> E;
		if(E == 0){
			break;
		}
		
		for(int i = 0; i < MAX_V; i++){
			G[i].clear();
		}
		
		for(int i = 0; i < E; i++){
			int num1, num2, cap = 1, cost;
			cin >> num1 >> num2 >> cost;
			add_edge(num1 - 1, num2, cap, -cost);
		}
		
		for(int i = 0; i < V; i++){
			add_edge(i, i + 1, 10, 0);
		}
		
		cout << -min_cost_flow(0, V, F, V + 1) << endl;
	}
	return 0;
}


Measured memory_bytes: 3248
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    token.parse().ok().expect("failed to parse token")
}

fn main() {

    let input = read::<String>();
    let i: i32 = input.parse().unwrap();
    let n: Vec<char>= input.chars().collect();

    let keta = n.len();

    let ans: i32 = match keta {
        1 => i,
        2 => 9,
        3 => 9 + i - 99,
        4 => 909,
        5 => 909 + i - 9999,
        6 => 90909,
        _ => 0,
    };
    println!("{}",ans);

}


Measured memory_bytes: 4352
#include<stdio.h>

int main(void)
{
   int a, b;
   
   scanf("%d", &a);
   scanf("%d", &b);
   
   if(a<b){
      printf("a < b\n");
   }
   else if(a>b){
      printf("a > b\n");
   }
   else{
      printf("a == b\n");
   }
      
   return 0;
}


Measured memory_bytes: 2024
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
ll mgcd(ll x,ll y){
	if(x==0ll)return y;
	else return mgcd(y%x,x);
}
ll A,B,C,D;
ll f(ll X){
	ll res = X/C+X/D;
	ll g = C/mgcd(C,D)*D;
	res -= X/g;
	return X -res;
}
int main(){
	cin >> A >> B >> C >> D;
	cout << f(B)-f(A-1) << endl;
	return 0;
}

Measured memory_bytes: 256
<?php
  $stdin = fopen('php://stdin', "r");

  fscanf($stdin, "%d %d", $n, $x);

  $m = [];
  $count = 0;
  for ($i=0; $i<$n; $i++) {
    fscanf($stdin, "%d", $m[$i]);
    $count++;
  }

  $min = min($m);

  $x = $x - array_sum($m);

  $count += (int)($x / $min);

  echo $count.PHP_EOL;


Measured memory_bytes: 4728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define DBG(v) cerr << #v << " = " << (v) << endl;

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


	int n, k;
	string s;
	cin >> n >> k >> s;

	s[k-1] += 'a' - 'A';
	cout << s;
	return 0;
}


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

int main()
{
    char x;
    scanf("%c",&x);
    switch(x)
    {
    case 'e':
    case 'a':
    case 'i':
    case 'o':
    case 'u':
    printf("vowel\n");
    break;
    default:
         printf("consonant\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
const int M = 179,R = 1000001;
int dp1[R],dp2[R],T[M];

void solve(void) {
    for (int i = 1; i < R; i++) dp1[i] = dp2[i] = R;
    for (int i = 1; i <= M+1; i++) T[i-1] = i*(i+1)*(i+2)/6;
    for (int i = 0; i < M; i++) {
        int t = T[i];
        for (int j = t; j < R; j++) {
            if (dp1[j-t] < R) dp1[j] = min(dp1[j], dp1[j-t]+1);
            if (t%2 == 0) continue;
            if (dp2[j-t] < R) dp2[j] = min(dp2[j], dp2[j-t]+1);
        }
    }
}

int main(void){
    solve();
    while (1) {
        int N;
        cin >> N;
        if (N == 0) break;
        printf("%d %d\n",dp1[N],dp2[N]);
    }
    return 0;    
}

Measured memory_bytes: 8948
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <utility>
#include <cmath>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

#define YesNo(b) ((b) ? "Yes" : "No")
#define YESNO(b) ((b) ? "YES" : "NO")

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;


using prime_map = std::unordered_map<int, int>;

ll pow5(int a)
{
    ll b = 1ll;
    for (int i = 0; i < 5; i++)
        b *= a;
    return b;    
}

pair<int,int> f(int X)
{
    int i = 0;
    vll memo;
    while (true)
    {
        ll i5 = pow5(i);
        for (int j = 0; j < (int)memo.size(); j++)
        {
            if(i5 - memo[j] == X) return pair(i, j);
            if(i5 + memo[j] == X) return pair(i, -j);
        }
        memo.push_back(i5);
        ++i;
    }
}

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

    auto [a, b] = f(X);
    cout << a << " " << b << endl;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"

#define pb push_back
#define ld long double
#define ll long long
#define f first
#define s second

using namespace std;

const ll MOD = 1e9 + 7;
const ll MOD1 = 2468777687;
const ll MOD2 = 1e9 + 9;

ll n;
vector<ll> t;
map<pair<ll, ll>, ll> v;
ll exp(ll a, ll x, ll MOD3){
    if(x == 0) return 1;
    ll tmp = exp(a, x/2, MOD3);
    tmp *= tmp;
    tmp %= MOD3;
    if(x%2) tmp *= a;
    tmp %= MOD3;
    return tmp;
}

ll inv(ll x, ll MOD3){
    return exp(x, MOD3 - 2, MOD3);
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    ll o = 0, e = 0, c = 0; 
    for(int i = 0; i < n; ++i){
        ll a, b;
        cin >> a >> b;
        if(a == 0 && b == 0) c++;
        else if(a == 0) e++;
        else if(b == 0) o++;
        else{
            ll a1 = ((a % MOD1) + MOD1) % MOD1;
            ll b1 = ((b % MOD1) + MOD1) % MOD1;
            ll a2 = ((a % MOD2) + MOD2) % MOD2;
            ll b2 = ((b % MOD2) + MOD2) % MOD2;
            v[{(a1 * inv(b1, MOD1))%MOD1, (a2 * inv(b2, MOD2))%MOD2}]++;
        }
    }
    t.assign(2e5 + 5, 1);
    for(int i = 1; i < t.size(); ++i){
        t[i] = 2 * t[i - 1];
        t[i] %= MOD;
    }
    ll res = 1;
    set<pair<ll, ll>> done;
    for(auto i : v){
        if(done.find(i.f) != done.end()) continue;
        ll oth1 = (inv((-i.f.f + MOD1)%MOD1, MOD1) + MOD1)%MOD1;
        ll oth2 = (inv((-i.f.s + MOD2)%MOD2, MOD2) + MOD2)%MOD2;
        ll cur = (t[i.s] + t[v[{oth1, oth2}]])%MOD;
        cur--;
        res *= cur;
        res %= MOD;
        // cout << i.f << " " << i.s << " " << oth << " " << cur << "\n";
        // cout << cur << "\n";
        done.insert(i.f);
        done.insert({oth1, oth2});
    }
    res *= ((t[o] + t[e]) - 1 + MOD)%MOD;
    res %= MOD;
    if(c > 0) res += c;
    cout << (res - 1 + MOD)%MOD;
    return 0;
}

Measured memory_bytes: 54688
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a) for(ll i=0;i<a;i++)
#define jkl ll debug = 0;
#define RREP(i,a) for(ll i=a-1;i>=0;i--)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)
#define printall(n,array) {for(ll i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
#define mp make_pair
typedef long long ll;
typedef pair<ll, ll> Pi;
typedef pair<ll, Pi> V;
typedef vector<ll> VE;
const ll mod = 1e9 + 7; //10^9+7

ll n, ans;
ll h[102];

Pi mini(int s, int t){
    ll min_ = mod;
    ll k = -1;
    rep(i, s, t){
        if(min_ <= h[i])continue;
        min_ = h[i];
        k = i;
    }
    return make_pair(min_, k);
}

void dfs(int s, int t){
    if(s==t){
        ans += h[s];
        return;
    }
    auto ret = mini(s, t);
    ll min_ = ret.first;
    ll k = ret.second;
    rep(i, s, t)h[i] -= min_;
    ans += min_;
    dfs(s, k);
    dfs(k+1, t);
}

int main(){
    cin >> n;
    REP(i, n)cin >> h[i];
    dfs(0, n);
    print(ans);
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int aa[100005],bb[100005],mm[100005];
int main()
{
	int a,b,m;
	int min1 = 100005,min2 = 100005;
	cin >> a >> b >> m;
	for(int i = 0;i < a;i++){
		cin >> aa[i];
		min1 = min(min1,aa[i]);
	}
	for(int i = 0;i < b;i++){
		cin >> bb[i];
		min2 = min(min2,bb[i]);
	}
	int min3 = min1+min2;
	for(int i = 0;i < m;i++){
		int a1,b1,c1;
		cin >> a1 >> b1 >> c1;
		min3 = min(min3,aa[a1-1]+bb[b1-1]-c1);
	}
	cout << min3 << endl;
	
	return 0;
}

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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
int n;
bool used[100];
int dfs(vector<int> graph[100],int from,bool used[100],int cnt){
    used[from] = true;
    cnt = 0;
    rep(i,0,n){
        if(used[i]) cnt++;
    }
    bool ok = (cnt==n);
    rep(i,0,graph[from].size()){
        if(!used[graph[from][i]]){
            ok = dfs(graph,graph[from][i],used,cnt);
            if(ok == true) break;
        }
    }
    return ok;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int m; cin >> n >> m;
    vector<int> graph[100];
    vector<pair<int,int>> hozon;
    int ans = 0;
    rep(i,0,m){
        int a,b;
        cin >> a >> b;
        a--;b--;
        hozon.push_back(make_pair(a,b));
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    rep(i,0,n) sort(all(graph[i]));
    rep(i,0,m){
        int a = hozon[i].first,b = hozon[i].second;
        graph[a].erase(lower_bound(all(graph[a]),b));
        graph[b].erase(lower_bound(all(graph[b]),a));
        bool used[100] = {};
        ans +=(dfs(graph,0,used,0) ? 0:1);
        rep(i,0,100) used[i] = false;
        graph[a].push_back(b);
        graph[b].push_back(a);
        sort(all(graph[a]));
        sort(all(graph[b]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr);
#endif
#define all(c) c.begin(),c.end()
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" ";cout<<endl;}
void solve(){
  string s;
  cin>>s;
  int val=count(all(s),'o');
  int ans=700+(val*100);
  cout<<(val>0?to_string(ans):"700")<<endl;
}
int32_t main(){
  IOS;
  solve();
  #ifdef LOCAL_DEFINE
  cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
  #endif
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C;cin>>A>>B>>C;
  string ans="NO";
  for(int i=1; i<B; i++){
    if((i*A)%B==C)ans="YES";
  }
  cout<<ans<<endl;
}

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

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef stack<int> si;
typedef deque<int> dqi;

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define PF push_front
#define PB push_back
#define FST first
#define SEC second
#define sz(obj) ((int)(obj).size())
#define ALL(v) (v).begin(), (v).end()

const int INF = 999999999;
const int MOD = 1e9 + 7;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

inline int in() {int x; std::cin >> x; return x;}
 
template <typename T>
void print(std::vector<T>& v, char c = ' ') {
  REP(i, v.size()) {
    if (i != 0) std::cout << c;
    std::cout << v[i];
  }
  std::cout << endl;
}
template <typename T> void print(T x) { std::cout << x << '\n'; }

int gcd(int a, int b){ int c; while (a != 0){ c = a; a = b % a; b = c; } return b; }

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

  int n = in();
  int dp[100005];
  fill(dp, dp + n, MOD);
  int ans = 0;
  vector<int> a(n);
  REP(i, n) a[i] = in();

  REP(i, n){
    *lower_bound(dp, dp + n, a[i]) = a[i];
  } 

  print(lower_bound(dp, dp + n, MOD) - dp);

/*  REP(i, n){
    dp[i] = 1;
    REP(j, i){
      if (a[i] > a[j]){
        dp[i] = max(dp[i], dp[j] + 1);
      }
    }
    ans = max(ans, dp[i]);
  }
*/

  return (0);
}

Measured memory_bytes: 1800
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
using namespace std;
typedef long long int ll;

int main() {
  int K,X;
  cin>>K>>X;
  
  for(int i=X-K+1;i<=X+K-1;++i){
    cout<<i<<" ";
  }
}


Measured memory_bytes: 256
"""
中間試験と期末試験は 50 点満点（m, f ≤ 50）、再試験は 100 点満点 （r ≤ 100）
試験を受けていない場合は点数を -1

中間試験、期末試験のいずれかを欠席した場合成績は F。
中間試験と期末試験の合計点数が 80 以上ならば成績は A 。
中間試験と期末試験の合計点数が 65 以上 80 未満ならば成績は B。
中間試験と期末試験の合計点数が 50 以上 65 未満ならば成績は C。
中間試験と期末試験の合計点数が 30 以上 50 未満ならば成績は D。 ただし、再試験の点数が 50 以上ならば成績は C。
中間試験と期末試験の合計点数が 30 未満ならば成績は F
"""
while True:
    mid_test, fin_test, re_test = map(int, input().split())
    if (mid_test == -1) & (fin_test == -1) & (re_test == -1):
        break
    else:
        if (mid_test == -1) or (fin_test == -1):
            print("F")
        else:
            total_mf = mid_test + fin_test
            if total_mf >= 80:
                print("A")
            elif 65 <= total_mf < 80:
                print("B")
            elif 50 <= total_mf < 65:
                print("C")
            elif 30 <= total_mf < 50:
                if re_test >= 50:
                    print("C")
                else:
                    print("D")
            else:
                print("F")
    



Measured memory_bytes: 5604
#include <iostream>
#include <string>
using namespace std;
int main(){
  string S;
  cin >> S;
  for(int i = 0; i < 3; i++){
  	if(S[i] == '7'){
      cout << "Yes\n";
      return 0;
    }
  }
  cout << "No\n";
  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  ll h, w;
  cin >> h >> w;

  if((h % 3) * (w % 3) == 0){
    cout << 0 << endl;
    return 0;
  }

  ll twin, rest, dif1, dif2, dif3, nd;
  vector<ll> ans;

  if(h % 2 == 0){
    twin = h / 2;
    rest = (w - 1) * h;
    dif1 = 1e10, dif2 = 1e10;
    while(1){
      if(abs(rest - twin) > dif1) break;
      dif1 = abs(rest - twin);
      twin += h / 2;
      rest -= h;
    }
    if(w % 2 == 0){
      twin = w / 2;
      rest = (h - 1) * w;
      while(1){
        if(abs(rest - twin) > dif2) break;
        dif2 = abs(rest - twin);
        twin += w / 2;
        rest -= w;
      }
    }
    ans.pb(dif1);
    ans.pb(dif2);
    ans.pb(h);
    ans.pb(w);

    VSORT(ans);
    cout << ans[0] << endl;
    return 0;
  }
  else{

    dif1 = 1e10, dif2 = 1e10, dif3 = 1e10, nd;
    ll A = w / 2, B = w / 2 + 1, C = (h - 1) * w;
    while(1){
      nd = max(max(abs(A - B), abs(A - C)), abs(B - C));
      if(nd > dif1) break;
      dif1 = nd;
      A += w / 2;
      B += w / 2 + 1;
      C -= w;
    }
    ans.pb(dif1);

    A = h / 2, B = h / 2 + 1, C = (w - 1) * h;
    while(1){
      nd = max(max(abs(A - B), abs(A - C)), abs(B - C));
      if(nd > dif2) break;
      dif2 = nd;
      A += h / 2;
      B += h / 2 + 1;
      C -= h;
    }
    ans.pb(dif2);

    ans.pb(h);
    ans.pb(w);

    if(w % 2 == 0){
      twin = w / 2;
      rest = (h - 1) * w;
      while(1){
        if(abs(rest - twin) > dif3) break;
        dif3 = abs(rest - twin);
        twin += w / 2;
        rest -= w;
      }
    }
    ans.pb(dif3);
    VSORT(ans);
    cout << ans[0] << endl;
    return 0;
  }
  return 0;
}


Measured memory_bytes: 256
/*
 ID: bradyawn
 PROG: contest
 LANG: C++11
 */

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <deque>
#include <string>
#include <cmath>
#include <map>
#include <unordered_map>
#include <utility>
#include <set>
#include <unordered_set>
#include <ctime>
#include <queue>
#include <stack>
#include <bitset>
#include <random>
#include <cstring>
#include <functional>

using namespace std;

typedef long long ll;
typedef pair<int,int> i2;
typedef pair<ll,ll> ll2;

bool grid[52][52];

int h, w;

int main()
{
    //ifstream inf("");
    //ofstream outf("");
    //cout << setprecision(10);
    ios_base::sync_with_stdio(0); cin.tie(0);
    
    cin >> h >> w;
    
    for (int i = 1; i <= h; i++)
        for (int j = 1; j <= w; j++)
        {
            char c; cin >> c;
            if (c == '#') grid[i][j] = 1;
        }
    
    for (int i = 1; i <= h; i++)
        for (int j = 1; j <= w; j++)
        {
            if (grid[i][j])
            {
                if (!grid[i+1][j] && !grid[i-1][j] && !grid[i][j+1] && !grid[i][j-1])
                {
                    cout << "No\n";
                    return 0;
                }
            }
        }
    
    cout << "Yes\n";
    
    return 0;
    
}




Measured memory_bytes: 256
import java.util.Scanner;
class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = 100;
		int c = 1;
		for(;;) {
			b += b/100;
			if(a <= b) break;
			c++;
		}
		System.out.println(c);
	}
}

Measured memory_bytes: 35700
# Simultaneous Equation
require 'matrix'
while line = ARGF.gets do
  a1,b1,z1,a2,b2,z2 = line.split.map(&:to_i)
  m1 = Matrix.column_vector [z1,z2]
  m2 = Matrix[[a1,b1],[a2,b2]]
  result  = (m2 ** -1) * m1
  puts result.map{|e| "%5.3f" % e}.column(0).to_a.join("\s") 
end

Measured memory_bytes: 6424
# import bisect
from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    p, q, r = list(map(int,ipti().split()))

    print(min(p+q, q+r, r+p))


if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
N, x = map(int, input().split())
a = [int(i) for i in input().split()]
ans = 0
for i in range(N-1):
    sum = a[i]+a[i+1]
    if sum > x:
        if a[i+1] >= sum-x:
            a[i+1] -= sum-x
            ans += sum-x
        else:
            a[i+1] = 0
            ans += sum-x
print(ans)

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

int main(){
    ios_base::sync_with_stdio(false);
    long long x; cin >> x;
    long long n; cin >> n;
    set<int> res;
    for(int i = 0; i < n; i++){
        int temp; cin >> temp;
        res.insert(temp);
    }
    int a = x, b = x;
    while(res.find(a) != res.end()) a++;
    while(res.find(b) != res.end()) b--;
    if (abs(x - a) < abs(x - b)) cout << a;
    else cout << b;
}

Measured memory_bytes: 3592
from collections import defaultdict
N, M = map(int, input().split())
ab = defaultdict(list)
for i in range(M):
    a, b = map(int, input().split())
    ab[a].append(b)
    ab[b].append(a)

ans = "IMPOSSIBLE"
for u in ab[1]:
    if N in ab[u]:
        ans = "POSSIBLE"
        break
print(ans)


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

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

const int mod = (int)pow(10, 9) + 7;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> count;
  rep(i, n) {
    cin >> a[i];
    count[a[i]]++;
  }

  bool yes = true;

  if(n % 2 == 0) {
    for(auto it=count.begin(); it!=count.end(); it++) {
      if(it->first % 2 == 0 || it->second != 2) {
        yes = false;
        break;
      }
    }
  } else {
    for(auto it=count.begin(); it!=count.end(); it++) {
      if(it->first == 0) {
        if(it->second == 1) continue;
        else {
          yes = false;
          break;
        }
      } else if(it->first % 2 == 1 || it->second != 2) {
        yes = false;
        break;
      }
    }
  }

  if(yes) {
    long long int ans = 1;
    for(int i=0;i<n/2;i++) {
      ans = (ans * 2) % mod;
    }

    cout << ans << endl;
  } else cout << 0 << endl;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define     ll          long long int
#define     REP(i,x,n)    for(ll i=x;i<n;i++)
#define     SZ(v)       (ll)v.size()
#define     endl        "\n"
#define     ff          first
#define     ss          second
#define     PQ_MIN      priority_queue <ll, vector<ll>, greater<ll> >
#define     PQ          priority_queue <int>
#define     pbds        tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define     setbit(x)   __builtin_popcount(x)
#define     prec(n)     fixed<<setprecision(n)
#define     pb(n)       push_back(n)
#define     mp(a,b)     make_pair(a,b)
#define     clr(n)      memset(n,0,sizeof(n))
#define     reset(n)    memset(n,-1,sizeof(n))
#define     ii          pair<ll,ll>
#define     vll         vector<ll>
using namespace std;
using namespace __gnu_pbds;
bool comp(pair<ll,ll> a,pair<ll,ll> b) {       }
const ll MOD=1e9+7;
void print(vector<vector<ll> >&v)
{
    ll n=v.size();
    ll m=v[0].size();
    cout<<"\n";
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<m;j++)
            cout<<v[i][j]<<" ";
        cout<<"\n";
    }
}
void print(vector<ll>&v)
{
    ll n=v.size();
    cout<<"\n";
    for(ll i=0;i<n;i++)
    {
            cout<<v[i]<<" ";
    }
        cout<<"\n";

}
void print(set<ll>&s)
{

cout<<endl;

set<ll>::iterator it;
for(it=s.begin();it!=s.end();it++)
    cout<<*it<<" ";
cout<<endl;
}
ll __lcm(ll a,ll b)
{
    return ((a*b)/__gcd(a,b));
}
ll power(ll a,ll p)
{
    ll res=1;
    while(p>0)
    {
        if(p&1){
            res=(res*a)%MOD;
            p--;
        }
            a=(a*a)%MOD;
            p/=2;
    }

    return res%MOD;
}
const ll INF=1e16;
const ll nxm=2e5+5;

ll spf[nxm];
void sieve()
{
    memset(spf,-1,sizeof(spf));

    spf[0]=spf[1]=1;

    for(ll i=2;i<nxm;i++)
    {
        if(spf[i]==-1)
            spf[i]=i;
        for(ll j=i*i;j<nxm;j+=i)
        {
            if(spf[j]==-1)
                spf[j]=i;

        }

    }
//    while(x>1)
//    {
//        ll s=spf[x];
//        temp[s]++;
//        x/=s;
//    }


// log n prime factor
}
void solve(){

ll k;

cin>>k;

if(!(k&1))
{
    cout<<-1<<endl;return ;
}


ll num=0;
ll cnt=0;



while(num<k)
{
    num=num*10+7;
    cnt++;

    if(cnt>k)
        break;
}


while(num%k!=0)
{
    num=num%k;
    num=num*10+7;
    cnt++;

    if(cnt>k)
        break;

}

if(cnt>k)
{
    cout<<-1;return;
}


cout<<cnt;















}
int main(){
//    freopen("timber_input", "r", stdin);
//    freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll t=1;
//	cin>>t;
    REP(i,1,t+1)
    {
//    cout<<"Case #"<<i<<": ";
		solve();
    }
	return 0;
}
//  bitset<64>(x).to_ullong() // in my com  _ulong()
//  cout<<bitset<64>(ans).to_string().substr(64-m)<<endl;
/*

char s[100];

fgets(s,100,stdin);

stringstream stram(s);

string abc;

bool ok1=0,ok2=0;

while(stram>>abc)
*/


Measured memory_bytes: 3652
n,m=map(int,input().split())
s=list(map(int,input().split()))
if n>=m:
    print(0)
else:
    s.sort()
    t=[]
    for i in range(1,m):
        t.append(s[i]-s[i-1])
    t.sort()
    print(sum(t[:m-n]))

Measured memory_bytes: 13968
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
   
//#include <x86intrin.h>
#include <bits/stdc++.h>   
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, m, x[N], y[N], z[N], ans;
vector <int> g[N];
bool used[N];

void dfs (int v) {
   used[v] = 1;
   for (auto to : g[v])
      if (!used[to])
         dfs (to);
}

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   cin >> n >> m;
   for (int i = 1; i <= m; i ++) {
      cin >> x[i] >> y[i] >> z[i];
      g[x[i]].pb (y[i]);
      g[y[i]].pb (x[i]);
   }
   for (int i = 1; i <= n; i ++)
      if (!used[i])
         dfs (i), ans ++;
   cout << ans;
}

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}
                          

Measured memory_bytes: 16512
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,r,l) for(int i=r;i>=l;i--)
#define IMAX 0x3f3f3f3f
#define LLMAX 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
typedef double db;
inline int read() {
  int x=0,f=1;
  char c=getchar();
  while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
  while(isdigit(c)){x=x*10+c-'0';c=getchar();}
  return x*f;
}

signed main() {
  int _=1;//_=read();
  while(_--){
    ll n;
    scanf("%lld",&n);
    printf("%lld\n",n/500*1000+(n%500)/5*5);
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#ifdef DEBUG
#define debug(x) cerr << #x << " " << x << '\n'
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using pii = pair<int,int>;
const int INF = 0x3f3f3f3f, N = 6e3 + 5;

int n, m;
vector <int> G[N];
double dp[N];

int main()
{
	scanf("%d%d",&n,&m);
 	for(int i=1;i<=m;i++)
 	{
 		int u, v;
 		scanf("%d%d",&u,&v);
 		G[u].pb(v);
 	}
 	double ans = 1e18;
 	for(int i=1;i<=n;i++) dp[i] = 0.0;
 	for(int i=n-1;i>=1;i--)
 	{
 		int sz = G[i].size();
 		if(sz==0)
 		{
 			dp[i] = INF;
 			continue;
 		}
 		double tmp = 1.0/sz;
 		for(int j : G[i]) dp[i] += tmp*(dp[j]+1);
 	}
 	ans = dp[1];
 	for(int x=1;x<=n;x++)
 	{
 		for(int i=1;i<=n;i++) dp[i] = 0.0;
	 	for(int i=n-1;i>=1;i--)
	 	{
	 		double maxn = 0.0;
	 		int sz = G[i].size();
	 		if(i==x&&sz) sz--;
	 		if(sz==0)
	 		{
	 			dp[i] = INF;
	 			continue;
	 		}
	 		double tmp = 1.0/sz;
	 		for(int j : G[i]) 
			{
				if(i==x) maxn = max(maxn,dp[j]+1);
				dp[i] += tmp*(dp[j]+1);
			}
			if(i==x) dp[i] -= tmp*maxn;
	 	}
	 	ans = min(ans,dp[1]);
	}
	printf("%.8f\n",ans);
	return 0;
}


Measured memory_bytes: 1536
input_number = input().split()

a = int(input_number[0])
b = int(input_number[1])

max_number = 0

if a >= b:
    max_number += a
    a -= 1

else:
    max_number += b
    b -= 1


if a >= b:
    max_number += a

else:
    max_number += b

print(max_number)


Measured memory_bytes: 2940
import math

N, K = map(int,input().split())
ans = 0
for i in range(N):
    if not 1<=i+1<=K-1:
        ans += 1/N
    else:
        tmp = 2**math.ceil(math.log2(K)-math.log2(i+1))
        ans += 1/(N*tmp)
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <stdio.h>
#include <iomanip>
using namespace std;
int main() {
    double  n,m;
    double ret=0.0;
    cin>> n>>m;
    double prob=(double)1/n;
    //cout<<prob<<endl;
    for(int i=1;i<n+1;i++){
      double num=0;
      double tmp=i;
      while(tmp<m){
        num++;
        tmp=2*tmp;
        }
        //cout<<num<<endl;
      ret+= prob*pow(0.5,num);
      //cout<<ret<<endl;
      }
    printf("%.12f\n",ret);
    //cout<<setprecision(11)<< ret<<endl;
    return 0 ;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		char[] s = in.next().toCharArray();

		int idx = 0;
		while ( idx < s.length ) {
			// Rの個数をカウント
			int cntR = 0;
			while ( idx < s.length && s[idx] == 'R' ) {
				cntR++;
				idx++;
			}

			// Rの連続がLに移行したポイントを記録
			int changePoint = cntR;

			// Lの個数をカウント
			int cntL = 0;
			while ( idx < s.length && s[idx] == 'L' ) {
				cntL++;
				idx++;
			}

			// 表示
			if ( (cntR + cntL) % 2 == 0 ) {
				for ( int i = 0; i < cntR + cntL; i++ ) {
					if ( i == changePoint - 1 || i == changePoint ) {
						System.out.print((cntR + cntL) / 2 + " ");
					} else {
						System.out.print(0 + " ");
					}
				}
			} else {
				for ( int i = 0; i < cntR + cntL; i++ ) {
					if ( i != changePoint - 1 && i != changePoint ) {
						System.out.print(0 + " ");

					} else
					// 切り替わりのR	
					if ( i != changePoint - 1 ) {

						if ( (changePoint - 1) % 2 == (cntR + cntL) % 2 ) {
							System.out.print(((cntR + cntL) / 2 + 1) + " ");
						} else {
							System.out.print((cntR + cntL) / 2 + " ");
						}
					} else
					// 切り替わりのL	
					if ( i != changePoint ) {

						if ( (changePoint) % 2 == (cntR + cntL) % 2 ) {
							System.out.print(((cntR + cntL) / 2 + 1) + " ");
						} else {
							System.out.print((cntR + cntL) / 2 + " ");
						}
					}
				}
			}
		}
		in.close();
	}
}

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



// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)




int N;
vector<vector<int>> target;
vector<vector<int>> ptype;
vector<int> people;
int ans;

// nがv(0or1)であると仮定
int check(){
    int res =0;
    for(int i=0;i<N;i++){
        if(people[i] == 0){
            continue;
        }
        for(int j=0;j<target[i].size();j++){
            if(people[target[i][j]] != ptype[i][j]){
                return 0;
            }
        }
        res++;
    }
    return res;
}

void dfs(int n,int v){
    // cout << "n="<< n << "v=" << v << endl;
    people[n] = v;
    if(n >=N-1){
        ans = max(ans,check());
        // cout << "ans =" << ans << endl;
        return;
    }
    dfs(n+1,0);
    dfs(n+1,1);
}

int main(){
    // Failed to predict input format
    cin >> N;
    target.resize(N);
    ptype.resize(N);
    people.resize(N,-1);

    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        for(int j=0;j<a;j++){
            int b,c;
            cin >> b >> c;
            b--;
            target[i].emplace_back(b);
            ptype[i].emplace_back(c);
        }
    }
    dfs(0,0);
    dfs(0,1);
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> v(n);
    for (int i=0;i<n;i++){
        cin >> v[i];
    }
    sort(v.begin(),v.end());
    long long int ans=0;
    for (int i=0;i<n-k;i++){
        ans += v[i];
    }
    cout << ans << endl;




    return 0;
}

//Sum accumulate(v.begin(),v.end(),0);
//Sort sort(v.begin(),v.end())


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

int main(){

 ll n;
 cin>>n;
 ll a[n+1];
 ll c1=0,c2=0,c3=0;
 for(int i=0;i<n;i++) {
 	cin>>a[i];
 	if(a[i]==1) c1++;
 	if(a[i]==2) c2++;
 	if(a[i]==3) c3++; 
 }

 double dp[n+1][n+1][n+1];

 memset(dp,0,sizeof(dp));

 for(int k=0;k<=n;k++){
 	for(int j=0;j+k<=n;j++){
 		for(int i=0;i+j+k<=n;i++){
 			if(i==0&&j==0&&k==0) {
 				continue;
 			}
 			if(i-1>=0) dp[i][j][k]+=(dp[i-1][j][k]*((double)(i)/(i+j+k)));
 			if(j-1>=0)dp[i][j][k]+=(dp[i+1][j-1][k]*((double)(j)/(j+i+k)));
 			if(k-1>=0)dp[i][j][k]+=(dp[i][j+1][k-1]*((double)(k)/(i+j+k)));
  			dp[i][j][k]+=((double)(n)/(i+j+k));
  			
 		}
 	}
 }
 	 cout.precision(10);
 cout<<dp[c1][c2][c3]<<endl;


}

Measured memory_bytes: 213248
n = gets.to_i
l = gets.split.map(&:to_i).sort
cnt = 0
c = 0
0.upto(n - 1) do |i|
  i.next.upto(n - 1) do |j|
    next if l[i] == l[j]
    j.next.upto(n - 1) do |k|
      cnt += 1 if l[i] + l[j] > l[k] && l[j] < l[k]
      c += 1
    end
  end
end
puts cnt

Measured memory_bytes: 14376
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

ll INF = (ll)pow(10, 16);

int main(){
  ll N;
  cin >> N;
  ll a, b, c;
  vector<vpll> abc(N + 1);
  rep(i, N - 1){
    cin >> a >> b >> c;
    abc[a].push_back(make_pair(b, c));
    abc[b].push_back(make_pair(a, c));
  }
  ll Q, K;
  cin >> Q >> K;
  vl x(Q), y(Q);
  rep(i, Q){
    cin >> x[i] >> y[i];
  }

  vl cost(N + 1, INF);
  cost[K] = 0;
  vl vis(N + 1, 0);
  priority_queue<pll, vpll, greater<pll> > cv;
  cv.push({0, K});

  while(!cv.empty()){
    ll v1 = cv.top().first, v2 = cv.top().second;
    cv.pop();

    if(vis[v2] == 1) continue;
    
    vis[v2] = 1;
    
    rep(i, abc[v2].size()){
      ll update = abc[v2][i].second + cost[v2];
      if(update < cost[abc[v2][i].first]) cost[abc[v2][i].first] = update;
      cv.push({cost[abc[v2][i].first], abc[v2][i].first});
    }
  }

  rep(i, Q){
    cout << cost[x[i]] + cost[y[i]] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 13424
def main():
    N=int(input())
    S=[input()for _ in range(N)]
    T=["".join(s) for s in zip(*S)]
    ans=0
    for i in range(N):
        if all(s==t for s,t in zip(S,T)):
            ans+=1
        S=[s[-1]+s[:-1] for s in S]
        T=[T[-1]]+T[:-1]
    print(ans*N)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
n = int(input())
z = [0] * n
for i in range(n):
  x,y,h = map(int,input().split())
  if h != 0:
    k = [x,y,h]
  z[i] = [x,y,h]
for i in range(101):
  for j in range(101):
    H = k[2] + abs(k[0]-i) + abs(k[1]-j)
    for l in z:
      if l[2] != max(H-abs(l[0]-i)-abs(l[1]-j),0):
        break
      if l == z[-1]:
        print(i,j,H)
        exit()

Measured memory_bytes: 3064