akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

class Main{
	public static void main(String[] args)throws NumberFormatException, IOException{
	    InputStreamReader input = new InputStreamReader (System. in);
	    BufferedReader buffer = new BufferedReader(input);
	    String read = buffer.readLine();
	    int amount = Integer.parseInt(read);
	    Deque<Integer> stack = new ArrayDeque<Integer>();
	    stack.add(0);
	    int[][] scanInt = new int[amount][100];
	    for(int i=0; i<amount; i++){
	    	read = buffer.readLine();
	    	String[] scan = read.split(" ");
	    	for(int j=0; j<scan.length; j++){
	    		scanInt[i][j] = Integer.parseInt(scan[j]);
	    	}
	    }
	    int[] foundTime = new int[amount];
	    int[] compTime = new int[amount];
	    int time = 1;
	    
	    while(true){
	    	int process = stack.peek();
	    	boolean branchIsRemain = false;
	    	if(foundTime[process] == 0){
	    		foundTime[process] = time;
	    	}
	    	compTime[process]= time+1;
	    	
	    	for(int i=2; i<2+scanInt[process][1]; i++){
	    		
	    		if(foundTime[-1 + scanInt[process][i]] == 0){
	    			stack.addFirst(-1 + scanInt[process][i]);
	    			branchIsRemain = true;
	    			break;
	    		}
	    	}
	    	if(branchIsRemain == false){
	    		stack.pop();
	    	}
	    	if(stack.isEmpty()){
	    		boolean numLeft = false;
	    		for(int i=0; i<amount; i++){
	    			if(foundTime[i] == 0){
	    				time++;
	    				stack.addFirst(i);
	    				numLeft = true;
	    				break;
	    			}
	    		}
	    		if(numLeft == false){
	    			break;
	    		}
	    	}
	    	
	    	time++;
	    }
	    for (int i=0; i<amount; i++){
	    	System.out.println((i+1)+" "+foundTime[i]+" "+compTime[i]);
	    }

	}
}

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

using namespace std;
using ll = long long;
constexpr int mod =1000000007;
constexpr ll md = mod;
constexpr ll inf = 1e15;
int dp[100050][2];
int main(){
    string L;
    cin>>L;
    int N = (int)L.size();
    dp[0][0] = 1;
    for(int i=0;i<N;++i){
        if(L[i] == '1'){
            (dp[i+1][0] += dp[i][0] * 2%mod)%= mod;
            dp[i+1][1] = dp[i][1];
            (dp[i+1][1] += dp[i][1] * 2%mod)%= mod;
            (dp[i+1][1] += dp[i][0]) %=mod;
        }else{
            dp[i+1][0] = dp[i][0];
            dp[i+1][1] = dp[i][1];
            (dp[i+1][1] += dp[i][1] * 2%mod) %= mod;
            
        }
    }
    cout << (dp[N][0] + dp[N][1])%mod << endl;
    return 0;
}



Measured memory_bytes: 1280
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <limits>
#include <iterator>
#include <cmath>
#include <numeric>
#include <stack>
using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> v(n),c(n);
	for (int i = 0; i < n; i++) { cin >> v[i]; }
	for (int i = 0; i < n; i++) { cin >> c[i]; }

	int ans = 0;
	for (int i = 0; i <n; i++)
	{
		ans += v[i] - c[i] > 0 ? v[i] - c[i] : 0;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 888
#include <iostream>
using namespace std;
#define CIN(n) int n; cin>>(n);
int main() {
	int t;
	cin >> t;
	long long int n[105];
	for (int i = 1; i < t + 1; i++) {
		cin >> n[i];
	}
	long long int q = n[1];
	long long int w = n[1];
	for (int i = 1; i < t + 1; i++) {
		if (q < n[i])q = n[i];
	}
	for (int i = 1; i < t + 1; i++) {
		if (w > n[i])w = n[i];
	}
	long long int r;
	r = q - w;
	cout << r;
}

Measured memory_bytes: 256
import sys

city = [0] * 4
for i in range(3):
    a, b = list(map(int, input().split()))
    city[a - 1] += 1
    city[b - 1] += 1
odd_count = 0
for count in city:
    if count % 2 == 1:
        odd_count += 1
        if odd_count > 2:
            print("NO")
            sys.exit()
print("YES")

Measured memory_bytes: 3060
c = []
for i in range(3):
    c.append(list(map(int, input().split())))

for i in range(2):
    for j in range(2):
        if c[j][i+1] - c[j][i] != c[j+1][i+1] - c[j+1][i]:
            print('No')
            exit()
print('Yes')

Measured memory_bytes: 9060
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
#define MAX 300005
using namespace std;
 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF64 = 1e18;
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
void doc()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}
int main()
{
	string s,temp="";
	cin>>s;
	ll n=s.length();
	ll t=n/2;
	while(t--)
		temp+="hi";
	cout<<(temp==s ? "Yes" : "No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const ll INF = 1LL << 58;
const ll MOD = 1000000007;
typedef vector<pii> vpii;
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;
}

signed main()
{
    int H, W;
    cin >> H >> W;
    bool A[1000][1000];
    REP(i, H)
    {
        REP(j, W)
        {
            A[i][j] = false;
        }
    }
    char tmp;
    queue<pii> q;
    REP(i, H)
    {
        REP(j, W)
        {
            cin >> tmp;
            if (tmp == '#')
            {
                A[i][j] = true;
                q.push(make_pair(i, j));
            }
        }
    }
    int ans = 0;
    pii tmpp;
    int th, tw;
    int num;
    while (true)
    {
        num = q.size();
        REP(i, num)
        {
            tmpp = q.front();
            q.pop();
            th = tmpp.first;
            tw = tmpp.second;
            if (th - 1 >= 0 and A[th - 1][tw] == false)
            {
                A[th - 1][tw] = true;
                q.push(make_pair(th - 1, tw));
            }
            if (tw - 1 >= 0 and A[th][tw - 1] == false)
            {
                A[th][tw - 1] = true;
                q.push(make_pair(th, tw - 1));
            }
            if (th + 1 < H and A[th + 1][tw] == false)
            {
                A[th + 1][tw] = true;
                q.push(make_pair(th + 1, tw));
            }
            if (tw + 1 < W and A[th][tw + 1] == false)
            {
                A[th][tw + 1] = true;
                q.push(make_pair(th, tw + 1));
            }
        }
        if (q.empty())
            break;
        ans++;
    }

    cout << ans << endl;
    // system("pause");
}


Measured memory_bytes: 17588
#include<iostream>
#include<algorithm>
#include<cassert>
#include<stdint.h>
#include<vector>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define all(n) (n).begin(),(n).end()
#define inf (1<<29)
using namespace std;

const uint64_t INF = 100000000000010;

struct List
{
  int identifier;
  uint64_t range[2];// [range[0],range[1]]
  bool hasNext,hasPrev;
  List *prev;
  List *next;
  List(int identifier=inf,uint64_t r1=INF,uint64_t r2=INF):identifier(identifier)
  {
    range[0] = r1, range[1] = r2;
    hasNext = hasPrev = false;
  }
};

int N,I,S,P;
char c;
List list;

void list_walk(List *l)
{
  cout << '[' << l->range[0] << "," << l->range[1] << " : " << l->identifier << "]";
  if(l->hasNext)list_walk(l->next);
}


void ddfs(List *l)
{
  if(l->hasNext)ddfs(l->next);
  if(l->hasPrev)delete l;
    
}

void init()
{
  if(list.hasNext)ddfs(&list);
  list.hasNext = true;
  list.hasPrev = false;
  list.range[0] = list.range[1] = -1;
  list.identifier = -1;
  list.next = new List;
  list.next->hasNext = false;
  list.next->hasPrev = true;
  list.next->range[0] = list.next->range[1] = INF;
  list.next->identifier = inf;
  list.next->prev = &list;
  //cout << "test : " << list.next->prev->identifier << endl;
  //cout << "test : " << list.next->identifier << endl;
}

void dfsW(List *l)
{
  if(!l->hasNext)
    {
      cout << "S = " << S << endl;
      list_walk(&list);
      assert(false);
      return;
    }

  uint64_t v1 = l->range[1];
  uint64_t v2 = l->next->range[0];
  //cout << "v1 = " << v1 << " v2 = " << v2 << endl;
  uint64_t diff = v2-v1-1;
  //cout << "diff = " << diff << endl;
  //assert(diff >= 0);
  if(diff)
    {
      List *node = new List;
      node->identifier = I;
      node->hasNext = node->hasPrev = true;
      node->next = l->next;
      node->prev = l;
      l->next->prev = node;
      l->next = node;

      node->range[0] = v1+1;
      if(S <= diff)
	{
	  node->range[1] = node->range[0] + S - 1;
	  S = 0;
	}
      else if(S > diff)
	{
	  node->range[1] = node->range[0] + diff - 1;
	  S -= diff;
	}
    
    }  

  if(S > 0)dfsW(l->next);
}

void compute_W()
{
  dfsW(&list);
}

void dfsD(List *l)
{
  if(l->identifier == I)
    {
      l->next->prev = l->prev;
      l->prev->next = l->next;
      delete l;
    }
  if(l->hasNext)dfsD(l->next);
}

void compute_D()
{
  dfsD(&list);
}

void dfsR(List *l)
{
  if(l->range[0] <= P && P <= l->range[1])
    {
      cout << l->identifier << endl;
    }
  else
    {
      if(l->hasNext)dfsR(l->next);
      else cout << -1 << endl;
    }
}

void compute_R()
{
  dfsR(&list);
}


int main()
{
  while(cin >> N,N)
    {

      init();
      rep(_,N)
	{
	  cin >> c;
	  if(c == 'W')cin >> I >> S,compute_W();
	  if(c == 'D')cin >> I,compute_D();
	  if(c == 'R')cin >> P,compute_R();
	  //list_walk(&list);cout << endl;
	}
      //list_walk(&list);cout << endl;
      cout << endl;
    }
  return 0;
}

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

using namespace std;

typedef long long Long;

const Long INF = ((Long)1<<31) - 1;
    
class SegTree {
public:
    int m_n;
    vector<Long> m_data;

    SegTree( int n ) { Init( n ); }

    void Init( int n ) {

	m_n = 1;
	while ( m_n < n ) m_n <<= 1;

	m_data.resize( 2*m_n - 1, INF );
    }

    void Update( int k, Long val ) {

	k += m_n - 1;

	m_data[k] = val;
	
	while ( k > 0 ) {
	    k = ( k - 1 )/2;
	    m_data[k] = min( m_data[2*k+1], m_data[2*k+2] );
	}
    }

    Long RMQ( int a, int b ) {
	return query( a, b + 1, 0, 0, m_n );
    }

    void Print() const {
	for ( int i=0; i<m_data.size(); ++i ) {
	    cout << i << ": " << m_data[i] << endl;
	}
    }
protected:

    Long query( int a, int b, int k, int l, int r ) {

	if ( b <= l || a >= r ) return INF;

	if ( a <= l && r <= b ) return m_data[k];

	Long left = query( a, b, 2*k+1, l, (l+r)/2 );
	Long right = query( a, b, 2*k+2, (l+r)/2, r );

	return min( left, right );
    }

};


int main() {

    int n, l;

    cin >> n >> l;

    SegTree seg( n );

    int a;
    for ( int i=0; i<n; ++i ) {
	cin >> a;
	seg.Update( i, (Long)a );
    }

    --l;
    for ( int i=0; i+l<n; ++i ) {
	cout << seg.RMQ( i, i+l );
	if ( i+l == n-1 ) cout << endl;
	else cout << " ";
    }
    
    return 0;
}



Measured memory_bytes: 19212
#include <iostream>

#define MAX_N 100

int N;
int A[MAX_N];

void insertion_sort() {
    int j;
    int v;
    for (int i=1; i<N; i++) {
        v = A[i];
        j = i-1;
        while (j>=0 && A[j] > v) {
            A[j+1] = A[j];
            j--;
            A[j+1] = v;
        }
        for (int k=0; k<N-1; k++) {
            std::cout << A[k] << ' ';
        }
        std::cout << A[N-1] << std::endl;
    }
}

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

    for (int i=0; i<N-1; i++) std::cout << A[i] << ' ';
    std::cout << A[N-1] << std::endl;
    insertion_sort();

    return 0;
}



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)
#define vi vector<int>
#define vl vector<ll>
#define P pair<int,int>
#define all(vec) (vec.begin()),(vec.end())

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define bit(n) (1<<(n))

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;++i)
#define FORVEC(i, v) for(int i = 0;i < sz(v);++i)

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

#define fil0(i,n) cout<<swet(n)<<setfill('0')<<i<<resetiosflags(ios_base::floatfield)
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define possible(n) cout<<((n)?"possible":"impossible")<<endl
#define Possible(n) cout<<((n)?"Possible":"Impossible")<<endl


int main(){
    string s;
    cin>>s;
    bool flag=true;
    int cnt=0;
    if(s[0]!='A')flag=false;
    FORVEC(i,s){
        if(!i)continue;
        if(i>1 && i<s.size()-1 && s[i]=='C')cnt++;
        else if(s[i]<'a')flag=false;
    }
    if(cnt!=1)flag=false;
    cout<<(flag?"AC":"WA")<<endl;
    return 0;
}


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

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N;
    FORR(i, 1, N) {
        itn a;
        cin >> a;
        A.pb(make_pair(a, i));
    }
    sort(all(A));
    FOR(i, 0, N) {
        cout << A[i].y << " ";
    }
    cout << endl;
    solve();
    return 0;
}


Measured memory_bytes: 2544
from collections import defaultdict

S = input()
T = input()

A = {}
B = {}

isok = True
for i in range(len(S)):
    if S[i] in A:
        if T[i] != A[S[i]]:
            isok = False
            break
    else:
        A[S[i]] = T[i]
    if T[i] in B:
        if S[i] != B[T[i]]:
            isok = False
            break
    else:
        B[T[i]] = S[i]
        
if isok:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3888
#include<stdio.h>
int main(void)
{
  int N,K,i,denko=1;

  scanf("%d",&N);
  scanf("%d",&K);

  for(i=0;i<N;i++){
    if(denko*2-denko<=K){
      denko*=2;
    } else {
      denko+=K;
    }
  }

  printf("%d\n",denko);

  return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class C
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	public void Solve()
	{
		WriteLine($"{Pow(GetDouble() / 3.0, 3.0):F9}");
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

Measured memory_bytes: 11220
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		
		Main ans = new Main();
		System.out.println(ans.solve());		
	}

	private double solve() {
		Scanner sc = new Scanner(System.in);
		int one=0,two=0, three=0;
		int N = sc.nextInt();
		for(int i=0;i<N;i++){
			int val = sc.nextInt();
			if (val==1) one++;
			else if (val==2) two++;
			else if (val==3) three++;
		}

		double [][][] dp = new double[301][301][301];
		return solve(dp, one, two, three, N);
	}

	private double solve(double[][][] dp, int one, int two, int three, int N) {

		if (one<0 || two<0 || three<0) return 0;
		if (one==0 && two==0 && three==0) return 0;


		if (dp[one][two][three] !=0)  return dp[one][two][three];

		double exp = N + ((one) * solve(dp, one-1, two, three, N)) + (two * solve(dp, one+1, two-1, three, N)) + (three * solve(dp, one, two+1, three-1, N));
		dp[one][two][three] = exp/(one+two+three);

		return dp[one][two][three];
	}


}

Measured memory_bytes: 273784
## coding: UTF-8
N = int(input())
A = [int(x) for x in input().split()]

#print(N)
#print(A)
A.sort(reverse=True) #大きい順に並べる
#print(A)

Alice = []
Bob = []

counter = 0

while True:
    if(len(A) == 0):
        break #リストの要素が全部取得されたらループを消す

    if(counter % 2 == 0): #first,third,...
        #x = A.pop(0)
        Alice.append(A.pop(0))
        counter += 1
    else:
        Bob.append(A.pop(0))
        counter += 1
    
#print(Alice)
#print(sum(Alice))
#print(Bob)
#print(sum(Bob))
print(sum(Alice) - sum(Bob))

Measured memory_bytes: 3064
#include<stdio.h>
#include<iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define pb          push_back
#define pii         pair<long,long>
#define vi          vector<long>
#define vii         vector<pii>
#define mi          map<long,long>
#define mii         map<pii,long>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define fIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

ll sub(ll a, ll b){return (a-b+hell)%hell;}
ll add(ll a, ll b){return (a+b)%hell;}
ll mul(ll a, ll b){return (a*b)%hell;}


int findRank(string str) 
{ 
    // store original string 
    string orgStr = str; 
  
    // Sort the string in lexicographically 
    // ascending order 
    sort(str.begin(), str.end()); 
   
    // Keep iterating until 
    // we reach equality condition 
    long int i = 1; 
    do { 
        // check for nth iteration 
        if (str == orgStr) 
            break; 
   
        i++; 
    } while (next_permutation(str.begin(), str.end())); 
   
    // return iterator value 
    return i; 
} 
   
int main()
{
fIO;


/*#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif*/


long long n,sum=0,t=1,m=0;
//cin >> t;
while(t--){
cin>>n;
string s="",s1="";
char x;
rep(i,0,n)cin>>x,s+=x;
rep(i,0,n)cin>>x,s1+=x;
//sort(all(s));
//cout<<s<<endl;
cout<<abs((int)findRank(s)-(int)findRank(s1));



}
	
}

Measured memory_bytes: 256
#include <iostream>
#define llint long long
#define mod 1000000007

using namespace std;

llint H, W;
llint A, B;
llint fact[200005], fact_i[200005];

llint pow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (pow(a, n-1)%mod)) % mod;
	}
	else{
		return pow((a*a)%mod, n/2) % mod;
	}
}

void make_fact()
{
	llint val = 1;
	fact[0] = 1;
	for(int i = 1; i < 200005; i++){
		val *= i;
		val %= mod;
		fact[i] = val;
	}
	for(int i = 0; i < 200005; i++){
		fact_i[i] = pow(fact[i], mod-2);
	}
}

llint comb(llint n, llint k)
{
	llint ret = 1;
	ret *= fact[n];
	ret *= fact_i[k], ret %= mod;
	ret *= fact_i[n-k], ret %= mod;
	return ret;
}

int main(void)
{
	cin >> H >> W >> A >> B;
	make_fact();
	
	llint ans = 0;
	for(int i = B; i < W; i++){
		ans += (comb(H-A-1+i, i) * comb(A+W-i-2, A-1)) % mod;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3328
import decimal    

data = input().split()
X = decimal.Decimal(data[0])
K = decimal.Decimal(data[1])
D = decimal.Decimal(data[2])
if X < 0:
    X *= -1
if X/D-X//D > 0.5:
    y = X//D + 1
else:
    y = X//D
if y > K:
    y = K
X -= y * D

if (K-y)%2 == 0:
    print(abs(X))
else:
    if X > 0:
        print(D-X)
    else:
        print(X+D)

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




int main()
{
    int n;
    cin>>n;
    int k;
    cin>>k;
    vector<int> arr;
    for(int x=0;x<n;x++)
    {
        int t;
        cin>>t;
        arr.push_back(t);
    }


    vector<int> dp(n);
    dp[0]=0;
    dp[1]=abs(arr[1]-arr[0]);
    if(n==2)
    {
        cout<<dp[1];
        exit(0);
    }
    for(int x=2;x<n;x++)
    {
        // dp[x]=min(dp[x-1]+abs(arr[x-1]-arr[x]),dp[x-2]+abs(arr[x-2]-arr[x]));
        dp[x]=INT_MAX;
        for(int y=x-1;y>=max(0,x-k);y--)
        {
            dp[x]=min(dp[x],dp[y]+abs(arr[x]-arr[y]));
        }


    }
    // cout<<endl;
    // for(int x=0;x<n;x++)
    // {
    //     cout<<dp[x]<<" ";
    // }


    // cout<<endl;
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1144
#include <iostream>
#include <cstring>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

#define YES puts("YES")
#define NO  puts("NO")
#define Yes puts("Yes")
#define No  puts("No")

using namespace std;

typedef long long ll;

ll ans;
char S[105];
ll K;

ll solve() {
	int n = strlen(S);

	int c = 0;
	REP(i, 1, n) {
		if (S[i-1] == S[i]) c++;
	}
	if (c == n-1) return (n*K) / 2;

	REP(i, 0, n) {
		int cnt = 1;
		while (S[i] == S[i+1] && i < n) {
			cnt++;
			i++;
		}
		ans += cnt / 2;
	}
	ans *= K;

	if (S[0] == S[n-1]) {
		int x = 1, y = 1;
		int xi = 0, yi = n-1;
		while (S[xi] == S[xi+1]) {x++; xi++;}
		while (S[yi] == S[yi-1]) {y++; yi--;}

		ans -= (K-1) * ((x/2) + (y/2));
		ans += (K-1) * ((x+y)/2);
	}
    
    
    return ans;
}

int main(void) {
    scanf("%s", S);
    scanf("%lld", &K);

    

    
    printf("%lld\n", solve());

	return 0;
}


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

using namespace std;

int main()
{
	int n, m, i, j, grade[100];
	string s[100], t[100];
	cin >> n;
	for(i = 0; i < 100; i++)
	{
		grade[i] = 0;
	}
	for(i = 0; i < n; i++)
	{
		cin>>s[i];
		grade[i]++;
		for(j = 0; j < i; j++)
		{
			if(s[j]==s[i])
			{
				grade[j]++;
				grade[i]++;
			}
		}
	}
	cin >> m;
	for(i = 0; i < m; i++)
	{
		cin>>t[i];
		for(j = 0; j < n; j++)
		{
			if(s[j]==t[i])
			{
				grade[j]--;
			}
		}
	}
	if(*max_element(grade, grade+n) <= 0)
	{
		cout << "0" << endl;
	}
	else
	{
		cout << (*max_element(grade, grade+n)) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
S = input()
a = 'dream'
b = 'dreamer'
c = 'erase'
d = 'eraser'

S = S.replace(d, '')  # dの並びはa,b,cのみでは再現不可（文字列にdの並びがあった際に再現できるのはdのみ）
S = S.replace(c, '')  # dの並びが存在しない文字列について、cの並びは、a,bのみでは再現不可
S = S.replace(b, '')  # c,dの並びが存在しない文字列について、bの並びは、aでは再現不可
S = S.replace(a, '')  # b,c,dの存在しない文字列がaのみで実現できる場合、replace結果は''となる
print('YES') if S == '' else print('NO')


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

int main(int argc, char const *argv[])
{
	
	int a, b;
	cin >> a >> b;

	if(b % a == 0){
		cout << a + b << endl;
	}
	else cout << b - a <<endl;
	return 0;
}

Measured memory_bytes: 256
import Control.Applicative ((<$>), (<*>), (<*), (*>), (<$))
import Control.Monad
import Data.List

main :: IO ()
main = do
  solve <$> getLine >>= putStrLn

solve :: String -> String
solve s
  | head s `elem` "aeiou" = "vowel"
  | otherwise = "consonant"


Measured memory_bytes: 380
//AOJ0033
#include<iostream>
using namespace std;
int table[10];

bool ok(int i,int left,int right){
	if(i>=10){
		return true;
	}
	if(left<table[i]){
		if(ok(i+1,table[i],right))return true;
	}
	
	if(right<table[i]){
		if(ok(i+1,left,table[i]))return true;
	}
	return false;
}
int main(){
	int n;
	cin>>n;
	for(int set=0;set<n;set++){
		for(int i=0;i<10;i++)cin>>table[i];
		if(ok(0,0,0))cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	
	}
	return 0;
}

Measured memory_bytes: 3032
using System;
using System.Collections;
using System.Collections.Generic;

class Program {
    static void Main (string[] args) {
        var tempstr = Console.ReadLine ().Split (' ');
        int A = int.Parse (tempstr[0]);
        int B = int.Parse (tempstr[1]);
        int C = int.Parse (tempstr[2]);
        int K = int.Parse (Console.ReadLine ());
        int stepleft = K;
        bool ans = false;
        while (stepleft > 0) {
            stepleft--;
            if (A >= B) {
                B *= 2;
            } else if (B >= C) {
                C *= 2;
            } else {
                ans = true;
                break;
            }
        }
        if (A < B && B < C) {
            ans = true;
        }
        if (ans) {
            Console.WriteLine ("Yes");
        } else {
            Console.WriteLine ("No");
        }
    }

}

//dotnet run --project test

Measured memory_bytes: 27496
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N;
	cin >> N;
	vector<int> A(N);
	vector<int> hist(100010,0);
	for(int i=0;i<N;++i){
		cin >> A[i];
		hist[ A[i] ]++;
	}
	int ansX = -1;
	int ansMAX = 0;
	for(int i=0;i<100010;++i){//右端
		//i-2,i-1,iの数を数える
		int res = 0;
		if( i-2 >= 0 ){
			res += hist[ i-2 ];
		}
		if( i-1 >= 0 ){
			res += hist[ i-1 ];
		}
		res += hist[i];
		if( ansMAX < res ){
			ansMAX = res;
			ansX = i-1;
		}
	}
	cout << ansMAX << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    string s;cin>>s;
    string tmp=s.substr(0,3);
    cout<<tmp<<endl;
}

Measured memory_bytes: 3628
from itertools import*
x=sorted(s[0]for s in open(0).readlines()[1:])
#print(list(x))
c=[len(list(v))for k,v in groupby(x)if k in"MARCH"]
#print(c)
y=combinations(c,3)
#print(list(y))
print(sum(p*q*r for p,q,r in list(y)))

Measured memory_bytes: 10668
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn = 1e5 + 20;
map<ll , ll> mp;
int main()
{
    ll n , k;
    cin >> n >> k;
    for(int i = 0; i < n; i++)
    {
        int a , b;
        cin >> a >> b;
        mp[a] += b;
    }
    for(auto x : mp)
    {
        if(k <= x.second)
        {
            cout << x.first << endl;
            return 0;
        }
        k -= x.second;
    }
}


Measured memory_bytes: 4224
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}

inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// ll dx[4] = {1, 0, -1, 0};
// ll dy[4] = {0, 1, 0, -1};

ll c[214514];
ll dp[214514]  = {};
ll sum[214514] = {};

signed main() {
	IOS();
	ll n;
	cin >> n;
	c[0] = -1;
	for (int i = 1; i <= n; i++) {
		cin >> c[i];
	}
	dp[0] = 1;
	for (int i = 1; i <= n; i++) {
		dp[i] = dp[i - 1];
		if (c[i] != c[i - 1]) {
			dp[i] += sum[c[i]];
			dp[i] %= MOD;
			sum[c[i]] = dp[i];
		}
	}

	dump(dp[n]);
	return 0;
}

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

using namespace std;

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

	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	if (a[2] == a[0] + a[1]) {
		cout << "Yes\n";
		return 0;
	}
	cout << "No\n";

	return 0;
}



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

int main() {
  int N , L;
  cin >> N >> L;
  vector<string> vec(N);
  for(int i=0;i<N;i++)
    cin >> vec[i];
  sort(vec.begin(),vec.end());
  string ans=vec[0];
  for(int j=1;j<N;j++)
    ans+=vec[j];
  cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3



# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    h, w = map(int, input().split())
    A = []
    for _ in range(h):
        A.append(input())
    for _ in range(w+2):
        print('#', end='')
    print('')
    for hh in range(h):
        print('#' + A[hh] + '#')
    for _ in range(w+2):
        print('#', end='')
    print('')

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    char[] c = S.toCharArray();
    int[] g = new int[c.length + 1];
    g[0] = 1; // ? e.g. 'a' => 1?
    g[1] = c[0] == c[1] ? 1 : 2; // ? e.g. 'aa' => 1?
    g[2] = c[0] == c[1] || c[1] == c[2] ? 2 : 3;
    for (int i = 3; i < c.length; i++) {
      if (c[i] != c[i - 1]) {
        g[i] = g[i - 1] + 1;
      } else {
        g[i] = g[i - 3] + 2;
      }
    }
    System.out.println(g[c.length - 1]);
  }
}

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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)

using namespace std;
void solve(){
    int a[3];
    rep(i,0,3){
        cin>>a[i];
    }
    sort(a,a+3);
    int res=a[2]*10+a[1];
    cout<<a[0]+res<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    while(t--){
        solve();
    }
    return 0;
}


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

using namespace std;

int main()
{
    int n;
    cin>>n;
    float ans=0;
    for (int i=0;i<n;++i) {
        float x;
        string s;
        cin>>x>>s;
        if(s=="JPY"){
            ans+=x;
        }else{
            ans+=x*380000.0;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	parseProblem()
}

func parseProblem() {
	n, k, q := scanInt(sc), scanInt(sc), scanInt(sc)
	as := nextIntSlice(sc, q)
	anser := make([]int, n)
	for _, p := range as {
		anser[p-1]++
	}
	for i := range anser {
		if k-q+anser[i] > 0 {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
	return
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	return int(a)
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextIntSlice(sc *bufio.Scanner, n int) (a []int) {

	a = make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt(sc)
	}
	return a
}

func resolve(n int) int {
	return n
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 4112
#include <iostream>

using namespace std;

int main()
{
    double min, max, tmp;
    cin >> tmp;
    min = max = tmp;

    while (cin >> tmp) {
        if (tmp < min) {
            min = tmp;
        }
        if (tmp > max) {
            max = tmp;
        }
    }

    cout << fixed << (max - min) << endl;

    return 0;
}

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

#define int long long 

using namespace std;

vector < vector <char> >matrix;
const int MOD = (int)1e9 + 7;

int func(int h, int w)
{
    vector <vector <int> > dp(h, vector <int>(w));
    for(int i = h - 1;i >= 0;i--)
    {
        for(int j = w - 1;j >= 0;j--)
        {
            if(matrix[i][j] == '#')dp[i][j] = 0;
            else if(i == h-1 && j == w-1)dp[i][j] = 1;
            else if(i == h-1)dp[i][j] = dp[i][j+1];
            else if(j == w-1)dp[i][j] = dp[i+1][j];
            else dp[i][j] = (dp[i + 1][j] + dp[i][j + 1]) % MOD;

        }
    }
    return dp[0][0];
    
}

signed main()
{
    int h, w;
    cin >> h >> w;
    matrix.assign(h, vector<char>(w));
    for(int i = 0;i < h;i++)
    {
        for(int j = 0;j < w; j++)
        {
            cin >> matrix[i][j];
        }
    }
    int ans = func(h, w);
    cout << ans << endl;

}

Measured memory_bytes: 9088
N, D = map(int, input().split())

x = [list(map(int, input().split())) for _ in range(N)]

ans = 0

for i in range(N):
  for j in range(i+1, N):
    dst = 0
    for d in range(D):
      dst += (x[i][d] - x[j][d])**2
    dst = dst ** 0.5
    if int(dst) == dst:
      ans += 1

print(ans)




Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 1000000007; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int N, M;
  cin >> N >> M;

  int a, b;
  vector<int> num(N, 0);
  REP(i, M){
    cin >> a >> b;
    num[a-1]++; num[b-1]++;
  }

  bool flag = true;
  REP(i, N) if(num[i]%2 == 1) flag = false;

  flag? YES: NO;

  return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<cmath>

using namespace std;

int main(void)
{
    long long x; cin>>x;
    for(long long a=-1000;a<=1000;++a){
        long long tmp = a*a*a*a*a - x;
        for(long long b=-1000;b<=1000;++b){
            if(b*b*b*b*b == tmp){
                cout<<a<<' '<<b<<'\n';
                return 0;
            }
        }
        
    }
    return 0;
}

Measured memory_bytes: 3628
/*
    ThunderClap and Flash.
    Raunaq Singh
*/
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define ThunderClap ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define debugg(something)   cout<<#something<<" - "<<something<<"\n";
#define vi vector
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define LB lower_bound
#define UB upper_bound
#define mp make_pair
#define pb push_back
#define in insert
#define s second
#define f first
#define pQueue priority_queue
#define maxElement *max_element
#define minElement *min_element
#define MAX 100000LL
#define mod 1000000007LL
#define inf 1000000000000000000LL
#define mI2 500000004LL
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod))%mod;}
inline ll mul(ll a, ll b){ return ((a%mod)*(b%mod))%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}

ll findMin(ll i, ll h, ll a[], ll b[], ll dp[][10001], ll n){
    if(h<=0){
        return 0;
    }
    if(i==n){
        return mod;
    }
    if(dp[i][h]!=-1){
        return dp[i][h];
    }
    ll ret=min(findMin(i,h-a[i],a,b,dp,n)+b[i],findMin(i+1,h,a,b,dp,n));
    return dp[i][h]=ret;
}
                                        
void Flash(){
    ll h,n;
    cin>>h>>n;
    ll a[n],b[n];
    for(ll i=0;i<n;i++){
        cin>>a[i]>>b[i];
    }
    ll dp[n][10001];
    memset(dp,-1,sizeof(dp));
    cout<<findMin(0,h,a,b,dp,n)<<"\n";
}

int main(int argc, char const *argv[]){
    ThunderClap;
    ll t=1;
    //cin>>t;
    for(ll i=1;i<=t;i++){
        //cout<<"Case #"<<i<<": ";
        Flash();
    }
    return 0;
}																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																																		

Measured memory_bytes: 79232
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> L(N);
  int sum =0;
  bool ans = false;

  for(int i=0; i<N; i++) {
    cin >> L.at(i);
  }
  sort(L.begin(),L.end());
  reverse(L.begin(),L.end());
  
  for(int i=1; i<N; i++) sum += L.at(i);
  
  if(L.at(0)< sum) ans = true;

  if(ans == true) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3604
#include <iostream>
using namespace std;
 
int main(){
  int K, S;
  int res=0;
  cin >> K >> S;
  for(int x=0;x<=K;++x){
    for(int y=0;y<=K;++y){
      int z = S - x -y;
      if(0<=z and z<=K) ++res;
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
import itertools

def check():
    max_profit = 0
    N = int(input())
    value = list(map(int, input().split(" ")))
    cost = list(map(int, input().split(" ")))
    num = [i for i in range(N)]
    
    for i in range(1,N+1):
        for numList in itertools.combinations(num,i):
            total = 0
            for k in numList:
                total += value[k] - cost[k]
            if max_profit < total:
                max_profit = total
    print(max_profit)

check()

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		long a = sc.nextInt();
		long b = sc.nextInt();
		int k = sc.nextInt();
		for (int i = 0; i < k; i++) {
			if (i % 2 == 0) {
				if (a % 2 == 1) {
					a--;
				}
				a = a / 2;
				b += a;
			} else {
				if (b % 2 == 1) {
					b--;
				}
				b = b / 2;
				a += b;
			}
		}
		System.out.println(a + " " + b);
	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1e9+7;
using namespace std;
typedef pair<int,int> pii;
int main(){
    int n;
    cin >> n;
    int tmpmin = n+1;
    int a[n];
    rep(i,n) cin >> a[i];
    int ans = 0;
    rep(i,n){
        if(tmpmin>a[i]) ans++;
        tmpmin = min(a[i],tmpmin);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#![allow(non_snake_case)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(
        a: f32,
        b: f32,
    );

    for yen in 1..1009 {
        let i = yen as f32;
        if ((i * 0.08).floor() == a) && ((i * 0.1).floor() == b) {
            println!("{}", i);
            return;
        }
    }
    // let down = (a / 0.08) as i32;
    // let up = (a / 0.08) as i32 + 1;
    // for yen in down..up {
    //     if (yen / 10) == b {
    //         println!("{} ", yen);
    //         return;
    //     }

    // }
    println!("-1");

}



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

#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
const double pi = 3.14159265358979;



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

    ll k,s;
    cin >> k >> s;

    ll ans = 0;
    for (ll x = 0; x <= k; x++){
        for (ll y = 0; y <= k; y++){
            if (0 <= (s-x-y) && (s-x-y) <= k){
                ans++;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3644
N=int(input())
A=input().split()
cnt=0
for i in range(N):
    if int(A[i])%6==0 or int(A[i])%10==0:
            cnt += 1
sum=0
for i in range(N):
    if int(A[i])%2==0:
        sum += 1
if cnt==sum:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
    using namespace std;
   
    int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    int cnt=1;
    char str = S[0];
    for (int i = 0; i < N; i++)
    {
      if(str != S[i]){
        cnt++;
        str = S[i];
      }
    }

    cout << cnt;
     }

Measured memory_bytes: 512
n, m = map(int, input().split())
ks = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
ans = 0
for i in range(2 ** n):
  onswichi = [False] * n
  onlight = [0] * m
  for j in range(n):
    if (i >> j) & 1:
      onswichi[j] = True
  for k in range(m):
    cnt = 0
    for f in ks[k][1:]:
      if onswichi[f-1]:
        cnt += 1
    if cnt % 2 == p[k]:
      onlight[k] = 1
  if sum(onlight) == m:
    ans += 1
print(ans)

Measured memory_bytes: 9168
#include <iostream>
using namespace std;
int main() {
    // insert code here...
    int a, b;
    while(1){
        cin >> a >> b;
        if (a == 0 && b == 0)break;
        if (a < b){
            cout << a << ' ' << b << endl;
        }
        else{
            cout << b << ' ' << a << endl;
        }
    }
    return 0;
}



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

int main(){
  int c[6];
  int money = 0;

  for(int i=0;i < 6;i++){
    cin >> c[i];
  }
  money = c[0]*1 + c[1]*5 + c[2]*10 + c[3]*50 + c[4]*100 + c[5]*500;

  if(money >= 1000)
    {
      cout << 1 << endl;
    }
  else
    {
      cout << 0 << endl;
    }
  return 0;
}



Measured memory_bytes: 3128