akhauriyash/Code-Regression huggingface dataset:
# Author: S Mahesh Raju
# Username: maheshraju2020
# Date: 31/07/2020

from sys import stdin,stdout
from math import gcd, ceil, sqrt
from collections import Counter
from bisect import bisect_left, bisect_right
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
mod = 1000000007

n, w = iia()
dp = [[0 for i in range(w + 1)] for j in range(n + 1)]
arr = []
for i in range(n):
    arr.append(iia())
for i in range(1, n + 1):
    for j in range(w + 1):
        if j < arr[i - 1][0]:
            dp[i][j] = dp[i - 1][j]
        else:
            dp[i][j] = max(dp[i - 1][j], arr[i - 1][1] + dp[i - 1][j - arr[i - 1][0]])
print(dp[-1][-1])

Measured memory_bytes: 172072
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <climits>
#include <vector>
#include <numeric>
#include <complex>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <set>
using namespace std;

#define __int64 long long
#define long __int64
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
const int Vec = 4;
const int Vecy[Vec] = {0,-1,0,1};
const int Vecx[Vec] = {1,0,-1,0};
const int Modd = 1000000007;

int main(){
	int a[3];
	int ans,maxd;
	
	cin >> a[0] >> a[1] >> a[2];
	
	maxd = max_element(a, a+3) - &a[0];
    
	if(a[maxd] % 2 == 0){
		cout << 0 << endl;
	}else{
		if(maxd == 0){
			cout << (long)a[1] * a[2] << endl;
		}else if(maxd == 1){
			cout << (long)a[0] * a[2] << endl;
		}else{
			cout << (long)a[0] * a[1] << endl;
		}
	}
	
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

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

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

vector<vector<vector<ll>>> left_table(const string &s) {
  auto res = table(26, 26, 0, 0LL);
  vector<ll> v = table(26, 0LL);
  for (char c: s) {
    int d = c - 'a';
    REP(i,26) {
      res[d][i].push_back(v[i]);
    }
    v[d]++;
  }
  return res;
}

void solve(string S) {
  auto lt = left_table(S);
  reverse(ALL(S));
  auto rt = left_table(S);
  ll res = 0;
  REP(i,26) REP(j,i) {
    const int len = lt[i][j].size();
    REP(k,len/2) {
      res += abs(lt[i][j][k] - rt[i][j][k]);
    }
    if (len % 2) {
      const ll d = abs(lt[i][j][len/2] - rt[i][j][len/2]);
      if (d % 2) { cout << -1 << endl; return; }
      res += d / 2;
    }
  }
  cout << res << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	string S;
	cin >> S;
	solve(S);
	return 0;
}


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


int main() {
    int n;
    cin >> n;
    int k =  (n + 999) / 1000;

    int result = k * 1000 - n;
    cout << result << endl;
}

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

int main()
{
	char n;
	int m=0;
	while(scanf("%c",&n)!=EOF)
	{
		if(n=='\n')
		break;
		m+=n-48;
		m%=9;
	}
	if(m==0)
	cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 3744
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
typedef pair<int,int> pp;
const int INF = 1001001001;
struct edge{int to, cost;};

int main() {
    int V;
    cin >> V;
    vector< vector<edge> > A(V);
    for(int i=0; i<V; i++) {
        int u,k;
        cin >> u >> k;
        A[u].resize(k);
        for(int j=0; j<k; j++) {
            int v,c;
            cin >> v >> c;
            struct edge e = {v,c};
            A[u][j] = e;
        }
    }

    vector<int> d(V,INF);
    d[0] = 0;
    priority_queue< pp, vector<pp>, greater<pp> > Q;
    Q.push(pp(d[0],0));
    
    while(!(Q.empty())) {
        pp temp = Q.top();
        Q.pop();
        int ct = temp.first;
        int u = temp.second;
        for(int j=0; j<A[u].size(); j++) {
            int v = A[u][j].to;
            int tmpcost = A[u][j].cost;
            if(d[v] > ct + tmpcost) {
                d[v] = ct + tmpcost;
                Q.push(pp(d[v], v));
            }
        }
    }

    for(int i=0; i<V; i++) cout << i << " " << d[i] << endl;
    return 0;
}


Measured memory_bytes: 6968
import sys
import numpy as np
from numba import jit
 
readline = sys.stdin.readline
 
@jit
def loop(n,k,a):
    for j in range(k):
        b = np.zeros(n+1, dtype=np.int64)
        for i in range(n):
            b[max(i-a[i], 0)] += 1
            b[min(i+a[i]+1, n)] -= 1
        a = np.cumsum(b)[:-1]
        if np.all(a==n):
            return(a)
            break
    else:
        return(a)
 
 
n, k = map(int, readline().split())
a = np.array(readline().split(), dtype=np.int64)
 
ans = loop(n,k,a)
print(*ans)

Measured memory_bytes: 126364
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    int p[n];
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    sort(p,p+n);
    long int sum=0;
    for(int i =0; i<k;i++)
        sum +=p[i];
    cout<<sum;
    return 0;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M,res=0,c;
  string str;
  cin >> N;
  vector<string>s(N);
  for (int i=0;i<N;i++){
    cin >> s.at(i);
  }
  cin >> M;
  vector<string>t(M);
  for (int i=0;i<M;i++){
    cin >> t.at(i);
  }
  for (int i=0;i<N;i++){
    c = 0;
    str = s.at(i);
    for (int j=0;j<N;j++){
      if (str==s.at(j)){
        c += 1;
      }
    }
    for (int j=0;j<M;j++){
      if (str==t.at(j)){
        c -= 1;
      }
    }
    if (c > res){
      res = c;
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    N = I()
    p = []
    for i in range(N):
        p.append(I())

    highest = max(p)
    del p[p.index(highest)]
    result = highest / 2 + sum(p)
    print(int(result))

main()


Measured memory_bytes: 5584
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
Mod = 1000000007




def main(): #startline--------------------------------------------
    N = int(input())
    H = list(map(int,input().split()))
    mav = 0
    for i in H:
        if mav <= i:
            mav = i
        elif mav - i >= 2:
            print("No")
            exit()
    print("Yes")

if __name__ == "__main__":
    main() #endline===============================================





def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n < 2 is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))):
        if prime[i] == 1:
            for j in range(2*i,n):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n):
        if prime[i] == 1:
            res.append(i)
    return res

class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py

    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

Measured memory_bytes: 16360
#include<stdio.h>
#include<math.h>
int main()
{
    int i,n,x[1001],y=0;
    double a=0,alpha,m;

    for(i=0;; i++)
    {
    scanf("%d",&n);
        if(n!=0)
        {
            a=0;y=0;
            for(i=0; i<n; i++)
            {
                scanf("%d",&x[i]);
                y=y+x[i];
            }
            m=(double)y/n;
    //printf("%.8lf\n",m);
    for(i=0;i<n;i++)
        a=a+((x[i]-m)*(x[i]-m));
    alpha=sqrt(a/n);
    printf("%.8lf\n",alpha);
    continue;
        }
        else if(n==0)
            break;
    }
    return 0;

}


Measured memory_bytes: 2040
#include<bits/stdc++.h>
#define U [7<<15]={}
#define G )+((c=A[a]+A[P[a]]+C[a])%k?c:0)-M(
typedef long long L;using namespace std;map<L,L>T U;L P U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U;L M(L f){return f?B[f]+M(f^f&-f):0;}L S(L a,L i){for(a=M(i++G i);i<2e5;i+=i&-i)B[i]+=a;}L D(L f){L d;for(map<L,L>::iterator I=T[f].begin();I!=T[f].end();I++)d=I->first,d-P[f]?P[d]=f,C[d]=I->second,D(d),Z[f]+=++Z[d],Z[H[f]]<Z[d]?H[f]=d:0:0;}L K(L f){a=X[f];n=X[b];return a-n?M(O[Z[a]>Z[n]?a=n,n=b,b=f,n:f]G O[a])+K(P[a]):abs(M(O[f])-M(O[b]));}main(){for(cin>>n>>k;--*Z+n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;for(D(n=0);Z[a=H[P[n]]-n?n:0];*Z=++n)for(;!O[a];S(a=H[a],O[a]=++b))X[a]=n;for(cin>>a;cin>>s>>a>>b;S(H[a],O[a]),S(a,O[a]-1))*s&2?cout<<K(a)<<endl,0:A[a]+=b;}

Measured memory_bytes: 37300
from collections import deque
n, m = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(m):
    u, v = map(int, input().split())
    graph[u-1].append(v-1)
s, t = map(int, input().split())
s -= 1
t -= 1
q = deque([s])
INF = 10**10
dist = [[INF]*3 for _ in range(n)]
dist[s][0] = 0
while q:
    node = q.popleft()
    for c_node in graph[node]:
        flg = False
        for i in range(3):
            nd = dist[node][i]+1
            if dist[c_node][nd%3] > nd:
                dist[c_node][nd%3] = nd
                flg = True
        if flg:
            q.append(c_node)
if dist[t][0]==INF:
    print(-1)
else:
    print(dist[t][0]//3)

Measured memory_bytes: 42584
import java.io.IOException;
import java.util.Scanner;

public class Main {
    public static void main (String args[]) throws IOException {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int M = sc.nextInt();
    	int y;

    	int[][] a = new int[N][M];
    	int[] c = new int[M] ;
    	//Arrays.fill(c, "");

    	for(int i=0;i<N;i++){
    	   for(int p=0;p<M;p++){
    		   int z = sc.nextInt();
    	      a[i][p] = z;
    	   }
    	}

        for(int p=0;p<M;p++){
        	int z = sc.nextInt();
    	      c[p] = z;
    	 }

        for(int i=0;i<N;i++){
           y =0;
    	   for(int p=0;p<M;p++){
    	     y += a[i][p] * c[p];

    	   }
    	   System.out.println(y);
    	}
    }
}

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

int main() {
    int n, m, ans=0;
    cin >> n >> m;
    ans+=(n-m)*100;
    ans+=1900*m;
    for(int i=1; i<=m; i++) {
        ans*=2;
    }
    cout << ans;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		//int a=scan.nextInt();
		int b=scan.nextInt();
		int c=scan.nextInt();
		//int d=scan.nextInt();
		//int f=scan.nextInt();
		String str=scan.next();
		boolean bool=false;
		String ans="";
		for(int i=0;i<str.length();i++) {
			char ch=str.charAt(i);
			if(i+1==c) {
				ch=(char) (ch-'A'+'a');
			}
			ans+=ch;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn count(aa: &Vec<u64>, n: usize) -> Vec<Vec<usize>> {
    let mut dp = vec![vec![0; 16]; n+1];
    for i in 0..16 {
        dp[n-1][i] = i;
    }
    for i in (0..n-1).rev() {
        for p in 0..16 {
            let a1 = aa[i]*4u64.pow(p as u32);
            let mut a2 = aa[i+1];
            let mut x = 0;
            while a2 < a1 {
                x += 1;
                a2 *= 4;
            }
            let p = p as usize;
            let x = x as usize;
            if x < 16 {
                dp[i][p] = dp[i+1][x] + p;
            } else {
                dp[i][p] = dp[i+1][15] + p + (x - 15) * (n-i-1);
            }
        }
    }
    dp
}

fn main() {
    input!{
      n: usize,
      aa: [u64; n],
    }

    let dp = count(&aa, n);
    let mut aa = aa;
    aa.reverse();
    let dp2 = count(&aa, n);

    let mut ans: usize = 1 << 60;
    for i in 0..n+1 {
        let c1 = dp[i][0] * 2;
        let c2 = dp2[n-i][0] * 2 + i;
        ans = min(c1+c2, ans);
    }
    println!("{}", ans);
}


Measured memory_bytes: 67836
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int len,n;
  vector<string> u;
  list<string> a;
  cin>>n;
  for(i=0;i<n;i++){
    string s;
    cin>>s;
    u.push_back(s);
  }
  for(i=0;i<n;i++){
    a.clear();
    a.push_back(u[i].substr(0,1));
    len=u[i].length();
    for(j=1;j<len;j+=3){
      if(u[i][j+1]=='>'){
	if(u[i].substr(j-1,1)==a.back())
	  a.push_back(u[i].substr(j+2,1));
      }else if(u[i][j]=='<'){
	if(u[i].substr(j-1,1)==a.front())
	  a.push_front(u[i].substr(j+2,1));
      }
    }
    list<string>::iterator it=a.begin();
    for(;it!=a.end();it++)
      cout<<*it;
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main(){
  string S;
  cin >> S;

  int num[10] = {};
  int k;

  cin >> k;
  int ans = 0;
  int count = 0;

  for(int i = 0; i < S.size(); i++){
    if(S[i] != '1') break;

    count++;
  }

  if(S.size() == 1){
    S.c_str();
    cout << S[0] << endl;
  }
  else if(k <= count) cout << 1 << endl;
  else{
    S.c_str();
    cout << S[count] << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int ar[200004],br[200004];
string s;
map<ll,ll>mp,mp1;
vector<ll>vc;
vector<ll>::iterator it;
ll  c,c1;
ll i,j,k,l,x,sum,cnt;
int main()
{
    int a=0,t;
    cin>>a;
    sum+=a/500;
    a%=500;
    cnt=sum*1000;
    sum=a/5;
    cnt+=sum*5;
    cout<<cnt<<endl;



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

struct mint {
  ll x;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

mint factorial(ll n) {
  mint answer = 1;
  while (n > 1) {
    answer *= n;
    n--;
  }
  return answer;
}

mint combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

mint permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

// setprecision(8) 桁数指定
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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

template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
// for (auto p : prime_factor(n)) {
//	while (p.second--) {
//		cout << p.first << endl;
//	}
//}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

vector<ll> Eratosthenes(const ll N) {
  bool is_prime[1000000 + 1];
  vector<ll> P;
  for (ll i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  for (ll i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (ll j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      P.emplace_back(i);
    }
  }
  return P;
}

typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

int main() {
  ll h, n;
  cin >> h >> n;
  ivec a(n);
  REP(i, n) cin >> a[i];
  bool flag = true;
  REP(i, n) { h -= a[i]; }

  cout << (h <= 0 ? "Yes" : "No") << endl;
  return 0;
}

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

const ll MOD = 1e9 + 7;

ll factorial(ll n, ll m = 2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i = m; i <= n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

int main() {
    int n;
    cin >> n;
    vector<ll> x(n);
    rep(i, n) cin >> x[i];

    ll ans = 0;
    ll factor = factorial(n - 1);
    ll running = factor;
    for (int i = 0; i < n - 1; i++) {
        ll d = x[i + 1] - x[i];
        ans += (running % MOD) * (d % MOD);
        ans %= MOD;
        running += (factor * modinv(i + 2, MOD)) % MOD;
    }
    cout << ans << endl;
}

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

namespace abc161
{
    class Program
    {
        static void Main(string[] args)
        {
            var abcd= Console.ReadLine().Split().Select(s=>int.Parse(s)).ToArray();
            
            int tcnt = 0;
            for (int i = 0; ; i++)
            {
                if (abcd[0] <= 0) break;
                else
                {
                    abcd[0] -= abcd[3];
                    tcnt++;
                }
            }
            int acnt = 0;
            for (int i = 0; ; i++)
            {
                if (abcd[2] <= 0) break;
                else
                {
                    abcd[2] -= abcd[1];
                    acnt++;
                }
            }
            var ans = tcnt >= acnt ? "Yes" : "No";
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 28148
//Author: Suifeng0214
//2020.6.30 19.03
#include <bits/stdc++.h>
#define int long long
using namespace std;
int dp[100010];
int arr[100010];
signed main()
{
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++){
		cin >> arr[i];
	}
	dp[0] = 0;
	for (int i = 1; i < k; i++){
		dp[i] = abs(arr[i] - arr[0]);
	}
	for (int i = k; i < n; i++){
		dp[i] = dp[i-1] + abs(arr[i-1] - arr[i]);
		for (int j = 2; j <= k; j++){
			dp[i] = min(dp[i-j] + abs(arr[i-j] - arr[i]), dp[i]);
		}
	}
	cout << dp[n-1];
} 

Measured memory_bytes: 5092
#include <bits/stdc++.h>
#define MAX 100005
#define ll long long
#define upperlimit 1000100
#define INF 1e18
#define eps 1e-8
#define endl '\n'
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define MOD 1000000007
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define clr(a) memset(a,0,sizeof(a))
#define debug(a) printf("check%d\n",a)
#define csl ios::sync_with_stdio(false);cin.tie(0);
#define fi(a,b,c) for(int i=a;i<b;i=i+c)
#define fj(a,b,c) for(int j=a;j<b;j+=c)
using namespace std;
 
ll gcd(ll n1,ll n2) {
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent) {
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%MOD;
		base=(base*base)%MOD;
		exponent/=2;
	}
	return ans;
}
ll max(ll a,ll b,ll c) {
	return max(a,max(b,c));
}
int max(int a,int b,int c) {
	return max(a,max(b,c));
}

int main()
{
	int n;
	sd(n);
	int d[n][2];
	fi(0,n,1){
		sd(d[i][0]);
		sd(d[i][1]);
	}
	bool t=0;
	fi(0,n-2, 1){
		if(d[i][1]==d[i][0] && d[i+1][1] ==d[i+1][0] && d[i+2][1]==d[i+2][0]){
			t=1;
		}
	}
	if(t==1){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
}

Measured memory_bytes: 3680
//22
//write 25min
//check 5min
//sample 6min mbug1
#include<cstdio>
#include<algorithm>
using namespace std;

const int maxn = 601;
const int lbt = 1e9 + 7;

int n, k;
int a[maxn], b[maxn];
int match[maxn];
int minl[maxn][maxn], maxr[maxn][maxn];
int f[maxn][maxn];
int g[maxn][maxn], dp[maxn][maxn];
int xs[maxn];

int main() {
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= k; i++) {
		scanf("%d%d", &a[i], &b[i]);
		match[a[i]] = b[i];
		match[b[i]] = a[i];
	}
	for (int l = 1; l <= 2 * n; l++) {
		minl[l][l] = 2 * n + 1;
		if (match[l]) {
			minl[l][l] = min(minl[l][l], match[l]);
			maxr[l][l] = max(maxr[l][l], match[l]);
		}
		for (int r = l + 1; r <= 2 * n; r++) {
			minl[l][r] = minl[l][r - 1];
			maxr[l][r] = maxr[l][r - 1];
			if (match[r]) {
				minl[l][r] = min(minl[l][r], match[r]);
				maxr[l][r] = max(maxr[l][r], match[r]);
			}
		}
	}
	for (int l = 1; l <= 2 * n; l++) {
		for (int r = l - 1; r <= 2 * n; r++) {
			for (int i = 0; i <= n; i++) {
				dp[r][i] = 0;
			}
		}
		dp[l - 1][0] = 1;
		for (int r = l; r <= 2 * n; r++) {
			if (match[r]) {
				for (int i = 0; i <= n; i++) {
					dp[r][i] = dp[r - 1][i];
				}
				continue;
			}
			for (int i = 1; i <= n; i++) {
				dp[r][i] = (dp[r][i] + dp[r - 1][i - 1]) % lbt;
			}
			for (int i = 0; i < n; i++) {
				dp[r][i] = (dp[r][i] + (long long)(i + 1) * dp[r - 1][i + 1]) % lbt;
			}
		}
		for (int r = l; r <= 2 * n; r++) {
			g[l][r] = dp[r][0];
			if (minl[l][r] < l || maxr[l][r] > r) g[l][r] = 0;
		}
	}
	for (int l = 1; l <= 2 * n; l++) {
		for (int r = l; r <= 2 * n; r++) {
			f[l][r] = g[l][r];
			for (int i = l; i < r; i++) {
				f[l][r] = (f[l][r] + (long long)(lbt - f[l][i]) * g[i + 1][r]) % lbt;
			}
		}
	}
	xs[0] = 1;
	for (int i = 1; i <= n; i++) {
		xs[i] = (long long)(2 * i - 1) * xs[i - 1] % lbt;
	}
	int ans = 0;
	for (int l = 1; l <= 2 * n; l++) {
		for (int r = l; r <= 2 * n; r++) {
			int cnt = 0;
			for (int i = 1; i < l; i++) {
				cnt += !match[i];
			}
			for (int i = r + 1; i <= 2 * n; i++) {
				cnt += !match[i];
			}
			ans = (ans + (long long)f[l][r] * xs[cnt / 2]) % lbt;
		}
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    string S, T;
    cin >> S >> T;
    vector<int> start(26, -1);
    vector<int> goal(26, -1);
    for(int i = 0; i < S.size(); i++) {
        int a = S[i] - 'a';
        int b = T[i] - 'a';

        if(start[a] != -1 || goal[b] != -1) {
            if(start[a] != b || goal[b] != a) {
                cout << "No" << endl;
                return 0;
            }
        }
        else {
            start[a] = b;
            goal[b] = a;
        }
    }

    cout << "Yes";

    cout << endl;
    return 0;
}

Measured memory_bytes: 776
import bisect

N, K = map(int, input().split())
x = list(map(int, input().split()))

ub = bisect.bisect(x, 0)
result = 10 ** 9
for left in range(min(K, ub), -1, -1):
    right = K - left
    if right > N - ub:
        break
    if left > 0:
        left_time = -x[ub - left]
    else:
        left_time = 0
    if right > 0:
        right_time = x[ub + right - 1]
    else:
        right_time = 0
    left_right = 2 * left_time + right_time
    right_left = 2 * right_time + left_time
    result = min(result, min(left_right, right_left))
print(result)

Measured memory_bytes: 14480
import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String[] nm = br.readLine().split(" ");
        int n = Integer.parseInt(nm[0]);
        int m = Integer.parseInt(nm[1]);

        System.out.println((1900*m + 100*(n-m)) * (int)Math.pow(2, m));
    }
}





Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
  int n;
  ll k;
  cin >> n >> k;
  vector<int> a(n);
  vector<int> f(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> f[i];
  sort(a.begin(), a.end());
  sort(f.rbegin(), f.rend());
  ll l = -1, r = 1e12;
  while (l+1<r) {
    ll c = (l+r)/2;
    bool ok = [&]{
      ll s = 0;
      rep(i,n) {
        s += max(0ll, a[i]-c/f[i]);
      }
      return s <= k;
    }();
    if (ok) r = c; else l = c;
  }
  cout << r << endl;
  return 0;
}

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

int main(){
  int64_t s;
  cin>>s;
vector<int64_t> vec(87);
 vec.at(0)=2;
  vec.at(1)=1;
  for(int64_t i=2;i<87;i++){
  vec.at(i)=vec.at(i-1)+vec.at(i-2);
  }
  cout<<vec.at(s)<<endl;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    int H, W;
    cin >> H >> W;
    vector<vector<int>> c(10, vector<int> (10));
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> c[i][j];
        }
    }

    for (int k = 0; k < 10; k++) {
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }

    vector<int> a(10, 0);
    int tmp;
    for (int i = 0; i < H*W; i++) {
        cin >> tmp;
        if(tmp == -1) continue;
        a[tmp]++;
    }

    ll ans = 0;
    for (int i = 0; i < 10; i++) {
        ans += c[i][1] * a[i];
    }

    // for (int i = 0; i < 10; i++) {
    //     printf("%d %d\n", c[i][1], a[i]);
    // }
    printf("%lld\n", ans);
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
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; }
const ll MOD = 1e9+7;

const ll INF = LLONG_MAX;
const int MAX_V = 100010;

vector<pair<int, ll> > G[MAX_V];
vector<ll> d;

typedef pair<ll, int> P;

void dijkstra(int s, int V){
    d.resize(V, INF);
    d[s] = 0;
    priority_queue<P, vector<P>, greater<P> > que;
    que.push(make_pair(0, s));
    while(!que.empty()){
        auto p = que.top();
        que.pop();
        ll c = p.first;
        int a = p.second;
        if(d[a] < c) continue;
        for(auto&& p : G[a]){
            int b = p.first;
            ll cc = p.second;
            if(d[b] > c + cc){
                d[b] = c + cc;
                que.push(make_pair(d[b], b));
            }
        }
    }
}

int main(){
    ll N, M;
    cin >> N >> M;
    REP(i,M){
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(make_pair(b,1));
        G[b].push_back(make_pair(a,1));
    }

    dijkstra(0, N);

    vector<ll> ANS(N);
    bool valid = true;
    for(int v = 1; v < N; v++){
        ll dist = d[v];
        ll ans = -1;
        for(auto&& p : G[v]){
            ll tmp = d[p.first];
            if(tmp == dist - 1){
                ans = p.first;
                break;
            }
        }

        if(ans == -1)
            valid = false;
        ANS[v] = ans+1;
    }

    if(!valid)
        cout << "No" << endl;
    else{
        cout << "Yes" << endl;
        for(int v = 1; v < N; v++){
            cout << ANS[v] << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 18684
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<queue>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int n;
int a[100];
void cf(int x)
{
    for(int i=2;x!=1;i++)
    {
        while(x%i==0)
        {
            a[i]++;
            x/=i;
        }

    }
}
int main()
{
    while(~scanf("%d",&n))
    {
        memset(a,0,sizeof(a));
        for(int i=2;i<=n;i++)
        {
            cf(i);
        }
        int $74=0,$2_23=0,$24=0,$4_13=0,$14=0,$2_3=0,$4=0;
        for(int i=0;i<100;i++)
        {
            if(a[i]>=74) $74++;
            if(a[i]>=2&&a[i]<=23) $2_23++;
            if(a[i]>=24) $24++;
            if(a[i]>=4&&a[i]<=13) $4_13++;
            if(a[i]>=14) $14++;
            if(a[i]>=2&&a[i]<=3) $2_3++;
            if(a[i]>=4) $4++;
        }
        printf("%d\n",$74+$2_23*$24+$24*($24-1)+$4_13*$14+$14*($14-1)+$2_3*$4*($4-1)/2+$4*($4-1)*($4-2)/2);

    }
    return 0;
}


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


def solve(N: int, M: int, s: "List[int]", c: "List[int]"):
    num = []
    for _ in range(N):
        num.append(-1)

    for i, j in zip(s, c):
        if num[i-1] < 0:
            num[i-1] = j
        elif num[i-1] == j:
            pass
        else:
            print(-1)
            return

    if num[0] == 0:
        if N == 1:
            print(0)
            return
        else:
            print(-1)
            return

    ret = []
    for i in range(N):
        if num[i] >= 0:
            ret.append(num[i])
        else:
            if i == 0:
                if N == 1:
                    print(0)
                    return
                else:
                    ret.append(1)
            else:
                ret.append(0)

    num = 0
    for i in range(N):
        num += ret[i] * 10 ** (N - i - 1)
    print(num)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    s = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        s[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, M, s, c)

if __name__ == '__main__':
    main()


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

struct Node {
  int key;
  struct Node *right, *left, *parent;
};

struct Node *root, *NIL;

struct Node *find(struct Node *, int);
void insert(int);
void print_i(struct Node *);
void print_p(struct Node *);

int main(){
  int n, i, x, k;
  struct Node *t;
  char com[20];
  scanf("%d", &n);

        for(i = 0 ; i < n ;i++){
                scanf("%s", com);
                if(strcmp(com, "insert") == 0){
                        scanf("%d", &x);
                        insert(x);
                }else if(strcmp(com, "print") == 0){
                        print_i(root);
                        printf("\n");
                        print_p(root);
                        printf("\n");
                }else{
                  scanf("%d", &x);
                  t = find(root, x);
                  if(t != NIL)printf("yes\n");
                  else printf("no\n");
                }
        }

  return 0;
}

struct Node *find(struct Node *u, int k){
  while(u != NIL && k != u->key){
    if(k < u->key)u = u->left;
    else u = u->right;
  }
  return u;
}

void insert(int k){
  struct Node *y = NIL;
  struct Node *x = root;
  struct Node *z;

  z = malloc(sizeof(struct Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
          y = x;
          if(z->key < x->key){
                x = x->left;
          }else{
                x = x->right;
          }
  }

  z->parent = y;

  if(y == NIL)
          root = z;
  else if(z->key < y->key)
          y->left = z;
  else
          y->right = z;
}

void print_i(struct Node *x){
        if(x == NIL)return;
        print_i(x->left);
        printf(" %d", x->key);
        print_i(x->right);
}

void print_p(struct Node *x){
        if(x == NIL)return;
        printf(" %d", x->key);
        print_p(x->left);
        print_p(x->right);
}



Measured memory_bytes: 20452
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;

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 (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

int main() {
    ll A,B,K;
    cin>>A>>B>>K;
    if(A<K){
        cout<<0<<" "<<max(B-(K-A),0ll)<<endl;
    }else {
        cout<<A-K<<" "<<B<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <list>
#define MOD 1000000007
#define INF 1000000000
typedef long long ll;
using namespace std;
typedef pair<int,int> P;

int main(void){
    int n;
    cin>>n;
    int a,b,c,d;
    d=n%10;
    n/=10;
    c=n%10;
    n/=10;
    b=n%10;
    n/=10;
    a=n%10;
    int tmp=0;
    int i,j,k;
    for(i=0;i<2;i++){
        for(j=0;j<2;j++){
            for(k=0;k<2;k++){
                if(i==0){
                    tmp=a+b;
                }else{
                    tmp=a-b;
                }
                if(j==0){
                    tmp+=c;
                }else{
                    tmp-=c;
                }
                if(k==0){
                    tmp+=d;
                }else{
                    tmp-=d;
                }
                if(tmp==7)goto End;
                else tmp=0;
            }
        }
    }
End:
    string res="";
    if(i==0)res+="+";
    else res+="-";
    if(j==0)res+="+";
    else res+="-";
    if(k==0)res+="+";
    else res+="-";
    printf("%d%c%d%c%d%c%d=7\n",a,res[0],b,res[1],c,res[2],d);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x, y;
  cin >> x >> y;
  int kame, turu;
  for(int i=0; i<=x; ++i){
    kame = x - i;
    turu = i;
    if(kame * 4 + turu * 2 == y){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No"<< endl;
  return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#define N_MAX 100
#include <string>
using namespace std;

int N,A,B,i,j,k;
string S;
int a[N_MAX];
int num[N_MAX] = {0};
int ans=0;
int r,g,b;

int main(){
  cin >> N;
  A = 1;
  while (A*2 <= N){
    A*=2;
  }
  cout << A << endl;
}

Measured memory_bytes: 256
import java.io.*;

class Main {
  public static void main(String[] args)throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str = br.readLine();
    
    String[] strAry = str.split(" ");
    
    int x = Integer.parseInt(strAry[0]);
    int y = Integer.parseInt(strAry[1]);
    
    System.out.println(x*y + " " + 2*(x+y));
  }
}

Measured memory_bytes: 24252
#include <bits/stdc++.h>
#define PI 3.1415926535897932
#define _GLIBCXX_DEBUG
using namespace std;
long long GCD(long long A,long long B){
  if(B==0){
    return A;
  }
  else{
    return GCD(B,A%B);
  }
}
int main() {
  
  int D,T,S;
  cin>>D>>T>>S;
  
  if((double)D/S<=T){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
 
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mp make_pair
#define y1 my_y1
#define fi first
#define se second
#define lcm mylcm
 
using namespace std;
 
const ll mod = 1e9 + 7;
const ll inf = 1e15;
const int N = 1e5 + 5;

ll n, m, w[N], v[N], sum, dp[105][N];

int main () {
	//freopen("a.out", "w", stdout);
    cin.tie(NULL);
	cout.tie(NULL);
	ios_base::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> w[i] >> v[i];
		sum += v[i];
	}
	for (int i = 0; i <= n; i++) {
		for (int j = 1; j <= sum; j++) dp[i][j] = inf;
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= sum; j++) {
			dp[i][j] = dp[i - 1][j];
			if (j >= v[i]) {
				dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
			}
			//cout << dp[i][j] << ' ';
		}
		//cout << endl;
	}
	for (int i = sum; i >= 0; i--) {
		//cout << dp[n][i] << endl;
		if (dp[n][i] <= m) {
			cout << i;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 80128
#include<stdio.h>
int main()
{
  int a,b,c,d,p,totalx,totaly;
  scanf("%d\n %d\n %d\n %d\n %d",&a,&b,&c,&d,&p);

  if(c<p){
    totaly=b+(p-c)*d;

      }else{
    totaly=b;
  }

  totalx=a*p;
  if(totaly<totalx){
    printf("%d\n",totaly);

  }else{
    printf("%d\n",totalx);
  }
  return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<string>
using namespace std;
int main()
{
  int n,m,i,j;
  string s,t;
  cin >> s >> t;
  n=s.size();
  m=t.size();
  for(i=n-m;i>=0;i--){
    for(j=0;j<m;j++)
      if(t[j]!=s[i+j] && s[i+j]!='?')
        break;
    if(j==m)
      break;
  }
  if(i<0){
    cout << "UNRESTORABLE" << endl;
  }else{
    for(j=0;j<n;j++){
      if(s[j]!='?')
        cout << s[j];
      else if(j<i || j>=i+m)
        cout << 'a';
      else
        cout << t[j-i];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
li = [0 for i in range(n)]
for i in range(k):
  a = int(input())
  li_a = list(map(int, input().split()))
  for j in range(a):
    li[li_a[j]-1] += 1
ans = 0
for x in li:
  if x == 0:
    ans += 1
print(ans)


Measured memory_bytes: 9184
// kill it - Abhinav IIITA
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define f(i,x,n) for(int i=x;i<n;++i)


// -----------------------------------------------------------------------


void solve(){	
	int n,k; cin>>n>>k;
	map<int,int> mp;
	while(k--){
		int d; cin>>d;
		while(d--){
			int x; cin>>x;
			mp[x]++;
		}
	}
	int ans=0;
	f(i,1,n+1)
	if(mp[i]==0) ans++;
	cout<<ans;
}

// -----------------------------------------------------------------------


int32_t main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); 	
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}


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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var dict = new Dictionary<string, bool>();

            for (var i = 0; i < n; i++)
            {
                var t = Console.ReadLine().Split();
                if (t[0] == "insert") dict[t[1]] = true;
                else
                {
                    if (dict.ContainsKey(t[1])) Console.WriteLine("yes");
                    else Console.WriteLine("no");
                }
            }
        }
    }
}



Measured memory_bytes: 44928
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1 {
    class Program {
        static void Main(string[] args) {
            //******Q4 To Infinity　class 使用**************
            //Sは数値の文字列　1>=　<=100
            //Kは何文字目を表す数値
            string s = Console.ReadLine();
            long k = long.Parse(Console.ReadLine());
            infinity Infinity = new infinity();
            Console.WriteLine(Infinity.ans(s, k));
          //  Console.ReadLine();



            //******Q3 105　class Divisor******************
            //int a = int.Parse(Console.ReadLine());
            //Divisor divisor = new Divisor();
            //int ans = divisor.Q3(a);
            //Console.WriteLine(ans );
            //******Q3 105 ここまで**********************
        }
        private static string Q1() {//練習問題
            //          a
            //          b c（bとcの間はスペース）
            //          s
            //          という入力値（改行されている）　abcは数値　sは文字列
            //　　これを　a+b+c sの形で出力せよ
            // 　　a=3.b=12,c=20 s="miho" なら　出力は　"35 miho"
            int a = int.Parse(Console.ReadLine());
            string[] bc = Console.ReadLine().Split(' ');

            int b = int.Parse(bc[0]);
            int c = int.Parse(bc[1]);
            string s = Console.ReadLine();
            return ((a + b + c) + " " + s);
        }
        private static int Q2() {//garden
            string[] ab = Console.ReadLine().Split(' ');
            int a = int.Parse(ab[0]);
            int b = int.Parse(ab[1]);
            return ((a - 1) * (b - 1));
        }
    
    }
   class infinity {
        public char ans(string s,long k) {
            char[] chars = s.ToCharArray();
            if (chars[0] != '1') return chars[0];
            long a = leftcnt1(s);
            if (a >= k) {
                return '1';
            }
            else { //  a < k
                return chars[a ];
            }
        }
        private long leftcnt1(string s) {
            char[] chars = s.ToCharArray();
            for (long i = 0; i < s.Length-1; i++) {
                if (chars[i] != '1') return i ;
            }
            return 0;
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <climits>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string.h>
#include <iomanip>
#include <ctype.h>

#define ll          long long int
#define ull         unsigned long long int
#define pb          push_back
#define pii         pair<int,int>
#define F         first
#define S          second
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
#define hell        1000000007
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 1e9
#define all(a)      (a).begin(),(a).end()
const long long INF = (long long) 1e18+2;


using namespace std;
void solve();

void fastIO() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

int main(){
   fastIO();
    solve();
}
//void sieve();
ll pw(ll k,ll x);
ll gcd(ll x,ll y);

void solve(){

  int n,w;
  cin>>n>>w;
  int wt[n];
  ll val[n];

  forn(i,0,n){
    cin>>wt[i]>>val[i];
  }
  ll dp[w+1][n+1];
  memset(dp,0,sizeof(dp));
  for(int i=1;i<=w;i++){
    for(int j=1;j<=n;j++){
      dp[i][j]=max(dp[i][j],dp[i][j-1]);
      if(i>=wt[j-1])
      dp[i][j]=max(dp[i][j],dp[i-wt[j-1]][j-1]+val[j-1]);
    }
  }
  cout<<dp[w][n];
}


///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1

ll gcd(ll x,ll y){
  if(x==0)
  return y;
  else
  return gcd(y%x,x);
}


ll pw(ll k,ll x){
  if(x==0)
  return 1;
  if(x&1)
  return ((pw(k,x-1)%hell)*k%hell)%hell;
  else
  return ((pw(k,x/2)%hell)*(pw(k,x/2)%hell))%hell;
}

/*void sieve(){

  for(int i=2;i<=1000000;i++){
    if(prime[i]==true){
      for(int j=i*i;j<=1000000;j+=i)
      prime[j]=false;
    }
  }

}*/


Measured memory_bytes: 79232
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 
void Main()
{
    int n;
    int k;
    int q;
    cin >> n;
    cin >> k;
    cin >> q;
    vector<int> a(q);
    vector<int> b(n);
    vector<int> c(n);
    REP(i, q)
    cin >> a[i];
  
  
    
    
  for(int i = 0; i < n; i++){
    b[i] = k - q;
    c[i] = 0;
  }
    
  for(int i = 0; i < q; i++){
    c[a[i]-1] += 1;
  }
  
  for(int j = 0; j < n; j++){
        b[j] = b[j] + c[j];
  }
  
  for(int i = 0; i < n; i++){
    if(b[i] <= 0){
      printf("No\n");
    }
    else
      printf("Yes\n");
  }
}
 
int main()
{
    std::cout << std::fixed << std::setprecision(15);
    Main();
}

Measured memory_bytes: 1792