akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
import java.math.BigDecimal;
import java.nio.file.Files;
import java.nio.charset.StandardCharsets;
public class Main {
    int mod = 998244353;
    Integer[][] memo;
    public void sol(int[] arr,int n,int s) {
        memo = new Integer[n+1][s+1];
        System.out.println(dp(0,0,arr,s));
    }

    int dp(int i, int sum, int[] arr,int s){
        if(i==arr.length){
            return sum==s?1:0;
        }
        if(sum>s) return 0;
        if(memo[i][sum]!=null) return memo[i][sum];
        int res = 0;
        res = dp(i+1,sum,arr,s)*2;
        res%=mod;
        res+= dp(i+1,sum+arr[i],arr,s);
        res%=mod;
        return memo[i][sum] = res;
    }



    public static void main(String[] args)  throws IOException {
        // Use the Scanner class
        Main aka = new Main();
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] ss = br.readLine().split(" ");
        int N = Integer.parseInt(ss[0]);
        int S = Integer.parseInt(ss[1]);
        int[] arr = new int[N];
        ss = br.readLine().split(" ");
        for(int i=0;i<N;i++){
            arr[i] = Integer.parseInt(ss[i]);
        }
        //int tot = Integer.parseInt(br.readLine());

        aka.sol(arr,N,S);
//        int i =1;
//        System.out.println();
//        while(tot>0){
//
//            String s = br.readLine();
//            String[] sr = s.split(" ");
//            List<Long> ls = new ArrayList<>();
//            for(String ss:sr){
//                ls.add(Long.parseLong(ss));
//            }
//            Main tt = new Main();
//            tt.sol(ls);
//            // String Buffer to store answer
//            StringBuffer sb = new StringBuffer();
////            Solution obj = new Solution();
////
////            System.out.println("Case #"+i+": "+obj.sol());
//            tot--;
//            i++;
//        }
    }

}


Measured memory_bytes: 285052
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int k;
int uk;
int cifre[1000000];
void ispisi(int ukcif) {
    for(int i=1; i<=ukcif; ++i) cout << cifre[i];
}
void konstr(int cif, int to, int ukcif) {
    if(cif<0||cif>9) return;
    cifre[to]=cif;
    if(to==ukcif) {
        ++uk;
        if(uk==k) {
            ispisi(ukcif);
            exit(0);
        }
        return;
    }
    konstr(cif-1, to+1, ukcif);
    konstr(cif, to+1, ukcif);
    konstr(cif+1, to+1, ukcif);
}
int main() {
    IOS; cin >> k;
    for(int i=1;;++i) {
        for(int j=1; j<=9; ++j) {
            konstr(j, 1, i);
        }
    }
}


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

int main() {
  int N, L;
  cin >> N >> L;
  
  vector<string> S(N);
  for (int i = 0; i < N; i++){
    cin >> S.at(i);
  }
  
  sort(S.begin(), S.end());
  
  string ans;
  for (int i = 0; i < N; i++){
    ans += S.at(i);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

int n, m, q;
vs32 a, b, c, d;
s32 A[10];

int dfs(int idx, int prev)
{
    if (idx == n)
    {
        int ret = 0;
        rep (i, q)
        {
            if (A[b[i]] - A[a[i]] == c[i])
            {
                ret += d[i];
            }
        }
        return ret;
    }

    int ret = 0;
    for (int x = prev; x <= m; ++x)
    {
        A[idx] = x;
        ret = max(ret, dfs(idx + 1, x));
    }
    return ret;
}

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

    cin >> n >> m >> q;
    a.resize(q);
    b.resize(q);
    c.resize(q);
    d.resize(q);
    rep (i, q)
    {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        --a[i], --b[i];
    }

    int ans = dfs(0, 1);

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



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

int main()
{

    int n, x;
    cin >> n >> x;
    int d[100];
    for (int i = 0; i < n; ++i)
    {
        cin >> d[i];
    }
    int sum = 0, m = 10000;
    for (int i = 0; i < n; ++i)
    {
        sum += d[i];
        if (d[i] < m)
            m = d[i];
    }
    cout << (x - sum) / m + n << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define vll vector<long long>
#define ll long long
#define pii pair<int,int>
const ll mod=1e9+7;
typedef struct node{
    int x;
    ll y;
}node;
ll power(ll x,int y){
    ll temp=x;
    for(int i=1;i<y;i++){
        x*=temp;
    }
    return x;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("inputf.txt","r",stdin);
    freopen("outputf.txt","w",stdout);
#endif
    
    string s;
    cin>>s;
    int n=s.length();
    cout<<s;
    if(s[n-1]=='s'){
        cout<<"es";
    }
    else cout<<"s";
    return 0;
}

Measured memory_bytes: 3660
#include <iostream>

using namespace std;

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

    int m = n;
    int sum = 0;
    while (n) {
        sum += n % 10;
        n /= 10;
    }

    if (m % sum == 0) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) int((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<int> V;
typedef vector<vector<int>> VV;
typedef pair<int, int> P;
typedef map<string, int> M;
typedef unordered_map<int, int> HM;
typedef set<int> S;
typedef multiset<int> MS;
typedef queue<int> Q;

//最大公約数
ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
//最小公倍数(LCM)
//LCM = (a*b)/GCD
ll LCM(ll a, ll b){
    return a / GCD(a, b) * b;
}
int main(){
    ll a,b,c,d; cin>>a>>b>>c>>d;
    ll cnta = (a-1) - (a-1)/c - (a-1)/d + (a-1)/LCM(c, d);
    ll cntb = b - b/c - b/d + b/LCM(c, d);
    cout << cntb-cnta << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
  int dec[10][10];
  int x,y,size,num,max;
  char a;
  num = 0;
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
       dec[i][j]=0;
    }
  }
                
  while(cin >> y >> a>> x>> a>> size){
    if(size == 1){
      if(x+1 < 10 && x+1 >= 0 && y>=0 && y<10) dec[x+1][y] += 1;
      if(x-1 >=0 && x-1 < 10 && y>=0 && y<10) dec[x-1][y] += 1;
      if(x >= 0 && x < 10 && y+1<10 && y+1 >= 0) dec[x][y+1] += 1;
	 if(x >=0 && x< 10 && y-1 <10 && y-1 >=0) dec[x][y-1] += 1;
	    dec[x][y] += 1;
	    } else if(size == 2){
      for(int i=-1;i<=1;i++){
	for(int j=-1;j<=1;j++){
	  if(x+i >=0&& x+i<10 && y+j>=0&& y+j<10) dec[x+i][y+j] +=1;
	}
      }
    }else if(size==3){
      for(int i=-1;i<=1;i++){
	for(int j=-1;j<=1;j++){
	  if(x+i >=0&& x+i<10 && y+j>=0&& y+j<10)  dec[x+i][y+j] +=1;
	}
      }
      if(x+2<10 && x+2 >=0 && y>=0 && y<10  )dec[x+2][y] +=1;
      if(x-2>=0 &&x-2 <10 && y>=0 && y<10  )dec[x-2][y] +=1;
      if(x<10 && x >=0 && y+2>=0 && y+2<10  )dec[x][y+2] +=1;
      if(x>=0 && x<10 && y-2>=0 && y-2<10  )dec[x][y-2] +=1;
    }
  }
  max = dec[0][0];
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){ 
      if(dec[i][j]==0)
	num +=1; 
      if(max < dec[i][j])
	max=dec[i][j];
    }
  }
  cout << num << endl << max<<endl;
}
 

Measured memory_bytes: 0
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string
from functools import lru_cache
import heapq

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]
        
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)
    def lcm(a,b):
        return (a * b) // Math.gcd(a,b)
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Math.roundUp(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

MOD = int(1e09) + 7

def main():
    N = cin.int()
    V = cin.mapInt()
    heapq.heapify(V)
    while len(V) >= 2:
        v = heapq.heappop(V) + heapq.heappop(V)
        v /= 2
        heapq.heappush(V,v)
    print(V[0])
    return

if __name__ == "__main__":
    main()


Measured memory_bytes: 38640
#include<stdio.h>
#include<string.h>
int main(void)
{
    int i = 0,j,k;
    char s1,s2,s3;
    scanf("%c%c%c",&s1,&s2,&s3);
    //printf("%c",s1);
    if(s1 == '1'){
        i++;
    }
    if(s2 == '1'){
        i++;
    }
    if(s3 == '1'){
        i++;
    }
    printf("%d",i);

    return 0;
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;


int main(){
	ios_base::sync_with_stdio(false);
	ll N, ans=0;
	ll A[100005];

	cin >> N;
	N++;
	rep(i,N) cin >> A[i];

	ll sum[100005] = {};
	rrep(i,N) sum[i] = sum[i+1] + A[i];

	ll cur = 1;
	rep(i,N){
		ans += cur;
		cur -= A[i];
		if(cur < 0 || sum[i+1] < cur){
			ans = -1;
			break;
		}
		cur = min(cur * 2, sum[i+1]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 5188
mod = 1000000007
    
N,M = map(int,input().split())

A = [int(input()) for _ in range(M)]

memo = [0]*(100001)

for a in A:
    memo[a] = 1

ruiseki = [0]*(N+1)

ruiseki[0] = 1

for i in range(1,N+1):
    ruiseki[i] = ruiseki[i-1]+ruiseki[i-2]
    if memo[i] != 0:
        ruiseki[i] = 0
print(ruiseki[-1]%mod)

Measured memory_bytes: 504724
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef vector<int> vi;
// #define ll long long 
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=1e5+2;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin>>n;
	set<int> s;
	int ans=0;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		s.insert(x);
		if(*s.begin()>=x)
		{
			ans++;
		}
	}
	cout<<ans;
}
// I never lose. I either win or I learn

Measured memory_bytes: 9600
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val (X, N) = nextIntList()
    if (N == 0) {
        next()
        println(X)
    } else {
        val P = nextIntList().sorted()
        val ans = (0..101).subtract(P).toList().bfind(X)
        println(ans)
    }
}

tailrec fun List<Int>.bfind(v: Int, l: Int = 0, r: Int = this.size): Int {
    if (r - l == 1) {
        if (r == this.size) return this[l]
        return if (Math.abs(this[l] - v) <= Math.abs(this[r] - v)) this[l] else this[r]
    }
    val m = (l + r) / 2
    val vm = this[m]
    return when {
        vm < v -> bfind(v, m, r)
        vm > v -> bfind(v, l, m)
        else -> v
    }
}

Measured memory_bytes: 39236
#include <iostream>
#include <string>
#include <set>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
using  ll =long long;

int main()
{
    ios::sync_with_stdio(false);
    int n;
    while(cin>>n){
        int a=n/100;
        int b=n%100;
        //cout << a << ' '<< b << endl;
        if((a<=12)&&(b<=12)&&a!=0&&b!=0)
            cout << "AMBIGUOUS" << endl;
        else if((a<=12&&a!=0)&&(b>12||b==0))
            cout << "MMYY" << endl;
        else if((a>12||a==0)&&(b<=12&&b!=0))
            cout << "YYMM" << endl;
        else
            cout << "NA" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>


int main(void){
  char s[200010];
  scanf("%s", s);
  int len = strlen(s);
  int sum = 0;
  for(int i = 0; i< len; i++)sum += s[i] - '0';
  if(sum % 9 == 0) puts("Yes");
  else puts("No");

  return 0;
}

Measured memory_bytes: 1808
N,W=map(int,input().split())
numbers=[]
for _ in range(N):
    w,v=input().split()
    numbers.append([int(w),int(v)])
def chmax(a,b):
    if a>=b:
        return a
    else:
        return b
dp=[[0 for i in range(W+1)] for j in range(N+1)]
for a in range(N):
    for sum_w in range(W+1):
        if sum_w-numbers[a][0]>=0:
            dp[a+1][sum_w]=chmax(dp[a+1][sum_w],dp[a][sum_w-numbers[a][0]]+numbers[a][1])
        dp[a+1][sum_w]=chmax(dp[a+1][sum_w],dp[a][sum_w])
print(dp[N][W])


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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ld = long double;

const ll MOD = 998244353;
const int N = 300 * 1000 + 10;

ll bpow(ll x, ll n) {
    ll res = 1;
    for (; n > 0; n /= 2) {
        if (n & 1)
            res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

ll inv(ll x) {
    ll ans = bpow(x, MOD - 2);
    assert(ans * x % MOD == 1);
    return ans;
}

ll f[N];
ll rf[N];

void init() {
    f[0] = 1;
    for (int i = 1; i < N; i++)
        f[i] = f[i - 1] * i % MOD;
    for (int i = 0; i < N; i++)
        rf[i] = inv(f[i]);
}

ll cnk(int n, int k) {
    if (k > n)
        return 0;
    return f[n] * rf[n - k] % MOD * rf[k] % MOD;
}

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

    init();
    
    ll n, a, b, k;
    cin >> n >> a >> b >> k;
    ll ans = 0;
    for (ll ca = 0; ca <= n; ca++) {
        ll rem = k - a * ca;
        if (rem < 0 || rem % b != 0)
            continue;
        ll cb = rem / b;
        ll cur = cnk(n, ca);
        cur = cur * cnk(n, cb) % MOD;
        ans += cur;
    }
    cout << ans % MOD << endl;
}

Measured memory_bytes: 4992
import java.util.*;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int N = sc.nextInt();

        int ans = 0;
        for (int i = 0; i < N; i++) {
            long a = sc.nextLong();
            if (a % 2 != 0) continue;

            int cnt = 0;
            while (a % 2 == 0) {
                a = a / 2;
                cnt++;
            }
            ans += cnt;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 36028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
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; }
void rcmb(ll *x,ll s,ll r,function<void(ll *)>f){if(r==0){f(x);}else{if(s<0)return;rcmb(x,s-1,r,f);x[r-1]=s;rcmb(x,s-1,r-1,f);}}
void cmb(ll n,ll k,function<void(ll *)>f){ll x[k];rcmb(x,n-1,k,f);}
void prm(ll n,function<void(ll *)>f){ll x[n];for(ll i=0;i<n;i++)x[i]=i;do{f(x);}while(next_permutation(x,x+n));}
void prm(ll n,ll k,function<void(ll *)>f){cmb(n,k,[&](ll *c){prm(k,[&](ll *p){ll x[k];for(ll i=0;i<k;i++){x[i]=c[p[i]];}f(x);});});}
// prm(4, 2, [](ll *x){ cout << x[0] << "," << x[1] << "\n"; });


void solve(long long H, long long W, long long h, long long w){
	ll res = (H-h) * (W-w);
	cout << res << "\n";
}

int main(){
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    long long h;
    scanf("%lld",&h);
    long long w;
    scanf("%lld",&w);
    solve(H, W, h, w);
    return 0;
}


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

using namespace std;
#define ll long long
#define pp pair<int,int>
#define ppl pair<ll,ll> 

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int n;
	cin>>n;

	int*arr=new int[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];

	vector<int> dp(n,0);
	dp[1]=abs(arr[1]-arr[0]);

	for(int i=2;i<n;i++)
		dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));

	cout<<dp[n-1];

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define maxs(x,y) x = max(x, y)
#define mins(x,y) x = min(x, y)
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int n, k, t;
    cin >> n >> k;
    vector<int> a(n);
    REP(i, n) {
        cin >> a[i];
        if (a[i] == 1) t = i;
    }

    if (k == n) {
        cout << 1 << endl;
        return 0;
    }

    cout << 1+(n-k-1)/(k-1) + 1 << endl;
    
    //cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, m;
  int ans;
  double r;
  double series;
  
  cin >> n >> m;
  ans = 0;
  
  series = 0;
  r = 1/pow(2,m);
  //cout<<r<<endl;
  //if(1900 * m * r >= 0.001) cout<<"!"<<endl;
  //else cout<<"?"<<endl;
  for(int i = 1; 1900 * m * r >= 0.00001 / n; i++)
  {
    r = pow(1-(1/pow(2,m)),i-1) * (1/pow(2,m));
    series += i*((n-m) * 100.0 + 1900.0 * m) * r;
    //cout << i<<":"<< series << endl;
    //cout << "* r:"<< r << endl;
  }
  //cout << series << endl;
  ans += round(series);
  
  cout << ans << endl;
  
  return 0;
}

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

int main(){
    int n,k;
    scanf(" %d %d",&n,&k);
    priority_queue<int> q;
    for(int i = 0; i < n;++i){
        int va; scanf(" %d",&va);
        q.push(va);
    }
    ll ans = 0;
    for(int i = 0; i < n;++i){
        int see = q.top();
        q.pop();
        if(k <= 0)ans += (ll)see;
        --k;
    }
    printf("%lld\n",ans);
    return 0;
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end

template<unsigned mod=1000000007>struct mint {
   unsigned val;
   static unsigned get_mod(){return mod;}
   unsigned inv() const{
      int tmp,a=val,b=mod,x=1,y=0;
      while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
      if(x<0)x+=mod; return x;
   }
   mint():val(0){}
   mint(ll x):val(x>=0?x%mod:mod+(x%mod)){}
   mint pow(ll t){mint res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
   mint& operator+=(const mint& x){if((val+=x.val)>=mod)val-=mod;return *this;}
   mint& operator-=(const mint& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
   mint& operator*=(const mint& x){val=ll(val)*x.val%mod; return *this;}
   mint& operator/=(const mint& x){val=ll(val)*x.inv()%mod; return *this;}
   mint operator+(const mint& x)const{return mint(*this)+=x;}
   mint operator-(const mint& x)const{return mint(*this)-=x;}
   mint operator*(const mint& x)const{return mint(*this)*=x;}
   mint operator/(const mint& x)const{return mint(*this)/=x;}
   bool operator==(const mint& x)const{return val==x.val;}
   bool operator!=(const mint& x)const{return val!=x.val;}
};
template<unsigned mod=1000000007>struct factorial {
   using Mint=mint<mod>;
   vector<Mint> Fact, Finv;
public:
   factorial(int maxx){
      Fact.resize(maxx+1),Finv.resize(maxx+1); Fact[0]=Mint(1); rep(i,0,maxx)Fact[i+1]=Fact[i]*(i+1);
      Finv[maxx]=Mint(1)/Fact[maxx]; rrep(i,maxx,0)Finv[i-1]=Finv[i]*i;
   }
   Mint fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];}
   Mint nPr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[n-r];}
   Mint nCr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[r]*Finv[n-r];}
};

int main(){
   int n,k; scanf("%d%d",&n,&k);
   mint<> res; factorial<> fact(401000);
   rep(i,0,k+1){
      res+=fact.nCr(n,i)*fact.nCr(n-1,i);
   } 
   printf("%d\n",res.val);
   return 0;
}

Measured memory_bytes: 3456
#include "bits/stdc++.h"
using namespace std;

using ll = long long int;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

#define pi 3.14159265358979

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




ll cnt_rep = 0;
ll powmod(ll N, ll P, ll M){
  cnt_rep++;
  if(P == 0) return 1;
  if(P%2 == 0){
    ll t = powmod(N, P/2, M);
    return t*t % M;
  }
  return (N * powmod(N, P-1, M)) % M;
}


ll gcd(ll a, ll b){
  ll resi, g, l;
  if(a > b){
    g = a; l = b;
  }else if(b > a){
    g = b; l = a;
  }else{
    return a;
  }
  resi = g % l;
  if(resi != 0){
    return gcd(l, resi);
  }else{
    return l;
  } 
}

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

int ans = 0;
int N, M, Q;

template<typename T>
void showall(vector<T> v){
  rep(i, 0, v.size()){
    cout << v[i] << " ";
  }
  cout << endl;
}


void dfs(vector<ll> ls, vector<vector<ll>> way, int ){
  ll cur = ls.back();
  ls.pop_back();

  rep(i, 0, N){
    if(way[cur][i] != 0){

    }
  }

}

 
int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> C(N), v(M), Asum(M, 0);
  vector<vector<int>> A(N, v);
  rep(i, 0, N){
    cin >> C[i];
    rep(j, 0, M){
      cin >> A[i][j];
      Asum[j] += A[i][j];
    }
  }

  rep(i, 0, M){
    if(Asum[i] < X){
      cout << "-1" << endl;
      return 0;
    }
  }

  ll total = pow(2,N);
  ll min = 1e9;
  
  rep(i, 1, total){
    vector<ll>  Anow(M, 0);
    ll sum = 0;
    int now = 0;
    ll top = i;
    while(true){
      if(top/2 > 0 && top%2 == 1){
        rep(j, 0, M){
          Anow[j] += A[now][j];
        }
        sum += C[now];
      }else if(top/2 <= 0){
        if(top == 1){
          rep(j, 0, M){
            Anow[j] += A[now][j];
          }
          sum += C[now];
          // cout << sum << endl;
        }
        rep(j, 0, M){
          if(Anow[j] < X){
            break;
          }else if(Anow[j] >= X && j == M-1 && min > sum){
            min = sum;
          }
        }
        break;
      }
      now++;
      top /= 2;
    }

  }

  cout << min << endl;

}

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

int main() {
    int n, m, x;
    scanf("%d %d %d", &n, &m, &x);
    
    int a[m+1];
    for (int i = 0; i < m; i++) {
        scanf("%d", &a[i]);
    }

    int i = 0;
    a[m] = x;
    while (a[i] < x) { i++; }
    printf("%d\n", min(i, m-i));
    return 0;
}

Measured memory_bytes: 256
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

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

typedef long long ll;

int main()
{
    ll n;
    cin>>n;
    if(n>=400 && n<=599)
    cout<<8;
    else if(n>=600 && n<=799)
    cout<<7;
    else if(n>=800 && n<=999)
    cout<<6;
    else if(n>=1000 && n<=1199)
    cout<<5;
    else if(n>=1200 && n<=1399)
    cout<<4;
    else if(n>=1400 && n<=1599)
    cout<<3;
     else if(n>=1600 && n<=1799)
    cout<<2;
     else if(n>=1800 && n<=1999)
    cout<<1;

    return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;/*10^12*/
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}

////////////////////////////////////////

ll c[26];
int main(){
    string s;cin>>s;
    ll n=s.size();
    rep(i,0,n-1)c[s[i]-'a']++;
    ll ans=n*(n-1)/2+1;
    rep(i,0,26-1){
        ans-=c[i]*(c[i]-1)/2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
#include<cstdio>
#include<complex>

typedef double type_n;
typedef complex<type_n> point;

void ccw(const point &a, const point &c, const point &z)
{
    point w;
    w = conj(c) * (z - a);
	type_n re = w.real(), im = w.imag();
	if(im != 0){
		(im > 0 ? printf("COUNTER_CLOCKWISE\n") : printf("CLOCKWISE\n"));
        return;
	}else{
        if(re < 0){ printf("ONLINE_BACK\n"); return; }
        if(re > norm(c)){ printf("ONLINE_FRONT\n"); return; }
	}
    printf("ON_SEGMENT\n");
    return;
}

int main()
{
    point a, b, c, z;
    int i, q;
    type_n a1, a2, b1, b2, z1, z2;
    scanf("%lf %lf %lf %lf", &a1, &a2, &b1, &b2);
    a.real(a1), a.imag(a2), b.real(b1), b.imag(b2);
    c = b - a;

    scanf("%d", &q);
    for(i = 0; i < q; i++){
        scanf("%lf %lf", &z1, &z2);
        z.real(z1), z.imag(z2);
        ccw(a, c, z);
    }
    return 0;
}

Measured memory_bytes: 1224
class UnionFind():
 def __init__(self, n):
  self.n = n
  self.parents = [-1] * n

 def find(self, x):
  if self.parents[x] < 0:
   return x
  else:
   self.parents[x] = self.find(self.parents[x])
   return self.parents[x]

 def union(self, x, y):
  x = self.find(x)
  y = self.find(y)

  if x == y:
   return

  if self.parents[x] > self.parents[y]:
   x, y = y, x

  self.parents[x] += self.parents[y]
  self.parents[y] = x

 def size(self, x):
  return -self.parents[self.find(x)]
 def same(self, x, y):
  return self.find(x) == self.find(y)
class UnionFind():
 def __init__(self, n):
  self.n = n
  self.parents = [-1] * n

 def find(self, x):
  if self.parents[x] < 0:
   return x
  else:
   self.parents[x] = self.find(self.parents[x])
   return self.parents[x]

 def union(self, x, y):
  x = self.find(x)
  y = self.find(y)

  if x == y:
   return

  if self.parents[x] > self.parents[y]:
   x, y = y, x

  self.parents[x] += self.parents[y]
  self.parents[y] = x

 def size(self, x):
  return -self.parents[self.find(x)]
 def same(self, x, y):
  return self.find(x) == self.find(y)

import sys
input = sys.stdin.readline
N,M,K = map(int,input().split())
uf = UnionFind(N)
lst=[0]*(N)
ans=[0]*(N)
for i in range(M):
 A,B=map(int,input().split())
 uf.union(A-1,B-1)
 lst[A-1]+=1
 lst[B-1]+=1
for i in range(K):
 A,B=map(int,input().split())
 if uf.same(A-1,B-1):
  lst[A-1]+=1
  lst[B-1]+=1
for i in range(N):
 ans[i]=uf.size(i)-lst[i]-1
L=[str(a) for a in ans]
L=' '.join(L)
print(L)

Measured memory_bytes: 18832
#include <cstdio>
#include <cstring>
using namespace std;

int main() {
  int H, W; scanf("%d%d", &H, &W);
  for(int i = 0; i < H; ++i) {
    for(int j = 0; j < W; ++j) {
      char s[7];
      scanf(" %6s", s);
      if(!strcmp(s, "snuke")) {
        printf("%c%d\n", 'A'+j, 1+i);
        return 0;
      }
    }
  }
  return 0;
}


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

using namespace std;

int main()
{
	string s;
	getline(cin,s);
	
	int a[200]={0};
	for(int i=0;i<s.size();i++)
		a[s[i]]++;
	 
	int sum=0; 
	int sum2=0;
	for(int i=0;i<200;i++)
	{
	 	if(a[i]>=1)
	 		sum2++;
	 	if(a[i]==2)
	 		sum++;
	}
	
	if(sum2==2&&sum==2)
	 	cout<<"Yes"<<endl;
	else
	 	cout<<"No"<<endl;
	return 0;
}

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

class Main {

	public static void main(String[] args) throws IOException{
		BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
		String i1[]=br.readLine().split(" ");
		int V=Integer.parseInt(i1[0]);
		int E=Integer.parseInt(i1[1]);
		String h[]=br.readLine().split(" ");
		int ht[]=new int[V];
		for(int i=0;i<V;i++)
		{
			ht[i]=Integer.parseInt(h[i]);
		}
		ArrayList<ArrayList<Integer>> graph=new ArrayList<>();
		
		for(int i=0;i<V;i++)
		{
			ArrayList<Integer> road=new ArrayList<>();
			graph.add(road);
		}
		
		for(int i=0;i<E;i++)
		{
			String uv[]=br.readLine().split(" ");
			int u=Integer.parseInt(uv[0]);
			int v=Integer.parseInt(uv[1]);
			
			u--;
			v--;
			graph.get(u).add(v);
			graph.get(v).add(u);
		}
		
		//For each from 0 to N;
		int total=0;
		for(int i=0;i<V;i++)
		{
			//here i is our obs;
			ArrayList<Integer> rd=graph.get(i);
			boolean good=true;
			int height=ht[i];
			
			for(Integer r: rd)
			{
				if(ht[r]>=height)
				{
					good=false;
					break;
				}
			}
			if(good)
			{
				total++;
			}
			
		}
		
		System.out.println(total);
		
		
		
	}

}


Measured memory_bytes: 67004
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    
    ll a,b;
    cin>>a>>b;
    cout<<(a*b)/__gcd(a,b);
    
    return 0;
}


Measured memory_bytes: 256
import math

n = int(input())
d = list(map(int,input().split()))

ans = -1

d_count = [0] * (max(d)+1)
for i in range(n):
  d_count[d[i]] += 1

if d[0] != 0 or d_count[0] != 1:
  print(0)
  exit()

ans = 1
for i in range(1,len(d_count)-1):
  for j in range(d_count[i+1]):
    ans = ans * d_count[i]
    ans = ans % 998244353

ans = ans % 998244353

print(int(ans))


Measured memory_bytes: 14396
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define pb push_back
using ll = long long;
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

signed main(void){
    int N;
    cin >> N;
    int sum=0;
    for(int i=0;i<N+1;i++){
        if(i%3 != 0 && i%5!=0){
            sum += i;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3596
def g(m,n):
    if m==0:
        return n
    elif n==0:
        return m
    elif m>n:
        m=m%n
        return g(m,n)
    else:
        n=n%m
        return g(m,n)

def h(m,n):
    return m*n//g(m,n)

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

print(h(A,B))


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

int main(){
	int n;
	cin >> n;
	long long p = 0;
	for(int i = 0 ; i < n ; i++){
		int a;
		char b;
		int c;
		cin >> a >> b >> c;
		if( b == '(' ) p += c;
		else p -= c;
		if(p){
			cout << "No" << endl;
		}else{
			cout << "Yes" << endl;
		}
	}
}

Measured memory_bytes: 1156
#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 r, c;
  cin >> r >> c;

  int t;
  vector<int> v;
  rep(i,r) {
    rep(j,c) {
      cin >> t;
      v.push_back(t);
    }
  }

  rep(i,r) {
    int s = v[i*c];
    cout << v[i*c];

    rep(j,c) {
      if (j==0) continue;
      cout << " " << v[i*c + j];
      s += v[i*c + j];
    }
    cout << " " << s << endl;
  }

  int total = 0;
  rep(j,c) {
    int s = 0;
    rep(i,r) {
      s += v[i*c + j];
    }
    cout << s << " ";
    total += s;
  }
  cout << total << endl;

  return 0;
}



Measured memory_bytes: 3232
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

#define DEBUG(x) cerr << #x << " = " << x << endl

typedef double D;

struct Node {
  D p;
  D h;
};

const D EPS = 1e-10;

int sig(D a, D b) {
  if(a < b - EPS) return -1;
  if(a > b + EPS) return +1;
  return 0;
}

bool check(D th, D speed, D start, D end, const vector<Node> &objs) {
  D vx = speed * cos(th);
  D vy = speed * sin(th);
  bool ok = true;
  for(int i = 0; i < (int)objs.size(); ++i) {
    if(sig(start, objs[i].p) <= 0 && sig(objs[i].p, end) <= 0) {
      D x = objs[i].p - start;
      D y = -(x*x/(2*vx*vx)) + vy*x/vx;
      if(sig(y, objs[i].h) < 0) {
        ok = false;
      }
    }
  }
  return ok;
}

D speed(D th, D len) {
  return sqrt(len / (sin(2*th)));
}

void test(D th, D len, D pos) {
  D sp = speed(th, len);
  D vx = sp * cos(th);
  D vy = sp * sin(th);
  D y = -(pos*pos/(2*vx*vx)) + (vy/vx)*pos;
  DEBUG(y);
}

int main() {
  D distance;
  int N, B;
  cin >> distance >> N >> B;
  vector<Node> objs(N);
  for(int i = 0; i < N; ++i) {
    cin >> objs[i].p >> objs[i].h;
  }
  B++;
  D ans = 1e20;
  for(int b = 1; b <= B; ++b) {
    for(int i = 0; i < b; ++i) {
      D start = distance / b * i;
      D end = distance / b * (i + 1);
      D len = abs(end - start);
      D estm;
      // DEBUG(start);
      // DEBUG(end);
      // DEBUG(len);
      // DEBUG(speed(M_PI/4, len));
      // D vx = speed(M_PI/4, len)*cos(M_PI/4);
      // D vy = speed(M_PI/4, len)*sin(M_PI/4);
      // DEBUG(-(len*len/(2*vx*vx))+(vy/vx)*len);
        // DEBUG("false");
      D lb = M_PI/4, ub = M_PI/2;
      for(int t = 0; t < 300; ++t) {
        D mid = (lb + ub) / 2;
        if(check(mid, speed(mid, len), start, end, objs)) {
          ub = mid;
        }
        else {
          lb = mid;
        }
      }
      estm = ub;
      D estm_sp = speed(estm, len);
      bool ok = true;
      for(int j = 0; j < b; ++j) {
        D start2 = distance / b * j;
        D end2 = distance / b * (j + 1);
        if(check(estm, estm_sp, start2, end2, objs) == false) {
          ok = false;
        }
      }
      if(ok) {
        ans = min(ans, estm_sp);
      }
    }
  }
  cout.setf(ios::fixed); cout.precision(10);
  cout << ans << endl;
}

Measured memory_bytes: 1360
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt(), b = sc.nextInt();
    if(a <= 8 && b <= 8)
      System.out.println("Yay!");
    else
      System.out.println(":(");
  }
}

Measured memory_bytes: 25044
<?php
list($n, $m) = explode(" ", trim(fgets(STDIN)));
$N = trim(fgets(STDIN));
$M = trim(fgets(STDIN));

$gcd = gcd($n, $m);
$len = lcm($n, $m);

for($i = 0; $i < $n; $i++){
    $c[$i * $m / $gcd] = $N[$i];
}
$flag = true;
for($i = 0; $i < $m; $i++){
    if(isset($c[$i * $n / $gcd]) && $M[$i] != $c[$i * $n / $gcd])$flag = false;
    $c[$i * $n / $gcd] = $M[$i];
}
if($flag){
    echo $len;
}else{
    echo -1;
}

function gcd($m, $n){
    if(!$n)return $m;
    return gcd($n, $m % $n);
}

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


Measured memory_bytes: 19448
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

const int MAX_N = 1e5 + 5, BLACK = 0, WHITE = 1, MOD = 1e9 + 7;
vector <int> tree[MAX_N];
long long no_of_ways[MAX_N][2];

long long dfs_count(int parent, int v, int colour)
{
    if(no_of_ways[v][colour] != -1)
    {
        return no_of_ways[v][colour];
    }

    no_of_ways[v][colour] = 1;

    for(int i = 0; i < tree[v].size(); i++)
    {
        int child = tree[v][i];

        if(child == parent) continue;

        long long no_of_subtrees = 1;

        if(colour == BLACK)
        {
            no_of_subtrees = dfs_count(v, child, WHITE);
        }
        else if(colour == WHITE)
        {
            no_of_subtrees = (dfs_count(v, child, BLACK) + dfs_count(v, child, WHITE))%MOD;
        }

        no_of_ways[v][colour] = (no_of_ways[v][colour]*no_of_subtrees)%MOD;
    }

    return no_of_ways[v][colour];
}

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

    for(int i = 1; i <= no_of_vertices - 1; i++)
    {
        int x, y;
        cin >> x >> y;

        tree[x].push_back(y);
        tree[y].push_back(x);
    }

    memset(no_of_ways, -1, sizeof(no_of_ways));

    long long answer = (dfs_count(0, 1, BLACK) + dfs_count(0, 1, WHITE))%MOD;

    cout << answer;
    return 0;
}


Measured memory_bytes: 17024
#include <stdio.h>

int main(){
    int n,m;
    int i,j;
    
    int a[100][100],b[100],c[100];
    
    scanf("%d %d",&n,&m);
    
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&a[i][j]);
        }
    }
    
    for(j=0;j<m;j++){
        scanf("%d",&b[j]);
    }
    
    for(i=0;i<n;i++){
        c[i]=0;
    }
    
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            c[i]+=a[i][j]*b[j];
        }
    }
    
    for(i=0;i<n;i++){
        printf("%d\n",c[i]);
    }
    
}

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

int main() {
  string S, T;
  cin >> S >> T;
  if (T == S + 'a')
    cout << "Yes" << endl;
  else if (T == S + 'b')
    cout << "Yes" << endl;
  else if (T == S + 'c')
    cout << "Yes" << endl;
  else if (T == S + 'd')
    cout << "Yes" << endl;
  else if (T == S + 'e')
    cout << "Yes" << endl;
  else if (T == S + 'f')
    cout << "Yes" << endl;
  else if (T == S + 'g')
    cout << "Yes" << endl;
  else if (T == S + 'h')
    cout << "Yes" << endl;
  else if (T == S + 'i')
    cout << "Yes" << endl;
  else if (T == S + 'j')
    cout << "Yes" << endl;
  else if (T == S + 'k')
    cout << "Yes" << endl;
  else if (T == S + 'l')
    cout << "Yes" << endl;
  else if (T == S + 'm')
    cout << "Yes" << endl;
  else if (T == S + 'n')
    cout << "Yes" << endl;
  else if (T == S + 'o')
    cout << "Yes" << endl;
  else if (T == S + 'p')
    cout << "Yes" << endl;
  else if (T == S + 'q')
    cout << "Yes" << endl;
  else if (T == S + 'r')
    cout << "Yes" << endl;
  else if (T == S + 's')
    cout << "Yes" << endl;
  else if (T == S + 't')
    cout << "Yes" << endl;
  else if (T == S + 'u')
    cout << "Yes" << endl;
  else if (T == S + 'v')
    cout << "Yes" << endl;
  else if (T == S + 'w')
    cout << "Yes" << endl;
  else if (T == S + 'x')
    cout << "Yes" << endl;
  else if (T == S + 'y')
    cout << "Yes" << endl;
  else if (T == S + 'z')
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int[] a = new int[N];
    int sum = 0;
    for (int i = 0; i < N; i++) {
      a[i] = scanner.nextInt();
      sum += a[i];
    }

    int cost1 = 0;
    for (int i = 0; i < N; i++) {
      int diff = a[i] - sum / N;
      cost1 += diff * diff;
    }
    int cost2 = 0;
    for (int i = 0; i < N; i++) {
      int diff = a[i] - sum / N - 1;
      cost2 += diff * diff;
    }

    System.out.println(Math.min(cost1, cost2));
  }
}


Measured memory_bytes: 22996
#include <stdio.h>
#include <cmath>

using namespace std;

#define REP(a, i, n) for (int i = a; i <= n; ++i)

const int MAX_N = 1e6 - 1;
bool memo[MAX_N + 1];

bool isPrime(int n) {
    if (memo[n]) return true;

    if (n == 1) return false;
    if (n == 2) return true;
    if (n % 2 == 0) return false;
    if (n == 3) return true;
    if (n % 3 == 0) return false;

    for (int i = 5; i <= sqrt(n); i += 2) {
        if (n % i == 0) {
            return false;
        }
    }

    memo[n] = true;
    return true;
}

//  n よりも小さい素数の数は何個存在するか
int main() {

    REP(0, i, MAX_N) {
        memo[i] = false;
    }

    int n = 0; // 999,999
    while(scanf("%d", &n) != EOF) {
        int cnt = 0;
        REP(1, i, n) {
            if (isPrime(i)) cnt++;
        }

        printf("%d\n", cnt);
    }

    return 0;
}



Measured memory_bytes: 3556
import scala.collection.mutable.ArrayBuffer

object Main extends App {
  import scala.io.StdIn._

  solve
  def solve: Unit = {
    val Array(s, d) = readLine.trim.split(' ').map(_.toInt)
    if (s == 0 && d == 0) return
    val union = Array.tabulate(s + d){_ ⇒ new UnionFind}
    for (i ← 1 until s){
      union(i).merge(union(i - 1))
    }
    val edges = ArrayBuffer[Edge]()
    for (f ← 0 until s){
      for ((distance, t) ← readLine.trim.split(' ').map(_.toInt).zipWithIndex.map{case (a, b) ⇒ (a, b + s)} if distance != 0){
        edges.append(Edge(f, t, distance))
      }
    }
    for (f ← 0 until d - 1){
      for ((distance, t) ← readLine.trim.split(' ').map(_.toInt).zipWithIndex.map{case (a, b) ⇒ (a, b + s + f + 1)} if distance != 0){
        edges.append(Edge(f + s, t, distance))
      }
    }
    var cost = 0
    for (e ← edges.sortBy(_.cost) if !union(e.to).isSameUnion(union(e.from))) {
      cost += e.cost
      union(e.to).merge(union(e.from))
    }
    println(cost)
    solve
  }
  case class Edge(from: Int, to: Int, cost: Int)
  class UnionFind {
    private var mParent = this
    private var mSize = 1
    private def parent(): UnionFind = {
      if (mParent != this){
        mParent = mParent.parent()
      }
      mParent
    }
    def isSameUnion(that: UnionFind): Boolean = parent() == that.parent()
    def merge(that: UnionFind): Unit = {
      if (!isSameUnion(that)){
        val thisP = this.parent()
        val thatP = that.parent()
        if (thisP.mSize < thatP.mSize){
          thisP.mParent = thatP
          thatP.mSize += thisP.mSize
        }else {
          thatP.mParent = thisP
          thisP.mSize += thatP.mSize
        }
      }
    }
  }
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def let[A](func: T ⇒ A): A = func(value)
    @inline
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}


Measured memory_bytes: 45516
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <unordered_set>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll h, n, dp[10010];
int main() {
	REP(i, 10010)dp[i] = INF;
	cin >> h >> n;
	dp[h] = 0;
	
	vector<ll> a(n), b(n);
	REP(i, n)cin >> a[i] >> b[i];
	REP(i, n) {
		REPR(j, h) {
			dp[max(0ll, j - a[i])] = min(dp[max(0ll, j - a[i])], dp[j] + b[i]);
		}
	}
	cout << dp[0] << endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<climits>
#include<set>
#include<utility>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;

int main(){

	string s;
	bool flag[4];
	memset(flag, 0, sizeof(flag));
	cin >> s;
	for(int i=0; i<s.size(); i++){
		if(s[i]=='N'){
			flag[0]=true;
		} else if(s[i]=='W'){
			flag[1]=true;
		} else if(s[i]=='S'){
			flag[2]=true;
		} else {
			flag[3]=true;
		}
	}
	if(flag[0] && flag[1] && flag[2] && flag[3]){
		cout << "Yes" << endl;
	} else if(flag[0] && !flag[1] && flag[2] && !flag[3]){
		cout << "Yes" << endl;
	} else if(!flag[0] && flag[1] && !flag[2] && flag[3]){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256