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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    int n;cin>>n;
    VPII r(n);
    VPII b(n);
    REP(i,n){
        cin>>r[i].first>>r[i].second;
    }
    REP(i,n){
        cin>>b[i].first>>b[i].second;
    }
    SORT_ASC(r);
    SORT_ASC(b);

    int result=0;

    vector<bool> rf(n,false),bf(n,false);
    REP(i,n){
        int idx=-1;
        int large = -1;
        REP(j,n){
            if(r[j].first>=b[i].first){
                break;
            }
            if(r[j].second>=b[i].second){
                continue;
            }
            if(rf[j]){
                continue;
            }

            if(r[j].second > large){
                idx=j;
                large=r[j].second;
            }
        }
        if(idx!=-1){
            result++;
            rf[idx]=true;
        }
    }
    cout<<result<<endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class D
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var s = Console.ReadLine();

		var d = s.ToLookup(c => c);
		var r = d['R'].LongCount() * d['G'].Count() * d['B'].Count();
		for (int i = 0; i < n; i++)
			for (int j = i + 1; j < n; j++)
				if (2 * j - i < n && s[i] + s[j] + s[2 * j - i] == 'R' + 'G' + 'B') r--;
		Console.WriteLine(r);
	}
}


Measured memory_bytes: 28324
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <functional>
#include <climits> // int ???????????§????????????????????????
using namespace std;
const int MAX_V = 100000; // ???????????°????????§???
const int MAX_E = 500000; // ????????°????????§???
const int INF = 10000; // ???????????§?????????(int ???????????§???)
struct E {
  int to, cost;
  E(int t, int c) : to(t), cost(c) {};
};
typedef pair<int, int> pii;
int v; // ????????°
vector<E> g[MAX_V]; // ??£??\?????????
int d[MAX_V]; // ??????s ????????????????????¢
void dijkstra(int s)
{
  // ??????
  fill(d, d + v, INF);
  d[s] = 0;
  // greater<pii>??§first ????°???????????????????????????????????????????
  priority_queue<pii, vector<pii>, greater<pii> > q;
  q.push(pii(0, s));
  // ??????s ????????????????????????????????¢????¨????
  while(!q.empty()){
    // ???????¢???????????????????????????????????????¢???????°???????????????¢???
    // ?????????????????¢???????????????????????¢????¢??????????
    pii p = q.top();
    q.pop();
    int from = p.second;
    if(d[from] < p.first)continue; // ???????????¢??§??????????????°??????
    // ???????????§????????°??????from ??????????????¢?¢????
    // ???????????¢????¢?????????????????????£??\????????????????????±?????´??°
    for(int i = 0; i < g[from].size(); ++i){
      int to = g[from][i].to;
      int cost = g[from][i].cost;
      if(d[to] > d[from] + cost){ // ???????????¢??¨??????????????´???
	d[to] = d[from] + cost;
	q.push(pii(d[to], to)); // ???????????¢???????£?????????????????????\
      }
    }
  }
}


int main()
{
  // ??\??????????????????gv ??????????????°???ge ???????????°???gr ????§????
  int gv, ge, gr;
  cin >> gv >> ge;
  v = gv;
  //fill(&g[0][0], &g[v][0], INF); // ??£??\??????????????????
  for(int i = 0; i < ge; ++i){
    // ??\??????????????????gs ??????????§???????gt ??????????????????gd ???????????????
    int gs, gt, gd,gd2;
    //cin >> gs >> gt >> gd >> gd2;
    scanf("%d,%d,%d,%d",&gs,&gt,&gd,&gd2);
    //printf("%d,%d,%d,%d",gs,gt,gd,gd2);

    g[gs-1].push_back(E(gt-1,gd)); // 2 ???????????????????????±????¨????
    g[gt-1].push_back(E(gs-1,gd2));
  }

  int goal,okane,daikin;

  //cin >> gr >> goal >> okane >> daikin;
  scanf("%d,%d,%d,%d",&gr,&goal,&okane,&daikin);


  dijkstra(gr-1);
  int kane=d[goal-1];
  dijkstra(goal-1);
  kane+=d[gr-1];

  // ??????????????????gr ????????????????????????????????¢

  cout << (okane-kane-daikin) << endl;
    
  return 0;
  
}

Measured memory_bytes: 3592
def calc_pw(arr)
  stack = []
  arr.each do |st|
    if st =~ /[0-9]+/
      stack.push(st.to_f)
    else
      b, a = stack.pop, stack.pop
      case st
        when "+"
          stack.push(a+b)
        when "-"
          stack.push(a-b)
        when "*"
          stack.push(a*b)
        when "/"
          stack.push(a/b)
      end
    end
  end
  return stack.first
end

while gets do
  arr = $_.split(' ')
  num = calc_pw(arr)
  puts sprintf("%.6f", num)
end

Measured memory_bytes: 6148
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

//defines
typedef long long ll;
typedef long double ld;
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define prev _prev
#define y0 y00

//permanent constants
const ld pi = acos(-1.0);
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int digarr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
const int alf = 26;
const int dig = 10;
const int two = 2;
const int th = 3;
const ll prost = 239;
const ll bt = 30;
const ld eps = 1e-9;
const ll INF = (ll)(1e18 + 239);
const int BIG = (int)(2e9 + 239);
const int MOD = 998244353; //1e9 + 7;
const ll MOD2 = (ll)MOD * (ll)MOD;

//random
mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

//constants
const int M = (int)(2e5 + 239);
const int N = (int)(2e3 + 239);
const int L = 20;
const int T = (1 << 20);
const int B = (int)sqrt(M);
const int X = 1e4 + 239;

int32_t main()
{
#ifdef ONPC
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s;
    cin >> s;
    int now = 0;
    ll ans = 0;
    int n = s.size();
    int i = 0;
    while (i < n)
    {
        if (s[i] == 'A')
        {
            now++;
            i++;
            continue;
        }
        if (i < n - 1 && s[i] == 'B' && s[i + 1] == 'C')
        {
            ans += now;
            i += 2;
            continue;
        }
        now = 0;
        i++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 720
#include<stdio.h>
 
int main(){
  int min,i,j,num[100],tmp,count=0,n;
   
  scanf("%d",&n);
   
  for(i=0;i<n;i++)scanf("%d",&num[i]);
   
  for(i=0;i<n;i++){
    min=i;
    for(j=i;j<n;j++){
      if(num[min]>num[j])min=j;
   }
    if(i!=min){
      tmp=num[i];
      num[i]=num[min];
      num[min]=tmp;
      count++;
    }
  }
   
  for(i=0;i<n-1;i++)printf("%d ",num[i]);
  printf("%d\n%d\n",num[i],count);
   
  return 0;
}

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


int main(){
    int n,k,i,ans;
    cin>>n>>k>>i;
    if(n==k){
        if(k!=i)ans=1;
        else ans=0;
    }
    else{
        if(n==i||k==i) ans=1;
        else ans=0;
    }
    if(ans)printf("Yes\n");
    else printf("No\n");
   
}

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

int main(void)
{
  char s[11];
  scanf("%s",s);

  int slen = strlen(s);

  int i,Ccnt=0;
  if(s[0]!='A'){
    printf("WA\n");
    return 0;
  }
  for(i=1;i<slen;i++)
    if((s[i]<'a')||(s[i]>'z')){
      if((i>=2)&&(i<=slen-2)&&(s[i]=='C')&&(Ccnt==0))
        Ccnt++;
      else{
        printf("WA\n");
	return 0;
      }
    }

  if(Ccnt!=1)
    printf("WA\n");
  else
    printf("AC\n");
  return 0;
}

Measured memory_bytes: 1620
#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 + 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T>using onset=tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}
void solve(){
  #ifndef ONLINE_JUDGE    
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
}
ld f(ld n){
  return (n*n);
}
signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    //*comment for all except cc/cf   
    ll n;
    ld d;
    cin>>n>>d; 
    pair<ll,ll>p[n];
    ll cnt=0;
    for(ll i=0;i<n;i++){
      cin>>p[i].ff>>p[i].ss; 
      ld ans=f(p[i].ff)+f(p[i].ss);
      ans=sqrt(ans);
      if(ans<=d){
        cnt++;
      }
    }
    cout<<cnt; 
    //printclock;
    return 0;
}
    

Measured memory_bytes: 6892
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;

ll par[100001];
ll ran[100001];
ll siz[100001];
 
void init(int n){
	for (int i = 0; i <= n; i++){
		par[i] = i;
		ran[i] = 0;
		siz[i] = 1;
	}
}
int find(int x){
	if (par[x] == x){
		return x;
	}else{
		par[x] = find(par[x]);
		return par[x];
	}
}
void unite(int x, int y){
	x = find(x);
	y = find(y);
	if (x == y) return;
 
	if (ran[x] < ran[y]){
		par[x] = y;
		siz[y] += siz[x];
	}else{
		par[y] = x;
		siz[x] += siz[y];
		if (ran[x] == ran[y]) ran[x]++;
	}
}
bool same(int x, int y){
	return find(x) == find(y);
}
int size(int x){
	return siz[find(x)];
}

int main(){
	int n, m;
	cin >> n >> m;
	init(n);
	vector<int> p(n+1);
	vector<pair<int, int> > vec(m);
	for (int i = 1; i <= n; i++){
		cin >> p[i];
	}
	for (int i = 0; i < m; i++){
		int x, y;
		cin >> x >> y;
		unite(x, y);
	}
	int ans = 0;
	for (int i = 1; i <= n; i++){
		if (same(i, p[i])) ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6588
#include<stdio.h>

int main(void)

{

int W,H,x,y,r;

scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

if(H>=y+r&&W>=x+r&&x-r>=0&&y-r>=0){

printf("Yes\n");

}

else{

printf("No\n");

}

return 0;

}

Measured memory_bytes: 584
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //e
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = 0;
  multiset<int> st;
  for (int i = 0; i < n; i++) {
    auto itr = st.upper_bound(-a[i]);
    if (itr == st.end()) {
      st.insert(-a[i]);
      ans++;
    } else {
      st.erase(itr);
      st.insert(-a[i]);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5376
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,int> p;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
const int INF = 1001001001;

vector<vector<int>> graph;
vector<bool> used;
int n, m;

bool dfs(int v, int d) {
  if(used[v] || d > 2) return false;
  if(v == n - 1) return true;
  used[v] = true;
  bool res = false;
  for(int u : graph[v]) {
    res |= dfs(u, d + 1);
  }
  return res;
}

int main() {
  
  cin >> n >> m;
  used.resize(n);
  graph.resize(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  bool ans = dfs(0, 0);
  cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}


Measured memory_bytes: 12016
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			decimal[] arr = Console.ReadLine().Trim().Split(' ').Select(hogehoge => decimal.Parse(hogehoge)).ToArray<decimal>();

			if (arr[0] / arr[2] > arr[1])
			{
				Console.WriteLine("No");
			}
			else
			{
				Console.WriteLine("Yes");
			}

		}

	}

}


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

using namespace std;

int n;
pair<int, int> a[100010];

bool cmp(pair<int, int> a, pair<int, int> b){
    return (a.first < b.first);
}

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

    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a, a + n, cmp);
    for(int i = 0; i < n; i++) cout << a[i].second + 1 << ' ';
}

Measured memory_bytes: 1664
#include <iostream>
#include <string>


int main()//170b
{
    int inX,inY;

    std::string ansYes("Yes"), retAns("No");

    // インプット
    std::cin >> inX >> inY;
    for (int i = 0;i <= inX; i++)
    {
        if (i * 2 + (inX - i) * 4 == inY)
        {
            retAns = ansYes;
        }


    }
    std::cout << retAns;

    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N, Q;
  cin >> N >> Q;
  vector<int> S(N), T(N), X(N);
  REP(i, N) cin >> S[i] >> T[i] >> X[i], S[i] -= X[i], T[i] -= X[i];
  vector<int> p(N);
  REP(i, N) p[i] = i;
  sort(p.begin(), p.end(), [&](int i, int j) {
    return X[i] < X[j];
  });
  vector<int> D(Q);
  set<pair<int, int>> st;
  REP(i, Q) cin >> D[i], st.emplace(D[i], i);
  vector<int> ans(Q, -1);
  for (int i : p) {
    auto it = st.lower_bound(make_pair(S[i], 0));
    while (it != st.end() && it->first < T[i]) {
      ans[it->second] = X[i];
      it = st.erase(it);
    }
  }
  REP(i, Q) cout << ans[i] << '\n';
}


Measured memory_bytes: 16000
from collections import Counter
from math import factorial
N = int(input())
S = [input()[0:1:] for i in range(N)]

march = ["M","A","R","C","H"]
list = []
c = Counter(S)
for k,v in c.items():
    if k in march:
        list.append(v)

ans = 0
if len(list) >= 3:
    for i in range(len(list)):
        for j in range(len(list)-1):
            for k in range(len(list)-2):
                if (i != j+1) and (j+1 != k+2) and (k+2 != i) and (i<j+1) and (j<k+1):
                    ans += list[i] * list[j+1] * list[k+2]

print(ans)


Measured memory_bytes: 4348
import java.util.*;
import static java.lang.System.*;
import java.io.*;
import java.math.*;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if (a > b) {
			for(int i = 0; i < a; i++)
				out.print(b);
		} else {
			for(int i = 0; i < b; i++)
				out.print(a);
		}

		out.close();
	}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}

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

int main(){
  int s;
  int s1, s2, s3;
    
  cin >>s;
  
  s1 = s % 2;
  s2 = (s / 10) % 2;
  s3 = (s / 100) % 2;
  
  cout << s1+s2+s3 <<endl;
  
}

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

using namespace std;

vector<int> to[100000], dist;

void dfs(int cur, int d, int p) {
    dist[cur] = d;
    for (auto v : to[cur]) {
        if (v == p) continue;
        dfs(v, d + 1, cur);
    }
}

int main(void) {
    int n, u, v; cin >> n >> u >> v;
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        to[a - 1].push_back(b - 1);
        to[b - 1].push_back(a - 1);
    }
    dist = vector<int>(n);
    vector<int> dist_t, dist_a;
    dfs(u - 1, 0, u - 1);
    dist_t = dist;
    dfs(v - 1, 0, v - 1);
    dist_a = dist;
    int mx = 0;
    for (int i = 0; i < n; i++) {
        if (dist_t[i] < dist_a[i]) {
            mx = max(mx, dist_a[i]);
        }
    }
    cout << mx - 1 << endl;
}

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

int N, K;
vector<int> a, dp;

int rec(int k) {
	if (dp[k] != -1)
		return dp[k];
	dp[k] = 0;
	for (int i = 0; i < N; i++) {
		if (k - a[i] < 0)
			break;
		dp[k] = dp[k] | (rec(k - a[i]) == 0);
	}
	return dp[k];
}

int main() {
	ios_base::sync_with_stdio(false);

	cin >> N >> K;
	a.resize(N);
	for (int i = 0; i < N; i++)
		cin >> a[i];
	dp.resize(K + 1, -1);
	if (rec(K)) {
		cout << "First";
	} else {
		cout << "Second";
	}

	return 0;
}

Measured memory_bytes: 8340
#include <stdio.h>
long long p = 998244353;
long long n, d, j;
long long a[100000];
long long ans = 1;
int main() {
	scanf("%lld", &n);
	scanf("%lld", &d);
	if (d)ans = 0;
	for (int i = 1; i < n; i++) {
		scanf("%lld", &d);
		a[d]++;
		if (d == 0)ans = 0;
	}
	d = n - 1;
	a[0] = 1; j = 1;
	while (d) {
		for (int i = 0; i < a[j]; i++) {
			ans *= a[j - 1];
			ans %= p;
		}
		d -= a[j];
		j++;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
long long int memo[3000][3000];
  long long int osec(vector<long long int> &v,int i,int j,long long int sum)
  {
    if(j==i+1)
      return max(v[i],v[j]);
    if(memo[i][j]!=-1)
      return memo[i][j];
    memo[i][j]=max(sum-osec(v,i+1,j,sum-v[i]),sum-osec(v,i,j-1,sum-v[j]));
    return memo[i][j];
  }
long long int strategy(vector<long long int> &v,long long int sum)
{
  for(int i=0;i<v.size();i++)
  {
    for(int j=0;j<v.size();j++)
    {
      memo[i][j]=-1;
    }
  }
  return osec(v,0,v.size()-1,sum);
}
int main()
{
  int n;
  cin>>n;
  vector<long long int> v;
  for(int i=0;i<n;i++)
  {
    long long int a;
    cin>>a;
    v.push_back(a);
  }
  long long int sum=0;
  for(int i=0;i<v.size();i++)
  {
    sum=sum+v[i];
  }
  long long int t=strategy(v,sum);
  cout<<t-(sum-t);
}

Measured memory_bytes: 70912
#include <iostream>
#include <vector>
#include <algorithm>

int main()
{
	long long N = 0, ans = 0;
	std::cin >> N;

	std::vector<long long> A(N), B(N);
	for (int i = 0; i < N; i++){
		std::cin >> A[i];
	}

	B = A;
	std::sort(B.begin(), B.end());

	for (int i = 0; i < N; i++){
		if (B[N - 1] <= A[i]){
			ans = B[N - 2];
		}
		else{
			ans = B[N - 1];
		}	
		std::cout << ans << std::endl;
	}	

	return 0;
}

Measured memory_bytes: 4736
#include <stdio.h>
#include <string.h>
#include <algorithm>


using LL = long long ;

int solve(int N, int h, int n)
{
    LL a = 4LL * n * h - n * 1LL * N - N * 1LL * h;
    LL b = N * 1LL * h * n;
    if (a == 0 || b % a != 0) return -1;
    if (b / a < 1 || b / a > 3500) return -1;
    return b / a;
}


int main()
{
    int N;
    scanf("%d", &N);
    for (int h = 1; h <= 3500; ++ h) {
        for (int n = 1; n <= 3500; ++ n) {
            int w = solve(N, h, n);
            if (w >= 1 && w <= 3500) {
                printf("%d %d %d\n", h, n, w);
                return 0;
            }
        }
    }
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e18,MOD=1e9+7;
const int iINF=1e9;
int main(){
    string s;
    cin>>s;
    if(s[0]=='S')cout<<"Cloudy"<<endl;
    else if(s[0]=='C')cout<<"Rainy"<<endl;
    else cout<<"Sunny"<<endl;
}

Measured memory_bytes: 256
from sys import exit

def func(i,j):
	f=True
	for x in range(M):
		for y in range(M):
			if A[i+x][j+y]!=B[x][y]:
				f=False
	return f


N,M=map(int,input().split())
A = []
B = []

for i in range(N):
	A.append(list(map(lambda x:1 if x=='#' else 0, input())))

for i in range(M):
	B.append(list(map(lambda x:1 if x=='#' else 0, input())))


for i in range(N-M+1):
	for j in range(N-M+1):
		if func(i,j):
			print('Yes')
			exit()

print('No')


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

int main() {
  int N,A,M;
    cin >> N >> A;
    
    M = N % 500;
  
  if (M <= A){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  } 
}

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

#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ll long long 
 
using namespace std;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	string s;
	cin>>s;
	int left=0;
	int right=1;
	int c=0;
     while(left<n)
     {
          if(s[left]==s[right])
          {
               c++;
               while(s[left]==s[right]&&right<n)
               {
                    right++;
               }
               left=right;
               right++;
          }
          else{
          c++;
          left++;
          }
          
     }
     cout<<c;

	return 0;
}

Measured memory_bytes: 3740
N = int(input())
L = list(map(int,input().split()))
one = list(filter(lambda x:x%2!=0,L))
two = list(filter(lambda x:x%4!=0 and x%2==0,L))
four = list(filter(lambda x:x%4==0,L))
if len(one) - len(four) == 1 :
    if len(two) >=1 :
        print("No")
    else:
        print("Yes")
elif len(one) <= len(four):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 14252
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>
#include<map>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;


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

	map<int, int> mp;

	for (int i = 0; i < N; ++i)
	{
		int A; cin >> A;
		mp[A]++;

		auto itr = mp.find(A);
		if (itr != mp.begin())
		{
			--itr;
			itr->second--;
			if (itr->second == 0)
			{
				//cout << "*" <<endl;
				int B = itr->first;
				mp.erase(B);
			}
		}
	}

	int ans = 0;
	for(auto & itr : mp)
	{
		ans += itr.second;
	}
	cout << ans << endl;
	return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

#define x(p) real(p)
#define y(p) imag(p)

const double eps=1e-8;
const double inf=1e12;
typedef complex<double> P;

namespace std{
  bool operator<(const P& a,const P& b){
    return x(a)==x(b)?y(a)<y(b):x(a)<x(b);
  }
}
double cross(const P& a,const P& b){
  return y(conj(a)*b);
}
double dot(const P& a,const P& b){
  return x(conj(a)*b);
}
struct L : public vector<P> { // line and segment
  L(const P& a,const P &b){
    push_back(a);
    push_back(b);
  }
};

P projection(const L& l,const P& p){
  P b=l[1]-l[0],c=p-l[0];
  return l[0]+b*x(c/b);
}
P reflection(const L& l,const P& p){
  return p+2.0*(projection(l,p)-p);
}
//// counter-clockwise
int ccw(P a,P b,P c) {
  b=b-a;c=c-a;
  if(cross(b,c)>0) return +1;       // counter clockwise
  if(cross(b,c)<0) return -1;       // clockwise
  if(dot(b,c)<0)   return +2;       // c--a--b on line
  if(norm(b)<norm(c)) return -2;       // a--b--c on line
  return 0;
}

bool intersectLL(const L& l,const L& m){
  return abs(cross(l[1]-l[0],m[1]-m[0]))>eps;
}
bool intersectSS(const L& s,const L& t){
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1])<=0&&ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1])<=0;
}
P crosspoint(const L& l,const L& m) {
  double A=cross(l[1]-l[0],m[1]-m[0]);
  double B=cross(l[1]-l[0],l[1]-m[0]);
  if (abs(A)<eps&&abs(B)<eps) return m[0]; // same line
  if (abs(A)<eps) assert(false); // !!!PRECONDITION NOT SATISFIED!!!
  return m[0]+B/A*(m[1]-m[0]);
}

int main(){
	cin.sync_with_stdio(false);
  int q;
  cin>>q;
  while(q--){
    P p[4];
    rep(i,4){
      double x,y;
      cin>>x>>y;
      p[i]=P(x,y);
    }
    P res=crosspoint(L(p[0],p[1]),L(p[2],p[3]));
    printf("%.10f %.10f\n", x(res),y(res));
  }
  return 0;
}

Measured memory_bytes: 3308
#include<stdio.h>

int main(void)
{
  int n;
  scanf("%d\n",&n);
  int i,h[n];
  for(i=0;i<n;i++)
    scanf("%d",&h[i]);

  int max=0,j=0;
  for(i=0;i<n-1;i++){
    if(h[i]>=h[i+1])
      j++;
    else{
      max=(max>j) ? max:j;
      j=0;
    }
  }
  max= max>j ? max:j;
  printf("%d\n",max);
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
  
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int N,A,B,C,D; cin >> N >> A >> B >> C >> D;
    string s; cin >> s;
    s = '0'+s;
    
    if(C < D){
        bool flg = true;
        for(int i=B+1; i<D; i++) if(s[i] == '#' && s[i+1] == '#') flg = false;
        for(int i=A+1; i<C; i++) if(s[i] == '#' && s[i+1] == '#') flg = false;

        if(flg) cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;

    } else {
        while(B<D){
            if(s[B-1] == '#' || s[B+1] == '#'){
                if(s[B+1] == '.') B++;
                else if(s[B+2] == '.') B += 2;
                else{
                    cout << "No" << endl;
                    return 0;
                }
            } else {
                break;
            }
        }
        if(D<B){
            cout << "No" << endl;
            return 0;
        }

        s[B] = '#';
        bool flg = true;
        for(int i=A+1; i<C; i++) if(s[i] == '#' && s[i+1] == '#') flg = false;
        if(!flg){
            cout << "No" << endl;
            return 0; 
        }

        for(int i=B+1; i<D; i++) if(s[i] == '#' && s[i+1] == '#') flg = false;
        if(!flg){
            cout << "No" << endl;
            return 0;
        }

        cout << "Yes" << endl;
        return 0;
    }
}

Measured memory_bytes: 772
import sys 
from collections import deque
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 LS(): return list(sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))

def main():
    x,n = IL()
    p = LI()
    i=0
    while True:
        if i==0:
            if not x in p:
                print(x)
                exit()
        else:
            if not x-i in p:
                print(x-i)
                exit()
            if not x+i in p:
                print(x+i)
                exit()
        i+=1
    return

if __name__=='__main__':
    main()

Measured memory_bytes: 9476
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = (ll)1 << 32;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef unsigned long long ul;
int k, n;
ll t[1 << 17], d[1 << 17];

priority_queue<LP> q;
priority_queue<LP,vector<LP>,greater<LP>> qq;
int used[1 << 17];
bool vanish[1 << 17];
priority_queue<ll> v[1 << 17];

//100000
const int MAX_N = (1 << 17);
int nn;LP dat[2 * MAX_N - 1];
void init(int n_) {
	nn = 1;
	while (nn < n_)nn *= 2;
	rep(i, 2 * nn - 1)dat[i] = { INF,-1 };
}
void update(int k, ll a) {
	k += nn - 1;
	dat[k] = { a,k - nn + 1 };
	while (k > 0) {
		k = (k - 1) / 2;
		dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
	}
}
LP query(int a, int b, int k, int l, int r) {
	if (r <= a || b <= l)return { INF,-1 };
	if (a <= l && r <= b)return dat[k];
	else {
		LP vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
		LP vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
		return min(vl, vr);
	}
}
int main() {
	cin >> n >> k; init(n+1);
	rep(i, n) {
		cin >> t[i] >> d[i];
		v[t[i]].push(d[i]);
	}
	ll sum = 0; ll num = 0;
	int cnt = 0;
	rep1(i, n) {
		if (!v[i].empty()) {
			ll val = v[i].top(); sum += val;
			qq.push({ val,i });
			v[i].pop();
			num++;
			update(i, val);
			used[i]++;
			while (!v[i].empty()) {
				val = v[i].top(); v[i].pop();
				q.push({ val,i });
			}
			cnt++;
		}
	}
	while (num > k) {
		LP x = qq.top(); qq.pop();
		sum -= x.first; vanish[x.second] = true;
		update(x.second, INF);
		used[x.second]--;
		num--;
		cnt--;
	}
	while (cnt < k) {
		LP x = q.top(); q.pop();
		sum += x.first;
		used[x.second]++;
		ll vval = dat[x.second + nn - 1].first;
		update(x.second, vval + x.first);
		cnt++;
	}
	ll ans = num * num + sum;
	for (ll i = num - 1; i > 0; i--) {
		LP x = query(0, n+1, 0, 0, nn);
		sum -= x.first; cnt -= used[x.second];
		vanish[x.second] = true; update(x.second, INF);
		//cout << cnt << endl;
		while (!q.empty() && cnt<k) {
			LP z = q.top(); q.pop();
			if (vanish[z.second])continue;
			sum += z.first; used[z.second]++;
			ll vval = dat[z.second + nn - 1].first;
			update(z.second, vval + z.first);
			cnt++;
		}
		//cout << sum << endl;
		ans = max(ans,i*i + sum);
	}
	cout << ans << endl;
	//stop
	return 0;
}


Measured memory_bytes: 16244
from fractions import gcd

N,M = map(int,input().split())
a = list(map(int,input().split()))

if len(set([i&-i for i in a])) != 1:
  print(0)
else:
  x = a[0]//2
  for i in range(1, len(a)):
      x = x*(a[i]//2//gcd(x,a[i]//2))

  print(M//x-M//(2*x))

Measured memory_bytes: 89580
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
import re
import math
import collections
import itertools
import functools

DEBUG = True
DEBUG = False

def dbg(*args):
    if DEBUG:
        print("DBG: ", file=sys.stderr, end="")
        print(*args, file=sys.stderr)



def main():
    W, a, b = map(int, input().split())

    if b+W >= a and b <= a+W:
        print(0)
    elif b+W < a:
        print(a-(b+W))
    elif b > a+W:
        print(b-(a+W))

if __name__ == "__main__": main()


Measured memory_bytes: 3956
import java.util.*;


public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		String S = scanner.nextLine();
	    int w = scanner.nextInt();
	    
	    String[] ar = S.split("");
	    String text = "";
	    int count;
	    count = S.length() / w;
	    if(S.length() - (S.length() / w) * w > 0) count  = S.length() / w + 1 ;
	    for(int i = 0; i<count; i++) {
	    		text = text + ar[w*i];
	    }
	    System.out.println(text);
		scanner.close();
	}

}


Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define mod 1000000007
#define vi vector<int>
#define si set<int>
#define pi pair<int,int>
#define li list<int>
#define fi first
#define in insert
#define se second
#define fr(i,n) for(i = 0 ; i < n ; i++)
int main()
{
    fio
    int h,w,i,j,k,n;
    cin>>h>>w;
    ll a[h][w];
char c[h][w];
fr(i,h)
fr(j,w)
cin>>c[i][j];

    a[0][0] = 1;
    for(i = 1;i<w;i++)
    {
        if(c[0][i]=='.')
                a[0][i] = a[0][i-1];
        else
            a[0][i] = 0;
    }

    for(i = 1;i<h;i++)
    {
        if(c[i][0]=='.')
            a[i][0] = a[i-1][0];
        else
            a[i][0] = 0;
    }
    for(i = 1; i<h;i++)
    {
       for(j = 1;j<w;j++)
        {   if(c[i][j]=='.')
                a[i][j] = (a[i-1][j]%mod+a[i][j-1]%mod)%mod;
            else
                a[i][j] = 0;
        }
    }
    cout<<a[h-1][w-1]%mod;
    return 0;
}


Measured memory_bytes: 9088
#include <algorithm>
#include <climits>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define DEBUG(x) cerr << #x << ": " << x << "\n"

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int N;
    cin >> N;
    cout << ceil(N, 111) * 111 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <queue>
using namespace std;
#define INF 1000000007
#define ll long long
#define rep(i, start, end) for(ll i=(ll)start; i<(ll)end; i++)
#define print(a) cout << a << endl;
#define printarray(a, len) rep(i,0,len) cout << a[i] << " ";
 
 
int main(){
  ll a, b;
  cin >> a >> b;
  print(max(max(a+b, a-b), a*b))
  return 0;
}

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

int main() {
    int P, ans = 0, max = 0;
    for (int i = 0; i < 5; ++i) {
        std::cin >> P;
        ans += P;
        if (P % 10 != 0) {
            ans += (10 - (P % 10));
            max = std::max(max, 10 - (P % 10));
        }
    }
     
    std::cout << ans - max << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>

using namespace std;
typedef long long int ll;typedef pair<int, int> P;
const long long mod = 1e9 + 7;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }

int main(void) {
	int a, b; cin >> a >> b;
	if (a > 9 || b > 9) {
		cout << -1 << endl;
	}
	else cout << a * b << endl;



	return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
//----------------------------------------------------------------

int MOD = 998244353;
// int MOD = 1000000007;


//----------------------------------------------------------------
signed main(){

	ll  n,k;
	cin >> n >> k;
	ll cnt = 0;
	rep(i,n){
		ll h;
		cin >> h;
		if(h >= k)cnt++;
	}
	cout << cnt << endl;



	
	

	return 0;
}

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

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://ddcc2017-final.contest.atcoder.jp/tasks/ddcc2017_final_b
// rm -r -f test;oj dl https://abc142.contest.atcoder.jp/tasks/abc142_b

Measured memory_bytes: 764
#include<bits/stdc++.h>
#define int long long
using namespace std;
int read(){
	int f=1,re=0;char ch;
	for(ch=getchar();!isdigit(ch)&&ch!='-';ch=getchar());
	if(ch=='-'){f=-1,ch=getchar();}
	for(;isdigit(ch);ch=getchar()) re=(re<<3)+(re<<1)+ch-'0';
	return re*f; 
}
int n,ans1,ans2;
signed main(){
	n=read();
	if(n) ans1=n/500;
	if(n) n=n%500;
	if(n) ans2=n/5;
	printf("%lld\n",ans1*1000+ans2*5);
	return 0;
}

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

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

    int n,cnt[2][111111];
    cin >> n;

    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        cnt[i&1][x]++;
    }

    int mx1=0,mx2=0,mxval=-1;

    for(int i=0;i<=100000;i++){
        if(cnt[1][i]>=mx1){
            mx2=mx1;
            mx1=cnt[1][i];
            mxval=i;
        }else if(cnt[1][i]>=mx2)
            mx2=cnt[1][i];
    }
    int res=INT_MAX;

    for(int i=0;i<=100000;i++){
        if(i==mxval)
            res=min(res,n-(mx2+cnt[0][i]));
        else
            res=min(res,n-(mx1+cnt[0][i]));
    }

    cout << res << endl;

    return 0;
}


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

int main(){
	string s1, s2, s3;
	char c1, c2, c3;
	cin >> s1 >> s2 >> s3;
	c1 = s1[0]-32;
	c2 = s2[0]-32;
	c3 = s3[0]-32;

	cout << c1 << c2 << c3 << endl;

	return 0;
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    vector<ll> x(n);
    vector<ll> y(n);
    vector<ll> plus(n);
    vector<ll> minus(n);
    rep(i,n){
        cin >> x[i] >> y[i];
        plus[i] = x[i] + y[i];
        minus[i] = x[i] - y[i];
    }
    sort(all(plus));
    sort(all(minus));
    ll a = plus.back() - plus.front();
    ll b = minus.back() - minus.front();
    cout << max(a, b) << endl; 


    return 0;
}

Measured memory_bytes: 9516
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<queue>
#include<set>
#include<map>
using namespace std;
#define INTMAX 1000000000
#define MOD 1000000007
#define LL long long
#define VI vector<int>
#define VVI vector<VI>
#define alf "abcdefghijklmnopqrstuvwxyz"

LL N, A[200002] = {}, ans = 0;

map<LL,int> sf;

int main(){
	cin >> N;
	sf[0] = 1;
	for(int i=1; i<=N; i++) {
		cin >> A[i];
		A[i] += A[i-1];
		if(sf.find(A[i]) == sf.end()) sf[A[i]] = 0;
		sf[A[i]]++;
}
	
	for(auto itr = sf.begin(); itr != sf.end(); itr++){
		LL cnt= itr->second;
		ans += (cnt * (cnt - 1)) / 2;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 14336
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






int R;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
int dx[4] = { 0, 1, 0, -1 }, dy[4] = { -1, 0, 1, 0 };
//---------------------------------------------------------------------------------------------------
int W, H, X, Y, A[505][505], dp[505][505], vis[505][505];
vector<pair<int,int>> get() {
    cin >> W >> H >> X >> Y;
    X--; Y--;
    rep(y, 0, H) rep(x, 0, W) cin >> A[y][x];

    rep(y, 0, H) rep(x, 0, W) dp[y][x] = inf;
    rep(y, 0, H) rep(x, 0, W) vis[y][x] = 0;
    dp[Y][X] = 1;

    min_priority_queue<pair<int, int>> que;
    que.push({ 1, Y * 505 + X });

    while (!que.empty()) {
        auto q = que.top(); que.pop();

        int c = q.first;
        int y = q.second / 505;
        int x = q.second % 505;

        if (vis[y][x]) continue;
        vis[y][x] = 1;

        rep(i, 0, 4) {
            int xx = x + dx[i];
            int yy = y + dy[i];

            if (0 <= xx and xx < W and 0 <= yy and yy < H) {
                int cc = max(c, A[yy][xx]);
                if (cc < dp[yy][xx]) {
                    dp[yy][xx] = cc;
                    que.push({ cc, yy * 505 + xx });
                }
            }
        }
    }

    map<int, int> cnt;
    rep(y, 0, H) rep(x, 0, W) cnt[dp[y][x]]++;

    vector<pair<int, int>> res;
    int sm = 0;
    fore(p, cnt) {
        sm += p.second;
        res.push_back({ sm, p.first });
    }
    return res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    while (cin >> R) {
        if (R == 0) return;
        auto a = get();
        auto b = get();

        int ans = inf;
        fore(p, a) {
            if (R <= p.first) {
                chmin(ans, p.second);
                continue;
            }

            int idx = lower_bound(all(b), make_pair(R - p.first, -inf)) - b.begin();
            if (idx < b.size()) {
                chmin(ans, p.second + b[idx].second);
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 13628
# -*- coding: utf-8 -*-
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
import copy
import math
sys.setrecursionlimit(10**6)

# lis_of_lis = [[] for _ in range(N)]


def zz(): return list(map(int, sys.stdin.readline().split()))


def z(): return int(sys.stdin.readline())


def S(): return sys.stdin.readline()[:-1]


def C(line): return [sys.stdin.readline() for _ in range(line)]


MOD = pow(10, 9)+7
N, K = zz()
A = zz()

# Aの中にある転倒数を求める
# Aの中にある転倒数 * K 個転倒数がある
# Aの各要素について、転倒数を求めておけば、それをK倍すればよい

num_tentou = [0] * N
num_tentou_within = [0] * N

for i in range(N):
    base = A[i]
    for j in range(N):
        if (base > A[j]):
            num_tentou[i] += 1
    for j in range(i + 1, N):
        if (base > A[j]):
            num_tentou_within[i] += 1
num = sum(num_tentou)
within_num = sum(num_tentou_within)
ans = -K*(K-1)*num//2 + K*(K-1)*num + within_num*K
print(ans % MOD)


Measured memory_bytes: 68836
n=int(input())
numlist=list(map(int,input().split()))
num=[]
for i in range(n):
  num.append(0)
count=0
for i in numlist:
  num[i]+=1
  if num[i]==3:
    count=-1
    break
  elif i==0 and num[0]==2:
    count=-1
    break
  else:
    pass
if count==-1:
  print(0)
else:
  count=2**(n//2)
  count=count%(10**9+7)
  print(count)

Measured memory_bytes: 14008
#include<iostream>
#include<cstring>
using namespace std;
const int BUF = 10;


int N;
bool adj[BUF][BUF];

void read() {
    int nEdge;
    memset(adj, 0, sizeof(adj));
    
    cin >> N >> nEdge;
    for (int i = 0; i < nEdge; ++i) {
        int s, t;
        cin >> s >> t;
        --s;
        --t;
        adj[s][t] = adj[t][s] = true;
    }
}


int rec(int cur, int mask, int dp[BUF][1 << BUF]) {
    int &ret = dp[cur][mask];
    if (ret != -1) return ret;
    
    if (mask == (1 << N) - 1) {
        return ret = 1;
    }
    
    ret = 0;
    for (int i = 0; i < N; ++i) {
        if (!adj[cur][i]) continue;
        if ((1 << i) & mask) continue;
        ret += rec(i, mask | (1 << i), dp);
    }
    
    return ret;
}

void work() {
    static int dp[BUF][1 << BUF];
    memset(dp, -1, sizeof(dp));
    cout << rec(0, 1, dp) << endl;
}


int main() {
    read();
    work();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s; 
int i=0;
int main()
{    
    getline(cin,s);
    while(i<s.length())
    {
        if(s[i]!='0'&&s[i]!='1')
        {
         if(i>0) s.erase(i-1,2),i--;
           else s.erase(i,1);
    }
    else i++;
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256