akhauriyash/Code-Regression huggingface dataset:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()

    # A*B<Nとなる(A, B)の数
    ans = 0
    for i in range(1, N):
        ans += (N - 1) // i

    print(ans)

if __name__ == '__main__':
    resolve()


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

bool dp[100005];
vector<int> v;

int main(){
	int n,k;
	cin>>n>>k;
	for(int i=0,t;i<n;i++)
		cin>>t,v.push_back(t);
	// sort(v.begin(),v.end());
	
	for(int i=0;i<=k;i++)
		dp[i]=1;
	for(int i=0;i<=k;dp[i]=!dp[i],/*cout<<"| "<<i<<' '<<dp[i]<<'\n',*/i++)
		for(int k=0;k<v.size() && v[k]<=i;/*cout<<dp[i-v[k]]<<' '<<dp[i]<<' '<<v[i-k]<<' '<<'-',*/k++)
			dp[i]=dp[i]&&dp[i-v[k]];
    cout<<(dp[k]?"First\n":"Second\n");
// 	for(int i=0;i<=k;i++)
// 		cout<<dp[i]<<' ';
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  char b;
  cin >> b;
  if (b == 'A')
    cout << 'T' << endl;
  else if (b == 'T')
    cout << 'A' << endl;
  else if (b == 'C')
    cout << 'G' << endl;
  else if (b == 'G')
    cout << 'C' << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define fs first
#define sc second
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}

int main(void){
    int n;
    cin >> n;
    vector<int> x(n);
    rep(i,n) cin >> x[i];
    int ave = round(sum(x) / (double)n);
    int ans = 0;
    rep(i,n){
        ans += (x[i]-ave) * (x[i]-ave);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> inline bool chmax(t&a,u b){if(a<b){a=b;return true;}return false;}
template<class t,class u> inline bool chmin(t&a,u b){if(b<a){a=b;return true;}return false;}

const int D = 60;
const int MAX_N = 200005;
int to[D][MAX_N];

int main(){
    int n;ll k;cin >> n >> k;
    rep(i,n){
        cin >> to[0][i];
        --to[0][i];
    }
    rep(i,D-1){
        rep(j, n){
            to[i+1][j] = to[i][to[i][j]];
        }
    }

    int v = 0;
    for(int i=D-1;i>=0;--i){
        ll l = 1ll<<i;
        if(l <= k) {
            v = to[i][v];
            k -= l;
        }
    }
    cout << v+1 << "\n";
}

Measured memory_bytes: 50500
import unittest


def main():
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    total_a = [0]*(n+1)
    total_b = [0] * (m + 1)
    for i in range(n):
        total_a[i+1] = total_a[i] + a[i]
    for i in range(m):
        total_b[i + 1] = total_b[i] + b[i]
    ai = 0
    bi = m
    max_v = 0
    while total_b[bi] > k:
        bi -= 1
    while ai <= n and total_a[ai] <= k:
        while bi > 0 and total_a[ai]+total_b[bi] > k:
            bi -= 1
        if total_a[ai]+total_b[bi] <= k:
            max_v = max(max_v, ai + bi)
        ai += 1
    print(max_v)


if __name__ == "__main__":
    main()


class TestAbc138_e(unittest.TestCase):
    def test_abc138_e(self):
        self.assertEqual(solve('contest', 'son'), 10)
        self.assertEqual(solve('contest', 'programming'), -1)
        self.assertEqual(solve('contest', 'sentence'), 33)
        self.assertEqual(solve('abc', 'abccccac'), 15)


Measured memory_bytes: 54652
function Main(input) {
  var x = parseInt(input.trim());
  var xsqrt = Math.sqrt(x);
  
  for (var n = x; true; n++) {
    var prime = true;
    for (var a = 2; a <= xsqrt; a++) {
      if (n % a == 0) {
        prime = false;
        break;
      }
    }
    if (prime) {
      console.log(n);
      return;
    }
  }
};
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058
#define MAXN 1000005

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
#define ceil(a,b) (a+b-1)/b
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

int spf[MAXN];
void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++) 
  
        spf[i] = i; 
  
    for (int i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
  
    for (int i=3; i*i<MAXN; i++) 
    { 
        if (spf[i] == i) 
        {  
            for (int j=i*i; j<MAXN; j+=i) 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 
  
vector<int> getFactorization(int x) 
{
    vector<int> ret;
    while (x != 1) 
    { 
        ret.pb(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret; 
} 

//START OF CODE ->->->->->->->

void solve()
{
    sieve();
    int n;
    cin>>n;
    vector<int> a(n);
    vector<int> f(MAXN,0);
    rep(i,0,a.size()){
        cin>>a[i];
        f[a[i]]++;
    }
    int cnt = 0;
    // vector<int> ret = getFactorization(16);
    // rep(i,0,ret.size()){
    //     out1(ret[i]);
    // }
    repr(i,a.size()-1,0){
        vector<int> ret;
        bool ok = true;
        for ( int j = 1 ; j <= sqrt(a[i]) ; j++ ){
            if ( a[i] % j == 0 ){
                ret.pb(j);
                if ( a[i]/j != j ){
                    ret.pb(a[i]/j);
                }
            }
        }
        // ret.pb(1);
        // ret.pb(a[i]);
        f[a[i]]--;
        rep(j,0,ret.size()){
            if(f[ret[j]]){
                ok = false;
                break;
            }
        }
        if(ok){
            cnt++;
        }
        f[a[i]]++;
    }
    cout<<cnt<<endl;
}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 20368
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
////////////////////////////

ll po(ll i,ll p){
    if(p==0)return 1;
    else{
        i=mod(i);
        if(p==1)return i;
        if(p%2==0)return po(mod(i*i),p/2);
        return mod(i*po(i,p-1));
    }
}
ll bunbo(ll n){
    return po(n,i_5);
}
ll comb(ll n,ll k){
    ll res=1;
    rep(i,1,k){
        res=mod(mod(res*bunbo(i))*(n+1-i));
    }
    return res;
}

int main(){fastio
    
    ll n,a,b;cin>>n>>a>>b;
    ll ans=po(2,n);
    ans=mod(ans-comb(n,a)-comb(n,b)-1);
    cout<<mod(ans)<<endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;

constexpr static ll MOD = 1000000007ll;
constexpr static int INF = 1 << 28; // for x <= 10^9
constexpr static ll INFL = 1ll << 60; // for x <= 10^19

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

    double ans = ((n + 1) / 2) / (double)n;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <regex>
#include "bits/stdc++.h"
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define LINF (LLONG_MAX / 2)
#define EPS (1.0e-8)
#define mkpr make_pair
const int MGN = 10;
const int ARY_SZ_MAX = (int)1e7;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>;
using vc = vector<char>; using vvc = vector<vc>;
using vb = vector<bool>; using vvb = vector<vb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using psl = pair<string, ll>;


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


  int N,K; cin>>N>>K;
  vl H(N); REP(i,N) cin>>H[i];
  sort(H.rbegin(),H.rend());

  if (N<=K) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = 0;
  FOR(i,K,N) {
    ans += H[i];
  }

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if (a > 8 || b > 8)
			System.out.println(":(");
		else
			System.out.println("Yay!");
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
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; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main(){
    string a,b;cin>>a>>b;
    
    if(a.length()==b.length()){
        for(int i=0;i<a.length();i++){
                if(a[i]>b[i]){
                    cout << "GREATER" << endl; 
                    return 0;
                }
                else if(a[i]<b[i]){
                    cout << "LESS" << endl; 
                    return 0;
                }
        }
    cout << "EQUAL" << endl;
    }
    else{
        if(a.length()>b.length())cout << "GREATER" << endl;
        else cout << "LESS" << endl; 
    }

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<iomanip>
#include<fstream>
#include<vector>
#include<set>
using namespace  std;
int main()
{
	char in[11] ;
	set <string>a;
	int time = 0;
	cin >> time;
	string str;
	
	while (time>0)
	{
		cin >> in;
		a.insert(in);
		time--;
	}
	int b=a.size();
	cout << b << endl;


	
	
}

Measured memory_bytes: 19108
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;

namespace atcorder
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int A = intArray[0];
            int B = intArray[1];
            if(A < 10 && B < 10)
            {
                Console.WriteLine(A * B);
            }
            else
            {
                Console.WriteLine(-1);
            }
        }
    }
}

//文字配列の取得
//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];

//文字列の取得
//string s = Console.ReadLine();

//数字配列の取得
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];

//数字の取得
//int N = int.Parse(Console.ReadLine());

//リスト型(int)の取得
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());

//出力
//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.WriteLine(cnt);



Measured memory_bytes: 28272
#include<cstdio>
#include<algorithm>
using namespace std;
int n;
int num[15];
int cnt[15];
int ans[30005];
int tot=0;
void dfs(int now,long long val,int pre0)
{
    if(now==10)
    {
        if(cnt[7]>0&&cnt[5]>0&&cnt[3]>0)
        {
            ans[++tot]=val;
            return;
        }
        return;
	}
	if(pre0==0)
    {
        num[now]=0;
        cnt[0]++;
        dfs(now+1,val*10+0,0);
        cnt[0]--;
	}
	num[now]=7;
	cnt[7]++;
	dfs(now+1,val*10+7,1);
	cnt[7]--;
	num[now]=5;
	cnt[5]++;
	dfs(now+1,val*10+5,1);
	cnt[5]--;
	num[now]=3;
	cnt[3]++;
	dfs(now+1,val*10+3,1);
	cnt[3]--;
}
void pretreat()
{
	dfs(1,0,0);
}
void work()
{
	int Ans=0;
	for(int i=1;i<=tot;i++)
	{
		if(ans[i]<=n)
		{
			Ans++;
		}
	}
	printf("%d",Ans);
}
int main()
{
	scanf("%d",&n);
	pretreat();
	work();
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string s;
  cin >> s;
  int ans = 0;
  while(s.size() > 2) {
    s.pop_back();
    int n = s.size();
    if(n % 2 != 0) continue;
    if(s.substr(0, n / 2) == s.substr(n / 2)) ans = max(ans, n);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
use std::io::{self, Read};

fn main() {
    let mut buffer = String::new();
    io::stdin().read_to_string(&mut buffer).unwrap();
    let buffer = buffer.trim();

    let iter = buffer.split_whitespace();

    let mut area = 1;
    let mut length = 0;

    for w in iter {
        let n: i32 = w.parse().unwrap();
        area *= n;
        length += n * 2;
    }

    println!("{} {}", area, length);
}



Measured memory_bytes: 5028
#define _USE_MATH_DEFINES

#include<iostream>
#include<iomanip>
#include<math.h>

using namespace std;

int main()
{
	double r;

	cin >> r;
	cout << fixed << setprecision(6);
	cout << pow(r, 2)* M_PI << " "<< 2 * r* M_PI<< endl;
	return 0;
}


Measured memory_bytes: 3252
package main
import "fmt"

func min(a int,b int) int{
	if a>b{
		return b
	} else {
		return a
	}
}
func zet(a int) int{
	if a<0 {
		return a*(-1)
	} else{
		return a
	}
}

func main() {
	var n,m,sc int
	fmt.Scan(&n,&m)
	tmp := 0
	ans := 1
	for i:=0;i<n;i+=1{
		fmt.Scan(&sc)
		tmp += sc
		if tmp<=m{
			ans += 1
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin >> N;
    int arr[N];
    for(int i = 0; i < N; i++){
        cin >> arr[i];
    }
    
    int cnt = 0;
    bool flag = true;
    while (flag){
        flag = false;
        for(int i = N-1; i >=1; i--){
            if(arr[i-1] > arr[i]){
                int tmp = arr[i-1];
                arr[i-1] = arr[i];
                arr[i] = tmp;
                flag = true;
                cnt++;
            }
        }
    }
    
    for(int i = 0; i < N; i++){
        if(i != N-1) cout << arr[i] << " ";
        else cout << arr[i] << endl;
    }
    
    cout << cnt << endl;
}




Measured memory_bytes: 3084
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, n, ans = 0;
  scanf("%lld", &n);
  ll a[n + 1];
  a[0] = 1e5, a[n] = 1e5;
  for(i = 1; i < n; ++i) scanf("%lld", &a[i]);
  for(i = 0; i < n; ++i) ans += a[i] < a[i + 1] ? a[i] : a[i + 1];
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define N 1111116
#define next nxt

int n,k,s,t,d,x[N],y[N],z[N],a[N],b[N],next[N],p[N],cnt[N],h[N];
long long ans;

bool cmp(int i,int j){
	return x[i]!=x[j]?x[i]<x[j]:y[i]<y[j];
}

void add(int x,int y){
	a[++k]=x;b[k]=y;next[k]=p[x];p[x]=k;
	a[++k]=y;b[k]=x;next[k]=p[y];p[y]=k;
}

bool check(int i,int j,int k){
	return x[i]<x[j]+d||(x[i]==x[j]+d&&y[i]<=y[j]+k);
}

void solve(int k){
	for (int i=1;i<=n;i++) z[i]=i;
	sort(z+1,z+n+1,cmp);
	for (int i=1,j=1,l=1,r=1;i<=n;i++){
		while (l<=n&&check(z[l],z[i],-k-1)) l++;
		while (r<=n&&check(z[r],z[i],k)) r++;
		cnt[z[i]]+=r-l;j=max(j,l);
		if (j==r) continue;
		add(z[i],z[j]);
		for (;j+1<r;j++) add(z[j],z[j+1]);
	}
}

void travel(int x){
	h[x]=1;ans+=cnt[x];
	for (int t=p[x];t;t=next[t])
		if (!h[b[t]]) travel(b[t]);
}

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	n=read();s=read();t=read();
	for (int i=1;i<=n;i++){
		int tx=read(),ty=read();
		x[i]=tx+ty;y[i]=tx-ty;
	}
	d=max(abs(x[s]-x[t]),abs(y[s]-y[t]));
	solve(d);
	for (int i=1;i<=n;i++) swap(x[i],y[i]);
	solve(d-1);travel(s);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 28672
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1000000007;

signed main() {
  
  string S;
  cin >> S;
  
  int gu = 0;
  int pa = 0;
  for( int i = 0; i < S.size(); i++ ){
    if( S.at(i) == 'g' ) gu++;
    else pa++;
  }  
  cout << (gu-pa)/2 << endl;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const ll match[10]={inf,2,5,5,4,5,6,3,7,6};
void update(string &a,string b){
    if(a=="x")a=b;
    else if(a.size()<b.size())a=b;
    else if(a.size()==b.size()){
        if(a<b)a=b;
    }
}
int main(){
    ll n,m;cin >> n >> m;
    vl a(m);rep(i,m)cin >> a[i];
    string dp[10100];
    rep(i,10100){
        dp[i]="x";
    }
    dp[0]="";
    rep(i,n+1){
        if(dp[i]=="x")continue;
        for(auto p:a){
            update(dp[i+match[p]],dp[i]+to_string(p));
        }
    }
    cout << dp[n] <<endl;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false); cin.tie(NULL);
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());

    cout << (s < t? "Yes" : "No");
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
#define N 1000700
int n,k,ct,p[N],q[N],rp[N],rq[N],s[N],rs[N],vis[N],st[N],as[N],s1[N];
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)scanf("%d",&p[i]);
	for(int i=1;i<=n;i++)scanf("%d",&q[i]);
	if(k==1){for(int i=1;i<=n;i++)printf("%d ",p[i]);return 0;}
	if(k<=6)
	{
		for(int i=3;i<=k;i++)
		{
			for(int j=1;j<=n;j++)s[p[j]]=q[j],p[j]=q[j];
			for(int j=1;j<=n;j++)q[j]=s[j];
		}
		for(int i=1;i<=n;i++)printf("%d ",q[i]);return 0;
	}
	for(int i=1;i<=n;i++)rp[p[i]]=i,rq[q[i]]=i;
	for(int i=1;i<=n;i++)s1[i]=rp[q[p[rq[i]]]];
	for(int i=3;i<=(k-1)%6+7;i++)
	{
		for(int j=1;j<=n;j++)s[p[j]]=q[j],p[j]=q[j];
		for(int j=1;j<=n;j++)q[j]=s[j];
	}
	for(int i=1;i<=n;i++)if(!vis[i])
	{
		ct=0;st[ct=1]=i;vis[i]=1;
		for(int j=s1[i];j!=i;j=s1[j])st[++ct]=j,vis[j]=1;
		for(int j=1;j<=ct;j++)as[st[j]]=st[(j-2+(k-1)/6)%ct+1];
	}
	for(int i=1;i<=n;i++)rs[as[i]]=i;
	for(int i=1;i<=n;i++)printf("%d ",rs[q[as[i]]]);
}//

Measured memory_bytes: 21632
#include <iostream>                                             
#include <string>                                               
#include <cctype>                                               
using namespace std;                                            
                                                                
int main() {                                                    
  string W, T;                                                  
  cin >> W;                                                     
  int ans = 0;                                                  
  while (true) {                                                
    cin >> T;                                                   
    if (T=="END_OF_TEXT") {                                     
      break;                                                    
    }                                                           
    for (int i=0; i<T.size(); i++) {                            
      T[i] = tolower(T[i]);                                     
    }                                                           
    if (W==T) {                                                 
      ans++;                                                    
    }                                                           
  }                                                             
  cout << ans << endl;                                          
  return 0;                                                     
}                                                               
                                                                
                                

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

int main()
{
    int n, x;
    long long int ans = 0;
    cin >> n >> x;
    vector<int> a(n), b(n);
    for(int i = 0;i < n;i++){
        cin >> a[i];
        b[i] = a[i];
    }

    for(int i = 0;i < n - 1;i++){
        if(a[i] + a[i + 1] > x){
            if(a[i] > x){
                a[i + 1] = 0;
                a[i] = x;
            }
            else{
                a[i + 1] = x - a[i];
            }
        }
    }

    for(int i = 0;i < n;i++){
        ans += b[i] - a[i];
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
  int h1,m1,h2,m2,k;
  
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  
  int t = ( h2 - h1 ) * 60 + m2 - m1;
  int res = t - k;
  
  cout << res << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
using Graph = vector<vector<int>>;
int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a,b;
    cin>>a>>b;
    int ans=1;
    for(int i=0;;i++){
        if(ans>=b){
            cout<<i<<endl;
            return 0;
        }
        ans=ans-1+a;
    }
}

Measured memory_bytes: 3656
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		HashMap<Integer, Boolean> m = new HashMap<Integer, Boolean>();
		int N;
		// GET INPUT
		N = sc.nextInt();
		for(int i=0; i<N; i++) {
			int A = sc.nextInt();
			if(m.containsKey(A)) {
				if(m.get(A)) {
					m.put(A, false);
				} else {
					m.put(A, true);
				}
			} else {
				m.put(A, true);
			}
		}
		
		
		
		// GET INPUT END
		
		sc.close();
		
		int ans = 0;
		for(Map.Entry<Integer, Boolean> entry : m.entrySet()) {
			if(entry.getValue()) {
				ans++;
			}
		}
		System.out.println(ans);
		
		


	}

}


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

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> p(N);
    for(int i = 0; i < N; ++i) cin >> p[i];

    // 期待値の和は和の期待値
    // E[X + Y] = E[X] + E[Y]を用いる

    // 計算量がO(N^2)でもまだ間に合わない。
    // O(N)にする方法は？

    double cnt = 0.0;
    double result = 0.0;
    for(int i = 0; i < N - K + 1; ++i) {

        if(i == 0) {
            for(int k = 0; k < K; ++k) {
                result += (double)(0.5 * p[k] * (p[k] + 1)) / (double)p[k];
            }
        } else {
            result -= (double)(0.5 * p[i - 1] * (p[i - 1] + 1)) / (double)p[i - 1];
            result += (double)(0.5 * p[i + K - 1] * (p[i + K - 1] + 1)) / (double)p[i + K - 1];
        }

        if(cnt < result) {
            cnt = result;
        }
    }

    cout << fixed << setprecision(10) << cnt << endl;
}

Measured memory_bytes: 1024
from sys import stdin
input = stdin.readline

k, n = map(int, input().split())

if n:
    p = [int(x) for x in input().split()]
else:
    p = []

a, b = -1, 101
p.sort()
chk = [0] * 101

for x in p:
    chk[x] = 1

for x in range(k, -1, -1):
    if chk[x] == 0:
        a = x
        break

for x in range(k, 101):
    if chk[x] == 0:
        b = x
        break

if k - a <= b - k:
    print(a)
else:
    print(b)

Measured memory_bytes: 9188
S = gets.chomp

c = Hash.new{|h, k| h[k] = 0}
(0...S.size).each{|i| c[S[i]] += 1}

ans = 'Yes'
if c.size == 2 then
  if c.any?{|k, v| v != 2} then
    ans = 'No'
  end
else
  ans = 'No'
end

puts ans


Measured memory_bytes: 3836
#include<bits/stdc++.h>
long long n, r, count;
using namespace std;
typedef long long ll;
//下面是一个输出函数
char ss[2000];
int number = 0;
int num[100008];
int main()
{
	int n;
	cin >> n;
	ll minn = 99999999;
	for (int i = 1; i <= n; i++)
		scanf("%d", &num[i]);
	sort(num + 1, num + 1 + n);
	for (int i = num[1]; i <= num[n]; i++)
	{
		ll sum = 0;
		for(int j=1;j<=n;j++)
		{ 
			sum += (num[j] - i) * (num[j] - i);
		}
		if (sum < minn) minn = sum;
	}
	cout << minn;
	return 0;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static final int MAX = 100; 
	
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
	
		String[] in;
		int[] a = new int[MAX + 1];
		for(int i = 0; i < n; ++i){
			in = br.readLine().split(" ");
			a[i] = Integer.parseInt(in[0]);
			a[i+1] = Integer.parseInt(in[1]);
		}
		
		long[][] cost = new long[MAX][MAX];
		calcCost(a, cost);
		
		System.out.println(cost[0][n-1]);
	}
	public static void calcCost(int[] a, long[][] cost){
		int n = cost.length;
		for(int k = 0; k < n; k++){
			for(int i = 0; i + k < n; i++){
				if(k == 0){
					cost[i][k] = 0;
					continue;
				}
				cost[i][k] = Long.MAX_VALUE;
				for(int j = 0; j < k; j++){
					long c = cost[i][j] + cost[i+j+1][k-j-1] + a[i]*a[i+j+1]*a[i+k+1]; 
					if(c < cost[i][k]){
						cost[i][k] = c;
					}
				}
			}
		}

	}

}

Measured memory_bytes: 24664
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter

n = ni()
a = list(li())

cnt = Counter(a)

ans = 0
for k,v in cnt.items():
    if v < k:
        ans += v
    elif v > k:
        ans += (v-k)
        
print(ans)

Measured memory_bytes: 18340
h,w = map(int,input().split())
rlist = [] #行を削除したリスト
#まずは.でできた行を削除したリストを作成
for i in range(h):
    olist = list(input()) #オリジナルリストから一行ずつ取り出す
    if olist != ['.']*w:
        rlist.append(olist)
#print(rlist)
#縦のリストを作成する
tlist = [0]*w
for j in rlist:
    for k in range(w):
        if j[k] == ('.'):
            tlist[k] += 1
#削除すべき行を判定するリスト
#print(tlist)
anslist = [[]]
for l in range(w):
    if tlist[l] == len(rlist):
        for m in rlist:
            m[l] = ''
#print(rlist)
newlist = []
for h in rlist:
    newlist.append(''.join(h))
#print(newlist)
for n in newlist:
    print(n)

Measured memory_bytes: 3188
#include <iostream>
using namespace std;
int N,S,tmp;
int main() {
  cin >> N;;
  tmp = N;
  while(tmp>9) {
    S = S+tmp%10;
    tmp = tmp/10;
  }
  S = S+tmp;
  if(N%S==0) {
    cout << "Yes" << '\n';
  }
  else {
    cout << "No" << '\n';
  }
  return(0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define init ios::sync_with_stdio(0); cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007 
#define PI atan(1)*4

typedef long long ll;
typedef long double ld;
using namespace std;


ll gcd(ll a, ll b){
    if(a>b)
        swap(a,b);
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
}

ll powerMod(ll x,ll y){
    ll res = 1;
    x %= MOD;
    while(y>0){
        if(y&1)res = (res*x)%MOD;
        y = y>>1;
        x = (x*x)%MOD;
    }
    return res;
}

//  =========     /\       /|    |====/|
//      |        /  \       |    |   / |
//      |       /____\      |    |  /  |
//      |      /      \     |    | /   |
//  ========= /        \  =====  |/====|  
//  code

int main(){
    init;
    int n,i,j,k,l;
    cin>>n;
    double p[n],dp[n+1][n+1];
    for(i=0;i<n;i++)
        cin>>p[i];
    memset(dp,0,sizeof(dp));
    dp[0][0] = 1;
    for(i=1;i<=n;i++){
        for(j=0;j<=i;j++){
          	// tails
            dp[i][j] += dp[i-1][j] * (1 - p[i-1]);
          	// heads
            if(j > 0)
                dp[i][j] += dp[i-1][j-1] * p[i-1];
        }
    }
    double ans = 0;
    for(i=n/2 + 1;i<=n;i++){
        ans += dp[n][i];
    }
    cout<<setprecision(20)<<ans<<endl;
    return 0;
}

Measured memory_bytes: 70656
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());

        // 主処理
        int result = 0;
        if (13 <= a) {
            result = b;
        } else if (6 <= a) {
            result = b / 2;
        }

        // 出力
        System.out.println(result);
        sc.close();
    }
}

Measured memory_bytes: 21716
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

struct Point{
  double x, y;
};

int main(){
  int n;
  Point P[21];
  int cs = 0;
  while(scanf("%lf,%lf", &P[cs].x, &P[cs].y) != EOF){
    cs++;
  }
  
  double area = 0;
  
  for(int i = 0 ; i < cs-1 ; i++){
    area += P[i].x * P[i+1].y - P[i].y * P[i+1].x;
  }
  area += P[cs-1].x * P[0].y - P[cs-1].y * P[0].x;
  
  printf("%f\n", abs(area)/2);
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int h, w;
string s[101];
bool ph[101], pw[101];

signed main() {
	cin >> h >> w;
	rep(i,h) cin >> s[i];
	rep(i,h) {
		bool b = 1;
		rep(j,w) if (s[i][j]=='#') b = 0;
		if (b) ph[i] = 1;
	}
	rep(i,w) {
		bool b = 1;
		rep(j,h) if (s[j][i]=='#') b = 0;
		if (b) pw[i] = 1;
	}
	rep(i,h) {
		bool wr = 0;
		rep(j,w) if (!ph[i] && !pw[j]) {
			cout << s[i][j];
			wr = 1;
		}
		if (wr) cout << endl;
	}
}

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

char s[100];

int main(){
	scanf("%s" , s + 1);
	int n = strlen(s + 1);
	if(n & 1){ puts("No"); return 0; }
	for(int i = 1; i <= n; i++)
		if(i & 1 && s[i] != 'h' || !(i & 1) && s[i] != 'i')
			{ puts("No"); return 0; }
	puts("Yes");
	return 0;
} 

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if((a==7 && b==5 && c==5) || (a==5 && b==7 && c==5) || (a==5 && b==5 && c==7)) {
		printf("YES");		
	}
	else{
		printf("NO");
	}
	
	
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    int N,s=0,sum=0;
    cin >> N;
    vector<int> b(N);
    for(int i = 0; i < N; i++){
        cin >> b[i];
    }
    for(int i = N-1; i >0; i--){
        s+=b[i];
        sum+=s*b[i-1];
    }
    cout << sum << endl;
    
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int d, n, ans;
    cin >>d >>n;
    if(n == 100){
        n += 1;
    }
    if(d == 0){
        ans = 1 * n;
    }else if(d == 1){
        ans = 100 * n;
    }else{
        ans = 10000 * n;
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
// Enjoy your stay.

#include <bits/stdc++.h>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

int isp[1300000];

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	fill(isp+2,isp+1300000,1);
	rep2(i,2,1300000)if(isp[i]){
		for(int j=i*2;j<1300000;j+=i)isp[j]=0;
	}
	int x;
	while(cin>>x && x){
		if(isp[x])cout<<0<<endl;
		else{
			int l=x,r=x;
			while(!isp[l])l--;
			while(!isp[r])r++;
			cout<<r-l<<endl;
		}
	}
}

Measured memory_bytes: 6272
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define fi first
#define se second
#define inf 1000000007

ll N,M;
vector<pl> prime;

ll modpow(ll a, ll p){
    if (p == 0) return 1;
    if (p%2 == 0){
        ll halfp = p/2;
        ll half = modpow(a,halfp)%inf;
        return half*half%inf;
    }
    else{
        return a*modpow(a,p-1)%inf;
    }
}

ll calcComb(ll a, ll b){
    if (b > a-b) return calcComb(a,a-b);
    ll ansMul = 1;
    ll ansDiv = 1;
    rep(i,b){
        ansMul *= (a-i);
        ansDiv *= (i+1);
        ansMul %=inf;
        ansDiv %=inf;
    }
    return ansMul*modpow(ansDiv,inf-2)%inf;
}

void primef(ll n){
    ll s;
    s = sqrt(n);
    repi(i,2,s+2){
        ll cnt = 0;
        if (n % i == 0){
            while(n % i == 0){
                cnt ++;
                n = n/i;
            }
        }
        pl temp;
        temp.fi = i; temp.se = cnt;
        prime.push_back(temp);
    }
    if (n > s){
        pl temp;
        temp.fi = n; temp.se = 1;
        prime.push_back(temp);
    }
    return;
}
int main() {
    scanf("%lld%lld",&N,&M);
    primef(M);
    ll ans = 1;
    rep(i,prime.size()){
        ans =  (ans*calcComb(prime[i].se+N-1,N-1))%inf;
    }
    cout << ans << endl;
    
    return 0;
}




Measured memory_bytes: 892
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        boolean f = false;
        while (sc.hasNext()) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            if (n == 0 && m == 0) {
                break;
            }
            List<Integer> l = new ArrayList<>();
            for (int i = n; i <= m; i++) {
                if (i % 400 == 0 || i % 4 == 0 && i % 100 != 0) {
                    l.add(i);
                }
            }
            if (f) {
                System.out.println();
            }
            f = true;
            if (l.isEmpty()) {
                System.out.println("NA");
            } else {
                for (int i : l) {
                    System.out.println(i);
                }
            }
        }
    }
}


Measured memory_bytes: 27680
#include <bits//stdc++.h>
using namespace std;
int main(void){
    int a,b;
    cin >> a >> b;
    string w;
    vector<string> s;
    for(int i=0;i<a;i++){
        cin >> w;
        s.push_back(w);
    }
    sort(s.begin(),s.end());
    for(int i=0;i<a;i++){
        cout << s[i];
    }
    cout <<endl;
}


Measured memory_bytes: 256
from heapq import heappush, heappop
def dijkstra(graph:list, node:int, start:int) -> list:
    inf = float('inf')
    dist = [inf]*node

    dist[start] = 0
    heap = [(0,start)]
    while heap:
        cost,thisNode = heappop(heap)
        for NextCost,NextNode in graph[thisNode]:
            dist_cand = dist[thisNode]+NextCost
            if dist_cand < dist[NextNode]:
                dist[NextNode] = dist_cand
                heappush(heap,(dist[NextNode],NextNode))
    return dist

N,M = map(int,input().split())
graph = [[] for _ in range(N)]
for i in range(N-1):
    graph[i+1].append((0,i))

for i in range(M):
    L,R,C = map(int,input().split())
    graph[L-1].append((C,R-1))
    graph[R-1].append((C,L-1))

d = dijkstra(graph,N,0)
ans = d[-1] if d[-1] != float('inf') else -1
print(ans)

Measured memory_bytes: 84780
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct BIT
{
    vector<ll> bit;
    ll MAX_N;

    BIT(ll n) : bit(n), MAX_N(n)
    {
        for(int i = 0; i < MAX_N; i++)
        {
            bit[i] = 0;
        }
    }

    int sum(int i)
    {
        int s = 0;
        while(i > 0)
        {
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }
    void add(int i, int x)
    {
        while(i <= MAX_N)
        {
            bit[i] += x;
            i += i & -i;
        }
    }
};

int main()
{
    int n;
    cin >> n;
    vector<char> c(2*n);
    vector<int> a(2*n);
    for(int i = 0; i < 2*n; i++)
    {
        cin >> c[i] >> a[i];
    }
    reverse(c.begin(), c.end());
    reverse(a.begin(), a.end());
    BIT bitb(n+1);
    BIT bitw(n+1);

    vector<vector<int>> dp(n+1, vector<int>(n+1));
    vector<vector<int>> costb(n+1, vector<int>(n+1));
    vector<vector<int>> costw(n+1, vector<int>(n+1));
    for(int i = 0; i < 2*n; i++)
    {
        int pos = a[i];
        if(c[i] == 'B')
        {
            bitb.add(a[i], 1);
            for(int j = 0; j <= n; j++)
            {
                costb[pos][j] = bitb.sum(pos-1) + bitw.sum(j);
            }
        }
        else
        {
            bitw.add(a[i], 1);
            for(int j = 0; j <= n; j++)
            {
                costw[j][pos] = bitb.sum(j) + bitw.sum(pos-1);
            }
        }
    }
    for(int i = 0; i <= n; i++)
    {
        for(int j = 0; j <= n; j++)
        {
            dp[i][j] = 1e9;
            if(i == 0 && j == 0) dp[i][j] = 0;
            if(i > 0)
            {
                dp[i][j] = min(dp[i][j], dp[i-1][j] + costb[i][j]);
            }
            if(j > 0)
            {
                dp[i][j] = min(dp[i][j], dp[i][j-1] + costw[i][j]);
            }
        }
    }

    cout << dp[n][n] << endl;
}


Measured memory_bytes: 47488
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<vector>
#include<utility>
#include<algorithm>

using namespace std;

#define LL long long
string s;
int x, a, b;

int main() {
	cin >> a;
	cout << a / 3600 << ":" << (a % 3600) / 60 << ":" << a % 60 << endl;
	return 0;
}


Measured memory_bytes: 3148
# -*- coding: utf-8 -*-
import sys
from functools import lru_cache
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

N=input()
A=tuple(map(int,input().split()))
X=0
for x in A[2:]:
    X^=x
S=A[0]+A[1]
if (S-X)%2:
    print(-1)
    exit()
D=(S-X)//2
ans=0
tmp=0
ttmp=0
f=False
for i in range(50):
    if (D>>i)&1==(X>>i)&1==1:
        print(-1)
        exit()
    elif (D>>i)&1==1 and (X>>i)&1==0: # (1,1)
        if (A[0]>>i)&1==0:
            ans-=1<<i
            f=True
    elif (D>>i)&1==0 and (X>>i)&1==1: # (1,0), (0,1)
        if (A[0]>>i)&1==1 and f:
            tmp=1<<i
            ans+=ttmp
            ttmp=0
            f=False
        elif (A[0]>>i)&1==0:
            ttmp-=1<<i
    else: # (0,0)
        if (A[0]>>i)&1==1:
            ans+=1<<i
            tmp=0
            ans+=ttmp
            ttmp=0
            f=False
if f:
    print(-1)
else:
    if ans+tmp>=A[0]:
        print(-1)
    else:
        print(ans+tmp)

Measured memory_bytes: 67524
a,b = map(int,raw_input().split())
cnt = 0
if a == b:
    print cnt
else:
    if abs(a) == abs(b):
        print 1
    if abs(a) < abs(b):
        if a > 0 and b < 0:
            print abs(b) - abs(a) + 1
        else:
            if a < 0:
                cnt += 1
                a *= (-1)
            if b < 0:
                cnt += 1
                b *= (-1)
            print cnt + abs(b-a)
    if abs(b) < abs(a):
        if a < b:
            if b > 0:
                print abs(a) - abs(b) + 1
            else:
                print abs(b-a)
        else:
            if a > b and b > 0:
                print (a-b) + 2
            else:
                cnt += 1
                a *= (-1)
                print cnt + abs(b-a)


Measured memory_bytes: 2692
#include<stdio.h>
int hws(int x)
{
    int num=0;
    while(x)
    {
        num*=10;
        num+=x%10;
        x=x/10;
    }
    return num;
}
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    int sum=0;
    for(int i=a;i<=b;i++)
    {
        if(i==hws(i))
            sum++;
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <complex>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

typedef complex<double> Point;

enum {
  INSIDE,
  OUTSIDE,
  INTERSECT,
  OTHER
};

int n;
Point target[2];
int kind[1100];
int value[1100];
Point point[1100];
double radius[1100];
int edge[1001][1001];

inline double square(double x) { return x * x; }

int dfs(int index) {
  if (value[index] != -1) { return value[index]; }
  int ret = 1;
  REP(i, n) {
    if (edge[index][i] != INSIDE) { continue; }
    ret = max(ret, dfs(i) + 1);
  }
  return value[index] = ret;
}

int main() {
  while (scanf("%d", &n), n) {
    MEMSET(value, -1);
    MEMSET(edge, -1);
    REP(i, 2) {
      double x, y;
      scanf("%lf %lf", &x, &y);
      target[i] = Point(x, y);
    }
    int m = 0;
    REP(i, n) {
      double x, y, r;
      scanf("%lf %lf %lf", &x, &y, &r);
      Point p = Point(x, y);
      double r2 = r * r;
      Point vect = target[0] - p;
      double t12 = vect.real() * vect.real() + vect.imag() * vect.imag();
      vect = target[1] - p;
      double t22 = vect.real() * vect.real() + vect.imag() * vect.imag();
      if (t12 == r2 || t22 == r2) { continue; }
      if ((t12 >= r2 && t22 >= r2) ||
          (t12 <= r2 && t22 <= r2)) { continue; }
      kind[m] = abs(target[0] - p) < r ? 0 : 1;
      point[m] = p;
      radius[m] = r;
      m++;
    }
    n = m;
    REP(i, n) {
      REP(j, n) {
        if (i == j) {
          edge[i][j] = INTERSECT;
          continue;
        }
        Point vect = point[i] - point[j];
        double d2 = vect.real() * vect.real() + vect.imag() * vect.imag();
        if (radius[i] > radius[j] && square(radius[i]  - radius[j]) > d2) { edge[i][j] = INSIDE; }
        else if (radius[j] > radius[i] && square(radius[j] - radius[i]) > d2) { edge[i][j] = OUTSIDE; }
        else if (square(radius[i] + radius[j]) >= d2 || ((square(radius[i]) >= d2 || square(radius[j]) >= d2) && square(radius[i] - radius[j]) <= d2)) { edge[i][j] = INTERSECT; }
        else { edge[i][j] = OTHER; }
      }
    }
    REP(i, m) { dfs(i); }
    int ans = 0;
    REP(i, m) {
      ans = max(ans, value[i]);
      REP(j, m) {
        if (kind[i] == kind[j]) { continue; }
        if (edge[i][j] != OTHER) { continue; }
        ans = max(ans, value[i] + value[j]);
      }
    }
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 4880