akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int(a.size()))
#define F first
#define S second
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};


typedef struct _state{
  int from,vis;
  double cost;
  _state(double ic,int ifr,int iv):cost(ic),from(ifr),vis(iv){
  };
  bool operator<(const _state&r)const{
    return cost>r.cost;
  };
}state;

vector<PI> V[30];


main(){
  ios::sync_with_stdio(false);
  int n,m,p,a,b;
  while(cin>>n>>m>>p>>a>>b,n){
    --a,--b;
    int ti[n];
    rep(i,n)cin>>ti[i];

    rep(i,m)V[i].clear();

    rep(i,p){
      int x,y,z;
      cin>>x>>y>>z;
      --x,--y;
      V[x].pb(mp(y,z));
      V[y].pb(mp(x,z));
    }

    priority_queue<state> Q;
    Q.push(state(0,a,0));

    bool fix[m][1<<n];
    double cost[m][1<<n];
    rep(i,m)fill(cost[i],cost[i]+(1<<n),1<<28);
    memset(fix,0,sizeof(fix));
    double ans=-1;

    while(!Q.empty()){
      int from=Q.top().from,cti=Q.top().vis;
      double ccost=Q.top().cost;
      Q.pop();
      if(fix[from][cti])continue;
      fix[from][cti]=true;
      if(from==b){
        ans=ccost;
        break;
      }

      rep(i,n){
        if(cti>>i&1)continue;
        rep(j,V[from].size()){
          int to=V[from][j].first;
          int cc=V[from][j].second;
          double ncost=ccost+1.0*cc/ti[i];          
          if(cost[to][cti|1<<i]<=ncost)continue;
          cost[to][cti|1<<i]=ncost;
          Q.push(state(ncost,to,cti|1<<i));
        }
      }
    }
    if(ans<0)cout<<"Impossible"<<endl;
    else cout<<ans<<endl;
  }
}

Measured memory_bytes: 7632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
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; }

int main(){
  ll x;
  cin >> x;
  ll mon = 100;
  ll year = 0;
  while (mon < x){
    mon += mon / 100;
    year++;
  }
  print(year);
}

Measured memory_bytes: 3624
def solve():
    
    A, B, C, D, E, F = map(int, input().split())
    memo = {}
    
    for a in range(31):
        for b in range(31):
            for c in range(101):
                for d in range(101):
                    w = (100*A)*a + (100*B)*b
                    s = C*c + D*d
                    if w ==0:
                        break
                    if w+s > F:
                        break
                    else:
                        if w/100 * E >= s:
                            dist = 100*s/(w+s)
                            memo[a,b,c,d] = dist
    
    max_v = max(memo.values())
    
    for k, v in memo.items():
        if v == max_v:
            print((100*A)*k[0] + (100*B)*k[1] + C*k[2] + D*k[3], C*k[2] + D*k[3] )
            break
 
if __name__ == '__main__':
	solve()

Measured memory_bytes: 39652
#include <stdio.h>
int main(){
  int money=100000,week,i;
  scanf("%d",&week);
  for(i=1;i<=week;i++){
    money+=money*5/100;
    if(money%1000!=0)money+=1000-money%1000;
  }
  printf("%d\n",money);
  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
int main() {
	lli t,n,m,a,b,c,ans;
	cin >> n >> a;
	lli arr[n];
	for(int i=0;i<n;i++){
		cin >> arr[i];
	}
	sort(arr,arr+n);
	ans=0;
	for(int i=0;i<a;i++){
		ans+=arr[i];
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S1 = sc.next();
		String S2 = sc.next();
		sc.close();
		if(S1.length() == S2.length()) {
			for(int i = 0; i < S1.length(); i++) {
				System.out.print(S1.charAt(i));
				System.out.print(S2.charAt(i));
			}
			System.out.println();
		}else {
			for(int i = 0; i < S1.length() - 1; i++) {
				System.out.print(S1.charAt(i));
				System.out.print(S2.charAt(i));
			}
			System.out.println(S1.charAt(S1.length() - 1));
		}
	}
}

Measured memory_bytes: 23508
def resolve():
    '''
    code here
    '''
    N, K = [int(item) for item in input().split()]
    R, S, P= [int(item) for item in input().split()]
    T = input()
    memo = [1 for _ in range(K)]
    def point_chk(s):
        if s == 'r':
            return P
        elif s == 's':
            return R
        elif s == 'p':
            return S
        else:
            raise

    
    max_point = 0
    for i, s in enumerate(T):
        if i < K:
            max_point += point_chk(s)
            memo[i%K] = s
        else:
            if s == memo[i%K]:
                memo[i%K] = 1
            else:
                memo[i%K] = s
                max_point += point_chk(s)
        # print(i, s, memo, max_point)
    
    print(max_point)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 3964
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int N;
bool FLG;

void recursive(int cards[14],int log[],int used_num,int sum){

	if(FLG)return;

	if(used_num == N){

		FLG = true;

		reverse(log,log+N);

		printf("%d",log[0]);
		for(int i = 1; i < N; i++){
			printf(" %d",log[i]);
		}
		printf("\n");

		return;
	}

	for(int i = 1; i <= 13; i++){
		if(cards[i] > 0 && (used_num == N-1 || (sum-i)%i == 0)){
			int next_cards[14],next_log[N];
			for(int k = 1; k <= 13; k++){
				next_cards[k] = cards[k];
			}
			next_cards[i]--;
			for(int k = 0; k < used_num; k++){
				next_log[k] = log[k];
			}
			next_log[used_num] = i;

			recursive(next_cards,next_log,used_num+1,sum-i);
		}
	}
}


void func(){

	FLG = false;

	int first[14];
	for(int i = 1; i <= 13; i++){
		first[i] = 0;
	}

	int tmp,sum = 0;
	for(int i = 0; i < N; i++){
		scanf("%d",&tmp);
		first[tmp]++;
		sum += tmp;
	}

	int log[N];

	recursive(first,log,0,sum);


	if(!FLG){
		printf("No\n");
	}
}

int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define vvi             vector<vi>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define mod             1000000007
#define inf             1e18
#define deb(x)          cout << #x << "=" << x << '\n';
#define ps(x,y)         fixed<<setprecision(y)<<x
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

void solve() {

    int n, W, with, without;
    cin >> n >> W;
    vi w(n), v(n);

    for(int i=0; i<n; i++) {
        cin >> w[i] >> v[i];
    }

    vvi dp(n, vi(W+1));
    for(int i=0; i<=W; i++)
        if(i>=w[n-1])
            dp[n-1][i] = v[n-1];
        else
            dp[n-1][i] = 0;

    for(int i=n-2; i>=0; i--) {
        for(int j=0; j<=W; j++) {
            without = dp[i+1][j];
            with = (j>=w[i]? (dp[i+1][j-w[i]]+v[i]): without);

            dp[i][j] = max(with, without);
        }
    }

    cout << dp[0][W] << '\n';
}

int32_t main() {
    FIO;
    int t = 1;
//    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 79488
import Data.List

dup [] = []
dup ([a,b]:x) = ([a,b]:[b,a]:(dup x))

mkt [] = []
mkt ([a,b]:x) =
  let l = map (\c -> c!!1) $ takeWhile (\ [a0,b0] -> a == a0 ) x
      r = dropWhile (\ [a0,b0] -> a == a0) x
  in
    (a,(b:l)):(mkt r)

get_val b = case b of
              Just b' -> b'
              Nothing -> []

ans' t l = concat $ map (\ a -> get_val $ lookup a t ) l

ans ([0]:[0]:_) = []
ans ([n]:[m]:x) =
  let s = sortBy (\[a0,a1] [b0,b1] -> compare a0 b0) $ dup $ take m x
      r = drop m x
      t = mkt s
      a1= ans' t [1]
      a2= ans' t a1
      a = (nub $ sort (a1++a2)) \\ [1]
      l = length a
  in
    l:(ans r)

main = do
  c <- getContents
  let i = map (map read) $ map words $ lines c :: [[Int]]
      o = ans i
  mapM_ print o




Measured memory_bytes: 12124
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
//#define int ll
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  int N, M;
  cin >> N >> M;
  
  vvi s(M, vi(N));
  vi k(M);
  
  rep(i, M) {
    cin >> k[i];
    rep(j, k[i]) {
      cin >> s[i][j];    
      s[i][j] --;
    }
  }
  vi p(M);
  rep(i, M) {
    cin >> p[i];
  }
  
  int ctt = 0;
  for(int bit=0; bit < 1<<N; bit++) {
    vi sw(N);
    for(int i=0; i<N; i++) {
      if(bit & (1<<i)) {
        sw[i] = 1;
      }
    }
    
    bool f = true;
    rep(i, M) {
      int ct = 0;
      rep(j, k[i]) {
        ct += sw[s[i][j]];
      }
      if(ct % 2 != p[i]) {
        f = false;
        break;
      }
    }
    
    if(f) ctt ++;
  }
  fin(ctt);
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	[ x, y ] <- readIntegers
	print $ length $ takeWhile ( <= y ) [ x * ( 2 ^ i ) | i <- [ 0 .. ] ]

Measured memory_bytes: 508
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <iostream>
#define REP(i, a, b) for (int i = a; i <= b; ++i)
#define PER(i, a, b) for (int i = a; i >= b; --i)
#define RVC(i, S) for (int i = 0; i < S.size(); ++i)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;

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

string str;
int w;
int main(){
	cin >> str >> w;
	for (int i = 0; i < str.size(); i += w)
		if (i < str.size()) putchar(str[i]);
	puts("");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    int n;
    cin>>n;
    string s;
    cin>>s;

    int lcnt = 0, rcnt = 0;
    rep(i, n) {
        if (s[i] == '(') lcnt++;
        else {
            if (!lcnt) rcnt++;
            if (lcnt) lcnt--;
        }
    }
    rep(i, rcnt) s = "(" + s;
    rep(i, lcnt) s += ")";
    cout<<s<<endl;
}

Measured memory_bytes: 256
import java.io.{InputStream, OutputStream, PrintStream}
import java.util.Scanner

object Main {

  def main(args: Array[String]): Unit = {
    val solver = new Solver(System.in, System.out)
    solver.solve()
  }

  class Solver(in: InputStream, out: OutputStream) {
    lazy val input = new Scanner(in)

    lazy val output = new PrintStream(out)

    def solve(): Unit = {
      val N = input.nextLine().toInt
      println(N match {
        case 22 => "Christmas Eve Eve Eve"
        case 23 => "Christmas Eve Eve"
        case 24 => "Christmas Eve"
        case _ => "Christmas"
      })
    }

  }

}


Measured memory_bytes: 25928
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			int N = stdIn.nextInt();
			if(N == 0)
			{
				break;
			}
			boolean[][] info = new boolean[101][101];
			for(int i = 0; i < 101; ++i)
			{
				for(int j = 0; j < 101; ++j)
				{
					info[i][j] = false;
				}
			}
			for(int i = 1; i <= N; ++i)
			{
				int M = stdIn.nextInt();
				for(int j = 0; j < M; ++j)
				{
					int p = stdIn.nextInt();
					info[i][p] = true;
				}
			}
			int K = stdIn.nextInt();
			List<Integer> list = new ArrayList<Integer>();
			for(int i = 0; i < K; ++i)
			{
				int a = stdIn.nextInt();
				list.add(a);
			}
			int alreadyFlag = 0;
			int ans = 0;
			for(int i = 1; i <= N; ++i)
			{
				boolean flag = true;
				for(int j = 0; j < K; ++j)
				{
					if(!info[i][list.get(j)])
					{
						flag = false;
						break;
					}
				}
				if(flag)
				{
					++alreadyFlag;
					ans = i;
					if(alreadyFlag >= 2)
					{
						System.out.println(-1);
						break;
					}
				}
			}
			if(alreadyFlag == 1)
			{
				System.out.println(ans);
			}
			else if(alreadyFlag == 0)
			{
				System.out.println(-1);
			}
		}
	}
}

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

using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define rep(i, N) for (ll i = 0; i < (N); i++)
#define For(i, a, b) for (ll i = (a); i < (b); i++)
#define all(A) (A).begin(), (A).end()

int main(){
    ll N, M;
    cin >> N >> M;
    vector<pll> AB(N);
    rep(i, N) {
        cin >> AB[i].first >> AB[i].second;
    }
    sort(all(AB));

    ll ans = 0;
    rep(i, N) {
        if (AB[i].second >= M) {
            ans += AB[i].first * M;
            cout << ans << endl;
            return 0;
        }
        else {
            ans += AB[i].first * AB[i].second;
            M -= AB[i].second;
        }
    }
    return 0;
}


Measured memory_bytes: 1792
s=raw_input().split();
n=int(s[0])
k=int(s[1])

lt=[]*n;
for i in range(0,n):
	a=int(raw_input())
	lt.append(a)
lt.sort()
mx=1000000000000000
i=0; j=k-1;
while j<n:
	l=lt[j]-lt[i]
	j+=1;
	i+=1;
	if l<mx:
		mx=l;
print(mx)

Measured memory_bytes: 10228
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define until(x) while(!(x))
#define unless(x) if(!(x))
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pc __builtin_popcount

int ar[100005];

int32_t main(){
	int n;
	cin>>n;
	int tot = 0;
	int cnt = 0;
	int mn = -1e18;
	for(int i=1;i<=n;i++){
		cin>>ar[i];
		tot += abs(ar[i]);
		if(ar[i]<0){
			cnt++;
		}
		if(abs(ar[i])<abs(mn)){
			mn = ar[i];
		}
	}
	if(cnt&1){
		cout<<tot-2*abs(mn);
	}
	else {
		cout<<tot;
	}
}


Measured memory_bytes: 1024
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    ll k;
    cin>>n>>c>>k;
    vector<ll> v(n);
    rep(i,n) {
        cin>>v[i];
    }
  priority_queue<ll, vector<ll>, greater<ll> > q;
    rep(i,n){
        q.push(v[i]);
    }
    ll bus=0;
    while(!q.empty()){
      //  cout<<q.top()<<endl;
        n=q.top();
        q.pop();
        sum=1;
        while(q.top()<=n+k&&sum<c&&!q.empty()){
            q.pop();
            sum++;
        }
        bus++;
    }
    cout<<bus<<endl;

    return 0;
}


Measured memory_bytes: 5036
program answer
  implicit none

  integer :: N, M, i
  integer, allocatable :: T(:), P(:), X(:)

  read(*,*) N
  allocate(T(N))
  read(*,*) T
  read(*,*) M
  allocate(P(M))
  allocate(X(M))
  do i = 1, M
     read(*,*) P(i), X(i)
  end do

  do i = 1, M
     write(*,*) sum(T)-T(P(i))+X(i)
  end do

  stop
 end program answer
  

Measured memory_bytes: 2776
// https://atcoder.jp/contests/abc150/tasks/abc150_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int K, X;
    cin >> K >> X;
    if (K * 500 >= X) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 384
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#define REP(i, N) for(int i=0; i<N; i++)
using namespace std;

//#include "atcoder.hpp"

long long gcd(long long a, long long b) {
    if (a>b) swap(a,b);
    
    auto r = b % a;
    
    return (r ? gcd(r, a) : a);
}

int main() {
    int H,W,N, sr,sc;
    string S,T;
    
    cin>>H>>W>>N>>sr>>sc>>S>>T;
    
    int cl = 0, cr = 0, cu = 0,cd = 0;
    int rl = 0, rr = 0, ru = 0,rd = 0;
    
    auto it_choku = S.begin(), it_rng = T.begin();
    
    while (it_choku != S.end()) {
        switch(*it_choku) {
            case 'L':
            cl++; break;
            case 'R':
            cr++; break;
            case 'U':
            cu++; break;
            case 'D':
            cd++; break;
        }
        if (sr - cu + rd < 1 || sr + cd - ru > H ||
            sc - cl + rr < 1 || sc + cr - rl > W)
        { cout << "NO" << endl; return 0;}
        switch(*it_rng) {
            case 'L':
            if(sc - rl > 1)rl++; break;
            case 'R':
            if(sc + rr < W)rr++; break;
            case 'U':
            if(sr - ru > 1)ru++; break;
            case 'D':
            if(sr + rd < H)rd++; break;
        }
        
        while (rl > 0 && cr > 0) {
            rl--; cr--;
        }
        while (rr > 0 && cl > 0) {
            rr--; cl--;
        }
        while (ru > 0 && cd > 0) {
            ru--; cd--;
        }
        while (rd > 0 && cu > 0) {
            rd--; cu--;
        }

        ++it_choku; ++it_rng;
    }
    
    
    cout << "YES" << endl;
    
    return 0;
}







Measured memory_bytes: 776
n, k = map(int, input().split())
li = []
for i in range(n):
    temp = list(map(int, input().split()))
    li.append(temp)
#print(li)
li.sort()
#print(li)
total=0
for i in range(n):
    if i==n-1:
        #print("here")
        print(li[i][0])
        break
    total+=li[i][1]
    if total<k:
        continue
    else:
        print(li[i][0])
        break
    #print(i, total)

Measured memory_bytes: 27564
#include <iostream>
#include <set>
#include <math.h>
#include <list>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MAX_N 1005
#define MAX_M 100

int N;
int B[MAX_N];
int A[MAX_N];

int main()
{
    map<char, char> mp;
    mp['A'] = 'T';
    mp['T'] = 'A';
    mp['C'] = 'G';
    mp['G'] = 'C';

    char x;
    cin >> x;
    cout << mp[x] << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt() - 1;
        }
        UnionFind u = new UnionFind(n);
        for (int i = 0; i < m; i++) {
            int x = sc.nextInt() - 1;
            int y = sc.nextInt() - 1;
            u.unite(x, y);
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (u.same(i, p[i])) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}
class UnionFind {
    static int[] par;
    public UnionFind(int n) {
        this.par = new int[n];
        for (int i = 0; i < n; i++) {
            par[i] = i;
        }
    }

    public int root(int x) {
        if (par[x] == x) {
            return x;
        }
        return par[x] = root(par[x]);
    }
    public void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) {
            return;
        }
        par[rx] = ry;
    }
    public boolean same(int x, int y) {
        return root(x) == root(y);
    }
    public String toString() {
        return String.format("par = %s %n", Arrays.toString(par));
    }
}


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

int main() {
	int n;
	cin >> n;
	int d[n];
	for(int i=0;i<n;i++){
		cin >> d[i];
	}
	
	sort(d,d+n);
	
	cout << d[n/2] - d[n/2-1] << endl;
	
	return 0;
}

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

using namespace std;
typedef long long ll;

int a[2000010], b[2000010];
ll c[10010];

int main(void) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    
    for (int i = 0; i < n; i++)
        c[a[i]]++;
    
    for (int i = 1; i <= 10000; i++)
        c[i] += c[i - 1];
    
    for (int i = n - 1; i >= 0; i--) {
        b[c[a[i]]] = a[i];
        c[a[i]]--;
    }

    for (int i = 1; i <= n; i++) {
        if (i != 1) cout << " ";
        cout << b[i];
    }
    cout << endl;

    return 0;
}


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

#include <iostream>
#include <string>

#include <algorithm>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define PB push_back
#define MP make_pair

#define FOR(i, b, e) for(int i=(b);i<(e);i++)
#define REP(i, n) FOR(i,0,n)

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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VPII;

const int MOD = 1000000007;
const int INF = 1e9;

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

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

LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }

int H, W;
string S[21];

int main() {
    cin >> H >> W;
    REP (i, H) {
        cin >> S[i];
    }
    deque<PII> deq;
    VVI d;
    int a = 0;
    REP (i, H) {
        REP (j, W) {
            if (S[i][j] == '#') {
                continue;
            }
            d = VVI(H, VI(W, -1));
            d[i][j] = 0;
            deq.PB(MP(i, j));
            while (!deq.empty()) {
                int y = deq.front().first;
                int x = deq.front().second;
                deq.pop_front();
                REP (k, 4) {
                    int y2 = y + dy[k];
                    int x2 = x + dx[k];
                    if (y2 < 0 || y2 >= H || x2 < 0 || x2 >= W) {
                        continue;
                    }
                    if (S[y2][x2] == '#') {
                        continue;
                    }
                    if (d[y2][x2] > -1) {
                        continue;
                    }
                    d[y2][x2] = d[y][x] + 1;
                    if (d[y2][x2] > a) {
                        a = d[y2][x2];
                    }
                    deq.PB(MP(y2, x2));
                }
            }
        }
    }
    cout << a << endl;
    return 0;
}


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

using namespace std;
int n;
int a[200005];
int dp[200005];
int main(){

    cin>>n;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
dp[0]=a[0];
dp[1]=abs(a[0]-a[1]);
dp[2]=min(abs(a[2]-a[0]),abs(a[2]-a[1])+dp[1]);
for(int i=3;i<n;i++)
dp[i]=min(abs(a[i]-a[i-2])+dp[i-2],abs(a[i]-a[i-1])+dp[i-1]);
cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 4368
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
//  cout.precision(15); cout << fixed;

int main() {
  int n, k; cin >> n >> k;
  vector<int> H(n);
  loop(i,0,n) cin >> H[i];
  int cnt = 0;
  for (auto&&h: H) {
    cnt += h >= k;
  }
  cout << cnt << endl;
  return 0;
}


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

long long mod = 1000000007;

class UnionFind
{
public:
   vector<int> parent;
   UnionFind(int N)
   {
      for (int i = 0; i < N; i++)
      {
         parent.push_back(-1);
      }
   }
   int root(int A)
   {
      if (parent[A] < 0)
         return A;
      return parent[A] = root(parent[A]);
   }
   int size(int A)
   {
      return -parent[root(A)];
   }

   bool unite(int A, int B)
   {
      A = root(A);
      B = root(B);
      if (A == B)
         return false;
      if (size(A) < size(B))
         swap(A, B);
      parent[A] += parent[B];
      parent[B] = A;
      return true;
   }
};

int main(void)
{
   string s;
   cin >> s;
   if (s[s.size() - 1] == 's')
   {
      s = s + "es";
   }
   else
   {
      s = s + "s";
   }
   cout << s << endl;
   return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <stack>
#include <cmath>
#include <string>
using namespace std;

#define ll long long
int main()
{
	int n, k;
	cin >> n >> k;

	string s;
	cin >> s;

	for (int i = 0; i < n; i++)
	{
		if (i == k - 1)
		{
			putchar(tolower(s[i]));
		}
		else
		{
			cout << s[i];
		}
	}
	cout << endl;
}





Measured memory_bytes: 256
#include <stdio.h>

/*

?´???°?????°

3????????´??° aa???bb???cc ??????????????????aa ?????? bb ?????§?????´??°????????????cc ????´???°?????????????????????????±???????????????°????????????????????????????????????

Input
aa???bb???cc ???1???????????????????????§1???????????????????????????

Output
?´???°?????°???1?????????????????????????????????

*/

int main( void )
{
	int aa, bb, cc, i, num;

	scanf( "%d %d %d", &aa, &bb, &cc  );
	
	num = 0;
	
	for ( i = aa ; i <= bb ; i++ ) {
		
		if ( ( cc % i ) == 0 ) {
			num++;
		}
	}
	printf( "%d\n", num );
	
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,ans=0;
  cin >> n;
	int a[2*n];
	for(int i=0;i<2*n;i++){
		cin >> a[i];
	}
	sort(a,a+2*n);
	for(int l=0;l<2*n;l++){
		if(l%2==0){
			ans+=a[l];
		}
	}
  cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
#define all(a) a.begin(), a.end()
#define show(ans)  cout << ans << endl;
const long MOD = 1000000007;


int main() {long n;
cin >> n;
vector<long> v(n);
rep(i, n) cin >> v[i];
vector<long> aodd(100001, 0); vector<long> aeven(100001, 0);
long oddmax = -1; long oddtmp; bool oddsame = false;
long evenmax = -1; long eventmp; bool evensame = false;
for(long i = 0; i <= n-2; i = i+2){
    aodd[v[i]]++;
    if(aodd[v[i]] > oddmax){
        oddmax = aodd[v[i]];
        oddtmp = v[i];
        oddsame = false;
    }
    else if(aodd[v[i]] == oddmax){
        oddsame = true;
    }
}
for(long i = 1; i <= n-1; i = i+2){
    aeven[v[i]]++;
    if(aeven[v[i]] > evenmax){
        evenmax = aeven[v[i]];
        eventmp = v[i];
        evensame = false;
    }
    else if(aeven[v[i]] == evenmax){
        evensame = true;
    }
}
sort(all(aodd));
sort(all(aeven));
reverse(all(aodd));
reverse(all(aeven));
long ans;
if(oddtmp == eventmp && oddsame == false && evensame == false){
    ans = n - (aodd[0] + max(aodd[1], aeven[1]));
}
else{
    ans = n - (aodd[0] + aeven[0]);
}


show(ans);
  return 0;
 
}



Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
    static void Main()
    {
        SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().Solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";


    void Solve()
    {
        int H = cin.Nextint, W = cin.Nextint, N = cin.Nextint;
        var G = new Dictionary<long, int>();
        long all = (long)(H - 2) * (W - 2);
        int[] dx = { -1, 0, 1, -1, 0, 1, -1, 0, 1 };
        int[] dy = { -1, -1, -1, 0, 0, 0, 1, 1, 1 };
        for (int i = 0; i < N; i++)
        {
            int tx = cin.Nextint;
            int ty = cin.Nextint;
            for (int j = 0; j < 9; j++)
            {
                int x = tx + dx[j];
                int y = ty + dy[j];
                if (x <= 1 || y <= 1 || x >= H || y >= W) continue;
                long k = (long)x * W + y;
                if (G.ContainsKey(k)) G[k]++;
                else G[k] = 1;
            }
        }
        var A = new long[10];
        foreach (var v in G.Values)
        {
            A[v]++;
        }
        A[0] = all - G.Count;
        foreach (var a in A)
        {
            WriteLine(a);
        }
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] Scan { get { return ReadLine().Split(); } }
    public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } }
    public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } }
    public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } }
    public string Next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return Next;
        }
    }
    public int Nextint { get { return int.Parse(Next); } }
    public long Nextlong { get { return long.Parse(Next); } }
    public double Nextdouble { get { return double.Parse(Next); } }
}

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

int main()
{
    string s;
    int n;
    cin >> s >> n;
    int first,second;
    string third;
    bool rev = false;
    pair<string, string> str = make_pair("","");
    
    for(int i = 0; i < n; ++i){
        cin >> first;
        if(first == 1) {
            rev = !rev;
        }
        else {
            cin >> second >> third;
            if(second == 1){
                if(rev) str.second += third; 
                else str.first += third;
            }
            else {
                if(rev) str.first += third; 
                else str.second += third;
            }
        }
    }
    reverse(str.first.begin(), str.first.end());
    s = str.first + s + str.second;
    if(rev) reverse(s.begin(), s.end());
    cout << s << endl;
}


Measured memory_bytes: 1348
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<climits>
#include<map>

using namespace std;

int main(){

	int N;

	cin >> N;

	int X = N;

	int dig;
	int sum =0;

	while(N){
	   dig = N%10;
	   sum = sum + dig;
	   N = N/10;
	}


	if(X%sum == 0){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}

    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n; cin >> n;
    string s; cin >> s;
    vector<vector<long long>> dp(n+1, vector<long long>(2, 1e18)); 
    // 0: ., 1: #
    dp[0][0] = (s[0] == '#');
    dp[0][1] = (s[0] == '.'); 
    for (int i = 0; i < n-1; i++) {
        dp[i+1][0] = min({dp[i+1][0], dp[i][0] + (s[i+1] == '#')});
        dp[i+1][1] = min({dp[i+1][1], dp[i][0] + (s[i+1] == '.'), dp[i][1] + (s[i+1] == '.')}); 
    }
    cout << min(dp[n-1][0], dp[n-1][1]) << endl;
    return 0;
}

Measured memory_bytes: 11396
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
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;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////

// UnionFind tree(n);
struct UnionFind {
    vector<int> parent;
    UnionFind (int n) : parent(n) {
        for (int i = 0; i < n; i++) parent[i] = i;
    }
    int root (int x) {
        if (parent[x] == x) return x;
        return parent[x] = root(parent[x]);
    }
    void unite (int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        parent[rx] = ry;
    }
    bool same_root (int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

    UnionFind tree(n);
    rep(i,m) {
        int x, y, z; cin >> x >> y >> z;
        x--; y--;
        tree.unite(x,y);
    }
    int ans = 0;
    rep(i,n) {
        if (tree.root(i) == i) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 896
import java.util.Scanner;

   class Main{
      public static void main(String args[]){
         Scanner sc =new Scanner(System.in);

         while(true){
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
             
            if(m==-1&&f==-1&&r==-1){
            break;
            }
             
            if(m==-1||f==-1){
               System.out.println("F");
            }else if(m+f>=80){
               System.out.println("A");
            }else if(m+f>=65){
               System.out.println("B");
            }else if(m+f>=50){
               System.out.println("C");
            }else if(m+f>=30){
               if(r>=50){
                  System.out.println("C");
                }else{
                   System.out.println("D");
                }
            }else {
                System.out.println("F");
            }
        }

      }
   }



Measured memory_bytes: 26380
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
// const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

int solve(int n, int k, vector<int> &a){
    int ret = 0;
    vector<int> count(n, 0);
    for (int i=0; i<n; ++i){
        count[a[i] - 1]++;
    }
    sort(ALL(count));
    for (int i=0; i<n-k; ++i){
        ret += count[i];
    }
    return ret;
}

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i=0; i<n; ++i){
        cin >> a[i];
    }
    cout << solve(n, k, a) << "\n";
    return 0;
}

Measured memory_bytes: 1920
using System;
using System.Globalization;
using System.IO.Pipes;
using System.Runtime.InteropServices;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int n, i;
            n = int.Parse(str[0]);
            i = int.Parse(str[1]);

            if (n<9 && i<9)
            {
                Console.WriteLine("Yay!");
            }
            else
            {
                Console.WriteLine(":(");
            }

        }

    }
}


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

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  int n;
  cin >> n;

  int ans = 0, mn = INT_MAX;
  for (int i = 0, x; i < n; ++i) {
    cin >> x;
    if (x <= mn)  ans++;
    mn = min(x, mn);
  }

  cout << ans;
}


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

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

using namespace std;

const int IINF = INT_MAX;
int dp[10100];

int main(){
  int M,N;
  cin >> M >> N;
  vector<int> manj(M);
  rep(i,M) cin >> manj[i];
  vector<int> cap(N), cost(N);
  rep(i,N) cin >> cap[i] >> cost[i];
  sort(manj.rbegin(),manj.rend());
  rep(i,M+1) dp[i] = IINF;
  dp[0] = 0;
  rep(i,N) {
    for(int j=M;j>=0;j--) if( dp[j] != IINF ) {
      int next = j + cap[i];
      if( dp[min(M,next)] > dp[j] + cost[i] ) {
	dp[min(M,next)] = dp[j] + cost[i];
      }
    }
    for(int j=M;j>=0;j--) if( j != M ) dp[j] = min(dp[j],dp[j+1]);
  }
  int maxi = 0, sum = 0;
  REP(i,1,M+1) {
    sum += manj[i-1];
    maxi = max(maxi,sum-dp[i]);
  }
  cout << maxi << endl;
  return 0;
}

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

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;


//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

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

#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)


struct Edge {
    int to, from;
    ll cost;
    Edge(int from, int to, ll cost): from(from), to(to), cost(cost) {}
};

typedef vector<vector<Edge>> AdjList;
AdjList graph;

typedef vector<ll> vec;
typedef vector<vec> mat;

mat mul(mat &A, mat &B) {
    mat C(A.size(), vec((int)B[0].size()));
    for(int i=0; i<A.size(); ++i){
        for(int k=0; k<B.size(); ++k){
            for(int j=0; j<B[0].size(); ++j){
                C[i][j] = (C[i][j] + A[i][k] * B[k][j] %MOD) % MOD;
            }
        }
    }
    return C;
}
mat mat_pow(mat A, ll n) {
    mat B(A.size(), vec((int)A.size()));

    for(int i=0; i<A.size(); ++i){
        B[i][i] = 1;
    }

    while(n > 0) {
        if(n & 1) B = mul(B, A);
        A = mul(A, A);
        n >>= 1;
    }
    return B;
}

int arr[110];
int main() {
    //cin.tie(0);
    //ios::sync_with_stdio(false);
    //cout << fixed << setprecision(10);
    
    ll N, M; cin >> N >> M;
    vector<pair<ll, ll>> vp;
    for(int i=0; i<N; ++i){
        ll A, B; cin >> A >> B;
        vp.push_back({A, B});
    }
    sort(all(vp));
    ll ans = 0;

    int cnt = 0;
    for(int i=0; i<N; ++i){
        if(cnt + vp[i].second >= M){
            ans += (M-cnt)*vp[i].first;
            break;
        }

        ans += vp[i].first * vp[i].second;
        cnt += vp[i].second;
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 2420
#include <stdio.h>
#include <iostream>
#include <string>
#include <math.h>
using namespace std;

int main()
{
    string S;
    char A;
    char B;
    cin >> S;
    int length = S.length();
    int count = 0;
    for(int i=0 ; i<length/2; i++){
        A = S[i];
        B = S[length - i - 1];
        if(A != B) count++;      
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int unt;
typedef double db;
typedef pair <int, int> pii;
typedef vector <int> vi;

#define Fi first
#define Se second
#define pb push_back
#define mp make_pair
#define rep(x, a, b) for(int x = (a); x <= (b); ++ x)
#define per(x, a, b) for(int x = (a); x >= (b); -- x)
#define rop(x, a, b) for(int x = (a); x < (b); ++ x)
#define por(x, a, b) for(int x = (a); x > (b); -- x)
#define forE(x, a) for(int x = head[a]; x; x = nxt[x])

#ifdef DEBUG
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define debug(x)
#endif

const db eps = 1e-8;
const int inf = 0x3f3f3f3f;
const int Minf = 0x7f7f7f7f;
const LL INF = 0x3f3f3f3f3f3f3f3fll;
const LL MINF = 0x7f7f7f7f7f7f7f7fll;

const int N = 255;

int a[N], b[N], c[N];
pii p[N << 2]; 
int f[N * 4][N];

int main() {
	int n, mod, ans = 0, tot = 0; scanf("%d%d", &n, &mod);
	rep(i, 0, n - 1) a[i + 1] = ceil(sqrt(n * n - i * i)) - 1;
	rep(i, 0, n - 1) c[i + 1] = floor(sqrt(4 * n * n - i * i));
	rep(i, n, (n << 1) - 1) b[i - n + 1] = floor(sqrt(4 * n * n - i * i));
	rep(i, 0, n - 1) p[++ tot].Fi = min(a[i + 1], (n << 1) - 1), p[tot].Se = 1;
	rep(i, 0, n - 1) p[++ tot].Fi = min(b[i + 1], (n << 1) - 1), p[tot].Se = 2;
	rep(i, 0, n - 1) p[++ tot].Fi = min(c[i + 1], (n << 1) - 1), p[tot].Se = 3;
	sort(p + 1, p + 1 + tot);
	rep(c, 0, n) {
		int nowc = 2 * n + 1;
		int rk = 0;
		memset(f, 0, sizeof f);
		f[0][0] = 1;
		rep(i, 1, n << 1) {
			if(p[i].Se == 2) {
				++ rk;
				rep(j, 0, min(i - 1, c)) {
					int nowrk = j + rk;
					f[i][j] = 1ll * f[i - 1][j] * max((p[i].Fi - nowrk + 2), 0) % mod;
				}
			}
			else {
				rep(j, 0, min(i, c)) {
					int nowrk = j + rk;
					int nowcrk = n + c + nowc - (n << 1) - j;
					if(j >= 0) f[i][j] = 1ll * f[i - 1][j] * max((p[nowc].Fi - nowcrk + 2), 0) % mod;
					if(j > 0) f[i][j] += 1ll * f[i - 1][j - 1] * max((p[i].Fi - nowrk + 2), 0) % mod;
					if(f[i][j] >= mod) f[i][j] -= mod;
				}
				++ nowc;
			}
		}
		ans += (c & 1) ? -f[n << 1][c] : f[n << 1][c];
		if(ans >= mod) ans -= mod;
		if(ans < 0) ans += mod;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 1408
# coding: utf-8
# Your code here!

def judge(number):
    def digit(check_num , number):
        if int(check_num) > number:
            return 0
        
        if all(check_num.count(digit_num) > 0 for digit_num in "753"):
            # print("dp:",check_num)
            count = 1
        else:
            # print("no_dp:",check_num)
            count = 0
        
        for add_num in "753":
            count = count + digit(check_num + add_num , number)
            # print("conut:{},add_num:{}".format(count,add_num))
        return count
        
    print(digit("0",number))

def main():
    number = int(input())
    judge(number)
    
if __name__ == "__main__":
    main()
    


Measured memory_bytes: 2940
S=input()
N=len(S)
x=[-1]*(N+1)
M=[-1]*(N+1)
from collections import deque
l=deque()
m=2
for i in range(N-1):
    if S[i:i+2]=='><':
        l.append((i+1,0,m))
        m+=1
if S[0]=='<':
    l.append((0,0,0))
if S[-1]=='>':
    l.append((N,0,1))
while l:
    n,v,m=l.popleft()
    if x[n]<0:
        x[n]=v
        M[n]=m
        if n>0 and S[n-1]=='>':
            l.append((n-1,v+1,m))
        if n<N and S[n]=='<':
            l.append((n+1,v+1,m))
    elif M[n]!=m:
        x[n]=v
        M[n]=m
print(sum(x))

Measured memory_bytes: 43372