akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
"""
Signboard
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0578

"""
import sys


def solve(target_name, n):
    ans = 0
    for _ in range(n):
        signboard = input()
        found = False
        for st in [i for i, ch in enumerate(signboard) if ch == target_name[0]]:
            if found:
                break
            gap = 1
            while True:
                x = signboard[st::gap]
                if len(x) < len(target_name):
                    break
                if x.startswith(target_name):
                    found = True
                    break
                gap += 1
        ans += found
    return ans


def main(args):
    n = int(input())
    s = input()
    ans = solve(s, n)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])



Measured memory_bytes: 5632
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int num[] =new int[n];
        for(int i=0;i<n;i++){
            num[i]=sc.nextInt();
        }
        Arrays.sort(num);
        double ans=(double) (num[0]+num[1])/2;
        for(int i=2;i<n;i++){
            ans= (double) (ans+num[i])/2;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

class UnionFind {
private:
	unsigned size_; 
	std::vector<unsigned> par, rank;
public:
	UnionFind() : size_(0), par(std::vector<unsigned>()), rank(std::vector<unsigned>()) {};
	UnionFind(unsigned size__) : size_(size__) {
		par.resize(size_); rank.resize(size_);
		for (unsigned i = 0; i < size_; i++) par[i] = i, rank[i] = 0;
	}
	unsigned size() { return size_; }
	//unsigned root(unsigned x) { return par[x] == x ? x : par[x] = root(par[x]); }
	unsigned root(unsigned x)
	{
		while(par[x] != x)
		{
			par[x] = par[par[x]];
			x = par[x];
		}
		return x;
	}
	bool same(unsigned x, unsigned y) { return root(x) == root(y); }
	void unite(unsigned x, unsigned y) {
		x = root(x), y = root(y);
		if (x == y) return;
		if (rank[x] < rank[y]) par[x] = y;
		else if (rank[x] == rank[y]) par[y] = x, rank[x]++;
		else par[y] = x;
	}
	bool operator==(const UnionFind &u) { return par == u.par; }
	bool operator!=(const UnionFind &u) { return par != u.par; }
};

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int N;
	
	cin >> N;

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

	int total = B[0] + B[N-2];

	rep(i, N-2)
	{
		total += min(B[i], B[i+1]);
	}

	cout << total << endl;

	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(5)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<short, short> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 1145141919;
const int MOD = 100000007;
const double EPS = 1e-10;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator > (const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///


int main()
{
	string s; int n;
	cin >> s >> n;
	ll mul = 0; ll ltr = s[0]-'0';
	int l = s.size();
	FOR(i,2, l)
	{
		if (isdigit(s[i]))
		{
			if (s[i - 1] == '+') ltr += s[i]-'0';
			else ltr *= s[i]-'0';
		}
	}
	vector<ll> v;
	REP(i, l)
	{
		if (isdigit(s[i])) v.push_back(s[i] - '0');
		else if (s[i] == '+') v.push_back(-1);
		else v.push_back(-2);
	}
	bool update = true;
	while (update)
	{
		update = false;
		REP(i, v.size())
		{
			if (v[i] == -2)
			{
				update = true;
				v[i - 1] = v[i - 1] * v[i + 1];
				v.erase(v.begin() + i);
				v.erase(v.begin() + i);
			}
		}
	}
	REP(i, v.size()) if (v[i] >= 0) mul += v[i];

	if (n == mul&&n == ltr) puts("U");
	else if (n == mul) puts("M");
	else if (n == ltr) puts("L");
	else puts("I");
	return 0;
}

Measured memory_bytes: 1200
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
from collections import deque
import heapq

t = int(input())
for _ in range(t):
    n, a, b, c, d = map(int, input().split())
    hq = []
    memo = dict()
    memo[n] = 0
    heapq.heappush(hq, -n)
    while hq:
        val = -heapq.heappop(hq)
        for base, cost in zip([2, 3, 5], (a, b, c)):
            diff = val % base
            nval_p = val // base
            if nval_p in memo:
                # use half div
                memo[nval_p] = min(memo[nval_p], memo[val] + cost + d * diff)
                # walk
                memo[nval_p] = min(memo[nval_p], memo[val] + (val - nval_p) * d)
            else:
                heapq.heappush(hq, -nval_p)
                # use half div
                memo[nval_p] = min(memo[val] + cost + d * diff, memo[val] + (val - nval_p) * d)
            if val % base != 0:
                nval_n = ((val - diff + base) // base)
                if nval_n in memo:
                    memo[nval_n] = min(memo[nval_n], memo[val] + cost + d * (base - diff))
                    # walk
                    memo[nval_n] = min(memo[nval_n], memo[val] + (val - nval_n) * d)
                else:
                    heapq.heappush(hq, -nval_n)
                    memo[nval_n] = min(memo[val] + cost + d * (base - diff), memo[val] + (val - nval_n) * d)
    print(memo[0])

Measured memory_bytes: 84616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
int f(string s) {
    string hh, mm, ss;
    hh = s.substr(0, 2);
    mm = s.substr(3, 2);
    ss = s.substr(6, 2);
    return 3600 * stoi(hh) + 60 * stoi(mm) + stoi(ss);
}
int main() {
    while (1) {
        int n;
        cin >> n;
        if (!n) return 0;
        vector<int> v(90001);
        rep(i, n) {
            string s, t;
            cin >> s >> t;
            v[f(s)]++;
            v[f(t)]--;
        }
        int ans = 0;
        rep(i, 90000) {
            v[i + 1] += v[i];
            chmax(ans, v[i]);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3496
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
const int N=2e5+3;
//string s,p;
//vector<int>v;
//map<int,int>mp;

int main()
{
    ft
    ll t,i,j,n,m,l,r,s=0;
    cin>>n>>m>>l>>r;
    for(i=0;i<min(n,m);i++)
    {
        s+=l;
    }
    for(;i<n;i++)
    {
        s+=r;
    }
    cout<<s<<"\n";
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX_V 1e3 + 1
#define INF 1e9 + 1
using namespace std;
using ll = long long;
typedef pair <int, int> item;

int main()
{	
	int n, w;
	ll sum_values = 0;
	cin >> n >> w;
	vector <item> items;
	vector<vector<ll>> dp(n + 1, vector<ll> (n * MAX_V, INF));
	items.push_back({0, 0});
	for (int i = 1; i <= n; i++) {
		item x;
		cin >> x.first >> x.second;
		items.push_back(x);
		sum_values += x.second;
	}

	dp[0][0] = 0;
	for (int i = 1; i <= n; i++) {

		for (int j = 0; j < items[i].second; j++) {
			dp[i][j] = dp[i - 1][j];
		}

		for (int j = items[i].second; j <= sum_values; j++) {
			
			dp[i][j] = min(dp[i - 1][j - items[i].second] + items[i].first, dp[i - 1][j]);
			
		}
	}

	int max_value = -1;

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= sum_values; j++) {

			if (dp[i][j] <= w) {
				max_value = max(max_value, j);
			}
		}
	}

	cout << max_value;
	return 0;	
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;

struct int_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

struct pair_hash {
    size_t operator()(pair<int, int> x) const {
        return int_hash{}(x.first) ^ (int_hash{}(x.second) << 16);
    }
};

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

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e7;
const int MX = 100001; //check the limits, dummy

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

    int n, k; cin >> n >> k;
    vector<double> v(n);
    for(double &i : v) cin >> i;

    double sum = 0;
    for(int i = 0; i < k; i++)
        sum += (v[i] + 1) / 2;

    double ans = sum;
    for(int i = k; i < n; i++) {
        sum += (v[i] + 1) / 2;
        sum -= (v[i - k] + 1) / 2;
        ans = max(ans, sum);
    }

    cout << fixed << setprecision(12) << ans << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string S;
    cin >> S;
    int ans = 0;
    vector<string> W = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
    if (S == W[0]) ans = 7;
    else if (S == W[1]) ans = 6;
    else if (S == W[2]) ans = 5;
    else if (S == W[3]) ans = 4;
    else if (S == W[4]) ans = 3;
    else if (S == W[5]) ans = 2;
    else if (S == W[6]) ans = 1;

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

	/**
	 * @param args
	 */
	public static int MOD = 1_000_000_007;
	
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int h= sc.nextInt();
		int w = sc.nextInt();
		long[][] ans = new long[h][w];
		ans[0][0]=1;
		for (int i=0;i<h;i++) {
			String str = sc.next();
			for (int j=0;j<w;j++) {
				if (str.charAt(j)=='.') {
					if (i>0) {
						ans[i][j]+=ans[i-1][j];
					}
					if (j>0) {
						ans[i][j]+=ans[i][j-1];
					}
					ans[i][j]%=MOD;
				}
			}
		}
		System.out.println(ans[h-1][w-1]);
	}

}


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

#define size 100002
bool vis[size];
ll dis[size];

stack<ll>S;

void dfs(vector< list<ll> >&G,ll s)
{
	vis[s]=1;
	for(auto it=G[s].begin();it!=G[s].end();it++)
	{
		if(!vis[*it])
			dfs(G,*it);
	}
	S.push(s);
}

int main()
{
	ios::sync_with_stdio(false);
	ll V,E,i;
	cin >> V >> E;
	vector< list<ll> >G(V);
	for(i=0;i<V;i++)
	{
		G[i].clear();
		vis[i]=0;
		dis[i]=0;
	}
	for(i=0;i<E;i++)
	{
		ll m,n;
		cin >> m >> n;
		G[m-1].push_back(n-1);
	}
	for(i=0;i<V;i++)
	{
		if(!vis[i])
			dfs(G,i);
	}
	while(!S.empty())
	{
		ll u=S.top();
		S.pop();
		for(auto it=G[u].begin();it!=G[u].end();it++)
		{
			if(dis[*it]<=dis[u]+1)
			{
				dis[*it]=dis[u]+1;
			}
		}
	}
	ll ans=0;
	for(i=0;i<V;i++)
		ans=max(ans,dis[i]);
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) {}
#endif



int main(){
	string s, t;
	cin >> s;
	cin >> t;
	int len = s.size();
	
	ll ct = 0;
	rep(i,len){
		if ( s[i] != t[i] )
			ct++;
	}
	
	cout << ct << endl;
	
	
	return 0;
}




Measured memory_bytes: 3844
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

string s;
int n, K, dp[310][310][310];

int dfs(int l, int r, int t){
    if(dp[l][r][t] >= 0) return dp[l][r][t];
    if(l == r) return dp[l][r][t] = 0;
    if(r-l == 1) return dp[l][r][t] = 1;
    int ret = max(dfs(l+1, r, t), dfs(l, r-1, t));
    if(s[l] == s[r-1]) chmax(ret, 2 + dfs(l+1, r-1, t));
    else if(t > 0) chmax(ret, 2 + dfs(l+1, r-1, t-1));
    return dp[l][r][t] = ret;
}

int main(){
    cin >> s >> K;
    int n = s.size();
    rep(i, n+1)rep(j, n+1)rep(k, K+1) dp[i][j][k] = -1;
    printf("%d\n", dfs(0, n, K));
}

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

#define all(x) (x).begin(), (x).end()
#define pb push_back

typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;

int main(){
	int n,y;
	cin>>n>>y;
	for (int i = 0; i <= n; ++i){
		for (int j = 0; i+j <= n; ++j){
			int k=n-i-j;
			if(10000*i+5000*j+1000*k==y){
				cout<<i<<' '<<j<<' '<<k<<endl;;
				return 0;
			}
		}
	}

	cout<<"-1 -1 -1"<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define all(a)  (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

int main(){
  int n; cin >> n;
  vi x(n), y(n), h(n);
  int index;
  rep(i, n){
    cin >> x[i] >> y[i] >> h[i];
    if(h[i] > 0) index = i;
  }

  rep(px, 101) rep(py, 101){
    int ph = h[index] + abs(x[index] - px) + abs(y[index] - py);
    bool ok = true;
    rep(i, n){
      int tmp = max(ph - abs(x[i] - px) - abs(y[i] - py), 0);
      if(tmp != h[i]) ok = false;
    }
    if(ok) printf("%d %d %d\n",px, py, ph);
  }
}


Measured memory_bytes: 256
(function(undefined){
	'use strict';
	(function init() {
		this.output = function() {
			console.log.apply( console, arguments );
		};
		this.stdin = process.openStdin();
		stdin.setEncoding('utf8');
		this.input_list = [];
		stdin.on('data', function(chunk){
			var result = chunk.match(/\d+/g);
			input_list = input_list.concat(result);
		});
		this.input_number = function() {
			return parseInt( input_list.splice(0,1)[0] );
		};
	}).call( this );
	(function solver(){
		function sq(x) {
			return x * x;
		}
		function check(v) {
			return sq(v.a)+sq(v.b)===sq(v.c)
			|| sq(v.b)+sq(v.c)===sq(v.a)
			|| sq(v.c)+sq(v.a)===sq(v.b);
		}
		setTimeout( function solve() {
			var n = input_number();
			var vertexes = [];
			while ( n -- )
				vertexes.push({
					a: input_number(),
					b: input_number(),
					c: input_number()
				});
			vertexes.forEach(function(vertex){
				output( check(vertex) ? 'YES' : 'NO' );
			});
		}, 0 );
	})();
}).call(global);

Measured memory_bytes: 10644
#include <stdio.h>
int main(void){
    // Your code here!
    int N,K,num=0;
    
    scanf("%d %d",&N,&K);
    
    if(N%2==0){
        if(N/2>=K){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }else{
        if((N+1)/2>=K){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
}

Measured memory_bytes: 128
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using ull=unsigned long long int;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
  ll a,b,c;
  cin>>a>>b>>c;
  if(60%(a+b)==0){
    if(c%(a+b)<=a){
      cout<<c<<"\n";
    }else cout<<-1<<"\n";
    return 0;
  }
  while(1){
    if(c%(a+b)<=a){
      cout<<c<<"\n";
      break;
    }
    c+=60;
    if(c>=100000000){
      cout<<-1<<"\n";
      break;
    }
  }
}


Measured memory_bytes: 3232
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <deque>
#include <map>
using namespace std;

#define ii pair <int, int>
#define lli long long
#define pb push_back
#define X first
#define Y second

const int Mod = 1E9 + 7;
const int Inf = 1E9 + 7;
const int N = 1e3 + 10;
int n, m, d[N][N];
ii S, T;
char a[N][N];

void Input()
{
    cin >> n >> m;
    cin >> S.X >> S.Y;
    cin >> T.X >> T.Y;
    for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j];
}

bool Inside(ii x)
{
    return 1 <= x.X && x.X <= n && 1 <= x.Y && x.Y <= m && a[x.X][x.Y] == '.';
}

bool UseMagic(ii Here, ii Next)
{
    return abs(Here.X - Next.X) + abs(Here.Y - Next.Y) > 1;
}

void Solve()
{
    deque <ii> DQ;
    DQ.push_back(S);

    for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) d[i][j] = Inf;
    d[S.X][S.Y] = 0;

    while (DQ.size()) {
        ii u = DQ.front();
        DQ.pop_front();

        for (int i = -2; i <= 2; i++)
        for (int j = -2; j <= 2; j++) {
            ii v = {u.X + i, u.Y + j};
            if (Inside(v) && d[v.X][v.Y] > d[u.X][u.Y]) {
                if (!UseMagic(u, v)) {
                    d[v.X][v.Y] = d[u.X][u.Y];
                    DQ.push_front(v);
                }
                else {
                    d[v.X][v.Y] = d[u.X][u.Y] + 1;
                    DQ.push_back(v);
                }
            }
        }
    }

    if (d[T.X][T.Y] == Inf) cout << -1;
    else cout << d[T.X][T.Y];
}

#define task "test"
int main()
{
    if (fopen(task ".inp", "r")) {
        freopen(task ".inp", "r", stdin);
        freopen(task ".out", "w", stdout);
    }
    int testcase = 1;
    /// cin >> testcase;
    while (testcase--) {
        Input();
        Solve();
    }
}




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

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  return ret;
}

int main() {
  ll n;
  cin >> n;
  vector<ll> a = divisor(n);
  int ans      = INT_MAX;
  for (int i = 0; i < a.size(); i++) {
    ll b    = max(a[i], n / a[i]);
    int cnt = 0;
    while (b) {
      b /= 10;
      cnt++;
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
s=str(input())
temp=list(s)
if temp[0]=="A":
  del temp[len(s)-1]
  del temp[1]
  del temp[0]
  c=temp.count("C")
  if c==1:
    s=s.replace("A","")
    s=s.replace("C","")
    if s.islower()==True:
      print("AC")
    else:
      print("WA")
  else:
    print("WA")
else:
  print("WA")

Measured memory_bytes: 3060
/*
ツつアツづ個姪「ツ妥ィツづ?づ債、ツヒツδ督トツづ?与ツつヲツづァツづェツづ?つ「ツづゥツ津環づィツ、ツ行ツ青板つェツ療アツ青板づ可氾、ツづ猟づ?氾アツ湘ュツづ可渉ュツづ按つ「ツづ?つキツ。
ツ行ツ青板づ個催?妥・ツつェ10ツづ?つ「ツつ、ツ点ツづ可陳債姪堋つオツづ慊つオツづ・ツつ、ツ。
ツ各ツ行ツづーツづ青づ?つュツづィツ陛板つキツつゥツづ青づ?つュツづィツ陛板つウツづ按つ「ツつゥツづ?つ「ツつ、ツ篠篠行ツづーツ、2^10ツづ個計ツ算ツ療環づ?偲?個サツづ?つォツづ慊つキツ。

ツつウツづ?、ツ各ツ行ツづーツづ青づ?つュツづィツ陛板つキツつゥツづ青づ?つュツづィツ陛板つウツづ按つ「ツつゥツつェツ個按づ慊づ?づ?つ「ツづゥツづ?可スツつェツつ、ツづェツつオツつ「ツづ?つオツづ・ツつ、ツつゥツ。
ツ各ツ療アツづーツ個ゥツつスツづ?つォツ、ツつサツづ個療アツづーツづ青づ?つュツづィツ陛板つキツつゥツづ青づ?つュツづィツ陛板つウツづ按つ「ツつゥツ、ツづ?づ?つソツつェツつ、ツづェツつオツつ「ツづ個つゥツづー
ツつキツつョツ仰?づ淞づゥツつアツづ?つェツづ?つォツづゥツづヲツつ、ツづ可づ按づィツづ慊つキツ。

ツ療。ツつヲツづ篠、ツ篠淞づ個づヲツつ、ツづ按つケツづアツづ猟つ「ツつェツ与ツつヲツづァツづェツつスツづ?つオツづ慊つキツ。

ツ?崢?慊?崢?慊??
ツ?慊?崢?崢?崢??

ツつアツづ個づ?つォツ、
ツ・1ツ行ツ姪堋づーツづ青づ?つュツづィツ陛板つキツつゥツづ青づ?つュツづィツ陛板つウツづ按つ「ツつゥツ、
ツ・2ツ行ツ姪堋づーツづ青づ?つュツづィツ陛板つキツつゥツづ青づ?つュツづィツ陛板つウツづ按つ「ツつゥツ、
ツづーツ催?帰ツづ可づヲツづィツ全ツ探ツ催オツつオツづ?個按津ィツつオツづ?づ「ツづィツづ慊つキツ。

ツつアツつアツづ?づ債、
ツ・1ツ行ツ姪堋づーツづ青づ?つュツづィツ陛板つキ
ツ・2ツ行ツ姪堋づーツづ青づ?つュツづィツ陛板つウツづ按つ「
ツづ?つ「ツつ、ツ湘ェツ債?づーツ考ツつヲツづ慊つオツづ・ツつ、ツ。

ツつサツつ、ツつキツづゥツづ?つケツづアツづ猟つ「ツづ個湘ウツ妥板づ債篠淞づ個づヲツつ、ツづ可陛渉づュツづィツづ慊つキツ。

ツ?慊?崢?慊?崢??
ツ?慊?崢?崢?崢??

ツつアツつアツづ?、ツ各ツ療アツづーツ個ゥツづ?つ「ツつォツづ慊つオツづ・ツつ、ツ。
1ツ療アツ姪堋づ債、ツづ青づ?つュツづィツ陛板つオツつスツ陛サツつェツつ「ツつ「ツつゥツ、ツづ青づ?つュツづィツ陛板つウツづ按つ「ツ陛サツつェツつ「ツつ「ツつゥツづ?つソツづァツづ?つオツづ・ツつ、ツ。
ツ?慊づ個青板づ個陛サツつェツ堕スツつ「ツづ個づ?つ?つォツづァツつゥツづ可づ青づ?つュツづィツ陛板つオツつスツ陛サツつェツつ「ツつ「ツづ?つキツづ仰。
ツつアツづ個づヲツつ、ツづ可、ツ各ツ行ツづーツづ青づ?つュツづィツ陛板つキツつゥツづ青づ?つュツづィツ陛板つウツづ按つ「ツつゥツづーツ個按づ淞づ?つィツつッツづ篠、
ツつ?づ?づ債、ツ各ツ療アツづーツづ青づ?つュツづィツ陛板つキツつゥツづ青づ?つュツづィツ陛板つウツづ按つ「ツつゥツづ債篠ゥツ督ョツ的ツづ可仰?づ慊づィツづ慊つキツ。

ツ・2ツ療アツ姪堋?ィツづ青づ?つュツづィツ陛板つウツづ按つ「
ツ・3ツ療アツ姪堋?ィツづ青づ?つュツづィツ陛板つオツづ?づ?づ青づ?つュツづィツ陛板つウツづ按つュツづ?づ?づ?つソツづァツづ?づ?つ「ツつ「
ツ・4ツ療アツ姪堋?ィツづ青づ?つュツづィツ陛板つウツづ按つ「
ツ・5ツ療アツ姪堋?ィツづ青づ?つュツづィツ陛板つキ

ツ?崢?崢?慊?崢??
ツ?崢?崢?崢?崢??

ツづヲツづ?づ?督堋つヲツづ?ツづ?つキツ。

 */
#include <iostream>
using namespace std;

int h, w, ans;
int t[12][10002];
bool flg[12];

//ツ各ツ行ツづーツづ青づ?つュツづィツ陛板つキツつゥツつェツ個按づ慊づ?づ?つ「ツづゥツづ?つォ, ツ各ツ療アツづーツづ青づ?つュツづィツ陛板つオツつスツ陛サツつェツつ「ツつ「ツつゥツ仰?づ淞づゥ
//ツ催?妥・ツづ個青カツつォツ残ツづゥツつケツづアツづ猟つ「ツづーツ姪淞づィツ値ツづ?つオツづ?陛板つキ
int getMaxAlive(){
  int res = 0;

  for(int x = 0; x < w; x++){
    int colSum = 0;

    for(int y = 0; y < h; y++){
      if(flg[y]){
        colSum += !t[y][x];
      }
      else{
        colSum += t[y][x];
      }
    }

    res += max(colSum, h - colSum);
  }

  return res;
}

//ツ催?帰ツづ可づヲツづィツ各ツ行ツづーツづ青づ?つュツづィツ陛板つキツつゥツ個按づ淞づ慊つキ
void rec(int y){
  if(y == h){
    ans = max(ans, getMaxAlive());
    return;
  }

  //ツづ青づ?つュツづィツ陛板つウツづ按つ「
  flg[y] = 0;
  rec(y + 1);

  //ツづ青づ?つュツづィツ陛板つキ
  flg[y] = 1;
  rec(y + 1);
}

int main(){
  while(cin >> h >> w, h || w){
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
        cin >> t[i][j];
      }
    }

    ans = 0;
    rec(0);
    cout << ans << endl;
  }
}

Measured memory_bytes: 1260
#include <stdio.h>
int main(){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  if(a>=b)if(a>=c){
    printf("%d",10*a+b+c);
    return 0;
  }
  if(b>=a)if(b>=c){
    printf("%d",10*b+a+c);
    return 0;
  }
  if(c>=b)if(c>=a){
    printf("%d",10*c+b+a);
    return 0;
  }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    unsigned long long  n,m;
    cin >> n >> m;
    if(n > m){
        swap(n,m);
    }
    if(n > 1 && m > 1){
        cout << (n-2) * (m-2) << endl;
    }else if (n == 1 && m == 1){
        cout << 1 << endl;
    }else if ((n == 1 && m > 1)){
        cout << m - 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;

const long long INF = 1LL<<60;

// 最長増加部分列の長さを求める
int LIS(const vector<long long> &a) {
    int N = (int)a.size();
    vector<long long> dp(N, INF);
    for (int i = 0; i < N; ++i) {
        // dp[k] > a[i] となる最小のイテレータを見つける
        auto it = lower_bound(dp.begin(), dp.end(), a[i]+1);

        // そこを a[i] で書き換える
        *it = a[i];
    }

    // dp[k] < INF となる最大の k に対して k+1 が答え
    // それは dp[k] >= INF となる最小の k に一致する
    return lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
}
int main(){


    int N;
    cin>>N;
    vector<ll> A(N);
    repr(i,N){
        cin>>A[i];
    }
    cout<<LIS(A)<<endl;

return 0;
}

Measured memory_bytes: 4764
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	while (a%b != 0)
	{
		int c = a%b;
		a = b;
		b = c;
	}
	cout << b << endl;
	return 0;
}


Measured memory_bytes: 3108
/* ex 7_3
   kanon */

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    //与えられる値を入れる数を宣言
    int i, j, height, width, *row_bool, *column_bool, flag = 0;
    char **ptr;

    //変数に値を入力する
    scanf("%d %d", &height, &width);

    //行と列のbool配列を作りメモリの動的確保
    row_bool = (int *)calloc(height, sizeof(int));
    if (row_bool == NULL)
    {
        fprintf(stderr, "calloc error.\n");
        exit(1);
    }

    column_bool = (int *)calloc(width, sizeof(int));
    if (column_bool == NULL)
    {
        fprintf(stderr, "calloc error.\n");
        exit(1);
    }

    //各行の配列へのポインタ分のメモリ領域を確保
    ptr = (char **)calloc(height, sizeof(char *));
    if (ptr == NULL)
    {
        fprintf(stderr, "calloc error.\n");
        exit(1);
    }

    //ptrの各行の要素分のメモリ領域を確保
    for (i = 0; i < height; i++)
    {
        ptr[i] = (char *)calloc(width, sizeof(char));
        if (ptr[i] == NULL)
        {
            fprintf(stderr, "calloc error.\n");
            exit(1);
        }
    }

    for (i = 0; i < height; i++)
    {
        scanf("%s", ptr[i]);
    }

    //行と列のbool配列の要素を１に揃える
    for (i = 0; i < height; i++)
        row_bool[i] = 1;
    for (i = 0; i < width; i++)
        column_bool[i] = 1;

    //完全に.のみの行と列を見つける
    for (i = 0; i < height; i++)
    {
        flag = 1;
        for (j = 0; j < width; j++)
        {
            if (ptr[i][j] != '.')
                flag = 0;
        }
        //完全に.のみの行はfalseに変える
        if (flag)
            row_bool[i] = 0;
    }

    for (i = 0; i < width; i++)
    {
        flag = 1;
        for (j = 0; j < height; j++)
        {
            if (ptr[j][i] != '.')
                flag = 0;
        }
        //完全に.のみの列はfalseに変える
        if (flag)
            column_bool[i] = 0;
    }

    //答えを出力
    for (i = 0; i < height; i++)
    {
        if (row_bool[i])
        {
            for (j = 0; j < width; j++)
            {
                if (column_bool[j])
                {
                    printf("%c", ptr[i][j]);
                }
            }
            printf("\n");
        }
    }

    //メモリ領域の解放，各行の要素分の領域を開放し，
    //各行の配列へのポインタの領域を解放
    //（メモリ領域の確保と逆順）
    for (i = 0; i < height; i++)
    {
        free(ptr[i]);
    }
    free(ptr);
    free(row_bool);
    free(column_bool);

    return 0;
}


Measured memory_bytes: 1628
#import math
#import bisect
#import numpy as np
#import itertools
#import copy
import sys

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

def main():
    n = int(input())
    a = list(map(int,ipti().split()))
    b = list(map(int,ipti().split()))

    ans = 0
    for i in range(n):
        herorem = b[i]
        if a[i] < herorem:
            herorem -= a[i]
            ans += a[i]
            a[i] = 0
            if a[i+1] < herorem:
                herorem -= a[i+1]
                ans += a[i+1]
                a[i+1] = 0
            else:
                ans += herorem
                a[i+1] -= herorem
        else:
            ans += herorem
            a[i] -= herorem

    print(ans)



if __name__ == '__main__':
    main()

Measured memory_bytes: 73316
////////////////////////////////////////////////////////////////////
// This source code is for Visual Studio
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <stack>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <deque>
#include <math.h>

#define	numberof(a)	(sizeof(a) / sizeof(a[0]))
#define	INF		UINT64_MAX
#define Rep(i,n) for(int i = 0; i < (n); ++i )

using namespace std;

typedef vector< vector<int> > MAT;
typedef pair<int, int> PINT;
typedef long long ll;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int32_t s32;
typedef int64_t s64;

////////////////////
// 回文判定 O(N)
////////////////////
bool isPalindrome(string input_str)
{
	bool ret = true;
	ll i = 0;
	ll j = input_str.length() - 1;

	while (ret && i <= j) {
		ret = ret & (input_str[i] == input_str[j]);
		i++;
		j--;
	}
	return ret;
}

ll solve(string input_str)
{
	ll ret = 0;
	ll i = 0;
	ll j = input_str.length() - 1;

	while (i <= j) {
		if (input_str[i] == input_str[j]) {
			i++;
			j--;
		}
		else{
			if (input_str[i] == 'x') {
				i++;
				ret++;
			}
			else if (input_str[j] == 'x') {
				j--;
				ret++;
			}
		}
	}
	return ret;
}

int main()
{
	stringstream ss("");
	string S = "";
	string modified_str = "";
	string tmp = "";
	ll num_of_x = 0;
	ll ret = 0;	// oxxx

	cin >> S;
	ll len = S.length();

	if (isPalindrome(S) == true) {
		// すでに回文
		ret = 0;
	}
	else {
		// 回文になるか判定
		Rep(i, len) {
			if (S[i] == 'x') {
				tmp += ' ';
				num_of_x++;
			}
			else {
				tmp += S[i];
			}
		}
		ss << tmp;

		// 'x'を取り除いた文字列を作成
		while (ss >> tmp) {
			modified_str += tmp;
		}

		if (isPalindrome(modified_str) == true) {
			// 回文になる
			ret = solve(S);
		}
		else {
			// 回文にならない
			ret = -1;
		}
	}

	cout << ret << endl;

	return 0;
}





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

std::pair<int,int> tmp[100000];

int main(){
  std::string b;
  std::cin>>b;
  for(int i=0;i<(int)b.length();++i){
    if(b[i]=='A'){
      std::cout<<'T';
    }else if(b[i]=='C'){
      std::cout<<'G';
    }else if(b[i]=='G'){
      std::cout<<'C';
    }else if(b[i]=='T'){
      std::cout<<'A';
    }
  }
  std::cout<<std::endl;
  return 0;
}



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

#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define str string
#define vint vector<int>
#define vvint vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vool vector<bool>
#define vtr vector<str>
#define vvtr vector<vector<str>>
#define pb() pushback()
#define elif else if
#define all(x) x.begin(),x.end()

int shizuku(int,int);

int main(){
    int N,X,b,H=0,W=0,count=0,count2=0;
    double d,D;
    int C='A'-'a';
    char op;
    str S,T;
    cin>>N;
    int info[N][4]={},ittou[3][10]={},nitou[3][10]={},santou[3][10]={},yontou[3][10]={};
    rep(0,N){
      REP(0,4){
        cin>>info[i][j];
      }
      if(info[i][0]==1)ittou[info[i][1]-1][info[i][2]-1]+=info[i][3];
      if(info[i][0]==2)nitou[info[i][1]-1][info[i][2]-1]+=info[i][3];
      if(info[i][0]==3)santou[info[i][1]-1][info[i][2]-1]+=info[i][3];
      if(info[i][0]==4)yontou[info[i][1]-1][info[i][2]-1]+=info[i][3];
    }
    rep(0,3){
      REP(0,10){
        cout<<" ";
        cout<<ittou[i][j];
      }
      cout<<endl;
    }
    rep(0,20)cout<<"#";
    cout<<endl;
    rep(0,3){
      REP(0,10){
        cout<<" ";
        cout<<nitou[i][j];
      }
      cout<<endl;
    }
    rep(0,20)cout<<"#";
    cout<<endl;
    rep(0,3){
      REP(0,10){
        cout<<" ";
        cout<<santou[i][j];
      }
      cout<<endl;
    }
    rep(0,20)cout<<"#";
    cout<<endl;
    rep(0,3){
      REP(0,10){
        cout<<" ";
        cout<<yontou[i][j];
      }
      cout<<endl;
    }
}



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

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

	bool ans = true;

	vector<int> vec(n);
	for (int i = 0; i < n; i++) {
		cin >> vec.at(i);
	}
	for (int i = 0; i < n; i++) {
		if (vec.at(i) % 2 == 0) {
			if (vec.at(i) % 3 != 0 && vec.at(i) % 5 != 0) ans = false;
		}
	}
	if (ans) cout << "APPROVED" << endl;
	else cout << "DENIED" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <cctype>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define du(x) cout<<#x<<'='<<x<<endl
#define du2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define du3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf());

int main() {

    int N;
    cin >> N;

    for (int a = 0; a <= 100; a += 4) {
        for (int b = 0; b <= 100; b += 7) {
            if (a + b == N) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

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

int main() {
  char a;
  cin >> a;
  if ('a' <= a && a <= 'z')
    cout << 'a' << endl;
  else
    cout << 'A' << endl;

  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll x;
	cin>>x;
	ll z=(x/500);
	x=x%500;
	ll z2=(x/5);
	cout<<(z*(ll)1000+z2*(ll)5)<<"\n";
	return 0;
}

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

int main(){
  int n,m; 
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m); 
  int ans = -1; 
  for(int i=0;i<m;i++){
    cin >> s[i] >> c[i];
  }
  int min;
  int max;
  if(n==2){
    min = 10;
    max = 99;
  }else if(n==3){
    min = 100;
    max = 999;
  }else{
    min = 0;
    max = 9;
  }
  vector<int> dig(3);
  int w =0;
  for(int i=min;i<=max;i++){
    w=0;
    for(int j=0;j<m;j++){
      if(n==1){
        dig[0]=i;
      }else if(n==2){
        dig[0]=i/10;
        dig[1]=i%10;
      }else{
        dig[0]=i/100;
        dig[1]=(i/10)%10;
        dig[2]=(i%100)%10;
      }
      if(dig[s[j]-1]!=c[j]){
        w = 1;
        break;
      }
    }
    if(w==0){
      ans = i;
      break;
    }
  }
  cout << ans;
}




Measured memory_bytes: 256
N, M = map(int, input().split())
photo_a = [list(input()) for _ in range(N)]
photo_b = [list(input()) for _ in range(M)]

for i in range(N):
  if i + M > N:
    break
  for j in range(N):
    if j + M > N:
      break
    same = True
    for k in range(i, i+M):
      for l in range(j, j+M):
        if photo_a[k][l] != photo_b[k-i][l-j]:
          same = False
          break
      else:
        continue
      break
    if same:
      print('Yes')
      exit()
print('No')

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifdef LOCAL
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#else
#define debug(x) ;
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int n, k, a[110];

  scanf("%d%d", &n, &k);

  for(int i=0;i<n;i++){
    scanf("%d", a+i);
  }

  int grundy[SIZE];

  for(int i=1;i<=k;i++){
    bool exist[110] = {};

    for(int j=0;j<n;j++){
      if(i-a[j] >= 0) exist[grundy[i-a[j]]] = true;
    }

    for(int j=0;j<=n;j++){
      if(!exist[j]) {
        grundy[i] = j;
        break;
      }
    }
  }

  cout << (grundy[k] ? "First" : "Second") << endl;

  return 0;
}


Measured memory_bytes: 640
from math import sqrt

i = 0
for a in range(1,100):
    for b in range(1, 100):
        for c in range(1, 100):
            if (a*a + b*b + c*c > 2*a*b + 2*b*c + 2*c*a) and (sqrt(a) + sqrt(b) > sqrt(c)):
               #print(a,b,c, "Jee");
               i+=1


a,b,c = input().split()

a = int(a)
b = int(b)
c = int(c)

if(a > c or b > c):
    print("No")

elif (a*a + b*b + c*c > 2*a*b + 2*b*c + 2*c*a):
    print("Yes")
else:
    print("No")


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

int main() {
  int N;
  long long a, b;
  bool be0;
  be0 = false;
  cin >> N >> a;
  N--;
  for(int i = 0; N > i; i++) {
    cin >> b;
    a *= b;
    if (be0 == false && b == 0) {
      be0 = true;
    }
	if (a > 1000000000000000000){
      a = 0;
  }
  }
  if(a == 0 && be0 == false) {
        a = -1;
  }
  cout << a << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    ll x;
    cin >> x;
    ll ans = 0;
    ans += (x / 500) * 1000;
    x %= 500;
    ans += (x / 5) * 5;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
#include<stdio.h>
#include<string.h>
#define SIZE 1000
int main(){

  int i,j;
  int na,nb,nc,n;
  int a[SIZE],b[SIZE],c[SIZE],d[SIZE],data[SIZE];

  while(1){
  scanf("%d %d %d",&na,&nb,&nc);
  if(na==0 && nb==0 && nc==0)break;
  scanf("%d",&n);

  for(i=1;i<=na+nb+nc;i++)data[i]=2;
  for(i=0;i<n;i++){
    scanf("%d %d %d %d",&a[i],&b[i],&c[i],&d[i]);
    if(d[i]==1){
      data[a[i]]=data[b[i]]=data[c[i]]=1;
    }
  }
  
  for(i=0;i<n;i++){
    if(d[i]==0){
      if(data[a[i]]==1 && data[b[i]]==1)data[c[i]]=0;
      else if(data[a[i]]==1 && data[c[i]]==1)data[b[i]]=0;
      else if(data[b[i]]==1 && data[c[i]]==1)data[a[i]]=0;
    }
  }
  
  for(i=1;i<=na+nb+nc;i++){
    printf("%d\n",data[i]);
  }
}
  return 0;
}

Measured memory_bytes: 620
#include <iostream>
#include <fstream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <utility>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <sstream>
#include <cstring>
#include <bitset>
#include <stack>
using namespace std;
#define MP make_pair
#define PB push_back
const long long mod=1e9+7LL;

inline long long p(long long x)
{
	long long res=1LL;
	for (long long i=1LL;i<=x;i++)
	{
		res*=i;
		res=res%mod;
	}
	return res;
}

int main()
{
	long long n,m;
	cin>>n>>m;
	long long pn=p(n);
	long long pm=p(m);
	if (n<m) swap(n,m);
	if (n-m>=2LL) 
	{
		cout<<0;
	}
	else
	{
		long long ans;
		if (n==m) 
		{
			ans=pn*pm;
			ans=ans%mod;
			ans+=ans;
			ans=ans%mod;
		}
		else
		{
			ans=pn*pm;
			ans=ans%mod;
		}
		cout<<ans;
	}
	return 0;
}

Measured memory_bytes: 256
# D - Maze Master
from collections import deque, defaultdict

INF = 1 << 30
MOD = 10 ** 9 + 7
dxy = [(-1, 0), (0, -1), (0, 1), (1, 0)]


def bfs(sx: int, sy: int):
    queue = deque([(sx, sy)])
    dist = defaultdict(lambda: INF)
    dist[sx * MOD + sy] = 0
    while queue:
        x, y = queue.popleft()
        for dx, dy in dxy:
            nx, ny = x + dx, y + dy
            if S[nx][ny] == ".":
                if nx * MOD + ny not in dist:
                    dist[nx * MOD + ny] = dist[x * MOD + y] + 1
                    queue.append((nx, ny))
    return max(dist.values())


def main():
    global S
    H, W, *S = open(0).read().split()
    H, W = int(H) + 2, int(W) + 2
    S = ["#" * W] + ["#" + s + "#" for s in S] + ["#" * W]  # put sentinels
    ans = max(bfs(i, j) for i, s in enumerate(S) for j, c in enumerate(s) if c == ".")
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3444
<?php
  list($a, $b, $c) = sscanf(fgets(STDIN), "%d %d %d");

  if($c-$a-$b < 0)
    print("No");
  else{
    if(($c-$a-$b)*($c-$a-$b) > 4*$a*$b)
      print("Yes");
    else
      print("No");
  }
?>

Measured memory_bytes: 4732
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  int k,n;
  cin >> k >> n;
  
  int x=0;
  vector<int> p(n);
  cin>>p[0];
  
  repo(i,n){
  cin>>p[i];
  x=max(x,p[i]-p[i-1]);
  }
  
  x=max(x,k-(p[n-1]-p[0]));
  
  cout << k-x << endl;
    
}

Measured memory_bytes: 1152
N, K = map(int, input().split())

ans = 0
mod = [0 for _ in range(K)]
for i in range(1, N+1):
    mod[i % K] += 1

for a_modk in range(K):
    b_modk = (K - a_modk) % K
    c_modk = (K - a_modk) % K
    if (b_modk + c_modk) % K == 0:
        ans += mod[a_modk] * mod[b_modk] * mod[c_modk]
print(ans)

Measured memory_bytes: 4632
import java.io.BufferedInputStream


const val YES = "Yes"
const val NO = "No"

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    fun iterateTokens(): Iterator<String> {
        val reader = BufferedInputStream(System.`in`).bufferedReader()
        val iterator = reader.use{ it.readText() }
                .split("\n| ".toRegex())
                .iterator()
        return iterator
    }
    val tokens = iterateTokens()
    val N = tokens.next().toLong()
    val A = LongArray(N.toInt())
    val B = LongArray(N.toInt())
    for(i in 0 until N.toInt()){
        A[i] = tokens.next().toLong()
        B[i] = tokens.next().toLong()
    }
    solve(N, A, B)
}

fun solve(N: Long, A: LongArray, B: LongArray){
    val n = N.toInt()
    val ab = Array<Pair<Long, Long>>(n){
            A[it] to B[it]
        }.sortedBy{ it.second }
    var time = 0L
    for ( i in 0 until n){
        time += ab[i].first
        if (time > ab[i].second){
            println(NO)
            return
        }
    }
    println(YES)
    return
}



Measured memory_bytes: 135372
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>

inline void read(int &T) {
	int x=0;bool f=0;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=!f;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	T=f?-x:x;
}

int x,y;

int main() {
	read(x),read(y);
	for(int i=0;i<=x;++i) {
		int j=x-i;
		if(i*2+j*4==y) {
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}

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

int main() {

        int n,m;
        cin >> m;

        n = m % 10;

        if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9) {
                cout << "hon" << endl;
        }
        else if (n == 0 || n == 1 || n == 6 || n == 8) {
                cout << "pon" << endl;
        }
        else{
                cout << "bon" << endl;
        }



}

Measured memory_bytes: 3632