akhauriyash/Code-Regression huggingface dataset:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

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

        if x == y:
            return

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

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

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

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    n = int(input())
    al = list(map(int, input().split()))
    q = int(input())
    cnt_dic = {}
    ans = 0
    for a in al:
        cnt_dic.setdefault(a,0)
        cnt_dic[a] += 1
        ans += a

    bcl = []
    for _ in range(q):
        b, c = map(int, input().split())
        bcl.append((b,c))


    for bc in bcl:
        b,c = bc
        if b not in cnt_dic:
            print(ans)
            continue
        ans += cnt_dic[b]*(c-b)
        cnt_dic.setdefault(c,0)
        cnt_dic[c] += cnt_dic[b]
        cnt_dic[b] = 0
        print(ans)




if __name__ == "__main__":
    main()

Measured memory_bytes: 92256
#include <iostream>
#include <vector>
#include <map>
using namespace std;
typedef long long LL;
int main(int argc, char* argv[])
{
	int X,Y,Z,K;
	cin>>X>>Y>>Z>>K;
	vector<LL> A(X);
	vector<LL> B(Y);
	vector<LL> C(Z);
	int i,j,k;
	for (i=0;i<X;i++){
		cin>>A[i];
	}
	for (i=0;i<Y;i++){
		cin>>B[i];
	}
	for (i=0;i<Z;i++){
		cin>>C[i];
	}
	multimap<LL,int> myMap;
	multimap<LL,int>::iterator mit;
	bool bFull=false;
	for (i=0;i<X;i++){
		for (j=0;j<Y;j++){
			for (k=0;k<Z;k++){
				LL xyz=A[i]+B[j]+C[k];
				if (!bFull){
					if (myMap.size()==K){
						bFull=true;
					}
				}
				if (!bFull){
					myMap.insert(multimap<LL,int>::value_type(xyz,0));
				}else{
					mit=myMap.begin();
					if (xyz>(*mit).first){
						myMap.erase(myMap.begin());
						myMap.insert(multimap<LL,int>::value_type(xyz,0));
					}
				}
			}
		}
	}
	
	vector<LL> R;
	for (mit=myMap.begin();mit!=myMap.end();mit++){
		R.push_back((*mit).first);
	}
	for (i=R.size()-1;i>=0;i--){
		cout<<R[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;

using namespace std;

int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);
    vector<long> v(n), c(n);
    long i;
    for(i=0; i<n; i++) {
        scanf("%ld", &v[i]);
    }
    for(i=0; i<n; i++) {
        scanf("%ld", &c[i]);
        v[i]-=c[i];
    }
    sort(v.rbegin(), v.rend());

    ll sum=0;
    for(i=0; i<n; i++) {
        if(v[i]>0) sum+= v[i];
    }
    printf("%lld\n", sum);



    return 0;
}


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	long long n,k;
	cin>>n>>k;
	long long ans=0;
	if(k==0){
		cout<<n*n;
		return 0;
	}
	for(int i=k+1;i<=n;i++){
		long long t=n/i;
		ans+=(i-k)*t;
		ans+=max(0LL,n-t*i-k+1);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    static Scanner scan=new Scanner(System.in);
    public static void main(String args[]){
        int n;
        Integer a[][]=new Integer[2][200];

        n=scan.nextInt();
        for(int i=0;i<2;i++){
            for(int j=0;j<n;j++){
                a[i][j]=scan.nextInt();
            }
        }
        int dp[][]=new int[3][200];
        dp[0][0]=a[0][0];
        for(int i=1;i<n;i++){
            dp[0][i]=dp[0][i-1]+a[0][i];
        }
        dp[1][0]=dp[0][0]+a[1][0];
        
        for(int i=1;i<2;i++){
            for(int j=1;j<n;j++){
                if(dp[i-1][j]>dp[i][j-1]){
                    dp[i][j]=dp[i-1][j]+a[i][j];
                }else{
                    dp[i][j]=dp[i][j-1]+a[i][j];
                }
            }
        }
        System.out.println(dp[1][n-1]);

    }
}

Measured memory_bytes: 21716
#include<stdio.h>
#include<stdlib.h>
void selectionSort(int *A,int N);
int main(){
  int *A,i,N;
  scanf("%d\n",&N);
  A=(int *)malloc(N*sizeof(int));
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  selectionSort(A,N);
  return 0;
}
void selectionSort(int *A,int N){
  int i,j,v,k,minj,count=0;
  for(i=0;i<=N-1;i++){
    minj=i;
    for(j=i;j<=N-1;j++){
      if(A[j]<A[minj]){
	minj=j;
      }
    }
    v=A[i];
    A[i]=A[minj];
    A[minj]=v;
    if(A[minj]!=A[i])count++;
  }
  for(i=0;i<N-1;i++){
    printf("%d",A[i]);
    printf(" ");
  }
  printf("%d\n",A[N-1]);
  printf("%d\n",count);
}



Measured memory_bytes: 2072
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb1(x) cout<<#x<<" :: "<<x<<"\n";
#define deb2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define deb3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define lli long long int
#define pii pair<lli,lli>
#define f first
#define sE second
lli n,x,y,t,mod=1e9+7,ans=0;
int main() { 
    fast
    cin>>n;
    vector<lli>a(n+1),b(n+1),c(n+1);
    lli dp[n+1][3];
    for(int i=1;i<=n;i++)
        cin>>a[i]>>b[i]>>c[i];
    dp[1][0]=a[1];
    dp[1][1]=b[1];
    dp[1][2]=c[1];
    for(int i=2;i<=n;i++){
        dp[i][0]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
        dp[i][1]=max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]);
        dp[i][2]=max(dp[i-1][1]+c[i],dp[i-1][0]+c[i]);
    }
    cout<<max(dp[n][1],max(dp[n][0],dp[n][2]))<<endl;
} 

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
vector<int> v[100001],a;
int u[100001];
  
int dfs(int x,int p) {
  if(u[x])return 1;
  u[x]=1;
  int f=0;
  for(int i=0;i<v[x].size();i++)if(p!=v[x][i])f|=dfs(v[x][i],x);
  if(f)a.push_back(x);
  return f;
}
  
int main() {
  int n,m;
  cin>>n>>m;
  int w[n];
  for(int i=0;i<n;i++)cin>>w[i];
  for(int i=0,x,y;i<m;i++){
    cin>>x>>y;
    x--,y--;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(0,-1);
  int d[n],ans=0,M=0;
  fill(d,d+n,-1);
  priority_queue<P,vector<P>,greater<P> >q;
  for(int i=0;i<a.size();i++){
    q.push(P(0,a[i]));
    d[a[i]]=0;
    ans+=w[a[i]];
  }
  if(q.empty())q.push(P(w[0],0)),d[0]=w[0];
  while(!q.empty()) {
    P p=q.top();q.pop();
    int x=p.second,c=p.first;
    if(d[x]>c)continue;
    for(int i=0;i<v[x].size();i++) {
      int y=v[x][i];
      if(d[y]==-1)d[y]=d[x]+w[y],q.push(P(d[y],y));
    }
  }
  for(int i=0;i<n;i++)M=max(M,d[i]);
  cout<<ans+M<<endl;
  return 0;
}


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

#define pb push_back
#define pf push_front
#define pp pop_back
#define sz(a) (int)(a.size())
#define mp make_pair
#define F first
#define S second
#define next _next
#define prev _prev
#define left _left
#define right _right
#define y1 _y1
#define all(x) x.begin(), x.end()
#define what_is(x) #x << " is " << (x)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N = (int)1e6 + 123;
const ll INF = (ll)1e18 + 123;
const int inf = (int)1e9 + 123;
const int MOD = (int)1e9 + 7;

void megaRandom() {
	unsigned int FOR;
 	asm("rdtsc" : "=A"(FOR));
  srand(FOR);
}

int h, w;
char c[511][511];
char red[511][511], blue[511][511];

int main() {
	megaRandom();
	cin >> h >> w;
	for(int i=  1; i <= h; i ++) {
		for(int j = 1; j <= w; j ++) {
			cin >> c[i][j];
  	}
	}
	for(int i = 1; i <= h; i ++) {
		red[i][1] = '#';		
		blue[i][w] = '#';
		if(i & 1) {
			for(int j = 1; j < w; j ++) 
				red[i][j] = '#';
		} else {
			for(int j = w; j > 1; j --)
				blue[i][j] = '#';
		}		
	}
	for(int i = 1; i <= h; i ++) {
		for(int j = 1; j <= w; j ++) {
			if(c[i][j] == '#')
				red[i][j] = blue[i][j] = '#';
		}
	}
	for(int i = 1; i <= h; i ++) {
		for(int j = 1; j <= w; j ++) {
			if(red[i][j] != '#') red[i][j] = '.';
			cout << red[i][j];
		}
		cout << "\n";
	}
	cout << "\n";
	for(int i = 1; i <= h; i ++) {
		for(int j = 1; j <= w; j ++) {
			if(blue[i][j] != '#') blue[i][j] = '.';
			cout << blue[i][j];
		}
		cout << "\n";
	}
	return 0;  
}


Measured memory_bytes: 1536
#include <iostream>
#include <string>
using namespace std;
int main(){
  int a,b,c,d,e,f;
  cin>>a>>b>>c>>d;
  e=c-a;
  f=d-b;
  cout<<string(f,'U')<<string(e,'R')
    <<string(f,'D')<<string(e,'L')
    <<'L'<<string(f+1,'U')<<string(e+1,'R')<<'D'
    <<'R'<<string(f+1,'D')<<string(e+1,'L')<<'U'<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <cmath>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59

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

    int W, N;
    int cnt = 0;
    while (cin >> W >> N)
    {
        cnt++;
        if (W == 0)
            break;

        vector<int> v(N), w(N);
        char c;
        for (int i = 0; i < N; ++i)
            cin >> v[i] >> c >> w[i];

        int dp[1010][1010];
        for (int i = 0; i <= N; ++i)
        {
            for (int j = 0; j <= W; ++j)
            {
                dp[i][j] = 0;
            }
        }

        for (int i = 0; i < N; ++i)
        {
            for (int j = 0; j <= W; ++j)
            {
                if (j - w[i] >= 0)
                {

                    dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
                }
                else
                {

                    dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
                }
            }
        }
        cout << "Case " << cnt << ":" << endl;
        int mv = 0, mw = 0;

        for (int i = 0; i <= W; ++i)
        {
            if (dp[N][i] > mv)
            {
                mv = dp[N][i];
                mw = i;
            }
        }
        cout << mv << "\n"
             << mw << endl;
    }

    return 0;
}


Measured memory_bytes: 7068
n = int(input())
Xs = []
Ys = []
for _ in range(n):
    x, y = map(int, input().split())
    Xs.append(x+y)
    Ys.append(x-y)
Xs.sort()
Ys.sort()

print(max(Xs[-1]-Xs[0], Ys[-1]-Ys[0]))


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

namespace KCLC
{
    class Program
    {
        static void Main()
        {
            string Input = Console.ReadLine();
          
            int Wa = 0;
            for(int i = 0; i < Input.Length; i++) Wa += Input[i] - '0';
          
            if(Wa % 9 == 0) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 26408
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman010 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
const int N = 1e5 + 5;
int n , a[N] , freq[2 * N] , lst[N];
ll m , b[N];
int main() {
    abdelrahman010
    cin >> n >> m;
    for(int i = 0;i < n;i++)
        cin >> a[i] , freq[a[i]]++;
    for(int i = 1e5;i >= 0;i--)
        freq[i] += freq[i + 1];
    sort(a , a + n , greater<>());
    b[0] = a[0];
    for(int i = 1;i < n;i++)
        b[i] = a[i] + b[i - 1];
    int low = 2 , high = 2e5 , mid , p = -1;
    while(low <= high) {
        mid = low + high >> 1;
        ll cnt = 0;
        for(int i = 0;i < n;i++)
            cnt += freq[max(0 , mid - a[i])];
        if(cnt >= m)
            p = mid , low = mid + 1;
        else
            high = mid - 1;
    }
    ll ans = 0;
    for(int i = 0;i < n;i++) {
        int low = 0 , high = n - 1 , mid , j = -1;
        while(low <= high) {
            mid = low + high >> 1;
            if(a[mid] + a[i] >= p + 1)
                j = mid , low = mid + 1;
            else
                high = mid - 1;
        }
        if(j == -1)
            continue;
        ll tmp = min(m , j + 1ll);
        if(!tmp)
            break;
        lst[i] = tmp;
        ans += b[tmp - 1] + 1ll * a[i] * tmp;
        m -= tmp;
    }
    for(int i = 0;i < n;i++) {
        int low = lst[i] , high = n - 1 , mid , j = -1;
        while(low <= high) {
            mid = low + high >> 1;
            if(a[mid] + a[i] >= p)
                j = mid , low = mid + 1;
            else
                high = mid - 1;
        }
        if(j == -1)
            continue;
        ll tmp = min(m , j + 1ll - lst[i]);
        if(!tmp)
            break;
        ans += b[lst[i] + tmp - 1] - (lst[i] ? b[lst[i] - 1] : 0) + 1ll * a[i] * tmp;
        m -= tmp;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 2176
n,k,q = map(int,input().split())
tokuten = [k]*n
ans_list = [q]*n
for i in range(q):
    num = int(input())
    ans_list[num-1] -= 1
for i in range(len(tokuten)):
    if tokuten[i]-ans_list[i] <= 0:
        print('No')
    else:
        print('Yes')

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

int main() {
    int N, K; scanf("%d%d", &N, &K);
    if(N < 3) {
        printf("0\n");
    }
    else {
        N -= 2;
        int ans = N / 11 * 5, rest = N % 11, val = 4;
        for(int i=0; i<rest; i++) {
            int tmp = val, ok = false;
            for(int k=0; k<5; k++) {
                if(tmp == K) {
                    ok = true;
                    break;
                }
                tmp = (tmp - 2 + 11) % 11;
            }
            ans += ok;
            val = (val - 3 + 11) % 11;
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(){
	int i,j,N,a[100],key;
	scanf("%d",&N);
	for(i=0;i<N;i++)scanf("%d",&a[i]);
	for(i=0;i<N;i++){
		key=a[i];
		j=i-1;
		while(j>=0&&a[j]>key){
			a[j+1]=a[j];
			j--;
		}
		a[j+1]=key;
		for(j=0;j<N;j++){
			printf("%d",a[j]);
			if(j!=N-1)printf(" ");
			else printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 604
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<string>
#include<cmath>
typedef long long int ll;
#define VI vector<int>

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

int n,m;

using namespace std;


int main(){
	double maxi=-1,mini=100000000;
	while(1){
		double n;
		if(!(cin>>n))break;
		if(n==0)break;
		if(maxi<n)maxi=n;
		if(mini>n)mini=n;
	}
	cout<<maxi-mini<<endl;
	return 0;
}

Measured memory_bytes: 1280
import java.util.*;
class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int[] nums=new int[n];
for(int i=0;i<n;i++)nums[i]=sc.nextInt();
for(int i=1;i<n;i++){
if(nums[i-1]<nums[i])nums[i]--;
else if(nums[i-1]>nums[i]){System.out.println("No");
return;}
}
System.out.println("Yes");
}}

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

using namespace std;

int main() {
    string X;
    cin >> X;
    for(int i = 1; i < X.size(); i++) {
        if(X[i - 1] == 'S' && X[i] == 'T') {
            X.erase(X.begin() + i - 1);
            X.erase(X.begin() + i - 1);
            i -= 2;
        }
    }
    cout << X.size() << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int maxN = 100 * 1000 + 9;
const int MOD = 1e9 + 7;
const double EPS = 1e-18;

string s;

void read(){
  cin >> s;
}

bool isMonth(int x){
  return (0 < x) && (x <= 12);
}

void solv(){
  int x = (s[0] - '0') * 10 + s[1] - '0';
  int y = (s[2] - '0') * 10 + s[3] - '0';

  if(isMonth(x) && isMonth(y)){
    cout << "AMBIGUOUS";
    return;
  }

  if(isMonth(x)){
    cout << "MMYY";
    return;
  }

  if(isMonth(y)){
    cout << "YYMM";
    return;
  }

  cout << "NA";
}

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

  read();
  solv();

  return 0;
}


Measured memory_bytes: 256
list_input_str = []
evenNumber = []
num = []
a = []

for i in range(2):
    s = input()
    if s:
        list_input_str.append(s)

if list_input_str:
    num = list_input_str[0]
    a = list_input_str[1].split(' ')

for i in range(int(num)):
    if int(a[i]) % 2 == 0:
        evenNumber.append(a[i])

if len(evenNumber) == 0:
    print('APPROVED')
else:
    for i in range(len(evenNumber)):
        if not (int(evenNumber[i]) % 3 == 0 or int(evenNumber[i]) % 5 == 0):
            print('DENIED')
            break
        else:
            if i == int(len(evenNumber)) - 1:
                print('APPROVED')


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void) {
	long long int a, b, k;
	cin >> a >> b >> k;
	if (k == 0) {
		cout << a << " " << b;
	} else if (k > 0 && a >= k) {
		cout << a - k << " " << b;
	} else if (k > 0 && a < k && b > (k - a)) {
		cout << 0 << " " << b - (k - a);
	} else {
		cout << "0 0";
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n, d1, d2;
    cin>>n;
    vector<long long> dd;
    while (n--)
    {
        cin>>d1>>d2;
        dd.push_back(abs(d1 - d2));
    }
    n = dd.size();
    for(long long i =0; i< n-2; i++)
        if((dd[i] + dd[1+ i]+dd[2 +i]) == 0){
            cout<<"Yes";
            return 0;
        };
    cout<<"No";
    return 0;

    
}

Measured memory_bytes: 3600
#include<iostream>
#include<cstdio>
using namespace std;
int a,b,c,ans;
int main()
{
    scanf("%d%d%d",&a,&b,&c);
    if(a%2==0&&a==b&&b==c){puts("-1");return 0;}
    while(a%2==0&&b%2==0&&c%2==0)
    {
        int aa=a>>1,bb=b>>1,cc=c>>1;
        a=bb+cc;b=aa+cc;c=aa+bb;++ans;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>
#include <utility>
#include <climits>

#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;
constexpr auto mod = 1000000007;
constexpr auto INF = ULLONG_MAX;

using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }
template <typename T> inline T max_value(vector<T>& x) { return *max_element(x.begin(), x.end()); }
template <typename T> inline T min_value(vector<T>& x) { return *min_element(x.begin(), x.end()); }
template <typename T> inline T sum_value(vector<T>& x) { return accumulate(x.begin(), x.end(), 0); }

int main() {
  ull n, k;
  cin >> n >> k;

  ull result = 0;
  result = n - (k-1);

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf=1<<29;
const int M=26;

int n;
string s;

int main(){
	cin>>s;
	n=s.size();
	vvi dp(n+1,vi(M+1,inf));
	map<int,int> m;
	int res=inf,S=0;
	dp[0][M]=0;
	m[0]=0;
	for(int i=0;i<n;i++){
		int c=s[i]-'a';
		S^=1<<c;
		dp[i+1][M]=dp[i][c];
		for(int j=0;j<M;j++){
			int T=S^(1<<j);
			if(m.find(T)!=m.end()){
				int I=m[T];
				for(int k=0;k<=M;k++) dp[i+1][j]=min(dp[i+1][j],dp[I][k]+(k!=M||I==0?1:0));
			}
		}
		m[S]=i+1;
	}
	for(int i=0;i<=M;i++) res=min(res,dp[n][i]);
	cout<<res<<endl;
}

Measured memory_bytes: 39556
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC043A
{
    class Program
    {
        static void Main(string[] args)
        {
            int x;
            var word = Console.ReadLine().Split(' ');
            x = int.Parse(word[0]);
            int a = 0;
            for (int i = 0; i <= x; i++)
                a += i;

            Console.WriteLine(a);

            Console.ReadKey();





        }
    }
}

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

int main()
{
    int X;
    cin >> X;
    int A, B;
    int i = 0;
    bool break_flag = false;
    while(!break_flag)
    {
        for(int j = 0; j <= i; j++)
        {
            if(pow(i, 5) - pow(j, 5) == X)
            {
                A = i; B = j;
                break_flag = true;
                break;
            }
            else if(pow(i, 5) + pow(j, 5) == X)
            {
                A = i; B = -1 * j;
                break_flag = true;
                break;
            }
            else if(-1 * pow(i, 5) - pow(j, 5) == X)
            {
                A = -1 * i; B = j;
                break_flag = true;
                break;
            }
            else if(-1 * pow(i, 5) + pow(j, 5) == X)
            {
                A = -1 * i; B = -1 * j;
                break_flag = true;
                break;
            }
        }
        i++;
    }
    cout << A << " " << B << endl;
}


Measured memory_bytes: 4000
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String step;
		String answer = "Yes";
		int len;

		// 文字列を読み込む
		step = scan.next();
		len = step.length();

		for(int i = 0; i < len; i++) {
			if((i % 2 == 0 && step.charAt(i) == 'L') || (i % 2 == 1 && step.charAt(i) == 'R')) {
				answer = "No";
				break;
			}
		}

		System.out.println(answer);

	}
}


Measured memory_bytes: 21844
n = int(input())
a = [0] + list(map(int, input().split())) + [0]
b = []
tot = 0
for i in range(n + 1):
    b.append(abs(a[i + 1] - a[i]))
    tot += b[i]
for i in range(n):
    print(tot - abs(a[i + 1] - a[i]) - abs(a[i + 2] - a[i + 1]) +\
            abs(a[i + 2] - a[i]))


Measured memory_bytes: 13920
#include <stdio.h>
#include <string.h>
int main(void){
int a,b,c,d;
  scanf("%d %d %d %d",&a,&b,&c,&d);
    if((a+b)==(c+d)){printf("Balanced\n");}
  else if((a+b)<(c+d)){printf("Right\n");}
  else {printf("Left\n");}
}

Measured memory_bytes: 128
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using namespace std;

int main() {
    int k;
    ll x;
    cin >> k >> x;
    if (x <= k * 500) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int a[3], k;
    cin >> a[0] >> a[1] >> a[2] >> k;
    sort(a, a+3);
    for(int i=0; i<k; i++) a[2]*=2;
    cout << a[0] + a[1] + a[2] << endl;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

void mod_inverse(int n, vector<long long>& inv, int mod)
{
    inv.assign(n+1, -1);
    inv[1] = 1;
    for(int i=2; i<=n; ++i)
        inv[i] = inv[mod % i] * (mod - mod / i) % mod;
}

class FactorialCalculation
{
private:
    const int mod;
    vector<long long> factorial;
    vector<long long> invFactorial;
public:
    FactorialCalculation(int n, int mod) : mod(mod)
    {
        factorial.resize(n+1, 1);
        invFactorial.resize(n+1, 1);
        vector<long long> inv;
        mod_inverse(n, inv, mod);
        for(int i=1; i<=n; ++i){
            factorial[i] = factorial[i-1] * i % mod;
            invFactorial[i] = invFactorial[i-1] * inv[i] % mod;
        }
    }
    long long getFactorial(int n){
        return factorial[n];
    }
    long long getInvFactorial(int n){
        return invFactorial[n];
    }
    long long getPermutation(int n, int r){
        if(n < r)
            return 0;
        return factorial[n] * invFactorial[n-r] % mod;
    }
    long long getCombination(int n, int r){
        if(n < r)
            return 0;
        return getPermutation(n, r) * invFactorial[r] % mod;
    }
    long long getHomogeneous(int n, int r){
        if(n == 0 && r == 0)
            return 1;
        return getCombination(n+r-1, r);
    }
};

const int MOD = 1000000007;

int main()
{
    int n, k;
    cin >> n >> k;
    FactorialCalculation fc(n*2, MOD);

    long long ans = 0;
    for(int i=0; i<=min(n-1,k); ++i){
        long long tmp = fc.getCombination(n, i);
        tmp *= fc.getHomogeneous(n-i, i);
        tmp %= MOD;
        ans += tmp;
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}


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

int main() {
  
  int x, y, z;
  
  while(1){
    cin >>x >>y;
    z = x +y;
    if(z == 0) break;
    if(x > y){
      cout <<y <<" " <<x <<"\n";
    }else {
      cout <<x <<" " <<y <<"\n";
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int n,ans,par,tmp,md;
vector<vector<vector<int>>> a;

int main(){

	scanf("%d", &n);
	a = vector<vector<vector<int>>>(2, vector<vector<int>>(8, vector<int>(0)));
	for (int i=0; i<n; i++){
		scanf("%d", &tmp);
		a[0][tmp&7].push_back(tmp);
	}
	for (int i=1; i<10; i++){
		for (int j=7; j>=0; j--){
			for (int t: a[par][j]){
				md = (t>>(3*i))&7;
				a[1-par][md].push_back(t);
			}
		}
		for (int hoge=0; hoge<8; hoge++){a[par][hoge].clear();}
		par = 1-par;
	}
	tmp = 0;
	int dup=0;
	for(int i=0; i<8; i++){
		for (int t: a[par][i]){
			if(t == tmp){ dup++; tmp=0;} else {tmp=t;}
		}
	}
	printf("%d\n", (n-dup*2));
}


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

using namespace std;
typedef long long ll;

int main() {
  ll A; cin >> A;
  ll B; cin >> B;
  if (A < 13) {
    B /= 2;
  }
  if (A <= 5) {
    B = 0;
  }
  cout << B << endl;
  return 0;
}


Measured memory_bytes: 256
no = gets.to_i
s = gets.split
no2 = gets.to_i
t = gets.split
same=0
for j in 0...no2
    i=0
    s[no] = t[j]
    until s[i] == t[j]
        i+=1
    end
    unless i == no
        same+=1
    end
end
puts same

Measured memory_bytes: 6312
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
        int b = sc.nextInt();
		if(Math.max(a,b)<=9){System.out.println(a*b);}
		else{System.out.println("-1");}
	}
}


Measured memory_bytes: 23252
#include<iostream>
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a<=b && c<=d) cout<<a+c<<endl;
    else if(b<=a && c<=d) cout<<b+c<<endl;
    else if(a<=b && d<=c) cout<<a+d<<endl;
    else cout<<b+d<<endl;
    return 0;
}


Measured memory_bytes: 256
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100;
const long long MOD = 1000000007;
typedef pair<long long,long long> P;
//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}
long long nCr(long long n, long long r) {
    long long A = 1, B = 1;
    //Aが分子Bが1/r!
    for (long long i = n - r + 1; i <= n; i++) {
        A = A * i % MOD;
    }
    for (long long i = 1; i <= r; i++) {
        B = B * i % MOD;
    }
    B = mod_pow(B, MOD - 2);
    B %= MOD;
    //Bは割るのではなく掛ける
    return (A * B) % MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
 
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

//long long A,B;
bool ok(long long key,long long index){
    if(index > key) return true;
    else if(index <= key) return false;
}
long long binary_search(long long key,long long size){
    //left,right,midはいずれもindex
    long long left = -1,right = size;
    while(right - left > 1){
        long long mid = left + (right-left)/2;
        long long hantei = ok(key,mid);
        if(hantei) right = mid;
        else left = mid;
    }
    if(left == -1)return 0;
    return left;
}

int main() {
    long long N,mod;cin >> N >> mod;
    vector<long long> retu(N);
    map<long long,int> M;
    long long now = 0;
    M[0]++;
    for(int i = 0;i<N;i++){
        cin >> retu.at(i);
        now += retu.at(i);
        now %= mod;
        M[now]++;
    }
    long long ans = 0;
    for(auto A : M){
        long long num = A.second;
        ans += (num*(num-1))/2;
    }

    cout << ans << endl;


    // PLEASE GIVE ME THE "ACCEPTED" !
}


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

using namespace std;

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

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

// 素因数分解
vector<pll> prime_factor(ll n){
	vector<pll> res;
	for(ll i=2; i*i<=n; ++i){
		if(n%i!=0){
			continue;
		}
		ll num=0;
		while(n%i==0){
			++num;
			n/=i;
		}
		res.push_back(pii(i, num));
	}
	if(n!=1){
		res.push_back(pii(n, 1));
	}
	return res;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, p;
	cin>>n>>p;
	if(n==1){
		cout<<p<<'\n';
		return 0;
	}
	vector<pll> x=prime_factor(p);
	ll ans=1;
	for(auto &y : x){
		for(ll i=0; i<y.second/n; ++i){
			ans*=y.first;
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

void printVec(vector<int> vec){
	for(int i = 0; i < vec.size(); i++){
		cout<<vec[i]<<endl;
	}
	return ;
}

int main()
{
	int n;
	vector<int> vec1,vec2;
	bool isPossible;
	cin>>n;
	for(int i = 0; i < n; i++){
		int num;
		cin>>num;
		vec1.push_back(num);
	}
	do{
		isPossible = false;
		for(int i = vec1.size() - 1; i >= 0; i--){
			if( vec1[i] == i + 1){
				vec2.insert(vec2.begin(),vec1[i]);
				vec1.erase(vec1.begin() + i);
				isPossible = true;
				break;
			}
		}
	}while(vec1.size() > 0 && isPossible == true);

	if( vec2.size() == n){
		printVec(vec2);
	}else{
		cout<<-1<<endl;
	}
	return 0;
}



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

signed main(){

  int n,q;
  cin>>n>>q;

  vector<stack<int>> a(n);
  while(q--){
    int com;
    cin>>com;
    if(com==0){
      int t,x;
      cin>>t>>x;
      a[t].push(x);
    }
    if(com==1){
      int t;
      cin>>t;
      if(a[t].empty())continue;
      cout<<a[t].top()<<endl;
    }
    if(com==2){
      int t;
      cin>>t;
      if(a[t].empty())continue;
      a[t].pop();
    }
  }

}


Measured memory_bytes: 4360
# (t, x, y)
INIT = [0] * 3

n = gets.to_i
# (t, x, y)[]
plans = Array.new(n + 1)
plans[0] = INIT
plans[1..-1] = Array.new(n) { gets.split.map(&:to_i) }

p = plans.each_cons(2).all? do |p0p1|
  dt, dx, dy = p0p1.transpose.map { |a0, a1| a1 - a0 }
  dist = dx.abs + dy.abs # move 4n
  d = dt - dist

  # reachable & parity match
  d >= 0 && d.even?
end

puts p ? 'Yes' : 'No'


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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

const ll mod = 1000000007;

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int x, y, z;
    cin >> x >> y >> z;
    swap(x, y);
    swap(x, z);
    cout << x << " " << y << " " << z << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

map<ll, int> res;
void prime_factorization(ll N) {
  if(N == 1 || N == 0) return;
  ll n = N;
  ll i = 2;
  while(n >= i * i) {
    while(n % i == 0) {
      if(res.count(i)) res[i]++;
      else res[i] = 1;
      n /= i;
    }
    if(i == 2) i++;
    else i += 2;
  }
  if(n != 1) res[n] = 1;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  prime_factorization(N);
  int cnt = 0;
  for(auto r: res) {
    int n = r.second;
    int tmp = 1;
    while(true) {
      if(tmp * (tmp+1) / 2 > n) break;
      tmp++;
    }
    cnt += (tmp-1);
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3660
#include<iostream>
using namespace std;
int main() {
	int a = 0;
	int b = 0;
	int c = 0;
	cin >> a;
	cin >> b;
	cin >> c;
	if (a <= b && a <= c)
	{
		cout << a<<" ";
		if (b < c)
		{
			cout << b <<" "<< c << endl;
		}
		else
		{
			cout << c << " " << b << endl;
		}
	}
	else if (b <= a && b <= c)
	{
		cout << b<< " ";
		if (c < a)
		{
			cout << c << " " << a << endl;
		}
		else
		{
			cout << a << " " << c << endl;
		}
	}
	else if (c <= a && c <= b)
	{
		cout << c<< " ";
		if (b < a)
		{
			cout << b << " " << a << endl;
		}
		else
		{
			cout << a << " " << b << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
    */
int main(){//CODEFESTIVAL2016
    string S;
    cin >> S;
    string T = "CODEFESTIVAL2016";
    ll s = S.size();
    ll ans = 0;
    rep(i,s){
        if(S[i] != T[i])ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
MOD = 10**9 + 7

N,X = map(int,input().split())
S = list(map(int,input().split()))
S.sort()
S = [None] + S
dp = [[0 for i in range(X+1)] for j in range(N+1)]
dp[1] = [i % S[1] for i in range(X+1)]
for n in range(2, N+1):
	for x in range(X+1):
		dp[n][x] = (dp[n-1][x] * (n-1) + dp[n-1][x%S[n]]) % MOD
print(dp[N][X])

Measured memory_bytes: 257928
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string.h>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.1415926535897932;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

ll a, b, c, d;

ll gcd (ll x, ll y) {
    if (y == 0) return x;
    return gcd(y, x%y);
}

void solve() {
    cin >> a >> b >> c >> d;
    if (a < b) {
        cout << "No" << endl;
        return;
    }
    if (b > d) {
        cout << "No" << endl;
        return;
    }
    if (c >= b) {
        cout << "Yes" << endl;
        return;
    }
    ll g = gcd(b, d);
    if (b - g + a%g > c) cout << "No" << endl;
    else cout << "Yes" << endl;
}

int main() {
    int t; cin >> t;
    rep(i,t) solve();
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, W;
int w[110];
ll v[110];

ll dp[100100];

ll solve() {
    fill_n(dp, W+1, -1e18);
    dp[0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = W; j >= w[i-1]; j--) {
            dp[j] = max(dp[j], dp[j-w[i-1]]+v[i-1]);
        }
    }

    ll res = 0;
    for (int i = 0; i <= W; i++) res = max(res, dp[i]);
    return res;
}

void input() {
    cin >> n >> W;
    for (int i = 0; i < n; i++) cin >> w[i] >> v[i];
}

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

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;

int main(){
    int n, m;

    scanf("%d %d", &n, &m);
    
    vector<int> g[100001];
    
    for(int i = 0; i < m; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        g[a].push_back(b);
        g[b].push_back(a);
    }

    int c4 = 0;
    int v4 = 0;

    for(int i = 1; i <= n; i++){
        if(g[i].size() % 2 == 1){
            printf("No\n");
            return 0;
        }
    }

    for(int i = 1; i <= n; i++){
        if(g[i].size() == 4){
            c4++;
            v4 = i;
        }else if(g[i].size() >= 6){
            printf("Yes\n");
            return 0;
        }
    }

    if(c4 >= 3){
        printf("Yes\n");
    }else if(c4 == 2){
        bool b[100001];
        for(int i = 1; i <= n; i++){
            b[i] = false;
        }
        queue<int> q;
        int c = 0;

        b[v4] = true;
        q.push(v4);
        
        while (!q.empty())
        {
            int i = q.front();
            q.pop();
            if(v4 != i && g[i].size() == 4){
                c++;
            }else{
                b[i] = true;
                for(int k = 0; k < g[i].size(); k++){
                    if(!b[g[i][k]]){
                        q.push(g[i][k]);
                    }
                }
            }
        }
        if(c == 2){
            printf("Yes\n");
        }else{
            printf("No\n");
        }
    }else{
        printf("No\n");
    }

    return 0;
}

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

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
const long long MOD = (ll)1e9+7;
const long long MAX = (ll)1e5+100;

int main(void) {
   ll N;
   cin>>N;
   string S;
   cin>>S;
   vector<set<ll>> vn;
   vn.resize(10);
   rep(i,0,S.size()) {
      vn[(int)S[i] - (int)'0'].insert(i);
   }
   // rep(i,0,10) {
   //    for (auto el: vn[i]) cout<<el<<" ";
   //    cout<<endl;
   // }
   ll ans = 0;

   rep(i,0,10) {
      if (!vn[i].size()) continue;
      int fe = *(vn[i].begin());
      rep(j,0,10) {
         auto itr = upper_bound(vn[j].begin(),vn[j].end(),fe);
         if (itr == vn[j].end()) continue;
         int me = *itr;
         rep(k,0,10) {
            auto itr2 = upper_bound(vn[k].begin(),vn[k].end(),me);
            if (itr2 == vn[k].end()) continue;
            ans++;
            // cout<<i<<j<<k<<endl;
         }
      }

   }
   cout<<ans<<endl;








   return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n; cin>>n;
    int ans=1;
    while(ans*ans<=n) ans++;
    ans--;
    cout<<ans*ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int, int> P;
 
int main(){
  int a, b, c, k;
  cin >> a >> b >> c >> k;

  int sum=0;
  if(a>=k) sum=k;
  else if(a+b>k) sum=a;
  else sum=a-(k-a-b);
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3636
import static java.util.Comparator.comparing;

import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        Solver solver = new Solver(System.in, out);
        solver.solve();
        out.close();
    }
}
class Solver {
	Scanner sc;
	PrintWriter out;
    public Solver(InputStream in, PrintWriter out) {
    	sc = new Scanner(in);
    	this.out = out;
    }
    // ==========================================================
    public void solve() {
    	int N = ni();
    	int M = ni();
    	out.println(M >= N ? "Yes" : "No");
    }
    // Set に入れるなら　PPKEY　を使う！
    static class PP{
    	public int key, val;
    	public PP(int key, int val) {
    		this.key = key;
    		this.val = val;
    	}
		public int getKey() {
			return key;
		}
		public void setKey(int key) {
			this.key = key;
		}
		public int getVal() {
			return val;
		}
		public void setVal(int val) {
			this.val = val;
		}
    }
    // ------------------------------------------
    // 入力
    // ------------------------------------------
    public int ni() {
    	return sc.nextInt();
    }
    public long nl() {
    	return sc.nextLong();
    }
    public String ns() {
    	return sc.next();
    }
    public char[] nc() {
    	return sc.next().toCharArray();
    }
    public int[] ndi(int N) {
    	int[] ans = new int[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = ni();
		}
    	return ans;
    }
    public long[] ndl(int N) {
    	long[] ans = new long[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = nl();
		}
    	return ans;
    }
    public String[] nds(int N) {
    	String[] ans = new String[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = ns();
		}
    	return ans;
    }
    public char[][] ndc(int N) {
    	char[][] ans = new char[N][];
    	for (int i = 0; i < N; i++) {
			ans[i] = nc();
		}
    	return ans;
    }
    public int[][] nddi(int N, int S) {
    	int[][] ans = new int[N][S];
    	for (int i = 0; i < N; i++) {
			for (int j = 0; j < S; j++) {
				ans[i][j] = ni();
			}
		}
    	return ans;
    }
}


Measured memory_bytes: 21460
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int a[] = new int[n];

		int mod = 1_000_000_007;
		long modsum[] = new long[n];
		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt();

			if(i == 0){
				modsum[i] = a[i];
			}
			else {
				modsum[i] = (a[i] + modsum[i - 1])%mod;
			}
		}

		long result = 0;
		for(int i = n - 1; i > 0; i--){
			result += modsum[i - 1]*a[i]%mod;
			result %= mod;
		}

		System.out.println(result);

	}
}

Measured memory_bytes: 52280
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>
#include <climits>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))

int main() {
  int L, R, d;
  cin >> L >> R >> d;

  int ans = 0;
  for (int i = L; i <= R; i++) {
    if (i % d == 0) ans++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3164