akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int W = sc.nextInt();
		Queue A = new PriorityQueue(Collections.reverseOrder());
		Queue B = new PriorityQueue(Collections.reverseOrder());
		Queue C = new PriorityQueue(Collections.reverseOrder());
		Queue D = new PriorityQueue(Collections.reverseOrder());
		
		/*int[]A = new int[W];
		int[]B = new int[W];
		int[]C = new int[W];
		int[]D = new int[W];*/
		long w1 = 0;
		for(int i = 0 ; i<N; i++){
			int w = sc.nextInt();
			int v = sc.nextInt();
			if(i == 0 )w1 = w;
			if(w-w1 == 0){
				A.add(v);
				//a++;
			}
			else if(w-w1 == 1){
				//B[b] = v;
				B.add(v);
		//		b++;
			}
			else if(w-w1 == 2){
			//	C[c] = v;
			//	c++;
				C.add(v);
			}
			else if(w-w1 == 3){
		//		D[d] = v;
		//		d++;
				D.add(v);
			}
		}
	/*	System.out.println(A);
		System.out.println(B);
		System.out.println(C);
		System.out.println(D);*/
	//	Queue test = new PriorityQueue(Collections.reverseOrder());
	//	test = A;
	//	System.out.println(test);
		/*Arrays.sort(A);
		Arrays.sort(B);
		Arrays.sort(C);
		Arrays.sort(D);
		System.out.println(Arrays.toString(A));
		System.out.println(Arrays.toString(B));
		System.out.println(Arrays.toString(C));
		System.out.println(Arrays.toString(D));*/
		int res = 0;
	/*	if(w1>W){
			System.out.println(res);
			return;
		}*/
		for(int i = 0 ; i<=A.size(); i++){
			for(int j = 0 ; j<=B.size(); j++){
				for(int x = 0 ; x<=C.size(); x++){
					for(int y = 0 ; y<=D.size(); y++){
						long w = (long)(i*w1)+(long)(j*(w1+1))+(long)(x*(w1+2))+(long)(y*(w1+3));
			//			System.out.println("w = " + w);
						int v = 0;
						if(w<=W){
							int a = i, b = j, c = x, d = y;
				//			System.out.println(w+"  "+W);
							Queue ca = new PriorityQueue(A);
							Queue cb = new PriorityQueue(B);
							Queue cc = new PriorityQueue(C);
							Queue cd = new PriorityQueue(D);
							while(a-->0){
								v+=(int)ca.poll();
							}
							while(b-->0){
								v+=(int)cb.poll();
							}
							while(c-->0){
								v+=(int)cc.poll();
							}
							while(d-->0){
								v+=(int)cd.poll();
							}
						}
						res = Math.max(res, v);
					}
				}
			}
		}
	/*	System.out.println("- -- - - - - - - - - - - - - - ");
		System.out.println(A);
		System.out.println(B);
		System.out.println(C);
		System.out.println(D);
		System.out.println("- - - - - - - - - - - - - - - - ");*/
		System.out.println(res);
		/*for(int i = A.length-1 ; i>=0 && A[i]!=0; i--){
			for(int j = B.length-1 ; j>=0 && B[i]!=0 ; j--){
				for(int k = C.length-1; k>=0 && C[i]!=0; k--){
					for(int m = D.length-1 ; m>=0 && D[i]!=0 ; m--){
						if(i*w1+j*(w1+1)+k*(w1+2)+m*(w1+3) <= W ){
							int v = A[i]+B[j]+C[k]+D[m];
							res = Math.max(v, res);
						}
					}
				}
			}
		}*/
	//	System.out.println(res);
	}
}


Measured memory_bytes: 59664
#include<stdio.h>
int main()
{
	int x,a,b;
	
	scanf("%d%d%d",&x,&a,&b);
	
	if(b<=a){
		puts("delicious");
	}else if(x+a>=b){
		puts("safe");
	}else{
		puts("dangerous");
	}
	return 0;
}

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

using namespace std;

int n, m, q;
int res, a[55], b[55], c[55], d[55], p[15];

void solve(int lv, int lt) {
	if (lv == n) {
		int tot = 0;
		for (int i = 0; i < q; i++) {
			if (p[b[i]] - p[a[i]] == c[i]) tot += d[i];
		}
		res = max(res, tot);
		return;
	}
	
	for (int i = lt; i <= m; i++) {
		p[lv] = i;
		solve(lv + 1, i);
	}
}

int main() {
	scanf("%d%d%d", &n, &m, &q);
	
	for (int i = 0; i < q; i++) {
		scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
		a[i]--;
		b[i]--;
	}
	
	solve(0, 1);
	
	printf("%d\n", res);
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44


/*const int MOD = (int) 1e9 + 7;

inline void mod(int &x) {
    if(x >= MOD)
        x -= MOD;
}

inline void add(int &x, int y) {
    x += y;
    mod(x);
}

inline void mul(int &x, int y) {
    x = (1LL * x * y) % MOD;
}*/

using namespace std;



int main() {
    //ifstream cin("B.in");
    //ofstream cout("B.out");
    int i, n;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    cin >> n;
    vector <int> p(n + 1), pos(n + 1);
    for(i = 1; i <= n; i++) {
        cin >> p[i];
        pos[p[i]] = i;
    }

    set <int> mst;
    ll ans = 0;
    for(i = n; i >= 1; i--) {
        mst.insert(pos[i]);
        auto it = mst.find(pos[i]);

        int l1 = pos[i], r1 = n - pos[i] + 1, l2 = 0, r2 = 0;

        if(next(it) != mst.end()) {
            it = next(it);
            r1 = *it - pos[i];
            r2 = n - *it + 1;
            if(next(it) != mst.end()) {
                it = next(it);
                r2 = *it - pos[i] - r1;
                it = prev(it);
            }
            it = prev(it);
        }
        if(it != mst.begin()) {
            it = prev(it);
            l1 = pos[i] - *it;
            l2 = *it;
            if(it != mst.begin()) {
                it = prev(it);
                l2 = pos[i] - *it - l1;
                it = next(it);
            }
            it = next(it);
        }
        //cerr << l1 << " " << r1 << " " << l2 << " " << r2 << "\n";
        ans += 1LL * i * (1LL * l1 * r2 + 1LL * l2 * r1);
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 5760
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  while (cin >> N) {
    vector<int> W(N);
    for (int& x : W) cin >> x;
    int res = 1 << 29;
    for (int T = 0; T < N - 1; T++) {
      int S1 = 0, S2 = 0;
      for (int i = 0; i <= T; i++) S1 += W[i];
      for (int i = T + 1; i < N; i++) S2 += W[i];
      res = min(res, abs(S1 - S2));
    }
    cout << res << endl;
  }
  return 0;
}


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

using namespace std;

int main(void){
    int d, t, s;
    cin >> d >> t >> s;
    cout << ((s * t >= d) ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
ll pow1(ll a, ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
		{
			ans=ans*a;
		}
		a=a*a;
		b=b>>1;
	}
	return ans;
}
int main()
{
	ll n,k,i,j,x;
	cin>>n>>k;
	ll cnt = 0,cnt1 = 0,cnt2 = 0;
	vector<ll> v;
	for(i=0;i<n;i++)
	{
		cin>>x;
		v.pb(x);
		if(x == 0)
			cnt++;
		if(x>0)
			cnt1++;
		else if(x<0)
			cnt2++;
	}
	if((cnt1 == n-1 && cnt == 1) || cnt1 == n)
	{
		cout<<(v[k-1])<<endl;
		return 0;
	}
	if((cnt2 == n-1 && cnt == 1) || cnt2 == n)
	{
		cout<<abs(v[n-k])<<endl;
		return 0;
	}
	ll arr[100005];
	ll mi = 1e18;
	for(i=0;i<=(n-k);i++)
	{
		arr[i] = min(abs(v[i]),abs(v[i+k-1])) + abs(v[i+k-1]-v[i]);
		mi = min(mi,arr[i]);
	}
	cout<<mi<<endl;
	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,m;
vi a,d;
vvi g;

int dfs(int v,int p){
	int mx=0;
	for(auto u:g[v]) if(u!=p) mx=max(mx,dfs(u,v));
	return mx+a[v];
}

bool DFS(int v,int p,vi& b){
	if(v==0){
		b[v]=1;
		return 1;
	}
	for(auto u:g[v]) if(u!=p){
		if(DFS(u,v,b)){
			b[v]=1;
			return 1;
		}
	}
	return 0;
}

int main(){
	cin>>n>>m;
	a=d=vi(n);
	g=vvi(n);
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		u--;v--;
		g[u].push_back(v);
		g[v].push_back(u);
		d[u]++;d[v]++;
	}
	vi b(n,1);
	queue<int> q;
	for(int i=0;i<n;i++) if(d[i]==1){
		q.push(i);
		b[i]=0;
	}
	while(!q.empty()){
		int v=q.front();
		q.pop();
		for(auto u:g[v]) if(b[u]){
			d[u]--;
			if(d[u]==1){
				q.push(u);
				b[u]=0;
			}
		}
	}
	int sum=0,cnt=0;
	for(int i=0;i<n;i++) if(b[i]) sum+=a[i],cnt++;
	if(sum){
		int N=n-cnt+1;
		vvi G(N);
		vi c(n),A(N);
		int id=1;
		for(int i=0;i<n;i++) if(!b[i]){
			c[i]=id;
			A[id]=a[i];
			id++;
		}
		A[0]=sum;
		for(int u=0;u<n;u++) for(auto v:g[u]) if(c[u]!=c[v]) G[c[u]].push_back(c[v]);
		n=N;
		g=G;
		a=A;
		if(c[0]==0) cout<<dfs(0,-1)<<endl;
		else{
			int res=dfs(c[0],-1);
			b=vi(N);
			DFS(c[0],-1,b);
			sum=0,cnt=0;
			for(int i=0;i<n;i++) if(b[i]) sum+=a[i],cnt++;
			N=n-cnt+1;
			G=vvi(N);
			c=vi(n),A=vi(N);
			id=1;
			for(int i=0;i<n;i++) if(!b[i]){
				c[i]=id;
				A[id]=a[i];
				id++;
			}
			A[0]=sum;
			for(int u=0;u<n;u++) for(auto v:g[u]) if(c[u]!=c[v]) G[c[u]].push_back(c[v]);
			n=N;
			g=G;
			a=A;
			cout<<max(res,dfs(0,-1))<<endl;
		}
	}
	else cout<<dfs(0,-1)<<endl;
}


Measured memory_bytes: 18280
#include <stdio.h>

int main(){
    double h, max, min;
    
    scanf("%lf", &max);
    
    min = max;
    
    while(scanf("%lf", &h) != EOF)
        if     (h > max) max = h;
        else if(h < min) min = h;
    
    printf("%.1lf\n", max - min);
 
    return 0;
}

Measured memory_bytes: 652
void main()
{
    long n, w;
    rdVals(n, w);
    Pair[] pair = n.rdCol!Pair;

    long[][] dp = new long[][](n+1, w+1);
    foreach (i, p; pair)
    {
        foreach (j; 0 .. w+1)
        {
            dp[i+1][j] = dp[i][j];
            if (j - p.a < 0) continue;
            dp[i+1][j] = max(dp[i+1][j], dp[i][j-p.a]+p.b);
        }
    }

    dp[n][w].writeln;
}

struct Pair
{
    long a, b;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

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

int main() {
  int A, B;
  cin >> A >> B;
  int p, m, c;
  p = A+B;
  m = A-B;
  c = A*B;

  if(p >= m && p >= c)
    cout << p << endl;
  else if(m >= p && m >=c)
    cout << m << endl;
  else if(c >= p && c >= m)
    cout << c << endl;
  return 0;
  
}

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

using namespace std;

int main() {
  int ssize;
  string s,t;
  cin>>s>>t;

  ssize=s.size();
  if(t.compare(0,ssize,s)==0){
    cout<<"Yes";
  }else{
    cout<<"No";
  }
  return 0;

}

Measured memory_bytes: 3588
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

t1,t2 = inm()
a1,a2 = inm()
b1,b2 = inm()
c = (a1-b1)*t1
d = (a2-b2)*t2
if c>0 and d>0 or c<0 and d<0 or abs(c)>abs(d):
    print(0)
    exit()
ac = abs(c)
e = abs(d)-ac
if e==0:
    print('infinity')
else:
    print((ac//e)*2 + (0 if ac%e == 0 else 1))


Measured memory_bytes: 38384
// failed to generate code

#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
#define cerr                                                                   \
  if (true)                                                                    \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

ll H, W, N;
vi A;

int d[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};

int M[200][200];

// bool BFS(int x, int y, int c) {
// 	int remain = A[c];
//
//
// }

void think() {
  REP(i, 200) REP(j, 200) { M[i][j] = -1; }

  // REP(i, N) {
  // REP(x, W) REP(y, H) if (M[y][x] == -1) { BFS(x, y, i); }
  // }
  REP(y, H) REP(x, W) {
    REP(i, N) if (A[i]) {
      M[x][y] = i + 1;
      A[i]--;
      break;
    }
  }

  REP(y, H) {
    if (y % 2 == 0) {
      REP(x, W) {
        cout << M[x][y];
        if (x != W - 1)
          cout << " ";
      }
    } else {
      for (int x = W - 1; x >= 0; --x) {
        cout << M[x][y];
        if (x != 0)
          cout << " ";
      }
    }
    cout << endl;
  }
}

int main() {
  ios::sync_with_stdio(false);

  cin >> H >> W;
  cin >> N;
  A.resize(N);
  REP(i, N) { cin >> A[i]; }

  think();
}


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

typedef long double ld;

struct pt{
    ld x,y;
    int id;
};
int arr[10];
pt pts[10];
int n;

ld get(){
    ld resp=0;
    for (int i=2; i<=n; i++){
        int u = arr[i-1], v = arr[i];
        resp += sqrt((pts[u].x - pts[v].x)*(pts[u].x - pts[v].x) + (pts[u].y - pts[v].y)*(pts[u].y - pts[v].y));
    }
    return resp;
}

int fat(int x){
    int resp=1;
    for (int i=1; i<=x; i++) resp *= i;
    return resp;
}

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

    cin >> n;

    for (int i=1; i<=n; i++){
        cin >> pts[i].x >> pts[i].y;
        pts[i].id = i;
        arr[i] = i;
    }

    ld total = fat(n), soma=0;
    do{
        soma += get();
    } while(next_permutation(arr+1, arr+n+1));
    cout << setprecision(12);
    cout << fixed << soma / total << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define endl "\n"
 
 
int pow1(int n, int p)
{
	if(p==0)	return 1;
	int x=pow1(n, p/2);
	x=(x*x)%mod;
	if(p%2==0)
		return x;
	else
		return (x*n)%mod;
}
 
int32_t main()
{
	fast;

	int n;
	cin>>n;
	map<pair<int, int>, int> m;
	for(int i=0;i<n;i++)
	{
		int x=i+1;
		int d1=x%10;
		int d2=to_string(x)[0]-48;
		m[{d1, d2}]++;
	}

	int c=0;

	for(int i=0;i<n;i++)
	{
		int x=i+1;
		int d1=x%10;
		int d2=to_string(x)[0]-48;
		c+=m[{d2, d1}];
	}
	cout<<c<<endl;

	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#include <climits>
#include <memory>
#include <numeric>
#include <utility>


#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
#define PI 3.14159265358979323846264338327950L;
const int INF2 = 1001001001;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
const ll LINF = 1e18 + 100;
using namespace std;
using Graph = vector<vector<int>>;



int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};

const int MAX_N = 110000;

int memo[MAX_N];

int rec(int n) {
	if (n == 0)return 0;
	if (memo[n] != -1)return memo[n];

	int res = n;

	for (int pow6 = 1; pow6 <= n; pow6 *= 6)res = min(res, rec(n - pow6) + 1);

	for (int pow9 = 1; pow9 <= n; pow9 *= 9)res = min(res, rec(n - pow9) + 1);

	return memo[n] = res;
}

int calc(int x) {
	int ret = 0;
	while (x % 2 == 0) {
		x /= 2;
		ret++;
	}

	return ret;
}

int a[12][12];
int D;
ll G;
vector<ll> P, C;

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

	int n,k;

	cin >> n >> k;
	ll a = 0;
	ll b = 0;
	ll ans = 0;

	rep(i, 1, n + 1) {
		if (i % k == 0)a++;
		else if (i % k == k / 2)b++;
	}

	ans = a * a * a;

	if (k % 2 == 0)ans += b * b * b;

	cout << ans << endl;
	
	
	
}
	

Measured memory_bytes: 256
module Main where

import Control.Applicative
import Control.Monad
import Data.List
import qualified Data.Graph as G
import qualified Data.ByteString.Lazy.Char8 as B

readi b | Just (n, _) <- B.readInt b = n

bfs :: [G.Tree Int] -> [[Int]]
bfs [] = []
bfs ts = fmap root ts : bfs (concatMap sub ts)
  where
    root (G.Node r _)  = r
    sub  (G.Node _ sf) = sf

main :: IO ()
main = do
    [n, m] <- fmap read . words <$> getLine :: IO [Int]
    as <- fmap ((\[a, b] -> (readi a, readi b)) . B.words) . B.lines <$> B.getContents

    let g = G.buildG (1, n) as
    let tree = G.dfs g [1]
    let bss = take 3 $ bfs tree

    if length bss < 3
        then putStrLn "IMPOSSIBLE"
        else do
            if any (== n) (bss !! 2)
                then putStrLn "POSSIBLE"
                else putStrLn "IMPOSSIBLE"

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

int main(){
    int h,a;
    cin >> h >> a;
    int ans = 0;
    while(h>0){
        h-=a;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <iostream>
using ll = long long;
using namespace std;

int main(){
  ll a, b, k;
  cin >> a >> b >> k;
  if (a >= k) a -= k;
  else if (a + b >= k){
    k -= a;
    a = 0;
    b -= k;
  }
  else{
    a = 0;
    b = 0;
  }
  cout << a << ' ' << b << endl;
  
  return 0;
}

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

int main() {
	int n,i; string w;
	cin >> w;
	vector<int> a(26);
	char c;
	for(i=0; i<w.size(); i++){
		c=w[i];
		n=c-'a';
		a[n]++;
	}
	for(i=0; i<26; i++){
		if(a[i]%2==1){
			cout << "No"; return 0;
		}
	}
	cout << "Yes";

}


Measured memory_bytes: 256
defmodule Main do
  def main do
      [a, b] =
      IO.read(:line)
      |> String.trim
      |> String.split(" ")
    n = String.to_integer(a <> b)
    if :math.sqrt(n) |> Float.round == :math.sqrt(n) do
      IO.puts("Yes")
    else
      IO.puts("No")
    end
  end
end


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

typedef long long LL;
typedef unsigned long long ULL;

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define __m  int mid=l+(r-l)/1

const int maxn   = 4e5 + 7;
const LL  inf_LL = 9e18   ;
const int inf    = 2e9 + 7;
const int mod    = 1e9 + 7;

int have[maxn];
int main() {
#ifdef LOCAL
    freopen("sample.in", "r", stdin);
#endif
    //ios::sync_with_stdio(false);

    int n,tot=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        int k;
        scanf("%d",&k);
        if(i==k)
            have[tot++]=i;
    }
    int ans=tot;
    for(int i=0;i<tot;i++)
    {
        if(i+1<tot&&have[i+1]-have[i]==1)
        {
            ans-=1;
            i++;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>

void binary(int n, std::vector<int> s, int q, std::vector<int> t) {
    int count = 0;
    int left;
    int right;
    int mid;
    for (int i = 0; i < q; i++) {
        left = 0;
        right = n;

        while (left < right) {
            mid = (left + right) / 2;
            if (t[i] == s[mid]) {
                count++;
                break;
            } else if (t[i] < s[mid]) {
                right = mid;
            } else {
                left = mid + 1; 
            }
        }
    }
    std::cout << count << std::endl;
    return;
}

int main(void) {
    int n;
    std::cin >> n;
    std::vector<int> s(n, 0);
    for (int i = 0; i < n; i++) {
        std::cin >> s[i];
    }

    int q;
    std::cin >> q;
    std::vector<int> t(q, 0);
    for (int i = 0; i < q; i++) {
        std::cin >> t[i];
    }

    binary(n, s, q, t);
    return 0;
}

Measured memory_bytes: 3836
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val s, t = sc.next()
  if (s.length < t.length) {
    println("UNRESTORABLE")
  } else {
    s.toSeq.sliding(t.length).zipWithIndex.toList.reverse.find(
      _._1.zip(t).forall{case (c1, c2) => c1 == '?' || c1 == c2}
    ) match {
      case Some((_, idx)) =>
        println(s"${s.take(idx).replace('?', 'a')}$t${s.drop(idx + t.length).replace('?', 'a')}")
      case None => println("UNRESTORABLE")
    }
  }
}


Measured memory_bytes: 58980
#include <bits/stdc++.h>
using namespace std;
 
//DEFINE and TYPEDEF--------------------------------------------------------------
 
#define timeKyaHorhaH 1.0 * clock() / CLOCKS_PER_SEC
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

#define FORG(i,a,n) for(lld i=a;i<n;i++) //for - general
#define FORZ(i,n) for(lld i=0;i<n;i++) //for - zero
#define FORGI(i,a,n,inc) for(lld i=a;i<n;i+=inc) //for - general incremental
#define FORZI(i,n,inc) for(lld i=0;i<n;i+=inc) //for - zero incremental
#define DEBUG(x) cerr<<(#x)<<" is "<<(x)<<"\n" //to debug values of variables
#define ZINDA cerr<<"\nIdhar-ich hai apun!!\n"; //to debug if code reached that point
#define SPEEDUP ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
 
#define SORTall(m) sort(m.begin(),m.end());
 
#define st first
#define nd second
#define mkp make_pair
#define pb push_back
#define endl '\n'
#define mod 1000000007
 
typedef long long int lld;
typedef unsigned long long int ulld;
 
lld power(lld b, lld e)
{
    if(e==0)
        return 1;
    if(e%2==1)
        return b*power(b*b,(e-1)/2);
    else
        return power(b*b,e/2);
}
 
lld power(lld b, lld e, lld m)
{
	if(e==0)
		return 1;
	if(e%2==1)
		return b*power(((b%m)*(b%m))%m,(e-1)/2,m)%m;
	else
		return power(((b%m)*(b%m))%m,e/2,m)%m;
}
 
int nDig(lld n)
{
	if(n<0) 
		n*=-1;
	if(n==0)
		return 1;

    return floor(log10(n) + 1);
}

//endl : changed to '\n', to flush comment that definition
//--------------------------------------------------------------------------------

lld gcd(lld a, lld b)
{
	if(a<b)
		swap(a,b);

	return __gcd(a,b);
}

lld gcd(lld a, lld b, lld c)
{
	lld x=gcd(a,b);
	lld y=gcd(b,c);

	return gcd(max(x,y),min(x,y));
}

void swagWaalaFunction()
{
	lld n,ans=0;
	cin>>n;

	FORG(i,1,n+1)
	FORG(j,1,n+1)
	FORG(k,1,n+1)
		ans+=gcd(i,j,k);

	cout<<ans;
	return;
}

int main()
{
    SPEEDUP;
 	lld t=1;
 	//cin>>t;

 	while(t--)
 		swagWaalaFunction();
	
	// cerr<<"\n"<<timeKyaHorhaH; 	
 	return 0;
}

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

int makeBigInt(char*, const char*);
int sumBigInt(char*, const char*, const char*);

int main(void){
	int i, n, err;
	char buf[1024], a[81], b[81];
	
	scanf("%d", &n);
	
	while(n--){
		err = 0;
		
		scanf(" %s", buf);
		
		err += makeBigInt(a, buf);
		
		scanf(" %s", buf);
		
		err += makeBigInt(b, buf);
		
		err += sumBigInt(buf, a, b);
		
		if(err < 0){
			printf("overflow\n");
			continue;
		}
		
		if(sumBigInt(buf, a, b))
			printf("overflow\n");
		else{
			for(i = 0; i < 79; i++)
				if(buf[i] != '0') break;
			
			printf("%s\n", buf + i);
		}
	}
}

int makeBigInt(char *s, const char *t){
	int l, i;
	
	l = 80 - strlen(t);
	
	if(l < 0) return -1;
		
	for(i = 0; i < l; i++)
		s[i] = '0';
	
	strcpy(s + l, t);
	
	return 0;
}

int sumBigInt(char *sum, const char *a, const char *b){
	int i, n;
	int m = 0;
	
	for(i = 79; i >= 0; i--){
		n = (a[i] - '0') + (b[i] - '0') + m;
		m = n / 10;
		sum[i] = (n % 10) + '0';
	}
	
	sum[80] = '\0';
	
	return (m ? -1 : 0);
}

Measured memory_bytes: 596
N = int(input())
D, X = map(int, input().split())
a = []
for i in range(N):
    a.append(int(input()))
    
c = []

for j in a:
    cnt = 0
    b = 0
    while b*j+1 <= D:
        cnt += 1
        b += 1
    c.append(cnt)

print(sum(c) + X)

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

const int maxn = 3000 + 5;
const int mod = 1e9 + 7;
const int inv = 500000004;
int dp[maxn][maxn], a[maxn], mult[maxn][maxn];
int pw[maxn], wp[maxn];

int main() {
    int n, q; scanf("%d%d", &n, &q);
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            dp[i][j] = a[i] > a[j];
            mult[i][j] = 0;
        }
    } 
    pw[0] = 1, wp[0] = 1;
    for (int i = 1; i <= q; ++i) {
        pw[i] = pw[i - 1] * 1ll * 2 % mod;
        wp[i] = wp[i - 1] * 1ll * inv % mod;
    }
    for (int t = 0; t < q; ++t) {
        int x, y; scanf("%d%d", &x, &y);
        --x, --y;
        vector<int> dxj, djx, dyj, djy;
        for (int j = 0; j < n; ++j) dxj.push_back(dp[x][j] * 1ll * pw[mult[x][j] + t] % mod);
        for (int j = 0; j < n; ++j) djx.push_back(dp[j][x] * 1ll * pw[mult[j][x] + t] % mod);
        for (int j = 0; j < n; ++j) dyj.push_back(dp[y][j] * 1ll * pw[mult[y][j] + t] % mod);
        for (int j = 0; j < n; ++j) djy.push_back(dp[j][y] * 1ll * pw[mult[j][y] + t] % mod);
        for (int j = 0; j < n; ++j) {
            if (j == x || j == y) continue;
            dp[x][j] = pw[mult[x][j] + t] * 1ll * dp[x][j] % mod;
            dp[j][x] = pw[mult[j][x] + t] * 1ll * dp[j][x] % mod;
            dp[y][j] = pw[mult[y][j] + t] * 1ll * dp[y][j] % mod;
            dp[j][y] = pw[mult[j][y] + t] * 1ll * dp[j][y] % mod;
        }
        for (int j = 0; j < n; ++j) {
            if (j == x || j == y) continue;
            (dp[x][j] += dyj[j]) %= mod;
            (dp[j][x] += djy[j]) %= mod;
            (dp[y][j] += dxj[j]) %= mod;
            (dp[j][y] += djx[j]) %= mod;
        }
        for (int j = 0; j < n; ++j) {
            if (j == x || j == y) continue;
            dp[x][j] = wp[mult[x][j] + t] * 1ll * dp[x][j] % mod;
            dp[j][x] = wp[mult[j][x] + t] * 1ll * dp[j][x] % mod;
            dp[y][j] = wp[mult[y][j] + t] * 1ll * dp[y][j] % mod;
            dp[j][y] = wp[mult[j][y] + t] * 1ll * dp[j][y] % mod;
        }
        for (int i = 0; i < n; ++i) {
            if (i == x || i == y) continue;
            mult[i][x]--;
            mult[x][i]--;
            mult[i][y]--;
            mult[y][i]--;
        }
        dp[x][y] = (pw[mult[x][y] + t] * 1ll * dp[x][y] % mod + dyj[x]) % mod;
        dp[y][x] = (pw[mult[y][x] + t] * 1ll * dp[y][x] % mod + dxj[y]) % mod;
        dp[x][y] = dp[x][y] * 1ll * wp[mult[x][y] + t] % mod;
        dp[y][x] = dp[y][x] * 1ll * wp[mult[y][x] + t] % mod;
        mult[x][y]--;
        mult[y][x]--;
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            (ans += dp[i][j] * 1ll * pw[mult[i][j] + q] % mod) %= mod;
            if (ans >= mod) ans -= mod;
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 70784
#include<iostream>
#include<string>
#include<bitset>

using namespace std;

int main() {

   int n;
   cin >> n;
   int live[4][3][10] = {};
   for (int i = 0; i < n; i++) {
      int b, f, r, v;
      cin >> b >> f >> r >> v;
      live[b - 1][f - 1][r - 1] += v;
   }

   for (int b = 0; b < 4; b++) {
      for (int f = 0; f < 3; f++) {
         for (int r = 0; r < 10; r++) {
            cout << " " << live[b][f][r];
         }
         cout << endl;
      }
      if (b != 3) {
         cout << "####################" << endl;
      }
   }

   return 0;

}

Measured memory_bytes: 1160
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vi b(n+1);
    rep(i,n-1)cin>>b[i+1];
    b[0]=b[n]=inf;
    int ans=0;
    rep(i,n){
        ans+=min(b[i],b[i+1]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int a,b,c;
int main() {
    cin>>a>>b>>c;
    int t=0;
    int ans=0;

    while(1) {
        rep(i,a) {
            t++;
            ans++;
            t%=60;
            if(t==c) {
                cout<<ans<<endl;
                return 0;
            }
        }
        t+=b;
        ans+=b;
        t%=60;
        if(t==0) {
            cout<<"-1"<<endl;
            return 0;
        }
    }



    return 0;
}

Measured memory_bytes: 1164
L,R = list(map(int, input().split()))

m = 2018

if L + 2019 < R:
    R = L + 2019

for i in range (L,R):
    for j in range(i+1,R+1):
        r = divmod(i*j, 2019)[1]
        if (r < m):
            m = r
print(m)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
 
using namespace std;
 
 
const int maxi=2e6+6;
 
 
int t[2][maxi];
int a[maxi],b[maxi];
int len,n;
int p[maxi];
int rez[maxi];
set<int> st;
set<int>st1;
 
void build(int *a, int n, int tip)
{
    len=1<< int (ceil(log2(n)));
 
    //cout<<len<<"\n";
    for (int i=len;i<2*len;i++)
        t[tip][i]=1e9;
 
    for (int i=len;i<2*len;i++)
        if (i>len+n-1) t[tip][i]=1e9; else
        if (i%2==0 && tip==1) t[1][i]=a[i-len+1]; else
        if (i%2==1 && tip==0)
        t[0][i]=a[i-len+1];
 
    for (int i=len-1;i>0;i--)
        t[tip][i]=min(t[tip][i<<1],t[tip][i<<1|1]);
}
 
 
int get(int l, int r,int tip)
{
    int ans=a[l];
 
    l+=len-1;
    r+=len;
 
    for (;l<r;l>>=1,r>>=1){
        if (l&1) ans=min(ans,t[tip][l++]);
        if (r&1) ans=min(ans,t[tip][--r]);
    }
    return ans;
}
 
 
int main()
{
 
    cin>>n;
 
    for (int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
         p[a[i]]=i;
    }
 
     build(a,n,0);
     build(a,n,1);
 
    st1.insert(0);
    st1.insert(n+1);
 
    st.insert(get(1,n,1));
 
    for (int i=1;i<=n;i+=2)
    {
        int cur=*st.begin();
        rez[i]=cur;
        int tip=(1-p[cur]%2);
        int idx=*st1.lower_bound(p[cur]);
        rez[i+1]=get(p[cur]+1,idx-1,tip);
        st.erase(cur);
 
        set<int>::iterator it=st1.lower_bound(p[cur]);
        it--;
 
        int ispod=*it;
        st1.insert(p[cur]);
        st1.insert(p[rez[i+1]]);
 
        if (p[cur]-ispod>1)
            st.insert(get(ispod+1,p[cur]-1,(ispod+1)%2));
 
         if (p[rez[i+1]]-p[cur]>1)
            st.insert(get(p[cur]+1,p[rez[i+1]]-1,(p[cur]+1)%2));
 
           if (idx-p[rez[i+1]]>1)
                st.insert(get(p[rez[i+1]]+1,idx-1,(p[rez[i+1]]+1)%2));
 
    }
 
  for (int i=1;i<=n;i++)
    printf("%d ",rez[i]);
  printf("\n");
   return 0;
}

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

int main(void) {
	string s;
	cin >> s;
	int ans = 0;
	if(s[0] == '1') ans ++;
	if(s[1] == '1') ans ++;
	if(s[2] == '1') ans ++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  double a,b,c,d,e,f,x,y;
  int ix,iy;

  while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f) != EOF){
    x = (c*e-b*f)/(a*e-b*d);
    y = (a*f-c*d)/(a*e-b*d);

    if(x>=0) ix = 1000*x+0.5;
    else ix = 1000*x-0.5;

    if(y>=0) iy = 1000*y+0.5;
    else iy = 1000*y-0.5;

    printf("%.3lf %.3lf\n",ix/1000.0,iy/1000.0);
  }

  return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

#define FOR(i,a,b) for(ll i = (a);i<(b);i++)
#define REP(i,a) FOR(i,0,(a))
#define MP make_pair

int main() {
	int a, b;
	cin >> a >> b;
	int sum = (a + b) % 24;
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)
#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))
#define all(x) (x).begin(),(x).end()
#define fast ios_base:: sync_with_stdio( false ); cin.tie(0); cout.tie(0);
#define eb              emplace_back
#define em              emplace
#define pb              push_back
#define Mp              make_pair
#define ff              first
#define ss              second
#define mod 1000000007
typedef long long ll;
using namespace std;

const int M = (int)(2e6 + 239);

ll gcd(ll a, ll b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b,a%b);
}


int getnum(string a)
{
    int i,p=0;
    rep0(i,a.size())
    {
        p*=10;
        p+=a[i]-'0';
    }
    return p;
}

int main()
{
    fast

    ll a;
    cin>>a;
    ll sum=0;
    for(int i=1; i<=a; i++)
    {
        for(int j=1; j<=a; j++)
        {
            for(int k=1; k<=a; k++)
            {
                ll temp=gcd(i,j);
                ll temp1=gcd(temp,k);
                sum+=temp1;
            }
        }
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 3648
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;

const int INF=2147483647;
const int MAXN=100000;
const int MAXM=500000;
int n,m,s;
int fir[MAXN],nxt[MAXM],to[MAXM],val[MAXM],cnt;

void add_edge(int u,int v,int w)
{
    nxt[++cnt]=fir[u];fir[u]=cnt;to[cnt]=v;val[cnt]=w;
}

int dis[MAXN],inq[MAXN];

void SPFA(int s)
{
    for(int i=0;i<n;i++) dis[i]=INF;
	dis[s]=0;
	
    queue<int>Q;Q.push(s);
    while(!Q.empty())
	{
        int u=Q.front();
		Q.pop();
        for(int e=fir[u];e;e=nxt[e])
		{
            int v=to[e],w=val[e];
            if(dis[u]+w<dis[v])
			{
                dis[v]=dis[u]+w;
                if(!inq[v]) Q.push(v);
            }
        }
    }
}

int main()
{
    scanf("%d%d%d",&n,&m,&s);
    for(int u,v,w,i=0;i<m;i++)
	{
        scanf("%d%d%d",&u,&v,&w);
        add_edge(u,v,w);
    }
    SPFA(s);
    for(int i=0;i<n;i++)
	{
		if (dis[i] == INF)
		{
			printf("INF\n");
		}
		else
		{
			printf("%d\n",dis[i]);
		}
	}
    return 0;
}

Measured memory_bytes: 9916
n, w = map(int, input().split())
value = []
weight = []

for i in range(n):
    ww, v = map(int, input().split())
    value.append(v)
    weight.append(ww)

dp = [[0 for i in range(w + 1)] for j in range(n + 1)]

for i in range(n):
    for mw in range(w + 1):
        if weight[i] <= mw:
            dp[i + 1][mw] = max(dp[i][mw], dp[i][mw - weight[i]] + value[i])
        else:
            dp[i + 1][mw] = dp[i][mw]

print(dp[n][w])


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

int n, m;
vector<int> sw;
vector<vector<int>> b;
vector<int> p;

bool check(){
	vector<int> res (m + 1, 0);
	for(int i = 1; i <= n; i++){
		if(sw[i] == 0) continue;
		for(int j = 0; j < (int)b[i].size(); j++){
			res[b[i][j]]++;
		}
	}
	for(int i = 1; i <= m; i++)
		if((res[i] % 2) != p[i]) return false;
	return true;
}

int bf(int ps = 1){
	if(ps > n) return check();
//	cerr << ps << '\n';
	int w = 0;
	sw[ps] = 0;
	w += bf(ps + 1);
	sw[ps] = 1;
	w += bf(ps + 1);
	return w;
}

int main() {
	cin >> n >> m;
	sw = vector<int>(n + 1, 0);
	p = vector<int>(m + 1);
	b = vector<vector<int>> (n + 1);
	for(int i = 1; i <= m; i++){
		int k; cin>>k;
		for(int j = 0; j < k; j++){
			int a; cin >> a;
			b[a].push_back(i);
		}
	}
	for(int i = 1; i <= m; i++) cin >> p[i];
	cout << bf() << '\n';
	return 0;
}


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

using ll = long long;

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)

int getsum(int x){
    int ans = 0;
    //cout << x << " ";
    while(x > 0){
        ans += x % 10;
        x /= 10;
    }
    //cout << ans << endl;
    return ans;
}


int main(){
    int n;
    int a,b;
    cin >> n >> a >> b;
    int sum = 0;
    reps(i,1,n+1){
        if(getsum(i) >= a && getsum(i) <= b){
            sum += i;
        }
    }
    cout << sum << endl;

    return 0;
}


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

////Problem A
using namespace std;

#include <stdio.h>

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

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<string> 
#include<vector>
using namespace std;
int k;
string s,t;
vector <string> v;
int main()
{
	cin>>s>>k;
	for(int i=0;i<s.size();i++)
	    for(int j=i;j<i+5;j++)
	    {
	    	if(j>s.size()-1)
	    	    continue;
	    	t=s.substr(i,j-i+1);
	    	v.push_back(t);
		}
	sort(v.begin(),v.end());
	int cnt=0;
	for(int i=0;i<v.size();i++)
	{
		if(i==0||v[i]!=v[i-1])
		    cnt++;
		if(cnt==k)
		{
			cout<<v[i];
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1660
import math
def factorization(N):
  tmp=N
  F=[]
  for i in range(2,int(math.sqrt(N))+1):
    if tmp%i==0:
      F.append(i)
      tmp//=i
    while tmp%i==0:
      tmp//=i
    if i>tmp:
      break
  if tmp!=1:
    F.append(tmp)
  return F

N=int(input())
F=factorization(N)
ans=0
for f in F:
  ff=f
  while N%ff==0:
    ans+=1
    N//=ff
    ff*=f
print(ans)


Measured memory_bytes: 63296
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  map<string, Int> c;
  string s;
  Int n;
  cin>>n;
  for(Int i=0;i<n;i++){
    cin>>s;
    c[s]++;
  }
  Int m;
  cin>>m;
  for(Int i=0;i<m;i++){
    cin>>s;
    c[s]--;
  }
  Int ans=0;
  for(auto p:c) chmax(ans,p.second);
  cout<<ans<<endl;
  return 0;
}


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

from collections import Counter
cnt = Counter(A)

ans = 0
for v in cnt.values():
    ans += v*(v-1)//2
for i in A:
    a = cnt[i]
    dif = a*(a-1)//2 - (a-1)*(a-2)//2
    print(ans-dif)

Measured memory_bytes: 108072
#include <bits/stdc++.h>
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
using namespace std;
typedef long long ll;

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

  ll *hs = new ll[n + 1];
  map<ll, ll> mp;

  FOR(j, 1, n)
  {
    cin >> hs[j];
    mp[j - hs[j]] += 1;
  }

  ll ans = 0;
  FOR(i, 1, n)
  {
    ans += mp[i + hs[i]];
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

#define all(x) (x).begin(), (x).end()

typedef long long ll;

const int N = 300100;

vector<int> prefix_function(string s) {
	int n = s.size();
	vector<int> pi(n);
	for (int i=1; i<n; ++i) {
		int j = pi[i-1];
		while (j > 0 && s[i] != s[j])
			j = pi[j-1];
		if (s[i] == s[j]) ++j;
		pi[i] = j;
	}
	return pi;
}

void solve() {
  string s; cin >> s;
  vector<int> p = prefix_function(s);
  reverse(all(s));
  vector<int> p2 = prefix_function(s);
  int n = s.size(), k = n - p[n - 1];
  //cout << k << endl;
  if (k == 1) {
    cout << n << "\n1\n"; return;
  }
  if (n % k != 0 || k == n) {
    cout << "1\n1\n"; return;
  }
  int ans = 0;
  for (int i = 0; i < n - 1; i++) {
    int len = i + 1, v = len - p[i];
    //cout << i << " " << len << " " << v << endl;
    if (len % v == 0 && len != v) continue;
    int len2 = (n-1)-(i+1)+1, v2 = len2 - p2[n-1-i-1];
    //cout << i << " " << len2 << " " << v2 << endl;
    if (len2 % v2 == 0 && len2 != v2) continue;
    ans++;
  }
  cout << 2 << " " << ans << endl;
}

// CHECK LIMITS (n <= 10^5)
// CHECK CORNER CASES (n == 1)

int main() {
  ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
  cout.setf(ios::fixed), cout.precision(20);
  //cout << 1.0 * clock() / CLOCKS_PER_SEC << endl;
  solve();
}


Measured memory_bytes: 8036
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
long double eps = 1e-9;
long double pi = acos(-1);


int dp[(1<<9)+1][100001];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int n;
    cin>>n;
    int a[n+1],b[n+1];
    for(int i=1;i<=n;i++){
        cin>>a[i]>>b[i];
    }
    int m = 9;
    for(int i=1;i<=(1<<m);i++){
        if(i > n)break;
        int nx = i/2;
        for(int j=0;j<=100000;j++){
            chmax(dp[i][j],dp[nx][j]);
            if(j+b[i] <= 100000)chmax(dp[i][j+b[i]],dp[nx][j]+a[i]);
            if(j)chmax(dp[i][j],dp[i][j-1]);
        }
    }
    int q;
    cin>>q;
    while(q--){
        int v,l;
        cin>>v>>l;
        if(v <= (1<<m)){
            cout << dp[v][l] << "\n";
            continue;
        }
        // v,v/2,...
        int ans = 0;
        queue<array<int,3>> que;
        que.push({v,0,0});
        while(que.size()){
            array<int,3> now = que.front();
            que.pop();
            int w = now[1],val = now[2],p = now[0];
            if(p <= (1<<m)){
                chmax(ans,dp[p][l-w]+val);
            }
            else{
                if(w+b[p] <= l)que.push({p/2,w+b[p],val+a[p]});
                que.push({p/2,w,val});
            }
        }
        cout << ans << "\n";
    }
    
}


Measured memory_bytes: 205240
#include <iostream>

using namespace std;

int main() {
	int a,b;
	char op;
	while( true ) {
		cin >> a >> op >> b;
		if( op == '?' ) { break; }
		int ans;
		switch( op ) {
			case '+': ans = a + b; break;
			case '-': ans = a - b; break;
			case '*': ans = a * b; break;
			case '/': ans = a / b; break;
		}
		cout << ans << endl;
	}
	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, ll> pcl;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), a.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(mp(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define mp make_pair
#define pb push_back
#define INF (1 << 29)
const int mod = 1000000007;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if((a == b && b == c) || (a != b && b != c && c != a)) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }

    return 0;
}

Measured memory_bytes: 256