akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class D
{
	public static readonly bool SHEEP = false;
	public static readonly bool WALF = true;

	public static void Main()
	{
		int N = GetInt();
		string s = GetString();

		bool[] ans = new bool[N];
		for(int i = 0; i <= 1; i++)
		{
			for(int j = 0; j <= 1; j++)
			{
				ans[0] = (i == 0);
				ans[1] = (j == 0);
				if(verify(s, N, ref ans))
				{
					StringBuilder sb = new StringBuilder();
					for(int k = 0; k < N; k++)
						sb.Append((ans[k] == SHEEP) ? "S" : "W");
					Console.WriteLine(sb);
					return;
				}
			}
		}
		Console.WriteLine(-1);
	}

	private static bool verify(string s, int N, ref bool[] ans)
	{
		for(int i = 1; i < N-1; i++)
			ans[i+1] = ans[i-1] ^ (s[i] == 'o') ^ (ans[i] == SHEEP);

		if(((s[N-1] == 'o') ^ (ans[N-1] == SHEEP)) != (ans[N-2] ^ ans[0]))
			return false;

		if(((s[0] == 'o') ^ (ans[0] == SHEEP)) != (ans[N-1] ^ ans[1]))
			return false;

		return true;
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}

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

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;


int main()
{
    double a, h, v, wv;
    cin >> a >> h >> v;
    double lo = 0, hi = 90, mid, ans=90, pie = acos(-1);
    int t = 1000;
    while(t--){
        mid = (lo+hi)/2;
        double rad = (mid*pie)/180;
        double var = a/tan(rad);
        if(var < h){
            wv = a*a*var/2;
            wv += (a*a*(h-var));
        }
        else{
            double hor = h*tan(rad);
            wv = h*hor*a/2;
        }
        if(wv > v){
            hi = mid;
        }
        else{
            ans = mid;
            lo = mid;
        }
    }
    cout << fixed << setprecision(10) << 90-ans << "\n";

    return 0;
}


Measured memory_bytes: 640
n = input()
k = int(input())
dp = [[[0] * (k + 2) for i in range(2)] for j in range(len(n) + 1)]
dp[0][0][0] = 1

for i in range(len(n)):
    value = int(n[i])
    for j in range(2):
        for l in range(k + 1):
            for d in range(10 if j == 1 else value + 1):
                dp[i + 1][1 if j == 1 else 1 if (d < value) else 0][l if d == 0 else l + 1] += dp[i][j][l]
print(dp[len(n)][0][k] + dp[len(n)][1][k])

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

bool f(int x){
    for(int i = 2; i <= x; i *= 2){
        if(i == x){ return true; }
    }
    return false;
}

int main(){
    int n; cin >> n;
    int ans = 1;

    for(int i = 1; i <= n; i++){
        if(f(i)){
            ans = max(ans, i);
        }
    }

    cout << ans << endl;
}

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

using namespace std;

long long a, b, c, ans = 1e9;
long long x, y;

int main(){
      cin >> a >> b >> c;
      cin >> x >> y;

      for(int i = 0; i <= max(x, y) * 2; i += 2){
            long long cur = i * c + max((x - i / 2), 0ll) * a + max((y - i / 2), 0ll) * b;
            ans = min(ans, cur);
      }

      cout << ans << endl;
}


Measured memory_bytes: 256
import sys


def main():
  n, m = map(int, sys.stdin.readline().split())
  set1, setn = set(), set()
  for _ in range(m):
    i, j = map(int, sys.stdin.readline().split())
    if i == 1:
      set1.add(j)
    if j == n:
      setn.add(i)
  if set1 & setn:
    print('POSSIBLE')
  else:
    print('IMPOSSIBLE')


if __name__ == '__main__':
  main()

Measured memory_bytes: 19168
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long int ll;

int main() {
  int N;
  cin>>N;
  
  double ans=0.0,A;
  for(int i=0;i<N;++i){
    cin>>A;
    ans+=1.0/A;
  }
  
  ans=1.0/ans;
  cout<<ans<<endl;
}


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

using namespace std;

#define pb push_back
#define nl '\n'
#define pi 2.0*acos(0.0)
#define mod maxm+7
#define FOR(i,j,n)    for(ll i=j;i<n;i++)
#define RFOR(i,j,n)    for(ll i=j;i>=n;i--)
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;

int main(){
    ll m,n,sum = 0;
    cin>>m>>n;
    ll arr[n];
    FOR(i,0,n) cin>>arr[i] , sum += arr[i];
    ll ans = m - sum;
    if(ans < 0) cout<< - 1 <<nl;
    else cout<< ans <<nl;
}


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

int main(void) {
	queue<int> time;
	queue<string> name;
	int queAmount,qtime,limitTime;
	string qname;
	cin >> queAmount;
	cin >> limitTime;

	for (int i = 0; i < queAmount; i++) {
		cin >> qname;
		name.push(qname);
		cin >> qtime;
		time.push(qtime);
	}

	int totalTime = 0;
	while (!time.empty()) {
		qname = name.front(); name.pop();
		qtime = time.front(); time.pop();
		if (qtime - limitTime <= 0) {
			totalTime += qtime;
			cout << qname << " " << totalTime << endl;
		} else {
			totalTime += limitTime;
			name.push(qname);
			time.push(qtime - limitTime);
		}
	}
	return 0;
}

Measured memory_bytes: 4176
#include<stdio.h>

int dsum(int m){
	int dsum=0;
	while(m>0){
	dsum=dsum+m%10;
	m=m/10;
    }
	return dsum;
}

int main(){

	int n,a,b;
	int c;
	int sum=0;
	
	scanf("%d %d %d",&n,&a,&b);
	
	for(int i=1;i<=n;i++){
		c=dsum(i);
		if((a<=c)&&(b>=c)){
			sum=sum+i;
			
    	}
	}	
	printf("%d",sum);
	return 0;
}

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

class Program {
    static void Main() {
        for (string line; (line = Console.ReadLine()) != "0";) {
            var n = int.Parse(line);
            var teams = new Dictionary<int, int>();

            for (var i = 0; i < n; i++) {
                var l = Console.ReadLine().Split();
                var id = int.Parse(l[0]);
                var time = int.Parse(l[1]) * 60 + int.Parse(l[2])
                         + int.Parse(l[3]) * 60 + int.Parse(l[4])
                         + int.Parse(l[5]) * 60 + int.Parse(l[6])
                         + int.Parse(l[7]) * 60 + int.Parse(l[8]);

                teams.Add(id, time);
            }

            var sortedTeams = teams.OrderBy(kv => kv.Value).ToArray();
            Console.WriteLine(sortedTeams[0].Key);
            Console.WriteLine(sortedTeams[1].Key);
            Console.WriteLine(sortedTeams[n - 2].Key);
        }
    }
}

Measured memory_bytes: 10644
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

struct Node{
	int parent;
	int depth;
	vector<int> children;
};

void solve(vector<struct Node> &node, int x){
	for(int i=0;i<node[x].children.size();i++){
		node[node[x].children[i]].depth += node[x].depth + 1;
		solve(node, node[x].children[i]);
	}
}

void printNode(vector<struct Node> node, int n){
	for(int i=0;i<n;i++){
		cout<<"node "<<i<<": parent = "<<node[i].parent<<", depth = "<<node[i].depth<<", ";
		
		if(node[i].parent == -1)
			cout<<"root";
		else if(node[i].children.size() == 0)
			cout<<"leaf";
		else
			cout<<"internal node";

		cout<<", [";
		for(int j=0;j<node[i].children.size();j++){
			cout<<node[i].children[j];
			if(j != node[i].children.size()-1)
				cout<<", ";
		}
		cout<<"]"<<endl;
	}
}

int main(){
	int n, id, k, c, x;
	vector<struct Node> node(100000);

	cin>>n;
	for(int i=0;i<n;i++){
		node[i].parent = -1;
		node[i].depth = 0;
	}

	for(int i=0;i<n;i++){
		cin>>id>>k;
		
		for(int j=0;j<k;j++){
			cin>>c;
			node[id].children.push_back(c);
			node[c].parent = id;
		}
	}

	for(int i=0;i<n;i++)
		if(node[i].parent == -1)
			x = i;

	solve(node, x);
	printNode(node, n);
	return 0;
}

Measured memory_bytes: 8596
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
using namespace std;

typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) v.begin(), v.end()


int main() {
	
	ll N;
	cin >> N;
	
	ll ans = 0;
	fori(n, 1, N + 1) {
		if (n % 2 == 1) {
			ll tmp = n;
			vll div;
			while (1 < tmp) {
				fori(i, 2, tmp + 1) {
					if (tmp % i == 0) {
						tmp /= i;
						div.push_back(i);
					}
				}
			}
			if (div.size() == 3 && div[0] != div[1] && div[1] != div[2] && div[2] != div[0]) {
				++ans;
			}
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define all(uiet) uiet.begin(),uiet.end()
#define read(UIET) for(int i = 0; i < n; ++i) cin >> UIET[i]
#define out(UIET) for(int i = 0; i < n; ++i) cout << UIET[i]
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"
#define mod 1000000007
const int INF=(1LL<<60)-1;
const int maxN = 1000001;
string extractStringAtKey(string str, int key){
    char *s = strtok((char *)str.c_str(), " ");
    while(key > 1){
        s = strtok(NULL, " ");
        key--;
    }
    return (string)s;
}
bool prime[maxN + 1];
void seive(){
    memset(prime, true, sizeof(prime));
    for(int i = 2; i * i <= maxN; ++i){
        if(prime[i]){
            for(int j = i * i; j <= maxN; j += i){
                prime[j] = false;
            }
        }
    }
}
int32_t main(){
    SPEED;
    int n, k;
    cin >> n >> k;
    int ans = k;
    if(n == 1) {
        cout << ans;
        return 0;
    }
    ans *= pow(k - 1, n - 1);
    cout << ans ;
}

Measured memory_bytes: 4012
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    int l = s.length();
    int count = 0;
    for(int i = 0;i<l;i++)
    {
        if(s[i] != t[i])
            count++;
    }
    cout<<count;
    return 0;
}

Measured memory_bytes: 3916
#include <iostream>
#include <vector>
#include <queue> 
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)

int main(){
	int  N ;
	cin >> N;
	vector<int> a(2*N);
	REP(i,2*N) cin >> a[i];
	
	priority_queue<int, vector<int>, greater<int>  > pq;
	
	REP(i,2*N) pq.push(a[i]);
	
	int ans = 0;
	REP(i,N ){
		int tmp1 = pq.top();
		pq.pop();
		int tmp2 = pq.top();
		pq.pop();
		ans += min(tmp1,tmp2);
	}
	
	cout << ans << endl;
	
	return 0;
}

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

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

int main() {
  int N, X; cin >> N >> X;
  vector<int> L(N); cin >> L;

  int d = 0;
  int cnt = 1;
  for (int i = 0; i < N; ++i) {
    d += L[i];
    if (d > X) {
      cout << cnt << endl;
      return 0;
    }
    ++cnt;
  }
  cout << cnt <<  endl;
}


Measured memory_bytes: 3608
import java.util. *;
	
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt(); 
        int M = sc.nextInt(); 
        int a[] = new int[M];
        for (int i = 0; i < M; i++) {
			a[i] = sc.nextInt();
		}
        int sum = Arrays.stream(a).sum();
        
        System.out.println(Math.max(N - sum, -1));
	}
}


Measured memory_bytes: 46736
import java.io.*;

class Main{
  public static void main(String[] args) {

    InputStreamReader sr = new InputStreamReader(System.in);
    BufferedReader br = new BufferedReader(sr);
    try{
      String str = br.readLine();
      int a = Integer.parseInt(str);
      int h = a / 3600;
      int m = a % 3600 / 60;
      int s = a % 3600 % 60;

      System.out.println(h+":"+m+":"+s);
    }
    catch(IOException e) {
            e.printStackTrace();
    }
  }
}

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

#define REP(i, n) for(int i = 0; i < (int)n; i++)
using namespace std;
int main()
{
  long A, B, C, D;
  cin >> A  >> B >> C >> D;
  long numC;
  long numD;
  long numE;

  long a1, a2, a3;
  long b1, b2, b3;
  a1 = A/C;
  a2 = A/D;

  b1 = B/C;
  b2 = B/D;

  numC = b1 - a1;
  numD = b2 - a2;

  if(A%C == 0) numC ++;
  if(A%D == 0) numD ++;

  long x = C*D;
  long tmp;
  if(C < D){
    tmp = C;
    C = D;
    D = tmp;
  }
  long r = C % D;
  while(r!=0){
    C = D;
    D = r;
    r = C % D;
  }
  long E = x/D;
  a3 = A/E;
  b3 = B/E;
  numE = b3 - a3;
  if(A%E == 0) numE ++;
  cout << B - A + 1 - (numC + numD - numE) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
#define diup(v,a) distance((v).begin(),upper_bound((v).begin(),(v).end(),(a)))
#define dilo(v,a) distance((v).begin(),lower_bound((v).begin(),(v).end(),(a)))
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(v.size())o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-6;
const ll LINF = 100200300400500600ll;
const int INF = 1001001001;
//--------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)
//--------------------------------------------------------------
template <class T> T chmin(T &a,T b){if(a>b){a=b; return 1;}else return 0;}
template <class T> T chmax(T &a,T b){if(a<b){a=b; return 1;}else return 0;}
const int dx[4] = {0,1,0,-1};
const int dy[4] = {-1,0,1,0};
#define MOD 1000000007

struct D21{
  int is,js;
  D21(int isize,int jsize){
    is = isize;
    js = jsize;
  }
  int operator()(int i,int j){
    return i*js+j;
  }
};


void Main(){
  int n;
  cin>>n;

  v(double) p(n);
  cin>>p;

  vv(double) dp(n+1, v(double)(n+1,0.0));
  dp[0][0] = 1.0;

  rep(i,n) rep(j,n) {
    dp[i+1][j  ] += dp[i][j]*p[i];
    dp[i+1][j+1] += dp[i][j]*(1.0 - p[i]);
  }

  double ans = 0.0;

  rep(i,n/2+1){
    ans+=dp[n][i];
  }
  // rep(i,n+1) cout<<dp[i]<<endl;
  cout<<setprecision(10)<<scientific<<ans<<endl;
  
} signed main(int argc,char** argv)
{fastio; myio; myloopset Main();}


Measured memory_bytes: 70784
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
///////////////////////////////////////////////
int main(){
	int N,K;
	SCD2(N,K);
	static int a[100002] = {};
	ARSCD(a,N);

	static int g[100002] = {};
	g[0] = 0;
	FORq(i,1,K){
		bool trans[102] = {};
		REP(j,N){
			if (i - a[j] < 0) continue;
			trans[g[i-a[j]]] = true;
		}
		int mex = -1;
		REP(j,N+1){
			if (!trans[j]){
				mex = j;
				break;
			}
		}

		g[i] = mex;
	}

	if (g[K] != 0) cout << "First" << "\n";
	else cout << "Second" << "\n";
}


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

using namespace std;

typedef vector<int> Vec;

int main()
{
    int N;
    cin >> N;
    set<Vec> st;
    Vec v(3);
    for (int i = 0; i < N; i++) {
        cin >> v[0] >> v[1] >> v[2];
        sort(v.begin(), v.end());
        st.insert(v);
    }
    cout << N - st.size() << endl;
    return 0;
}

Measured memory_bytes: 3248
import java.io.*;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int tri[] = new int[3];
		String str = br.readLine();
		String[] str2 = str.split(" ");
		for (int i=0; i < str2.length;i++){
			tri[i] = Integer.parseInt(str2[i]);
		}
		Arrays.sort(tri);
		int S = tri[0]*tri[1]/2;
		System.out.println(S);
		
	}
}


Measured memory_bytes: 22356
N = gets.to_i
memo = Hash.new 0
A = N.times.map do
  memo[a = gets.to_i] += 1
  a
end
memo = memo.sort.reverse
A.each do |n|
  puts n < memo[0][0] ? memo[0][0] : memo[0][1] > 1 ? memo[0][0] : memo[1][0]
end

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

int main() {
	int n, a;
	cin >> n >> a;
	int o = n % 500;
	string ans;
	if (o <= a) {
		ans = "Yes";
	} else {
		ans = "No";
	}
	cout << ans << endl;
	return 0;
}

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

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

  int win = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == 'o') win++;
  }
  if (win + 15 - S.size() >= 8) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
import sys
N = int(input())
g = [[] for _ in range(N + 5)]
Fennec = [0]*(N+10)
Sunuke = [0]*(N+10)
sys.setrecursionlimit(10**8)

def dfs(r,f,d,dist):
	dist[r]=d
	for x in range(len(g[r])):
		if g[r][x]==f : continue
		else : dfs(g[r][x],r,d+1,dist)

# main

for i in range(N-1):
	a,b=map(int,input().split())
	a-=1
	b-=1
	g[a].append(b)
	g[b].append(a)
dfs(0,-1,0,Fennec)
dfs(N-1,-1,0,Sunuke)
ans = int(0)

for i in range(N):
	if Fennec[i]<=Sunuke[i] : ans+=1
	else : ans-=1
if(ans>0):
	print("Fennec")
else:
	print("Snuke")


Measured memory_bytes: 116604
#include <bits/stdc++.h>
using namespace std;
#define LONGLONGMAX 9223372036854775807
#define LONGLONGMIN -9223372036854775807
#define INTMAX 32767
#define INTMIN -32767
#define ROUNDUP(divisor,dividend) (divisor + (dividend - 1)) / dividend
int r,g,b,n;
int main(){
  cin >> r >> g >> b >> n;
  int c=0;
  for (int i = 0; i <= n; i++) {
    for (int l = 0; l <= n; l++) {
      if((n-(i*r + l*g)) % b == 0 && i*r + l*g + floor((n-(i*r + l*g)) / b)*b == n && (n-(i*r + l*g)) >= 0){
        c++;
      }
    }
  }
  cout << c << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
#include <cstdio>
#include <complex>
#include <cstring>

using namespace std;

typedef long long LL;

const int N = 100000 + 5;

LL n, a, b;

void solve()
{
    cin >> n >> a >> b;
    int x;
    int prex;
    LL ans = 0;
    for(int i = 0; i < n; ++ i) {
        scanf("%d", &x);
        if (i) {
            ans += min((x - prex) * a, b);
        }
        prex = x;
    }
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 384
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    long x;
    scan(x);

    auto ans = (x / 500) * 1000 + ((x % 500) / 5) * 5;
    writeln(ans);
}



void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
a = A.count(1)
b = A.count(2)
c = A.count(3)
dp = [[[0.0] * (N+1) for _ in range(N+1)] for _ in range(N+1)]

for k in range(c + 1):
    for j in range(b + c + 1 - k): # ２貫の皿の数の最大値 - 3枚の皿の数
        for i in range(a + b + c + 1 - k - j):
            if i == 0 and j == 0 and k == 0:
                continue
            tmp = N * 1.0
            if i > 0:
                tmp += i * dp[i-1][j][k]
            if j > 0:
                tmp += j * dp[i+1][j-1][k]
            if k > 0:
                tmp += k * dp[i][j+1][k-1]
            dp[i][j][k] = tmp / (i + j + k)
print(dp[i][j][k])


Measured memory_bytes: 253832
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define PI 3.141592653589793
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    ll H,A;
    cin >> H >> A;
    cout << (H +A -1)/A <<endl;
    return 0;
}

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

using namespace std;

int acc[1000][1000];

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

    while(true) {
        int N;
        cin >> N;
        if(!N) break;
        for(int i = 0; i < N; ++i) {
            acc[0][i] = 0;
        }
        for(int i = 0; i < N; ++i) {
            string line;
            cin >> line;
            for(int c = 0; c < N; ++c) {
                if(i > 0) acc[i][c] = acc[i-1][c];
                if(line[c] == '*') acc[i][c] = 0;
                else acc[i][c]++;
            }
        }
        int ans = 0;
        for(int r = 0; r < N; ++r) {
            // スタックの中身は常に昇順になっている．
            stack<pair<int,int> > stk;
            for(int c = 0; c < N; ++c) {
                int len = 0;
                const int cur = acc[r][c];
                while(!stk.empty() && stk.top().first >= cur) {
                    len += stk.top().second;
                    if(len >= stk.top().first) {
                        ans = max(ans, stk.top().first);
                    }
                    stk.pop();
                }
                ++len;
                if(len >= cur) {
                    ans = max(ans, cur);
                }
                stk.push(make_pair(cur, len));
            }
            int len = 0;
            while(!stk.empty()) {
                len += stk.top().second;
                if(len >= stk.top().first) {
                    ans = max(ans, stk.top().first);
                    break;
                }
                stk.pop();
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 5120
N, M, X = map(int, input().split(' '))
price, exp = [], [ [] for i in range(N) ]
rst = -1
for i in range(N):
    ls = list(map(int, input().split(' ')))
    price.append(ls[0])
    exp[i] = ls[1:]
for i in range(1 << N):
    price_combi, exp_combi, sum_exp, ls_cnt = [], [], [0] * M, []
    for j in range(N):
        if i >> j & 1:
            price_combi.append(price[j])
            exp_combi.append(exp[j])
    for s in exp_combi:
        for t in range(M):
            sum_exp[t] += s[t]
    [ ls_cnt.append(x) for x in sum_exp if x >= X ]
    if len(ls_cnt) == M:
        if rst == -1:
            rst = sum(price_combi)
        else:
            rst = min(rst, sum(price_combi))
print(rst)

Measured memory_bytes: 9252
from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n, m = map(int, input().split())
request_list = []
ans = 0
for i in range(m):
    a, b = map(int, input().split())
    request_list.append((a,b))

request_list.sort(key = lambda x: x[1])

just_cut = -1
for a, b in request_list:
    if a > just_cut:
        ans += 1
        just_cut = b-1

print(ans)


Measured memory_bytes: 29888
#include <bits/stdc++.h>
using namespace std;
 
struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const long long INF = 9223372000000000000/2145;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
//#define int ll

signed main(){
    string s;
    cin >> s;
    int a[26]={};
    REP(i,s.length()){
        if(a[s[i]-97]){
            printf("no\n");
            return 0;
        }
        a[s[i]-97]++;
    }

    puts("yes\n");
    return 0;
}

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

int main(){
  int h, w;
  cin >> h >> w;
  queue<P> que;
  char a[h+1][w+1];
  int d[h+1][w+1];
  rep(i, h){
    rep(j, w) {
      cin >> a[i+1][j+1];
      if(a[i+1][j+1] == '#') {
        que.push(P(i+1,j+1));
        d[i+1][j+1] = 0;
      } else d[i+1][j+1] = -1;
    }
  }
  while(que.size()){
    P p = que.front(); que.pop();
    int i = p.first, j = p.second;
    if(i-1 >= 1 && d[i-1][j] < 0){
      d[i-1][j] = d[i][j] + 1;
      que.push(P(i-1, j));
    }
    if(j-1 >= 1 && d[i][j-1] < 0){
      d[i][j-1] = d[i][j] + 1;
      que.push(P(i, j-1));
    }
    if(i+1 <= h && d[i+1][j] < 0){
      d[i+1][j] = d[i][j] + 1;
      que.push(P(i+1, j));
    }
    if(j+1 <= w && d[i][j+1] < 0){
      d[i][j+1] = d[i][j] + 1;
      que.push(P(i, j+1));
    }
  }
  int ans = 0;
  rep(i, h){
    rep(j, w) ans = max(ans, d[i+1][j+1]);
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  if(a == b && a != c)
    cout << "Yes\n";
  else if(a == c && a != b)
    cout << "Yes\n";
  else if(b == c && b != a)
    cout << "Yes\n";
  else
    cout << "No\n";
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 998244353;

long long int fact[1100000];

long long int rev_mod(long long int num){
	long long int pow_num = MOD - 2;
	long long int mod_num = MOD;
	long long int pow_cur = num;
	long long int ret = 1;
	while(pow_num > 0){
		if(pow_num % 2 == 1){
			ret *= pow_cur;
			ret %= mod_num;
		}
		pow_cur *= pow_cur;
		pow_cur %= mod_num;
		pow_num /= 2;
	}
	return ret;
}

long long int cnt[1100000];

int main(){
	for(int i = 1; i <= 1000100; i++){
		fact[i] += rev_mod(i);
		fact[i] %= MOD;
		for(int j = i * 2; j <= 1000100; j += i){
			fact[j] += MOD - fact[i];
			fact[j] %= MOD;
		}
	}
	int N;
	cin >> N;
	for(int i = 0; i < N; i++){
		int num;
		cin >> num;
		cnt[num] += 1;
	}
	long long int ans = 0;
	for(int i = 1; i <= 1000100; i++){
		long long int S = 0;
		for(int j = i; j <= 1000100; j += i){
			ans += MOD - (cnt[j] * j % MOD * j % MOD * fact[i] % MOD);
			S += cnt[j] * j;
		}
		S %= MOD;
		ans += S * S % MOD * fact[i] % MOD;
		ans %= MOD;
	}
	cout << ans * rev_mod(2) % MOD << endl;
	return 0;
}

Measured memory_bytes: 16640
N,L = map(int,input().split())

l = []
tmp = 1000000
ans_tmp = 0

for i in range(N):
    l.append(L+i)
    if(abs(l[i]) < tmp):
        tmp = abs(l[i])
        ans_tmp = l[i]



ans = sum(l) - ans_tmp
print(ans)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
int h, w, n;
int ans[110][110];
int main()
{
	scanf("%d%d%d", &h, &w, &n);
	int x = 1, y = 0, dir = 1;
	for(int i = 1; i <= n; ++i)
	{
		int t;
		scanf("%d", &t);
		while(t--)
		{
			y += dir;
			if(y == w + 1) 
			{
				y = w;
				++x;
				dir = -dir;
			} 
			else if(y == 0)
			{
				y = 1;
				++x;
				dir = -dir;
			}
			ans[x][y] = i;
		}
	}
	for(int i = 1; i <= h; ++i)
	{
		for(int j = 1; j <= w; ++j) printf("%d ", ans[i][j]);
		puts(""); 
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
#define mp make_pair
using namespace std;
using LL = long long;
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; }
const int INF = 1e9;
const LL LLINF = 1e16;

using Graph = vector<vector<int>>;

int bfs(Graph &G, int st, int gl){
    vector<vector<int>> d(G.size(), vector<int>(3, -1));
    d[st][0] = 0;
    queue<pair<int, int>> que;
    que.push(mp(st, 0));
    while(!que.empty()){
        int v, m;
        tie(v, m) = que.front(); que.pop();
        int nm = (m+1)%3;
        repe(i, G[v]){
            if(d[i][nm] != -1) continue;
            d[i][nm] = d[v][m] + 1;
            que.push(mp(i, nm));
        }
    }
    return d[gl][0];
}


int main(){
    int n, m;
    cin >> n >> m;
    Graph G(n);
    rep(i, m){
        int u, v;
        cin >> u >> v;
        u--; v--;
        G[u].push_back(v);
    }
    int s, t;
    cin >> s >> t;
    s--; t--;
    int ans = bfs(G, s, t);
    if(ans > 0) ans /= 3;
    cout << ans << endl;
}

Measured memory_bytes: 11136
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

int cnt[200000];

int main()
{
  int i,x,y,n,m;
  scanf("%d%d",&n,&m);
  memset(cnt,0,sizeof(cnt));
  for (i=0;i<m;i++)
  {
    scanf("%d%d",&x,&y);
    x--;y--;
    cnt[x]++;cnt[y]++;
  }
  for (i=0;i<n;i++)
    if (cnt[i]%2!=0)
    {
      printf("NO\n");return 0;
    }
  printf("YES\n");
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;
using MIte = multimap<vector<long>, int>::iterator;

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

	int r, D, xint;
	cin >> r >> D >> xint;

	int x = xint;

	for (int i = 0; i != 10; ++i) {
		x = r * x - D;
		cout << x << endl;
	}

	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()
t = [0] * (M - 1)
for i in range(1, M):
    t[i - 1] = X[i] - X[i - 1]
t.sort(reverse=True)
print(sum(t[N - 1:]))


Measured memory_bytes: 13968
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class D
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var HWN = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var (H, W, N) = (HWN[0], HWN[1], HWN[2]);
            var grid = new HashSet<(int, int)>();
            var AB = new (int A, int B)[N];
            for (var i = 0; i < N; i++)
            {
                var ab = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
                AB[i] = (ab[0], ab[1]);
                grid.Add((ab[0], ab[1]));
            }
            var answer = new long[10];
            answer[0] = (long)(H - 2) * (W - 2);

            int GetCount(int h, int w)
            {
                var ret = 0;
                for (var y = -1; y <= 1; y++)
                {
                    for (var x = -1; x <= 1; x++)
                    {
                        if (grid.Contains((h + y, w + x))) ret++;
                    }
                }
                return ret;
            }

            var hash = new HashSet<(int, int)>();
            for (var k = 0; k < N; k++)
            {
                var (h, w) = AB[k];
                for (var i = -1; i <= 1; i++)
                {
                    if (h + i <= 1 || h + i >= H) continue;
                    for (var j = -1; j <= 1; j++)
                    {
                        if (w + j <= 1 || w + j >= W) continue;
                        if (hash.Contains((h + i, w + j))) continue;
                        hash.Add((h + i, w + j));
                        var count = GetCount(h + i, w + j);
                        answer[count]++;
                        answer[0]--;
                    }
                }
            }

            for (var i = 0; i < 10; i++)
            {
                Console.WriteLine(answer[i]);
            }
        }
    }
}


Measured memory_bytes: 90224
import Foundation

extension String {
    @inlinable
    func wordsMap<T>(_ f: (Substring) -> T?) -> [T] {
        return self.split(separator: " ").compactMap(f)
    }
}
 
@inlinable
func 📜<T>(_ f: (Substring) -> T?) -> [T] {
    return readLine()!.wordsMap(f)
}

prefix operator ✂
extension Array {
    typealias E = Array.Element
    static prefix func ✂ (a: Array) -> (E, E) { return (a[0], a[1]) }
    static prefix func ✂ (a: Array) -> (E, E, E) { return (a[0], a[1], a[2]) }
    static prefix func ✂ (a: Array) -> (E, E, E, E) { return (a[0], a[1], a[2], a[3]) }
    static prefix func ✂ (a: Array) -> (E, E, E, E, E) { return (a[0], a[1], a[2], a[3], a[4]) }
}

// ✂📜

func main() {
    let (a, b, c) = ✂📜 { Int($0)! }
    if a == b && b != c || a == c && a != b || b == c && a != c {
        print("Yes")
    } else {
        print("No")
    }
}

main()



Measured memory_bytes: 13492
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
//extension Array where Element == String {
//    func joined(separator separator: String) -> String {
//        return self.joinWithSeparator(separator)
//    }
//}
extension Array where Element: Comparable {
    func max() -> Element {
        return self.maxElement()!
    }
    func min() -> Element {
        return self.minElement()!
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}
func exponentiate(_ lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}

/*************** テストスペース ***************/



/*************** メインプログラム ***************/

let X = readInt()!
var ans = 0
loop: for b in 1..<32 {
    for p in 2..<10 {
        let exp = exponentiate(b, p)
        if exp == X {
            ans = exp
            break loop
        } else if exp < X {
            ans = max(exp, ans)
        } else {
            break
        }
    }
}
print(ans)


Measured memory_bytes: 6632
#include <cstdio>

int main() {
  int a, b, c, x, y = 0;
  scanf("%d %d %d", &a , &b, &c);
  for(x = a; x <= b; x++){
    if(c%x == 0) y++;
  }
  printf("%d\n", y);

  return 0;
}

Measured memory_bytes: 2756
#include <bits/stdc++.h>
 
using namespace std;
 
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define forp(a,b,c) for(int (a)=(b); (a)<(c); (a++))
#define form(a,b,c) for(int (a)=(b); (a)>(c); (a--))
#define fori(a,b) for(auto (a):(b))
#define pb(a) push_back(a)
#define INF ((unsigned) ~0)
#define endl "\n"
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
ll gcd(ll a, ll b) {return b ? gcd(b, a%b) : a;}
 
int main()
{
    fastIO
    int res=0;
    int n,in;
    cin>>n;
    forp(i,1,n+1)
    {
        cin>>in;
        if(i%2==1 && in%2==1) res++;
    }
    cout<<res;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
//#include <iostream>
//#include <iomanip>
//#include <vector>
//#include <cmath>
//#include <algorithm>
using namespace std;


#define F first
#define PB push_back
#define MP make_pair

typedef unsigned long long ll;

ll p = pow(10, 9) + 7;





int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int N, W;
    cin >> N >> W;
    vector<ll> v(N + 1);
    vector<ll> w(N + 1);
    for(ll i = 1; i <= N; i++)
    {
        cin >> w[i] >> v[i];
    }

    vector<vector<ll> > dp(W + 1 , vector<ll>(N + 1));

    for(ll i = 1; i <= W; i++)
    {
        for(ll j = 1; j<= N; j++)
        {
            if(w[j] <= i)
            {
                dp[i][j] = max(dp[i - w[j]][j - 1] + v[j], dp[i][j - 1]);
            }else
            {
                dp[i][j] = dp[i][j - 1];
            }
        }

    }
    cout << dp[W][N] << endl;
}


Measured memory_bytes: 82304
#include <iostream>
#include <cstdio>
using namespace std;
int n, a;
double ans;

int main()
{
    cin >> n;
    while(n--){
        cin >> a;
        ans += 1.0 / a;
    }
    ans = 1.0 / ans;
    printf("%.9f", ans);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <cmath>

#include <sstream>
#include <bitset>

using namespace std;
long long MOD = 1000000007LL;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX  2147483647

int main() {
	int N, K;
	cin >> N >> K;
    ++N;

	long long ans = 1;



	for (long long i = K; i < N; ++i) {
        long long buf1 = i * (i - 1) / 2;
        long long buf2 = i * (N - i) + buf1;
        ans = (ans + (buf2 - buf1) + 1) % MOD;
	}

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

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <list>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

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

int main() {
    int n;
    cin >> n;
    vector<ll> t(n);
    rep(i, n) cin >> t[i];
    long long ans = t[0];
    rep(i, n) ans = lcm(ans, t[i]);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
    int num;
    double dis1=0,dis2=0,dis3=0,dis4=0,tmp=0;
    cin>>num;
    double vector1[num];
    double vector2[num];
    for(int i=0;i<num;i++) {
        cin >> vector1[i];
    }
    for(int i=0;i<num;i++)
    {
        cin>>vector2[i];
        tmp=abs(vector1[i]-vector2[i]);
        dis1+=tmp;
        dis2+=pow(tmp,2);
        dis3+=pow(tmp,3);
        if(tmp>dis4) dis4=tmp;
    }
    cout<<setiosflags(ios::fixed)<<setprecision(8)<<dis1<<endl<<sqrt(dis2)<<endl<<pow(dis3,0.333333333333333)<<endl<<dis4<<endl;
    return 0;
}


Measured memory_bytes: 3476
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;



int main(){
    LL N,K;
    cin >> N >> K;
    vector<LL> v(K,0);
    for(int i=1;i<=N;i++){
        v[i%K]++;
    }
    LL ans=0;
    for(int i=0;i<K;i++){
        if((2*K-2*i)%K==0) ans+=v[i]*v[(K-i)%K]*v[(K-i)%K];
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int n;
    cin>>n;
    int points[n+1][3];
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<3;j++){
            cin>>points[i][j];
        }
    }
    int dp[n+1][3];
    dp[1][0]=points[1][0];dp[1][1]=points[1][1];dp[1][2]=points[1][2];
    for(int i=2;i<=n;i++)
    {
        for(int j=0;j<3;j++)
        {
            dp[i][j]=points[i][j]+max(dp[i-1][(j+4)%3],dp[i-1][(j+5)%3]);
        }
    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;
    return 0;
}


Measured memory_bytes: 2560
#include <cstdio>
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <set>
#include <cstring> 

using namespace std;

#ifdef DEBUG_MODE
#define DBG(n) n;
#else
#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;

vector<vector<int>> v(111111);

ll graphType[3];
ll pointColor[111111];

int main() {

	ll n, m; cin >> n >> m;

	REP(i, m) {
		int a, b; cin >> a >> b;
		a--; b--;
		v[a].PB(b);
		v[b].PB(a);
	}

	REP(i, n) {
		if (pointColor[i] == 0) {
			queue<int> que;
			que.push(i);
			pointColor[i] = 1;
			int thisType = 1;
			while (!que.empty()) {
				auto now = que.front(); que.pop();

				REP(j, v[now].size()) {
					if (pointColor[v[now][j]] == 0) {
						pointColor[v[now][j]] = -pointColor[now];
						que.push(v[now][j]);
					}
					else {
						if (pointColor[v[now][j]] == pointColor[now]) {
							thisType = 2;
						}
					}
				}

			}
			if (v[i].size() == 0) {
				graphType[0]++;
			}
			else {
				graphType[thisType]++;
			}
		}
	}

	ll ans = 0;


	ans += 2 * graphType[0] * (n - graphType[0]);
	ans += graphType[0] * graphType[0];
	ans += 2 * graphType[1] * graphType[1];
	ans += 2 * graphType[1] * graphType[2];
	ans += graphType[2] * graphType[2];

//	SHOW1d(graphType, 3);
//	SHOW1d(pointColor, n);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 7936