akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m;
  cin >> n >> m;
  vector<int> a(pow(2,n),10000000);
  for(int i = 0;i < m;i++){
    int c,d;
    cin >> c >> d;
    int n = 0;
    for(int j = 0;j < d;j++){
      int k;
      cin >> k;
    n|= (1<<k-1);}
    a.at(n) = min(a.at(n),c);}
  for(int h = 1;h < 12;++h){
    
  for(int i = 0;i < pow(2,n);++i){
    if(__builtin_popcount(i)==h){
    for(int j = 0;j < pow(2,n);++j){
      
      a.at(i|j) = min(a.at(i|j),a.at(i)+a.at(j));
    }
    }
  }
  }
 int ans = a.at(pow(2,n)-1);
  if(ans == 10000000)ans = -1;
  cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
d,x = map(int,input().split())
a = [int(input()) for i in range(n)]
eaten = 0
j = 0
for i in range(n):
    while 1+a[i]*j <= d:
        j += 1
        eaten += 1
    j = 0
print(x+eaten)


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

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD=1e9+7;

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

  ll n,W,cnt[4]={};cin>>n>>W;
  std::vector<ll> w(n+1),v(n+1),li[4];
  for(int i=1;i<=n;i++){
      cin>>w[i]>>v[i];
      li[w[i]-w[1]].push_back(v[i]);
      cnt[w[i]-w[1]]++;
  }
  for(int i=0;i<4;i++) sort(li[i].rbegin(),li[i].rend());
  VVI sum(4,vector<ll>(n+1,0));
  ll dp[n+1][n+1][n+1];
  for(int i=0;i<=n;i++)for(int j=0;j<=n;j++)for(int k=0;k<=n;k++) dp[i][j][k]=0;
  for(int i=0;i<4;i++){
      for(int j=1;j<=(int)li[i].size();j++){
          sum[i][j]=sum[i][j-1]+li[i][j-1];
      }
  }
  for(int i=0;i<=n;i++)for(int j=0;j<=n-i;j++)for(int k=0;k<=n-i-j;k++){
      if(w[1]*i+(w[1]+1)*j+(w[1]+2)*k<=W){
          dp[i][j][k]=sum[0][i]+sum[1][j]+sum[2][k];
          ll cap=(W-(w[1]*i+(w[1]+1)*j+(w[1]+2)*k))/(w[1]+3);
          if(cap>=cnt[3]) dp[i][j][k]+=sum[3][cnt[3]];
          else dp[i][j][k]+=sum[3][cap];
      }
  }
  ll res=-1;
  for(int i=0;i<=n;i++)for(int j=0;j<=n-i;j++)for(int k=0;k<=n-i-j;k++)res=max(res,dp[i][j][k]);
  cout<<res<<endl;
}


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

using namespace std;

using ll = long long;

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

  if((s[2] == s[3]) && (s[4] == s[5])){
    cout << "Yes" << endl;
    return 0;
  }

  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <random>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
#include <random>
using namespace std;
using LL = long long;

int main() {
	int N;
	cin >> N;
	int streak = 0;
	for (int i = 0; i < N; i++) {
		int a, b;
		cin >> a >> b;
		if (a == b) {
			streak++;
		}
		else {
			streak = 0;
		}
		if (streak >= 3) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define PI 3.14159265358979323846
using namespace std;

int main() {
    int s, w;
    cin >> s >> w;
    if (s <= w) {
        cout << "unsafe" << endl;
    }
    else {
        cout << "safe" << endl;
    }
}

Measured memory_bytes: 3600
#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    int a[5];
    repi(i, 5, 0)
    {
        cin >> a[i];
    }
    int k;
    cin >> k;
    bool ans = true;
    repi(i, 5, 0)
    {
        repi(j, 5, 0)
        {
            if (abs(a[i] - a[j]) > k)
                ans = false;
        }
    }
    cout << (ans ? "Yay!" : ":(") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(b);i>=(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
ll sum(const T& a){return accumulate(all(a),0LL);}

void solve(){
    string s;
    getline(cin,s);
    rep(i,s.size()){
        if('A'<=s[i]&&s[i]<='Z'){
            s[i]+='a'-'A';
        }else if('a'<=s[i]&&s[i]<='z'){
            s[i]+='A'-'a';
        }
    }
    cout<<s<<endl;
}

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



Measured memory_bytes: 3148
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <bitset>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10

bool is_kai(string S) {
	string Sr(S);
	reverse(Sr.begin(), Sr.end());
	return S == Sr;
}


int main() {
	string S; cin >> S;
	string f;
	for (int i = 0; i < (S.length() - 1) / 2; i++)f += S[i];
	string b;
	for (int i = (S.length()+1)/2; i < S.length(); i++)b += S[i];


	if (is_kai(S) && is_kai(f) && is_kai(b))
		print("Yes");
	else
		print("No");


	return 0;
}


Measured memory_bytes: 256
#include <iostream> 
using namespace std;
int main() {
    string s; cin >> s;
    for (int i = 0; i < (1 << 3);i++) {
        int sum = s[0] - '0';
        for (int j = 0; j < 3;j++) {
            if (i & (1 << j)) {
                sum += s[j + 1] - '0';
            }
            else
                sum -= s[j + 1] - '0';
        }
        if (sum == 7) {
            cout << s[0];
            for (int k = 0;k < 3;k++) {
                if (i & (1 << k))
                    cout << "+" << s[k + 1];
                else
                    cout << "-" << s[k + 1];
            }
            cout  << "=7"<< endl;
            break;
        }
    }
}

Measured memory_bytes: 256
import java.io.*;
import java.lang.*;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;
import java.math.BigInteger;

public class Main {
    static InputReader in = new InputReader(System.in);
    static PrintWriter out = new PrintWriter(System.out);
    static int[] dx = {1,0,-1,0};
    static int[] dy = {0,1,0,-1};
    public static void main(String[] args) {
        int n = in.nextInt();
        int[] a = new int[n];
        int curr = 11;
        for(int i = 0; i<n; i++){
            BigInteger b = new BigInteger(String.valueOf(curr));
            while(!b.isProbablePrime(10)){
                curr+=10;
                b = new BigInteger(String.valueOf(curr));
            }
            a[i] = curr;
            curr+=10;
        }
        for(int i : a){
            out.print(i + " ");
        }
        out.close();
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

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

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        public boolean hasNext() {
            String next = null;
            try {
                next = reader.readLine();
            } catch (Exception e) {
            }
            if (next == null) {
                return false;
            }
            tokenizer = new StringTokenizer(next);
            return true;
        }

        public BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
    }
}



Measured memory_bytes: 37400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iA = int.Parse(sS[0]);
            int iB = int.Parse(sS[1]);
            int iC = int.Parse(sS[2]);
            int iK = int.Parse(sS[3]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            int iOut = 0;
            int iAdd = 0;
            if (iA >= iK) { iAdd = iK; iK = 0; }
            else  { iAdd = iA; iK -= iA; }
            iOut += iAdd;
            if (iB >= iK) { iAdd = 0; iK = 0; }
            else { iAdd = 0; iK -= iB; }
            iOut += iAdd;
            if (iC >= iK) { iAdd = - iK ; iK = 0; }
            else { iAdd = - iB; iK -= iB; }
            iOut += iAdd;

            // 出力
            System.Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


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

signed main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
    //int t=1 ; cin>>t ; while(t--)
    {
        int a, b;
        cin >> a >> b;

        cout << (b  + (b%a ==0 ? 1 : -1)*a) << '\n'; 
    }
    
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define P(s) cout<<s<<"\n"

bool Ss(const char* s1, const char* s2, int32_t len) {
    for (auto i = 0; i < len; ++i) {
        if (s1[i] != s2[i]) {
            return false;
        }
    }
    return true;
}

int main() {
    string s; cin >> s;
    int32_t len = static_cast<int32_t>(s.size() - 1) / 2;
    for (;; --len) {
        if (Ss(&s[0], &s[len], len)) {
            P(len * 2);
            break;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K;
    cin >> N >> K;
    ll V[55];
    rep(i,0,N) cin >> V[i];
    ll sum_plus = 0;
    rep(i,0,N){
        if(V[i] > 0) sum_plus += V[i];
    }
    if(K >= 2*N){
        print(sum_plus);
        return 0;
    }
    ll ans = 0;
    rep(n1,0,K+1){
        rep(n2,0,K+1){
            ll n3 = K - n1 - n2;
            if(n3 < 0) continue;
            vector<ll> v;
            if(n1 + n2 >= N){
                rep(i,0,N) v.push_back(V[i]);
            }else{
                rep(i,0,n1) v.push_back(V[i]);
                rep(i,0,n2) v.push_back(V[N-1-i]);
            }
            sort(v.begin(), v.end());
            rep(i,0,min(n3, (ll)v.size())){
                if(v[i] < 0) v[i] = 0;
            }
            ll val = 0;
            rep(i,0,v.size()) val += v[i];
            ans = max(ans, val);
        }
    }
    print(ans);


    
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<map>
#include<cmath>
#define ll long long
#define N 100100
#define MZ 333
using namespace std;

ll n,a[N],b[N],zs[N],zz,ans;
bool P[N];
map<ll,ll>cnt;
map<ll,bool>vis;

inline void get()
{
	ll i,j;
	for(i=2; i<=100000; i++)
	{
		if(!P[i]) zs[++zz]=i;
		for(j=1; j<=zz&&zs[j]*i<=100000; j++) P[zs[j]*i]=1;
	}
}

int main()
{
	ll i,j,k,p,q,t,tmp;
	get();
	cin>>n;
	for(i=1; i<=n; i++)
	{
		scanf("%lld",&a[i]);
	}
	for(i=1; i<=n; i++)
	{
		t=a[i];
		b[i]=q=1;
		for(j=1; j<=MZ&&t!=1; j++)
		{
			p=0;
			for(; t%zs[j]==0; t/=zs[j]) p++;
			p%=3;
			if(!p) continue;
			for(k=1; k<=p; k++) q*=zs[j];
			for(k=p+1; k<=3; k++) b[i]*=zs[j];
		}
		if(t)
		{
			tmp=sqrt(t);
			if(tmp*tmp==t)
			{
				q*=t;
				b[i]*=tmp;
			}
			else
			{
				q*=t;
				b[i]*=t*t;
			}
		}
		a[i]=q;
		cnt[a[i]]++;
	}
	for(i=1; i<=n; i++)
	{
		if(vis[a[i]] || vis[b[i]] || a[i]==1) continue;
		vis[a[i]]=1;
		ans+=max(cnt[a[i]],cnt[b[i]]);
	}
	cout<<ans+(!!cnt[1]);
}

Measured memory_bytes: 27008
from fractions import gcd
N = int(input())
As = list(map(int, input().split()))

lcm = 1
mod = 10**9+7

def getprime(n):
    if not isinstance(n, int):
        raise TypeError("Input int")
    if n < 2:
        raise ValueError("N >= 2")
    prime = []
    # 約数はsqrt(N)まで調べればOK
    data = [i+1 for i in range(1,n)]
    while True:
        p = data[0]
        if p >= int(n**0.5):
            return prime+data
        prime.append(p)
        # pで割り切れないものだけを残す
        data = [d for d in data if d%p != 0]

from collections import defaultdict
def factorization(n):
    factors = defaultdict(int)
    if n == 2 or n == 3:
        factors[n] = 1
        return factors
    primes = getprime(int(n**0.5))
    for prime in primes:
        while n % prime == 0:
            factors[prime] += 1
            n //= prime
            # print(factors,n)
    if n != 1:
        factors[n] += 1
    return factors

d = defaultdict(int)
factors_list = []
cnt_1 = 0
for a in As:
    if a == 1:
        cnt_1 += 1
        continue
    factors = factorization(a)
    factors_list.append(factors)
    for f in factors.keys():
        d[f] = max(d[f],factors[f])

for f in d.keys():
    lcm *= f ** d[f]
    lcm %= mod

As_inv = [pow(a,mod-2,mod) for a in As]
a = sum(As_inv)%mod



print((lcm*a)%mod)


Measured memory_bytes: 84184
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
    int N; cin >> N;
    int A; cin >> A;
    N %= 500;
    cout << (N <= A ? "Yes" : "No") << endl;
}


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

using namespace std;
int main(){
    string s;
    int flag = 0;
    cin >> s;
    sort(s.begin(),s.end());
    if(s[0]==s[1] && s[2]==s[3] && s[0]!=s[2]) 
      cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
ll a[1000007];
int main() {
    ll i, j, k, l, test, n, x, y;
    
    cin>>n;

    for(i=-1000;i<=1000;i++) {
        for(j=-1000;j<=1000;j++) {
            if(pow(i,5)-pow(j,5)==n) {
                cout<<i<<" "<<j<<"\n";
              	return 0;
            }
        }
    }
}

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

int main(int argc, char const *argv[])
{
	int h,w,d;
	cin>>h>>w>>d;
	int a;
	pair<int,int> b[h*w];
	for (int i = 0; i < h; ++i)
	{
		for (int j = 0; j < w; ++j)
		{
			cin>>a;
			b[a]={i,j};
		}
	}
	int dist[h*w+5]={};
	for (int i = 1; i <= d; ++i)
	{
		for (int j = i+d; j <= h*w; j+=d)
		{
			dist[j]=dist[j-d]+abs(b[j-d].first-b[j].first)+abs(b[j-d].second-b[j].second);
		}
	}
	int q;
	cin>>q;
	for (int i = 0; i < q; ++i)
	{
		int l,r;
		cin>>l>>r;
		cout<<dist[r]-dist[l]<<endl;
	}
	return 0;
}


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

int main() {
  double N,M;
  cin >>N>>M;
  int sum =0;
  vector<double> vec(N);
  for(int i =0;i < N;i++){
    cin >>vec[i];
    sum += vec[i];
  }
  int a =0;
  for(int i =0;i < N;i++){
    if(vec[i] >= sum/(4*M)){
      a++;
    }
  }  
  if(a >= M)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
    
}


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

int main(){
    string S;
    cin >> S;
    int len_S = S.size();
    int half = len_S / 2;
    int quarter = half /2;
    bool ans = true;
    rep(i,quarter){
        if (S[i] != S[half - 1 - i]){
            ans = false;
        }
    }
    rep(i,quarter){
        if (S[i + half + 1] != S[len_S - 1 - i]){
            ans = false;
        }
    }
    rep(i,half){
        if (S[i] != S[len_S - i - 1]){
            ans = false;
        }
    }
    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)

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

const ll MOD=1000000007;
int N;
int ans;
bool check(ll x){
    set<int> s;
    while(x>0){
        s.insert(x%10);
        x/=10;
    }
    return 3==s.size();
}
void dfs(ll x){
    if(x<=N){
        dfs(10*x+3);
        dfs(10*x+5);
        dfs(10*x+7);
        if(check(x)){
            ans++;
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N;
    ans=0;
    dfs(0);
    cout << ans<< "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,z,a[1010],b[1010],f[1010],ansn=2147483647;
void dfs(int dep,int no){
	if (dep==n+1){
		int sum1=0,sum2=0,sum3;
		for (int i=1;i<=n;i++){
			if (f[i]==1){sum1+=a[i];sum2+=b[i]+a[i]*i*100;}
		}
		if (sum2<z){
			if (no*100*(a[no]-1)+sum2>=z){
				sum3=z-sum2;
				if (sum3%(no*100)==0) sum1+=sum3/(no*100);
				else sum1+=(sum3)/(no*100)+1;
			}else return ;
		}
		ansn=min(ansn,sum1);
	}else{
		f[dep]=0;dfs(dep+1,no);
		f[dep]=1;dfs(dep+1,no);
		if (no==0){f[dep]=2;dfs(dep+1,dep);}
	}
}
int main(){
	cin>>n>>z;
	for (int i=1;i<=n;i++)cin>>a[i]>>b[i];
	dfs(1,0);
	cout<<ansn<<endl;
	return 0;
}

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

typedef long long LL;

int SimpleKnapSack(LL w[], int val[], int W, int n)
{
    if (!W || !n)
        return 0;

    if (w[n - 1] > W)
        return SimpleKnapSack(w, val, W, n - 1);

    else
        return (max(val[n - 1] + SimpleKnapSack(w, val, W - w[n - 1], n - 1), SimpleKnapSack(w, val, W, n - 1)));
}

LL KnapSackDP(LL wt[], int val[], int W, int n)
{
    LL K[n + 1][W + 1];

    for (int i = 0; i <= n; i++)
    {
        for (LL w = 0; w <= W; w++)
        {
            if (!w || !i)
                K[i][w] = 0;

            else if (wt[i - 1] <= w)
                K[i][w] = max(val[i - 1] + K[i - 1][w - wt[i - 1]], K[i - 1][w]);
            else
                 K[i][w] = K[i - 1][w];
        }
    }

    return K[n][W];
}

int main() {
    int N;
    LL W;
    cin >> N >> W;
    LL w[N];
    int val[N];
    for (int i = 0; i < N; i++)
    {
        cin >> w[i] >> val[i];
    }

    cout << KnapSackDP(w, val, W, N);

    return 0;
}


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

#define lugan "proO"
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define endl '\n'
#define _io ios_base::sync_with_stdio(0);   cin.tie(NULL); cout.tie(NULL);

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int N = 30;
const int MASK = (1 << 21) + 10;
const int oo = 1e9+7;

inline void initf()
{
    freopen(lugan".inp", "r", stdin);
    freopen(lugan".out", "w", stdout);
}

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

void enter()
{
    cin >> n;
    for (int i=1; i<=n; i++)
        for (int j=1; j<=n; j++)
            cin >> a[i][j];
}

int getbit(int mask, int k)
{
    return (mask >> k) & 1;
}

vector<int> bit1[N];

void getbit()
{
    for (int mask = 0; mask < (1 << n); mask++)
        bit1[__builtin_popcount(mask)].pb(mask);
}

void solve()
{
    dp[0][0] = 1;
    for (int i=1; i<=n; i++)
        for (int j=1; j<=n; j++)
        {
            if (a[i][j] == 0) continue;
            for (int to : bit1[i])
                if (getbit(to, j-1) == 1)
                {
                    int mask = to, premask = mask - (1 << (j-1));
                    dp[i][mask] = (dp[i][mask] + dp[i-1][premask]) % oo;
                }

        }
//    for (int i=1; i<=n; i++, cout << endl)
//        for (int mask = 0; mask < (1 << n); mask++)
//            cout << dp[i][mask] << ' ';
    cout << dp[n][(1 << n) - 1];
}

int main()
{
    _io
    ///initf();
    enter();
    getbit();
    solve();
    return 0;
}



Measured memory_bytes: 173500
import sys
rl = sys.stdin.readline


def solve():
    N, M = map(int, rl().split())
    graph = [set() for _ in range(N)]
    for _ in range(M):
        a, b = map(lambda x: int(x) - 1, rl().split())
        graph[a].add(b)
        graph[b].add(a)
    
    for child in graph[0]:
        if N - 1 in graph[child]:
            print('POSSIBLE')
            exit()
    print('IMPOSSIBLE')


if __name__ == '__main__':
    solve()


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

static const int N = 3;
int grid[N][N];

int main() {
    bool ok = true;
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> grid[i][j];
        }
    }
    for (int i = 1; i < 3; ++i) {
        for (int j = 1; j < 3; ++j) {
            if (grid[i][j] - grid[i][j - 1] != grid[0][j] - grid[0][j - 1]) {
                ok = false;
            }
            if (grid[i][j] - grid[i - 1][j] != grid[i][0] - grid[i - 1][0]) {
                ok = false;
            }
        }
    }
    if (ok)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3660
a,b,k=map(int,input().split())
a0=[]
b0=[]
for i in range(1,a+1):
    if a%i==0:
        a0.append(i)
for j in range(1,b+1):
    if b%j==0:
        b0.append(j)
a0=set(a0)
b0=set(b0)
c=a0 & b0
c=sorted(list(c))
print(c[-k])



Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <functional>
#include <cmath>
#include <utility>
#include <tuple>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<vector<int> > vvi;
#define rep(i,n) for (int i=0;i<n;i++)

ll mod = 1e9+7;

int main(){
    int n;
    cin >> n;
    vector<int> d(n);
    for (int i=0;i<n;i++) cin >> d[i];
    int ans = 0;
    for (int i=0;i<n-1;i++){
        for (int j=i+1;j<n;j++) ans += d[i]*d[j];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i=0;i<N;i++){
    int x;
    cin >> x;
    A[i]=x-(i+1);
  }
  sort(A.begin(),A.end());
  int x=A[(N+1)/2-1];
  long long ans=0;
  for (int i=0;i<N;i++){
    ans+=(long long)abs(A[i]-x);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
N=int(input())
A=[i for i in map(int,input().split())]
X=[0]*N
for i in range(N//2):
    X[0]+=A[i*2]-A[i*2+1]
X[0]+=A[N-1]
for i in range(1, N):
    X[i]=2*A[i-1]-X[i-1]

for x in X:
    print(x,end=" ")
print()


Measured memory_bytes: 14220
//   2次配列のよみこみ

function Main(input) {
    input = input.split("\n");
  	n = Number(input[0].split(" "));
    V = input[1].split(" ").map(Number);
    C = input[2].split(" ").map(Number);
    
  //  console.log(n);
  //  console.log(V);
  //  console.log(C);
    
    
  	var Y = 0;
  	for(var i=0; i<n; i++){y = V[i]-C[i];
                             if ( y >= 0){Y = Y + y;}
                                      }
   console.log(Y);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<iostream>
#include<string>
#include<map>
#include<sstream>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
int main(){
  string s;
  int i,j,k;
  vector<P> v;
  while(cin >> s,s[0]!='0'){
    for(i=0;i<s.size();i++) if(s[i]==',') s[i]=' ';
    stringstream ss(s);
    P p;
    ss >> p.second >> p.first;
    v.push_back(p);
  }
  sort(v.begin(),v.end(),greater<P>());
  int rank[105]={};
  k=1;
  rank[v[0].second]=k;
  for(i=1;i<v.size();i++){
    if(v[i-1].first!=v[i].first) k++;
    rank[v[i].second]=k;
  }
  while(cin >> k) cout << rank[k] << endl;
  return 0;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
#define pvec(vec) {for (auto v: vec) cout << v << ' '; cout << endl;}
#define pivec(vec) {rep(i, 0, vec.size()) cout << i << ':' << vec[i] << ' '; cout << endl;}

using namespace std;
using ll = long long;

int main()
{
    ll N, D;
    cin >> N >> D;
    int cnt = 0;
    rep(i, 0, N)
    {
        ll X, Y;
        scanf("%lld %lld", &X, &Y);

        if (X*X+Y*Y<=D*D) ++cnt;
    }
    printf("%d\n", cnt);
    return 0;
}



Measured memory_bytes: 3808
from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N, A, B = read_int()

def solve():
    ans = (N // (A + B)) * A
    r = (N % (A + B))
    ans += r if r < A else A
    return ans

if __name__ == "__main__":
    print(solve())

Measured memory_bytes: 3892
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}

ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


string Toupper(string s){
  string ans="";
  rep(i,s.size()){
    if('a'<=s[i] && s[i]<='z') ans+=(char)s[i]-32;
    else ans+=s[i];
  }
  return ans;
}
string Tolower(string s){
  string ans="";
  rep(i,s.size()){
    if('A'<=s[i] && s[i]<='Z') ans+=(char)s[i]+32;
    else ans+=s[i];
  }
  return ans;
}


const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*bool cmp(pint a, pint b) { return a.second < b.second; }*/

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll a,b,c,d,e,f,g,h,i;
  cin>>a>>b>>c>>d>>e>>f>>g>>h>>i;
  if(d-a==e-b && e-b==f-c && g-d==h-e && h-e==i-f) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

#define ll long long
#define INF 99999999
#define INF_LL 1LL << 60
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

int main()
{
    double R;
    cin >> R;
    put_double(2.0 * R * 3.1415926);
}


Measured memory_bytes: 3788
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    a,b,q = map(int, input().split())
    s = [int(input()) for _ in range(a)] + [-10**20, 10**20]
    t = [int(input()) for _ in range(b)] + [-10**20, 10**20]
    s.sort()
    t.sort()

    for _ in range(q):
        pos = int(input())
        l_s = bisect_left(s, pos)
        l_t = bisect_left(t, pos)

        left_shrine = s[l_s-1]
        right_shrine = s[l_s]
        left_temple = t[l_t-1]
        right_temple = t[l_t]

        d1 = pos - min(left_shrine, left_temple)
        d2 = max(right_shrine, right_temple) - pos
        d3 = 2 * (pos - left_shrine) + (right_temple - pos)
        d4 = 2 * (right_temple - pos) + (pos - left_shrine)
        d5 = 2 * (pos - left_temple) + (right_shrine - pos)
        d6 = 2 * (right_shrine - pos) + (pos - left_temple)

        ans = min([
            d1, d2, d3, d4, d5, d6
        ])
        print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 13232
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*
    s.find_by_order(k) ---> returns iterator to the element at index(from 0) k
    s.order_of_key(val) ---> number of elements that are strictly smaller than the given value
*/
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int tc; cin >> tc; cin.ignore(); while(tc--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}
 
int main() {
	fast();
 
    /*NA – JEONG – MO – SA – JI – MI – DA – CHAE – TZU*/
    
    ll n;
    cin >> n;
    inpv(a, n);
    ll ans = 1e18;
    for(int i=0; i<=100; i++){
        ll curr = 0;
        for(auto j:a){
            curr += ((j-i)*(j-i));
        }
        ans = min(ans, curr);
    }
    out(ans);
}

Measured memory_bytes: 256
<?php
while ($input = trim(fgets(STDIN))) {
	list($m, $f, $r) = explode(" ", $input);
	if ($m + $f + $r == -3) break;
	$sum = $m + $f;
	if ($m == -1 || $f == -1 || $sum < 30) echo "F\n";
	else if ($sum >= 30 && $sum < 50) {
		if ($r >= 50) echo "C\n";
		else echo "D\n";
	}
	else if ($sum >= 50 && $sum < 65) echo "C\n";
	else if ($sum >= 65 && $sum < 80) echo "B\n";
	else echo "A\n";
}

Measured memory_bytes: 15356
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 10000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl

signed main(){
    int N,M;
    int x[114514],y[114514];
    int sum[114514]={};
    bool ex[114514]={};
    cin >> N >> M;
    REP(i,M){
        cin >> x[i] >> y[i];
        x[i]--;y[i]--;
    }
    REP(i,N){
        sum[i]=1;
    }
    ex[0]=1;
    REP(i,M){
        if(ex[x[i]]==1){
            ex[y[i]]=1;
            if(sum[x[i]]==1){
                ex[x[i]]=0;
            }
        }
        sum[x[i]]--;
        sum[y[i]]++;
        //REP(j,M){cout << ex[j] << " ";}cout << Endl;
    }
    int Ans=0;
    REP(i,N){
        if(ex[i]==1){
            Ans++;
        }
    }
    cout << Ans << endl;
    return 0;
}   


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

int main(){
  int n,x,count=1,d=0;
  cin >> n >> x;
  vector<int> l(n+1);
  l[0] = 0;
  for(int i=1;i<n+1;i++){
    cin >> l[i];
  }
  for(int i=1;i<n+1;i++){
      d = d+l[i];
//      cout << "d" << d<<endl;
      if(d <= x)count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
import queue
Data = []
Path = []
H,W = map(int,input().split())

def bfs(sy,sx,R,C):
    q = queue.Queue()
    q.put([sy,sx])

    diff = [[1,0],[-1,0],[0,1],[0,-1]]
    Path[sy][sx] = 0
    Data[sy][sx] = 'x'

    count = 1 
    while not q.empty():
        x = q.get()
        r,c = x
        for di in diff:
            rr = r + di[0]
            cc = c + di[1]

            if rr >= 0 and cc >= 0 and rr < R and cc < C:
                if Data[rr][cc] == '.':
                    q.put([rr,cc])
                    Path[rr][cc] = Path[r][c]+1
                    Data[rr][cc] = 'x'

for _ in range(H):
    Data.append(list(input()))
block = 0
for d in Data:
    for x in d:
        if x == '#':
            block += 1

for _ in range(H):
    Path.append([-1]*W)
bfs(0,0,H,W)
n = Path[H-1][W-1]

if n == -1:
    print(-1)
else:
    ans = H*W-block-n-1
    print(ans)

Measured memory_bytes: 3944
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.math.*;

public class Main {
    private static Scanner sc;

    public static void main(final String[] args) {
        final Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null)
                br.close();
        }

        public String next() throws IOException {
            if (i < s.length)
                return s[i++];
            String st = br.readLine();
            while (st == "")
                st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }

    private void solve() {
        try {

            int a = sc.nextInt();
            int b = sc.nextInt();

            if (a == 0) {
                if (b != 100) {
                    System.out.println(b);
                } else {
                    System.out.println(101);
                }

            } else if (a == 1) {
                if (b != 100) {
                    System.out.println(b * 100);
                } else {
                    System.out.println(10100);
                }
            } else {
                if (b != 100) {
                    System.out.println(b * 10000);
                } else {
                    System.out.println(1010000);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}


Measured memory_bytes: 22356
/*
ツ個ゥツづ按づェツつスツ姪「ツ妥ィツづ?つキツづ?
'@'ツづ個湘ェツ渉環つゥツづァ, ツ深ツつウツ優ツ静ヲツ探ツ催オツづ?嘉ーツつォツづ慊つオツづ・ツつ、.
 */
#include <iostream>
using namespace std;

int w, h;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
char t[22][22];

int solve(int x, int y){
  int res = 1;

  t[y][x] = '#';

  for(int i = 0; i < 4; i++){
    int nx = x + dx[i];
    int ny = y + dy[i];

    if(0 <= nx && nx < w && 0 <= ny && ny < h && t[ny][nx] != '#'){
      res += solve(nx, ny);
    }
  }

  return res;
}

int main(){
  while(cin >> w >> h, w || h){
    int sx, sy;

    for(int i = 0; i < h; i++){
      cin >> t[i];

      for(int j = 0; j < w; j++){
        if(t[i][j] == '@'){
          sy = i;
          sx = j;
          t[i][j] = '.';
        }
      }
    }

    cout << solve(sx, sy) << endl;
  }
}

Measured memory_bytes: 0
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//                       _oo0oo_                         //
//                      o8888888o                        //
//                      88" . "88      ------ hzt1       //
//                      (| -_- |)                        //
//                      0\  =  /0                        //
//                    ___/`---'\___                      //
//                  .' \|     |// '.                     //
//                 / \|||  :  |||// \                    //
//                / _||||| -:- |||||- \                  //
//               |   | \  -  /// |     |                 //
//               | \_|  ''\---/''  |_/ |                 //
//               \  .-\__  '-'  ___/-. /                 //
//             ___'. .'  /--.--\  `. .'___               //
//          ."" '<  `.___\_<|>_/___.' >' "".             //
//         | | :  `- \`.;`\ _ /`;.`/ - ` : | |           //
//         \  \ `_.   \_ __\ /__ _/   .-` /  /           //
//     =====`-.____`.___ \_____/___.-`___.-'=====        //
//                       `=---='                         //
//                                                       //
//                                                       //
//     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~       //
//                                                       //
//                 God-He Bless All.                     //
//           This Code Will Never Explode.               //
//                                                       //
//                                                       //
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
#include<vector>
#define pb push_back
#define mp make_pair
#define xx first
#define yy second
#define rep(i,a,b) for(int i=(a),i##_end_=(b);i<=i##_end_;i++)
#define dwn(i,a,b) for(int i=(a),i##_end_=(b);i>=i##_end_;i--)
using namespace std;
const int Size=1<<16;
char buffer[Size],*head,*tail;
inline char Getchar() {
    if(head==tail) {
        int l=fread(buffer,1,Size,stdin);
        tail=(head=buffer)+l;
    }
    if(head==tail) return -1;
    return *head++;
}
typedef long long ll;
inline ll read() {
    ll x=0,f=1;char c=Getchar();
    for(;!isdigit(c);c=Getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=Getchar()) x=x*10+c-'0';
    return x*f;
}
typedef pair<int,int> pii;
const int maxn=100010;
int n,m,top;
ll ans[maxn],A[maxn],cnt[maxn];
int main() {
	n=read();m=read();
	A[++top]=n;
	rep(i,1,m) {
		ll x=read();
		while(top&&A[top]>=x) top--;
		A[++top]=x;
	}
	cnt[top]=1;
	dwn(i,top,1) {
		ll x=A[i];int t;
		while(t=upper_bound(A,A+i,x)-A-1) {
			cnt[t]+=(ll)cnt[i]*(x/A[t]);
			x%=A[t];
		}
		ans[x]+=cnt[i];
	}
	dwn(i,n-1,1) ans[i]+=ans[i+1];
	rep(i,1,n) printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 3968
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
typedef long long int ll;
using namespace std;

int main (void)
{
	ll x, y, z;
	ll result = 0;

	cin >> x >> y >> z;

	result = x/(z+y);
	if (x % (z+y) < z) result--;

	cout << result << endl;
}

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

double dice(int n){
  int sum = n*(n+1)/2;

  return (double)sum/n;
}



int main(){
  int n,k;
  cin >> n >> k;
  vector<int> p;
  p.resize(n);
  for(int i = 0; i < p.size();i++){
    cin >> p.at(i);
  }

  double exp[n]={};
  double sum[n]={};
  for(int i = 0; i < n; i++){
    exp[i] = dice(p[i]);
    sum[i+1] = exp[i]+sum[i];
  }


  double max = 0;
  for(int i = k; i <= n; i++){
    double temp = sum[i]-sum[i-k];
    if(temp > max){
      max = temp;
    }
  }

  cout << fixed << setprecision(15)<< max << endl;


}

Measured memory_bytes: 4096
n=int(input())
a,b=map(int,input().split())
arr=list(map(int,input().split()))
arr=sorted(arr)
pos1=0
pos2=0
for i in range(n):
  if arr[i]<=a:
    pos1=i+1
  if arr[i]<=b:
    pos2=i+1
ans=min(pos1,pos2-pos1,n-pos2)
print(ans)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(int argc, const char *argv[])
{
  int n;
  cin >> n;

  int max_cnt = 0, ans = 1;
  for (int i = 1; i <= n; i++) {
    int cnt = 0;
    int i_org = i;
    while (i % 2 == 0) {
      cnt++;
      i /= 2;
    }

    i = i_org;
    if (cnt > max_cnt) {
      max_cnt = cnt;
      ans = i;
    }
  }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define precise fixed(cout);cout<<setprecision(16);
using namespace std;

ostream& operator << (ostream &out, vector<int> &v) { for(auto a:v) out << a<<" "; out<<endl; }

int main()
{
  int n;
  string s;
  cin >> s;
  n=s.size();
  int res1=0,res2=0;
  for(int i=0;i<n;i++)
  {
    if(s[i]=='0'+(i%2==0)){
      res1++;
    }
    if(s[i]=='0'+(i%2==1)){
      res2++;
    }
  }
  cout <<min(res1,res2)<<endl;

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

vector<int> prime;
void setPrime(int n) {
    vector<bool> alive(n, true);
    alive[0] = alive[1] = false;
    rep2(i, 2, n + 1) {
        if (alive[i]) {
            prime.emplace_back(i);
            for (int j = 2 * i; j <= n; j += i) {
                alive[j] = false;
            }
        }
    }
}

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

    setPrime(300000);
    int n;
    while (cin >> n, n) {
        cout << upper_bound(all(prime), 2 * n) - upper_bound(all(prime), n) << endl;
    }
}

Measured memory_bytes: 3340