akhauriyash/Code-Regression huggingface dataset:
s = input()
dow = ['SUN','MON','TUE','WED','THU','FRI','SAT']
s = dow.index(s)
ans = 0

for i in range(len(dow)):
    if dow[s] == 'SUN' and ans > 0:
        break
    else:
        ans += 1
        s += 1
        if s > 6:
            s = 0
print(ans)

Measured memory_bytes: 3060
while(True):
    a=input().split()
    a[0]=int(a[0])
    a[2]=int(a[2])
    if(a[1]=="?"):
        break
    elif(a[1]=="+"):
        print(a[0]+a[2])
    elif(a[1]=="-"):
        print(a[0]-a[2])
    elif(a[1]=="*"):
        print(a[0]*a[2])
    elif(a[1]=="/"):
        print(a[0]//a[2])

Measured memory_bytes: 7616
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#define DEBUG(x) std::cout << '>' << #x << ':' << x << '\n';
#define PRINTVEC(x) for (int i = 0; i < (int)x.size(); i++) std::cout << x[i] << ' '; std::cout << '\n';
#define PRINTP(x) for (int i = 0; i < (int)x.size(); i++) std::cout << x[i].first << ' ' << x[i].second << '\n'; std::cout << '\n';
#define io std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);   
const int INF = 1<<29;
typedef long long ll;



int main()
{
	io;
    #ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);  
    #endif

    ll n,a,b;
    std::cin >> n >> a >> b;
    ll ans = n / (a + b) * a;
    ll rem = n % (a + b);
    ans += std::min(a, rem);
    std::cout << ans;

    #ifndef ONLINE_JUDGE   
    //std::cout << '\n' << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    #endif
    return 0;
}


Measured memory_bytes: 256
N, K = [int(i) for i in input().split()]
ans = 0
mod = 10**9+7
for i in range(K,N+2):
    start = i*(i-1)//2
    end = i*(i-1)//2 + (N-i+1)*i
    ans += end - start + 1
print(ans%mod)

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define sar(a,n) {cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl;}

using namespace std;

template<typename S,typename T>auto&operator<<(ostream&o,pair<S,T>p){return o<<"{"<<p.fi<<","<<p.se<<"}";}
template<typename T>auto&operator<<(ostream&o,set<T>s){for(auto&e:s)o<<e<<" ";return o;}
template<typename S,typename T,typename U>
auto&operator<<(ostream&o,priority_queue<S,T,U>q){while(!q.empty())o<<q.top()<<" ",q.pop();return o;}
template<typename K,typename T>auto&operator<<(ostream&o,map<K,T>&m){for(auto&e:m)o<<e<<" ";return o;}
template<typename T>auto&operator<<(ostream&o,vector<T>v){for(auto&e:v)o<<e<<" ";return o;}
void ashow(){cout<<endl;}template<typename T,typename...A>void ashow(T t,A...a){cout<<t<<" ";ashow(a...);}
template<typename S,typename T,typename U>
struct TRI{S fi;T se;U th;TRI(){}TRI(S f,T s,U t):fi(f),se(s),th(t){}
bool operator<(const TRI&_)const{return(fi==_.fi)?((se==_.se)?(th<_.th):(se<_.se)):(fi<_.fi);}};
template<typename S,typename T,typename U>
auto&operator<<(ostream&o,TRI<S,T,U>&t){return o<<"{"<<t.fi<<","<<t.se<<","<<t.th<<"}";}

typedef pair<ll, ll> P;

const int MAX_N = 100005;

vector<int> G[MAX_N];
ll D;

void dfs(int u, int p, int d){
    D += d;
    for(int v : G[u]){
        if(v != p) dfs(v, u, d+1);
    }
}

unordered_map<ll, int> mp;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    set<P> st;
    ll ch = 0;
    rep(i,n){
        ll d;
        cin >> d;
        if(i == 0) ch = d;
        mp[d] = i;
        st.insert(P(d, 1));
    }
    vector<pair<int, int> > vec;
    while(len(st) > 1){
        auto p = *(--st.end());
        st.erase(--st.end());
        auto it = st.lower_bound(P(p.fi+2*p.se-n, -INF));
        if(it->fi != p.fi+2*p.se-n){
            cout << "-1\n";
            return 0;
        }
        G[mp[p.fi]].pb(mp[it->fi]);
        G[mp[it->fi]].pb(mp[p.fi]);
        vec.emplace_back(mp[p.fi], mp[it->fi]);
        P nw = P(it->fi, it->se + p.se);
        st.erase(it);
        st.insert(nw);
    }
    dfs(0, -1, 0);
    if(D != ch){
        cout << "-1\n";
        return 0;
    }
    rep(i,n-1){
        cout << vec[i].fi+1 << " " << vec[i].se+1 << "\n";
    }
    return 0;
}


Measured memory_bytes: 20000
N = int(input())
F = [list(map(int,input().split())) for i in range(N)]
P = [list(map(int,input().split())) for i in range(N)]

import itertools
zero = [0,1]
ans = -float("inf")
for i in itertools.product(zero,repeat = 10):
    if i != (0,)*10:
        tmp = 0
        for j in range(N):
            c = 0
            for k in range(10):
                c += i[k]*F[j][k]
            tmp += P[j][c]
        if ans < tmp:
            ans = tmp
print(ans)

Measured memory_bytes: 41836
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a, b, i;
	string s;
	cin >> a >> b >> s;
	if (s[a]!='-'||a+b+1!=s.size())
	{
		cout << "No" << endl;
		return 0;
	}
	for (i=0; i<a; i++)
		if (!(s[i]>='0'&&s[i]<='9'))
		{
			cout << "No" << endl;
			return 0;
		}
	for (i=0; i<b; i++)
		if (!(s[i+a+1]>='0'&&s[i+a+1]<='9'))
		{
			cout << "No" << endl;
			return 0;
		}	
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
x,n = map(int, input().split())
p = list(map(int, input().split()))
ab = min(abs(101 - x),abs(x))
if abs(101 - x) >= abs(x):
    answer = 0
else:
    answer = 101
for i in range(1,101):
    if i in p:
        continue
    else:
        if ab > abs(x - i):
            ab = abs(x - i)
            answer = i
        elif ab == abs(x-i) and answer > i:
            answer = i
print(answer)

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

int main() {
  int64_t n,a,b;
  cin >> n >> a >> b;
  int64_t ans=0, p;
  ans=n/(a+b)*a;
  p=n%(a+b);
  if(p<a)cout << ans+p << endl;
  else cout << ans+a << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

//#include<bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define _USE_MATH_DEFINES
#define ll long long
#define ins Not Needed Thing
#define ull unsigned long long
#define ld long double
#define Accepted 0
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define sz(x) (int)(x.size())
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define SORRY FUL Accepted 
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
#define Toktama Kazakhstan 

using namespace std;

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 3e5 + 123;                                          
const int PRI = 555557;
const int pri = 997;

int tests = 1;

int n, ans = -1;
int a[N], mx;

inline void Solve () {
	//easy
	cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
		mx = max(mx, a[i]);
	}

	for (int i = 1; i <= n ; i ++) {
		if (mx == a[i]) continue;
		int left = mx - a[i];
		if ((ans == -1) || (min(left, a[i]) > min(ans, mx - ans))) {
			ans = a[i];
		}
	}

	cout << mx << ' ' << ans;
}

int main () {
	SpeedForce;
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);	
	// cin >> tests;
	while(tests --) {
		Solve ();
		// Ee Zadrot
	}

	return Accepted; 
}

Measured memory_bytes: 640
H, W = map(int, input().split())
c = [[0]*10 for i in range(10)]

for i in range(10):
    a = list(map(int, input().split()))
    for j in range(10):
        c[i][j] = a[j]

A = [[0]*W for i in range(H)]

for i in range(H):
    a = list(map(int, input().split()))
    for j in range(W):
        A[i][j] = a[j]

for k in range(10):
    for i in range(10):
        for j in range(10):
                if i != j:
                    c[i][j] = min(c[i][j], c[i][k]+c[k][j])

ans = 0
for i in range(H):
    for j in range(W):
        if A[i][j] != -1 and A[i][j] != 1:
            ans += c[A[i][j]][1]
            
print(ans)

Measured memory_bytes: 3444
use std::vec::Vec;
use std::cmp;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let (n, m) = {
      let v: Vec<usize> = read_vec();
      (v[0], v[1])
    };

    let mut a: Vec<i64> = read_vec();
    a.sort();

    let mut bc: Vec<(i64, i64)> = Vec::new();
    for _ in 0..m {
      let v: Vec<i64> = read_vec();
      if v[1] >= a[0] {
          bc.push((v[0], v[1]));
      }
    }

    if bc.is_empty() {
      println!("{}", a.iter().fold(0, |acc, i| acc + i));

    }
    else {
      bc.sort_by(|a, b| (b.1).cmp(&a.1));
      let mut indx: usize = 0;
      let mut stop: usize = 0;
      for &e in &bc {
        stop = cmp::min(indx + e.0 as usize, n);
        for i in indx..stop {
          if a[i] < e.1 {
            a[i] = e.1;
          }
        }
        indx = stop;
      }
      println!("{}", a.iter().fold(0, |acc, i| acc + i));
    }

}


Measured memory_bytes: 11512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int x[20][20];
int main()
{
	ll l,r;cin>>l>>r;
	int x1=l/2019,x2=r/2019;
	int mn=2019;
	if(x1==x2)
	{
		l=l%2019;
		r=r%2019;
		for(int i=l;i<=r;i++)
		{
			for(int j=i+1;j<=r;j++)
			{
				mn=min(mn,(i*j)%2019);
			}
		}
		cout<<mn<<endl;
	}
	else
	{
		cout<<0<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int A, B, C;

int main(void) {

    cin >> A >> B >> C;
    if ((A == B && B == C && C == A) || (A != B && B != C && C != A)) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
s=list(map(int,input().split()))
t=[list(map(int,input().split())) for i in range(s[0])]
u=[0]*(s[1]+1)
for i in range(s[0]):
  for j in range(t[i][0]):
    a=t[i][j+1]
    u[a]+=1
b=0
for k in range(len(u)):
  if u[k]==s[0]:
    b+=1
print(b)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define N 101
#define M 51
using namespace std;
int n,m,l;
double p[N],t[N],d[N];
vector<double> A[N],B[N];

double mem[M][M];
double nCr(int n, int r){
  if(mem[n][r]!=0)return mem[n][r];
  if(r==0||n==r)return 1;
  double a=1;
  for(int i=0;i<r;i++) a*=(n-i)/(i+1.0);
  return mem[n][r]=a;
}

double DP(){
  double dp[N][M]={};
  for(int i=0;i<=m;i++)dp[0][i]=A[0][m-i]*B[0][i]*nCr(m,i);
  
  for(int i=1;i<n;i++)
    for(int j=0;j<=m;j++)
      for(int k=0;k<=m;k++)
	if(d[0]+j*t[0]<d[i]+k*t[i]) 
	  dp[i][j]+=dp[i-1][j]*A[i][m-k]*B[i][k]*nCr(m,k);

  double res=0;
  for(int i=0;i<=m;i++)res+=dp[n-1][i];
  return res;
}

int main(){
  cin>>n>>m>>l;
  for(int i=0;i<n;i++)cin>>p[i]>>t[i]>>d[i],p[i]/=100,d[i]=l/d[i];
  for(int i=0;i<n;i++) {
    //A???j?????????????????£????¢????
    //B???j?????????????¢???????
    A[i]=B[i]=vector<double>(m+1,0);
    A[i][0]=B[i][0]=1;
    for(int j=1;j<=m;j++){
      A[i][j]=A[i][j-1]*(1-p[i]);
      B[i][j]=B[i][j-1]*p[i];
    }
  }
  for(int i=0;i<n;i++){
      printf("%.10f\n",DP());
      swap(p[0],p[i+1]);
      swap(t[0],t[i+1]);
      swap(d[0],d[i+1]);    
      swap(A[0],A[i+1]);    
      swap(B[0],B[i+1]);    
  }
  return 0;
}

Measured memory_bytes: 3388
import itertools
import math
N = int(input())
C = [i for i in range(N)]
X = [list(map(int,input().split())) for i in range(N)]
A = 0
B = list(itertools.permutations(C,N))
for i in range(len(B)):
    for j in range(N - 1):
        a = B[i][j]
        b = B[i][j+1]
        A += ((X[a][0] - X[b][0]) ** 2 + (X[a][1] - X[b][1]) ** 2) ** 0.5
print(A/math.factorial(N))


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

class Program {
  static void Main() {
    var arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int h = arr[0];
    int w = arr[1];
    var a = new List<string>();
    while (h-- > 0) {
      var s = Console.ReadLine();
      if (s.All(x => x == '.')) continue;
      a.Add(s);
    }
    var c = new SortedSet<int>();
    for (int i = 0; i < a.Count; i++) {
      for (int j = 0; j < w; j++) {
        if (a[i][j] == '#') c.Add(j);
      }
    }
    for (int i = 0; i < a.Count; i++) {
      foreach (var j in c) {
        Console.Write(a[i][j]);
      }
      Console.WriteLine();
    }
  }
}

Measured memory_bytes: 13524
#include<bits/stdc++.h>
using namespace std;
int main(){
    int X,A,B,Y;
    cin>>X>>A>>B;
    Y=X-A;
    for(int i=0;i<10000;i++){
        Y -= B;
        if(Y<B){
            break;
        }
    }
    cout<<Y<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		long ans = 0;
		Scanner sc = new Scanner(System.in);
		long k = sc.nextLong();
		long a = sc.nextLong();
		long b = sc.nextLong();
		
		ans = k+1;
		if(b-a > 2){
			long time = a+2;
			while(time <= k+1){
				ans += b-a-2;
				time += 2;
			}
		}
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 23252
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <sstream>
#include <string>
#include <utility>
#include <map>
#include <memory>
#include <set>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>

using namespace std;

class DFS
{
public:
  int n;
  int solve();
  int dfs( int v, int t, vector<vector<int>>& adj, vector<int>& d, vector<int>& f );
};

int DFS::dfs( int v, int t, vector<vector<int>>& adj, vector<int>& d, vector<int>& f )
{
  if ( d[v] )
    return t;
  else
    d[v] = t++;

  for ( auto i = 1; i <= n; ++i )
    if ( adj[v][i] )
      t = dfs( i, t, adj, d, f );

  f[v] = t;

  return ++t;
}

int DFS::solve()
{
  cin >> n;

  vector<vector<int>> adj(n+1, vector<int>(n+1, 0));
  vector<int> d(n+1,0);
  vector<int> f(n+1,0);

  for ( auto i = 0; i < n; ++i )
    {
      int x, k;
      cin >> x;
      cin >> k;
      for ( auto j = 0; j < k; ++j )
        {
          int y;
          cin >> y;
          adj[x][y] = 1;
        }
    }

  int t = 1;
  
  for ( auto i = 1; i <= n; ++i )
    t = dfs( i, t, adj, d, f );

  for ( auto i = 1; i <= n; ++i )
    cout << i << " " << d[i] << " " << f[i] << endl;
  
  return 0;
}

int main()
{
  DFS d;

  d.solve();

  return 0;
}

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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define per(i,n) for(ll i = n-1; i >= 0; i--)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define PER(i,n) for(ll i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



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

  int n, k;
  cin >> n >> k;
  vl cnt(k);
  REP(i,n+1) cnt[i%k]++;
  ll ans = 0;
  rep(a,k) {
    int b = (k-a) % k;
    int c = (k-a) % k;
    if((b+c) % k == 0) {
      ans += cnt[a] * cnt[b] * cnt[c];
    }
  }
  cout << ans << endl;
}

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

int north;
int west;
int east;
int south;
int up;
int down;


void turn(string s){
	if(s=="North"){
		swap(up,south);
		swap(south,down);
		swap(down,north);
	}else if(s=="East"){
		swap(up,west);
		swap(west,down);
		swap(down,east);
	}else if(s=="West"){
		swap(up,east);
		swap(east,down);
		swap(down,west);
	}else if(s=="South"){
		swap(up,north);
		swap(north,down);
		swap(down,south);
	}else if(s=="Right"){
		swap(north,west);
		swap(west,south);
		swap(south,east);
	}else{
		swap(north,east);
		swap(east,south);
		swap(south,west);
	}
}


int main(){
	int n;
	while(cin>>n,n){
		int ans=1;
		north=5;
		west=4;
		east=3;
		south=2;
		up=1;
		down=6;
		while(n--){
			string s;
			cin>>s;
			turn(s);
			ans+=up;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1220
#include <stdio.h>

int main (void)
{
	int a11=0,a12=0,a13=0,a21=0,a22=0,a23=0,a31=0,a32=0,a33=0;
	int N=0,a=0,i=0,X=0;
  scanf("%d %d %d %d %d %d %d %d %d",&a11,&a12,&a13,&a21,&a22,&a23,&a31,&a32,&a33);

	scanf("%d",&N);

  int A[N];

  while(i<N)
  {
      scanf("%d",&a);
      A[i]=a;
			i++;
  }

i=0;

  while(i<N)
    {
			a=A[i];

      if(a11==a)
			{
				a11=0;
			}

			if(a12==a)
			{
				a12=0;
			}

			if(a13==a)
			{
				a13=0;
			}

			if(a21==a)
			{
				a21=0;
			}

			if(a22==a)
			{
				a22=0;
			}

			if(a23==a)
			{
				a23=0;
			}

			if(a31==a)
			{
				a31=0;
			}

			if(a32==a)
			{
				a32=0;
			}

			if(a33==a)
			{
				a33=0;
			}

		  i++;
    	}


		if(a11==0&&a12==0&&a13==0)
		{
			X++;
		}
		if(a21==0&&a22==0&&a23==0)
		{
			X++;
		}
		if(a31==0&&a32==0&&a33==0)
		{
			X++;
		}
		if(a11==0&&a21==0&&a31==0)
		{
			X++;
		}
		if(a12==0&&a22==0&&a32==0)
		{
			X++;
		}
		if(a13==0&&a23==0&&a33==0)
		{
			X++;
		}
		if(a11==0&&a22==0&&a33==0)
		{
			X++;
		}
		if(a13==0&&a22==0&&a31==0)
		{
			X++;
		}

		if(X==0)
		{
			printf("No\n");
		}
		if(X!=0)
		{
			printf("Yes\n");
		}
		
  	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#define llint long long

using namespace std;

llint n, W, V;
llint w[105], v[105];
llint dp[105][100005];

int main(void)
{
	cin >> n >> W;
	for(int i = 1; i <= n; i++) cin >> w[i] >> v[i];
	V = 1000*n;
	
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= V; j++){
			dp[i][j] = 1e18;
		}
	}
	dp[0][0] = 0;
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j <= V; j++){
			dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
			if(j+v[i+1] <= V) dp[i+1][j+v[i+1]] = min(dp[i+1][j+v[i+1]], dp[i][j] + w[i+1]);
		}
	}
	llint ans = 0;
	for(int i = 0; i <= V; i++) if(dp[n][i] <= W) ans = i;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 80128
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long t=1;
    //cin>>t;
    for(long long q=0;q<t;q++){
        long n,m;
        cin>>n>>m;
        long long ans=(n*(n-1))/2+(m*(m-1))/2;
        cout<<ans<<"\n";
        //cout<<"Case #"<<(q+1)<<": "<<ans<<"\n"; 
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;




int main()
{
    vector<ll> T;
    T.push_back(2);
    rep(i,31) T.push_back(T.back()*2);
        
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    sort(all(A));
    
    map<ll,int> Map;
    rep(i,N) Map[A[i]]++;
    
    ll ans = 0;
    for (int i = N-1; i >= 0; i--) {
        if(Map[A[i]] == 0) continue;
        Map[A[i]]--;
        ll t = *upper_bound(all(T), A[i]);
        ll a = t - A[i];
        ll b = *lower_bound(all(A),a);
        if(b!=a) continue;
        if(Map[b] > 0){
            ans++;
            Map[b]--;
        }
        

    }
    cout << ans << endl;
    
    
    
    return 0;
}



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

int main() {
  int n;
  cin >> n;
  string s,t;
  cin >> s >> t;
  r(i,n)cout<<s[i]<<t[i];
  cout<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 
  
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
  
typedef long long int ll;
  
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn =5*100001;
ll power(ll x, ll n) {
  ll res = 1;
  for (; n > 0; n >>= 1) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
  }
  return res;
}
int dp[100001][101][2];
int d;
string s;
int solve(int pos,int di,int f,int sum)
{
    if(di>d)
        return 0;
    if(pos==s.length())
    {
        //cout<<sum<<endl;
        if(di==0)
        return 1;
    else
        return 0;
    }
    int &res=dp[pos][di][f];
    if(res!=-1)
        return dp[pos][di][f];
    res=0;
    int fin;
    if(f==0)
    {
        fin=s[pos]-'0';
    }
    else
        fin=9;
   // cout<<fin<<endl;
    for(int x=0;x<=fin;++x)
    {
        int k=f;
        if(f==0 and x<fin)
            k=1;
        res+=solve(pos+1,(sum+x)%d,k,sum+x);
        res=res%mod;
    }
 
    return res%mod;
}
int main()
{
    IOS
    
    
    cin>>s;
    
    cin>>d;
    memset(dp,-1,sizeof(dp));
    int x=solve(0,0,0,0);
    int n=s.length();
    cout<<(x-1+mod)%mod<<endl;
 
}

Measured memory_bytes: 80000
N,K=map(int,input().split())
kashi_num = [str(i+1) for i in range(N)]
for _ in range(K):
  d = input()
  for a in input().split():
    if a in kashi_num:
      kashi_num.remove(a)
  if len(kashi_num)==0:
    break
print(len(kashi_num))

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

N, M = map(int, input().split())
B = {}
for i in range(1, N+1):
    B[i] = []

for i in range(M):
    a, b = map(int, input().split())
    if b == N or a == 1:
        B[a].append(b)
for sima in B[1]:
    if N in B[sima]:
        print('POSSIBLE')
        exit()
print('IMPOSSIBLE')


Measured memory_bytes: 77408
N = int(input())
A = list(map(int, input().split()))

mod = 0
for i in range(N):
    mod += A[i]%(10**9+7)

ans = (mod*mod)%(10**9+7)
for i in range(N):
    ans -= A[i]*A[i]
    ans = ans%(10**9+7)
ans = ans*pow(2, -1, 10**9+7)
ans = ans %(10**9+7)
print(ans)



Measured memory_bytes: 31436
//   PIGMEISTER™   //

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define sidha(i,x,n) for(ll i=(ll)(x);i<(ll)(n);++i)
#define ulta(i,x,n) for(ll i=(ll)(x);i>=(ll)(n);--i)
#define sab(a) a.begin(),a.end()
#define bas(a) a.rbegin(),a.rend()
#define test ll _;cin>>_;while(_--)
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD (ll)1000000007
//#define MOD (ll)998244353
#define MAX 100005

int main()
{
    jaldi;
    
    ll n, m;
    cin >> n >> m;
    map<ll, ll> adj[n+1];
    ll h[n];
    sidha (i, 0, n) cin >> h[i];
    ll a, b;
    sidha (i, 0, m) {
        cin >> a >> b;
        adj[a][h[b-1]]++;
        adj[b][h[a-1]]++;
    }

    ll ans = 0;
    sidha (i, 0, n) {
        adj[i+1][h[i]]++;
        auto it = adj[i+1].rbegin();
        if (it->first == h[i] and it->second == 1)
            ++ans;
    }

    cout << ans;
    
    return 0;
}


Measured memory_bytes: 27856
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
int main() {
    ll n, d, a;
    cin >> n >> d >> a;
    vector<pair<ll, ll>> xh(n);
    vector<ll> x(n), h(n);
    for(int i = 0; i < n; i++) {
        cin >> xh[i].first >> xh[i].second;
    }
    sort(all(xh));
    for(int i = 0; i < n; i++) {
        x[i] = xh[i].first;
        h[i] = xh[i].second;
    }
    ll ans = 0;
    ll ind = -1;
    ll nowdmg = 0;
    vector<ll> damage(n + 1, 0);
    for(int i = 0; i < n; i++) {
        nowdmg -= damage[i];
        h[i] -= nowdmg;
        if(h[i] <= 0) {
            continue;
        }
        ind = upper_bound(all(x), x[i] + 2 * d) - x.begin();
        ll num = (h[i] + a - 1) / a;
        ans += num;
        damage[ind] += num * a;
        nowdmg += num * a;
    }
    cout << ans << endl;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}

int main(){
    ll n, k;
    cin >> n >> k;
    vll a(n);
    rep(i, n) {
        cin >> a.at(i);
    }
    rep(i, n-k) {
        if(a[i] >= a[i+k]) {
            cout << "No" << endl;
        }
        else {
            cout << "Yes" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define EPS 0.0000000001
#define INF 1000000000
#define MOD 1000000007
typedef long long ll;

int main()
{
    ll s;
    cin>>s;
    if(s==10e18){
        cout<<0<<" ";
        cout<<0<<" ";

        cout<<1000000000<<" ";
        cout<<0<<" ";

        cout<<0<<" ";
        cout<<1000000000<<" ";
    }
    else{
        ll y1,y2;

        y2=(s+INF-1)/INF;
        y1=INF*y2-s;

        

        cout<<0<<" ";
        cout<<0<<" ";

        cout<<1000000000<<" ";
        cout<<y1<<" ";

        cout<<1<<" ";
        cout<<y2<<" ";
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn =1e5+50;
int a[maxn];
int ans=0;
int odd=0;
void solve()
{
    for(int i=1;i<maxn ;i++ )
    {
        if(a[i]>0)
            ans++;
        if(a[i]>=2&&a[i]%2==1)
            continue;
        if(a[i]>=2&&a[i]%2==0)
            odd++;
    }

}
int main()
{
    int n;
    cin>>n;
    int x;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        a[x]++;
    }
    solve();
    if(odd%2==1)
        ans--;
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 640
N = int(input())

def dfs(s, mx):
    if len(s) == N:
        print(s)
    else:
        c = 'a'
        while ord(c) <= ord(mx):
            if c == mx:
                dfs(s + c, chr(ord(mx) + 1))
            else:
                dfs(s + c, mx)
            c = chr(ord(c) + 1)

dfs('', 'a')

Measured memory_bytes: 4380
char m[102][102];

solve(c,i,j){
  m[i][j]=0;
  if(m[i][j-1]==c)solve(c,i,j-1);
  if(m[i-1][j]==c)solve(c,i-1,j);
  if(m[i+1][j]==c)solve(c,i+1,j);
  if(m[i][j+1]==c)solve(c,i,j+1);
}

main(){
  int w,h,i,j,r;
  for(;scanf("%d%d",&h,&w),h;printf("%d\n",r)){
    memset(m,0,sizeof(m));
    for(r=0,i=1;i<=h;i++)scanf("%s",m[i]+1);
    for(i=1;i<=h;i++)for(j=1;j<=w;j++)if(m[i][j])solve(m[i][j],i,j),r++;
  }
exit(0);}

Measured memory_bytes: 1392
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int N; ll K;
vector<ll> A,F;

bool check(ll x){
  // 成績をx以下にすることができるか
  // 乃ち、適切に修行を行えばA[i]*F[i]の最大値をx以下にすることができるか
  ll res = K; // 残り修行回数
  rep(i, N){
    // A[i] * F[i] <= x にしたい
    if (A[i] * F[i] <= x) continue;
    res -= A[i] - x/F[i];
  }
  return res >= 0;
}


int main() {
  cin >>N >>K;
  A.assign(N, 0); rep(i, N) cin >>A[i];
  F.assign(N, 0); rep(i, N) cin >>F[i];
  sort(all(A)); sort(allR(F));
  ll ok = 1000000000000, ng = -1;
  while (abs(ok-ng) > 1){
    ll mid = (ok+ng)/2;
    if (check(mid)) ok = mid;
    else ng = mid;
  }
  ll res = ok;
  cout <<res <<endl;
}

Measured memory_bytes: 3328
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

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

	while (cin >> N >> M >> K, N) {
		long double ans = 0;
		vector<int>v(N, 1);
		while (v[0] <= M) {
			int add = accumulate(v.begin(), v.end(), 0) - K;
			ans += max(add, 1);
			int cnt = N - 1;
			v.back()++;
			while (cnt > 0 && v[cnt] > M) {
				v[cnt--] = 1;
				v[cnt]++;
			}
		}
		ans /= pow(M, N);
		cout << fixed << setprecision(20) << ans << endl;
	}
}


Measured memory_bytes: 3460
#pragma warning (disable:4996)
#include<stdio.h>

int main(void) {
	char s[4], t[4];
	int count = 0;
	scanf("%s%s", s, t);
	for (int i = 0; i < 3; ++i) {
		if (s[i] == t[i]) {
			++count;
		}
	}
	printf("%d", count);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <queue>
using namespace std;

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

// (x, y) を始点とした BFS をして、(x, y) から最も遠いマスへの距離を答える
int bfs(const vector<string> &v, int x, int y) {
    int H = v.size(), W = v[0].size();
    vector<vector<int>> dist(H, vector<int>(W, -1));
    queue<pair<int,int>> que;

    int res = 0;
    que.push({x, y});
    dist[x][y] = 0;
    while (!que.empty()) {
        int x = que.front().first, y = que.front().second;
        res = max(res, dist[x][y]);
        que.pop();
        for (int dir = 0; dir < 4; ++dir) {
            int nx = x+ dx[dir], ny = y + dy[dir];
            if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
            if (v[nx][ny] == '#') continue;
            if (dist[nx][ny] == -1) {
                dist[nx][ny] = dist[x][y] + 1;
                que.push({nx, ny});
            }
        }
    }
    return res;
}

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> v(H);
    for (int i = 0; i < H; ++i) cin >> v[i];

    int res = 0;
    for (int x = 0; x < H; ++x) {
        for (int y = 0; y < W; ++y) {
            if (v[x][y] == '#') continue;
            res = max(res, bfs(v, x, y));
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n)   for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(long long i=(a);((a)<(b)?i<=(b):i>=(b));((a)<(b)?++i:--i))
#define ALL(v)     (v).begin(),(v).end()
#define debug(x)   cerr<<#x<<": "<<(x)<<endl
using namespace std;
using llong = long long;
using vi    = vector<int>;
using vvi   = vector<vi >;
using vvvi  = vector<vvi >;
using pii   = pair<int,int>;
constexpr int    INF=1e9;
constexpr double EPS=1e-9;
constexpr int    MOD=1e9+7;
template<class Type>
void line(const Type &a){int cnt=0;for(const auto &elem:a){cerr<<(cnt++?' ':'>');cerr<<elem;}cerr<<endl;}


int main(){
	int n;
	cin>>n;
	
	vector<llong> a(n);
	REP(i,n) cin>>a[i];
	
	llong sum=0LL;
	for(int i=1;i<n;++i){
		if(a[i-1]>a[i]){
			llong tmp=a[i-1]-a[i];
			sum+=tmp;
			a[i]+=tmp;
		}
	}
	
	cout<<sum<<endl;
}

Measured memory_bytes: 4784
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
std::vector<int> alpha[26];
std::string S, ans;
bool had[26];
int suff[200010];
int main() {
	std::cin >> S;
	int sf = 0;
	int ac = 1;
	for (int i = S.size() - 1; i >= 0; i--) {
		alpha[S[i] - 'a'].emplace_back(i + 1);
		suff[i + 1] = ac;
		if (!had[S[i] - 'a']) {
			had[S[i] - 'a'] = true;
			sf++;
		}
		if (sf == 26) {
			for (int j = 0; j < 26; j++)had[j] = false;
			sf = 0;
			ac++;
		}
	}
	for (int i = 0; i < 26; i++) {
		alpha[i].emplace_back(S.size() + 1);
		std::sort(alpha[i].begin(), alpha[i].end());
	}
	int now = 0;
	suff[0] = ac;
	for (int i = 1; i <= ac; ac--) {
		for (int j = 0; j < 26; j++) {
			auto it = std::upper_bound(alpha[j].begin(), alpha[j].end(), now);
			if (suff[now] - 1 == suff[*it]) {
				ans += ('a' + j);
				now = *it;
				break;
			}
		}
	}
	std::cout << ans << std::endl;
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    if (__builtin_popcount(N) == 1) {
        printf("No\n");
        return 0;
    }
    printf("Yes\n");
    
    if (N%2 == 1) {
        for (int i = 2; i <= N; i+=2) {
            printf("1 %d\n", i);
            printf("1 %d\n", i+1);
            printf("%d %d\n", i, N+i+1);
            printf("%d %d\n", i+1, N+i);
        }
        printf("%d %d\n", N+1, N+2);
    }else {
        for (int i = 2; i <= N-2; i+=2) {
            printf("1 %d\n", i);
            printf("1 %d\n", i+1);
            printf("%d %d\n", i, N+i+1);
            printf("%d %d\n", i+1, N+i);
        }
        printf("%d %d\n", N+1, N+2);
        int d = 1;
        while ((N&d) == 0) d <<= 1;
        printf("%d %d\n", N, d+1);
        printf("%d %d\n", N*2, N^d);
        
    }
    return 0;
}


Measured memory_bytes: 2304
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<string>
#include<vector>
#include<cctype>
using namespace std;

int main(){
vector<int>a;
int n,s=0,b=0;long sum=0;
cin>>n;int nnn;
if(n>0){
	for(int i=0;i<n;i++){cin>>nnn;a.push_back(nnn);}
		 s=a[0],b=a[0];
		for(int i=0;i<a.size();i++){
			sum+=a[i];
			b=max(b,a[i]);
			s=min(s,a[i]);
		}
	cout<<s<<" "<<b<<" "<<sum<<endl;
		}
	else{
		printf("%d %d %d\n",s,b,sum);
		}
return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0, sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int N; cin >> N;
    VI a(N); REP(i,N) cin >> a[i];
    VI ans(N+1,0);
    int M = 0;
    RREP(i,N){
        int tmp = 0;
        for(int j=i+i+2; j<=N; j+=i+1) tmp += ans[j];
        if(tmp%2 != a[i]){
            M++;
            ans[i+1] = 1;
        }
    }
    cout << M << en;
    REP(i,N) if(ans[i+1]) cout << i+1 << " ";
    cout << en;
    return 0;
}

Measured memory_bytes: 2432
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"

using namespace std;

//constexpr long long int MOD = 1000000007;
constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

int N, M, K, H, W, L, R;
//long long int N, M, K, H, W, L, R;



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

	string s, t;
	cin >> s >> t;
	N = s.size();
	s += s;
	vector<int>l(26, MOD);
	vector<vector<int>>nx(N, vector<int>(26));
	for (int i = 2 * N - 1; i >= N; i--) {
		l[s[i] - 'a'] = i;
	}
	for (int i = N - 1; i >= 0; i--) {
		for (int j = 0; j < 26; j++) {
			nx[i][j] = l[j];
		}
		l[s[i] - 'a'] = i;
	}
	long long int ans = l[t[0]-'a'];
	if (ans == MOD) {
		cout << -1 << endl;
		return 0;
	}
	for (int i = 1; i < t.size(); i++) {
		if (nx[ans%N][t[i] - 'a'] == MOD) {
			cout << -1 << endl;
			return 0;
		}
		ans += nx[ans%N][t[i] - 'a']-(ans%N);
	}
	ans++;
	cout << ans << endl;
}


Measured memory_bytes: 13804
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int popcount(int bits){
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int f(int n) {
    //cout << "f(" << n << ")" << endl;
    if (n == 0)
        return 0;
    return f(n % popcount(n)) + 1;
}

int main() {
    int n;
    string x;
    cin >> n >> x;
    
    int p = 0;
    for (int i = 0; i < n; i++)
        if (x[i] == '1')
            p++;
    
    if (p == 0) {
        for (int i = 0; i < n; i++)
            cout << 1 << endl;
        return 0;
    }
    if (p == 1) {
        for (int i = 0; i < n; i++) {
            if (x[i] == '1')
                cout << 0 << endl;
            else {
                if ((i != n-1 && x[n-1] == '1') || (i == n-1 && x[i] == '0'))
                    cout << 2 << endl;
                else
                    cout << 1 << endl;
            }
        }
        return 0;
    }
    
    int fp = x[0] - '0', fq = x[0] - '0';
    for (int i = 1; i < n; i++) {
        fp <<= 1;   fq <<= 1;
        fp += x[i] - '0';   fq += x[i] - '0';
        fp %= p+1;  fq %= p-1;
        //cout << "  " << fn << " " << fp << " " << fq << endl;
    }
    
    //cout << p << " | " << fn << " " << fp << " " << fq << endl;
    
    vector<int> p2(n);
    p2[0] = 1;
    for (int i = 1; i < n; i++) {
        p2[i] = p2[i-1] * 2;
        p2[i] %= p+1;
    }
    vector<int> q2(n);
    q2[0] = 1;
    for (int i = 1; i < n; i++) {
        q2[i] = q2[i-1] * 2;
        q2[i] %= p-1;
    }
    
    for (int i = 0; i < n; i++) {
        int fx;
        if (x[i] == '0') {
            fx = fp + p2[n-i-1];
            //cout << fp << " + " << p2[n-i-1] << " ";
            fx %= p+1;
        }
        else {
            fx = fq - q2[n-i-1];
            //cout << fq << " - " << q2[n-i-1] << " ";
            fx += p-1;
            fx %= p-1;
        }
        cout << f(fx)+1 << endl;
    }
        
    return 0;
}


Measured memory_bytes: 5236
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

#define NMAX 100000
#define MOD 1000000007
#define INF 2000000000

#define MIN(a, b) (a < b ? a : b)

using namespace std;

int n, k;

int main()
{
	cin >> n >> k;
	int maxPairs = (n - 1) * (n - 2) / 2;
	if (k > maxPairs)
	{
		cout << -1 << '\n';
	}
	else
	{
		int pairsToRemove = maxPairs - k;
		cout << n - 1 + pairsToRemove << '\n';
		for (int i = 1; i < n; i++)
			cout << i << ' ' << n << '\n';
		for (int i = 1; i < n && pairsToRemove > 0; i++)
			for (int j = i + 1; j < n && pairsToRemove > 0; j++)
			{
				cout << i << ' ' << j << '\n';
				pairsToRemove--;
			}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int a,b,c,p,ans=0;
  for(int i=0;i<1000;i++){
    a=i/100%10;
    b=i/10%10;
    c=i%10;
    p=0;
    for(int j=0;j<n;j++){
      if(p==0&&s[j]-'0'==a){
        p=1;
        continue;
      }
      if(p==1&&s[j]-'0'==b){
        p=2;
        continue;
      }
      if(p==2&&s[j]-'0'==c){
        ans++;
        break;
      }
    }
  }
  cout << ans;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int cnt = 0;

            for (int i = 0; i < n; i++)
            {
                int input = int.Parse(Console.ReadLine());

                if (IsPrime(input)) cnt++;
            }
            Console.WriteLine(cnt);
        }

        static bool IsPrime(int x)
        {
            if (x < 2) return false;
            if (x == 2) return true;
            if (x % 2 == 0) return false;

            int len = (int)Math.Sqrt(x);
            for (int i = 3; i <= len; i += 2)
            {
                if (x % i == 0) return false;
            }
            return true;
        }
    }
}

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

int main() {
    int H, W, A, B; cin >> H >> W >> A >> B;
    REP(i,H){
        REP(j,W){
            if((i<B&&j<A)||(i>=B&&j>=A)) printf("1");
            else printf("0");
        }
        printf("\n");
    }
}


Measured memory_bytes: 1280
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
if n%2==1:
    ans = 0
else:
    tmp = 2
    v2 = 0
    while n//tmp>0:
        v2 += n//tmp
        tmp *= 2
    v5 = 0
    tmp = 5
    nn = n//2
    while nn//tmp>0:
        v5 += nn//tmp
        tmp *= 5
    ans = min(v2, v5)
print(ans)

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

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

  int m1, d1, m2, d2;
  cin >> m1 >> d1 >> m2 >> d2;

  if (d2 == 1) cout << 1 << endl;
  else cout << 0 << endl;
  
  
  return 0;
}

Measured memory_bytes: 3636
n,k = map(int,input().split())
v = list(map(int,input().split()))
ans = 0
for a in range(min(n,k)+1):
    for b in range(min(n,k)-a+1):
        c = v[:a] + v[n-b:]
        c = sorted(c)
        for i in range(k-a-b):
            if len(c) == 0:
                break
            if c[0] < 0:
                c = c[1:]
            else:
                break
        ans = max(ans,sum(c))
print(ans)


Measured memory_bytes: 9088
n = int(input())
lh = [int(w) for w in input().split()]

cond = True
nh = lh[0]-1
for i in range(1, n):
    if lh[i] == nh:
        continue
    elif lh[i] > nh:
        nh = lh[i]-1
        continue
    else:
        cond = False
        break

print("Yes" if cond else "No")


Measured memory_bytes: 20588
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int MAX = 2e5+4;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n,k;
	cin >> n >> k;
	vector<int> a(n);
	for(int i=1;i<=n;i++)
	{
		cin >> a[i];
	}
	int dp[MAX];
	dp[1]=0;
	for(int i=2;i<=n;i++)
	{
		dp[i]=INT_MAX;
		for(int j=1;j<=k;j++)
		{
			if(i-j<=0) break;
			dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
		}
	}
	cout << dp[n];
	return 0;
}

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


void solve(long long N, long long M, std::vector<long long> X){
    sort(X.begin(), X.end());

    std::vector<long long> Y;
    for (int i = 0; i < X.size()-1; i++) {
        Y.push_back(X[i+1] - X[i]);
    }
    sort(Y.begin(), Y.end(), greater<long long>());
    long long s = 0;
    for (int i = N-1; i < Y.size(); i++) {
        s += Y[i];
    }

    printf("%lld\n", s);
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> X(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&X[i]);
    }
    solve(N, M, std::move(X));
    return 0;
}


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

#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++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    //経路１
    cout << string(tx - sx, 'R') << string(ty - sy, 'U');
    //経路２
    cout << string(tx - sx, 'L') << string(ty - sy, 'D');
    //経路３
    cout << "L" << string(ty - sy + 1, 'U') << string(tx - sx + 1, 'R') << "D";
    //経路４
    cout << "R" << string(ty - sy + 1, 'D') << string(tx - sx + 1, 'L') << "U";

    return 0;
}

/*int main()
{
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    char u = 'U', r = 'R', d = 'D', l = 'L';

    if (tx < sx && ty > sy)
        swap(r, l);
    else if (tx > sx && ty < sy)
        swap(u, d);
    else if (tx < sx && ty < sy)
    {
        swap(r, l);
        swap(u, d);
    }

    rep(i, abs(ty - sy)) cout << u;
    rep(i, abs(tx - sx)) cout << r;
    rep(i, abs(ty - sy)) cout << d;
    rep(i, abs(tx - sx)) cout << l;

    cout << d;
    rep(i, abs(tx - sx) + 1) cout << r;
    rep(i, abs(ty - sy) + 1) cout << u;
    cout << l;
    cout << u;
    rep(i, abs(tx - sx) + 1) cout << l;
    rep(i, abs(ty - sy) + 1) cout << d;
    cout << r;

    cout << endl;
    return 0;
}*/

Measured memory_bytes: 256