akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
 
public class Main {
    static boolean[][] used;
    static int[] ans;
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int[] al = new int[101];
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int ans = 0;
        for(int i = a; i < b; i++){
            al[i]++;
        }
        for(int i = c; i < d; i++){
            ans += al[i];
        }
        System.out.println(ans);
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 23248
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<cmath>
#include<set>
#include<random>
#include<map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 11451419198109130;
typedef pair<int, int> P;
typedef pair<int,P> PP;
struct edge { int to, cor; };
int x[1005], y[1005];
vector<int>V;
signed main() {
	int n; cin >> n;
	int on = 0, en = 0;
	rep(i, n) {
		cin >> x[i] >> y[i];
		if (abs(x[i] + y[i]) & 1)on++;
		else en++;
	}
	if (on&&en) {
		cout << -1 << endl;
		return 0;
	}
	rep(i, 32) {
		V.push_back(1ll << i);
	}
	if (en) {
		V.push_back(1);
	}

	int sum = 1ll << 32;
	if (on)sum--;
	cout << V.size() << endl;
	rep(i, V.size()) {
		if (i)cout << ' '; cout << V[i];
	}
	cout << endl;
	rep(i, n) {
		int na = x[i] + y[i], nb = x[i] - y[i];
		int ans[35];
		fill(ans, ans + 35, 0);
		int naa = (na + sum) / 2, nbb = (nb + sum) / 2;
		rep(j, 32) {
			if (naa&(1ll << j))ans[j] += 1;
			if (nbb&(1ll << j))ans[j] += 2;
		}
		rep(j, V.size()) {
			if (ans[j] == 0)cout << 'L';
			else if (ans[j] == 1)cout << 'U';
			else if (ans[j] == 2)cout << 'D';
			else cout << 'R';
		}
		cout << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define int long long
signed main(){
    string v;
    cin>>v;
    int count[26]={};
    for(int i=0;i<v.size();i++){
        count[v[i]-'a']++;
    }
    bool a=true;
    for(int i=0;i<26;i++){
        if(count[i]%2==1)a=false;
    }
    if(a==true)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
h_list = [int(i) for i in input().split()]

count = 0
max_count = 0
for i in range(len(h_list) - 1):
    if(h_list[i] >= h_list[i+1]):
        count += 1
        if count > max_count:
            max_count = count
    else:
        count = 0

print(max_count)


Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1LL<<60;
const int INF = 1LL<<17;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

ll bit[500500];
ll n;
#define N 500010

ll sum(ll i){
    ll res=0;
    while(0<i){
        res += bit[i];
        i -= i&-i;
    }
    return res;
}
void add(ll i, ll x){
    while(i<=n){
        bit[i] += x;
        i += i&-i;
    }
}


ll rsum(ll l, ll r){
    return sum(r)-sum(l-1);
}
vector<vector<ll>> qr(N), qri(N);

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

    vector<ll> c(n+1);
    rep(i, n) cin >> c[i+1];
    vector<ll> a(N);
    rep(i, q){
        ll a, b;    cin >> a >> b;
        qr[b].push_back(a);
        qri[b].push_back(i);
    }
    vector<ll> res(q+1);
    FOR(i, 1, n+1){
        if(a[c[i]]>0) add(a[c[i]], -1);
        add(i, 1);
        a[c[i]] = i;
        rep(j, qr[i].size()){
            res[qri[i][j]] = rsum(qr[i][j], i);
        }
    }
    rep(i, q) cout << res[i] << endl;
}


Measured memory_bytes: 62648
#include <vector>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a) (a).begin(),(a).end()

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

  string S;
  cin >> S;
  int len = S.length();

  ll ans = 0;
  for (int mask = 0; mask < 1 << (len-1); mask++) {
      ll num = S[0] - '0';
      for (int i = 0; i < len-1; i++) {
          if (mask & 1 << i) {
              ans += num;
              num = 0;
          }
          num = num*10 + (S[i+1] - '0');
      }
      ans += num;
  }

  cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 256
url = "https://atcoder.jp//contests/abc051/tasks/abc051_c"
def search_route(f, t):
    route = ''
    y = t[1] - f[1]
    tmp_y = 'U'*y if y >= 0 else 'D'*(y*-1)
    x = t[0] - f[0]
    tmp_x = 'R'*x if x >= 0 else 'L'*(x*-1)
    route = tmp_y + tmp_x
    return route


def main():
    t = list(map(int, input().split()))
    route = search_route(t[:2], t[2:]) + search_route(t[2:], t[:2])
    tmp = t[:]
    t[0] -= 1
    t[3] += 1
    route_2 = 'L' + search_route(t[:2], t[2:]) + 'D'
    t = tmp
    t[1] -= 1
    t[2] += 1
    route_2 = route_2 + 'R' + search_route(t[2:], t[:2]) + 'U'

    print(route+route_2)


if __name__ == '__main__':
    main()



Measured memory_bytes: 9168
a=b=c=d=0
for _ in range(int(input())):
  s=input()
  if s=='AC':
    a+=1
  elif s=='WA':
    b+=1
  elif s=='TLE':
    c+=1
  else:
    d+=1
 
print('AC x',a)
print('WA x',b)
print('TLE x',c)
print('RE x',d)

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

using namespace std;

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


const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()

int main(){
    int a,b;
    cin>>a>>b;
    vector<string> C(2);
    string A(b,char('0'+a)),B(a,char('0'+b));
    C[0]=A;
    C[1]=B;
    sort(ALL(C));
    cout<<C[0]<<endl;

    return 0;
}

//a=97,z=122

Measured memory_bytes: 256
from decimal import *
getcontext().prec = 50

N, D = map(int, input().split())


def distance(x1, x2, y1, y2):
    dx = x2-x1
    dy = y2-y1
    return (dx*dx + dy*dy).sqrt()

X = [0] * N
Y = [0] * N
for i in range(N):
    X[i], Y[i] = map(Decimal, input().split())

ans = 0
for i in range(N):
    if (distance(0, X[i], 0, Y[i]) <= D):
        ans += 1

print(ans)


Measured memory_bytes: 57420
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
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; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A, B; cin >> A >> B;
	vector<int> a(A); rep(i, 0, A) { cin >> a[i]; }
	vector<int> b(B); rep(i, 0, B) { cin >> b[i]; }
	int ans = 0;
	rep(i, 0, B){
		int ii = i;
		rep(j, 0, A) {
			if (b[ii] == a[j]) {
				ii++;
				if (ii == B)break;
			}
		}
		chmax(ans, ii - i);
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int q,w,e,r;
  cin>>q>>w>>e>>r;
  int a=e-q,b=r-w;
  cout<<e-b<<" "<<r+a<<" "<<q-b<<" "<<w+a<<endl;
}

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

int main(){
  char input[7];
  int num[100];
  int i = 0;

  while(scanf("%s", input) != EOF){
    if(input[0] == '+') num[i-2] = num[i-2] + num[i-1];
    else if(input[0] == '-') num[i-2] = num[i-2] - num[i-1];
    else if(input[0] == '*') num[i-2] = num[i-2] * num[i-1];
   
    else {
      num[i] = atoi(input);
      i += 2;
    }
    i--;
  }
  
  printf("%d\n", num[0]);
 
  return 0;
}

    
    

Measured memory_bytes: 1740
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE TypeApplications #-}
import Data.Int (Int64)

main = do
  n <- readLn @Int64
  print $ sum [ x | x <- [1..n], x `rem` 3 /= 0, x `rem` 5 /= 0 ]


Measured memory_bytes: 4860
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def solve(f):
    n, m = f.read_int_list()
    g = collections.defaultdict(list)
    for _ in xrange(m):
        l, r, d = f.read_int_list()
        g[l].append((r, d))
        g[r].append((l, -d))

    dst = [None]*(n+1)

    for i in xrange(1, n+1):
        if dst[i] is not None: continue
        dst[i] = 0
        que = [i]
        while len(que) > 0:
            v0 = que.pop()
            for vi, di in g[v0]:
                if dst[vi] is not None:
                    if dst[v0]+di != dst[vi]: return 'No'
                else:
                    dst[vi] = dst[v0] + di
                    que.append(vi)

    return 'Yes'


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)


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

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

  int ones = n % 500;
  if(ones <= a){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}

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

const int INF = 1000000000;

int main()
{
	int C[100][100];
	int T[100][100];
	int z=0;
	int p[200];
	int q[200];
	int r[200];
	int A[200];
	while(true){
		int n, m;
		cin >> n >> m;

		if(n==0 && m==0)
			break;

		for(int i=0; i<m; i++){
			for(int j=0; j<m; j++){
				if(i==j){
					C[i][j] = T[i][j] = 0;
				}
				else{
					C[i][j] = T[i][j] = INF;
				}
			}
		}

		for(int i=0; i<n; i++){
			int a, b, c, t;
			cin >> a >> b >> c >> t;

			C[a-1][b-1] = C[b-1][a-1] = c;
			T[a-1][b-1] = T[b-1][a-1] = t;
		}
		for(int k=0;k<m;k++){
			for(int i=0;i<m;i++){
				for(int j=0;j<m;j++){
					if(C[i][j]>C[i][k]+C[k][j]){
						C[i][j]=C[i][k]+C[k][j];
						
					}
				}
			}
		}
		for(int k=0;k<m;k++){
			for(int i=0;i<m;i++){
				for(int j=0;j<m;j++){
					if(T[i][j]>T[i][k]+T[k][j]){
						T[i][j]=T[i][k]+T[k][j];
						
					}
				}
			}
		}
		cin>>z;
		for(int i=0;i<z;i++){
				cin>>p[i]>>q[i]>>r[i];
			if(r[i]==0){
				cout<<C[p[i]-1][q[i]-1]<<endl;
			}
			if(r[i]==1){
				cout<<T[p[i]-1][q[i]-1]<<endl;
			}
		}
		
	}
	

	return 0;
}

Measured memory_bytes: 1236
import java.util.*;
class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
        int number1 = scan.nextInt();
        int number2 = scan.nextInt();
        
       if(number1 == number2){
        System.out.println(number1*2);
       } else {
         int x = max(number1,number2);
        System.out.println(x*2-1);
       }
    }
   public static int max(int n, int m){
   		if(n > m){
        	return n;
        } else {
        	return m;
        }
   }
}

Measured memory_bytes: 22612
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD = 1000000007
#define INF (1e9)
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;


int main()
{
    ll a, b;
    cin >> a >> b;
    ll ans = a-1;
    if (a <= b) {
        ans++;
    }
    print(ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
int ddx[6]={0,1,0,-1,1,-1},ddy[6]={-1,0,1,0,1,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n;
string s1[55];
string ans;

int main(){
	while(1){
		cin>>n;
		if(n==0)break;
		REP(j,n){
			string s2;
			cin>>s2;
			ans=" ";
			ans[0]=s2[0];
			for(int i=0;i<s2.size()-1;i++){
				if(s2[i]=='a'||s2[i]=='i'||s2[i]=='u'||s2[i]=='e'||s2[i]=='o'){
					ans=ans+s2[i+1];
				}
			}
			//cout<<ans<<endl;
			s1[j]=ans;
		}
		int ans=0;
		int flag=0;
		sort(s1,s1+n);
		for(int i=0;i<n-1;i++){
			if(s1[i]==s1[i+1]){
				flag=1;
				break;
			}
			for(int j=0;j<min(s1[i].size(),s1[i+1].size());j++){
				if(s1[i][j]!=s1[i+1][j]){
					ans=max(ans,j+1);
					break;
				}
				if(j==min(s1[i].size(),s1[i+1].size())-1){
					ans=max(ans,j+2);
				}
			}
		}
		if(flag)cout<<-1<<endl;
		else cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3232
N, X, M = map(int, input().split())
if X == 0:
    print(0)
    exit()
U = [0] * (M + 10)
U[X] = 1
S = [0] * (M + 10)
S[1] = X
v = X
l = r = 0  # [l,r) で巡回
cycle_sum = 0
for i in range(2, M + 1):
    v = (v * v) % M
    if U[v]:
        l = U[v]
        r = i
        cycle_sum = S[i - 1] + v - S[l]
        break
    U[v] = i
    S[i] = S[i - 1] + v
if N <= l:
    print(S[N])
    exit()

ans = S[l - 1]
N -= l - 1
d, m = divmod(N, r - l)
ans += d * cycle_sum
ans += S[l + m - 1] - S[l - 1]
print(ans)


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

int main() {
    int K, S;
    cin >> K >> S;
  int c = 0;
  
    for (int X = 0; X <= K; X++) {  // Xの数を 0 〜 K で調べる
        for (int Y = 0; Y <= K; Y++) {  // Yの数を 0 〜 K で調べる
            int Z = S - X - Y;
            if (Z >= 0 && Z <= K) {// 答えが見つかったら
             c++;
            }
        }
    }
  cout << c << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 2 * 1000 + 47;
const int MOD = 1000 * 1000 * 1000 + 7;

LL getUnion(LL a, LL b, LL c, LL d)
{
	LL r = min(d, b) - max(a, c) + 1;
	LL com = max(r, 0LL);
	return b - a + 1 + d - c + 1 - com;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	
	LL a, b;
	cin >> a >> b;
	if (a == b)
	{
		cout << 1 << endl;
		return 0;
	}

	int p = -1;
	FOR(i, 0, 62)
	{
		if ((a >> i) == (b >> i))
		{
			p = i;
			break;
		}
	}

	p--;
	LL mask = (1LL << p) - 1;
	LL c = a | mask;

	//cout << "!" << a << " " << c << endl;
	LL ans = c - a + 1;
	LL tmp = b & mask;
	int k = 0;
	while ((tmp >> k) != 0) k++;
	tmp = (1LL << k) - 1;

	LL l1 = c + 1;
	LL r1 = b | tmp;
	LL l2 = a | (1LL << p);
	LL r2 = l2 | mask;

	//cout << l1 << " " << r1 << " - " << l2 << " " << r2 << endl;
	//cout << getUnion(l1, r1, l2, r2) << endl;
	ans += getUnion(l1, r1, l2, r2);

	cout << ans << endl;
}


Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    ll y, m, d;
    y = (S[0] - '0') * 1000 + (S[1] - '0') * 100 + (S[2] - '0') * 10 + (S[3] - '0');
    m = (S[5] - '0') * 10 + (S[6] - '0');
    d = (S[8] - '0') * 10 + (S[9] - '0');

    if(y > 2019){
        cout << "TBD" << endl;
    }else if(y == 2019 && m > 4){
        cout << "TBD" << endl;
    }else{
        cout << "Heisei" << endl;
    }

    return 0;
}

Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x=0;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){cin>>a[i];}
    //set <int> s;
    for(int i=1;i<n-1;i++){
        vector <int> v={a[i],a[i+1],a[i-1]};
        sort(v.begin(),v.end());
        if(v[1]==a[i])
            x++;
            //s.insert(v[1]);
    }
    cout<<x;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main() {
	int W, H, x, y, r;
	scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
	if (r <= x&&x <= W - r&&r <= y&&y <= H - r)
		printf("Yes\n");
	else
		printf("No\n");		

}

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

int N;

int main() {
  cin>>N;
  
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  
  int ans=0;
  
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  for(int i=0;i<N;i++){
    if(i%2==0){
      ans+=a[i];
    }
    else{
      ans-=a[i];
    }
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
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; }


ll dp[505];

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

	int N; cin >> N;
	vei C(N), S(N), F(N); rep(i,N-1) cin >> C[i] >> S[i] >> F[i];
	rep(i,N) {
		int t = 0;
		repk(j,i,N-1) {
			if(t < S[j]) t = S[j];
			else if(t % F[j] == 0) ;
			else t = t + F[j] - (t % F[j]);
			t += C[j];
		}
		cout << t << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()
r = s.count('R')
g = s.count('G')
b = n - r - g

ans = r*g*b

for i in range(n-2):
  for j in range(i+1, n-1):
    k = j + (j - i)
    if k > n-1:
    	break
    if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
      ans -= 1
print(ans)

Measured memory_bytes: 9188
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;


int main(){

	char buf[21];
	int length,small_count = 0,big_count = 0,num_count = 0;

	scanf("%s",buf);

	for(length = 0;buf[length] != '\0';length++);

	if(length <= 5){
		printf("INVALID\n");
		return 0;
	}

	for(int i = 0; i < length; i++){
		if(buf[i] >= '0' && buf[i] <= '9'){
			num_count++;
		}else if(buf[i] >= 'a' && buf[i] <= 'z'){
			small_count++;
		}else if(buf[i] >= 'A' && buf[i] <= 'Z'){
			big_count++;
		}
	}

	if(num_count == 0 || big_count == 0 || small_count == 0){
		printf("INVALID\n");
	}else{
		printf("VALID\n");
	}

	return 0;
}

Measured memory_bytes: 2700
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define N 200100
#define mod 1000000007
#define fn(i,n) for(int i=0;i<n;i+=1)
#define rep(i,l,r) for(int i=l;i<=r;i+=1)
#define INF 100000000000000
#define pii pair<int,int>
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

signed main()
{
    
    speed
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    while(1){
      c-=b;
      if(c<=0){
        cout<<"Yes"<<endl;
        break;
      }
      a-=d;
      if(a<=0){
        cout<<"No"<<endl;
        break;
      }

    }


 
 
    return 0;
}

Measured memory_bytes: 3652
// Author: Wenxing Mei
//   File: a.cpp
//   Date: 2019-03-14 00:27
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define per(i, b, a) for (int i = (int)b; i >= (int)a; --i)
#define repv(ele, cont) for (auto &ele : cont)
#define all(x) x.begin(), x.end()
#define mp make_pair
#define eb emplace_back
#define ep emplace
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<ll> vll;
// END OF TEMPLATE

int main() {
#ifndef LOCAL
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#endif
    string s;
    cin >> s;
    int m = (s[5] - '0') * 10 + s[6] - '0';
    if (m <= 4)
        puts("Heisei");
    else
        puts("TBD");
    return 0;
}


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

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

using namespace std;

#define MAX 310

int n,w[MAX];
int memo[MAX][MAX];

bool dfs(int L,int R) { // memo??????????????¨??§



  if( R - L <= 1 ) {
    return memo[L][R] = 0;
  }
  if( R - L <= 2 ) {
    assert( R-1 < n);
    if( abs(w[R-1] - w[L]) <= 1 ) {
      memo[L][R] = 1;
    } else {
      memo[L][R] = 0;
    }
    return memo[L][R];
  }
  if( memo[L][R] != -1 ) return memo[L][R];
  int &ret = memo[L][R];
  ret = 0;
  for(int med=L;med<R;++med) {
    if( dfs(L,med+1) && dfs(med+1,R) ) {
      ret = 1;
      break;
    }
  }



  if( ret == 0 ) {
    if( abs(w[L]-w[R-1] ) <= 1 )  {
      if( dfs(L+1,R-1) ) {
	ret = 1;
      }
    }
  }
 Fin:;
  return ret;
}

int dp[MAX];

void compute() {
  memset(memo,-1,sizeof memo);
  rep(i,n) memo[i][i+1] = 0;
  REP(len,2,n+1) {
    for(int L=0;L<n;++L) {
      int R = L + len;
      if( R > n ) break;
      dfs(L,R);
    }
  }
  //rep(L,n) for(int R=L+1;R<=n;++R) dfs(L,R); // [0,n)
  /*
  rep(L,n) for(int R=L+1;R<=n;++R) {
    cout << "[" << L << "," << R << ") = " << memo[L][R]  << endl;
  }
  */

  memset(dp,0,sizeof dp);
  int maxi = 0;
  rep(i,n) {
    dp[i] = max(dp[i],dp[i-1]);
    REP(j,i+1,n+1) {
      int cost = -1;
      if( memo[i][j] ) {
	cost = ( j - i)  ;
      }
      if( cost == -1 ) continue;
      if( dp[j] < dp[i] + cost ) {
	dp[j] = dp[i] + cost;
	maxi = max(maxi,dp[j]);
      }
    }
  }
  cout << maxi << endl;
}

int main(){
  while( cin >> n, n ) {
    rep(i,n) cin >> w[i];
    compute();
  }
  return 0;
}

Measured memory_bytes: 3460
s = list(input())
while True:
    if len(s) % 2 != 0:
        s = s[:-1]
    else:
        s = s[:-2]
    if s[:len(s)//2] == s[len(s)//2:]:
        break
    if len(s) == 1:
        break

print(len(s))

Measured memory_bytes: 3060
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
const int MAXN=1000005,MAXM=30000000;
const int P=1000000007;
#define L 1048576
#define real long double
#define eps 1e-9
char _buf[L],*S,*T,_buf1[L],*S1=_buf1;
inline char gc()
{
	if(S==T)
	{
		T=(S=_buf)+fread(_buf,1,L,stdin);
		if(S==T)return 0;
	}
	return *S++;
}
template<class T> void get(T &x)
{
	char c;
	for(c=gc();(c<'0'||c>'9')&&c!='-';c=gc());
	bool b=0;
	if(c=='-')
	{
		b=1;
		c=gc();
	}
	for(x=c^'0',c=gc();c>='0'&&c<='9';c=gc())x=(x<<3)+(x<<1)+(c^'0');
	if(b)x=-x;
}
inline void pc(char c)
{
	if(S1==_buf1+L)
	{
		fwrite(_buf1,1,L,stdout);
		S1=_buf1;
	}
	*S1++=c;
}
void out(ll x)
{
	if(x>9)out(x/10);
	pc(x%10^'0');
}
int Pow(int x,int y)
{
	int s=1;
	for(;y;y>>=1,x=(ll)x*x%P)if(y&1)s=(ll)s*x%P;
	return s;
}
int A(int x)
{
	return x<0?-x:x;
}
int i,j,t,n,f[20][20],g[20],a,b;
int ask(int n,int m)
{
	int s=g[m-1],i;
	for(i=1;i<m;i++)s=(ll)s*(n+i)%P;
	return s;
}
int main()
{
	f[16][5]=1;
	for(i=16;i;i--)for(j=5;j;j--)
	{
		f[i-1][j]=(f[i-1][j]+(ll)(P+1)/2*f[i][j])%P;
		f[i][j-1]=(f[i][j-1]+(ll)(P+1)/2*f[i][j])%P;
	}
	for(i=g[0]=1;i<20;i++)g[i]=(ll)g[i-1]*Pow(i,P-2)%P;
	get(t);
	while(t--)
	{
		get(n);
		if(n<5)
		{
			pc('0');
			pc('\n');
			continue;
		}
		n-=5;
		a=b=0;
		for(i=1;i<=16;i++)a=(a+(ll)f[i][0]*ask(n,i))%P;
		for(i=1;i<=5;i++)b=(b+(ll)f[0][i]*ask(n,i))%P;
		if(n&1)a=(a+P-b)%P;
		else a=(a+b)%P;
		out(a);
		pc('\n');
	}
	fwrite(_buf1,1,S1-_buf1,stdout);
	return 0;
}

Measured memory_bytes: 3516
//author Forsaken
#define Hello the_cruel_world!
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<utility>
#include<cmath>
#include<climits>
#include<deque>
#include<functional>
#include<numeric>
#define max(x,y) ((x) > (y) ? (x) : (y))
#define min(x,y) ((x) < (y) ? (x) : (y))
#define lowbit(x) ((x) & (-(x)))
#define FRIN freopen("C:\\Users\\Administrator.MACHENI-KA32LTP\\Desktop\\1.in", "r", stdin)
#define FROUT freopen("C:\\Users\\Administrator.MACHENI-KA32LTP\\Desktop\\1.out", "w", stdout)
#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define outd(x) printf("%d\n", x)
#define outld(x) printf("%lld\n", x)
#define memset0(arr) memset(arr, 0, sizeof(arr))
#define il inline
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int maxn = 1e5;
const int INF = 0x7fffffff;
const int mod = 1e9 + 7;
const double eps = 1e-7;
const double Pi = acos(-1.0);
il int read_int() {
	char c;
	int ret = 0, sgn = 1;
	do { c = getchar(); } while ((c < '0' || c > '9') && c != '-');
	if (c == '-') sgn = -1; else ret = c - '0';
	while ((c = getchar()) >= '0' && c <= '9') ret = ret * 10 + (c - '0');
	return sgn * ret;
}
il ll read_ll() {
	char c;
	ll ret = 0, sgn = 1;
	do { c = getchar(); } while ((c < '0' || c > '9') && c != '-');
	if (c == '-') sgn = -1; else ret = c - '0';
	while ((c = getchar()) >= '0' && c <= '9') ret = ret * 10 + (c - '0');
	return sgn * ret;
}
il ll quick_pow(ll base, ll index) {
	ll res = 1;
	while (index) {
		if (index & 1)res = res * base % mod;
		base = base * base % mod;
		index >>= 1;
	}
	return res;
}
int n, a, b;
int main()
{
	cin >> n >> a >> b;
	cout << min(a * n, b) << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int table[40];

int main() {
    int N, M;

    cin >> N >> M;

    for (int i = 0; i < N; i++) {
        int K;
        cin >> K;
        for (int j = 0; j < K; j++) {
            int A;
            cin >> A;
            table[A - 1]++;
        }
    }
    int cnt = 0;
    for (int i = 0; i < M; i++) {
        if (table[i] == N) {
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
m = 10**9+7
n = int(input())
a = list(map(int, input().split()))
check = True
if n%2 == 0:
    if 0 in a or len(set(a)) != n//2:
      check = False
else:
    if len([0 for i in a if i==0]) != 1 or len(set(a)) != n//2+1:
      check = False
      
if check:
  print(2**(n//2)%m)
else:
  print(0)

Measured memory_bytes: 14008
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <chrono>
#include <queue>
#include <functional>

using namespace std;

typedef long long ll;

int main() {
    //cin.tie(0);
    //ios::sync_with_stdio(false);
    int A, B, T;
    cin >> A >> B >> T;

    A *= 2;
    T = 2 * T + 1;

    int ans = 0;
    for (int i = 1; A * i <= T; ++i) {
        ans += B;
    }

    cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.LinkedList;

public class Main {
	public static void main(String[] args) {

		// LinkedList型としてインスタンス化
		LinkedList<Integer> list = new LinkedList<>();

		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
			int n = Integer.parseInt(br.readLine());
			for (int i = 0; i < n; i++) {
				String[] cmd = br.readLine().split(" ");
				switch (cmd[0]) {
				case "insert":
					// リストの先頭に追加
					list.addFirst(Integer.parseInt(cmd[1]));
					break;

				case "delete":
					// parseIntの戻り値はint型である為、
					// そのまま渡すとremove(int index)が呼び出されてしまう。
					// 明示的にInteger型に変換することで、
					// remove(Object o)メソッドを呼び出す。
					list.remove((Integer) Integer.parseInt(cmd[1]));
					break;

				case "deleteFirst":
					// 先頭の要素を削除
					list.removeFirst();
					break;

				case "deleteLast":
					// 末尾の要素を削除
					list.removeLast();
					break;
				}
			}

			StringBuilder sb = new StringBuilder();
			for (Iterator<Integer> it = list.listIterator(); it.hasNext();) {
				sb.append(it.next());
				if (it.hasNext()) {
					sb.append(" ");
				}
			}
			System.out.println(sb);

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}


Measured memory_bytes: 204020
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);
ll dp[2001][2001];



int main() {
ll n,m;
cin>>n>>m;
vector<ll> s(n);
vector<ll> t(m);
rep(i,n){
    cin>>s[i];
}
rep(i,m){
    cin>>t[i];
}

for(int i=0;i<n;i++){//s
    for(int j=0;j<m;j++){//m
            //dp[i+1][j+1]+=dp[i][j+1];
        if(s[i]==t[j]){
            dp[i+1][j+1]=dp[i+1][j]+1+dp[i][j+1];
            dp[i+1][j+1]%=MOD;

        }else{
            //dp[i+1][j+1]+=max(dp[i][j+1],dp[i+1][j]);
            dp[i+1][j+1]+=(dp[i][j+1]-dp[i][j]+MOD)%MOD;
            dp[i+1][j+1]+=dp[i+1][j];
            dp[i+1][j+1]%=MOD;
        }
    }
}
//rep(i,n+1){
//    rep(j,m+1){
//        cout<<dp[i][j];
//    }
//    cout<<endl;
//}


cout<<(dp[n][m]+1)%MOD<<endl;






    return 0;
}


Measured memory_bytes: 31488
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mp make_pair
#define inf 1000000007
#define int long long
using namespace std;
int fld[514][514];
signed main(){
	int H,W,h,w;
	cin>>H>>W>>h>>w;
	if( (H%h==0) && (W%w==0)){
		cout<<"No"<<endl;
		return 0;
	}
	if( H%h != 0){
		cout<<"Yes"<<endl;
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(i%h == h-1){
					fld[i][j] = -1 * ( (h-1) *100000 + 1);
				}
				else{
					fld[i][j] = 100000;
				}
			}
		}
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				cout<<fld[i][j]<<" ";
			}
			cout<<endl;
		}
	}
	else{
		cout<<"Yes"<<endl;
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(j%w == w-1){
					fld[i][j] = -1 * ( (w-1) *100000 + 1);
				}
				else{
					fld[i][j] = 100000;
				}
			}
		}
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				cout<<fld[i][j]<<" ";
			}
			cout<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 4096
#include<iostream>
using namespace std;
int main()
{
    long long N;
    cin >> N;

    long long power = 5; 
    long long ans = 0;
    long long p;

    if(N%2==0){

    while(N>power){
        p = N/power/2;
        ans = ans + p;
        power = power * 5;
    }

    }else{}
    cout << ans << endl;

    return 0;

}

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

using namespace std;

int main()
{
  uint64_t N, M;
  cin >> N >> M;
  
  vector<multiset<uint64_t>> jobs(M);
  for (uint64_t n = 0; n < N; ++n) {
    uint64_t A, B;
    cin >> A >> B;
    
    if (A <= M) {
      jobs[A - 1].insert(B);
    }
  }
  
  vector<uint64_t> dp(M + 1, 0);
  multiset<uint64_t, greater<uint64_t>> s;
  for (uint64_t m = 0; m < M; ++m) {
    for (uint64_t p : jobs[m]) { s.insert(p); }
    
    dp[m + 1] = dp[m];
    
    if (!s.empty()) {
      dp[m + 1] += *s.begin();
      s.erase(s.begin());
    }
  }
  
  cout << dp[M] << endl;
  
  return 0;
}

Measured memory_bytes: 15104
#include <bits/stdc++.h>
using namespace std;
const int maxn=22;
int a[maxn],b[maxn];
int main(){int ans=0;
    int n;cin>>n;for(int i=1;i<=n;i++) cin>>a[i];for(int i=1;i<=n;i++){
        cin>>b[i];if(a[i]>b[i]) ans+=a[i]-b[i];
    }
    cout<<ans;
    return 0;
}


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

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){return a/GCD(a,b)*b;}

const int INF=1e9;
const double eps=0.0000000001;

int main(){
  ll n;
  cin >> n;
  ll t[1000],ans=1;
  FOR(i,n){
    cin >> t[i];
    ans=LCM(ans,t[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define vsort(v) sort(v.begin(), v.end())
#define ll long long
const ll MOD = 1e9 + 7;

int main() {
	int k, s;
	cin >> k >> s;
	int c = 0;
	rep(x, k+1) {
		rep(y, k+1) {
			int z = s - x - y;
			if (0 <= z && z <= k) c++;
		}
	}
	cout << c << endl;
}

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

int main() {
    int h, w, cnt;
    cin >> h >> w;
    string s[h];
    for (int i=0; i<h; ++i) {
        cin >> s[i];
    }
    
    for (int i=0; i<h; ++i) {
        for (int j=0; j<w; ++j) {
            if (s[i].at(j) == '.') {
                cnt = 0;
                for (int hi=i-1; hi<i+2; ++hi) {
                    if (hi<0||hi>=h) { continue; }
                    for (int wj=j-1; wj<j+2; ++wj) {
                        if (wj<0||wj>=w) { continue; }
                        
                        if (s[hi].at(wj) == '#') {
                            ++cnt;
                        }
                    }
                }
                s[i].at(j) = '0' + cnt;
            }
        }
    }
    
    for (int i=0; i<h; ++i) {
        cout << s[i] << endl;
    }
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define endl '\n'
#define pii pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define traceloop(x,a) {for(ll i=0;i<x;i++) cerr<<a[i]<<" "; cerr<<endl;}
ll ab(ll x) {return x>0LL?x:-x;}

const ll inf = 1e18 + 5;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	ll n,W;
	cin>>n>>W;
	vector<ll> w(n),v(n);
	ll sum=0;
	for(int i=0; i<n; i++)
	{
		cin>>w[i]>>v[i];
		sum+=v[i];
	}
	vector<ll> dp(sum+1, inf);
	dp[0]=0;
	for(int item = 0; item<n; item++)
	{
		for(int j=sum; j>=0; j--)
		{
			if(dp[j]>=0 && j+v[item]<=sum)
			{
				dp[j+v[item]] = min(dp[j+v[item]],dp[j]+w[item]);
			}
		}
	} 
	//traceloop(sum,dp);
	for(int i=sum; i>=0; i--)
	{
		if(dp[i]<=W)
		{
			cout<<i;
			break;
		}
	}
	return 0;
}
	

Measured memory_bytes: 1024
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
//#include<vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

void pakuri_sort(int N, int A[]) {
	const int b = 8;
	int tmp[100001];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

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


	int N = getint();
	int A = getint();
	int B = getint();
	A -= B;
	int H[100000], M[100000] = {};
	ll D[100000] = {};
	rep(i, N) H[i] = getint();
	pakuri_sort(N, H);
	rep(i, N) {
		D[i + 1] = H[i] / A + D[i];
		M[i] = H[i] % A;
	}

	int L = 0;
	int R = (1000000000 + B - 1) / B;

	while (L + 1 != R) {
		int mid = (L + R) / 2;
		int damage = B * mid;
		ll cnt = 0;
		auto k = upper_bound(H, H + N, damage) - H;
		ll d = damage / A;
		int m = damage % A;
		cnt += D[N] - D[k] - d * (N - k);
		for (; k != N; k++) {
			cnt += (M[k] > m);
			if (cnt > mid) break;
		}
		if (cnt > mid) L = mid;
		else R = mid;
	}

	printf("%lld", R);

	Would you please return 0;
}

Measured memory_bytes: 2176
n = input()
c = input()
i = 0
while 1:
    l = c.find('W')
    r = c.rfind('R')
    if l == -1 or r == -1 or l >= r:
        break
    c = c[:l] + 'R' + c[l + 1:r] + 'W'  + c[r + 1:]
    i += 1
print(i)


Measured memory_bytes: 9844
#include <stdio.h>
#include <string.h>>

int main()
{
    char p[7] = {0};
    scanf("%s", p);
    if (strcmp(p, "Sunny") == 0) printf("Cloudy");
    else if (strcmp(p, "Cloudy") == 0) printf("Rainy");
    else printf("Sunny");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  int K,strsize;
  cin >> K >> S;
  strsize = S.size();
  if(K < strsize){
    int i=0;
    while(i<K){
      cout << S.at(i);
      i++;
    }
    cout << "...";
  }else{
    cout << S;
  }
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    string s;
    cin >> s;
    ll n = s.size();
    vector<ll> ans(n);
    rep(ri, 2) {
        {
            ll cnt = 0;
            rep(i, n) {
                if(s.at(i) == 'R')
                    cnt++;
                else {
                    ans.at(i) += cnt / 2;
                    ans.at(i - 1) += (cnt + 1) / 2;
                    cnt = 0;
                }
            }
        }
        reverse(ans.begin(), ans.end());
        reverse(s.begin(), s.end());
        rep(i, n) {
            if(s.at(i) == 'L')
                s.at(i) = 'R';
            else
                s.at(i) = 'L';
        }
    }
    rep(i, n) cout << ans.at(i) << ' ';
}

Measured memory_bytes: 1408
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#define BUFSIZE 1000000

int N,K;
int  hoge[BUFSIZE]={0};
long long V,W,T;
int count = 0;
int main(void){
  int X,Y;
  scanf("%d %d",&X,&Y);
  if(X*4 < Y){
    printf("No");
    exit(0);
  }
  for(int i = 0;;i++){
    if(X*4-i*2 < X*2) break;
    if((X*4-i*2) == Y){
      printf("Yes");
      exit(0);
    }
  }
  printf("No");
  return 0;
}


Measured memory_bytes: 1732
PI = Math::PI

a,b,x = gets.split.map(&:to_f)

s = x / a
ans = 0
if s > b * a / 2
  bu = 2 * s / a - b
  s -= a * bu
  b -= bu
else
  a = 2 * s / b
end
r = Math.atan(b/a)
ans = r * (180.0/PI)

puts ans

Measured memory_bytes: 1788
def mydiv(n, cnt=0)
    n % 2 == 0 ? mydiv(n.div(2), cnt.next) : cnt
end
N = gets.to_i
max_cnt = 0
max_n = 1
1.upto(N) do |n|
    cnt = mydiv(n)
    if max_cnt < cnt
        max_cnt = cnt 
        max_n = n
    end
end
puts max_n

Measured memory_bytes: 1788
from collections import defaultdict

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n= readInt()
a = readInts()
q = readInt()
bc = []
for i in range(q):
	bc.append(readInts())

s = sum(a)
d = defaultdict(int)
for i in a:
	d[str(i)]+=1
for i in bc:
	t = d[str(i[0])]
	d[str(i[0])]=0
	d[str(i[1])]+=t
	s=s-t*i[0]+t*i[1]
	print(s)

Measured memory_bytes: 45884
s = gets.chomp

b1 = s[0] == 'A'
ss = s[2..s.length-2]
b2 = ss.count('C') == 1
b3 = false
b4 = false
if b2
    ss.delete!('C')
    b3 = ss.downcase == ss
    b4 = s[1].downcase == s[1] && s[s.length-1].downcase == s[s.length-1]
end

if b1&&b2&&b3&&b4
    puts 'AC'
else
    puts 'WA'
end


Measured memory_bytes: 1788
/*
 *
 *
 */

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

#define endl "\n"
#define FSP(n) cout << fixed << setprecision(n);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define ALL(v) (v).begin(), (v).end();
#define SORT(v) sort(ALL(v));
#define REV(v) reverse(ALL(v));
static inline ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b);}
static inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
#define prepare cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);

void solve() {
    int X;
    cin >> X;
    int happy = 0;
    int first = (X / 500) * 1000;
    X %= 500;
    int second = (X / 5) * 5;
    happy = first + second;
    cout << happy << endl;
}

signed main() {
    prepare
    solve();
}


Measured memory_bytes: 256