akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define all(v) v.begin(), v.end()

const ll mod=1000000007;

ll countBits(ll in){
  int res=0;
  for(;in>0;in>>=1){
    if((in&0x01)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}

ll powm(ll a,ll n, ll m){
  ll ret=1;
  while(n>0){
    if(n%2==1){
      ret=(ret*a)%m;
    }
    n>>=1;
    a=(a*a)%m;
  }
  return ret;
}

const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int n;cin>>n;
  vector<int> a(n,0);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(all(a));
  int ans=0;
  vector<bool> dp(a[n-1]+1,true);
  for(int i=0;i<n;i++){
    int val=a[i];
    for(int j=val*2;j<=a[n-1];j+=val){
      dp[j]=false;
    }
  }
  for(int i=0;i<n;i++){
    if(dp[a[i]]){
      ans++;
      if(i!=n-1&&a[i]==a[i+1]){
        ans--;
      }
      dp[a[i]]=false;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4048
N = int(input())
ans = 0
from itertools import product
for i in range(3, 10):
    for t in product(["7", "5", "3"], repeat=i):
        d = {"7":True, "5":True, "3":True}
        for v in t:
            d[v] = False
        if True in d.values():
            continue

        n = int("".join(t))
        if n <= N:
            ans += 1
print(ans)


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

const int maxn = 2e5 + 5;
long long dp[maxn];
int h[maxn], dq[maxn];

long long f(int i, int j) {
    return -2ll * h[i] * h[j] + dp[i] + h[i] * 1ll * h[i];
}

bool g(int i, int j, int k) {
    int ai = -2 * h[i], aj = -2 * h[j], ak = -2 * h[k];
    long long bi = dp[i] + h[i] * 1ll * h[i];
    long long bj = dp[j] + h[j] * 1ll * h[j];
    long long bk = dp[k] + h[k] * 1ll * h[k];
    return (bj - bi) / (ai - aj) >= (bk - bj) / (aj - ak);
}

int main() {
    int n; scanf("%d", &n);
    long long c; scanf("%lld", &c);
    for (int i = 1; i <= n; ++i) scanf("%d", &h[i]);
    dp[1] = 0;
    // h[j] * h[j] - 2 * h[j] * h[i] + h[i] * h[i] + C
    int l = 0, r = 0;
    dq[r++] = 1;
    for (int i = 2; i <= n; ++i) {
        while (r - l >= 2 && f(dq[l], i) >= f(dq[l + 1], i)) ++l;
        dp[i] = f(dq[l], i) + h[i] * 1ll * h[i] + c;
        while (r - l >= 2 && g(dq[r - 2], dq[r - 1], i)) --r;
        dq[r++] = i;
    }
    printf("%lld\n", dp[n]);
    return 0;
}


Measured memory_bytes: 3328
import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    N, X, M = MI()
    S = list([X])
    num = X
    for i in range(N-1):
        num = (num**2) % M
        if not num in S:
            S.append(num)
        else:
            break

    len_s = len(S)
    if len_s == N:
        print(sum(S))
    else:
        index_s = S.index(num)
        #循環を開始する前までの個数
        num1 = index_s
        sum1 = sum(S[0:index_s])
        
        #循環後
        num2 = len_s - index_s
        sum2 = sum(S)-sum1
        
        #循環する個数
        num3 = (N-num1) // num2
        sum3 = sum2 * num3
        
        #あまり
        num4 = (N-num1) % num2
        sum4 = sum(S[index_s:index_s+num4])
        
        ans = sum1+sum3+sum4
        print(ans)
    
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 74624
const chunks = [];
process.stdin.on("data", (chunk) => {
  chunks.push(chunk);
});
process.stdin.on("end", () => {
  const lines = Buffer.concat(chunks)
    .toString("utf8")
    .trim()
    .split("\n")
    .map((line) => line.split(" ").map((s) => parseInt(s, 10)));
  const [X, N] = lines[0];
  const ps = lines[1];
  console.log(solve(X, N, ps));
});

function solve(X, N, ps) {
  const set = new Set(ps);
  for (let i = 0; i <= 100; i++) {
    if (!set.has(X - i)) return X - i;
    if (!set.has(X + i)) return X + i;
  }
  return X;
}


Measured memory_bytes: 29844
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = l[0], M = l[1];
            Console.WriteLine(N==M?"Yes":"No");
        }
    }
}


Measured memory_bytes: 13268
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>
#include<time.h>
typedef long long int ll;
//#include<bits/stdc++.h>


using namespace std;
 


int main()
{
   
    int n, k;
    cin >> n >> k;
    set<int>p;
    for (int i = 0; i < k; i++) {
        int d;
        cin >> d;
        for (int j = 0; j < d; j++) {
            int x;
            cin >> x;
            p.insert(x);
        }
    }
    cout << n - p.size() << endl;
    return 0;

}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,t;
  cin>>n>>t;
  vector<Int> h(n);
  for(Int i=0;i<n;i++) cin>>h[i];
  vector<Int> s(n+1,0);
  for(Int i=0;i<n;i++) s[i+1]=s[i]+h[i];
  
  Int x=0;
  for(Int i=0;i<n;i++){
    if(t<=s[i]){
      cout<<1<<endl;
      continue;
    }
    if(h[x]<=h[i]) x=i;
    Int a=(t-s[i])/h[x];
    Int b=(t-s[i])%h[x];    
    cout<<a+(b>=h[i])+1<<endl;
  }  
  return 0;
}



Measured memory_bytes: 4408
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int main()
{
    vector<int> a(3);
    for(int i=0; i<3; ++i)
        cin >> a[i];

    sort(a.begin(), a.end());
    if(a == vector<int>({5, 5, 7}))
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
from itertools import accumulate

N = int(input())
L, R = [0], [0]
for i in range(N):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

L.sort(reverse=True)
R.sort()

L = list(accumulate(L))
R = list(accumulate(R))

ans = 0
for k in range(N+1):
    ans = max(ans, 2*(L[k] - R[k]))

print(ans)


Measured memory_bytes: 69336
chara = [chr(c) for c in range(ord('a'), ord('z') + 1)]
count = [50 for _ in range(len(chara))]
n = int(input())
for _ in range(n):
    s = input()
    count = [min(count[i], s.count(chara[i])) for i in range(26)]

ans = [(chara[i] * count[i]) for i in range(26)]
print(''.join(ans))


Measured memory_bytes: 3060
from itertools import permutations
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

t = 0
x = 0
y = 0
for i in permutations(range(1,n+1),n):
  t += 1
  if i == p: x = t
  if i == q: y = t

print(abs(x-y))

Measured memory_bytes: 9188
#include<bits/stdc++.h>
#define mo 1000000007
#define pi 3.1415926535898
#define eps 1e-9 
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
long long n,i,j,k,l,c[405][8],ans;
map<long long,long long> mp,mp2;
void add(long long x,long long flag){
	long long sum;
	for(long long y=0;y<=3;y++){
		sum=0;
		for(long long z=y;z<=y+3;z++)
			sum=sum*1007+c[x][z];
		mp2[sum]=x;
		mp[sum]+=flag;
	}
}
long long make_hash(long long x,long long y,long long z,long long w){
	long long sum=0;
	sum=sum*1007+x;
	sum=sum*1007+y;
	sum=sum*1007+z;
	sum=sum*1007+w;
	return sum;
}
int main(){
	//freopen("camp.in","r",stdin);
	//freopen("camp.out","w",stdout);
	long long x,p1,p2,p3,y,z,sum;
	n=read();
	for(i=1;i<=n;i++){
		for(j=0;j<=3;j++){
			c[i][j]=read();
			c[i][j+4]=c[i][j];
		}
		add(i,1);
	}
	for(i=1;i<=n;i++){
		add(i,-1);
		for(j=i+1;j<=n;j++){
			add(j,-1);
			for(k=0;k<=3;k++){
				x=c[i][7];p1=0;p2=0;p3=0;
				for(l=7;l>=1;l--)
					c[i][l]=c[i][l-1];
				c[i][0]=x;
				sum=1;
				
				x=make_hash(c[i][1],c[i][0],c[j][1],c[j][0]);
				if(mp[x]!=0){
					sum=sum*mp[x];
					p1=mp2[x];
					add(p1,-1);
				}
				else
					sum=0;
					
				x=make_hash(c[i][2],c[i][1],c[j][0],c[j][3]);
				if(mp[x]!=0){
					sum=sum*mp[x];
					p2=mp2[x];
					add(p2,-1);
				}
				else
					sum=0;
				
				x=make_hash(c[i][3],c[i][2],c[j][3],c[j][2]);
				if(mp[x]!=0){
					sum=sum*mp[x];
					p3=mp2[x];
					add(p3,-1);
				}
				else
					sum=0;
				
				x=make_hash(c[i][0],c[i][3],c[j][2],c[j][1]);
				if(mp[x]!=0)
					sum=sum*mp[x];
				else
					sum=0;
				
				ans+=sum;
				
				if(p1!=0)
					add(p1,1);
				if(p2!=0)
					add(p2,1);
				if(p3!=0)
					add(p3,1);
			}
			add(j,1);
		}
		add(i,1);
	}
	pus(ans/3,2);
	return 0;
}

Measured memory_bytes: 80256
local function main()
    a,b,x=io.read("*n","*n","n")
    c=2*x/a/b
    if c<=a then
        print(180*math.atan(b/c)/math.acos(-1))
    else
        print(180*math.atan((2*b-2*x/a/a)/a)/math.acos(-1))
    end
end

main()

Measured memory_bytes: 888
#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn=2e5+1e2;
const int maxs=6e6+1e2;

#define LL long long

int a[maxn],root[maxn];
LL sum[maxn],num[maxn];

struct node
{
	int l,r,sum;
}tr[maxs];

int cnt=0;

int getint()
{
	char ch;int b=1;
	for(ch=getchar();ch>'9'||ch<'0';ch=getchar())if(ch=='-')b=-1;
	int num=ch-'0';
	for(ch=getchar();ch>='0'&&ch<='9';ch=getchar())num=num*10+ch-'0';
	return num*b;
}

LL v;
void insert(int l,int r,int &now)
{
	tr[++cnt]=tr[now];
	now=cnt;
	tr[now].sum++;
	if(l==r)return;
	int mid=(l+r)>>1;
	if(v<=num[mid])insert(l,mid,tr[now].l);
	else insert(mid+1,r,tr[now].r);
}

LL query(int l,int r,int now1,int now2)
{
	if(num[l]>=v)return tr[now1].sum-tr[now2].sum;
	int mid=(l+r)>>1;
	if(v<=num[mid])return query(l,mid,tr[now1].l,tr[now2].l)+query(mid+1,r,tr[now1].r,tr[now2].r);
	return query(mid+1,r,tr[now1].r,tr[now2].r);
}

int main()
{
	int n=getint(),k=getint();
	for(int i=1;i<=n;i++)a[i]=getint();
	for(int i=1;i<=n;i++)sum[i]=sum[i-1]+a[i];
	for(int i=1;i<=n;i++)sum[i]-=(LL)k*i;
	for(int i=1;i<=n;i++)num[i]=sum[i];
	sort(num+1,num+n+1);
	int m=unique(num+1,num+n+1)-num-1;
	for(int i=1;i<=n;i++)
	{
		root[i]=root[i-1];
		v=sum[i];
		insert(1,m,root[i]);
	}
	LL now=0,ans=0;
	for(int i=1;i<=n;i++)
	{
		v=now;
		if(v<=num[m])ans+=query(1,m,root[n],root[i-1]);
		now+=a[i]-k;
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
  long n, i, ans = 0;
  cin >> n;
  
  vector<long> a(3 * n);
  for(i = 0; i < 3 * n; i++){
    cin >> a.at(i);
  }
  
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  
  for(i = 0; i < n; i++){
    ans += a.at(2 * i + 1);
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 2560
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N, X, D;
std::map<ll, std::map<ll, ll>> mp;

int main() {
  std::cin >> N >> X >> D;

  if( !D ) {
    if( !X ) {
      std::cout << 1 << endl;
    }
    else {
      std::cout << N+1 << endl;
    }

    return 0;
  }
  
  ll ans = 0;

  rep( k, N+1 ) {
    ll B = X*k;
    ll L = B+D*k*(k-1)/2;
    ll R = B+D*(N-k+N-1)*k/2;

    ll m = (B%D+D)%D;

    ++mp[m][(L-m)/D];
    --mp[m][(R-m)/D+1];
  }

  for( auto m : mp ) {
    auto es = m.second;

    ll acc = 0, prv = -1;

    for( auto p : es ) {
      auto [i, x] = p;

      if( acc > 0 )
        ans += i-prv;

      acc += x;
      prv = i;
    }
  }

  std::cout << ans << endl;

  return 0;
}

Measured memory_bytes: 78384
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;

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

#define M 1111111
int sosu[M];

int main(){
	sosu[0]=sosu[1]=1;
	rep(i,M){
		if(sosu[i]==0){
			for(int j=i*2;j<M;j+=i){
				sosu[j]=1;
			}
		}
	}
		
	
	while(1){
		int a,d,n;
		cin>>a>>d>>n;
		
		if(a==0 && d==0 && n==0)break;
		
		int count = 0;
		while(1){
			if(sosu[a]==0)count++;
			if(count==n){
				printf("%d\n",a);
				break;
			}
			a+=d;
		}
	}
}

Measured memory_bytes: 5484
#include <bits/stdc++.h>
using namespace std;
int digcou(long long a){
  int cou=0;
  while(a){
    cou++;
    a/=10;
  }
  return cou;
}
int main(){
long long n;
  int ans=15;
  cin>>n;
  for(int i=1;i<=sqrt(n);++i){
    if(n%i==0){
      ans=min(ans,max(digcou(i),digcou(n/i)));
    }
  }
  cout<<ans<<endl;
}


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

int main() {
  int A, B; cin >> A >> B;

  int Ans = 0;
  int Plug = 1;
  while ( Plug<B ) {
    Plug--;
    Plug += A;
    Ans++;
  }
  cout << Ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define NUMBER_MAX 1000000000

int main()
{
	int n, element, minimam, max_value = -NUMBER_MAX;

	cin >> n;
	cin >> minimam;
	for (int i = 0; i < n - 1; i++) {
		cin >> element;
		if (max_value < element - minimam)
			max_value = element - minimam;
		if (element < minimam)
			minimam = element;
	}
	cout << max_value << endl;
	return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const ll MOD = 939561957918767; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
//ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 2e5;
int n, c[N];
ll d[N];
V<int> e[N];
stack<int> t[N];
int dfs(int a, int p){
  int r = 1, cc = c[a];
  for(int b:e[a])if(p != b){
    t[cc].push(0);
    int rr = dfs(b, a);
    ll o = rr-t[cc].top();
    d[cc] += o*(o+1)/2;
    t[cc].pop();
    r += rr;
  }
  t[cc].top() += r;
  return r;
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n){
    t[i].push(0);
    cin >> c[i];
    c[i]--;
  }
  FOR(i, 1, n){
    int a, b;
    cin >> a >> b;
    a--; b--;
    e[a].pb(b);
    e[b].pb(a);
  }
  dfs(0, -1);
  ll k = ll(n)*(n+1)/2;
  FOR(i, 0, n){
    ll o = n - t[i].top();
    cout << k - d[i] - o*(o+1)/2 << endl;
  }
}


Measured memory_bytes: 173092
/*May The Force Be With Me*/
#include <bits/stdc++.h>
#include <stdio.h>
#include <ctype.h>
#pragma GCC optimize ("Ofast")
#define ll long long
#define MOD 1000000007
#define endl "\n"
#define vll vector<long long>
#define mll map<long long,long long>
#define pll pair<long long, long long>
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define pb push_back
#define f first
#define s second
#define inf INT_MAX
#define size_1d 10000000
#define size_2d 1000
#define rep(i,v,n) for(ll i = v; i < n; i++)
//Snippets: delta, sieve, fastexp, dfs, bfs, dijkstra, floodfill

using namespace std;

string a, b;

void Input() {
	cin >> a >> b;
}

void Solve() {
	ll n = a.size(), m = b.size();
	ll c[n + 1][m + 1];
	memset(c, 0, sizeof c);
	for (ll i = 0; i <= n; i++) for (ll j = 0; j <= m; j++) {
			if (!i or !j)continue;
			else if (a[i - 1] == b[j - 1])c[i][j] = 1 + c[i - 1][j - 1];
			else c[i][j] = max(c[i - 1][j], c[i][j - 1]);
		}
	string ans = "";
	ll i = n, j = m;
	while (i > 0 and j > 0) {
		if (a[i - 1] == b[j - 1])ans += a[i - 1], i--, j--;
		else if (c[i - 1][j] > c[i][j - 1])i--;
		else j--;
	}
	reverse(all(ans));
	cout << ans;
}

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

	ll T = 1;
	//cin >> T;
	//ll t = 1;
	while (T--) {
		Input();
		//cout << "Case " << t << ": ";
		Solve();
		//t++;
	}
	return 0;
}

Measured memory_bytes: 73900
import sys
input = sys.stdin.readline
from collections import *

N, M = map(int, input().split())
ins = [0]*N
outs = defaultdict(list)

for _ in range(M):
    x, y = map(int, input().split())
    ins[y-1] += 1
    outs[x-1].append(y-1)

q = deque([v for v in range(N) if ins[v]==0])
dp = [0]*N

while q:
    v = q.popleft()
    
    for nv in outs[v]:
        dp[nv] = max(dp[nv], dp[v]+1)
        ins[nv] -= 1
        
        if ins[nv]==0:
            q.append(nv)

print(max(dp))

Measured memory_bytes: 67036
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
using datas=pair<ll,ll>;
using tdata=pair<datas,ll>;

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncrlistp[200000],modncrlistm[200000];

ll modncrs(ll n,ll r){
  ll i,j;
  if(modncrlistp[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistp[i])break;
    }
    if(i<0){
      modncrlistp[0]=1;
      rep1(i,n+1){
        modncrlistp[i]=(modncrlistp[i-1]*i)%mod;
      }
    }else{
      For(j,i+1,n+1){
        modncrlistp[j]=(modncrlistp[j-1]*j)%mod;
      }
    }
  }
  if(modncrlistm[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistm[i])break;
    }
    if(i<0){
      modncrlistm[0]=1;
      rep1(i,n+1){
        modncrlistm[i]=(modncrlistm[i-1]*modinv(i))%mod;
      }
    }else{
      For(j,i+1,n+1)modncrlistm[j]=(modncrlistm[j-1]*modinv(j))%mod;
    }
  }
  return (((modncrlistp[n]*modncrlistm[r])%mod)*modncrlistm[n-r])%mod;
}

ll modncr(ll n,ll r){
  if(r*2>n)return modncr(n,n-r);
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll euclidean_gcd(ll a, ll b) {
  if(a<b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

void printmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  For(i,0,H+2){
    For(j,0,W+2){cout<<a[i*(W+2)+j];}
    cout<<endl;
  }
}
void inputmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  string ss;
  For(i,1,H+1){
    cin>>ss;
    For(j,1,W+1){
      if(ss[j-1]=='#'){
        a[i*(W+2)+j]=1;
      }else{
        a[i*(W+2)+j]=0;
      }
    }
  }
}

int main(){
  ll i,j,N,M,a,b,c;
  cin>>N>>M;
  vec ans(8,0);
  mat v(8,vec(N));
  rep(i,N){
    cin>>a>>b>>c;
    v[0][i]=a+b+c;
    v[1][i]=a-b+c;
    v[2][i]=a+b-c;
    v[3][i]=a-b-c;
    rep(j,4)v[j+4][i]=-v[j][i];
  }
  rep(i,8){
    vrsort(v[i]);
    rep(j,M)ans[i]+=v[i][j];
  }
  vrsort(ans);
  cout<<ans[0]<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll int
#define mp make_pair
#define pb push_back
#define pa pair<int,int>
#define st first
#define nd second
#define ld long double
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int MAX=1e5+5;
int dp[MAX];

const int mod=1e9+7;
void add_self(int & a,int  b)
{
    a+=b;
    if (a>=mod)
    {
        a-=mod;
    }
}

void sub_self(int & a,int  b)
{
    a-=b;
    if (a<0)
    {
        a+=mod;
    }
}

int main() {
    int n, k;
    scanf("%d%d", &n, &k);

    // dp[i] - the number of ways such that we used i candies so far
    dp[0] = 1;
    for(int child = 0; child < n; ++child) {
        int up_to;
        scanf("%d", &up_to);
        int fake[MAX];
        for (int i=0;i<MAX-1;i++)
        {
            fake[i]=0;
        }
        for(int used = k; used >= 0; --used) {
            int tmp = dp[used];
            int L = used + 1;
            int R = used + min(up_to, k - used);
            if(L <= R) {
                add_self(fake[L], tmp);
                if(R + 1 <= k) {
                    sub_self(fake[R+1], tmp);
                }
            }
        }
        int prefix_sum = 0;
        for(int i = 0; i <= k; ++i) {
            add_self(prefix_sum, fake[i]);
            add_self(dp[i], prefix_sum);
        }
    }
    printf("%d\n", dp[k]);
}


Measured memory_bytes: 1024
// Template
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
#include <complex>
#include <cassert>
#define rep(i, x) for (int i = 0; i < (x); ++i)
#define rng(i, x, y) for (int i = (x); i < (y); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
void solve();
int main() {
    // ios::sync_with_stdio(false);
    // cin.tie(nullptr);
    // cout << fixed << setprecision(10);
    solve();
    return 0;
}


// Main Code
void solve() {
    int h, w;
    cin >> h >> w;
    rep(i, h) rep(j, w) {
        string s;
        cin >> s;
        if (s == "snuke") {
            cout << (char)('A' + j) << i + 1 << "\n";
        }
    }
    return;
}


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

string s;

void abc120c() {
  int n = s.size(), cnt_0 = 0, cnt_1 = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '0') {
      cnt_0++;
    }
    else {
      cnt_1++;
    }
  }

  if (cnt_0 == 0 || cnt_1 == 0) {
    cout << 0 << '\n';
    return;
  }
  else {
    cout << 2 * min(cnt_0, cnt_1) << '\n';
    return;
  }
}

int main() {
  cin >> s;
  abc120c();
  return 0;
}

Measured memory_bytes: 512
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

template <typename T>
bool chmax(T &a, const T& b) {
    if (a < b) {
      a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
    if (a > b) {
      a = b;
      return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N,K;
    cin >> N >> K;
    vl V(N);
    rep(i,N) cin >> V[i];
    ll ans=0;
    rep(p,min(N,K)+1){
        rep(q,min(N,K)+1-p){
            ll res=0;
            priority_queue<ll,vector<ll>,greater<ll>> pq;
            rep(i,p){
                pq.push(V[i]);
                res+=V[i];
            }
            rep(i,q){
                pq.push(V[N-1-i]);
                res+=V[N-1-i];
            }
            rep(t,min((ll)p+q,K-p-q)){
                ll x=pq.top();
                pq.pop();
                if(x<0){
                    res-=x;
                }
            }
            chmax(ans,res);
        }
    }
    cout << ans << endl;
}

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

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

int main(){
    int k;
    string s;
    cin >> k >> s;
    int len = min(k, int(s.length()));
    rep(i,len){
        cout << s[i];
    }
    if (k<int(s.length())){
        cout << "...";
    }

    cout << endl;
    
}

Measured memory_bytes: 3628
public class
Main
{
  public static int
  gcd (
    int a,
    int b
    )
  {
    if ( a == 0 ) return ( b );

    return
    gcd ( b % a, a );
  }

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

    while ( cin.hasNext ( ) )
    {
      int a, b;

      a = cin.nextInt ( ); b = cin.nextInt ( );
      System.out.println ( gcd ( a, b ) + " " + a / gcd ( a, b ) * b );
    }

    return ;
  }
}

Measured memory_bytes: 12000
while True:
    H, W = map(int, input().split(' '))
    if H == 0 and W == 0:
        break
    
    for i in range(H):
        for j in range(W):
            
            if  i == 0 or j == 0 or i == H - 1 or j == W - 1:
                print('#', end = '')
            else:
                print('.', end = '')
        print()
    print()
    


Measured memory_bytes: 7000
/*
 * @Author: BilyHurington
 * @Date: 2020-03-22 20:53:17
 * @LastEditors: BilyHurington
 * @LastEditTime: 2020-03-22 21:13:36
 */
#include<bits/stdc++.h>
using namespace std;
int n,s,a[3010];
long long f[3010];
const int mod=998244353;
int main(){
    scanf("%d %d",&n,&s);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    long long ans=0;
    for(int i=1;i<=n;i++){
        for(int j=s-a[i];j>=0;j--){
            f[j+a[i]]=(f[j+a[i]]+f[j])%mod;
        }
        f[a[i]]+=i;
        ans+=f[s]%mod;
        ans%=mod;
        // for(int i=0;i<=s;i++) printf("%lld ",f[i]);
        // printf("\n");
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    cout << fixed << setprecision(10);
    
    int N; cin >> N;
    vector<P> BA(N);
    rep(i, N) {
        int a, b;
        cin >> a >> b;
        BA[i] = make_pair(b, a);
    }
    sort(BA.begin(), BA.end());
    ll nt = 0;
    rep(i, N) {
        int a, b;
        a = BA[i].second;
        b = BA[i].first;
        if (nt+a > b) {
            cout << "No" << endl;
            return 0;
        } else {
            nt += a;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define forn(i,n) for(int i=0;i<n;i++)
#define fre(i,a,b) for(int i = a; i < b; i++)
#define sf(n) scanf("%lld", &n)
#define sff(a,b) scanf("%lld %lld", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pfn(n) printf("%d\n", n)
#define pfs(n) printf("%d ", n)
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long int
#define f find
#define ub upper_bound
#define lb lower_bound
#define ld long double
#define in insert
#define bs binary_search  
#define le length()
ll max_i=1e16+7;
#define np(s) next_permutation(s.begin(),s.end())
//it gives the lexicographically next string//

int main()
{
    int t=1;
    //cin>>t;
    while(t--)
    {
       ll a,b,c,k;
       cin>>a>>b>>c>>k;
       if(k<=a) cout<<k;
       else if(k>a && k<=a+b) cout<<a;
       else if(k>a+b) cout<<a-(k-a-b);
    }
	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
using namespace std;
int main(){
  int n,a,result=0;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a;
    if(a%2==1) result++;
  }
  cout << (result%2==0 ? "YES" : "NO") << endl;
  return 0;
}

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

typedef int64_t ll;

template <class T1, class T2>
using dict = std::unordered_map<T1, T2>;

int main(){
    string o,e;
    cin >> o;
    cin >> e;
    string ans = "";
    
    for (int i=0;i<e.size();i++){
        ans += o.at(i);
        ans += e.at(i);
    }
    if(o.size()>e.size()) ans += o.at(o.size()-1);

    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <vector>
#include <chrono>
#include <random>
#include <stack>
#include <ctime>
#include <queue>
#include <list>
#include <set>
#include <cstring>
#include <cstdlib>
#include <cctype>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define FORR(i, m, n) for(int i = m; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define INF 999999999

using namespace std;

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

void swap(int *X, int *Y){
    int t = *X; *X = *Y; *Y = t;
}

int vector_finder(vector<int> vec, int number) {
    auto itr = find(vec.begin(), vec.end(), number);
    size_t index = distance( vec.begin(), itr );
    if (index != vec.size()) { // 発見できたとき
        return 1;
    }
    else { // 発見できなかったとき
        return 0;
    }
}

int main() {
    int x;
    cin >> x;
    if (x == 1) {
        cout << 1 << endl;
        return 0;
    }
    vector<int > Exp;
    int b = 2, p = 2;
    while(true) {
        if (pow(b, p) <= x) {
            Exp.push_back(pow(b, p));
            ++p;
        } else {
            ++b, p = 2;
            if (pow(b, p) > x) break;
        }
    }

    sort(Exp.begin(), Exp.end());
    vector<int >::iterator it = lower_bound(Exp.begin(), Exp.end(), x);

    if (vector_finder(Exp, x)){
        cout << *it << endl;
    } else {
        cout << *(--it) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define print(v) for(auto &z:v) cout<<z<<' ';cout<<'\n'
#define db cout<<"db: "
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define all(v) v.B,v.E
#define sz(v) (int)((v).size())
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define clk1 clock_t start_time=clock()
#define clk2 cout<<(clock()-start_time)/(double)CLOCKS_PER_SEC
#define clean(arr) memset(arr,0,sizeof(arr))
#define mod 1000000007
#define mod2 998244353
#define space 100005
//<<fixed << setprecision(9)


int expo(ll x,ll pow)
{
    if(pow==0) return 1;
    ll res=expo((x*x)%mod,pow/2);
    if(pow%2)res*=x;
    return res%mod;
}

int main()
{
    int n,i,j,t;
    boost;

    cin>>n;
    if(n==1)
        cout<<0;
    else
    {
        ll ans = expo(10,n) - 2*expo(9,n) + expo(8,n);
        ans%=mod;
        ans+=mod;
        cout<<ans%mod;
    }

    return 0;
}

Measured memory_bytes: 3644
#include <stdio.h>

int main(){

    int N;
    int h=0,m=0,s=0;

    scanf("%d",&N);

    while(N>=3600){
        h++;
        N -= 3600;
    }

    while(N>=60){
        m++;
        N -= 60;
    }

    while(N>0){
        s++;
        N -= 1;
    }

    printf("%d:%d:%d\n",h,m,s);
    
}


Measured memory_bytes: 2136
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

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

int ab, bc, ca;

int main()
{
    cin >> ab >> bc >> ca;
    cout << ab * bc / 2 << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS 
#include <stdio.h>

int main()
{
	int W, H, x, y, r;
	W = 0; H = 0; x = 0; y = 0; r = 0;

	if ((x < -100 || x > 100)
		|| (y < -100 || y > 100)
		|| (W <= 0 || W > 100)
		|| (H <= 0 || H > 100)
		|| (r <= 0 || r > 100)) {

		scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
		if (((y + r) > H) || (x + r) > W 
			|| (x<0 && W>0) || (y<0 && H>0)
			|| (x>0 && W<0) || (y>0 && H<0)) {
			printf("No\n");
		}
		else {
			printf("Yes\n");
		}
	}

	return 0;
}



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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n + 1);
    vector<int> box(n + 1, 0);
    vector<int> num(n + 1, 0);
    int m = 0;

    for (auto i = 1; i < n + 1; i++)
    {
        int a_i;
        cin >> a_i;
        a[i] = a_i;
    }

    for (auto i = n / 2 + 1; i < n + 1; i++)
    {
        box[i] = a[i];
        if (a[i] == 1)
        {
            m += 1;
            for (auto j = 1; j * j <= i; j++)
            {
                if (i % j == 0)
                {
                    num[j] += 1;
                    if (j * j != i)
                    {
                        num[i / j] += 1;
                    }
                }
            }
        }
    }

    for (auto i = n / 2; i >= 1; i--)
    {
        if (a[i] == 1)
        {
            if (num[i] % 2 == 1)
            {
                box[i] = 0;
            }
            else
            {
                box[i] = 1;
                for (auto j = 1; j * j <= i; j++)
                {
                    if (i % j == 0)
                    {
                        num[j] += 1;
                        if (j * j != i)
                        {
                            num[i / j] += 1;
                        }
                    }
                }
                m += 1;
            }
        }
        else
        {
            if (num[i] % 2 == 1)
            {
                box[i] = 1;
                for (auto j = 1; j * j <= i; j++)
                {
                    if (i % j == 0)
                    {
                        num[j] += 1;
                        if (j * j != i)
                        {
                            num[i / j] += 1;
                        }
                    }
                }
                m += 1;
            }
            else
            {
                box[i] = 0;
            }
        }
    }
    if (m == 0)
    {
        cout << 0 << endl;
        return 0;
    }

    cout << m << endl;

    for (auto i = 1; i < n + 1; i++)
    {
        if (box[i] == 1)
        {
            cout << i << " ";
        }
    }
    cout << endl;
}

Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
using ll = long long;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;

int main() {
    ll X;
    cin >> X;
    ll count = 0;
    count += (X / 500) * 1000;
    X %= 500;
    count += (X / 5) * 5;
    cout << count << endl;


}


Measured memory_bytes: 256
#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 (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
LL A[200001];
LL S[200001];
int main(){
	cin>>N;
	vector<LL>v;
	REP(i,N){
		cin>>A[i];
		A[i]-=(i+1);
		v.push_back(A[i]);
	}
	sort(v.begin(),v.end());
	REP(i,N){
		//cout<<v[i]<<endl;
		if(i==0){
			S[i]=v[i];
		}else{
			S[i]=S[i-1]+v[i];
		}
	}
	LL ans=10000000000000000;
	REP(i,N){
		//if(v[i]<0)continue;
		LL a=0;
		a+=((i+1)*v[i]);
		a-=((N-i-1)*v[i]);
		a-=S[i];
		a+=(S[N-1]-S[i]);
		//cout<<"a"<<a<<endl;;
		ans=min(ans,a);
	}
	cout<<ans<<endl;
	return(0);
}

Measured memory_bytes: 5104
#include <bits/stdc++.h>
using namespace std;
int main(void){
    vector<vector<int>>A(3,vector<int>(3));
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin >> A[i][j];
        }
    }
    int N;
    cin >> N;
    vector<int>B(N);
    for(int k=0;k<N;k++){
        cin >> B[k];
    }
    for(int a=0;a<N;a++){
        for(int b=0;b<3;b++){
            for(int c=0;c<3;c++){
                if(B[a]==A[b][c]){
                    A[b][c]=0;
                }
            }
        }
    }
    if(A[0][0]==0&&A[0][1]==0&&A[0][2]==0)cout << "Yes"<< endl;
    else if(A[1][0]==0&&A[1][1]==0&&A[1][2]==0)cout<< "Yes" <<endl;
    else if(A[2][0]==0&&A[2][1]==0&&A[2][2]==0)cout<< "Yes" <<endl;
    else if(A[0][0]==0&&A[1][1]==0&&A[2][2]==0)cout<< "Yes" <<endl;
    else if(A[0][2]==0&&A[1][1]==0&&A[2][0]==0)cout<< "Yes" <<endl;
    else if(A[0][0]==0&&A[1][0]==0&&A[2][0]==0)cout<< "Yes" <<endl;
    else if(A[0][1]==0&&A[1][1]==0&&A[2][1]==0)cout<< "Yes" <<endl;
    else if(A[0][2]==0&&A[1][2]==0&&A[2][2]==0)cout<< "Yes" <<endl;
    else cout << "No" <<endl;
    
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
   	
        String Date = sc.next();
        String[] A = Date.split("/");
    	
        int B0 = Integer.parseInt(A[0]);
        int B1 = Integer.parseInt(A[1]);
        
        if(B0 < 2019) {
     		System.out.println("Heisei");
        }
        
        if(B0 == 2019) {
        	if(B1 <= 4) {
        		System.out.println("Heisei");
        	}
        	else {
        		System.out.println("TBD");
        	}       	
        }
        if(B0 > 2019) {
    		System.out.println("TBD");
        }
  	}
}

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

struct edge{int to,cost;};
typedef pair<int,int> P;
int n,a[114514],b[114514],c[114514],q,k,x[114514],y[114514];
vector<edge> g[114514];
long long d[114514];

void dijkstra(){
	fill(d,d+n+1,INF);
	priority_queue<P,vector<P>,greater<P>> que;
	que.push({0,k});
	d[k]=0;
	while(que.size()){
		P p=que.top();
		que.pop();
		int v=p.second;
		if(d[v]<p.first) continue;
		for(edge e:g[v]){
			if(d[e.to]>d[v]+e.cost){
				d[e.to]=d[v]+e.cost;
				que.push({d[e.to],e.to});
			}
		}
	}
}

signed main(){
	cin>>n;
	rep(i,n-1){
		cin>>a[i]>>b[i]>>c[i];
		g[a[i]].push_back({b[i],c[i]});
		g[b[i]].push_back({a[i],c[i]});
	}
	cin>>q>>k;
	dijkstra();
	rep(i,q){
		cin>>x[i]>>y[i];
		cout<<d[x[i]]+d[y[i]]<<endl;
	}
		
}


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

using namespace std;
typedef pair<int, int> ii;


const int MOD = (int)1e9 + 7;



int main() {
    char str[10002];
    cin >> str;
    int d; cin >> d;
    int len = strlen(str);
    long long dp[len][d];

    int n = len;
    for(int i = 0; i < len; ++i) {
        for(int j = 0; j < d; ++j ) dp[i][j] = 0;
    }

    for(int i = 0; i < 10; ++i) dp[0][i%d] += 1;


    if(len == 1) {
        //
        long long ans = 0;
        for(int i = 1; i <= str[0] - '0'; ++i) {
            if(i%d == 0) ans += 1;
        }
        cout << ans ;
        return 0;
    }


    for(int i = 1; i < len; ++i) {
        int end = 10;
        if(i == len - 1) end = str[0] - '0';
        for(int j = 0; j < end; ++j) {
            for(int k = 0; k < d; ++k) {
                dp[i][(j+k)%d] +=  dp[i-1][k];
                dp[i][(j+k)%d] %= MOD;
            }

        }

    }


    int cc = str[0] - '0';
    for(int i = 1; i < len; ++i) {
        for(int j = 0; j < str[i] - '0'; ++j) {
            for(int k = 0; k < d; ++k) {
                if(i == len-1) {
                    dp[n-1][(cc + j)%d] += 1;
                    break;
                }
                dp[n-1][ (cc + (k + j) )%d ] += dp[len - 1 - (i+1)][k];

                dp[n-1][(cc + (k + j))%d] %= MOD;

            }  
        }
        cc += str[i] - '0';
        cc %= d;
    }
    if(cc%d == 0) {
        dp[n-1][0] += 1;
    }

    long long ans = dp[n-1][0];

    ans -= 1;

    cout <<(ans %MOD+ MOD)%MOD;
    

}

Measured memory_bytes: 8064
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <stdbool.h>

#define MAX_NUM 9
#define MAX_SIZE MAX_NUM * 4

typedef struct _Card {
	uint8_t suit;
	uint8_t number;
} Card;
#define MAX_CARDS_SIZE MAX_SIZE * sizeof(Card)

typedef struct _Checker {
	uint8_t suits[5];
	uint8_t count;
} Checker;

void DispCards(Card arr[], int32_t len) {
	printf("%c%c", arr[0].suit, arr[0].number);
	for (int32_t i = 1; i < len; i++) {
		printf(" %c%c", arr[i].suit, arr[i].number);
	}
	putchar('\n');
}

void DispStable(Card arr1[], Card arr2[], int32_t len, int32_t cardNumCnt[]) {
	for (int32_t i = 1; i <= MAX_NUM; i++) {
		if (cardNumCnt[i] < 2) continue;

		Checker chk1 = {0};
		Checker chk2 = {0};
		for (int32_t j = 0; j < len; j++) {
			if (arr1[j].number == i + 0x30) chk1.suits[chk1.count++] = arr1[j].suit;
			if (arr2[j].number == i + 0x30) chk2.suits[chk2.count++] = arr2[j].suit;
		}
		if (memcmp(chk1.suits, chk2.suits, 4)) {
			puts("Not stable");
			return;
		}
	}
	puts("Stable");
}

void Swap(Card *a, Card *b) {
	Card tmp = *a;
	*a = *b;
	*b = tmp;
}

void BubbleSort(Card arr[], int32_t len) {
	bool needLoop = true;
	for (int32_t i = 0; needLoop; i++) {
		needLoop = false;
		for (int32_t j = len-1; j > i; j--) {
			if (arr[j-1].number > arr[j].number) {
				Swap(&arr[j-1], &arr[j]);
				needLoop = true;
			}
		}
	}
}

void SelectionSort(Card arr[], int32_t len) {
	int32_t last = len - 1;
	for (int32_t i = 0; i < last; i++) {
		int32_t minPos = i;
		for (int32_t j = i+1; j < len; j++) {
			minPos = (arr[minPos].number > arr[j].number) ? j : minPos;
		}
		if (minPos != i) {
			Swap(&arr[i], &arr[minPos]);
		}
	}
}

int main() {
	int32_t dataNum;
	scanf("%d", &dataNum);
	getchar();

	Card cards[MAX_SIZE] = {0};
	int32_t cardNumCnt[MAX_NUM+1] = {0};
	for (int32_t i = 0; i < dataNum; i++) {
		uint8_t buf[3] = {0};
		scanf("%2s", buf);
		cards[i].suit = buf[0];
		cards[i].number = buf[1];
		cardNumCnt[buf[1] - 0x30]++;
	}

	Card tmp[MAX_SIZE];
	memcpy(tmp, &cards, MAX_CARDS_SIZE);

	BubbleSort(tmp, dataNum);
	DispCards(tmp, dataNum);
	DispStable(cards, tmp, dataNum, cardNumCnt);

	memcpy(tmp, &cards, MAX_CARDS_SIZE);

	SelectionSort(tmp, dataNum);
	DispCards(tmp, dataNum);
	DispStable(cards, tmp, dataNum, cardNumCnt);

	return 0;
}



Measured memory_bytes: 2044
#include<bits/stdc++.h>
using namespace std;
int main(){
	
	string s;cin>>s;

	int n = s.length();

	string target = "keyence";

	if(target==s){
		puts("YES");
		return 0;
	}

	for(int i=0;i<n;i++){

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

			string temp = "";

			for( int k=0;k<n;k++ ){

				if( i<=k && k<=j )continue;
				temp+=s[k];

			}

			if( temp==target ){
				puts("YES");
				return 0;
			}

		}

	}
	puts("NO");
	return 0;

	/*
	1. Check for output format
	2. CHeck for corner cases
	3. Compile and run given TC first
	*/

}

Measured memory_bytes: 3552