akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
const ll MOD = (ll)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

ll fac[1] = {1}, inv[1] = {1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll mp(ll a,ll b){ll ret=1;while(b){if(b&1)ret=ret*a%MOD;a=a*a%MOD;b>>=1;}return ret;}
ll cmb(ll r, ll c) {return fac[r] * inv[c] % MOD * inv[r - c] % MOD;}

int main() {
    ll n,d,k;
    scanf("%lld %lld %lld", &n, &k, &d);
    n=abs(n);

    if (n/d >= k) {
        ll ans = n - (d*k);
        printf("%lld\n", ans);
        return 0;
    }

    ll t=n%d;
    ll tt=n/d;
    k -= tt; // 남은 횟수.

    if (k%2==1) {
        printf("%lld", d-t);
    }
    else {
        printf("%lld", t);
    }

    // 그게 아닌경우 항상 갈 수 있고.
    // d단위로 움직인다.
}

Measured memory_bytes: 3812
k,x = (int(i) for i in input().split())

mini = x - k + 1
maxi = x + k

l = list(range(max([mini,-1000000]),min([1000000,maxi])))
if not l:
  print(x)
else:
  for a in range(len(l)):
    print(l[a],end=" ")

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

int main(){
    ll a, b;
    cin >> a >> b;

    if(a < 0 && b > 0){
        cout << "Zero" << endl;
    }else if(a == 0 || b == 0){
        cout << "Zero" << endl;
    }else if(a > 0){
        cout << "Positive" << endl;
    }else{
        ll k = b - a + 1;

        if(k % 2 == 0){
            cout << "Positive" << endl;
        }else{
            cout << "Negative" << endl;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define int long long

int n;
long long sum[407], dp[407][407], a[407];
bool vis[407][407];

long long solve(int l, int r){
	if(vis[l][r]) return dp[l][r];
	vis[l][r] = true;
	if(l >= r) return 0LL;
	long long ans = 2e18;
	for(int i = l; i <= r; i++){
		long long cal = 0;
		if(i == l) cal = a[l] + sum[r] - sum[l] + solve(l + 1, r);
		else if(i == r) cal = a[r] + sum[r - 1] - sum[l - 1] + solve(l, r - 1);
		else{
			long long lef = sum[i - 1] - sum[l - 1];
			long long rig = sum[r] - sum[i];
			cal = 2LL * (min(lef, rig) + a[i]) + max(lef, rig) + solve(l, i - 1) + solve(i + 1, r);
			long long cal2 = sum[i] - sum[l - 1] + sum[r] - sum[i] + solve(l, i) + solve(i + 1, r);
			cal = min(cal, cal2);
		}
		ans = min(ans, cal);
	}
	dp[l][r] = ans;
	return ans;
}

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	sum[0] = 0;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		sum[i] = sum[i - 1] + a[i];
	}
	cout << solve(1, n);
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <map>
#include <functional>

using namespace std;


int main() {
	string s;
	int ans = 0;
	cin >> s;
	for (auto& a : s) {
		if (a == '1') {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#define ll long long
#define inf 6000000000000000000
#define norm 0
#define mod 1000000007
#define IO                    \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
using namespace std;
void fill(vector<int>&vec)
{
    int arr[1005]={};
    arr[0]=1;
    arr[1]=1;
    for(int i=2;i<1005;i++)
    {
        if(arr[i]==0)
        {
            //cout<<i<<endl;
            vec.push_back(i);
            for(int ii=2;ii*i<1005;ii++)
            {
                arr[ii*i]=1;
            }

        }
    }

}
ll gcd(int a,int b)
{
    if(b==0)return a;
        return gcd(b,a%b);
}
int main()
{
    IO
   ll a,b;
    cin>>a>>b;
    ll aa=a,bb=b;
    a%=2019;
    b%=2019;
    ll res=inf;
    if(bb-aa>=2019)res=0;
    for(int i=min(a,b);i<=max(a,b);i++)
    {
        for(int ii=i+1;ii<=max(a,b);ii++)
        {

            res=min(res,(ll)((i*ii)%2019));
            if(res==0) {
                break;
            }

        }
        if(res==0)break;
    }
    cout<<res<<endl;
    return 0;
}




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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  bool flag = true;
  int i = 0;
  reverse(S.begin(), S.end());

  while(i < S.size()) {
    if(S.substr(i, 7) == "remaerd") {
      i += 7;
    } else if(S.substr(i, 6) == "resare") {
      i += 6;
    } else if(S.substr(i, 5) == "maerd") {
      i += 5;
    } else if(S.substr(i, 5) == "esare") {
      i += 5;
    } else {
      flag = false;
      break;
    }
  }
  if(flag)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

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

const ll mod = 1e9 + 7;

const ll INF = 1e15;

ll n, m, k;
vector<vector<ll>> scores;
vector<ll> costs;
vector<ll> cache;
ll dfs(int index, ll currentCosts) {
	if (index == n) {
		rep(i, m) {
			if (cache[i] < k) return INF;
		}
		return currentCosts;
	}
	auto c = dfs(index + 1, currentCosts);
	rep(i, m) {
		cache[i] += scores[index][i];
	}
	auto d = dfs(index + 1, currentCosts + costs[index]);
	rep(i, m) {
		cache[i] -= scores[index][i];
	}
	return min(c, d);
}

int main() {
	cin >> n >> m >> k;
	costs.resize(n, 0);
	scores.resize(n, vector<ll>(m, 0));
	rep(i, n)
	{
		cin >> costs[i];
		rep(j, m) {
			cin >> scores[i][j];
		}
	}
	cache.resize(n, 0);
	ll low = dfs(0, 0);
	if (low == INF) {
		cout << -1 << endl;
	}
	else {
		cout << low << endl;
	}
	return 0;
}


Measured memory_bytes: 3640
import sys
from collections import deque
#import numpy as np
import math
#sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def solve():
    return

if __name__=='__main__':
    n = I()
    d,x = IL()
    days = 0
    for _ in range(n):
        a = I()
        tmp = 1
        count = 1
        while tmp<=d:
            days += 1
            tmp = count*a + 1
            count += 1
    ans = days + x
    print(ans)
    solve()

Measured memory_bytes: 9400
// Problem : D - Floor Function
// Contest : AtCoder - AtCoder Beginner Contest 165
// URL : https://atcoder.jp/contests/abc165/tasks/abc165_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<string, string> pss;
#define pb push_back
#define PI acos(-1.0)
#define EPS 1e-4
#define mp make_pair
#define all(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fout(S,x)            cout<<fixed<<setprecision(x)<<(S)<<endl
#define present(c,x) ((c).find(x) != (c).end())
#define T() ll t;cin>>t;while(t--)
#define mem(input,b) memset(input,b,sizeof(input))
#define ff first
#define ss second
#define fread(input) freopen("input","r",stdin)
#define fwrite(b) freopen("b","w",stdout)
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define FOREACH(i,c) for (__typeof ((c).begin()) i = (c).begin() ; i != (c).end() ; i++)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
ll a,b,n;
ll f(ll x){
	ll mul1 = (a*x)/b;
	ll mul2 = (x/b)*a;
	return mul1-mul2;
}
int main(){
    fastio;
    cin>>a>>b>>n;
    ll l,r;
    l=1;
    r=n;
    while(r-l>2){
    	//trace(l,r);
    	ll m1 = l + (r - l) / 3;
        ll m2 = r - (r - l) / 3;
        ll f1 = f(m1);
        ll f2 = f(m2);
        if (f1 <= f2)
            l = m1;
        else
            r = m2;
    }
    ll ansv = f(l);
    for(ll k=l+1;k<=r;++k){
    	ll tempv = f(k);
    	if(tempv>ansv){
    		ansv=tempv;
    	}
    }
    cout << ansv << endl;
    return 0;
}    


Measured memory_bytes: 3656
import java.util.*;
class Main
{
    public static void main(String[] ards)
    {
	Scanner sc=new Scanner(System.in);
	while(true){
	    int cards=sc.nextInt();
	    int shuffle=sc.nextInt();
	    if(cards==0&&shuffle==0)break;
	    LinkedList<Integer> list=new LinkedList<Integer>();
	    for(int i=1;i<=cards;i++){
		list.addFirst(i);
	    }
	    for(int i=0;i<shuffle;i++){
		LinkedList<Integer> temp=new LinkedList<Integer>();
		int p=sc.nextInt()-1;
		int c=sc.nextInt();
		for(int j=0;j<c;j++){
		    temp.addFirst(list.get(p));
		    list.remove(p);
		}
		for(int j=0;j<c;j++){
		    list.addFirst(temp.poll());
		}
	    }
	    System.out.println(list.getFirst());
	}
    }
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
int DP[110][5][5];
int main()
{
  int N,K;
  string S;
  cin>>S>>K;
  N=S.length();
  DP[0][0][1]=1;
  for(int i=0;i<N;i++)
    for(int j=0;j<=K;j++)
    {
      if(S[i]=='0'){
        DP[i+1][j][1]+=DP[i][j][1];
      	DP[i+1][j][0]+=DP[i][j][0];
      	DP[i+1][j+1][0]+=DP[i][j][0]*9;
      }
      else
      {
        DP[i+1][j][0]+=DP[i][j][1]+DP[i][j][0];
        for(int _=1;_<10;_++)
          DP[i+1][j+1][0]+=DP[i][j][0];
        for(int _=1;_<S[i]-'0';_++)
          DP[i+1][j+1][0]+=DP[i][j][1];
        DP[i+1][j+1][1]+=DP[i][j][1];
      }
    }
  cout<<DP[N][K][1]+DP[N][K][0]<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define range(i, a, b) for(auto i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const long double EPS = 1e-8;

void dfs(int n, vector <vector <int>>& G, vector <bool>& used, vector <int>& dist,
				 int turn, int cnt = 0){
	for (const auto& i : G[n]) {
		if (used[i]) continue;
		used[i] = true;
		dist[i] = cnt + 1;
		dfs(i, G, used, dist, turn, cnt + 1);
	}
	return;
}

signed main() {
	int n;
	cin >> n;
	vector <vector <int>> G(n);
	rep (i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector <vector <bool>> used(2, vector <bool> (n, false));
	used[0][0] = used[1][n - 1] = true;
	vector <vector <int>> dist(2, vector <int> (n));
	int fen = 0, snu = 0;
	rep (i, 2) dfs(i ? n - 1 : 0, G, used[i], dist[i], i);
	rep (i, n) {
		if (i == 0 || i == n - 1) continue;
		(dist[0][i] <= dist[1][i] ? fen : snu) += 1;
	}
	cout << (fen > snu ? "Fennec" : "Snuke") << endl;
	return 0;
}


Measured memory_bytes: 15088
import sys
input=sys.stdin.readline
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
a.sort()
from collections import deque
def getsm(q):
    last=q.popleft()
    sm=0
    for num in q:
        sm+=abs(last-num)
        last=num
    return sm

q = deque()
q.append(a[0])
l=0
r=n
while True:
    r-=1
    if r==l:
        break
    q.appendleft(a[r])
    r-=1
    if r==l:
        break
    q.append(a[r])
    l+=1
    if r==l:
        break
    q.appendleft(a[l])
    l+=1
    if r==l:
        break
    q.append(a[l])
ans1=getsm(q)


q = deque()
q.append(a[-1])
l=-1
r=n-1
while True:
    l+=1
    if r==l:
        break
    q.appendleft(a[l])
    l+=1
    if r==l:
        break
    q.append(a[l])
    r-=1
    if r==l:
        break
    q.appendleft(a[r])
    r-=1
    if r==l:
        break
    q.append(a[r])
ans2=getsm(q)
print(max(ans1,ans2))

Measured memory_bytes: 49756
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

#define T int
#define sort(v) (sort(v.begin(), v.end()))

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

	vector<T> A(n);
	for(int i = 0; i < n; i++)
		cin >> A[i];

	sort(A);
	int flg = 0;
	for(int i = 0; i < n - 1; i++){
		if(A[i] == A[i+1])
			flg = 1;
	}

	cout << (flg ? "NO" : "YES") << endl;
}

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

int main(){
  ll x;
  cin >> x;
  ll tmp = 100;
  ll count = 0;
  while(tmp < x){
    tmp *= 1.01;
    count++;
  }
  cout << count << endl;
}

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

int main(){
    int n,k,q;
    cin>>n>>k>>q;
    vector<int> p(n,k-q);
    for(int i=0;i<q;i++){
        int a;
        cin>>a;
        a--;
        p[a]++;
    }
    for(int i=0;i<n;i++){
        if(p[i]>0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = 2019;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int power(int a, int b, int m = mod){a %= m; if(b < 0)b += m-1; int r = 1; while(b){if(b&1)r=(r*a)%m; a = (a*a)%m; b>>=1;}return r;}

void solve(){
   string s;

   cin >> s;
   int n = (int)(s.size());

   vector<int> freq(mod);
   int ans = 0;

   reverse(s.begin(), s.end());
   freq[0]++;

   int pw = 1, ret = 0;
   for (int i = 0; i < n; ++i)
   {
      ans = (s[i] - '0') * pw + ans % mod;
      ans %= mod;
      pw *= 10;
      pw %= mod;
      ret += freq[ans];
      freq[ans]++;
   }

   cout<<ret;
}

int32_t main(){_
   
   int t = 1;
   //cin >> t;

   while(t--){
     solve();
     cout << endl;
   }
   

   return 0;
}

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

typedef long long LL;
typedef long double LD;
typedef pair < int, int > PII;
typedef pair < LL, LL > PLL;
typedef pair < LD, LD > PDD;

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
template < typename _T > inline void _DBG(const char *s, _T x) { cerr << s << " = " << x << "\n"; }
template < typename _T, typename... args > void _DBG(const char *s, _T x, args... a) { while(*s != ',') cerr << *s++; cerr << " = " << x << ','; _DBG(s + 1, a...); }

#ifdef LOCAL
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr if(0) cout
#endif

// ********************** CODE ********************** //

LL a, b, c, d, n;

int main()
{
    _upgrade
    cin >> a >> b >> c >> d;
    cin >> n;
    n *= 4LL;
    b = min(b, 2 * a);
    c = min(c, 2 * b);
    d = min(d, 2 * c);
    LL cost = (n / 8) * d;
    n %= 8;
    cost += (n / 4) * c;
    n %= 4;
    cost += (n / 2) * b;
    n %= 2;
    cost += n * a;
    cout << cost << "\n";
    return 0;
}


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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <int,int> ii;

const int mod = 1e9 + 7;
const ll INF = (1LL<<50);
const int N = 100005;
int main(){
	fastio;
	ll a,b,c,d;
	cin >> a >> b >> c >> d;
	cout << max(max(a*c, a*d), max(b*c, b*d)) << '\n';
	return 0;
}


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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

//--------------------------------------------
const double EPS = 1e-14;
const double PI  = acos(-1.0);

//--------------------------------------------

int main(){
  int a,b;

  scanf("%d %d",&a,&b);

  if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) printf("Possible\n");
  else printf("Impossible\n");
}


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

if N == K:
    print(1)
    exit()

if K == 2:
    print(N - 1)
    exit()

if N % K != 0:
    print((N - 1) // (K - 1) + 1)
else:
    print((N - 1) // (K - 1))



Measured memory_bytes: 13880
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
  ll l,r,ans;
  cin>>l>>r;
  if(r-l>=2018)
  {
    ans=0;
  }
  else
  {
    ll i,j;
    ans=2020;
    int f=0;
    for(i=l;i<r;i++)
    {
      for(j=i+1;j<=r;j++)
      {
     	if((i*j)%2019 <ans) ans=(i*j)%2019;
        if(ans==0) {f=1;break;}
      }
      if(f==1) break;
    }
  }
  cout<<ans;
  return  0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define erep(i,a,b) for(int i=a;i<=(int)(b);i++)
#define per(i,a,b) for(int i=(b)-1;i>(a);i--)
#define eper(i,a,b) for(int i=((int)(a));i>=b;i--)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n, d, x, ans;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n >> d >> x;
    rep(i, 0, n) {
        int a; 
        cin >> a;
        ans += d/a;
        if (d%a) ans++;
    }
    cout << ans + x << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main(){
	int n, k;
	int x, y, z;
	int s, ans;
	bool v = true;
	ans = 0;
	scanf("%d %d", &n, &k);
	ans = 1000000;
	f(i, n){
		scanf("%d %d", &x, &y);
		if (y <= k){
			if (ans > x)ans = x;
		}
	}
	if (ans == 1000000)printf("TLE\n");
	else printf("%d\n", ans);


	return 0;
}

Measured memory_bytes: 128
#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;

int main(){
    int n;
    scanf("%d", &n);
    lint a[n], b[n];
    rep(i, n) scanf("%lld", &a[i]);
    rep(i, n) scanf("%lld", &b[i]);
    lint tmp = 0;
    rep(i, n) tmp += (b[i] >= a[i] ? (b[i]-a[i])/2 : b[i]-a[i]);
    puts(tmp >= 0 ? "Yes" : "No");
}

Measured memory_bytes: 3920
#include<iostream>
#include<cstdio>
#include<cstring>
char s[1000];
int main() {
    scanf("%s",s+1);
    int n=strlen(s+1);
    int ans=0;
    int l=1,r=n;
    while(l<r) {
        if(s[l]!=s[r]) ans++;
        l++;r--;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll g(ll n) {
    if(n <= 0) {
        return 0;
    }
    ll r = n%4;
    if(r == 0) {
        return n;
    }
    else if(r == 1) {
        return 1;
    }
    else if(r == 2) {
        return n - r + 3;
    }
    else if(r == 3) {
        return 0;
    }
}
 
int main() {
    ll a, b;
    cin >> a >> b;
    ll ans = g(b)^g(a-1);
    out(ans);
    re0;
}

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

int main() {
  int K, S, C;
  cin >> K >> S;
  int counter = 0;
  for(int A = 0; A <= K; A++) {
    for(int B = 0; B <= K; B++) {
      C = S - A - B;
      if(0 <= C && C <= K) counter++;
    }
  }
  cout << counter << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
long long lcm(long long, long long);
long long gcd(long long, long long);
int main() {
	int a1, m1, a2, m2, a3, m3;
	long long x, y, z;
	while(cin >> a1 >> m1 >> a2 >> m2 >> a3 >> m3, a1 && m1 && a2 && m2 && a3 && m3) {
		x = y = z = 1;
		for(int i = a1 % m1; i != 1; i = i * a1 % m1) x++;
		for(int i = a2 % m2; i != 1; i = i * a2 % m2) y++;
		for(int i = a3 % m3; i != 1; i = i * a3  %m3) z++;
		cout << lcm(lcm(x, y), z) << endl;
	}
}

long long lcm(long long a, long long b) {
	return a * b / gcd(a, b);
}

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

Measured memory_bytes: 1156
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
#include<bitset>
typedef long long ll;
using namespace std;
int main() {
	ll a[1000];
	for (ll i = 0; i <= 2; ++i) {
		cin >> a[i];
	}
	ll sum = 0;
	sort(a, a + 3);
	ll x=2*a[2]-a[1]-a[0];
  	if(x%2==0)
      cout<<x/2<<endl;
  	else if(x%2==1)
      cout<<(x+3)/2<<endl;
  
}

Measured memory_bytes: 256
n,m,d=map(int, input().split(" "))
if d==0:
    node=n
else:
    if n<2*d:
        node=n
    else:
        node1=2*d
        node2=n-2*d
        node=node1*1+node2*2
print(node/(n**2)*(m-1))


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

#define pb push_back
#define sz(X) ((int)(X).size())
#define all(X) (X).begin(),(X).end()
#define ll long long
#define pi pair<int,int>
const int N=1e5+5,MOD=100;

using namespace std;

int n,m;
std::vector<int> g[N];
bool revealed[N];
int root[N];
int sz[N];

int find(int u){
	if(root[u]==u)return u;

	return root[u]=find(root[u]);
}
void go(int u){
	revealed[u]=1;

	for(auto v : g[u]){
		if(!revealed[v]){
			go(v);
		}
	}
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++)root[i]=i;
	for(int i=0,a,b,w;i<m;i++){
		scanf("%d %d %d",&a,&b,&w);
		g[a].pb(b);
		g[b].pb(a);

		int p1=find(a) ,p2=find(b);

		if(p1!=p2){
			root[p1]=p2;
			sz[p2]+=sz[p1];
			sz[p1]=0;
		}

	}
	priority_queue<pi>q;
	for(int i=1;i<=n;i++){

		q.push({sz[i],i});
	}
	int ans = 0;
	while(!q.empty()){

		auto p = q.top();
		int u=p.second;
		q.pop();

		if(!revealed[u]){
			ans++;
			go(u);
		}
	}

	printf("%d\n",ans );
	
}


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

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

using namespace std;
int main() {
	int a, b;
	cin >> a >> b;

	if (a + b >= 10)
		cout << "error" << endl;
	else
		cout << a + b << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int r,g,b;
    cin >> r >> g >> b;
    cout << ((10*g+b)%4==0?"YES":"NO") << endl;             
}


Measured memory_bytes: 256
#かけて最小公倍数になる　そのために必要な数がB
from fractions import gcd
N=int(input())
if N==1:
  print(1)
  exit()

mod=10**9+7
A=list(map(int, input().split()))
def lcm(a,b):
  return a//gcd(a,b)*b

if N==2:
  LCM=lcm(A[0],A[1])
  ans=((LCM//A[0])+(LCM//A[1]))%mod
  print(ans)
  exit()

LCM=1
#LCM%=mod
for a in A:
  LCM=lcm(LCM, a)
  #LCM%=mod
  
#print(LCM)
ans=0
for a in A:
  ans+=LCM//a
  #ans%=mod

print(int(ans%mod))



Measured memory_bytes: 6108
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define mset(x,y) memset(x,y,sizeof(x))
#define rep(i,n) for(int i=0;i<int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define rng(i,a,b) for(int i=int(a);i<=int(b);i++)
#define gnr(i,b,a) for(int i=int(b);i>=int(a);i--)
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
#ifdef LOCAL
#define dmp(...) _dmp(#__VA_ARGS__, __VA_ARGS__)
#else
#define dmp(...) (__VA_ARGS__)
#endif
template<class T> using vt=vector<T>;
template<class T> using vvt=vt<vt<T>>;
template<class TA,class TB> void chmax(TA&a,TB b){if(a<b)a=b;}
template<class TA,class TB> void chmin(TA&a,TB b){if(b<a)a=b;}
template<class TA,class TB>
ostream& operator<<(ostream& os,const pair<TA,TB>& p){
	return os<<"{"<<p.fi<<","<<p.se<<"}";
}
template<class T> ostream& operator<<(ostream& os,const vt<T>& v){
	os<<"{";for(auto& e:v)os<<e<<",";return os<<"}";
}
template<class TH> void _dmp(const char *sdbg, TH h){cout<<sdbg<<"="<<h<<endl;}
template<class TH, class... TA> void _dmp(const char *sdbg, TH h, TA...a){
while(*sdbg!=',')cout<<*sdbg++;cout<<"="<<h<<","; _dmp(sdbg+1, a...);
}
template<class T> void make_unique(vt<T>& v) {
	sort(all(v));v.erase(unique(all(v)),v.end());
}
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
int ri(){int x;cin>>x;return x;}
ll rll(){ll x;cin>>x;return x;}
vi rvi(int n){vi v;rep(i,n)v.pb(ri());return v;}
int n,m,h[100010];
vi g[100010];
void MAIN() {
	cin>>n>>m;
	rep(i,n)cin>>h[i];
	rep(i,m) {
		int u,v;cin>>u>>v;
		u--,v--;
		g[u].pb(v);
		g[v].pb(u);
	}
	int cnt=0;
	rep(i,n){
		bool flag=true;
		for(auto& v:g[i]) {
			if(h[v]>=h[i]) {
				flag=false;
				break;
			}
		}
		cnt+=flag;
	}
	cout<<cnt;
}
int main() {
	ios::sync_with_stdio(false);cin.tie(0);
	int T=1;
	//cin>>T;
	for(int tt=1;tt<=T;tt++) {
		MAIN();
	}
	return 0;
}

Measured memory_bytes: 9180
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
// dfmt on

void main()
{
    long N = lread();
    auto A = aryread();
    long[] ans;
    auto B = new long[](N);
    foreach_reverse (i; 0 .. N)
    {
        long tmp;
        long j = 1;
        while (j * (i + 1) - 1 < N)
        {
            tmp = tmp ^ B[j * (i + 1) - 1];
            j++;
        }
        if (tmp != A[i])
        {
            B[i] = 1;
            ans ~= i + 1;
        }
    }
    writeln(ans.length);
    if (ans.empty)
        return;
    foreach (i; 0 .. ans.length - 1)
        write(ans[i], " ");
    writeln(ans[$ - 1]);
}


Measured memory_bytes: 9644
while True:
    try:
        a = float(raw_input())
    except EOFError:
        break
    
    ls = [a]
    for i in range(9):
        if i%2 == 0:
            ls.append(ls[-1]*2.0)
        elif i%2 == 1:
            ls.append(ls[-1]/3.0)
    print sum(ls)

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

using namespace std;

using ll = long long;
using vll = vector<ll>;

vector<vector<int> > dp;

int f(const int i, int x) {
    if (i > 5) return x == 0;
    int& res = dp[i][x];
    if (res != -1) return res;
    res = 0;
    while (x >= 0) {
        res |= f(i + 1, x);
        x -= 100 + i;
    }
    return res;
}

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

    int n;
    cin >> n;
    dp.assign(6, vector<int>(n + 1, -1));

    cout << f(0, n) << '\n';
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
//using namespace __gnu_pbds;
#define rep(i,a,b) for(i=(a);i<=(b);i++)
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e18
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout)
#define SET(a,b) memset(a,b,sizeof(a))
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
//template<typename T>
//using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out <<  "(" << a.F << ", " << a.S << ")";
}
 
template<class A> ostream& operator << (ostream& out, const vector<A> &a) {
	out << "[";
	for (auto it = a.begin(); it != a.end(); ++it) {
		if (it != a.begin())
			out << ", ";
		out << *it;
	}
	return out << "]";
}
int main()
{
    boost;
    ll n,i,j,x,t,y,a,b;
	cin>>a>>b;
	x=(a*100LL)/8;
	y=b*10;
	ll t1,t2;
	if(floor(x*0.08)==a&&floor(x*0.1)==b) cout<<x;
	else if(floor(y*0.08)==a&&floor(y*0.1)==b) cout<<y;
	else {
		x++;
		y++;
		if(floor(x*0.08)==a&&floor(x*0.1)==b) cout<<x;
		else if(floor(y*0.08)==a&&floor(y*0.1)==b) cout<<y;
		else{
			x-=2;
			y-=2;
			if(floor(x*0.08)==a&&floor(x*0.1)==b) cout<<x;
			else if(floor(y*0.08)==a&&floor(y*0.1)==b) cout<<y;
			else cout<<"-1";
		}
	}
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter

s = readline().rstrip().decode()
check = ['1', '4', '7', '9']
counter = list(Counter(list(s)))
for k in counter:
    if k in check:
        check.pop(check.index(k))
if check:
    print('NO')
else:
    print('YES')


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
#define S set<int>
#define itn int
bool dbg = false;
itn n;
void solve() {
    int ans = n - 1;
    FOR(i, 2, sqrt(n) + 1) {
        if (n % i == 0) {
            ans = n / i + i - 2;
        }
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> n;
    solve();
    return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
l=[0]*(n+1)
b=[1]*(n+1)
l[1]=1
for i in range(m):
    x,y=map(int,input().split())
    b[x]-=1
    b[y]+=1
    l[y]=max(l[y],l[x])
    if b[x]==0:l[x]=0
print(sum(l))

Measured memory_bytes: 4596
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define pr(x) prev(x.end())
# define mset multiset
# define umap unordered_map
# define gcd __gcd
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)
# define lr(i,l,r) for(int i=l;(l>r?i>=r:i<=r);(l>r?--i:++i))

using namespace std;

template<class T> void umin(T &a,T b){a=min(a,b);}
template<class T> void umax(T &a,T b){a=max(a,b);}

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

const int mod = 1e9+7;//998244353
const int N = 1e5+5;



void solve(){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<(a+b-1)/b*c;
}

int main(){
	Speed();
	int T=1; 
	//cin>>T;	
	while(T--)
		solve();
	return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/

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

#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define endl '\n'
#define int long long
typedef long long li;
const int N = 1e5 + 10;
int n;
int a[N];
int dp[N];
int k;
int solve(int i){

	if(i>=n-1)
		return 0;
	if(dp[i]!=INT_MAX)
		return dp[i];

//	dp[i] = abs(a[i] - a[i-1]) + solve(i+1);
	for(int j = 1 ; j <= k ; ++j){
		if(i+j>=n)
			break;
		dp[i] = min(dp[i] , abs(a[i]-a[i+j]) + solve(i+j));

	}
	return dp[i];
}
signed main(){
	cin>>n>>k;
	for(int i = 0 ; i < n ; ++i)
		cin>>a[i];
	for(int i = 0 ; i < N ; ++i)
		dp[i] = INT_MAX;
	//cout<<dp[0]<<" "<<dp[1]<<endl;
	cout<<solve(0)<<endl;
}

Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>

using namespace std;
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
//typedef boost::multiprecision::cpp_int bigint;

ll sx, sy, tx, ty;

int main() {
	cin >> sx >> sy >> tx >> ty;
	ll dx = tx - sx;
	ll dy = ty - sy;
	for (ll d = 0; d < dx; d++)cout << "R";
	for (ll d = 0; d < dy; d++)cout << "U";
	for (ll d = 0; d < dx; d++)cout << "L";
	for (ll d = 0; d < dy; d++)cout << "D";
	cout << "D";
	for (ll d = 0; d <= dx; d++)cout << "R";
	for (ll d = 0; d <= dy; d++)cout << "U";
	cout << "L";
	cout << "U";
	for (ll d = 0; d <= dx; d++)cout << "L";
	for (ll d = 0; d <= dy; d++)cout << "D";
	cout << "R" << endl;
	return 0;
}

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

const int INF = 1e+9;
typedef pair<int, int> P;

int memo[100001];
int d[100001];
vector<int> G[100001];

int dfs(vector<int> b, int l){
	if(l == 0){
		for(int i = 0; i < b.size(); ++i){
			if(i)
				printf(" ");
			printf("%d", b[i]);
		}
		printf("\n");
	}
	else{
		for(int i = l; i > 0; --i){
			vector<int> temp = b;
			bool flag = false;
			temp.push_back(i);
			for(int j = 0; j < temp.size() - 1; ++j){
				if(temp[j] < temp[j + 1]){
					flag = true;
					break;
				}
			}
			if(flag)
				continue;
			dfs(temp, l - i);
		}
	}
}

int main() {
	int n;
	while(cin >> n && n){
		vector<int> blocks;
		dfs(blocks, n);
	}
	return 0;
}

Measured memory_bytes: 3544
query_n = int(input())

lst = []

for _ in range(query_n):
    query = input().split()
    
    if query[0] == "0":
        lst.append(query[1])
    elif query[0] == "1":
        print(lst[int(query[1])])
    elif query[0] == "2":
        del lst[-1]


Measured memory_bytes: 19828
n,s=map(int,input().split())
a=list(map(int,input().split()))

dp=[0]*(s+1)
for i in range(n+1):
    dp[0]=1
ans=0

for i,w in enumerate(a):
    for j in range(s-w,-1,-1):
        dp[j+w]+=dp[j]
        dp[j+w]%=998244353
    ans+=dp[-1]
    ans%=998244353
    dp[0]+=1

print(ans)


Measured memory_bytes: 42092
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cinttypes>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  
  int result = numeric_limits<int>::max();
  int lim = 2 * max(X, Y);
  for (int c = 0; c <= lim; ++c) {
    int has_a = c / 2;
    int has_b = c / 2;
    
    int need_a = max(0, X - has_a);
    int need_b = max(0, Y - has_b);
    
    result = min(result, c * C + need_a * A + need_b * B);
  }
  
  cout << result << '\n';
    
  return 0;
}


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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];
int getChar(char ch){
	if(ch == 'A') return 1;
	else if(ch == 'C') return 2;
	else if(ch == 'G') return 3;
	else if(ch == 'T') return 4;
	else return 0;
}
long long getKey(char str[]){
	long long sum = 0, p = 1,i;
	for(i = 0;i < strlen(str);i++){
		sum += p*(getChar(str[i]));
		p *=5;
	}
	return sum;
}
int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }
int find(char str[]){
	long long key,i,h;
	key = getKey(str);
	for(i = 0;;i++){
		h = (h1(key) + i * h2(key)) % M;
		if( strcmp(H[h],str) == 0) return 1;
		else if (strlen(H[h]) == 0 ) return 0;
	}
	return 0;
}
int insert(char str[]){
	long long key, i, h;
	key = getKey(str);
	for(i = 0;;i++){
		h = (h1(key) + i * h2(key)) % M;
		if(strcmp(H[h],str) == 0) return 1;
		else if(strlen(H[h]) == 0 ){
			strcpy(H[h],str);
			return 0;
		}
	}
	return 0;
}
int main(int argc, char const* argv[])
{
	char str[L],com[9];
	int i,n,h;
	std::cin >> n;
	for(i = 0;i < M;i++) H[i][0] = '\0';
	scanf("%d",&n);
	for(int i=0;i < n;i++){
		scanf("%s %s",com,str);
		if(com[0] == 'i'){
			insert(str);
			// printf("ins\n");
		}else{
			if( find(str) ){
				printf("yes\n");
			}else{
				printf("no\n");
			}
		}
	}
	return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ar array
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll mod = 1e9 + 7;
const ll inf = 2e9 + 5;
double PI = 3.14159265358979323846;

const int mxn = 1e3+5;
int n, m;
int dx[] = { -1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
char grid[mxn][mxn];

bool legal(int x, int y) {
    if (x < 1 or y < 1 or x > n or y > m or grid[x][y] == '#')return false;
    return true;
}

void solve() {

    cin >> n >> m;
    int sx, sy, ex, ey;
    cin >> sx >> sy >> ex >> ey;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m ; j++) {
            cin >> grid[i][j];
        }
    }

    // 0-1 bfs:
    int dist[n + 1][m + 1];
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            dist[i][j] = inf;
        }
    }

    deque<pi> q;
    q.push_front({sx, sy});
    dist[sx][sy] = 0;
    while (!q.empty()) {
        auto p = q.front();
        q.pop_front();
        int x = p.F;
        int y = p.S;
        for (int i = 0; i < 4; i++) {
            int xx = x + dx[i];
            int yy = y + dy[i];
            if (!legal(xx, yy))continue;
            if (dist[xx][yy] > dist[x][y]) {
                dist[xx][yy] = dist[x][y];
                q.push_front({xx, yy});
            }
        }

        for (int i = x - 2; i <= x + 2; i++) {
            for (int j = y - 2; j <= y + 2; j++) {
                int xx = i;
                int yy = j;
                if (!legal(xx, yy))continue;
                if (dist[xx][yy] > dist[x][y] + 1) {
                    dist[xx][yy] = dist[x][y] + 1;
                    q.push_back({xx, yy});
                }
            }
        }
    }
    if(dist[ex][ey] == inf){
        cout << -1 << endl;
    }else{
        cout << dist[ex][ey] << endl;
    }


}

int32_t main()
{
    IOS
    // int T; cin >> T; while (T--)
    solve();
    return 0;
}


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

int main() {
  int c[3][3];
  for(int i=0;i<9;i++){
    cin>>c[i/3][i%3];
  }
  int a[3];
  int b[3];
  bool res=false;
  a[0]=0;
  b[0]=c[0][0]-a[0];
  a[1]=c[1][0]-b[0];
  a[2]=c[2][0]-b[0];
  b[1]=c[0][1]-a[0];
  b[2]=c[0][2]-a[0];
  if(c[1][1]==a[1]+b[1] && c[1][2]==a[1]+b[2] && c[2][1]==a[2]+b[1] && c[2][2]==a[2]+b[2]){
    res=true;
  }
  if(res) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
inputed_str = input()
str_list = inputed_str.split(' ')
data = [int(i) for i in str_list]
target = data[0]
def how_much(a, b):
    sumnum = 0
    summoney = 0
    while sumnum < target:
        sumnum += a
        summoney += b 
    return summoney

x = how_much(data[1], data[2])
y = how_much(data[3], data[4])
print(min(x, y))


Measured memory_bytes: 5604
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
    
using namespace std;    
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

ll dist(pair<ll , ll>p1, pair<ll , ll>p2 ){
    return abs(p1.first - p2.first) + abs(p1.second - p2.second);
}


int main(){

    int N, M;
    cin >> N >> M;
    vector< pair<ll , ll> > a(N);
    vector< pair<ll , ll> > b(M);
    for(int i = 0; i < N; i++){
        ll a1, a2;
        cin >> a1 >> a2;
        a[i] = make_pair(a1, a2);
    }
    for(int i = 0; i < M; i++){
        ll a1, a2;
        cin >> a1 >> a2;
        b[i] = make_pair(a1, a2);

    }
    for(int i = 0; i < N; i++){
        int minInd = 0;
        ll minDist = 10000000000;
        for(int j = 0; j < M; j++){
            if(dist(a[i],b[j] ) < minDist  ){
                minDist = dist(a[i],b[j] );
                minInd = j;
            }
        }
        cout << minInd + 1 << endl;
    }

}


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

int main(){
  int S;
  cin >> S;
  vector<int> dp(2010, 0);
  
  dp[0]=1;
  dp[1]=0;
  dp[2]=0;
  
  for(int i = 3; i<=2000; i++){
    dp[i] = dp[i-1]+dp[i-3];
    dp[i] %= 1000000007;
  }
  
  cout << dp[S] << endl; 
}

      

Measured memory_bytes: 3592
inp = list(map(int,input().split())) 
n=inp[0]
d=inp[1]
ans=0
for _ in range(n):
    inp = list(map(int,input().split())) 
    a=inp[0]
    b=inp[1]
    if a**2+b**2 <=d**2:
        ans+=1
print (ans)

Measured memory_bytes: 9196
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	s := next()

	if s[0] != 'A' {
		fmt.Println("WA")
		return
	}

	cCount := 0
	for i := 2; i <= len(s)-2; i++ {
		if s[i] == 'C' {
			cCount++
		}
	}
	if cCount != 1 {
		fmt.Println("WA")
		return
	}

	for i := 0; i < len(s); i++ {
		if !(s[i] == 'A' || s[i] == 'C' || (s[i] >= 'a' && s[i] <= 'z')) {
			fmt.Println("WA")
			return
		}
	}

	fmt.Println("AC")
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int n;
string u;
long long a;
double ans,x;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x>>u;
		if(u[0]=='B') ans+=x*10000;
		else a+=x;
	}
	cout<<ans*38+a;
 	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <functional>
using namespace std;

int main(){
    int  N, T, A;
    scanf("%d", &N);
    scanf("%d %d", &T, &A);
    int min_index;

    float H[N];
    float tem[N];

    for(int i=0; i<N; i++){
        scanf("%f", &H[i]);
        H[i] = fabs(A - (T - (H[i]*0.006)));
        tem[i] = H[i];
    }

    sort(H, H+N, greater<float>());

    for(int i=0; i<N; i++){
        if(H[N-1] == tem[i]){
            min_index = i+1;
        }
    }
    
    printf("%d\n", min_index);

    return 0;

}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
typedef long long ll;

using ipair = pair<int, int>;

ll INF = 1e16+7;

bool operator>(const ipair a,const ipair b){return a.first > b.first;}

int MOD = 1e9+7;

int N, K;
vector<int> v;

ll solve(int l, int r, int d){
  ll ret = 0;
  vector<int> minus;

  int l_cnt=0;
  while(l_cnt < l){
    ret += v[l_cnt];
    if(v[l_cnt] < 0){
      minus.push_back(v[l_cnt]);
    }
    l_cnt++;
  }

  int r_cnt=0;
  while(r_cnt < r){
    ret += v[N-1-r_cnt];
    if(v[N-1-r_cnt] < 0){
      minus.push_back(v[N-1-r_cnt]);
    }
    r_cnt++;
  }

  sort(minus.begin(), minus.end());

  // cout << "===" << endl;
  // cout << "l:" << l << endl; 
  // cout << "r:" << r << endl; 
  // cout << "d:" << d << endl; 
  // rep(i, sz(minus)) cout << minus[i] << " ";
  // cout << endl;

  rep(i, min(d, sz(minus))){
    if(minus[i] < 0){
      ret -= minus[i];
    }
  }

  return ret;
}

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

  rep(i, N){
    int tmp;
    cin >> tmp;
    v.push_back(tmp);
  }

  ll ans = 0;
  for(int l=0; l<=K; l++){
    for(int r=0; r<=K-l; r++){
      if(l+r > N) continue;
      int d = K - (l+r);
      ans = max(ans, solve(l, r, d));

      // cout << "ans: " << ans << endl;
    }
  }
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
def main():
    A = input().split()
    length = len(A)
    stack = []
    for i in range(length):
        if A[i] == "+":
            stack.insert( 0, stack[1] + stack[0] )
            stack.pop(1)
            stack.pop(1)
        elif A[i] == "-":
            stack.insert( 0, stack[1] - stack[0] )
            stack.pop(1)
            stack.pop(1)
        elif A[i] == "*":
            stack.insert( 0, stack[1] * stack[0] )
            stack.pop(1)
            stack.pop(1)
        else :
            stack.insert( 0, int(A[i]) )
    print( stack[0] )

if __name__ == "__main__":
    main()



Measured memory_bytes: 5604