akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cassert>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <map>

// 0 : space 1 : twall 2 : start 3 : goal 4 : wall
int board[32][32];
int W, H;

void init() {
  for(int i = 0; i < (int)32; ++i) {
    for(int j = 0; j < (int)32; ++j) {
      board[i][j] = 4;
    }
  }
}

void Load() {
  scanf("%d %d", &W, &H);
  for(int i = 0; i < (int)H; ++i) {
    for(int j = 0; j < (int)W; ++j) {
      scanf("%d", &board[i+1][j+1]);
    }
  }
}

int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};

class Solve_ {
  std::pair<int, int> start, end;
  int dist[32][32][4];
  int limit;
  bool ok;
public:
  int operator() () {
    init();
    ok = false;
    int res = (1 << 29);
    for(limit = 1; limit < 11; ++limit) {
      dfs(start, 0);
      if( ok ) {
        res = limit;
        break;
      }
    }
    if( res >= 11 ) res = -1;
    return res;
  }
  void dfs(std::pair<int, int> p, int d) {
    if( d >= limit ) return;
    int r = p.first, c = p.second;
    if( board[r][c] == 3 ) return;
    for(int k = 0; k < 4; ++k) {
      int nr = r + dr[k], nc = c + dc[k];
      if( board[nr][nc] == 1 or board[nr][nc] == 4 ) continue;
      if( nr == end.first and nc == end.second ) {
        ok = true;
        return;
      }
      for(;;) {
        int nnr = nr + dr[k], nnc = nc + dc[k];
        if( board[nnr][nnc] == 1 or board[nnr][nnc] == 4 ) break;
        nr = nnr;
        nc = nnc;
        if( nr == end.first and nc == end.second ) {
          ok = true;
          return;
        }
      }
      if( board[nr+dr[k]][nc+dc[k]] == 4 ) continue;
      //if( dist[nr][nc][k] <= d + 1 ) continue;
      dist[nr][nc][k] = d + 1;
      bool b = false;
      if( board[nr+dr[k]][nc+dc[k]] == 1 ) {
        b = true;
      }
      if( b ) {
        board[nr+dr[k]][nc+dc[k]] = 0;
      }
      dfs(std::pair<int, int>(nr, nc), d + 1);
      if( b ) {
        board[nr+dr[k]][nc+dc[k]] = 1;
      }
      if( ok ) break;
    }
  }
  void init() {
    for(int i = 1; i <= H; ++i) {
      for(int j = 1; j <= W; ++j) {
        if( board[i][j] == 2 ) {
          start = std::pair<int, int>(i, j);
        }
        if( board[i][j] == 3 ) {
          end = std::pair<int, int>(i, j);
        }
      }
    }
    for(int i = 0; i < 32; ++i) {
      for(int j = 0; j < 32; ++j) {
        for(int k = 0; k < 4; ++k) {
          dist[i][j][k] = (1 << 29);          
        }
      }
    }
  }
};
Solve_ Solve;

int main() {
  for(;;) {
    init();
    Load();
    if( W == 0 and H == 0 ) break;
    int res = Solve();
    printf("%d\n", res);
  }
  
  return 0;
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    set<string> v;
    string s;
    cin>>s;
    v.insert(s);
    string pre=s.substr(s.size()-1,1);
    for(int i=1;i<n;i++){
        cin>>s;
        v.insert(s);
        if(v.size()==i||(s[0]!=pre[0])){
            printf("No\n");
            return 0;
        }
        pre=s[s.size()-1];
    }
    printf("Yes\n");
    return 0;
}


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

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

	stack<int> st1;
	stack<pair<int, int>> st2;
	string input;
	cin >> input;
	int sum = 0;
	for (int i=0; i<input.size();i++) {
		if (input[i] == '\\') {
			st1.push(i);
		} else if (st1.size() > 0 && input[i] == '/') {
			int j = st1.top(); st1.pop();
			sum += i-j;
			int a = i-j;	
			while (st2.size() > 0 && st2.top().first > j) {
				a += st2.top().second; st2.pop();
			}
			st2.push(pair<int, int>(j, a));
		}
	}

	vector<int> ans;
	while(st2.size() > 0) {
		ans.insert(ans.begin(), st2.top().second); st2.pop();
	}
	cout << sum << endl;
	cout << ans.size();
	for (int i = 0;i < ans.size(); i++){
		cout << ' ';
		cout << ans[i];
	}
	cout << endl;
}




Measured memory_bytes: 3296
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<ll,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  ll x, y;
  cin >> x >> y;
  bool win = true;
  if (llabs(x-y) <= 1) win = false;
  cout << (win ? "Alice" : "Brown") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N;
    string S;
    cin >> N >> S;
    int ans = 0;
    for(int i = 1; i < N; i++) {
        int cnt = 0;
        string s = "";
        string t = "";
        for(int j = 0; j < i; j++) {
            s+=S[j];
        }
        for(int j = i; j < N; j++) {
            t+=S[j];
        }
        vector<int>hantei(26);
        for(int j = 0; j < s.size(); j++) {
            hantei[s[j]-'a']++;
        }
        vector<bool>ok(26,false);
        for(int j = 0; j < t.size();  j++) {
            if(hantei[t[j]-'a']){
                ok[t[j]-'a'] = true;
            }
        }
        for(int j = 0; j < 26; j++) {
            if(ok[j]) {
                cnt++;
            }
        }
        ans = max(ans,cnt);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
ll a[N];
ll pref_sum[N];

void solve(){
	ll i, j, k, p, q, r, x, y, u, v, n, m=1e9+7;
    ll ans=0;
    cin>>n;
    pref_sum[0]=0;
    a[0]=0;
    for(i=1;i<=n;i++){
        cin>>a[i];
        pref_sum[i]=(pref_sum[i-1]+a[i])%m;
    }
    for(i=1;i<=n;i++){
        ans=ans%m+(a[i]*(pref_sum[n]-pref_sum[i]))%m;
    }
    cout<<(ans+m)%m<<endl;




}

int main() {
	ios_base::sync_with_stdio(0);
	int i,t=1;
	//cin>>t;
	for(i=1;i<=t;i++){
		solve();
	}
	return 0;
}

int mpow(int base, int exp) {
	base %= mod;
	int result = 1;
	while (exp > 0) {
		if (exp & 1) result = ((ll)result * base) % mod;
		base = ((ll)base * base) % mod;
		exp >>= 1;
	}
	return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}




Measured memory_bytes: 13780
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		sc.close();
		
		long cnt = 0;
		for(int b=1;b<=N;b++) {
			long loop = N/b;
			long rem = N%b + 1;
			long tmp = Math.max(b-K, 0)*loop + Math.max(rem-K, 0);  
			cnt += tmp;
			if(K==0) {
				cnt -= 1;
			}
		}
		System.out.println(cnt);
	}
	
}


Measured memory_bytes: 23508
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL))
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

int main()
{
    fastread();

   ll a,b,c;


cin>>a>>b>>c;


   for(ll i=0;i<10;i++)
   {
       cout<<(a*c)-b<<endl;
       c=(a*c)-b;
   }



}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long ;
int main(){
    int n;
    cin >> n;
    int x,y;
    x = 800*n;
    y = (n/15)*200;
    cout << x - y << endl;
}

Measured memory_bytes: 3576
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	var a int
	var sum int
	for i := 0; i < m; i++ {
		fmt.Scan(&a)
		sum += a
	}

	ans := n-sum
	if ans < 0 {
		fmt.Println("-1")
		return
	}
	fmt.Println(ans)
}


Measured memory_bytes: 2340
def main():
  ## IMPORT MODULE
  #import sys

  #sys.setrecursionlimit(100000)
  #input=lambda :sys.stdin.readline().rstrip()

  #f_inf=float("inf")
  #MOD=10**9+7
  
  if 'get_ipython' in globals(): 
    ## SAMPLE INPUT
    n, k = 3, 2
    D = [2, 1]
    A = [[1, 3], [3]]

  else:
    ##INPUT 
    #n = input()
    n, k = map(int, input().split())
    D = [0]*k
    A = []
    for i in range(k):
      D[i] = int(input())
      A.append(list(map(int, input().split())))

  ## SUBMITION CODES HERE
  cnt = 0
  ans = []
  for a in A:
    for i in a:
      if i not in ans:
        ans.append(i)
  print(n-len(ans))
  
main()

Measured memory_bytes: 9124
#include<stdio.h>
int main()
{
    int a, b, c;
    int tmp;
 
    scanf("%d%d%d", &a, &b, &c);
    if (a > b) tmp = a, a = b, b = tmp;
    if (b > c) {
        tmp = b, b = c, c = tmp;
        if (a > b) tmp = a, a = b, b = tmp;
    }
    printf("%d %d %d\n", a, b, c);
    return 0;
}


Measured memory_bytes: 2012
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long int
//#define lli long long int
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define pci pair<char,int
#define mii map<int,int>
#define mll map<long long int,long long int>
#define mci map<char,int>
#define umii unordered_map<int,int>
#define umll unordered_map<long long int,long long int>
#define umci unordered_map<char,int>
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define mod 1000000007
using namespace std;
ll visit[100001]={0};
vector<ll> adj[1000001];

bool sortinrev(const pair<ll,ll> &a,  
               const pair<ll,ll> &b) 
{
       if(a.first!=b.first) return(a.first > b.first);
       else return (a.second<b.second);
} 
ll power(ll x,ll n,ll m)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%m;
        x=(x*x)%m;
        n=n/2;
    }
    return result%m;
}
bool isPrime(ll k){
    if(k<=1){return false;}
    if(k==2){return true;}
    if(k%2==0){return false;}
    ll i = 3;
   while (i*i <= k) {if (k % i == 0) {return false;}i += 2;}
return true;
}
 
ll bin(ll n)
{
    int di= 0;
    while(n)
    {   di=di+n%10;
        n=n/10;
        
    }
    return di;
}
ll coun(auto v, vector<ll> a, ll x)
{
	ll ans1 = 0;
	for(auto i=v;i!=a.end();i++)
	{
		while(1)
		{
			ans1++;
			if(x>=*i)
			{
				x = *i;
				break;
			}
			x*=2;
		}
		x*=2;
	}
	ans1=ans1+v-a.begin();
	return ans1;
}
int main(){
   IOS;
ll t1;t1=1;
while(t1--){
ll l,r,d;
cin>>l>>r>>d;
if(l%d==0){cout<<r/d-l/d+1;}
else cout<<r/d-l/d;
}



return 0;}

Measured memory_bytes: 27068
#include <stdio.h>
#include <algorithm>
#include <vector>
#define MIN(a, b) ((a)>(b)? (b): (a))
using namespace std;

int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    vector<int> a(n);
    int i;
    for(i=0; i<n; i++) {
        scanf("%d", &a[i]);
    }
    sort(a.begin(), a.end());

    for(i=0; i<n; i+=2) {
        a[i]=24-a[i];
    }
    sort(a.begin(), a.end());

    int min=MIN(a[0], 24-a[n-1]);
    for(i=1; i<n; i++) {
        min=MIN(min,a[i]-a[i-1]);
    }
    printf("%d\n", min);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
#include <string.h>
#include <set>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

ll N, M;
string S, T;

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

ll lcm (ll a, ll b) {
  return (a * b / gcd(a, b));
}

int main(){
  cin >> N >> M;
  cin >> S >> T;

  ll L = lcm(N, M);
  ll G = gcd(N, M);
  ll n = N / G;
  ll m = M / G;
  REP(i, G) {
    if(S[n * i] != T[m * i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << L << endl;

  return 0;
}



Measured memory_bytes: 512
from heapq import heappush, heappop
while 1:
    n, m, cap = map(int, raw_input().split())
    if n==0:
        break
    src, dest = raw_input().split()
    G = {}
    for i in xrange(n):
        c1, c2, d = raw_input().split()
        d = int(d)
        G.setdefault(c1, {})[c2] = d
        G.setdefault(c2, {})[c1] = d
    S = {raw_input() for i in xrange(m)} | {src, dest}

    INF = 10**18
    cap *= 10

    def dijkstra(s, G):
        dist = {s: 0}
        que = [(0, s)]
        while que:
            co, v = heappop(que)
            if dist.get(v, INF) < co:
                continue
            for t, cost in G[v].items():
                if co+cost < dist.get(t, INF):
                    dist[t] = co+cost
                    heappush(que, (co+cost, t))
        return dist

    H = {}
    for s in S:
        dist = dijkstra(s, G)
        for k, v in dist.items():
            if k in S and v <= cap:
                H.setdefault(s, {})[k] = v
    dist = dijkstra(src, H)
    print dist.get(dest, -1)

Measured memory_bytes: 15636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N;
  cin >> N;
  ll A[N];
  int B[N] = {0};
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    while(A[i] % 2 == 0) {
      B[i]++;
      A[i] /= 2;
    }
  }
  sort(B,B + N);
  cout << B[0] << endl;
  return 0;
}


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

using namespace std;
int main()
{
    int n,a[100001],dig[10001],rem,prod,k,mx;
    bool flag=true;
    while(cin >>n)
    {
        for(int i=0; i<n; i++) cin >> a[i];
        mx=0;
        sort(a,a+n);
        for(int i=n-1; i>0;i--)
        {
            for(int j=i-1;j>=0; j--)
            {
                flag=true;
                prod=a[i]*a[j];
              
                rem=prod;
                k=0;
                while(rem>0)
                {
                    dig[k]=rem%10;
                    rem/=10;
                  
                    if(k>0 && ((dig[k]+1)!=dig[k-1])) 
                    flag=false;
                    k++;
                }
                if(flag)
                {
                    if(prod>mx) mx=prod;
                }
                else if(flag==false && mx==0) mx=-1;

            }
        }
        cout << mx << endl;
    }
    return 0;
}

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

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

    int res = 0;
    for (int i = 0; i < N; ++i) {
        // same を抜ける
        while (i+1 < N && A[i] == A[i+1]) ++i;

        // up
        if (i+1 < N && A[i] < A[i+1]) {
            while (i+1 < N && A[i] <= A[i+1]) ++i;
        }
        // down
        else if (i+1 < N && A[i] > A[i+1]) {
            while (i+1 < N && A[i] >= A[i+1]) ++i;
        }
        ++res;
    }
    cout << res << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define llenar(a,val)   memset(a,val,sizeof(a))
#define pb          push_back 
#define endl        "\n"
#define mostrar(x,y) cout<<x<<" "<<y<<endl;
#define f           first
#define s           second
#define mod         1000000007
#define EPS         1e-9
using namespace std;
typedef pair<int,int> ii;
typedef pair<pair<int,int>,int> iii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef long long ll;
typedef vector< pair<pair<int,int>,int> > viii;

char a[1000][1000];

int main(){
    ofstream out("output.txt");
    
    string s;
    cin>>s;
    if(s =="Sunny") cout<<"Cloudy"<<endl;
    else if(s == "Cloudy") cout<<"Rainy"<<endl;
    else cout<<"Sunny"<<endl;

    
    return 0;
}

 
 







Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }


int exp_mod(long long a, long long b, int m) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a) % m;
        a = (a * a) % m;
        b >>= 1;
    }
    return (int)res;
}

int fact_mod(int n, int m) {
    long long res = 1;
    for (int i = n; i>0; --i)
        res = (res * i) % m;
    return (int)res;
}

int comb_mod(int n, int r, ll p) {
    long long res = 1;
    for (int i = 0; i<r; ++i)
        res = (res * (n - i)) % p;
    return (res * exp_mod(fact_mod(r, p), p - 2, p)) % p;
}

int main() {
    int N, K;
    cin >> N >> K;
    v2ll dp(K + 1, vll(K + 1, 0));
    rep(i, K + 1) {
        dp[1][i] = 1;
    }
    ll p = 1000000007;
    REP(i, 2, K + 1) {
        REP(j, i, K + 1) {
            dp[i][j] = (dp[i - 1][j - 1] + dp[i][j - 1]) % p;
        }
    }
    
    rep(i, K) {
        cout << (comb_mod(N - K + 1, i + 1, p) * dp[i + 1][K])%p << endl;;
    }

    return 0;
}

Measured memory_bytes: 31616
from collections import Counter

N = int(input())
A = Counter(list(map(int, input().split())))

bar = []
for k, v in A.items():
  bar += [k]*(v//2)
bar.sort(reverse=True)  

if len(bar) < 2:
  print(0)
else:
  print(bar[0]*bar[1])

Measured memory_bytes: 18600
#include<bits/stdc++.h>
int f[17777][17],n,m;
int se[33333],e[16][16],tr[16],sum=0,ans=0;
void maxs(int&a,int b){if(a<b)a=b;}
int main(){
	memset(e,-0x3f,sizeof(e));
	scanf("%d%d",&n,&m);
	for(int i=0,a,b,c;i<m;++i){
		scanf("%d%d%d",&a,&b,&c);
		--a,--b;sum+=c;
		e[a][b]=e[b][a]=c;
		int s=1<<a|1<<b;
		for(int j=0;j<(1<<n);++j)if((j&s)==s)se[j]+=c;
	}
	--n;
	int mx=1<<n;
	memset(f,-0x3f,sizeof(f[0])*mx);
	for(int i=1;i<mx;++i)if(i&1)f[i][0]=se[i];
	for(int i=1;i<mx;++i)if(i&1){
		memset(tr,-0x3f,sizeof(tr));
		for(int j=0;j<n;++j)if(i>>j&1){
			for(int k=0;k<n;++k)if(~i>>k&1){
				maxs(tr[k],f[i][j]+e[j][k]);
			}
		}
		int rv=mx-1-i;
		for(int j=rv;j;j=j-1&rv){
			int v=se[j];
			for(int k=0;k<n;++k)if(j>>k&1)maxs(f[i|j][k],tr[k]+v);
		}
		for(int j=0;j<n;++j)maxs(ans,f[i][j]+e[n][j]+se[mx*2-1-i]);
	}
	printf("%d\n",sum-ans);
	return 0;
}

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

using namespace std;
typedef long long ll;

int main()
{
    ll  n,m,k; std::cin >> n >> m >> k;
    ll  a[200001], b[200001];
    // std::vector<long long>  a(n+1), b(m+1);
    a[0]=0; b[0]=0;
    for (int i=1;i<n+1;i++)
        cin >> a[i];
    for (int i=1; i<m+1; i++)
        cin >> b[i];
    
    for (int i=1; i<n+1; i++)
        a[i]+=a[i-1];
    for (int i=1; i<m+1; i++)
        b[i]+=b[i-1];

    ll ans=0, r=m;
    for (int i=0; i<n+1; i++)
    {
        if(a[i]>k) break;
        while (a[i]+b[r]>k)
            r--;
        ans = max(ans, i+r);
    }
    
    std::cout << ans;

    return 0;
}

Measured memory_bytes: 6720
n = int(input())
 
isExist = False

for i in range(int(n / 7) + 1):
  for j in range(int(n / 4) + 1):
    if (7 * i + 4 * j == n):
      isExist = True
      break

if isExist:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 2940
N,L = gets.split.map(&:to_i)
all = 0
A = Array.new(N)
N.times do |i|
    A[i] = L + (i+1) - 1
    all += L + (i+1) - 1
end

if L > 0 then
    puts all - A.min
elsif A.include?(0) then
    puts all
else
    puts all - A.max
end

Measured memory_bytes: 1788
#include <map>
#include <list>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
const int a[]={1,2,4,8,16,32,64}; 
int main()
{
	int n;
	cin>>n;
	for (int i=0;i<=6;i++)
	   if (a[i]>n)
	   {
	   	   cout<<a[i-1]<<endl;
	   	   return 0;
	   }
	cout<<64<<endl;
    return 0;
}

Measured memory_bytes: 256
int main(){
	int h,w,hi,wi;
	while (1){
		scanf("%d %d",&h,&w);
		if (h == 0) break;
		for (hi=0; hi<h; hi++){
			for (wi=0; wi<w; wi++)
				if ((hi==0||hi==h-1)||(wi==0||wi==w-1))
					printf("#");
				else
					printf(".");
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
n=int(input())
s=list(input())
ans=s.count('R')*s.count('G')*s.count('B')
for i in range(n):
  if s[i] =="R":
    s[i]=1
  elif s[i] =="G":
    s[i]=2
  elif s[i] =="B":
    s[i]=4
for i in range(n):
  for j in range(i+1,n):

    k=2*j-i
    if k>= n:
      continue
    if s[i]+s[j]+s[k]==7:
      ans -=1
print (ans)

Measured memory_bytes: 9248
#include <bits/stdc++.h>
#define INF 1000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  string n;
  cin >> n;
  bool ok = true;
  char before = n[0];
  for (ll i = 0; i < n.size(); ++i)
  {
    if (i == 0)
    {
      continue;
    }
    if (n[i] < before)
    {
      break;
    }
    if (n[i] == before)
    {
      continue;
    }
    ok = false;
    break;
  }
  if (ok)
  {
    for (ll i = 0; i < n.size(); ++i)
    {
      cout << n[0];
    }
  }
  else
  {
    for (ll i = 0; i < n.size(); ++i)
    {
      cout << n[0] - '0' + 1;
    }
  }
  cout << endl;
}


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

public class Main {
  public static void main(String[] args) {
    FastScanner fs = new FastScanner();
    int N = fs.nextInt();
    String S = "No";
    for (int i = 1; i < 10; i++)
      for (int j = 1; j < 10; j++) if (i * j == N) S = "Yes";
    System.out.println(S);
  }
}

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;

  private boolean hasNextByte() {
    if (ptr < buflen) {
      return true;
    } else {
      ptr = 0;
      try {
        buflen = in.read(buffer);
      } catch (IOException e) {
        e.printStackTrace();
      }
      if (buflen <= 0) {
        return false;
      }
    }
    return true;
  }

  private int readByte() {
    if (hasNextByte())
    return buffer[ptr++];
    else
    return -1;
  }

  private static boolean isPrintableChar(int c) {
    return 33 <= c && c <= 126;
  }

  public boolean hasNext() {
    while (hasNextByte() && !isPrintableChar(buffer[ptr]))
    ptr++;
    return hasNextByte();
  }

  public String next() {
    if (!hasNext())
    throw new NoSuchElementException();
    StringBuilder sb = new StringBuilder();
    int b = readByte();
    while (isPrintableChar(b)) {
      sb.appendCodePoint(b);
      b = readByte();
    }
    return sb.toString();
  }

  public long nextLong() {
    if (!hasNext())
    throw new NoSuchElementException();
    long n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while (true) {
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
      throw new NumberFormatException();
      }
      b = readByte();
    }
  }

  public int nextInt() {
    long nl = nextLong();
    if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
    throw new NumberFormatException();
    return (int) nl;
  }

  public double nextDouble() {
    return Double.parseDouble(next());
  }
}

Measured memory_bytes: 23252
*s,n=map(int,input().split())
s.sort()
c=0
for i in range(n//s[2]+1):
    for j in range(n//s[1]+1):
        if (n-s[2]*i-s[1]*j)%s[0] == 0 and 0<=(n-s[2]*i-s[1]*j):
            #print(i,j,n-s[2]*i-s[1]*j)
            c+=1
print(c)

Measured memory_bytes: 67552
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())

#define pb emplace_back
#define fi first
#define se second

using namespace std;

using ld = long double;
using ll = long long int;

const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> void UNIQUE(vector<T> &a){ a.erase(unique(a.begin(), a.end()), a.end()); }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll in(){long long int x; scanf("%lld", &x); return x;}
ld fin(){double x; scanf("%lf", &x); return x;}
char yuyushiki[1000010]; string stin(){scanf( "%s", yuyushiki ); return yuyushiki;}

// head

int main(){

  int n = in();
  vector<string> s(3);
  REP(i, 3){
    s[i] = stin();
  }
  int ans = 0;
  REP(i, n){
    set<char> ss;
    REP(j, 3){
      ss.insert(s[j][i]);
    }
    ans += SZ(ss) - 1;
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
N,M= (int(i) for i in input().split()) 
AB = [[int(i) for i in input().split()] for i in range(N)] 
AB.sort()

ans=0
buy = 0
buy_sum = 0

for i in range(N):
	buy = min(AB[i][1], M-buy_sum)
	ans += AB[i][0]*buy
	buy_sum += buy
	if M==buy_sum:
		break
print(ans)

Measured memory_bytes: 21612
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
#define int long long
#define double long double
 
main(){
    int n;
    cin>>n;
    vector<string> s(n);
    vector<int> t(n);
    for (int i = 0; i < n; ++i){
        cin>>s[i]>>t[i];
    }
    string x;
    cin>>x;
    int count=0;
    int ans=0;
    rep(i,n){
        if(count==1){
            ans+=t[i];
        }
        if(x==s[i]) count=1;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define MOD 1000000007
int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int64_t rll() {
	long long n;
	scanf("%lld", &n);
	return n;
}

int main() {
	int n = ri();
	int k = ri();
	int a[n];
	for (int i = 0; i < n; i++) a[i] = ri();
	
	bool dp[5001] = { 0 };
	dp[0] = true;
	std::vector<int> del[n];
	for (int i = n - 1; i >= 0; i--) {
		for (int j = 5000; j >= 0; j--) {
			if (!dp[j]) continue;
			if (j + a[i] <= 5000 && !dp[j + a[i]]) {
				dp[j + a[i]] = true;
				del[i].push_back(j + a[i]);
			}
		}
	}
	std::set<int> all;
	for (int i = 0; i <= 5000; i++) if (dp[i]) all.insert(i);
	memset(dp, 0, sizeof(dp));
	dp[0] = true;
	int res = 0;
	for (int i = 0; i < n; i++) {
		/*
	std::cerr << std::endl;
	for (auto i : all) std::cerr << i << " ";
	for (int i = 0; i <= 5000; i++) if (dp[i]) std::cerr << i << " ";
	std::cerr << std::endl;*/
		for (auto j : del[i]) all.erase(j);
		for (int j = 0; j <= 5000; j++) {
			if (dp[j]) {
				auto itr = all.lower_bound(k - a[i] - j);
				if (itr != all.end() && *itr < k - j) {
					res++;
					break;
				}
			}
		}
		for (int j = 5000; j >= 0; j--)
			if (j + a[i] <= 5000 && dp[j]) dp[j + a[i]] = true;
	}
	std::cout << n - res << std::endl;
	return 0;
}


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

int main() {
  string S, T, U;
  cin >> S >> T;
  int A, B;
  cin >> A >> B;
  cin >> U;
  if (U == S) {
    cout << A - 1 << ' ' << B << endl;
  } else {
    cout << A << ' ' << B - 1 << endl;
  }
  return 0;
}


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

using namespace std;
typedef long long ll;

const ll MOD = 1e9 + 7;

ll calc_pow(ll x, ll pow) {
    if (pow == 0) return 1;
    ll a = calc_pow(x, pow / 2);
    a = a * a % MOD;
    if (pow % 2 == 1) a *= x;
    return a % MOD;
}

ll calc_div(ll a, ll b) {
    return a * calc_pow(b, MOD - 2) % MOD;
}

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    ll sum = 0;
    for (int i = 0; i < n; i++)cin >> a[i], sum += a[i], sum %= MOD;

    ll ret = sum * sum % MOD;
    for (int i = 0; i < n; i++) {
        ret -= (a[i] * a[i]) % MOD;
        if (ret < 0)ret += MOD;
    }

    cout << calc_div(ret, 2) << endl;
    return 0;
}

Measured memory_bytes: 4840
n = int(input())
s = ""
k = 0
while n!=0:
  if n%(2**(k+1)) == 2**k:
    if k%2 == 0:
      n -= 2**k
    else:
      n += 2**k
    s = "1"+s
  else:
    s = "0"+s
  k += 1

if s=="":
  s="0"

print("".join(s))

Measured memory_bytes: 3060
N = gets.to_i
sizes = gets.split.map(&:to_i).sort
left = 0
right = N-1
while left != right
  tar = (left + right)/2
  s = sizes[0..tar].inject(:+)
  flag = true
  ((tar+1)...N).each do |i|
    if 2*s >= sizes[i]
      s += sizes[i]
    else
      flag = false
      break
    end
  end
  if flag
    right = tar
  else
    left = tar
    if right == left + 1
      left = right
    end
  end
  # pp [left, right]
end
puts N-left


Measured memory_bytes: 11528
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline T intceil(T a, T b) { return (a + (b - 1)) / b; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
#define precout(val) cout << std::fixed << std::setprecision(20) << val;
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };
static const double pi = 3.141592653589793;

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

  long double a,b,h,m; cin >> a >> b >> h >> m;

  long double jishin = h == 0 ? 360 : 360 * (h / 12);
  jishin += (m * (long double)0.5);
  long double hunshin = m == 0 ? 360 : 360 * (m / 60);

  long double kakudo = min(abs(hunshin - jishin), abs(jishin - hunshin));

  long double co = cos(pi / ((long double)180 / kakudo));

  long double ans = (a * a) + (b * b) - (long double)2 * a * b * co;
  ans = sqrt(ans);

  precout(ans) cout << endl;
}


Measured memory_bytes: 4176
N=int(input())
A=[int(x) for x in input().split()]
Ans=sorted(A)

Ami=Ans[N//2-1]
Ama=Ans[N//2]

for i in range(N):
  if A[i]<=Ami:
    print(Ama)
  else:
    print(Ami)

Measured memory_bytes: 25624
function main()
    A = parse(Int, readline())
    B = parse(Int, readline())
    C = parse(Int, readline())
    X = parse(Int, readline())

    res = 0
    for a = 0:A
        for b = 0:B
            for c = 0:C
                total = 500 * a + 100 * b + 50 * c
                if total == X
                    res += 1
                end
            end
        end
    end

    println(res)
end

main()

Measured memory_bytes: 110212
import sys

input = sys.stdin.readline
MOD = 1000000007

A,B,K = map(int,input().split())

res = []
for i in range(A,min(A+K,B+1)):
    res.append(i)

for i in range(max(B-K+1,A),B+1):
    res.append(i)

for x in sorted(list(set(res))):
    print(x)

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

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

int n, w;
int weight[110], value[110];
long long dp[110][100100];
int main()
{
	cin >> n >> w;
	for (int i = 0; i < n; i++) cin >> weight[i] >> value[i];

	for (int i = 0; i < n; i++){
		for (int sum_w = 0; sum_w <= w; sum_w++){
			if (sum_w - weight[i] >= 0){
				chmax(dp[i+1][sum_w], dp[i][sum_w-weight[i]] + value[i]);
			}
			chmax(dp[i+1][sum_w], dp[i][sum_w]);
		}
	}
	cout << dp[n][w] << endl;
}

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

int main() {
	int n; cin >> n;
	long long arr[n];
	for (int i = 0; i < n; i++) cin >> arr[i];

	long long ans = 0;
	for (int i = 0; i < n; i++) {
		if (i == 0 || arr[i-1] == 0) {
			ans += arr[i]/2;
			arr[i] %= 2;
		} else if (arr[i] > 0) {
			ans += (arr[i]+arr[i-1])/2;
			arr[i] = (arr[i]+arr[i-1])%2;
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
typedef long long               ll;
typedef long double             ld;
 
 
#define racecar          ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define si(a)            scanf("%d", &a)
#define si2(a,b)         scanf("%d %d", &a,&b)
#define sll(a)           scanf("%I64d",&a)
#define sll2(a,b)        scanf("%I64d %I64d",&a,&b)
#define pb               push_back
#define pi(a)            printf("%d",int(a))
#define pll(a)           printf("%I64d",ll(a))
#define all(x)           (x).begin(),(x).end()
#define rall(x)          (x).rbegin(),(x).rend()
#define ps               printf(" ")
#define nln              printf("\n")
#define ff               first
#define ss               second
#define vi               vector<int>
#define vll              vector<ll>
#define vstr             vector<string>
#define vc               vector<char>
#define pii              pair<int,int>
#define PLL              pair<ll,ll>
#define PI               acos(-1)
#define sq(x)            x*x
#define forr(i,a,b)      for(ll i=ll(a);i<ll(b);i++)
#define forn(i,a,b)      for(ll i=ll(a);i>ll(b);i--)
#define max3(a,b,c)      max(a,max(b,c))
#define max4(a,b,c,d)    max(max3(a,b,c),d)
#define min3(a,b,c)      min(a,min(b,c))
#define mod              1000000007
#define inf              9223372036854775807
 
ll power(ll b,ll n)
{
    if(n==0) return 1;
    else if(n%2) return b*power(b,n/2)*power(b,n/2);
    else return power(b,n/2)*power(b,n/2);
} 
 
ld root(ll n,ll r)
{
    ld dif=0.0001;
    ld guess=n/2.0;
    while(abs(pow(guess,r)-n)>=dif)
    {
        ld temp=pow(guess,r)-n;
        ld tmp=r*pow(guess,r-1);
        guess-=temp/tmp;
    }
    return guess;
}
 
void fileio()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
}
 
      
 
int solve()
{   
	ll n,a,b;
	sll(n);
	sll2(a,b);
	ll cnt=0;
	while(n--)
	{
		ll x,y;
		sll2(x,y);
		if(x>=a && y>=b) cnt++;
	}
	pll(cnt);
	
	return 0;
}
 
int main()
{   
 
//    racecar;
//    cout<<fixed<<setprecision(6);
//    fileio();
    solve();
}
 
 
 
///    Before submission=>
///    ***check for integer overflow,array bounds
///    ***check for n

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    bool h = true;
    for (int i = 0; i < s.size(); i += 2) {
        if (s.substr(i, 2) != "hi") h = false;
    }
    cout << (h ? "Yes\n" : "No\n");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+7; 
vector<int>ss[N];
queue<int>qe;
int vis[N]; 
int main()
{
	int n;
	cin>>n;
	int u,v,x,y;
	memset(vis,0,sizeof(vis)); 
	for(int i=1;i<=n;i++)
		ss[i].clear(); 
	for(int i=1;i<n;i++)
	{
		cin>>u>>v;
		ss[u].emplace_back(v);
		ss[v].emplace_back(u); 
	} 
	qe.push(1);
	qe.push(n); 
	vis[1]=1;
	vis[n]=2;
	x=0,y=0; 
	while(!qe.empty())
	{	
		u=qe.front();
		qe.pop(); 
		for(int i=0;i<ss[u].size();i++)
		{
			v=ss[u][i];	 
	 		if(!vis[v])
			{	
			 	vis[v]=vis[u];
				 qe.push(v);
				 if(vis[v]==1) x++;
				 else y++;
			}
		}
	} 
	if(x<=y)
	cout<<"Snuke"<<endl;
	else
	cout<<"Fennec"<<endl; 
	return 0;
} 

Measured memory_bytes: 6272
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())

#define MOD 1000000007


vector<int> compress(vector<int> v) {
	vector<int> ret;
	int prev = -1;
	for(int x: v) {
		if (prev != x)ret.push_back(x);
		prev = x;
	}
	return ret;
}

int v[200000];

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

	int n;
	vector<int> c;
	cin >> n;
	rep(i,n) {
		int x;
		cin >> x;
		c.push_back(x - 1);
	}
	c = compress(c);


	int ans = 1, prev = 1;

	rep(i, c.size()) {
		ans += v[c[i]];
		ans %= MOD;

		v[c[i]] += prev;
		v[c[i]] %= MOD;

		prev = ans;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3316
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
using namespace std;

int main(int argc, char* argv[]){

	string S;
	cin >> S;

	char A[3] = {0};
	A[0] = S[0]; A[1] = S[1];
	int a = atoi(A);

	char B[3] = {0};
	B[0] = S[2]; B[1] = S[3];
	int b = atoi(B);

	if(a >= 1 && a <=12 && b >= 1 && b <= 12){
		printf("AMBIGUOUS\n");
	}
	else if((a == 0 || a > 12) && b >= 1 && b <= 12){
		printf("YYMM\n");
	}
	else if(a >= 1 && a <= 12 && (b == 0 || b > 12)){
		printf("MMYY\n");
	}
	else{
		printf("NA\n");
	}
	return 0;
}

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

#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)

#define REPISE (s,e) for(int i=s,i<e;i++)
#define REPJSE (s,e) for(int j=s,j<e;j++)

using namespace std;

int main ()
{
  int N;
  long long res=0;
  cin >> N;
  REPI(N+1){
    if (i % 3 == 0 || i % 5 == 0)
      continue;
    res += i;
  }

  printf("%lld\n",res);
  return 0;
}

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


int main()
{
    ios::sync_with_stdio(false);
    int n, x[101], y[101], h[101];
    int flag = 0;
    cin >> n;
    for(int i = 0; i < n; ++i)
    {
        cin >> x[i] >> y[i] >> h[i];
        if(h[i] != 0)
            flag = i;
    }

    int i,j,H;
    for(i = 0; i <= 100; ++i)
    {
        for(j = 0; j <= 100; ++j)
        {
            H = abs(x[flag] - i) + abs(y[flag] - j) + h[flag];
            for(int k = 0; k < n; ++k)
            {
                if(h[k] != max((H - abs(x[k] - i) - abs(y[k] - j)), 0))
                    break;
                if(k == n-1)
                {
                    cout << i << " " << j << " " << H << endl;
                }
            }
        }
    }
}

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

int main()
{
    int n,k,vis[10]={0},ans;
    scanf("%d%d",&n,&k);
    for(int i=0;i<k;i++){
        int tem;
        scanf("%d",&tem);
        vis[tem]=1;
    }
    ans=n;
    while(1){
        int tem=ans;
        int flag=1;
        while(tem!=0){
            if(vis[tem%10]){flag=0;break;}
            tem/=10;
        }
        if(flag)break;
        ans++;
    }
    cout<<ans;
}


Measured memory_bytes: 3656
N, M = map(int,input().split())
X = list(map(int,input().split()))
if N >= M:
    ans = 0
else:
    X.sort()
    Sa = [0]*(M-1)
    for i in range(M-1):
        Sa[i] = X[i+1] - X[i]
    Sa.sort()
    ans = sum(Sa[:M-N])
print(ans)

Measured memory_bytes: 13968
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
typedef long long ll;

int n,k,m,d;
string s,t;

int main() {
  cin >> m >> d;
  int ans=0;
  rep(i,m+1)rep(j,d+1){
    int a=j%10,b=j/10;
    if(a>=2 && b>=2 && a*b==i) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <sstream>
#include <fstream>
#include <string.h>

#define X first
#define Y second
#define MP make_pair
typedef long long ll;
using namespace std;
const int MAX = 101;

template<class T, class U>
void convert(T &t, U &u){
	stringstream ss;
	ss << t;
	ss >> u;
}

int main(){
	int n;
	while(cin >> n && n != 0){
		vector<vector<int> > ans(n+1, vector<int>(n+1, 0));
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cin >> ans[i][j];
				ans[i][n] += ans[i][j];
				ans[n][j] += ans[i][j];
			}
			ans[n][n] += ans[i][n];
		}

		for(int i = 0; i <= n; i++){
			for(int j = 0; j <= n; j++){
				printf("%5d", ans[i][j]);
			}
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1216
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn calc(mid: i64, seq: &Vec<i64>) -> i64 {
    let n = seq.len();
    let mut rest = mid;
    for i in 0..n {
        rest = seq[i] - rest;
    }
    rest
}

fn main() {
    let n = read::<usize>();
    let mut seq = vec![0; n];
    for i in 0..n {
        seq[i] = read::<i64>();
    }
    let mut l = 0;
    let mut r = seq[0] + 1;
    while r - l > 1 {
        let mid = (l + r) / 2;
        if calc(mid, &seq) >= mid {
            l = mid;
        } else {
            r = mid;
        }
    }
    let mut rest = l;
    for i in 0..n {
        if i != 0 {
            print!(" ");
        }
        print!("{}", rest * 2);
        rest = seq[i] - rest;
    }
    println!("");
}


Measured memory_bytes: 5372
S = input()
K = int(input())

length = len(S)
dp = [[[0] * (K + 1) for _ in range(2)] for _ in range(length + 1)]
dp[0][0][0] = 1

for i in range(1, length + 1):
    for j in range(2):
        for k in range(K + 1):
            os = int(S[i - 1])
            for x in range(10):
                ni = i
                nj = j
                nk = k
                if x != 0:
                    nk += 1
                if nk > K:
                    continue
                if j == 0:
                    if x > os:
                        continue
                    elif x < os:
                        nj = 1
                dp[ni][nj][nk] += dp[i - 1][j][k]

ans = dp[length][0][K] + dp[length][1][K]
print(ans)


Measured memory_bytes: 3064
import math 
  
def formula(y):
    return int(((8 * y + 1) ** 0.5 - 1) / 2)

def factorize(n): 
    count = 0; 
    ans = 0
    while ((n % 2 > 0) == False):  
          
        n >>= 1;  
        count += 1; 
  
    if (count > 0): 
        ans += formula(count)
  
    for i in range(3, int(math.sqrt(n)) + 1): 
        count = 0; 
        while (n % i == 0):  
            count += 1; 
            n = int(n / i); 
        if (count > 0): 
            ans += formula(count)
        i += 2; 
  
    if (n > 2): 
        ans += 1
    return ans

n = int(input())            
print(factorize(n))

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

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

int main(){
	long a,b;
  	cin >> a >> b;
  	cout << (a*b)/gcd(a,b) << endl;
}

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

int pos[1256];

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

   int n; cin >> n;
   for (int i = 0; i < n; i++)
   {
      cin >> pos[i];
   }
   sort(pos, pos + n);
   int m = pos[n-1] - pos[0];
   cout << m;
   return 0;
}

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

int main() {
    int a,b;
    cin >> a >> b;

    if(a==1 && b ==2) cout << 3 << endl;
    else if(a==2 && b==1) cout << 3 << endl;
    else if(a==1 && b==3) cout << 2 << endl;
    else if(a==2 && b==3) cout << 1  << endl;
    else if(a==3 && b==1) cout << 2 << endl;
    else if(a==3 && b==2) cout << 1 << endl; 

}


Measured memory_bytes: 256
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from scipy.sparse.csgraph import floyd_warshall
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations, combinations_with_replacement
from heapq import heappop, heappush, heapify
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

def main():
    n = int(input())
    a = list(map(int,input().split()))
    a.sort(reverse = True)
    ans = 0
    que = deque()
    ans = 0
    que.append(a[0])
    for i in range(1,n):
        ans += que.popleft()
        que.append(a[i])
        que.append(a[i])
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 98936