akhauriyash/Code-Regression huggingface dataset:
x,y=map(int,input().split())

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 
N = 10**6
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


if (-x+2*y)%3!=0:
  ans=0
else:
  a=(-x+2*y)//3
  b=(2*x-y)//3
  ans=cmb(a+b,a,mod)
  
print(ans)

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


namespace AtCoder
{
	class Program
	{
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            long[][] AB = new long[N][];

            for (int i = 0; i < N; i++)
            {
                string[] str = Console.ReadLine().Split(' ');
                AB[i] = new long[2];
                AB[i][0] = long.Parse(str[0]);
                AB[i][1] = long.Parse(str[1]);
            }
            Array.Sort(AB, (a, b) => (int)(a[1] - b[1]));
            long time = 0;
            string ans = "Yes";
            for(int i = 0; i < N; i++)
            {
                time += AB[i][0];
                if(time > AB[i][1])
                {
                    ans = "No";
                    break;
                }
            }

            Console.WriteLine(ans);

            Console.ReadLine();
        }
    }
    
}


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

const int N = 8;

char masu[N][N];

bool check(int x, int y) {
    int m, n;

    for (m = 0; m < N; m++) {
        if (masu[m][y] == 'Q' && m != x) return false;
        if (masu[x][m] == 'Q' && m != y) return false;
    }

    m = x; n = y;
    while (m > 0 && n > 0)
        if (masu[--m][--n] == 'Q') return false;

    m = x; n = y;
    while (m < N-1 && n < N-1)
        if (masu[++m][++n] == 'Q') return false;

    m = x; n = y;
    while (m > 0 && n < N-1)
        if (masu[--m][++n] == 'Q') return false;

    m = x; n = y;
    while (m < N-1 && n > 0)
        if (masu[++m][--n] == 'Q') return false;

    return true;
}

bool dfs(int i) {
    if (i == N) return true;

    for (int j = 0; j < N; j++) {
        if (masu[i][j] == 'Q') {
            if (dfs(i+1)) return true;
        } else {
            if (check(i, j)) {
                masu[i][j] = 'Q';
                if (dfs(i+1)) return true;
                masu[i][j] = '.';
            }
        }
    }

    return false;
}

int main(void) {
    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
            masu[i][j] = '.';

    int k; cin >> k;
    for (int i = 0; i < k; i++) {
        int r, c; cin >> r >> c;
        masu[r][c] = 'Q';
    }

    dfs(0);

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cout << masu[i][j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1156
#include<stdio.h>
int main(){
  int a,b,i,k[4],ans=0,ab;
  scanf("%d %d", &a,&b);
  ab=b-a;
  for(i=0;i<=ab;i++){
    k[0]=a/10000;
    k[1]=(a/1000)%10;
    k[2]=(a/100)%10;
    k[3]=(a/10)%10;
    k[4]=a%10;
    if(k[0]==k[4] && k[1]==k[3])ans++;
    a++;
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define mp make_pair 
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = n - 1; i>= 0; i--)
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define sq(a) (a)*(a)
#define nl "\n"
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,
//tree_order_statistics_node_update> indexed_set;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<ll> vll;
vector<vi> adj;

const double pi = 3.14159265359;
const int MAXN = 100005;
ll mod=1000000007;
vi id;
vector<bool> vis;
void bfs(int parent){
	queue<int> q;
	vis[parent] = true;
	q.push(parent);
	while(!q.empty()){
		int x = q.front();
		q.pop();
		for(auto y : adj[x]){
			if(!vis[y]){
				q.push(y);
				vis[y] = true;
				id[y] = x;
			}
		}
	}
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,m;
	cin>>n>>m;
	adj.resize(n+1);
	vis.resize(n+1,false);
	id.resize(n+1,-1);	
	id[1] = 0;
	rep(i,m){
		int a,b;
		cin>>a>>b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	bfs(1);
	for(int i = 2; i < n; i++){
		if(id[i]==-1){
			cout<<"No"<<nl;
			return 0;
		}
	}
	cout<<"Yes"<<nl;
	for(int i = 2; i <= n; i++){
		cout<<id[i]<<nl;
	}
	return 0;
}



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

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

int main() {
  int s, k, cnt = 0;
  cin >> k >> s;

  for (int i = 0; i <= k; ++i) {
    for (int j = 0; j <= k; ++j) {
      if (s - i - j <= k && s - i - j >= 0) cnt++;
    }
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    int N;cin>>N;
    set<int> s;
    rep(i,N){
        int p;cin>>p;
        s.insert(p);
    }
    if(N==s.size())cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

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

#define ms(s, n) memset(s, n, sizeof(s))
#define f(i, a, b) for (int i = (a); i <=(b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<ll> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int MOD2 = MOD + 2; //1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) - 1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
int modulo(int a, int b) { return (a % b + b) % b; }
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";

int main()
{
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll x, n;
	cin >> x >> n;
	vi a(n);
	unordered_set<ll>vis;
	f(i, 0, n - 1) {
		cin >> a[i];
		vis.insert(a[i]);
	}
	ll dif = INT_MAX, ans = INT_MAX;
	f(i, -200, 200) {
		if (vis.find(i) == vis.end()) {
			ll curdif = abs(i - x);
			if (dif > curdif) {
				dif = curdif;
				ans = i;
			}
		}
	}
	cout << ans << endl;
	return 0;
}































Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int n,a[200010],cnt,ans[200010];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=n;i>=1;i--){
		cnt=0;
		for(int j=1;j<=n/i;j++) cnt+=ans[j*i];
		if(cnt%2!=a[i]) ans[i]=1;
	}
	cnt=0;
	for(int i=1;i<=n;i++) cnt+=ans[i];
	printf("%d\n",cnt);
	for(int i=1;i<=n;i++) if(ans[i]) printf("%d ",i);
	return 0;
}

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

using namespace std;
typedef long long ll;

int main(){
  int N; ll x;   cin >> N >> x;
  vector<ll> a(N); 
 for(int i = 0; i < N; i++){ cin >> a[i];}
   ll sum = 0;
  for(int i = 0; i < N - 1; i++){
    // reserch on a[i] and a[i+1]
    ll res = a[i] + a[i+1];
    
    if( res <= x){ continue;}
    else{
      res = res - x;
      
      if( a[i+1] >= res){ a[i+1] -= res; sum += res;   }
     
      else{
        sum += a[i+1];
        res -= a[i+1]; a[i+1] = 0;
     
        a[i] -= res; sum += res;}
      
    }
  }
  
  cout <<sum << endl; return 0;}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {
	//------------入力------------
	int A = 0, B = 0, C = 0;
	cin >> A >> B >> C;
	//------------出力------------
	int j = 0;
	for (int i = 1; i <= B; ++i) {
		if (i*A % B == C) {
			cout << "YES" << endl;
			j = 1;
			break;
		}
	}
	if (j == 0) cout << "NO" << endl;

	return 0;
}

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

int main(){
	int n; cin >> n;
	vector<int> v;
	for(int i = 0; i < 2 * n; ++i){
		int a; cin >> a;
		v.push_back(a);
	}
	sort(v.begin(), v.end());
	int ans = 0;
	for(int i = 0; i < n; ++i){
		ans += v[2 * i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import collections
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N = int(input())
s = [input() for _ in range(N)]
split_s = [''.join(sorted([j for j in i])) for i in s]

c = collections.Counter(split_s)
ans = 0
for i in c.values():
    if i > 1:
        ans += cmb(i,2)

print(ans)


Measured memory_bytes: 27148
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n, k;
  cin >> n >> k;
  ll ans = 0;
  vector<int> v(n);
  for(auto &e : v) cin >> e;
  
  for(int i = 0; i <= n; i++) for(int j = 0; j <= n; j++) {
    if(i + j > n) continue;
    if(i + j > k) continue;
    int rest = k - i - j;
    vector<int> neg;
    ll res = 0;
    for(int l = 0; l < i; l++) {
      res += v[l];
      if(v[l] < 0) neg.push_back(v[l]);
    }
    for(int l = 0; l < j; l++) {
      res += v[n - 1 - l];
      if(v[n-1-l] < 0) neg.push_back(v[n-1-l]);
    }
    sort(begin(neg), end(neg));
    for(int i = 0; i < min<int>(rest, neg.size()); i++) {
      res += -neg[i];
    }
    ans = max(res, ans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iomanip>
#include<queue>

using namespace std;

#define N 100010
int a[N],b[N];
int ans,n; 

int main(){
	int i,j,k;
	int x=0,y=0,z=0;
	ans = 0;
	cin>>n;
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(a[i]<0)x++;
		if(a[i]==0)y++;
		if(a[i]>0)z++;
	}
	sort(a+1,a+1+n);
	if(z==0){
		ans = a[n];
		for(i=n-1;i>=1;i--){
			ans -= a[i];
		}
		cout<<ans<<endl;
		for(i=n-1;i>=1;i--){
			printf("%d %d\n",a[n],a[i]);
			a[n]-=a[i];
		}
		return 0;
	}
	if(x==0){
		ans = a[1];
		for(i=2;i<n;i++){
			ans-=a[i];
		}
		ans = a[n] - ans;
		printf("%d\n",ans);
		for(i=2;i<n;i++){
			printf("%d %d\n",a[1],a[i]);
			a[1]-=a[i];
		}
		printf("%d %d\n", a[n], a[1]);
		return 0;
	}
	for(i=1;i<=n;i++){
		ans+=abs(a[i]);
	}

	printf("%d\n",ans);
	for(i=1;i<z;i++){
		printf("%d %d\n",a[1], a[n-i+1]);
		a[1]-=a[n-i+1];
	}
	j=1;
	for(i=z;i<n;i++){
		printf("%d %d\n",a[n-z+1],a[j]);
		a[n-z+1]-=a[j];
		j++;
	}

	

	return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using tii = tuple<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define INF 1E9
#define LINF 1E18*5
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template<class S, class T>ostream& operator<<(ostream&os, pair<S, T>p) { os << "[" << p.first << ", " << p.second << "]"; return os; };
template<class S>auto&operator<<(ostream&os, vector<S>t) { bool a = 1; for (auto s : t) { os << (a ? "" : " ") << s; a = 0; } return os; }

//int dx[]={1,1,1,0,-1,-1,-1,0},dy[8]={1,0,-1,-1,-1,0,1,1,1};
//
constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

class compare {
public:
	bool operator()(tuple<int, int> a, tuple<int, int> b) {
		return (get<1>(a) < get<1>(b));
	}
};

class pcompare {
public:
	bool operator()(tuple<int, int> a, tuple<int, int> b) {
		return !(get<1>(a) < get<1>(b));
	}
};

int main() {
	int n, in1, in2;
	cin >> n;
	vvi vv(n);
	rep(i, n - 1) {
		cin >> in1 >> in2;
		in1--; in2--;
		vv[in1].push_back(in2);
		vv[in2].push_back(in1);
	}
	queue<pii> f, s;
	vi c(n, 0);
	c[0] = 1; c[n - 1] = -1;
	//rep(i, vv[0].size())f.push(pii(vv[0][i],0));
	//rep(i, vv[n-1].size())s.push(pii(vv[n-1][i],0));
	f.push(pii(0, 0));
	s.push(pii(n - 1, 0));
	rep(i, n-1) {
		bool sw = false;
		while (!f.empty()&&f.front().sc == i) {
			rep(j, vv[f.front().fs].size()) {
				if (c[vv[f.front().fs][j]] == 0) {
					f.push(pii(vv[f.front().fs][j], i + 1));
					sw = true;
					c[vv[f.front().fs][j]] = 1;
				}
			}
			f.pop();
		}
		while (!s.empty()&&s.front().sc == i) {
			rep(j, vv[s.front().fs].size()) {
				if (c[vv[s.front().fs][j]] == 0){
					s.push(pii(vv[s.front().fs][j], i + 1));
					sw = true;
					c[vv[s.front().fs][j]] = -1;
				}
			}
			s.pop();
		}
		if (!sw)break;
	}
	queue<int> fe, su;
	fe.push(0);	su.push(0);
	ll cnt = 1;
	while (!fe.empty()) {
		c[fe.front()] = 2;
		rep(i, vv[fe.front()].size()) {
			if (c[vv[fe.front()][i]] ==0 || c[vv[fe.front()][i]] ==1) {
				fe.push(vv[fe.front()][i]);
				cnt++;
			}
		}
		fe.pop();
		//cnt++;
	}
	cout << (cnt * 2 > n ? "Fennec" : "Snuke") << endl;
	

}

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

public class Main{
    final static String alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toLowerCase();//.toCharArray();
    static class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){br = new BufferedReader(new InputStreamReader(System.in));}
        String next(){while (st == null || !st.hasMoreElements()){try{st = new StringTokenizer(br.readLine());}catch (IOException  e){e.printStackTrace();}}return st.nextToken();}
        int nextInt(){return Integer.parseInt(next());}
        long nextLong(){return Long.parseLong(next());}
        double nextDouble(){return Double.parseDouble(next());}
        int[] readArray(int n){int[] a=new int[n];for (int i=0; i<n; i++) a[i]=nextInt();return a;}
        long[] readLongArray(int n){long[] a=new long[n];for (int i=0; i<n; i++) a[i]=nextLong();return a;}
        String nextLine(){String str = "";try{str = br.readLine();}catch (IOException e){e.printStackTrace();}return str;}
    }
    static int getGcd(int n1,int n2){
        while(n1 != n2){
            if(n1 > n2) n1 -= n2;
            else n2 -= n1;
        }
        return n1;
    }
    static boolean isSorted(int[] arr, int n){
        for(int i=1;i<n;i++){
            if(arr[i]<arr[i-1]) return false;
        }
        return true;
    }
    static boolean isPrime(long n){
        if(n==2) return true;
        else if(n%2==0) return false;
        for(int i=3;i<=n/2;i+=2){
            if(n%i==0) return false;
        }
        return true;
    }
    static boolean isPrime(int n){
        if(n==2) return true;
        else if(n%2==0) return false;
        for(int i=3;i<=n/2;i+=2){
            if(n%i==0) return false;
        }
        return true;
    }
    static void printArray(int[] arr){
        for(int x:arr){
            System.out.print(x+" ");
        }
        System.out.println();
    }
    static long Fact(int n){
        //int p=1000000007;
        long result = 1;
        for (int i = 1; i <= n; i++) result = (result*i);
        //for (int i = 1; i <= n; i++) result = (result*i)%p;
        return result;
    }
    static int findLargestDiv(int n){
        if(n%2==0) return n/2;
        else{
            for(int i=3;i<=n/2;i+=2){
                if(n%i==0) return n/i;
            }
        }
        return 1;
    }
    public static void main(String[] args) throws NumberFormatException, IOException {
        FastReader s = new FastReader();
        String str = s.nextLine();
        int count=0,ans=0;
        for(int i=0;i<str.length();i++){
            if(str.charAt(i)=='R'){
                count++;
                if(i==(2)) ans=Math.max(ans,count);
            }
            else{
                ans=Math.max(ans,count);
                count=0;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 25332
n, k = map(int, input().split())
s = list(input())
if s[k - 1] == 'A':
    s[k - 1] = 'a'
elif s[k - 1] == 'B':
    s[k - 1] = 'b'
elif s[k - 1] == 'C':
    s[k - 1] = 'c'
print("".join(s))

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

#define int long long
typedef long long ll;
typedef long long ll; 
typedef vector<ll> vi; 
typedef pair<int, int> ii; 
typedef vector<ii> vii; 
typedef vector<vi> vvi;
#define sz(a) int((a).size())
#define F first
#define S second
#define pb emplace_back
#define M 1000000007
#define watch(x) cout << (#x) << " is " << (x) << endl
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr(i,a,b) for(int i = a; i<= b; i++)
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())

main() {
    IOS;
  
    int n, W;
    cin >> n >> W;

    int ar[n+1], val[n+1];

    fr (i,1,n) 
        cin >> ar[i] >> val[i];

    int dp[n+1][W+1] = {0};

    for (int i = 0; i <= n; i++) {
        for (int w = 0; w <= W; w++) {
            if (i == 0 or w == 0) {
                dp[i][w] = 0;
                continue;
            }
            if (ar[i] > w) 
                dp[i][w] = dp[i-1][w];
            else 
                dp[i][w] = max(dp[i-1][w], val[i] + dp[i-1][w-ar[i]]);
        }
    }

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

/*  Check for base cases such as n == 1
    and cases like it where code can fail */

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

using namespace std;

typedef long long ll;

const int maxn = 2e5 + 50;

ll x[maxn], y[maxn];
int w[maxn];

int main(){
	ios_base::sync_with_stdio(false);
	ll n, L, T;
	cin >> n >> L >> T;
	for (int i = 0; i < n; i++)
		cin >> x[i] >> w[i];
	for (int i = 0; i < n; i++){
		if (w[i] == 1)
			y[i] = (x[i] + T) % L;
		else
			y[i] = ((x[i] - T) % L + L) % L;
	}
	int p1 = y[0], pos;
	T = T + T;
	sort(y, y + n);
	for (int i = 0; i < n; i++){
		if (y[i] == p1){
			if (i == n - 1 or y[i + 1] != p1){
				pos = i;
				break;
			}
			if (w[0] == 1)
				pos = i + 1;
			else
				pos = i;
			break;
		}
	}
	ll now = 0;
	for (int i = 1; i < n; i++){
		if (w[i] == w[0])
			continue;
		ll t, dis;
		if (w[0] == 1){
			dis = x[i] - x[0];
			if (T < dis)
				continue;
			t = T - dis;
			now = (now + 1) % n;
			t /= L;
			now = (now + t) % n;
		}
		else{
			dis = L - (x[i] - x[0]);
			if (T < dis)
				continue;
			t = T - dis;
			now = (now - 1 + n) % n;
			t /= L;
			t %= n;
			now = (now - t + n) % n;
		}
	}
	for (int i = (pos - now + n) % n, cnt = 0; cnt < n; i = (i + 1) % n, cnt++)
		cout << y[i] << " ";
	cout << endl;

}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int>b(N);
  int count = 1;
  for(int i=0; i<N; i++){
    cin >> b.at(i);
  }
  for(int i=0; i<N; i++){
    if (b.at(0) == 2){
      cout << count << endl;
      break;
    }
    else{
      b.at(0) = b.at(b.at(0)-1);
      count++;
      continue;
    }
  }
  if (count >= N) 
    cout << -1 << endl;
}

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

typedef long long ll;

ll N;
ll T, X, Y;

int main() {
  cin >> N;
  for (ll i = 0; i < N; ++i) {
    ll t, x, y;
    cin >> t >> x >> y;
    ll dxy = abs(x - X) + abs(y - Y), dt = t - T;
    if (!(dxy <= dt && (dt - dxy) % 2 == 0)) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

using namespace std;
int main() {
	int n, m,l, A[1010101];
	string S;
	cin >> n >> m >> l;
	if (l>=n && n+m>l)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;

inline int read()
{
	int X=0; bool flag=1; char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
	while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
	if(flag) return X;
	return ~(X-1);
}

ll fpow(ll a,ll k,int p){
	ll res=1;
	while(k){
		if(k&1) res=(ll)res*a%p;
		k>>=1;
		a=(ll)a*a%p;
	}
	return res;
}

ll n;

int main() {
    //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	n=read();
	ll res=fpow(10,n,mod)-2*fpow(9,n,mod)+fpow(8,n,mod);
	res%=mod;
	res=(res+mod)%mod;
	printf("%lld\n",res);
	
    return 0;
}

Measured memory_bytes: 3760
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<utility>

using namespace std;
typedef pair<int, int> P;
const int INF = (1 << 30);
int V, E, r;
int dp[100000];
struct edge{
	int to, cost;
	edge(int to,int cost=1):to(to),cost(cost){}
};
vector<edge> G[100000];



int main()
{
	cin.tie(0);
	ios::ios_base::sync_with_stdio(false);
	 cin >> V >> E >> r;
	for (int i = 0; i < E; ++i) {
		int s, t, d;
		cin >> s >> t >> d;
		edge e(t,d);
		G[s].push_back(e);
	}
	fill(dp, dp + V, INF);
	dp[r] = 0;
	priority_queue<P, vector<P>, greater<P>> que;
	P start(0, r);
	que.push(start);
	while (!que.empty()) {
		P p = que.top(); que.pop();
		if (dp[p.second] < p.first)continue;

		int v = p.second;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (dp[e.to]>dp[v] + e.cost) {
				dp[e.to] = dp[v] + e.cost;
				que.push(P(dp[e.to], e.to));
			}
		}
	}
	for (int i = 0; i < V; i++) {
		if (dp[i] == INF)cout << "INF\n";
		else cout << dp[i] << "\n";
	}
	cout << flush;
	return 0;
}

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

typedef long long ll;

bool table[20000000];

int num(char c){
    if(c=='A')return 1;
    if(c=='C')return 2;
    if(c=='G')return 3;
    if(c=='T')return 4;
}


ll hs(string str){
    ll n=0;
    for(int i=0;i<str.size();i++){
        if(i)n*=5;
        n+=num(str[i]);
    }
//    cout << str << " : " << n << endl;
    return n;
}

void inpt(ll key){
    table[key] = true;
}

bool find(ll key){
    return table[key];

}

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

    int n;
    cin >> n;
    string str,in;
    for(int i=0;i<n;i++){
        cin >> str >> in;
        if(str=="insert"){
            inpt(hs(in));
        }else{
            if(find(hs(in))) cout << "yes\n";
            else cout << "no\n";
        }
    }

}



Measured memory_bytes: 8456
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;

int main(int argc, const char * argv[]) {
  int n;
  cin >> n;
  cout << (n+1)/2 << endl;
  return 0;
}

Measured memory_bytes: 888
// https://atcoder.jp/contests/arc068/tasks/arc068_b

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N;
  cin >> N;

  map<ll, ll> cts;

  rep(i, N) {
    ll a;
    cin >> a;
    cts[a]++;
  }

  ll res;

  if (cts.size() % 2 == 1) {
    res = cts.size();
  } else {
    res = cts.size() - 1;
  }

  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


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

int main(){
    int N;
    cin >> N;
    
    int d[100005];
    for(int i = 0;i < N;i++){
        cin >> d[i];
    }
    
    sort(d,d + N);
    
    int center = N/2;
    
    cout << d[center] - d[center - 1] << endl;
 
}


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

string s;

int main() {
	cin >> s;
	
	int i, cnt = 0;
	for (i = 0; i < s.length(); i++) {
		if (s[i] == '2') cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;

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

		String input = br.readLine();
		double r = Double.parseDouble(input);

		double s = r * r * Math.PI;
		double l = r * 2 * Math.PI;

//		System.out.printf("%.6f", "%.6f", s, l);

		String ansS = String.format("%.6f", s);
		String ansL = String.format("%.6f", l);

		System.out.println(ansS + " " + ansL);
	}
}

Measured memory_bytes: 24684
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int H = cin.nextint;
        int W = cin.nextint;
        var C = new List<List<char>>();
        for (int i = 0; i < H; i++)
        {
            C.Add(ReadLine().ToList());
            if (!C.Last().Contains('#'))
            {
                C.RemoveAt(C.Count - 1);
            }
        }
        for (int j = W - 1; j >= 0; j--)
        {
            bool flag = true;
            for (int i = 0; i < C.Count; i++)
            {
                if (C[i][j] == '#')
                {
                    flag = false;
                    break;
                }
            }
            if (flag)
            {
                for (int i = 0; i < C.Count; i++)
                {
                    C[i].RemoveAt(j);
                }
            }
        }

        foreach (var item in C)
        {
            WriteLine(string.Join("", item));
        }
    }
}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, m, k;
	cin >> n >> m >> k;
	int cnt = 0;
	vector<vector<int> > a(n, vector<int>(m, 0));
	for(int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		for(int j = 0; j < m; ++j) {
			if(s[j] == '#') {
				a[i][j] = ++cnt;
				for(int k = j - 1; ~k; --k) {
					if(a[i][k] || s[k] == '#') {
						break;
					}
					a[i][k] = cnt;
				}
				for(int k = j + 1; k < m; ++k) {
					if(a[i][k] || s[k] == '#') {
						break;
					}
					a[i][k] = cnt;
				}
			}
		}
	}
	cout << '\n';
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j) {
			if(!a[i][j]) {
				continue;
			}
			for(int k = i - 1; ~k; --k) {
				if(a[k][j]) {
					break;
				}
				a[k][j] = a[i][j];
			}
			for(int k = i + 1; k < n; ++k) {
				if(a[k][j]) {
					break;
				}
				a[k][j] = a[i][j];
			}
		}
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < m; ++j) {
			cout << a[i][j] << ' ';
		}
		cout << '\n';
	}
	return 0;
}

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

ll l,r;

int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  cin >> l >> r;

  if (r - l > 5000) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = 5000;
  for (ll i = l; i < r; i++)
    for (ll j = i+1; j <= r; j++) {
      chmin(ans,i*j%2019);
    }

  cout << ans << endl;

  return 0;
}


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

int main(){
  int n,k,count=1;
  cin >> n >> k;
  r(i,n){
    if(count>=k)count+=k;
    else count*=2;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
using namespace std;
const int MAX = 1e5 + 10;
const ll MOD = 1e9 + 7;
int N, M, K, Q;
int arr[60];
ll dp[3000][60];

int main()
{
	int i, j, k;
	ll A;
	scanf("%d%d", &N, &A);
	for (i = 1; i <= N; ++i) scanf("%d", arr + i);
	
	for (i = 1; i <= N; ++i) {
		for (j = A * N; j > 0; --j) {
			for (k = 2; k <= i; ++k) {
				if (j - arr[i] > 0) dp[j][k] += dp[j - arr[i]][k - 1];
			}
		}
		dp[arr[i]][1]++;
	}
	ll sum = 0;
	for (i = 1; i <= N; ++i) {
		sum += dp[A*i][i];
	}
	printf("%lld", sum);
}

Measured memory_bytes: 1408
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    N,K = map(int,input().split())
    p = list(map(int,input().split()))

    p = sorted(p)
    p = p[:K]

    res = sum(p)

    print(res)



main()


Measured memory_bytes: 9108
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }

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

  ll n, a;
  cin >> n >> a;
  if(n - (n/500)*500 > a) cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#define mm(a,x) memset(a,x,sizeof(a))
#define sync std::ios::sync_with_stdio(false);std::cin.tie(0)
#define ll long long
using namespace std;
const int MAXN=40100;
vector<int>rp,gp,bp;
int vis1[MAXN],vis2[MAXN],vis3[MAXN];
int main(void)
{
    sync;
    int n;
    string s;
    cin>>n>>s;
    for(int i=0;i<n;++i)
        if(s[i]=='R')
        {
            rp.push_back(i);
            vis1[i]=1;
        }
        else if(s[i]=='G')
        {
            gp.push_back(i);
            vis2[i]=1;
        }
        else
        {
            bp.push_back(i);
            vis3[i]=1;
        }
    ll res=rp.size()*gp.size()*bp.size();
    for(auto i:rp)
        for(auto j:gp)
            if(2*j-i>=0&&vis3[2*j-i])
                --res;
    for(auto i:gp)
        for(auto j:rp)
            if(2*j-i>=0&&vis3[2*j-i])
                --res;
    for(auto i:rp)
        for(auto j:bp)
            if(2*j-i>=0&&vis2[2*j-i])
                --res;
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 3264
#include <stdio.h>

int main(int argc, char *argv[])
{
    char line[256];
    int a, b;

    if (!fgets(line, sizeof(line), stdin)) {
        fprintf(stderr, "error input val\n");
        return -1;
    }

    if (sscanf(line, "%d %d", &a, &b) != 2) {
        fprintf(stderr, "error input format\n");
        return -1;
    }

    printf("%d %d %f", a/b, a%b, (double)a/(double)b);

    return 0;
}

Measured memory_bytes: 644
#include<bits/stdc++.h>
using namespace std;
#define MAX_V 1000
int V;
vector<int> G[MAX_V];
vector<int> rG[MAX_V];
vector<int> vs;
bool used[MAX_V];
int cmp[MAX_V];

void init(){
	for(int i=0;i<MAX_V;i++)G[i].clear();
	for(int i=0;i<MAX_V;i++)rG[i].clear();
	for(int i=0;i<MAX_V;i++){
		cmp[i]=0;
		used[i]=0;
	}
}

void add_edge(int from,int to){
	G[from].push_back(to);
	rG[to].push_back(from);
}

void dfs(int v){
	used[v]=true;
	for(int i=0;i<G[v].size();i++)
		if(!used[G[v][i]])dfs(G[v][i]);
	vs.push_back(v);
}

void rdfs(int v,int k){
	used[v]=true;
	cmp[v]=k;
	for(int i=0;i<rG[v].size();i++)
		if(!used[rG[v][i]])rdfs(rG[v][i],k);
}

int scc(){
	memset(used,0,sizeof(used));
	vs.clear();
	for(int v=0;v<V;v++)
		if(!used[v])dfs(v);

	memset(used,0,sizeof(used));
	int k=0;
	for(int i=vs.size()-1;i>=0;i--)
		if(!used[vs[i]])rdfs(vs[i],k++);

	return k;
}

int main(){
	while(cin>>V,V){
		init();
		double p[101];
		for(int i=0;i<V;i++){
			int a;
			cin>>p[i]>>a;
			for(int j=0;j<a;j++){
				int k;
				cin>>k;
				k--;
				add_edge(i,k);
			}
		}
		int use[101]={};
		int k=scc();
		//cout<<k<<endl;
		vector<int> P[101];
	
		for(int i=0;i<V;i++){
			//cout<<cmp[i]<<endl;
			P[cmp[i]].push_back(i);
			for(int j=0;j<G[i].size();j++){
				if(cmp[G[i][j]]!=cmp[i])use[cmp[G[i][j]]]=1;
			}
		}
	
		vector<double> ans;
		for(int i=0;i<k;i++){
			if(use[i])continue;
			double tt;
			for(int j=0;j<P[i].size();j++){
				if(j==0)tt=p[P[i][j]];
				else{
					tt*=p[P[i][j]];
				}
			}
			ans.push_back(1-tt);
		}
	
		double sum;
		for(int i=0;i<ans.size();i++){
			if(i==0)sum=ans[i];
			else{
				sum*=ans[i];
			}
		}
		printf("%lf\n",sum);
	}
	return 0;
}



Measured memory_bytes: 3348
s = list(input())

f = False

for i in range(len(s)):
    if i%2==0:
        if s[i]!='R' and s[i]!='U' and s[i]!='D':
            f = True
    else:
        if s[i]!='L' and s[i]!='U' and s[i]!='D':
            f = True
if f:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3060
#include <stdio.h>

int parent(int);
int left(int);
int right(int);

int data[250];
int main(){
  int H;
  int i;
  scanf("%d",&H);
  for(i=1;i<=H;i++)
    scanf("%d",&data[i]);
  for(i=1;i<=H;i++){
    printf("node %d: key = %d, ",i,data[i]);
    if(i/2!=0) printf("parent key = %d, ",parent(i));
    if(i*2<=H) printf("left key = %d, ",left(i));
    if(i*2+1<=H) printf("right key = %d, ",right(i));

    printf("\n");
    }
  return 0;
}

int parent(int i){
  return data[i/2];
}

int left(int i){
  return data[2*i];
}

int right(int i){
  return data[2*i+1];
}



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

void solve(std::string S, std::string T)
{
    cout << T << S << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}


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

#define Online 1
// #define multitest 1
#define Debug 1
typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;
void ControlIO();
void TimerStart();
void TimerStop();
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#endif

void solve()
{
	int a,p;
	cin >> a >> p;
	p += a*3;
	cout << p/2;
}

int main()
{
	ControlIO();
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	TimerStart();
	while (t--)
		solve();
	TimerStop();
	return 0;
}

void ControlIO()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifndef Online
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();

void TimerStart()
{
#ifndef Online
	TimeStart = chrono::steady_clock::now();
#endif
}

void TimerStop()
{
#ifndef Online
	TimeEnd = chrono::steady_clock::now();
	auto ElapsedTime = TimeEnd - TimeStart;
	cout << "\n\nTime elapsed: " << chrono::duration<double>(ElapsedTime).count() << " seconds.\n";
#endif
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

void primeFactor(int n, unordered_map<int, int> &ans)
{
  for (int i = 2; i*i <= n; ++i) {
    while(n % i == 0) {
      ans[i] += 1;
      n /= i;
    }
  }
  if (n > 1) ans[n] += 1;

  return;
}

signed main()
{
  int N; cin >> N;

  unordered_map<int, int> pf;

  for (int i = 2; i <= N; ++i) {
    primeFactor(i, pf);
  }

  i64 ans = 1;

  for (const auto e : pf) {
    ans = (ans * (e.second + 1)) % 1'000'000'007;
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
n, m = list(map(int, input().split()))
Students = [tuple(map(int, input().split())) for i in range(n)]
CheckPoints = [tuple([i] + list(map(int, input().split()))) for i in range(m)]

for student in Students:
    ManhattanDistanceList = []
    for point in CheckPoints:
        sx, sy = student
        px, py = point[1], point[2]
        ManhattanDistanceList.append(
            tuple([point[0], abs(sx - px) + abs(sy - py)]))
    ManhattanDistanceList.sort(key=lambda x: x[1])
    print(ManhattanDistanceList[0][0]+1)


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


typedef long double ld;
typedef long long ll;

using namespace std;

#define INF (1LL << 61)
#define MAXN (1 << 17)

ll a[MAXN];
ll n, m;
ll ss[MAXN];

ll count(ll pos, ll val) {
	if (pos >= n) {
		return 0;
	}
	if (a[pos] < val) {
		return 0;
	}
	if (a[n - 1] >= val) {
		return n - pos;
	}
	ll lleft = pos;
	ll rright = n - 1;
	while (rright - lleft > 1) {
		ll mm = (lleft + rright) / 2;
		if (a[mm] >= val) {
			lleft = mm;
		} else {
			rright = mm;
		}
	}
	return rright - pos;
}

bool check(ll minval) {
	ll ret = 0;
	for (int i = 0; i < n; i++) {
		ret += count(0, minval - a[i]);
	}
	return (ret >= m);
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	reverse(a, a + n);
	ll l = 0, r = INF;
	while (r - l > 1) {
		ll med = (r + l) / 2;
		if (check(med)) {
			l = med;
		} else {
			r = med;
		}
	}
	//cerr << l << endl;
	ll minval = l;
	ll ret = 0;
	ll leftover = m;
	ss[0] = 0;
	for (int i = 1; i <= n; i++) {
		ss[i] = ss[i - 1] + a[i - 1];
	}
	for (int i = 0; i < n; i++) {
		ll cur = count(0, minval + 1 - a[i]);
		ret += a[i] * cur;
		ret += ss[cur];
		leftover -= cur;
	}
	ret += leftover * minval;
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 5188
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

int main()
{
  i64 n, q;
  cin >> n >> q;
  vector<i64> edge[n];
  for (i64 i = 0; i < n - 1; i++)
  {
    i64 a, b;
    cin >> a >> b;
    a--;
    b--;
    edge[a].push_back(b);
  }
  vector<i64> ans(n);
  for (i64 i = 0; i < q; i++)
  {
    i64 p, x;
    cin >> p >> x;
    p--;
    ans[p] += x;
  }
  vector<bool> tmp(n);
  queue<i64> que;
  que.push(0);
  tmp[0] = true;
  while (que.size())
  {
    i64 p = que.front();
    que.pop();
    for (i64 i : edge[p])
      if (!tmp[i])
      {
        ans[i] += ans[p];
        que.push(i);
      }
  }
  for (i64 i = 0; i < n; i++)
    cout << ans[i] << (i + 1 == n ? "\n" : " ");
  return 0;
}


Measured memory_bytes: 14976