akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
using namespace std;

int main(void) {
	int N, K;
	stringstream ss;
	vector<bool> L;

	cin >> N >> K;
	L.resize(10, true);
	for (int i = 0; i < K; ++i) {
		int d;
		cin >> d;
		L[d] = false;
	}

	int ans = -1;
	for (int i = N; i <= N * 10; ++i) {
		ss.str("");
		ss.clear();
		ss << i;
		string s = ss.str();
		bool flag = true;
		for (int j = 0; j < (int)s.length(); ++j) {
			int num = (int)(s[j] - '0');
			if (L[num] == false) {
				flag = false;
				break;
			}
		}
		if (flag) {
			ans = i;
			break;
		}
	}

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
sx = sorted(x)
sy = sorted(y)

if sx[-1] < sy[0] and X < sy[0] and sx[-1] < Y:
    print('No War')
else:
    print('War')

Measured memory_bytes: 9216
#define _USE_MATH_DEFINES
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
  
/*
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
*/
  
using namespace std;
  
class Dice
{
  public:
    int s1[10];
    void roll(char dir)
    {
        int tmp1[10];
  
        memcpy(tmp1, s1, sizeof(int) * 10);
        switch (dir)
        {
        case 'N':
            s1[1] = tmp1[2];
            s1[2] = tmp1[6];
            s1[6] = tmp1[5];
            s1[5] = tmp1[1];
            break;
        case 'E':
            s1[1] = tmp1[4];
            s1[4] = tmp1[6];
            s1[6] = tmp1[3];
            s1[3] = tmp1[1];
            break;
        case 'W':
            s1[1] = tmp1[3];
            s1[3] = tmp1[6];
            s1[6] = tmp1[4];
            s1[4] = tmp1[1];
            break;
        case 'S':
            s1[1] = tmp1[5];
            s1[5] = tmp1[6];
            s1[6] = tmp1[2];
            s1[2] = tmp1[1];
            break;
        case 'R':
            s1[2] = tmp1[3];
            s1[3] = tmp1[5];
            s1[5] = tmp1[4];
            s1[4] = tmp1[2];
            break;
        }
  
        /*
        cout << "#    " << s1[1] << "    " << endl
             << "#  " << s1[4] << " " << s1[2] << " " << s1[3] << " " << s1[5] << endl
             << "#    " << s1[6] << "    " << endl
             << endl;
        */
        return;
    }
    void roll(int x)
    {
        switch (x)
        {
        case 1:
            break;
        case 2:
            roll('N');
            break;
        case 3:
            roll('W');
            break;
        case 4:
            roll('E');
            break;
        case 5:
            roll('S');
            break;
        case 6:
            roll('N');
            roll('N');
            break;
        }
        return;
    }
};
  
bool comp(Dice d1, Dice d2)
{
    for (int i = 1; i <= 6; i++)
        if (d1.s1[i] != d2.s1[i])
            return false;
    return true;
}
  
int main()
{
    bool ans = false;
  
    Dice d1, d2;
    for (int i = 1; i <= 6; i++)
        cin >> d1.s1[i];
    for (int i = 1; i <= 6; i++)
        cin >> d2.s1[i];
  
    Dice tmp1 = d1;
  
    for (int i = 1; i <= 6; i++)
    {
        d1 = tmp1;
        d1.roll(i);
        for (int i = 0; i < 4; i++)
        {
            d1.roll('R');
            if (comp(d1, d2))
                ans = true;
        }
    }
  
    if (ans)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 3096
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;

int main()
{
	int a,b,ans;
	while(~scanf("%d %d",&a,&b))
	{
		ans = a;
		if(b < a) ans--;
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
const ll INF=100000000000000001;
const double PI=3.141592653589;


int main(){
  string s; cin>>s;
  bool ans=0;
  if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3])
  ans=0;
  else
  ans=1;

  cout<<(ans?"Good":"Bad");


  return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split(" "))
S = input()
S_list = ["l" for k in range(N)]
for i in range(N):
    S_list[i] = S[i]

if S_list[K-1] == "A":
    S_list[K-1] = "a"
elif S[K-1] == "B":
    S_list[K-1] = "b"
else:
    S_list[K-1] = "c"

A = ""
for j in range(N):
    A += S_list[j]

print(A)

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

public class Hello
{
    private const int MOD_N = 1000000000 + 7;

    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var ws = new int[n];
        var list = Console.ReadLine().Split(' ');
        for (int i = 0; i < ws.Length; ++i)
            ws[i] = int.Parse(list[i]);

        int total = 0;
        for (int i = 0; i < ws.Length; ++i)
            total += ws[i];

        int s1 = ws[0];
        var diff = Math.Abs(total - s1 * 2);

        for (int i = 2; i < ws.Length; ++i)
        {
            s1 += ws[i - 1];
            var s2 = total - s1;

            var d = Math.Abs(s1 - s2);
            if (d < diff)
                diff = d;

            if (s1 > s2)
                break;
        }

        Console.WriteLine(diff);
    }

    private static int Comb(int m, int n)
    {
        var t = m - n;
        if (n > t)
            n = t;

        long numerator = 1;
        for (int i = 0; i < n; ++i)
        {
            numerator *= m - i;
            numerator %= MOD_N;
        }
        long denominator = 1;
        for (; n != 0; --n)
        {
            denominator *= n;
            denominator %= MOD_N;
        }

        var inv_denominator = ModInv((int)denominator, MOD_N);
        var ret = (int)(numerator * inv_denominator % MOD_N);

        return ret >= 0 ? ret : ret + MOD_N;
    }

    private static int ModInv(int a, int m)
    {
        int b = m, x = 1, y = 0;
        while (b != 0)
        {
            var t = a / b;
            a -= t * b;
            Swap(ref a, ref b);
            x -= t * y;
            Swap(ref x, ref y);
        }
        x %= m;
        return x >= 0 ? x : x + m;
    }

    private static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
}


Measured memory_bytes: 13140
#include<iostream>
using namespace std;
int dp[3001][3001] , n , m , a[3001] , b[3001] , BB[3001][3001];
string s , t;
void init(){
	for(int i=0 ; i<3001 ; ++i)
		for(int j=0 ; j<3001 ; ++j)
			BB[i][j] = 0;

	a[0] = -1 , b[0] = -1;
	for(int i=1 ; i<=n ; ++i)
		a[i] = s[i-1]-'a' , BB[i][0] = 1;
	for(int i=1 ; i<=m ; ++i)
		b[i] = t[i-1]-'a' , BB[0][i] = -1;
}
void output(int x , int y){
	if(x==0 && y==0) return;
	if(BB[x][y] == 0){
		output(x-1 , y-1);
		cout << (char)(a[x]+'a');
	}
	if(BB[x][y] == 1){
		output(x-1 , y);
	}
	if(BB[x][y] == -1){
		output(x ,  y-1);
	}
}
int main(){ios::sync_with_stdio(false),cin.tie(0);
	cin >> s >> t;
	n = s.size() , m = t.size();
	init();

	for(int i=1 ; i<=n ; ++i)
		for(int j=1 ; j<=m ; ++j)
			if(b[j] == a[i])
				dp[i][j] = dp[i-1][j-1]+1 , BB[i][j] = 0;
			else{
				dp[i][j] = max(dp[i-1][j] , dp[i][j-1]);
				if(dp[i-1][j] >= dp[i][j-1]) BB[i][j] = 1;
				else BB[i][j] = -1;
			}
	output(n , m);
}

Measured memory_bytes: 71040
#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;
long long n,ans;
int s;

int main()
{
    long long n,min,l=0;     
    cin>>n;
    min=n;      
    for(int i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)     
        {
            min=n/i;     
    }
}
    while(min!=0)
    {
        min/=10;
        l++;
    }           
    cout<<l<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
#include <set>
#include <map>

#define ll unsigned long long
#define pb push_back
using namespace std;
const int N = 100005;
int a[N][3], d[N][3];
int main () {
	int n;
	cin >> n;
	for (int i=0; i<n; i++) 
		cin >> a[i][0] >> a[i][1] >> a[i][2];

	d[0][0]=a[0][0];
	d[0][1]=a[0][1];
	d[0][2]=a[0][2];
	
	for (int i=1; i<n; i++){
		d[i][0]=max(d[i-1][1],d[i-1][2])+a[i][0];
		d[i][1]=max(d[i-1][0],d[i-1][2])+a[i][1];
		d[i][2]=max(d[i-1][0],d[i-1][1])+a[i][2];
	}
	cout << max(d[n-1][0],max(d[n-1][1],d[n-1][2]));
	return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>
#define N 50
int fibonacci(int);
int F[N];
int main(){
  int n,i;
  
  for(i=0;i<N;i++) F[i]=-1;
  scanf("%d",&n);
  printf("%d\n",fibonacci(n));
  return 0;
}
  
int fibonacci(int n){
  if(n==0 || n==1) return F[n]=1;
  if(F[n]!=-1) return F[n];
  //if(F[n]==n) return F[n];
  return F[n]=fibonacci(n-1)+fibonacci(n-2);
}


  



Measured memory_bytes: 2148
#include <stdio.h>

int gcd(int a,int b)
{
    if(a>b)
        if(a%b==0) return b;
        else return gcd(a%b,b);
    else
        if(b%a==0) return a;
        else return gcd(b%a,a);
}

int n;
int a[100000];

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    int ans=gcd(a[0],a[1]);
    for(int i=2;i<n;i++)
    ans=gcd(ans,a[i]);
    printf("%d\n",ans);
}

Measured memory_bytes: 640
// From Xcode on iMac
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <map>
#include <numeric>
using namespace std;
#define elif else if
#define echo cout <<
#define read cin >>
#define fin << '\n'
#define finn cout << '\n'
#define forin(i, n) for ( int i = 0; i < n; i++ )
#define unless(flg) if(!(flg))
#define zu >>
#define und <<
#define alles(obj) obj.begin(), obj.end()
#define bash push_back
#define makePair make_pair
// type-define
#define String string
#define Stack stack
#define Queue queue
#define pQueue priority_queue
#define Vector vector
#define Pair pair
#define Map map
typedef long long llong;
typedef bool boolean;
typedef Pair<int,int> Pii;
typedef Vector<int> Vi;
// utils
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int INF = 1 << 30;
boolean isMovable(int x,int y,int w,int h){return (x>=0&&y>=0&&x<w&&y<h);};

Vi vi;

signed main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    int n, x;
    read n >> x;
    vi.bash(x);
    for ( int i = 0; i < n; i++ ) {
        int a;
        read a;
        vi.bash(a);
    }
    sort(alles(vi));
    int ans = INF;
    int prev = vi[0];
    for ( int i = 1; i < vi.size(); i++ ) {
        ans = min(ans, vi[i] - prev);
        prev = vi[i];
    }
    
    for ( int i = 1; i < vi.size(); i++ ) {
        vi[i] -= vi[0];
    }
    vi[0] = 0;
    
shizuoka:;
    for ( int i = 1; i < vi.size(); i++ ) {
        if ( vi[i] % ans != 0 ) {
            ans--;
            goto shizuoka;
        }
    }
    
    echo ans fin;
     
    return 0;
}


Measured memory_bytes: 892
import bisect
a, b, q = map(int, input().split())
ss = [int(input()) for _ in range(a)]
ts = [int(input()) for _ in range(b)]
xs = [int(input()) for _ in range(q)]
ss = [-float('inf')] + ss + [float('inf')]
ts = [-float('inf')] + ts + [float('inf')]
for x in xs:
    s_r = bisect.bisect_left(ss, x)
    t_r = bisect.bisect_left(ts, x)
    s_l = s_r - 1
    t_l = t_r - 1
    res = float('inf')
    if ss[s_l] > ts[t_l]:
        res = min(res, x - ts[t_l], (x - ss[s_l])*2 + (ts[t_r] - x))
    elif ss[s_l] < ts[t_l]:
        res = min(res, x - ss[s_l], (x - ts[t_l])*2 + (ss[s_r] - x))
    else:
        res = min(res, (x - ss[s_l])*2 + (ss[s_r] - x), x - ss[s_l]*2 + (ts[t_r] - x))
    if ss[s_r] > ts[t_r]:
        res = min(res, ss[s_r] - x, (ts[t_r] - x)*2 + (x - ss[s_l]))
    elif ss[s_r] < ts[t_r]:
        res = min(res, ts[t_r] - x, (ss[s_r] - x)*2 + (x - ts[t_l]))
    else:
        res = min(res, (ss[s_r] - x)*2 + (x - ss[s_l]), (ss[s_r] - x)*2 + (x - ts[t_l]))
    print(res)

Measured memory_bytes: 22476
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<long long> v(n);
	for(int i=0;i<n;i++)cin>>v[i];	
	/* set<vector<long long > >s; */
	int ans=0;
	sort(v.begin(),v.end());
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			for(int k=j+1;k<n;k++)
			{
				if(v[i]!=v[j]&&v[j]!=v[k])
				if(v[i]+v[j]>v[k])
				{
					ans++;
					/* if(s.find({v[i],v[j],v[k]})==s.end()) */
					/* s.insert({ v[i],v[j],v[k] }); */
				}
				
			}
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=2e5+100,mod=1e9+7;
ll seg[N*4];
void upd(ll nod,ll l,ll r,ll id,ll val){
    if (r-l==1){
        seg[nod]=val;
        return ;
    }
    ll mid=(r+l)/2;
    if (mid>id) upd(nod*2,l,mid,id,val);
    else upd(nod*2+1,mid,r,id,val);
    seg[nod]=min(seg[nod*2],seg[nod*2+1]);
}
ll get(ll nod,ll l,ll r,ll L,ll R){
    if (l>=R || L>=r) return 1e9;
    if (l>=L && r<=R) return seg[nod];
    ll mid=(r+l)/2;
    return min(get(nod*2,l,mid,L,R),get(nod*2+1,mid,r,L,R));
}
ll dp[N];
ll par[N];
ll pn[N],px[N];
ll a[N];
map <int,int> mp;
int32_t main(){
    sync;
    ll n;
    cin >> n;
    for (int i=1;i<=n;i++) upd(1,1,n+1,i,1e9);
    vector <pii> aa;
    vector <int> tt;
    for (int i=1;i<=n;i++){
        ll x,y;
        cin >> x >> y;
        aa.pb({x,y});
        tt.pb(y);
    }
    sort(tt.begin(),tt.end());
    for (int i=0;i<tt.size();i++){
        mp[tt[i]]=i+1;
    }
    sort(aa.begin(),aa.end());
    for (int i=1;i<=n;i++){
        a[i]=mp[aa[i-1].S];
        //upd(1,1,n+1,i,a[i]);
    }
    dp[n]=1;
    for (int i=1;i<=n;i++) px[i]=max(a[i],px[i-1]);
    pn[n]=a[n];
    for (int i=n-1;i;i--) pn[i]=min(a[i],pn[i+1]);
    par[n+1]=1;
    par[n]=2;
    pn[n+1]=1e9;
    ll l=n;
    upd(1,1,n+1,a[n],n);
    for (int i=n-1;i;i--){
        while(l>i){
            if (get(1,1,n+1,px[i],pn[l+1])<=l){
                upd(1,1,n+1,a[l],1e9);
                l--;
            }
            else break;
        }
        dp[i]=par[i+1]-par[l+2];
        dp[i]+=mod;
        dp[i]%=mod;
        par[i]=par[i+1]+dp[i];
        par[i]%=mod;
        upd(1,1,n+1,a[i],i);
      //  cout << i << " " << dp[i] << " " << r << endl;
    }
    ll r=n+1;
    l=1;
    while(r-l>1){
        ll mid=(r+l)/2;
        if (pn[1]!=pn[mid]) r=mid;
        else l=mid;
    }
    cout << (par[1]-par[r]+mod)%mod;
}



Measured memory_bytes: 32424
#include<iostream>
using namespace std;
int main()
{
    int i,n,cou=0;
    cin>>n;
    char c[n*2];
    for(i=0;i<n;i++)
    {
        cin>>c[i];
        if(c[i]=='Y')
        {
            cou++;
        }
    }
    if(cou>0)
    {
        cout<<"Four"<<endl;
    }
    else
        cout<<"Three"<<endl;

}


Measured memory_bytes: 256
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n=gi
s=gs
puts s.scan(/ABC/).size

Measured memory_bytes: 1788
#include<iostream>
#include<stdio.h>
using namespace std;

int main() {
    int n, q, com, tmp, r_min, r_max, add;
    scanf("%d %d", &n, &q);
    int a[n];
    for(int i=0; i<=n; i++) {
        a[i] = 0;
    }
    for (int i=0; i<q; i++) {
        scanf("%d", &com);
        if (com == 0) {
            scanf("%d %d", &tmp, &add);
            a[tmp] += add;
        } else {
            scanf("%d %d", &r_min, &r_max);
            tmp = 0;
            for (int j=r_min; j<=r_max; j++) {
                tmp += a[j];
            }
            printf("%d\n", tmp);
        }
    }
}


Measured memory_bytes: 3596
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 62); // 1152921504606846976
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
int nmax=200000; // 2*(10^5)
vvec g(nmax);



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n,kk;
    cin>>n>>kk;
    vec x(n);
    vec y(n);
    pvec z(n);
    rep(i,n){
        cin>>x[i]>>y[i];
        z[i]=P(x[i],y[i]);
    }
    sort(all(x));
    sort(all(y));
    ll ans=INF;
    rep(i,n-1){
        for(int j=i+1;j<n;j++){
            rep(k,n-1){
                for(int l=k+1;l<n;l++){
                    int memo=(abs(x[i]-x[j])*abs(y[k]-y[l]));
                    int cnt=0;
                    rep(c,n){
                        if(x[i]<=z[c].fs&&z[c].fs<=x[j]&&y[k]<=z[c].sc&&z[c].sc<=y[l]){
                            cnt++;
                        }
                    }
                    if(cnt>=kk){
                        if(chmin(ans,memo)){
                        }
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
ll INF = pow(10,15);

vector<ll> a;
vector<vector<ll>> dp(3010, vector<ll>(3010, INF));
ll solve1(int i, int j);
ll solve2(int i, int j);

ll solve1(int i, int j){
	if(dp[i][j] != INF){
		return dp[i][j];
	}
	if(j - i == 0){
		dp[i][j] = a[i];
	}else if(j - i == 1){
		if(a[i] > a[j]) dp[i][j] = a[i] - a[j];
		else dp[i][j] = a[j] - a[i]; 
	}else{
		ll c1 = a[i] + solve2(i+1,j);
		ll c2 = a[j] + solve2(i,j-1);
		if(c1 > c2) dp[i][j] = c1;
		else dp[i][j] = c2;
	}
	return dp[i][j];
}

ll solve2(int i, int j){
	if(dp[i][j] != INF){
		return dp[i][j];
	}
	if(j - i == 0){
		dp[i][j] = a[i];
	}else if(j - i == 1){
		if(a[i] < a[j]) dp[i][j] = a[i] - a[j];
		else dp[i][j] = a[j] - a[i]; 
	}else{
		ll c1 = solve1(i+1,j) - a[i];
		ll c2 = solve1(i,j-1) - a[j];
		if(c1 < c2) dp[i][j] = c1;
		else dp[i][j] = c2;
	}
	return dp[i][j];
}

int main(){
	int n;
	cin >> n;
	a.resize(n);
	rep(i,n) cin >> a[i];
	cout << solve1(0,n-1) << endl;
	return 0;
}

Measured memory_bytes: 71296
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#include <stack>
#include <cctype>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)

#define AAA (1000000007) 


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;


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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll powD(ll a, ll b) {
	ll ans = 1;
	a %= AAA;
	for (int i = 0; i < b; i++)
	{
		ans *= a;
		ans %= AAA;
	}
	return ans;
}


int main() {
	//int i, j, k;
	//int N, M, K;
	ll i, j;
	ll N, M;
	cin >> N;
	ll d[1000010] = { 0 };
	M = N;
	i = 2;
	if (N == 1) {
		cout << 0;
		return 0;
	}
	ll MAX = sqrt(N)+1;
	while (N > 1 && i < MAX) {
		if (N % i == 0) {
			d[i]++;
			N /= i;
		}
		else {
			i++;
		}

	}
	ll ans = 0;

	if (N == M) {
		cout << 1;
		return 0;
	}
	else {
		if (N != 1) {
			if (N > 1000000)
				ans++;
			else
				d[N]++;
		}

	}
	rep(i, 2, 1000000) {
		for (j = 1;; j++) {
			if (d[i] < j) {
				break;
			}
			d[i] -= j;
			ans++;
		}
	}
	cout << ans;
	return 0;
}

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

using namespace std;

int fourThrowFiveUp(double n) {
    // fprintf(stderr, "debug print : n = %lf\n", n);	// 4debug
    if((int)(n * 10) >= 5) return (int)(n + 1);
    else return (int)n;
}

bool median(vector<int> *A, int length, int *ans) {
    sort((*A).begin(), (*A).end());
    if(length % 2 == 0) {
        *ans = ((*A)[length / 2] + (*A)[length / 2 - 1]) / 2.0;
        return false;
    }
    else {
        *ans = (*A)[length / 2];
        return true;
    }
}

int main() {
    int N, cnd, med;
    long long int ans1 = 0, ans2 = 0, ans3 = 0, tmp1 = 0, tmp2 = 0;
    double ave = 0.0;

    cin>>N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) {
        cin>>A[i];
        A[i] -= i + 1;
        ave += A[i];
        // fprintf(stderr, "debug print : ave = %lf\n", ave);	// 4debug
    }
    ave /= N;
    
    cnd = fourThrowFiveUp(ave);
    // fprintf(stderr, "debug print : cnd = %d\n", cnd);	// 4debug
    
    for(int i = 0; i < N; i++) {
        ans1 += abs(A[i] - cnd);
        ans2 += abs(A[i] - cnd + 1);
        ans3 += abs(A[i] - cnd - 1);
    }

    if(!median(&A, N, &med)) {
        for(int i = 0; i < N; i++) {
            tmp1 += abs(A[i] - med);
            tmp2 += abs(A[i] - med - 1);
        }
        if(tmp1 > tmp2) {
            tmp1 = tmp2;
        }
    }
    else {
        for(int i = 0; i < N; i++) {
            tmp1 += abs(A[i] - med);
        }
    }

    printf("%lld\n", min(min(tmp1, ans1), min(ans2, ans3)));

    return 0;
}

Measured memory_bytes: 1024
import sys
import itertools
n = input()
x = int(n)
l = len(n)
if x < 357:
    print(0)
    sys.exit()
ans = 0
if l==3:
    if x>=753:
        print(6)
        sys.exit()
    elif 753>x>=735:
        print(5)
        sys.exit()
    elif 735>x>=573:
        print(4)
        sys.exit()
    elif 573>x>=537:
        print(3)
        sys.exit()
    elif 537>x>=375:
        print(2)
        sys.exit()
    elif 375>x>=357:
        print(1)
        sys.exit()
    else:
        print(0)
        sys.exit()

for i in range(3,l):
    ans += 3**i - 3*2**i + 3

if int(n[0]) > 7:
    ans += 3**l - 3*2**l + 3
    print(ans)
    sys.exit()

def check(arg):
    l = len(arg)
    c = 0
    for i,d in enumerate(arg):
        c+= d*10**(l-i-1)
    return c

def check2(x):
    if 3 in x and 5 in x and 7 in x:
        return True
    else:
        return False

for d in itertools.product([3,5,7], repeat=l):
    if check(d) <= x and check2(d):
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()

#define endl "\n"
#define pb push_back
#define elif else if
#define cout_db cout << fixed

#define MOD 1000000007
#define PI 3.1415926
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};

typedef long long ll;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

vector< vector<ll> > mod;

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

	ll h, w, d, a[300][300], q, l[100000], r[100000];
	map<ll, pair<ll, ll> > mp;
	cin >> h >> w >> d;
	for (ll i = 0; i < h; i++) {
		for (ll j = 0; j < w; j++) {
			cin >> a[i][j];
			mp[a[i][j]] = make_pair(i, j);
		}
	}
	cin >> q;
	for (ll i = 0; i < q; i++) {
		cin >> l[i] >> r[i];
	}

	mod.resize(d);
	for (ll i = 0; i < d; i++) {
		mod[i].resize((h*w)/d + 2);
	}

	for (ll i = 1; i <= d; i++) {
		ll pos = i+d, cnt = 0, tmp = 1;
		mod[i%d][0] = 0;
		while(pos <= h*w){
			pair<ll, ll> pa = mp[pos-d];
			pair<ll, ll> pb = mp[pos];

			cnt += abs(pa.first - pb.first)+abs(pa.second - pb.second);
			if(i == d) mod[i%d][tmp+1] = cnt;
			else mod[i%d][tmp] = cnt;

			pos += d;
			tmp++;
		}
	}

	for (ll i = 0; i < q; i++) {
		cout << mod[r[i]%d][r[i]/d] - mod[l[i]%d][l[i]/d] << endl;
	}

	return 0;
}

Measured memory_bytes: 13312
main = do
  getLine
  as <- map read . words <$> getLine
  bs <- map read . words <$> getLine
  let x = sum $ filter (0 <) $ zipWith (-) as bs
      y = sum $ map (`div` 2) $ filter (0 <) $ zipWith (-) bs as
  putStrLn $ if x <= y then "Yes" else "No"

Measured memory_bytes: 9852
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

//HEADER FILES AND NAMESPACES
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>  
#include <ext/pb_ds/tree_policy.hpp>   
using namespace std;
using namespace __gnu_pbds;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; 
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);  

#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r+", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w+", stdout);
#endif  
	
    ll dp[2001];
    for(int i=1;i<=2000;i++) {
    	dp[i] = 0;
    }
    dp[0] = 1;
    for(int i=3;i<=2000;i++) {
    	for(int j=0;j<=i-3;j++) {
    		dp[i] = (dp[i] + dp[j]) % MOD;
    	}
    }
    int S;
    cin >> S;
    cout << dp[S] << '\n';

}
 
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3536
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
using namespace std;
ll A,B,ans=1;
int main()
{
    cin>>A>>B;
    A=__gcd(A,B);
    ll n=(ll)sqrt(A+.5);
    for(ll i=2;i<=n;i++)
        if(A%i==0)
        {
            ans++;
            while(A%i==0) A/=i;
        }
    if(A>1) ans++;
    cout<<ans;
    return 0;
}



Measured memory_bytes: 256
a = list(map(int, input().split()))
count = 0
while a[0] != a[1] or a[1] != a[2]:
    a.sort()
    if a[1] != a[2]:
        a[0] += 1
        a[1] += 1
    else:
        a[0] += 2
    count += 1
print(count)
        

Measured memory_bytes: 9052
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,ans,now,cnt,b[N],vi[N];
map<__int128,__int128>ma,pos;
__int128 a[N<<1];
int main(){
	scanf("%d",&n);
	for(int i=2;i<N;i++){
		if(!vi[i])	b[++now]=i;
		for(int j=1;j<=now&&b[j]*i<N;j++){
			vi[i*b[j]]=1;
			if(i%b[j]==0)	break;
		}
	}
	for(int i=1;i<=n;i++){
		__int128 x,val=1,res=1;
		long long h;
 
		scanf("%lld",&h),x=h;
		int k=pow(x+0.5,1.0/3);
		for(int i=1;i<=now;i++)
			if(b[i]>k)	break;
			else{
				int d=0;
				while(x%b[i]==0)
					x/=b[i],++d;
				d%=3;
				if(!d)	continue;
				if(d==1)	val*=b[i],res*=b[i]*b[i];
				else	val*=b[i]*b[i],res*=b[i];
			}
		k=sqrt(x),val*=x;
		if(1LL*k*k==x)	res*=k;
		else	res*=x*x;
		pos[val]=res,pos[res]=val,++ma[val],a[++cnt]=res,a[++cnt]=val;
	}
	sort(a+1,a+cnt+1);
	n=unique(a+1,a+cnt+1)-a-1;
	for(int i=1;i<=n;i++){
		if(pos[a[i]]>a[i])	ans+=max(ma[a[i]],ma[pos[a[i]]]);
		else	if(pos[a[i]]==a[i])	++ans;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 36608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;
const int mod1=998244353;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> u(n-1),v(n-1),w(n-1);
	rep(i,n-1) cin >> u.at(i) >> v.at(i) >> w.at(i);
	vector<vector<pii>> g(n,vector<pii>());
	rep(i,n-1){
		g.at(u.at(i)-1).pb(mp(v.at(i)-1,w.at(i)));
		g.at(v.at(i)-1).pb(mp(u.at(i)-1,w.at(i)));
	}
	vector<int> ans(n);
	vector<bool> b(n,true);
	queue<pair<int,ll>> q;
	q.push(mp(0,0));
	while(!q.empty()){
		pair<int,ll> cur=q.front();q.pop();
		if(cur.second%2==1) ans.at(cur.first)=1;
		b.at(cur.first)=false;
		rep(i,g.at(cur.first).size()){
			if(b.at(g.at(cur.first).at(i).first))q.push(mp(g.at(cur.first).at(i).first,cur.second+g.at(cur.first).at(i).second));
		}
	}
	rep(i,n) cout << ans.at(i) << endl;
}


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

typedef long long LL;

const int N = 3010, mod = 1e9 + 7, i2 = (mod + 1) / 2;

int a[N], dp[N][N];

int main() {
    int n, q, tot = 1; scanf("%d%d", &n, &q);
    for (int i = 1; i <= q; i++) tot <<= 1, tot %= mod;
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            dp[i][j] = a[i] > a[j];
    for (int i = 1; i <= q; i++) {
        int l, r; scanf("%d%d", &l, &r);
        dp[l][r] = dp[r][l] = (LL)(dp[l][r] + dp[r][l]) * i2 % mod;
        for (int j = 1; j <= n; j++) if (j != r && j != l) {
            dp[j][r] = dp[j][l] = (LL)(dp[j][r] + dp[j][l]) * i2 % mod;
            dp[l][j] = dp[r][j] = (LL)(dp[l][j] + dp[r][j]) * i2 % mod;
        }
    }
    int res = 0;
    for (int i = 1; i <= n; i++)
        for (int j = i + 1; j <= n; j++)
            res = (res + dp[i][j]) % mod;
    printf("%d\n", (LL)res * tot % mod);
}

Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch TOrT | diff TOrT.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address TOrT.cpp && ./a.out

/*
 
 7/7/2019
 
 5:00-
 
 */

int N,A,B;

void solve() {
  cout<<min(N*A,B)<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>A>>B;
  solve();
  
  return 0;
}


Measured memory_bytes: 256
#|
------------------------------------
|               Body               |
------------------------------------
|#

(defparameter *inf* 10000000)

(defun count-proc (s x)
  (let ((w-cnt (count #\W s
                      :start 0
                      :end x))
        (r-cnt (count #\R s
                      :start x)))
    (max w-cnt
         r-cnt)))

(defun solve (n s)
  (loop for i below n
     with w-cnt = 0
     with r-cnt = (count #\R s)
     with res = r-cnt
     do
       (if (char-equal (char s i) #\W)
           (incf w-cnt)
           (decf r-cnt))
       (setf res (min res (max w-cnt r-cnt)))
     finally
       (return res)))
       

(defun main ()
  (let ((n (read))
        (s (read-line)))
    (princ (solve n s))
    (fresh-line)))

#-swank (main)


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

int main(){
    int W, H, N;
    cin >> W >> H >> N;
    int x[110], y[110], a[110];
    for(int i = 0; i < N; ++i) cin >> x[i] >> y[i] >> a[i];
    int high_x = W;
    int low_x = 0;
    int high_y = H;
    int low_y = 0;
    for(int i = 0; i < N; ++i){
        if(a[i] == 1 && x[i] > low_x) low_x = x[i];
        if(a[i] == 2 && x[i] < high_x) high_x = x[i];
        if(a[i] == 3 && y[i] > low_y) low_y = y[i];
        if(a[i] == 4 && y[i] < high_y) high_y = y[i];
    }
    int dif_x = high_x - low_x;
    int dif_y = high_y - low_y;
    if(dif_x > 0 && dif_y > 0) cout << dif_x * dif_y << endl;
    else cout << "0" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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; }

typedef long long ll;

using namespace std;
int mod=1e9+7,mi=(mod+1)/3;
unordered_map<ll,ll>ma;
ll cal(ll size,ll line,ll th)
{
  if(line==0)return 1;
  if(line==1)return 2;
  if(ma.count(line))return ma[line];
  if(line<size/2)return cal(size>>1,line,th*mi%mod);
  ll t=(th*mi)%mod;
  if(line-size/2-size/4>=0) return ma[line]=(2*cal(size>>1,line-size/2,t)-cal(size>>2,line-size/2-size/4,(t*mi)%mod)+th*2+mod)%mod;
  return ma[line]=(cal(size>>1,line-size/4,t)+cal(size>>2,line-size/2,(t*mi)%mod)+th)%mod;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,cn=1,m=1;
  cin>>n;
  while(n>=cn){cn<<=1;m=(m*3)%mod;}
  m=m*mi%mod*mi%mod;
  cout<<cal(cn,n,m)<<endl;


  return 0;

}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def warshall_floyd(d):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d


N, M, L = map(int, input().split())
INF = 10 ** 10
d = [[INF for _ in range(N)] for _ in range(N)]
D = [[INF for _ in range(N)] for _ in range(N)]

for i in range(N):
    d[i][i] = 0
for i in range(M):
    A, B, C = map(int, input().split())
    A -= 1
    B -= 1
    d[A][B] = C
    d[B][A] = C
d = warshall_floyd(d)

for i in range(N):
    for j in range(N):
        if 0 < d[i][j] <= L:
            D[i][j] = 1
        elif d[i][j] == 0:
            D[i][j] = 0
D = warshall_floyd(D)

Q = int(input())
for _ in range(Q):
    s, t = map(int, input().split())
    s -= 1
    t -= 1
    print(D[s][t] - 1 if D[s][t] != INF else -1)


Measured memory_bytes: 56668
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.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 EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
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>;
// functions

#endif


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

    int H, W; cin >> H >> W;
    int N; cin >> N;
    vi A(N); REP(i, N) cin >> A[i];

    vvi C(H, vi(W, 0));

    int cnt = 0;
    int k = 0;
    REP(i,H) {
        if (i%2==0) {        
            for (int j = 0; j < W; j++) {
                C[i][j] = k+1;
                cnt++;
                if (cnt>=A[k]) {
                    cnt = 0;
                    k++;
                }
            }
        } else {
            for (int j = W-1; j >= 0; j--) {
                C[i][j] = k+1;
                cnt++;
                if (cnt>=A[k]) {
                    cnt = 0;
                    k++;
                }
            }
        }
    }

    REP(i,H){
        REP(j,W) {
            if (j==0) cout << C[i][j];
            else cout << " " << C[i][j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main(){
    FIN;
    ll n; cin >> n;
    map<ll,ll> a;
    for(int i=0;i<n;i++){
        int l; cin >> l;
        a[l]++;
    }
    
    ll first=0,second=0;
    map<ll,ll>::iterator it;
    for(it=a.begin();it!=a.end();it++){
        if(it->second >= 2){
            second = first;
            first = it->first;
        }
        if(it->second >= 4)
            second = first;
    }

    cout << first * second << endl;
    return 0;
}



Measured memory_bytes: 9748
#include<cstdio>

using namespace std;

int main(){
	int x,y;
	scanf("%d%d",&x,&y);
	if(x%y==0){
		printf("-1\n");
		return 0;
	}
	int o=x;
	for(int i=2;i*i<=o;i++)
		if(o%i==0){
			if(1ll*x*i%y){
				printf("%lld\n",1ll*x*i);
				return 0;
			}
			while(o%i==0)o/=i;
		}
	if(1ll*x*o%y){
		printf("%lld\n",1ll*x*o);
		return 0;
	}
	printf("%lld\n",y+1ll);
}


Measured memory_bytes: 128
#include <stdio.h>

#define A 55555

int main() {
	static char composite[A + 1];
	static int aa[A];
	int a, b, k, n, i;

	k = 0;
	for (a = 2; a <= A; a++) {
		if (composite[a])
			continue;
		if (a % 10 == 1)
			aa[k++] = a;
		for (b = a + a; b <= A; b += a)
			composite[b] = 1;
	}
	scanf("%d", &n);
	for (i = 0; i < n; i++)
		printf("%d ", aa[i]);
	printf("\n");
	return 0;
}


Measured memory_bytes: 256
import Data.List

chk _ [] = []
chk n (x:xs) = 
  (min x n):( chk (n-1) xs )

ans x =
  let s = sort x
      l = length x
  in
    maximum $ chk l s

main = do
  _ <- getLine
  l <- getLine
  let i = map read $ words l :: [Int]
      o = ans i
  print o
  

Measured memory_bytes: 4120
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;

int main(void) {
	string s;
	int size,a;
	a = 0;
	cin >> s;
	size = s.length();
	for (int i = 1; i < size; i++) {
		if (s[i - 1] == 'A'&&s[i] == 'C')a = 1;
	}
	if(a==1)cout << "Yes" << endl;
		else cout << "No" << endl;
}


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

#define int long long
using namespace std;

int j[100];
double b[100];
int N;

signed main()
{
	cin >> N; 
	for(int i=0;i<N;i++){
		double a;
		cin >> a;
		string s;
		cin >> s;
		if (s == "JPY") {
			j[i] = a;
		}
		else {
			b[i] = a;
		}
	}
	double ans = 0;
	double SUM = 0;
	for (int i = 0; i < N; i++) {
		SUM += b[i];
		ans += j[i];
	}
	SUM *= 380000.0;

	ans += SUM;
	cout << ans << endl;


//	system("pause");

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
  
int main(){
    int cost[22][22]={0};
    int n,m,i,j,k,a,b,c,d;
    char cc;
    cin>>n>>m;
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            cost[i][j] = 1001001;
        }
    }
    for(i=0;i<m;i++){
        cin>>a>>cc>>b>>cc>>c>>cc>>d;
        cost[a][b]=c;cost[b][a]=d;
    }
    for(k=1;k<=n;k++){
        for(i=1;i<=n;i++){
            for(j=1;j<=n;j++){
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
                cin>>a>>cc>>b>>cc>>c>>cc>>d;
            }
        }
    }
    cout << c-d-cost[a][b]-cost[b][a] << endl;
}

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

using namespace std;

int main(){
  int K, T;
  cin >> K >> T;
  int a[T], s = 0;
  for (int i = 0; i < T; i++){
    cin >> a[i];
    s += a[i];
  }

  sort(a, a+T);

  s -= a[T-1];

  if(s < a[T-1]){
    printf("%d\n", a[T-1] - s - 1);
  }else{
    printf("0\n");
  }
}


Measured memory_bytes: 3720
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
 
using namespace std;


	
int main()
{ 
	int n;
	int m;
	cin>>n>>m;
	int cnt=0;
	for(int i=0;i<m;i++){
		int a;
		cin>>a;
		cnt+=a;
	}
	if(cnt>n)cout<<"-1"<<endl;
	else cout<<n-cnt<<endl;
	return 0;
}
	
	



Measured memory_bytes: 3632
import java.util.Scanner;
import java.util.Arrays;

public class Main{
  
  public void _main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();

    int[][] ab = new int[M][2];
    for (int i = 0; i < M; i++){
      ab[i] = new int[]{sc.nextInt(), sc.nextInt()};
    }

    Arrays.sort(ab, (x, y) -> Integer.compare(y[0], x[0]));

    int ans = 0;
    int prev = Integer.MAX_VALUE;
    for (int i = 0; i < M; i++){
      if (!(prev < ab[i][1])){
        prev = ab[i][0];
        ans++;
      }
    }
     System.out.println(ans);
     sc.close();
  }

  public static void main(String[] args){
    new Main()._main(args);
  }

}


Measured memory_bytes: 95264
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M;
    cin >> N >> M;
    vector<ll> A(N);
    vector<pair<ll,ll>> B(M);
    REP(i,N)cin >> A.at(i);
    REP(i,M){
        int x,y;
        cin >> x;
        cin >> y;
        B.at(i) = make_pair(y,x);
    }
    sort(B.rbegin(),B.rend());
    sort(A.begin(),A.end());
    int x = 0;
    bool ok =0;
    REP(i,M){
        REP(l,B.at(i).second){
            if(A.at(x)<B.at(i).first){
                A.at(x) = B.at(i).first;
                x++;
                if(x >= N)ok = 1;
            }else{
                ok = 1;
            }
            if(ok == 1)break;
        }
        if(ok == 1)break;
    }
    ll answer = 0;
    REP(i,N)answer+=A.at(i);
    cout <<answer<< "\n";
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	std::string s; cin >> s;
	int n = s.size(), p = 2019;
	
	reverse(begin(s), end(s));
	std::vector<int> tan(n + 1, 1);
	for(int i = 1; i < n + 1; i++) tan[i] = tan[i - 1] * 10 % p;
	
	std::vector<int> vec(1, 0);
	for(int i = 0; i < n; i++) {
		int d = s[i] - '0';

		vec.push_back((vec.back() + d * tan[i]) % p);
	}

	i64 ans = 0;
	std::map<int, i64> mp;
	for(int i = n; i >= 0; i--) {
		ans += mp[vec[i]];
		mp[vec[i]]++;
	}
	printf("%lld\n", ans);
	return 0;
}


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

int main(){
  int n;
  int ans=0;
  cin>> n;
  for(int i=1; i<=n; i++){
    if(i/10==1){
      i=100;
    }if(i/1000==1){
      i=10000;
    }if(i/100000==1){
    break; 
    }if(i<=n){
    ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
s = 'a'
ans = []
alpha = [chr(ord('a') + j) for j in range(10)]
#print(alpha)
def dfs(S):
  if len(S)==N:
    ans.append(S)
    #print(S)
    return None
  lis = alpha[:max([alpha.index(s) for s in S])+2]
  #print(lis)
  for t in lis:
    T = S+t
    dfs(T)
    
dfs('a')
print(*ans, sep='\n')

Measured memory_bytes: 14464